[cig-commits] r14896 - in short/3D/PyLith/trunk: . pylith pylith/tests pylith/utils tests/1d/line2

brad at geodynamics.org brad at geodynamics.org
Wed May 6 13:01:41 PDT 2009


Author: brad
Date: 2009-05-06 13:01:40 -0700 (Wed, 06 May 2009)
New Revision: 14896

Added:
   short/3D/PyLith/trunk/pylith/tests/
   short/3D/PyLith/trunk/pylith/tests/Fault.py
   short/3D/PyLith/trunk/pylith/tests/PhysicalProperties.py
   short/3D/PyLith/trunk/pylith/tests/Solution.py
   short/3D/PyLith/trunk/pylith/tests/StateVariables.py
   short/3D/PyLith/trunk/pylith/tests/__init__.py
Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/__init__.py
   short/3D/PyLith/trunk/pylith/utils/VTKDataReader.py
   short/3D/PyLith/trunk/tests/1d/line2/TestAxial.py
   short/3D/PyLith/trunk/tests/1d/line2/TestDislocation.py
   short/3D/PyLith/trunk/tests/1d/line2/TestLine2.py
Log:
Refactor testing routines. Still need to test fault data output.

Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/TODO	2009-05-06 20:01:40 UTC (rev 14896)
@@ -10,7 +10,7 @@
 
     1-D
       1. axial disp [DONE]
-      2. dislocation [DONE]
+      2. dislocation (need fault tests)
 
     2-D
       1. axial/shear (DirichletBC)

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-06 20:01:40 UTC (rev 14896)
@@ -119,7 +119,12 @@
 	utils/VTKDataReader.py \
 	utils/importing.py \
 	utils/profiling.py \
-	utils/testarray.py
+	utils/testarray.py \
+	tests/__init__.py \
+	tests/PhysicalProperties.py \
+	tests/Solution.py \
+	tests/StateVariables.py \
+	tests/Fault.py
 
 
 if ENABLE_TETGEN

Modified: short/3D/PyLith/trunk/pylith/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/__init__.py	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/pylith/__init__.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -24,6 +24,7 @@
            'problems',
            'topology',
            'utils',
+           'tests',
            ]
 
 

Added: short/3D/PyLith/trunk/pylith/tests/Fault.py
===================================================================
--- short/3D/PyLith/trunk/pylith/tests/Fault.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/tests/Fault.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/tests/Fault.py
+##
+## @brief Check fault output from PyLith.
+
+import numpy
+
+def check_info(testcase, filename, mesh, fieldNames):
+  """
+  Check properties.
+  """
+  data = testcase.reader.read(filename)
+  
+  # Check cells
+  (ncells, ncorners) = data['cells'].shape
+  testcase.assertEqual(mesh['ncells'], ncells)
+  testcase.assertEqual(mesh['ncorners'], ncorners)
+
+  # Check vertices
+  (nvertices, spaceDim) = data['vertices'].shape
+  testcase.assertEqual(mesh['nvertices'], nvertices)
+  testcase.assertEqual(mesh['spaceDim'], spaceDim)
+
+  # Check fault information
+  tolerance = 1.0e-5
+
+  for name in fieldNames:
+    valuesE = testcase.calcFaultInfo(name, data['vertices'])
+    values = data['vertex_fields'][name]
+
+    (nverticesE, dim) = valuesE.shape
+    values = values.reshape( (nvertices, dim) )
+    testcase.assertEqual(nverticesE, nvertices)
+
+    for i in xrange(dim):
+      ratio = numpy.abs(1.0 - values[:,i]/valuesE[:,i])
+      diff = numpy.abs(values[:,i] - valuesE[:,i])
+      mask = valuesE[:,i] != 0.0
+      okay = mask*(ratio < tolerance) + ~mask*(diff < tolerance)
+      if numpy.sum(okay) != nvertices:
+        print "Error in component %d of field '%s'." % (i, name)
+        print "Expected values:",valuesE
+        print "Output values:",values
+      testcase.assertEqual(numpy.sum(okay), nvertices)
+
+  return
+
+
+# End of file

