[cig-commits] r6864 - in short/3D/PyLith/trunk: modulesrc/topology pylith pylith/topology unittests/pytests/topology

brad at geodynamics.org brad at geodynamics.org
Fri May 11 22:00:42 PDT 2007


Author: brad
Date: 2007-05-11 22:00:42 -0700 (Fri, 11 May 2007)
New Revision: 6864

Added:
   short/3D/PyLith/trunk/pylith/topology/MeshGenSimple.py
   short/3D/PyLith/trunk/pylith/topology/Partitioner.py
   short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py
Removed:
   short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py
Modified:
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/topology/Mesh.py
   short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
   short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
   short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py
   short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
Log:
Cleaned up implementation of simple mesh generation and unit test for distribute- created MeshGenSimple object for generating simple meshes; renamed MeshDistributor as Partitioner; removed junk from MeshGenerator. Simple mesh generator requires TetGen.

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-05-12 05:00:42 UTC (rev 6864)
@@ -64,95 +64,6 @@
   return
 
 # ----------------------------------------------------------------------
-cdef class MeshGenerator:
-
-  def createCubeBoundary(self, debug = 0):
-    """
-    Returns a Mesh that is the boundary of the unit cube
-    """
-    # create shim for method 'read'
-    #embed{ void MeshGenerator_createCubeBoundary(int debug, void* meshVptr)
-    try {
-      assert(0 != meshVptr);
-      ALE::Obj<ALE::Mesh>* pMesh   = (ALE::Obj<ALE::Mesh>*) meshVptr;
-      const double lower[3] = {0.0, 0.0, 0.0};
-      const double upper[3] = {1.0, 1.0, 1.0};
-      const int    faces[3] = {1, 1, 1};
-      *pMesh = ALE::MeshBuilder::createCubeBoundary(PETSC_COMM_WORLD, lower, upper, faces, debug);
-    } catch (const std::exception& err) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      const_cast<char*>(err.what()));
-    } catch (...) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      "Caught unknown C++ exception.");
-    } // try/catch
-    #}embed
-    mesh = Mesh()
-    MeshGenerator_createCubeBoundary(debug, ptrFromHandle(mesh))
-    return mesh
-
-  def generateMesh(self, meshBd):
-    """
-    Generate a Mesh from a boundary
-    """
-    # create shim for method 'read'
-    #embed{ void MeshGenerator_generateMesh(void* meshBdVptr, void* meshVptr)
-    try {
-      assert(0 != meshBdVptr);
-      assert(0 != meshVptr);
-      ALE::Obj<ALE::Mesh>* pMeshBd = (ALE::Obj<ALE::Mesh>*) meshBdVptr;
-      ALE::Obj<ALE::Mesh>* pMesh   = (ALE::Obj<ALE::Mesh>*) meshVptr;
-      *pMesh = ALE::Generator::generateMesh(*pMeshBd);
-    } catch (const std::exception& err) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      const_cast<char*>(err.what()));
-    } catch (...) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      "Caught unknown C++ exception.");
-    } // try/catch
-    #}embed
-    if meshBd.name != "pylith_topology_Mesh":
-      raise TypeError, \
-            "Argument must be extension module type 'Mesh'."
-    mesh = Mesh()
-    MeshGenerator_generateMesh(ptrFromHandle(meshBd), ptrFromHandle(mesh))
-    return mesh
-
-# ----------------------------------------------------------------------
-cdef class MeshDistributor:
-
-  def distributeMesh(self, mesh, partitioner = None):
-    """
-    Distribute a Mesh
-    """
-    # create shim for method 'read'
-    #embed{ void MeshDistributor_distributeMesh(void* meshVptr, char *partitioner, void* newMeshVptr)
-    try {
-      assert(0 != meshVptr);
-      assert(0 != newMeshVptr);
-      ALE::Obj<ALE::Mesh>* pMesh    = (ALE::Obj<ALE::Mesh>*) meshVptr;
-      ALE::Obj<ALE::Mesh>* pNewMesh = (ALE::Obj<ALE::Mesh>*) newMeshVptr;
-      if (!strlen(partitioner)) {
-        *pNewMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*pMesh);
-      } else {
-        *pNewMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*pMesh, 0, partitioner);
-      }
-    } catch (const std::exception& err) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      const_cast<char*>(err.what()));
-    } catch (...) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      "Caught unknown C++ exception.");
-    } // try/catch
-    #}embed
-    if mesh.name != "pylith_topology_Mesh":
-      raise TypeError, \
-            "Argument must be extension module type 'Mesh'."
-    newMesh = Mesh()
-    MeshDistributor_distributeMesh(ptrFromHandle(mesh), partitioner, ptrFromHandle(newMesh))
-    return newMesh
-
-# ----------------------------------------------------------------------
 cdef class Mesh:
 
   cdef void* thisptr # Pointer to C++ object
