Thyra_TesterBase.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
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

Generated on Tue Oct 20 12:47:27 2009 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.4.7