[cig-commits] r7047 - in short/3D/PyLith/trunk: . pylith pylith/feassemble pylith/meshio pylith/problems pylith/utils

brad at geodynamics.org brad at geodynamics.org
Fri Jun 1 21:30:17 PDT 2007


Author: brad
Date: 2007-06-01 21:30:16 -0700 (Fri, 01 Jun 2007)
New Revision: 7047

Added:
   short/3D/PyLith/trunk/pylith/meshio/SingleOutput.py
   short/3D/PyLith/trunk/pylith/utils/ObjectBin.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/PyLithApp.py
   short/3D/PyLith/trunk/pylith/feassemble/Constraint.py
   short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
   short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py
   short/3D/PyLith/trunk/pylith/meshio/__init__.py
   short/3D/PyLith/trunk/pylith/problems/Explicit.py
   short/3D/PyLith/trunk/pylith/problems/Formulation.py
   short/3D/PyLith/trunk/pylith/problems/Implicit.py
   short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
   short/3D/PyLith/trunk/pylith/utils/__init__.py
Log:
Added writing of solution field.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/TODO	2007-06-02 04:30:16 UTC (rev 7047)
@@ -4,6 +4,12 @@
 
 0. Incorporate Quad/Hex basis stuff (waiting for Matt to fix)
 
+Replace specific object bins with ObjectBin.
+
+Python unit tests
+  Integrator.finalize()
+  Constraint.finalize()
+
 1. Simple tests with analytical solutions
 
    a. 1-D

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2007-06-02 04:30:16 UTC (rev 7047)
@@ -59,6 +59,7 @@
 	meshio/MeshIOAscii.py \
 	meshio/MeshIOCubit.py \
 	meshio/MeshIOLagrit.py \
+	meshio/SingleOutput.py \
 	meshio/SolutionIO.py \
 	meshio/SolutionIOVTK.py \
 	problems/__init__.py \
@@ -82,6 +83,7 @@
 	utils/__init__.py \
 	utils/CheckpointTimer.py \
 	utils/CppData.py \
+	utils/ObjectBin.py \
 	utils/PetscManager.py \
 	utils/importing.py \
 	utils/testarray.py

Modified: short/3D/PyLith/trunk/pylith/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/PyLithApp.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -84,6 +84,7 @@
     # Initialize problem and then run
     self.problem.initialize(mesh)
     self.problem.run(self)
+    self.problem.finalize()
     
     self.petsc.finalize()
     return

Modified: short/3D/PyLith/trunk/pylith/feassemble/Constraint.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Constraint.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/feassemble/Constraint.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -86,4 +86,11 @@
     return
 
 
+  def finalize(self):
+    """
+    Cleanup after time stepping.
+    """
+    return
+  
+
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -127,4 +127,11 @@
     return
     
 
+  def finalize(self):
+    """
+    Cleanup after time stepping.
+    """
+    return
+  
+
 # End of file 

Added: short/3D/PyLith/trunk/pylith/meshio/SingleOutput.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/SingleOutput.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/meshio/SingleOutput.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/meshio/SingleOutput.py
+##
+## @brief Python container with one output type.
+##
+## Factory: object_bin
+
+from pylith.utils.ObjectBin import ObjectBin
+
+# SingleOutput class
+class SingleOutput(ObjectBin):
+  """
+  Python container with one output type.
+
+  Factory: object_bin
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(ObjectBin.Inventory):
+    """
+    Python object for managing SingleOutput facilities and properties.
+    """
+    
+    ## @class Inventory
+    ## Python object for managing SingleOutput facilities and properties.
+    ##
+    ## \b Properties
+    ## @li None
+    ##
+    ## \b Facilities
+    ## @li \b output Output manager
+
+    import pyre.inventory
+
+    from SolutionIOVTK import SolutionIOVTK
+    output = pyre.inventory.facility("output", family="solution_io",
+                                     factory=SolutionIOVTK)
+    output.meta['tip'] = "Output manager."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="singleoutput"):
+    """
+    Constructor.
+    """
+    ObjectBin.__init__(self, name)
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set attributes from inventory.
+    """
+    ObjectBin._configure(self)
+    self.bin = [self.inventory.output]
+    return
+
+  
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def object_bin():
+  """
+  Factory associated with SingleOutput.
+  """
+  return SingleOutput()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/meshio/SolutionIO.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -36,13 +36,29 @@
     ## Python object for managing SolutionIOVTK facilities and properties.
     ##
     ## \b Properties
