44 #ifndef THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
45 #define THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
49 #include "Thyra_Amesos2LinearOpWithSolve.hpp"
50 #include "Amesos2.hpp"
51 #include "Amesos2_Details_LinearSolverFactory.hpp"
52 #include "Amesos2_Version.hpp"
53 #include "Amesos2_Factory.hpp"
56 #include "Thyra_DefaultDiagonalLinearOp.hpp"
67 template<
typename Scalar>
68 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::SolverType_name
71 template<
typename Scalar>
72 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::RefactorizationPolicy_name
73 =
"Refactorization Policy";
75 template<
typename Scalar>
76 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::ThrowOnPreconditionerInput_name
77 =
"Throw on Preconditioner Input";
79 template<
typename Scalar>
80 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::Amesos2_Settings_name
85 template<
typename Scalar>
90 paramList_->validateParameters(
91 *this->getValidParameters(),0
96 template<
typename Scalar>
100 const bool throwOnPrecInput
102 :solverType_(solverType)
103 ,refactorizationPolicy_(refactorizationPolicy)
104 ,throwOnPrecInput_(throwOnPrecInput)
110 template<
typename Scalar>
112 const LinearOpSourceBase<Scalar> &fwdOpSrc
116 fwdOp = fwdOpSrc.getOp();
117 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
118 if ( ! dynamic_cast<const MAT * >(&*tpetraFwdOp) )
123 template<
typename Scalar>
130 template<
typename Scalar>
132 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
133 LinearOpWithSolveBase<Scalar> *Op,
134 const ESupportSolveUse
137 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: Amesos2LOWSF");
145 out = Teuchos::VerboseObjectBase::getDefaultOStream();
150 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
151 auto tpetraCrsMat = Teuchos::rcp_dynamic_cast<
const MAT>(tpetraFwdOp);
159 bool startOver = ( amesos2Op->get_amesos2Solver()==
Teuchos::null );
161 auto oldTpetraFwdOp = ConverterT::getConstTpetraOperator(amesos2Op->get_fwdOp());
164 tpetraFwdOp.get() != oldTpetraFwdOp.get()
180 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:InitConstruct",
182 switch(solverType_) {
184 amesos2Solver = ::Amesos2::create<MAT,MV>(
"klu2", tpetraCrsMat);
186 #ifdef HAVE_AMESOS2_LAPACK
188 amesos2Solver = ::Amesos2::create<MAT,MV>(
"lapack", tpetraCrsMat);
191 #ifdef HAVE_AMESOS2_SUPERLU
192 case Thyra::Amesos2::SUPERLU:
193 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlu", tpetraCrsMat);
196 #ifdef HAVE_AMESOS2_SUPERLUMT
197 case Thyra::Amesos2::SUPERLUMT:
198 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlumt", tpetraCrsMat);
201 #ifdef HAVE_AMESOS2_SUPERLUDIST
202 case Thyra::Amesos2::SUPERLUDIST:
203 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superludist", tpetraCrsMat);
206 #ifdef HAVE_AMESOS2_PARDISO_MKL
207 case Thyra::Amesos2::PARDISO_MKL:
208 amesos2Solver = ::Amesos2::create<MAT,MV>(
"pardiso_mkl", tpetraCrsMat);
211 #ifdef HAVE_AMESOS2_CHOLMOD
212 case Thyra::Amesos2::CHOLMOD:
213 amesos2Solver = ::Amesos2::create<MAT,MV>(
"cholmod", tpetraCrsMat);
216 #ifdef HAVE_AMESOS2_BASKER
217 case Thyra::Amesos2::BASKER:
218 amesos2Solver = ::Amesos2::create<MAT,MV>(
"basker", tpetraCrsMat);
221 #ifdef HAVE_AMESOS2_MUMPS
222 case Thyra::Amesos2::MUMPS:
223 amesos2Solver = ::Amesos2::create<MAT,MV>(
"mumps", tpetraCrsMat);
228 true, std::logic_error
229 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
236 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
237 amesos2Solver->symbolicFactorization();
240 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Factor", Factor);
241 amesos2Solver->numericFactorization();
248 dup_list->
remove(SolverType_name);
249 dup_list->
remove(RefactorizationPolicy_name);
250 dup_list->
remove(ThrowOnPreconditionerInput_name);
251 dup_list->
remove(
"VerboseObject");
252 amesos2Solver->setParameters(dup_list);
255 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
261 auto amesos2Solver = amesos2Op->get_amesos2Solver();
264 amesos2Solver->setA(tpetraCrsMat);
268 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
269 amesos2Solver->symbolicFactorization();
272 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF::Factor", Factor);
273 amesos2Solver->numericFactorization();
277 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
279 amesos2Op->setOStream(this->getOStream());
280 amesos2Op->setVerbLevel(this->getVerbLevel());
283 template<
typename Scalar>
289 template<
typename Scalar>
291 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
292 const RCP<
const PreconditionerBase<Scalar> > &,
293 LinearOpWithSolveBase<Scalar> *Op,
294 const ESupportSolveUse supportSolveUse
298 this->throwOnPrecInput_, std::logic_error,
299 "Error, the concrete implementation described as \'"<<this->description()
300 <<
"\' does not support preconditioners"
301 " and has been configured to throw this exception when the"
302 " initializePreconditionedOp(...) function is called!"
304 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
307 template<
typename Scalar>
309 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
310 const RCP<
const LinearOpSourceBase<Scalar> > &,
311 LinearOpWithSolveBase<Scalar> *Op,
312 const ESupportSolveUse supportSolveUse
316 this->throwOnPrecInput_, std::logic_error,
317 "Error, the concrete implementation described as \'"<<this->description()
318 <<
"\' does not support preconditioners"
319 " and has been configured to throw this exception when the"
320 " initializePreconditionedOp(...) function is called!"
322 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
325 template<
typename Scalar>
327 LinearOpWithSolveBase<Scalar> *Op,
328 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
329 RCP<
const PreconditionerBase<Scalar> > *prec,
330 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
341 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
348 template<
typename Scalar>
357 paramList_ = paramList;
364 ,paramList_->name()+
"->"+SolverType_name
366 refactorizationPolicy_ =
369 RefactorizationPolicy_name
372 ,paramList_->name()+
"->"+RefactorizationPolicy_name
374 throwOnPrecInput_ = paramList_->get(ThrowOnPreconditionerInput_name,throwOnPrecInput_);
375 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
378 template<
typename Scalar>
385 template<
typename Scalar>
394 template<
typename Scalar>
401 template<
typename Scalar>
405 return generateAndGetValidParameters();
410 template<
typename Scalar>
413 std::ostringstream oss;
414 oss <<
"Thyra::Amesos2LinearOpWithSolveFactory{";
415 oss <<
"solverType=" <<
toString(solverType_);
422 template<
typename Scalar>
427 if (validParamList.
get()==NULL) {
430 validParamList->
set(RefactorizationPolicy_name,
432 validParamList->
set(ThrowOnPreconditionerInput_name,
bool(
true));
433 Teuchos::setupVerboseObjectSublist(&*validParamList);
435 return validParamList;
440 #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
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#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.
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...