@@ -173,6 +84,9 @@
     } 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.");
@@ -206,6 +120,9 @@
     } 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.");
@@ -240,6 +157,9 @@
     } 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.");
@@ -279,6 +199,9 @@
     } 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.");
@@ -291,40 +214,7 @@
     ptr = Mesh_createMatrix(self.thisptr, fieldVptr)
     return PyCObject_FromVoidPtr(ptr, PetscMat_destructor)
 
-  def distribute(self, newMesh, height=0, partitioner=None):
-    """
-    Distribute the mesh across processes.
-    """
-    # create shim for MeshDistribute
-    #embed{ void Mesh_distribute(void* objVptr, void* newVptr, int height, char *partitioner)
-    try {
-      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) objVptr;
-      ALE::Obj<ALE::Mesh>* newMesh = (ALE::Obj<ALE::Mesh>*) newVptr;
-      assert(0 != mesh);
-      assert(0 != newMesh);
-      assert(!mesh->isNull());
-      assert(height >= 0);
 
-      if (0 == partitioner) {
-        *newMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh);
-      } else {
-        *newMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh, 0, partitioner);
-      } // if/else
-    } catch (const std::exception& err) {
-    PyErr_SetString(PyExc_RuntimeError,
-                    const_cast<char*>(err.what()));
-    } catch (...) {
-    PyErr_SetString(PyExc_RuntimeError,
-                    "Caught unknown C++ exception.");
-    } // try/catch
-    #}embed
-    if newMesh.name != "pylith_topology_Mesh":
-      raise TypeError, \
-            "Argument must be extension module type 'Mesh'."
-    Mesh_distribute(self.thisptr, ptrFromHandle(newMesh), height, partitioner)
-    return
-    
-
   def _createHandle(self):
     """
     Wrap pointer to C++ object in PyCObject.
@@ -349,6 +239,9 @@
       } 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.");
@@ -371,6 +264,9 @@
       } 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.");
@@ -396,6 +292,9 @@
       } 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.");
@@ -405,6 +304,110 @@
       return Mesh_dimension_get(self.thisptr)
 
       
+# ----------------------------------------------------------------------
+cdef class MeshGenSimple:
+
+  def createCubeBoundary(self, debug = 0):
+    """
+    Returns a Mesh that is the boundary of the unit cube
+    """
+    # create shim for method 'read'
+    #embed{ void MeshGenerator_createCubeBoundary(int debug, void* meshVptr)
+    try {
+      assert(0 != meshVptr);
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      const double lower[3] = {0.0, 0.0, 0.0};
+      const double upper[3] = {1.0, 1.0, 1.0};
+      const int    faces[3] = {1, 1, 1};
+      *mesh = ALE::MeshBuilder::createCubeBoundary(PETSC_COMM_WORLD, lower, upper, faces, debug);
+    } 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
+    mesh = Mesh()
+    MeshGenerator_createCubeBoundary(debug, ptrFromHandle(mesh))
+    return mesh
+
+
+  def generate(self, meshBdry):
+    """
+    Generate a mesh from a boundary mesh.
+    """
+    # create shim for method 'read'
+    #embed{ void MeshGenerator_generate(void* meshVptr, void* meshBdryVptr)
+    try {
+      assert(0 != meshVptr);
+      assert(0 != meshBdryVptr);
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ALE::Obj<ALE::Mesh>* meshBdry = (ALE::Obj<ALE::Mesh>*) meshBdryVptr;
+      *mesh = ALE::Generator::generateMesh(*meshBdry);
+    } 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
+    if meshBdry.name != "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type 'Mesh'."
+    mesh = Mesh()
+    MeshGenerator_generate(ptrFromHandle(mesh), ptrFromHandle(meshBdry))
+    return mesh
+
+
+# ----------------------------------------------------------------------
+cdef class Partitioner:
+
+  def distribute(self, mesh, partitioner):
+    """
+    Distribute a mesh.
+    """
+    # create shim for method 'distribute'
+    #embed{ void Partitioner_distribute(void* newMeshVptr, void* meshVptr, char *partitioner)
+    try {
+      assert(0 != meshVptr);
+      assert(0 != newMeshVptr);
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ALE::Obj<ALE::Mesh>* newMesh = (ALE::Obj<ALE::Mesh>*) newMeshVptr;
+      if (strlen(partitioner) > 0) {
+        *newMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh);
+      } else {
+        *newMesh =
+          ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh, 0, partitioner);
+      }
+    } 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
+    if mesh.name != "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument must be extension module type 'Mesh'."
+    newMesh = Mesh()
+    Partitioner_distribute(ptrFromHandle(newMesh), ptrFromHandle(mesh),
+                           partitioner)
+    return newMesh
+
+
+# ----------------------------------------------------------------------
 def zeroRealSection(section):
   """
   Zero real section.
