[cig-commits] r6932 - in short/3D/PyLith/trunk: . libsrc/topology modulesrc/topology pylith/topology unittests/libtests/topology unittests/pytests/topology

brad at geodynamics.org brad at geodynamics.org
Sat May 19 15:38:22 PDT 2007


Author: brad
Date: 2007-05-19 15:38:21 -0700 (Sat, 19 May 2007)
New Revision: 6932

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc
   short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/topology/FieldsManager.py
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc
   short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh
   short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py
Log:
Added setFiberDimension() and allocate() to FieldsManager. Added corresponding C++ and Python unit tests.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/TODO	2007-05-19 22:38:21 UTC (rev 6932)
@@ -13,13 +13,6 @@
   dimensions, we probably want to allow it in MeshIO, just not in the
   simulation where we don't support it.
 
-0. Create FieldsManager
-  b. C++ unit tests
-  c. Python unit tests
-
-Update TestDirichlet to check constraints.
-  getConstraintDof() IS IMPLEMENTED!
-
 1. Switch to more uniform implementation of integrators.
 
   Formulation HASA FieldsManager (solnfields)

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc	2007-05-19 22:38:21 UTC (rev 6932)
@@ -80,6 +80,58 @@
 } // delReal
 
 // ----------------------------------------------------------------------
+// Set fiber dimension for field.
+void
+pylith::topology::FieldsManager::setFiberDimension(const char* name,
+						   const int fiberDim,
+						   const char* points)
+{ // setFiberDimension
+  assert(!_mesh.isNull());
+  assert(fiberDim >= 0);
+
+  map_real_type::const_iterator iter = _real.find(name);
+  if (iter == _real.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name << "' to delete.";
+    throw std::runtime_error(msg.str());
+  } // if
+
+  assert(!_real[name].isNull());
+  if (0 == strcasecmp(points, "vertices")) {
+    const ALE::Obj<Mesh::label_sequence>& vertices = _mesh->depthStratum(0);
+    _real[name]->setFiberDimension(vertices, fiberDim);
+  } else if (0 == strcasecmp(points, "cells")) {
+    const ALE::Obj<Mesh::label_sequence>& cells = _mesh->heightStratum(0);
+    _real[name]->setFiberDimension(cells, fiberDim);
+  } else {
+    std::ostringstream msg;
+    msg << "Could not determine parse '" << points
+	<< "' into a known point type when setting fiber dimension to "
+	<< fiberDim << " for section '" << name << "'.\n"
+	<< "Known point types are 'vertices' and 'cells'.";
+    throw std::runtime_error(msg.str());
+  } // if/else
+} // setFiberDimension
+
+// ----------------------------------------------------------------------
+// Allocate field.
+void
+pylith::topology::FieldsManager::allocate(const char* name)
+{ // allocate
+  assert(!_mesh.isNull());
+
+  map_real_type::const_iterator iter = _real.find(name);
+  if (iter == _real.end()) {
+    std::ostringstream msg;
+    msg << "Could not find field '" << name << "' to delete.";
+    throw std::runtime_error(msg.str());
+  } // if
+  
+  assert(!_real[name].isNull());
+  _mesh->allocate(_real[name]);
+} // allocate
+
+// ----------------------------------------------------------------------
 // Copy layout of field to all other fields.
 void
 pylith::topology::FieldsManager::copyLayout(const char* name)

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh	2007-05-19 22:38:21 UTC (rev 6932)
@@ -63,6 +63,23 @@
    */
   void delReal(const char* name);
 
