[cig-commits] r7132 - in short/3D/PyLith/trunk: . modulesrc/faults pylith/faults pylith/feassemble pylith/problems unittests/pytests/bc unittests/pytests/faults unittests/pytests/faults/data unittests/pytests/feassemble

brad at geodynamics.org brad at geodynamics.org
Mon Jun 11 15:00:04 PDT 2007


Author: brad
Date: 2007-06-11 15:00:03 -0700 (Mon, 11 Jun 2007)
New Revision: 7132

Added:
   short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3.mesh
   short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_finalslip.spatialdb
   short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_peakrate.spatialdb
   short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_sliptime.spatialdb
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/modulesrc/faults/faults.pyxe.src
   short/3D/PyLith/trunk/pylith/faults/Fault.py
   short/3D/PyLith/trunk/pylith/faults/FaultCohesiveKin.py
   short/3D/PyLith/trunk/pylith/feassemble/Constraint.py
   short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
   short/3D/PyLith/trunk/pylith/problems/Implicit.py
   short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py
   short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py
   short/3D/PyLith/trunk/unittests/pytests/faults/data/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py
   short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py
Log:
Added implements tests to Python integrator and constraint pytests. Implemented Python unit tests for FaultCohesiveKin. Implemented necessary bindings and fixed bugs in Python FaultCohesiveKin.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/TODO	2007-06-11 22:00:03 UTC (rev 7132)
@@ -2,6 +2,10 @@
 MAIN PRIORITIES (Brad)
 ======================================================================
 
+solutioniovtk
+
+  need to write each time step to a different file.
+
 1. Simple tests with analytical solutions
 
    a. 2-D
@@ -22,15 +26,9 @@
 3. Implement faults for kinematic source
    a. Creation of cohesive cells
      Add tests for each possible face as fault (CohesiveDataXXX).
+       Tet
+       Hex
 
-   b. Implement integrator for faults
-
-     ii. FaultCohesiveKin
-       (1) C++ unit tests
-       (2) Python unit tests
-         initialize()
-         adjustTopology()
-
 3. Allow use of all elasticity constants (9 for 2-D, 36 for 3-D).
    a. Materials C++ code
    b. Integrator C++ code
@@ -39,12 +37,12 @@
 4. Implement absorbing boundary conditions
 
 5. Additional unit tests
-  a. FaultCohesive
-    i. Add checking of faultMesh [not currently used]
-
   b. ElasticityExplicit and ElasticityImplicit
     i. multiple materials
 
+  a. FaultCohesive
+    i. Add checking of faultMesh [not currently used]
+
 ======================================================================
 SECONDARY PRIORITIES
 ======================================================================

Modified: short/3D/PyLith/trunk/modulesrc/faults/faults.pyxe.src
===================================================================
--- short/3D/PyLith/trunk/modulesrc/faults/faults.pyxe.src	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/modulesrc/faults/faults.pyxe.src	2007-06-11 22:00:03 UTC (rev 7132)
@@ -273,6 +273,239 @@
     return
 
 
