46 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
47 #include "Thyra_DefaultMultipliedLinearOp.hpp"
48 #include "Thyra_DefaultDiagonalLinearOp.hpp"
49 #include "Thyra_VectorStdOps.hpp"
50 #include "Thyra_TestingTools.hpp"
51 #include "Thyra_LinearOpTester.hpp"
54 #include "EpetraExt_readEpetraLinearSystem.h"
62 # include "Epetra_MpiComm.h"
64 # include "Epetra_SerialComm.h"
76 using Thyra::epetraExtDiagScaledMatProdTransformer;
77 using Thyra::VectorBase;
78 using Thyra::LinearOpBase;
79 using Thyra::createMember;
80 using Thyra::LinearOpTester;
82 using Thyra::multiply;
83 using Thyra::diagonal;
86 std::string matrixFile =
"";
87 std::string matrixFile2 =
"";
93 "matrix-file", &matrixFile,
94 "Defines the Epetra_CrsMatrix to read in." );
96 "matrix-file-2", &matrixFile2,
97 "Defines the second Epetra_CrsMatrix to read in." );
102 buildBDGOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
103 const Teuchos::RCP<
const Thyra::LinearOpBase<double> > & G,
104 const double vecScale, std::ostream & out)
111 RCP<const LinearOpBase<double> > M;
112 RCP<VectorBase<double> > d;
114 d = createMember(
B->domain(),
"d");
116 d = createMember(
B->range(),
"d");
117 V_S( d.ptr(), vecScale );
123 M = multiply( scale(scalea,
B), diagonal(d), scale(scaleb,G),
"M" );
124 out <<
" Testing B*D*G" << std::endl;
127 M = multiply( scale(scalea,
B), diagonal(d), adjoint(G),
"M" );
128 out <<
" Testing B*D*adj(G)" << std::endl;
131 M = multiply( adjoint(
B), diagonal(d), scale(scaleb,G),
"M" );
132 out <<
" Testing adj(B)*D*G" << std::endl;
135 M = multiply( adjoint(
B), diagonal(d), adjoint(G),
"M" );
136 out <<
" Testing adj(B)*D*adj(G)" << std::endl;
139 M = multiply(
B, scale(scaled,diagonal(d)), G,
"M" );
140 out <<
" Testing B*(52.0*D)*G" << std::endl;
146 out <<
"\nM = " << *M;
153 buildBGOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
154 const Teuchos::RCP<
const Thyra::LinearOpBase<double> > & G,
160 RCP<const LinearOpBase<double> > M;
166 M = multiply( scale(scalea,
B), scale(scaleb,G),
"M" );
167 out <<
" Testing B*G" << std::endl;
170 M = multiply( scale(scalea,
B), adjoint(G),
"M" );
171 out <<
" Testing B*adj(G)" << std::endl;
174 M = multiply( adjoint(
B), scale(scaleb,G),
"M" );
175 out <<
" Testing adj(B)*G" << std::endl;
178 M = multiply( adjoint(
B), adjoint(G),
"M" );
179 out <<
" Testing adj(B)*adj(G)" << std::endl;
185 out <<
"\nM = " << *M;
191 buildBDBOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
192 const double vecScale, std::ostream & out)
194 return buildBDGOperator(scenario,
B,
B,vecScale,out);
206 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
209 Epetra_MpiComm comm(MPI_COMM_WORLD);
211 Epetra_SerialComm comm;
213 RCP<Epetra_CrsMatrix> epetra_B;
214 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
220 const RCP<const Thyra::LinearOpBase<double> >
B = Thyra::epetraLinearOp(epetra_B);
229 for(
int scenario=1;scenario<=5;scenario++) {
230 const RCP<const Thyra::LinearOpBase<double> > M = buildBDBOperator(scenario,B,4.5,out);
236 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
241 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
243 BtDB_transformer->transform( *M, M_explicit.ptr() );
245 out <<
"\nM_explicit = " << *M_explicit;
251 LinearOpTester<double> M_explicit_tester;
252 M_explicit_tester.show_all_tests(
true);;
254 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
255 if (!result) success =
false;
267 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'";
268 out <<
" and from the file \'"<<matrixFile2<<
"\' ...\n";
271 Epetra_MpiComm comm(MPI_COMM_WORLD);
273 Epetra_SerialComm comm;
275 RCP<Epetra_CrsMatrix> epetra_B;
276 RCP<Epetra_CrsMatrix> epetra_G;
277 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
278 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
284 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::epetraLinearOp(epetra_B);
285 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
292 for(
int scenario=1;scenario<=3;scenario++) {
293 RCP<const Thyra::LinearOpBase<double> > M;
294 if(scenario==1 || scenario==3)
295 M = buildBDGOperator(scenario,B,G,4.5,out);
297 M = buildBDGOperator(scenario,G,B,4.5,out);
303 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
308 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
310 BtDB_transformer->transform( *M, M_explicit.ptr() );
312 out <<
"\nM_explicit = " << *M_explicit;
318 LinearOpTester<double> M_explicit_tester;
319 M_explicit_tester.show_all_tests(
true);;
321 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
322 if (!result) success =
false;
334 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
337 Epetra_MpiComm comm(MPI_COMM_WORLD);
339 Epetra_SerialComm comm;
341 RCP<Epetra_CrsMatrix> epetra_G;
342 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
348 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
355 int scenes[] = {1,4};
356 for(
int i=0;i<2;i++) {
357 int scenario = scenes[i];
358 const RCP<const Thyra::LinearOpBase<double> > M = buildBDGOperator(scenario,G,G,4.5,out);
364 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
369 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
371 BtDB_transformer->transform( *M, M_explicit.ptr() );
373 out <<
"\nM_explicit = " << *M_explicit;
379 LinearOpTester<double> M_explicit_tester;
380 M_explicit_tester.show_all_tests(
true);;
382 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
383 if (!result) success =
false;
395 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'";
396 out <<
" and from the file \'"<<matrixFile2<<
"\' ...\n";
399 Epetra_MpiComm comm(MPI_COMM_WORLD);
401 Epetra_SerialComm comm;
403 RCP<Epetra_CrsMatrix> epetra_B;
404 RCP<Epetra_CrsMatrix> epetra_G;
405 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
406 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
412 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::epetraLinearOp(epetra_B);
413 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
420 for(
int scenario=1;scenario<=4;scenario++) {
421 RCP<const Thyra::LinearOpBase<double> > M;
422 if(scenario==1 || scenario==3)
423 M = buildBGOperator(scenario,B,G,out);
425 M = buildBGOperator(scenario,G,B,out);
427 M = buildBGOperator(scenario,G,G,out);
433 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
438 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
440 BtDB_transformer->transform( *M, M_explicit.ptr() );
442 out <<
"\nM_explicit = " << *M_explicit;
448 LinearOpTester<double> M_explicit_tester;
449 M_explicit_tester.show_all_tests(
true);;
451 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
452 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)
#define TEUCHOS_ASSERT(assertion_test)