44 #include "Stratimikos_InternalConfig.h" 46 #include "Thyra_DelayedLinearOpWithSolveFactory.hpp" 52 #ifdef HAVE_STRATIMIKOS_AMESOS 55 #if defined(HAVE_STRATIMIKOS_EPETRAEXT) && defined(HAVE_STRATIMIKOS_AZTECOO) 58 #ifdef HAVE_STRATIMIKOS_BELOS 59 # include "Thyra_BelosLinearOpWithSolveFactory.hpp" 61 #ifdef HAVE_STRATIMIKOS_IFPACK 64 #ifdef HAVE_STRATIMIKOS_ML 72 const std::string LinearSolverType_name =
"Linear Solver Type";
73 const std::string LinearSolverTypes_name =
"Linear Solver Types";
74 const std::string PreconditionerType_name =
"Preconditioner Type";
75 const std::string PreconditionerTypes_name =
"Preconditioner Types";
76 const std::string None_name =
"None";
77 const std::string EnableDelayedSolverConstruction_name =
"Enable Delayed Solver Construction";
78 const bool EnableDelayedSolverConstruction_default =
false;
91 const std::string ¶msXmlFileName_in
92 ,
const std::string &extraParamsXmlString_in
93 ,
const std::string ¶msUsedXmlOutFileName_in
94 ,
const std::string ¶msXmlFileNameOption_in
95 ,
const std::string &extraParamsXmlStringOption_in
96 ,
const std::string ¶msUsedXmlOutFileNameOption_in
98 :paramsXmlFileName_(paramsXmlFileName_in)
99 ,extraParamsXmlString_(extraParamsXmlString_in)
100 ,paramsUsedXmlOutFileName_(paramsUsedXmlOutFileName_in)
101 ,paramsXmlFileNameOption_(paramsXmlFileNameOption_in)
102 ,extraParamsXmlStringOption_(extraParamsXmlStringOption_in)
103 ,paramsUsedXmlOutFileNameOption_(paramsUsedXmlOutFileNameOption_in)
104 ,enableDelayedSolverConstruction_(EnableDelayedSolverConstruction_default)
123 &solveStrategyFactory,
124 const std::string &solveStrategyName,
125 const bool makeDefault
138 const std::string &solveStrategyName)
146 &precStrategyFactory,
147 const std::string &precStrategyName,
148 const bool makeDefault
152 pfArray_.push_back(precStrategyFactory);
161 const std::string &precStrategyName)
171 paramsXmlFileNameOption().c_str(),¶msXmlFileName_
172 ,
"Name of an XML file containing parameters for linear solver " 173 "options to be appended first." 176 extraParamsXmlStringOption().c_str(),&extraParamsXmlString_
177 ,
"An XML string containing linear solver parameters to be appended second." 180 paramsUsedXmlOutFileNameOption().c_str(),¶msUsedXmlOutFileName_
181 ,
"Name of an XML file that can be written with the parameter list after it " 182 "has been used on completion of this program." 189 using Teuchos::parameterList;
191 using Teuchos::updateParametersFromXmlFile;
192 using Teuchos::updateParametersFromXmlString;
196 paramList_ = parameterList(
"DefaultLinearSolverBuilder");
198 if (paramsXmlFileName().length()) {
200 *out << endl <<
"Reading parameters from XML file \"" 201 << paramsXmlFileName() <<
"\" ..." << endl;
203 updateParametersFromXmlFile (paramsXmlFileName (),
paramList_.ptr());
205 if (extraParamsXmlString().length()) {
207 *out << endl <<
"Appending extra parameters from the XML string \"" 208 << extraParamsXmlString() <<
"\" ..." << endl;
210 updateParametersFromXmlString (extraParamsXmlString (),
paramList_.ptr());
217 const Thyra::LinearOpWithSolveFactoryBase<double> &lowsFactory,
218 const std::string &outputXmlFileName
222 const std::string xmlOutputFile =
223 ( outputXmlFileName.length() ? outputXmlFileName : paramsUsedXmlOutFileName() );
224 if (xmlOutputFile.length()) {
225 Teuchos::writeParameterListToXmlFile(*
paramList_, xmlOutputFile);
259 EnableDelayedSolverConstruction_name, EnableDelayedSolverConstruction_default );
289 using Teuchos::rcp_implicit_cast;
302 (std::string(
"Determines the type of linear solver that will be used.\n")
303 +
"The parameters for each solver type are specified in the sublist \"" 304 + LinearSolverTypes_name +
"\"").c_str(),
308 LinearSolverTypes_name,
false,
309 "Sublists for each of the linear solver types set using the parameter\n" 310 "\"" + LinearSolverType_name +
"\". Note that the options for each\n" 311 "linear solver type given below will only be used if linear solvers\n" 312 "of that type are created. It is fine to list parameter sublists for\n" 313 "linear solver types that are not used." 315 for(
int i = 0; i < static_cast<int>(
lowsfArray_.size()); ++i ) {
320 linearSolverTypesSL.
sublist(lsname).setParameters(*lowsf->getValidParameters()
321 ).disableRecursiveValidation();
329 (std::string(
"Determines the type of preconditioner that will be used.\n")
330 +
"This option is only meaningful for linear solvers that accept preconditioner" 331 +
" factory objects!\n" 332 +
"The parameters for each preconditioner are specified in the sublist \"" 333 + PreconditionerTypes_name +
"\"").c_str(),
337 PreconditionerTypes_name,
false,
338 "Sublists for each of the preconditioner types set using the parameter\n" 339 "\"" + PreconditionerType_name +
"\". Note that the options for each\n" 340 "preconditioner type given below will only be used if preconditioners\n" 341 "of that type are created. It is fine to list parameter sublists for\n" 342 "preconditioner types that are not used." 344 for(
int i = 0; i < static_cast<int>(
pfArray_.size()); ++i ) {
349 precTypesSL.
sublist(pfname).setParameters(*pf->getValidParameters()
350 ).disableRecursiveValidation();
354 EnableDelayedSolverConstruction_name, EnableDelayedSolverConstruction_default,
355 "When this option is set to true, the linear solver factory will be wrapped\n" 356 "in a delayed evaluation Decorator factory object. This results in a delay\n" 357 "in the creation of a linear solver (and the associated preconditioner) until\n" 358 "the first solve is actually performed. This helps in cases where it is not\n" 359 "known a-priori if a linear solve will be needed on a given linear operator and\n" 360 "therefore can significantly improve performance for some types of algorithms\n" 361 "such as NOX and LOCA." 375 const std::string &linearSolveStrategyName
381 #ifdef THYRA_DEFAULT_REAL_LINEAR_SOLVER_BUILDER_DUMP 382 std::cout <<
"\nEntering DefaultLinearSolverBuilder" 383 <<
"::createLinearSolveStrategy(...) ...\n";
384 std::cout <<
"\nlinearSolveStrategyName = \"" 385 << linearSolveStrategyName <<
"\"\n";
386 std::cout <<
"\nlinearSolveStrategyName.length() = " 387 << linearSolveStrategyName.length() <<
"\n";
388 std::cout <<
"\ndefaultLOWSF_ = \"" <<
defaultLOWSF_ <<
"\"\n";
389 std::cout <<
"\nthis->getLinearSolveStrategyName() = \"" 393 lsname = ( linearSolveStrategyName.length()
394 ? linearSolveStrategyName
396 #ifdef THYRA_DEFAULT_REAL_LINEAR_SOLVER_BUILDER_DUMP 397 std::cout <<
"\nlsname = \"" << lsname <<
"\"\n";
409 if(lowsf->acceptsPreconditionerFactory()) {
414 lowsf->setPreconditionerFactory(pf,pfName);
419 lowsf->setParameterList(
420 sublist(sublist(
paramList_, LinearSolverTypes_name), lsname));
424 new Thyra::DelayedLinearOpWithSolveFactory<double>(lowsf)
435 const std::string &preconditioningStrategyName
442 pfname = ( preconditioningStrategyName.length()
443 ? preconditioningStrategyName
453 pf->setParameterList(
454 sublist(sublist(
paramList_, PreconditionerTypes_name), pfname));
469 using Teuchos::abstractFactoryStd;
481 #ifdef HAVE_STRATIMIKOS_BELOS 483 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<double>,
489 #ifdef HAVE_STRATIMIKOS_AMESOS 491 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<double>,
497 #if defined(HAVE_STRATIMIKOS_EPETRAEXT) && defined(HAVE_STRATIMIKOS_AZTECOO) 499 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<double>,
505 #ifdef HAVE_STRATIMIKOS_AMESOS 518 #ifdef HAVE_STRATIMIKOS_ML 520 abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,
526 #ifdef HAVE_STRATIMIKOS_IFPACK 528 abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,
Concrete LinearOpWithSolveFactoryBase adapter subclass that uses Amesos direct solvers.
RCP< Thyra::PreconditionerFactoryBase< double > > createPreconditioningStrategy(const std::string &preconditioningStrategyName) const
Array< pf_fcty_t > pfArray_
void setPreconditioningStrategyFactory(const RCP< const AbstractFactory< Thyra::PreconditionerFactoryBase< double > > > &precStrategyFactory, const std::string &precStrategyName, const bool makeDefault=false)
Set a new preconditioner strategy factory object.
Concrete preconditioner factory subclass based on Ifpack.
RCP< const ParameterList > getValidParameters() const
Array< std::string > validLowsfNames_
LinearOpWithSolveFactoryBase subclass implemented in terms of AztecOO.
bool is_null(const boost::shared_ptr< T > &p)
void setupCLP(Teuchos::CommandLineProcessor *clp)
Setup the command-line processor to read in the needed data to extra the parameters from...
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void setDefaultLinearSolveStrategyFactoryName(const std::string &solveStrategyName)
Set the default linear solver factory name.
Array< std::string > validPfNames_
Array< lowsf_fcty_t > lowsfArray_
RCP< Thyra::LinearOpWithSolveFactoryBase< double > > createLinearSolveStrategy(const std::string &linearSolveStrategyName) const
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Concrete preconditioner factory subclass based on ML.
std::string defaultLOWSF_
void setParameterList(RCP< ParameterList > const ¶mList)
void readParameters(std::ostream *out)
Force the parameters to be read from a file and/or an extra XML string.
RCP< ParameterList > paramList_
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
void initializeDefaults()
void justInTimeInitialize() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::string getStringValue(const ParameterEntry &entry, const std::string ¶mName="", const std::string &sublistName="", const bool activeQuery=true) const
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
std::string getPreconditionerStrategyName() const
Get the name of the preconditioner strategy that will be created on the next call to this->createPrec...
RCP< const ParameterList > getParameterList() const
void resize(size_type new_size, const value_type &x=value_type())
bool enableDelayedSolverConstruction_
LinearOpWithSolveFactoryBase subclass implemented in terms of Belos.
IntegralType getIntegralValue(const std::string &str, const std::string ¶mName="", const std::string &sublistName="") const
RCP< const Teuchos::StringToIntegralParameterEntryValidator< int > > lowsfValidator_
RCP< ParameterList > unsetParameterList()
bool nonnull(const boost::shared_ptr< T > &p)
~DefaultLinearSolverBuilder()
RCP< ParameterList > getNonconstParameterList()
RCP< const ParameterList > validParamList_
void push_back(const value_type &x)
RCP< const Teuchos::StringToIntegralParameterEntryValidator< int > > pfValidator_
void writeParamsFile(const Thyra::LinearOpWithSolveFactoryBase< double > &lowsFactory, const std::string &outputXmlFileName="") const
Write the parameters list for a LinearOpWithSolveFactoryBase object to a file after the parameters ar...
DefaultLinearSolverBuilder(const std::string ¶msXmlFileName="", const std::string &extraParamsXmlString="", const std::string ¶msUsedXmlOutFileName="", const std::string ¶msXmlFileNameOption="linear-solver-params-file", const std::string &extraParamsXmlStringOption="extra-linear-solver-params", const std::string ¶msUsedXmlOutFileNameOption="linear-solver-params-used-file")
Construct with default parameters.
void setLinearSolveStrategyFactory(const RCP< const AbstractFactory< Thyra::LinearOpWithSolveFactoryBase< double > > > &solveStrategyFactory, const std::string &solveStrategyName, const bool makeDefault=false)
Set a new linear solver strategy factory object.
std::string getLinearSolveStrategyName() const
Get the name of the linear solver strategy that will be created on the next call to this->createLinea...
void setDefaultPreconditioningStrategyFactoryName(const std::string &precStrategyName)
Set the default linear solver factory name.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)