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 "Epetra_RowMatrix.h" 65 ML_PROBTYPE_SMOOTHED_AGGREGATION,
66 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
67 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
70 const std::string BaseMethodDefaults_valueNames_none =
"none";
72 = Teuchos::tuple<std::string>(
73 BaseMethodDefaults_valueNames_none,
89 const std::string BaseMethodDefaults_name =
"Base Method Defaults";
90 const std::string BaseMethodDefaults_default =
"SA";
94 BaseMethodDefaults_validator;
96 const std::string ReuseFineLevelSmoother_name =
"Reuse Fine Level Smoother";
97 const bool ReuseFineLevelSmoother_default =
false;
99 const std::string MLSettings_name =
"ML Settings";
116 :epetraFwdOpViewExtractor_(
Teuchos::
rcp(new EpetraOperatorViewExtractorStd()))
124 const LinearOpSourceBase<double> &fwdOpSrc
127 using Teuchos::outArg;
129 EOpTransp epetraFwdOpTransp;
130 EApplyEpetraOpAs epetraFwdOpApplyAs;
131 EAdjointEpetraOp epetraFwdOpAdjointSupport;
132 double epetraFwdOpScalar;
134 fwdOp = fwdOpSrc.getOp();
135 epetraFwdOpViewExtractor_->getEpetraOpView(
137 outArg(epetraFwdOp),outArg(epetraFwdOpTransp),
138 outArg(epetraFwdOpApplyAs),
139 outArg(epetraFwdOpAdjointSupport),
140 outArg(epetraFwdOpScalar)
142 if( !dynamic_cast<const Epetra_RowMatrix*>(&*epetraFwdOp) )
163 return Teuchos::rcp(
new DefaultPreconditioner<double>());
168 const Teuchos::RCP<
const LinearOpSourceBase<double> > &fwdOpSrc,
169 PreconditionerBase<double> *prec,
170 const ESupportSolveUse supportSolveUse
173 using Teuchos::outArg;
179 using Teuchos::rcp_dynamic_cast;
180 using Teuchos::rcp_const_cast;
181 using Teuchos::set_extra_data;
182 using Teuchos::get_optional_extra_data;
185 totalTimer.start(
true);
190 *out <<
"\nEntering Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
201 EOpTransp epetraFwdOpTransp;
202 EApplyEpetraOpAs epetraFwdOpApplyAs;
203 EAdjointEpetraOp epetraFwdOpAdjointSupport;
204 double epetraFwdOpScalar;
205 epetraFwdOpViewExtractor_->getEpetraOpView(
206 fwdOp,outArg(epetraFwdOp),outArg(epetraFwdOpTransp),outArg(epetraFwdOpApplyAs),
207 outArg(epetraFwdOpAdjointSupport),outArg(epetraFwdOpScalar)
211 epetraFwdRowMat = rcp_dynamic_cast<
const Epetra_RowMatrix>(epetraFwdOp,
true);
213 epetraFwdOpApplyAs != EPETRA_OP_APPLY_APPLY, std::logic_error
214 ,
"Error, incorrect apply mode for an Epetra_RowMatrix" 220 DefaultPreconditioner<double>
226 epetra_precOp = rcp_dynamic_cast<EpetraLinearOp>(defaultPrec->getNonconstUnspecifiedPrecOp(),
true);
231 if(epetra_precOp.
get())
232 ml_precOp = rcp_dynamic_cast<ML_Epetra::MultiLevelPreconditioner>(epetra_precOp->epetra_op(),
true);
236 if(ml_precOp!=Teuchos::null) {
239 const Epetra_RowMatrix & rm = ml_precOp->RowMatrix();
241 TEUCHOS_TEST_FOR_EXCEPTION(
242 &rm!=&*epetraFwdRowMat, std::logic_error
243 ,
"ML requires Epetra_RowMatrix to be the same for each initialization of the preconditioner" 249 const bool startingOver = (ml_precOp.get() == NULL);
253 *out <<
"\nCreating the initial ML_Epetra::MultiLevelPreconditioner object...\n";
257 new ML_Epetra::MultiLevelPreconditioner(
273 TEUCHOS_TEST_FOR_EXCEPT(
282 set_extra_data(epetraFwdOp,
"IFPF::epetraFwdOp", Teuchos::inOutArg(ml_precOp),
288 *out <<
"\nComputing the preconditioner ...\n";
291 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ComputePreconditioner());
294 TEUCHOS_TEST_FOR_EXCEPT(0!=ml_precOp->ReComputePreconditioner(
paramList_->
get<
bool>(ReuseFineLevelSmoother_name)));
308 set_extra_data(fwdOp,
"IFPF::fwdOp", Teuchos::inOutArg(ml_precOp),
314 epetra_precOp =
rcp(
new EpetraLinearOp);
316 epetra_precOp->initialize(
319 ,EPETRA_OP_APPLY_APPLY_INVERSE
320 ,EPETRA_OP_ADJOINT_UNSUPPORTED
325 defaultPrec->initializeUnspecified(
326 Teuchos::rcp_implicit_cast<LinearOpBase<double> >(epetra_precOp)
330 *out <<
"\nTotal time in MLPreconditionerFactory = "<<totalTimer.totalElapsedTime()<<
" sec\n";
332 *out <<
"\nLeaving Thyra::MLPreconditionerFactory::initializePrec(...) ...\n";
337 PreconditionerBase<double> *prec,
339 ESupportSolveUse *supportSolveUse
359 paramList_->
set<
bool>(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default);
363 *
paramList_,BaseMethodDefaults_name,BaseMethodDefaults_default
365 if( ML_PROBTYPE_NONE != defaultType ) {
367 defaultTypeStr = BaseMethodDefaults_valueNames[defaultType];
370 0!=ML_Epetra::SetDefaults(defaultTypeStr,defaultParams)
372 ,
"Error, the ML problem type \"" << defaultTypeStr <<
"\' is not recognized by ML!" 421 using Teuchos::tuple;
423 using Teuchos::rcp_implicit_cast;
433 BaseMethodDefaults_validator =
rcp(
435 BaseMethodDefaults_valueNames,
437 "Do not set any default parameters",
438 "Set default parameters for a smoothed aggregation method",
439 "Set default parameters for a domain decomposition method",
440 "Set default parameters for a domain decomposition method special to ML",
441 "Set default parameters for a Maxwell-type of linear operator" 443 tuple<EMLProblemType>(
445 ML_PROBTYPE_SMOOTHED_AGGREGATION,
446 ML_PROBTYPE_DOMAIN_DECOMPOSITION,
447 ML_PROBTYPE_DOMAIN_DECOMPOSITION_ML,
450 BaseMethodDefaults_name
454 pl->set(BaseMethodDefaults_name,BaseMethodDefaults_default,
455 "Select the default method type which also sets parameter defaults\n" 456 "in the sublist \"" + MLSettings_name +
"\"!",
457 rcp_implicit_cast<const PEV>(BaseMethodDefaults_validator)
460 pl->set(ReuseFineLevelSmoother_name,ReuseFineLevelSmoother_default,
461 "Enables/disables the reuse of the fine level smoother.");
476 MLSettings_name,
false,
477 "Sampling of the parameters directly accepted by ML\n" 478 "This list of parameters is generated by combining all of\n" 479 "the parameters set for all of the default problem types supported\n" 480 "by ML. Therefore, do not assume these parameters are at values that\n" 481 "are reasonable to ML. This list is just to give a sense of some of\n" 482 "the parameters that ML accepts. Consult ML documentation on how to\n" 483 "set these parameters. Also, you can print the parameter list after\n" 484 "it is used and see what defaults where set for each default problem\n" 485 "type. Warning! the parameters in this sublist are currently *not*\n" 486 "being validated by ML!" 492 i < implicit_cast<int>(BaseMethodDefaults_valueNames.size());
497 const std::string defaultTypeStr = BaseMethodDefaults_valueNames[i];
498 if (defaultTypeStr != BaseMethodDefaults_valueNames_none) {
500 0!=ML_Epetra::SetDefaults(defaultTypeStr,defaultParams)
502 ,
"Error, the ML problem type \"" << defaultTypeStr
503 <<
"\' is not recognized by ML!" 525 std::ostringstream oss;
526 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)
ParameterList & setParameters(const ParameterList &source)
#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