Thyra Version of the Day
Thyra_VectorTester_def.hpp
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef THYRA_VECTOR_TESTER_HPP
00043 #define THYRA_VECTOR_TESTER_HPP
00044 
00045 #include "Thyra_VectorTester_decl.hpp"
00046 #include "Thyra_VectorStdOps.hpp"
00047 #include "Thyra_VectorBase.hpp"
00048 #include "Thyra_VectorSpaceBase.hpp"
00049 #include "Thyra_TestingTools.hpp"
00050 #include "Teuchos_VerbosityLevel.hpp"
00051 
00052 
00053 namespace Thyra {
00054 
00055 
00056 template<class Scalar>
00057 VectorTester<Scalar>::VectorTester(
00058   const ScalarMag     warning_tol_in
00059   ,const ScalarMag    error_tol_in
00060   ,const int          num_random_vectors_in
00061   ,const bool         show_all_tests_in
00062   ,const bool         dump_all_in
00063   )
00064   :warning_tol_(warning_tol_in)
00065   ,error_tol_(error_tol_in)
00066   ,num_random_vectors_(num_random_vectors_in)
00067   ,show_all_tests_(show_all_tests_in)
00068   ,dump_all_(dump_all_in)
00069 {}
00070 
00071 
00072 template<class Scalar>
00073 bool VectorTester<Scalar>::check(
00074   const VectorBase<Scalar>       &v
00075   ,Teuchos::FancyOStream         *out_arg
00076   ) const
00077 {
00078 
00079   using std::endl;
00080   using Teuchos::describe;
00081   using Teuchos::FancyOStream;
00082   using Teuchos::OSTab;
00083   typedef Teuchos::ScalarTraits<Scalar> ST;
00084   //typedef typename ST::magnitudeType    ScalarMag;
00085 
00086   Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
00087   const Teuchos::EVerbosityLevel verbLevel = (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
00088 
00089   OSTab tab(out,1,"THYRA");
00090 
00091   bool result, success = true;
00092 
00093   if(out.get()) *out <<endl<< "*** Entering Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
00094 
00095   if(out.get()) *out <<endl<< "Testing a VectorBase object described as:\n" << describe(v,verbLevel);
00096 
00097   if(out.get()) *out <<endl<< "A) Creating temporary vector t1, t2, t3, and t4 from v.space() ...\n";
00098   Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
00099     vs = v.space();
00100   Teuchos::RCP<Thyra::VectorBase<Scalar> >
00101     t1 = createMember(vs), t2 = createMember(vs), t3 = createMember(vs), t4 = createMember(vs);
00102 
00103   if(out.get()) *out <<endl<< "B) Testing VectorBase::applyOp(...) by calling a few standard RTOp operations ... ";
00104 
00105   const Scalar
00106     one   = ST::one(),
00107     two   = Scalar(2)*one,
00108     three = Scalar(3)*one;
00109 
00110   {
00111     using Teuchos::inOutArg;
00112 
00113     std::ostringstream oss;
00114     bool these_results = true;
00115     
00116     oss <<endl<< "assign(t1.ptr(),2.0) ...\n";
00117     Thyra::assign( t1.ptr(), two );
00118     if(dump_all()) oss <<endl<< "\nt1 =\n" << describe(*t1,verbLevel);
00119     
00120     result = Teuchos::testRelErr<Scalar>(
00121       "sum(t1)", sum(*t1), "2*vs->dim()", two*Scalar(vs->dim()),
00122       "error_tol()", error_tol(), "warning_tol()", warning_tol(),
00123       inOutArg(oss)
00124       );
00125     if(!result) these_results = false;
00126     
00127     oss <<endl<< "assign(t2.ptr(),3.0) ...\n";
00128     Thyra::assign( t2.ptr(), three );
00129     if(dump_all()) oss <<endl<< "t2 =\n" << *t1;
00130     
00131     result = Teuchos::testRelErr<Scalar>(
00132       "sum(t2)",sum(*t2),"3*vs->dim()",three*Scalar(vs->dim()),
00133       "error_tol()",error_tol(),"warning_tol()",warning_tol(),
00134       inOutArg(oss)
00135       );
00136     if(!result) these_results = false;
00137     
00138     result = Teuchos::testRelErr<Scalar>(
00139       "vs->scalarProd(*t1,*t2)",vs->scalarProd(*t1,*t2),"2*3*vs->dim()",two*three*Scalar(vs->dim()),
00140       "error_tol()",error_tol(),"warning_tol()",warning_tol(),
00141       inOutArg(oss)
00142       );
00143     if(!result) these_results = false;
00144 
00145     printTestResults(these_results,oss.str(),show_all_tests(),&success,out.get());
00146 
00147   }
00148     
00149   // ToDo: Test the rest of the specific VectorBase interface on v1
00150 
00151   if(out.get()) *out <<endl<< "C) Checking the MultiVectorBase interface of v ...\n";
00152   result = multiVectorTester_.check(v, out.ptr());
00153   if(!result) success = false;
00154 
00155   if(out.get()) *out <<endl<< "*** Leaving Thyra::VectorTester<"<<ST::name()<<">::check(v,...) ...\n";
00156   
00157   return success;
00158 
00159 }
00160 
00161 
00162 } // namespace Thyra
00163 
00164 
00165 #endif // THYRA_VECTOR_TESTER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines