[cig-commits] r20028 - in short/3D/PyLith/branches/v1.7-trunk: libsrc/pylith/faults modulesrc/faults pylith/faults unittests/pytests/faults unittests/pytests/faults/data

brad at geodynamics.org brad at geodynamics.org
Thu May 3 09:21:16 PDT 2012


Author: brad
Date: 2012-05-03 09:21:15 -0700 (Thu, 03 May 2012)
New Revision: 20028

Added:
   short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/TestFaultCohesiveImpulses.py
   short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/tri3_impulses.spatialdb
Modified:
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.cc
   short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.hh
   short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/FaultCohesiveImpulses.i
   short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/faults.i
   short/3D/PyLith/branches/v1.7-trunk/pylith/faults/FaultCohesiveImpulses.py
   short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/Makefile.am
   short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/Makefile.am
   short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/testfaults.py
Log:
Added Python unit tests for FaultCohesiveImpulses. Fixed bugs in Python/C++ interface for FaultCohesiveImpulses.

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.cc
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.cc	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.cc	2012-05-03 16:21:15 UTC (rev 20028)
@@ -101,7 +101,7 @@
 // ----------------------------------------------------------------------
 // Set threshold for nonzero impulse amplitude.
 void
-pylith::faults::FaultCohesiveImpulses::threshold(const double value)
+pylith::faults::FaultCohesiveImpulses::threshold(const PylithScalar value)
 { // threshold
   if (value < 0) {
     std::ostringstream msg;

Modified: short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.hh
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.hh	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/libsrc/pylith/faults/FaultCohesiveImpulses.hh	2012-05-03 16:21:15 UTC (rev 20028)
@@ -70,7 +70,7 @@
    *
    * @param value Threshold for detecting nonzero amplitude.
    */
-  void threshold(const double value);
+  void threshold(const PylithScalar value);
 
   /** Get number of impulses.
    *

Modified: short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/FaultCohesiveImpulses.i
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/FaultCohesiveImpulses.i	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/FaultCohesiveImpulses.i	2012-05-03 16:21:15 UTC (rev 20028)
@@ -51,14 +51,19 @@
        * @param flags Array of indices for degrees of freedom.
        * @param size Size of array
        */
+      %apply(int* INPLACE_ARRAY1, int DIM1) {
+	(const int* flags, 
+	 const int size)
+	  };
       void impulseDOF(const int* flags,
 		      const int size);  
+      %clear(const int* flags, const int size);
       
       /** Set threshold for nonzero impulse amplitude.
        *
        * @param value Threshold for detecting nonzero amplitude.
        */
-      void threshold(const double value);
+      void threshold(const PylithScalar value);
       
       /** Get number of impulses.
        *
@@ -108,6 +113,16 @@
 	vertexField(const char* name,
 		    const pylith::topology::SolutionFields* fields =0);
       
+      /** Get cell field associated with integrator.
+       *
+       * @param name Name of cell field.
+       * @param fields Solution fields.
+       * @returns Cell field.
+       */
+      const pylith::topology::Field<pylith::topology::SubMesh>&
+      cellField(const char* name,
+		const pylith::topology::SolutionFields* fields =0);
+
     }; // class FaultCohesiveImpulses
 
   } // faults

Modified: short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/faults.i
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/faults.i	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/modulesrc/faults/faults.i	2012-05-03 16:21:15 UTC (rev 20028)
@@ -33,6 +33,7 @@
 #include "pylith/faults/FaultCohesiveLagrange.hh"
 #include "pylith/faults/FaultCohesiveKin.hh"
 #include "pylith/faults/FaultCohesiveDyn.hh"
+#include "pylith/faults/FaultCohesiveImpulses.hh"
 #include "pylith/faults/FaultCohesiveTract.hh"
 
 #include "pylith/topology/SubMesh.hh"
@@ -85,6 +86,7 @@
 %include "FaultCohesiveLagrange.i"
 %include "FaultCohesiveKin.i"
 %include "FaultCohesiveDyn.i"
