[cig-commits] r7584 - short/3D/PyLith/trunk/playpen/verification
brad at geodynamics.org
brad at geodynamics.org
Sun Jul 1 16:15:33 PDT 2007
Author: brad
Date: 2007-07-01 16:15:33 -0700 (Sun, 01 Jul 2007)
New Revision: 7584
Modified:
short/3D/PyLith/trunk/playpen/verification/verify.py
Log:
Converted verify script to Pyre application.
Modified: short/3D/PyLith/trunk/playpen/verification/verify.py
===================================================================
--- short/3D/PyLith/trunk/playpen/verification/verify.py 2007-07-01 21:57:03 UTC (rev 7583)
+++ short/3D/PyLith/trunk/playpen/verification/verify.py 2007-07-01 23:15:33 UTC (rev 7584)
@@ -1,65 +1,151 @@
#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file verification/verify
+
+## @brief Python application to check VTK files from 1 processor and 2
+## processor runs of PyLith.
+
import os, re, sys
-class Verifier:
- def __init__(self):
- self.pylith = '/Users/brad/tools/cig/gcc-4.0/bin/pylith'
-# self.petscOpts = ['--petsc.ksp_type=preonly', '--petsc.pc_type=lu', '--petsc.mat_type=aijmumps']
- self.petscOpts = ['--petsc.pc_type=asm']
- self.exp = re.compile(r'SCALARS \w+_verify_t. double 4')
+from pyre.applications.Script import Script as Application
+
+class Verifier(Application):
+ """
+ Python application to check VTK files from 1 processor and 2
+ processors runs of PyLith.
+ """
+
+ class Inventory(Application.Inventory):
+ """
+ Python object for managing Verifier facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing Verifier facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b cfg_file Filename of .cfg file with simulation parameters.
+ ## @li \b pylith Absolute path to 'pylith' executable.
+ ## @li \b petsc_options PETSc options.
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ cfgFile = pyre.inventory.str("cfg_file", default="pylithapp.cfg")
+ cfgFile.meta['tip'] = "Filename of .cfg file with simulation parameters."
+
+ pylith = pyre.inventory.str("pylith", default="`which pylith`")
+ pylith.meta['tip'] = "Absolute path to 'pylith' executable."
+
+ petscOptions = pyre.inventory.list("petsc_options",
+ default=['--petsc.ksp_type=preonly',
+ '--petsc.pc_type=lu',
+ '--petsc.mat_type=aijmumps'])
+ petscOptions.meta['tip'] = "PETSc options."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="verifyapp"):
+ Application.__init__(self, name)
+ self.exp = re.compile(r'SCALARS \w+_verify_t. double 4')
return
- def readVTK(self, filename):
+
+ def main(self):
+ outputFiles = []
+ for p in [1, 2]:
+ basename = os.path.splitext(os.path.basename(self.cfgFile))[0] + \
+ '_p'+str(p)
+ outputname = basename+'.vtk'
+ outputFiles.append(basename+'_t0.vtk')
+ cmd = '%s --nodes=%d %s --problem.formulation.output.output.filename=%s %s' % \
+ (self.pylith, p, ' '.join(self.petscOptions), outputname,
+ self.cfgFile)
+ print 'Running %s' % cmd
+ os.system(cmd)
+ for file1, file2 in zip(outputFiles[:-1], outputFiles[1:]):
+ self._compare(file1, file2)
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Setup members using inventory.
+ """
+ Application._configure(self)
+ self.cfgFile = self.inventory.cfgFile
+ self.pylith = self.inventory.pylith
+ self.petscOptions = self.inventory.petscOptions
+ return
+
+
+ def _readVTK(self, filename):
f = file(filename)
found = False
data = []
for line in f.readlines():
if self.exp.match(line):
found = True
- if found and not line.startswith('LOOKUP') and not line.startswith('SCALARS'):
+ if found and \
+ not line.startswith('LOOKUP') and \
+ not line.startswith('SCALARS'):
data.append(line)
f.close()
data.sort()
return data
- def compare(self, file1, file2):
- def convertLine(line):
+ def _compare(self, file1, file2):
+ def _convertLine(line):
parts = line.split()
return (int(parts[0]), float(parts[1]), float(parts[2]), float(parts[3]))
- data1 = self.readVTK(file1)
- data2 = self.readVTK(file2)
+ data1 = self._readVTK(file1)
+ data2 = self._readVTK(file2)
if not data1 == data2:
# Do full check
+ ok = True
for line1, line2 in zip(data1, data2):
- v1,x1,y1,z1 = convertLine(line1)
- v2,x2,y2,z2 = convertLine(line2)
+ v1,x1,y1,z1 = _convertLine(line1)
+ v2,x2,y2,z2 = _convertLine(line2)
if not v1 == v2:
- sys.exit('ERROR: Nonmatching vertex sets')
+ ok = False
+ print('ERROR: Nonmatching vertex sets')
if abs(x1 - x2) > 1.0e-10:
- sys.exit('ERROR: Nonmatching x displacement, vertex %d, %g != %g' % (v1, x1, x2))
+ ok = False
+ print('ERROR: Nonmatching x displacement, vertex %d, %g != %g' % \
+ (v1, x1, x2))
if abs(y1 - y2) > 1.0e-10:
- sys.exit('ERROR: Nonmatching y displacement, vertex %d, %g != %g' % (v1, y1, y2))
+ ok = False
+ print('ERROR: Nonmatching y displacement, vertex %d, %g != %g' % \
+ (v1, y1, y2))
if abs(z1 - z2) > 1.0e-10:
- sys.exit('ERROR: Nonmatching z displacement, vertex %d, %g != %g' % (v1, z1, z2))
- print file1,'matches',file2
+ ok = False
+ print('ERROR: Nonmatching z displacement, vertex %d, %g != %g' % \
+ (v1, z1, z2))
+ if not ok:
+ sys.exit("File '%s' DOES NOT MATCH file '%s'." % (file1, file2))
+ print "File '%s' MATCHES '%s'." % (file1, file2)
return
- def run(self, cfgFilename):
- outputFiles = []
- for p in [1, 2]:
- basename = os.path.splitext(os.path.basename(cfgFilename))[0]+'_p'+str(p)
- outputname = basename+'.vtk'
- outputFiles.append(basename+'_t0.vtk')
- cmd = '%s --nodes=%d %s --problem.formulation.output.output.filename=%s %s' % (self.pylith, p, ' '.join(self.petscOpts), outputname, cfgFilename)
- print 'Running',cmd
- os.system(cmd)
- for file1, file2 in zip(outputFiles[:-1], outputFiles[1:]):
- self.compare(file1, file2)
- return
+# ----------------------------------------------------------------------
if __name__ == '__main__':
- if not len(sys.argv) == 2:
- print 'Usage: verify.py <cfg file>'
- sys.exit()
- Verifier().run(sys.argv[1])
+ app = Verifier()
+ app.run()
+
+# End of file
More information about the cig-commits
mailing list