10 #ifndef THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
11 #define THYRA_AMESOS2_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
16 #include "Thyra_Amesos2LinearOpWithSolve.hpp"
17 #include "Amesos2.hpp"
18 #include "Amesos2_Details_LinearSolverFactory.hpp"
19 #include "Amesos2_Version.hpp"
20 #include "Amesos2_Factory.hpp"
24 #include "Thyra_DefaultDiagonalLinearOp.hpp"
36 template<
typename Scalar>
37 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::SolverType_name
40 template<
typename Scalar>
41 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::RefactorizationPolicy_name
42 =
"Refactorization Policy";
44 template<
typename Scalar>
45 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::ThrowOnPreconditionerInput_name
46 =
"Throw on Preconditioner Input";
48 template<
typename Scalar>
49 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::Amesos2_Settings_name
54 template<
typename Scalar>
59 paramList_->validateParameters(
60 *this->getValidParameters(),0
65 template<
typename Scalar>
69 const bool throwOnPrecInput
71 :solverType_(solverType)
72 ,refactorizationPolicy_(refactorizationPolicy)
73 ,throwOnPrecInput_(throwOnPrecInput)
79 template<
typename Scalar>
81 const LinearOpSourceBase<Scalar> &fwdOpSrc
85 fwdOp = fwdOpSrc.getOp();
86 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
87 if ( ! dynamic_cast<const MAT * >(&*tpetraFwdOp) )
92 template<
typename Scalar>
99 template<
typename Scalar>
101 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
102 LinearOpWithSolveBase<Scalar> *Op,
103 const ESupportSolveUse
106 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: Amesos2LOWSF");
114 out = Teuchos::VerboseObjectBase::getDefaultOStream();
119 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
120 auto tpetraCrsMat = Teuchos::rcp_dynamic_cast<
const MAT>(tpetraFwdOp);
128 bool startOver = ( amesos2Op->get_amesos2Solver()==
Teuchos::null );
130 auto oldTpetraFwdOp = ConverterT::getConstTpetraOperator(amesos2Op->get_fwdOp());
133 tpetraFwdOp.get() != oldTpetraFwdOp.get()
149 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:InitConstruct",
151 switch(solverType_) {
153 amesos2Solver = ::Amesos2::create<MAT,MV>(
"klu2", tpetraCrsMat);
155 #ifdef HAVE_AMESOS2_LAPACK
157 amesos2Solver = ::Amesos2::create<MAT,MV>(
"lapack", tpetraCrsMat);
160 #ifdef HAVE_AMESOS2_SUPERLU
161 case Thyra::Amesos2::SUPERLU:
162 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlu", tpetraCrsMat);
165 #ifdef HAVE_AMESOS2_SUPERLUMT
166 case Thyra::Amesos2::SUPERLUMT:
167 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlumt", tpetraCrsMat);
170 #ifdef HAVE_AMESOS2_SUPERLUDIST
171 case Thyra::Amesos2::SUPERLUDIST:
172 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superludist", tpetraCrsMat);
175 #ifdef HAVE_AMESOS2_PARDISO_MKL
176 case Thyra::Amesos2::PARDISO_MKL:
177 amesos2Solver = ::Amesos2::create<MAT,MV>(
"pardiso_mkl", tpetraCrsMat);
180 #ifdef HAVE_AMESOS2_CHOLMOD
181 case Thyra::Amesos2::CHOLMOD:
182 amesos2Solver = ::Amesos2::create<MAT,MV>(
"cholmod", tpetraCrsMat);
185 #ifdef HAVE_AMESOS2_BASKER
186 case Thyra::Amesos2::BASKER:
187 amesos2Solver = ::Amesos2::create<MAT,MV>(
"basker", tpetraCrsMat);
190 #ifdef HAVE_AMESOS2_MUMPS
191 case Thyra::Amesos2::MUMPS:
192 amesos2Solver = ::Amesos2::create<MAT,MV>(
"mumps", tpetraCrsMat);
197 true, std::logic_error
198 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
205 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
206 amesos2Solver->symbolicFactorization();
209 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Factor", Factor);
210 amesos2Solver->numericFactorization();
217 dup_list->
remove(SolverType_name);
218 dup_list->
remove(RefactorizationPolicy_name);
219 dup_list->
remove(ThrowOnPreconditionerInput_name);
220 dup_list->
remove(
"VerboseObject");
221 amesos2Solver->setParameters(dup_list);
224 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
230 auto amesos2Solver = amesos2Op->get_amesos2Solver();
233 amesos2Solver->setA(tpetraCrsMat);
237 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
238 amesos2Solver->symbolicFactorization();
241 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF::Factor", Factor);
242 amesos2Solver->numericFactorization();
246 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
248 amesos2Op->setOStream(this->getOStream());
249 amesos2Op->setVerbLevel(this->getVerbLevel());
252 template<
typename Scalar>
258 template<
typename Scalar>
260 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
261 const RCP<
const PreconditionerBase<Scalar> > &,
262 LinearOpWithSolveBase<Scalar> *Op,
263 const ESupportSolveUse supportSolveUse
267 this->throwOnPrecInput_, std::logic_error,
268 "Error, the concrete implementation described as \'"<<this->description()
269 <<
"\' does not support preconditioners"
270 " and has been configured to throw this exception when the"
271 " initializePreconditionedOp(...) function is called!"
273 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
276 template<
typename Scalar>
278 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
279 const RCP<
const LinearOpSourceBase<Scalar> > &,
280 LinearOpWithSolveBase<Scalar> *Op,
281 const ESupportSolveUse supportSolveUse
285 this->throwOnPrecInput_, std::logic_error,
286 "Error, the concrete implementation described as \'"<<this->description()
287 <<
"\' does not support preconditioners"
288 " and has been configured to throw this exception when the"
289 " initializePreconditionedOp(...) function is called!"
291 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
294 template<
typename Scalar>
296 LinearOpWithSolveBase<Scalar> *Op,
297 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
298 RCP<
const PreconditionerBase<Scalar> > *prec,
299 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
310 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
317 template<
typename Scalar>
326 paramList_ = paramList;
333 ,paramList_->name()+
"->"+SolverType_name
335 refactorizationPolicy_ =
338 RefactorizationPolicy_name
341 ,paramList_->name()+
"->"+RefactorizationPolicy_name
343 throwOnPrecInput_ = paramList_->get(ThrowOnPreconditionerInput_name,throwOnPrecInput_);
344 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
347 template<
typename Scalar>
354 template<
typename Scalar>
363 template<
typename Scalar>
370 template<
typename Scalar>
374 return generateAndGetValidParameters();
379 template<
typename Scalar>
382 std::ostringstream oss;
383 oss <<
"Thyra::Amesos2LinearOpWithSolveFactory{";
384 oss <<
"solverType=" <<
toString(solverType_);
391 template<
typename Scalar>
396 if (validParamList.
get()==NULL) {
402 validParamList->
set(SolverType_name,
404 "Type of Amesos2 solver",
407 validParamList->
set(RefactorizationPolicy_name,
409 validParamList->
set(ThrowOnPreconditionerInput_name,
bool(
true));
410 Teuchos::setupVerboseObjectSublist(&*validParamList);
412 return validParamList;
417 #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)
const char * solverTypeNames[numSolverTypes]
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...