@@ -421,6 +424,9 @@
   } 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.");

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2007-05-12 05:00:42 UTC (rev 6864)
@@ -71,8 +71,9 @@
 	solver/SolverLinear.py \
 	topology/__init__.py \
 	topology/Mesh.py \
-	topology/MeshDistributor.py \
+	topology/Partitioner.py \
 	topology/MeshGenerator.py \
+	topology/MeshGenSimple.py \
 	topology/MeshImporter.py \
 	utils/__init__.py \
 	utils/CheckpointTimer.py \

Modified: short/3D/PyLith/trunk/pylith/topology/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -64,16 +64,7 @@
       dim = self.cppHandle.dimension
     return dim
 
-  def distribute(self, partitioner=None):
-    """
-    Distribute mesh across processors.
-    """
-    self._info.log("WARNING: Mesh::distribute() not tested.")
-    mesh = Mesh()
-    self.cppHandle.distribute(mesh.cppHandle, partitioner=partitioner)
-    return mesh
 
-
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def _configure(self):

Deleted: short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -1,106 +0,0 @@
-#!/usr/bin/env python
-#
-# ----------------------------------------------------------------------
-#
-#                           Brad T. Aagaard
-#                        U.S. Geological Survey
-#
-# <LicenseText>
-#
-# ----------------------------------------------------------------------
-#
-
-## @file pylith/topology/MeshDistributor.py
-##
-## @brief Python abstract base class for mesh distributor.
-##
-## Factory: mesh_distributor.
-
-from pyre.components.Component import Component
-
-# MeshDistributor class
-class MeshDistributor(Component):
-  """
-  Python abstract base class for mesh distributor.
-
-  Factory: mesh_distributor
-  """
-
-  # INVENTORY //////////////////////////////////////////////////////////
-
-  class Inventory(Component.Inventory):
-    """
-    Python object for managing MeshDistributor facilities and properties.
-    """
-
-    ## @class Inventory
-    ## Python object for managing MeshDistributor facilities and properties.
-    ##
-    ## \b Properties
-    ## @li \b debug Debugging flag for mesh.
-    ## @li \b interpolate Build intermediate mesh topology elements (if true)
-    ## @li \b partitioner Name of mesh partitioner {"parmetis", "chaco"}
-    ##
-    ## \b Facilities
-    ## @li None
-
-    import pyre.inventory
-
-    debug = pyre.inventory.bool("debug", default=False)
-    debug.meta['tip'] = "Debugging flag for mesh."
-
-    interpolate = pyre.inventory.bool("interpolate", default=False)
-    interpolate.meta['tip'] = "Build intermediate mesh topology elements"
-
-    partitioner = pyre.inventory.str("partitioner", default="chaco",
-                                      validator=pyre.inventory.choice(["chaco",
-                                                                       "parmetis"]))
-    partitioner.meta['tip'] = "Name of mesh partitioner."
-
-
-  # PUBLIC METHODS /////////////////////////////////////////////////////
-
-  def __init__(self, name="meshdistributor"):
-    """
-    Constructor.
-    """
-    Component.__init__(self, name, facility="mesh_distributor")
-    import pylith.topology.topology as bindings
-    self.cppHandle = bindings.MeshDistributor()
-    self.debug = False
-    self.interpolate = False
-    self.partitioner = ''
-    return
-
-
-  def distributeMesh(self, mesh):
-    """
-    Distribute a Mesh
-    """
-    return self.cppHandle.distributeMesh(mesh, self.partitioner)
-
-
-  # PRIVATE METHODS ////////////////////////////////////////////////////
-
-  def _configure(self):
-    """
-    Set members based using inventory.
-    """
-    Component._configure(self)
-    self.debug = self.inventory.debug
-    self.interpolate = self.inventory.interpolate
-    self.partitioner = self.inventory.partitioner
-    return
-
-
-  def _adjustTopology(self, mesh, faults):
-    """
-    Adjust topology for fault implementation.
-    """
-    if not faults is None:
-      for fault in faults:
-        mesh.adjustTopology(fault)
-    return
-  
-
-# End of file 

