[cig-commits] r17179 - in short/3D/PyLith/trunk: libsrc/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Tue Sep 7 19:47:37 PDT 2010
Author: brad
Date: 2010-09-07 19:47:37 -0700 (Tue, 07 Sep 2010)
New Revision: 17179
Modified:
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
Log:
Fixed bug in FieldsNew. Added remaining unit tests.
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc 2010-09-07 22:59:05 UTC (rev 17178)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc 2010-09-08 02:47:37 UTC (rev 17179)
@@ -94,7 +94,7 @@
// Set fiber dimension
const int fiberDim = _fiberDim();
assert(fiberDim > 0);
- _section = new section_type(_mesh.comm(), fiberDim, _mesh.debug());
+ _section = new section_type(_mesh.comm(), _mesh.debug());
assert(!_section.isNull());
// Set spaces
@@ -142,7 +142,7 @@
// Set fiber dimension
const int fiberDim = _fiberDim();
assert(fiberDim > 0);
- _section = new section_type(_mesh.comm(), fiberDim, _mesh.debug());
+ _section = new section_type(_mesh.comm(), _mesh.debug());
assert(!_section.isNull());
// Set spaces
@@ -253,8 +253,8 @@
f_iter->second.field =
new Field<mesh_type>(_mesh, _section->getFibration(fibration),
f_iter->second.metadata);
- assert(0 != f_iter->second.field);
} // if
+ assert(0 != f_iter->second.field);
return *f_iter->second.field;
} // get
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-07 22:59:05 UTC (rev 17178)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-08 02:47:37 UTC (rev 17179)
@@ -42,6 +42,8 @@
friend class TestFieldsNewMesh; // unit testing
friend class TestFieldsNewSubMesh; // unit testing
+ typedef typename mesh_type::RealSection section_type;
+
// PUBLIC MEMBERS ///////////////////////////////////////////////////////
public :
@@ -117,6 +119,12 @@
*/
const mesh_type& mesh(void) const;
+ /** Get section containing fields.
+ *
+ * @returns Sieve section
+ */
+ const ALE::Obj<section_type>& section(void) const;
+
/** Return the names of all fields.
*
* @param numNames Number of fields,
@@ -140,8 +148,6 @@
typedef std::map< std::string, FieldInfo > map_type;
- typedef typename mesh_type::RealSection section_type;
-
// PROTECTED METHODS ////////////////////////////////////////////////////
protected :
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc 2010-09-07 22:59:05 UTC (rev 17178)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.icc 2010-09-08 02:47:37 UTC (rev 17179)
@@ -33,5 +33,14 @@
return _mesh;
} // mesh
+// ----------------------------------------------------------------------
+// Get section containing fields.
+template<typename mesh_type>
+const ALE::Obj<typename pylith::topology::FieldsNew<mesh_type>::section_type>&
+pylith::topology::FieldsNew<mesh_type>::section(void) const
+{ // section
+ return _section;
+} // section
+
// End of file
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc 2010-09-07 22:59:05 UTC (rev 17178)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc 2010-09-08 02:47:37 UTC (rev 17179)
@@ -97,37 +97,109 @@
CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
} // testAdd
-#if 0
// ----------------------------------------------------------------------
-// Test add(domain).
+// Test allocate(sequence).
void
-pylith::topology::TestFieldsNewMesh::testAddDomain(void)
-{ // testAddDomain
- const int fiberDim = 3;
+pylith::topology::TestFieldsNewMesh::testAllocateSequence(void)
+{ // testAllocateSequence
+ const int fiberDim = 7;
CPPUNIT_ASSERT(0 != _mesh);
FieldsNewMesh fields(*_mesh);
- const char* label = "field";
- fields.add(label, "velocity", Field<Mesh>::VERTICES_FIELD, fiberDim);
- const size_t size = 1;
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "other", 4, FieldBase::OTHER);
+
+ const ALE::Obj<SieveMesh>& sieveMesh = _mesh->sieveMesh();
+ CPPUNIT_ASSERT(!sieveMesh.isNull());
+ const ALE::Obj<SieveMesh::label_sequence>& vertices =
+ sieveMesh->depthStratum(0);
+ CPPUNIT_ASSERT(!vertices.isNull());
+
+ fields.allocate(vertices);
+
+ const size_t size = 2;
CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
- Field<Mesh>& field = fields.get(label);
- const ALE::Obj<RealSection>& section = field.section();
+ const ALE::Obj<RealSection>& section = fields.section();
CPPUNIT_ASSERT(!section.isNull());
+ for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+ v_iter != vertices->end();
+ ++v_iter)
+ CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testAllocateSequence
+
+// ----------------------------------------------------------------------
+// Test allocate(array).
+void
+pylith::topology::TestFieldsNewMesh::testAllocateArray(void)
+{ // testAllocateSequence
+ const int fiberDim = 7;
+ const int nptsIn = 3;
+ const int ptsIn[nptsIn] = {
+ 1, 3, 4,
+ };
+ const int nptsOut = 1;
+ const int ptsOut[nptsOut] = {
+ 2,
+ };
+
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "other", 4, FieldBase::OTHER);
+
+ int_array verticesIn(nptsIn);
+ for (int i=0; i < nptsIn; ++i)
+ verticesIn = ptsIn[i];
+
+ int_array verticesOut(nptsOut);
+ for (int i=0; i < nptsOut; ++i)
+ verticesOut = ptsOut[i];
+
+ fields.allocate(verticesIn);
+
+ const size_t size = 2;
+ CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+
+ const ALE::Obj<RealSection>& section = fields.section();
+ CPPUNIT_ASSERT(!section.isNull());
+ for (int i=0; i < nptsIn; ++i)
+ CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(verticesIn[i]));
+ for (int i=0; i < nptsOut; ++i)
+ CPPUNIT_ASSERT_EQUAL(0, section->getFiberDimension(verticesOut[i]));
+} // testAllocateArray
+
+// ----------------------------------------------------------------------
+// Test allocate(domain).
+void
+pylith::topology::TestFieldsNewMesh::testAllocateDomain(void)
+{ // testAllocateDomain
+ const int fiberDim = 7;
+
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "other", 4, FieldBase::OTHER);
+ fields.allocate(Field<Mesh>::VERTICES_FIELD);
+
+ const size_t size = 2;
+ CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+
+ const ALE::Obj<RealSection>& section = fields.section();
+ CPPUNIT_ASSERT(!section.isNull());
const ALE::Obj<SieveMesh>& sieveMesh = _mesh->sieveMesh();
CPPUNIT_ASSERT(!sieveMesh.isNull());
const ALE::Obj<SieveMesh::label_sequence>& vertices =
sieveMesh->depthStratum(0);
CPPUNIT_ASSERT(!vertices.isNull());
- field.allocate();
for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
v_iter != vertices->end();
++v_iter)
CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
-} // testAddDomain
-#endif
+} // testAllocateDomain
// ----------------------------------------------------------------------
// Test get().
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh 2010-09-07 22:59:05 UTC (rev 17178)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh 2010-09-08 02:47:37 UTC (rev 17179)
@@ -49,13 +49,11 @@
CPPUNIT_TEST( testConstructor );
CPPUNIT_TEST( testHasField );
CPPUNIT_TEST( testAdd );
-#if 0
CPPUNIT_TEST( testAllocateSequence );
CPPUNIT_TEST( testAllocateArray );
CPPUNIT_TEST( testAllocateDomain );
CPPUNIT_TEST( testGet );
CPPUNIT_TEST( testGetConst );
-#endif
CPPUNIT_TEST( testMesh );
CPPUNIT_TEST( testFieldNames );
More information about the CIG-COMMITS
mailing list