14 #include "Thyra_BelosLinearOpWithSolveFactory.hpp"
15 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
17 #include "Thyra_LinearOpTester.hpp"
18 #include "Thyra_LinearOpWithSolveBase.hpp"
19 #include "Thyra_LinearOpWithSolveTester.hpp"
20 #include "Thyra_MultiVectorStdOps.hpp"
21 #include "Thyra_VectorStdOps.hpp"
22 #include "EpetraExt_readEpetraLinearSystem.h"
23 #include "Epetra_SerialComm.h"
25 #ifdef HAVE_BELOS_IFPACK
31 bool Thyra::test_single_belos_thyra_solver(
32 const std::string matrixFile
33 ,
const bool testTranspose
34 ,
const bool usePreconditioner
36 ,
const int numRandomVectors
37 ,
const double maxFwdError
38 ,
const double maxResid
39 ,
const double maxSolutionError
40 ,
const bool showAllTests
49 bool result, success =
true;
59 <<
"\n*** Testing Thyra::BelosLinearOpWithSolveFactory (and Thyra::BelosLinearOpWithSolve)"
61 <<
"\nEchoing input options:"
62 <<
"\n matrixFile = " << matrixFile
63 <<
"\n testTranspose = " << testTranspose
64 <<
"\n usePreconditioner = " << usePreconditioner
65 <<
"\n numRhs = " << numRhs
66 <<
"\n numRandomVectors = " << numRandomVectors
67 <<
"\n maxFwdError = " << maxFwdError
68 <<
"\n maxResid = " << maxResid
69 <<
"\n showAllTests = " << showAllTests
70 <<
"\n dumpAll = " << dumpAll
74 if(out.
get()) *out <<
"\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
76 Epetra_SerialComm comm;
78 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
84 if(out.
get()) *out <<
"\nB) Creating a BelosLinearOpWithSolveFactory object opFactory ...\n";
90 belosLowsFactory =
Teuchos::rcp(
new BelosLinearOpWithSolveFactory<double>());
91 lowsFactory = belosLowsFactory;
95 *out <<
"\nlowsFactory.getValidParameters() before setting preconditioner factory:\n";
96 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
99 if(usePreconditioner) {
100 #ifdef HAVE_BELOS_IFPACK
102 *out <<
"\nSetting an Ifpack preconditioner factory ...\n";
104 RCP<PreconditionerFactoryBase<double> >
105 precFactory =
Teuchos::rcp(
new IfpackPreconditionerFactory());
107 precFactory->setParameterList(
rcp(precPL,
false));
108 lowsFactory->setPreconditionerFactory(precFactory,
"Ifpack");
115 *out <<
"\nlowsFactory.getValidParameters() after setting preconditioner factory:\n";
116 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
117 *out <<
"\nbelosLOWSFPL before setting parameters:\n";
121 lowsFactory->setParameterList(
Teuchos::rcp(belosLOWSFPL,
false));
124 *out <<
"\nbelosLOWSFPL after setting parameters:\n";
128 if(out.
get()) *out <<
"\nC) Creating a BelosLinearOpWithSolve object nsA from A ...\n";
131 Thyra::initializeOp<double>(*lowsFactory, A, nsA.
ptr());
133 if(out.
get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
135 LinearOpTester<double> linearOpTester;
136 linearOpTester.check_adjoint(testTranspose);
137 linearOpTester.num_rhs(numRhs);
138 linearOpTester.num_random_vectors(numRandomVectors);
139 linearOpTester.set_all_error_tol(maxFwdError);
140 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
141 linearOpTester.show_all_tests(showAllTests);
142 linearOpTester.dump_all(dumpAll);
143 Thyra::seed_randomize<double>(0);
145 if(!result) success =
false;
147 if(out.
get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
149 LinearOpWithSolveTester<double> linearOpWithSolveTester;
150 linearOpWithSolveTester.num_rhs(numRhs);
151 linearOpWithSolveTester.turn_off_all_tests();
152 linearOpWithSolveTester.check_forward_default(
true);
153 linearOpWithSolveTester.check_forward_residual(
true);
155 linearOpWithSolveTester.check_adjoint_default(
true);
156 linearOpWithSolveTester.check_adjoint_residual(
true);
159 linearOpWithSolveTester.check_adjoint_default(
false);
160 linearOpWithSolveTester.check_adjoint_residual(
false);
162 linearOpWithSolveTester.set_all_solve_tol(maxResid);
163 linearOpWithSolveTester.set_all_slack_error_tol(maxResid);
164 linearOpWithSolveTester.set_all_slack_warning_tol(1e+1*maxResid);
165 linearOpWithSolveTester.forward_default_residual_error_tol(2*maxResid);
166 linearOpWithSolveTester.forward_default_solution_error_error_tol(maxSolutionError);
167 linearOpWithSolveTester.adjoint_default_residual_error_tol(2*maxResid);
168 linearOpWithSolveTester.adjoint_default_solution_error_error_tol(maxSolutionError);
169 linearOpWithSolveTester.show_all_tests(showAllTests);
170 linearOpWithSolveTester.dump_all(dumpAll);
171 Thyra::seed_randomize<double>(0);
172 result = linearOpWithSolveTester.check(*nsA,out.
get());
173 if(!result) success =
false;
176 *out <<
"\nbelosLOWSFPL after solving:\n";
182 if(out.
get()) *out <<
"\nTest failed since is was not even compiled since SUN_CXX was defined!\n";
188 catch(
const std::exception &excpt ) {
189 if(out.
get()) *out << std::flush;
190 std::cerr <<
"*** Caught standard exception : " << excpt.what() << std::endl;
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)