Added: short/3D/PyLith/trunk/pylith/topology/MeshGenSimple.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshGenSimple.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/topology/MeshGenSimple.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/topology/MeshGenSimple.py
+##
+## @brief Python manager for simple mesh generator.
+##
+## Factory: mesh_generator.
+
+from MeshGenerator import MeshGenerator
+
+# MeshGenSimple class
+class MeshGenSimple(MeshGenerator):
+  """
+  Python manager for simple mesh generator.
+
+  Factory: mesh_generator
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="meshgensimple"):
+    """
+    Constructor.
+    """
+    MeshGenerator.__init__(self, name)
+    import pylith.topology.topology as bindings
+    self.cppHandle = bindings.MeshGenSimple()
+    return
+
+
+  def create(self, faults=None):
+    """
+    Generate a Mesh from a boundary
+    """
+    return self.cppHandle.generate(self.boundary)
+
+
+  def setBoundary(self, boundary):
+    """
+    Set boundary for domain to mesh.
+    """
+    self.boundary = boundary
+    return
+  
+
+  def createCubeBoundary(self):
+    """
+    Returns a Mesh that is the boundary of the unit cube
+    """
+    return self.cppHandle.createCubeBoundary(self.debug)
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    MeshGenerator._configure(self)
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -59,27 +59,19 @@
     Constructor.
     """
     Component.__init__(self, name, facility="mesh_generator")
-    import pylith.topology.topology as bindings
-    self.cppHandle = bindings.MeshGenerator()
     self.debug = False
     self.interpolate = False
     return
 
 
-  def create(self, boundary, faults = None):
+  def create(self, faults=None):
     """
     Generate a Mesh from a boundary
     """
-    return self.cppHandle.generateMesh(boundary)
+    raise NotImplementedError("MeshGenerator.create() not implemented.")
+    return
 
 
-  def createCubeBoundary(self):
-    """
-    Returns a Mesh that is the boundary of the unit cube
-    """
-    return self.cppHandle.createCubeBoundary(self.debug)
-
-
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):

Modified: short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -40,13 +40,21 @@
     ## @li None
     ##
     ## \b Facilities
-    ## @li \b importer Mesh importer
+    ## @li \b importer Mesh importer.
+    ## @li \b partitioner Mesh partitioner.
 
     import pyre.inventory
 
     from pylith.meshio.MeshIOAscii import MeshIOAscii
-    importer = pyre.inventory.facility("importer", factory=MeshIOAscii)
+    importer = pyre.inventory.facility("importer", family="mesh_io",
+                                       factory=MeshIOAscii)
     importer.meta['tip'] = "Mesh importer."
+
+    from Partitioner import Partitioner
+    partitioner = pyre.inventory.facility("partitioner",
+                                          family="mesh_partitioner",
+                                          factory=Partitioner)
+    partitioner.meta['tip'] = "Mesh partitioner."
   
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
@@ -59,23 +67,16 @@
     return
 
 
-  def create(self, faults):
+  def create(self, faults=None):
     """
     Hook for creating mesh.
     """
     mesh = self.importer.read(self.debug, self.interpolate)
     self._adjustTopology(mesh, faults)
-    mesh.distribute(self.partitioner)
+    mesh = self.partitioner.distribute(mesh)
     return mesh
 
 
