46 #include "Thyra_AmesosLinearOpWithSolveFactory.hpp"
48 #include "Thyra_AmesosLinearOpWithSolve.hpp"
49 #include "Thyra_EpetraOperatorViewExtractorStd.hpp"
51 #include "Teuchos_dyn_cast.hpp"
52 #include "Teuchos_TimeMonitor.hpp"
53 #include "Teuchos_TypeNameTraits.hpp"
54 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
56 #ifdef HAVE_AMESOS_KLU
59 #ifdef HAVE_AMESOS_PASTIX
60 #include "Amesos_Pastix.h"
62 #ifdef HAVE_AMESOS_LAPACK
63 #include "Amesos_Lapack.h"
65 #ifdef HAVE_AMESOS_MUMPS
66 #include "Amesos_Mumps.h"
68 #ifdef HAVE_AMESOS_SCALAPACK
69 #include "Amesos_Scalapack.h"
71 #ifdef HAVE_AMESOS_UMFPACK
74 #ifdef HAVE_AMESOS_SUPERLUDIST
75 #include "Amesos_Superludist.h"
77 #ifdef HAVE_AMESOS_SUPERLU
78 #include "Amesos_Superlu.h"
80 #ifdef HAVE_AMESOS_DSCPACK
81 #include "Amesos_Dscpack.h"
83 #ifdef HAVE_AMESOS_PARDISO
84 #include "Amesos_Pardiso.h"
86 #ifdef HAVE_AMESOS_TAUCS
89 #ifdef HAVE_AMESOS_PARAKLETE
95 const std::string epetraFwdOp_str =
"epetraFwdOp";
119 *this->getValidParameters(),0
125 const Amesos::ESolverType solverType
126 ,
const Amesos::ERefactorizationPolicy refactorizationPolicy
127 ,
const bool throwOnPrecInput
130 ,solverType_(solverType)
131 ,refactorizationPolicy_(refactorizationPolicy)
132 ,throwOnPrecInput_(throwOnPrecInput)
141 using Teuchos::outArg;
143 fwdOp = fwdOpSrc.
getOp();
148 double epetraFwdOpScalar;
149 epetraFwdOpViewExtractor_->getEpetraOpView(
151 outArg(epetraFwdOp), outArg(epetraFwdOpTransp),
152 outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport),
153 outArg(epetraFwdOpScalar)
155 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
172 using Teuchos::outArg;
173 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: AmesosLOWSF");
178 fwdOp = fwdOpSrc->getOp();
186 double epetraFwdOpScalar;
187 epetraFwdOpViewExtractor_->getEpetraOpView(
189 outArg(epetraFwdOp), outArg(epetraFwdOpTransp),
190 outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport),
191 outArg(epetraFwdOpScalar)
222 epetraLP->
SetOperator(const_cast<Epetra_Operator*>(&*epetraFwdOp));
223 Teuchos::set_extra_data< RCP<const Epetra_Operator> >( epetraFwdOp, epetraFwdOp_str,
224 Teuchos::inOutArg(epetraLP) );
229 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:InitConstruct",
231 switch(solverType_) {
232 case Thyra::Amesos::LAPACK :
235 #ifdef HAVE_AMESOS_KLU
236 case Thyra::Amesos::KLU :
240 #ifdef HAVE_AMESOS_PASTIX
241 case Thyra::Amesos::PASTIX :
242 amesosSolver =
Teuchos::rcp(
new Amesos_Pastix(*epetraLP));
245 #ifdef HAVE_AMESOS_MUMPS
246 case Thyra::Amesos::MUMPS :
250 #ifdef HAVE_AMESOS_SCALAPACK
251 case Thyra::Amesos::SCALAPACK :
255 #ifdef HAVE_AMESOS_UMFPACK
256 case Thyra::Amesos::UMFPACK :
260 #ifdef HAVE_AMESOS_SUPERLUDIST
261 case Thyra::Amesos::SUPERLUDIST :
265 #ifdef HAVE_AMESOS_SUPERLU
266 case Thyra::Amesos::SUPERLU :
270 #ifdef HAVE_AMESOS_DSCPACK
271 case Thyra::Amesos::DSCPACK :
275 #ifdef HAVE_AMESOS_PARDISO
276 case Thyra::Amesos::PARDISO :
280 #ifdef HAVE_AMESOS_TAUCS
281 case Thyra::Amesos::TAUCS :
285 #ifdef HAVE_AMESOS_PARAKLETE
286 case Thyra::Amesos::PARAKLETE :
292 true, std::logic_error
293 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
298 if(paramList_.
get()) amesosSolver->SetParameters(paramList_->
sublist(
"Amesos Settings"));
301 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:Symbolic", Symbolic);
302 const int err = amesosSolver->SymbolicFactorization();
304 "Error, SymbolicFactorization() on amesos solver of type \'"<<
Teuchos::typeName(*amesosSolver)<<
"\'\n"
305 "returned error code "<<err<<
"!" );
308 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:Factor", Factor);
309 const int err = amesosSolver->NumericFactorization();
311 "Error, NumericFactorization() on amesos solver of type \'"<<
Teuchos::typeName(*amesosSolver)<<
"\'\n"
312 "returned error code "<<err<<
"!" );
315 amesosOp->
initialize(fwdOp,fwdOpSrc,epetraLP,amesosSolver,epetraFwdOpTransp,epetraFwdOpScalar);
329 epetraLP->
SetOperator(const_cast<Epetra_Operator*>(&*epetraFwdOp));
330 Teuchos::get_nonconst_extra_data<RCP<const Epetra_Operator> >(epetraLP,epetraFwdOp_str) = epetraFwdOp;
334 if(refactorizationPolicy_==Amesos::REPIVOT_ON_REFACTORIZATION) {
335 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:Symbolic", Symbolic);
336 const int err = amesosSolver->SymbolicFactorization();
338 "Error, SymbolicFactorization() on amesos solver of type \'"<<
Teuchos::typeName(*amesosSolver)<<
"\'\n"
339 "returned error code "<<err<<
"!" );
342 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF::Factor", Factor);
343 const int err = amesosSolver->NumericFactorization();
345 "Error, NumericFactorization() on amesos solver of type \'"<<
Teuchos::typeName(*amesosSolver)<<
"\'\n"
346 "returned error code "<<err<<
"!" );
354 amesosOp->
initialize(fwdOp,fwdOpSrc,epetraLP,amesosSolver,epetraFwdOpTransp,epetraFwdOpScalar);
356 amesosOp->setOStream(this->getOStream());
357 amesosOp->setVerbLevel(this->getVerbLevel());
373 this->throwOnPrecInput_, std::logic_error
374 ,
"Error, the concrete implementation described as \'"<<this->
description()<<
"\' does not support preconditioners "
375 "and has been configured to throw this exception when the initializePreconditionedOp(...) function is called!"
388 this->throwOnPrecInput_, std::logic_error
389 ,
"Error, the concrete implementation described as \'"<<this->
description()<<
"\' does not support preconditioners "
390 "and has been configured to throw this exception when the initializePreconditionedOp(...) function is called!"
410 if(_fwdOpSrc.
get()) {
413 Teuchos::get_nonconst_extra_data< RCP<const Epetra_Operator> >(
414 epetraLP,epetraFwdOp_str
422 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
423 if(prec) *prec = Teuchos::null;
424 if(approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
435 paramList_ = paramList;
437 Amesos::solverTypeNameToEnumMap.get<Amesos::ESolverType>(
444 refactorizationPolicy_ =
445 Amesos::refactorizationPolicyNameToEnumMap.get<Amesos::ERefactorizationPolicy>(
453 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
466 paramList_ = Teuchos::null;
479 return generateAndGetValidParameters();
486 std::ostringstream oss;
487 oss <<
"Thyra::AmesosLinearOpWithSolveFactory{";
488 oss <<
"solverType=" <<
toString(solverType_);
496 AmesosLinearOpWithSolveFactory::generateAndGetValidParameters()
499 if(validParamList.
get()==NULL) {
503 #ifdef HAVE_AMESOS_KLU
512 Teuchos::setupVerboseObjectSublist(&*validParamList);
514 return validParamList;
const std::string & name() const
Teuchos::RCP< const LinearOpSourceBase< double > > extract_fwdOpSrc()
Extract the LinearOpSourceBase<double> object so that it can be modified.
void SetOperator(Epetra_RowMatrix *A)
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
Returns false .
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
bool isCompatible(const LinearOpSourceBase< double > &fwdOpSrc) const
Returns true if dynamic_cast<const EpetraLinearOpBase*>(fwdOpSrc)!=NULL .
~AmesosLinearOpWithSolveFactory()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< Amesos_BaseSolver > get_amesosSolver() const
static const std::string Amesos_Settings_name
T_To & dyn_cast(T_From &from)
static Teuchos::ParameterList GetValidParameters()
static const std::string SolverType_name
static const std::string RefactorizationPolicy_name
static const std::string ThrowOnPreconditionerInput_name
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
void uninitializeOp(LinearOpWithSolveBase< double > *Op, Teuchos::RCP< const LinearOpSourceBase< double > > *fwdOpSrc, Teuchos::RCP< const PreconditionerBase< double > > *prec, Teuchos::RCP< const LinearOpSourceBase< double > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
void initialize(const Teuchos::RCP< const LinearOpBase< double > > &fwdOp, const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< Epetra_LinearProblem > &epetraLP, const Teuchos::RCP< Amesos_BaseSolver > &amesosSolver, const EOpTransp amesosSolverTransp, const double amesosSolverScalar)
First initialization.
Concrete LinearOpWithSolveBase subclass that adapts any Amesos_BaseSolver object. ...
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
ParameterList & setParameters(const ParameterList &source)
Teuchos::RCP< LinearOpWithSolveBase< double > > createOp() const
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
void initializePreconditionedOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, const Teuchos::RCP< const PreconditionerBase< double > > &prec, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
Throws exception if this->throwOnPrecInput()==true and calls this->initializeOp(fwdOpSrc,Op) otherwise.
AmesosLinearOpWithSolveFactory(const Amesos::ESolverType solverType=Amesos::LAPACK, const Amesos::ERefactorizationPolicy refactorizationPolicy=Amesos::REPIVOT_ON_REFACTORIZATION, const bool throwOnPrecInput=true)
Constructor which sets the defaults.
Teuchos::RCP< Epetra_LinearProblem > get_epetraLP() const
Epetra_Operator * GetOperator() const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
std::string description() const
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
EOpTransp get_amesosSolverTransp() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
std::string typeName(const T &t)
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()