[cig-commits] r7029 - in short/3D/PyLith/trunk: . modulesrc/materials modulesrc/topology pylith pylith/materials pylith/problems unittests/pytests/materials

brad at geodynamics.org brad at geodynamics.org
Fri Jun 1 08:43:30 PDT 2007


Author: brad
Date: 2007-06-01 08:43:29 -0700 (Fri, 01 Jun 2007)
New Revision: 7029

Added:
   short/3D/PyLith/trunk/pylith/materials/ElasticMaterial.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/modulesrc/materials/materials.pyxe.src
   short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py
   short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStrain.py
   short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStress.py
   short/3D/PyLith/trunk/pylith/materials/ElasticStrain1D.py
   short/3D/PyLith/trunk/pylith/materials/ElasticStress1D.py
   short/3D/PyLith/trunk/pylith/materials/Material.py
   short/3D/PyLith/trunk/pylith/materials/MaxwellIsotropic3D.py
   short/3D/PyLith/trunk/pylith/materials/__init__.py
   short/3D/PyLith/trunk/pylith/problems/Implicit.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStrain.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStress.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStrain1D.py
   short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStress1D.py
Log:
Added useElasticBehavior() method to Python elastic materials and ElasticMaterial binding. Finished implementation of implicit formulation (added use of useElasticBehavior() and updating displacement fields).

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/TODO	2007-06-01 15:43:29 UTC (rev 7029)
@@ -2,14 +2,6 @@
 MAIN PRIORITIES (Brad)
 ======================================================================
 
-topology module
-  add section->add(fieldA, fieldB)
-
-Implicit.py
-  use section->add(fieldA, fieldB)
-
-Add useElasticBehavior() switches to Implicit::solveElastic().
-
 1. Unit tests for Integrator stuff.
 
   a. Add unit test for IntegratorElasticity::calcTotalStrain

Modified: short/3D/PyLith/trunk/modulesrc/materials/materials.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/materials/materials.pyxe.src	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/modulesrc/materials/materials.pyxe.src	2007-06-01 15:43:29 UTC (rev 7029)
@@ -246,6 +246,27 @@
     return
 
 
+  property useElasticBehavior:
+    def __set__(self, value):
+      """
+      Set useElasticBehavior flag.
+      """
+      # create shim for method 'useElasticBehavior'
+      #embed{ void Material_useElasticBehavior_set(void* objVptr, int value)
+      try {
+        assert(0 != objVptr);
+        ((pylith::materials::ElasticMaterial*) objVptr)->useElasticBehavior(value);
+      } catch (const std::exception& err) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        const_cast<char*>(err.what()));
+      } catch (...) {
+        PyErr_SetString(PyExc_RuntimeError,
+                        "Caught unknown C++ exception.");
+      } // try/catch
+      #}embed
+      Material_useElasticBehavior_set(self.thisptr, value)
+
+
 # ----------------------------------------------------------------------
 cdef class ElasticStrain1D(ElasticMaterial):
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/modulesrc/topology/topology.pyxe.src	2007-06-01 15:43:29 UTC (rev 7029)
@@ -797,11 +797,9 @@
   """
   # create shim for zero section
   #embed{ void* Section_zero(void* objVptr)
-  typedef ALE::Mesh::real_section_type real_section_type;
-  
   try {
-    ALE::Obj<real_section_type>* section =
-      (ALE::Obj<real_section_type>*) objVptr;
+    ALE::Obj<pylith::real_section_type>* section =
+      (ALE::Obj<pylith::real_section_type>*) objVptr;
     assert(!section->isNull());
     (*section)->zero();
   } catch (const std::exception& err) {
@@ -821,4 +819,39 @@
   return
 
 
+# ----------------------------------------------------------------------
+def addRealSections(dst, srcA, srcB):
+  """
+  Add two sections, storing result in third section.
+  """
+  # create shim for Field::add()
+  #embed{ void* Section_addRealSections(void* objVptr, void* aVptr, void* bVptr)
+  try {
+    ALE::Obj<pylith::real_section_type>* dst =
+      (ALE::Obj<pylith::real_section_type>*) objVptr;
+    assert(!dst->isNull());
+    ALE::Obj<pylith::real_section_type>* a =
+      (ALE::Obj<pylith::real_section_type>*) aVptr;
+    assert(!a->isNull());
+    ALE::Obj<pylith::real_section_type>* b =
+      (ALE::Obj<pylith::real_section_type>*) bVptr;
+    assert(!b->isNull());
+    (*dst)->add(*a, *b);
+  } 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
+  Section_addRealSections(PyCObject_AsVoidPtr(dst),
+                          PyCObject_AsVoidPtr(srcA),
+                          PyCObject_AsVoidPtr(srcB))
+  return
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2007-06-01 15:43:29 UTC (rev 7029)
@@ -44,6 +44,7 @@
 	feassemble/quadrature/Quadrature3D.py \
 	feassemble/quadrature/__init__.py \
 	materials/__init__.py \
+	materials/ElasticMaterial.py \
 	materials/ElasticIsotropic3D.py \
 	materials/ElasticPlaneStrain.py \
 	materials/ElasticPlaneStress.py \

Modified: short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticIsotropic3D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -16,13 +16,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-# import pylith.materials.materials as bindings
-
-
 # ElasticIsotropic3D class
-class ElasticIsotropic3D(Material):
+class ElasticIsotropic3D(ElasticMaterial):
   """
   Python object implementing 3-D isotropic linear elastic material.
 
