[cig-commits] r14327 - short/3D/PyLith/trunk/playpen/postproc

willic3 at geodynamics.org willic3 at geodynamics.org
Sun Mar 15 17:26:57 PDT 2009


Author: willic3
Date: 2009-03-15 17:26:56 -0700 (Sun, 15 Mar 2009)
New Revision: 14327

Modified:
   short/3D/PyLith/trunk/playpen/postproc/vtkdiff.cfg
   short/3D/PyLith/trunk/playpen/postproc/vtkdiff.py
Log:
Updated vtkdiff.py and associated .cfg file to be equivalent to versions in
2.5D/benchmarks/savageprescott/utils.



Modified: short/3D/PyLith/trunk/playpen/postproc/vtkdiff.cfg
===================================================================
--- short/3D/PyLith/trunk/playpen/postproc/vtkdiff.cfg	2009-03-16 00:21:01 UTC (rev 14326)
+++ short/3D/PyLith/trunk/playpen/postproc/vtkdiff.cfg	2009-03-16 00:26:56 UTC (rev 14327)
@@ -2,6 +2,9 @@
 [vtkdiff]
 
 # Top-level info
+# Convert meters to cm, so results will be in cm/year.
+scale_factor = 100.0
+
+# Filename info
 vtk_input_root = savageprescott-groundsurf
 vtk_output_root = savageprescott-groundsurf-diff
-time_scale = 1.0*year

Modified: short/3D/PyLith/trunk/playpen/postproc/vtkdiff.py
===================================================================
--- short/3D/PyLith/trunk/playpen/postproc/vtkdiff.py	2009-03-16 00:21:01 UTC (rev 14326)
+++ short/3D/PyLith/trunk/playpen/postproc/vtkdiff.py	2009-03-16 00:26:56 UTC (rev 14327)
@@ -38,7 +38,7 @@
     ## \b Properties
     ## @li \b vtk_input_root Root filename for VTK input files.
     ## @li \b vtk_output_root Root filename for VTK output files.
-    ## @li \b time_scale Time scaling factor used in input filenames.
+    ## @li \b scale_factor Scale factor to apply to results.
 
     import pyre.inventory
 
@@ -48,8 +48,8 @@
     vtkOutputRoot = pyre.inventory.str("vtk_output_root", default="output.vtk")
     vtkOutputRoot.meta['tip'] = "Root filename for VTK output files."
 
-    timeScale = pyre.inventory.dimensional("time_scale", default=1.0*s)
-    timeScale.meta['tip'] = "Time scaling factor for used in input files."
+    scaleFactor = pyre.inventory.float("scale_factor", default=1.0)
+    scaleFactor.meta['tip'] = "Scaling factor to apply to results."
 
 
   class TooFewFilesError(IOError):
@@ -76,11 +76,9 @@
 
     self.numVertsPerCell = 0
     self.numCells = 0
-    self.cellsArray = numpy.array([0])
-    self.verticesArray = numpy.array([0])
     self.numVerts = 0
     self.spaceDim = 0
-    self.cellType = ""
+    self.cellType = None
     self.readMesh = False
     return
 
@@ -137,7 +135,7 @@
     else:
       self.vtkOutputRoot = baseOutputNameStripped
 
-    self.timeScale = self.inventory.timeScale.value
+    self.scaleFactor = self.inventory.scaleFactor
 
     return
 
@@ -153,6 +151,7 @@
     fileString = self.vtkInputRoot + "_t[0-9]*.vtk"
     searchString = os.path.join(self.vtkInputDir, fileString)
     self.vtkInputList = glob.glob(searchString)
+    self.vtkInputList.sort()
     self.numVtkInputFiles = len(self.vtkInputList)
     if self.numVtkInputFiles < 2:
       try:
@@ -185,7 +184,8 @@
     for fileInd in range(self.numVtkInputFiles - 1):
       timeStamp1 = self.vtkInputTimes[fileInd]
       timeStamp2 = self.vtkInputTimes[fileInd + 1]
-      dt = self.timeScale * (timeStamp2 - timeStamp1)
+      dt = (timeStamp2 - timeStamp1)/self.scaleFactor
+      # We assume that differences correspond to midpoint of the 2 time steps.
       timeStampOut = int(0.5 * (timeStamp1 + timeStamp2))
       timeStampOutString = repr(timeStampOut).rjust(self.timeStampWidth, '0')
       outputFileName = self.vtkOutputRoot + "_t" + timeStampOutString + ".vtk"
@@ -236,58 +236,58 @@
     numVertDataArrays = vertData1._get_number_of_arrays()
     if numVertDataArrays != 0:
       vertData2 = data2._get_point_data()
