46 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
47 #include "Thyra_DefaultMultipliedLinearOp.hpp"
48 #include "Thyra_DefaultAddedLinearOp.hpp"
49 #include "Thyra_DefaultDiagonalLinearOp.hpp"
50 #include "Thyra_VectorStdOps.hpp"
51 #include "Thyra_TestingTools.hpp"
52 #include "Thyra_LinearOpTester.hpp"
56 #include "Thyra_DefaultIdentityLinearOp.hpp"
57 #include "EpetraExt_readEpetraLinearSystem.h"
65 # include "Epetra_MpiComm.h"
67 # include "Epetra_SerialComm.h"
79 using Thyra::epetraExtAddTransformer;
80 using Thyra::VectorBase;
81 using Thyra::LinearOpBase;
82 using Thyra::createMember;
83 using Thyra::LinearOpTester;
85 using Thyra::multiply;
86 using Thyra::diagonal;
89 std::string matrixFile =
"";
90 std::string matrixFile2 =
"";
96 "matrix-file", &matrixFile,
97 "Defines the Epetra_CrsMatrix to read in." );
99 "matrix-file-2", &matrixFile2,
100 "Defines the Epetra_CrsMatrix to read in." );
104 buildAddOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
A,
108 RCP<const Thyra::LinearOpBase<double> > M;
112 M = Thyra::add(
A,
B,
"A+B");
115 M = Thyra::add(
A,
B,
"A+adj(B)");
118 M = Thyra::add(
A,
B,
"adj(A)+B");
121 M = Thyra::add(
A,
B,
"adb(A)+adb(B)");
137 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
140 Epetra_MpiComm comm(MPI_COMM_WORLD);
142 Epetra_SerialComm comm;
144 RCP<Epetra_CrsMatrix> crsMat;
145 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &crsMat, NULL, NULL, NULL );
154 const RCP<const Thyra::LinearOpBase<double> >
A = Thyra::scale<double>(scaleMat,Thyra::epetraLinearOp(crsMat));
155 RCP<VectorBase<double> > d = createMember(A->domain(),
"d");
157 const RCP<const Thyra::LinearOpBase<double> >
B = diagonal(d);
159 out <<
"\nA = " << *A;
160 out <<
"\nB = " << *B;
162 for(
int scenario=0;scenario<4;scenario++) {
167 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
173 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
177 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
178 ApB_transformer->transform( *M, M_explicit.ptr() );
180 out <<
"\nM_explicit = " << *M_explicit;
186 LinearOpTester<double> M_explicit_tester;
187 M_explicit_tester.show_all_tests(
true);;
189 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
190 if (!result) success =
false;
193 for(
int scenario=0;scenario<4;scenario++) {
198 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,B,A);
204 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
208 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
209 ApB_transformer->transform( *M, M_explicit.ptr() );
211 out <<
"\nM_explicit = " << *M_explicit;
217 LinearOpTester<double> M_explicit_tester;
218 M_explicit_tester.show_all_tests(
true);;
220 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
221 if (!result) success =
false;
232 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
235 Epetra_MpiComm comm(MPI_COMM_WORLD);
237 Epetra_SerialComm comm;
239 RCP<Epetra_CrsMatrix> crsMat;
240 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &crsMat, NULL, NULL, NULL );
249 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleMat,Thyra::epetraLinearOp(crsMat));
250 const RCP<const Thyra::LinearOpBase<double> > B = identity(A->domain(),
"id");
252 out <<
"\nA = " << *A;
253 out <<
"\nB = " << *B;
255 for(
int scenario=0;scenario<4;scenario++) {
260 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
266 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
270 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
271 ApB_transformer->transform( *M, M_explicit.ptr() );
273 out <<
"\nM_explicit = " << *M_explicit;
279 LinearOpTester<double> M_explicit_tester;
280 M_explicit_tester.show_all_tests(
true);;
282 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
283 if (!result) success =
false;
286 for(
int scenario=0;scenario<4;scenario++) {
291 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,B,A);
297 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
301 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
302 ApB_transformer->transform( *M, M_explicit.ptr() );
304 out <<
"\nM_explicit = " << *M_explicit;
310 LinearOpTester<double> M_explicit_tester;
311 M_explicit_tester.show_all_tests(
true);;
313 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
314 if (!result) success =
false;
325 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
326 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
329 Epetra_MpiComm comm(MPI_COMM_WORLD);
331 Epetra_SerialComm comm;
333 RCP<Epetra_CrsMatrix> epetra_A;
334 RCP<Epetra_CrsMatrix> epetra_B;
335 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
336 EpetraExt::readEpetraLinearSystem( matrixFile2, comm, &epetra_B, NULL, NULL, NULL );
344 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleA,Thyra::epetraLinearOp(epetra_B));
345 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::scale<double>(scaleB,Thyra::epetraLinearOp(epetra_B));
347 out <<
"\nA = " << *A;
348 out <<
"\nB = " << *B;
350 for(
int scenario=0;scenario<4;scenario++) {
355 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
361 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
365 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
366 ApB_transformer->transform( *M, M_explicit.ptr() );
368 out <<
"\nM_explicit = " << *M_explicit;
374 LinearOpTester<double> M_explicit_tester;
375 M_explicit_tester.show_all_tests(
true);;
377 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inOutArg(out) );
378 if (!result) success =
false;
389 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
390 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
393 Epetra_MpiComm comm(MPI_COMM_WORLD);
395 Epetra_SerialComm comm;
397 RCP<Epetra_CrsMatrix> epetra_A;
398 RCP<Epetra_CrsMatrix> epetra_B;
399 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
400 EpetraExt::readEpetraLinearSystem( matrixFile2, comm, &epetra_B, NULL, NULL, NULL );
408 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::scale<double>(scaleA,Thyra::epetraLinearOp(epetra_B));
409 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::scale<double>(scaleB,Thyra::epetraLinearOp(epetra_B));
411 out <<
"\nA = " << *A;
412 out <<
"\nB = " << *B;
414 for(
int scenario=0;scenario<4;scenario++) {
419 const RCP<const Thyra::LinearOpBase<double> > M = buildAddOperator(scenario,A,B);
425 const RCP<EpetraExtAddTransformer> ApB_transformer = epetraExtAddTransformer();
429 const RCP<LinearOpBase<double> > M_explicit = ApB_transformer->createOutputOp();
430 const RCP<LinearOpBase<double> > M_explicit_orig = M_explicit;
431 ApB_transformer->transform( *M, M_explicit.ptr() );
434 double * view;
int numEntries;
435 epetra_B->Scale(3.2);
437 for(
int i=0;i<numEntries;i++) view[i] += view[i]*
double(i+1);
440 ApB_transformer->transform( *M, M_explicit.ptr() );
442 out <<
"\nM_explicit = " << *M_explicit;
451 LinearOpTester<double> M_explicit_tester;
452 M_explicit_tester.show_all_tests(
true);;
454 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
455 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)