[cig-commits] r6922 - in short/3D/PyLith/trunk: . modulesrc/topology pylith/bc pylith/problems pylith/topology unittests/pytests unittests/pytests/bc unittests/pytests/bc/data

brad at geodynamics.org brad at geodynamics.org
Fri May 18 09:55:50 PDT 2007


Author: brad
Date: 2007-05-18 09:55:48 -0700 (Fri, 18 May 2007)
New Revision: 6922

Added:
   short/3D/PyLith/trunk/unittests/pytests/bc/
   short/3D/PyLith/trunk/unittests/pytests/bc/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py
   short/3D/PyLith/trunk/unittests/pytests/bc/data/
   short/3D/PyLith/trunk/unittests/pytests/bc/data/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.mesh
   short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.spatialdb
   short/3D/PyLith/trunk/unittests/pytests/bc/testbc.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/bc/Dirichlet.py
   short/3D/PyLith/trunk/pylith/problems/Explicit.py
   short/3D/PyLith/trunk/pylith/problems/Implicit.py
   short/3D/PyLith/trunk/pylith/topology/Mesh.py
   short/3D/PyLith/trunk/unittests/pytests/Makefile.am
Log:
Add Python unit tests for Dirichlet boundary conditions. In Mesh, separated creating real section and allocating real section into separate methods to allow setting constraints. Updated Explicit and Implicit formulations accordingly.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/TODO	2007-05-18 16:55:48 UTC (rev 6922)
@@ -13,9 +13,8 @@
   dimensions, we probably want to allow it in MeshIO, just not in the
   simulation where we don't support it.
 
-1. Implement Dirichlet boundary conditions
-   c. C++ unit tests
-   d. Python unit tests
+1. Unit tests for Mesh.py
+  create section, matrix, etc
 
 2. Finish implementing ExplicitElasticity and Explicit
    a. Replace integrateConstant() with integrateResidual()

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/configure.ac	2007-05-18 16:55:48 UTC (rev 6922)
@@ -231,6 +231,8 @@
 		unittests/libtests/meshio/data/Makefile
 		unittests/libtests/topology/Makefile
 		unittests/pytests/Makefile
+		unittests/pytests/bc/Makefile
+		unittests/pytests/bc/data/Makefile
 		unittests/pytests/faults/Makefile
 		unittests/pytests/faults/data/Makefile
 		unittests/pytests/feassemble/Makefile

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-18 16:55:48 UTC (rev 6922)
@@ -159,8 +159,6 @@
         (*mesh)->getRealSection(label);
       assert(!section.isNull());
       section->setFiberDimension((*mesh)->depthStratum(0), fiberDim);