+%include "FaultCohesiveImpulses.i"
 %include "FaultCohesiveTract.i"
 
 // End of file

Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/faults/FaultCohesiveImpulses.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/faults/FaultCohesiveImpulses.py	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/faults/FaultCohesiveImpulses.py	2012-05-03 16:21:15 UTC (rev 20028)
@@ -77,8 +77,12 @@
   impulseDOF = pyre.inventory.list("impulse_dof", default=[], validator=validateDOF)
   impulseDOF.meta['tip'] = "Indices of impulse components " \
       "(0=1st DOF, 1=2nd DOF, etc)."
+
+  from spatialdata.spatialdb.SimpleDB import SimpleDB
+  dbImpulseAmp = pyre.inventory.facility("db_impulse_amplitude", family="spatial_database", factory=SimpleDB)
+  dbImpulseAmp.meta['tip'] = "Amplitude of slip impulses."
   
-  from pylith.meshio.OutputFaultKin import OutputFaultImpulses
+  from pylith.meshio.OutputFaultImpulses import OutputFaultImpulses
   output = pyre.inventory.facility("output", family="output_manager",
                                    factory=OutputFaultImpulses)
   output.meta['tip'] = "Output manager associated with fault data."
@@ -201,11 +205,14 @@
     """
     Setup members using inventory.
     """
+    import numpy
     FaultCohesive._configure(self)
     self.output = self.inventory.output
 
-    ModuleFaultCohesiveImpulses.threshold(self, self.inventory.threshold)
-    ModuleFaultCohesiveImpulses.impulseDOF(self, self.inventory.impulseDOF)
+    ModuleFaultCohesiveImpulses.threshold(self, self.inventory.threshold.value)
+    impulseDOF = numpy.array(self.inventory.impulseDOF, dtype=numpy.int32)
+    ModuleFaultCohesiveImpulses.impulseDOF(self, impulseDOF)
+    ModuleFaultCohesiveImpulses.dbImpulseAmp(self, self.inventory.dbImpulseAmp)
     return
 
 

Modified: short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/Makefile.am	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/Makefile.am	2012-05-03 16:21:15 UTC (rev 20028)
@@ -32,6 +32,7 @@
 	TestEqKinSrc.py \
 	TestFaultCohesiveKin.py \
 	TestFaultCohesiveDyn.py \
+	TestFaultCohesiveImpulses.py \
 	TestLiuCosSlipFn.py \
 	TestSingleRupture.py \
 	TestStepSlipFn.py \

