10 #include "Thyra_DefaultProductVectorSpace.hpp"
11 #include "Thyra_VectorStdOps.hpp"
12 #include "Thyra_MultiVectorStdOps.hpp"
13 #include "Thyra_SpmdVectorSpaceBase.hpp"
14 #include "Thyra_VectorSpaceTester.hpp"
15 #include "Thyra_TestingTools.hpp"
16 #include "Epetra_Vector.h"
27 using Teuchos::ptrFromRef;
29 using Teuchos::rcp_dynamic_cast;
33 void createEpetraVsAndMap(
const Thyra::Ordinal localDim_in,
34 const Ptr<RCP<
const Thyra::VectorSpaceBase<double> > > &vs,
35 const Ptr<RCP<const Epetra_Map> > &epetra_map,
36 const int emptyProcRootRank = -1
39 const RCP<const Epetra_Comm> epetra_comm = getEpetraComm();
40 const int procRank = epetra_comm->MyPID();
41 const Thyra::Ordinal localDim = (procRank == emptyProcRootRank ? 0 : localDim_in);
42 *epetra_map =
rcp(
new Epetra_Map(-1, as<int>(localDim), 0, *epetra_comm));
47 void runVectorSpaceTesterTest(
const int emptyProc,
50 using Thyra::VectorSpaceBase;
51 using Thyra::SpmdVectorSpaceBase;
52 using Thyra::MultiVectorBase;
54 RCP<const VectorSpaceBase<double> > vs;
55 RCP<const Epetra_Map> epetra_map;
56 createEpetraVsAndMap(
g_localDim, outArg(vs), outArg(epetra_map), emptyProc);
57 const int numProcs = epetra_map->Comm().NumProc();
59 if (emptyProc >= numProcs) {
60 out <<
"emptyProc = " << emptyProc <<
" >= numProcs = " << numProcs
61 <<
": Skipping this test case!\n";
65 const Ordinal dimMultiplier = (emptyProc < 0 ? numProcs : numProcs-1);
69 const RCP<const SpmdVectorSpaceBase<double> > spmd_vs =
70 rcp_dynamic_cast<
const SpmdVectorSpaceBase<double> >(vs,
true);
72 TEST_EQUALITY(spmd_vs->localSubDim(), as<int>(epetra_map->NumMyElements()));
74 Thyra::VectorSpaceTester<double> vectorSpaceTester;
76 vectorSpaceTester.warning_tol((0.1)*tol);
77 vectorSpaceTester.error_tol(tol);
78 vectorSpaceTester.show_all_tests(g_show_all_tests);
79 vectorSpaceTester.dump_all(g_dumpAll);
84 void runCreateVectorUnitTest(
const int emptyProc,
87 using Thyra::VectorBase;
88 using Thyra::VectorSpaceBase;
89 using Thyra::MultiVectorBase;
91 RCP<const VectorSpaceBase<double> > vs;
92 RCP<const Epetra_Map> epetra_map;
93 createEpetraVsAndMap(
g_localDim, outArg(vs), outArg(epetra_map), emptyProc);
94 const int numProcs = epetra_map->Comm().NumProc();
96 if (emptyProc >= numProcs) {
97 out <<
"emptyProc = " << emptyProc <<
" >= numProcs = " << numProcs
98 <<
": Skipping this test case!\n";
102 const RCP<Epetra_Vector> epetra_vec =
rcp(
new Epetra_Vector(*epetra_map));
104 const RCP<Epetra_Vector> epetra_vec2 =
108 const RCP<const Epetra_Vector> const_epetra_vec2 =
123 const RCP<const Epetra_Comm> epetra_comm = getEpetraComm();
137 runVectorSpaceTesterTest(-1, out, success);
143 runVectorSpaceTesterTest(0, out, success);
149 runVectorSpaceTesterTest(1, out, success);
161 runCreateVectorUnitTest(0, out, success);
167 runCreateVectorUnitTest(1, out, success);
180 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, get_Epetra_MultiVector_singleBlockProductVector )
182 using Thyra::VectorSpaceBase;
183 using Thyra::MultiVectorBase;
185 RCP<const VectorSpaceBase<double> > vs;
186 RCP<const Epetra_Map> epetra_map;
187 createEpetraVsAndMap(
g_localDim, outArg(vs), outArg(epetra_map));
189 const RCP<const VectorSpaceBase<double> > pvs = Thyra::productVectorSpace(vs, 1);
191 const RCP<MultiVectorBase<double> > pmv = Thyra::createMembers(pvs, 1);
193 const double alpha = 3.5;
194 Thyra::assign<double>( pmv.ptr(), alpha );
196 const RCP<Epetra_MultiVector> epetra_mv =
199 const RCP<MultiVectorBase<double> > mv2 =
202 Thyra::testRelNormDiffErr<double>(
203 "*pmv->col(0)", *pmv->col(0),
204 "*mv2->col(0)", *mv2->col(0),
RCP< Epetra_MultiVector > get_Epetra_MultiVector(const Epetra_Map &map, const RCP< MultiVectorBase< double > > &mv)
Get a non-const Epetra_MultiVector view from a non-const MultiVectorBase object if possible...
static magnitudeType eps()
RCP< const VectorSpaceBase< double > > create_VectorSpace(const RCP< const Epetra_Map > &epetra_map)
Create an VectorSpaceBase object given an Epetra_Map object.
TEUCHOS_UNIT_TEST(EpetraOperatorWrapper, basic)
RCP< MultiVectorBase< double > > create_MultiVector(const RCP< Epetra_MultiVector > &epetra_mv, const RCP< const VectorSpaceBase< double > > &range=Teuchos::null, const RCP< const VectorSpaceBase< double > > &domain=Teuchos::null)
Create a non-const MultiVectorBase object from a non-const Epetra_MultiVector object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< VectorBase< double > > create_Vector(const RCP< Epetra_Vector > &epetra_v, const RCP< const VectorSpaceBase< double > > &space=Teuchos::null)
Create a non-const VectorBase object from a non-const Epetra_Vector object.
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
Get a non-const Epetra_Vector view from a non-const VectorBase object if possible.
RCP< const Epetra_Comm > get_Epetra_Comm(const Teuchos::Comm< Ordinal > &comm)
Get (or create) and Epetra_Comm given a Teuchos::Comm object.
#define TEST_EQUALITY(v1, v2)
RCP< const Teuchos::Comm< Ordinal > > create_Comm(const RCP< const Epetra_Comm > &epetraComm)
Given an Epetra_Comm object, return an equivalent Teuchos::Comm object.