-      (*mesh)->allocate(section);
-      section->zero();
       result = (void*) &section;
     } catch (const std::exception& err) {
       PyErr_SetString(PyExc_RuntimeError,
@@ -179,6 +177,40 @@
     return PyCObject_FromVoidPtr(ptr, NULL)
     
 
+  def allocateRealSection(self, section):
+    """
+    Allocate (and zero) real section.
+    """
+    # create shim for allocate
+    #embed{ void* Mesh_allocateRealSection(void* objVptr, void* sectionVptr)
+    typedef ALE::Mesh::real_section_type real_section_type;
+    
+    try {
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) objVptr;
+      ALE::Obj<pylith::real_section_type>* section =
+        (ALE::Obj<pylith::real_section_type>*) sectionVptr;
+      assert(0 != mesh);
+      assert(!mesh->isNull());
+      assert(0 != section);
+      assert(!section->isNull());
+      (*mesh)->allocate(*section);
+      (*section)->zero();
+    } 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
+    cdef void* ptr
+    ptr = Mesh_allocateRealSection(self.thisptr, PyCObject_AsVoidPtr(section))
+    return
+    
+
   def createMatrix(self, field):
     """
     Create matrix compatible with field.

Modified: short/3D/PyLith/trunk/pylith/bc/Dirichlet.py
===================================================================
--- short/3D/PyLith/trunk/pylith/bc/Dirichlet.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/pylith/bc/Dirichlet.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -47,7 +47,7 @@
 
   # INVENTORY //////////////////////////////////////////////////////////
 
-  class Inventory(Component.Inventory):
+  class Inventory(BoundaryCondition.Inventory):
     """
     Python object for managing BoundaryCondition facilities and properties.
     """
@@ -63,8 +63,8 @@
 
     import pyre.inventory
 
-    fixeDOF = pyre.inventory.list("fixed_dof", default=[],
-                                  validator=validateDOF)
+    fixedDOF = pyre.inventory.list("fixed_dof", default=[],
+                                   validator=validateDOF)
     fixedDOF.meta['tip'] = "Indices of fixed DOF (0=1st DOF, 1=2nd DOF, etc)."
     
 
@@ -86,8 +86,8 @@
     Initialize Dirichlet boundary condition.
     """
     BoundaryCondition.initialize(self, mesh)
-    self.cppHandle.fixedDOF = fixedDOF
-    self.cppHandle.initialize(mesh.cppHandle, mesh.coordsys)
+    self.cppHandle.fixedDOF = self.fixedDOF
+    self.cppHandle.initialize(mesh.cppHandle, mesh.coordsys.cppHandle)
     return
   
 
@@ -96,7 +96,7 @@
     Set number of constraints at points in field.
     """
     assert(None != self.cppHandle)
-    self.cppHandle.setConstraintSizes(field)
+    self.cppHandle.setConstraintSizes(field, mesh.cppHandle)
     return
 
 
@@ -105,7 +105,7 @@
     Set which degrees of freedom are constrained at points in field.
     """
     assert(None != self.cppHandle)
-    self.cppHandle.setConstraints(field)
+    self.cppHandle.setConstraints(field, mesh.cppHandle)
     return
 
 
@@ -114,7 +114,7 @@
     Set solution field at time t.
     """
     assert(None != self.cppHandle)
-    self.cppHandle.setField(field, t)
+    self.cppHandle.setField(t, field, mesh.cppHandle)
     return
   
 

Modified: short/3D/PyLith/trunk/pylith/problems/Explicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -86,12 +86,21 @@
     self._info.log("Initializing integrators.")
 
     self._info.log("Creating fields and matrices.")
-    self.dispT = mesh.cppHandle.createRealSection("dispT", dimension)
-    self.dispTmdt = mesh.cppHandle.createRealSection("dispTmdt", dimension)
-    self.dispTpdt = mesh.cppHandle.createRealSection("dispTpdt", dimension)
-    self.constant = mesh.cppHandle.createRealSection("constant", dimension)
-    self.jacobian = mesh.cppHandle.createMatrix(self.constant)
+    self.dispT = mesh.createRealSection("dispT", dimension)
+    self.dispTmdt = mesh.createRealSection("dispTmdt", dimension)
+    self.dispTpdt = mesh.createRealSection("dispTpdt", dimension)
+    self.constant = mesh.createRealSection("constant", dimension)
 
+    # Setup constraints
+    # STUFF GOES HERE
+
+    mesh.allocateRealSection(self.dispT)
+    mesh.allocateRealSection(self.dispTmdt)
+    mesh.allocateRealSection(self.dispTpdt)
+    mesh.allocateRealSection(self.constant)
+    
+    self.jacobian = mesh.createMatrix(self.constant)
+
     self._info.log("Integrating Jacobian of operator.")
     for integrator in self.integrators:
       integrator.timeStep(dt)

Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -90,11 +90,17 @@
     self._info.log("Initializing integrators.")
 
     self._info.log("Creating fields and matrices.")
-    self.dispT = mesh.cppHandle.createRealSection("dispT", dimension)
-    self.dispTpdt = mesh.cppHandle.createRealSection("dispTpdt", dimension)
-    self.residual = mesh.cppHandle.createRealSection("residual", dimension)
-    self.jacobian = mesh.cppHandle.createMatrix(self.residual)
+    self.dispT = mesh.createRealSection("dispT", dimension)
+    self.dispTpdt = mesh.createRealSection("dispTpdt", dimension)
+    self.residual = mesh.createRealSection("residual", dimension)
 
+    # Setup constraints
+    # STUFF GOES HERE
+
+    mesh.allocateRealSection(self.dispT)
+    mesh.allocateRealSection(self.dispTpdt)
+    mesh.allocateRealSection(self.residual)
+
     self._info.log("Integrating Jacobian of operator.")
     for integrator in self.integrators:
       integrator.timeStep(dt)

Modified: short/3D/PyLith/trunk/pylith/topology/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -77,6 +77,38 @@
     return comm
 
 
+  def getRealSection(self, label):
+    """
+    Get real section from mesh.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.getRealSection(label)
+
+
+  def createRealSection(self, label, fiberDim):
+    """
+    Create real section (but don't allocate).
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.createRealSection(label, fiberDim)
+
+
+  def allocateRealSection(self, field):
+    """
+    Allocated (and zero) real section.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.allocateRealSection(field)
+
+
+  def createMatrix(self, field):
+    """
+    Create sparse matrix compatible with field.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.createMatrix(field)
+  
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def _configure(self):

Modified: short/3D/PyLith/trunk/unittests/pytests/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/Makefile.am	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/Makefile.am	2007-05-18 16:55:48 UTC (rev 6922)
@@ -11,6 +11,7 @@
 #
 
 SUBDIRS = \
+	bc \
 	faults \
 	feassemble \
 	materials \

Added: short/3D/PyLith/trunk/unittests/pytests/bc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/Makefile.am	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/Makefile.am	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,28 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = bc
+include $(top_srcdir)/subpackage.am
+
+SUBDIRS = data
+
+TESTS = testbc.py
+
+check_SCRIPTS = testbc.py
+
+noinst_PYTHON = \
+	TestDirichlet.py
+
+TESTS_ENVIRONMENT = $(PYTHON)
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,146 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/bc/TestDirichlet.py
+
+## @brief Unit testing of Dirichlet object.
+
+import unittest
+
+from pylith.bc.Dirichlet import Dirichlet
+
+# ----------------------------------------------------------------------
+class TestDirichlet(unittest.TestCase):
+  """
+  Unit testing of Dirichlet object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    from pylith.bc.Dirichlet import Dirichlet
+    bc = Dirichlet()
+
+    self.assertNotEqual(None, bc.cppHandle)
+    return
+
+
+  def test_initialize(self):
+    """
+    Test initialize().
+
+    WARNING: This is not a rigorous test of initialize() because we
+    don't verify the results.
+    """
+
+    self._initialize()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
+  def test_setConstraintSizes(self):
+    """
+    Test setConstraintSizes().
+
+    WARNING: This is not a rigorous test of setConstraintSizes() because we
+    don't verify the results.
+    """
+
+    (mesh, bc) = self._initialize()
+    field = mesh.createRealSection("field", mesh.dimension())
+    bc.setConstraintSizes(field, mesh)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
+  def test_setConstraints(self):
+    """
+    Test setConstraints().
+
+    WARNING: This is not a rigorous test of setConstraints() because we
+    don't verify the results.
+    """
+
+    (mesh, bc) = self._initialize()
+    field = mesh.createRealSection("field", mesh.dimension())
+    bc.setConstraintSizes(field, mesh)
+    mesh.allocateRealSection(field)
+    bc.setConstraints(field, mesh)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
+  def test_setField(self):
+    """
+    Test setField().
+
+    WARNING: This is not a rigorous test of setField() because we
+    don't verify the results.
+    """
+
+    (mesh, bc) = self._initialize()
+    field = mesh.createRealSection("field", mesh.dimension())
+    bc.setConstraintSizes(field, mesh)
+    mesh.allocateRealSection(field)
+    bc.setConstraints(field, mesh)
+    t = 1.0
+    bc.setField(t, field, mesh)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _initialize(self):
+    """
+    Initialize Dirichlet boundary condition.
+    """
+    from pylith.bc.Dirichlet import Dirichlet
+    bc = Dirichlet()
+    bc.id = 0
+    bc.label = "bc"
+    bc.fixedDOF = [1]
+
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    iohandler = SimpleIOAscii()
+    iohandler.filename = "data/tri3.spatialdb"
+    db = SimpleDB()
+    db.label = "TestDirichlet tri3"
+    db.iohandler = iohandler
+    db.initialize()
+    bc.db = db
+
+    from spatialdata.geocoords.CSCart import CSCart
+    cs = CSCart()
+    cs.spaceDim = 2
+
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    importer = MeshIOAscii()
+    importer.filename = "data/tri3.mesh"
+    importer.coordsys = cs
+    mesh = importer.read(debug=False, interpolate=False)
+    
+    bc.initialize(mesh)
+    return (mesh, bc)
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/bc/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/data/Makefile.am	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/data/Makefile.am	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,30 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+noinst_DATA = \
+	tri3.spatialdb \
+	tri3.mesh
+
+noinst_TMP =
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/pytests/bc/data
+export-data: $(noinst_DATA)
+	for f in $(noinst_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done
+
+BUILT_SOURCES = export-data
+
+CLEANFILES = \
+	$(export_datadir)/$(noinst_DATA)
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.mesh	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.mesh	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,42 @@
+mesh = {
+  dimension = 2
+  use-index-zero = true
+  vertices = {
+    dimension = 2
+    count = 4
+    coordinates = {
+             0     -1.0  0.0
+             1      0.0 -1.0
+             2      0.0  1.0
+             3      1.0  0.0
+    }
+  }
+  cells = {
+    count = 2
+    num-corners = 3
+    simplices = {
+             0       0  1  2
+             1       1  3  2
+    }
+    material-ids = {
+             0   0
+             1   0
+    }
+  }
+  group = {
+    name = bc
+    type = vertices
+    count = 2
+    indices = {
+      1  3
+    }
+  }
+  group = {
+    name = bc2
+    type = vertices
+    count = 1
+    indices = {
+      0
+    }
+  }
+}

Added: short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.spatialdb	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/data/tri3.spatialdb	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 1
+  value-names =  dof-1
+  value-units =  m
+  num-locs = 2
+  data-dim = 1
+  space-dim = 2
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 2
+  }
+}
+ 0.0 -1.0  0.3
+ 1.0  0.0  0.7

