[cig-commits] r14317 - in short/3D/PyLith/branches/pylith-swig: . pylith/materials unittests/pytests/materials

brad at geodynamics.org brad at geodynamics.org
Fri Mar 13 17:33:59 PDT 2009


Author: brad
Date: 2009-03-13 17:33:59 -0700 (Fri, 13 Mar 2009)
New Revision: 14317

Added:
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticMaterial.py
Modified:
   short/3D/PyLith/branches/pylith-swig/TODO
   short/3D/PyLith/branches/pylith-swig/pylith/materials/Material.py
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticStrain1D.py
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestMaterial.py
   short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/testmaterials.py
Log:
More work updating python tests for materials.

Modified: short/3D/PyLith/branches/pylith-swig/TODO
===================================================================
--- short/3D/PyLith/branches/pylith-swig/TODO	2009-03-13 23:52:54 UTC (rev 14316)
+++ short/3D/PyLith/branches/pylith-swig/TODO	2009-03-14 00:33:59 UTC (rev 14317)
@@ -11,6 +11,9 @@
   Cleanup error checking on PETSc calls. Use PetscError as in
   Jacobian.
 
+  pytests/materials/TestElasticXXXXXX
+    continue adding methods (see ElasticStrain1D)
+
   TestMesh.test_view()
   TestMesh.test_checkMaterialIds()
   

Modified: short/3D/PyLith/branches/pylith-swig/pylith/materials/Material.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/pylith/materials/Material.py	2009-03-13 23:52:54 UTC (rev 14316)
+++ short/3D/PyLith/branches/pylith-swig/pylith/materials/Material.py	2009-03-14 00:33:59 UTC (rev 14317)
@@ -123,7 +123,7 @@
               "Quadrature spatial dimension: %d\n" \
               "Mesh cell dimension: %d\n" \
               "Mesh spatial dimension: %d" % \