-    ## @li None
+    ## @li \b output_freq Flag indicating whether to use 'time_step' or 'skip'
+    ##   to set frequency of solution output.
+    ## @li \b time_step Time step between solution output.
+    ## @li \b skip Number of time steps to skip between solution output.
     ##
     ## \b Facilities
     ## @li \b coordsys Coordinate system for output.
 
     import pyre.inventory
 
+    outputFreq = pyre.inventory.str("output_freq", default="skip",
+             validator=pyre.inventory.choice(["skip", "time_step"]))
+    outputFreq.meta['tip'] = "Flag indicating whether to use 'time_step' " \
+                             "or 'skip' to set frequency of solution output."
+
+    from pyre.units.time import s
+    dt = pyre.inventory.dimensional("time_step", default=1.0*s)
+    dt.meta['tip'] = "Time step between solution output."
+
+    skip = pyre.inventory.int("skip", default=1,
+                              validator=pyre.inventory.greaterEqual(0))
+    skip.meta['tip'] = "Number of time steps to skip between solution output."
+
     from spatialdata.geocoords.CSCart import CSCart
     coordsys = pyre.inventory.facility("coordsys", family="coordsys",
                                        factory=CSCart)
@@ -58,6 +74,9 @@
     Component.__init__(self, name, facility="solution_io")
     self.cppHandle = None
     self.coordsys = None
+    self.mesh = None
+    self.t = None
+    self.istep = None
     return
 
 
@@ -66,6 +85,7 @@
     Open files for solution.
     """
     self._info.log("Opening files for output of solution.")
+    self.mesh = mesh
 
     # Set flags
     self._sync()
@@ -94,26 +114,39 @@
     return
 
 
-  def writeTopology(self, mesh):
+  def writeTopology(self):
     """
     Write solution topology to file.
     """
     self._info.log("Writing solution topology.")
 
     assert(self.cppHandle != None)
-    assert(mesh.cppHandle != None)
-    assert(mesh.coordsys.cppHandle != None)
-    self.cppHandle.writeTopology(mesh.cppHandle, mesh.coordsys.cppHandle)
+    assert(self.mesh.cppHandle != None)
+    assert(self.mesh.coordsys.cppHandle != None)
+    self.cppHandle.writeTopology(self.mesh.cppHandle,
+                                 self.mesh.coordsys.cppHandle)
     return
 
 
-  def writeField(self, t, field, name, mesh):
+  def writeField(self, t, istep, field, name):
     """
     Write solution field at time t to file.
     """
-    self._info.log("Writing solution field '%s'." % name)
-
-    self.cppHandle.writeField(t, field, name, mesh.cppHandle)
+    write = False
+    if self.istep == None or not "value" in dir(self.t):
+      write = True
+    elif self.outputFreq == "skip":
+      if istep > self.istep + self.skip:
+        write = True
+    elif t >= self.t + self.dt:
+      write = True
+    if write:
+      self._info.log("Writing solution field '%s'." % name)
+      assert(self.cppHandle != None)
+      assert(self.mesh.cppHandle != None)
+      self.cppHandle.writeField(t.value, field, name, self.mesh.cppHandle)
+      self.istep = istep
+      self.t = t
     return
 
 
@@ -124,6 +157,9 @@
     Set members based using inventory.
     """
     Component._configure(self)
+    self.outputFreq = self.inventory.outputFreq
+    self.dt = self.inventory.dt
+    self.skip = self.inventory.skip
     self.coordsys = self.inventory.coordsys
     return
 

Modified: short/3D/PyLith/trunk/pylith/meshio/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/__init__.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/meshio/__init__.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -17,7 +17,8 @@
 __all__ = ['MeshIO',
            'MeshIOAscii',
            'MeshIOCubit',
-           'MeshIOLagrit'
+           'MeshIOLagrit',
+           'SingleOutput',
            'SolutionIO',
            'SolutionIOVTK']
 

Modified: short/3D/PyLith/trunk/pylith/problems/Explicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/problems/Explicit.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -45,6 +45,8 @@
     Constructor.
     """
     Formulation.__init__(self, name)
+    self.solnField = {'name': "dispT",
+                      'label': "displacements"}
     return
 
 
@@ -66,16 +68,16 @@
 
     self._info.log("Creating fields and matrices.")
     self.fields.addReal("dispT")
-    self.fields.addReal("dispTmdt")
-    self.fields.addReal("dispTpdt")
-    self.fields.addReal("residual")
-    self.fields.createHistory(["dispTpdt", "dispT", "dispTmdt"])    
     self.fields.setFiberDimension("dispT", dimension)
     for constraint in self.constraints:
       constraint.setConstraintSizes(self.fields.getReal("dispT"), mesh)
     self.fields.allocate("dispT")
     for constraint in self.constraints:
       constraint.setConstraints(self.fields.getReal("dispT"), mesh)    
+    self.fields.addReal("dispTmdt")
+    self.fields.addReal("dispTpdt")
+    self.fields.addReal("residual")
+    self.fields.createHistory(["dispTpdt", "dispT", "dispTmdt"])    
     self.fields.copyLayout("dispT")
     self.jacobian = mesh.createMatrix(self.fields.getReal("residual"))
 
@@ -150,6 +152,8 @@
     self._info.log("Updating integrators states.")
     for integrator in self.integrators:
       integrator.updateState(self.fields.getReal("dispT"))
+
+    Formulation.poststep(self, t)
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Formulation.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/problems/Formulation.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -44,6 +44,7 @@
     ##
     ## \b Facilities
     ## @li \b solver Algebraic solver.
+    ## @li \b output Solution output.
 
     import pyre.inventory
 
@@ -51,7 +52,10 @@
     solver = pyre.inventory.facility("solver", family="solver",
                                      factory=SolverLinear)
     solver.meta['tip'] = "Algebraic solver."
-    
+
+    from pylith.meshio.SingleOutput import SingleOutput
+    output = pyre.inventory.facility("output", family="object_bin",
+                                     factory=SingleOutput)
   
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
@@ -63,6 +67,8 @@
     self.integrators = None
     self.constraints = None
     self.fields = None
+    self.solnField = None
+    self._istep = 0
     return
 
 
@@ -119,9 +125,38 @@
         raise TypeError, \
               "Could not determine whether interface condition '%s' is an " \
               "integrator or a constraint." % ic.name
+
+    self._info.log("Setting up solution output.")
+    for output in self.output.bin:
+      output.open(mesh)
+      output.writeTopology()
     return
 
 
+  def poststep(self, t):
+    """
+    Hook for doing stuff after advancing time step.
+    """
+    field = self.fields.getReal(self.solnField['name'])
+    for output in self.output.bin:
+      output.writeField(t, self._istep, field, self.solnField['label'])
+    self._istep += 1
+    return
+
+
+  def finalize(self):
+    """
+    Cleanup after time stepping.
+    """
+    for integrator in self.integrators:
+      integrator.finalize()
+    for constraint in self.constraints:
+      constraint.finalize()
+    for output in self.output.bin:
+      output.close()
+    return
+  
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):
@@ -130,6 +165,7 @@
     """
     Component._configure(self)
     self.solver = self.inventory.solver
+    self.output = self.inventory.output
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -68,6 +68,8 @@
     Constructor.
     """
     Formulation.__init__(self, name)
+    self.solnField = {'name': "dispTBctpdt",
+                      'label': "displacements"}
     return
 
 
@@ -89,14 +91,14 @@
 
     self._info.log("Creating fields and matrices.")
     self.fields.addReal("dispTBctpdt")
-    self.fields.addReal("dispIncr")
-    self.fields.addReal("residual")
     self.fields.setFiberDimension("dispTBctpdt", dimension)
     for constraint in self.constraints:
       constraint.setConstraintSizes(self.fields.getReal("dispTBctpdt"))
     self.fields.allocate("dispTBctpdt")
     for constraint in self.constraints:
       constraint.setConstraints(self.fields.getReal("dispTBctpdt"))
+    self.fields.addReal("dispIncr")
+    self.fields.addReal("residual")
     self.fields.copyLayout("dispTBctpdt")
     self.jacobian = mesh.createMatrix(self.fields.getReal("dispTBctpdt"))
 
@@ -123,9 +125,9 @@
     """
     # Set dispTBctpdt to the BC at time t+dt. Unconstrained DOF are
     # unaffected and will be equal to their values at time t.