@@ -35,7 +32,7 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
     import pylith.materials.materials as bindings
     self.cppHandle = bindings.ElasticIsotropic3D()
     self.dimension = self.cppHandle.dimension

Added: short/3D/PyLith/trunk/pylith/materials/ElasticMaterial.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticMaterial.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticMaterial.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/materials/ElasticMaterial.py
+##
+## @brief Python abstract base class for managing physical properties
+## of an elastic material.
+##
+## Factory: material
+
+from Material import Material
+
+# ElasticMaterial class
+class ElasticMaterial(Material):
+  """
+  Python abstract base class for managing physical properties of an
+  elastic material.
+
+  Factory: material
+  """
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="elasticmaterial"):
+    """
+    Constructor.
+    """
+    Material.__init__(self, name)
+    return
+
+
+  def useElasticBehavior(self, flag):
+    """
+    Set useElasticBehavior flag (True=elastic, False=inelastic if applicable).
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.useElasticBehavior = flag
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Setup members using inventory.
+    """
+    Material._configure(self)
+    return
+
+  
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStrain.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStrain.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStrain.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -17,13 +17,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-import pylith.materials.materials as bindings
-
-
 # ElasticPlaneStrain class
-class ElasticPlaneStrain(Material):
+class ElasticPlaneStrain(ElasticMaterial):
   """
   Python object implementing 2-D isotropic linear elastic material for
   plane strain.
@@ -37,7 +34,8 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
+    import pylith.materials.materials as bindings
     self.cppHandle = bindings.ElasticPlaneStrain()
     self.dimension = self.cppHandle.dimension
     return

Modified: short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStress.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStress.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticPlaneStress.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -17,13 +17,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-import pylith.materials.materials as bindings
-
-
 # ElasticPlaneStress class
-class ElasticPlaneStress(Material):
+class ElasticPlaneStress(ElasticMaterial):
   """
   Python object implementing 2-D isotropic linear elastic material for
   plane stress.
@@ -37,7 +34,8 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
+    import pylith.materials.materials as bindings
     self.cppHandle = bindings.ElasticPlaneStress()
     self.dimension = self.cppHandle.dimension
     return

Modified: short/3D/PyLith/trunk/pylith/materials/ElasticStrain1D.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticStrain1D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticStrain1D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -17,13 +17,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-import pylith.materials.materials as bindings
-
-
 # ElasticStrain1D class
