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

brad at geodynamics.org brad at geodynamics.org
Tue Sep 16 16:36:24 PDT 2008


Author: brad
Date: 2008-09-16 16:36:23 -0700 (Tue, 16 Sep 2008)
New Revision: 12894

Added:
   short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc
   short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.hh
   short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc
   short/3D/PyLith/trunk/libsrc/topology/RefineUniform.hh
   short/3D/PyLith/trunk/pylith/topology/MeshRefiner.py
   short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
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/Makefile.am
   short/3D/PyLith/trunk/pylith/topology/Distributor.py
   short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
   short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
   short/3D/PyLith/trunk/pylith/topology/__init__.py
Log:
Setup steps for uniform global refinement. Default is no refinement.

Modified: short/3D/PyLith/trunk/libsrc/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/Makefile.am	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/libsrc/Makefile.am	2008-09-16 23:36:23 UTC (rev 12894)
@@ -94,6 +94,8 @@
 	topology/FieldsManager.cc \
 	topology/Distributor.cc \
 	topology/MeshOps.cc \
+	topology/MeshRefiner.cc \
+	topology/RefineUniform.cc \
 	utils/EventLogger.cc
 
 libpylith_la_LDFLAGS = $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)

Modified: short/3D/PyLith/trunk/libsrc/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/libsrc/topology/Makefile.am	2008-09-16 23:36:23 UTC (rev 12894)
@@ -16,7 +16,9 @@
 subpkginclude_HEADERS = \
 	Distributor.hh \
 	FieldsManager.hh \
-	MeshOps.hh
+	MeshOps.hh \
+	MeshRefiner.hh \
+	RefineUniform.hh
 
 noinst_HEADERS =
 