+  def integrateResidual(self, residual, fields, mesh):
+    """
+    Integrate contributions to residual term (r) for operator.
+    """
+    # create shim for method 'integrateResidual'
+    #embed{ void FaultCohesiveKin_integrateResidual(void* objVptr, void* residualVptr, void* fieldsVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != residualVptr);
+      assert(0 != fieldsVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<ALE::Mesh>* mesh =
+        (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ALE::Obj<pylith::real_section_type>* residual =
+        (ALE::Obj<pylith::real_section_type>*) residualVptr;
+      pylith::topology::FieldsManager* fields =
+        (pylith::topology::FieldsManager*) fieldsVptr;
+      ((pylith::faults::FaultCohesiveKin*) objVptr)->integrateResidual(*residual,
+                                                              fields, *mesh);
+    } 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'."
+    FaultCohesiveKin_integrateResidual(self.thisptr, 
+                                 PyCObject_AsVoidPtr(residual),
+                                 ptrFromHandle(fields),
+                                 ptrFromHandle(mesh))
+    return
+
+
+  def integrateJacobian(self, mat, fields, mesh):
+    """
+    Compute contributions to Jacobian matrix (A) associated with operator.
+    """
+    # create shim for method 'integrateJacobian'
+    #embed{ void FaultCohesiveKin_integrateJacobian(void* objVptr, void* matVptr, void* fieldsVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != matVptr);
+      assert(0 != fieldsVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<ALE::Mesh>* mesh =
+        (ALE::Obj<ALE::Mesh>*) meshVptr;
+      PetscMat* mat = (PetscMat*) matVptr;
+      pylith::topology::FieldsManager* fields =
+        (pylith::topology::FieldsManager*) fieldsVptr;
+      ((pylith::faults::FaultCohesiveKin*) objVptr)->integrateJacobian(
+                                                        mat, fields, *mesh);
+    } 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 'mesh' must be extension module type 'Mesh'."
+    FaultCohesiveKin_integrateJacobian(self.thisptr,
+                                 PyCObject_AsVoidPtr(mat),
+                                 ptrFromHandle(fields),
+                                 ptrFromHandle(mesh))
+    return
+
+
+  def updateState(self, field, mesh):
+    """
+    Update state variables as needed.
+    """
+    # create shim for method 'updateState'
+    #embed{ void FaultCohesiveKin_updateState(void* objVptr, void* fieldVptr, void* meshVptr)
+    try {
+      assert(0 != objVptr);
+      assert(0 != fieldVptr);
+      assert(0 != meshVptr);
+      ALE::Obj<pylith::real_section_type>* field =
+        (ALE::Obj<pylith::real_section_type>*) fieldVptr;
+      ALE::Obj<ALE::Mesh>* mesh =
+        (ALE::Obj<ALE::Mesh>*) meshVptr;
+      ((pylith::faults::FaultCohesiveKin*) objVptr)->updateState(*field, *mesh);
+    } 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 'mesh' must be extension module type 'Mesh'."
+    FaultCohesiveKin_updateState(self.thisptr, PyCObject_AsVoidPtr(field),
+                           ptrFromHandle(mesh))
+    return
+
+
+  property quadrature:
+    def __set__(self, q):
+      """
+      Set quadrature.
+      """
+      # create shim for method 'quadrature'
+      #embed{ void FaultCohesiveKin_quadrature_set(void* objVptr, void* qVptr)
+      try {
+        assert(0 != objVptr);
+        pylith::feassemble::Quadrature* quadrature =
+          (pylith::feassemble::Quadrature*) qVptr;
+        ((pylith::faults::FaultCohesiveKin*) objVptr)->quadrature(quadrature);
+      } 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
+      if not q.name == "pylith_feassemble_Quadrature":
+        raise TypeError, \
+              "Argument must be extension module type 'Quadrature'."
+      FaultCohesiveKin_quadrature_set(self.thisptr, ptrFromHandle(q))
+
+
+  property eqsrc:
+    def __set__(self, src):
+      """
+      Set quadrature.
+      """
+      # create shim for method 'eqsrc'
+      #embed{ void FaultCohesiveKin_eqsrc_set(void* objVptr, void* srcVptr)
+      try {
+        assert(0 != objVptr);
+        pylith::faults::EqKinSrc* eqsrc =
+          (pylith::faults::EqKinSrc*) srcVptr;
+        ((pylith::faults::FaultCohesiveKin*) objVptr)->eqsrc(eqsrc);
+      } 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
+      if not src.name == "pylith_faults_EqKinSrc":
+        raise TypeError, \
+              "Argument must be extension module type 'EqKinSrc'."
+      FaultCohesiveKin_eqsrc_set(self.thisptr, ptrFromHandle(src))
+
+
+  property timeStep:
+    def __set__(self, dt):
+      """
+      Set timeStep.
+      """
+      # create shim for method 'timeStep'
+      #embed{ void FaultCohesiveKin_timeStep_set(void* objVptr, double dt)
+      try {
+        assert(0 != objVptr);
+        ((pylith::faults::FaultCohesiveKin*) objVptr)->timeStep(dt);
+      } 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
+      FaultCohesiveKin_timeStep_set(self.thisptr, dt)
+
+
+  property stableTimeStep:
+    def __get__(self):
+      """
+      Get stable time step.
+      """
+      # create shim for method 'stableTimeStep'
+      #embed{ double FaultCohesiveKin_stableTimeStep_get(void* objVptr)
+      double result = 0.0;
+      try {
+        assert(0 != objVptr);
+        result =
+          ((pylith::faults::FaultCohesiveKin*) objVptr)->stableTimeStep();
+      } 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
+      return result;
+      #}embed
+      return FaultCohesiveKin_stableTimeStep_get(self.thisptr)
+
+
+  property needNewJacobian:
+    def __get__(self):
+      """
+      Set timeStep.
+      """
+      # create shim for method 'needNewJacobian'
+      #embed{ int FaultCohesiveKin_needNewJacobian_get(void* objVptr)
+      int result = 0;
+      try {
+        assert(0 != objVptr);
+        ((pylith::faults::FaultCohesiveKin*) objVptr)->needNewJacobian();
+      } 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
+      return result;
+      #}embed
+      return FaultCohesiveKin_needNewJacobian_get(self.thisptr)
+
+
 # ----------------------------------------------------------------------
 cdef class EqKinSrc:
 

Modified: short/3D/PyLith/trunk/pylith/faults/Fault.py
===================================================================
--- short/3D/PyLith/trunk/pylith/faults/Fault.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/pylith/faults/Fault.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -117,20 +117,114 @@
     """
     self._info.log("Initializing fault '%s'." % self.label)
 
-    if 2 != self.quadrature.cell.cellDim:
+    self.quadrature.initialize()
+
+    faultDim = mesh.dimension() - 1
+    if faultDim != self.quadrature.cell.cellDim:
       raise ValueError, \
             "Quadrature is incompatible with fault surface.\n" \
-            "Dimensions for quadrature: %d, dimensions for surface: 2" % \
-            self.quadrature.cell.cellDim
+            "Dimensions for quadrature: %d, dimensions of fault: %d" % \
+            (self.quadrature.cell.cellDim, faultDim)
 
     assert(None != self.cppHandle)
     self.cppHandle.id = self.id
     self.cppHandle.label = self.label
     self.cppHandle.quadrature = self.quadrature.cppHandle
-    self.cppHandle.initialize(mesh.cppHandle, mesh.coordsys.cppHandle)
+    self.cppHandle.initialize(mesh.cppHandle, mesh.coordsys.cppHandle,
+                              self.upDir)
     return
 
 
+  def timeStep(self, dt):
+    """
+    Set time step for advancing from time t to time t+dt.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.timeStep = dt.value
+    return
+
+
+  def stableTimeStep(self):
+    """
+    Get stable time step for advancing from time t to time t+dt.
+    """
+    assert(None != self.cppHandle)
+    from pyre.units.time import second
+    return self.cppHandle.stableTimeStep*second
+
+
+  def integrateResidual(self, residual, fields):
+    """
+    Integrate contributions to residual term at time t.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.integrateResidual(residual, fields.cppHandle,
+                                     self.mesh.cppHandle)
+    return
+
+
+  def needNewJacobian(self):
+    """
+    Returns true if we need to recompute Jacobian matrix for operator,
+    false otherwise.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.needNewJacobian
+
+
+  def integrateJacobian(self, jacobian, fields):
+    """
+    Integrate contributions to Jacobian term at time t.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.integrateJacobian(jacobian, fields.cppHandle,
+                                     self.mesh.cppHandle)
+    return
+
+
+  def updateState(self, field):
+    """
+    Update state variables as needed.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.updateState(field, self.mesh.cppHandle)
+    return
+    
+
+  def setConstraintSizes(self, field):
+    """
+    Set constraint sizes in field.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.setConstraintSizes(field, self.mesh.cppHandle)
+    return
+
+
+  def setConstraints(self, field):
+    """
+    Set constraints for field.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.setConstraints(field, self.mesh.cppHandle)
+    return
+
+
+  def setField(self, t, field):
+    """
+    Set constrained values in field at time t.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.setField(t.value, field, self.mesh.cppHandle)
+    return
+
+
+  def finalize(self):
+    """
+    Cleanup after time stepping.
+    """
+    return
+  
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):
@@ -140,6 +234,7 @@
     Component._configure(self)
     self.id = self.inventory.id
     self.label = self.inventory.label
+    self.upDir = self.inventory.upDir
     self.quadrature = self.inventory.quadrature
     return
 

Modified: short/3D/PyLith/trunk/pylith/faults/FaultCohesiveKin.py
===================================================================
--- short/3D/PyLith/trunk/pylith/faults/FaultCohesiveKin.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/pylith/faults/FaultCohesiveKin.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -48,9 +48,9 @@
     import pyre.inventory
 
     from EqKinSrc import EqKinSrc
-    eqSrc = pyre.inventory.facility("eq_src", family="eq_kinematic_src",
+    eqsrc = pyre.inventory.facility("eq_src", family="eq_kinematic_src",
                                     factory=EqKinSrc)
-    eqSrc.meta['tip'] = "Kinematic earthquake source information."
+    eqsrc.meta['tip'] = "Kinematic earthquake source information."
 
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
@@ -69,11 +69,77 @@
     """
     Initialize cohesive elements.
     """
-    self.eqSrc.initialize()
+    self.mesh = mesh
+    assert(None != self.cppHandle)
+    self.eqsrc.initialize()
+    self.cppHandle.eqsrc = self.eqsrc.cppHandle
     FaultCohesive.initialize(self, mesh)
     return
 
 
+  def timeStep(self, dt):
+    """
+    Set time step for advancing from time t to time t+dt.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.timeStep = dt.value
+    return
+
+
+  def stableTimeStep(self):
+    """
+    Get stable time step for advancing from time t to time t+dt.
+    """
+    assert(None != self.cppHandle)
+    from pyre.units.time import second
+    return self.cppHandle.stableTimeStep*second
+
+
+  def integrateResidual(self, residual, fields):
+    """
+    Integrate contributions to residual term at time t.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.integrateResidual(residual, fields.cppHandle,
+                                     self.mesh.cppHandle)
+    return
+
+
+  def needNewJacobian(self):
+    """
+    Returns true if we need to recompute Jacobian matrix for operator,
+    false otherwise.
+    """
+    assert(None != self.cppHandle)
+    return self.cppHandle.needNewJacobian
+
+
+  def integrateJacobian(self, jacobian, fields):
+    """
+    Integrate contributions to Jacobian term at time t.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.integrateJacobian(jacobian, fields.cppHandle,
+                                     self.mesh.cppHandle)
+    return
+
+
+  def updateState(self, field):
+    """
+    Update state variables as needed.
+    """
+    assert(None != self.cppHandle)
+    self.cppHandle.updateState(field, self.mesh.cppHandle)
+    return
+    
+
+  def finalize(self):
+    """
+    Cleanup after time stepping.
+    """
+    return
+  
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):
@@ -81,7 +147,7 @@
     Setup members using inventory.
     """
     FaultCohesive._configure(self)
-    eqSrc = self.inventory.eqSrc
+    eqsrc = self.inventory.eqsrc
     return
 
   

Modified: short/3D/PyLith/trunk/pylith/feassemble/Constraint.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Constraint.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/pylith/feassemble/Constraint.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -26,7 +26,8 @@
   if not "timeStep" in attrs or \
      not "setConstraintSizes" in attrs or \
      not "setConstraints" in attrs or \
-     not "setField" in attrs:
+     not "setField" in attrs or \
+     not "finalize" in attrs:
     result = False
   return result
 

Modified: short/3D/PyLith/trunk/pylith/feassemble/Integrator.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/pylith/feassemble/Integrator.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -23,11 +23,12 @@
   """
   result = True
   attrs = dir(obj)
