[cig-commits] r14524 - in short/3D/PyLith/branches/pylith-swig: libsrc/problems libsrc/topology modulesrc/problems modulesrc/topology pylith/apps pylith/problems pylith/topology

brad at geodynamics.org brad at geodynamics.org
Sat Mar 28 19:10:23 PDT 2009


Author: brad
Date: 2009-03-28 19:10:21 -0700 (Sat, 28 Mar 2009)
New Revision: 14524

Modified:
   short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.cc
   short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.hh
   short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Fields.i
   short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Jacobian.i
   short/3D/PyLith/branches/pylith-swig/pylith/apps/PyLithApp.py
   short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py
   short/3D/PyLith/branches/pylith-swig/pylith/problems/Problem.py
   short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py
   short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py
   short/3D/PyLith/branches/pylith-swig/pylith/topology/Field.py
   short/3D/PyLith/branches/pylith-swig/pylith/topology/Fields.py
   short/3D/PyLith/branches/pylith-swig/pylith/topology/Jacobian.py
   short/3D/PyLith/branches/pylith-swig/pylith/topology/SolutionFields.py
Log:
Added cleanup() and deallocation() methods to properly deallocate PETSc and other data structures.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.cc	2009-03-29 02:10:21 UTC (rev 14524)
@@ -43,7 +43,6 @@
   if (0 != _ksp) {
     PetscErrorCode err = KSPDestroy(_ksp); _ksp = 0;
     CHECK_PETSC_ERROR(err);
-    std::cout << "DESTROYED KSP." << std::endl;
   } // if
 } // deallocate
   

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/problems/SolverLinear.hh	2009-03-29 02:10:21 UTC (rev 14524)
@@ -41,7 +41,7 @@
   /// Destructor
   ~SolverLinear(void);
 
