42#ifndef THYRA_MULTI_VECTOR_STD_OPS_TESTER_HPP
43#define THYRA_MULTI_VECTOR_STD_OPS_TESTER_HPP
45#include "Thyra_MultiVectorStdOpsTester_decl.hpp"
46#include "Thyra_MultiVectorStdOps.hpp"
47#include "Thyra_VectorStdOps.hpp"
48#include "Thyra_TestingTools.hpp"
54template <
class Scalar>
58 ,
const int num_mv_cols_in
60 :warning_tol_(warning_tol_in)
61 ,error_tol_(error_tol_in)
62 ,num_mv_cols_(num_mv_cols_in)
65template <
class Scalar>
78 *out <<
"\n*** Entering MultiVectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n"
79 <<
"using a \'" << vecSpc.
description() <<
"\' object ...\n";
82 if(out) *out <<
"\nvecSpc.dim() = " << vecSpc.
dim() << std::endl;
87 two = as<Scalar>(2.0),
88 three = as<Scalar>(3.0),
89 four = as<Scalar>(4.0);
93 if(out) *out <<
"\nCreating MultiVectorBase objects V1, V2, and V3 ...\n";
99 if(out) *out <<
"\nassign(V1.ptr(),-2.0);\n";
108 if(out) *out <<
"\n"<<tc<<
") sums(*V1);\n";
111 sums(*V1, scalars1());
113 scalars2[i] = -two*as<Scalar>(vecSpc.
dim());
115 "sums(*V1)", scalars1(),
116 "-2.0*n", scalars2(),
117 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
123 if(out) *out <<
"\n"<<tc<<
") norms_1(*V1);\n";
128 mags2[i] = ST::magnitude(two)*as<ScalarMag>(vecSpc.
dim());
130 "norms_1(*V1)", mags1(),
132 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
138 if(out) *out <<
"\n"<<tc<<
") norms_2(*V1);\n";
143 mags2[i] = ST::magnitude(two * ST::squareroot(as<Scalar>(n)));
145 "norms_2(*V1)", mags1(),
146 "2.0*sqrt(n)", mags2(),
147 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
153 if(out) *out <<
"\n"<<tc<<
") norms_inf(*V1);\n";
158 mags2[i] = ST::magnitude(two);
160 "norms_inf(*V1)", mags1(),
162 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
168 if(out) *out <<
"\n"<<tc<<
") assign(V2.ptr(), alpha);\n";
174 mags2[i] = ST::magnitude(three * ST::squareroot(as<Scalar>(n)));
176 "norms_2(*V2)", mags1(),
177 "3.0*sqrt(n)", mags2(),
178 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
184 if(out) *out <<
"\n"<<tc<<
") assign(V2.ptr(), *V1);\n";
190 "norms_2(*V1)", mags1(),
191 "norms_2(*V2)", mags2(),
192 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
197 if(out) *out <<
"\n"<<tc<<
") scale(alpha,V2.ptr());\n";
200 Scalar alpha = as<Scalar>(1.2345);
202 scale(alpha, V2.ptr());
205 mags1[i] *= ST::magnitude(alpha);
208 "norms_2(alpha*V1)", mags1(),
209 "alpha*norms_2(V1)", mags2(),
210 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
216 if(out) *out <<
"\n"<<tc<<
") scaleUpdate(a,V1,V2.ptr());\n";
225 "norms_2(*V2)", mags1(),
226 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
232 if(out) *out <<
"\n"<<tc<<
") update(a,V1,V2.ptr());\n";
235 Scalar alpha = as<Scalar>(1.2345);
238 scale(alpha, V3.ptr());
244 "norms_2(*V2)", mags1(),
245 "norms_2(*V3)", mags2(),
246 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
252 if(out) *out <<
"\n"<<tc<<
") update(alpha,beta,*V1,V2.ptr());\n";
257 alpha[i] = as<Scalar>(i+1);
258 Scalar beta = as<Scalar>(1.2345);
261 scale(beta, V3.ptr());
263 scale(alpha[i], V3->col(i).ptr());
270 "norms_2(*V2)", mags1(),
271 "norms_2(*V3)", mags2(),
272 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
278 if(out) *out <<
"\n"<<tc<<
") update(*V1,alpha,beta,V2.ptr());\n";
283 alpha[i] = as<Scalar>(i+1);
284 Scalar beta = as<Scalar>(1.2345);
287 scale(beta, V3.ptr());
289 scale(alpha[i], V3->col(i).ptr());
292 update(*V1, alphaView, beta, V2.ptr());
296 "norms_2(*V2)", mags1(),
297 "norms_2(*V3)", mags2(),
298 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
304 if(out) *out <<
"\n"<<tc<<
") linear_combination({alpha,beta,gamma},{V1.ptr(),V2.ptr(),V3.ptr()},0.0,V4.ptr());\n";
307 Scalar alpha = two, beta = -three, gamma = three;
312 tuple<Scalar>(alpha, beta, gamma),
318 mags2[i] = ST::magnitude(two * ST::squareroot(as<Scalar>(n)));
320 "norms_2(*V4)", mags1(),
321 "2.0*sqrt(n)", mags2(),
322 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
327 if(out) *out <<
"\n"<<tc<<
") linear_combination({alpha,beta,gamma},{V1.ptr(),V2.ptr(),V3.ptr()},0.5,V4.ptr());\n";
330 Scalar alpha = two, beta = -three, gamma = three;
336 tuple<Scalar>(alpha, beta, gamma),
342 "norms_2(*V4)", mags1(),
343 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
349 if(out) *out <<
"\n"<<tc<<
") Vt_S(V1.ptr(),alpha);\n";
352 Scalar alpha = as<Scalar>(1.2345);
354 Vt_S(V2.ptr(), alpha);
357 mags1[i] *= ST::magnitude(alpha);
360 "norms_2(alpha*V1)", mags1(),
361 "alpha*norms_2(V1)", mags2(),
362 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
368 if(out) *out <<
"\n"<<tc<<
") Vp_S(V2.ptr(),alpha);\n";
375 "norms_2(V2)", mags1(),
376 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
382 if(out) *out <<
"\n"<<tc<<
") Vp_V(V2.ptr(),*V1);\n";
389 "norms_2(V2)", mags1(),
390 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
397 if(out) *out <<
"\n"<<tc<<
") V_VpV(V3.ptr(),*V1,*V2);\n";
401 V_VpV(V3.ptr(), *V1, *V2);
404 "norms_2(V3)", mags1(),
405 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
412 if(out) *out <<
"\n"<<tc<<
") V_VmV(V3.ptr(),*V1,*V2);\n";
416 V_VmV(V3.ptr(), *V1, *V2);
419 "norms_2(V3)", mags1(),
420 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
427 if(out) *out <<
"\n"<<tc<<
") V_StVpV(V3.ptr(),alpha,*V1,*V2);\n";
430 Scalar alpha = as<Scalar>(1.2345);
432 V_StVpV(V3.ptr(), alpha, *V1, *V2);
435 V_VmV(V3.ptr(), *V2, *V3);
438 "norms_2(V3)", mags1(),
439 "error_tol", error_tol(),
"warning_tol", warning_tol(), ptr(out)
446 <<
"\n*** Leaving MultiVectorStdOpsTester<"<<ST::name()<<
">::checkStdOps(...) ...\n";
virtual std::string description() const
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
Interface for a collection of column vectors called a multi-vector.
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
void sums(const MultiVectorBase< Scalar > &V, const ArrayView< Scalar > &sums)
Multi-vector column sum.
void V_VpV(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = X(i,j) + Y(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void norms_inf(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector infinity norm.
void Vt_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) *= alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void update(Scalar alpha, const MultiVectorBase< Scalar > &U, const Ptr< MultiVectorBase< Scalar > > &V)
alpha*U + V -> V.
void norms_2(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector 2 (Euclidean) norm.
void V_VmV(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = X(i,j) - Y(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void linear_combination(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &X, const Scalar &beta, const Ptr< MultiVectorBase< Scalar > > &Y)
Y.col(j)(i) = beta*Y.col(j)(i) + sum( alpha[k]*X[k].col(j)(i), k=0...m-1 ), for i = 0....
void scaleUpdate(const VectorBase< Scalar > &a, const MultiVectorBase< Scalar > &U, const Ptr< MultiVectorBase< Scalar > > &V)
A*U + V -> V (where A is a diagonal matrix with diagonal a).
void V_StVpV(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha, const MultiVectorBase< Scalar > &X, const MultiVectorBase< Scalar > &Y)
Z(i,j) = alpha*X(i,j) + Y(i), i = 0...z->space()->dim()-1, , j = 0...Z->domain()->dim()-1.
void Vp_V(const Ptr< MultiVectorBase< Scalar > > &Z, const MultiVectorBase< Scalar > &X)
Z(i,j) += X(i,j), i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void Vp_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) += alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.
void norms_1(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector one norm.
bool checkStdOps(const VectorSpaceBase< Scalar > &vecSpc, std::ostream *out=0, const bool &dumpAll=false)
Run the tests using a vector space.
MultiVectorStdOpsTester(const ScalarMag &warning_tol=0, const ScalarMag &error_tol=0, const int num_mv_cols=4)
Teuchos::ScalarTraits< Scalar >::magnitudeType ScalarMag
Abstract interface for objects that represent a space for vectors.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
RCP< MultiVectorBase< Scalar > > createMembers(const RCP< const VectorSpaceBase< Scalar > > &vs, int numMembers, const std::string &label="")
Create a set of vector members (a MultiVectorBase) from the vector space.
bool testRelErrors(const std::string &v1_name, const ArrayView< const Scalar1 > &v1, const std::string &v2_name, const ArrayView< const Scalar2 > &v2, const std::string &maxRelErr_error_name, const ScalarMag &maxRelErr_error, const std::string &maxRelErr_warning_name, const ScalarMag &maxRelErr_warning, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Compute, check and optionally print the relative errors in two scalar arays.
bool testMaxErrors(const std::string &error_name, const ArrayView< const typename Teuchos::ScalarTraits< Scalar >::magnitudeType > &errors, const std::string &max_error_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_error, const std::string &max_warning_name, const typename Teuchos::ScalarTraits< Scalar >::magnitudeType &max_warning, const Ptr< std::ostream > &out, const std::string &leadingIndent=std::string(""))
Check that an array of errors is less than some error tolerence.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
TypeTo as(const TypeFrom &t)