Added: short/3D/PyLith/trunk/pylith/tests/PhysicalProperties.py
===================================================================
--- short/3D/PyLith/trunk/pylith/tests/PhysicalProperties.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/tests/PhysicalProperties.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/tests/PhysicalProperties.py
+##
+## @brief Check physical properties output from PyLith.
+
+import numpy
+
+def check_properties(testcase, filename, mesh, properties):
+  """
+  Check properties.
+  """
+  data = testcase.reader.read(filename)
+  
+  # Check cells
+  (ncells, ncorners) = data['cells'].shape
+  testcase.assertEqual(mesh['ncells'], ncells)
+  testcase.assertEqual(mesh['ncorners'], ncorners)
+
+  # Check vertices
+  (nvertices, spaceDim) = data['vertices'].shape
+  testcase.assertEqual(mesh['nvertices'], nvertices)
+  testcase.assertEqual(mesh['spaceDim'], spaceDim)
+
+  # Check physical properties
+  tolerance = 1.0e-5
+
+  for name in properties.keys():
+    propertyE = properties[name]
+    property = data['cell_fields'][name]
+    ratio = numpy.abs(1.0 - property[:]/propertyE[:,0])
+    diff = numpy.abs(property[:] - propertyE[:,0])
+    mask = propertyE[:,0] != 0.0
+    okay = mask*(ratio < tolerance) + ~mask*(diff < tolerance)
+    if numpy.sum(okay) != ncells:
+      print "Error in values for physical property '%s'." % name
+      print "Expected values:",propertyE
+      print "Output values:",property
+    testcase.assertEqual(numpy.sum(okay), ncells)
+
+  return
+
+
+# End of file

Added: short/3D/PyLith/trunk/pylith/tests/Solution.py
===================================================================
--- short/3D/PyLith/trunk/pylith/tests/Solution.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/tests/Solution.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/tests/Solution.py
+##
+## @brief Check displacement solution output from PyLith.
+
+import numpy
+
+def check_displacements(testcase, filename, mesh):
+  """
+  Check displacements.
+  """
+  data = testcase.reader.read(filename)
+  
+  # Check cells
+  (ncells, ncorners) = data['cells'].shape
+  testcase.assertEqual(mesh['ncells'], ncells)
+  testcase.assertEqual(mesh['ncorners'], ncorners)
+
+  # Check vertices
+  (nvertices, spaceDim) = data['vertices'].shape
+  testcase.assertEqual(mesh['nvertices'], nvertices)
+  testcase.assertEqual(mesh['spaceDim'], spaceDim)
+
+  # Check displacement solution
+  tolerance = 1.0e-5
+
+  dispE = testcase.calcDisplacements(data['vertices'])
+  disp = data['vertex_fields']['displacement']
+
+  # Check x displacements
+  diff = numpy.abs(disp[:,0] - dispE[:,0])
+  okay = diff < tolerance
+  if numpy.sum(okay) != nvertices:
+    "Error in x-component of displacement field."
+    print "Expected values: ",dispE
+    print "Output values: ",disp
+  testcase.assertEqual(nvertices, numpy.sum(okay))    
+    
+  # Check y displacements
+  diff = numpy.abs(disp[:,1] - dispE[:,1])
+  okay = diff < tolerance
+  if numpy.sum(okay) != nvertices:
+    "Error in y-component of displacement field."
+    print "Expected values: ",dispE
+    print "Output values: ",disp
+  testcase.assertEqual(nvertices, numpy.sum(okay))    
+
+  # Check z displacements
+  diff = numpy.abs(disp[:,2] - dispE[:,2])
+  okay = diff < tolerance
+  if numpy.sum(okay) != nvertices:
+    "Error in z-component of displacement field."
+    print "Expected values: ",dispE
+    print "Output values: ",disp
+  testcase.assertEqual(nvertices, numpy.sum(okay))    
+
+  return
+
+
+# End of file

Added: short/3D/PyLith/trunk/pylith/tests/StateVariables.py
===================================================================
--- short/3D/PyLith/trunk/pylith/tests/StateVariables.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/tests/StateVariables.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/tests/StateVariables.py
+##
+## @brief Check state variables output from PyLith.
+
+import numpy
+
+def check_state_variables(testcase, filename, mesh, stateVarNames):
+  """
+  Check state variables.
+  """
+  data = testcase.reader.read(filename)
+  
+  # Check cells
+  (ncells, ncorners) = data['cells'].shape
+  testcase.assertEqual(mesh['ncells'], ncells)
+  testcase.assertEqual(mesh['ncorners'], ncorners)
+
+  # Check vertices
+  (nvertices, spaceDim) = data['vertices'].shape
+  testcase.assertEqual(mesh['nvertices'], nvertices)
+  testcase.assertEqual(mesh['spaceDim'], spaceDim)
+
+  # Check state variables
+  tolerance = 1.0e-5
+
+  for name in stateVarNames:
+    valuesE = testcase.calcStateVar(name, data['vertices'], data['cells'])
+    values = data['cell_fields'][name]
+
+    (ncellsE, dim) = valuesE.shape
+    values = values.reshape( (ncells, dim) )
+    testcase.assertEqual(ncellsE, ncells)
+
+    for i in xrange(dim):
+      ratio = numpy.abs(1.0 - values[:,i]/valuesE[:,i])
+      diff = numpy.abs(values[:,i] - valuesE[:,i])
+      mask = valuesE[:,i] != 0.0
+      okay = mask*(ratio < tolerance) + ~mask*(diff < tolerance)
+      if numpy.sum(okay) != ncells:
+        print "Error in component %d of state variable '%s'." % (i, name)
+        print "Expected values:",valuesE
+        print "Output values:",values
+      testcase.assertEqual(numpy.sum(okay), ncells)
+    
+  return
+
+
+# End of file

Added: short/3D/PyLith/trunk/pylith/tests/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/tests/__init__.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/tests/__init__.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ----------------------------------------------------------------------
+#
+
+__all__ = ['PhysicalProperties',
+           'Solution',
+           'StateVariables',
+           'Fault',
+           ]
+
+
+# End of file

Modified: short/3D/PyLith/trunk/pylith/utils/VTKDataReader.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/VTKDataReader.py	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/pylith/utils/VTKDataReader.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -76,6 +76,8 @@
       ncorners = 3
     elif cellId == 3:
       ncorners = 2
+    elif cellId == 255:
+      ncorners = 1
     else:
       raise ValueError("Unknown VTK cell type '%d'." % cellId)
     cells = cells.reshape( (ncells, 1+ncorners) )[:,1:1+ncorners]

Modified: short/3D/PyLith/trunk/tests/1d/line2/TestAxial.py
===================================================================
--- short/3D/PyLith/trunk/tests/1d/line2/TestAxial.py	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/tests/1d/line2/TestAxial.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -59,106 +59,38 @@
     return
 
 
-  def test_soln(self):
+  def calcDisplacements(self, vertices):
     """
-    Check solution (displacement) field.
+    Calculate displacement field given coordinates of vertices.
     """
-    if self.reader is None:
-      return
+    nvertices = self.mesh['nvertices']
+    spaceDim = self.mesh['spaceDim']    
+    disp = numpy.zeros( (nvertices, spaceDim), dtype=numpy.float64)
+    disp[:,0] = -0.2 + 0.1 * vertices[:,0]
 
-    data = self.reader.read("%s_t0000000.vtk" % self.outputRoot)
+    return disp
 
-    # Check cells
-    (ncells, ncorners) = data['cells'].shape
-    self.assertEqual(self.ncells, ncells)
-    self.assertEqual(self.ncorners, ncorners)
 