Added: short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,56 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "MeshRefiner.hh" // implementation of class methods
+
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
+#include "pylith/meshio/DataWriter.hh" // USES DataWriter
+
+#include <string.h> // USES strlen()
+#include <strings.h> // USES strcasecmp()
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+#include <assert.h> // USES assert()
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::topology::MeshRefiner::MeshRefiner(void)
+{ // constructor
+} // constructor
+ 
+// ----------------------------------------------------------------------
+// Destructor
+pylith::topology::MeshRefiner::~MeshRefiner(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Write refined mesh.
+void
+pylith::topology::MeshRefiner::write(meshio::DataWriter* const writer,
+				     const ALE::Obj<Mesh>& mesh,
+				     const spatialdata::geocoords::CoordSys* cs)
+{ // write
+  assert(!mesh.isNull());
+
+  const double t = 0.0;
+  const int numTimeSteps = 0;
+  writer->open(mesh, cs, numTimeSteps);
+  writer->openTimeStep(t, mesh, cs);
+  writer->closeTimeStep();
+  writer->close();
+} // write
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.hh	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,76 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/topology/MeshRefiner.hh
+ *
+ * @brief Object for managing mesh refinement.
+ */
+
+#if !defined(pylith_topology_meshrefiner_hh)
+#define pylith_topology_meshrefiner_hh
+
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
+
+namespace pylith {
+  namespace topology {
+    class MeshRefiner;
+    class TestMeshRefiner;
+  } // topology
+
+  namespace meshio {
+    class DataWriter;
+  } // meshio
+} // pylith
+
+namespace spatialdata {
+  namespace geocoords {
+    class CoordSys;
+  } // geocoords
+} // spatialdata
+
+class pylith::topology::MeshRefiner
+{ // MeshRefiner
+  friend class TestMeshRefiner; // unit testing
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /// Constructor
+  MeshRefiner(void);
+
+  /// Destructor
+  ~MeshRefiner(void);
+
+  /** Write refined mesh.
+   *
+   * @param writer Data writer for partition information.
+   * @param mesh Refined mesh.
+   * @param cs Coordinate system for mesh.
+   */
+  static
+  void write(meshio::DataWriter* const writer,
+	     const ALE::Obj<Mesh>& mesh,
+	     const spatialdata::geocoords::CoordSys* cs);
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  MeshRefiner(const MeshRefiner&); ///< Not implemented
+  const MeshRefiner& operator=(const MeshRefiner&); ///< Not implemented
+
+}; // MeshRefiner
+
+#endif // pylith_topology_meshrefiner_hh
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,45 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+#include <portinfo>
+
+#include "RefineUniform.hh" // implementation of class methods
+
+#include "pylith/utils/sievetypes.hh" // USES PETSc Mesh
+
+#include <stdexcept> // USES std::runtime_error
+#include <sstream> // USES std::ostringstream
+#include <assert.h> // USES assert()
+
+// ----------------------------------------------------------------------
+// Constructor
+pylith::topology::RefineUniform::RefineUniform(void)
+{ // constructor
+} // constructor
+ 
+// ----------------------------------------------------------------------
+// Destructor
+pylith::topology::RefineUniform::~RefineUniform(void)
+{ // destructor
+} // destructor
+
+// ----------------------------------------------------------------------
+// Refine mesh.
+void
+pylith::topology::RefineUniform::refine(ALE::Obj<Mesh>* const newMesh,
+					const ALE::Obj<Mesh>& mesh,
+					const int levels)
+{ // refine
+} // refine
+
+
+// End of file 

Added: short/3D/PyLith/trunk/libsrc/topology/RefineUniform.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/RefineUniform.hh	                        (rev 0)
+++ short/3D/PyLith/trunk/libsrc/topology/RefineUniform.hh	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,65 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+//                           Brad T. Aagaard
+//                        U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+/**
+ * @file pylith/topology/RefineUniform.hh
+ *
+ * @brief Object for managing uniform global mesh refinement.
+ */
+
+#if !defined(pylith_topology_refineuniform_hh)
+#define pylith_topology_refineuniform_hh
+
+#include "MeshRefiner.hh" // ISA MeshRefiner
+
+namespace pylith {
+  namespace topology {
+    class RefineUniform;
+    class TestRefineUniform;
+  } // topology
+} // pylith
+
+class pylith::topology::RefineUniform : public MeshRefiner
+{ // RefineUniform
+  friend class TestRefineUniform; // unit testing
+
+// PUBLIC MEMBERS ///////////////////////////////////////////////////////
+public :
+
+  /// Constructor
+  RefineUniform(void);
+
+  /// Destructor
+  ~RefineUniform(void);
+
+  /** Refine mesh.
+   *
+   * @param newMesh Refined mesh (result).
+   * @param mesh Mesh to refine.
+   * @param levels Number of levels to refine.
+   */
+  void refine(ALE::Obj<Mesh>* const newMesh,
+	      const ALE::Obj<Mesh>& mesh,
+	      const int levels);
+
+// NOT IMPLEMENTED //////////////////////////////////////////////////////
+private :
+
+  RefineUniform(const RefineUniform&); ///< Not implemented
+  const RefineUniform& operator=(const RefineUniform&); ///< Not implemented
+
+}; // RefineUniform
+
+#endif // pylith_topology_refineuniform_hh
+
+
+// End of file 

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2008-09-16 23:36:23 UTC (rev 12894)
@@ -14,6 +14,8 @@
 #include "pylith/topology/FieldsManager.hh"
 #include "pylith/topology/Distributor.hh"
 #include "pylith/topology/MeshOps.hh"
+#include "pylith/topology/MeshRefiner.hh"
+#include "pylith/topology/RefineUniform.hh"
 #include "pylith/utils/sievetypes.hh"
 #include "pylith/utils/petscfwd.h"
 #include <petscmesh.hh>
@@ -84,7 +86,6 @@
 import mpi
 
 # ----------------------------------------------------------------------
-
 cdef class Mesh:
 
   cdef void* thisptr # Pointer to C++ object
@@ -586,6 +587,147 @@
 
 
 # ----------------------------------------------------------------------
+cdef void MeshRefiner_destructor(void* obj):
+  """
+  Destroy MeshRefiner object.
+  """
+  # create shim for destructor
+  #embed{ void MeshRefiner_destructor_cpp(void* objVptr)
+  pylith::topology::MeshRefiner* pRefiner =
+    (pylith::topology::MeshRefiner*) objVptr;
+  delete pRefiner;
+  #}embed
+  MeshRefiner_destructor_cpp(obj)
+  return
+
+
+cdef class MeshRefiner:
+
+  cdef void* thisptr # Pointer to C++ object
+  cdef readonly object handle # PyCObject holding pointer to C++ object
+  cdef readonly object name # Identifier for object base type
+
+  def __init__(self):
+    """
+    Constructor.
+    """
+    self.handle = None
+    self.thisptr = NULL
+    self.name = "pylith_topology_meshrefiner"
+    return
+
+
+  def _createHandle(self):
+    """Wrap pointer to C++ object in PyCObject."""
+    return PyCObject_FromVoidPtr(self.thisptr, MeshRefiner_destructor)
+
+
+  def write(self, writer, mesh, cs):
+    """
+    Write refined mesh to file..
+    """
+    # create shim for method 'write'
+    #embed{ void MeshRefiner_write(void* writerVptr, void* meshVptr, void* csVptr)
+    try {
+      assert(0 != writerVptr);
+      assert(0 != meshVptr);
+      assert(0 != csVptr);
+      ALE::Obj<pylith::Mesh>* mesh = (ALE::Obj<pylith::Mesh>*) meshVptr;
+      pylith::meshio::DataWriter* writer =
+        (pylith::meshio::DataWriter*) writerVptr;
+      spatialdata::geocoords::CoordSys* cs =
+        (spatialdata::geocoords::CoordSys*) csVptr;
+      pylith::topology::MeshRefiner::write(writer, *mesh, cs);
+    } 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 writer.name != "pylith_meshio_DataWriter":
+      raise TypeError, \
+            "Argument 'writer' must be extension module type 'DataWriter'."
+    if mesh.name != "pylith_topology_Mesh":
+      raise TypeError, \
+            "Argument 'mesh' must be extension module type 'Mesh'."
+    if cs.name != "spatialdata_geocoords_CoordSys":
+      raise TypeError, \
+            "Argument 'cs' must be extension module type 'CoordSys'."
+    MeshRefiner_write(ptrFromHandle(writer), ptrFromHandle(mesh),
+                      ptrFromHandle(cs))
+    return
+
+
+# ----------------------------------------------------------------------
+cdef class RefineUniform(MeshRefiner):
+
+  def __init__(self):
+    """Constructor."""
+    # create shim for constructor
+    #embed{ void* RefineUniform_constructor()
+    void* result = 0;
+    try {
+      result = (void*)(new pylith::topology::RefineUniform);
+      assert(0 != result);
+    } 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
+
+    MeshRefiner.__init__(self)
+    self.thisptr = RefineUniform_constructor()
+    self.handle = self._createHandle()
+    return
+
+
+  def refine(self, mesh, levels):
+    """
+    Refine mesh.
+    """
+    # create shim for method 'refine'
+    #embed{ void RefineUniform_refine(void* objVptr, void* newMeshVptr, void* meshVptr, int levels)
+    try {
+      assert(0 != objVptr);
+      assert(0 != meshVptr);
+      assert(0 != newMeshVptr);
+      ALE::Obj<pylith::Mesh>* mesh = (ALE::Obj<pylith::Mesh>*) meshVptr;
+      ALE::Obj<pylith::Mesh>* newMesh = (ALE::Obj<pylith::Mesh>*) newMeshVptr;
+      ((pylith::topology::RefineUniform*) objVptr)->refine(newMesh, *mesh, levels);
+    } 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()
+    RefineUniform_refine(self.thisptr, ptrFromHandle(newMesh),
+                         ptrFromHandle(mesh), levels)
+    return newMesh
+
+
+
+# ----------------------------------------------------------------------
 cdef class FieldsManager:
 
   cdef void* thisptr # Pointer to C++ object

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2008-09-16 23:36:23 UTC (rev 12894)
@@ -112,6 +112,8 @@
 	topology/Mesh.py \
 	topology/MeshGenerator.py \
 	topology/MeshImporter.py \
+	topology/MeshRefiner.py \
+	topology/RefineUniform.py \
 	utils/__init__.py \
 	utils/CheckpointTimer.py \
 	utils/CppData.py \

Modified: short/3D/PyLith/trunk/pylith/topology/Distributor.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Distributor.py	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/pylith/topology/Distributor.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -41,7 +41,7 @@
     ## @li \b debug Write partition information to file.
     ##
     ## \b Facilities
-    ## @li \b output Output manager for partition information
+    ## @li \b writer Data writer for for partition information.
 
     import pyre.inventory
 
@@ -137,7 +137,7 @@
 
 # FACTORIES ////////////////////////////////////////////////////////////
 
-def mesh_partitioner():
+def mesh_distributor():
   """
   Factory associated with Distributor.
   """

Modified: short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/pylith/topology/MeshGenerator.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -66,7 +66,7 @@
 
   def create(self, faults=None):
     """
-    Generate a Mesh from a boundary
+    Generate a Mesh.
     """
     raise NotImplementedError("MeshGenerator.create() not implemented.")
     return

Modified: short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/pylith/topology/MeshImporter.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -42,6 +42,7 @@
     ## \b Facilities
     ## @li \b importer Mesh importer.
     ## @li \b partitioner Mesh partitioner.
+    ## @li \b refiner Mesh refiner.
 
     import pyre.inventory
 
@@ -55,8 +56,13 @@
                                           family="mesh_distributor",
                                           factory=Distributor)
     distributor.meta['tip'] = "Mesh distributor."
