46 #include "Thyra_DefaultPreconditioner.hpp"
47 #include "ml_MultiLevelPreconditioner.h"
48 #include "ml_MultiLevelOperator.h"
49 #include "ml_ValidateParameters.h"
50 #include "ml_RefMaxwell.h"
51 #include "ml_GradDiv.h"
52 #include "Epetra_RowMatrix.h"
67 ML_PROBTYPE_SMOOTHED_AGGREGATION,
68 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
69 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
70 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
72 ML_PROBTYPE_REFMAXWELL,
75 const std::string BaseMethodDefaults_valueNames_none =
"none";
77 = Teuchos::tuple<std::string>(
78 BaseMethodDefaults_valueNames_none,
92 TEUCHOS_STATIC_SETUP()
97 const std::string BaseMethodDefaults_name =
"Base Method Defaults";
98 const std::string BaseMethodDefaults_default =
"SA";
102 BaseMethodDefaults_validator;
104 const std::string ReuseFineLevelSmoother_name =
"Reuse Fine Level Smoother";
105 const bool ReuseFineLevelSmoother_default =
false;
107 const std::string MLSettings_name =
"ML Settings";
132 const LinearOpSourceBase<double> &fwdOpSrc
135 using Teuchos::outArg;
137 EOpTransp epetraFwdOpTransp;
140 double epetraFwdOpScalar;
142 fwdOp = fwdOpSrc.getOp();
143 epetraFwdOpViewExtractor_->getEpetraOpView(
145 outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
146 outArg(epetraFwdOpApplyAs),
147 outArg(epetraFwdOpAdjointSupport),
148 outArg(epetraFwdOpScalar)
150 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
171 return Teuchos::rcp(
new DefaultPreconditioner<double>());
176 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
177 PreconditionerBase<double> *prec,
178 const ESupportSolveUse
181 using Teuchos::outArg;
187 using Teuchos::rcp_dynamic_cast;
188 using Teuchos::rcp_const_cast;
189 using Teuchos::set_extra_data;
190 using Teuchos::get_optional_extra_data;
193 totalTimer.start(
true);
198 *out <<
"\nEntering Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
201 const EMLProblemType problemType = BaseMethodDefaults_validator->getIntegralValue(*
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default);
212 EOpTransp epetraFwdOpTransp;
215 double epetraFwdOpScalar;
216 epetraFwdOpViewExtractor_->getEpetraOpView(
217 fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
218 outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
222 epetraFwdRowMat = rcp_dynamic_cast<
const Epetra_RowMatrix>(epetraFwdOp,
true);
225 ,
"Error, incorrect apply mode for an Epetra_RowMatrix"
232 DefaultPreconditioner<double>
238 epetra_precOp = rcp_dynamic_cast<
EpetraLinearOp>(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
245 if(epetra_precOp.
get()) {
246 if(problemType == ML_PROBTYPE_REFMAXWELL)
247 rm_precOp = rcp_dynamic_cast<ML_Epetra::RefMaxwellPreconditioner>(epetra_precOp->epetra_op(),
true);
248 else if(problemType == ML_PROBTYPE_GRADDIV)
249 gd_precOp = rcp_dynamic_cast<ML_Epetra::GradDivPreconditioner>(epetra_precOp->epetra_op(),
true);
251 ml_precOp = rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(epetra_precOp->epetra_op(),
true);
259 const Epetra_RowMatrix & rm = ml_precOp->RowMatrix();
261 TEUCHOS_TEST_FOR_EXCEPTION(
262 &rm!=&*epetraFwdRowMat, std::logic_error
263 ,
"ML requires Epetra_RowMatrix to be the same for each initialization of the preconditioner"
271 const bool startingOver = (ml_precOp.get() == NULL && rm_precOp.
get() == NULL);
275 *out <<
"\nCreating the initial ML_Epetra::MultiLevelPreconditioner object...\n";
279 if(problemType==ML_PROBTYPE_REFMAXWELL)
280 rm_precOp =
rcp(
new ML_Epetra::RefMaxwellPreconditioner(*epetraFwdCrsMat,
paramList_->
sublist(MLSettings_name),
false));
281 else if(problemType==ML_PROBTYPE_GRADDIV)
282 gd_precOp =
rcp(
new ML_Epetra::GradDivPreconditioner(*epetraFwdCrsMat,
paramList_->
sublist(MLSettings_name),
false));
284 ml_precOp =
rcp(
new ML_Epetra::MultiLevelPreconditioner(*epetraFwdRowMat,
paramList_->
sublist(MLSettings_name),
false));
298 if (problemType==ML_PROBTYPE_REFMAXWELL) {
299 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
301 else if (problemType==ML_PROBTYPE_GRADDIV) {
302 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
305 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
312 if (problemType==ML_PROBTYPE_REFMAXWELL)
313 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(rm_precOp),
315 else if (problemType==ML_PROBTYPE_GRADDIV)
316 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(gd_precOp),
319 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(ml_precOp),
325 *out <<
"\nComputing the preconditioner ...\n";
327 if (problemType==ML_PROBTYPE_REFMAXWELL) {
329 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ComputePreconditioner());
332 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ReComputePreconditioner());
335 else if (problemType==ML_PROBTYPE_GRADDIV) {
337 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->ComputePreconditioner());
340 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->ReComputePreconditioner());
345 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ComputePreconditioner());
348 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ReComputePreconditioner(
paramList_->
get<
bool>(ReuseFineLevelSmoother_name)));
363 if (problemType==ML_PROBTYPE_REFMAXWELL)
364 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(rm_precOp),
366 else if (problemType==ML_PROBTYPE_GRADDIV)
367 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(gd_precOp),
370 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(ml_precOp),
379 if (problemType==ML_PROBTYPE_REFMAXWELL)
381 else if (problemType==ML_PROBTYPE_GRADDIV)
388 defaultPrec->initializeUnspecified(
389 Teuchos::rcp_implicit_cast<LinearOpBase<double> >(epetra_precOp)
393 *out <<
"\nTotal time in MLPreconditionerFactory = "<<totalTimer.totalElapsedTime()<<
" sec\n";
395 *out <<
"\nLeaving Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
400 PreconditionerBase<double> * ,
424 paramList_->
set<
bool>(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default);
428 *
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default
430 if( ML_PROBTYPE_NONE != defaultType ) {
431 const std::string defaultTypeStr = BaseMethodDefaults_valueNames[defaultType];
435 if(defaultType == ML_PROBTYPE_REFMAXWELL) {
436 ML_Epetra::SetDefaultsRefMaxwell(defaultParams);
438 else if(defaultType == ML_PROBTYPE_GRADDIV) {
439 ML_Epetra::SetDefaultsGradDiv(defaultParams);
444 ,
"Error, the ML problem type \"" << defaultTypeStr <<
"\' is not recognized by ML!"
496 using Teuchos::tuple;
498 using Teuchos::rcp_implicit_cast;
508 BaseMethodDefaults_validator =
rcp(
510 BaseMethodDefaults_valueNames,
512 "Do not set any default parameters",
513 "Set default parameters for a smoothed aggregation method",
514 "Set default parameters for a nonsymmetric smoothed aggregation method",
515 "Set default parameters for a domain decomposition method",
516 "Set default parameters for a domain decomposition method special to ML",
517 "Set default parameters for a Maxwell-type of preconditioner",
518 "Set default parameters for a RefMaxwell-type preconditioner",
519 "Set default parameters for a Grad-Div-type preconditioner"
521 tuple<EMLProblemType>(
523 ML_PROBTYPE_SMOOTHED_AGGREGATION,
524 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
525 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
526 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
528 ML_PROBTYPE_REFMAXWELL,
531 BaseMethodDefaults_name
535 pl->set(BaseMethodDefaults_name,BaseMethodDefaults_default,
536 "Select the default method type which also sets parameter defaults\n"
537 "in the sublist \"" + MLSettings_name +
"\"!",
538 rcp_implicit_cast<const PEV>(BaseMethodDefaults_validator)
541 pl->set(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default,
542 "Enables/disables the reuse of the fine level smoother.");
545 pl->set(MLSettings_name,mlpl,
546 "Sampling of the parameters directly accepted by ML\n"
547 "This list of parameters is generated by combining all of\n"
548 "the parameters set for all of the default problem types supported\n"
549 "by ML. Therefore, do not assume these parameters are at values that\n"
550 "are reasonable to ML. This list is just to give a sense of some of\n"
551 "the parameters that ML accepts. Consult ML documentation on how to\n"
552 "set these parameters. Also, you can print the parameter list after\n"
553 "it is used and see what defaults where set for each default problem\n"
554 "type. Warning! the parameters in this sublist are currently *not*\n"
555 "being validated by ML!"
572 std::ostringstream oss;
573 oss <<
"Thyra::MLPreconditionerFactory";
std::string description() const
bool is_null(const boost::shared_ptr< T > &p)
Teuchos::RCP< Teuchos::ParameterList > paramList_
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)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Teuchos::ParameterList > getParameterList() 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)
basic_OSTab< char > OSTab
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool applyTransposeSupportsConj(EConj conj) const
T_To & dyn_cast(T_From &from)
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOp, PreconditionerBase< double > *prec, const ESupportSolveUse supportSolveUse) const
TypeTo implicit_cast(const TypeFrom &t)
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
void uninitializePrec(PreconditionerBase< double > *prec, Teuchos::RCP< const LinearOpSourceBase< double > > *fwdOp, ESupportSolveUse *supportSolveUse) const
Teuchos::RCP< PreconditionerBase< double > > createPrec() const
bool isType(const std::string &name) const
double totalElapsedTime(bool readCurrentTime=false) const
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
bool applySupportsConj(EConj conj) const
bool isCompatible(const LinearOpSourceBase< double > &fwdOp) const