11 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
12 #include "Thyra_DefaultMultipliedLinearOp.hpp"
13 #include "Thyra_DefaultAddedLinearOp.hpp"
14 #include "Thyra_DefaultDiagonalLinearOp.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 #include "Thyra_TestingTools.hpp"
17 #include "Thyra_LinearOpTester.hpp"
21 #include "Thyra_DefaultIdentityLinearOp.hpp"
22 #include "EpetraExt_readEpetraLinearSystem.h"
30 # include "Epetra_MpiComm.h"
32 # include "Epetra_SerialComm.h"
44 using Thyra::epetraExtAddTransformer;
45 using Thyra::VectorBase;
46 using Thyra::LinearOpBase;
47 using Thyra::createMember;
48 using Thyra::LinearOpTester;
50 using Thyra::multiply;
51 using Thyra::diagonal;
54 std::string matrixFile =
"";
55 std::string matrixFile2 =
"";
61 "matrix-file", &matrixFile,
62 "Defines the Epetra_CrsMatrix to read in." );
64 "matrix-file-2", &matrixFile2,
65 "Defines the Epetra_CrsMatrix to read in." );
69 buildAddOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
A,
73 RCP<const Thyra::LinearOpBase<double> > M;
77 M = Thyra::add(
A,
B,
"A+B");
80 M = Thyra::add(
A,
B,
"A+adj(B)");
83 M = Thyra::add(
A,
B,
"adj(A)+B");
86 M = Thyra::add(
A,
B,
"adb(A)+adb(B)");
102 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
105 Epetra_MpiComm comm(MPI_COMM_WORLD);
107 Epetra_SerialComm comm;
109 RCP<Epetra_CrsMatrix> crsMat;
110 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &crsMat, NULL, NULL, NULL );
119 const RCP<const Thyra::LinearOpBase<double> >
A = Thyra::scale<double>(scaleMat,Thyra::epetraLinearOp(crsMat));
120 RCP<VectorBase<double> > d = createMember(A->domain(),
"d");
122 const RCP<const Thyra::LinearOpBase<double> >
B = diagonal(d);
124 out <<
"\nA = " << *A;
125 out <<
"\nB = " << *B;
127 for(
int scenario=0;scenario<4;scenario++) {
132 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
138 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
142 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
143 ApB_transformer->transform( *M, M_explicit.ptr() );
145 out <<
"\nM_explicit = " << *M_explicit;
151 LinearOpTester<double> M_explicit_tester;
152 M_explicit_tester.show_all_tests(
true);;
154 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
155 if (!result) success =
false;
158 for(
int scenario=0;scenario<4;scenario++) {
163 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,B,A);
169 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
173 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
174 ApB_transformer->transform( *M, M_explicit.ptr() );
176 out <<
"\nM_explicit = " << *M_explicit;
182 LinearOpTester<double> M_explicit_tester;
183 M_explicit_tester.show_all_tests(
true);;
185 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
186 if (!result) success =
false;
197 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
200 Epetra_MpiComm comm(MPI_COMM_WORLD);
202 Epetra_SerialComm comm;
204 RCP<Epetra_CrsMatrix> crsMat;
205 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &crsMat, NULL, NULL, NULL );
214 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleMat,Thyra::epetraLinearOp(crsMat));
215 const RCP<const Thyra::LinearOpBase<double> > B = identity(A->domain(),
"id");
217 out <<
"\nA = " << *A;
218 out <<
"\nB = " << *B;
220 for(
int scenario=0;scenario<4;scenario++) {
225 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
231 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
235 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
236 ApB_transformer->transform( *M, M_explicit.ptr() );
238 out <<
"\nM_explicit = " << *M_explicit;
244 LinearOpTester<double> M_explicit_tester;
245 M_explicit_tester.show_all_tests(
true);;
247 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
248 if (!result) success =
false;
251 for(
int scenario=0;scenario<4;scenario++) {
256 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,B,A);
262 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
266 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
267 ApB_transformer->transform( *M, M_explicit.ptr() );
269 out <<
"\nM_explicit = " << *M_explicit;
275 LinearOpTester<double> M_explicit_tester;
276 M_explicit_tester.show_all_tests(
true);;
278 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
279 if (!result) success =
false;
290 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
291 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
294 Epetra_MpiComm comm(MPI_COMM_WORLD);
296 Epetra_SerialComm comm;
298 RCP<Epetra_CrsMatrix> epetra_A;
299 RCP<Epetra_CrsMatrix> epetra_B;
300 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
301 EpetraExt::readEpetraLinearSystem( matrixFile2, comm, &epetra_B, NULL, NULL, NULL );
309 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleA,Thyra::epetraLinearOp(epetra_B));
310 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::scale<double>(scaleB,Thyra::epetraLinearOp(epetra_B));
312 out <<
"\nA = " << *A;
313 out <<
"\nB = " << *B;
315 for(
int scenario=0;scenario<4;scenario++) {
320 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
326 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
330 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
331 ApB_transformer->transform( *M, M_explicit.ptr() );
333 out <<
"\nM_explicit = " << *M_explicit;
339 LinearOpTester<double> M_explicit_tester;
340 M_explicit_tester.show_all_tests(
true);;
342 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
343 if (!result) success =
false;
354 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
355 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
358 Epetra_MpiComm comm(MPI_COMM_WORLD);
360 Epetra_SerialComm comm;
362 RCP<Epetra_CrsMatrix> epetra_A;
363 RCP<Epetra_CrsMatrix> epetra_B;
364 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
365 EpetraExt::readEpetraLinearSystem( matrixFile2, comm, &epetra_B, NULL, NULL, NULL );
373 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleA,Thyra::epetraLinearOp(epetra_B));
374 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::scale<double>(scaleB,Thyra::epetraLinearOp(epetra_B));
376 out <<
"\nA = " << *A;
377 out <<
"\nB = " << *B;
379 for(
int scenario=0;scenario<4;scenario++) {
384 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
390 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
394 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
395 const RCP<LinearOpBase<double> > M_explicit_orig = M_explicit;
396 ApB_transformer->transform( *M, M_explicit.ptr() );
399 double * view;
int numEntries;
400 epetra_B->Scale(3.2);
402 for(
int i=0;i<numEntries;i++) view[i] += view[i]*
double(i+1);
405 ApB_transformer->transform( *M, M_explicit.ptr() );
407 out <<
"\nM_explicit = " << *M_explicit;
416 LinearOpTester<double> M_explicit_tester;
417 M_explicit_tester.show_all_tests(
true);;
419 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
420 if (!result) success =
false;
static CommandLineProcessor & getCLP()
TEUCHOS_UNIT_TEST(EpetraOperatorWrapper, basic)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Teuchos::RCP< Epetra_Operator > get_Epetra_Operator(LinearOpBase< double > &op)
Full specialization for Scalar=double.
#define TEUCHOS_ASSERT(assertion_test)