Thyra Package Browser (Single Doxygen Collection) Version of the Day
DetachedSpmdVectorView_UnitTests.cpp
Go to the documentation of this file.
00001 
00002 #include "Thyra_DetachedSpmdVectorView.hpp"
00003 #include "Thyra_DefaultSpmdVectorSpace.hpp"
00004 #include "Thyra_VectorStdOps.hpp"
00005 #include "Teuchos_UnitTestHarness.hpp"
00006 #include "Teuchos_DefaultComm.hpp"
00007 
00008 
00009 namespace {
00010 
00011 
00012 //
00013 // Helper code and declarations
00014 //
00015 
00016 
00017 using Teuchos::as;
00018 using Teuchos::null;
00019 using Teuchos::RCP;
00020 using Thyra::VectorBase;
00021 using Thyra::VectorSpaceBase;
00022 using Thyra::createMember;
00023 using Thyra::V_S;
00024 using Thyra::defaultSpmdVectorSpace;
00025 using Thyra::ConstDetachedSpmdVectorView;
00026 using Thyra::DetachedSpmdVectorView;
00027 
00028 
00029 const Teuchos_Ordinal g_localDim = 4; // ToDo: Make variable!
00030 
00031 
00032 template<class Scalar>
00033 RCP<VectorSpaceBase<Scalar> > 
00034 createSpmdVectorSpace(const Teuchos_Ordinal localDim)
00035 {
00036   return defaultSpmdVectorSpace<Scalar>(
00037     Teuchos::DefaultComm<Teuchos_Ordinal>::getComm(),
00038     localDim, -1 );
00039 }
00040 
00041 
00042 //
00043 // ConstDetachedSpmdVectorView unit tests
00044 //
00045 
00046 
00047 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ConstDetachedSpmdVectorView, construct_null,
00048   Scalar )
00049 {
00050   ECHO(ConstDetachedSpmdVectorView<Scalar> dvv(null));
00051   TEST_EQUALITY_CONST(dvv.globalOffset(), 0);
00052   TEST_EQUALITY_CONST(dvv.subDim(), 0);
00053   TEST_EQUALITY_CONST(dvv.values(), null);
00054   TEST_EQUALITY_CONST(dvv.stride(), 0);
00055 }
00056 
00057 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( ConstDetachedSpmdVectorView,
00058   construct_null )
00059 
00060 
00061 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ConstDetachedSpmdVectorView, basic, Scalar )
00062 {
00063   ECHO(const RCP<const VectorSpaceBase<Scalar> >
00064     vs = createSpmdVectorSpace<Scalar>(g_localDim));
00065   ECHO(RCP<VectorBase<Scalar> > v = createMember(vs));
00066   ECHO(V_S(v.ptr(), as<Scalar>(2.0)));
00067   ECHO(ConstDetachedSpmdVectorView<Scalar> dvv(v));
00068   TEST_INEQUALITY(dvv.spmdSpace(), null);
00069   TEST_ASSERT(vs->isCompatible(*dvv.spmdSpace()));
00070   TEST_EQUALITY_CONST(dvv.globalOffset(), 0);
00071   TEST_EQUALITY(dvv.subDim(), g_localDim);
00072   TEST_ASSERT(!is_null(dvv.values()));
00073   TEST_EQUALITY(dvv.values().size(), g_localDim);
00074   TEST_EQUALITY_CONST(dvv.stride(), 1);
00075   {
00076     out << "\nTest that dvv[i] == 2.0 ... ";
00077     bool local_success = true;
00078     for (Teuchos_Ordinal i = 0; i < dvv.subDim(); ++i) {
00079       TEST_ARRAY_ELE_EQUALITY( dvv, i, as<Scalar>(2.0) );
00080     }
00081     if (local_success) out << "passed\n";
00082     else success = false;
00083   }
00084   // ToDo: Write a better test than this because this does not give me a lot
00085   // of confidence.
00086 }
00087 
00088 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( ConstDetachedSpmdVectorView,
00089   basic )
00090 
00091 
00092 //
00093 // DetachedSpmdVectorView unit tests
00094 //
00095 
00096 
00097 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DetachedSpmdVectorView, construct_null,
00098   Scalar )
00099 {
00100   ECHO(DetachedSpmdVectorView<Scalar> dvv(null));
00101   TEST_EQUALITY_CONST(dvv.globalOffset(), 0);
00102   TEST_EQUALITY_CONST(dvv.subDim(), 0);
00103   TEST_EQUALITY_CONST(dvv.values(), null);
00104   TEST_EQUALITY_CONST(dvv.stride(), 0);
00105 }
00106 
00107 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DetachedSpmdVectorView, construct_null )
00108 
00109 
00110 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( DetachedSpmdVectorView, basic,
00111   Scalar )
00112 {
00113   ECHO(const RCP<const VectorSpaceBase<Scalar> >
00114     vs = createSpmdVectorSpace<Scalar>(g_localDim));
00115   ECHO(RCP<VectorBase<Scalar> > v = createMember(vs));
00116   {
00117     ECHO(DetachedSpmdVectorView<Scalar> dvv(v));
00118     TEST_INEQUALITY(dvv.spmdSpace(), null);
00119     TEST_ASSERT(vs->isCompatible(*dvv.spmdSpace()));
00120     TEST_EQUALITY_CONST(dvv.globalOffset(), 0);
00121     TEST_EQUALITY(dvv.subDim(), g_localDim);
00122     TEST_ASSERT(!is_null(dvv.values()));
00123     TEST_EQUALITY(dvv.values().size(), g_localDim);
00124     TEST_EQUALITY_CONST(dvv.stride(), 1);
00125     for (Teuchos_Ordinal i = 0; i < dvv.subDim(); ++i) {
00126       dvv[i] = as<Scalar>(2.0); // ToDo: Do something better here!
00127     }
00128   }
00129   {
00130     ECHO(ConstDetachedSpmdVectorView<Scalar> dvv(v));
00131     out << "\nTest that dvv[i] == 2.0 ... ";
00132     bool local_success = true;
00133     for (Teuchos_Ordinal i = 0; i < dvv.subDim(); ++i) {
00134       TEST_ARRAY_ELE_EQUALITY( dvv, i, as<Scalar>(2.0) );
00135     }
00136     if (local_success) out << "passed\n";
00137     else success = false;
00138   }
00139   // ToDo: Write a better test than this because this does not give me a lot
00140   // of confidence.
00141 }
00142 
00143 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES( DetachedSpmdVectorView,
00144   basic )
00145 
00146 
00147 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines