test_handles.cpp

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 #include "Teuchos_GlobalMPISession.hpp"
00030 #include "Teuchos_DefaultComm.hpp"
00031 #include "Thyra_VectorImpl.hpp"
00032 #include "Thyra_VectorSpaceImpl.hpp"
00033 #include "Thyra_VectorOpTester.hpp"
00034 #include "Thyra_DefaultSpmdVectorSpace.hpp"
00035 #include "Teuchos_CommandLineProcessor.hpp"
00036 #include "Teuchos_ScalarTraits.hpp"
00037 #include "Teuchos_StandardCatchMacros.hpp"
00038 #include "Teuchos_VerboseObject.hpp"
00039 
00040 using namespace Teuchos;
00041 using namespace Thyra;
00042 
00043 
00044 template <class Scalar> inline 
00045 bool runVectorTests(int n, Teuchos::RefCountPtr<Teuchos::FancyOStream>& out)
00046 {
00047   typedef typename Teuchos::ScalarTraits<Scalar> ST;
00048   typedef typename ST::magnitudeType Mag;
00049 
00050   bool ok = true;
00051   
00052   Mag epsErr = 1.0e1 * ST::prec();
00053   Mag epsWarn = 1.0e2 * epsErr;
00054 
00055   Teuchos::RefCountPtr<const Comm<int> > comm = DefaultComm<Index>::getComm();
00056 
00057   /* ------- test on a monolithic space ------------ */
00058   
00059   *out << "======= Testing on a monolithic vector space ======" << std::endl;
00060   VectorSpace<Scalar> space 
00061     = new DefaultSpmdVectorSpace<Scalar>(comm,n,-1);
00062   
00063   VectorOpTester<Scalar> tester(comm, space, out, 
00064                                 TestSpecifier<Scalar>(true, epsErr, epsWarn));
00065   
00066   ok = tester.runAllTests() && ok;
00067   
00068   /* -------- test on a block space ----------------*/
00069   *out << "======= Testing on a block vector space ======" << std::endl;
00070   VectorSpace<Scalar> blockSpace = productSpace(space, space);
00071   
00072   tester = VectorOpTester<Scalar>(comm, blockSpace, out, 
00073                                   TestSpecifier<Scalar>(true, epsErr, epsWarn));
00074   
00075   ok = tester.runAllTests() && ok;           
00076   
00077   
00078   
00079   
00080   /* -------- test on a space with recursive block structure -----------*/
00081   *out << "======= Testing on a recursively blocked vector space ======" << std::endl;
00082   VectorSpace<Scalar> recSpace = productSpace(space, blockSpace);
00083   
00084   tester = VectorOpTester<Scalar>(comm, recSpace, out,
00085                                   TestSpecifier<Scalar>(true, epsErr, epsWarn));
00086   
00087   ok = tester.runAllTests() && ok;
00088 
00089   return ok;
00090 }
00091 
00092 
00093 int main( int argc, char *argv[] ) 
00094 {
00095   bool success = false;
00096   
00097   GlobalMPISession mpiSession(&argc, &argv);
00098     
00099   // Get stream that can print to just root or all streams!
00100   Teuchos::RefCountPtr<Teuchos::FancyOStream>
00101     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00102   
00103   try {
00104     
00105     int  n = 100;
00106     CommandLineProcessor  clp;
00107     clp.throwExceptions(false);
00108     clp.addOutputSetupOptions(true);
00109     bool verbose = false;
00110     clp.setOption( "verbose", "quiet", &verbose,
00111                    "Determines if any output is printed or not." );
00112     clp.setOption( "local-dim", &n, "Local number of elements in each constituent vector." );
00113     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00114     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) return parse_return;
00115     if (!verbose) out = rcp(new FancyOStream(rcp(new oblackholestream())));
00116     
00117     success = runVectorTests<double>(n, out) ;
00118 
00119     success = runVectorTests<float>(n, out) && success;
00120 
00121 #if defined(HAVE_COMPLEX) && defined(HAVE_TEUCHOS_COMPLEX)
00122     success = runVectorTests<std::complex<double> >(n, out) && success;
00123 #endif
00124 
00125   }
00126   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,out.get()?*out:std::cerr,success)
00127 
00128     if (success)
00129       {
00130         *out << "all tests PASSED!" << std::endl;
00131         return 0;
00132       }
00133     else
00134       {
00135         *out << "at least one test FAILED!" << std::endl;
00136         return 1;
00137       }
00138 }
00139 

Generated on Thu Sep 18 12:33:02 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1