[cig-commits] r6047 - in short/3D/PyLith/trunk: . examples/twotri3 modulesrc/utils pylith pylith/feassemble pylith/meshio pylith/utils unittests/pytests/feassemble

brad at geodynamics.org brad at geodynamics.org
Sat Feb 17 19:28:56 PST 2007


Author: brad
Date: 2007-02-17 19:28:56 -0800 (Sat, 17 Feb 2007)
New Revision: 6047

Added:
   short/3D/PyLith/trunk/pylith/utils/PetscManager.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
   short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src
   short/3D/PyLith/trunk/pylith/PyLithApp.py
   short/3D/PyLith/trunk/pylith/feassemble/ExplicitElasticity.py
   short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
   short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
   short/3D/PyLith/trunk/pylith/feassemble/IntegratorExplicit.py
   short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
   short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATSimplex.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py
Log:
Added missing PetscManager. Small trivial cleanup of some code, including updating use of numpy to 1.0 in some Python unittests.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/TODO	2007-02-18 03:28:56 UTC (rev 6047)
@@ -1,12 +1,5 @@
 MAIN PRIORITIES
 
-0. Add in PETSc initialize/finalize using petsc2py.
-
-  STATUS:
-
-    Initial implementation. Still need to get PETSc options from
-    command line. See comment in PyLithApp.py.
-
 1. Debug reading mesh via pylithic
 
 2. Bridge gap b/t Problem and Formulation (advance versus calcResidual)

Modified: short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/examples/twotri3/pylithapp.cfg	2007-02-18 03:28:56 UTC (rev 6047)
@@ -6,6 +6,7 @@
 journal.info.eqdeformation = 1
 journal.info.explicit = 1
 journal.info.petsc = 1
+journal.info.meshioascii = 1
 
 # ----------------------------------------------------------------------
 # MPI

Modified: short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/modulesrc/utils/petsc.pyxe.src	2007-02-18 03:28:56 UTC (rev 6047)
@@ -11,8 +11,6 @@
 #
 
 # ----------------------------------------------------------------------
-cdef enum:
-  PETSC_NULL = 0
 cdef extern from "petsc.h":
   ctypedef int PetscErrorCode
   PetscErrorCode PetscInitialize(int*, char***, char[], char[])
@@ -55,7 +53,7 @@
     argv[i] = <char*> malloc((strlen(arg)+1)*sizeof(char));
     strcpy(argv[i], arg);
   argv[argc] = NULL;
-  err = PetscInitialize(&argc, &argv, <char*> PETSC_NULL, <char*> PETSC_NULL)
+  err = PetscInitialize(&argc, &argv, NULL, NULL)
   for i from 0 <= i < argc:
     free(argv[i])
   free(argv)

Modified: short/3D/PyLith/trunk/pylith/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -61,8 +61,17 @@
     petsc = pyre.inventory.facility("petsc", factory=PetscManager)
     petsc.meta['tip'] = "Manager for PETSc options."
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
+  def __init__(self, name="pylithapp"):
+    """
+    Constructor.
+    """
+    Application.__init__(self, name)
+    return
+
+
   def main(self):
     """
     Run the application.
@@ -76,14 +85,6 @@
     return
   
 
-  def __init__(self, name="pylithapp"):
-    """
-    Constructor.
-    """
-    Application.__init__(self, name)
-    return
-
-
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):

Modified: short/3D/PyLith/trunk/pylith/feassemble/ExplicitElasticity.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/ExplicitElasticity.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/feassemble/ExplicitElasticity.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -49,14 +49,6 @@
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
-  def initialize(self, mesh):
-    """
-    Initialize integrator.
-    """
-    self.cppHandle.setupMatProp(mesh.cppHandle, mesh.coordsys, db.cppHandle)
-    return
-
-
   def __init__(self, name="explicitelasticity"):
     """
     Constructor.
@@ -68,6 +60,14 @@
     return
 
 
+  def initialize(self, mesh):
+    """
+    Initialize integrator.
+    """
+    self.cppHandle.setupMatProp(mesh.cppHandle, mesh.coordsys, db.cppHandle)
+    return
+
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):

Modified: short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/feassemble/FIATCell.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -35,6 +35,7 @@
     ReferenceCell.__init__(self, name)
     return
 
+
   def initialize(self):
     """
     Initialize reference finite-element cell.

Modified: short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -46,6 +46,7 @@
     quadrature = pyre.inventory.facility("quadrature", factory=Quadrature)
     quadrature.meta['tip'] = "Quadrature object for integration."
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="integrator"):

Modified: short/3D/PyLith/trunk/pylith/feassemble/IntegratorExplicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/IntegratorExplicit.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/feassemble/IntegratorExplicit.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -27,6 +27,14 @@
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
+  def __init__(self, name="integratorexplicit"):
+    """
+    Constructor.
+    """
+    Integrator.__init__(self, name)
+    return
+
+
   def timeStep(self, t):
     """
     Set time step for advancing from time t to time t+dt.
@@ -73,12 +81,4 @@
     return
 
 
