Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_VectorTester_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_TESTER_HPP
11#define THYRA_VECTOR_TESTER_HPP
12
13#include "Thyra_VectorTester_decl.hpp"
14#include "Thyra_VectorStdOps.hpp"
15#include "Thyra_VectorBase.hpp"
16#include "Thyra_VectorSpaceBase.hpp"
17#include "Thyra_TestingTools.hpp"
18#include "Teuchos_VerbosityLevel.hpp"
19
20
21namespace Thyra {
22
23
24template<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
40template<class Scalar>
42 const VectorBase<Scalar> &v
43 ,Teuchos::FancyOStream *out_arg
44 ) const
45{
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(out.get()) *out <<endl<< "*** Entering Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
62
63 if(out.get()) *out <<endl<< "Testing a VectorBase object described as:\n" << describe(v,verbLevel);
64
65 if(out.get()) *out <<endl<< "A) Creating temporary vector t1, t2, t3, and t4 from v.space() ...\n";
67 vs = v.space();
69 t1 = createMember(vs), t2 = createMember(vs), t3 = createMember(vs), t4 = createMember(vs);
70
71 if(out.get()) *out <<endl<< "B) Testing VectorBase::applyOp(...) by calling a few standard RTOp operations ... ";
72
73 const Scalar
74 one = ST::one(),
75 two = Scalar(2)*one,
76 three = Scalar(3)*one;
77
78 {
79 using Teuchos::inoutArg;
80
81 TestResultsPrinter testResultsPrinter(out, show_all_tests());
82 const RCP<FancyOStream> testOut = testResultsPrinter.getTestOStream();
83
84 bool these_results = true;
85
86 *testOut <<endl<< "assign(t1.ptr(),2.0) ...\n";
87 Thyra::assign( t1.ptr(), two );
88 if(dump_all()) *testOut <<endl<< "\nt1 =\n" << describe(*t1,verbLevel);
89
91 "sum(t1)", sum(*t1), "2*vs->dim()", two*Scalar(vs->dim()),
92 "error_tol()", error_tol(), "warning_tol()", warning_tol(),
93 inoutArg(*testOut)
94 );
95 if(!result) these_results = false;
96
97 *testOut <<endl<< "assign(t2.ptr(),3.0) ...\n";
98 Thyra::assign( t2.ptr(), three );
99 if(dump_all()) *testOut <<endl<< "t2 =\n" << *t1;
100
102 "sum(t2)",sum(*t2),"3*vs->dim()",three*Scalar(vs->dim()),
103 "error_tol()",error_tol(),"warning_tol()",warning_tol(),
104 inoutArg(*testOut)
105 );
106 if(!result) these_results = false;
107
109 "vs->scalarProd(*t1,*t2)",vs->scalarProd(*t1,*t2),"2*3*vs->dim()",two*three*Scalar(vs->dim()),
110 "error_tol()",error_tol(),"warning_tol()",warning_tol(),
111 inoutArg(*testOut)
112 );
113 if(!result) these_results = false;
114
115 testResultsPrinter.printTestResults(these_results, inoutArg(success));
116
117 }
118
119 // ToDo: Test the rest of the specific VectorBase interface on v1
120
121 if(out.get()) *out <<endl<< "C) Checking the MultiVectorBase interface of v ...\n";
122 result = multiVectorTester_.check(v, out.ptr());
123 if(!result) success = false;
124
125 if(out.get()) *out <<endl<< "*** Leaving Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
126
127 return success;
128
129}
130
131
132} // namespace Thyra
133
134
135#endif // THYRA_VECTOR_TESTER_HPP
Ptr< T > ptr() const
T * get() const
Control printing of test results.
RCP< FancyOStream > getTestOStream()
Return the stream used for testing.
void printTestResults(const bool this_result, const Ptr< bool > &success)
Print the test result.
Abstract interface for finite-dimensional dense vectors.
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
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.
bool check(const VectorBase< Scalar > &v, Teuchos::FancyOStream *out) const
Check a vector object in a set of comprehensive tests.
T_To & dyn_cast(T_From &from)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)