00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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
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
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