-              (self.label,
+              (self.matLabel,
                self.matQuadrature.cellDim, self.matQuadrature.spaceDim,
                self.mesh.dimension(), self.mesh.coordsys().spaceDim())
     
@@ -151,6 +151,7 @@
     if self.inventory.useInitialState:
       self.dbInitialState(self.inventory.dbInitialState)
 
+    self.matLabel = self.inventory.label
     self.matQuadrature = self.inventory.quadrature
     return
 

Added: short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticMaterial.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticMaterial.py	                        (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticMaterial.py	2009-03-14 00:33:59 UTC (rev 14317)
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/materials/TestElasticMaterial.py
+
+## @brief Unit testing of Material object.
+
+import unittest
+
+# ----------------------------------------------------------------------
+class TestElasticMaterial(unittest.TestCase):
+  """
+  Unit testing of ElasticMaterial object.
+  """
+
+  def setUp(self):
+    """
+    Setup test subject.
+    """
+    from pylith.materials.ElasticStrain1D import ElasticStrain1D
+    self.material = ElasticStrain1D()
+    return
+    
+
+  def testDBInitialStress(self):
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    iohandler = SimpleIOAscii()
+    iohandler.inventory.filename = "data/matinitialize.spatialdb"
+    iohandler._configure()
+    db = SimpleDB()
+    db.inventory.label = "material properties"
+    db.inventory.iohandler = iohandler
+    db._configure()
+
+    self.material.dbInitialStress(db)
+
+    # No test of result.
+    return
+
+
+  def testDBInitialStrain(self):
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    iohandler = SimpleIOAscii()
+    iohandler.inventory.filename = "data/matinitialize.spatialdb"
+    iohandler._configure()
+    db = SimpleDB()
+    db.inventory.label = "material properties"
+    db.inventory.iohandler = iohandler
+    db._configure()
+
+    self.material.dbInitialStrain(db)
+
+    # No test of result.
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticStrain1D.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticStrain1D.py	2009-03-13 23:52:54 UTC (rev 14316)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestElasticStrain1D.py	2009-03-14 00:33:59 UTC (rev 14317)
@@ -24,13 +24,19 @@
   Unit testing of ElasticStrain1D object.
   """
 
+  def setUp(self):
+    """
+    Setup test subject.
+    """
+    self.material = ElasticStrain1D()
+    return
+  
+
   def test_constructor(self):
     """
     Test constructor.
     """
-    material = ElasticStrain1D()
-
-    self.assertEqual(1, material.dimension())
+    self.assertEqual(1, self.material.dimension())
     return
 
 
@@ -38,9 +44,38 @@
     """
     Test useElasticBehavior().
     """
-    material = ElasticStrain1D()
-    material.useElasticBehavior(False)
+    self.material.useElasticBehavior(False)
     return
 
 
+  def testHasStateVars(self):
+    self.failIf(self.material.hasStateVars())
+    return
+
+
+  def testStableTimeStepImplicit(self):
+    maxfloat = 1.0e+30
+    self.assertEqual(maxfloat, self.material.stableTimeStepImplicit())
+    return
+
+
+  def testTensorSize(self):
+    self.assertEqual(1, self.material.tensorSize())
+    return
+
+
+  def testNeedNewJacobian(self):
+    """
+    Test needNewJacobian().
+    """
+    # Default should be False.
+    self.failIf(self.material.needNewJacobian())
+
+    # Changing time step should not require new Jacobian.
+    self.material.timeStep(1.0)
+    self.material.timeStep(2.0)
+    self.failIf(self.material.needNewJacobian())
+    return
+  
+
 # End of file 

Modified: short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestMaterial.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestMaterial.py	2009-03-13 23:52:54 UTC (rev 14316)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/TestMaterial.py	2009-03-14 00:33:59 UTC (rev 14317)
@@ -22,61 +22,156 @@
   Unit testing of Material object.
   """
 
-  def test_initialize(self):
+  def setUp(self):
     """
-    Test initialize().
+    Setup test subject.
+    """
+    from pylith.materials.ElasticStrain1D import ElasticStrain1D
+    self.material = ElasticStrain1D()
+    return
+    
 
+  def testId(self):
+    """
+    Test id().
+    """
+    id = 1234
+    self.material.id(id)
+    self.assertEqual(id, self.material.id())
+    return
+
+
+  def testLabel(self):
+    """
+    Test label().
+    """
+    label = "material abc"
+    self.material.label(label)
+
+    # No test of result.
+    return
+
+
+  def testTimeStep(self):
+    """
+    Test timeStep().
+    """
+    dt = 0.5
+    self.material.timeStep(dt)
+    self.assertEqual(dt, self.material.timeStep())
+    return
+
+
+  def testDBProperties(self):
+    """
+    Test dbProperties().
+    """
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    iohandler = SimpleIOAscii()
+    iohandler.inventory.filename = "data/matinitialize.spatialdb"
+    iohandler._configure()
+    db = SimpleDB()
+    db.inventory.label = "material properties"
+    db.inventory.iohandler = iohandler
+    db._configure()
+
+    self.material.dbProperties(db)
+
+    # No test of result.
+    return
+
+
+  def testDBInitialState(self):
+    """
+    Test dbInitialState().
+    """
+    from spatialdata.spatialdb.SimpleDB import SimpleDB
+    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
+    iohandler = SimpleIOAscii()
+    iohandler.inventory.filename = "data/matinitialize.spatialdb"
+    iohandler._configure()
+    db = SimpleDB()
+    db.inventory.label = "material properties"
+    db.inventory.iohandler = iohandler
+    db._configure()
+
+    self.material.dbInitialState(db)
+
+    # No test of result.
+    return
+
+
+  def testNormalizer(self):
+    """
+    Test normalizer().
+    """
+    from spatialdata.units.Nondimensional import Nondimensional
+    normalizer = Nondimensional()
+    normalizer._configure()
+
+
+    self.material.normalizer(normalizer)
+
+    # No test of result.
+    return
+
+
+  def test_preinitialize(self):
+    """
+    Test preinitialize().
+
     WARNING: This is not a rigorous test of initialize() because we
     don't verify the results.
     """
-    from pylith.materials.ElasticStrain1D import ElasticStrain1D
-    material = ElasticStrain1D()
-
-    from pylith.feassemble.quadrature.Quadrature1D import Quadrature1D
-    quadrature = Quadrature1D()
-    quadrature._configure()
     from pylith.feassemble.FIATSimplex import FIATSimplex
     cell = FIATSimplex()
-    cell.shape = "line"
-    cell.order = 1
-    cell.degree = 1
-    quadrature.cell = cell
-    quadrature.minJacobian = 1.0e-4
-    quadrature.preinitialize()
-    material.quadrature = quadrature
+    cell.inventory.shape = "line"
+    cell.inventory.order = 1
+    cell.inventory.degree = 1
+    cell._configure()
 
+    from pylith.feassemble.Quadrature import MeshQuadrature
+    quadrature = MeshQuadrature()
+    quadrature.inventory.cell = cell
+    quadrature.inventory.minJacobian = 1.0e-4
+    quadrature._configure()
+
     from spatialdata.spatialdb.SimpleDB import SimpleDB
     from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii
     iohandler = SimpleIOAscii()
-    iohandler.filename = "data/matinitialize.spatialdb"
+    iohandler.inventory.filename = "data/matinitialize.spatialdb"
+    iohandler._configure()
     db = SimpleDB()
-    db.label = "material properties"
-    db.iohandler = iohandler
-    initialStateDB = None
-    material.db = db
-    material.label = "my material"
-    material.id = 54
-    material.initialStateDB = initialStateDB
+    db.inventory.label = "material properties"
+    db.inventory.iohandler = iohandler
+    db._configure()
 
+    from pylith.materials.ElasticStrain1D import ElasticStrain1D
+    material = ElasticStrain1D()
+    material.inventory.quadrature = quadrature
+    material.inventory.db = db
+    material.inventory.label = "my material"
+    material.inventory.id = 54
+    material._configure()
+
     from spatialdata.geocoords.CSCart import CSCart
     cs = CSCart()
-    cs.spaceDim = 1
+    cs.inventory.spaceDim = 1
+    cs._configure()
 
     from spatialdata.units.Nondimensional import Nondimensional
     normalizer = Nondimensional()
-    normalizer.initialize()
+    normalizer._configure()
 
     from pylith.meshio.MeshIOAscii import MeshIOAscii
     importer = MeshIOAscii()
-    importer.filename = "data/twoelems.mesh"
-    importer.coordsys = cs
+    importer.inventory.filename = "data/twoelems.mesh"
+    importer.inventory.coordsys = cs
+    importer._configure()
     mesh = importer.read(normalizer, debug=False, interpolate=False)
     
     material.preinitialize()
-    from pyre.units.time import second
-    totalTime = 0.0*second
-    numTimeSteps = 1
-    material.initialize(mesh, totalTime, numTimeSteps, normalizer)
 
     # We should really add something here to check to make sure things
     # actually initialized correctly    

Modified: short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/testmaterials.py
===================================================================
--- short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/testmaterials.py	2009-03-13 23:52:54 UTC (rev 14316)
+++ short/3D/PyLith/branches/pylith-swig/unittests/pytests/materials/testmaterials.py	2009-03-14 00:33:59 UTC (rev 14317)
@@ -56,9 +56,6 @@
 
     suite = unittest.TestSuite()
 
-    #from TestMaterial import TestMaterial
-    #suite.addTest(unittest.makeSuite(TestMaterial))
-
     from TestElasticStrain1D import TestElasticStrain1D
     suite.addTest(unittest.makeSuite(TestElasticStrain1D))
 
@@ -80,9 +77,15 @@
     #from TestGenMaxwellIsotropic3D import TestGenMaxwellIsotropic3D
     #suite.addTest(unittest.makeSuite(TestGenMaxwellIsotropic3D))
 
-    #from TestHomogeneous import TestHomogeneous
-    #suite.addTest(unittest.makeSuite(TestHomogeneous))
+    from TestMaterial import TestMaterial
+    suite.addTest(unittest.makeSuite(TestMaterial))
 
+    from TestElasticMaterial import TestElasticMaterial
+    suite.addTest(unittest.makeSuite(TestElasticMaterial))
+
+    from TestHomogeneous import TestHomogeneous
+    suite.addTest(unittest.makeSuite(TestHomogeneous))
+
     return suite
 
 



More information about the CIG-COMMITS mailing list