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

Generated on Wed May 12 21:26:54 2010 for Thyra Operator/Vector Support by  doxygen 1.4.7