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::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

Generated on Thu Sep 18 12:33:03 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1