Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_VectorSpaceTester_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_VECTOR_SPACE_TESTER_HPP
11 #define THYRA_VECTOR_SPACE_TESTER_HPP
12 
13 #include "Thyra_VectorSpaceTester_decl.hpp"
14 #include "Thyra_TestingTools.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 #include "Thyra_MultiVectorStdOps.hpp"
17 #include "Teuchos_TestingHelpers.hpp"
18 
19 
20 namespace Thyra {
21 
22 
23 template <class Scalar>
25  const ScalarMag warning_tol_in
26  ,const ScalarMag error_tol_in
27  ,const int num_random_vectors_in
28  ,const int num_mv_cols_in
29  ,const bool show_all_tests_in
30  ,const bool dump_all_in
31  )
32  :num_mv_cols_(num_mv_cols_in) // declared first!
33  ,warning_tol_(warning_tol_in)
34  ,error_tol_(error_tol_in)
35  ,num_random_vectors_(num_random_vectors_in)
36  ,show_all_tests_(show_all_tests_in)
37  ,dump_all_(dump_all_in)
38 {}
39 
40 
41 template <class Scalar>
43  const VectorSpaceBase<Scalar> &vs
44  ,Teuchos::FancyOStream *out_arg
45  ) const
46 {
47  using std::endl;
48  using Teuchos::describe;
50  using Teuchos::OSTab;
52  //typedef typename ST::magnitudeType ScalarMag;
53 
54  Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
56 
57  OSTab tab(out,1,"THYRA");
58 
59  bool result, success = true;
60 
61  if (nonnull(out)) *out <<endl<< "*** Entering Thyra::VectorSpaceTester<"<<ST::name()<<">::check(vs,...) ...\n";
62 
63  if (nonnull(out)) *out <<endl<< "Testing a vector space vs described as:\n" << describe(vs,verbLevel);
64 
65  if (nonnull(out))
66  *out
67  <<endl<< "A) Calling basic query functions ...\n"
68  <<endl<< "vs.dim() = " << vs.dim()
69  <<endl<< "vs.hasInCoreView() = " << vs.hasInCoreView() << std::endl;
70 
71  if (nonnull(out)) *out <<endl<< "B) Checking that vs is compatible with itself, cloning, etc. ...\n";
72 
73  TEUCHOS_TEST_ASSERT(vs.isCompatible(vs), *out, success);
74 
75  const RCP<const VectorSpaceBase<Scalar> > vs_clone = vs.clone();
76  if (nonnull(vs_clone)) {
77  TEUCHOS_TEST_ASSERT(vs.isCompatible(*vs_clone), *out, success);
78  }
79 
80  if (nonnull(out)) *out <<endl<< "C) Creating a randomized vector member v ...\n";
82  v = createMember(vs);
83  randomize(Scalar(-ST::one()),Scalar(+ST::one()),v.ptr());
84 
85  if (nonnull(out)) *out <<endl<< "D) Testing the VectorBase interface of v ...\n";
86 
87  result = vectorTester_.check(*v,out.get());
88  if(!result) success = false;
89 
90  if (nonnull(out)) *out <<endl<< "C) Creating a randomized MultiVector member mv ...\n";
92  mv = createMembers(vs,num_mv_cols());
93  randomize(Scalar(-ST::one()),Scalar(+ST::one()),mv.ptr());
94 
95  if (nonnull(out)) *out <<endl<< "D) Testing the MultiVectorBase interface of mv ...\n";
96 
97  result = vectorTester_.multiVectorTester().check(*mv, out.ptr());
98  if(!result) success = false;
99 
100  if (nonnull(out)) {
101  if(success)
102  *out << endl <<"Congratulations, this VectorSpaceBase object seems to check out!\n";
103  else
104  *out << endl <<"Oh no, at least one of the tests performed with this VectorSpaceBase object failed (see above failures)!\n";
105  *out << endl << "*** Leaving VectorSpaceTester<"<<ST::name()<<">::check(vs,...)\n";
106  }
107 
108  return success;
109 
110 }
111 
112 
113 } // namespace Thyra
114 
115 
116 #endif // THYRA_VECTOR_SPACE_TESTER_HPP
basic_OSTab< char > OSTab
virtual RCP< const VectorSpaceBase< Scalar > > clone() const
Clone this object (if supported).
basic_FancyOStream< char > FancyOStream
T * get() const
Abstract interface for objects that represent a space for vectors.
VectorSpaceTester(const ScalarMag warning_tol=1e-13, const ScalarMag error_tol=1e-10, const int num_random_vectors=1, const int num_mv_cols=4, const bool show_all_tests=false, const bool dump_all=false)
Default constructor which sets default parameter values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_TEST_ASSERT(v1, out, success)
Ptr< T > ptr() const
bool nonnull(const boost::shared_ptr< T > &p)
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Local typedef for scalar magnitude.
bool check(const VectorSpaceBase< Scalar > &vs, Teuchos::FancyOStream *out) const
Check a vector space and the objects it creates through a set of comprehensive tests.
virtual bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const =0
Compare the compatibility of two vector spaces.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
virtual bool hasInCoreView(const Range1D &rng=Range1D(), const EViewType viewType=VIEW_TYPE_DETACHED, const EStrideType strideType=STRIDE_TYPE_NONUNIT) const
Returns true if this-&gt;acquireDetachedView(rng,...) returns a direct view of the range of data request...