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::RCP;
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 RCP<const Comm<int> >& comm,
00056 const VectorSpace<Scalar>& space, int nCols,
00057 Teuchos::RCP<Teuchos::FancyOStream>& out)
00058 : comm_(comm), space_(space), nCols_(nCols), out_(out)
00059 {
00060 using std::endl;
00061 *out << "==========================================================================="
00062 << endl;
00063 *out << " testing on type "
00064 << Teuchos::ScalarTraits<Scalar>::name() << endl;
00065 *out << "==========================================================================="
00066 << endl;
00067 }
00068
00070 virtual ~TesterBase(){;}
00071
00073 virtual bool runAllTests() const = 0 ;
00074
00075
00077 bool checkTest(const TestSpecifier<Scalar>& spec,
00078 const ScalarMag& err,
00079 const string& testName) const ;
00080
00082 void randomizeVec(Vector<Scalar>& x) const ;
00083
00085 LinearOperator<Scalar> randomDenseOp() const ;
00086
00088 const VectorSpace<Scalar>& space() const {return space_;}
00089
00091 ostream& out() const {return *out_;}
00092
00094 const Comm<int>& comm() const {return *comm_;}
00095
00096 private:
00097 RCP<const Comm<int> > comm_;
00098 VectorSpace<Scalar> space_;
00099 int nCols_;
00100 mutable Teuchos::RCP<Teuchos::FancyOStream> out_;
00101 };
00102
00103 template <class Scalar>
00104 inline void TesterBase<Scalar>
00105 ::randomizeVec(Vector<Scalar>& x) const
00106 {
00107 typedef ScalarTraits<Scalar> ST;
00108 randomize(Scalar(-ST::one()),Scalar(+ST::one()),x.ptr().get());
00109
00110 }
00111
00112 template <class Scalar>
00113 inline bool TesterBase<Scalar>
00114 ::checkTest(const TestSpecifier<Scalar>& spec,
00115 const ScalarMag& err,
00116 const string& testName) const
00117 {
00118
00119 using std::endl;
00120
00121 bool rtn = true;
00122 if (err > spec.errorTol())
00123 {
00124 *out_ << testName << " test FAILED: err=" << err << ", tol = "
00125 << spec.errorTol() << endl;
00126 rtn = false;
00127 }
00128 else if (err > spec.warningTol())
00129 {
00130 *out_ << "WARNING: " << testName << " test err="
00131 << err << " could not beat tol = "
00132 << spec.warningTol() << endl;
00133 }
00134 else
00135 {
00136 *out_ << "test " << testName << " PASSED with tol=" << spec.errorTol() << endl;
00137 }
00138 return rtn;
00139 }
00140
00141 template <class Scalar>
00142 inline LinearOperator<Scalar> TesterBase<Scalar>
00143 ::randomDenseOp() const
00144 {
00145 typedef ScalarTraits<Scalar> ST;
00146 RCP<MultiVectorBase<Scalar> > mv = space_.createMembers(nCols_);
00147 randomize(-ST::one(), ST::one(), &*mv);
00148 RCP<LinearOpBase<Scalar> > rtn = mv;
00149 return rtn;
00150 }
00151
00152
00153
00154 }
00155 #endif