[cig-commits] r8093 - in short/3D/PyLith/trunk: libsrc libsrc/topology modulesrc/topology pylith/topology tests tests/distribute

brad at geodynamics.org brad at geodynamics.org
Sun Oct 7 20:57:00 PDT 2007


Author: brad
Date: 2007-10-07 20:56:59 -0700 (Sun, 07 Oct 2007)
New Revision: 8093

Added:
   short/3D/PyLith/trunk/tests/distribute/
   short/3D/PyLith/trunk/tests/distribute/MesherApp.py
   short/3D/PyLith/trunk/tests/distribute/README
   short/3D/PyLith/trunk/tests/distribute/testdistribute.py
   short/3D/PyLith/trunk/tests/distribute/tri3a.mesh
Modified:
   short/3D/PyLith/trunk/libsrc/Makefile.am
   short/3D/PyLith/trunk/libsrc/topology/Makefile.am
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/topology/Distributor.py
Log:
Added C++ Distributor object. Added Distributor::write() to write partitioning info. Added distribution test in tests/distribution.

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2007-10-08 03:56:59 UTC (rev 8093)
@@ -80,7 +80,8 @@
 	meshio/PsetFileBinary.cc \
 	meshio/SolutionIO.cc \
 	meshio/SolutionIOVTK.cc \
-	topology/FieldsManager.cc
+	topology/FieldsManager.cc \
+	topology/Distributor.cc
 
 libpylith_la_LDFLAGS = $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
 libpylith_la_LIBADD = \

Modified: short/3D/PyLith/trunk/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2007-10-08 03:56:59 UTC (rev 8093)
@@ -14,7 +14,8 @@
 include $(top_srcdir)/subpackage.am
 
 subpkginclude_HEADERS = \
-	FieldsManager.hh
+	FieldsManager.hh \
+	Distributor.hh
 
 noinst_HEADERS =
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-10-08 03:56:59 UTC (rev 8093)
@@ -12,6 +12,7 @@
 
 #header{
 #include "pylith/topology/FieldsManager.hh"
+#include "pylith/topology/Distributor.hh"
 #include "pylith/utils/sievetypes.hh"
 #include "pylith/utils/petscfwd.h"
 #include <petscmesh.hh>
@@ -482,10 +483,7 @@
       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);
+      pylith::topology::Distributor::distribute(newMesh, *mesh, partitioner);
     } catch (const std::exception& err) {
       PyErr_SetString(PyExc_RuntimeError,
                       const_cast<char*>(err.what()));
@@ -506,6 +504,40 @@
     return newMesh
 
 
+  def write(self, mesh, writer):
+    """
+    Write partitioning information to file..
+    """
+    # create shim for method 'write'
+    #embed{ void Distributor_write(void* meshVptr, void* writerVptr)
+    try {
+      assert(0 != meshVptr);
+      assert(0 != writerVptr);
+      ALE::Obj<ALE::Mesh>* mesh = (ALE::Obj<ALE::Mesh>*) meshVptr;
+      pylith::meshio::SolutionIO* writer =
+        (pylith::meshio::SolutionIO*) writerVptr;
+      pylith::topology::Distributor::write(*mesh, writer);
+    } 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 'mesh' must be extension module type 'Mesh'."
+    if writer.name != "pylith_meshio_SolutionIO":
+      raise TypeError, \
+            "Argument 'writer' must be extension module type 'SolutionIO'."
+    Distributor_write(ptrFromHandle(mesh), ptrFromHandle(writer))
+    return
+
+
 # ----------------------------------------------------------------------
 cdef class FieldsManager:
 

Modified: short/3D/PyLith/trunk/pylith/topology/Distributor.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Distributor.py	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/pylith/topology/Distributor.py	2007-10-08 03:56:59 UTC (rev 8093)
@@ -37,10 +37,11 @@
     ## Python object for managing Distributor facilities and properties.
     ##
     ## \b Properties
-    ## @li \b partitioner Name of mesh partitioner {"parmetis", "chaco"}
+    ## @li \b partitioner Name of mesh partitioner {"parmetis", "chaco"}.
+    ## @li \b debug Write partition information to file.
     ##
     ## \b Facilities
-    ## @li None
+    ## @li \b writer Writer for partition information
 
     import pyre.inventory
 
@@ -49,7 +50,14 @@
                                                                       "parmetis"]))
     partitioner.meta['tip'] = "Name of mesh partitioner."
 
+    debug = pyre.inventory.bool("debug", default=False)
+    debug.meta['tip'] = "Write partition information to file."
 
+    from pylith.meshio.SolutionIOVTK import SolutionIOVTK
+    writer = pyre.inventory.facility("writer", factory=SolutionIOVTK,
+                                     family="solution_io")
+    writer.meta['tip'] = "Writer for partition information."
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="partitioner"):
@@ -72,6 +80,11 @@
     newMesh.cppHandle = self.cppHandle.distribute(mesh.cppHandle,
                                                   self.partitioner)
     newMesh.coordsys = mesh.coordsys
+
+    if self.debug:
+      self.writer.open(newMesh)
+      self.cppHandle.write(newMesh.cppHandle, self.writer.cppHandle)
+      self.writer.close()
     return newMesh
 
 
