Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_PreconditionerFactory.hpp
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 #ifndef __Teko_PreconditionerFactory_hpp__
11 #define __Teko_PreconditionerFactory_hpp__
12 
13 #include "Teuchos_ParameterListAcceptor.hpp"
14 
15 // Thyra includes
16 #include "Thyra_SolveSupportTypes.hpp"
17 #include "Thyra_LinearOpSourceBase.hpp"
18 #include "Thyra_PreconditionerFactoryBase.hpp"
19 #include "Thyra_DefaultBlockedLinearOp.hpp"
20 #include "Thyra_DefaultPreconditioner.hpp"
21 
22 // Teko includes
23 #include "Teko_Utilities.hpp"
24 #include "Teko_InverseLibrary.hpp"
25 #include "Teko_CloneFactory.hpp"
26 #include "Teko_PreconditionerState.hpp"
27 #include "Teko_RequestHandler.hpp"
28 #include "Teko_RequestHandlerContainer.hpp"
29 
30 namespace Teko {
31 
32 using Thyra::DefaultPreconditioner;
33 using Thyra::LinearOpBase;
34 
45 class PreconditionerFactory : public virtual Thyra::PreconditionerFactoryBase<double>,
47  public:
61  virtual LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const = 0;
62 
75  virtual Teuchos::RCP<PreconditionerState> buildPreconditionerState() const {
76  return Teuchos::rcp(new PreconditionerState());
77  }
78 
80 
81 
94  virtual void initializeFromParameterList(const Teuchos::ParameterList & /* settings */) {}
95 
110  virtual Teuchos::RCP<Teuchos::ParameterList> getRequestedParameters() const {
111  return Teuchos::null;
112  }
113 
127  virtual bool updateRequestedParameters(const Teuchos::ParameterList & /* pl */) { return true; }
128 
130 
132  void setInverseLibrary(const Teuchos::RCP<const InverseLibrary> &il);
133 
135  Teuchos::RCP<const InverseLibrary> getInverseLibrary() const;
136 
138 
139 
141  bool isCompatible(const Thyra::LinearOpSourceBase<double> &fwdOpSrc) const;
142 
144  Teuchos::RCP<Thyra::PreconditionerBase<double> > createPrec() const;
145 
156  void initializePrec(const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > &fwdOpSrc,
157  const Teuchos::RCP<const Thyra::MultiVectorBase<double> > &solnVec,
158  Thyra::PreconditionerBase<double> *precOp,
159  const Thyra::ESupportSolveUse supportSolveUse) const;
160 
162  void initializePrec(const Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > &fwdOpSrc,
163  Thyra::PreconditionerBase<double> *precOp,
164  const Thyra::ESupportSolveUse supportSolveUse) const;
165 
167  void uninitializePrec(Thyra::PreconditionerBase<double> *prec,
168  Teuchos::RCP<const Thyra::LinearOpSourceBase<double> > *fwdOpSrc,
169  Thyra::ESupportSolveUse *supportSolveUse) const;
171 
173 
174 
176  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> &paramList);
177 
179  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
180 
182  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
184 
186  void setRequestHandler(const Teuchos::RCP<RequestHandler> &rh) { callbackHandler_ = rh; }
187 
189  Teuchos::RCP<RequestHandler> getRequestHandler() const { return callbackHandler_; }
190 
191  protected:
193  Teuchos::RCP<Teuchos::ParameterList> paramList_;
194 
196  Teuchos::RCP<RequestHandler> callbackHandler_;
197 
198  private:
200  Teuchos::RCP<const InverseLibrary> inverseLibrary_;
201 
203  static void setOpRequestHandler(const RequestHandlerContainer &rhc, const LinearOp &op);
204 
205  public:
220  static Teuchos::RCP<PreconditionerFactory> buildPreconditionerFactory(
221  const std::string &name, const Teuchos::ParameterList &settings,
222  const Teuchos::RCP<const InverseLibrary> &invLib = Teuchos::null);
223 
237  static void addPreconditionerFactory(const std::string &name,
238  const Teuchos::RCP<Cloneable> &clone);
239 
242  static void getPreconditionerFactoryNames(std::vector<std::string> &names);
243 
244  private:
246  static CloneFactory<PreconditionerFactory> precFactoryBuilder_;
247 
249  static void initializePrecFactoryBuilder();
250 };
251 
252 } // end namespace Teko
253 
254 #endif
virtual void initializeFromParameterList(const Teuchos::ParameterList &)
This function builds the internals of the preconditioner factory from a parameter list...
static void getPreconditionerFactoryNames(std::vector< std::string > &names)
Get the names of the block preconditioner factories.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Get the parameter list that was set using setParameterList().
Abstract class which block preconditioner factories in Teko should be based on.
Teuchos::RCP< Teuchos::ParameterList > paramList_
for ParameterListAcceptor
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &paramList)
Set parameters from a parameter list and return with default values.
void uninitializePrec(Thyra::PreconditionerBase< double > *prec, Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > *fwdOpSrc, Thyra::ESupportSolveUse *supportSolveUse) const
wipe clean a already initialized preconditioner object
virtual bool updateRequestedParameters(const Teuchos::ParameterList &)
Update this object with the fields from a parameter list.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
Unset the parameter list that was set using setParameterList().
void setRequestHandler(const Teuchos::RCP< RequestHandler > &rh)
Set the request handler with pointers to the appropriate callbacks.
static void addPreconditionerFactory(const std::string &name, const Teuchos::RCP< Cloneable > &clone)
Add a preconditioner factory to the builder. This is done using the clone pattern.
Teuchos::RCP< RequestHandler > callbackHandler_
For handling requests and send requests back to the user.
void setInverseLibrary(const Teuchos::RCP< const InverseLibrary > &il)
Set the inverse library used by this preconditioner factory.
virtual LinearOp buildPreconditionerOperator(LinearOp &lo, PreconditionerState &state) const =0
Function that is called to build the preconditioner for the linear operator that is passed in...
bool isCompatible(const Thyra::LinearOpSourceBase< double > &fwdOpSrc) const
is this operator compatiable with the preconditioner factory?
Teuchos::RCP< const InverseLibrary > getInverseLibrary() const
Get the inverse library used by this preconditioner factory.
void initializePrec(const Teuchos::RCP< const Thyra::LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< const Thyra::MultiVectorBase< double > > &solnVec, Thyra::PreconditionerBase< double > *precOp, const Thyra::ESupportSolveUse supportSolveUse) const
initialize a newly created preconditioner object
Teuchos::RCP< Thyra::PreconditionerBase< double > > createPrec() const
create an instance of the preconditioner
virtual Teuchos::RCP< Teuchos::ParameterList > getRequestedParameters() const
Request the additional parameters this preconditioner factory needs.
An implementation of a state object preconditioners.
Teuchos::RCP< RequestHandler > getRequestHandler() const
Get the request handler with pointers to the appropriate callbacks.
virtual Teuchos::RCP< PreconditionerState > buildPreconditionerState() const
Function that permits the construction of an arbitrary PreconditionerState object.
static Teuchos::RCP< PreconditionerFactory > buildPreconditionerFactory(const std::string &name, const Teuchos::ParameterList &settings, const Teuchos::RCP< const InverseLibrary > &invLib=Teuchos::null)
Builder function for creating preconditioner factories (yes this is a factory factory).