Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_VectorSpaceTester_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_SPACE_TESTER_HPP
43#define THYRA_VECTOR_SPACE_TESTER_HPP
44
45#include "Thyra_VectorSpaceTester_decl.hpp"
46#include "Thyra_TestingTools.hpp"
47#include "Thyra_VectorStdOps.hpp"
48#include "Thyra_MultiVectorStdOps.hpp"
49#include "Teuchos_TestingHelpers.hpp"
50
51
52namespace Thyra {
53
54
55template <class Scalar>
57 const ScalarMag warning_tol_in
58 ,const ScalarMag error_tol_in
59 ,const int num_random_vectors_in
60 ,const int num_mv_cols_in
61 ,const bool show_all_tests_in
62 ,const bool dump_all_in
63 )
64 :num_mv_cols_(num_mv_cols_in) // declared first!
65 ,warning_tol_(warning_tol_in)
66 ,error_tol_(error_tol_in)
67 ,num_random_vectors_(num_random_vectors_in)
68 ,show_all_tests_(show_all_tests_in)
69 ,dump_all_(dump_all_in)
70{}
71
72
73template <class Scalar>
76 ,Teuchos::FancyOStream *out_arg
77 ) const
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 (nonnull(out)) *out <<endl<< "*** Entering Thyra::VectorSpaceTester<"<<ST::name()<<">::check(vs,...) ...\n";
94
95 if (nonnull(out)) *out <<endl<< "Testing a vector space vs described as:\n" << describe(vs,verbLevel);
96
97 if (nonnull(out))
98 *out
99 <<endl<< "A) Calling basic query functions ...\n"
100 <<endl<< "vs.dim() = " << vs.dim()
101 <<endl<< "vs.hasInCoreView() = " << vs.hasInCoreView() << std::endl;
102
103 if (nonnull(out)) *out <<endl<< "B) Checking that vs is compatible with itself, cloning, etc. ...\n";
104
105 TEUCHOS_TEST_ASSERT(vs.isCompatible(vs), *out, success);
106
107 const RCP<const VectorSpaceBase<Scalar> > vs_clone = vs.clone();
108 if (nonnull(vs_clone)) {
109 TEUCHOS_TEST_ASSERT(vs.isCompatible(*vs_clone), *out, success);
110 }
111
112 if (nonnull(out)) *out <<endl<< "C) Creating a randomized vector member v ...\n";
114 v = createMember(vs);
115 randomize(Scalar(-ST::one()),Scalar(+ST::one()),v.ptr());
116
117 if (nonnull(out)) *out <<endl<< "D) Testing the VectorBase interface of v ...\n";
118
119 result = vectorTester_.check(*v,out.get());
120 if(!result) success = false;
121
122 if (nonnull(out)) *out <<endl<< "C) Creating a randomized MultiVector member mv ...\n";
124 mv = createMembers(vs,num_mv_cols());
125 randomize(Scalar(-ST::one()),Scalar(+ST::one()),mv.ptr());
126
127 if (nonnull(out)) *out <<endl<< "D) Testing the MultiVectorBase interface of mv ...\n";
128
129 result = vectorTester_.multiVectorTester().check(*mv, out.ptr());
130 if(!result) success = false;
131
132 if (nonnull(out)) {
133 if(success)
134 *out << endl <<"Congratulations, this VectorSpaceBase object seems to check out!\n";
135 else
136 *out << endl <<"Oh no, at least one of the tests performed with this VectorSpaceBase object failed (see above failures)!\n";
137 *out << endl << "*** Leaving VectorSpaceTester<"<<ST::name()<<">::check(vs,...)\n";
138 }
139
140 return success;
141
142}
143
144
145} // namespace Thyra
146
147
148#endif // THYRA_VECTOR_SPACE_TESTER_HPP
Ptr< T > ptr() const
T * get() const
Abstract interface for objects that represent a space for vectors.
virtual RCP< const VectorSpaceBase< Scalar > > clone() const
Clone this object (if supported).
virtual bool hasInCoreView(const Range1D &rng=Range1D(), const EViewType viewType=VIEW_TYPE_DETACHED, const EStrideType strideType=STRIDE_TYPE_NONUNIT) const
Returns true if this->acquireDetachedView(rng,...) returns a direct view of the range of data request...
virtual Ordinal dim() const =0
Return the dimension of the vector space.
virtual bool isCompatible(const VectorSpaceBase< Scalar > &vecSpc) const =0
Compare the compatibility of two vector spaces.
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Local typedef for scalar magnitude.
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.
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.
#define TEUCHOS_TEST_ASSERT(v1, out, success)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)