-class ElasticStrain1D(Material):
+class ElasticStrain1D(ElasticMaterial):
   """
   Python object implementing 1-D linear elastic material with axial strain.
 
@@ -36,7 +33,8 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
+    import pylith.materials.materials as bindings
     self.cppHandle = bindings.ElasticStrain1D()
     self.dimension = self.cppHandle.dimension
     return

Modified: short/3D/PyLith/trunk/pylith/materials/ElasticStress1D.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/ElasticStress1D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/ElasticStress1D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -17,13 +17,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-import pylith.materials.materials as bindings
-
-
 # ElasticStress1D class
-class ElasticStress1D(Material):
+class ElasticStress1D(ElasticMaterial):
   """
   Python object implementing 1-D linear elastic material with axial stress.
 
@@ -36,7 +33,8 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
+    import pylith.materials.materials as bindings
     self.cppHandle = bindings.ElasticStress1D()
     self.dimension = self.cppHandle.dimension
     return

Modified: short/3D/PyLith/trunk/pylith/materials/Material.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/Material.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/Material.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -104,6 +104,7 @@
             (mesh.dimension(), self.dimension)
 
     self.db.initialize()
+    assert(None != self.cppHandle)
     self.cppHandle.id = self.id
     self.cppHandle.label = self.label
     self.cppHandle.db = self.db.cppHandle

Modified: short/3D/PyLith/trunk/pylith/materials/MaxwellIsotropic3D.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/MaxwellIsotropic3D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/MaxwellIsotropic3D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -16,13 +16,10 @@
 ##
 ## Factory: material.
 
-from Material import Material
+from ElasticMaterial import ElasticMaterial
 
-# import pylith.materials.materials as bindings
-
-
 # MaxwellIsotropic3D class
