Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef TSF_COMPOUNDTESTER_HPP
00031 #define TSF_COMPOUNDTESTER_HPP
00032
00033 #include "TSFLinearOperatorDecl.hpp"
00034 #include "TSFSimpleComposedOpDecl.hpp"
00035 #include "TSFSimpleScaledOpDecl.hpp"
00036 #include "TSFSimpleAddedOpDecl.hpp"
00037 #include "TSFSimpleDiagonalOpDecl.hpp"
00038 #include "TSFTesterBase.hpp"
00039 #include "Teuchos_ScalarTraits.hpp"
00040 #include "TSFLinearCombinationImpl.hpp"
00041
00042 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00043 #include "TSFSimpleComposedOpImpl.hpp"
00044 #include "TSFSimpleScaledOpImpl.hpp"
00045 #include "TSFSimpleAddedOpImpl.hpp"
00046 #include "TSFSimpleDiagonalOpImpl.hpp"
00047 #include "TSFRandomSparseMatrixBuilderImpl.hpp"
00048 #endif
00049
00050 using namespace TSFExtended;
00051 using namespace Teuchos;
00052
00053 using Thyra::TestSpecifier;
00054
00055 namespace TSFExtended
00056 {
00057
00058
00059 template <class Scalar>
00060 class CompoundTester : public TesterBase<Scalar>
00061 {
00062 public:
00063
00064 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00065
00066
00067 CompoundTester(const LinearOperator<Scalar>& A,
00068 const LinearOperator<Scalar>& B,
00069 const TestSpecifier<Scalar>& sumSpec,
00070 const TestSpecifier<Scalar>& composedSpec,
00071 const TestSpecifier<Scalar>& scaledSpec,
00072 const TestSpecifier<Scalar>& diagSpec);
00073
00074
00075 bool runAllTests() const ;
00076
00077
00078 bool sumTest() const ;
00079
00080
00081 bool composedTest() const ;
00082
00083
00084 bool scaledTest() const ;
00085
00086
00087 bool diagTest() const ;
00088
00089
00090 private:
00091
00092 LinearOperator<Scalar> A_;
00093
00094 LinearOperator<Scalar> B_;
00095
00096 TestSpecifier<Scalar> sumSpec_;
00097
00098 TestSpecifier<Scalar> composedSpec_;
00099
00100 TestSpecifier<Scalar> scaledSpec_;
00101
00102 TestSpecifier<Scalar> diagSpec_;
00103
00104 };
00105
00106 template <class Scalar>
00107 inline CompoundTester<Scalar>
00108 ::CompoundTester(const LinearOperator<Scalar>& A,
00109 const LinearOperator<Scalar>& B,
00110 const TestSpecifier<Scalar>& sumSpec,
00111 const TestSpecifier<Scalar>& composedSpec,
00112 const TestSpecifier<Scalar>& scaledSpec,
00113 const TestSpecifier<Scalar>& diagSpec)
00114 : TesterBase<Scalar>(),
00115 A_(A),
00116 B_(B),
00117 sumSpec_(sumSpec),
00118 composedSpec_(composedSpec),
00119 scaledSpec_(scaledSpec),
00120 diagSpec_(diagSpec)
00121 {;}
00122
00123 template <class Scalar>
00124 inline bool CompoundTester<Scalar>
00125 ::runAllTests() const
00126 {
00127 bool pass = true;
00128
00129 pass = sumTest() && pass;
00130 pass = composedTest() && pass;
00131 pass = scaledTest() && pass;
00132 pass = diagTest() && pass;
00133
00134 return pass;
00135 }
00136
00137 template <class Scalar>
00138 inline bool CompoundTester<Scalar>
00139 ::sumTest() const
00140 {
00141 if (sumSpec_.doTest())
00142 {
00143 Out::root() << "running operator addition test..." << std::endl;
00144 LinearOperator<Scalar> sum = A_ + B_;
00145
00146 Vector<Scalar> x = A_.domain().createMember();
00147 randomizeVec(x);
00148 Out::root() << "computing y1 = (A+B)*x..." << std::endl;
00149 Vector<Scalar> y1 = sum*x;
00150 Out::root() << "computing y2 = A*x + B*x..." << std::endl;
00151 Vector<Scalar> y2 = A_*x + B_*x;
00152
00153 ScalarMag err = (y1 - y2).norm2();
00154
00155 Out::root() << "|y1-y2| = " << err << std::endl;
00156
00157 return checkTest(sumSpec_, err, "operator addition");
00158 }
00159 Out::root() << "skipping operator addition test..." << std::endl;
00160 return true;
00161 }
00162
00163
00164 template <class Scalar>
00165 inline bool CompoundTester<Scalar>
00166 ::composedTest() const
00167 {
00168 if (composedSpec_.doTest())
00169 {
00170 Out::root() << "running operator composition test..." << std::endl;
00171 LinearOperator<Scalar> composed = A_ * B_;
00172
00173 Vector<Scalar> x = B_.domain().createMember();
00174 randomizeVec(x);
00175 Out::root() << "computing y1 = (A*B)*x..." << std::endl;
00176 Vector<Scalar> y1 = composed*x;
00177 Out::root() << "computing y2 = B*x..." << std::endl;
00178 Vector<Scalar> y2 = B_*x;
00179 Out::root() << "computing y3 = A*y2..." << std::endl;
00180 Vector<Scalar> y3 = A_*y2;
00181
00182 ScalarMag err = (y1 - y3).norm2();
00183
00184 Out::root() << "|y1-y3| = " << err << std::endl;
00185 return checkTest(composedSpec_, err, "operator composition");
00186 }
00187 Out::root() << "skipping operator composition test..." << std::endl;
00188 return true;
00189 }
00190
00191
00192 template <class Scalar>
00193 inline bool CompoundTester<Scalar>
00194 ::scaledTest() const
00195 {
00196 if (scaledSpec_.doTest())
00197 {
00198 Out::root() << "running operator scaling test..." << std::endl;
00199 Scalar alpha = sqrt(2.0);
00200 LinearOperator<Scalar> scaled = alpha*A_;
00201
00202 Vector<Scalar> x = A_.domain().createMember();
00203 randomizeVec(x);
00204 Out::root() << "computing y1 = (alpha*A)*x..." << std::endl;
00205 Vector<Scalar> y1 = scaled*x;
00206 Out::root() << "computing y2 = A*x..." << std::endl;
00207 Vector<Scalar> y2 = A_*x;
00208 Out::root() << "computing y3 = alpha*y2..." << std::endl;
00209 Vector<Scalar> y3 = alpha*y2;
00210
00211 ScalarMag err = (y1 - y3).norm2();
00212
00213 Out::root() << "|y1-y3| = " << err << std::endl;
00214 return checkTest(composedSpec_, err, "operator scaling");
00215 }
00216 Out::root() << "skipping operator scaling test..." << std::endl;
00217 return true;
00218 }
00219
00220
00221
00222 template <class Scalar>
00223 inline bool CompoundTester<Scalar>
00224 ::diagTest() const
00225 {
00226 if (diagSpec_.doTest())
00227 {
00228 Out::root() << "running diagonal operator test..." << std::endl;
00229
00230 Vector<Scalar> x = A_.domain().createMember();
00231 randomizeVec(x);
00232
00233 Vector<Scalar> d = A_.domain().createMember();
00234 randomizeVec(d);
00235
00236 LinearOperator<Scalar> D = diagonalOperator(d);
00237
00238 Out::root() << "computing y1 = D*x..." << std::endl;
00239 Vector<Scalar> y1 = D*x;
00240 Out::root() << "computing y2 = d .* x..." << std::endl;
00241 Vector<Scalar> y2 = x.dotStar(d);
00242
00243 ScalarMag err = (y1 - y2).norm2();
00244
00245 Out::root() << "|y1-y2| = " << err << std::endl;
00246 return checkTest(diagSpec_, err, "diagonal operator");
00247 }
00248 Out::root() << "skipping diagonal operator test..." << std::endl;
00249 return true;
00250 }
00251
00252
00253
00254 }
00255 #endif