10#ifndef ANASAZI_MVOPTESTER_HPP
11#define ANASAZI_MVOPTESTER_HPP
34#include "Teuchos_SetScientific.hpp"
35#include "Teuchos_RCP.hpp"
36#include "Teuchos_as.hpp"
45 template<
class ScalarType,
class MV >
48 const Teuchos::RCP<const MV> &
A ) {
51 using Teuchos::SetScientific;
128 typedef Teuchos::ScalarTraits<ScalarType> SCT;
129 typedef typename SCT::magnitudeType
MagType;
131 const ScalarType
one = SCT::one();
132 const ScalarType
zero = SCT::zero();
161 if ( MVT::GetNumberVecs(*
A) <= 0 ) {
163 <<
"*** ERROR *** MultiVectorTraits::GetNumberVecs()." <<
endl
164 <<
"Returned <= 0." <<
endl;
172 if ( MVT::GetGlobalLength(*
A) <= 0 ) {
174 <<
"*** ERROR *** MultiVectorTraitsExt::GetGlobalLength()" <<
endl
175 <<
"Returned <= 0." <<
endl;
186 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs);
190 if ( MVT::GetNumberVecs(*
B) !=
numvecs ) {
192 <<
"*** ERROR *** MultiVecTraits::Clone()." <<
endl
193 <<
"Did not allocate requested number of vectors." <<
endl;
196 if ( MVT::GetGlobalLength(*
B) != MVT::GetGlobalLength(*
A) ) {
198 <<
"*** ERROR *** MultiVecTraits::Clone()." <<
endl
199 <<
"Did not allocate requested number of vectors." <<
endl;
205 <<
"*** WARNING *** MultiVecTraits::MvNorm()." <<
endl
206 <<
"Method resized the output vector." <<
endl;
212 <<
"*** ERROR *** MultiVecTraits::Clone()." <<
endl
213 <<
"Vector had negative norm." <<
endl;
236 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs);
244 <<
"*** ERROR *** MultiVecTraits::MvInit() "
245 <<
"and MultiVecTraits::MvNorm()" <<
endl
246 <<
"Supposedly zero vector has non-zero norm." <<
endl;
257 <<
"*** ERROR *** MultiVecTraits::MvRandom()." <<
endl
258 <<
"Random vector was empty (very unlikely)." <<
endl;
263 <<
"*** ERROR *** MultiVecTraits::MvRandom()." <<
endl
264 <<
"Vector had negative norm." <<
endl;
269 <<
"*** ERROR *** MutliVecTraits::MvRandom()." <<
endl
270 <<
"Vectors not random enough." <<
endl;
285 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs);
289 MVT::MvScale(*
B,SCT::zero());
294 <<
"*** ERROR *** MultiVecTraits::MvScale(alpha) "
295 <<
"Supposedly zero vector has non-zero norm." <<
endl;
307 <<
"*** ERROR *** MultiVecTraits::MvScale(alphas) "
308 <<
"Supposedly zero vector has non-zero norm." <<
endl;
329 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs);
338 <<
"*** ERROR *** MultiVecTraits::MvRandom()." <<
endl
339 <<
"Vector had negative norm." <<
endl;
345 <<
"Warning testing MultiVecTraits::MvInit()." <<
endl
346 <<
"Ones vector should have norm sqrt(dim)." <<
endl
347 <<
"norms[i]: " <<
norms[
i] <<
"\tdim: " << MVT::GetGlobalLength(*
B) <<
endl <<
endl;
362 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs);
369 <<
"*** ERROR *** MultiVecTraits::MvInit()." <<
endl
370 <<
"Vector had negative norm." <<
endl;
375 <<
"*** ERROR *** MultiVecTraits::MvInit()." <<
endl
376 <<
"Zero vector should have norm zero." <<
endl;
389 Teuchos::RCP<MV>
B,
C;
395 C = MVT::CloneCopy(*
B,
ind);
399 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." <<
endl
400 <<
"Wrong number of vectors." <<
endl;
403 if ( MVT::GetGlobalLength(*
C) != MVT::GetGlobalLength(*
B) ) {
405 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." <<
endl
406 <<
"Vector lengths don't match." <<
endl;
412 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." <<
endl
413 <<
"Copied vectors do not agree:"
416 <<
" exceeds the tolerance 100*eps = " <<
tol <<
endl;
421 MVT::MvInit(*
B,
zero);
426 <<
"*** ERROR *** MultiVecTraits::CloneCopy(ind)." <<
endl
427 <<
"Copied vectors were not independent." <<
endl
429 <<
" exceeds the tolerance 100*eps = " <<
tol <<
endl;
442 Teuchos::RCP<MV>
B,
C;
448 C = MVT::CloneCopy(*
B);
450 if ( MVT::GetNumberVecs(*
C) !=
numvecs ) {
452 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." <<
endl
453 <<
"Wrong number of vectors." <<
endl;
459 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." <<
endl
460 <<
"Copied vectors do not agree." <<
endl
462 <<
" exceeds the tolerance 100*eps = " <<
tol <<
endl;
466 MVT::MvInit(*
B,
zero);
471 <<
"*** ERROR *** MultiVecTraits::CloneCopy()." <<
endl
472 <<
"Copied vectors were not independent." <<
endl
474 <<
" exceeds the tolerance 100*eps = " <<
tol <<
endl;
488 Teuchos::RCP<MV>
B,
C;
494 C = MVT::CloneViewNonConst(*
B,
ind);
498 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." <<
endl
499 <<
"Wrong number of vectors." <<
endl;
505 <<
"*** ERROR *** MultiVecTraits::CloneView(ind)." <<
endl
506 <<
"Viewed vectors do not agree." <<
endl;
521 Teuchos::RCP<const MV>
constB,
C;
531 C = MVT::CloneView(*
B,
ind);
535 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." <<
endl
536 <<
"Wrong number of vectors." <<
endl;
542 <<
"*** ERROR *** const MultiVecTraits::CloneView(ind)." <<
endl
543 <<
"Viewed vectors do not agree." <<
endl;
562 Teuchos::RCP<MV>
B,
C;
578 MVT::SetBlock(*
C,
ind,*
B);
586 <<
"*** ERROR *** MultiVecTraits::SetBlock()." <<
endl
587 <<
"Operation modified source vectors." <<
endl;
598 <<
"*** ERROR *** MultiVecTraits::SetBlock()." <<
endl
599 <<
"Copied vectors do not agree." <<
endl
601 <<
" exceeds the tolerance 100*eps = " <<
tol <<
endl;
609 <<
"*** ERROR *** MultiVecTraits::SetBlock()." <<
endl
610 <<
"Incorrect vectors were modified." <<
endl;
615 MVT::MvInit(*
C,
zero);
621 <<
"*** ERROR *** MultiVecTraits::SetBlock()." <<
endl
622 <<
"Copied vectors were not independent." <<
endl;
655 Teuchos::RCP<MV>
B,
C;
657 Teuchos::SerialDenseMatrix<int,ScalarType>
SDM(
p,
q);
659 B = MVT::Clone(*
A,
p);
660 C = MVT::Clone(*
A,
q);
672 if (
SDM.numRows() !=
p ||
SDM.numCols() !=
q ) {
674 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
675 <<
"Routine resized SerialDenseMatrix." <<
endl;
682 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
683 <<
"Scalar argument processed incorrectly." <<
endl;
692 for (
int i=0;
i<
p;
i++) {
693 for (
int j=0;
j<
q;
j++) {
694 if ( SCT::magnitude(
SDM(
i,
j))
697 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
698 <<
"Triangle inequality did not hold: "
699 << SCT::magnitude(
SDM(
i,
j))
710 for (
int i=0;
i<
p;
i++) {
711 for (
int j=0;
j<
q;
j++) {
714 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
715 <<
"Inner products not zero for C==0." <<
endl;
723 for (
int i=0;
i<
p;
i++) {
724 for (
int j=0;
j<
q;
j++) {
727 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
728 <<
"Inner products not zero for B==0." <<
endl;
741 Teuchos::SerialDenseMatrix<int, ScalarType>
largeSDM(
p+1,
q+1);
742 Teuchos::SerialDenseMatrix<int, ScalarType>
SDM2(Teuchos::View,
largeSDM,
p,
q);
747 for (
int i=0;
i<
p;
i++) {
748 for (
int j=0;
j<
q;
j++) {
751 <<
"*** ERROR *** MultiVecTraits::MvTransMv()." <<
endl
752 <<
"Inner products not zero for C==0 when using a view into Teuchos::SerialDenseMatrix<>." <<
endl;
769 Teuchos::RCP<MV>
B,
C;
770 std::vector<ScalarType>
iprods(
q);
773 B = MVT::Clone(*
A,
p);
774 C = MVT::Clone(*
A,
p);
781 if ( (
int)
iprods.size() !=
q ) {
783 <<
"*** ERROR *** MultiVecTraits::MvDot." <<
endl
784 <<
"Routine resized results vector." <<
endl;
787 for (
int i=0;
i<
p;
i++) {
791 <<
"*** ERROR *** MultiVecTraits::MvDot()." <<
endl
792 <<
"Inner products not valid." <<
endl;
799 for (
int i=0;
i<
p;
i++) {
802 <<
"*** ERROR *** MultiVecTraits::MvDot()." <<
endl
803 <<
"Inner products not zero for B==0." <<
endl;
810 for (
int i=0;
i<
p;
i++) {
813 <<
"*** ERROR *** MultiVecTraits::MvDot()." <<
endl
814 <<
"Inner products not zero for C==0." <<
endl;
830 Teuchos::RCP<MV>
B,
C,
D;
837 B = MVT::Clone(*
A,
p);
838 C = MVT::Clone(*
A,
p);
839 D = MVT::Clone(*
A,
p);
851 for (
int i=0;
i<
p;
i++) {
854 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
855 <<
"Input arguments were modified." <<
endl;
860 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
861 <<
"Input arguments were modified." <<
endl;
866 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
867 <<
"Assignment did not work." <<
endl;
877 for (
int i=0;
i<
p;
i++) {
880 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
881 <<
"Input arguments were modified." <<
endl;
886 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
887 <<
"Input arguments were modified." <<
endl;
892 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
893 <<
"Assignment did not work." <<
endl;
906 for (
int i=0;
i<
p;
i++) {
909 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
910 <<
"Input arguments were modified." <<
endl;
915 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
916 <<
"Input arguments were modified." <<
endl;
928 for (
int i=0;
i<
p;
i++) {
931 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
932 <<
"Input arguments were modified." <<
endl;
937 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
938 <<
"Input arguments were modified." <<
endl;
943 <<
"*** ERROR *** MultiVecTraits::MvAddMv()." <<
endl
944 <<
"Results varies depending on initial state of dest vectors." <<
endl;
970 Teuchos::RCP<MV>
B,
D;
971 Teuchos::RCP<const MV>
C;
972 std::vector<MagType>
normsB(
p),
977 B = MVT::Clone(*
A,
p);
987 for (
int i=0;
i<
p;
i++) {
990 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" <<
endl
991 <<
"Assignment did not work." <<
endl;
999 for (
int i=0;
i<
p;
i++) {
1002 <<
"*** ERROR *** MultiVecTraits::MvAddMv() #2" <<
endl
1003 <<
"Assignment did not work." <<
endl;
1021 const int p = 7,
q = 5;
1022 Teuchos::RCP<MV>
B,
C;
1023 Teuchos::RCP<MV>
Vp,
Vq;
1025 Teuchos::SerialDenseMatrix<int,ScalarType>
SDM(
p,
q);
1029 B = MVT::Clone(*
A,
p);
1030 C = MVT::Clone(*
A,
q);
1033 Vp = MVT::Clone(*
A,
p);
1034 Vq = MVT::Clone(*
A,
q);
1047 for (
int i=0;
i<
p;
i++) {
1050 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1051 <<
"Input vectors were modified." <<
endl;
1055 for (
int i=0;
i<
q;
i++) {
1058 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1059 <<
"Arithmetic test 1 failed." <<
endl;
1075 for (
int i=0;
i<
p;
i++) {
1078 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1079 <<
"Input vectors were modified." <<
endl;
1083 for (
int i=0;
i<
q;
i++) {
1086 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1087 <<
"Arithmetic test 2 failed: "
1103 for (
int i=0;
i<
q;
i++) {
1109 for (
int i=0;
i<
p;
i++) {
1112 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1113 <<
"Input vectors were modified." <<
endl;
1117 for (
int i=0;
i<
q;
i++) {
1120 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1121 <<
"Arithmetic test 3 failed: "
1139 for (
int i=0;
i<
p;
i++) {
1142 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1143 <<
"Input vectors were modified." <<
endl;
1147 for (
int i=0;
i<
q;
i++) {
1150 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1151 <<
"Arithmetic test 4 failed." <<
endl;
1167 const int p = 5,
q = 7;
1168 Teuchos::RCP<MV>
B,
C;
1169 Teuchos::RCP<MV>
Vp,
Vq;
1170 Teuchos::SerialDenseMatrix<int,ScalarType>
SDM(
p,
q);
1174 B = MVT::Clone(*
A,
p);
1175 C = MVT::Clone(*
A,
q);
1178 Vp = MVT::Clone(*
A,
p);
1179 Vq = MVT::Clone(*
A,
q);
1192 for (
int i=0;
i<
p;
i++) {
1195 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1196 <<
"Input vectors were modified." <<
endl;
1200 for (
int i=0;
i<
q;
i++) {
1203 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1204 <<
"Arithmetic test 5 failed." <<
endl;
1220 for (
int i=0;
i<
p;
i++) {
1223 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1224 <<
"Input vectors were modified." <<
endl;
1228 for (
int i=0;
i<
q;
i++) {
1231 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1232 <<
"Arithmetic test 6 failed: "
1247 for (
int i=0;
i<
p;
i++) {
1253 for (
int i=0;
i<
p;
i++) {
1256 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1257 <<
"Input vectors were modified." <<
endl;
1261 for (
int i=0;
i<
p;
i++) {
1264 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1265 <<
"Arithmetic test 7 failed." <<
endl;
1269 for (
int i=
p;
i<
q;
i++) {
1272 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1273 <<
"Arithmetic test 7 failed." <<
endl;
1287 for (
int i=0;
i<
p;
i++) {
1290 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1291 <<
"Input vectors were modified." <<
endl;
1295 for (
int i=0;
i<
q;
i++) {
1298 <<
"*** ERROR *** MultiVecTraits::MvTimesMatAddMv()." <<
endl
1299 <<
"Arithmetic test 8 failed." <<
endl;
1316 template<
class ScalarType,
class MV,
class OP>
1319 const Teuchos::RCP<const MV> &
A,
1320 const Teuchos::RCP<const OP> &
M) {
1332 typedef Teuchos::ScalarTraits<ScalarType> SCT;
1334 typedef typename SCT::magnitudeType
MagType;
1340 Teuchos::RCP<MV>
B = MVT::Clone(*
A,
numvecs),
1356 OPT::Apply(*
M,*
B,*
C);
1362 <<
"*** ERROR *** OperatorTraits::Apply() [1]" <<
endl
1363 <<
"Apply() modified the input vectors." <<
endl;
1368 <<
"*** ERROR *** OperatorTraits::Apply() [1]" <<
endl
1369 <<
"Operator applied to zero did not return zero." <<
endl;
1377 OPT::Apply(*
M,*
B,*
C);
1384 <<
"*** ERROR *** OperatorTraits::Apply() [2]" <<
endl
1385 <<
"Apply() modified the input vectors." <<
endl;
1390 <<
"*** ERROR *** OperatorTraits::Apply() [2]" <<
endl
1391 <<
"Operator applied to random vectors returned zero." <<
endl;
1400 OPT::Apply(*
M,*
B,*
C);
1406 <<
"*** ERROR *** OperatorTraits::Apply() [3]" <<
endl
1407 <<
"Apply() modified the input vectors." <<
endl;
1418 OPT::Apply(*
M,*
B,*
C);
1424 <<
"*** ERROR *** OperatorTraits::Apply() [4]" <<
endl
1425 <<
"Apply() modified the input vectors." <<
endl;
1431 <<
"*** WARNING *** OperatorTraits::Apply() [4]" <<
endl
1432 <<
"Apply() returned two different results." <<
endl <<
endl;
Anasazi header file which uses auto-configuration information to include necessary C++ headers.
Declaration of basic traits for the multivector type.
Virtual base class which defines basic traits for the operator type.
Abstract class definition for Anasazi Output Managers.
Types and exceptions used within Anasazi solvers and interfaces.
Anasazi's templated virtual class for constructing an operator that can interface with the OperatorTr...
Namespace Anasazi contains the classes, structs, enums and utilities used by the Anasazi package.
bool TestOperatorTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A, const Teuchos::RCP< const OP > &M)
This function tests the correctness of an operator implementation with respect to an OperatorTraits s...
bool TestMultiVecTraits(const Teuchos::RCP< OutputManager< ScalarType > > &om, const Teuchos::RCP< const MV > &A)
This is a function to test the correctness of a MultiVecTraits specialization and multivector impleme...