[cig-commits] r5120 -
cs/benchmark/trunk/benchmark/short/applications
brad at geodynamics.org
brad at geodynamics.org
Mon Oct 30 15:07:46 PST 2006
Author: brad
Date: 2006-10-30 15:07:45 -0800 (Mon, 30 Oct 2006)
New Revision: 5120
Modified:
cs/benchmark/trunk/benchmark/short/applications/femlabtoh5.py
Log:
Updated to allow multiple time steps.
Modified: cs/benchmark/trunk/benchmark/short/applications/femlabtoh5.py
===================================================================
--- cs/benchmark/trunk/benchmark/short/applications/femlabtoh5.py 2006-10-30 22:48:56 UTC (rev 5119)
+++ cs/benchmark/trunk/benchmark/short/applications/femlabtoh5.py 2006-10-30 23:07:45 UTC (rev 5120)
@@ -37,7 +37,8 @@
## Python object for managing Translator facilities and properties.
##
## \b Properties
- ## @li \b ascii_file Name of file containing analytical solution.
+ ## @li \b scenario_root Filename root for simulation scenario.
+ ## @li \b time_steps Indices of time steps
## @li \b h5_file Name of HDF5 file to create.
##
## \b Facilities
@@ -45,9 +46,13 @@
import pyre.inventory
- asciiFile = pyre.inventory.str("ascii_file", default="points.disp")
- asciiFile.meta['tip'] = "Name of file containing analytical solution."
-
+ scenarioRoot = pyre.inventory.str("scenario_root",
+ default="output/femlab/tet4_1000m")
+ scenarioRoot.meta['tip'] = "Filename root for simulation scenario."
+
+ timeSteps = pyre.inventory.list("time_steps", default=[0,10,50,100])
+ timeSteps.meta['tip'] = "Indices of time steps."
+
h5File = pyre.inventory.str("h5_file", default="points.h5")
h5File.meta['tip'] = "Name of HDF5 file to create."
@@ -64,30 +69,37 @@
Entry point for application.
"""
- npts = self._countLines(self.asciiFile)
- ndims = 3
+ import tables
+ fileOut = tables.openFile(self.h5File, 'w')
- points = numpy.zeros( (npts, ndims), dtype=numpy.Float32)
- displacements = numpy.zeros( (npts, ndims), dtype=numpy.Float32)
+ for timeStep in self.timeSteps:
+ filename = "%s_t%02d.dat" % (self.scenarioRoot, timeStep/10)
- filein = open(self.asciiFile, 'r')
- ipt = 0
- for line in filein:
- values = map(float, line.split())
- points[ipt] = tuple(values[0:3])
- displacements[ipt] = tuple(values[3:6])
- ipt += 1
- filein.close()
+ npts = self._countLines(filename)
+ ndims = 3
- import tables
- fileOut = tables.openFile(self.h5File, 'w')
+ points = numpy.zeros( (npts, ndims), dtype=numpy.Float32)
+ displacements = numpy.zeros( (npts, ndims), dtype=numpy.Float32)
- group = createGroup(fileOut, fileOut.root, "projection")
- fileOut.createArray(group, "points", points)
+ filein = open(filename, 'r')
+ ipt = 0
+ for line in filein:
+ values = map(float, line.split())
+ points[ipt] = tuple(values[0:3])
+ displacements[ipt] = tuple(values[3:6])
+ ipt += 1
+ filein.close()
- group = createGroup(fileOut, fileOut.root,
- "projection/data/snapshot0")
- fileOut.createArray(group, "displacements", displacements)
+ group = createGroup(fileOut, fileOut.root, "projection")
+ try:
+ fileOut.createArray(group, "points", points)
+ except tables.exceptions.NodeError:
+ print "Points already exist..." \
+ " skipping adding points for time index %d" % timeStep
+
+ group = createGroup(fileOut, fileOut.root,
+ "projection/data/snapshot%d" % timeStep)
+ fileOut.createArray(group, "displacements", displacements)
fileOut.close()
return
@@ -100,7 +112,8 @@
"""
Script._configure(self)
- self.asciiFile = self.inventory.asciiFile
+ self.scenarioRoot = self.inventory.scenarioRoot
+ self.timeSteps = map(int, self.inventory.timeSteps)
self.h5File = self.inventory.h5File
return
More information about the cig-commits
mailing list