[cig-commits] r20167 - short/3D/PyLith/branches/v1.7-trunk/pylith/tests
brad at geodynamics.org
brad at geodynamics.org
Wed May 16 18:02:43 PDT 2012
Author: brad
Date: 2012-05-16 18:02:43 -0700 (Wed, 16 May 2012)
New Revision: 20167
Modified:
short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Fault.py
short/3D/PyLith/branches/v1.7-trunk/pylith/tests/PhysicalProperties.py
short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Solution.py
short/3D/PyLith/branches/v1.7-trunk/pylith/tests/StateVariables.py
short/3D/PyLith/branches/v1.7-trunk/pylith/tests/__init__.py
Log:
Switched automated tests from VTK output to HDF5 output.
Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Fault.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Fault.py 2012-05-17 00:29:45 UTC (rev 20166)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Fault.py 2012-05-17 01:02:43 UTC (rev 20167)
@@ -21,39 +21,41 @@
## @brief Check fault output from PyLith.
import numpy
+import h5py
+from spatialdata.units.NondimElasticQuasistatic import NondimElasticQuasistatic
def check_vertex_fields(testcase, filename, mesh, fieldNames):
"""
Check properties.
"""
- data = testcase.reader.read(filename)
+ h5 = h5py.File(filename, "r", driver="sec2")
# Check cells
- (ncells, ncorners) = data['cells'].shape
+ cells = h5['topology/cells'][:]
+ (ncells, ncorners) = cells.shape
testcase.assertEqual(mesh['ncells'], ncells)
testcase.assertEqual(mesh['ncorners'], ncorners)
# Check vertices
- (nvertices, spaceDim) = data['vertices'].shape
+ vertices = h5['geometry/vertices'][:]
+ (nvertices, spaceDim) = vertices.shape
testcase.assertEqual(mesh['nvertices'], nvertices)
testcase.assertEqual(mesh['spaceDim'], spaceDim)
# Check fault information
tolerance = 1.0e-5
- from spatialdata.units.NondimElasticQuasistatic import NondimElasticQuasistatic
normalizer = NondimElasticQuasistatic()
normalizer._configure()
for name in fieldNames:
- valuesE = testcase.calcFaultField(name, data['vertices'])
- values = data['vertex_fields'][name]
+ valuesE = testcase.calcFaultField(name, vertices)
+ values = h5['vertex_fields/%s' % name][:]
- (nverticesE, dimE) = valuesE.shape
- if 1 == dimE:
- values = values.reshape( (nvertices, dimE) )
- (nvertices, dim) = values.shape
+ (nstepsE, nverticesE, dimE) = valuesE.shape
+ (nsteps, nvertices, dim) = values.shape
+ testcase.assertEqual(nstepsE, nsteps)
testcase.assertEqual(nverticesE, nvertices)
testcase.assertEqual(dimE, dim)
@@ -61,17 +63,19 @@
if name == "traction_change" or name == "traction":
scale *= normalizer.pressureScale().value
- for i in xrange(dim):
- ratio = numpy.abs(1.0 - values[:,i]/valuesE[:,i])
- diff = numpy.abs(values[:,i] - valuesE[:,i]) / scale
- 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)
+ for istep in xrange(nsteps):
+ for idim in xrange(dim):
+ ratio = numpy.abs(1.0 - values[istep,:,idim]/valuesE[istep,:,idim])
+ diff = numpy.abs(values[istep,:,idim] - valuesE[istep,:,idim]) / scale
+ mask = valuesE[istep,:,idim] != 0.0
+ okay = mask*(ratio < tolerance) + ~mask*(diff < tolerance)
+ if numpy.sum(okay) != nvertices:
+ print "Error in component %d of field '%s' for timestep %d." % (idim, name, istep)
+ print "Expected values:",valuesE
+ print "Output values:",values
+ testcase.assertEqual(numpy.sum(okay), nvertices)
+ h5.close()
return
@@ -79,15 +83,17 @@
"""
Check properties.
"""
- data = testcase.reader.read(filename)
+ h5 = h5py.File(filename, "r", driver="sec2")
# Check cells
- (ncells, ncorners) = data['cells'].shape
+ cells = h5['topology/cells'][:]
+ (ncells, ncorners) = cells.shape
testcase.assertEqual(mesh['ncells'], ncells)
testcase.assertEqual(mesh['ncorners'], ncorners)
# Check vertices
- (nvertices, spaceDim) = data['vertices'].shape
+ vertices = h5['geometry/vertices'][:]
+ (nvertices, spaceDim) = vertices.shape
testcase.assertEqual(mesh['nvertices'], nvertices)
testcase.assertEqual(mesh['spaceDim'], spaceDim)
@@ -96,7 +102,7 @@
for name in fieldNames:
valuesE = testcase.calcFaultInfo(name, data['vertices'])
- values = data['vertex_fields'][name]
+ values = h5['vertex_fields/%s' % name][:]
(nverticesE, dim) = valuesE.shape
values = values.reshape( (nvertices, dim) )
@@ -112,7 +118,7 @@
print "Expected values:",valuesE
print "Output values:",values
testcase.assertEqual(numpy.sum(okay), nvertices)
-
+ h5.close()
return
Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/tests/PhysicalProperties.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/tests/PhysicalProperties.py 2012-05-17 00:29:45 UTC (rev 20166)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/tests/PhysicalProperties.py 2012-05-17 01:02:43 UTC (rev 20167)
@@ -21,20 +21,23 @@
## @brief Check physical properties output from PyLith.
import numpy
+import h5py
def check_properties(testcase, filename, mesh, properties):
"""
Check properties.
"""
- data = testcase.reader.read(filename)
+ h5 = h5py.File(filename, "r", driver="sec2")
# Check cells
- (ncells, ncorners) = data['cells'].shape
+ cells = h5['topology/cells'][:]
+ (ncells, ncorners) = cells.shape
testcase.assertEqual(mesh['ncells'], ncells)
testcase.assertEqual(mesh['ncorners'], ncorners)
# Check vertices
- (nvertices, spaceDim) = data['vertices'].shape
+ vertices = h5['geometry/vertices'][:]
+ (nvertices, spaceDim) = vertices.shape
testcase.assertEqual(mesh['nvertices'], nvertices)
testcase.assertEqual(mesh['spaceDim'], spaceDim)
@@ -43,7 +46,7 @@
for name in properties.keys():
propertyE = properties[name]
- property = data['cell_fields'][name]
+ property = h5['cell_fields/%s' % name][:]
ratio = numpy.abs(1.0 - property[:]/propertyE[:,0])
diff = numpy.abs(property[:] - propertyE[:,0])
mask = propertyE[:,0] != 0.0
@@ -52,8 +55,9 @@
print "Error in values for physical property '%s'." % name
print "Expected values:",propertyE
print "Output values:",property
- testcase.assertEqual(numpy.sum(okay), ncells)
+ testcase.assertEqual(ncells, numpy.sum(okay))
+ h5.close()
return
Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Solution.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Solution.py 2012-05-17 00:29:45 UTC (rev 20166)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/tests/Solution.py 2012-05-17 01:02:43 UTC (rev 20167)
@@ -21,15 +21,17 @@
## @brief Check displacement solution output from PyLith.
import numpy
+import h5py
def check_displacements(testcase, filename, mesh):
"""
Check displacements.
"""
- data = testcase.reader.read(filename)
+ h5 = h5py.File(filename, "r", driver="sec2")
# Check vertices
- (nvertices, spaceDim) = data['vertices'].shape
+ vertices = h5['geometry/vertices'][:]
+ (nvertices, spaceDim) = vertices.shape
testcase.assertEqual(mesh['nvertices'], nvertices)
testcase.assertEqual(mesh['spaceDim'], spaceDim)
@@ -37,48 +39,32 @@
toleranceMask = 1.0e-3
tolerance = 1.0e-5
- dispE = testcase.calcDisplacements(data['vertices'])
- disp = data['vertex_fields']['displacement']
+ dispE = testcase.calcDisplacements(vertices)
+ disp = h5['vertex_fields/displacement'][:]
- # Check x displacements
- mask = numpy.abs(dispE[:,0]) > toleranceMask
- diff = numpy.abs(disp[:,0] - dispE[:,0])
- diffR = numpy.abs(1.0 - disp[:,0] / dispE[:,0])
- okay = ~mask * (diff < tolerance) + mask * (diffR < tolerance)
- if numpy.sum(okay) != nvertices:
- print "Error in x-component of displacement field."
- print "Expected values: ",dispE
- print "Output values: ",disp
- print dispE[~okay]
- print disp[~okay]
- print diffR[~okay]
- testcase.assertEqual(nvertices, numpy.sum(okay))
-
- # Check y displacements
- mask = numpy.abs(dispE[:,1]) > toleranceMask
- diff = numpy.abs(disp[:,1] - dispE[:,1])
- diffR = numpy.abs(1.0 - disp[:,1] / dispE[:,1])
- okay = ~mask * (diff < tolerance) + mask * (diffR < tolerance)
- if numpy.sum(okay) != nvertices:
- print "Error in y-component of displacement field."
- print "Expected values: ",dispE
- print "Output values: ",disp
- print dispE[~okay]
- print disp[~okay]
- print diffR[~okay]
- testcase.assertEqual(nvertices, numpy.sum(okay))
+ (nstepsE, nverticesE, ncompsE) = dispE.shape
+ (nsteps, nvertices, ncomps) = disp.shape
+ testcase.assertEqual(nstepsE, nsteps)
+ testcase.assertEqual(nverticesE, nvertices)
+ testcase.assertEqual(ncompsE, ncomps)
- # Check z displacements
- mask = numpy.abs(dispE[:,2]) > toleranceMask
- diff = numpy.abs(disp[:,2] - dispE[:,2])
- diffR = numpy.abs(1.0 - disp[:,2] / dispE[:,2])
- okay = ~mask * (diff < tolerance) + mask * (diffR < tolerance)
- if numpy.sum(okay) != nvertices:
- print "Error in z-component of displacement field."
- print "Expected values: ",dispE
- print "Output values: ",disp
- testcase.assertEqual(nvertices, numpy.sum(okay))
+ for istep in xrange(nsteps):
+ for icomp in xrange(ncomps):
+ mask = numpy.abs(dispE[istep,:,icomp]) > toleranceMask
+ diff = numpy.abs(disp[istep,:,icomp] - dispE[istep,:,icomp])
+ diffR = numpy.abs(1.0 - disp[istep,:,icomp] / dispE[istep,:,icomp])
+ okay = ~mask * (diff < tolerance) + mask * (diffR < tolerance)
+ if numpy.sum(okay) != nvertices:
+ print "Error in component %d of displacement field at time step %d." % (icomp, istep)
+ print "Expected values: ",dispE[istep,:,:]
+ print "Output values: ",disp[istep,:,:]
+ print dispE[istep,~okay,icomp]
+ print disp[istep,~okay,icomp]
+ print diffR[~okay]
+ testcase.assertEqual(nvertices, numpy.sum(okay))
+
+ h5.close()
return
Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/tests/StateVariables.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/tests/StateVariables.py 2012-05-17 00:29:45 UTC (rev 20166)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/tests/StateVariables.py 2012-05-17 01:02:43 UTC (rev 20167)
@@ -21,20 +21,23 @@
## @brief Check state variables output from PyLith.
import numpy
+import h5py
def check_state_variables(testcase, filename, mesh, stateVarNames):
"""
Check state variables.
"""
- data = testcase.reader.read(filename)
+ h5 = h5py.File(filename, "r", driver="sec2")
# Check cells
- (ncells, ncorners) = data['cells'].shape
+ cells = h5['topology/cells'][:]
+ (ncells, ncorners) = cells.shape
testcase.assertEqual(mesh['ncells'], ncells)
testcase.assertEqual(mesh['ncorners'], ncorners)
# Check vertices
- (nvertices, spaceDim) = data['vertices'].shape
+ vertices = h5['geometry/vertices'][:]
+ (nvertices, spaceDim) = vertices.shape
testcase.assertEqual(mesh['nvertices'], nvertices)
testcase.assertEqual(mesh['spaceDim'], spaceDim)
@@ -46,32 +49,33 @@
tolerance = 1.0e-6
for name in stateVarNames:
- valuesE = testcase.calcStateVar(name, data['vertices'], data['cells'])
- values = data['cell_fields'][name]
+ valuesE = testcase.calcStateVar(name, vertices, cells)
+ values = h5['cell_fields/%s' % name][:]
- (ncellsE, dimE) = valuesE.shape
- if 1 == dimE:
- values = values.reshape( (ncells, dimE) )
- (ncells, dim) = values.shape
+ (nstepsE, ncellsE, ncompsE) = valuesE.shape
+ (nsteps, ncells, ncomps) = values.shape
+ testcase.assertEqual(nstepsE, nsteps)
testcase.assertEqual(ncellsE, ncells)
- testcase.assertEqual(dimE, dim)
+ testcase.assertEqual(ncompsE, ncomps)
scale = 1.0
if name == "stress":
scale *= normalizer.pressureScale().value
- for i in xrange(dim):
- ratio = numpy.abs(1.0 - values[:,i]/valuesE[:,i])
- diff = numpy.abs(values[:,i] - valuesE[:,i]) / scale
- 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)
-
+ for istep in xrange(nsteps):
+ for icomp in xrange(ncomps):
+ ratio = numpy.abs(1.0 - values[istep,:,icomp]/valuesE[istep,:,icomp])
+ diff = numpy.abs(values[istep,:,icomp] - valuesE[istep,:,icomp]) / scale
+ mask = valuesE[istep,:,icomp] != 0.0
+ okay = mask*(ratio < tolerance) + ~mask*(diff < tolerance)
+ if numpy.sum(okay) != ncells:
+ print "Error in component %d of state variable '%s' at time step %d." % (icomp, name, istep)
+ print "Expected values:",valuesE
+ print "Output values:",values
+ testcase.assertEqual(ncells, numpy.sum(okay))
+
+ h5.close()
return
Modified: short/3D/PyLith/branches/v1.7-trunk/pylith/tests/__init__.py
===================================================================
--- short/3D/PyLith/branches/v1.7-trunk/pylith/tests/__init__.py 2012-05-17 00:29:45 UTC (rev 20166)
+++ short/3D/PyLith/branches/v1.7-trunk/pylith/tests/__init__.py 2012-05-17 01:02:43 UTC (rev 20167)
@@ -23,4 +23,18 @@
]
+def has_h5py():
+ if not "flag" in dir(has_h5py):
+ try:
+ import h5py
+ has_h5py.flag = True
+ except ImportError:
+ print "WARNING: Cannot find h5py Python modele."
+ print " Tests limited to running PyLith without errors."
+ print " Install h5py (available via the installer utility) "
+ print " in order to enable verification of output."
+ has_h5py.flag = False
+ return has_h5py.flag
+
+
# End of file
More information about the CIG-COMMITS
mailing list