-  if not "initQuadrature" in attrs or \
-     not "timeStep" in attrs or \
+  if not "timeStep" in attrs or \
      not "stableTimeStep" in attrs or \
      not "integrateResidual" in attrs or \
-     not "integrateJacobian" in attrs:
+     not "integrateJacobian" in attrs or \
+     not "updateState" in attrs or \
+     not "finalize" in attrs:
     result = False
   return result
 

Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -141,8 +141,6 @@
         integrator.timeStep(dt)
         integrator.integrateJacobian(self.jacobian, self.fields)
       petsc.mat_assemble(self.jacobian)
-    # Put in loop over integrators to see if stiffness needs
-    # reforming.  If so, then reform it.
     return
 
 

Modified: short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/bc/TestDirichlet.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -24,6 +24,16 @@
   Unit testing of Dirichlet object.
   """
 
+  def test_implementsConstraint(self):
+    """
+    Test to make sure Dirichlet satisfies constraint requirements.
+    """
+    bc = Dirichlet()
+    from pylith.feassemble.Constraint import implementsConstraint
+    self.assertTrue(implementsConstraint(bc))
+    return
+    
+
   def test_constructor(self):
     """
     Test constructor.
@@ -124,6 +134,22 @@
     return
 
 
+  def test_finalize(self):
+    """
+    Test finalize().
+
+    WARNING: This is not a rigorous test of finalize() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, bc) = self._initialize()
+
+    bc.finalize()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _initialize(self):

Modified: short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/TestFaultCohesiveKin.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -10,20 +10,42 @@
 # ======================================================================
 #
 
-## @file unittests/pytests/faults/TestFault.py
+## @file unittests/pytests/faults/TestFaultCohesiveKin.py
 
-## @brief Unit testing of Fault object.
+## @brief Unit testing of FaultCohesiveKin object.
 
 import unittest
 
 from pylith.faults.FaultCohesiveKin import FaultCohesiveKin
 
+from spatialdata.geocoords.CSCart import CSCart
+
 # ----------------------------------------------------------------------
 class TestFaultCohesiveKin(unittest.TestCase):
   """
   Unit testing of Fault object.
   """
 
+  def test_implementsIntegrator(self):
+    """
+    Test to make sure FaultCohesiveKin satisfies integrator requirements.
+    """
+    fault = FaultCohesiveKin()
+    from pylith.feassemble.Integrator import implementsIntegrator
+    self.assertTrue(implementsIntegrator(fault))
+    return
+    
+
+  def test_implementsConstraint(self):
+    """
+    Test to make sure FaultCohesiveKin satisfies constraint requirements.
+    """
+    fault = FaultCohesiveKin()
+    from pylith.feassemble.Constraint import implementsConstraint
+    self.assertTrue(implementsConstraint(fault))
+    return
+    
+
   def test_constructor(self):
     """
     Test constructor.
