14 #include "Thyra_DefaultPreconditioner.hpp"
15 #include "ml_MultiLevelPreconditioner.h"
16 #include "ml_MultiLevelOperator.h"
17 #include "ml_ValidateParameters.h"
18 #include "ml_RefMaxwell.h"
19 #include "ml_GradDiv.h"
20 #include "Epetra_RowMatrix.h"
35 ML_PROBTYPE_SMOOTHED_AGGREGATION,
36 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
37 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
38 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
40 ML_PROBTYPE_REFMAXWELL,
43 const std::string BaseMethodDefaults_valueNames_none =
"none";
45 = Teuchos::tuple<std::string>(
46 BaseMethodDefaults_valueNames_none,
60 TEUCHOS_STATIC_SETUP()
65 const std::string BaseMethodDefaults_name =
"Base Method Defaults";
66 const std::string BaseMethodDefaults_default =
"SA";
70 BaseMethodDefaults_validator;
72 const std::string ReuseFineLevelSmoother_name =
"Reuse Fine Level Smoother";
73 const bool ReuseFineLevelSmoother_default =
false;
75 const std::string MLSettings_name =
"ML Settings";
100 const LinearOpSourceBase<double> &fwdOpSrc
103 using Teuchos::outArg;
105 EOpTransp epetraFwdOpTransp;
108 double epetraFwdOpScalar;
110 fwdOp = fwdOpSrc.getOp();
111 epetraFwdOpViewExtractor_->getEpetraOpView(
113 outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
114 outArg(epetraFwdOpApplyAs),
115 outArg(epetraFwdOpAdjointSupport),
116 outArg(epetraFwdOpScalar)
118 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
139 return Teuchos::rcp(
new DefaultPreconditioner<double>());
144 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
145 PreconditionerBase<double> *prec,
146 const ESupportSolveUse
149 using Teuchos::outArg;
155 using Teuchos::rcp_dynamic_cast;
156 using Teuchos::rcp_const_cast;
157 using Teuchos::set_extra_data;
158 using Teuchos::get_optional_extra_data;
161 totalTimer.start(
true);
166 *out <<
"\nEntering Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
169 const EMLProblemType problemType = BaseMethodDefaults_validator->getIntegralValue(*
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default);
180 EOpTransp epetraFwdOpTransp;
183 double epetraFwdOpScalar;
184 epetraFwdOpViewExtractor_->getEpetraOpView(
185 fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
186 outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
190 epetraFwdRowMat = rcp_dynamic_cast<
const Epetra_RowMatrix>(epetraFwdOp,
true);
193 ,
"Error, incorrect apply mode for an Epetra_RowMatrix"
200 DefaultPreconditioner<double>
206 epetra_precOp = rcp_dynamic_cast<
EpetraLinearOp>(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
213 if(epetra_precOp.
get()) {
214 if(problemType == ML_PROBTYPE_REFMAXWELL)
215 rm_precOp = rcp_dynamic_cast<ML_Epetra::RefMaxwellPreconditioner>(epetra_precOp->epetra_op(),
true);
216 else if(problemType == ML_PROBTYPE_GRADDIV)
217 gd_precOp = rcp_dynamic_cast<ML_Epetra::GradDivPreconditioner>(epetra_precOp->epetra_op(),
true);
219 ml_precOp = rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(epetra_precOp->epetra_op(),
true);
227 const Epetra_RowMatrix & rm = ml_precOp->RowMatrix();
229 TEUCHOS_TEST_FOR_EXCEPTION(
230 &rm!=&*epetraFwdRowMat, std::logic_error
231 ,
"ML requires Epetra_RowMatrix to be the same for each initialization of the preconditioner"
239 const bool startingOver = (ml_precOp.get() == NULL && rm_precOp.
get() == NULL);
243 *out <<
"\nCreating the initial ML_Epetra::MultiLevelPreconditioner object...\n";
247 if(problemType==ML_PROBTYPE_REFMAXWELL)
248 rm_precOp =
rcp(
new ML_Epetra::RefMaxwellPreconditioner(*epetraFwdCrsMat,
paramList_->
sublist(MLSettings_name),
false));
249 else if(problemType==ML_PROBTYPE_GRADDIV)
250 gd_precOp =
rcp(
new ML_Epetra::GradDivPreconditioner(*epetraFwdCrsMat,
paramList_->
sublist(MLSettings_name),
false));
252 ml_precOp =
rcp(
new ML_Epetra::MultiLevelPreconditioner(*epetraFwdRowMat,
paramList_->
sublist(MLSettings_name),
false));
266 if (problemType==ML_PROBTYPE_REFMAXWELL) {
267 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
269 else if (problemType==ML_PROBTYPE_GRADDIV) {
270 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
273 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->SetParameterList(
paramList_->
sublist(MLSettings_name)));
280 if (problemType==ML_PROBTYPE_REFMAXWELL)
281 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(rm_precOp),
283 else if (problemType==ML_PROBTYPE_GRADDIV)
284 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(gd_precOp),
287 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(ml_precOp),
293 *out <<
"\nComputing the preconditioner ...\n";
295 if (problemType==ML_PROBTYPE_REFMAXWELL) {
297 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ComputePreconditioner());
300 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ReComputePreconditioner());
303 else if (problemType==ML_PROBTYPE_GRADDIV) {
305 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->ComputePreconditioner());
308 TEUCHOS_TEST_FOR_EXCEPT(0!=gd_precOp->ReComputePreconditioner());
313 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ComputePreconditioner());
316 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ReComputePreconditioner(
paramList_->
get<
bool>(ReuseFineLevelSmoother_name)));
331 if (problemType==ML_PROBTYPE_REFMAXWELL)
332 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(rm_precOp),
334 else if (problemType==ML_PROBTYPE_GRADDIV)
335 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(gd_precOp),
338 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(ml_precOp),
347 if (problemType==ML_PROBTYPE_REFMAXWELL)
349 else if (problemType==ML_PROBTYPE_GRADDIV)
356 defaultPrec->initializeUnspecified(
357 Teuchos::rcp_implicit_cast<LinearOpBase<double> >(epetra_precOp)
361 *out <<
"\nTotal time in MLPreconditionerFactory = "<<totalTimer.totalElapsedTime()<<
" sec\n";
363 *out <<
"\nLeaving Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
368 PreconditionerBase<double> * ,
392 paramList_->
set<
bool>(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default);
396 *
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default
398 if( ML_PROBTYPE_NONE != defaultType ) {
399 const std::string defaultTypeStr = BaseMethodDefaults_valueNames[defaultType];
403 if(defaultType == ML_PROBTYPE_REFMAXWELL) {
404 ML_Epetra::SetDefaultsRefMaxwell(defaultParams);
406 else if(defaultType == ML_PROBTYPE_GRADDIV) {
407 ML_Epetra::SetDefaultsGradDiv(defaultParams);
412 ,
"Error, the ML problem type \"" << defaultTypeStr <<
"\' is not recognized by ML!"
464 using Teuchos::tuple;
466 using Teuchos::rcp_implicit_cast;
476 BaseMethodDefaults_validator =
rcp(
478 BaseMethodDefaults_valueNames,
480 "Do not set any default parameters",
481 "Set default parameters for a smoothed aggregation method",
482 "Set default parameters for a nonsymmetric smoothed aggregation method",
483 "Set default parameters for a domain decomposition method",
484 "Set default parameters for a domain decomposition method special to ML",
485 "Set default parameters for a Maxwell-type of preconditioner",
486 "Set default parameters for a RefMaxwell-type preconditioner",
487 "Set default parameters for a Grad-Div-type preconditioner"
489 tuple<EMLProblemType>(
491 ML_PROBTYPE_SMOOTHED_AGGREGATION,
492 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
493 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
494 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
496 ML_PROBTYPE_REFMAXWELL,
499 BaseMethodDefaults_name
503 pl->set(BaseMethodDefaults_name,BaseMethodDefaults_default,
504 "Select the default method type which also sets parameter defaults\n"
505 "in the sublist \"" + MLSettings_name +
"\"!",
506 rcp_implicit_cast<const PEV>(BaseMethodDefaults_validator)
509 pl->set(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default,
510 "Enables/disables the reuse of the fine level smoother.");
513 pl->set(MLSettings_name,mlpl,
514 "Sampling of the parameters directly accepted by ML\n"
515 "This list of parameters is generated by combining all of\n"
516 "the parameters set for all of the default problem types supported\n"
517 "by ML. Therefore, do not assume these parameters are at values that\n"
518 "are reasonable to ML. This list is just to give a sense of some of\n"
519 "the parameters that ML accepts. Consult ML documentation on how to\n"
520 "set these parameters. Also, you can print the parameter list after\n"
521 "it is used and see what defaults where set for each default problem\n"
522 "type. Warning! the parameters in this sublist are currently *not*\n"
523 "being validated by ML!"
540 std::ostringstream oss;
541 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)
#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)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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