-    # This is very kludgy because I haven't yet figured out how to include
-    # multiple scalar or vector fields, and I also don't know how to put in
-    # a name for a general array (represented as a field).
-    numScalarsUsed = 0
-    numVectorsUsed = 0
-    for vertDataArray in range(numVertDataArrays):
-      array1 = vertData1.get_array(vertDataArray).to_array()
-      (numPoints, numCols) = array1.shape
-      arrayName = vertData1.get_array_name(vertDataArray) + "/dt"
-      array2 = vertData2.get_array(vertDataArray).to_array()
-      arrayOut = (array2 - array1)/dt
-      # This is wrong if we have a scalar field with 3 components
-      if (numCols == 3 and numVectorsUsed == 0):
-        mesh.point_data.vectors = arrayOut
-        mesh.point_data.vectors.name = arrayName
-        numVectorsUsed += 1
-      elif numScalarsUsed == 0:
-        mesh.point_data.scalars = arrayOut
-        mesh.point_data.scalars.name = arrayName
-        numScalarsUsed += 1
-      # Kludge to add a general array
-      else:
-        mesh.point_data.add_array(arrayOut)
+      # This is very kludgy because I haven't yet figured out how to include
+      # multiple scalar or vector fields, and I also don't know how to put in
+      # a name for a general array (represented as a field).
+      numScalarsUsed = 0
+      numVectorsUsed = 0
+      for vertDataArray in range(numVertDataArrays):
+        array1 = vertData1.get_array(vertDataArray).to_array()
+        (numPoints, numCols) = array1.shape
+        arrayName = vertData1.get_array_name(vertDataArray) + "/dt"
+        array2 = vertData2.get_array(vertDataArray).to_array()
+        arrayOut = (array2 - array1)/dt
+        # This is wrong if we have a scalar field with 3 components
+        if (numCols == 3 and numVectorsUsed == 0):
+          mesh.point_data.vectors = arrayOut
+          mesh.point_data.vectors.name = arrayName
+          numVectorsUsed += 1
+        elif numScalarsUsed == 0:
+          mesh.point_data.scalars = arrayOut
+          mesh.point_data.scalars.name = arrayName
+          numScalarsUsed += 1
+        # Kludge to add a general array
+        else:
+          mesh.point_data.add_array(arrayOut)
 
     # Get cell fields and compute differences if the fields exist
     cellData1 = data1._get_cell_data()
     numCellDataArrays = cellData1._get_number_of_arrays()
     if numCellDataArrays != 0:
       cellData2 = data2._get_cell_data()
-    # This is very kludgy because I haven't yet figured out how to include
-    # multiple scalar or vector fields, and I also don't know how to put in
-    # a name for a general array (represented as a field).
-    numScalarsUsed = 0
-    numVectorsUsed = 0
-    for cellDataArray in range(numCellDataArrays):
-      array1 = cellData1.get_array(cellDataArray).to_array()
-      (numPoints, numCols) = array1.shape
-      arrayName = cellData1.get_array_name(cellDataArray) + "/dt"
-      array2 = cellData2.get_array(cellDataArray).to_array()
-      arrayOut = (array2 - array1)/dt
-      # This is wrong if we have a scalar field with 3 components
-      if (numCols == 3 and numVectorsUsed == 0):
-        mesh.cell_data.vectors = arrayOut
-        mesh.cell_data.vectors.name = arrayName
-        numVectorsUsed += 1
-      elif numScalarsUsed == 0:
-        mesh.cell_data.scalars = arrayOut
-        mesh.cell_data.scalars.name = arrayName
-        numScalarsUsed += 1
-      # Kludge to add a general array
-      else:
-        mesh.cell_data.add_array(arrayOut)
+      # This is very kludgy because I haven't yet figured out how to include
+      # multiple scalar or vector fields, and I also don't know how to put in
+      # a name for a general array (represented as a field).
+      numScalarsUsed = 0
+      numVectorsUsed = 0
+      for cellDataArray in range(numCellDataArrays):
+        array1 = cellData1.get_array(cellDataArray).to_array()
+        (numPoints, numCols) = array1.shape
+        arrayName = cellData1.get_array_name(cellDataArray) + "/dt"
+        array2 = cellData2.get_array(cellDataArray).to_array()
+        arrayOut = (array2 - array1)/dt
+        # This is wrong if we have a scalar field with 3 components
+        if (numCols == 3 and numVectorsUsed == 0):
+          mesh.cell_data.vectors = arrayOut
+          mesh.cell_data.vectors.name = arrayName
+          numVectorsUsed += 1
+        elif numScalarsUsed == 0:
+          mesh.cell_data.scalars = arrayOut
+          mesh.cell_data.scalars.name = arrayName
+          numScalarsUsed += 1
+        # Kludge to add a general array
+        else:
+          mesh.cell_data.add_array(arrayOut)
 
     # Write results to VTK file
     w = tvtk.UnstructuredGridWriter(file_name=vtkFileOut, input=mesh)



More information about the CIG-COMMITS mailing list