-  
+ 
+    from MeshRefiner import MeshRefiner
+    refiner = pyre.inventory.facility("refiner",
+                                      family="mesh_refiner",
+                                      factory=MeshRefiner)
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="meshimporter"):
@@ -91,6 +97,9 @@
       mesh = self.distributor.distribute(mesh)
     #mesh.view()
 
+    # refine mesh (if necessary)
+    mesh = self.refiner.refine(mesh)
+
     self._logger.eventEnd(logEvent)    
     return mesh
 
@@ -104,6 +113,7 @@
     MeshGenerator._configure(self)
     self.importer = self.inventory.importer
     self.distributor = self.inventory.distributor
+    self.refiner = self.inventory.refiner
     return
   
 

Added: short/3D/PyLith/trunk/pylith/topology/MeshRefiner.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshRefiner.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/topology/MeshRefiner.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,117 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/topology/MeshRefiner.py
+##
+## @brief Python manager for refining mesh in parallel.
+##
+## Factory: mesh_refiner.
+
+from pyre.components.Component import Component
+
+# MeshRefiner class
+class MeshRefiner(Component):
+  """
+  Python manager for refining mesh in parallel.
+
+  Factory: mesh_refiner
+  """
+
+  class Inventory(Component.Inventory):
+    """
+    Python object for managing RefineUniform facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing RefineUniform facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b debug Write partition information to file.
+    ##
+    ## \b Facilities
+    ## @li \b writer Data writer for for partition information.
+
+    import pyre.inventory
+
+    debug = pyre.inventory.bool("debug", default=False)
+    debug.meta['tip'] = "Write partition information to file."
+
+    from pylith.meshio.DataWriterVTK import DataWriterVTK
+    dataWriter = pyre.inventory.facility("data_writer", factory=DataWriterVTK,
+                                         family="output_data_writer")
+    dataWriter.meta['tip'] = "Data writer for partition information."
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="refiner"):
+    """
+    Constructor.
+    """
+    Component.__init__(self, name, facility="refiner")
+    self.cppHandle = None
+    return
+
+
+  def refine(self, mesh):
+    """
+    Refine mesh.
+    """
+    return mesh
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    Component._configure(self)
+    self.debug = self.inventory.debug
+    self.dataWriter = self.inventory.dataWriter
+    return
+
+
+  def _createCppHandle(self):
+    """
+    Create handle to C++ object.
+    """
+    raise NotImplementedError("Please implement _createCppHandle().");
+    return
+  
+
+  def _setupLogging(self):
+    """
+    Setup event logging.
+    """
+    self._loggingPrefix = "Refin "
+    from pylith.utils.EventLogger import EventLogger
+    logger = EventLogger()
+    logger.setClassName("FE Refinement")
+    logger.initialize()
+    events = ["refine"]
+    for event in events:
+      logger.registerEvent("%s%s" % (self._loggingPrefix, event))
+
+    self._logger = logger
+    return
+  
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def mesh_refiner():
+  """
+  Factory associated with MeshRefiner.
+  """
+  return MeshRefiner()
+
+
+# End of file 

Added: short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/RefineUniform.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/topology/RefineUniform.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/topology/RefineUniform.py
+##
+## @brief Python manager for uniform global refinement of mesh in
+## parallel.
+##
+## Factory: mesh_refiner.
+
+from MeshRefiner import MeshRefiner
+
+# RefineUniform class
+class RefineUniform(MeshRefiner):
+  """
+  Python manager for uniform global refinement of mesh in parallel.
+
+  Factory: mesh_refiner
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(MeshRefiner.Inventory):
+    """
+    Python object for managing RefineUniform facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing RefineUniform facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b levels Number of refinement levels.
+    ##
+    ## \b Facilities
+    ## @li None
+
+    import pyre.inventory
+
+    levels = pyre.inventory.int("levels", default=2,
+                                validator=pyre.inventory.choice([2, 4]))
+    levels.meta['tip'] = "Number of refinement levels."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="refineuniform"):
+    """
+    Constructor.
+    """
+    MeshRefiner.__init__(self, name)
+    return
+
+
+  def refine(self, mesh):
+    """
+    Refine mesh.
+    """
+    self._setupLogging()
+    logEvent = "%srefine" % self._loggingPrefix
+    self._logger.eventBegin(logEvent)
+
+    self._createCppHandle()
+    
+    from Mesh import Mesh
+    newMesh = Mesh()
+    assert(None != self.cppHandle)
+    newMesh.cppHandle = self.cppHandle.refine(mesh.cppHandle,
+                                              self.levels)
+    newMesh.coordsys = mesh.coordsys
+
+    if self.debug:
+      self.dataWriter.initialize()
+      self.cppHandle.write(self.dataWriter.cppHandle,
+                           newMesh.cppHandle, newMesh.coordsys.cppHandle)
+
+    self._logger.eventEnd(logEvent)
+    return newMesh
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    Component._configure(self)
+    self.levels = self.inventory.levels
+    return
+
+
+  def _createCppHandle(self):
+    """
+    Create handle to C++ object.
+    """
+    if None == self.cppHandle:
+      import pylith.topology.topology as bindings
+      self.cppHandle = bindings.RefineUniform()
+    return
+  
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def mesh_distributor():
+  """
+  Factory associated with RefineUniform.
+  """
+  return RefineUniform()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/topology/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/__init__.py	2008-09-16 21:41:41 UTC (rev 12893)
+++ short/3D/PyLith/trunk/pylith/topology/__init__.py	2008-09-16 23:36:23 UTC (rev 12894)
@@ -20,6 +20,8 @@
            'MeshGenSimple',
            'MeshGenerator',
            'MeshImporter',
+           'MeshRefiner',
+           'RefineUniform',
            ]
 
 



More information about the cig-commits mailing list