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

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