[cig-commits] r7174 - 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
Tue Jun 12 15:09:39 PDT 2007


Author: brad
Date: 2007-06-12 15:09:39 -0700 (Tue, 12 Jun 2007)
New Revision: 7174

Modified:
   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 setting name of solution field and getting solution field to FieldsManager. Updated unit tests accordingly.

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsManager.cc	2007-06-12 22:09:39 UTC (rev 7174)
@@ -21,7 +21,8 @@
 // ----------------------------------------------------------------------
 // Constructor
 pylith::topology::FieldsManager::FieldsManager(const ALE::Obj<Mesh>& mesh) :
-  _mesh(mesh)
+  _mesh(mesh),
+  _solutionName("")
 { // constructor
 } // constructor
 
@@ -207,6 +208,29 @@
 } // copyLayout
 
 // ----------------------------------------------------------------------
+// Set name of solution field.
+void
+pylith::topology::FieldsManager::solutionField(const char* name)
+{ // solutionField
+  map_real_type::const_iterator iter = _real.find(name);
+  if (iter == _real.end()) {
+    std::ostringstream msg;
+    msg << "Cannot use unknown field '" << name 
+	<< "' when setting name of solution field.";
+    throw std::runtime_error(msg.str());
+  } // if
+  _solutionName = name;
+} // solutionField
+
+// ----------------------------------------------------------------------
+// Get solution field.
+const ALE::Obj<pylith::real_section_type>&
+pylith::topology::FieldsManager::getSolution(void)
+{ // getSolution
+  return getReal(_solutionName.c_str());
+} // getSolution
+
+// ----------------------------------------------------------------------
 // Create history manager for a subset of the managed fields.
 void
 pylith::topology::FieldsManager::createHistory(const char** fields,

Modified: short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/libsrc/topology/FieldsManager.hh	2007-06-12 22:09:39 UTC (rev 7174)
@@ -93,6 +93,18 @@
    */
   void copyLayout(const ALE::Obj<real_section_type>& field);
 
+  /** Set name of solution field.
+   *
+   * @param name Name of field that is the solution.
+   */
+  void solutionField(const char* name);
+
+  /** Get solution field.
+   *
+   * @returns Solution field.
+   */
+  const ALE::Obj<real_section_type>& getSolution(void);
+
   /** Create history manager for a subset of the managed fields.
    *
    * @param fields Fields in history (first is most recent).
@@ -110,6 +122,7 @@
   /** Get field in history by position.
    *
    * @param index Index in history [0=most recent, 1=previous, etc]
+   * @returns Field in history.
    */
   const ALE::Obj<real_section_type>& getHistoryItem(const int index);
 
@@ -136,6 +149,9 @@
   /// Map for fieldss stored as real fields
   map_real_type _real;
 
+  /// Name of field that corresponds to the solution.
+  std::string _solutionName;
+
   /// History manager for a subset of the fields
   std::vector<std::string> _history;
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-06-12 22:09:39 UTC (rev 7174)
@@ -702,6 +702,58 @@
     return
 
 
+  def solutionField(self, name):
+    """
+    Set name of field corresponding to solution.
+    """
+    # create shim for solutionField
+    #embed{ void FieldsManager_solutionField(void* objVptr, char* name)
+    try {
+      assert(0 != objVptr);
+      ((pylith::topology::FieldsManager*) objVptr)->solutionField(name);
+    } 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_solutionField(self.thisptr, name)
+
+
+  def getSolution(self):
+    """
+    Get field corresponding to solution.
+    """
+    # create shim for getSolution
+    #embed{ void* FieldsManager_getSolution(void* objVptr)
+    void* result = 0;
+    try {
+      assert(0 != objVptr);
+      const ALE::Obj<pylith::real_section_type>& field =
+        ((pylith::topology::FieldsManager*) objVptr)->getSolution();
+      result = (void*) &field;
+    } 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
+    return result;
+    #}embed
+    cdef void* ptr
+    ptr = FieldsManager_getSolution(self.thisptr)
+    return PyCObject_FromVoidPtr(ptr, NULL)
+
+
   def createHistory(self, labels):
     """
     Create history manager for a subset of the managed fields.

Modified: short/3D/PyLith/trunk/pylith/topology/FieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/FieldsManager.py	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/pylith/topology/FieldsManager.py	2007-06-12 22:09:39 UTC (rev 7174)
@@ -89,12 +89,30 @@
     return self.cppHandle.copyLayoutFromSrc(field)
 
 
+  def solutionField(self, name):
+    """
+    Set name of field corresponding to solution.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.solutionField(name)
+    return
+
+
+  def getSolution(self):
+    """
+    Get field corresponding to solution.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.getSolution()
+
+
   def createHistory(self, labels):
     """
     Create history manager for a subset of the managed fields.
     """
     assert(None != self.cppHandle)
     self.cppHandle.createHistory(labels)
+    return
 
 
   def shiftHistory(self):
@@ -103,6 +121,7 @@
     """
     assert(None != self.cppHandle)
     self.cppHandle.shiftHistory()
+    return
 
 
   def getHistoryItem(self, index):

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.cc	2007-06-12 22:09:39 UTC (rev 7174)
@@ -253,6 +253,53 @@
 } // testCopyLayoutFromField
 
 // ----------------------------------------------------------------------