Added: short/3D/PyLith/trunk/unittests/pytests/bc/testbc.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/testbc.py	2007-05-18 15:58:01 UTC (rev 6921)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/testbc.py	2007-05-18 16:55:48 UTC (rev 6922)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/bc/testbc.py
+
+## @brief Python application for testing bc code.
+
+from pyre.applications.Script import Script
+
+import unittest
+
+class TestApp(Script):
+  """
+  Test application.
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="testapp"):
+    """
+    Constructor.
+    """
+    Script.__init__(self, name)
+    return
+
+
+  def main(self):
+    """
+    Run the application.
+    """
+    from pylith.utils.PetscManager import PetscManager
+    petsc = PetscManager()
+    petsc.initialize()
+
+    unittest.TextTestRunner(verbosity=2).run(self._suite())
+
+    petsc.finalize()
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _suite(self):
+    """
+    Setup the test suite.
+    """
+
+    suite = unittest.TestSuite()
+
+    from TestDirichlet import TestDirichlet
+    suite.addTest(unittest.makeSuite(TestDirichlet))
+
+    return suite
+
+
+# ----------------------------------------------------------------------
+if __name__ == '__main__':
+  app = TestApp()
+  app.run()
+
+
+# End of file 


Property changes on: short/3D/PyLith/trunk/unittests/pytests/bc/testbc.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the cig-commits mailing list