@@ -33,20 +55,235 @@
     return
 
 
+  def test_adjustTopology(self):
+    """
+    Test adjustTopology().
+
+    WARNING: This is not a rigorous test of updateState() because we
+    neither set the input fields or verify the results.
+    """
+    cs = CSCart()
+    cs.spaceDim = 2
+    
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    importer = MeshIOAscii()
+    importer.filename = "data/tri3.mesh"
+    importer.coordsys = cs
+    mesh = importer.read(debug=False, interpolate=False)
+
+    fault = FaultCohesiveKin()
+    fault.id = 10
+    fault.label = "fault"
+
+    fault.adjustTopology(mesh)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
   def test_initialize(self):
     """
     Test initialize().
+
+    WARNING: This is not a rigorous test of updateState() because we
+    neither set the input fields or verify the results.
     """
-    raise NotImplementedError("Unit test not implemented.")
+    (mesh, fault, fields) = self._initialize()
+    
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
     return
 
 
-  def test_adjustTopology(self):
+  def test_timeStep(self):
     """
-    Test adjustTopology().
+    Test timeStep().
     """
-    raise NotImplementedError("Unit test not implemented.")
+    from pyre.units.time import second
+    dt = 2.4*second
+    fault = FaultCohesiveKin()
+    fault.timeStep = dt
+    self.assertEqual(dt, fault.timeStep)
     return
 
