Thyra Package Browser (Single Doxygen Collection) Version of the Day
DefaultSpmdMultiVector_UnitTests.cpp
Go to the documentation of this file.
00001 
00002 #include "Thyra_DefaultSpmdVectorSpace.hpp"
00003 #include "Thyra_DefaultSpmdMultiVector.hpp"
00004 #include "Thyra_MultiVectorTester.hpp"
00005 #include "Thyra_MultiVectorStdOps.hpp"
00006 #include "Thyra_TestingTools.hpp"
00007 #include "Teuchos_UnitTestHarness.hpp"
00008 #include "Teuchos_DefaultComm.hpp"
00009 
00010 
00011 namespace {
00012 
00013 
00014 //
00015 // Helper code and declarations
00016 //
00017 
00018 
00019 using Teuchos::as;
00020 using Teuchos::null;
00021 using Teuchos::RCP;
00022 using Teuchos::rcp;
00023 using Teuchos::rcp_dynamic_cast;
00024 using Teuchos::inOutArg;
00025 using Teuchos::Range1D;
00026 using Thyra::VectorSpaceBase;
00027 using Thyra::MultiVectorBase;
00028 using Thyra::createMembers;
00029 using Thyra::DefaultSpmdMultiVector;
00030 using Thyra::DefaultSpmdVectorSpace;
00031 using Thyra::defaultSpmdVectorSpace;
00032 typedef Thyra::Ordinal Ordinal;
00033 
00034 
00035 const int g_localDim = 6; // ToDo: Make variable!
00036 const int g_numCols = 5;  // ToDo: Make variable!
00037 
00038 
00039 template<class Scalar>
00040 RCP<VectorSpaceBase<Scalar> > 
00041 createSpmdVectorSpace(const Teuchos_Ordinal localDim)
00042 {
00043   return defaultSpmdVectorSpace<Scalar>(
00044     Teuchos::DefaultComm<Teuchos_Ordinal>::getComm(),
00045     localDim, -1 );
00046 }
00047 
00048 
00049 //
00050 // Unit Tests
00051 //
00052 
00053 
00054 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, defaultConstruct,
00055   Scalar )
00056 {
00057   typedef Teuchos::ScalarTraits<Scalar> ST;
00058   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00059   RCP<const MultiVectorBase<Scalar> > mv = createMembers(*vs, g_numCols);
00060   Teuchos::Array<Scalar> mv_sums(g_numCols);
00061   Thyra::sums<Scalar>(*mv, mv_sums());
00062   out << "sums(mv) = " << mv_sums << "\n";
00063 #ifdef THYRA_INITIALIZE_VECS_MULTIVECS_WITH_NANS
00064   for (int i = 0; i < g_numCols; ++i) {
00065     TEST_ASSERT(ST::isnaninf(mv_sums[i]));
00066   }
00067 #endif
00068 }
00069 
00070 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00071   defaultConstruct )
00072 
00073 
00074 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, defaultTester,
00075   Scalar )
00076 {
00077   typedef Teuchos::ScalarTraits<Scalar> ST;
00078   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00079   Thyra::MultiVectorTester<Scalar> mvTester;
00080   const bool mvTesterResult = mvTester.checkMultiVector(*vs, inOutArg(out));
00081   TEST_ASSERT(mvTesterResult);
00082 }
00083 
00084 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00085   defaultTester )
00086 
00087 
00088 // Make sure the currect public member access protections are in place
00089 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, memberAccess,
00090   Scalar )
00091 {
00092   typedef Teuchos::ScalarTraits<Scalar> ST;
00093   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00094   RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, g_numCols);
00095   Thyra::assign<Scalar>(mv.ptr(), ST::zero());
00096   RCP<DefaultSpmdMultiVector<Scalar> > spmdMv = 
00097     rcp_dynamic_cast<DefaultSpmdMultiVector<Scalar> >(mv, true);
00098   TEST_ASSERT(nonnull(spmdMv->spmdSpace()));
00099 }
00100 
00101 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00102   memberAccess )
00103 
00104 
00105 //
00106 // Make sure that DefaultSpmdMultiVector::subview(...) return a
00107 // DefaultSpmdMultiVector object!
00108 //
00109 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, constContigSubViewImpl,
00110   Scalar )
00111 {
00112   typedef Teuchos::ScalarTraits<Scalar> ST;
00113   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00114   RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, g_numCols);
00115   Thyra::assign<Scalar>(mv.ptr(), ST::zero());
00116   RCP<const MultiVectorBase<Scalar> > mvv = mv.getConst()->subView(Range1D(0, 1));
00117   RCP<const DefaultSpmdMultiVector<Scalar> > spmdMvv = 
00118     rcp_dynamic_cast<const DefaultSpmdMultiVector<Scalar> >(mvv, true);
00119   TEST_ASSERT(nonnull(spmdMvv->spmdSpace()));
00120 }
00121 
00122 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00123   constContigSubViewImpl )
00124 
00125 
00126 //
00127 // Make sure that DefaultSpmdMultiVector::subview(...) return a
00128 // DefaultSpmdMultiVector object!
00129 //
00130 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, nonconstContigSubViewImpl,
00131   Scalar )
00132 {
00133   typedef Teuchos::ScalarTraits<Scalar> ST;
00134   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00135   RCP<MultiVectorBase<Scalar> > mv = createMembers(vs, g_numCols);
00136   Thyra::assign<Scalar>(mv.ptr(), ST::zero());
00137   RCP<MultiVectorBase<Scalar> > mvv = mv->subView(Range1D(0, 1));
00138   RCP<DefaultSpmdMultiVector<Scalar> > spmdMvv = 
00139     rcp_dynamic_cast<DefaultSpmdMultiVector<Scalar> >(mvv, true);
00140   TEST_ASSERT(nonnull(spmdMvv->spmdSpace()));
00141 }
00142 
00143 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00144   nonconstContigSubViewImpl )
00145 
00146 
00147 //
00148 // Test that a dangling non-const column subviews don't write back their data.
00149 // If the parent object is gone then why write back the data?  This is a
00150 // performance optimization.
00151 //
00152 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, danglingSubViews,
00153   Scalar )
00154 {
00155   using Teuchos::tuple;
00156   typedef Teuchos::ScalarTraits<Scalar> ST;
00157   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00158   RCP<MultiVectorBase<Scalar> > mv = createMembers(*vs, g_numCols);
00159   RCP<MultiVectorBase<Scalar> > mvView = mv->subView(tuple<int>(0, 1));
00160   mv = null;
00161 #ifdef THYRA_DEBUG
00162   const int startingNumCopyBack = DefaultSpmdMultiVector<Scalar>::numSkipCopyBack;
00163 #endif
00164   mvView = null; // Should not write back data since parent mv is gone now.
00165 #ifdef THYRA_DEBUG
00166   TEST_EQUALITY(DefaultSpmdMultiVector<Scalar>::numSkipCopyBack, startingNumCopyBack+1);
00167 #endif
00168 }
00169 
00170 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00171   danglingSubViews )
00172 
00173 
00174 #ifdef THYRA_DEBUG
00175 
00176 
00177 //
00178 // Test that invalid column indexes throw the right exception messages.
00179 //
00180 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DefaultSpmdMultiVector, invalidSubviews,
00181   Scalar )
00182 {
00183   using Teuchos::tuple;
00184   typedef Teuchos::ScalarTraits<Scalar> ST;
00185   RCP<const VectorSpaceBase<Scalar> > vs = createSpmdVectorSpace<Scalar>(g_localDim);
00186   RCP<const MultiVectorBase<Scalar> > mv = createMembers(*vs, 1);
00187   TEST_THROW(mv->subView(tuple<int>(0, 1)), std::invalid_argument);
00188   TEST_THROW(mv->subView(tuple<int>(-1)), std::out_of_range);
00189   TEST_THROW(mv->subView(tuple<int>(1)), std::out_of_range);
00190 }
00191 
00192 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DefaultSpmdMultiVector,
00193   invalidSubviews )
00194 
00195 
00196 #endif // THYRA_DEBUG
00197 
00198 
00199 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines