42 #ifndef THYRA_MULTI_VECTOR_TESTER_DEF_HPP 43 #define THYRA_MULTI_VECTOR_TESTER_DEF_HPP 45 #include "Thyra_MultiVectorTester_decl.hpp" 46 #include "Thyra_MultiVectorBase.hpp" 47 #include "Thyra_MultiVectorStdOps.hpp" 48 #include "Thyra_VectorSpaceBase.hpp" 49 #include "Thyra_VectorStdOps.hpp" 50 #include "Teuchos_TestingHelpers.hpp" 56 template<
class Scalar>
60 const int num_random_vectors_in,
61 const bool show_all_tests_in,
62 const bool dump_all_in
64 :warning_tol_(warning_tol_in),
65 error_tol_(error_tol_in),
66 num_random_vectors_(num_random_vectors_in),
67 show_all_tests_(show_all_tests_in),
68 dump_all_(dump_all_in)
72 template<
class Scalar>
75 const Ptr<Teuchos::FancyOStream> &out_inout
80 using Teuchos::describe;
81 using Teuchos::FancyOStream;
85 typedef Teuchos::ScalarTraits<Scalar> ST;
88 RCP<FancyOStream> out;
89 if (!is_null(out_inout))
90 out = Teuchos::rcpFromPtr(out_inout);
92 out = Teuchos::fancyOStream(rcp(
new Teuchos::oblackholestream));
94 const Teuchos::EVerbosityLevel verbLevel =
95 (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
97 OSTab tab(out,1,
"THYRA");
101 *out <<
"\n*** Entering "<<this->description()<<
"::checkMultiVector(vs,...) ...\n";
103 *out <<
"\nTesting MultiVectorBase objects created from vs = " << describe(vs, verbLevel);
106 const Scalar scalarDim = as<Scalar>(dim);
110 *out <<
"\n"<<tc<<
") Checking non-contiguous non-const multi-vector views ...\n";
114 const int numCols = 6;
115 const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
116 assign<Scalar>(mv.ptr(), ST::zero());
118 one = as<Scalar>(1.0),
119 three = as<Scalar>(3.0),
120 five = as<Scalar>(5.0);
122 const RCP<MultiVectorBase<Scalar> > mvView = mv->subView(tuple<int>(1, 3, 5)());
123 assign<Scalar>(mvView->col(0).ptr(), one);
124 assign<Scalar>(mvView->col(1).ptr(), three);
125 assign<Scalar>(mvView->col(2).ptr(), five);
127 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(0)), ST::zero(), error_tol_,
129 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(1)), as<Scalar>(one*scalarDim), error_tol_,
131 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(2)), ST::zero(), error_tol_,
133 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(3)), as<Scalar>(three*scalarDim), error_tol_,
135 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(4)), ST::zero(), error_tol_,
137 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(5)), as<Scalar>(five*scalarDim), error_tol_,
141 *out <<
"\n"<<tc<<
") Checking non-contiguous const multi-vector views ...\n";
145 const int numCols = 6;
146 const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
148 one = as<Scalar>(1.0),
149 three = as<Scalar>(3.0),
150 five = as<Scalar>(5.0);
151 assign<Scalar>(mv.ptr(), ST::zero());
152 assign<Scalar>(mv->col(1).ptr(), one);
153 assign<Scalar>(mv->col(3).ptr(), three);
154 assign<Scalar>(mv->col(5).ptr(), five);
156 const RCP<const MultiVectorBase<Scalar> > mvView =
157 mv.getConst()->subView(tuple<int>(1, 3, 4, 5)());
158 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(0)), as<Scalar>(one*scalarDim), error_tol_,
160 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(1)), as<Scalar>(three*scalarDim), error_tol_,
162 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(2)), ST::zero(), error_tol_,
164 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(3)), as<Scalar>(five*scalarDim), error_tol_,
170 *out <<
"\nCongratulations, this MultiVectorBase objects" 171 <<
" created form this vector space seems to check out!\n";
173 *out <<
"\nOh no, at least one of the tests performed failed!\n";
175 *out <<
"\n*** Leaving "<<this->description()<<
"::checkMultiVector(vs,...) ...\n";
182 template<
class Scalar>
185 const Ptr<Teuchos::FancyOStream> &out_inout
189 using Teuchos::describe;
190 using Teuchos::FancyOStream;
191 using Teuchos::OSTab;
192 typedef Teuchos::ScalarTraits<Scalar> ST;
195 RCP<FancyOStream> out;
196 if (!is_null(out_inout))
197 out = Teuchos::rcpFromPtr(out_inout);
199 out = Teuchos::fancyOStream(rcp(
new Teuchos::oblackholestream));
201 const Teuchos::EVerbosityLevel verbLevel =
202 (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
204 OSTab tab(out,1,
"THYRA");
206 bool result, success =
true;
208 *out <<
"\n*** Entering Thyra::MultiVectorTester<"<<ST::name()<<
">::check(mv,...) ...\n";
210 *out <<
"\nTesting a MultiVectorBase object mv described as:\n" << describe(mv,verbLevel);
214 *out <<
"\nChecking the LinearOpBase interface of mv ...\n";
215 result =linearOpTester_.check(mv, out.ptr());
216 if(!result) success =
false;
219 *out <<
"\nCongratulations, this MultiVectorBase object seems to check out!\n";
221 *out <<
"\nOh no, at least one of the tests performed with this MultiVectorBase object failed (see above failures)!\n";
223 *out <<
"\n*** Leaving MultiVectorTester<"<<ST::name()<<
">::check(mv,...)\n";
233 #endif // THYRA_MULTI_VECTOR_TESTER_DEF_HPP Abstract interface for objects that represent a space for vectors.
bool checkMultiVector(const VectorSpaceBase< Scalar > &vs, const Ptr< Teuchos::FancyOStream > &out) const
Check a multi-vector as created by a VectorSpaceBase object.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Local typedef for scalar magnitude.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
bool check(const MultiVectorBase< Scalar > &mv, const Ptr< Teuchos::FancyOStream > &out) const
Check a multi-vector object in a set of comprehensive teats.
MultiVectorTester(const ScalarMag warning_tol=1e-13, const ScalarMag error_tol=1e-10, const int num_random_vectors=1, const bool show_all_tests=false, const bool dump_all=false)
Default constructor which sets default parameter values.
virtual Ordinal dim() const =0
Return the dimension of the vector space.