10 #ifndef __Teko_NeumannSeriesPreconditionerFactory_hpp__
11 #define __Teko_NeumannSeriesPreconditionerFactory_hpp__
13 #include "Teko_NeumannSeriesPreconditionerFactoryDecl.hpp"
15 #include "Thyra_DefaultPreconditioner.hpp"
16 #include "Thyra_DefaultPreconditioner.hpp"
17 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
18 #include "Thyra_DefaultAddedLinearOp.hpp"
19 #include "Thyra_DefaultMultipliedLinearOp.hpp"
20 #include "Thyra_DefaultIdentityLinearOp.hpp"
22 #include "Teuchos_Array.hpp"
23 #include "Teuchos_StandardParameterEntryValidators.hpp"
30 static RCP<Teuchos::StringToIntegralParameterEntryValidator<Teko::DiagonalType> > scalingTypeVdtor;
32 template <
typename ScalarT>
33 NeumannSeriesPreconditionerFactory<ScalarT>::NeumannSeriesPreconditionerFactory()
34 : numberOfTerms_(1), scalingType_(Teko::NotDiag) {}
37 template <
typename ScalarT>
38 bool NeumannSeriesPreconditionerFactory<ScalarT>::isCompatible(
39 const Thyra::LinearOpSourceBase<ScalarT> & )
const {
44 template <
typename ScalarT>
45 RCP<Thyra::PreconditionerBase<ScalarT> > NeumannSeriesPreconditionerFactory<ScalarT>::createPrec()
47 return rcp(
new Thyra::DefaultPreconditioner<ScalarT>());
58 template <
typename ScalarT>
59 void NeumannSeriesPreconditionerFactory<ScalarT>::initializePrec(
60 const RCP<
const Thyra::LinearOpSourceBase<ScalarT> > &fwdOpSrc,
61 Thyra::PreconditionerBase<ScalarT> *prec,
62 const Thyra::ESupportSolveUse )
const {
64 using Thyra::multiply;
67 RCP<const Thyra::LinearOpBase<ScalarT> > M;
68 RCP<const Thyra::LinearOpBase<ScalarT> > A = fwdOpSrc->getOp();
69 if (scalingType_ != Teko::NotDiag) {
70 M = Teko::getInvDiagonalOp(A, scalingType_);
71 A = Thyra::multiply(M, A);
74 RCP<const Thyra::LinearOpBase<ScalarT> >
id = Thyra::identity<ScalarT>(A->range());
75 RCP<const Thyra::LinearOpBase<ScalarT> > idMA = add(
id, scale(-1.0, A));
77 RCP<const Thyra::LinearOpBase<ScalarT> > precOp;
78 if (numberOfTerms_ == 1) {
82 int iters = numberOfTerms_ - 1;
84 precOp = add(scale(2.0,
id), scale(-1.0, A));
85 for (
int i = 0; i < iters; i++) precOp = add(
id, multiply(idMA, precOp));
89 if (M != Teuchos::null) precOp = Thyra::multiply(precOp, M);
92 Thyra::DefaultPreconditioner<ScalarT> &dPrec =
93 Teuchos::dyn_cast<Thyra::DefaultPreconditioner<ScalarT> >(*prec);
96 dPrec.initializeUnspecified(Teuchos::rcp_const_cast<Thyra::LinearOpBase<ScalarT> >(precOp));
100 template <
typename ScalarT>
101 void NeumannSeriesPreconditionerFactory<ScalarT>::uninitializePrec(
102 Thyra::PreconditionerBase<ScalarT> *prec,
103 RCP<
const Thyra::LinearOpSourceBase<ScalarT> > * ,
104 Thyra::ESupportSolveUse * )
const {
105 Thyra::DefaultPreconditioner<ScalarT> &dPrec =
106 Teuchos::dyn_cast<Thyra::DefaultPreconditioner<ScalarT> >(*prec);
109 dPrec.uninitialize();
115 template <
typename ScalarT>
116 void NeumannSeriesPreconditionerFactory<ScalarT>::setParameterList(
117 const RCP<Teuchos::ParameterList> ¶mList) {
118 TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
121 paramList->validateParametersAndSetDefaults(*getValidParameters(), 0);
124 paramList_ = paramList;
126 numberOfTerms_ = paramList_->get<
int>(
"Number of Terms");
129 scalingType_ = Teko::NotDiag;
130 const Teuchos::ParameterEntry *entry = paramList_->getEntryPtr(
"Scaling Type");
131 if (entry != NULL) scalingType_ = scalingTypeVdtor->getIntegralValue(*entry);
135 template <
typename ScalarT>
136 RCP<const Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::getValidParameters()
138 static RCP<Teuchos::ParameterList> validPL;
141 if (validPL == Teuchos::null) {
142 RCP<Teuchos::ParameterList> pl = rcp(
new Teuchos::ParameterList());
145 scalingTypeVdtor = Teuchos::stringToIntegralParameterEntryValidator<DiagonalType>(
146 Teuchos::tuple<std::string>(
"Diagonal",
"Lumped",
"AbsRowSum",
"None"),
147 Teuchos::tuple<Teko::DiagonalType>(Teko::Diagonal, Teko::Lumped, Teko::AbsRowSum,
151 pl->set<
int>(
"Number of Terms", 1,
152 "The number of terms to use in the Neumann series expansion.");
153 pl->set(
"Scaling Type",
"None",
"The number of terms to use in the Neumann series expansion.",
163 template <
typename ScalarT>
164 RCP<Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::unsetParameterList() {
165 Teuchos::RCP<Teuchos::ParameterList> oldList = paramList_;
166 paramList_ = Teuchos::null;
171 template <
typename ScalarT>
172 RCP<const Teuchos::ParameterList> NeumannSeriesPreconditionerFactory<ScalarT>::getParameterList()
178 template <
typename ScalarT>
179 RCP<Teuchos::ParameterList>
180 NeumannSeriesPreconditionerFactory<ScalarT>::getNonconstParameterList() {
184 template <
typename ScalarT>
185 std::string NeumannSeriesPreconditionerFactory<ScalarT>::description()
const {
186 std::ostringstream oss;
187 oss <<
"Teko::NeumannSeriesPreconditionerFactory";