Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_VectorSpaceTester_def.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 #ifndef THYRA_VECTOR_SPACE_TESTER_HPP
00030 #define THYRA_VECTOR_SPACE_TESTER_HPP
00031 
00032 #include "Thyra_VectorSpaceTester_decl.hpp"
00033 #include "Thyra_TestingTools.hpp"
00034 #include "Thyra_VectorStdOps.hpp"
00035 #include "Thyra_MultiVectorStdOps.hpp"
00036 
00037 
00038 namespace Thyra {
00039 
00040 
00041 template <class Scalar>
00042 VectorSpaceTester<Scalar>::VectorSpaceTester(
00043   const ScalarMag     warning_tol_in
00044   ,const ScalarMag    error_tol_in
00045   ,const int          num_random_vectors_in
00046   ,const int          num_mv_cols_in
00047   ,const bool         show_all_tests_in
00048   ,const bool         dump_all_in
00049   )
00050   :num_mv_cols_(num_mv_cols_in) // declared first!
00051   ,warning_tol_(warning_tol_in)
00052   ,error_tol_(error_tol_in)
00053   ,num_random_vectors_(num_random_vectors_in)
00054   ,show_all_tests_(show_all_tests_in)
00055   ,dump_all_(dump_all_in)
00056 {}
00057 
00058 
00059 template <class Scalar>
00060 bool VectorSpaceTester<Scalar>::check(
00061   const VectorSpaceBase<Scalar>  &vs
00062   ,Teuchos::FancyOStream         *out_arg
00063   ) const
00064 {
00065   using std::endl;
00066   using Teuchos::describe;
00067   using Teuchos::FancyOStream;
00068   using Teuchos::OSTab;
00069   typedef Teuchos::ScalarTraits<Scalar> ST;
00070   //typedef typename ST::magnitudeType    ScalarMag;
00071 
00072   Teuchos::RCP<FancyOStream> out = Teuchos::rcp(out_arg,false);
00073   const Teuchos::EVerbosityLevel verbLevel = (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
00074 
00075   OSTab tab(out,1,"THYRA");
00076 
00077   bool result, success = true;
00078 
00079   if(out.get()) *out <<endl<< "*** Entering Thyra::VectorSpaceTester<"<<ST::name()<<">::check(vs,...) ...\n";
00080 
00081   if(out.get()) *out <<endl<< "Testing a vector space vs described as:\n" << describe(vs,verbLevel);
00082 
00083   if(out.get())
00084     *out
00085       <<endl<< "A) Calling basic query functions ...\n"
00086       <<endl<< "vs.dim() = " << vs.dim()
00087       <<endl<< "vs.hasInCoreView() = " << vs.hasInCoreView() << std::endl;
00088 
00089   if(out.get()) *out <<endl<< "B) Checking that vs is compatible with itself ...\n";
00090 
00091   if(out.get()) *out <<endl<< "vs.isCompatible(vs)=";
00092   result = vs.isCompatible(vs);
00093   if(!result) success = false;
00094   if(out.get()) *out << result << " == true : " << passfail(result) << std::endl;
00095 
00096   if(out.get()) *out <<endl<< "C) Creating a randomized vector member v ...\n";
00097   Teuchos::RCP<Thyra::VectorBase<Scalar> >
00098     v = createMember(vs);
00099   randomize(Scalar(-ST::one()),Scalar(+ST::one()),v.ptr());
00100 
00101   if(out.get()) *out <<endl<< "D) Testing the VectorBase interface of v ...\n";
00102 
00103   result = vectorTester_.check(*v,out.get());
00104   if(!result) success = false;
00105 
00106   if(out.get()) *out <<endl<< "C) Creating a randomized MultiVector member mv ...\n";
00107   Teuchos::RCP<Thyra::MultiVectorBase<Scalar> >
00108     mv = createMembers(vs,num_mv_cols());
00109   randomize(Scalar(-ST::one()),Scalar(+ST::one()),mv.ptr());
00110 
00111   if(out.get()) *out <<endl<< "D) Testing the MultiVectorBase interface of mv ...\n";
00112 
00113   result = vectorTester_.multiVectorTester().check(*mv, out.ptr());
00114   if(!result) success = false;
00115 
00116   if(out.get()) {
00117     if(success)
00118       *out << endl <<"Congratulations, this VectorSpaceBase object seems to check out!\n";
00119     else
00120       *out << endl <<"Oh no, at least one of the tests performed with this VectorSpaceBase object failed (see above failures)!\n";
00121     *out << endl << "*** Leaving VectorSpaceTester<"<<ST::name()<<">::check(vs,...)\n";
00122   }
00123   
00124   return success;
00125 
00126 }
00127 
00128 
00129 } // namespace Thyra
00130 
00131 
00132 #endif // THYRA_VECTOR_SPACE_TESTER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines