From 43b27c579997920bd7f6d2ed1e9adb918fbea5bd Mon Sep 17 00:00:00 2001 From: "antoine.meyer1" Date: Thu, 17 Aug 2023 06:40:22 -0400 Subject: [PATCH] #67: First test build but raised errors to fix --- .../unit_tests/tStridedTpetraOperator.cpp | 158 ++++++++---------- 1 file changed, 72 insertions(+), 86 deletions(-) diff --git a/packages/teko/tests/unit_tests/tStridedTpetraOperator.cpp b/packages/teko/tests/unit_tests/tStridedTpetraOperator.cpp index 1bef8f0a6031..b7bd20513915 100644 --- a/packages/teko/tests/unit_tests/tStridedTpetraOperator.cpp +++ b/packages/teko/tests/unit_tests/tStridedTpetraOperator.cpp @@ -61,9 +61,6 @@ // Thyra includes #include "Thyra_VectorStdOps.hpp" -//#include "Thyra_EpetraThyraWrappers.hpp" // TO REMOVE -//#include "Thyra_EpetraLinearOp.hpp" // TO REMOVE -//#include "Thyra_EpetraOperatorWrapper.hpp" // TO REMOVE #include "Thyra_DefaultBlockedLinearOp.hpp" #include "Thyra_ProductVectorBase.hpp" #include "Thyra_SpmdVectorSpaceBase.hpp" @@ -72,45 +69,41 @@ // TriUtils includes //#include "Trilinos_Util_CrsMatrixGallery.h" // TO REMOVE EPETRA -//#include "Teko_StridedEpetraOperator.hpp" // TO REMOVE +// Teko includes +#include "Teko_StridedTpetraOperator.hpp" #include "Teko_Utilities.hpp" #define SS_ECHO(ops) { std::stringstream ss; ss << ops; ECHO(ss.str()); }; +// Teuchos using using Teuchos::Comm; using Teuchos::null; using Teuchos::RCP; using Teuchos::rcp; using Teuchos::rcp_dynamic_cast; +// Thyra using using Thyra::VectorBase; using Thyra::LinearOpBase; using Thyra::createMember; using Thyra::LinearOpTester; +// Tpetra using using ST = typename Tpetra::Vector::scalar_type; using LO = typename Tpetra::Vector<>::local_ordinal_type; using GO = typename Tpetra::Vector<>::global_ordinal_type; using NT = typename Tpetra::Vector<>::node_type; using tcrsmatrix_t = Tpetra::CrsMatrix; using tmap_t = Tpetra::Map; +using tmultivector_t = Tpetra::MultiVector; -double tolerance = 1e-14; +ST tolerance = 1e-14; const RCP> GetComm() { return Tpetra::getDefaultComm(); } -// TO REMOVE v -TEUCHOS_UNIT_TEST(t_AM_BLALBA, AM_BLALBLA) -{ - int max = 20; - int min = 2; - TEST_ASSERT(max >= min); -} -// TO REMOVE ^ - TEUCHOS_UNIT_TEST(tStridedTpetraOperator, test_numvars_constr) { // communicator @@ -123,83 +116,76 @@ TEUCHOS_UNIT_TEST(tStridedTpetraOperator, test_numvars_constr) // create a big matrix to play with RCP FGallery = rcp(new tmap_t(nx * ny, 0, comm)); - RCP A = rcp(new tcrsmatrix_t(FGallery, 1), false); - double beforeNorm = A->getFrobeniusNorm(); // AM: before was Epetra_CrsMatrix->NormOne() + RCP A = rcp(new tcrsmatrix_t(FGallery, 1)); + ST beforeNorm = A->getFrobeniusNorm(); - - - /* + // create a strided tpetra operator int vars = 3; int width = 3; - Epetra_MultiVector x(A->OperatorDomainMap(),width); - Epetra_MultiVector ys(A->OperatorRangeMap(),width); - Epetra_MultiVector y(A->OperatorRangeMap(),width); - - Teko::Epetra::StridedEpetraOperator shell(vars,A); - - // test the operator against a lot of random vectors - int numtests = 50; - double max = 0.0; - double min = 1.0; - for(int i=0;i norm(width); - std::vector rel(width); - x.Random(); - - shell.Apply(x,y); - A->Apply(x,ys); - - Epetra_MultiVector e(y); - e.Update(-1.0,ys,1.0); - e.Norm2(&norm[0]); - - // compute relative error - ys.Norm2(&rel[0]); - for(int j=0;jnorm[j]/rel[j] ? max : norm[j]/rel[j]; - min = mingetDomainMap(), width); + tmultivector_t ys(A->getRangeMap(), width); + tmultivector_t y(A->getRangeMap(), width); + Teko::TpetraHelpers::StridedTpetraOperator shell(vars, A); // AM: TO FIX + + // test the operator against a lot of random vectors + int numtests = 50; + ST max = 0.0; + ST min = 1.0; + for(int i=0; i norm(width); + std::vector rel(width); + x.randomize(); // AM: TO FIX + + shell.apply(x,y); // AM: TO FIX + A->apply(x,ys); + + tmultivector_t e(y, Teuchos::Copy); + e.update(-1.0, ys, 1.0); + e.norm2(Teuchos::ArrayView(norm)); + + // compute relative error + ys.norm2(Teuchos::ArrayView(rel)); + for(int j=0;jnorm[j]/rel[j] ? max : norm[j]/rel[j]; + min = min=min); - TEST_ASSERT(max<=tolerance); + TEST_ASSERT(max >= min); + TEST_ASSERT(max <= tolerance); - int * indexOffset,* indicies; - double * values; - A->ExtractCrsDataPointers(indexOffset,indicies,values); - for(int i=0;iNumMyNonzeros();i++) - values[i] *= 2.0; // square everything! - - double afterNorm = A->NormOne(); - TEST_ASSERT(beforeNorm!=afterNorm); - - shell.RebuildOps(); - - // test the operator against a lot of random vectors - numtests = 50; - max = 0.0; - min = 1.0; - for(int i=0;i norm(width); - std::vector rel(width); - x.Random(); - - shell.Apply(x,y); - A->Apply(x,ys); - - Epetra_MultiVector e(y); - e.Update(-1.0,ys,1.0); - e.Norm2(&norm[0]); - - // compute relative error - ys.Norm2(&rel[0]); - for(int j=0;jnorm[j]/rel[j] ? max : norm[j]/rel[j]; - min = min=min); - TEST_ASSERT(max<=tolerance); - */ + // double everything + A->scale(2.0); + + ST afterNorm = A->getFrobeniusNorm(); + TEST_ASSERT(beforeNorm != afterNorm); + + shell.RebuildOps(); + + // test the operator against a lot of random vectors + numtests = 50; + max = 0.0; + min = 1.0; + for(int i=0; i norm(width); + std::vector rel(width); + x.randomize(); // AM: PROBABLY TO FIX + + shell.apply(x,y); // AM: PROBABLY TO FIX + A->apply(x,ys); + + tmultivector_t e(y, Teuchos::Copy); + e.update(-1.0, ys, 1.0); + e.norm2(Teuchos::ArrayView(norm)); + + // compute relative error + ys.norm2(Teuchos::ArrayView(rel)); + for(int j=0; jnorm[j]/rel[j] ? max : norm[j]/rel[j]; + min = min= min); + TEST_ASSERT(max <= tolerance); } /*