66 const std::string matrixFile
67 ,
const bool testTranspose
68 ,
const bool usePreconditioner
70 ,
const int numRandomVectors
71 ,
const double maxFwdError
72 ,
const double maxResid
73 ,
const double maxSolutionError
74 ,
const bool showAllTests
76 ,Teuchos::ParameterList *belosLOWSFPL
77 ,Teuchos::ParameterList *precPL
78 ,Teuchos::FancyOStream *out_arg
83 bool result, success =
true;
85 Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::rcp(out_arg,
false);
93 <<
"\n*** Testing Thyra::BelosLinearOpWithSolveFactory (and Thyra::BelosLinearOpWithSolve)"
95 <<
"\nEchoing input options:"
96 <<
"\n matrixFile = " << matrixFile
97 <<
"\n testTranspose = " << testTranspose
98 <<
"\n usePreconditioner = " << usePreconditioner
99 <<
"\n numRhs = " << numRhs
100 <<
"\n numRandomVectors = " << numRandomVectors
101 <<
"\n maxFwdError = " << maxFwdError
102 <<
"\n maxResid = " << maxResid
103 <<
"\n showAllTests = " << showAllTests
104 <<
"\n dumpAll = " << dumpAll
108 if(out.get()) *out <<
"\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
110 Epetra_SerialComm comm;
111 Teuchos::RCP<Epetra_CrsMatrix> epetra_A;
112 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
114 Teuchos::RCP<const LinearOpBase<double> > A = epetraLinearOp(epetra_A);
116 if(out.get() && dumpAll) *out <<
"\ndescribe(A) =\n" << describe(*A,Teuchos::VERB_EXTREME);
118 if(out.get()) *out <<
"\nB) Creating a BelosLinearOpWithSolveFactory object opFactory ...\n";
120 Teuchos::RCP<LinearOpWithSolveFactoryBase<double> >
123 Teuchos::RCP<BelosLinearOpWithSolveFactory<double> >
124 belosLowsFactory = Teuchos::rcp(
new BelosLinearOpWithSolveFactory<double>());
125 lowsFactory = belosLowsFactory;
129 *out <<
"\nlowsFactory.getValidParameters() before setting preconditioner factory:\n";
130 lowsFactory->getValidParameters()->print(OSTab(out).o(),0,
true,
false);
133 if(usePreconditioner) {
134#ifdef HAVE_BELOS_IFPACK
136 *out <<
"\nSetting an Ifpack preconditioner factory ...\n";
138 RCP<PreconditionerFactoryBase<double> >
141 precFactory->setParameterList(rcp(precPL,
false));
142 lowsFactory->setPreconditionerFactory(precFactory,
"Ifpack");
144 TEUCHOS_TEST_FOR_EXCEPT(usePreconditioner);
149 *out <<
"\nlowsFactory.getValidParameters() after setting preconditioner factory:\n";
150 lowsFactory->getValidParameters()->print(OSTab(out).o(),0,
true,
false);
151 *out <<
"\nbelosLOWSFPL before setting parameters:\n";
152 belosLOWSFPL->print(OSTab(out).o(),0,
true);
155 lowsFactory->setParameterList(Teuchos::rcp(belosLOWSFPL,
false));
158 *out <<
"\nbelosLOWSFPL after setting parameters:\n";
159 belosLOWSFPL->print(OSTab(out).o(),0,
true);
162 if(out.get()) *out <<
"\nC) Creating a BelosLinearOpWithSolve object nsA from A ...\n";
164 Teuchos::RCP<LinearOpWithSolveBase<double> > nsA = lowsFactory->createOp();
165 Thyra::initializeOp<double>(*lowsFactory, A, nsA.ptr());
167 if(out.get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
169 LinearOpTester<double> linearOpTester;
170 linearOpTester.check_adjoint(testTranspose);
171 linearOpTester.num_rhs(numRhs);
172 linearOpTester.num_random_vectors(numRandomVectors);
173 linearOpTester.set_all_error_tol(maxFwdError);
174 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
175 linearOpTester.show_all_tests(showAllTests);
176 linearOpTester.dump_all(dumpAll);
177 Thyra::seed_randomize<double>(0);
178 result = linearOpTester.check(*nsA,Teuchos::Ptr<Teuchos::FancyOStream>(out.get()));
179 if(!result) success =
false;
181 if(out.get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
183 LinearOpWithSolveTester<double> linearOpWithSolveTester;
184 linearOpWithSolveTester.num_rhs(numRhs);
185 linearOpWithSolveTester.turn_off_all_tests();
186 linearOpWithSolveTester.check_forward_default(
true);
187 linearOpWithSolveTester.check_forward_residual(
true);
189 linearOpWithSolveTester.check_adjoint_default(
true);
190 linearOpWithSolveTester.check_adjoint_residual(
true);
193 linearOpWithSolveTester.check_adjoint_default(
false);
194 linearOpWithSolveTester.check_adjoint_residual(
false);
196 linearOpWithSolveTester.set_all_solve_tol(maxResid);
197 linearOpWithSolveTester.set_all_slack_error_tol(maxResid);
198 linearOpWithSolveTester.set_all_slack_warning_tol(1e+1*maxResid);
199 linearOpWithSolveTester.forward_default_residual_error_tol(2*maxResid);
200 linearOpWithSolveTester.forward_default_solution_error_error_tol(maxSolutionError);
201 linearOpWithSolveTester.adjoint_default_residual_error_tol(2*maxResid);
202 linearOpWithSolveTester.adjoint_default_solution_error_error_tol(maxSolutionError);
203 linearOpWithSolveTester.show_all_tests(showAllTests);
204 linearOpWithSolveTester.dump_all(dumpAll);
205 Thyra::seed_randomize<double>(0);
206 result = linearOpWithSolveTester.check(*nsA,out.get());
207 if(!result) success =
false;
210 *out <<
"\nbelosLOWSFPL after solving:\n";
211 belosLOWSFPL->print(OSTab(out).o(),0,
true);
216 if(out.get()) *out <<
"\nTest failed since is was not even compiled since SUN_CXX was defined!\n";
222 catch(
const std::exception &excpt ) {
223 if(out.get()) *out << std::flush;
224 std::cerr <<
"*** Caught standard exception : " << excpt.what() << std::endl;
bool test_single_belos_thyra_solver(const std::string matrixFile, const bool testTranspose, const bool usePreconditioner, const int numRhs, const int numRandomVectors, const double maxFwdError, const double maxResid, const double maxSolutionError, const bool showAllTests, const bool dumpAll, Teuchos::ParameterList *belosLOWSFPL, Teuchos::ParameterList *precPL, Teuchos::FancyOStream *out)
Testing function for a single belos solver with a single matrix.