+  /** Set fiber dimension for field.
+   *
+   * @param name Name of field.
+   * @param fiberDim Fiber dimension
+   * @param points Name of set of points in mesh over which section is defined
+   *   { "vertices", "cells" }
+   */
+  void setFiberDimension(const char* name,
+			 const int fiberDim,
+			 const char* points);
+
+  /** Allocate field.
+   *
+   * @param name Name of field.
+   */
+  void allocate(const char* name);
+
   /** Copy layout of field to all other fields.
    *
    * @param name Name of field.

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-19 22:38:21 UTC (rev 6932)
@@ -526,7 +526,7 @@
     Get real field over mesh.
     """
     # create shim for getReal
-    #embed{ void* Mesh_getReal(void* objVptr, char* label)
+    #embed{ void* FieldsManager_getReal(void* objVptr, char* label)
     void* result = 0;
     try {
       pylith::topology::FieldsManager* manager =
@@ -549,7 +549,7 @@
     return result;
     #}embed
     cdef void* ptr
-    ptr = Mesh_getReal(self.thisptr, label)
+    ptr = FieldsManager_getReal(self.thisptr, label)
     return PyCObject_FromVoidPtr(ptr, NULL)
     
 
@@ -558,7 +558,7 @@
     Create real section over mesh.
     """
     # create shim for addReal
-    #embed{ void Mesh_addReal(void* objVptr, char* label)
+    #embed{ void FieldsManager_addReal(void* objVptr, char* label)
     try {
       assert(0 != objVptr);
       ((pylith::topology::FieldsManager*) objVptr)->addReal(label);
@@ -573,7 +573,7 @@
                       "Caught unknown C++ exception.");
     } // try/catch
     #}embed
-    Mesh_addReal(self.thisptr, label)
+    FieldsManager_addReal(self.thisptr, label)
     return
 
 
@@ -582,7 +582,7 @@
     Delete real section over mesh.
     """
     # create shim for delReal
-    #embed{ void Mesh_delReal(void* objVptr, char* label)
+    #embed{ void FieldsManager_delReal(void* objVptr, char* label)
     try {
       assert(0 != objVptr);
       ((pylith::topology::FieldsManager*) objVptr)->delReal(label);
@@ -597,16 +597,64 @@
                       "Caught unknown C++ exception.");
     } // try/catch
     #}embed
-    Mesh_delReal(self.thisptr, label)
+    FieldsManager_delReal(self.thisptr, label)
     return
 
 
+  def setFiberDimension(self, label, fiberDim, points):
+    """
+    Set fiber dimension for field.
+    """
+    # create shim for setFiberDimension
+    #embed{ void FieldsManager_setFiberDimension(void* objVptr, char* label, int fiberDim, char* points)
+    try {
+      assert(0 != objVptr);
+      ((pylith::topology::FieldsManager*) objVptr)->setFiberDimension(label, fiberDim, points);
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (const ALE::Exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.msg().c_str()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    #}embed
+    FieldsManager_setFiberDimension(self.thisptr, label, fiberDim, points)
+    return
+
+
+  def allocate(self, label):
+    """
+    Allocate field.
+    """
+    # create shim for allocate
+    #embed{ void FieldsManager_allocate(void* objVptr, char* label)
+    try {
+      assert(0 != objVptr);
+      ((pylith::topology::FieldsManager*) objVptr)->allocate(label);
+    } catch (const std::exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.what()));
+    } catch (const ALE::Exception& err) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      const_cast<char*>(err.msg().c_str()));
+    } catch (...) {
+      PyErr_SetString(PyExc_RuntimeError,
+                      "Caught unknown C++ exception.");
+    } // try/catch
+    #}embed
+    FieldsManager_allocate(self.thisptr, label)
+    return
+
+
   def copyLayout(self, label):
     """
     Copy layout of given section to all other sections in manager.
     """
     # create shim for copyLayout
-    #embed{ void Mesh_copyLayout(void* objVptr, char* label)
+    #embed{ void FieldsManager_copyLayout(void* objVptr, char* label)
     try {
       assert(0 != objVptr);
       ((pylith::topology::FieldsManager*) objVptr)->copyLayout(label);
@@ -621,7 +669,7 @@
                       "Caught unknown C++ exception.");
     } // try/catch
     #}embed
-    Mesh_copyLayout(self.thisptr, label)
+    FieldsManager_copyLayout(self.thisptr, label)
     return
 
 
@@ -630,7 +678,7 @@
     Copy layout of section to all sections in manager.
     """
     # create shim for copyLayout
-    #embed{ void Mesh_copyLayoutFromSrc(void* objVptr, void* fieldVptr)
+    #embed{ void FieldsManager_copyLayoutFromSrc(void* objVptr, void* fieldVptr)
     try {
       assert(0 != objVptr);
       assert(0 != fieldVptr);
@@ -648,7 +696,7 @@
                       "Caught unknown C++ exception.");
     } // try/catch
     #}embed
-    Mesh_copyLayoutFromSrc(self.thisptr, PyCObject_AsVoidPtr(field))
+    FieldsManager_copyLayoutFromSrc(self.thisptr, PyCObject_AsVoidPtr(field))
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/topology/FieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/FieldsManager.py	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/pylith/topology/FieldsManager.py	2007-05-19 22:38:21 UTC (rev 6932)
@@ -55,6 +55,24 @@
     return self.cppHandle.delReal(label)
 
 
+  def setFiberDimension(self, label, fiberDim, points="vertices"):
+    """
+    Set fiber dimension for field
+
+    points = { 'vertices', 'cells' }
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.setFiberDimension(label, fiberDim, points)
+
+
+  def allocate(self, label):
+    """
+    Allocate field.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.allocate(label)
+
+
   def copyLayout(self, label):
     """
     Copy layout of field to all fields in manager.

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc	2007-05-19 22:38:21 UTC (rev 6932)
@@ -87,6 +87,66 @@
 } // testDelReal
 
 // ----------------------------------------------------------------------
+// Test setFiberDimension().
+void
+pylith::topology::TestFieldsManager::testSetFiberDimension(void)
+{ // testSetFiberDimension
+  ALE::Obj<Mesh> mesh;
+  _initialize(&mesh);
+  FieldsManager manager(mesh);
+
+  const int fiberDim = 3;
+
+  const char* labelA = "field A";
+  manager.addReal(labelA);
+  manager.setFiberDimension(labelA, fiberDim, "vertices");
+  const ALE::Obj<real_section_type>& fieldA = manager.getReal(labelA);
+  CPPUNIT_ASSERT(!fieldA.isNull());
+  const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+  mesh->allocate(fieldA);
+  for (Mesh::label_sequence::iterator v_iter = vertices->begin();
+       v_iter != vertices->end();
+       ++v_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, fieldA->getFiberDimension(*v_iter));
+
+  const char* labelB = "field B";
+  manager.addReal(labelB);
+  manager.setFiberDimension(labelB, fiberDim, "cells");
+  const ALE::Obj<real_section_type>& fieldB = manager.getReal(labelB);
+  CPPUNIT_ASSERT(!fieldB.isNull());
+  const ALE::Obj<Mesh::label_sequence>& cells = mesh->heightStratum(0);
+  mesh->allocate(fieldB);
+  for (Mesh::label_sequence::iterator c_iter = cells->begin();
+       c_iter != cells->end();
+       ++c_iter)
+    CPPUNIT_ASSERT_EQUAL(fiberDim, fieldB->getFiberDimension(*c_iter));
+} // testSetFiberDimension
+
+// ----------------------------------------------------------------------
+// Test allocate().
+void
+pylith::topology::TestFieldsManager::testAllocate(void)
+{ // testAllocate
+  ALE::Obj<Mesh> mesh;
+  _initialize(&mesh);
+  FieldsManager manager(mesh);
+
+  const int fiberDim = 3;
+
+  const char* labelA = "field A";
+  manager.addReal(labelA);
+  const ALE::Obj<real_section_type>& fieldA = manager.getReal(labelA);
+  manager.setFiberDimension(labelA, fiberDim, "vertices");
+  manager.allocate(labelA);
+
+  const char* labelB = "field B";
+  manager.addReal(labelB);
+  const ALE::Obj<real_section_type>& fieldB = manager.getReal(labelB);
+  manager.setFiberDimension(labelB, fiberDim, "cells");
+  manager.allocate(labelB);
+} // testAllocate
+
+// ----------------------------------------------------------------------
 // Test copyLayout().
 void
 pylith::topology::TestFieldsManager::testCopyLayout(void)

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh	2007-05-19 22:38:21 UTC (rev 6932)
@@ -44,6 +44,8 @@
   CPPUNIT_TEST( testAddReal );
   CPPUNIT_TEST( testGetReal );
   CPPUNIT_TEST( testDelReal );
+  CPPUNIT_TEST( testSetFiberDimension );
+  CPPUNIT_TEST( testAllocate );
   CPPUNIT_TEST( testCopyLayout );
   CPPUNIT_TEST( testCopyLayoutFromField );
   CPPUNIT_TEST_SUITE_END();
@@ -63,6 +65,12 @@
   /// Test delReal().
   void testDelReal(void);
 
+  /// Test setFiberDimension().
+  void testSetFiberDimension(void);
+
+  /// Test allocate().
+  void testAllocate(void);
+
   /// Test copyLayout().
   void testCopyLayout(void);
 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py	2007-05-19 22:37:27 UTC (rev 6931)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py	2007-05-19 22:38:21 UTC (rev 6932)
@@ -93,6 +93,50 @@
     return
 
 
+  def test_setFiberDimension(self):
+    """
+    Test setFiberDimension().
+
+    WARNING: This is not a rigorous test of setConstraints() because we
+    don't verify the results.
+    """
+
+    mesh = self._initialize()
+    from pylith.topology.FieldsManager import FieldsManager
+    manager = FieldsManager(mesh)
+
+    manager.addReal("field A")
+    manager.setFiberDimension("field A", 3, "vertices")
+
+    manager.addReal("field B")
+    manager.setFiberDimension("field B", 2, "cells")
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
+  def test_allocate(self):
+    """
+    Test allocate().
+
+    WARNING: This is not a rigorous test of setConstraints() because we
+    don't verify the results.
+    """
+
+    mesh = self._initialize()
+    from pylith.topology.FieldsManager import FieldsManager
+    manager = FieldsManager(mesh)
+
+    manager.addReal("field")
+    manager.setFiberDimension("field", 3, "vertices")
+    manager.allocate("field")
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
   def test_copyLayout(self):
     """
     Test copyLayout().



More information about the cig-commits mailing list