[cig-commits] r14010 - in short/3D/PyLith/branches/pylith-swig: libsrc/topology unittests/libtests/topology

brad at geodynamics.org brad at geodynamics.org
Mon Feb 2 18:06:23 PST 2009


Author: brad
Date: 2009-02-02 18:06:22 -0800 (Mon, 02 Feb 2009)
New Revision: 14010

Added:
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.hh
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.cc
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.hh
Modified:
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am
   short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/Makefile.am
Log:
Added Fields object for manager fields (will replace FieldsManager with SolutionFields which will inherit from Fields<Mesh,Field>).

Added: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,118 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file libsrc/topology/Fields.hh
+ *
+ * @brief Object for managing fields over a finite-element mesh.
+ */
+
+#if !defined(pylith_topology_fields_hh)
+#define pylith_topology_fields_hh
+
+// Include directives ---------------------------------------------------
+#include "FieldBase.hh" // USES FieldBase::DomainEnum
+
+// Forward declarations -------------------------------------------------
+namespace pylith {
+  namespace topology {
+    template<typename field_type, typename mesh_type> class Fields;
+
+    class TestFieldsMesh; // unit testing
+    class TestFieldsSubMesh; // unit testing
+  } // topology
+} // pylith
+
+// Fields ---------------------------------------------------------------
+template<typename field_type, typename mesh_type>
+class pylith::topology::Fields
+{ // Fields
+  friend class TestFieldsMesh; // unit testing
+  friend class TestFieldsSubMesh; // unit testing
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /** Default constructor.
+   *
+   * @param mesh Finite-element mesh.
+   */
+  Fields(const mesh_type& mesh);
+
+  /// Destructor.
+  ~Fields(void);
+
+  /** Add field.
+   *
+   * @param name Name of field.
+   */
+  void add(const char* name);
+
+  /** Add field.
+   *
+   * @param name Name of field.
+   * @param domain Type of points over which to define field.
+   * @param fiberDim Fiber dimension for field.
+   */
+  void add(const char* name,
+	   const FieldBase::DomainEnum domain,
+	   const int fiberDim);
+
+  /** Delete field.
+   *
+   * @param name Name of field.
+   */
+  void del(const char* name);
+
+  /** Get field.
+   *
+   * @param name Name of field.
+   */
+  const field_type& get(const char* name) const;
+	   
+  /** Get field.
+   *
+   * @param name Name of field.
+   */
+  field_type& get(const char* name);
+	   
+  /** Copy layout to other fields.
+   *
+   * @param name Name of field to use as template for layout.
+   */
+  void copyLayout(const char* name);
+
+// PRIVATE TYPEDEFS /////////////////////////////////////////////////////
+private :
+
+  typedef std::map< std::string, field_type* > map_type;
+
+// PRIVATE MEMBERS //////////////////////////////////////////////////////
+private :
+
+  map_type _fields;
+  const mesh_type& _mesh;
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  Fields(const Fields&); ///< Not implemented
+  const Fields& operator=(const Fields&); ///< Not implemented
+
+}; // Fields
+
+#include "Fields.icc"
+
+#endif // pylith_topology_fields_hh
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,141 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#if !defined(pylith_topology_fields_hh)
+#error "Fields.icc must be included only from Fields.hh"
+#endif
+
+
+// ----------------------------------------------------------------------
+// Default constructor.
+template<typename field_type, typename mesh_type>
+pylith::topology::Fields<field_type, mesh_type>::Fields(const mesh_type& mesh) :
+  _mesh(mesh)
+{ // constructor
+} // constructor
+
+// ----------------------------------------------------------------------
+// Destructor.
+template<typename field_type, typename mesh_type>
+pylith::topology::Fields<field_type, mesh_type>::~Fields(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Add field.
+template<typename field_type, typename mesh_type>
+void
+pylith::topology::Fields<field_type, mesh_type>::add(const char* name)
+{ // add
+  typename map_type::iterator iter = _fields.find(name);
+  if (iter != _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not add field '" << name
+	<< "' to fields manager, because it already exists.";
+    throw std::runtime_error(msg.str());
+  } // if
+  
+  _fields[name] = new field_type(_mesh);
+} // add
+
+// ----------------------------------------------------------------------
+// Add field.
+template<typename field_type, typename mesh_type>
+void 
+pylith::topology::Fields<field_type, mesh_type>::add(const char* name,
+						     const FieldBase::DomainEnum domain,
+						     const int fiberDim)
+{ // add
+  typename map_type::iterator iter = _fields.find(name);
+  if (iter != _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not add field '" << name
+	<< "' to fields manager, because it already exists.";
+    throw std::runtime_error(msg.str());
+  } // if
+  
+  _fields[name] = new field_type(_mesh);
+  _fields[name]->newSection(domain, fiberDim);
+} // add
+
+// ----------------------------------------------------------------------
+// Delete field.
+template<typename field_type, typename mesh_type>
+void
+pylith::topology::Fields<field_type, mesh_type>::del(const char* name)
+{ // del
+  typename map_type::iterator iter = _fields.find(name);
+  if (iter == _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name
+	<< "' in fields manager to delete.";
+    throw std::runtime_error(msg.str());
+  } // if
+  delete iter->second; iter->second = 0;
+  _fields.erase(name);
+} // del
+
+// ----------------------------------------------------------------------
+// Get field.
+template<typename field_type, typename mesh_type>
+const field_type&
+pylith::topology::Fields<field_type, mesh_type>::get(const char* name) const
+{ // get
+  typename map_type::const_iterator iter = _fields.find(name);
+  if (iter == _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name
+	<< "' in fields manager for retrieval.";
+    throw std::runtime_error(msg.str());
+  } // if
+  return *iter->second;
+} // get
+	   
+// ----------------------------------------------------------------------
+// Get field.
+template<typename field_type, typename mesh_type>
+field_type&
+pylith::topology::Fields<field_type, mesh_type>::get(const char* name)
+{ // get
+  typename map_type::iterator iter = _fields.find(name);
+  if (iter == _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name
+	<< "' in fields manager for retrieval.";
+    throw std::runtime_error(msg.str());
+  } // if
+  return *iter->second;
+} // get
+
+// ----------------------------------------------------------------------
+// Copy layout to other fields.
+template<typename field_type, typename mesh_type>
+void
+pylith::topology::Fields<field_type, mesh_type>::copyLayout(const char* name)
+{ // copyLayout
+  typename map_type::const_iterator src = _fields.find(name);
+  if (src == _fields.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name
+	<< "' in fields manager for retrieval.";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  const typename map_type::iterator begin = _fields.begin();
+  const typename map_type::iterator end = _fields.end();
+  for (typename map_type::iterator iter=begin; iter != end; ++iter)
+    if (iter != src)
+      iter->second->newSection(*src->second);
+} // copyLayout
+
+
+// End of file 

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am	2009-02-02 22:10:24 UTC (rev 14009)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Makefile.am	2009-02-03 02:06:22 UTC (rev 14010)
@@ -21,8 +21,8 @@
 	Field.icc \
 	FieldSubMesh.hh \
 	FieldSubMesh.icc \
-	FieldsManager.hh \
-	FieldOps.hh \
+	Fields.hh \
+	Fields.icc \
 	Mesh.hh \
 	Mesh.icc \
 	MeshOps.hh \

Modified: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/Makefile.am	2009-02-02 22:10:24 UTC (rev 14009)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/Makefile.am	2009-02-03 02:06:22 UTC (rev 14010)
@@ -27,10 +27,10 @@
 	TestFieldBase.cc \
 	TestField.cc \
 	TestFieldSubMesh.cc \
+	TestFieldsMesh.cc \
+	TestFieldsSubMesh.cc \
 	test_topology.cc
 
-#	TestFieldsManager.cc
-
 noinst_HEADERS = \
 	TestMesh.hh \
 	TestSubMesh.hh \
@@ -38,8 +38,10 @@
 	TestFieldBase.hh \
 	TestField.hh \
 	TestFieldSubMesh.hh \
-	TestFieldsManager.hh
+	TestFieldsMesh.hh \
+	TestFieldsSubMesh.hh
 
+
 # Source files associated with testing data
 testtopology_SOURCES += 
 

Added: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.cc	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.cc	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,187 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestFieldsMesh.hh" // Implementation of class methods
+
+#include "pylith/topology/Fields.hh" // USES Fields
+
+#include "pylith/topology/Field.hh" // USES Field
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+
+typedef pylith::topology::Fields<pylith::topology::Field,
+				 pylith::topology::Mesh> FieldsMesh;
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldsMesh );
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsMesh::setUp(void)
+{ // setUp
+  _mesh = new Mesh;
+  meshio::MeshIOAscii importer;
+  importer.filename("data/tri3.mesh");
+  importer.read(_mesh);
+} // setUp
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsMesh::tearDown(void)
+{ // tearDown
+  delete _mesh; _mesh = 0;
+} // tearDown
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestFieldsMesh::testConstructor(void)
+{ // testConstructor
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+} // testConstructor
+ 
+// ----------------------------------------------------------------------
+// Test add().
+void
+pylith::topology::TestFieldsMesh::testAdd(void)
+{ // testAdd
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+  
+  const char* label = "field";
+  fields.add(label);
+  const size_t size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+} // testAdd
+
+// ----------------------------------------------------------------------
+// Test add(domain).
+void
+pylith::topology::TestFieldsMesh::testAddDomain(void)
+{ // testAddDomain
+  const int fiberDim = 3;
+
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+  
+  const char* label = "field";
+  fields.add(label, Field::VERTICES_FIELD, fiberDim);
+  const size_t size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+
+  Field& field = fields.get(label);
+  const ALE::Obj<MeshRealSection>& section = field.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
+
+// ----------------------------------------------------------------------
+// Test del().
+void
+pylith::topology::TestFieldsMesh::testDelete(void)
+{ // testDelete
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+
+  const char* labelA = "field A";
+  fields.add(labelA);
+
+  const char* labelB = "field B";
+  fields.add(labelB);
+
+  size_t size = 2;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  fields.del(labelA);
+  size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  const Field& field = fields.get(labelB);
+} // testDelete
+
+// ----------------------------------------------------------------------
+// Test get().
+void
+pylith::topology::TestFieldsMesh::testGet(void)
+{ // testGet
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+
+  const char* label = "field";
+  fields.add(label);
+  const Field& field = fields.get(label);
+} // testGet
+
+// ----------------------------------------------------------------------
+// Test get() const.
+void
+pylith::topology::TestFieldsMesh::testGetConst(void)
+{ // testGetConst
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+
+  const char* label = "field";
+  fields.add(label);
+
+  const FieldsMesh* fieldsPtr = &fields;
+  CPPUNIT_ASSERT(0 != fieldsPtr);
+  const Field& field = fieldsPtr->get(label);
+} // testGetConst
+
+// ----------------------------------------------------------------------
+// Test copyLayout().
+void
+pylith::topology::TestFieldsMesh::testCopyLayout(void)
+{ // testCopyLayout
+  const int fiberDim = 3;
+
+  CPPUNIT_ASSERT(0 != _mesh);
+  FieldsMesh fields(*_mesh);
+  
+  const char* labelA = "field A";
+  fields.add(labelA, Field::VERTICES_FIELD, fiberDim);
+
+  const char* labelB = "field B";
+  fields.add(labelB);
+  Field& fieldA = fields.get(labelA);
+  fieldA.allocate();
+
+  fields.copyLayout(labelA);
+
+  const size_t size = 2;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  const Field& field = fields.get(labelB);
+  const ALE::Obj<MeshRealSection>& section = field.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());
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testCopyLayout
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.hh	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsMesh.hh	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,93 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/topology/TestFieldsMesh.hh
+ *
+ * @brief C++ unit testing for Fields<Mesh,Field>.
+ */
+
+#if !defined(pylith_topology_testfieldsmesh_hh)
+#define pylith_topology_testfieldsmesh_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestFieldsMesh;
+
+    class Mesh;
+  } // topology
+} // pylith
+
+// TestField -------------------------------------------------------------
+/// C++ unit testing for Field.
+class pylith::topology::TestFieldsMesh : public CppUnit::TestFixture
+{ // class TestField
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestFieldsMesh );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testAdd );
+  CPPUNIT_TEST( testAddDomain );
+  CPPUNIT_TEST( testDelete );
+  CPPUNIT_TEST( testGet );
+  CPPUNIT_TEST( testGetConst );
+  CPPUNIT_TEST( testCopyLayout );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Setup test case.
+  void setUp(void);
+
+  /// Tear down test case.
+  void tearDown(void);
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test add().
+  void testAdd(void);
+
+  /// Test add(domain).
+  void testAddDomain(void);
+
+  /// Test delete().
+  void testDelete(void);
+
+  /// Test get().
+  void testGet(void);
+
+  /// Test get() for const Fields.
+  void testGetConst(void);
+
+  /// Test copyLayout(domain).
+  void testCopyLayout(void);
+
+// PRIVATE MEMBERS /////////////////////////////////////////////////////
+private :
+
+  Mesh* _mesh;
+
+}; // class TestFieldsMesh
+
+#endif // pylith_topology_testfieldsmesh_hh
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.cc	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.cc	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,191 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+#include <portinfo>
+
+#include "TestFieldsSubMesh.hh" // Implementation of class methods
+
+#include "pylith/topology/Fields.hh" // USES Fields
+
+#include "pylith/topology/Mesh.hh" // USES Mesh
+#include "pylith/topology/SubMesh.hh" // USES SubMesh
+#include "pylith/topology/FieldSubMesh.hh" // USES FieldSubMesh
+#include "pylith/meshio/MeshIOAscii.hh" // USES MeshIOAscii
+
+typedef pylith::topology::Fields<pylith::topology::FieldSubMesh,
+				 pylith::topology::SubMesh> FieldsSubMesh;
+
+// ----------------------------------------------------------------------
+CPPUNIT_TEST_SUITE_REGISTRATION( pylith::topology::TestFieldsSubMesh );
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsSubMesh::setUp(void)
+{ // setUp
+  _mesh = new Mesh;
+  meshio::MeshIOAscii importer;
+  importer.filename("data/tri3.mesh");
+  importer.read(_mesh);
+
+  _submesh = new SubMesh(*_mesh, "bc");
+} // setUp
+
+// ----------------------------------------------------------------------
+void
+pylith::topology::TestFieldsSubMesh::tearDown(void)
+{ // tearDown
+  delete _mesh; _mesh = 0;
+  delete _submesh; _submesh = 0;
+} // tearDown
+
+// ----------------------------------------------------------------------
+// Test constructor.
+void
+pylith::topology::TestFieldsSubMesh::testConstructor(void)
+{ // testConstructor
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+} // testConstructor
+ 
+// ----------------------------------------------------------------------
+// Test add().
+void
+pylith::topology::TestFieldsSubMesh::testAdd(void)
+{ // testAdd
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+  
+  const char* label = "field";
+  fields.add(label);
+  const size_t size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+} // testAdd
+
+// ----------------------------------------------------------------------
+// Test add(domain).
+void
+pylith::topology::TestFieldsSubMesh::testAddDomain(void)
+{ // testAddDomain
+  const int fiberDim = 3;
+
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+  
+  const char* label = "field";
+  fields.add(label, FieldSubMesh::VERTICES_FIELD, fiberDim);
+  const size_t size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+
+  FieldSubMesh& field = fields.get(label);
+  const ALE::Obj<MeshRealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
+  const ALE::Obj<SieveMesh>& sieveMesh = _submesh->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
+
+// ----------------------------------------------------------------------
+// Test del().
+void
+pylith::topology::TestFieldsSubMesh::testDelete(void)
+{ // testDelete
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+
+  const char* labelA = "field A";
+  fields.add(labelA);
+
+  const char* labelB = "field B";
+  fields.add(labelB);
+
+  size_t size = 2;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  fields.del(labelA);
+  size = 1;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  const FieldSubMesh& field = fields.get(labelB);
+} // testDelete
+
+// ----------------------------------------------------------------------
+// Test get().
+void
+pylith::topology::TestFieldsSubMesh::testGet(void)
+{ // testGet
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+
+  const char* label = "field";
+  fields.add(label);
+  const FieldSubMesh& field = fields.get(label);
+} // testGet
+
+// ----------------------------------------------------------------------
+// Test get() const.
+void
+pylith::topology::TestFieldsSubMesh::testGetConst(void)
+{ // testGetConst
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+
+  const char* label = "field";
+  fields.add(label);
+
+  const FieldsSubMesh* fieldsPtr = &fields;
+  CPPUNIT_ASSERT(0 != fieldsPtr);
+  const FieldSubMesh& field = fieldsPtr->get(label);
+} // testGetConst
+
+// ----------------------------------------------------------------------
+// Test copyLayout().
+void
+pylith::topology::TestFieldsSubMesh::testCopyLayout(void)
+{ // testCopyLayout
+  const int fiberDim = 3;
+
+  CPPUNIT_ASSERT(0 != _submesh);
+  FieldsSubMesh fields(*_submesh);
+  
+  const char* labelA = "field A";
+  fields.add(labelA, FieldSubMesh::VERTICES_FIELD, fiberDim);
+
+  const char* labelB = "field B";
+  fields.add(labelB);
+  FieldSubMesh& fieldA = fields.get(labelA);
+  fieldA.allocate();
+
+  fields.copyLayout(labelA);
+
+  const size_t size = 2;
+  CPPUNIT_ASSERT_EQUAL(size, fields._fields.size());
+  const FieldSubMesh& field = fields.get(labelB);
+  const ALE::Obj<MeshRealSection>& section = field.section();
+  CPPUNIT_ASSERT(!section.isNull());
+  const ALE::Obj<SieveMesh>& sieveMesh = _submesh->sieveMesh();
+  CPPUNIT_ASSERT(!sieveMesh.isNull());
+  const ALE::Obj<SieveMesh::label_sequence>& vertices
+    = sieveMesh->depthStratum(0);
+  CPPUNIT_ASSERT(!vertices.isNull());
+  for (SieveMesh::label_sequence::iterator v_iter=vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, section->getFiberDimension(*v_iter));
+} // testCopyLayout
+
+
+// End of file 

Added: short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.hh	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/unittests/libtests/topology/TestFieldsSubMesh.hh	2009-02-03 02:06:22 UTC (rev 14010)
@@ -0,0 +1,95 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ----------------------------------------------------------------------
+//
+
+/**
+ * @file unittests/libtests/topology/TestFieldsSubMesh.hh
+ *
+ * @brief C++ unit testing for Fields<Mesh,Field>.
+ */
+
+#if !defined(pylith_topology_testfieldssubmesh_hh)
+#define pylith_topology_testfieldssubmesh_hh
+
+// Include directives ---------------------------------------------------
+#include <cppunit/extensions/HelperMacros.h>
+
+// Forward declarations -------------------------------------------------
+/// Namespace for pylith package
+namespace pylith {
+  namespace topology {
+    class TestFieldsSubMesh;
+
+    class Mesh;
+    class SubMesh;
+  } // topology
+} // pylith
+
+// TestField -------------------------------------------------------------
+/// C++ unit testing for Field.
+class pylith::topology::TestFieldsSubMesh : public CppUnit::TestFixture
+{ // class TestField
+
+  // CPPUNIT TEST SUITE /////////////////////////////////////////////////
+  CPPUNIT_TEST_SUITE( TestFieldsSubMesh );
+
+  CPPUNIT_TEST( testConstructor );
+  CPPUNIT_TEST( testAdd );
+  CPPUNIT_TEST( testAddDomain );
+  CPPUNIT_TEST( testDelete );
+  CPPUNIT_TEST( testGet );
+  CPPUNIT_TEST( testGetConst );
+  CPPUNIT_TEST( testCopyLayout );
+
+  CPPUNIT_TEST_SUITE_END();
+
+  // PUBLIC METHODS /////////////////////////////////////////////////////
+public :
+
+  /// Setup test case.
+  void setUp(void);
+
+  /// Tear down test case.
+  void tearDown(void);
+
+  /// Test constructor.
+  void testConstructor(void);
+
+  /// Test add().
+  void testAdd(void);
+
+  /// Test add(domain).
+  void testAddDomain(void);
+
+  /// Test delete().
+  void testDelete(void);
+
+  /// Test get().
+  void testGet(void);
+
+  /// Test get() for const Fields.
+  void testGetConst(void);
+
+  /// Test copyLayout(domain).
+  void testCopyLayout(void);
+
+// PRIVATE MEMBERS /////////////////////////////////////////////////////
+private :
+
+  Mesh* _mesh;
+  SubMesh* _submesh;
+
+}; // class TestFieldsSubMesh
+
+#endif // pylith_topology_testfieldssubmesh_hh
+
+
+// End of file 



More information about the CIG-COMMITS mailing list