Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_LU2x2PreconditionerFactory.cpp
1 // @HEADER
2 // *****************************************************************************
3 // Teko: A package for block and physics based preconditioning
4 //
5 // Copyright 2010 NTESS and the Teko contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teko_LU2x2PreconditionerFactory.hpp"
11 
12 // Teko includes
13 #include "Teko_LU2x2InverseOp.hpp"
14 #include "Teko_BlockUpperTriInverseOp.hpp"
15 
16 // default strategies
17 #include "Teko_LU2x2DiagonalStrategy.hpp"
18 #include "NS/Teko_PCDStrategy.hpp"
19 
20 using Teuchos::rcp;
21 using Teuchos::RCP;
22 
23 namespace Teko {
24 
25 // construct a PreconditionerFactory
27  : invOpsStrategy_(rcp(new StaticLU2x2Strategy(invA00, invA00, invS))), useFullLDU_(true) {}
28 
30 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(LinearOp& hatInvA00, LinearOp& tildeInvA00,
31  LinearOp& invS)
32  : invOpsStrategy_(rcp(new StaticLU2x2Strategy(hatInvA00, tildeInvA00, invS))),
33  useFullLDU_(true) {}
34 
35 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(const RCP<LU2x2Strategy>& strategy)
36  : invOpsStrategy_(strategy), useFullLDU_(true) {}
37 
39  : invOpsStrategy_(Teuchos::null), useFullLDU_(true) {}
40 
41 // for PreconditionerFactoryBase
43 
44 // initialize a newly created preconditioner object
46  BlockedLinearOp& A, BlockPreconditionerState& state) const {
47  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildPreconditionerOperator", 10);
48  LinearOp hatInvA00 = invOpsStrategy_->getHatInvA00(A, state);
49  LinearOp tildeInvA00 = invOpsStrategy_->getTildeInvA00(A, state);
50  LinearOp invS = invOpsStrategy_->getInvS(A, state);
51 
52  // build the SchurSolve LinearOp
53  if (useFullLDU())
54  return createLU2x2InverseOp(A, hatInvA00, tildeInvA00, invS, "LU2x2-Full");
55  else {
56  std::vector<LinearOp> invDiag(2);
57  invDiag[0] = hatInvA00;
58  invDiag[1] = scale(-1.0, invS);
59  return createBlockUpperTriInverseOp(A, invDiag, "LU2x2-Upper");
60  }
61 }
62 
76  const Teuchos::ParameterList& settings) {
77  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeFromParameterList", 10);
78 
79  // use Golub & Wathen type or full LDU decomposition for inverse solve?
80  bool useLDU = true;
81  if (settings.isParameter("Use LDU")) useLDU = settings.get<bool>("Use LDU");
82  setFullLDU(useLDU);
83 
84  // build strategy object
85  std::string stratName = settings.get<std::string>("Strategy Name");
86  const Teuchos::ParameterList& pl = settings.sublist("Strategy Settings");
88 }
89 
104 Teuchos::RCP<Teuchos::ParameterList> LU2x2PreconditionerFactory::getRequestedParameters() const {
105  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::getRequestedParameters", 0);
106  return invOpsStrategy_->getRequestedParameters();
107 }
108 
122 bool LU2x2PreconditionerFactory::updateRequestedParameters(const Teuchos::ParameterList& pl) {
123  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::updateRequestedParameters", 0);
124  return invOpsStrategy_->updateRequestedParameters(pl);
125 }
126 
128 // Static members and methods
130 
132 CloneFactory<LU2x2Strategy> LU2x2PreconditionerFactory::strategyBuilder_;
133 
147  const std::string& name, const Teuchos::ParameterList& settings,
148  const RCP<const InverseLibrary>& invLib, const RCP<RequestHandler>& rh) {
149  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildStrategy", 0);
150 
151  // initialize the defaults if necessary
152  if (strategyBuilder_.cloneCount() == 0) initializeStrategyBuilder();
153 
154  Teko_DEBUG_MSG_BEGIN(1) std::vector<std::string> names;
155  strategyBuilder_.getCloneNames(names);
156  DEBUG_STREAM << "Strategy names = ";
157  for (std::size_t i = 0; i < names.size(); i++) DEBUG_STREAM << names[i] << ", ";
158  DEBUG_STREAM << std::endl;
159  Teko_DEBUG_MSG_END()
160 
161  // request the preconditioner factory from the CloneFactory
162  RCP<LU2x2Strategy>
163  strategy = strategyBuilder_.build(name);
164 
165  if (strategy == Teuchos::null) {
166  Teko_DEBUG_MSG("Warning: Could not build LU2x2Strategy named \""
167  << name << "\"...pressing on, failure expected",
168  0) return Teuchos::null;
169  }
170 
171  // now that inverse library has been set,
172  // pass in the parameter list
173  strategy->setRequestHandler(rh);
174  strategy->initializeFromParameterList(settings, *invLib);
175 
176  return strategy;
177 }
178 
192 void LU2x2PreconditionerFactory::addStrategy(const std::string& name, const RCP<Cloneable>& clone) {
193  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::addStrategy", 10);
194 
195  // initialize the defaults if necessary
196  if (strategyBuilder_.cloneCount() == 0) initializeStrategyBuilder();
197 
198  // add clone to builder
199  strategyBuilder_.addClone(name, clone);
200 }
201 
203 void LU2x2PreconditionerFactory::initializeStrategyBuilder() {
204  Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeStrategyBuilder", 10);
205 
206  RCP<Cloneable> clone;
207 
208  // add various strategies to the factory
209  clone = rcp(new AutoClone<LU2x2DiagonalStrategy>());
210  strategyBuilder_.addClone("Diagonal Strategy", clone);
211 
212  // add various strategies to the factory
213  clone = rcp(new AutoClone<NS::PCDStrategy>());
214  strategyBuilder_.addClone("NS PCD Strategy", clone);
215 }
216 
217 } // end namespace Teko
LinearOp buildPreconditionerOperator(BlockedLinearOp &blo, BlockPreconditionerState &state) const
Create the LU 2x2 preconditioner operator.
virtual bool updateRequestedParameters(const Teuchos::ParameterList &pl)
Update this object with the fields from a parameter list.
static RCP< LU2x2Strategy > buildStrategy(const std::string &name, const Teuchos::ParameterList &settings, const RCP< const InverseLibrary > &invLib, const RCP< RequestHandler > &rh)
Builder function for creating strategies.
Teuchos::RCP< LU2x2Strategy > invOpsStrategy_
some members
An implementation of a state object for block preconditioners.
virtual void setFullLDU(bool value)
Set the type of inverse operation to use.
static void addStrategy(const std::string &name, const RCP< Cloneable > &clone)
Add a strategy to the builder. This is done using the clone pattern.
LU2x2PreconditionerFactory()
Default constructor for use with AutoClone.
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
virtual bool useFullLDU() const
Determine the type of inverse operator to build.
A simple strategy for use with LU2x2PreconditionerFactory, that offers static objects for inv(F) and ...
Teuchos::RCP< RequestHandler > getRequestHandler() const
Get the request handler with pointers to the appropriate callbacks.
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
Request the additional parameters this preconditioner factory needs.
virtual void initializeFromParameterList(const Teuchos::ParameterList &settings)
This function builds the internals of the preconditioner factory from a parameter list...