97 const std::string ¶msXmlFileName_in
98 ,
const std::string &extraParamsXmlString_in
99 ,
const std::string ¶msUsedXmlOutFileName_in
100 ,
const std::string ¶msXmlFileNameOption_in
101 ,
const std::string &extraParamsXmlStringOption_in
102 ,
const std::string ¶msUsedXmlOutFileNameOption_in
104 :paramsXmlFileName_(paramsXmlFileName_in)
105 ,extraParamsXmlString_(extraParamsXmlString_in)
106 ,paramsUsedXmlOutFileName_(paramsUsedXmlOutFileName_in)
107 ,paramsXmlFileNameOption_(paramsXmlFileNameOption_in)
108 ,extraParamsXmlStringOption_(extraParamsXmlStringOption_in)
109 ,paramsUsedXmlOutFileNameOption_(paramsUsedXmlOutFileNameOption_in)
110 ,enableDelayedSolverConstruction_(EnableDelayedSolverConstruction_default)
130 const RCP<
const AbstractFactory<Thyra::LinearOpWithSolveFactoryBase<Scalar> > >
131 &solveStrategyFactory,
132 const std::string &solveStrategyName,
133 const bool makeDefault
136 validLowsfNames_.push_back(solveStrategyName);
137 lowsfArray_.push_back(solveStrategyFactory);
138 validParamList_ = Teuchos::null;
140 setDefaultLinearSolveStrategyFactoryName(solveStrategyName);
155 const RCP<
const AbstractFactory<Thyra::PreconditionerFactoryBase<Scalar> > >
156 &precStrategyFactory,
157 const std::string &precStrategyName,
158 const bool makeDefault
161 validPfNames_.push_back(precStrategyName);
162 pfArray_.push_back(precStrategyFactory);
163 validParamList_ = Teuchos::null;
165 setDefaultPreconditioningStrategyFactoryName(precStrategyName);
181 TEUCHOS_TEST_FOR_EXCEPT(clp==NULL);
183 paramsXmlFileNameOption().c_str(),¶msXmlFileName_
184 ,
"Name of an XML file containing parameters for linear solver "
185 "options to be appended first."
188 extraParamsXmlStringOption().c_str(),&extraParamsXmlString_
189 ,
"An XML string containing linear solver parameters to be appended second."
192 paramsUsedXmlOutFileNameOption().c_str(),¶msUsedXmlOutFileName_
193 ,
"Name of an XML file that can be written with the parameter list after it "
194 "has been used on completion of this program."
202 using Teuchos::parameterList;
204 using Teuchos::updateParametersFromXmlFile;
205 using Teuchos::updateParametersFromXmlString;
208 if (!paramList_.get()) {
209 paramList_ = parameterList(
"LinearSolverBuilder");
211 if (paramsXmlFileName().length()) {
213 *out << endl <<
"Reading parameters from XML file \""
214 << paramsXmlFileName() <<
"\" ..." << endl;
216 updateParametersFromXmlFile (paramsXmlFileName (), paramList_.ptr());
218 if (extraParamsXmlString().length()) {
220 *out << endl <<
"Appending extra parameters from the XML string \""
221 << extraParamsXmlString() <<
"\" ..." << endl;
223 updateParametersFromXmlString (extraParamsXmlString (), paramList_.ptr());
225 setParameterList(paramList_);
231 const Thyra::LinearOpWithSolveFactoryBase<Scalar> &,
232 const std::string &outputXmlFileName
235 justInTimeInitialize();
236 const std::string xmlOutputFile =
237 ( outputXmlFileName.length() ? outputXmlFileName : paramsUsedXmlOutFileName() );
238 if (xmlOutputFile.length()) {
239 Teuchos::writeParameterListToXmlFile(*paramList_, xmlOutputFile);
310 using Teuchos::rcp_implicit_cast;
311 typedef Teuchos::ParameterEntryValidator PEV;
312 if (is_null(validParamList_)) {
313 RCP<Teuchos::ParameterList>
314 validParamList = Teuchos::rcp(
new Teuchos::ParameterList);
316 lowsfValidator_ = Teuchos::rcp(
317 new Teuchos::StringToIntegralParameterEntryValidator<int>(
318 validLowsfNames_,LinearSolverType_name
322 LinearSolverType_name, defaultLOWSF_,
323 (std::string(
"Determines the type of linear solver that will be used.\n")
324 +
"The parameters for each solver type are specified in the sublist \""
325 + LinearSolverTypes_name +
"\"").c_str(),
326 rcp_implicit_cast<const PEV>(lowsfValidator_)
328 Teuchos::ParameterList &linearSolverTypesSL = validParamList->sublist(
329 LinearSolverTypes_name,
false,
330 "Sublists for each of the linear solver types set using the parameter\n"
331 "\"" + LinearSolverType_name +
"\". Note that the options for each\n"
332 "linear solver type given below will only be used if linear solvers\n"
333 "of that type are created. It is fine to list parameter sublists for\n"
334 "linear solver types that are not used."
336 for(
int i = 0; i < static_cast<int>(lowsfArray_.size()); ++i ) {
338 &lsname = validLowsfNames_[i];
339 const RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >
340 lowsf = lowsfArray_[i]->create();
341 linearSolverTypesSL.sublist(lsname).setParameters(*lowsf->getValidParameters()
342 ).disableRecursiveValidation();
345 pfValidator_ = Teuchos::rcp(
346 new Teuchos::StringToIntegralParameterEntryValidator<int>(
347 validPfNames_, PreconditionerType_name ) );
349 PreconditionerType_name, defaultPF_,
350 (std::string(
"Determines the type of preconditioner that will be used.\n")
351 +
"This option is only meaningful for linear solvers that accept preconditioner"
352 +
" factory objects!\n"
353 +
"The parameters for each preconditioner are specified in the sublist \""
354 + PreconditionerTypes_name +
"\"").c_str(),
355 rcp_implicit_cast<const PEV>(pfValidator_)
357 Teuchos::ParameterList &precTypesSL = validParamList->sublist(
358 PreconditionerTypes_name,
false,
359 "Sublists for each of the preconditioner types set using the parameter\n"
360 "\"" + PreconditionerType_name +
"\". Note that the options for each\n"
361 "preconditioner type given below will only be used if preconditioners\n"
362 "of that type are created. It is fine to list parameter sublists for\n"
363 "preconditioner types that are not used."
365 for(
int i = 0; i < static_cast<int>(pfArray_.size()); ++i ) {
367 &pfname = validPfNames_[i+1];
368 const RCP<Thyra::PreconditionerFactoryBase<Scalar> >
369 pf = pfArray_[i]->create();
370 precTypesSL.sublist(pfname).setParameters(*pf->getValidParameters()
371 ).disableRecursiveValidation();
375 EnableDelayedSolverConstruction_name, EnableDelayedSolverConstruction_default,
376 "When this option is set to true, the linear solver factory will be wrapped\n"
377 "in a delayed evaluation Decorator factory object. This results in a delay\n"
378 "in the creation of a linear solver (and the associated preconditioner) until\n"
379 "the first solve is actually performed. This helps in cases where it is not\n"
380 "known a-priori if a linear solve will be needed on a given linear operator and\n"
381 "therefore can significantly improve performance for some types of algorithms\n"
382 "such as NOX and LOCA."
385 validParamList_ = validParamList;
387 return validParamList_;
397 const std::string &linearSolveStrategyName
400 justInTimeInitialize();
403#ifdef THYRA_DEFAULT_REAL_LINEAR_SOLVER_BUILDER_DUMP
404 std::cout <<
"\nEntering LinearSolverBuilder"
405 <<
"::createLinearSolveStrategy(...) ...\n";
406 std::cout <<
"\nlinearSolveStrategyName = \""
407 << linearSolveStrategyName <<
"\"\n";
408 std::cout <<
"\nlinearSolveStrategyName.length() = "
409 << linearSolveStrategyName.length() <<
"\n";
410 std::cout <<
"\ndefaultLOWSF_ = \"" << defaultLOWSF_ <<
"\"\n";
411 std::cout <<
"\nthis->getLinearSolveStrategyName() = \""
412 << this->getLinearSolveStrategyName() <<
"\"\n";
415 lsname = ( linearSolveStrategyName.length()
416 ? linearSolveStrategyName
417 : this->getLinearSolveStrategyName() );
418#ifdef THYRA_DEFAULT_REAL_LINEAR_SOLVER_BUILDER_DUMP
419 std::cout <<
"\nlsname = \"" << lsname <<
"\"\n";
424 ls_idx = lowsfValidator_->getIntegralValue(lsname, LinearSolverType_name);
427 RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >
428 lowsf = lowsfArray_[ls_idx]->create();
431 if(lowsf->acceptsPreconditionerFactory()) {
432 const std::string &pfName = this->getPreconditionerStrategyName();
433 RCP<Thyra::PreconditionerFactoryBase<Scalar> >
434 pf = this->createPreconditioningStrategy(pfName);
436 lowsf->setPreconditionerFactory(pf,pfName);
441 lowsf->setParameterList(
442 sublist(sublist(paramList_, LinearSolverTypes_name), lsname));
444 if (enableDelayedSolverConstruction_) {
446 new Thyra::DelayedLinearOpWithSolveFactory<Scalar>(lowsf)
458 const std::string &preconditioningStrategyName
461 justInTimeInitialize();
465 pfname = ( preconditioningStrategyName.length()
466 ? preconditioningStrategyName
467 : this->getPreconditionerStrategyName() );
468 RCP<Thyra::PreconditionerFactoryBase<Scalar> >
473 pf_idx = pfValidator_->getIntegralValue(pfname, PreconditionerType_name);
475 pf = pfArray_[pf_idx-1]->create();
476 pf->setParameterList(
477 sublist(sublist(paramList_, PreconditionerTypes_name), pfname));
492 using Teuchos::abstractFactoryStd;
495 defaultPF_ = None_name;
496 validLowsfNames_.resize(0);
497 validPfNames_.resize(0);
498 validPfNames_.push_back(None_name);
504#ifdef HAVE_STRATIMIKOS_AMESOS2
505 setLinearSolveStrategyFactory(
506 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
507 Thyra::Amesos2LinearOpWithSolveFactory<Scalar>>(),
512#ifdef HAVE_STRATIMIKOS_BELOS
513 setLinearSolveStrategyFactory(
514 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
515 Thyra::BelosLinearOpWithSolveFactory<Scalar> >(),
527 using Scalar = double;
529 using Teuchos::abstractFactoryStd;
532 defaultPF_ = None_name;
533 validLowsfNames_.resize(0);
534 validPfNames_.resize(0);
535 validPfNames_.push_back(None_name);
541#ifdef HAVE_STRATIMIKOS_AMESOS2
542 setLinearSolveStrategyFactory(
543 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
544 Thyra::Amesos2LinearOpWithSolveFactory<Scalar>>(),
549#ifdef HAVE_STRATIMIKOS_BELOS
550 setLinearSolveStrategyFactory(
551 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
552 Thyra::BelosLinearOpWithSolveFactory<Scalar> >(),
557#ifdef HAVE_STRATIMIKOS_AMESOS
558 setLinearSolveStrategyFactory(
559 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
565#if defined(HAVE_STRATIMIKOS_EPETRAEXT) && defined(HAVE_STRATIMIKOS_AZTECOO)
566 setLinearSolveStrategyFactory(
567 abstractFactoryStd<Thyra::LinearOpWithSolveFactoryBase<Scalar>,
576#ifdef HAVE_STRATIMIKOS_AMESOS
577 if (Teuchos::GlobalMPISession::getNProc() == 1) {
578 setDefaultLinearSolveStrategyFactoryName(
"Amesos");
586#ifdef HAVE_STRATIMIKOS_ML
587 setPreconditioningStrategyFactory(
588 abstractFactoryStd<Thyra::PreconditionerFactoryBase<Scalar>,
594#ifdef HAVE_STRATIMIKOS_IFPACK
595 setPreconditioningStrategyFactory(
596 abstractFactoryStd<Thyra::PreconditionerFactoryBase<Scalar>,
LinearSolverBuilder(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.