Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_MultiVectorTester_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_MULTI_VECTOR_TESTER_DEF_HPP
00030 #define THYRA_MULTI_VECTOR_TESTER_DEF_HPP
00031 
00032 #include "Thyra_MultiVectorTester_decl.hpp"
00033 #include "Thyra_MultiVectorBase.hpp"
00034 #include "Thyra_MultiVectorStdOps.hpp"
00035 #include "Thyra_VectorSpaceBase.hpp"
00036 #include "Thyra_VectorStdOps.hpp"
00037 #include "Teuchos_TestingHelpers.hpp"
00038 
00039 
00040 namespace Thyra {
00041 
00042 
00043 template<class Scalar>
00044 MultiVectorTester<Scalar>::MultiVectorTester(
00045   const ScalarMag warning_tol_in,
00046   const ScalarMag error_tol_in,
00047   const int num_random_vectors_in,
00048   const bool show_all_tests_in,
00049   const bool dump_all_in
00050   )
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 MultiVectorTester<Scalar>::checkMultiVector(
00061   const VectorSpaceBase<Scalar> &vs,
00062   const Ptr<Teuchos::FancyOStream> &out_inout
00063   ) const
00064 {
00065 
00066   using Teuchos::as;
00067   using Teuchos::describe;
00068   using Teuchos::FancyOStream;
00069   using Teuchos::OSTab;
00070   using Teuchos::tuple;
00071   using Teuchos::null;
00072   typedef Teuchos::ScalarTraits<Scalar> ST;
00073   //typedef typename ST::magnitudeType ScalarMag;
00074 
00075   RCP<FancyOStream> out;
00076   if (!is_null(out_inout))
00077     out = Teuchos::rcpFromPtr(out_inout);
00078   else
00079     out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
00080 
00081   const Teuchos::EVerbosityLevel verbLevel =
00082     (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
00083 
00084   OSTab tab(out,1,"THYRA");
00085 
00086   bool success = true;
00087   
00088   *out << "\n*** Entering "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
00089 
00090   *out << "\nTesting MultiVectorBase objects created from vs = " << describe(vs, verbLevel);
00091 
00092   const Ordinal dim = vs.dim();
00093   const Scalar scalarDim = as<Scalar>(dim);
00094 
00095   int tc = 0;
00096 
00097   *out << "\n"<<tc<<") Checking non-contiguous non-const multi-vector views ...\n";
00098   ++tc;
00099   {
00100     OSTab tab2(out);
00101     const int numCols = 6;
00102     const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
00103     assign<Scalar>(mv.ptr(), ST::zero());
00104     const Scalar
00105       one = as<Scalar>(1.0),
00106       three = as<Scalar>(3.0),
00107       five = as<Scalar>(5.0);
00108     {
00109       const RCP<MultiVectorBase<Scalar> > mvView = mv->subView(tuple<int>(1, 3, 5)());
00110       assign<Scalar>(mvView->col(0).ptr(), one);
00111       assign<Scalar>(mvView->col(1).ptr(), three);
00112       assign<Scalar>(mvView->col(2).ptr(), five);
00113     }
00114     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(0)), ST::zero(), error_tol_,
00115       *out, success);
00116     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(1)), as<Scalar>(one*scalarDim), error_tol_,
00117       *out, success);
00118     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(2)), ST::zero(), error_tol_,
00119       *out, success);
00120     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(3)), as<Scalar>(three*scalarDim), error_tol_,
00121       *out, success);
00122     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(4)), ST::zero(), error_tol_,
00123       *out, success);
00124     TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mv->col(5)), as<Scalar>(five*scalarDim), error_tol_,
00125       *out, success);
00126   }
00127 
00128   *out << "\n"<<tc<<") Checking non-contiguous const multi-vector views ...\n";
00129   ++tc;
00130   {
00131     OSTab tab2(out);
00132     const int numCols = 6;
00133     const RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, numCols);
00134     const Scalar
00135       one = as<Scalar>(1.0),
00136       three = as<Scalar>(3.0),
00137       five = as<Scalar>(5.0);
00138     assign<Scalar>(mv.ptr(), ST::zero());
00139     assign<Scalar>(mv->col(1).ptr(), one);
00140     assign<Scalar>(mv->col(3).ptr(), three);
00141     assign<Scalar>(mv->col(5).ptr(), five);
00142     {
00143       const RCP<const MultiVectorBase<Scalar> > mvView =
00144         mv.getConst()->subView(tuple<int>(1, 3, 4, 5)());
00145       TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(0)), as<Scalar>(one*scalarDim), error_tol_,
00146         *out, success);
00147       TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(1)), as<Scalar>(three*scalarDim), error_tol_,
00148         *out, success);
00149       TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(2)), ST::zero(), error_tol_,
00150         *out, success);
00151       TEUCHOS_TEST_FLOATING_EQUALITY( sum(*mvView->col(3)), as<Scalar>(five*scalarDim), error_tol_,
00152         *out, success);
00153     }
00154   }
00155 
00156   if(success)
00157     *out << "\nCongratulations, this MultiVectorBase objects"
00158          << " created form this vector space seems to check out!\n";
00159   else
00160     *out << "\nOh no, at least one of the tests performed failed!\n";
00161 
00162   *out << "\n*** Leaving "<<this->description()<<"::checkMultiVector(vs,...) ...\n";
00163 
00164   return success;
00165 
00166 }
00167 
00168 
00169 template<class Scalar>
00170 bool MultiVectorTester<Scalar>::check(
00171   const MultiVectorBase<Scalar> &mv,
00172   const Ptr<Teuchos::FancyOStream> &out_inout
00173   ) const
00174 {
00175 
00176   using Teuchos::describe;
00177   using Teuchos::FancyOStream;
00178   using Teuchos::OSTab;
00179   typedef Teuchos::ScalarTraits<Scalar> ST;
00180   //typedef typename ST::magnitudeType ScalarMag;
00181 
00182   RCP<FancyOStream> out;
00183   if (!is_null(out_inout))
00184     out = Teuchos::rcpFromPtr(out_inout);
00185   else
00186     out = Teuchos::fancyOStream(rcp(new Teuchos::oblackholestream));
00187 
00188   const Teuchos::EVerbosityLevel verbLevel =
00189     (dump_all()?Teuchos::VERB_EXTREME:Teuchos::VERB_MEDIUM);
00190 
00191   OSTab tab(out,1,"THYRA");
00192 
00193   bool result, success = true;
00194 
00195   *out << "\n*** Entering Thyra::MultiVectorTester<"<<ST::name()<<">::check(mv,...) ...\n";
00196 
00197   *out << "\nTesting a MultiVectorBase object mv described as:\n" << describe(mv,verbLevel);
00198   
00199   // ToDo: Test the specific MultiVectorBase interface
00200   
00201   *out << "\nChecking the LinearOpBase interface of mv ...\n";
00202   result =linearOpTester_.check(mv, out.ptr());
00203   if(!result) success = false;
00204 
00205   if(success)
00206     *out << "\nCongratulations, this MultiVectorBase object seems to check out!\n";
00207   else
00208     *out << "\nOh no, at least one of the tests performed with this MultiVectorBase object failed (see above failures)!\n";
00209   
00210   *out << "\n*** Leaving MultiVectorTester<"<<ST::name()<<">::check(mv,...)\n";
00211 
00212   return success;
00213 
00214 }
00215 
00216 
00217 } // namespace Thyra
00218 
00219 
00220 #endif // THYRA_MULTI_VECTOR_TESTER_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines