47 #ifndef __Teko_NeumannSeriesPreconditionerFactory_hpp__
48 #define __Teko_NeumannSeriesPreconditionerFactory_hpp__
50 #include "Teko_NeumannSeriesPreconditionerFactoryDecl.hpp"
52 #include "Thyra_DefaultPreconditioner.hpp"
53 #include "Thyra_DefaultPreconditioner.hpp"
54 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
55 #include "Thyra_DefaultAddedLinearOp.hpp"
56 #include "Thyra_DefaultMultipliedLinearOp.hpp"
57 #include "Thyra_DefaultIdentityLinearOp.hpp"
59 #include "Teuchos_Array.hpp"
60 #include "Teuchos_StandardParameterEntryValidators.hpp"
67 static RCP<Teuchos::StringToIntegralParameterEntryValidator<Teko::DiagonalType> > scalingTypeVdtor;
69 template <
typename ScalarT>
70 NeumannSeriesPreconditionerFactory<ScalarT>::NeumannSeriesPreconditionerFactory()
71 : numberOfTerms_(1), scalingType_(Teko::NotDiag)
76 template <
typename ScalarT>
77 bool NeumannSeriesPreconditionerFactory<ScalarT>::isCompatible(
const Thyra::LinearOpSourceBase<ScalarT> &)
const
83 template <
typename ScalarT>
84 RCP<Thyra::PreconditionerBase<ScalarT> > NeumannSeriesPreconditionerFactory<ScalarT>::createPrec()
const
86 return rcp(
new Thyra::DefaultPreconditioner<ScalarT>());
97 template <
typename ScalarT>
98 void NeumannSeriesPreconditionerFactory<ScalarT>::initializePrec(
const RCP<
const Thyra::LinearOpSourceBase<ScalarT> > & fwdOpSrc,
99 Thyra::PreconditionerBase<ScalarT> * prec,
100 const Thyra::ESupportSolveUse )
const
104 using Thyra::multiply;
106 RCP<const Thyra::LinearOpBase<ScalarT> > M;
107 RCP<const Thyra::LinearOpBase<ScalarT> > A = fwdOpSrc->getOp();
108 if(scalingType_!=Teko::NotDiag) {
109 M = Teko::getInvDiagonalOp(A,scalingType_);
110 A = Thyra::multiply(M,A);
113 RCP<const Thyra::LinearOpBase<ScalarT> >
id = Thyra::identity<ScalarT>(A->range());
114 RCP<const Thyra::LinearOpBase<ScalarT> > idMA = add(
id,scale(-1.0,A));
117 RCP<const Thyra::LinearOpBase<ScalarT> > precOp;
118 if(numberOfTerms_==1) {
123 int iters = numberOfTerms_-1;
125 precOp = add(scale(2.0,
id),scale(-1.0,A));
126 for(
int i=0;i<iters;i++)
127 precOp = add(
id,multiply(idMA,precOp));
132 precOp = Thyra::multiply(precOp,M);
135 Thyra::DefaultPreconditioner<ScalarT> & dPrec = Teuchos::dyn_cast<Thyra::DefaultPreconditioner<ScalarT> >(*prec);
138 dPrec.initializeUnspecified(Teuchos::rcp_const_cast<Thyra::LinearOpBase<ScalarT> >(precOp));
142 template <
typename ScalarT>
143 void NeumannSeriesPreconditionerFactory<ScalarT>::uninitializePrec(Thyra::PreconditionerBase<ScalarT> * prec,
144 RCP<
const Thyra::LinearOpSourceBase<ScalarT> > * ,
145 Thyra::ESupportSolveUse * )
const
147 Thyra::DefaultPreconditioner<ScalarT> & dPrec = Teuchos::dyn_cast<Thyra::DefaultPreconditioner<ScalarT> >(*prec);
150 dPrec.uninitialize();
156 template <
typename ScalarT>
157 void NeumannSeriesPreconditionerFactory<ScalarT>::setParameterList(
const RCP<Teuchos::ParameterList> & paramList)
159 TEUCHOS_TEST_FOR_EXCEPT(paramList==Teuchos::null);
162 paramList->validateParametersAndSetDefaults(*getValidParameters(),0);
165 paramList_ = paramList;
167 numberOfTerms_ = paramList_->get<
int>(
"Number of Terms");
170 scalingType_ = Teko::NotDiag;
171 const Teuchos::ParameterEntry * entry = paramList_->getEntryPtr(
"Scaling Type");
173 scalingType_ = scalingTypeVdtor->getIntegralValue(*entry);
177 template <
typename ScalarT>
178 RCP<const Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::getValidParameters()
const
180 static RCP<Teuchos::ParameterList> validPL;
183 if(validPL==Teuchos::null) {
184 RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
187 scalingTypeVdtor = Teuchos::stringToIntegralParameterEntryValidator<DiagonalType>(
188 Teuchos::tuple<std::string>(
"Diagonal",
"Lumped",
"AbsRowSum",
"None"),
189 Teuchos::tuple<Teko::DiagonalType>(Teko::Diagonal,Teko::Lumped,Teko::AbsRowSum,Teko::NotDiag),
192 pl->set<
int>(
"Number of Terms",1,
193 "The number of terms to use in the Neumann series expansion.");
194 pl->set(
"Scaling Type",
"None",
"The number of terms to use in the Neumann series expansion.",
204 template <
typename ScalarT>
205 RCP<Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::unsetParameterList()
207 Teuchos::RCP<Teuchos::ParameterList> oldList = paramList_;
208 paramList_ = Teuchos::null;
213 template <
typename ScalarT>
214 RCP<const Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::getParameterList()
const
220 template <
typename ScalarT>
221 RCP<Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::getNonconstParameterList()
226 template <
typename ScalarT>
227 std::string NeumannSeriesPreconditionerFactory<ScalarT>::description()
const
229 std::ostringstream oss;
230 oss <<
"Teko::NeumannSeriesPreconditionerFactory";