+  
+  def test_stableTimeStep(self):
+    """
+    Test stableTimeStep().
+    """
+    from pyre.units.time import second
+    dt = 2.3*second
+    fault = FaultCohesiveKin()
+    fault.timeStep(dt)
+    self.assertEqual(dt, fault.stableTimeStep())
+    return
 
+  
+  def test_needNewJacobian(self):
+    """
+    Test needNewJacobian().
+    """
+    fault = FaultCohesiveKin()
+    self.assertEqual(False, fault.needNewJacobian())
+    return
+
+  
+  def test_integrateResidual(self):
+    """
+    Test integrateResidual().
+
+    WARNING: This is not a rigorous test of integrateResidual() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    residual = fields.getReal("residual")
+    fault.integrateResidual(residual, fields)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+  
+  def test_integrateJacobian(self):
+    """
+    Test integrateJacobian().
+
+    WARNING: This is not a rigorous test of integrateJacobian() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    jacobian = mesh.createMatrix(fields.getReal("residual"))
+    import pylith.utils.petsc as petsc
+    petsc.mat_setzero(jacobian)
+    fault.integrateJacobian(jacobian, fields)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+  
+  def test_updateState(self):
+    """
+    Test updateState().
+
+    WARNING: This is not a rigorous test of updateState() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    dispT = fields.getReal("dispT")
+    fault.updateState(dispT)
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+  
+
+  def test_finalize(self):
+    """
+    Test finalize().
+
+    WARNING: This is not a rigorous test of finalize() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    fault.finalize()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _initialize(self):
+    """
+    Initialize fault.
+    """
+    from pyre.units.time import second
+    dt = 1.0*second
+    
+    # Setup mesh
+    cs = CSCart()
+    cs.spaceDim = 2
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    importer = MeshIOAscii()
+    importer.filename = "data/tri3.mesh"
+    importer.coordsys = cs
+    mesh = importer.read(debug=False, interpolate=False)
+
+    # Setup quadrature
+    from pylith.feassemble.FIATSimplex import FIATSimplex
+    cell = FIATSimplex()
+    cell.shape = "line"
+    cell.degree = 1
+    cell.order = 1
+    from pylith.feassemble.quadrature.Quadrature1Din2D import Quadrature1Din2D
+    quadrature = Quadrature1Din2D()
+    quadrature.cell = cell
+
+    # Setup earthquake source
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    ioFinalSlip = SimpleIOAscii()
+    ioFinalSlip.filename = "data/tri3_finalslip.spatialdb"
+    dbFinalSlip = SimpleDB()
+    dbFinalSlip.iohandler = ioFinalSlip
+    dbFinalSlip.label = "final slip"
+    
+    ioSlipTime = SimpleIOAscii()
+    ioSlipTime.filename = "data/tri3_sliptime.spatialdb"
+    dbSlipTime = SimpleDB()
+    dbSlipTime.iohandler = ioSlipTime
+    dbSlipTime.label = "slip time"
+    
+    ioPeakRate = SimpleIOAscii()
+    ioPeakRate.filename = "data/tri3_peakrate.spatialdb"
+    dbPeakRate = SimpleDB()
+    dbPeakRate.iohandler = ioPeakRate
+    dbPeakRate.label = "peak rate"
+    
+    from pylith.faults.BruneSlipFn import BruneSlipFn
+    slipfn = BruneSlipFn()
+    slipfn.slip = dbFinalSlip
+    slipfn.slipTime = dbSlipTime
+    slipfn.slipRate = dbPeakRate
+
+    from pylith.faults.EqKinSrc import EqKinSrc
+    eqsrc = EqKinSrc()
+    eqsrc.slipfn = slipfn
+
+    # Setup fault
+    fault = FaultCohesiveKin()
+    fault.id = 10
+    fault.label = "fault"
+    fault.upDir = [0, 0, 1]
+    fault.quadrature = quadrature
+    fault.eqsrc = eqsrc
+    fault.timeStep(dt)
+    fault.adjustTopology(mesh)
+    fault.initialize(mesh)
+
+    # Setup fields
+    from pylith.topology.FieldsManager import FieldsManager
+    fields = FieldsManager(mesh)
+    fields.addReal("residual")
+    fields.addReal("dispTpdt")
+    fields.addReal("dispT")
+    fields.addReal("dispTmdt")
+    fields.createHistory(["dispTpdt", "dispT", "dispTmdt"])
+    fields.setFiberDimension("residual", cs.spaceDim)
+    fields.allocate("residual")
+    fields.copyLayout("residual")
+
+    import pylith.topology.topology as bindings
+    bindings.zeroRealSection(fields.getReal("residual"))
+    
+    return (mesh, fault, fields)
+
+
 # End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/faults/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/data/Makefile.am	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/data/Makefile.am	2007-06-11 22:00:03 UTC (rev 7132)
