33 #include "Thyra_AmesosLinearOpWithSolveFactory.hpp"
35 #include "Thyra_AmesosLinearOpWithSolve.hpp"
36 #include "Thyra_EpetraOperatorViewExtractorStd.hpp"
41 #ifdef HAVE_AMESOS_KLU
44 #ifdef HAVE_AMESOS_LAPACK
47 #ifdef HAVE_AMESOS_MUMPS
50 #ifdef HAVE_AMESOS_SCALAPACK
53 #ifdef HAVE_AMESOS_UMFPACK
56 #ifdef HAVE_AMESOS_SUPERLUDIST
59 #ifdef HAVE_AMESOS_SUPERLU
62 #ifdef HAVE_AMESOS_DSCPACK
65 #if defined(HAVE_AMESOS_PARDISO) || defined(HAVE_AMESOS_PARDISO_MKL)
68 #ifdef HAVE_AMESOS_TAUCS
71 #ifdef HAVE_AMESOS_PARAKLETE
79 const std::string epetraFwdOp_str =
"epetraFwdOp";
88 const std::string AmesosLinearOpWithSolveFactory::SolverType_name =
"Solver Type";
90 const std::string AmesosLinearOpWithSolveFactory::RefactorizationPolicy_name =
"Refactorization Policy";
92 const std::string AmesosLinearOpWithSolveFactory::ThrowOnPreconditionerInput_name =
"Throw on Preconditioner Input";
94 const std::string AmesosLinearOpWithSolveFactory::Amesos_Settings_name =
"Amesos Settings";
98 AmesosLinearOpWithSolveFactory::~AmesosLinearOpWithSolveFactory()
102 paramList_->validateParameters(
103 *this->getValidParameters(),0
108 AmesosLinearOpWithSolveFactory::AmesosLinearOpWithSolveFactory(
109 const Amesos::ESolverType solverType
110 ,
const Amesos::ERefactorizationPolicy refactorizationPolicy
111 ,
const bool throwOnPrecInput
113 :epetraFwdOpViewExtractor_(
Teuchos::rcp(
new EpetraOperatorViewExtractorStd()))
114 ,solverType_(solverType)
115 ,refactorizationPolicy_(refactorizationPolicy)
116 ,throwOnPrecInput_(throwOnPrecInput)
123 bool AmesosLinearOpWithSolveFactory::isCompatible(
124 const LinearOpSourceBase<double> &fwdOpSrc
128 fwdOp = fwdOpSrc.getOp();
131 EApplyEpetraOpAs epetraFwdOpApplyAs;
132 EAdjointEpetraOp epetraFwdOpAdjointSupport;
133 double epetraFwdOpScalar;
134 epetraFwdOpViewExtractor_->getEpetraOpView(
136 ,&epetraFwdOp,&epetraFwdOpTransp,&epetraFwdOpApplyAs,&epetraFwdOpAdjointSupport,&epetraFwdOpScalar
138 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
144 AmesosLinearOpWithSolveFactory::createOp()
const
149 void AmesosLinearOpWithSolveFactory::initializeOp(
150 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
151 ,LinearOpWithSolveBase<double> *Op
152 ,
const ESupportSolveUse supportSolveUse
160 fwdOp = fwdOpSrc->getOp();
166 EApplyEpetraOpAs epetraFwdOpApplyAs;
167 EAdjointEpetraOp epetraFwdOpAdjointSupport;
168 double epetraFwdOpScalar;
169 epetraFwdOpViewExtractor_->getEpetraOpView(
170 fwdOp,&epetraFwdOp,&epetraFwdOpTransp,&epetraFwdOpApplyAs,&epetraFwdOpAdjointSupport,&epetraFwdOpScalar
173 AmesosLinearOpWithSolve
178 bool startOver = ( amesosOp->get_amesosSolver()==
Teuchos::null );
182 epetraFwdOpTransp != amesosOp->get_amesosSolverTransp() ||
183 epetraFwdOp.
get() != amesosOp->get_epetraLP()->GetOperator()
201 epetraLP->
SetOperator(const_cast<Epetra_Operator*>(&*epetraFwdOp));
202 Teuchos::set_extra_data< Teuchos::RCP<const Epetra_Operator> >( epetraFwdOp,
203 epetraFwdOp_str, Teuchos::inOutArg(epetraLP) );
209 switch(solverType_) {
213 #ifdef HAVE_AMESOS_KLU
218 #ifdef HAVE_AMESOS_MUMPS
223 #ifdef HAVE_AMESOS_SCALAPACK
228 #ifdef HAVE_AMESOS_UMFPACK
233 #ifdef HAVE_AMESOS_SUPERLUDIST
238 #ifdef HAVE_AMESOS_SUPERLU
243 #ifdef HAVE_AMESOS_DSCPACK
248 #ifdef HAVE_AMESOS_PARDISO
253 #ifdef HAVE_AMESOS_TAUCS
258 #ifdef HAVE_AMESOS_PARAKLETE
265 true, std::logic_error
266 ,
"Error, the solver type ID = " << solverType_ <<
" is invalid!"
271 if(paramList_.get()) amesosSolver->setParameterList(sublist(paramList_,
"Amesos Settings"));
275 amesosSolver->SymbolicFactorization();
279 amesosSolver->NumericFactorization();
282 amesosOp->initialize(fwdOp,fwdOpSrc,epetraLP,amesosSolver,epetraFwdOpTransp,epetraFwdOpScalar);
294 amesosSolver = amesosOp->get_amesosSolver();
296 epetraLP->
SetOperator(const_cast<Epetra_Operator*>(&*epetraFwdOp));
297 Teuchos::get_extra_data< Teuchos::RCP<const Epetra_Operator> >(epetraLP,epetraFwdOp_str) = epetraFwdOp;
299 if(paramList_.get()) amesosSolver->setParameterList(sublist(paramList_,Amesos_Settings_name));
301 if(refactorizationPolicy_==Amesos::REPIVOT_ON_REFACTORIZATION) {
303 amesosSolver->SymbolicFactorization();
307 amesosSolver->NumericFactorization();
311 amesosOp->initialize(fwdOp,fwdOpSrc,epetraLP,amesosSolver,epetraFwdOpTransp,epetraFwdOpScalar);
313 amesosOp->setOStream(this->getOStream());
314 amesosOp->setVerbLevel(this->getVerbLevel());
317 bool AmesosLinearOpWithSolveFactory::supportsPreconditionerInputType(
const EPreconditionerInputType precOpType)
const
322 void AmesosLinearOpWithSolveFactory::initializePreconditionedOp(
323 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
324 ,
const Teuchos::RCP<
const PreconditionerBase<double> > &prec
325 ,LinearOpWithSolveBase<double> *Op
326 ,
const ESupportSolveUse supportSolveUse
330 this->throwOnPrecInput_, std::logic_error
331 ,
"Error, the concrete implementation described as \'"<<this->description()<<
"\' does not support preconditioners "
332 "and has been configured to throw this exception when the initializePreconditionedOp(...) function is called!"
334 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
337 void AmesosLinearOpWithSolveFactory::initializePreconditionedOp(
338 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
339 ,
const Teuchos::RCP<
const LinearOpSourceBase<double> > &approxFwdOpSrc
340 ,LinearOpWithSolveBase<double> *Op
341 ,
const ESupportSolveUse supportSolveUse
345 this->throwOnPrecInput_, std::logic_error
346 ,
"Error, the concrete implementation described as \'"<<this->description()<<
"\' does not support preconditioners "
347 "and has been configured to throw this exception when the initializePreconditionedOp(...) function is called!"
349 this->initializeOp(fwdOpSrc,Op,supportSolveUse);
352 void AmesosLinearOpWithSolveFactory::uninitializeOp(
353 LinearOpWithSolveBase<double> *Op
354 ,
Teuchos::RCP<
const LinearOpSourceBase<double> > *fwdOpSrc
356 ,
Teuchos::RCP<
const LinearOpSourceBase<double> > *approxFwdOpSrc
357 ,ESupportSolveUse *supportSolveUse
363 AmesosLinearOpWithSolve
366 _fwdOpSrc = amesosOp->extract_fwdOpSrc();
367 if(_fwdOpSrc.
get()) {
370 Teuchos::get_extra_data< Teuchos::RCP<const Epetra_Operator> >(
371 epetraLP,epetraFwdOp_str
379 if(fwdOpSrc) *fwdOpSrc = _fwdOpSrc;
386 void AmesosLinearOpWithSolveFactory::setParameterList(
392 paramList_ = paramList;
394 Amesos::solverTypeNameToEnumMap.
get<Amesos::ESolverType>(
397 ,Amesos::toString(solverType_)
399 ,paramList_->name()+
"->"+SolverType_name
401 refactorizationPolicy_ =
402 Amesos::refactorizationPolicyNameToEnumMap.
get<Amesos::ERefactorizationPolicy>(
404 RefactorizationPolicy_name
405 ,Amesos::toString(refactorizationPolicy_)
407 ,paramList_->name()+
"->"+RefactorizationPolicy_name
409 throwOnPrecInput_ = paramList_->get(ThrowOnPreconditionerInput_name,throwOnPrecInput_);
413 AmesosLinearOpWithSolveFactory::getNonconstParameterList()
419 AmesosLinearOpWithSolveFactory::unsetParameterList()
427 AmesosLinearOpWithSolveFactory::getParameterList()
const
433 AmesosLinearOpWithSolveFactory::getValidParameters()
const
435 return generateAndGetValidParameters();
440 std::string AmesosLinearOpWithSolveFactory::description()
const
442 std::ostringstream oss;
443 oss <<
"Thyra::AmesosLinearOpWithSolveFactory{";
444 oss <<
"solverType=" <<
toString(solverType_);
452 void AmesosLinearOpWithSolveFactory::initializeTimers()
454 if(!overallTimer.get()) {
463 AmesosLinearOpWithSolveFactory::generateAndGetValidParameters()
466 if(validParamList.
get()==NULL) {
470 #ifdef HAVE_AMESOS_KLU
476 validParamList->
set(RefactorizationPolicy_name,Amesos::toString(Amesos::REPIVOT_ON_REFACTORIZATION));
477 validParamList->
set(ThrowOnPreconditionerInput_name,
bool(
true));
480 return validParamList;
Amesos_Klu: A serial, unblocked code ideal for getting started and for very sparse matrices...
void SetOperator(Epetra_RowMatrix *A)
Amesos_Paraklete: A serial, unblocked code ideal for getting started and for very sparse matrices...
Amesos_Superludist: An object-oriented wrapper for Superludist.
Amesos_Mumps: An object-oriented wrapper for the double precision version of MUMPS.
T & get(ParameterList &l, const std::string &name)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Amesos_Dscpack: An object-oriented wrapper for Dscpack.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static Teuchos::ParameterList GetValidParameters()
Get the list of valid parameters.
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
const char * toString(const EReductionType reductType)
Amesos_Pardiso: Interface to the PARDISO package.
Amesos_Superlu: Amesos interface to Xioye Li's SuperLU 3.0 serial code.
static RCP< Time > getNewTimer(const std::string &name)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
T_To & dyn_cast(T_From &from)
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Amesos_Lapack: an interface to LAPACK.
Class Amesos_Umfpack: An object-oriented wrapper for UMFPACK.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Amesos_Scalapack: A serial and parallel dense solver. For now, we implement only the unsymmetric ScaL...
Amesos_Taucs: An interface to the TAUCS package.