Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_MultiVectorTester_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_MULTI_VECTOR_TESTER_DEF_HPP
11 #define THYRA_MULTI_VECTOR_TESTER_DEF_HPP
12 
13 #include "Thyra_MultiVectorTester_decl.hpp"
14 #include "Thyra_MultiVectorBase.hpp"
15 #include "Thyra_MultiVectorStdOps.hpp"
16 #include "Thyra_VectorSpaceBase.hpp"
17 #include "Thyra_VectorStdOps.hpp"
18 #include "Teuchos_TestingHelpers.hpp"
19 
20 
21 namespace Thyra {
22 
23 
24 template<class Scalar>
26  const ScalarMag warning_tol_in,
27  const ScalarMag error_tol_in,
28  const int num_random_vectors_in,
29  const bool show_all_tests_in,
30  const bool dump_all_in
31  )
32  :warning_tol_(warning_tol_in),
33  error_tol_(error_tol_in),
34  num_random_vectors_(num_random_vectors_in),
35  show_all_tests_(show_all_tests_in),
36  dump_all_(dump_all_in)
37 {}
38 
39 
40 template<class Scalar>
42  const VectorSpaceBase<Scalar> &vs,
43  const Ptr<Teuchos::FancyOStream> &out_inout
44  ) const
45 {
46 
47  using Teuchos::as;
48  using Teuchos::describe;
50  using Teuchos::OSTab;
51  using Teuchos::tuple;
52  using Teuchos::null;
54  //typedef typename ST::magnitudeType ScalarMag;
55 
57  if (!is_null(out_inout))
58  out = Teuchos::rcpFromPtr(out_inout);
59  else
60  out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
61 
62  const Teuchos::EVerbosityLevel verbLevel =
64 
65  OSTab tab(out,1,"THYRA");
66 
67  bool success = true;
68 
69  *out << "\n*** Entering "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
70 
71  *out << "\nTesting MultiVectorBase objects created from vs = " << describe(vs, verbLevel);
72 
73  const Ordinal dim = vs.dim();
74  const Scalar scalarDim = as<Scalar>(dim);
75 
76  int tc = 0;
77 
78  *out << "\n"<<tc<<") Checking non-contiguous non-const multi-vector views ...\n";
79  ++tc;
80  {
81  OSTab tab2(out);
82  const int numCols = 6;
83  const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
84  assign<Scalar>(mv.ptr(), ST::zero());
85  const Scalar
86  one = as<Scalar>(1.0),
87  three = as<Scalar>(3.0),
88  five = as<Scalar>(5.0);
89  {
90  const RCP<MultiVectorBase<Scalar> > mvView = mv->subView(tuple<int>(1, 3, 5)());
91  assign<Scalar>(mvView->col(0).ptr(), one);
92  assign<Scalar>(mvView->col(1).ptr(), three);
93  assign<Scalar>(mvView->col(2).ptr(), five);
94  }
95  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(0)), ST::zero(), error_tol_,
96  *out, success);
97  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(1)), as<Scalar>(one*scalarDim), error_tol_,
98  *out, success);
99  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(2)), ST::zero(), error_tol_,
100  *out, success);
101  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(3)), as<Scalar>(three*scalarDim), error_tol_,
102  *out, success);
103  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(4)), ST::zero(), error_tol_,
104  *out, success);
105  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(5)), as<Scalar>(five*scalarDim), error_tol_,
106  *out, success);
107  }
108 
109  *out << "\n"<<tc<<") Checking non-contiguous const multi-vector views ...\n";
110  ++tc;
111  {
112  OSTab tab2(out);
113  const int numCols = 6;
114  const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
115  const Scalar
116  one = as<Scalar>(1.0),
117  three = as<Scalar>(3.0),
118  five = as<Scalar>(5.0);
119  assign<Scalar>(mv.ptr(), ST::zero());
120  assign<Scalar>(mv->col(1).ptr(), one);
121  assign<Scalar>(mv->col(3).ptr(), three);
122  assign<Scalar>(mv->col(5).ptr(), five);
123  {
124  const RCP<const MultiVectorBase<Scalar> > mvView =
125  mv.getConst()->subView(tuple<int>(1, 3, 4, 5)());
126  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(0)), as<Scalar>(one*scalarDim), error_tol_,
127  *out, success);
128  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(1)), as<Scalar>(three*scalarDim), error_tol_,
129  *out, success);
130  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(2)), ST::zero(), error_tol_,
131  *out, success);
132  TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(3)), as<Scalar>(five*scalarDim), error_tol_,
133  *out, success);
134  }
135  }
136 
137  if(success)
138  *out << "\nCongratulations, this MultiVectorBase objects"
139  << " created form this vector space seems to check out!\n";
140  else
141  *out << "\nOh no, at least one of the tests performed failed!\n";
142 
143  *out << "\n*** Leaving "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
144 
145  return success;
146 
147 }
148 
149 
150 template<class Scalar>
152  const MultiVectorBase<Scalar> &mv,
153  const Ptr<Teuchos::FancyOStream> &out_inout
154  ) const
155 {
156 
157  using Teuchos::describe;
158  using Teuchos::FancyOStream;
159  using Teuchos::OSTab;
161  //typedef typename ST::magnitudeType ScalarMag;
162 
163  RCP<FancyOStream> out;
164  if (!is_null(out_inout))
165  out = Teuchos::rcpFromPtr(out_inout);
166  else
167  out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
168 
169  const Teuchos::EVerbosityLevel verbLevel =
171 
172  OSTab tab(out,1,"THYRA");
173 
174  bool result, success = true;
175 
176  *out << "\n*** Entering Thyra::MultiVectorTester<"<<ST::name()<<">::check(mv,...) ...\n";
177 
178  *out << "\nTesting a MultiVectorBase object mv described as:\n" << describe(mv,verbLevel);
179 
180  // ToDo: Test the specific MultiVectorBase interface
181 
182  *out << "\nChecking the LinearOpBase interface of mv ...\n";
183  result =linearOpTester_.check(mv, out.ptr());
184  if(!result) success = false;
185 
186  if(success)
187  *out << "\nCongratulations, this MultiVectorBase object seems to check out!\n";
188  else
189  *out << "\nOh no, at least one of the tests performed with this MultiVectorBase object failed (see above failures)!\n";
190 
191  *out << "\n*** Leaving MultiVectorTester<"<<ST::name()<<">::check(mv,...)\n";
192 
193  return success;
194 
195 }
196 
197 
198 } // namespace Thyra
199 
200 
201 #endif // THYRA_MULTI_VECTOR_TESTER_DEF_HPP
RCP< const T > getConst() const
bool is_null(const boost::shared_ptr< T > &p)
basic_OSTab< char > OSTab
basic_FancyOStream< char > FancyOStream
Abstract interface for objects that represent a space for vectors.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Local typedef for scalar magnitude.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
Ptr< T > ptr() const
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.
TypeTo as(const TypeFrom &t)
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)
bool checkMultiVector(const VectorSpaceBase< Scalar > &vs, const Ptr< Teuchos::FancyOStream > &out) const
Check a multi-vector as created by a VectorSpaceBase object.
virtual Ordinal dim() const =0
Return the dimension of the vector space.