@@ -10,20 +10,23 @@
 # ----------------------------------------------------------------------
 #
 
-noinst_DATA =
+noinst_DATA = \
+	tri3.mesh \
+	tri3_finalslip.spatialdb \
+	tri3_sliptime.spatialdb \
+	tri3_peakrate.spatialdb
 
 noinst_TMP =
 
 # 'export' the input files by performing a mock install
-export_datadir = $(top_builddir)/unittests/pytests/materials/data
+export_datadir = $(top_builddir)/unittests/pytests/faults/data
 export-data: $(noinst_DATA)
 	for f in $(noinst_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done
 
 BUILT_SOURCES = export-data
 
 CLEANFILES = \
-	$(export_datadir)/$(noinst_DATA) \
-	$(export_datadir)/$(noinst_TMP)
+	$(export_datadir)/$(noinst_DATA)
 
 
 # End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3.mesh
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3.mesh	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3.mesh	2007-06-11 22:00:03 UTC (rev 7132)
@@ -0,0 +1,45 @@
+mesh = {
+  dimension = 2
+  use-index-zero = true
+  vertices = {
+    dimension = 2
+    count = 4
+    coordinates = {
+             0     -1.0  0.0
+             1      0.0  1.0
+             2      0.0 -1.0
+             3      1.0  0.0
+    }
+  }
+  cells = {
+    count = 2
+    num-corners = 3
+    simplices = {
+             0       0  2  1
+             1       1  2  3
+    }
+    material-ids = {
+             0   0
+             1   0
+    }
+  }
+  group = {
+    name = fault
+    type = vertices
+    count = 2
+    indices = {
+      1
+      2
+    }
+  }
+  group = {
+    name = output
+    type = vertices
+    count = 3
+    indices = {
+      1
+      2
+      3
+    }
+  }
+}

Added: short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_finalslip.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_finalslip.spatialdb	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_finalslip.spatialdb	2007-06-11 22:00:03 UTC (rev 7132)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 2
+  value-names =  slip fault-opening
+  value-units =  m   m
+  num-locs = 2
+  data-dim = 1
+  space-dim = 2
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 2
+  }
+}
+0.0  +1.0   2.3   0.1
+0.0  -1.0   2.4   0.2