-    dispTBctpdt = self.fields.getReal("dispTBctpdt")
+    solnField = self.fields.getReal("dispTBctpdt")
     for constraint in self.constraints:
-      constraint.setField(t+dt, dispTBctpdt)
+      constraint.setField(t+dt, solnField)
 
     needNewJacobian = False
     for integrator in self.integrators:
@@ -171,13 +173,15 @@
     # nonzero at unconstrained DOF) so that after poststrp(),
     # dispTBctpdt constains the solution at time t+dt.
     import pylith.topology.topology as bindings
-    dispTBctpdt = self.fields.getReal("dispTBctpdt")
-    bindings.addRealSections(dispTBctpdt, dispTBctpdt,
+    solnField = self.fields.getReal("dispTBctpdt")
+    bindings.addRealSections(solnField, solnField,
                              self.fields.getReal("dispIncr"))
 
     self._info.log("Updating integrators states.")
     for integrator in self.integrators:
-      integrator.updateState(dispTBctpdt)
+      integrator.updateState(solnField)
+
+    Formulation.poststep(self, t)
     return
 
 
@@ -201,11 +205,11 @@
       material.useElasticBehavior(True)
 
     self._info.log("Setting constraints.")
-    dispTBctpdt = self.fields.getReal("dispTBctpdt")
+    solnField = self.fields.getReal("dispTBctpdt")
     import pylith.topology.topology as bindings
-    bindings.zeroRealSection(dispTBctpdt)
+    bindings.zeroRealSection(solnField)
     for constraint in self.constraints:
-      constraint.setField(t, dispTBctpdt)
+      constraint.setField(t, solnField)
 
     self._info.log("Integrating Jacobian and residual of operator.")
     import pylith.utils.petsc as petsc
@@ -223,12 +227,11 @@
     self.solver.solve(dispIncr, self.jacobian, residual)
 
     import pylith.topology.topology as bindings
-    dispTBctpdt = self.fields.getReal("dispTBctpdt")
-    bindings.addRealSections(dispTBctpdt, dispTBctpdt, dispIncr)
+    bindings.addRealSections(solnField, solnField, dispIncr)
 
     self._info.log("Updating integrators states.")
     for integrator in self.integrators:
-      integrator.updateState(dispTBctpdt)
+      integrator.updateState(solnField)
     return
   
 

Modified: short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeDependent.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/problems/TimeDependent.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -137,6 +137,14 @@
     return
 
 
+  def finalize(self):
+    """
+    Cleanup after running problem.
+    """
+    self.formulation.finalize()
+    return
+
+
   def checkpoint(self):
     """
     Save problem state for restart.

Added: short/3D/PyLith/trunk/pylith/utils/ObjectBin.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/ObjectBin.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/utils/ObjectBin.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/utils/ObjectBin.py
+##
+## @brief Python container for a collection of objects.
+##
+## Factory: object_bin
+
+from pyre.components.Component import Component
+
+# ObjectBin class
+class ObjectBin(Component):
+  """
+  Python container for a collection of objects.
+
+  Factory: object_bin
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="objectbin"):
+    """
+    Constructor.
+    """
+    Component.__init__(self, name, facility="object_bin")
+    self.bin = []
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/utils/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/__init__.py	2007-06-02 01:12:38 UTC (rev 7046)
+++ short/3D/PyLith/trunk/pylith/utils/__init__.py	2007-06-02 04:30:16 UTC (rev 7047)
@@ -12,6 +12,8 @@
 
 __all__ = ['CheckpointTimer',
            'CppData',
+           'ObjectBin',
+           'PetscManager',
            'testarray',
            'importing']
 



More information about the cig-commits mailing list