-  /// Deallocate data structures.
+  /// Deallocate PETSc and local data structures.
   void deallocate(void);
   
   /** Set initial guess zero flag.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.cc	2009-03-29 02:10:21 UTC (rev 14524)
@@ -43,6 +43,15 @@
 template<typename mesh_type>
 pylith::topology::Field<mesh_type>::~Field(void)
 { // destructor
+  deallocate();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Deallocate PETSc and local data structures.
+template<typename mesh_type>
+void
+pylith::topology::Field<mesh_type>::deallocate(void)
+{ // deallocate
   PetscErrorCode err = 0;
   if (0 != _vector) {
     err = VecDestroy(_vector); _vector = 0;
@@ -53,7 +62,7 @@
     err = VecScatterDestroy(_scatter); _scatter = 0;
     CHECK_PETSC_ERROR(err);
   } // if
-} // destructor
+} // deallocate
 
 // ----------------------------------------------------------------------
 // Get spatial dimension of domain.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Field.hh	2009-03-29 02:10:21 UTC (rev 14524)
@@ -63,6 +63,9 @@
   /// Destructor.
   ~Field(void);
 
+  /// Deallocate PETSc and local data structures.
+  void deallocate(void);
+  
   /** Get Sieve section.
    *
    * @returns Sieve section.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.hh	2009-03-29 02:10:21 UTC (rev 14524)
@@ -43,6 +43,9 @@
   /// Destructor.
   ~Fields(void);
 
+  /// Deallocate PETSc and local data structures.
+  void deallocate(void);
+  
   /** Add field.
    *
    * @param name Name of field.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Fields.icc	2009-03-29 02:10:21 UTC (rev 14524)
@@ -30,12 +30,21 @@
 template<typename field_type>
 pylith::topology::Fields<field_type>::~Fields(void)
 { // destructor
+  deallocate();
+} // destructor
+
+// ----------------------------------------------------------------------
+// Deallocate PETSc and local data structures.
+template<typename field_type>
+void
+pylith::topology::Fields<field_type>::deallocate(void)
+{ // deallocate
   const typename map_type::iterator begin = _fields.begin();
   const typename map_type::iterator end = _fields.end();
   for (typename map_type::iterator iter=begin; iter != end; ++iter) {
     delete iter->second; iter->second = 0;
   } // for
-} // destructor
+} // deallocate
 
 // ----------------------------------------------------------------------
 // Add field.

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.cc
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.cc	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.cc	2009-03-29 02:10:21 UTC (rev 14524)
@@ -39,10 +39,21 @@
 // Destructor.
 pylith::topology::Jacobian::~Jacobian(void)
 { // destructor
-  MatDestroy(_matrix); _matrix = 0;
+  deallocate();
 } // destructor
 
 // ----------------------------------------------------------------------
+// Deallocate PETSc and local data structures.
+void
+pylith::topology::Jacobian::deallocate(void)
+{ // deallocate
+  if (0 != _matrix) {
+    PetscErrorCode err = MatDestroy(_matrix); _matrix = 0;
+    CHECK_PETSC_ERROR(err);
+  } // if
+} // deallocate
+
+// ----------------------------------------------------------------------
 // Get PETSc matrix.
 const PetscMat
 pylith::topology::Jacobian::matrix(void) const

Modified: short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.hh
===================================================================
--- short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.hh	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/libsrc/topology/Jacobian.hh	2009-03-29 02:10:21 UTC (rev 14524)
@@ -41,6 +41,9 @@
   /// Destructor.
   ~Jacobian(void);
 
+  /// Deallocate PETSc and local data structures.
+  void deallocate(void);
+  
   /** Get PETSc matrix.
    *
    * @returns PETSc sparse matrix.

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/problems/SolverLinear.i	2009-03-29 02:10:21 UTC (rev 14524)
@@ -31,7 +31,7 @@
       /// Destructor
       ~SolverLinear(void);
 
-      /// Deallocate data structures.
+      /// Deallocate PETSc and local data structures.
       void deallocate(void);
 
       /** Set initial guess zero flag.

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Field.i	2009-03-29 02:10:21 UTC (rev 14524)
@@ -44,6 +44,9 @@
       /// Destructor.
       ~Field(void);
       
+      /// Deallocate PETSc and local data structures.
+      void deallocate(void);
+
       /** Get mesh associated with field.
        *
        * @returns Finite-element mesh.

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Fields.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Fields.i	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Fields.i	2009-03-29 02:10:21 UTC (rev 14524)
@@ -35,6 +35,9 @@
       /// Destructor.
       ~Fields(void);
 
+      /// Deallocate PETSc and local data structures.
+      void deallocate(void);
+
       /** Add field.
        *
        * @param name Name of field.

Modified: short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Jacobian.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Jacobian.i	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/topology/Jacobian.i	2009-03-29 02:10:21 UTC (rev 14524)
@@ -34,6 +34,9 @@
       /// Destructor.
       ~Jacobian(void);
       
+      /// Deallocate PETSc and local data structures.
+      void deallocate(void);
+
       /** Get PETSc matrix.
        *
        * @returns PETSc sparse matrix.

Modified: short/3D/PyLith/branches/pylith-swig/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/apps/PyLithApp.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/apps/PyLithApp.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -14,17 +14,17 @@
 ##
 ## @brief Python PyLith application
 
-from mpi import Application
+from PetscApplication import PetscApplication
 
 # PyLithApp class
-class PyLithApp(Application):
+class PyLithApp(PetscApplication):
   """
   Python PyLithApp application.
   """
   
   # INVENTORY //////////////////////////////////////////////////////////
 
-  class Inventory(Application.Inventory):
+  class Inventory(PetscApplication.Inventory):
     """
     Python object for managing PyLithApp facilities and properties.
     """
@@ -33,8 +33,7 @@
     ## Python object for managing PyLithApp facilities and properties.
     ##
     ## \b Properties
- 
-   ## @li None
+    ## @li None
     ##
     ## \b Facilities
     ## @li \b mesher Generates or imports the computational mesh.
@@ -53,20 +52,14 @@
                                       factory=TimeDependent)
     problem.meta['tip'] = "Computational problem to solve."
 
-    # 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="pylithapp"):
     """
     Constructor.
     """
-    Application.__init__(self, name)
+    PetscApplication.__init__(self, name)
     self._loggingPrefix = "PyLith "
     return
 
@@ -77,7 +70,6 @@
     """
     from pylith.utils.profiling import resourceUsageString
     
-    self.petsc.initialize()
     self._debug.log(resourceUsageString())
 
     self._setupLogging()
@@ -119,12 +111,8 @@
 
     del mesh
     del self.problem
-    import gc
-    print gc.collect()
 
     self._logger.eventEnd("PyLith main")
-    print "TEMPORARY PetscFinalized() commented out in PyLithApp.py"
-    #self.petsc.finalize()
     return
   
 
@@ -134,10 +122,9 @@
     """
     Setup members using inventory.
     """
-    Application._configure(self)
+    PetscApplication._configure(self)
     self.mesher = self.inventory.mesher
     self.problem = self.inventory.problem
-    self.petsc = self.inventory.petsc
 
     import journal
     self._debug = journal.debug(self.name)

Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/Formulation.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -17,7 +17,7 @@
 ##
 ## Factory: pde_formulation
 
-from pyre.components.Component import Component
+from pylith.utils.PetscComponent import PetscComponent
 from problems import Formulation as ModuleFormulation
 
 from pylith.utils.profiling import resourceUsageString
@@ -35,7 +35,7 @@
 
 
 # Formulation class
-class Formulation(Component, ModuleFormulation):
+class Formulation(PetscComponent, ModuleFormulation):
   """
   Python abstract base class for formulations of solving equations.
 
@@ -47,7 +47,7 @@
 
   # INVENTORY //////////////////////////////////////////////////////////
 
-  class Inventory(Component.Inventory):
+  class Inventory(PetscComponent.Inventory):
     """
     Python object for managing Formulation facilities and properties.
     """
@@ -97,11 +97,12 @@
     """
     Constructor.
     """
-    Component.__init__(self, name, facility="pde_formulation")
+    PetscComponent.__init__(self, name, facility="pde_formulation")
     ModuleFormulation.__init__(self)
     self.integratorsMesh = None
     self.integratorsSubMesh = None
     self.constraints = None
+    self.jacobian = None
     self.fields = None
     self.solnName = None
     return
@@ -311,7 +312,7 @@
     """
     Set members based using inventory.
     """
-    Component._configure(self)
+    PetscComponent._configure(self)
     self.timeStep = self.inventory.timeStep
     self.solver = self.inventory.solver
     self.output = self.inventory.output
@@ -473,6 +474,17 @@
     return
   
 
+  def _cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    if not self.jacobian is None:
+      self.jacobian.cleanup()
+    if not self.fields is None:
+      self.fields.cleanup()
+    return
+
+
 # FACTORIES ////////////////////////////////////////////////////////////
 
 def pde_formulation():

Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/Problem.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/Problem.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/Problem.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -16,7 +16,7 @@
 ##
 ## Factory: problem.
 
-from pyre.components.Component import Component
+from pylith.utils.PetscComponent import PetscComponent
 
 # ITEM FACTORIES ///////////////////////////////////////////////////////
 
@@ -48,7 +48,7 @@
 
 
 # Problem class
-class Problem(Component):
+class Problem(PetscComponent):
   """
   Python abstract base class for crustal dynamics problems.
 
@@ -57,7 +57,7 @@
   
   # INVENTORY //////////////////////////////////////////////////////////
 
-  class Inventory(Component.Inventory):
+  class Inventory(PetscComponent.Inventory):
     """
     Python object for managing Problem facilities and properties.
     """
@@ -124,7 +124,7 @@
     """
     Constructor.
     """
-    Component.__init__(self, name, facility="problem")
+    PetscComponent.__init__(self, name, facility="problem")
     self.mesh = None
     return
 
@@ -223,7 +223,7 @@
     """
     Set members based using inventory.
     """
-    Component._configure(self)
+    PetscComponent._configure(self)
     self.normalizer = self.inventory.normalizer
     self.dimension = self.inventory.dimension
     self.materials = self.inventory.materials

Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/Solver.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -16,10 +16,10 @@
 ##
 ## Factory: solver
 
-from pyre.components.Component import Component
+from pylith.utils.PetscComponent import PetscComponent
 
 # Solver class
-class Solver(Component):
+class Solver(PetscComponent):
   """
   Python abstract base class for solver.
 
@@ -28,7 +28,7 @@
 
   # INVENTORY //////////////////////////////////////////////////////////
 
-  class Inventory(Component.Inventory):
+  class Inventory(PetscComponent.Inventory):
     """
     Python object for managing Solver facilities and properties.
     """
@@ -54,7 +54,7 @@
     """
     Constructor.
     """
-    Component.__init__(self, name, facility="solver")
+    PetscComponent.__init__(self, name, facility="solver")
     return
 
 
@@ -64,7 +64,7 @@
     """
     Set members based using inventory.
     """
-    Component._configure(self)
+    PetscComponent._configure(self)
     return
 
 

Modified: short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/problems/SolverLinear.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -76,6 +76,14 @@
     return
 
 
+  def _cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
+
+
 # FACTORIES ////////////////////////////////////////////////////////////
 
 def solver():

Modified: short/3D/PyLith/branches/pylith-swig/pylith/topology/Field.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/Field.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/Field.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -34,6 +34,14 @@
     """
     ModuleMeshField.__init__(self, mesh)
     return
+
+
+  def cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
     
 
 # ----------------------------------------------------------------------
@@ -54,4 +62,12 @@
     return
     
 
+  def cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
+    
+
 # End of file

Modified: short/3D/PyLith/branches/pylith-swig/pylith/topology/Fields.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/Fields.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/Fields.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -36,6 +36,14 @@
     return
     
 
+  def cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
+    
+
 # ----------------------------------------------------------------------
 # SubMeshFields class
 class SubMeshFields(ModuleSubMeshFields):
@@ -54,4 +62,12 @@
     return
     
 
+  def cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
+    
+
 # End of file

Modified: short/3D/PyLith/branches/pylith-swig/pylith/topology/Jacobian.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/Jacobian.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/Jacobian.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -35,4 +35,12 @@
     return
     
 
+  def cleanup(self):
+    """
+    Dellocate PETSC and local data structures.
+    """
+    self.deallocate()
+    return
+
+
 # End of file

Modified: short/3D/PyLith/branches/pylith-swig/pylith/topology/SolutionFields.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/topology/SolutionFields.py	2009-03-28 22:37:01 UTC (rev 14523)
+++ short/3D/PyLith/branches/pylith-swig/pylith/topology/SolutionFields.py	2009-03-29 02:10:21 UTC (rev 14524)
@@ -34,4 +34,12 @@
     return
     
 
+  def cleanup(self):
+    """
+    Deallocate PETSc and local data structures.
+    """
+    self.deallocate()
+    return
+    
+
 # End of file



More information about the CIG-COMMITS mailing list