45 #include "Thyra_ScaledLinearOpBase.hpp"
46 #include "Thyra_RowStatLinearOpBase.hpp"
47 #include "Thyra_LinearOpTester.hpp"
48 #include "Thyra_DefaultBlockedLinearOp.hpp"
49 #include "Thyra_VectorBase.hpp"
50 #include "Thyra_VectorStdOps.hpp"
51 #include "Thyra_MultiVectorBase.hpp"
52 #include "Thyra_MultiVectorStdOps.hpp"
55 #include "Teuchos_UnitTestHarness.hpp"
61 bool g_dumpAll =
false;
65 TEUCHOS_STATIC_SETUP()
67 Teuchos::UnitTestRepository::getCLP().setOption(
68 "dump-all",
"no-dump-all", &g_dumpAll,
69 "Dump lots of data" );
87 using Teuchos::inOutArg;
88 using Teuchos::updateSuccess;
89 using Teuchos::rcp_dynamic_cast;
90 typedef ScalarTraits<double> ST;
94 const RCP<const Epetra_Comm> comm = getEpetraComm();
95 const int numLocalRows = g_localDim;
96 const int numRows = numLocalRows * comm->NumProc();
97 const int numCols = numLocalRows / 2;
98 const RCP<Epetra_CrsMatrix> epetraCrsM = getEpetraMatrix(numRows, numCols);
99 const RCP<LinearOpBase<double> > epetraOp = nonconstEpetraLinearOp(epetraCrsM);
101 const RCP<ScaledLinearOpBase<double> > scaledOp =
102 rcp_dynamic_cast<ScaledLinearOpBase<double> >(epetraOp,
true);
106 const double two = 2.0;
108 const RCP<VectorBase<double> > rhs_vec =
109 createMember<double>(epetraOp->domain());
110 assign<double>(rhs_vec.ptr(), two);
112 const RCP<VectorBase<double> > lhs_orig_vec =
113 createMember<double>(epetraOp->range());
115 apply<double>(*epetraOp, Thyra::NOTRANS, *rhs_vec, lhs_orig_vec.ptr());
118 out <<
"epetraOp = " << *epetraOp;
119 out <<
"rhs_vec = " << *rhs_vec;
120 out <<
"lhs_orig_vec = " << *lhs_orig_vec;
125 const double three = 3.0;
127 const RCP<VectorBase<double> > row_scaling =
128 createMember<double>(epetraOp->range());
129 assign<double>(row_scaling.ptr(), three);
131 scaledOp->scaleLeft(*row_scaling);
134 out <<
"row_scaling = " << *row_scaling;
135 out <<
"epetraOp left scaled = " << *epetraOp;
140 const RCP<VectorBase<double> > lhs_left_scaled_vec =
141 createMember<double>(epetraOp->range());
143 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_left_scaled_vec.ptr());
146 out <<
"lhs_left_scaled_vec = " << *lhs_left_scaled_vec;
149 TEST_FLOATING_EQUALITY(
150 three * sum<double>(*lhs_orig_vec),
151 sum<double>(*lhs_left_scaled_vec),
152 as<double>(10.0 * ST::eps())
157 const RCP<VectorBase<double> > inv_row_scaling =
158 createMember<double>(epetraOp->range());
159 reciprocal<double>(*row_scaling, inv_row_scaling.ptr());
161 scaledOp->scaleLeft(*inv_row_scaling);
164 out <<
"inv_row_scaling = " << *row_scaling;
165 out <<
"epetraOp left scaled back to orig = " << *epetraOp;
168 const RCP<VectorBase<double> > lhs_orig2_vec =
169 createMember<double>(epetraOp->range());
171 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_orig2_vec.ptr());
174 out <<
"lhs_orig2_vec = " << *lhs_orig2_vec;
177 TEST_FLOATING_EQUALITY(
178 sum<double>(*lhs_orig_vec),
179 sum<double>(*lhs_orig2_vec),
180 as<double>(10.0 * ST::eps())
187 const double four = 4.0;
189 const RCP<VectorBase<double> > col_scaling =
190 createMember<double>(epetraOp->domain());
191 assign<double>(col_scaling.ptr(), four);
193 scaledOp->scaleRight(*col_scaling);
196 out <<
"col_scaling = " << *col_scaling;
197 out <<
"epetraOp right scaled = " << *epetraOp;
202 const RCP<VectorBase<double> > lhs_right_scaled_vec =
203 createMember<double>(epetraOp->range());
205 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_right_scaled_vec.ptr());
208 out <<
"lhs_right_scaled_vec = " << *lhs_right_scaled_vec;
211 TEST_FLOATING_EQUALITY(
212 four * sum<double>(*lhs_orig_vec),
213 sum<double>(*lhs_right_scaled_vec),
214 as<double>(10.0 * ST::eps())
219 const RCP<VectorBase<double> > inv_col_scaling =
220 createMember<double>(epetraOp->domain());
221 reciprocal<double>(*col_scaling, inv_col_scaling.ptr());
223 scaledOp->scaleRight(*inv_col_scaling);
226 out <<
"inv_col_scaling = " << *col_scaling;
227 out <<
"epetraOp right scaled back to orig = " << *epetraOp;
230 const RCP<VectorBase<double> > lhs_orig3_vec =
231 createMember<double>(epetraOp->range());
233 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_orig3_vec.ptr());
236 out <<
"lhs_orig3_vec = " << *lhs_orig3_vec;
239 TEST_FLOATING_EQUALITY(
240 sum<double>(*lhs_orig_vec),
241 sum<double>(*lhs_orig3_vec),
242 as<double>(10.0 * ST::eps())
253 using Teuchos::inOutArg;
254 using Teuchos::updateSuccess;
255 using Teuchos::rcp_dynamic_cast;
256 typedef ScalarTraits<double> ST;
260 const RCP<const Epetra_Comm> comm = getEpetraComm();
261 const int numLocalRows = g_localDim;
262 const int numRows = numLocalRows * comm->NumProc();
263 const int numCols = numLocalRows / 2;
264 const RCP<Epetra_CrsMatrix> epetraCrsM = getEpetraMatrix(numRows, numCols);
265 const double two = 2.0;
266 epetraCrsM->PutScalar(two);
267 const RCP<LinearOpBase<double> > epetraOp = nonconstEpetraLinearOp(epetraCrsM);
269 const RCP<RowStatLinearOpBase<double> > rowStatOp =
270 rcp_dynamic_cast<RowStatLinearOpBase<double> >(epetraOp,
true);
273 out <<
"epetraOp = " << *epetraOp;
278 const RCP<VectorBase<double> > inv_row_sums =
279 createMember<double>(epetraOp->range());
281 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM,
285 out <<
"inv_row_sums = " << *inv_row_sums;
288 TEST_FLOATING_EQUALITY(
289 sum<double>(*inv_row_sums),
290 as<double>((1.0 / (two * numCols)) * numRows),
291 as<double>(10.0 * ST::eps())
300 using Teuchos::inOutArg;
301 using Teuchos::updateSuccess;
303 const RCP<const Epetra_Comm> comm = getEpetraComm();
305 const int numLocalRows = g_localDim;
306 const int numRows = numLocalRows * comm->NumProc();
307 const int numCols = numLocalRows / 2;
309 const RCP<Epetra_CrsMatrix> epetraCrsM = getEpetraMatrix(numRows, numCols);
311 const RCP<const LinearOpBase<double> > epetraOp = epetraLinearOp(epetraCrsM);
313 LinearOpTester<double> linearOpTester;
314 updateSuccess(linearOpTester.check(*epetraOp, inOutArg(out)), success);
322 using Teuchos::describe;
325 RCP<const LinearOpBase<double> > A00 =
326 epetraLinearOp(getEpetraMatrix(4,4,0));
327 RCP<const LinearOpBase<double> > A01 =
328 epetraLinearOp(getEpetraMatrix(4,3,1));
329 RCP<const LinearOpBase<double> > A02 =
330 epetraLinearOp(getEpetraMatrix(4,2,2));
331 RCP<const LinearOpBase<double> > A10 =
332 epetraLinearOp(getEpetraMatrix(3,4,3));
333 RCP<const LinearOpBase<double> > A11 =
334 epetraLinearOp(getEpetraMatrix(3,3,4));
335 RCP<const LinearOpBase<double> > A12 =
336 epetraLinearOp(getEpetraMatrix(3,2,5));
337 RCP<const LinearOpBase<double> > A20 =
338 epetraLinearOp(getEpetraMatrix(2,4,6));
339 RCP<const LinearOpBase<double> > A21 =
340 epetraLinearOp(getEpetraMatrix(2,3,8));
341 RCP<const LinearOpBase<double> > A22 =
342 epetraLinearOp(getEpetraMatrix(2,2,8));
344 out <<
"Sub operators built" << std::endl;
348 RCP<const LinearOpBase<double> > A = block2x2<double>(
349 block2x2<double>(A00, A01, A10, A11), block2x1<double>(A02,A12),
350 block1x2<double>(A20, A21), A22
353 out <<
"First composite operator built" << std::endl;
356 RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
357 RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
359 randomize(-1.0, 1.0, x.ptr());
361 out <<
"A = \n" << describe(*A, Teuchos::VERB_HIGH) << std::endl;
362 out <<
"x = \n" << describe(*x, Teuchos::VERB_HIGH) << std::endl;
363 out <<
"y = \n" << describe(*y, Teuchos::VERB_HIGH) << std::endl;
366 apply(*A, NOTRANS, *x, y.ptr());
368 out <<
"First composite operator completed" << std::endl;
372 RCP<const LinearOpBase<double> > A = block2x2<double>(
373 A11, block1x2<double>(A10, A12),
374 block2x1<double>(A01, A21), block2x2<double>(A00, A02, A20, A22)
377 out <<
"Second composite operator built" << std::endl;
380 RCP<MultiVectorBase<double> > x = createMembers<double>(A->domain(), 3);
381 RCP<MultiVectorBase<double> > y = createMembers<double>(A->range(), 3);
383 randomize(-1.0, 1.0, x.ptr());
385 out <<
"A = \n" << describe(*A, Teuchos::VERB_HIGH) << std::endl;
386 out <<
"x = \n" << describe(*x, Teuchos::VERB_HIGH) << std::endl;
387 out <<
"y = \n" << describe(*y, Teuchos::VERB_HIGH) << std::endl;
390 apply(*A, NOTRANS, *x, y.ptr());
392 out <<
"Second composite operator completed" << std::endl;
395 out <<
"Test complete" << std::endl;
Concrete LinearOpBase adapter subclass for Epetra_Operator object.
TEUCHOS_UNIT_TEST(EpetraOperatorWrapper, basic)