Added: short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/TestFaultCohesiveImpulses.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/TestFaultCohesiveImpulses.py	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/TestFaultCohesiveImpulses.py	2012-05-03 16:21:15 UTC (rev 20028)
@@ -0,0 +1,350 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/faults/TestFaultCohesiveImpulses.py
+
+## @brief Unit testing of FaultCohesiveImpulses object.
+
+import unittest
+
+from pylith.faults.FaultCohesiveImpulses import FaultCohesiveImpulses
+
+from spatialdata.geocoords.CSCart import CSCart
+from pyre.units.time import second
+
+# ----------------------------------------------------------------------
+class TestFaultCohesiveImpulses(unittest.TestCase):
+  """
+  Unit testing of Fault object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    fault = FaultCohesiveImpulses()
+    return
+
+
+  def test_configure(self):
+    """
+    Test _configure().
+    """
+    fault = FaultCohesiveImpulses()
+    fault.inventory.faultLabel = "fault group"
+    fault._configure()
+    return
+
+
+  def test_implementsIntegrator(self):
+    """
+    Test to make sure FaultCohesiveImpulses satisfies integrator requirements.
+    """
+    fault = FaultCohesiveImpulses()
+    from pylith.feassemble.Integrator import implementsIntegrator
+    self.failUnless(implementsIntegrator(fault))
+    return
+    
+
+  def test_useFaultMesh(self):
+    """
+    Test useFaultMesh().
+    """
+    fault = FaultCohesiveImpulses()
+    fault.inventory.faultLabel = "fault group"
+    fault._configure()
+
+    fault.useFaultMesh(True);
+
+    # No test of result
+    return
+
+
+  def test_faultMeshFilename(self):
+    """
+    Test faultMeshFilename().
+    """
+    fault = FaultCohesiveImpulses() 
+    fault.inventory.faultLabel = "fault group"
+    fault._configure()
+
+    filename = "SanAndreas.inp"
+    fault.faultMeshFilename(filename)
+
+    # No test of result
+    return
+
+
+  def test_adjustTopology(self):
+    """
+    Test adjustTopology().
+
+    WARNING: This is not a rigorous test of adjustTopology() because we
+    neither set the input fields or verify the results.
+    """
+    cs = CSCart()
+    cs.inventory.spaceDim = 2
+    cs._configure()
+    
+    from spatialdata.units.Nondimensional import Nondimensional
+    normalizer = Nondimensional()
+    normalizer._configure()
+
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    importer = MeshIOAscii()
+    importer.inventory.filename = "data/tri3.mesh"
+    importer.inventory.coordsys = cs
+    importer._configure()
+    mesh = importer.read(debug=False, interpolate=False)
+
+    fault = FaultCohesiveImpulses()
+    fault.inventory.matId = 10
+    fault.inventory.faultLabel = "fault"
+    fault._configure()
+
+    nvertices = fault.numVerticesNoMesh(mesh)
+    firstFaultVertex = 0
+    firstLagrangeVertex = nvertices
+    firstFaultCell      = 2*nvertices
+    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
+                         firstFaultCell)
+
+    # 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 initialize() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+    
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+
+  def test_timeStep(self):
+    """
+    Test timeStep().
+    """
+    dt = 2.4
+    (mesh, fault, fields) = self._initialize()
+    fault.timeStep(dt)
+
+    # No test of result
+    return
+
+  
+  def test_stableTimeStep(self):
+    """
+    Test stableTimeStep().
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    from pylith.utils.utils import maxscalar
+    self.assertAlmostEqual(1.0, fault.stableTimeStep(mesh)/maxscalar(), 7)
+    return
+
+  
+  def test_needNewJacobian(self):
+    """
+    Test needNewJacobian().
+    """
+    (mesh, fault, fields) = self._initialize()
+    self.assertEqual(True, 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.get("residual")
+    t = 1.0
+    fault.integrateResidual(residual, t, 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()
+
+    from pylith.topology.Jacobian import Jacobian
+    jacobian = Jacobian(fields.solution())
+    jacobian.zero()
+    t = 1.0
+    fault.integrateJacobian(jacobian, t, fields)
+    self.assertEqual(False, fault.needNewJacobian())
+
+    # We should really add something here to check to make sure things
+    # actually initialized correctly    
+    return
+
+  
+  def test_poststep(self):
+    """
+    Test poststep().
+
+    WARNING: This is not a rigorous test of poststep() because we
+    neither set the input fields or verify the results.
+    """
+    (mesh, fault, fields) = self._initialize()
+
+    t = 0.50
+    residual = fields.get("residual")
+    fault.integrateResidual(residual, t, fields)
+
+    dt = 0.1
+    totalTime = 5
+    fault.poststep(t, dt, fields)
+
+    # 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
+
+
+  def test_factory(self):
+    """
+    Test factory method.
+    """
+    from pylith.faults.FaultCohesiveImpulses import fault
+    f = fault()
+    return
+
+
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _initialize(self):
+    """
+    Initialize fault.
+    """
+    dt = 2.4
+    
+    from spatialdata.units.Nondimensional import Nondimensional
+    normalizer = Nondimensional()
+    normalizer._configure()
+
+    # Setup mesh
+    cs = CSCart()
+    cs.inventory.spaceDim = 2
+    cs._configure()
+
+    from pylith.meshio.MeshIOAscii import MeshIOAscii
+    importer = MeshIOAscii()
+    importer.inventory.filename = "data/tri3.mesh"
+    importer.inventory.coordsys = cs
+    importer._configure()
+    mesh = importer.read(debug=False, interpolate=False)
+
+    # Setup quadrature
+    from pylith.feassemble.FIATSimplex import FIATSimplex
+    cell = FIATSimplex()
+    cell.inventory.dimension = 1
+    cell.inventory.degree = 1
+    cell.inventory.order = 1
+    cell._configure()
+    from pylith.feassemble.Quadrature import SubMeshQuadrature
+    quadrature = SubMeshQuadrature()
+    quadrature.inventory.cell = cell
+    quadrature._configure()
+
+    # Setup impulses
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    ioImpulseAmp = SimpleIOAscii()
+    ioImpulseAmp.inventory.filename = "data/tri3_impulses.spatialdb"
+    ioImpulseAmp._configure()
+    dbImpulseAmp = SimpleDB()
+    dbImpulseAmp.inventory.iohandler = ioImpulseAmp
+    dbImpulseAmp.inventory.label = "impulse amplitude"
+    dbImpulseAmp._configure()
+    
+    # Setup fault
+    fault = FaultCohesiveImpulses()
+    fault.inventory.output.inventory.writer._configure()
+    fault.inventory.output._configure()
+    fault.inventory.matId = 10
+    fault.inventory.faultLabel = "fault"
+    fault.inventory.upDir = [0, 0, 1]
+    fault.inventory.faultQuadrature = quadrature
+    fault.inventory.dbImpulseAmp = dbImpulseAmp
+    fault._configure()
+
+    nvertices = fault.numVerticesNoMesh(mesh)
+    firstFaultVertex = 0
+    firstLagrangeVertex = nvertices
+    firstFaultCell      = 2*nvertices
+    fault.adjustTopology(mesh, firstFaultVertex, firstLagrangeVertex,
+                         firstFaultCell)
+    fault.preinitialize(mesh)
+    fault.timeStep(dt)
+    fault.verifyConfiguration()
+    from pyre.units.time import s
+    fault.initialize(totalTime=0.0*s, numTimeSteps=1, normalizer=normalizer)
+
+    # Setup fields
+    from pylith.topology.SolutionFields import SolutionFields
+    fields = SolutionFields(mesh)
+    fields.add("residual", "residual")
+    fields.add("dispIncr(t->t+dt)", "displacement_increment")
+    fields.add("disp(t)", "displacement")
+    fields.solutionName("dispIncr(t->t+dt)")
+    residual = fields.get("residual")
+    residual.newSection(residual.VERTICES_FIELD, cs.spaceDim())
+    residual.allocate()
+    residual.zero()
+    fields.copyLayout("residual")
+    
+    return (mesh, fault, fields)
+
+
+# End of file 

Modified: short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/Makefile.am	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/Makefile.am	2012-05-03 16:21:15 UTC (rev 20028)
@@ -24,6 +24,7 @@
 	tri3_peakrate.spatialdb \
 	tri3_initialtractions.spatialdb \
 	tri3_staticfriction.spatialdb \
+	tri3_impulses.spatialdb \
 	slipfn.timedb
 
 noinst_TMP =

Added: short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/tri3_impulses.spatialdb
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/tri3_impulses.spatialdb	                        (rev 0)
+++ short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/data/tri3_impulses.spatialdb	2012-05-03 16:21:15 UTC (rev 20028)
@@ -0,0 +1,15 @@
+#SPATIAL.ascii 1
+SimpleDB {
+  num-values = 1
+  value-names =  slip
+  value-units =  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.0
+0.0  -1.0   2.1

Modified: short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/testfaults.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/testfaults.py	2012-05-03 15:41:58 UTC (rev 20027)
+++ short/3D/PyLith/branches/v1.7-trunk/unittests/pytests/faults/testfaults.py	2012-05-03 16:21:15 UTC (rev 20028)
@@ -86,6 +86,9 @@
     from TestFaultCohesiveDyn import TestFaultCohesiveDyn
     suite.addTest(unittest.makeSuite(TestFaultCohesiveDyn))
 
+    from TestFaultCohesiveImpulses import TestFaultCohesiveImpulses
+    suite.addTest(unittest.makeSuite(TestFaultCohesiveImpulses))
+
     from TestSingleRupture import TestSingleRupture
     suite.addTest(unittest.makeSuite(TestSingleRupture))
 



More information about the CIG-COMMITS mailing list