-  def __init__(self, name="integratorexplicit"):
-    """
-    Constructor.
-    """
-    Integrator.__init__(self, name)
-    return
-
-
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIO.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIO.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIO.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -62,11 +62,12 @@
 
     @returns PETSc mesh object containing finite-element mesh
     """
+    self._info.log("Reading finite-element mesh")
+    self._sync()
     from pylith.topology.Mesh import Mesh
     mesh = Mesh()
-    self.cppHandle.interpolate = self.interpolate
     mesh.cppHandle = self.cppHandle.read(mesh.cppHandle)
-    return 
+    return mesh
 
 
   def write(self, mesh):
@@ -75,8 +76,9 @@
 
     @param mesh PETSc mesh object containing finite-element mesh
     """
-    self.cppHandle.interpolate = self.interpolate
-    self.cppHandle.write(mesh.handle)
+    self._info.log("Writing finite-element mesh")
+    self._sync()
+    self.cppHandle.write(mesh.cppHandle)
     return
 
 
@@ -91,4 +93,12 @@
     return
 
 
+  def _sync(self):
+    """
+    Force synchronization between Python and C++.
+    """
+    self.cppHandle.interpolate = self.interpolate
+    return
+  
+
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/meshio/MeshIOAscii.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -70,4 +70,13 @@
     return
 
 
+  def _sync(self):
+    """
+    Force synchronization between Python and C++.
+    """
+    MeshIO._sync(self)
+    self.cppHandle.filename = self.filename
+    return
+  
+
 # End of file 

Added: short/3D/PyLith/trunk/pylith/utils/PetscManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/PetscManager.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/pylith/utils/PetscManager.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/utils/PetscManager.py
+
+## @brief Python PetscManager object for managing PETSc options.
+
+## The PetscManager also takes care of initializing and finalizing
+## PETSc.
+
+from pyre.components.Component import Component
+
+# PetscManager class
+class PetscManager(Component):
+  """
+  Python PetscManager object for managing PETSc options.
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def initialize(self):
+    """
+    Initialize PETSc.
+    """
+    self._info.log("Initializing PETSc.")
+    import pylith.utils.petsc as bindings
+    import sys
+    args = [sys.executable]
+    options = self._getOptions()
+    if len(options) > 0:
+      for arg in options:
+        args.append(arg)
+    bindings.petsc_initialize(args)
+    return
+
+
+  def finalize(self):
+    """
+    Finalize PETSc.
+    """
+    self._info.log("Finalizing PETSc.")
+    import pylith.utils.petsc as bindings
+    bindings.petsc_finalize()
+    return
+  
+
+  def updateConfiguration(self, registry):
+    """
+    Update Pyre configuration.
+    """
+    self.options = [
+      (name, descriptor.value) for name, descriptor in registry.properties.iteritems()
+      ]
+    return []
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def __init__(self, name="petsc"):
+    """
+    Constructor.
+    """
+    Component.__init__(self, name, facility="petsc")
+    self.options = []
+    return
+
+
+  def _getOptions(self):
+    """
+    Cleanup options for PETSc.
+    """
+    args = []
+    for iname, value in self.options:
+      args.append('-' + iname)
+      if value != 'true':
+        args.append(value)
+    return args
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATSimplex.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATSimplex.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestFIATSimplex.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -81,14 +81,14 @@
                              (+1.0/3**0.5,)],
                             dtype=numpy.float64 )
     quadWtsE = numpy.array( [1.0, 1.0], dtype=numpy.float64 )
-    basis = numpy.zeros( (2, 3), dtype=numpy.Float64)
-    basisDeriv = numpy.zeros( (2, 3, 1), dtype=numpy.Float64)
+    basis = numpy.zeros( (2, 3), dtype=numpy.float64)
+    basisDeriv = numpy.zeros( (2, 3, 1), dtype=numpy.float64)
     iQuad = 0
     for q in quadPtsE:
       basis[iQuad] = numpy.array([N0(q), N1(q), N2(q)],
                                  dtype=numpy.float64).reshape( (3,) )
       deriv = numpy.array([[N0p(q)], [N1p(q)], [N2p(q)]],
-                          dtype=numpy.Float64)      
+                          dtype=numpy.float64)      
       basisDeriv[iQuad] = deriv.reshape((3, 1))
       iQuad += 1
 

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py	2007-02-17 17:43:00 UTC (rev 6046)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestQuadrature.py	2007-02-18 03:28:56 UTC (rev 6047)
@@ -68,14 +68,14 @@
                              (+1.0/3**0.5,)],
                             dtype=numpy.float64 )
     quadWtsE = numpy.array( [1.0, 1.0], dtype=numpy.float64 )
-    basisE = numpy.zeros( (2, 3), dtype=numpy.Float64)
-    basisDerivE = numpy.zeros( (2, 3, 1), dtype=numpy.Float64)
+    basisE = numpy.zeros( (2, 3), dtype=numpy.float64)
+    basisDerivE = numpy.zeros( (2, 3, 1), dtype=numpy.float64)
     iQuad = 0
     for q in quadPtsE:
       basisE[iQuad] = numpy.array([N0(q), N1(q), N2(q)],
                                  dtype=numpy.float64).reshape( (3,) )
       deriv = numpy.array([[N0p(q)], [N1p(q)], [N2p(q)]],
-                          dtype=numpy.Float64)      
+                          dtype=numpy.float64)      
       basisDerivE[iQuad] = deriv.reshape((3, 1))
       iQuad += 1
 



More information about the cig-commits mailing list