46 #include "Thyra_Amesos2LinearOpWithSolveFactory.hpp"
47 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
50 #include "Thyra_LinearOpTester.hpp"
51 #include "Thyra_LinearOpWithSolveBase.hpp"
52 #include "Thyra_LinearOpWithSolveTester.hpp"
53 #include "Thyra_MultiVectorStdOps.hpp"
54 #include "Thyra_VectorStdOps.hpp"
55 #include "MatrixMarket_Tpetra.hpp"
58 bool Thyra::test_single_amesos2_tpetra_solver(
59 const std::string matrixFile
61 ,
const int numRandomVectors
62 ,
const double maxFwdError
63 ,
const double maxResid
64 ,
const double maxSolutionError
65 ,
const bool showAllTests
74 bool result, success =
true;
82 <<
"\n*** Testing Thyra::BelosLinearOpWithSolveFactory (and Thyra::BelosLinearOpWithSolve)"
84 <<
"\nEchoing input options:"
85 <<
"\n matrixFile = " << matrixFile
86 <<
"\n numRhs = " << numRhs
87 <<
"\n numRandomVectors = " << numRandomVectors
88 <<
"\n maxFwdError = " << maxFwdError
89 <<
"\n maxResid = " << maxResid
90 <<
"\n showAllTests = " << showAllTests
91 <<
"\n dumpAll = " << dumpAll
95 if(out.
get()) *out <<
"\nA) Reading in a tpetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
97 using Scalar = double;
99 using MAT =
typename LOWS::MAT;
101 auto A_tpetra = Tpetra::MatrixMarket::Reader<MAT>::readSparseFile(matrixFile, comm);
102 auto domain_thyra = Thyra::tpetraVectorSpace<Scalar>(A_tpetra->getDomainMap());
103 auto range_thyra = Thyra::tpetraVectorSpace<Scalar>(A_tpetra->getRangeMap());
108 auto A_thyra = Thyra::constTpetraLinearOp(range_thyra_const, domain_thyra_const, A_tpetra_const);
112 if(out.
get()) *out <<
"\nB) Creating an Amesos2LinearOpWithSolveFactory object opFactory ...\n";
119 lowsFactory = amesos2LowsFactory;
123 *out <<
"\nlowsFactory.getValidParameters():\n";
124 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
125 *out <<
"\namesos2LOWSFPL before setting parameters:\n";
129 lowsFactory->setParameterList(
Teuchos::rcp(amesos2LOWSFPL,
false));
132 *out <<
"\namesos2LOWSFPL after setting parameters:\n";
136 if(out.
get()) *out <<
"\nC) Creating a Amesos2LinearOpWithSolve object nsA from A ...\n";
139 Thyra::initializeOp<Scalar>(*lowsFactory, A_thyra, nsA.
ptr());
141 if(out.
get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
143 LinearOpTester<Scalar> linearOpTester;
144 linearOpTester.check_adjoint(
false);
145 linearOpTester.num_rhs(numRhs);
146 linearOpTester.num_random_vectors(numRandomVectors);
147 linearOpTester.set_all_error_tol(maxFwdError);
148 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
149 linearOpTester.show_all_tests(showAllTests);
150 linearOpTester.dump_all(dumpAll);
151 Thyra::seed_randomize<Scalar>(0);
153 if(!result) success =
false;
155 if(out.
get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
157 LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
158 linearOpWithSolveTester.num_rhs(numRhs);
159 linearOpWithSolveTester.turn_off_all_tests();
160 linearOpWithSolveTester.check_forward_default(
true);
161 linearOpWithSolveTester.check_forward_residual(
true);
162 linearOpWithSolveTester.check_adjoint_default(
false);
163 linearOpWithSolveTester.check_adjoint_residual(
false);
164 linearOpWithSolveTester.set_all_solve_tol(maxResid);
165 linearOpWithSolveTester.set_all_slack_error_tol(maxResid);
166 linearOpWithSolveTester.set_all_slack_warning_tol(1e+1*maxResid);
167 linearOpWithSolveTester.forward_default_residual_error_tol(2*maxResid);
168 linearOpWithSolveTester.forward_default_solution_error_error_tol(maxSolutionError);
169 linearOpWithSolveTester.adjoint_default_residual_error_tol(2*maxResid);
170 linearOpWithSolveTester.adjoint_default_solution_error_error_tol(maxSolutionError);
171 linearOpWithSolveTester.show_all_tests(showAllTests);
172 linearOpWithSolveTester.dump_all(dumpAll);
173 Thyra::seed_randomize<Scalar>(0);
174 result = linearOpWithSolveTester.check(*nsA,out.
get());
175 if(!result) success =
false;
178 *out <<
"\namesos2LOWSFPL after solving:\n";
183 catch(
const std::exception &excpt ) {
184 if(out.
get()) *out << std::flush;
185 std::cerr <<
"*** Caught standard exception : " << excpt.what() << std::endl;
Concrete LinearOpWithSolveBase subclass in terms of Amesos2.
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)