42 #include "Thyra_MLPreconditionerFactory.hpp"
44 #include "Thyra_EpetraOperatorViewExtractorStd.hpp"
45 #include "Thyra_EpetraLinearOp.hpp"
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 "Epetra_RowMatrix.h"
52 #include "Teuchos_StandardParameterEntryValidators.hpp"
53 #include "Teuchos_dyn_cast.hpp"
54 #include "Teuchos_TimeMonitor.hpp"
55 #include "Teuchos_implicit_cast.hpp"
56 #include "Teuchos_ValidatorXMLConverterDB.hpp"
57 #include "Teuchos_StaticSetupMacro.hpp"
58 #include "Teuchos_iostream_helpers.hpp"
66 ML_PROBTYPE_SMOOTHED_AGGREGATION,
67 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
68 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
69 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
71 ML_PROBTYPE_REFMAXWELL
73 const std::string BaseMethodDefaults_valueNames_none =
"none";
75 = Teuchos::tuple<std::string>(
76 BaseMethodDefaults_valueNames_none,
86 TEUCHOS_ENUM_INPUT_STREAM_OPERATOR(EMLProblemType)
89 TEUCHOS_STATIC_SETUP()
94 const std::string BaseMethodDefaults_name =
"Base Method Defaults";
95 const std::string BaseMethodDefaults_default =
"SA";
99 BaseMethodDefaults_validator;
101 const std::string ReuseFineLevelSmoother_name =
"Reuse Fine Level Smoother";
102 const bool ReuseFineLevelSmoother_default =
false;
104 const std::string MLSettings_name =
"ML Settings";
132 using Teuchos::outArg;
137 double epetraFwdOpScalar;
139 fwdOp = fwdOpSrc.
getOp();
140 epetraFwdOpViewExtractor_->getEpetraOpView(
142 outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
143 outArg(epetraFwdOpApplyAs),
144 outArg(epetraFwdOpAdjointSupport),
145 outArg(epetraFwdOpScalar)
147 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
178 using Teuchos::outArg;
184 using Teuchos::rcp_dynamic_cast;
185 using Teuchos::rcp_const_cast;
186 using Teuchos::set_extra_data;
187 using Teuchos::get_optional_extra_data;
190 totalTimer.start(
true);
195 *out <<
"\nEntering Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
198 const EMLProblemType problemType = BaseMethodDefaults_validator->getIntegralValue(*paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default);
212 double epetraFwdOpScalar;
213 epetraFwdOpViewExtractor_->getEpetraOpView(
214 fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
215 outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
219 epetraFwdRowMat = rcp_dynamic_cast<
const Epetra_RowMatrix>(epetraFwdOp,
true);
222 ,
"Error, incorrect apply mode for an Epetra_RowMatrix"
235 epetra_precOp = rcp_dynamic_cast<
EpetraLinearOp>(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
241 if(epetra_precOp.
get()) {
242 if(problemType == ML_PROBTYPE_REFMAXWELL)
243 rm_precOp = rcp_dynamic_cast<ML_Epetra::RefMaxwellPreconditioner>(epetra_precOp->epetra_op(),
true);
245 ml_precOp = rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(epetra_precOp->epetra_op(),
true);
250 if(ml_precOp!=Teuchos::null) {
255 TEUCHOS_TEST_FOR_EXCEPTION(
256 &rm!=&*epetraFwdRowMat, std::logic_error
257 ,
"ML requires Epetra_RowMatrix to be the same for each initialization of the preconditioner"
265 const bool startingOver = (ml_precOp.get() == NULL && rm_precOp.
get() == NULL);
269 *out <<
"\nCreating the initial ML_Epetra::MultiLevelPreconditioner object...\n";
273 if(problemType==ML_PROBTYPE_REFMAXWELL)
274 rm_precOp =
rcp(
new ML_Epetra::RefMaxwellPreconditioner(*epetraFwdCrsMat, paramList_->
sublist(MLSettings_name),
false));
276 ml_precOp =
rcp(
new ML_Epetra::MultiLevelPreconditioner(*epetraFwdRowMat, paramList_->
sublist(MLSettings_name),
false));
289 if(paramList_.
get()) {
290 if (problemType==ML_PROBTYPE_REFMAXWELL) {
291 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->SetParameterList(paramList_->
sublist(MLSettings_name)));
294 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->SetParameterList(paramList_->
sublist(MLSettings_name)));
301 if (problemType==ML_PROBTYPE_REFMAXWELL)
302 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(rm_precOp),
303 Teuchos::POST_DESTROY,
false);
305 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(ml_precOp),
306 Teuchos::POST_DESTROY,
false);
311 *out <<
"\nComputing the preconditioner ...\n";
313 if (problemType==ML_PROBTYPE_REFMAXWELL) {
315 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ComputePreconditioner());
318 TEUCHOS_TEST_FOR_EXCEPT(0!=rm_precOp->ReComputePreconditioner());
323 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ComputePreconditioner());
326 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ReComputePreconditioner(paramList_->
get<
bool>(ReuseFineLevelSmoother_name)));
341 if (problemType==ML_PROBTYPE_REFMAXWELL)
342 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(rm_precOp),
343 Teuchos::POST_DESTROY,
false);
345 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(ml_precOp),
346 Teuchos::POST_DESTROY,
false);
354 if (problemType==ML_PROBTYPE_REFMAXWELL)
361 defaultPrec->initializeUnspecified(
366 *out <<
"\nTotal time in MLPreconditionerFactory = "<<totalTimer.totalElapsedTime()<<
" sec\n";
368 *out <<
"\nLeaving Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
393 paramList_ = paramList;
396 if(!paramList_->
isType<
bool>(ReuseFineLevelSmoother_name))
397 paramList_->
set<
bool>(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default);
401 *paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default
403 if( ML_PROBTYPE_NONE != defaultType ) {
404 const std::string defaultTypeStr = BaseMethodDefaults_valueNames[defaultType];
408 if(defaultType == ML_PROBTYPE_REFMAXWELL) {
409 ML_Epetra::SetDefaultsRefMaxwell(defaultParams);
414 ,
"Error, the ML problem type \"" << defaultTypeStr <<
"\' is not recognized by ML!"
446 paramList_ = Teuchos::null;
466 using Teuchos::tuple;
468 using Teuchos::rcp_implicit_cast;
478 BaseMethodDefaults_validator =
rcp(
480 BaseMethodDefaults_valueNames,
482 "Do not set any default parameters",
483 "Set default parameters for a smoothed aggregation method",
484 "Set default parameters for a nonsymmetric smoothed aggregation method",
485 "Set default parameters for a domain decomposition method",
486 "Set default parameters for a domain decomposition method special to ML",
487 "Set default parameters for a Maxwell-type of preconditioner",
488 "Set default parameters for a RefMaxwell-type preconditioner"
490 tuple<EMLProblemType>(
492 ML_PROBTYPE_SMOOTHED_AGGREGATION,
493 ML_PROBTYPE_NONSYMMETRIC_SMOOTHED_AGGREGATION,
494 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
495 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
497 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)
basic_OSTab< char > OSTab
T & get(const std::string &name, T def_value)
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()
T_To & dyn_cast(T_From &from)
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
TypeTo implicit_cast(const TypeFrom &t)
void initializePrec(const Teuchos::RCP< const LinearOpSourceBase< double > > &fwdOp, PreconditionerBase< double > *prec, const ESupportSolveUse supportSolveUse) const
#define TEUCHOS_ADD_STRINGTOINTEGRALVALIDATOR_CONVERTER(INTEGRALTYPE)
ParameterList & setParametersNotAlreadySet(const ParameterList &source)
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
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual Teuchos::RCP< const LinearOpBase< Scalar > > getOp() const =0
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