11 #include "Thyra_ScaledLinearOpBase.hpp"
12 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
13 #include "Thyra_RowStatLinearOpBase.hpp"
14 #include "Thyra_LinearOpTester.hpp"
15 #include "Thyra_DefaultBlockedLinearOp.hpp"
16 #include "Thyra_VectorBase.hpp"
17 #include "Thyra_VectorStdOps.hpp"
18 #include "Thyra_MultiVectorBase.hpp"
19 #include "Thyra_MultiVectorStdOps.hpp"
20 #include "Thyra_DefaultProductVectorSpace.hpp"
21 #include "Thyra_DefaultProductVector.hpp"
22 #include "Thyra_DefaultDiagonalLinearOp.hpp"
23 #include "Thyra_DefaultMultipliedLinearOp.hpp"
24 #include "Thyra_DefaultZeroLinearOp.hpp"
25 #include "Thyra_LinearOpTester.hpp"
26 #include "Thyra_UnitTestHelpers.hpp"
27 #include "Thyra_DefaultSpmdVectorSpace.hpp"
31 #include "Thyra_DefaultBlockedLinearOp.hpp"
54 using Teuchos::inOutArg;
56 using Teuchos::rcp_dynamic_cast;
57 typedef ScalarTraits<double> ST;
63 const int numRows = numLocalRows * comm->NumProc();
64 const int numCols = numLocalRows / 2;
69 rcp_dynamic_cast<ScaledLinearOpBase<double> >(epetraOp,
true);
73 const double two = 2.0;
76 createMember<double>(epetraOp->domain());
77 assign<double>(rhs_vec.
ptr(), two);
80 createMember<double>(epetraOp->range());
82 apply<double>(*epetraOp, Thyra::NOTRANS, *rhs_vec, lhs_orig_vec.
ptr());
85 out <<
"epetraOp = " << *epetraOp;
86 out <<
"rhs_vec = " << *rhs_vec;
87 out <<
"lhs_orig_vec = " << *lhs_orig_vec;
92 const double three = 3.0;
95 createMember<double>(epetraOp->range());
96 assign<double>(row_scaling.
ptr(), three);
98 scaledOp->scaleLeft(*row_scaling);
101 out <<
"row_scaling = " << *row_scaling;
102 out <<
"epetraOp left scaled = " << *epetraOp;
108 createMember<double>(epetraOp->range());
110 apply<double>(*epetraOp,
NOTRANS, *rhs_vec, lhs_left_scaled_vec.
ptr());
113 out <<
"lhs_left_scaled_vec = " << *lhs_left_scaled_vec;
117 three * sum<double>(*lhs_orig_vec),
118 sum<double>(*lhs_left_scaled_vec),
119 as<double>(10.0 * ST::eps())
125 createMember<double>(epetraOp->range());
126 reciprocal<double>(*row_scaling, inv_row_scaling.
ptr());
128 scaledOp->scaleLeft(*inv_row_scaling);
131 out <<
"inv_row_scaling = " << *row_scaling;
132 out <<
"epetraOp left scaled back to orig = " << *epetraOp;
136 createMember<double>(epetraOp->range());
138 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_orig2_vec.
ptr());
141 out <<
"lhs_orig2_vec = " << *lhs_orig2_vec;
145 sum<double>(*lhs_orig_vec),
146 sum<double>(*lhs_orig2_vec),
147 as<double>(10.0 * ST::eps())
154 const double four = 4.0;
157 createMember<double>(epetraOp->domain());
158 assign<double>(col_scaling.
ptr(), four);
160 scaledOp->scaleRight(*col_scaling);
163 out <<
"col_scaling = " << *col_scaling;
164 out <<
"epetraOp right scaled = " << *epetraOp;
170 createMember<double>(epetraOp->range());
172 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_right_scaled_vec.
ptr());
175 out <<
"lhs_right_scaled_vec = " << *lhs_right_scaled_vec;
179 four * sum<double>(*lhs_orig_vec),
180 sum<double>(*lhs_right_scaled_vec),
181 as<double>(10.0 * ST::eps())
187 createMember<double>(epetraOp->domain());
188 reciprocal<double>(*col_scaling, inv_col_scaling.
ptr());
190 scaledOp->scaleRight(*inv_col_scaling);
193 out <<
"inv_col_scaling = " << *col_scaling;
194 out <<
"epetraOp right scaled back to orig = " << *epetraOp;
198 createMember<double>(epetraOp->range());
200 apply<double>(*epetraOp, NOTRANS, *rhs_vec, lhs_orig3_vec.
ptr());
203 out <<
"lhs_orig3_vec = " << *lhs_orig3_vec;
207 sum<double>(*lhs_orig_vec),
208 sum<double>(*lhs_orig3_vec),
209 as<double>(10.0 * ST::eps())
220 using Teuchos::inOutArg;
222 using Teuchos::rcp_dynamic_cast;
223 typedef ScalarTraits<double> ST;
229 const int numRows = numLocalRows * comm->NumProc();
230 const int numCols = numLocalRows / 2;
232 const double two = 2.0;
233 epetraCrsM->PutScalar(-two);
237 rcp_dynamic_cast<RowStatLinearOpBase<double> >(epetraOp,
true);
240 out <<
"epetraOp = " << *epetraOp;
246 createMember<double>(epetraOp->range());
248 createMember<double>(epetraOp->range());
250 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM,
252 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM,
256 out <<
"inv_row_sums = " << *inv_row_sums;
257 out <<
"row_sums = " << *row_sums;
261 sum<double>(*inv_row_sums),
262 as<double>((1.0 / (two * numCols)) * numRows),
263 as<double>(10.0 * ST::eps())
267 sum<double>(*row_sums),
268 as<double>(two * numCols * numRows),
269 as<double>(10.0 * ST::eps())
277 const Epetra_Map rowMap(numRows, 0, *comm);
278 const Epetra_Map domainMap(numCols, numCols, 0, *comm);
281 rcp(
new Epetra_CrsMatrix(
Copy, rowMap,domainMap,0));
283 Array<double> rowEntries(numCols);
284 Array<int> columnIndices(numCols);
285 for (
int j = 0; j < numCols; ++j)
286 columnIndices[j] = j;
288 const int numLocalRows = rowMap.NumMyElements();
289 for (
int i = 0; i < numLocalRows; ++i) {
290 for (
int j = 0; j < numCols; ++j) {
291 rowEntries[j] = as<double>(i+1) + as<double>(j+1) / 10 + shift;
294 epetraCrsM->InsertMyValues( i, numCols, &rowEntries[0], &columnIndices[0] );
297 epetraCrsM->FillComplete(domainMap,rowMap);
304 using Teuchos::inOutArg;
306 using Teuchos::rcp_dynamic_cast;
313 const int numRows = numLocalRows * comm->NumProc();
314 const int numCols = numLocalRows ;
316 out <<
"numRows = " << numRows <<
", numCols = " << numCols << std::endl;
322 epetraCrsM00_base->PutScalar(2.0);
323 epetraCrsM01_base->PutScalar(-8.0);
324 epetraCrsM10_base->PutScalar(-9.0);
325 epetraCrsM11_base->PutScalar(3.0);
330 epetraCrsM00->PutScalar(2.0);
331 epetraCrsM01->PutScalar(-8.0);
332 epetraCrsM10->PutScalar(-9.0);
333 epetraCrsM11->PutScalar(3.0);
351 put_scalar(7.0,left_scale.
ptr());
352 put_scalar(-4.0,right_scale.ptr());
354 rcp_dynamic_cast<ScaledLinearOpBase<double> >(blocked)->scaleLeft(*left_scale);
357 LinearOpTester<double> tester;
358 tester.set_all_error_tol(1e-10);
359 tester.show_all_tests(
true);
360 tester.dump_all(
true);
361 tester.num_random_vectors(5);
365 updateSuccess(tester.compare(*ref_op, *blocked, ptrFromRef(out)), success);
368 rcp_dynamic_cast<ScaledLinearOpBase<double> >(blocked)->scaleRight(*right_scale);
371 LinearOpTester<double> tester;
372 tester.set_all_error_tol(1e-10);
373 tester.show_all_tests(
true);
374 tester.dump_all(
true);
375 tester.num_random_vectors(5);
380 updateSuccess(tester.compare(*ref_op, *blocked, ptrFromRef(out)), success);
387 using Teuchos::inOutArg;
389 using Teuchos::rcp_dynamic_cast;
390 typedef ScalarTraits<double> ST;
396 const int numRows = numLocalRows * comm->NumProc();
397 const int numCols = numLocalRows / 2;
399 out <<
"numRows = " << numRows <<
", numCols = " << numCols << std::endl;
405 epetraCrsM00->PutScalar(2.0);
406 epetraCrsM01->PutScalar(-8.0);
407 epetraCrsM10->PutScalar(-9.0);
408 epetraCrsM11->PutScalar(3.0);
418 rcp_dynamic_cast<
const RowStatLinearOpBase<double> >(blocked,
true);
421 out <<
"epetraOp = " << *blocked;
427 createMember<double>(blocked->range());
429 createMember<double>(blocked->range());
431 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM,
433 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM,
437 out <<
"inv_row_sums = " << *inv_row_sums;
438 out <<
"row_sums = " << *row_sums;
442 sum<double>(*inv_row_sums),
443 as<double>((1.0/(numRows*2.0+numCols*8.0))*numRows + (1.0/(numRows*9.0+numCols*3.0))*numCols),
444 as<double>(10.0 * ST::eps())
447 sum<double>(*row_sums),
448 as<double>((numRows*2.0+numCols*8.0)*numRows + (numRows*9.0+numCols*3.0)*numCols),
449 as<double>(10.0 * ST::eps())
456 using Teuchos::inOutArg;
458 using Teuchos::rcp_dynamic_cast;
459 typedef ScalarTraits<double> ST;
466 const int numLocalRows = 4;
467 const int numRows = numLocalRows * comm->NumProc();
468 const int numCols = numLocalRows / 2;
470 out <<
"numRows = " << numRows <<
", numCols = " << numCols << std::endl;
474 epetraCrsM00->PutScalar(2.0);
475 epetraCrsM00_base->PutScalar(2.0);
489 assign(vec_01.ptr(),-8.0);
490 assign(vec_10t.
ptr(),-9.0);
491 assign(vec_01_base.ptr(),-8.0);
492 assign(vec_10t_base.
ptr(),-9.0);
502 out <<
"FIRST" << std::endl;
508 rcp_dynamic_cast<
const RowStatLinearOpBase<double> >(blocked,
true);
513 createMember<double>(blocked->range());
515 createMember<double>(blocked->range());
517 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM,
519 rowStatOp->getRowStat(RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM,
523 sum<double>(*inv_row_sums),
524 as<double>((1.0/(numRows*2.0+numCols*8.0))*numRows + (1.0/(numRows*9.0+numCols*0.0))*numCols),
525 as<double>(10.0 * ST::eps())
528 sum<double>(*row_sums),
529 as<double>((numRows*2.0+numCols*8.0)*numRows + (numRows*9.0+numCols*0.0)*numCols),
530 as<double>(10.0 * ST::eps())
537 put_scalar(7.0,left_scale.
ptr());
538 put_scalar(-4.0,right_scale.ptr());
540 rcp_dynamic_cast<ScaledLinearOpBase<double> >(blocked)->scaleLeft(*left_scale);
543 LinearOpTester<double> tester;
544 tester.set_all_error_tol(1e-10);
545 tester.show_all_tests(
true);
546 tester.dump_all(
false);
547 tester.num_random_vectors(2);
551 updateSuccess(tester.compare(*ref_op, *blocked, ptrFromRef(out)), success);
554 rcp_dynamic_cast<ScaledLinearOpBase<double> >(blocked)->scaleRight(*right_scale);
557 LinearOpTester<double> tester;
558 tester.set_all_error_tol(1e-10);
559 tester.show_all_tests(
true);
560 tester.dump_all(
false);
561 tester.num_random_vectors(5);
566 updateSuccess(tester.compare(*ref_op, *blocked, ptrFromRef(out)), success);
575 using Teuchos::inOutArg;
579 const int numProcs = comm->NumProc();
582 const int numRows = numLocalRows * comm->NumProc();
583 const int numCols = numLocalRows / 2;
589 LinearOpTester<double> linearOpTester;
590 linearOpTester.check_adjoint(numProcs == 1);
591 linearOpTester.show_all_tests(g_show_all_tests);
592 linearOpTester.dump_all(g_dumpAll);
593 updateSuccess(linearOpTester.check(*epetraOp, inOutArg(out)), success);
605 out <<
"Skipping test if numProc > 2 since it fails for some reason\n";
609 using Teuchos::describe;
613 epetraLinearOp(getEpetraMatrix(4,4,0));
615 epetraLinearOp(getEpetraMatrix(4,3,1));
617 epetraLinearOp(getEpetraMatrix(4,2,2));
619 epetraLinearOp(getEpetraMatrix(3,4,3));
621 epetraLinearOp(getEpetraMatrix(3,3,4));
623 epetraLinearOp(getEpetraMatrix(3,2,5));
625 epetraLinearOp(getEpetraMatrix(2,4,6));
627 epetraLinearOp(getEpetraMatrix(2,3,8));
629 epetraLinearOp(getEpetraMatrix(2,2,8));
634 out <<
"Sub operators built" << std::endl;
640 block2x2<double>(A00, A01, A10, A11), block2x1<double>(A02,A12),
641 block1x2<double>(A20, A21), A22
644 out <<
"First composite operator built" << std::endl;
650 randomize(-1.0, 1.0, x.
ptr());
652 out <<
"A = \n" << describe(*A, verbLevel) << std::endl;
653 out <<
"x = \n" << describe(*x, verbLevel) << std::endl;
654 out <<
"y = \n" << describe(*y, verbLevel) << std::endl;
659 out <<
"First composite operator completed" << std::endl;
664 A11, block1x2<double>(A10, A12),
665 block2x1<double>(A01, A21), block2x2<double>(A00, A02, A20, A22)
668 out <<
"Second composite operator built" << std::endl;
674 randomize(-1.0, 1.0, x.
ptr());
676 out <<
"A = \n" << describe(*A, verbLevel) << std::endl;
677 out <<
"x = \n" << describe(*x, verbLevel) << std::endl;
678 out <<
"y = \n" << describe(*y, verbLevel) << std::endl;
683 out <<
"Second composite operator completed" << std::endl;
686 out <<
"Test complete" << std::endl;
Concrete LinearOpBase adapter subclass for Epetra_Operator object.
RCP< Epetra_CrsMatrix > getMyEpetraMatrix(int numRows, int numCols, double shift=0.0)
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
TEUCHOS_UNIT_TEST(EpetraOperatorWrapper, basic)
void updateSuccess(const bool result, bool &success)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)