+// Test solutionField().
+void
+pylith::topology::TestFieldsManager::testSolutionField(void)
+{ // testSolutionField
+  ALE::Obj<Mesh> mesh;
+  _initialize(&mesh);
+  FieldsManager manager(mesh);
+
+  const std::string& name = "my solution";
+  manager.addReal(name.c_str());
+  manager.solutionField(name.c_str());
+  CPPUNIT_ASSERT_EQUAL(name, manager._solutionName);
+} // testSolutionField
+
+// ----------------------------------------------------------------------
+// Test getSolution().
+void
+pylith::topology::TestFieldsManager::testGetSolution(void)
+{ // testGetSolution
+  ALE::Obj<Mesh> mesh;
+  _initialize(&mesh);
+  FieldsManager manager(mesh);
+
+  const char* labels[] = { "field A", "field B", "field C" };
+  const int size = 3;
+  const int fiberDimA = 2;
+  const int fiberDimB = 3;
+  const int fiberDimC = 4;
+
+  for (int i=0; i < size; ++i)
+    manager.addReal(labels[i]);
+
+  const ALE::Obj<Mesh::label_sequence>& vertices = mesh->depthStratum(0);
+  const ALE::Obj<real_section_type>& fieldA = manager.getReal(labels[0]);
+  const ALE::Obj<real_section_type>& fieldB = manager.getReal(labels[1]);
+  const ALE::Obj<real_section_type>& fieldC = manager.getReal(labels[2]);
+  fieldA->setFiberDimension(vertices, fiberDimA);
+  fieldB->setFiberDimension(vertices, fiberDimB);
+  fieldC->setFiberDimension(vertices, fiberDimC);
+
+  manager.solutionField(labels[1]);
+  const ALE::Obj<real_section_type>& solution = manager.getSolution();
+  CPPUNIT_ASSERT_EQUAL(fiberDimB, 
+		       solution->getFiberDimension(*(vertices->begin())));
+} // testGetSolution
+
+// ----------------------------------------------------------------------
 // Test createHistory().
 void
 pylith::topology::TestFieldsManager::testCreateHistory(void)

Modified: short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh
===================================================================
--- short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/unittests/libtests/topology/TestFieldsManager.hh	2007-06-12 22:09:39 UTC (rev 7174)
@@ -48,6 +48,8 @@
   CPPUNIT_TEST( testAllocate );
   CPPUNIT_TEST( testCopyLayout );
   CPPUNIT_TEST( testCopyLayoutFromField );
+  CPPUNIT_TEST( testSolutionField );
+  CPPUNIT_TEST( testGetSolution );
   CPPUNIT_TEST( testCreateHistory );
   CPPUNIT_TEST( testShiftHistory );
   CPPUNIT_TEST( testGetHistoryItem );
@@ -80,6 +82,12 @@
   /// Test copyLayoutFromField().
   void testCopyLayoutFromField(void);
 
+  /// Test solutionField().
+  void testSolutionField(void);
+
+  /// Test getSolution().
+  void testGetSolution(void);
+
   /// Test createHistory().
   void testCreateHistory(void);
 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py	2007-06-12 21:02:27 UTC (rev 7173)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestFieldsManager.py	2007-06-12 22:09:39 UTC (rev 7174)
@@ -40,7 +40,7 @@
     """
     Test addReal().
 
-    WARNING: This is not a rigorous test of initialize() because we
+    WARNING: This is not a rigorous test of addReal() because we
     don't verify the results.
     """
 
@@ -58,7 +58,7 @@
     """
     Test getReal().
 
-    WARNING: This is not a rigorous test of setConstraintSizes() because we
+    WARNING: This is not a rigorous test of getReal() because we
     don't verify the results.
     """
     mesh = self._initialize()
@@ -77,7 +77,7 @@
     """
     Test delReal().
 
-    WARNING: This is not a rigorous test of setConstraints() because we
+    WARNING: This is not a rigorous test of delReal() because we
     don't verify the results.
     """
 
@@ -97,7 +97,7 @@
     """
     Test setFiberDimension().
 
-    WARNING: This is not a rigorous test of setConstraints() because we
+    WARNING: This is not a rigorous test of setFiberDimension() because we
     don't verify the results.
     """
 
@@ -120,7 +120,7 @@
     """
     Test allocate().
 
-    WARNING: This is not a rigorous test of setConstraints() because we
+    WARNING: This is not a rigorous test of allocate() because we
     don't verify the results.
     """
 
@@ -141,7 +141,7 @@
     """
     Test copyLayout().
 
-    WARNING: This is not a rigorous test of setField() because we
+    WARNING: This is not a rigorous test of copyLayout() because we
     don't verify the results.
     """
 
@@ -159,7 +159,7 @@
     """
     Test copyLayoutFromSrc().
 
-    WARNING: This is not a rigorous test of setField() because we
+    WARNING: This is not a rigorous test of copyLayoutFromSrc() because we
     don't verify the results.
     """
 
@@ -179,6 +179,51 @@
     return
 
 
+  def test_solutionField(self):
+    """
+    Test solutionField().
+
+    WARNING: This is not a rigorous test of solutionField() because we
+    don't verify the results.
+    """
+    mesh = self._initialize()
+    from pylith.topology.FieldsManager import FieldsManager
+    manager = FieldsManager(mesh)
+    
+    fields = ["field A", "field B", "field C"]
+    for field in fields:
+      manager.addReal(field)
+
+    manager.solutionField("field B")
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
+  def test_getSolution(self):
+    """
+    Test getSolution().
+
+    WARNING: This is not a rigorous test of getSolution() because we
+    don't verify the results.
+    """
+    mesh = self._initialize()
+    from pylith.topology.FieldsManager import FieldsManager
+    manager = FieldsManager(mesh)
+    
+    fields = ["field A", "field B", "field C"]
+    for field in fields:
+      manager.addReal(field)
+
+    manager.solutionField("field B")
+    solution = manager.getSolution()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
   def test_createHistory(self):
     """
     Test createHistory().



More information about the cig-commits mailing list