11 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
12 #include "Thyra_DefaultMultipliedLinearOp.hpp"
13 #include "Thyra_DefaultDiagonalLinearOp.hpp"
14 #include "Thyra_VectorStdOps.hpp"
15 #include "Thyra_TestingTools.hpp"
16 #include "Thyra_LinearOpTester.hpp"
19 #include "EpetraExt_readEpetraLinearSystem.h"
27 # include "Epetra_MpiComm.h"
29 # include "Epetra_SerialComm.h"
41 using Thyra::epetraExtDiagScaledMatProdTransformer;
42 using Thyra::VectorBase;
43 using Thyra::LinearOpBase;
44 using Thyra::createMember;
45 using Thyra::LinearOpTester;
47 using Thyra::multiply;
48 using Thyra::diagonal;
51 std::string matrixFile =
"";
52 std::string matrixFile2 =
"";
58 "matrix-file", &matrixFile,
59 "Defines the Epetra_CrsMatrix to read in." );
61 "matrix-file-2", &matrixFile2,
62 "Defines the second Epetra_CrsMatrix to read in." );
67 buildBDGOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
68 const Teuchos::RCP<
const Thyra::LinearOpBase<double> > & G,
69 const double vecScale, std::ostream & out)
76 RCP<const LinearOpBase<double> > M;
77 RCP<VectorBase<double> > d;
79 d = createMember(
B->domain(),
"d");
81 d = createMember(
B->range(),
"d");
82 V_S( d.ptr(), vecScale );
88 M = multiply( scale(scalea,
B), diagonal(d), scale(scaleb,G),
"M" );
89 out <<
" Testing B*D*G" << std::endl;
92 M = multiply( scale(scalea,
B), diagonal(d), adjoint(G),
"M" );
93 out <<
" Testing B*D*adj(G)" << std::endl;
96 M = multiply( adjoint(
B), diagonal(d), scale(scaleb,G),
"M" );
97 out <<
" Testing adj(B)*D*G" << std::endl;
100 M = multiply( adjoint(
B), diagonal(d), adjoint(G),
"M" );
101 out <<
" Testing adj(B)*D*adj(G)" << std::endl;
104 M = multiply(
B, scale(scaled,diagonal(d)), G,
"M" );
105 out <<
" Testing B*(52.0*D)*G" << std::endl;
111 out <<
"\nM = " << *M;
118 buildBGOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
119 const Teuchos::RCP<
const Thyra::LinearOpBase<double> > & G,
125 RCP<const LinearOpBase<double> > M;
131 M = multiply( scale(scalea,
B), scale(scaleb,G),
"M" );
132 out <<
" Testing B*G" << std::endl;
135 M = multiply( scale(scalea,
B), adjoint(G),
"M" );
136 out <<
" Testing B*adj(G)" << std::endl;
139 M = multiply( adjoint(
B), scale(scaleb,G),
"M" );
140 out <<
" Testing adj(B)*G" << std::endl;
143 M = multiply( adjoint(
B), adjoint(G),
"M" );
144 out <<
" Testing adj(B)*adj(G)" << std::endl;
150 out <<
"\nM = " << *M;
156 buildBDBOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
B,
157 const double vecScale, std::ostream & out)
159 return buildBDGOperator(scenario,
B,
B,vecScale,out);
171 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\' ...\n";
174 Epetra_MpiComm comm(MPI_COMM_WORLD);
176 Epetra_SerialComm comm;
178 RCP<Epetra_CrsMatrix> epetra_B;
179 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
185 const RCP<const Thyra::LinearOpBase<double> >
B = Thyra::epetraLinearOp(epetra_B);
194 for(
int scenario=1;scenario<=5;scenario++) {
195 const RCP<const Thyra::LinearOpBase<double> > M = buildBDBOperator(scenario,B,4.5,out);
201 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
206 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
208 BtDB_transformer->transform( *M, M_explicit.ptr() );
210 out <<
"\nM_explicit = " << *M_explicit;
216 LinearOpTester<double> M_explicit_tester;
217 M_explicit_tester.show_all_tests(
true);;
219 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
220 if (!result) success =
false;
232 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'";
233 out <<
" and from the file \'"<<matrixFile2<<
"\' ...\n";
236 Epetra_MpiComm comm(MPI_COMM_WORLD);
238 Epetra_SerialComm comm;
240 RCP<Epetra_CrsMatrix> epetra_B;
241 RCP<Epetra_CrsMatrix> epetra_G;
242 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
243 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
249 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::epetraLinearOp(epetra_B);
250 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
257 for(
int scenario=1;scenario<=3;scenario++) {
258 RCP<const Thyra::LinearOpBase<double> > M;
259 if(scenario==1 || scenario==3)
260 M = buildBDGOperator(scenario,B,G,4.5,out);
262 M = buildBDGOperator(scenario,G,B,4.5,out);
268 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
273 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
275 BtDB_transformer->transform( *M, M_explicit.ptr() );
277 out <<
"\nM_explicit = " << *M_explicit;
283 LinearOpTester<double> M_explicit_tester;
284 M_explicit_tester.show_all_tests(
true);;
286 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
287 if (!result) success =
false;
299 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile2<<
"\' ...\n";
302 Epetra_MpiComm comm(MPI_COMM_WORLD);
304 Epetra_SerialComm comm;
306 RCP<Epetra_CrsMatrix> epetra_G;
307 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
313 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
320 int scenes[] = {1,4};
321 for(
int i=0;i<2;i++) {
322 int scenario = scenes[i];
323 const RCP<const Thyra::LinearOpBase<double> > M = buildBDGOperator(scenario,G,G,4.5,out);
329 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
334 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
336 BtDB_transformer->transform( *M, M_explicit.ptr() );
338 out <<
"\nM_explicit = " << *M_explicit;
344 LinearOpTester<double> M_explicit_tester;
345 M_explicit_tester.show_all_tests(
true);;
347 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
348 if (!result) success =
false;
360 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'";
361 out <<
" and from the file \'"<<matrixFile2<<
"\' ...\n";
364 Epetra_MpiComm comm(MPI_COMM_WORLD);
366 Epetra_SerialComm comm;
368 RCP<Epetra_CrsMatrix> epetra_B;
369 RCP<Epetra_CrsMatrix> epetra_G;
370 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
371 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_G, NULL, NULL, NULL );
377 const RCP<const Thyra::LinearOpBase<double> > B = Thyra::epetraLinearOp(epetra_B);
378 const RCP<const Thyra::LinearOpBase<double> > G = Thyra::epetraLinearOp(epetra_G);
385 for(
int scenario=1;scenario<=4;scenario++) {
386 RCP<const Thyra::LinearOpBase<double> > M;
387 if(scenario==1 || scenario==3)
388 M = buildBGOperator(scenario,B,G,out);
390 M = buildBGOperator(scenario,G,B,out);
392 M = buildBGOperator(scenario,G,G,out);
398 const RCP<EpetraExtDiagScaledMatProdTransformer> BtDB_transformer =
403 const RCP<LinearOpBase<double> > M_explicit = BtDB_transformer->createOutputOp();
405 BtDB_transformer->transform( *M, M_explicit.ptr() );
407 out <<
"\nM_explicit = " << *M_explicit;
413 LinearOpTester<double> M_explicit_tester;
414 M_explicit_tester.show_all_tests(
true);;
416 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
417 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)