@@ -83,6 +96,8 @@
     """
     Component._configure(self)
     self.partitioner = self.inventory.partitioner
+    self.debug = self.inventory.debug
+    self.writer = self.inventory.writer
     return
 
 

Added: short/3D/PyLith/trunk/tests/distribute/MesherApp.py
===================================================================
--- short/3D/PyLith/trunk/tests/distribute/MesherApp.py	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/tests/distribute/MesherApp.py	2007-10-08 03:56:59 UTC (rev 8093)
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+from mpi import Application
+
+# MesherApp class
+class MesherApp(Application):
+  """
+  Python MesherApp application.
+  """
+  
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(Application.Inventory):
+    """
+    Python object for managing MesherApp facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing MesherApp facilities and properties.
+    ##
+    ## \b Properties
+    ## @li None
+    ##
+    ## \b Facilities
+    ## @li \b mesher Generates or imports the computational mesh.
+    ## @li \b petsc Manager for PETSc options
+
+    import pyre.inventory
+
+    from pylith.topology.MeshImporter import MeshImporter
+    mesher = pyre.inventory.facility("mesh_generator", family="mesh_generator",
+                                     factory=MeshImporter)
+    mesher.meta['tip'] = "Generates or imports the computational mesh."
+
+    # Dummy facility for passing options to PETSc
+    from pylith.utils.PetscManager import PetscManager
+    petsc = pyre.inventory.facility("petsc", family="petsc_manager",
+                                    factory=PetscManager)
+    petsc.meta['tip'] = "Manager for PETSc options."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="mesherapp"):
+    """
+    Constructor.
+    """
+    Application.__init__(self, name)
+    return
+
+
+  def main(self, *args, **kwds):
+    """
+    Run the application.
+    """
+    from pylith.utils.profiling import resourceUsageString
+    
+    self.petsc.initialize()
+    self._debug.log(resourceUsageString())
+
+    # Create mesh (adjust to account for interfaces (faults) if necessary)
+    interfaces = None
+    mesh = self.mesher.create(interfaces)
+    self._debug.log(resourceUsageString())
+
+    self.petsc.finalize()
+    return
+  
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Setup members using inventory.
+    """
+    Application._configure(self)
+    self.mesher = self.inventory.mesher
+    self.petsc = self.inventory.petsc
+
+    import journal
+    self._debug = journal.debug(self.name)
+    return
+  
+
+# End of file 

Added: short/3D/PyLith/trunk/tests/distribute/README
===================================================================
--- short/3D/PyLith/trunk/tests/distribute/README	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/tests/distribute/README	2007-10-08 03:56:59 UTC (rev 8093)
@@ -0,0 +1 @@
+tdistribute.py --mesh_generator.importer.filename=tri3a.mesh --mesh_generator.debug=1 --mesh_generator.distributor.debug=1 --mesh_generator.distributor.partitioner=parmetis --nodes=2

Added: short/3D/PyLith/trunk/tests/distribute/testdistribute.py
===================================================================
--- short/3D/PyLith/trunk/tests/distribute/testdistribute.py	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/tests/distribute/testdistribute.py	2007-10-08 03:56:59 UTC (rev 8093)
@@ -0,0 +1,22 @@
+#!/usr/bin/env nemesis
+# -*- Python -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+__requires__ = "PyLith"
+
+if __name__ == "__main__":
+
+    from MesherApp import MesherApp
+    from pyre.applications import start
+    start(applicationClass=MesherApp)
+
+# End of file 


Property changes on: short/3D/PyLith/trunk/tests/distribute/testdistribute.py
___________________________________________________________________
Name: svn:executable
   + *

Added: short/3D/PyLith/trunk/tests/distribute/tri3a.mesh
===================================================================
--- short/3D/PyLith/trunk/tests/distribute/tri3a.mesh	2007-10-05 20:02:02 UTC (rev 8092)
+++ short/3D/PyLith/trunk/tests/distribute/tri3a.mesh	2007-10-08 03:56:59 UTC (rev 8093)
@@ -0,0 +1,67 @@
+//
+//  6 ----- 7 ----- 8
+//  | 0   / | \  2  |
+//  |   /   |   \   |
+//  | / 4   |  6  \ |
+//  3 ----- 4 ----- 5
+//  | \ 7   |  5  / |
+//  |   \   |   /   |
+//  | 3   \ | /  1  |
+//  0 ----- 1 ----- 2
+//
+mesh = {
+  dimension = 2
+  vertices = {
+    dimension = 2
+    count = 9
+    coordinates = {
+      0  -1.0  -1.0
+      1   0.0  -1.0
+      2   1.0  -1.0
+      3  -1.0   0.0
+      4   0.0   0.0
+      5   1.0   0.0
+      6  -1.0   1.0
+      7   0.0   1.0
+      8   1.0   1.0
+    } // coordinates
+  } // vertices
+  
+  cells = {
+    num-corners = 3
+    count = 8
+    simplices = {
+      0    3  7  6
+      1    1  2  5
+      2    5  8  7
+      3    0  1  3
+      4    3  4  7
+      5    1  5  4
+      6    4  5  7
+      7    1  4  3
+    } // cells
+
+    material-ids = {
+      0   1
+      1   1
+      2   1
+      3   1
+      4   1
+      5   1
+      6   1
+      7   1
+    } // material-ids
+  } // cells
+
+  group = {
+    type = vertices
+    name = fault
+    count = 3
+    indices = {
+      1
+      4
+      7
+    } // indices
+  } // group
+
+} // mesh



More information about the cig-commits mailing list