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"
68 template<
typename Scalar>
69 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::SolverType_name
72 template<
typename Scalar>
73 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::RefactorizationPolicy_name
74 =
"Refactorization Policy";
76 template<
typename Scalar>
77 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::ThrowOnPreconditionerInput_name
78 =
"Throw on Preconditioner Input";
80 template<
typename Scalar>
81 const std::string Amesos2LinearOpWithSolveFactory<Scalar>::Amesos2_Settings_name
86 template<
typename Scalar>
91 paramList_->validateParameters(
92 *this->getValidParameters(),0
97 template<
typename Scalar>
101 const bool throwOnPrecInput
103 :solverType_(solverType)
104 ,refactorizationPolicy_(refactorizationPolicy)
105 ,throwOnPrecInput_(throwOnPrecInput)
111 template<
typename Scalar>
113 const LinearOpSourceBase<Scalar> &fwdOpSrc
117 fwdOp = fwdOpSrc.getOp();
118 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
119 if ( ! dynamic_cast<const MAT * >(&*tpetraFwdOp) )
124 template<
typename Scalar>
131 template<
typename Scalar>
133 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
134 LinearOpWithSolveBase<Scalar> *Op,
135 const ESupportSolveUse
138 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: Amesos2LOWSF");
146 out = Teuchos::VerboseObjectBase::getDefaultOStream();
151 auto tpetraFwdOp = ConverterT::getConstTpetraOperator(fwdOp);
152 auto tpetraCrsMat = Teuchos::rcp_dynamic_cast<
const MAT>(tpetraFwdOp);
160 bool startOver = ( amesos2Op->get_amesos2Solver()==
Teuchos::null );
162 auto oldTpetraFwdOp = ConverterT::getConstTpetraOperator(amesos2Op->get_fwdOp());
165 tpetraFwdOp.get() != oldTpetraFwdOp.get()
181 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:InitConstruct",
183 switch(solverType_) {
185 amesos2Solver = ::Amesos2::create<MAT,MV>(
"klu2", tpetraCrsMat);
187 #ifdef HAVE_AMESOS2_LAPACK
189 amesos2Solver = ::Amesos2::create<MAT,MV>(
"lapack", tpetraCrsMat);
192 #ifdef HAVE_AMESOS2_SUPERLU
193 case Thyra::Amesos2::SUPERLU:
194 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlu", tpetraCrsMat);
197 #ifdef HAVE_AMESOS2_SUPERLUMT
198 case Thyra::Amesos2::SUPERLUMT:
199 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superlumt", tpetraCrsMat);
202 #ifdef HAVE_AMESOS2_SUPERLUDIST
203 case Thyra::Amesos2::SUPERLUDIST:
204 amesos2Solver = ::Amesos2::create<MAT,MV>(
"superludist", tpetraCrsMat);
207 #ifdef HAVE_AMESOS2_PARDISO_MKL
208 case Thyra::Amesos2::PARDISO_MKL:
209 amesos2Solver = ::Amesos2::create<MAT,MV>(
"pardiso_mkl", tpetraCrsMat);
212 #ifdef HAVE_AMESOS2_CHOLMOD
213 case Thyra::Amesos2::CHOLMOD:
214 amesos2Solver = ::Amesos2::create<MAT,MV>(
"cholmod", tpetraCrsMat);
217 #ifdef HAVE_AMESOS2_BASKER
218 case Thyra::Amesos2::BASKER:
219 amesos2Solver = ::Amesos2::create<MAT,MV>(
"basker", tpetraCrsMat);
222 #ifdef HAVE_AMESOS2_MUMPS
223 case Thyra::Amesos2::MUMPS:
224 amesos2Solver = ::Amesos2::create<MAT,MV>(
"mumps", tpetraCrsMat);
229 true, std::logic_error
230 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
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();
249 dup_list->
remove(SolverType_name);
250 dup_list->
remove(RefactorizationPolicy_name);
251 dup_list->
remove(ThrowOnPreconditionerInput_name);
252 dup_list->
remove(
"VerboseObject");
253 amesos2Solver->setParameters(dup_list);
256 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
262 auto amesos2Solver = amesos2Op->get_amesos2Solver();
265 amesos2Solver->setA(tpetraCrsMat);
269 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF:Symbolic", Symbolic);
270 amesos2Solver->symbolicFactorization();
273 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: Amesos2LOWSF::Factor", Factor);
274 amesos2Solver->numericFactorization();
278 amesos2Op->initialize(fwdOp,fwdOpSrc,amesos2Solver);
280 amesos2Op->setOStream(this->getOStream());
281 amesos2Op->setVerbLevel(this->getVerbLevel());
284 template<
typename Scalar>
290 template<
typename Scalar>
292 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
293 const RCP<
const PreconditionerBase<Scalar> > &,
294 LinearOpWithSolveBase<Scalar> *Op,
295 const ESupportSolveUse supportSolveUse
299 this->throwOnPrecInput_, std::logic_error,
300 "Error, the concrete implementation described as \'"<<this->description()
301 <<
"\' does not support preconditioners"
302 " and has been configured to throw this exception when the"
303 " initializePreconditionedOp(...) function is called!"
305 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
308 template<
typename Scalar>
310 const RCP<
const LinearOpSourceBase<Scalar> > &fwdOpSrc,
311 const RCP<
const LinearOpSourceBase<Scalar> > &,
312 LinearOpWithSolveBase<Scalar> *Op,
313 const ESupportSolveUse supportSolveUse
317 this->throwOnPrecInput_, std::logic_error,
318 "Error, the concrete implementation described as \'"<<this->description()
319 <<
"\' does not support preconditioners"
320 " and has been configured to throw this exception when the"
321 " initializePreconditionedOp(...) function is called!"
323 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
326 template<
typename Scalar>
328 LinearOpWithSolveBase<Scalar> *Op,
329 RCP<
const LinearOpSourceBase<Scalar> > *fwdOpSrc,
330 RCP<
const PreconditionerBase<Scalar> > *prec,
331 RCP<
const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
342 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
349 template<
typename Scalar>
358 paramList_ = paramList;
365 ,paramList_->name()+
"->"+SolverType_name
367 refactorizationPolicy_ =
370 RefactorizationPolicy_name
373 ,paramList_->name()+
"->"+RefactorizationPolicy_name
375 throwOnPrecInput_ = paramList_->get(ThrowOnPreconditionerInput_name,throwOnPrecInput_);
376 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
379 template<
typename Scalar>
386 template<
typename Scalar>
395 template<
typename Scalar>
402 template<
typename Scalar>
406 return generateAndGetValidParameters();
411 template<
typename Scalar>
414 std::ostringstream oss;
415 oss <<
"Thyra::Amesos2LinearOpWithSolveFactory{";
416 oss <<
"solverType=" <<
toString(solverType_);
423 template<
typename Scalar>
428 if (validParamList.
get()==NULL) {
431 validParamList->
set(RefactorizationPolicy_name,
433 validParamList->
set(ThrowOnPreconditionerInput_name,
bool(
true));
434 Teuchos::setupVerboseObjectSublist(&*validParamList);
436 return validParamList;
441 #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...