[cig-commits] r14991 - in short/3D/PyLith/trunk: pylith/meshio unittests/pytests/meshio

brad at geodynamics.org brad at geodynamics.org
Tue May 12 16:51:56 PDT 2009


Author: brad
Date: 2009-05-12 16:51:56 -0700 (Tue, 12 May 2009)
New Revision: 14991

Modified:
   short/3D/PyLith/trunk/pylith/meshio/OutputManager.py
   short/3D/PyLith/trunk/unittests/pytests/meshio/TestOutputManagerMesh.py
Log:
Fixed bug associted with estimating the number of time steps associated with output.

Modified: short/3D/PyLith/trunk/pylith/meshio/OutputManager.py
===================================================================
--- short/3D/PyLith/trunk/pylith/meshio/OutputManager.py	2009-05-12 22:30:48 UTC (rev 14990)
+++ short/3D/PyLith/trunk/pylith/meshio/OutputManager.py	2009-05-12 23:51:56 UTC (rev 14991)
@@ -154,13 +154,7 @@
     logEvent = "%sopen" % self._loggingPrefix
     self._logger.eventBegin(logEvent)    
 
-    nsteps = numTimeSteps
-    if numTimeSteps > 0 and self.outputFreq == "skip" and self.skip > 0:
-      nsteps = int(numTimeSteps / (1+self.skip))
-    elif numTimeSteps > 0 and self.outputFreq == "time_step":
-      timeScale = self.normalizer.timeScale()
-      totalTimeN = self.normalizer.nondimensionalize(totalTime, timeScale)
-      nsteps = int(1 + totalTimeN / self.dtN)
+    nsteps = self._estimateNumSteps(totalTime, numTimeSteps)
 
     (mesh, label, labelId) = self.dataProvider.getDataMesh()
     self._open(mesh, nsteps, label, labelId)
@@ -253,8 +247,24 @@
     """
     raise NotImplementedError, \
         "Please implement _createModuleObj() in derived class."
+    return
+  
 
+  def _estimateNumSteps(self, totalTime, numTimeSteps):
+    """
+    Estimate the number of time steps we expect to output.
+    """
+    nsteps = numTimeSteps
+    if numTimeSteps > 0 and self.outputFreq == "skip" and self.skip > 0:
+      nsteps = int(1 + (numTimeSteps-1) / (1+self.skip))
+    elif numTimeSteps > 0 and self.outputFreq == "time_step":
+      timeScale = self.normalizer.timeScale()
+      totalTimeN = self.normalizer.nondimensionalize(totalTime, timeScale)
+      nsteps = int(1 + totalTimeN / self.dtN)
 
+    return nsteps
+
+
   def _checkWrite(self, t):
     """
     Check if we want to write data at time t.

Modified: short/3D/PyLith/trunk/unittests/pytests/meshio/TestOutputManagerMesh.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/meshio/TestOutputManagerMesh.py	2009-05-12 22:30:48 UTC (rev 14990)
+++ short/3D/PyLith/trunk/unittests/pytests/meshio/TestOutputManagerMesh.py	2009-05-12 23:51:56 UTC (rev 14991)
@@ -260,6 +260,51 @@
     return
 
 
+  def test_estimateNumSteps(self):
+    """
+    Test _estimateNumSteps().
+    """
+    from pyre.units.time import second
+
+    output = OutputManagerMesh()
+    output.inventory.outputFreq = "skip"
+    output.inventory.skip = 2
+    output._configure()
+
+    numTimeSteps = 0
+    totalTime = 1.0*second
+    self.assertEqual(0, output._estimateNumSteps(totalTime, numTimeSteps))
+
+    numTimeSteps = 4
+    totalTime = 1.0*second
+    self.assertEqual(2, output._estimateNumSteps(totalTime, numTimeSteps))
+
+    numTimeSteps = 2
+    totalTime = 1.0*second
+    self.assertEqual(1, output._estimateNumSteps(totalTime, numTimeSteps))
+
+    output = OutputManagerMesh()
+    output.inventory.outputFreq = "time_step"
+    output.inventory.dt = 2.0*second
+    output._configure()
+    dataProvider = TestProvider()
+    output.preinitialize(dataProvider)
+    output.initialize(self.normalizer)
+
+    numTimeSteps = 0
+    totalTime = 1.0*second
+    self.assertEqual(0, output._estimateNumSteps(totalTime, numTimeSteps))
+
+    numTimeSteps = 4
+    totalTime = 1.0*second
+    self.assertEqual(1, output._estimateNumSteps(totalTime, numTimeSteps))
+
+    numTimeSteps = 2
+    totalTime = 2.0*second
+    self.assertEqual(2, output._estimateNumSteps(totalTime, numTimeSteps))
+    return
+
+
   def test_checkWrite(self):
     """
     Test _checkWrite().



More information about the CIG-COMMITS mailing list