Added: short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_peakrate.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_peakrate.spatialdb	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_peakrate.spatialdb	2007-06-11 22:00:03 UTC (rev 7132)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 1
+  value-names =  slip-rate
+  value-units =  m/s
+  num-locs = 2
+  data-dim = 1
+  space-dim = 2
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 2
+  }
+}
+0.0  +1.0   1.4
+0.0  -1.0   1.5

Added: short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_sliptime.spatialdb
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_sliptime.spatialdb	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/faults/data/tri3_sliptime.spatialdb	2007-06-11 22:00:03 UTC (rev 7132)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 1
+  value-names =  slip-time
+  value-units =  s
+  num-locs = 2
+  data-dim = 1
+  space-dim = 2
+  cs-data = cartesian {
+    to-meters = 1.0
+    space-dim = 2
+  }
+}
+0.0  +1.0    1.2
+0.0  -1.0    1.3

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityExplicit.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -25,6 +25,16 @@
   Unit testing of Python ElasticityExplicit object.
   """
 
+  def test_implementsIntegrator(self):
+    """
+    Test to make sure ElasticityExplicit satisfies integrator requirements.
+    """
+    integrator = ElasticityExplicit()
+    from pylith.feassemble.Integrator import implementsIntegrator
+    self.assertTrue(implementsIntegrator(integrator))
+    return
+    
+
   def test_initQuadrature(self):
     """
     Test initQuadrature().
@@ -159,6 +169,22 @@
     return
   
 
+  def test_finalize(self):
+    """
+    Test finalize().
+
+    WARNING: This is not a rigorous test of finalize() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, integrator, fields) = self._initialize()
+
+    integrator.finalize()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _initialize(self):

Modified: short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py	2007-06-11 21:01:01 UTC (rev 7131)
+++ short/3D/PyLith/trunk/unittests/pytests/feassemble/TestElasticityImplicit.py	2007-06-11 22:00:03 UTC (rev 7132)
@@ -25,6 +25,16 @@
   Unit testing of Python ElasticityImplicit object.
   """
 
+  def test_implementsIntegrator(self):
+    """
+    Test to make sure ElasticityImplicit satisfies integrator requirements.
+    """
+    integrator = ElasticityImplicit()
+    from pylith.feassemble.Integrator import implementsIntegrator
+    self.assertTrue(implementsIntegrator(integrator))
+    return
+    
+
   def test_initQuadrature(self):
     """
     Test initQuadrature().
@@ -159,6 +169,22 @@
     return
   
 
+  def test_finalize(self):
+    """
+    Test finalize().
+
+    WARNING: This is not a rigorous test of finalize() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, integrator, fields) = self._initialize()
+
+    integrator.finalize()
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly.
+    return
+
+
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _initialize(self):



More information about the cig-commits mailing list