10 #include "Teko_Config.h"
11 #include "Teko_PreconditionerFactory.hpp"
13 #include "Teko_InverseLibrary.hpp"
14 #include "Teko_Preconditioner.hpp"
17 #include "Teko_JacobiPreconditionerFactory.hpp"
18 #include "Teko_GaussSeidelPreconditionerFactory.hpp"
19 #include "Teko_HierarchicalGaussSeidelPreconditionerFactory.hpp"
20 #include "Teko_AddPreconditionerFactory.hpp"
21 #include "Teko_MultPreconditionerFactory.hpp"
22 #include "Teko_LU2x2PreconditionerFactory.hpp"
23 #include "Teko_IterativePreconditionerFactory.hpp"
24 #include "Teko_DiagnosticPreconditionerFactory.hpp"
25 #include "Teko_DiagonallyScaledPreconditionerFactory.hpp"
26 #include "Teko_DiagonalPreconditionerFactory.hpp"
27 #ifdef TEKO_HAVE_EPETRA
28 #include "Teko_ProbingPreconditionerFactory.hpp"
30 #include "Teko_IdentityPreconditionerFactory.hpp"
31 #include "NS/Teko_LSCPreconditionerFactory.hpp"
32 #include "NS/Teko_SIMPLEPreconditionerFactory.hpp"
33 #include "NS/Teko_TimingsSIMPLEPreconditionerFactory.hpp"
35 #ifdef Teko_ENABLE_ML_SMOOTHERS
36 #include "Teko_SmootherPreconditionerFactory.hpp"
37 #include "Teko_MLPreconditionerFactory.hpp"
40 #include "Thyra_DefaultPreconditioner.hpp"
42 using namespace Thyra;
49 bool PreconditionerFactory::isCompatible(
const Thyra::LinearOpSourceBase<double> &fwdOpSrc)
const {
50 RCP<const Thyra::LinearOpBase<double> > A = fwdOpSrc.getOp();
51 return A != Teuchos::null;
55 RCP<Thyra::PreconditionerBase<double> > PreconditionerFactory::createPrec()
const {
58 bp->setStateObject(buildPreconditionerState());
59 bp->getStateObject()->setInitialized(
false);
65 void PreconditionerFactory::initializePrec(
const RCP<
const LinearOpSourceBase<double> > &ASrc,
66 PreconditionerBase<double> *prec,
67 const ESupportSolveUse )
const {
69 LinearOp A = Teuchos::rcp_const_cast<Thyra::LinearOpBase<double> >(ASrc->getOp());
72 TEUCHOS_ASSERT(blkPrec != 0);
75 RCP<PreconditionerState> state = blkPrec->getStateObject();
76 state->setInitialized(
false);
79 const RCP<const LinearOpBase<double> > M = buildPreconditionerOperator(A, *state);
82 setOpRequestHandler(*
this, M);
85 DefaultPreconditioner<double> &dPrec = Teuchos::dyn_cast<DefaultPreconditioner<double> >(*prec);
86 dPrec.initializeUnspecified(Teuchos::rcp_const_cast<LinearOpBase<double> >(M));
90 void PreconditionerFactory::initializePrec(
91 const RCP<
const LinearOpSourceBase<double> > &ASrc,
92 const RCP<
const Thyra::MultiVectorBase<double> > &solnVec, PreconditionerBase<double> *prec,
93 const ESupportSolveUse supportSolveUse)
const {
94 Preconditioner *blkPrec =
dynamic_cast<Preconditioner *
>(prec);
95 blkPrec->setSourceVector(Teuchos::rcp_const_cast<Thyra::MultiVectorBase<double> >(solnVec));
97 initializePrec(ASrc, prec, supportSolveUse);
101 void PreconditionerFactory::uninitializePrec(
102 PreconditionerBase<double> * ,
103 RCP<
const LinearOpSourceBase<double> > * ,
104 ESupportSolveUse * )
const {
108 TEUCHOS_TEST_FOR_EXCEPT_MSG(
true,
"\"PreconditionerFactory::uninitializePrec not implemented\"");
115 void PreconditionerFactory::setParameterList(
const RCP<Teuchos::ParameterList> ¶mList) {
116 paramList_ = paramList;
120 RCP<Teuchos::ParameterList> PreconditionerFactory::getNonconstParameterList() {
return paramList_; }
123 RCP<Teuchos::ParameterList> PreconditionerFactory::unsetParameterList() {
124 RCP<Teuchos::ParameterList> _paramList = paramList_;
125 paramList_ = Teuchos::null;
130 void PreconditionerFactory::setInverseLibrary(
const RCP<const InverseLibrary> &il) {
131 inverseLibrary_ = il;
135 RCP<const InverseLibrary> PreconditionerFactory::getInverseLibrary()
const {
137 if (inverseLibrary_ == Teuchos::null)
return InverseLibrary::buildFromStratimikos();
139 return inverseLibrary_;
148 const LinearOp &op) {
149 ModifiableLinearOp mlo = Teuchos::rcp_const_cast<Thyra::LinearOpBase<double> >(op);
152 RCP<RequestHandlerContainer> reqHandCont =
154 if (reqHandCont != Teuchos::null) {
162 CloneFactory<PreconditionerFactory> PreconditionerFactory::precFactoryBuilder_;
178 RCP<PreconditionerFactory> PreconditionerFactory::buildPreconditionerFactory(
179 const std::string &name,
const Teuchos::ParameterList &settings,
180 const RCP<const InverseLibrary> &invLib) {
181 Teko_DEBUG_SCOPE(
"PreconditionerFactory::buildPreconditionerFactory", 10);
184 if (precFactoryBuilder_.cloneCount() == 0) initializePrecFactoryBuilder();
187 RCP<PreconditionerFactory> precFact = precFactoryBuilder_.build(name);
189 Teko_DEBUG_MSG_BEGIN(5);
190 DEBUG_STREAM <<
"Looked up \"" << name <<
"\"" << std::endl;
191 DEBUG_STREAM <<
"Built " << precFact << std::endl;
192 Teko_DEBUG_MSG_END();
194 if (precFact == Teuchos::null)
return Teuchos::null;
197 if (invLib != Teuchos::null) {
198 precFact->setInverseLibrary(invLib);
199 precFact->setRequestHandler(invLib->getRequestHandler());
204 precFact->initializeFromParameterList(settings);
222 void PreconditionerFactory::addPreconditionerFactory(
const std::string &name,
223 const RCP<Cloneable> &clone) {
225 if (precFactoryBuilder_.cloneCount() == 0) initializePrecFactoryBuilder();
228 precFactoryBuilder_.addClone(name, clone);
232 void PreconditionerFactory::initializePrecFactoryBuilder() {
233 RCP<Cloneable> clone;
237 precFactoryBuilder_.addClone(
"Block LU2x2", clone);
240 precFactoryBuilder_.addClone(
"Block Jacobi", clone);
243 precFactoryBuilder_.addClone(
"Block Gauss-Seidel", clone);
246 precFactoryBuilder_.addClone(
"Hierarchical Block Gauss-Seidel", clone);
249 precFactoryBuilder_.addClone(
"Block Add", clone);
252 precFactoryBuilder_.addClone(
"Block Multiply", clone);
255 precFactoryBuilder_.addClone(
"NS LSC", clone);
258 precFactoryBuilder_.addClone(
"NS SIMPLE", clone);
261 precFactoryBuilder_.addClone(
"NS SIMPLE-Timed", clone);
264 precFactoryBuilder_.addClone(
"Iterative Preconditioner", clone);
267 precFactoryBuilder_.addClone(
"Explicit Diagonal Preconditioner", clone);
270 precFactoryBuilder_.addClone(
"Diagnostic Inverse", clone);
273 precFactoryBuilder_.addClone(
"Diagonal Scaling", clone);
276 precFactoryBuilder_.addClone(
"Identity", clone);
278 #if defined(Teko_ENABLE_Isorropia) && defined(TEKO_HAVE_EPETRA)
280 precFactoryBuilder_.addClone(
"Probing Preconditioner", clone);
283 #ifdef Teko_ENABLE_ML_SMOOTHERS
285 precFactoryBuilder_.addClone(
"Blocked ML Preconditioner", clone);
289 void PreconditionerFactory::getPreconditionerFactoryNames(std::vector<std::string> &names) {
291 if (precFactoryBuilder_.cloneCount() == 0) initializePrecFactoryBuilder();
292 precFactoryBuilder_.getCloneNames(names);
virtual void setRequestHandler(const Teuchos::RCP< RequestHandler > &rh)=0
Set the request handler with pointers to the appropriate callbacks.
An extension of the Thyra::DefaultPreconditioner class with some specializations useful for use withi...
virtual Teuchos::RCP< RequestHandler > getRequestHandler() const =0
Get the request handler with pointers to the appropriate callbacks.