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

brad at geodynamics.org brad at geodynamics.org
Sun Apr 22 16:51:20 PDT 2007


Author: brad
Date: 2007-04-22 16:51:20 -0700 (Sun, 22 Apr 2007)
New Revision: 6629

Modified:
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/PyLithApp.py
   short/3D/PyLith/trunk/pylith/topology/Mesh.py
   short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
   short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
Log:
Finished implementing distribute(). Runs but needs unit test.

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-04-22 03:25:16 UTC (rev 6628)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-04-22 23:51:20 UTC (rev 6629)
@@ -201,39 +201,38 @@
     ptr = Mesh_createMatrix(self.thisptr, fieldVptr)
     return PyCObject_FromVoidPtr(ptr, PetscMat_destructor)
 
-  def distribute(self, height = 0, partitioner = None):
+  def distribute(self, newMesh, height=0, partitioner=None):
     """
     Distribute the mesh across processes.
     """
     # create shim for MeshDistribute
-    #embed{ void* Mesh_distribute(void* objVptr, int height, char *partitioner)
-    void* result = 0;
+    #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 = new ALE::Obj<ALE::Mesh>;
+      ALE::Obj<ALE::Mesh>* newMesh = (ALE::Obj<ALE::Mesh>*) newVptr;
       assert(0 != mesh);
       assert(0 != newMesh);
       assert(!mesh->isNull());
       assert(height >= 0);
 
-      if (partitioner == NULL) {
-        (*newMesh) = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh);
+      if (0 == partitioner) {
+        *newMesh = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh);
       } else {
-        (*newMesh) = ALE::Distribution<ALE::Mesh>::distributeMesh(*mesh, 0, partitioner);
-      }
-      result = (void*) newMesh;
+        *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()));
+    PyErr_SetString(PyExc_RuntimeError,
+                    const_cast<char*>(err.what()));
     } catch (...) {
-      PyErr_SetString(PyExc_RuntimeError,
-                      "Caught unknown C++ exception.");
+    PyErr_SetString(PyExc_RuntimeError,
+                    "Caught unknown C++ exception.");
     } // try/catch
-    return result;
     #}embed
-    cdef void* ptr
-    ptr = Mesh_distribute(self.thisptr, height, partitioner)
-    return PyCObject_FromVoidPtr(ptr, MeshPtr_destructor)
+    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):

Modified: short/3D/PyLith/trunk/pylith/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-04-22 03:25:16 UTC (rev 6628)
+++ short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-04-22 23:51:20 UTC (rev 6629)
@@ -88,7 +88,7 @@
     mesh = self.mesher.create(faults)
 
     # Initialize problem and then run
-    self.problem.initialize(mesh.distribute())
+    self.problem.initialize(mesh)
     self.problem.run(self)
     
     self.petsc.finalize()

Modified: short/3D/PyLith/trunk/pylith/topology/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-04-22 03:25:16 UTC (rev 6628)
+++ short/3D/PyLith/trunk/pylith/topology/Mesh.py	2007-04-22 23:51:20 UTC (rev 6629)
@@ -64,13 +64,14 @@
       dim = self.cppHandle.dimension
     return dim
 
-  def distribute(self):
+  def distribute(self, partitioner=None):
     """
     Distribute mesh across processors.
     """
     self._info.log("WARNING: Mesh::distribute() not tested.")
-    self.cppHandle.distribute()
-    return self
+    mesh = Mesh()
+    self.cppHandle.distribute(mesh.cppHandle, partitioner=partitioner)
+    return mesh
 
 
   # PUBLIC METHODS /////////////////////////////////////////////////////

Modified: short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2007-04-22 03:25:16 UTC (rev 6628)
+++ short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2007-04-22 23:51:20 UTC (rev 6629)
@@ -39,6 +39,7 @@
     ## \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
@@ -51,7 +52,12 @@
     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="meshgenerator"):
@@ -81,6 +87,7 @@
     Component._configure(self)
     self.debug = self.inventory.debug
     self.interpolate = self.inventory.interpolate
+    self.partitioner = self.inventory.partitioner
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-04-22 03:25:16 UTC (rev 6628)
+++ short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2007-04-22 23:51:20 UTC (rev 6629)
@@ -65,6 +65,7 @@
     """
     mesh = self.importer.read(self.debug, self.interpolate)
     self._adjustTopology(mesh, faults)
+    mesh.distribute(self.partitioner)
     return mesh
 
 



More information about the cig-commits mailing list