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"
57#include "Amesos_Klu.h"
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
72#include "Amesos_Umfpack.h"
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
87#include "Amesos_Taucs.h"
89#ifdef HAVE_AMESOS_PARAKLETE
90#include "Amesos_Paraklete.h"
95const std::string epetraFwdOp_str =
"epetraFwdOp";
127 ,
const bool throwOnPrecInput
129 :epetraFwdOpViewExtractor_(
Teuchos::rcp(new EpetraOperatorViewExtractorStd()))
130 ,solverType_(solverType)
131 ,refactorizationPolicy_(refactorizationPolicy)
132 ,throwOnPrecInput_(throwOnPrecInput)
138 const LinearOpSourceBase<double> &fwdOpSrc
141 using Teuchos::outArg;
142 RCP<const LinearOpBase<double> >
143 fwdOp = fwdOpSrc.getOp();
144 RCP<const Epetra_Operator> epetraFwdOp;
145 EOpTransp epetraFwdOpTransp;
146 EApplyEpetraOpAs epetraFwdOpApplyAs;
147 EAdjointEpetraOp epetraFwdOpAdjointSupport;
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) )
160RCP<LinearOpWithSolveBase<double> >
167 const RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
168 ,LinearOpWithSolveBase<double> *Op
169 ,
const ESupportSolveUse
172 using Teuchos::outArg;
173 THYRA_FUNC_TIME_MONITOR(
"Stratimikos: AmesosLOWSF");
175 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
177 const RCP<const LinearOpBase<double> >
178 fwdOp = fwdOpSrc->getOp();
182 RCP<const Epetra_Operator> epetraFwdOp;
183 EOpTransp epetraFwdOpTransp;
184 EApplyEpetraOpAs epetraFwdOpApplyAs;
185 EAdjointEpetraOp epetraFwdOpAdjointSupport;
186 double epetraFwdOpScalar;
187 epetraFwdOpViewExtractor_->getEpetraOpView(
189 outArg(epetraFwdOp), outArg(epetraFwdOpTransp),
190 outArg(epetraFwdOpApplyAs), outArg(epetraFwdOpAdjointSupport),
191 outArg(epetraFwdOpScalar)
195 *amesosOp = &Teuchos::dyn_cast<AmesosLinearOpWithSolve>(*Op);
204 epetraFwdOp.get() != amesosOp->
get_epetraLP()->GetOperator()
220 RCP<Epetra_LinearProblem>
221 epetraLP = Teuchos::rcp(
new Epetra_LinearProblem());
222 epetraLP->SetOperator(
const_cast<Epetra_Operator*
>(&*epetraFwdOp));
223 Teuchos::set_extra_data< RCP<const Epetra_Operator> >( epetraFwdOp, epetraFwdOp_str,
224 Teuchos::inOutArg(epetraLP) );
226 RCP<Amesos_BaseSolver>
229 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:InitConstruct",
233 amesosSolver = Teuchos::rcp(
new Amesos_Lapack(*epetraLP));
235#ifdef HAVE_AMESOS_KLU
236 case Thyra::Amesos::KLU :
237 amesosSolver = Teuchos::rcp(
new Amesos_Klu(*epetraLP));
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 :
247 amesosSolver = Teuchos::rcp(
new Amesos_Mumps(*epetraLP));
250#ifdef HAVE_AMESOS_SCALAPACK
251 case Thyra::Amesos::SCALAPACK :
252 amesosSolver = Teuchos::rcp(
new Amesos_Scalapack(*epetraLP));
255#ifdef HAVE_AMESOS_UMFPACK
256 case Thyra::Amesos::UMFPACK :
257 amesosSolver = Teuchos::rcp(
new Amesos_Umfpack(*epetraLP));
260#ifdef HAVE_AMESOS_SUPERLUDIST
261 case Thyra::Amesos::SUPERLUDIST :
262 amesosSolver = Teuchos::rcp(
new Amesos_Superludist(*epetraLP));
265#ifdef HAVE_AMESOS_SUPERLU
266 case Thyra::Amesos::SUPERLU :
267 amesosSolver = Teuchos::rcp(
new Amesos_Superlu(*epetraLP));
270#ifdef HAVE_AMESOS_DSCPACK
271 case Thyra::Amesos::DSCPACK :
272 amesosSolver = Teuchos::rcp(
new Amesos_Dscpack(*epetraLP));
275#ifdef HAVE_AMESOS_PARDISO
276 case Thyra::Amesos::PARDISO :
277 amesosSolver = Teuchos::rcp(
new Amesos_Pardiso(*epetraLP));
280#ifdef HAVE_AMESOS_TAUCS
281 case Thyra::Amesos::TAUCS :
282 amesosSolver = Teuchos::rcp(
new Amesos_Taucs(*epetraLP));
285#ifdef HAVE_AMESOS_PARAKLETE
286 case Thyra::Amesos::PARAKLETE :
287 amesosSolver = Teuchos::rcp(
new Amesos_Paraklete(*epetraLP));
291 TEUCHOS_TEST_FOR_EXCEPTION(
292 true, std::logic_error
293 ,
"Error, the solver type ID = " <<
solverType_ <<
" is invalid!"
301 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:Symbolic", Symbolic);
302 const int err = amesosSolver->SymbolicFactorization();
303 TEUCHOS_TEST_FOR_EXCEPTION( 0!=err, CatastrophicSolveFailure,
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();
310 TEUCHOS_TEST_FOR_EXCEPTION( 0!=err, CatastrophicSolveFailure,
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);
324 RCP<Epetra_LinearProblem>
325 epetraLP = Teuchos::rcp_const_cast<Epetra_LinearProblem>(amesosOp->
get_epetraLP());
326 RCP<Amesos_BaseSolver>
329 epetraLP->SetOperator(
const_cast<Epetra_Operator*
>(&*epetraFwdOp));
330 Teuchos::get_nonconst_extra_data<RCP<const Epetra_Operator> >(epetraLP,epetraFwdOp_str) = epetraFwdOp;
335 THYRA_FUNC_TIME_MONITOR_DIFF(
"Stratimikos: AmesosLOWSF:Symbolic", Symbolic);
336 const int err = amesosSolver->SymbolicFactorization();
337 TEUCHOS_TEST_FOR_EXCEPTION( 0!=err, CatastrophicSolveFailure,
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();
344 TEUCHOS_TEST_FOR_EXCEPTION( 0!=err, CatastrophicSolveFailure,
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());
366 const RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
367 ,
const RCP<
const PreconditionerBase<double> > &
368 ,LinearOpWithSolveBase<double> *Op
369 ,
const ESupportSolveUse supportSolveUse
372 TEUCHOS_TEST_FOR_EXCEPTION(
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!"
381 const RCP<
const LinearOpSourceBase<double> > &fwdOpSrc
382 ,
const RCP<
const LinearOpSourceBase<double> > &
383 ,LinearOpWithSolveBase<double> *Op
384 ,
const ESupportSolveUse supportSolveUse
387 TEUCHOS_TEST_FOR_EXCEPTION(
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!"
396 LinearOpWithSolveBase<double> *Op
397 ,RCP<
const LinearOpSourceBase<double> > *fwdOpSrc
398 ,RCP<
const PreconditionerBase<double> > *prec
399 ,RCP<
const LinearOpSourceBase<double> > *approxFwdOpSrc
404 TEUCHOS_TEST_FOR_EXCEPT(Op==NULL);
407 *amesosOp = &Teuchos::dyn_cast<AmesosLinearOpWithSolve>(*Op);
408 RCP<const LinearOpSourceBase<double> >
410 if(_fwdOpSrc.get()) {
412 RCP<Epetra_LinearProblem> epetraLP = amesosOp->
get_epetraLP();
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;
430 RCP<Teuchos::ParameterList>
const& paramList
433 TEUCHOS_TEST_FOR_EXCEPT(paramList.get()==NULL);
453 Teuchos::readVerboseObjectSublist(&*
paramList_,
this);
456RCP<Teuchos::ParameterList>
462RCP<Teuchos::ParameterList>
465 RCP<Teuchos::ParameterList> _paramList =
paramList_;
470RCP<const Teuchos::ParameterList>
476RCP<const Teuchos::ParameterList>
486 std::ostringstream oss;
487 oss <<
"Thyra::AmesosLinearOpWithSolveFactory{";
495RCP<const Teuchos::ParameterList>
498 static RCP<Teuchos::ParameterList> validParamList;
499 if(validParamList.get()==NULL) {
500 validParamList = Teuchos::rcp(
new Teuchos::ParameterList(
"Amesos"));
503#ifdef HAVE_AMESOS_KLU
512 Teuchos::setupVerboseObjectSublist(&*validParamList);
514 return validParamList;
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
static const std::string SolverType_name
~AmesosLinearOpWithSolveFactory()
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,...
Amesos::ESolverType solverType_
std::string description() const
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< const Teuchos::ParameterList > getParameterList() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
Returns false .
Teuchos::RCP< LinearOpWithSolveBase< double > > createOp() const
static const std::string RefactorizationPolicy_name
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
void initializeOp(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOpSrc, LinearOpWithSolveBase< double > *Op, const ESupportSolveUse supportSolveUse) const
static const std::string ThrowOnPreconditionerInput_name
Amesos::ERefactorizationPolicy refactorizationPolicy_
Teuchos::RCP< Teuchos::ParameterList > paramList_
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
bool isCompatible(const LinearOpSourceBase< double > &fwdOpSrc) const
Returns true if dynamic_cast<const EpetraLinearOpBase*>(fwdOpSrc)!=NULL .
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
static const std::string Amesos_Settings_name
static Teuchos::RCP< const Teuchos::ParameterList > generateAndGetValidParameters()
Concrete LinearOpWithSolveBase subclass that adapts any Amesos_BaseSolver object.
Teuchos::RCP< Amesos_BaseSolver > get_amesosSolver() const
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.
EOpTransp get_amesosSolverTransp() const
Teuchos::RCP< const LinearOpSourceBase< double > > extract_fwdOpSrc()
Extract the LinearOpSourceBase<double> object so that it can be modified.
Teuchos::RCP< Epetra_LinearProblem > get_epetraLP() const
Teuchos::StringToIntMap refactorizationPolicyNameToEnumMap
Teuchos::StringToIntMap solverTypeNameToEnumMap
ERefactorizationPolicy
The policy used on refactoring a matrix.
const char * toString(const ESolverType solverType)
@ REPIVOT_ON_REFACTORIZATION
Completely new pivoting will be used on refactorizations!