[cig-commits] r17182 - in short/3D/PyLith/trunk: libsrc/topology unittests/libtests/topology
brad at geodynamics.org
brad at geodynamics.org
Wed Sep 8 16:45:06 PDT 2010
Author: brad
Date: 2010-09-08 16:45:06 -0700 (Wed, 08 Sep 2010)
New Revision: 17182
Modified:
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
Log:
Added FieldsNew::sectionIndex() and corresponding unit test.
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc 2010-09-08 23:20:47 UTC (rev 17181)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.cc 2010-09-08 23:45:06 UTC (rev 17182)
@@ -74,6 +74,13 @@
// Set fibration and fiber dimension
info.fibration = _fields.size();
info.fiberDim = fiberDim;
+ int sindex = 0;
+ const typename map_type::const_iterator fieldsEnd = _fields.end();
+ for (typename map_type::iterator f_iter=_fields.begin();
+ f_iter != fieldsEnd;
+ ++f_iter)
+ sindex += f_iter->second.fiberDim;
+ info.sindex = sindex;
info.field = 0;
@@ -265,6 +272,23 @@
} // get
// ----------------------------------------------------------------------
+// Get index of first value of field in section.
+template<typename mesh_type>
+int
+pylith::topology::FieldsNew<mesh_type>::sectionIndex(const char* name) const
+{ // sectionIndex
+ typename map_type::const_iterator f_iter = _fields.find(name);
+ if (f_iter == _fields.end()) {
+ std::ostringstream msg;
+ msg << "Could not find field '" << name
+ << "' in fields manager for retrieval of section index.";
+ throw std::runtime_error(msg.str());
+ } // if
+
+ return f_iter->second.sindex;
+} // sectionIndex
+
+// ----------------------------------------------------------------------
// Get names of all fields
template<typename mesh_type>
void
Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-08 23:20:47 UTC (rev 17181)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsNew.hh 2010-09-08 23:45:06 UTC (rev 17182)
@@ -131,6 +131,13 @@
*/
const ALE::Obj<section_type>& section(void) const;
+ /** Get index of first value of field in section.
+ *
+ * @param name Name of field.
+ * @returns Index of first value of field in section.
+ */
+ int sectionIndex(const char* name) const;
+
/** Return the names of all fields.
*
* @param numNames Number of fields,
@@ -143,10 +150,11 @@
protected :
struct FieldInfo {
- FieldBase::Metadata metadata;
- int fiberDim;
- int fibration;
- Field<mesh_type, section_type>* field;
+ FieldBase::Metadata metadata; ///< Metadata for field.
+ Field<mesh_type, section_type>* field; ///< Single field.
+ int fiberDim; ///< Fiber dimension of field.
+ int fibration; ///< Index of fibration associated with field.
+ int sindex; ///< Index of first value of field in section.
}; // FieldInfo
// PROTECTED TYPEDEFS ///////////////////////////////////////////////////
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc 2010-09-08 23:20:47 UTC (rev 17181)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.cc 2010-09-08 23:45:06 UTC (rev 17182)
@@ -274,6 +274,21 @@
} // testMesh
// ----------------------------------------------------------------------
+// Test sectionIndex().
+void
+pylith::topology::TestFieldsNewMesh::testSectionIndex(void)
+{ // testSectionIndex
+ CPPUNIT_ASSERT(0 != _mesh);
+ FieldsNewMesh fields(*_mesh);
+
+ fields.add("field A", "velocity", 3, FieldBase::VECTOR);
+ fields.add("field B", "displacement", 4, FieldBase::OTHER, 2.0, true);
+
+ CPPUNIT_ASSERT_EQUAL(0, fields.sectionIndex("field A"));
+ CPPUNIT_ASSERT_EQUAL(3, fields.sectionIndex("field B"));
+} // testSectionIndex
+
+// ----------------------------------------------------------------------
// Test fieldNames() const.
void
pylith::topology::TestFieldsNewMesh::testFieldNames(void)
Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh 2010-09-08 23:20:47 UTC (rev 17181)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsNewMesh.hh 2010-09-08 23:45:06 UTC (rev 17182)
@@ -55,6 +55,7 @@
CPPUNIT_TEST( testGet );
CPPUNIT_TEST( testGetConst );
CPPUNIT_TEST( testMesh );
+ CPPUNIT_TEST( testSectionIndex );
CPPUNIT_TEST( testFieldNames );
CPPUNIT_TEST_SUITE_END();
@@ -95,6 +96,9 @@
/// Test mesh().
void testMesh(void);
+ /// Test sectionIndex().
+ void testSectionIndex(void);
+
/// Test fieldNames().
void testFieldNames(void);
More information about the CIG-COMMITS
mailing list