15 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
16 #include "Thyra_LinearOpWithSolveFactoryExamples.hpp"
17 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
18 #include "Thyra_DefaultInverseLinearOp.hpp"
20 #include "Thyra_LinearOpTester.hpp"
21 #include "Thyra_LinearOpWithSolveTester.hpp"
22 #include "EpetraExt_readEpetraLinearSystem.h"
24 #include "Epetra_MpiComm.h"
26 #include "Epetra_SerialComm.h"
31 bool Thyra::test_single_amesos_thyra_solver(
32 const std::string matrixFile
34 ,
const bool testTranspose_in
35 ,
const int numRandomVectors
36 ,
const double maxFwdError
37 ,
const double maxError
38 ,
const double maxResid
39 ,
const bool showAllTests
48 bool result, success =
true;
50 RCP<Teuchos::FancyOStream>
58 <<
"\n*** Testing Thyra::AmesosLinearOpWithSolveFactory (and Thyra::AmesosLinearOpWithSolve)"
60 <<
"\nEchoing input options:"
61 <<
"\n matrixFile = " << matrixFile
62 <<
"\n testTranspose = " << testTranspose_in
63 <<
"\n numRandomVectors = " << numRandomVectors
64 <<
"\n maxFwdError = " << maxFwdError
65 <<
"\n maxError = " << maxError
66 <<
"\n maxResid = " << maxResid
67 <<
"\n showAllTests = " << showAllTests
68 <<
"\n dumpAll = " << dumpAll
73 <<
"amesosLOWSFPL:\n";
78 if(out.get()) *out <<
"\nA) Reading in an epetra matrix A from the file \'"<<matrixFile<<
"\' ...\n";
81 Epetra_MpiComm comm(MPI_COMM_WORLD);
83 Epetra_SerialComm comm;
85 RCP<Epetra_CrsMatrix> epetra_A;
86 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A );
88 RCP<const LinearOpBase<double> >
89 A = Thyra::epetraLinearOp(epetra_A);
93 if(out.get()) *out <<
"\nB) Creating a AmesosLinearOpWithSolveFactory object lowsFactory ...\n";
95 RCP<LinearOpWithSolveFactoryBase<double> >
96 lowsFactory =
Teuchos::rcp(
new AmesosLinearOpWithSolveFactory());
98 lowsFactory->setParameterList(
Teuchos::rcp(amesosLOWSFPL,
false));
101 *out <<
"\nlowsFactory.description() = " << lowsFactory->description() << std::endl;
102 *out <<
"\nlowsFactory.getValidParameters() =\n";
103 lowsFactory->getValidParameters()->print(
OSTab(out).o(),0,
true,
false);
106 if(out.get()) *out <<
"\nC) Creating a AmesosLinearOpWithSolve object nsA ...\n";
108 RCP<LinearOpWithSolveBase<double> >
109 nsA = lowsFactory->createOp();
111 initializeOp<double>(*lowsFactory, A, nsA.ptr());
113 bool testTranspose = testTranspose_in;
114 if (testTranspose_in && !Thyra::solveSupports(*nsA, Thyra::CONJTRANS)) {
116 <<
"\nChanging testTranspose=false since "
117 << nsA->description() <<
" does not support adjoint solves!\n";
118 testTranspose =
false;
121 if(out.get()) *out <<
"\nD) Testing the LinearOpBase interface of nsA ...\n";
123 Thyra::seed_randomize<double>(0);
125 LinearOpTester<double> linearOpTester;
126 linearOpTester.check_adjoint(testTranspose);
127 linearOpTester.num_random_vectors(numRandomVectors);
128 linearOpTester.set_all_error_tol(maxFwdError);
129 linearOpTester.set_all_warning_tol(1e-2*maxFwdError);
130 linearOpTester.show_all_tests(showAllTests);
131 linearOpTester.dump_all(dumpAll);
132 result = linearOpTester.check(*nsA,out());
133 if(!result) success =
false;
135 if(out.get()) *out <<
"\nE) Testing the LinearOpWithSolveBase interface of nsA ...\n";
137 LinearOpWithSolveTester<double> linearOpWithSolveTester;
138 linearOpWithSolveTester.turn_off_all_tests();
139 linearOpWithSolveTester.check_forward_default(
true);
140 linearOpWithSolveTester.forward_default_residual_error_tol(1.1*maxResid);
141 linearOpWithSolveTester.forward_default_residual_warning_tol(2.0*maxResid);
142 linearOpWithSolveTester.check_forward_residual(
true);
143 linearOpWithSolveTester.forward_residual_solve_tol(maxResid);
144 linearOpWithSolveTester.forward_residual_slack_error_tol(1e-1*maxResid);
145 linearOpWithSolveTester.forward_residual_slack_warning_tol(maxResid);
146 linearOpWithSolveTester.check_adjoint_default(testTranspose);
147 linearOpWithSolveTester.adjoint_default_residual_error_tol(1.1*maxResid);
148 linearOpWithSolveTester.adjoint_default_residual_warning_tol(2.0*maxResid);
149 linearOpWithSolveTester.check_adjoint_residual(testTranspose);
150 linearOpWithSolveTester.adjoint_residual_solve_tol(maxResid);
151 linearOpWithSolveTester.adjoint_residual_slack_error_tol(1e-1*maxResid);
152 linearOpWithSolveTester.adjoint_residual_slack_warning_tol(maxResid);
153 linearOpWithSolveTester.num_random_vectors(numRandomVectors);
154 linearOpWithSolveTester.show_all_tests(showAllTests);
155 linearOpWithSolveTester.dump_all(dumpAll);
157 LinearOpWithSolveTester<double> adjLinearOpWithSolveTester(linearOpWithSolveTester);
158 adjLinearOpWithSolveTester.check_forward_default(testTranspose);
159 adjLinearOpWithSolveTester.check_forward_residual(testTranspose);
161 result = linearOpWithSolveTester.check(*nsA,out.get());
162 if(!result) success =
false;
164 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";
166 uninitializeOp<double>(*lowsFactory, nsA.ptr());
167 epetra_A->Scale(2.5);
168 initializeOp<double>(*lowsFactory, A, nsA.ptr());
170 if(out.get()) *out <<
"\nG) Testing the LinearOpBase interface of nsA ...\n";
172 Thyra::seed_randomize<double>(0);
174 result = linearOpTester.check(*nsA, out());
175 if(!result) success =
false;
177 if(out.get()) *out <<
"\nH) Testing the LinearOpWithSolveBase interface of nsA ...\n";
179 result = linearOpWithSolveTester.check(*nsA,out.get());
180 if(!result) success =
false;
182 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";
184 RCP<Epetra_CrsMatrix>
185 epetra_A2 =
Teuchos::rcp(
new Epetra_CrsMatrix(*epetra_A));
186 epetra_A2->Scale(2.5);
187 RCP<const LinearOpBase<double> >
188 A2 = Thyra::epetraLinearOp(epetra_A2);
189 initializeOp<double>(*lowsFactory, A2, nsA.ptr());
191 if(out.get()) *out <<
"\nJ) Testing the LinearOpBase interface of nsA ...\n";
193 Thyra::seed_randomize<double>(0);
195 result = linearOpTester.check(*nsA, out());
196 if(!result) success =
false;
198 if(out.get()) *out <<
"\nK) Testing the LinearOpWithSolveBase interface of nsA ...\n";
200 result = linearOpWithSolveTester.check(*nsA, out.get());
201 if(!result) success =
false;
203 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";
205 RCP<const LinearOpBase<double> >
206 A3 = scale<double>(2.5,Thyra::transpose<double>(A));
207 RCP<LinearOpWithSolveBase<double> >
208 nsA2 = linearOpWithSolve(*lowsFactory,A3);
210 if(out.get()) *out <<
"\nM) Testing the LinearOpBase interface of nsA2 ...\n";
212 Thyra::seed_randomize<double>(0);
214 result = linearOpTester.check(*nsA2,out());
215 if(!result) success =
false;
217 if(out.get()) *out <<
"\nN) Testing the LinearOpWithSolveBase interface of nsA2 ...\n";
219 result = adjLinearOpWithSolveTester.check(*nsA2,out.get());
220 if(!result) success =
false;
222 if(out.get()) *out <<
"\nO) Testing that LinearOpBase interfaces of transpose(nsA) == nsA2 ...\n";
224 result = linearOpTester.compare(
225 *transpose(Teuchos::rcp_implicit_cast<
const LinearOpBase<double> >(nsA)),*nsA2
228 if(!result) success =
false;
230 if(out.get()) *out <<
"\nP) Running example use cases ...\n";
232 nonExternallyPreconditionedLinearSolveUseCases(
233 *A,*lowsFactory,
true,*out
236 if(out.get()) *out <<
"\nQ) Creating a DefaultInverseLinearOp object from nsA and testing the LinearOpBase interface ...\n";
238 RCP<const LinearOpBase<double> >
239 invA = inverse<double>(nsA.getConst());
241 result = linearOpTester.check(*invA,out());
242 if(!result) success =
false;
246 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)