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"
20 #include "EpetraExt_readEpetraLinearSystem.h"
32 # include "Epetra_MpiComm.h"
34 # include "Epetra_SerialComm.h"
46 using Thyra::epetraExtDiagScalingTransformer;
47 using Thyra::VectorBase;
48 using Thyra::LinearOpBase;
49 using Thyra::createMember;
50 using Thyra::LinearOpTester;
52 using Thyra::multiply;
53 using Thyra::diagonal;
56 std::string matrixFile =
"";
62 "matrix-file", &matrixFile,
63 "Defines the Epetra_CrsMatrix to read in." );
68 buildADOperator(
int scenario,
const Teuchos::RCP<
const Thyra::LinearOpBase<double> > &
A,
69 const double vecScale, std::ostream & out)
75 RCP<const LinearOpBase<double> > M;
76 RCP<VectorBase<double> > d;
78 d = createMember(
A->domain(),
"d");
80 d = createMember(
A->range(),
"d");
81 V_S( d.ptr(), vecScale );
87 M = multiply( scale(scalea,
A), scale(scaled,diagonal(d)),
"M" );
88 out <<
" Testing A*D" << std::endl;
91 M = multiply( scale(scaled,diagonal(d)), scale(scalea,
A),
"M" );
92 out <<
" Testing D*A" << std::endl;
95 M = multiply(
A, scale(scaled,diagonal(d)),
"M" );
96 out <<
" Testing adj(A)*D" << std::endl;
99 M = multiply( scale(scaled,diagonal(d)),
A,
"M" );
100 out <<
" Testing D*adj(A)" << std::endl;
105 out <<
"\nM = " << *M;
112 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'\n";
115 Epetra_MpiComm comm(MPI_COMM_WORLD);
117 Epetra_SerialComm comm;
120 RCP<Epetra_CrsMatrix> epetra_A;
121 RCP<Epetra_CrsMatrix> epetra_B;
122 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
123 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_B, NULL, NULL, NULL );
124 const RCP<const Thyra::LinearOpBase<double> >
A = Thyra::epetraLinearOp(epetra_A);
125 const RCP<const Thyra::LinearOpBase<double> >
B = Thyra::epetraLinearOp(epetra_B);
127 RCP<VectorBase<double> > d = createMember(B->domain(),
"d");
130 const RCP<EpetraExtDiagScalingTransformer> BD_transformer =
135 RCP<const LinearOpBase<double> > M;
140 M = multiply(A,scale(3.9,diagonal(d)));
143 M = multiply(scale(3.0,diagonal(d)),scale(9.0,B));
146 M = multiply(B,scale(3.0,diagonal(d)),scale(9.0,B));
156 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'\n";
159 Epetra_MpiComm comm(MPI_COMM_WORLD);
161 Epetra_SerialComm comm;
163 RCP<Epetra_CrsMatrix> epetra_A;
164 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
170 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::epetraLinearOp(epetra_A);
172 RCP<const Thyra::LinearOpBase<double> > M;
175 for(
int scenario=1;scenario<=2;scenario++) {
176 out <<
"**********************************************************" << std::endl;
177 out <<
"**************** Starting Scenario = " << scenario << std::endl;
178 out <<
"**********************************************************" << std::endl;
183 const RCP<EpetraExtDiagScalingTransformer> BD_transformer =
192 const RCP<LinearOpBase<double> > M_explicit = BD_transformer->createOutputOp();
196 M = buildADOperator(scenario,A,4.5,out);
197 BD_transformer->transform( *M, M_explicit.ptr() );
200 M = buildADOperator(scenario,A,7.5,out);
201 BD_transformer->transform( *M, M_explicit.ptr() );
207 out <<
"\nM_explicit = " << *M_explicit;
213 LinearOpTester<double> M_explicit_tester;
214 M_explicit_tester.show_all_tests(
true);;
216 const bool result = M_explicit_tester.compare( *M, *M_explicit, Teuchos::inoutArg(out) );
217 if (!result) success =
false;
228 out <<
"\nReading linear system in Epetra format from the file \'"<<matrixFile<<
"\'\n";
231 Epetra_MpiComm comm(MPI_COMM_WORLD);
233 Epetra_SerialComm comm;
235 RCP<Epetra_CrsMatrix> epetra_A;
236 EpetraExt::readEpetraLinearSystem( matrixFile, comm, &epetra_A, NULL, NULL, NULL );
242 const RCP<const Thyra::LinearOpBase<double> > A = Thyra::epetraLinearOp(epetra_A);
249 for(
int scenario=1;scenario<=4;scenario++) {
250 out <<
"**********************************************************" << std::endl;
251 out <<
"**************** Starting Scenario = " << scenario << std::endl;
252 out <<
"**********************************************************" << std::endl;
254 RCP<const Thyra::LinearOpBase<double> > M = buildADOperator(scenario,A,4.5,out);
259 const RCP<EpetraExtDiagScalingTransformer> BD_transformer =
264 BD_transformer->isCompatible(*M);
270 const RCP<LinearOpBase<double> > M_explicit = BD_transformer->createOutputOp();
271 BD_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;
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 TEST_EQUALITY(v1, v2)
#define TEUCHOS_ASSERT(assertion_test)