Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_VectorTester_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_VECTOR_TESTER_HPP
43 #define THYRA_VECTOR_TESTER_HPP
44 
45 #include "Thyra_VectorTester_decl.hpp"
46 #include "Thyra_VectorStdOps.hpp"
47 #include "Thyra_VectorBase.hpp"
48 #include "Thyra_VectorSpaceBase.hpp"
49 #include "Thyra_TestingTools.hpp"
50 #include "Teuchos_VerbosityLevel.hpp"
51 
52 
53 namespace Thyra {
54 
55 
56 template<class Scalar>
58  const ScalarMag warning_tol_in
59  ,const ScalarMag error_tol_in
60  ,const int num_random_vectors_in
61  ,const bool show_all_tests_in
62  ,const bool dump_all_in
63  )
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)
69 {}
70 
71 
72 template<class Scalar>
74  const VectorBase<Scalar> &v
75  ,Teuchos::FancyOStream *out_arg
76  ) const
77 {
78 
79  using std::endl;
80  using Teuchos::describe;
82  using Teuchos::OSTab;
84  //typedef typename ST::magnitudeType ScalarMag;
85 
86  Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
88 
89  OSTab tab(out,1,"THYRA");
90 
91  bool result, success = true;
92 
93  if(out.get()) *out <<endl<< "*** Entering Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
94 
95  if(out.get()) *out <<endl<< "Testing a VectorBase object described as:\n" << describe(v,verbLevel);
96 
97  if(out.get()) *out <<endl<< "A) Creating temporary vector t1, t2, t3, and t4 from v.space() ...\n";
99  vs = v.space();
101  t1 = createMember(vs), t2 = createMember(vs), t3 = createMember(vs), t4 = createMember(vs);
102 
103  if(out.get()) *out <<endl<< "B) Testing VectorBase::applyOp(...) by calling a few standard RTOp operations ... ";
104 
105  const Scalar
106  one = ST::one(),
107  two = Scalar(2)*one,
108  three = Scalar(3)*one;
109 
110  {
111  using Teuchos::inoutArg;
112 
113  TestResultsPrinter testResultsPrinter(out, show_all_tests());
114  const RCP<FancyOStream> testOut = testResultsPrinter.getTestOStream();
115 
116  bool these_results = true;
117 
118  *testOut <<endl<< "assign(t1.ptr(),2.0) ...\n";
119  Thyra::assign( t1.ptr(), two );
120  if(dump_all()) *testOut <<endl<< "\nt1 =\n" << describe(*t1,verbLevel);
121 
122  result = Teuchos::testRelErr<Scalar>(
123  "sum(t1)", sum(*t1), "2*vs->dim()", two*Scalar(vs->dim()),
124  "error_tol()", error_tol(), "warning_tol()", warning_tol(),
125  inoutArg(*testOut)
126  );
127  if(!result) these_results = false;
128 
129  *testOut <<endl<< "assign(t2.ptr(),3.0) ...\n";
130  Thyra::assign( t2.ptr(), three );
131  if(dump_all()) *testOut <<endl<< "t2 =\n" << *t1;
132 
133  result = Teuchos::testRelErr<Scalar>(
134  "sum(t2)",sum(*t2),"3*vs->dim()",three*Scalar(vs->dim()),
135  "error_tol()",error_tol(),"warning_tol()",warning_tol(),
136  inoutArg(*testOut)
137  );
138  if(!result) these_results = false;
139 
140  result = Teuchos::testRelErr<Scalar>(
141  "vs->scalarProd(*t1,*t2)",vs->scalarProd(*t1,*t2),"2*3*vs->dim()",two*three*Scalar(vs->dim()),
142  "error_tol()",error_tol(),"warning_tol()",warning_tol(),
143  inoutArg(*testOut)
144  );
145  if(!result) these_results = false;
146 
147  testResultsPrinter.printTestResults(these_results, inoutArg(success));
148 
149  }
150 
151  // ToDo: Test the rest of the specific VectorBase interface on v1
152 
153  if(out.get()) *out <<endl<< "C) Checking the MultiVectorBase interface of v ...\n";
154  result = multiVectorTester_.check(v, out.ptr());
155  if(!result) success = false;
156 
157  if(out.get()) *out <<endl<< "*** Leaving Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
158 
159  return success;
160 
161 }
162 
163 
164 } // namespace Thyra
165 
166 
167 #endif // THYRA_VECTOR_TESTER_HPP
Control printing of test results.
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
basic_OSTab< char > OSTab
basic_FancyOStream< char > FancyOStream
T * get() const
bool check(const VectorBase< Scalar > &v, Teuchos::FancyOStream *out) const
Check a vector object in a set of comprehensive tests.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Ptr< T > ptr() const
void printTestResults(const bool this_result, const Ptr< bool > &success)
Print the test result.
Abstract interface for finite-dimensional dense vectors.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Local typedef for scalar magnitude.
VectorTester(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.
RCP< FancyOStream > getTestOStream()
Return the stream used for testing.