47 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
48 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
49 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
50 #include "Thyra_DefaultInverseLinearOp.hpp"
52 #include "Thyra_LinearOpTester.hpp"
53 #include "Thyra_LinearOpWithSolveTester.hpp"
54 #include "EpetraExt_readEpetraLinearSystem.h"
56 #include "Epetra_MpiComm.h"
58 #include "Epetra_SerialComm.h"
63 bool Thyra::test_single_amesos_thyra_solver(
64 const std::string matrixFile
66 ,
const bool testTranspose_in
67 ,
const int numRandomVectors
68 ,
const double maxFwdError
69 ,
const double maxError
70 ,
const double maxResid
71 ,
const bool showAllTests
80 bool result, success =
true;
82 RCP<Teuchos::FancyOStream>
90 <<
"\n*** Testing Thyra::AmesosLinearOpWithSolveFactory (and Thyra::AmesosLinearOpWithSolve)"
92 <<
"\nEchoing input options:"
93 <<
"\n matrixFile = " << matrixFile
94 <<
"\n testTranspose = " << testTranspose_in
95 <<
"\n numRandomVectors = " << numRandomVectors
96 <<
"\n maxFwdError = " << maxFwdError
97 <<
"\n maxError = " << maxError
98 <<
"\n maxResid = " << maxResid
99 <<
"\n showAllTests = " << showAllTests
100 <<
"\n dumpAll = " << dumpAll
105 <<
"amesosLOWSFPL:\n";
110 if(out.get()) *out <<
"\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
113 Epetra_MpiComm comm(MPI_COMM_WORLD);
115 Epetra_SerialComm comm;
117 RCP<Epetra_CrsMatrix> epetra_A;
118 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
120 RCP<const LinearOpBase<double> >
121 A = Thyra::epetraLinearOp(epetra_A);
125 if(out.get()) *out <<
"\nB) Creating a AmesosLinearOpWithSolveFactory object lowsFactory ...\n";
127 RCP<LinearOpWithSolveFactoryBase<double> >
128 lowsFactory =
Teuchos::rcp(
new AmesosLinearOpWithSolveFactory());
130 lowsFactory->setParameterList(
Teuchos::rcp(amesosLOWSFPL,
false));
133 *out <<
"\nlowsFactory.description() = " << lowsFactory->description() << std::endl;
134 *out <<
"\nlowsFactory.getValidParameters() =\n";
135 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
138 if(out.get()) *out <<
"\nC) Creating a AmesosLinearOpWithSolve object nsA ...\n";
140 RCP<LinearOpWithSolveBase<double> >
141 nsA = lowsFactory->createOp();
143 initializeOp<double>(*lowsFactory, A, nsA.ptr());
145 bool testTranspose = testTranspose_in;
146 if (testTranspose_in && !Thyra::solveSupports(*nsA, Thyra::CONJTRANS)) {
148 <<
"\nChanging testTranspose=false since "
149 << nsA->description() <<
" does not support adjoint solves!\n";
150 testTranspose =
false;
153 if(out.get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
155 Thyra::seed_randomize<double>(0);
157 LinearOpTester<double> linearOpTester;
158 linearOpTester.check_adjoint(testTranspose);
159 linearOpTester.num_random_vectors(numRandomVectors);
160 linearOpTester.set_all_error_tol(maxFwdError);
161 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
162 linearOpTester.show_all_tests(showAllTests);
163 linearOpTester.dump_all(dumpAll);
164 result = linearOpTester.check(*nsA,out());
165 if(!result) success =
false;
167 if(out.get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
169 LinearOpWithSolveTester<double> linearOpWithSolveTester;
170 linearOpWithSolveTester.turn_off_all_tests();
171 linearOpWithSolveTester.check_forward_default(
true);
172 linearOpWithSolveTester.forward_default_residual_error_tol(1.1*maxResid);
173 linearOpWithSolveTester.forward_default_residual_warning_tol(2.0*maxResid);
174 linearOpWithSolveTester.check_forward_residual(
true);
175 linearOpWithSolveTester.forward_residual_solve_tol(maxResid);
176 linearOpWithSolveTester.forward_residual_slack_error_tol(1e-1*maxResid);
177 linearOpWithSolveTester.forward_residual_slack_warning_tol(maxResid);
178 linearOpWithSolveTester.check_adjoint_default(testTranspose);
179 linearOpWithSolveTester.adjoint_default_residual_error_tol(1.1*maxResid);
180 linearOpWithSolveTester.adjoint_default_residual_warning_tol(2.0*maxResid);
181 linearOpWithSolveTester.check_adjoint_residual(testTranspose);
182 linearOpWithSolveTester.adjoint_residual_solve_tol(maxResid);
183 linearOpWithSolveTester.adjoint_residual_slack_error_tol(1e-1*maxResid);
184 linearOpWithSolveTester.adjoint_residual_slack_warning_tol(maxResid);
185 linearOpWithSolveTester.num_random_vectors(numRandomVectors);
186 linearOpWithSolveTester.show_all_tests(showAllTests);
187 linearOpWithSolveTester.dump_all(dumpAll);
189 LinearOpWithSolveTester<double> adjLinearOpWithSolveTester(linearOpWithSolveTester);
190 adjLinearOpWithSolveTester.check_forward_default(testTranspose);
191 adjLinearOpWithSolveTester.check_forward_residual(testTranspose);
193 result = linearOpWithSolveTester.check(*nsA,out.get());
194 if(!result) success =
false;
196 if(out.get()) *out <<
"\nF) Uninitialize the matrix object nsA, scale the epetra_A object by 2.5, and then refactor nsA with epetra_A ...\n";
198 uninitializeOp<double>(*lowsFactory, nsA.ptr());
199 epetra_A->Scale(2.5);
200 initializeOp<double>(*lowsFactory, A, nsA.ptr());
202 if(out.get()) *out <<
"\nG) Testing the LinearOpBase interface of nsA ...\n";
204 Thyra::seed_randomize<double>(0);
206 result = linearOpTester.check(*nsA, out());
207 if(!result) success =
false;
209 if(out.get()) *out <<
"\nH) Testing the LinearOpWithSolveBase interface of nsA ...\n";
211 result = linearOpWithSolveTester.check(*nsA,out.get());
212 if(!result) success =
false;
214 if(out.get()) *out <<
"\nI) Uninitialize the matrix object nsA, create a scaled (by 2.5) copy epetra_A2 of epetra_A, and then refactor nsA with epetra_A2 ...\n";
216 RCP<Epetra_CrsMatrix>
217 epetra_A2 =
Teuchos::rcp(
new Epetra_CrsMatrix(*epetra_A));
218 epetra_A2->Scale(2.5);
219 RCP<const LinearOpBase<double> >
220 A2 = Thyra::epetraLinearOp(epetra_A2);
221 initializeOp<double>(*lowsFactory, A2, nsA.ptr());
223 if(out.get()) *out <<
"\nJ) Testing the LinearOpBase interface of nsA ...\n";
225 Thyra::seed_randomize<double>(0);
227 result = linearOpTester.check(*nsA, out());
228 if(!result) success =
false;
230 if(out.get()) *out <<
"\nK) Testing the LinearOpWithSolveBase interface of nsA ...\n";
232 result = linearOpWithSolveTester.check(*nsA, out.get());
233 if(!result) success =
false;
235 if(out.get()) *out <<
"\nL) Create an implicitly scaled (by 2.5) and transposed matrix A3 = scale(2.5,transpose(A)) and initialize nsA2 ...\n";
237 RCP<const LinearOpBase<double> >
238 A3 = scale<double>(2.5,Thyra::transpose<double>(A));
239 RCP<LinearOpWithSolveBase<double> >
240 nsA2 = linearOpWithSolve(*lowsFactory,A3);
242 if(out.get()) *out <<
"\nM) Testing the LinearOpBase interface of nsA2 ...\n";
244 Thyra::seed_randomize<double>(0);
246 result = linearOpTester.check(*nsA2,out());
247 if(!result) success =
false;
249 if(out.get()) *out <<
"\nN) Testing the LinearOpWithSolveBase interface of nsA2 ...\n";
251 result = adjLinearOpWithSolveTester.check(*nsA2,out.get());
252 if(!result) success =
false;
254 if(out.get()) *out <<
"\nO) Testing that LinearOpBase interfaces of transpose(nsA) == nsA2 ...\n";
256 result = linearOpTester.compare(
257 *transpose(Teuchos::rcp_implicit_cast<
const LinearOpBase<double> >(nsA)),*nsA2
260 if(!result) success =
false;
262 if(out.get()) *out <<
"\nP) Running example use cases ...\n";
264 nonExternallyPreconditionedLinearSolveUseCases(
265 *A,*lowsFactory,
true,*out
268 if(out.get()) *out <<
"\nQ) Creating a DefaultInverseLinearOp object from nsA and testing the LinearOpBase interface ...\n";
270 RCP<const LinearOpBase<double> >
271 invA = inverse<double>(nsA.getConst());
273 result = linearOpTester.check(*invA,out());
274 if(!result) success =
false;
278 if(out.get()) *out <<
"\nTest failed since is was not even compiled since SUN_CXX was defined!\n";
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)