-  def createCubeBoundary(self):
-    """
-    Hook for creating cube boundary.
-    """
-    return self.importer.createCubeBoundary(self.debug)
-
-
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):
@@ -84,6 +85,7 @@
     """
     MeshGenerator._configure(self)
     self.importer = self.inventory.importer
+    self.partitioner = self.inventory.partitioner
     return
   
 

Copied: short/3D/PyLith/trunk/pylith/topology/Partitioner.py (from rev 6862, short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py)
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshDistributor.py	2007-05-12 01:37:42 UTC (rev 6862)
+++ short/3D/PyLith/trunk/pylith/topology/Partitioner.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/topology/Partitioner.py
+##
+## @brief Python manager for mesh partitioner.
+##
+## Factory: mesh_partitioner.
+
+from pyre.components.Component import Component
+
+# Partitioner class
+class Partitioner(Component):
+  """
+  Python manager for mesh partitioner.
+
+  Factory: mesh_partitioner
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(Component.Inventory):
+    """
+    Python object for managing Partitioner facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing Partitioner facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b partitioner Name of mesh partitioner {"parmetis", "chaco"}
+    ##
+    ## \b Facilities
+    ## @li None
+
+    import pyre.inventory
+
+    partitioner = pyre.inventory.str("partitioner", default="chaco",
+                                     validator=pyre.inventory.choice(["chaco",
+                                                                      "parmetis"]))
+    partitioner.meta['tip'] = "Name of mesh partitioner."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="partitioner"):
+    """
+    Constructor.
+    """
+    Component.__init__(self, name, facility="partitioner")
+    import pylith.topology.topology as bindings
+    self.cppHandle = bindings.Partitioner()
+    return
+
+
+  def distribute(self, mesh):
+    """
+    Distribute a Mesh
+    """
+    return self.cppHandle.distribute(mesh, self.partitioner)
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    Component._configure(self)
+    self.partitioner = self.inventory.partitioner
+    return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def mesh_partitioner():
+  """
+  Factory associated with Partitioner.
+  """
+  return Partitioner()
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenSimple.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/topology/TestMeshGenSimple.py
+
+## @brief Unit testing of MeshGenSimple object.
+
+import unittest
+
+from pylith.topology.MeshGenSimple import MeshGenSimple
+
+# ----------------------------------------------------------------------
+class TestMeshGenSimple(unittest.TestCase):
+  """
+  Unit testing of MeshGenSimple object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    generator = MeshGenSimple()
+    return
+  
+
+  def test_distribute(self):
+    """
+    Test distribute()
+    """
+    generator = MeshGenSimple()
+    generator.interpolate = True
+    generator.setBoundary(generator.createCubeBoundary())
+    mesh = generator.create()
+    
+    #from pylith.meshio.SolutionIOVTK import SolutionIOVTK
+    #io = SolutionIOVTK()
+    #io.filename = 'mesh.vtk'
+    #import spatialdata.geocoords.CSCart
+    #io.coordsys = spatialdata.geocoords.CSCart.CSCart()
+    #io.open(mesh)
+    #io.writeTopology(mesh)
+    #io.close()
+
+    #from pylith.topology.Partitioner import Partitioner
+    #partitioner = Partitioner()
+    #newMesh = partitioner.distribute(mesh)
+    #io.filename = 'newMesh.vtk'
+    #io.open(newMesh)
+    #io.writeTopology(newMesh)
+    #io.close()
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/TestMeshGenerator.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -17,13 +17,11 @@
 import unittest
 
 from pylith.topology.MeshGenerator import MeshGenerator
-from pylith.topology.MeshDistributor import MeshDistributor
-from pylith.meshio.SolutionIOVTK import SolutionIOVTK
 
 # ----------------------------------------------------------------------
 class TestMeshGenerator(unittest.TestCase):
   """
-  Unit testing of MeshIO object.
+  Unit testing of MeshGenerator object.
   """
 
   def test_constructor(self):
@@ -64,28 +62,4 @@
     return
 
 
-  def test_distribution(self):
-    """
-    Test mesh distribution
-    """
-    io = SolutionIOVTK()
-    generator = MeshGenerator()
-    generator.interpolate = True
-    mesh = generator.create(generator.createCubeBoundary())
-    io.filename = 'mesh.vtk'
-    #import spatialdata.geocoords.CSCart
-    #io.coordsys = spatialdata.geocoords.CSCart.CSCart()
-    io.open(mesh)
-    io.writeTopology(mesh)
-    io.close()
-    distributor = MeshDistributor()
-    newMesh = distributor.distributeMesh(mesh)
-    io.filename = 'newMesh.vtk'
-    io.open(newMesh)
-    io.writeTopology(newMesh)
-    io.close()
-    self.assertEqual(True, generator.interpolate)
-    return
-
-
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py	2007-05-12 04:18:27 UTC (rev 6863)
+++ short/3D/PyLith/trunk/unittests/pytests/topology/testdriver.py	2007-05-12 05:00:42 UTC (rev 6864)
@@ -64,6 +64,9 @@
     from TestMeshImporter import TestMeshImporter
     suite.addTest(unittest.makeSuite(TestMeshImporter))
 
+    from TestMeshGenSimple import TestMeshGenSimple
+    suite.addTest(unittest.makeSuite(TestMeshGenSimple))
+
     return suite
 
 



More information about the cig-commits mailing list