-    # Check vertices
-    vertices = data['vertices']
-    (nvertices, spaceDim) = vertices.shape
-    self.assertEqual(self.nvertices, nvertices)
-    self.assertEqual(self.spaceDim, spaceDim)
-
-    # Check displacement solution
-    tolerance = 1.0e-5
-    dispE = numpy.zeros( (nvertices, spaceDim), dtype=numpy.float64)
-    dispE[:,0] = -0.2 + 0.1 * vertices[:,0]
-
-    disp = data['vertex_fields']['displacement']
-
-    # Check x displacements
-    diff = numpy.abs(disp[:,0] - dispE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-      self.assertEqual(nvertices, numpy.sum(okay))    
-    
-    # Check y displacements
-    diff = numpy.abs(disp[:,1] - dispE[:,1])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-      self.assertEqual(nvertices, numpy.sum(okay))    
-
-    # Check z displacements
-    diff = numpy.abs(disp[:,2] - dispE[:,2])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-      self.assertEqual(nvertices, numpy.sum(okay))    
-    
-    return
-
-
-  def test_elastic_statevars(self):
+  def calcStateVar(self, name, vertices, cells):
     """
-    Check elastic state variables.
+    Calculate state variable.
     """
-    if self.reader is None:
-      return
-
-    data = self.reader.read("%s-statevars-elastic_t0000000.vtk" % \
-                              self.outputRoot)
-
-    # Check cells
-    (ncells, ncorners) = data['cells'].shape
-    self.assertEqual(self.ncells, ncells)
-    self.assertEqual(self.ncorners, ncorners)
-
-    # Check vertices
-    vertices = data['vertices']
-    (nvertices, spaceDim) = vertices.shape
-    self.assertEqual(self.nvertices, nvertices)
-    self.assertEqual(self.spaceDim, spaceDim)
-
-    # Check strains
-    tolerance = 1.0e-5
     exx = 0.1
-    strainE = exx*numpy.ones( (ncells, self.tensorSize), dtype=numpy.float64)
-    strain = data['cell_fields']['total_strain']
-    diff = numpy.abs(strain[:]-strainE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Strain field expected: ",strainE
-      print "Strain field: ",strain
-    self.assertEqual(ncells, numpy.sum(okay))    
 
-    # Check stresses
-    lp2m = self.density*self.vp**2
-    stressE = lp2m*exx * numpy.ones( (ncells, self.tensorSize), 
-                                     dtype=numpy.float64)
-    stress = data['cell_fields']['stress']
-    diff = numpy.abs(stress[:]-stressE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Stress field expected: ",stressE
-      print "Stress field: ",stress
-    self.assertEqual(ncells, numpy.sum(okay))    
+    ncells = self.mesh['ncells']
+    tensorSize = self.mesh['tensorSize']
 
-    return
+    if name == "total_strain":
+      stateVar = exx*numpy.ones( (ncells, tensorSize), dtype=numpy.float64)
+    
+    elif name == "stress":
+      lp2m = self.density*self.vp**2
+      stateVar = lp2m*exx * numpy.ones( (ncells, tensorSize), 
+                                       dtype=numpy.float64)
+    else:
+      raise ValueError("Unknown state variable '%s'." % name)
 
+    return stateVar
 
+
 # End of file 

Modified: short/3D/PyLith/trunk/tests/1d/line2/TestDislocation.py
===================================================================
--- short/3D/PyLith/trunk/tests/1d/line2/TestDislocation.py	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/tests/1d/line2/TestDislocation.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -50,9 +50,14 @@
     Setup for test.
     """
     TestLine2.setUp(self)
-    self.nvertices = 6
+    self.mesh['nvertices'] = 6
     self.nverticesO = 5
 
+    self.faultMesh = {'nvertices': 1,
+                      'spaceDim': 3,
+                      'ncells': 1,
+                      'ncorners': 1}
+
     run_pylith()
     self.outputRoot = "dislocation"
     if has_vtk():
@@ -62,111 +67,87 @@
     return
 
 
-  def test_soln(self):
+  def test_fault_info(self):
     """
-    Check solution (displacement) field.
+    Check fault information.
     """
     if self.reader is None:
       return
 
-    data = self.reader.read("%s_t0000000.vtk" % self.outputRoot)
+    filename = "%s-fault_info.vtk" % self.outputRoot
+    from pylith.tests.Fault import check_info
+    fields = ["normal_dir", "final_slip", "slip_time"]
+    check_info(self, filename, self.faultMesh, fields)
 
-    # Check cells
-    (ncells, ncorners) = data['cells'].shape
-    self.assertEqual(self.ncells, ncells)
-    self.assertEqual(self.ncorners, ncorners)
+    return
 
-    # Check vertices
-    vertices = data['vertices']
-    (nvertices, spaceDim) = vertices.shape
-    self.assertEqual(self.nvertices, nvertices)
-    self.assertEqual(self.spaceDim, spaceDim)
 
-    # Check displacement solution
-    tolerance = 1.0e-5
-    dispE = numpy.zeros( (nvertices, spaceDim), dtype=numpy.float64)
+  def calcDisplacements(self, vertices):
+    """
+    Calculate displacement field given coordinates of vertices.
+    """
+    nvertices = self.mesh['nvertices']
+    spaceDim = self.mesh['spaceDim']    
+    nverticesO = self.nverticesO
+
+    disp = numpy.zeros( (nvertices, spaceDim), dtype=numpy.float64)
     maskP = vertices[:,0] >= 2.0
-    maskP[self.nverticesO:self.nvertices] = False
+    maskP[nverticesO:nvertices] = False
     maskN = numpy.bitwise_and(vertices[:,0] <= 2.0, ~maskP)
-    dispE[:,0] = \
+    disp[:,0] = \
         maskN*(-0.20 - 0.025*vertices[:,0]) + \
         maskP*(+0.30 - 0.025*vertices[:,0])
 
-    disp = data['vertex_fields']['displacement']
+    return disp
 
-    # Check x displacements
-    diff = numpy.abs(disp[:,0] - dispE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-    self.assertEqual(nvertices, numpy.sum(okay))    
-    
-    # Check y displacements
-    diff = numpy.abs(disp[:,1] - dispE[:,1])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-    self.assertEqual(nvertices, numpy.sum(okay))    
 
-    # Check z displacements
-    diff = numpy.abs(disp[:,2] - dispE[:,2])
-    okay = diff < tolerance
-    if numpy.sum(okay) != nvertices:
-      print "Displacement field expected: ",dispE
-      print "Displacement field: ",disp
-    self.assertEqual(nvertices, numpy.sum(okay))    
+  def calcStateVar(self, name, vertices, cells):
+    """
+    Calculate state variable.
+    """
+    exx = -0.025
+
+    ncells = self.mesh['ncells']
+    tensorSize = self.mesh['tensorSize']
+
+    if name == "total_strain":
+      stateVar = exx*numpy.ones( (ncells, tensorSize), dtype=numpy.float64)
     
-    return
+    elif name == "stress":
+      lp2m = self.density*self.vp**2
+      stateVar = lp2m*exx * numpy.ones( (ncells, tensorSize), 
+                                       dtype=numpy.float64)
+    else:
+      raise ValueError("Unknown state variable '%s'." % name)
 
+    return stateVar
 
-  def test_elastic_statevars(self):
+
+  def calcFaultInfo(self, name, vertices):
     """
-    Check elastic state variables.
+    Calculate fault info.
     """
-    if self.reader is None:
-      return
 
-    data = self.reader.read("%s-statevars-elastic_t0000000.vtk" % \
-                              self.outputRoot)
+    normalDir = 1.0
+    finalSlip = -0.5
+    slipTime = 0.0
 
-    # Check cells
-    (ncells, ncorners) = data['cells'].shape
-    self.assertEqual(self.ncells, ncells)
-    self.assertEqual(self.ncorners, ncorners)
+    nvertices = self.faultMesh['nvertices']
 
-    # Check vertices
-    vertices = data['vertices']
-    (nvertices, spaceDim) = vertices.shape
-    self.assertEqual(self.nvertices, nvertices)
-    self.assertEqual(self.spaceDim, spaceDim)
+    if name == "normal_dir":
+      field = normalDir*numpy.ones( (nvertices, 1), dtype=numpy.float64)
 
-    # Check strains
-    tolerance = 1.0e-5
-    exx = -0.025
-    strainE = exx*numpy.ones( (ncells, self.tensorSize), dtype=numpy.float64)
-    strain = data['cell_fields']['total_strain']
-    diff = numpy.abs(strain[:]-strainE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Strain field expected: ",strainE
-      print "Strain field: ",strain
-    self.assertEqual(ncells, numpy.sum(okay))    
+    elif name == "final_slip":
+      field = numpy.zeros( (nvertices, 3), dtype=numpy.float64)
+      field[:,0] = finalSlip
+      
+    elif name == "slip_time":
+      field = slipTime*numpy.ones( (nvertices, 1), dtype=numpy.float64)
+      
+    else:
+      raise ValueError("Unknown fault info field '%s'." % name)
 
-    # Check stresses
-    lp2m = self.density*self.vp**2
-    stressE = lp2m*exx * numpy.ones( (ncells, self.tensorSize), 
-                                     dtype=numpy.float64)
-    stress = data['cell_fields']['stress']
-    diff = numpy.abs(stress[:]-stressE[:,0])
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Stress field expected: ",stressE
-      print "Stress field: ",stress
-    self.assertEqual(ncells, numpy.sum(okay))    
+    return field
 
-    return
 
-
 # End of file 

Modified: short/3D/PyLith/trunk/tests/1d/line2/TestLine2.py
===================================================================
--- short/3D/PyLith/trunk/tests/1d/line2/TestLine2.py	2009-05-06 19:12:06 UTC (rev 14895)
+++ short/3D/PyLith/trunk/tests/1d/line2/TestLine2.py	2009-05-06 20:01:40 UTC (rev 14896)
@@ -26,16 +26,17 @@
     """
     Setup for tests.
     """
-    self.ncells = 4
-    self.ncorners = 2
-    self.nvertices = 5
-    self.spaceDim = 3
-    self.tensorSize = 1
+    self.mesh = {'ncells': 4,
+                 'ncorners': 2,
+                 'nvertices': 5,
+                 'spaceDim': 3,
+                 'tensorSize': 1}
     self.vs = 3000.0
     self.vp = 5291.502622129181
     self.density = 2500.0
     return
 
+
   def test_elastic_info(self):
     """
     Check elastic info.
@@ -43,48 +44,54 @@
     if self.reader is None:
       return
 
-    data = self.reader.read("%s-statevars-elastic_info.vtk" % self.outputRoot)
+    ncells= self.mesh['ncells']
 
-    # Check cells
-    (ncells, ncorners) = data['cells'].shape
-    self.assertEqual(self.ncells, ncells)
-    self.assertEqual(self.ncorners, ncorners)
+    filename = "%s-statevars-elastic_info.vtk" % self.outputRoot
+    m = self.density*self.vs**2
+    l = self.density*self.vp**2 - 2*m
 
-    # Check vertices
-    (nvertices, spaceDim) = data['vertices'].shape
-    self.assertEqual(self.nvertices, nvertices)
-    self.assertEqual(self.spaceDim, spaceDim)
+    propMu =  m*numpy.ones( (ncells, 1), dtype=numpy.float64)
+    propLambda = l*numpy.ones( (ncells, 1), dtype=numpy.float64)
+    propDensity = self.density*numpy.ones( (ncells, 2), dtype=numpy.float64)
 
-    # Check physical properties
-    tolerance = 1.0e-5
+    properties = {'mu': propMu,
+                  'lambda': propLambda,
+                  'density': propDensity}
 
-    # Lame's constant mu (shear modulus)
-    muE = self.density*self.vs**2
-    diff = numpy.abs(1.0 - data['cell_fields']['mu']/muE)
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Expected Lame's constant mu: ",muE
-      print "Lame's constant mu: ",data['cell_fields']['mu']
-      self.assertEqual(ncells, numpy.sum(okay))    
+    from pylith.tests.PhysicalProperties import check_properties
+    check_properties(self, filename, self.mesh, properties)
 
-    # Lame's constant lambda
-    lambdaE = self.density*self.vp**2 - 2*muE
-    diff = numpy.abs(1.0 - data['cell_fields']['lambda']/lambdaE)
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Expected Lame's constant lambda: ",lambdaE
-      print "Lame's constant lambda: ",data['cell_fields']['lambda']
-      self.assertEqual(ncells, numpy.sum(okay))    
+    return
 
-    # Density
-    diff = numpy.abs(1.0 - data['cell_fields']['density']/self.density)
-    okay = diff < tolerance
-    if numpy.sum(okay) != ncells:
-      print "Expected density: ",self.density
-      print "Density: ",data['cell_fields']['density']
-      self.assertEqual(ncells, numpy.sum(okay))    
 
+  def test_soln(self):
+    """
+    Check solution (displacement) field.
+    """
+    if self.reader is None:
+      return
+
+    filename = "%s_t0000000.vtk" % self.outputRoot
+    from pylith.tests.Solution import check_displacements
+    check_displacements(self, filename, self.mesh)
+
     return
 
 
+  def test_elastic_statevars(self):
+    """
+    Check elastic state variables.
+    """
+    if self.reader is None:
+      return
+
+    filename = "%s-statevars-elastic_t0000000.vtk" % self.outputRoot
+
+    from pylith.tests.StateVariables import check_state_variables
+    stateVars = ["total_strain", "stress"]
+    check_state_variables(self, filename, self.mesh, stateVars)
+
+    return
+
+
 # End of file



More information about the CIG-COMMITS mailing list