15 #include "Tpetra_Core.hpp"
16 #include "Tpetra_CrsMatrix.hpp"
17 #include "MatrixMarket_Tpetra.hpp"
21 #include "Thyra_LinearOpBase.hpp"
22 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
23 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
27 int main(
int argc,
char* argv[])
34 using Teuchos::getParameter;
35 typedef double Scalar;
36 typedef Tpetra::Map<>::local_ordinal_type
LO;
37 typedef Tpetra::Map<>::global_ordinal_type
GO;
38 typedef Tpetra::Map<>::node_type NO;
47 out = Teuchos::VerboseObjectBase::getDefaultOStream();
50 Tpetra::ScopeGuard tpetraScope(&argc,&argv);
57 std::string inputFile =
"";
58 std::string extraParams =
"";
59 bool printUnusedParams =
false;
60 RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
61 int MyPID = rank(*comm);
62 verbose = ( out && (MyPID==0) );
64 CommandLineProcessor clp(
false);
65 clp.addOutputSetupOptions(
true);
66 clp.setOption(
"input-file", &inputFile,
"Input file [Required].",
true );
67 clp.setOption(
"extra-params", &extraParams,
"Extra parameters overriding the parameters read in from --input-file");
68 clp.setOption(
"print-unused-params",
"no-print-unused-params", &printUnusedParams,
"Whether to print all unused parameters at the end.");
70 "Testing program for Trilinos Tpetra linear solvers access through Thyra."
73 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
74 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
return parse_return;
77 if(verbose) *out <<
"\nReading parameters from XML file \""<<inputFile<<
"\" ...\n";
78 Teuchos::updateParametersFromXmlFile(inputFile, Teuchos::inOutArg(*paramList));
79 if(extraParams.length()) {
80 if(verbose) *out <<
"\nAppending extra parameters from the XML string \""<<extraParams<<
"\" ...\n";
81 Teuchos::updateParametersFromXmlString(extraParams, Teuchos::inOutArg(*paramList));
85 *out <<
"\nEchoing input parameters ...\n";
86 paramList->print(*out,1,
true,
false);
91 validParamList.
set(
"Matrix File",
"fileName");
92 validParamList.
sublist(
"Linear Solver Builder").disableRecursiveValidation();
94 if(verbose) *out <<
"\nValidating top-level input parameters ...\n";
95 paramList->validateParametersAndSetDefaults(validParamList);
98 &matrixFile = getParameter<std::string>(*paramList,
"Matrix File");
100 solverBuilderSL = sublist(paramList,
"Linear Solver Builder",
true);
102 if(verbose) *out <<
"\nReading in an tpetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
104 RCP<const Tpetra::CrsMatrix<Scalar, LO, GO, NO>> tpetra_A = Tpetra::MatrixMarket::Reader<Tpetra::CrsMatrix<Scalar, LO, GO, NO>>::readSparseFile( matrixFile, comm );
106 RCP<Tpetra::Vector<Scalar,LO,GO,NO>> tpetra_x0 =
rcp(
new Tpetra::Vector<Scalar,LO,GO,NO>(tpetra_A->getDomainMap()));
107 RCP<Tpetra::Vector<Scalar,LO,GO,NO>> tpetra_b =
rcp(
new Tpetra::Vector<Scalar,LO,GO,NO>(tpetra_A->getRangeMap()));
108 tpetra_x0->putScalar(1.0);
109 tpetra_A->apply(*tpetra_x0, *tpetra_b);
110 tpetra_x0->putScalar(0.0);
112 RCP<const Thyra::LinearOpBase<double> >
115 RCP<Thyra::VectorBase<double> >
117 RCP<const Thyra::VectorBase<double> >
120 if(verbose) *out <<
"\nCreating a Stratimikos::DefaultLinearSolverBuilder object ...\n";
126 Stratimikos::enableBelosPrecTpetra<Tpetra::CrsMatrix<Scalar,LO,GO,NO>>(linearSolverBuilder);
130 if(verbose) *out <<
"\nCreating the LinearOpWithSolveFactoryBase object lowsFactory ...\n";
131 RCP<Thyra::LinearOpWithSolveFactoryBase<double> >
132 lowsFactory = createLinearSolveStrategy(linearSolverBuilder);
134 if(verbose) *out <<
"\nChecking the LOWSB interface ...\n";
135 RCP<Thyra::LinearOpWithSolveBase<Scalar> >
136 lowsA = Thyra::linearOpWithSolve<Scalar>(*lowsFactory, A);
139 Thyra::SolveStatus<double> status;
140 status = Thyra::solve<double>(*lowsA, Thyra::NOTRANS, *b, x0.ptr());
142 success = (status.solveStatus == Thyra::SOLVE_STATUS_CONVERGED ?
true :
false);
144 if(verbose && printUnusedParams) {
145 *out <<
"\nPrinting the parameter list (showing what was used) ...\n";
146 paramList->print(*out,1,
true,
true);
151 catch(
const std::exception &excpt ) {
152 std::cerr <<
"*** Caught standard exception : " << excpt.what() << std::endl;
157 if(success) *out <<
"\nCongratulations! The test passed!\n";
158 else *out <<
"\nOh no! At least one of the solves failed!\n";
161 return ( success ? EXIT_SUCCESS : EXIT_FAILURE );
int main(int argc, char *argv[])
RCP< ParameterList > sublist(const RCP< ParameterList > ¶mList, const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
basic_OSTab< char > OSTab
RCP< const LinearOpBase< Scalar > > createConstLinearOp(const RCP< const Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraOperator, const RCP< const VectorSpaceBase< Scalar > > rangeSpace=Teuchos::null, const RCP< const VectorSpaceBase< Scalar > > domainSpace=Teuchos::null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< VectorBase< Scalar > > createVector(const RCP< Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &tpetraVector, const RCP< const VectorSpaceBase< Scalar > > space=Teuchos::null)
void setParameterList(RCP< ParameterList > const ¶mList)
Concrete subclass of Thyra::LinearSolverBuilderBase for creating Thyra::LinearOpWithSolveFactoryBase ...
map_type::local_ordinal_type LO
map_type::global_ordinal_type GO