Thyra Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
EpetraThyraWrappers_UnitTests.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00006 //                 Copyright (2004) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 #include "Thyra_DefaultProductVectorSpace.hpp"
00045 #include "Thyra_VectorStdOps.hpp"
00046 #include "Thyra_MultiVectorStdOps.hpp"
00047 #include "Thyra_SpmdVectorSpaceBase.hpp"
00048 #include "Thyra_VectorSpaceTester.hpp"
00049 #include "Thyra_TestingTools.hpp"
00050 #include "Epetra_Vector.h"
00051 #include "Teuchos_GlobalMPISession.hpp"
00052 
00053 #include "EpetraThyraAdaptersTestHelpers.hpp"
00054 
00055 #include "Teuchos_UnitTestHarness.hpp"
00056 
00057 
00058 namespace {
00059 
00060 
00061 using Teuchos::ptrFromRef;
00062 using Teuchos::Comm;
00063 using Teuchos::rcp_dynamic_cast;
00064 using Teuchos::rcp;
00065 
00066 
00067 void runVectorSpaceTesterTest(const int emptyProc, 
00068   Teuchos::FancyOStream &out, bool &success)
00069 {
00070   using Thyra::VectorSpaceBase;
00071   using Thyra::SpmdVectorSpaceBase;
00072   using Thyra::MultiVectorBase;
00073   
00074   RCP<const VectorSpaceBase<double> > vs;
00075   RCP<const Epetra_Map> epetra_map;
00076   createEpetraVsAndMap(g_localDim, outArg(vs), outArg(epetra_map), emptyProc);
00077   const int numProcs = epetra_map->Comm().NumProc();
00078 
00079   if (emptyProc >= numProcs) {
00080     out << "emptyProc = " << emptyProc << " >= numProcs = " << numProcs
00081         << ": Skipping this test case!\n";
00082     return;
00083   }
00084 
00085   const Ordinal dimMultiplier = (emptyProc < 0 ? numProcs : numProcs-1);
00086   
00087   TEST_EQUALITY(vs->dim(), g_localDim * dimMultiplier);
00088 
00089   const RCP<const SpmdVectorSpaceBase<double> > spmd_vs =
00090     rcp_dynamic_cast<const SpmdVectorSpaceBase<double> >(vs, true);
00091 
00092   TEST_EQUALITY(spmd_vs->localSubDim(), as<int>(epetra_map->NumMyElements()));
00093   
00094   Thyra::VectorSpaceTester<double> vectorSpaceTester;
00095   const double tol = 100.0 * Teuchos::ScalarTraits<double>::eps();
00096   vectorSpaceTester.warning_tol((0.1)*tol);
00097   vectorSpaceTester.error_tol(tol);
00098   vectorSpaceTester.show_all_tests(g_show_all_tests);
00099   vectorSpaceTester.dump_all(g_dumpAll);
00100   TEST_ASSERT(vectorSpaceTester.check(*vs, &out));
00101 }
00102 
00103 
00104 void runCreateVectorUnitTest(const int emptyProc, 
00105   Teuchos::FancyOStream &out, bool &success)
00106 {
00107   using Thyra::VectorBase;
00108   using Thyra::VectorSpaceBase;
00109   using Thyra::MultiVectorBase;
00110   
00111   RCP<const VectorSpaceBase<double> > vs;
00112   RCP<const Epetra_Map> epetra_map;
00113   createEpetraVsAndMap(g_localDim, outArg(vs), outArg(epetra_map), emptyProc);
00114   const int numProcs = epetra_map->Comm().NumProc();
00115 
00116   if (emptyProc >= numProcs) {
00117     out << "emptyProc = " << emptyProc << " >= numProcs = " << numProcs
00118         << ": Skipping this test case!\n";
00119     return;
00120   }
00121 
00122   const RCP<Epetra_Vector> epetra_vec = rcp(new Epetra_Vector(*epetra_map));
00123   const RCP<VectorBase<double> > thyra_vec = Thyra::create_Vector(epetra_vec, vs);
00124   const RCP<Epetra_Vector> epetra_vec2 =
00125     Thyra::get_Epetra_Vector(*epetra_map, thyra_vec);
00126   TEST_EQUALITY(epetra_vec, epetra_vec2);
00127 
00128   const RCP<const Epetra_Vector> const_epetra_vec2 =
00129     Thyra::get_Epetra_Vector(*epetra_map, thyra_vec.getConst());
00130   TEST_EQUALITY(epetra_vec.getConst(), const_epetra_vec2);
00131 
00132 }
00133 
00134 
00135 //
00136 // Unit Tests
00137 //
00138 
00139 
00140 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, comm )
00141 {
00142   typedef Teuchos::GlobalMPISession GMPIS;
00143   const RCP<const Epetra_Comm> epetra_comm = getEpetraComm();
00144   TEST_EQUALITY(epetra_comm->NumProc(), GMPIS::getNProc());
00145   TEST_EQUALITY(epetra_comm->MyPID(), GMPIS::getRank());
00146   const RCP<const Comm<Ordinal> > comm = Thyra::create_Comm(epetra_comm);
00147   TEST_EQUALITY(comm->getSize(), GMPIS::getNProc());
00148   TEST_EQUALITY(comm->getRank(), GMPIS::getRank());
00149   const RCP<const Epetra_Comm> epetra_comm2 = Thyra::get_Epetra_Comm(*comm);
00150   TEST_EQUALITY(epetra_comm2->NumProc(), GMPIS::getNProc());
00151   TEST_EQUALITY(epetra_comm2->MyPID(), GMPIS::getRank());
00152 }
00153 
00154 
00155 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, vectorSpaceTester )
00156 {
00157   runVectorSpaceTesterTest(-1, out, success);
00158 }
00159 
00160 
00161 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, vectorSpaceTester_empty_p0 )
00162 {
00163   runVectorSpaceTesterTest(0, out, success);
00164 }
00165 
00166 
00167 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, vectorSpaceTester_empty_p1 )
00168 {
00169   runVectorSpaceTesterTest(1, out, success);
00170 }
00171 
00172 
00173 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, vectorSpaceTester_empty_pLast )
00174 {
00175   runVectorSpaceTesterTest(Teuchos::GlobalMPISession::getNProc()-1, out, success);
00176 }
00177 
00178 
00179 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, createAndViewVector_empty_p0 )
00180 {
00181   runCreateVectorUnitTest(0, out, success);
00182 }
00183 
00184 
00185 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, createAndViewVector_empty_p1 )
00186 {
00187   runCreateVectorUnitTest(1, out, success);
00188 }
00189 
00190 
00191 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, createAndViewVector_empty_pLast )
00192 {
00193   runCreateVectorUnitTest(Teuchos::GlobalMPISession::getNProc()-1, out, success);
00194 }
00195 
00196 
00197 // Test Thyra::create_MultiVector() (const and nonconst) and all views with empty processes
00198 
00199 
00200 TEUCHOS_UNIT_TEST( EpetraThyraWrappers, get_Epetra_MultiVector_singleBlockProductVector )
00201 {
00202 using Thyra::VectorSpaceBase;
00203 using Thyra::MultiVectorBase;
00204 
00205   RCP<const VectorSpaceBase<double> > vs;
00206   RCP<const Epetra_Map> epetra_map;
00207   createEpetraVsAndMap(g_localDim, outArg(vs), outArg(epetra_map));
00208 
00209   const RCP<const VectorSpaceBase<double> > pvs = Thyra::productVectorSpace(vs, 1);
00210 
00211   const RCP<MultiVectorBase<double> > pmv = Thyra::createMembers(pvs, 1);
00212 
00213   const double alpha = 3.5;
00214   Thyra::assign<double>( pmv.ptr(), alpha );
00215 
00216   const RCP<Epetra_MultiVector> epetra_mv =
00217     Thyra::get_Epetra_MultiVector(*epetra_map, pmv);
00218 
00219   const RCP<MultiVectorBase<double> > mv2 =
00220     Thyra::create_MultiVector(epetra_mv, pvs);
00221 
00222   Thyra::testRelNormDiffErr<double>(
00223     "*pmv->col(0)", *pmv->col(0),
00224     "*mv2->col(0)", *mv2->col(0),
00225     "max-error", 0.0,
00226     "max-warning", 0.0,
00227     &out
00228     );
00229    
00230 }
00231 
00232 
00233 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines