10 #ifndef THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
11 #define THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
15 #include "Thyra_Amesos2LinearOpWithSolve.hpp"
16 #include "Amesos2.hpp"
17 #include "Amesos2_Details_LinearSolverFactory.hpp"
18 #include "Amesos2_Version.hpp"
19 #include "Amesos2_Factory.hpp"
22 #include "Thyra_DefaultDiagonalLinearOp.hpp"
33 template<
typename Scalar>
34 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::SolverType_name
37 template<
typename Scalar>
38 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::RefactorizationPolicy_name
39 =
"Refactorization Policy";
41 template<
typename Scalar>
42 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::ThrowOnPreconditionerInput_name
43 =
"Throw on Preconditioner Input";
45 template<
typename Scalar>
46 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::Amesos2_Settings_name
51 template<
typename Scalar>
56 paramList_->validateParameters(
57 *this->getValidParameters(),0
62 template<
typename Scalar>
66 const bool throwOnPrecInput
68 :solverType_(solverType)
69 ,refactorizationPolicy_(refactorizationPolicy)
70 ,throwOnPrecInput_(throwOnPrecInput)
76 template<
typename Scalar>
78 const LinearOpSourceBase<Scalar> &fwdOpSrc
82 fwdOp = fwdOpSrc.getOp();
83 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
84 if ( ! dynamic_cast<const MAT * >(&*tpetraFwdOp) )
89 template<
typename Scalar>
96 template<
typename Scalar>
98 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
99 LinearOpWithSolveBase<Scalar> *Op,
100 const ESupportSolveUse
103 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: Amesos2LOWSF");
111 out = Teuchos::VerboseObjectBase::getDefaultOStream();
116 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
117 auto tpetraCrsMat = Teuchos::rcp_dynamic_cast<
const MAT>(tpetraFwdOp);
125 bool startOver = ( amesos2Op->get_amesos2Solver()==
Teuchos::null );
127 auto oldTpetraFwdOp = ConverterT::getConstTpetraOperator(amesos2Op->get_fwdOp());
130 tpetraFwdOp.get() != oldTpetraFwdOp.get()
146 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:InitConstruct",
148 switch(solverType_) {
150 amesos2Solver = ::Amesos2::create<MAT,MV>(
"klu2", tpetraCrsMat);
152 #ifdef HAVE_AMESOS2_LAPACK
154 amesos2Solver = ::Amesos2::create<MAT,MV>(
"lapack", tpetraCrsMat);
157 #ifdef HAVE_AMESOS2_SUPERLU
158 case Thyra::Amesos2::SUPERLU:
159 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlu", tpetraCrsMat);
162 #ifdef HAVE_AMESOS2_SUPERLUMT
163 case Thyra::Amesos2::SUPERLUMT:
164 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlumt", tpetraCrsMat);
167 #ifdef HAVE_AMESOS2_SUPERLUDIST
168 case Thyra::Amesos2::SUPERLUDIST:
169 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superludist", tpetraCrsMat);
172 #ifdef HAVE_AMESOS2_PARDISO_MKL
173 case Thyra::Amesos2::PARDISO_MKL:
174 amesos2Solver = ::Amesos2::create<MAT,MV>(
"pardiso_mkl", tpetraCrsMat);
177 #ifdef HAVE_AMESOS2_CHOLMOD
178 case Thyra::Amesos2::CHOLMOD:
179 amesos2Solver = ::Amesos2::create<MAT,MV>(
"cholmod", tpetraCrsMat);
182 #ifdef HAVE_AMESOS2_BASKER
183 case Thyra::Amesos2::BASKER:
184 amesos2Solver = ::Amesos2::create<MAT,MV>(
"basker", tpetraCrsMat);
187 #ifdef HAVE_AMESOS2_MUMPS
188 case Thyra::Amesos2::MUMPS:
189 amesos2Solver = ::Amesos2::create<MAT,MV>(
"mumps", tpetraCrsMat);
194 true, std::logic_error
195 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
202 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
203 amesos2Solver->symbolicFactorization();
206 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Factor", Factor);
207 amesos2Solver->numericFactorization();
214 dup_list->
remove(SolverType_name);
215 dup_list->
remove(RefactorizationPolicy_name);
216 dup_list->
remove(ThrowOnPreconditionerInput_name);
217 dup_list->
remove(
"VerboseObject");
218 amesos2Solver->setParameters(dup_list);
221 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
227 auto amesos2Solver = amesos2Op->get_amesos2Solver();
230 amesos2Solver->setA(tpetraCrsMat);
234 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
235 amesos2Solver->symbolicFactorization();
238 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF::Factor", Factor);
239 amesos2Solver->numericFactorization();
243 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
245 amesos2Op->setOStream(this->getOStream());
246 amesos2Op->setVerbLevel(this->getVerbLevel());
249 template<
typename Scalar>
255 template<
typename Scalar>
257 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
258 const RCP<
const PreconditionerBase<Scalar> > &,
259 LinearOpWithSolveBase<Scalar> *Op,
260 const ESupportSolveUse supportSolveUse
264 this->throwOnPrecInput_, std::logic_error,
265 "Error, the concrete implementation described as \'"<<this->description()
266 <<
"\' does not support preconditioners"
267 " and has been configured to throw this exception when the"
268 " initializePreconditionedOp(...) function is called!"
270 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
273 template<
typename Scalar>
275 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
276 const RCP<
const LinearOpSourceBase<Scalar> > &,
277 LinearOpWithSolveBase<Scalar> *Op,
278 const ESupportSolveUse supportSolveUse
282 this->throwOnPrecInput_, std::logic_error,
283 "Error, the concrete implementation described as \'"<<this->description()
284 <<
"\' does not support preconditioners"
285 " and has been configured to throw this exception when the"
286 " initializePreconditionedOp(...) function is called!"
288 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
291 template<
typename Scalar>
293 LinearOpWithSolveBase<Scalar> *Op,
294 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
295 RCP<
const PreconditionerBase<Scalar> > *prec,
296 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
307 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
314 template<
typename Scalar>
323 paramList_ = paramList;
330 ,paramList_->name()+
"->"+SolverType_name
332 refactorizationPolicy_ =
335 RefactorizationPolicy_name
338 ,paramList_->name()+
"->"+RefactorizationPolicy_name
340 throwOnPrecInput_ = paramList_->get(ThrowOnPreconditionerInput_name,throwOnPrecInput_);
341 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
344 template<
typename Scalar>
351 template<
typename Scalar>
360 template<
typename Scalar>
367 template<
typename Scalar>
371 return generateAndGetValidParameters();
376 template<
typename Scalar>
379 std::ostringstream oss;
380 oss <<
"Thyra::Amesos2LinearOpWithSolveFactory{";
381 oss <<
"solverType=" <<
toString(solverType_);
388 template<
typename Scalar>
393 if (validParamList.
get()==NULL) {
396 validParamList->
set(RefactorizationPolicy_name,
398 validParamList->
set(ThrowOnPreconditionerInput_name,
bool(
true));
399 Teuchos::setupVerboseObjectSublist(&*validParamList);
401 return validParamList;
406 #endif // THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
const std::string toString(const EAdjointEpetraOp adjointEpetraOp)
static Teuchos::RCP< const Teuchos::ParameterList > generateAndGetValidParameters()
Teuchos::RCP< LinearOpWithSolveBase< Scalar > > createOp() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Concrete LinearOpWithSolveBase subclass in terms of Amesos2.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void initializePreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const Teuchos::RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Throws exception if this->throwOnPrecInput()==true and calls this->initializeOp(fwdOpSrc,Op) otherwise.
Completely new pivoting will be used on refactorizations!
std::string description() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
ERefactorizationPolicy
The policy used on refactoring a matrix.
int get(const std::string &option, const std::string &groupName="") const
typename Amesos2LinearOpWithSolve< Scalar >::MAT MAT
bool remove(std::string const &name, bool throwIfNotExists=true)
const char * solverTypeNames[numSolverTypes]
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
T_To & dyn_cast(T_From &from)
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
const char * toString(const ESolverType solverType)
Teuchos::StringToIntMap refactorizationPolicyNameToEnumMap
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
~Amesos2LinearOpWithSolveFactory()
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
Returns false .
Teuchos::StringToIntMap solverTypeNameToEnumMap
Amesos2LinearOpWithSolveFactory(const Amesos2::ESolverType solverType=Amesos2::LAPACK, const Amesos2::ERefactorizationPolicy refactorizationPolicy=Amesos2::REPIVOT_ON_REFACTORIZATION, const bool throwOnPrecInput=true)
Constructor which sets the defaults.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, Teuchos::RCP< const PreconditionerBase< Scalar > > *prec, Teuchos::RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
Teuchos::RCP< const LinearOpSourceBase< Scalar > > extract_fwdOpSrc()
Extract the forward LinearOpSourceBase<double> object so that it can be modified and remove it from t...