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

brad at geodynamics.org brad at geodynamics.org
Mon Jul 7 08:46:21 PDT 2008


Author: brad
Date: 2008-07-07 08:46:21 -0700 (Mon, 07 Jul 2008)
New Revision: 12383

Modified:
   short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
   short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
Log:
Added loop switch for user specified time steps. Updated corresponding unit tests.

Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py	2008-07-07 09:53:56 UTC (rev 12382)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py	2008-07-07 15:46:21 UTC (rev 12383)
@@ -66,6 +66,8 @@
     ## \b Properties
     ## @li \b total_time Time duration for simulation.
     ## @li \b filename Name of file with time step sizes.
+    ## @li \b loop_steps Loop over steps if true, otherwise keep
+    ##   using last time step size.
     ##
     ## \b Facilities
     ## @li None
@@ -80,7 +82,11 @@
     filename = pyre.inventory.str("filename", default="timesteps.txt")
     filename.meta['tip'] = "Name of file with tme step sizes."
 
+    loopSteps = pyre.inventory.bool("loop_steps", default=False)
+    loopSteps.meta['tip'] = "Loop over steps if true, otherwise keep " \
+                            "using last time step size."
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="timestepuser"):
@@ -123,7 +129,10 @@
       t += self.steps[index]
       index += 1
       if index >= len(self.steps):
-        index = 0
+        if self.loopSteps:
+          index = 0
+        else:
+          index -= 1
       nsteps += 1
     return nsteps
 
@@ -135,7 +144,10 @@
     self.dt = self.steps[self.index]
     self.index += 1
     if self.index >= len(self.steps):
-      self.index = 0
+      if self.loopSteps:
+        self.index = 0
+      else:
+        self.index -= 1
     return self.dt
 
   
@@ -148,6 +160,7 @@
     TimeStep._configure(self)
     self.totalTime = self.inventory.totalTime
     self.filename = self.inventory.filename
+    self.loopSteps = self.inventory.loopSteps
     return
 
 

Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py	2008-07-07 09:53:56 UTC (rev 12382)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py	2008-07-07 15:46:21 UTC (rev 12383)
@@ -65,6 +65,10 @@
 
     self.assertEqual(1, tstep.numTimeSteps())
 
+    tstep.totalTime = 12.0*year
+    self.assertEqual(6, tstep.numTimeSteps())
+
+    tstep.loopSteps = True
     tstep.totalTime = 7.0*year
     self.assertEqual(5, tstep.numTimeSteps())
     return
@@ -84,8 +88,16 @@
     self.assertEqual(1.0*year, tstep.timeStep(0.5*year))
     self.assertEqual(2.0*year, tstep.timeStep(0.5*year))
     self.assertEqual(3.0*year, tstep.timeStep(0.5*year))
+    self.assertEqual(3.0*year, tstep.timeStep(0.5*year))
+    self.assertEqual(3.0*year, tstep.timeStep(0.5*year))
+
+    tstep.index = 0
+    tstep.loopSteps = True
     self.assertEqual(1.0*year, tstep.timeStep(0.5*year))
     self.assertEqual(2.0*year, tstep.timeStep(0.5*year))
+    self.assertEqual(3.0*year, tstep.timeStep(0.5*year))
+    self.assertEqual(1.0*year, tstep.timeStep(0.5*year))
+    self.assertEqual(2.0*year, tstep.timeStep(0.5*year))
     return
 
 



More information about the cig-commits mailing list