-class MaxwellIsotropic3D(Material):
+class MaxwellIsotropic3D(ElasticMaterial):
   """
   Python object implementing 3-D isotropic linear Maxwell viscoelastic material.
 
@@ -35,7 +32,7 @@
     """
     Constructor.
     """
-    Material.__init__(self, name)
+    ElasticMaterial.__init__(self, name)
     import pylith.materials.materials as bindings
     self.cppHandle = bindings.MaxwellIsotropic3D()
     self.dimension = self.cppHandle.dimension

Modified: short/3D/PyLith/trunk/pylith/materials/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/__init__.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/materials/__init__.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -14,14 +14,16 @@
 
 ## @brief Python PyLith materials module initialization
 
-__all__ = ['ElasticIsotropic3D',
+__all__ = ['ElasticMaterial',
+           'ElasticIsotropic3D',
            'ElasticPlaneStrain',
            'ElasticPlaneStress',
            'ElasticStrain1D',
            'ElasticStress1D',
            'Homogeneous',
            'Material',
-           'MaterialsBin']
+           'MaterialsBin',
+           'MaxwellIsotropic3D']
 
 
 # End of file

Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -103,7 +103,7 @@
     self.jacobian = mesh.createMatrix(self.fields.getReal("dispT"))
 
     from pyre.units.time import s
-    self._solveElastic(mesh, t=0.0*s, dt=dt)
+    self._solveElastic(mesh, materials, t=0.0*s, dt=dt)
 
     self.solver.initialize(mesh, self.fields.getReal("dispIncr"))
     return
@@ -174,18 +174,15 @@
     # t+dt.  The displacement increments computed from the residual
     # are then added to this to give us the total displacement field
     # at time t+dt.
+    import pylith.topology.topology as bindings
+    dispT = self.fields.getReal("dispT")
+    dispTBctpdt = self.fields.getReal("dispTBctpdt")
+    bindings.addRealSections(dispT, dispTBctpdt,
+                             self.fields.getReal("dispIncr"))
 
-    # Need a real way to do the operation below.
-    print "MISSING: UPDATING OF DISP"
-    # self.dispT = self.dispTBctpdt + self.dispIncr
-    self.fields.shiftHistory()
-
     self._info.log("Updating integrators states.")
     for integrator in self.integrators:
-      integrator.updateState(self.fields.getReal("dispT"))
-    # call update state here.
-    # This will recompute stresses and state variables.
-    # Need to loop over integrators, and put this into integrator.
+      integrator.updateState(dispT)
     return
 
 
@@ -199,35 +196,47 @@
     return
 
 
-  def _solveElastic(self, mesh, t, dt):
+  def _solveElastic(self, mesh, materials, t, dt):
     """
     Solve for elastic solution.
     """
     self._info.log("Computing elastic solution.")
 
+    for material in materials.materials:
+      material.useElasticBehavior(True)
+
     self._info.log("Setting constraints.")
-    dispT = self.fields.getReal("dispT")
+    dispTBctpdt = self.fields.getReal("dispTBctpdt")
     import pylith.topology.topology as bindings
-    bindings.zeroRealSection(dispT)
+    bindings.zeroRealSection(dispTBctpdt)
     for constraint in self.constraints:
-      constraint.setField(t, dispT)
+      constraint.setField(t, dispTBctpdt)
 
     self._info.log("Integrating Jacobian and residual of operator.")
     import pylith.utils.petsc as petsc
     petsc.mat_setzero(self.jacobian)
+    residual = self.fields.getReal("residual")
+    dispIncr = self.fields.getReal("dispIncr")
     for integrator in self.integrators:
       integrator.timeStep(dt)
       integrator.integrateJacobian(self.jacobian, self.fields)
-      integrator.integrateResidual(self.fields.getReal("dispT"),
-                                   self.fields)
+      integrator.integrateResidual(residual, self.fields)
     import pylith.utils.petsc as petsc
     petsc.mat_assemble(self.jacobian)
 
-    self.solver.initialize(mesh, dispT)
+    self.solver.initialize(mesh, dispIncr)
 
     self._info.log("Solving equations.")
-    self.solver.solve(dispT, self.jacobian, self.fields.getReal("residual"))
+    self.solver.solve(dispIncr, self.jacobian, residual)
 
+    import pylith.topology.topology as bindings
+    dispT = self.fields.getReal("dispT")
+    dispTBctpdt = self.fields.getReal("dispTBctpdt")
+    bindings.addRealSections(dispT, dispTBctpdt, dispIncr)
+
+    self._info.log("Updating integrators states.")
+    for integrator in self.integrators:
+      integrator.updateState(dispT)
     return
   
 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticIsotropic3D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -44,4 +44,13 @@
     return
 
 
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    material = ElasticIsotropic3D()
+    material.useElasticBehavior(False)
+    return
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStrain.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStrain.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStrain.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -43,4 +43,13 @@
     return
 
 
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    material = ElasticPlaneStrain()
+    material.useElasticBehavior(False)
+    return
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStress.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStress.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticPlaneStress.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -43,4 +43,13 @@
     return
 
 
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    material = ElasticPlaneStress()
+    material.useElasticBehavior(False)
+    return
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStrain1D.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStrain1D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStrain1D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -43,4 +43,13 @@
     return
 
 
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    material = ElasticStrain1D()
+    material.useElasticBehavior(False)
+    return
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStress1D.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStress1D.py	2007-06-01 04:25:18 UTC (rev 7028)
+++ short/3D/PyLith/trunk/unittests/pytests/materials/TestElasticStress1D.py	2007-06-01 15:43:29 UTC (rev 7029)
@@ -43,4 +43,13 @@
     return
 
 
+  def test_useElasticBehavior(self):
+    """
+    Test useElasticBehavior().
+    """
+    material = ElasticStress1D()
+    material.useElasticBehavior(False)
+    return
+
+
 # End of file 



More information about the cig-commits mailing list