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 THYRA_TESTERBASE_HPP
00031 #define THYRA_TESTERBASE_HPP
00032
00033 #include "Thyra_LinearOperatorImpl.hpp"
00034 #include "Thyra_TestSpecifier.hpp"
00035 #include "Thyra_SUNDIALS_Ops.hpp"
00036 #include "Teuchos_ScalarTraits.hpp"
00037 #include "Teuchos_Comm.hpp"
00038 #include "Teuchos_CommHelpers.hpp"
00039
00040
00041 namespace Thyra
00042 {
00043 using Teuchos::RefCountPtr;
00044 using Teuchos::ScalarTraits;
00045
00047 template <class Scalar>
00048 class TesterBase
00049 {
00050 public:
00052 typedef typename ScalarTraits<Scalar>::magnitudeType ScalarMag;
00053
00055 TesterBase(const RefCountPtr<const Comm<int> >& comm,
00056 const VectorSpace<Scalar>& space, int nCols,
00057 Teuchos::RefCountPtr<Teuchos::FancyOStream>& out)
00058 : comm_(comm), space_(space), nCols_(nCols), out_(out)
00059 {
00060 *out << "==========================================================================="
00061 << endl;
00062 *out << " testing on type "
00063 << Teuchos::ScalarTraits<Scalar>::name() << endl;
00064 *out << "==========================================================================="
00065 << endl;
00066 }
00067
00069 virtual ~TesterBase(){;}
00070
00072 virtual bool runAllTests() const = 0 ;
00073
00074
00076 bool checkTest(const TestSpecifier<Scalar>& spec,
00077 const ScalarMag& err,
00078 const string& testName) const ;
00079
00081 void randomizeVec(Vector<Scalar>& x) const ;
00082
00084 LinearOperator<Scalar> randomDenseOp() const ;
00085
00087 const VectorSpace<Scalar>& space() const {return space_;}
00088
00090 ostream& out() const {return *out_;}
00091
00093 const Comm<int>& comm() const {return *comm_;}
00094
00095 private:
00096 RefCountPtr<const Comm<int> > comm_;
00097 VectorSpace<Scalar> space_;
00098 int nCols_;
00099 mutable Teuchos::RefCountPtr<Teuchos::FancyOStream> out_;
00100 };
00101
00102 template <class Scalar>
00103 inline void TesterBase<Scalar>
00104 ::randomizeVec(Vector<Scalar>& x) const
00105 {
00106 typedef ScalarTraits<Scalar> ST;
00107 randomize(Scalar(-ST::one()),Scalar(+ST::one()),x.ptr().get());
00108
00109 }
00110
00111 template <class Scalar>
00112 inline bool TesterBase<Scalar>
00113 ::checkTest(const TestSpecifier<Scalar>& spec,
00114 const ScalarMag& err,
00115 const string& testName) const
00116 {
00117 bool rtn = true;
00118 if (err > spec.errorTol())
00119 {
00120 *out_ << testName << " test FAILED: err=" << err << ", tol = "
00121 << spec.errorTol() << endl;
00122 rtn = false;
00123 }
00124 else if (err > spec.warningTol())
00125 {
00126 *out_ << "WARNING: " << testName << " test err="
00127 << err << " could not beat tol = "
00128 << spec.warningTol() << endl;
00129 }
00130 else
00131 {
00132 *out_ << "test " << testName << " PASSED with tol=" << spec.errorTol() << endl;
00133 }
00134 return rtn;
00135 }
00136
00137 template <class Scalar>
00138 inline LinearOperator<Scalar> TesterBase<Scalar>
00139 ::randomDenseOp() const
00140 {
00141 typedef ScalarTraits<Scalar> ST;
00142 RefCountPtr<MultiVectorBase<Scalar> > mv = space_.createMembers(nCols_);
00143 randomize(-ST::one(), ST::one(), &*mv);
00144 RefCountPtr<LinearOpBase<Scalar> > rtn = mv;
00145 return rtn;
00146 }
00147
00148
00149
00150 }
00151 #endif