Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_MultiVectorTester_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_MULTI_VECTOR_TESTER_DEF_HPP
43#define THYRA_MULTI_VECTOR_TESTER_DEF_HPP
44
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"
51
52
53namespace Thyra {
54
55
56template<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
72template<class Scalar>
75 const Ptr<Teuchos::FancyOStream> &out_inout
76 ) const
77{
78
79 using Teuchos::as;
80 using Teuchos::describe;
82 using Teuchos::OSTab;
83 using Teuchos::tuple;
84 using Teuchos::null;
86 //typedef typename ST::magnitudeType ScalarMag;
87
89 if (!is_null(out_inout))
90 out = Teuchos::rcpFromPtr(out_inout);
91 else
92 out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
93
94 const Teuchos::EVerbosityLevel verbLevel =
96
97 OSTab tab(out,1,"THYRA");
98
99 bool success = true;
100
101 *out << "\n*** Entering "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
102
103 *out << "\nTesting MultiVectorBase objects created from vs = " << describe(vs, verbLevel);
104
105 const Ordinal dim = vs.dim();
106 const Scalar scalarDim = as<Scalar>(dim);
107
108 int tc = 0;
109
110 *out << "\n"<<tc<<") Checking non-contiguous non-const multi-vector views ...\n";
111 ++tc;
112 {
113 OSTab tab2(out);
114 const int numCols = 6;
115 const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
116 assign<Scalar>(mv.ptr(), ST::zero());
117 const Scalar
118 one = as<Scalar>(1.0),
119 three = as<Scalar>(3.0),
120 five = as<Scalar>(5.0);
121 {
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);
126 }
127 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(0)), ST::zero(), error_tol_,
128 *out, success);
129 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(1)), as<Scalar>(one*scalarDim), error_tol_,
130 *out, success);
131 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(2)), ST::zero(), error_tol_,
132 *out, success);
133 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(3)), as<Scalar>(three*scalarDim), error_tol_,
134 *out, success);
135 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(4)), ST::zero(), error_tol_,
136 *out, success);
137 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(5)), as<Scalar>(five*scalarDim), error_tol_,
138 *out, success);
139 }
140
141 *out << "\n"<<tc<<") Checking non-contiguous const multi-vector views ...\n";
142 ++tc;
143 {
144 OSTab tab2(out);
145 const int numCols = 6;
146 const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
147 const Scalar
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);
155 {
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_,
159 *out, success);
160 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(1)), as<Scalar>(three*scalarDim), error_tol_,
161 *out, success);
162 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(2)), ST::zero(), error_tol_,
163 *out, success);
164 TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(3)), as<Scalar>(five*scalarDim), error_tol_,
165 *out, success);
166 }
167 }
168
169 if(success)
170 *out << "\nCongratulations, this MultiVectorBase objects"
171 << " created form this vector space seems to check out!\n";
172 else
173 *out << "\nOh no, at least one of the tests performed failed!\n";
174
175 *out << "\n*** Leaving "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
176
177 return success;
178
179}
180
181
182template<class Scalar>
184 const MultiVectorBase<Scalar> &mv,
185 const Ptr<Teuchos::FancyOStream> &out_inout
186 ) const
187{
188
189 using Teuchos::describe;
191 using Teuchos::OSTab;
193 //typedef typename ST::magnitudeType ScalarMag;
194
196 if (!is_null(out_inout))
197 out = Teuchos::rcpFromPtr(out_inout);
198 else
199 out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
200
201 const Teuchos::EVerbosityLevel verbLevel =
203
204 OSTab tab(out,1,"THYRA");
205
206 bool result, success = true;
207
208 *out << "\n*** Entering Thyra::MultiVectorTester<"<<ST::name()<<">::check(mv,...) ...\n";
209
210 *out << "\nTesting a MultiVectorBase object mv described as:\n" << describe(mv,verbLevel);
211
212 // ToDo: Test the specific MultiVectorBase interface
213
214 *out << "\nChecking the LinearOpBase interface of mv ...\n";
215 result =linearOpTester_.check(mv, out.ptr());
216 if(!result) success = false;
217
218 if(success)
219 *out << "\nCongratulations, this MultiVectorBase object seems to check out!\n";
220 else
221 *out << "\nOh no, at least one of the tests performed with this MultiVectorBase object failed (see above failures)!\n";
222
223 *out << "\n*** Leaving MultiVectorTester<"<<ST::name()<<">::check(mv,...)\n";
224
225 return success;
226
227}
228
229
230} // namespace Thyra
231
232
233#endif // THYRA_MULTI_VECTOR_TESTER_DEF_HPP
RCP< const T > getConst() const
Ptr< T > ptr() const
Interface for a collection of column vectors called a multi-vector.
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.
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.
bool check(const MultiVectorBase< Scalar > &mv, const Ptr< Teuchos::FancyOStream > &out) const
Check a multi-vector object in a set of comprehensive teats.
Abstract interface for objects that represent a space for vectors.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
TypeTo as(const TypeFrom &t)
T_To & dyn_cast(T_From &from)
#define TEUCHOS_TEST_FLOATING_EQUALITY(v1, v2, tol, out, success)