46 #include "Thyra_DefaultPreconditioner.hpp" 47 #include "ml_MultiLevelPreconditioner.h" 48 #include "ml_MultiLevelOperator.h" 49 #include "ml_ValidateParameters.h" 50 #include "Epetra_RowMatrix.h" 65 ML_PROBTYPE_SMOOTHED_AGGREGATION,
66 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
67 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
68 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
71 const std::string BaseMethodDefaults_valueNames_none =
"none";
73 = Teuchos::tuple<std::string>(
74 BaseMethodDefaults_valueNames_none,
91 const std::string BaseMethodDefaults_name =
"Base Method Defaults";
92 const std::string BaseMethodDefaults_default =
"SA";
96 BaseMethodDefaults_validator;
98 const std::string ReuseFineLevelSmoother_name =
"Reuse Fine Level Smoother";
99 const bool ReuseFineLevelSmoother_default =
false;
101 const std::string MLSettings_name =
"ML Settings";
126 const LinearOpSourceBase<double> &fwdOpSrc
129 using Teuchos::outArg;
131 EOpTransp epetraFwdOpTransp;
134 double epetraFwdOpScalar;
136 fwdOp = fwdOpSrc.getOp();
137 epetraFwdOpViewExtractor_->getEpetraOpView(
139 outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
140 outArg(epetraFwdOpApplyAs),
141 outArg(epetraFwdOpAdjointSupport),
142 outArg(epetraFwdOpScalar)
144 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
165 return Teuchos::rcp(
new DefaultPreconditioner<double>());
170 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
171 PreconditionerBase<double> *prec,
172 const ESupportSolveUse supportSolveUse
175 using Teuchos::outArg;
181 using Teuchos::rcp_dynamic_cast;
182 using Teuchos::rcp_const_cast;
183 using Teuchos::set_extra_data;
184 using Teuchos::get_optional_extra_data;
187 totalTimer.start(
true);
192 *out <<
"\nEntering Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
203 EOpTransp epetraFwdOpTransp;
206 double epetraFwdOpScalar;
207 epetraFwdOpViewExtractor_->getEpetraOpView(
208 fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
209 outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
213 epetraFwdRowMat = rcp_dynamic_cast<
const Epetra_RowMatrix>(epetraFwdOp,
true);
216 ,
"Error, incorrect apply mode for an Epetra_RowMatrix" 222 DefaultPreconditioner<double>
228 epetra_precOp = rcp_dynamic_cast<
EpetraLinearOp>(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
233 if(epetra_precOp.
get())
234 ml_precOp = rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(epetra_precOp->epetra_op(),
true);
238 if(ml_precOp!=Teuchos::null) {
241 const Epetra_RowMatrix & rm = ml_precOp->RowMatrix();
244 &rm!=&*epetraFwdRowMat, std::logic_error
245 ,
"ML requires Epetra_RowMatrix to be the same for each initialization of the preconditioner" 251 const bool startingOver = (ml_precOp.get() == NULL);
255 *out <<
"\nCreating the initial ML_Epetra::MultiLevelPreconditioner object...\n";
259 new ML_Epetra::MultiLevelPreconditioner(
284 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(ml_precOp),
290 *out <<
"\nComputing the preconditioner ...\n";
310 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(ml_precOp),
318 epetra_precOp->initialize(
327 defaultPrec->initializeUnspecified(
328 Teuchos::rcp_implicit_cast<LinearOpBase<double> >(epetra_precOp)
332 *out <<
"\nTotal time in MLPreconditionerFactory = "<<totalTimer.totalElapsedTime()<<
" sec\n";
334 *out <<
"\nLeaving Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
339 PreconditionerBase<double> *prec,
341 ESupportSolveUse *supportSolveUse
361 paramList_->
set<
bool>(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default);
365 *
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default
367 if( ML_PROBTYPE_NONE != defaultType ) {
369 defaultTypeStr = BaseMethodDefaults_valueNames[defaultType];
372 0!=ML_Epetra::SetDefaults(defaultTypeStr,defaultParams)
374 ,
"Error, the ML problem type \"" << defaultTypeStr <<
"\' is not recognized by ML!" 423 using Teuchos::tuple;
425 using Teuchos::rcp_implicit_cast;
435 BaseMethodDefaults_validator =
rcp(
437 BaseMethodDefaults_valueNames,
439 "Do not set any default parameters",
440 "Set default parameters for a smoothed aggregation method",
441 "Set default parameters for a nonsymmetric smoothed aggregation method",
442 "Set default parameters for a domain decomposition method",
443 "Set default parameters for a domain decomposition method special to ML",
444 "Set default parameters for a Maxwell-type of linear operator" 446 tuple<EMLProblemType>(
448 ML_PROBTYPE_SMOOTHED_AGGREGATION,
449 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
450 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
451 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
454 BaseMethodDefaults_name
458 pl->set(BaseMethodDefaults_name,BaseMethodDefaults_default,
459 "Select the default method type which also sets parameter defaults\n" 460 "in the sublist \"" + MLSettings_name +
"\"!",
461 rcp_implicit_cast<const PEV>(BaseMethodDefaults_validator)
464 pl->set(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default,
465 "Enables/disables the reuse of the fine level smoother.");
480 MLSettings_name,
false,
481 "Sampling of the parameters directly accepted by ML\n" 482 "This list of parameters is generated by combining all of\n" 483 "the parameters set for all of the default problem types supported\n" 484 "by ML. Therefore, do not assume these parameters are at values that\n" 485 "are reasonable to ML. This list is just to give a sense of some of\n" 486 "the parameters that ML accepts. Consult ML documentation on how to\n" 487 "set these parameters. Also, you can print the parameter list after\n" 488 "it is used and see what defaults where set for each default problem\n" 489 "type. Warning! the parameters in this sublist are currently *not*\n" 490 "being validated by ML!" 496 i < implicit_cast<int>(BaseMethodDefaults_valueNames.size());
501 const std::string defaultTypeStr = BaseMethodDefaults_valueNames[i];
502 if (defaultTypeStr != BaseMethodDefaults_valueNames_none) {
504 0!=ML_Epetra::SetDefaults(defaultTypeStr,defaultParams)
506 ,
"Error, the ML problem type \"" << defaultTypeStr
507 <<
"\' is not recognized by ML!" 529 std::ostringstream oss;
530 oss <<
"Thyra::MLPreconditionerFactory";
bool isCompatible(const LinearOpSourceBase< double > &fwdOp) const
std::string description() const
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< Teuchos::ParameterList > paramList_
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() const
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)
bool applyTransposeSupportsConj(EConj conj) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void uninitializePrec(PreconditionerBase< double > *prec, Teuchos::RCP< const LinearOpSourceBase< double > > *fwdOp, ESupportSolveUse *supportSolveUse) const
MLPreconditionerFactory()
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEUCHOS_ENUM_INPUT_STREAM_OPERATOR(ENUMTYPE)
bool applySupportsConj(EConj conj) const
basic_OSTab< char > OSTab
EPETRA_OP_APPLY_APPLY_INVERSE
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
IntegralType getIntegralValue(ParameterList const ¶mList, std::string const ¶mName)
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
void start(bool reset=false)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
T_To & dyn_cast(T_From &from)
bool isType(const std::string &name) const
TypeTo implicit_cast(const TypeFrom &t)
double totalElapsedTime(bool readCurrentTime=false) const
ParameterList & setParameters(const ParameterList &source)
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
EPETRA_OP_ADJOINT_UNSUPPORTED
Teuchos::RCP< PreconditionerBase< double > > createPrec() const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOp, PreconditionerBase< double > *prec, const ESupportSolveUse supportSolveUse) const