12 #include "Thyra_Amesos2LinearOpWithSolveFactory.hpp"
13 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
16 #include "Thyra_LinearOpTester.hpp"
17 #include "Thyra_LinearOpWithSolveBase.hpp"
18 #include "Thyra_LinearOpWithSolveTester.hpp"
19 #include "Thyra_MultiVectorStdOps.hpp"
20 #include "Thyra_VectorStdOps.hpp"
21 #include "MatrixMarket_Tpetra.hpp"
24 bool Thyra::test_single_amesos2_tpetra_solver(
25 const std::string matrixFile
27 ,
const int numRandomVectors
28 ,
const double maxFwdError
29 ,
const double maxResid
30 ,
const double maxSolutionError
31 ,
const bool showAllTests
40 bool result, success =
true;
48 <<
"\n*** Testing Thyra::BelosLinearOpWithSolveFactory (and Thyra::BelosLinearOpWithSolve)"
50 <<
"\nEchoing input options:"
51 <<
"\n matrixFile = " << matrixFile
52 <<
"\n numRhs = " << numRhs
53 <<
"\n numRandomVectors = " << numRandomVectors
54 <<
"\n maxFwdError = " << maxFwdError
55 <<
"\n maxResid = " << maxResid
56 <<
"\n showAllTests = " << showAllTests
57 <<
"\n dumpAll = " << dumpAll
61 if(out.
get()) *out <<
"\nA) Reading in a tpetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
63 using Scalar = double;
65 using MAT =
typename LOWS::MAT;
67 auto A_tpetra = Tpetra::MatrixMarket::Reader<MAT>::readSparseFile(matrixFile, comm);
68 auto domain_thyra = Thyra::tpetraVectorSpace<Scalar>(A_tpetra->getDomainMap());
69 auto range_thyra = Thyra::tpetraVectorSpace<Scalar>(A_tpetra->getRangeMap());
74 auto A_thyra = Thyra::constTpetraLinearOp(range_thyra_const, domain_thyra_const, A_tpetra_const);
78 if(out.
get()) *out <<
"\nB) Creating an Amesos2LinearOpWithSolveFactory object opFactory ...\n";
85 lowsFactory = amesos2LowsFactory;
89 *out <<
"\nlowsFactory.getValidParameters():\n";
90 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
91 *out <<
"\namesos2LOWSFPL before setting parameters:\n";
95 lowsFactory->setParameterList(
Teuchos::rcp(amesos2LOWSFPL,
false));
98 *out <<
"\namesos2LOWSFPL after setting parameters:\n";
102 if(out.
get()) *out <<
"\nC) Creating a Amesos2LinearOpWithSolve object nsA from A ...\n";
105 Thyra::initializeOp<Scalar>(*lowsFactory, A_thyra, nsA.
ptr());
107 if(out.
get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
109 LinearOpTester<Scalar> linearOpTester;
110 linearOpTester.check_adjoint(
false);
111 linearOpTester.num_rhs(numRhs);
112 linearOpTester.num_random_vectors(numRandomVectors);
113 linearOpTester.set_all_error_tol(maxFwdError);
114 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
115 linearOpTester.show_all_tests(showAllTests);
116 linearOpTester.dump_all(dumpAll);
117 Thyra::seed_randomize<Scalar>(0);
119 if(!result) success =
false;
121 if(out.
get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
123 LinearOpWithSolveTester<Scalar> linearOpWithSolveTester;
124 linearOpWithSolveTester.num_rhs(numRhs);
125 linearOpWithSolveTester.turn_off_all_tests();
126 linearOpWithSolveTester.check_forward_default(
true);
127 linearOpWithSolveTester.check_forward_residual(
true);
128 linearOpWithSolveTester.check_adjoint_default(
false);
129 linearOpWithSolveTester.check_adjoint_residual(
false);
130 linearOpWithSolveTester.set_all_solve_tol(maxResid);
131 linearOpWithSolveTester.set_all_slack_error_tol(maxResid);
132 linearOpWithSolveTester.set_all_slack_warning_tol(1e+1*maxResid);
133 linearOpWithSolveTester.forward_default_residual_error_tol(2*maxResid);
134 linearOpWithSolveTester.forward_default_solution_error_error_tol(maxSolutionError);
135 linearOpWithSolveTester.adjoint_default_residual_error_tol(2*maxResid);
136 linearOpWithSolveTester.adjoint_default_solution_error_error_tol(maxSolutionError);
137 linearOpWithSolveTester.show_all_tests(showAllTests);
138 linearOpWithSolveTester.dump_all(dumpAll);
139 Thyra::seed_randomize<Scalar>(0);
140 result = linearOpWithSolveTester.check(*nsA,out.
get());
141 if(!result) success =
false;
144 *out <<
"\namesos2LOWSFPL after solving:\n";
149 catch(
const std::exception &excpt ) {
150 if(out.
get()) *out << std::flush;
151 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)