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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef PLAYA_COMPOUNDTESTER_HPP
00044 #define PLAYA_COMPOUNDTESTER_HPP
00045
00046 #include "PlayaLinearOperatorDecl.hpp"
00047 #include "PlayaSimpleComposedOpDecl.hpp"
00048 #include "PlayaSimpleScaledOpDecl.hpp"
00049 #include "PlayaSimpleAddedOpDecl.hpp"
00050 #include "PlayaSimpleDiagonalOpDecl.hpp"
00051 #include "PlayaTesterBase.hpp"
00052 #include "Teuchos_ScalarTraits.hpp"
00053 #include "PlayaLinearCombinationImpl.hpp"
00054
00055 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00056 #include "PlayaSimpleComposedOpImpl.hpp"
00057 #include "PlayaSimpleTransposedOpImpl.hpp"
00058 #include "PlayaSimpleScaledOpImpl.hpp"
00059 #include "PlayaSimpleAddedOpImpl.hpp"
00060 #include "PlayaSimpleDiagonalOpImpl.hpp"
00061 #include "PlayaRandomSparseMatrixBuilderImpl.hpp"
00062 #endif
00063
00064 using namespace Playa;
00065 using namespace Teuchos;
00066
00067
00068
00069 namespace Playa
00070 {
00071
00072
00073 template <class Scalar>
00074 class CompoundTester : public TesterBase<Scalar>
00075 {
00076 public:
00077
00078 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType ScalarMag;
00079
00080
00081 CompoundTester(const LinearOperator<Scalar>& A,
00082 const LinearOperator<Scalar>& B,
00083 const TestSpecifier<Scalar>& sumSpec,
00084 const TestSpecifier<Scalar>& composedSpec,
00085 const TestSpecifier<Scalar>& scaledSpec,
00086 const TestSpecifier<Scalar>& diagSpec);
00087
00088
00089 bool runAllTests() const ;
00090
00091
00092 bool sumTest() const ;
00093
00094
00095 bool composedTest() const ;
00096
00097
00098 bool scaledTest() const ;
00099
00100
00101 bool diagTest() const ;
00102
00103
00104 private:
00105
00106 LinearOperator<Scalar> A_;
00107
00108 LinearOperator<Scalar> B_;
00109
00110 TestSpecifier<Scalar> sumSpec_;
00111
00112 TestSpecifier<Scalar> composedSpec_;
00113
00114 TestSpecifier<Scalar> scaledSpec_;
00115
00116 TestSpecifier<Scalar> diagSpec_;
00117
00118 };
00119
00120 template <class Scalar>
00121 inline CompoundTester<Scalar>
00122 ::CompoundTester(const LinearOperator<Scalar>& A,
00123 const LinearOperator<Scalar>& B,
00124 const TestSpecifier<Scalar>& sumSpec,
00125 const TestSpecifier<Scalar>& composedSpec,
00126 const TestSpecifier<Scalar>& scaledSpec,
00127 const TestSpecifier<Scalar>& diagSpec)
00128 : TesterBase<Scalar>(),
00129 A_(A),
00130 B_(B),
00131 sumSpec_(sumSpec),
00132 composedSpec_(composedSpec),
00133 scaledSpec_(scaledSpec),
00134 diagSpec_(diagSpec)
00135 {;}
00136
00137 template <class Scalar>
00138 inline bool CompoundTester<Scalar>
00139 ::runAllTests() const
00140 {
00141 bool pass = true;
00142
00143 pass = sumTest() && pass;
00144 pass = composedTest() && pass;
00145 pass = scaledTest() && pass;
00146 pass = diagTest() && pass;
00147
00148 return pass;
00149 }
00150
00151 template <class Scalar>
00152 inline bool CompoundTester<Scalar>
00153 ::sumTest() const
00154 {
00155 if (sumSpec_.doTest())
00156 {
00157 Out::root() << "running operator addition test..." << std::endl;
00158 LinearOperator<Scalar> sum = A_ + B_;
00159
00160 Vector<Scalar> x = A_.domain().createMember();
00161 this->randomizeVec(x);
00162 Out::root() << "computing y1 = (A+B)*x..." << std::endl;
00163 Vector<Scalar> y1 = sum*x;
00164 Out::root() << "computing y2 = A*x + B*x..." << std::endl;
00165 Vector<Scalar> y2 = A_*x + B_*x;
00166
00167 ScalarMag err = (y1 - y2).norm2();
00168
00169 Out::root() << "|y1-y2| = " << err << std::endl;
00170
00171 return this->checkTest(sumSpec_, err, "operator addition");
00172 }
00173 Out::root() << "skipping operator addition test..." << std::endl;
00174 return true;
00175 }
00176
00177
00178 template <class Scalar>
00179 inline bool CompoundTester<Scalar>
00180 ::composedTest() const
00181 {
00182 if (composedSpec_.doTest())
00183 {
00184 Out::root() << "running operator composition test..." << std::endl;
00185 LinearOperator<Scalar> composed = A_ * B_;
00186
00187 Vector<Scalar> x = B_.domain().createMember();
00188 this->randomizeVec(x);
00189 Out::root() << "computing y1 = (A*B)*x..." << std::endl;
00190 Vector<Scalar> y1 = composed*x;
00191 Out::root() << "computing y2 = B*x..." << std::endl;
00192 Vector<Scalar> y2 = B_*x;
00193 Out::root() << "computing y3 = A*y2..." << std::endl;
00194 Vector<Scalar> y3 = A_*y2;
00195
00196 ScalarMag err = (y1 - y3).norm2();
00197
00198 Out::root() << "|y1-y3| = " << err << std::endl;
00199 return this->checkTest(composedSpec_, err, "operator composition");
00200 }
00201 Out::root() << "skipping operator composition test..." << std::endl;
00202 return true;
00203 }
00204
00205
00206 template <class Scalar>
00207 inline bool CompoundTester<Scalar>
00208 ::scaledTest() const
00209 {
00210 if (scaledSpec_.doTest())
00211 {
00212 Out::root() << "running operator scaling test..." << std::endl;
00213 Scalar alpha = sqrt(2.0);
00214 LinearOperator<Scalar> scaled = alpha*A_;
00215
00216 Vector<Scalar> x = A_.domain().createMember();
00217 this->randomizeVec(x);
00218 Out::root() << "computing y1 = (alpha*A)*x..." << std::endl;
00219 Vector<Scalar> y1 = scaled*x;
00220 Out::root() << "computing y2 = A*x..." << std::endl;
00221 Vector<Scalar> y2 = A_*x;
00222 Out::root() << "computing y3 = alpha*y2..." << std::endl;
00223 Vector<Scalar> y3 = alpha*y2;
00224
00225 ScalarMag err = (y1 - y3).norm2();
00226
00227 Out::root() << "|y1-y3| = " << err << std::endl;
00228 return this->checkTest(composedSpec_, err, "operator scaling");
00229 }
00230 Out::root() << "skipping operator scaling test..." << std::endl;
00231 return true;
00232 }
00233
00234
00235
00236 template <class Scalar>
00237 inline bool CompoundTester<Scalar>
00238 ::diagTest() const
00239 {
00240 if (diagSpec_.doTest())
00241 {
00242 Out::root() << "running diagonal operator test..." << std::endl;
00243
00244 Vector<Scalar> x = A_.domain().createMember();
00245 this->randomizeVec(x);
00246
00247 Vector<Scalar> d = A_.domain().createMember();
00248 this->randomizeVec(d);
00249
00250 LinearOperator<Scalar> D = diagonalOperator(d);
00251
00252 Out::root() << "computing y1 = D*x..." << std::endl;
00253 Vector<Scalar> y1 = D*x;
00254 Out::root() << "computing y2 = d .* x..." << std::endl;
00255 Vector<Scalar> y2 = x.dotStar(d);
00256
00257 ScalarMag err = (y1 - y2).norm2();
00258
00259 Out::root() << "|y1-y2| = " << err << std::endl;
00260 return this->checkTest(diagSpec_, err, "diagonal operator");
00261 }
00262 Out::root() << "skipping diagonal operator test..." << std::endl;
00263 return true;
00264 }
00265
00266
00267
00268 }
00269 #endif