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

brad at geodynamics.org brad at geodynamics.org
Sun Jul 6 15:06:56 PDT 2008


Author: brad
Date: 2008-07-06 15:06:55 -0700 (Sun, 06 Jul 2008)
New Revision: 12377

Added:
   short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py
   short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
   short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py
   short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py
   short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
   short/3D/PyLith/trunk/unittests/pytests/problems/data/
   short/3D/PyLith/trunk/unittests/pytests/problems/data/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/problems/data/timesteps.txt
Modified:
   short/3D/PyLith/trunk/configure.ac
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/problems/TimeStep.py
   short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
   short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am
   short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py
   short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py
Log:
Added TimeStepUser and TimeStepAdapt. Added corresponding unit tests. Still need to integrate calculation of stable time step.

Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/configure.ac	2008-07-06 22:06:55 UTC (rev 12377)
@@ -253,6 +253,7 @@
 		unittests/pytests/meshio/Makefile
 		unittests/pytests/meshio/data/Makefile
 		unittests/pytests/problems/Makefile
+		unittests/pytests/problems/data/Makefile
 		unittests/pytests/topology/Makefile
 		unittests/pytests/topology/data/Makefile
 		unittests/pytests/utils/Makefile

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2008-07-06 22:06:55 UTC (rev 12377)
@@ -99,7 +99,9 @@
 	problems/Problem.py \
 	problems/TimeDependent.py \
 	problems/TimeStep.py \
+	problems/TimeStepAdapt.py \
 	problems/TimeStepUniform.py \
+	problems/TimeStepUser.py \
 	solver/__init__.py \
 	solver/Solver.py \
 	solver/SolverLinear.py \

Modified: short/3D/PyLith/trunk/pylith/problems/TimeStep.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStep.py	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStep.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -37,6 +37,7 @@
     Component.__init__(self, name, facility="time_step")
     from pyre.units.time import second
     self.totalTime = 0.0*second
+    self.dt = 0.0*second
     return
 
 
@@ -93,8 +94,7 @@
     """
     Get current time step size.
     """
-    raise NotImplementedError("Please implement currentStep().");
-    return
+    return self.dt
   
 
   # PRIVATE METHODS ////////////////////////////////////////////////////

Added: short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,126 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/problems/TimeStepAdapt.py
+##
+## @brief Python class for marching forward in time with irregular
+## time steps that adapt to the solution.
+##
+## Factory: time_step
+
+from TimeStep import TimeStep
+
+from pylith.utils.profiling import resourceUsageString
+
+# TimeStepAdapt class
+class TimeStepAdapt(TimeStep):
+  """
+  Python abstract base class for marching format in time with
+  irregular time steps that adapt to the solution.
+
+  Factory: time_step.
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(TimeStep.Inventory):
+    """
+    Python object for managing TimeStepAdapt facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing TimeStepAdapt facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b total_time Time duration for simulation.
+    ## @li \b max_dt Maximum time step.
+    ## @li \b adapt_skip Number of time steps to skip between adjusting value.
+    ##
+    ## \b Facilities
+    ## @li None
+
+    import pyre.inventory
+
+    from pyre.units.time import second
+    totalTime = pyre.inventory.dimensional("total_time", default=0.0*second,
+                          validator=pyre.inventory.greaterEqual(0.0*second))
+    totalTime.meta['tip'] = "Time duration for simulation."
+
+    maxDt = pyre.inventory.dimensional("max_dt", default=1.0*second,
+                                    validator=pyre.inventory.greater(0.0*second))
+    maxDt.meta['tip'] = "Maximum time step."
+
+    adaptSkip = pyre.inventory.int("adapt_skip", default=10,
+                                   validator=pyre.inventory.greaterEqual(0))
+    adaptSkip.meta['tip'] = "Number of time steps to skip between " \
+        "adjusting value."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="timestepadapt"):
+    """
+    Constructor.
+    """
+    TimeStep.__init__(self, name)
+    self.skipped = 0
+    return
+
+
+  def numTimeSteps(self):
+    """
+    Get number of total time steps (or best guess if adaptive).
+    """
+    # Guess using maximum time step
+    nsteps = 1.0 + int(self.totalTime / self.maxDt)
+    return nsteps
+
+
+  def timeStep(self, dtStable):
+    """
+    Adjust stable time step for advancing forward in time.
+    """
+    from pyre.units.time import second
+    if self.skipped < self.adaptSkip and \
+          self.dt != 0.0*second and \
+          self.dt < dtStable:
+      self.skipped += 1
+    else:
+      self.dt = min(dtStable, self.maxDt)
+      self.skipped = 0
+    return self.dt
+
+  
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    TimeStep._configure(self)
+    self.totalTime = self.inventory.totalTime
+    self.maxDt = self.inventory.maxDt
+    self.adaptSkip = self.inventory.adaptSkip
+    self.dt = self.maxDt
+    return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def time_step():
+  """
+  Factory associated with TimeStepAdapt.
+  """
+  return TimeStepAdapt()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -40,7 +40,7 @@
     ##
     ## \b Properties
     ## @li \b total_time Time duration for simulation.
-    ## @li \b default_dt Default time step.
+    ## @li \b dt Default time step.
     ##
     ## \b Facilities
     ## @li None
@@ -81,13 +81,6 @@
     return self.dt
 
   
-  def currentStep(self):
-    """
-    Get current time step size.
-    """
-    return self.dt
-  
-
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):

Added: short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,200 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/problems/TimeStepUser.py
+##
+## @brief Python class for marching forward in time with user
+## specified time steps.  Time step sizes are repeated until total
+## time is reached.
+##
+## Format of file with user specified time steps:
+##
+## Notes: Whitespace is ignored. Comment lines begin with '#'.
+##
+## units = VALUE
+##
+## dt0
+## dt1
+## dt2
+##
+## Factory: time_step
+
+from TimeStep import TimeStep
+
+from pylith.utils.profiling import resourceUsageString
+
+# TimeStepUser class
+class TimeStepUser(TimeStep):
+  """
+  Python abstract base class for marching format in time with user
+  specified time steps. Time step sizes are repeated until total time
+  is reached.
+
+
+  Format of file with user specified time steps:
+
+  Notes: Whitespace is ignored. Comment lines begin with '#'.
+
+  units = VALUE
+
+  dt0
+  dt1
+  dt2
+
+  Factory: time_step.
+  """
+
+  # INVENTORY //////////////////////////////////////////////////////////
+
+  class Inventory(TimeStep.Inventory):
+    """
+    Python object for managing TimeStepUser facilities and properties.
+    """
+
+    ## @class Inventory
+    ## Python object for managing TimeStepUser facilities and properties.
+    ##
+    ## \b Properties
+    ## @li \b total_time Time duration for simulation.
+    ## @li \b filename Name of file with time step sizes.
+    ##
+    ## \b Facilities
+    ## @li None
+
+    import pyre.inventory
+
+    from pyre.units.time import second
+    totalTime = pyre.inventory.dimensional("total_time", default=0.0*second,
+                          validator=pyre.inventory.greaterEqual(0.0*second))
+    totalTime.meta['tip'] = "Time duration for simulation."
+
+    filename = pyre.inventory.str("filename", default="timesteps.txt")
+    filename.meta['tip'] = "Name of file with tme step sizes."
+
+
+  # PUBLIC METHODS /////////////////////////////////////////////////////
+
+  def __init__(self, name="timestepuser"):
+    """
+    Constructor.
+    """
+    TimeStep.__init__(self, name)
+    self.steps = []
+    self.index = 0
+    return
+
+
+  def initialize(self):
+    """
+    Initialize time step algorithm.
+    """
+    logEvent = "%sinit" % self._loggingPrefix
+    self._logger.eventBegin(logEvent)
+
+    TimeStep.initialize(self)
+
+    self._readSteps()
+    assert(len(self.steps) > 0)
+    assert(self.index == 0)
+    self.dt = self.steps[self.index]
+
+    self._logger.eventEnd(logEvent)
+    return
+
+
+  def numTimeSteps(self):
+    """
+    Get number of total time steps (or best guess if adaptive).
+    """
+    from pyre.units.time import second
+    t = 0.0*second
+    nsteps = 0
+    index = 0
+    while t <= self.totalTime:
+      t += self.steps[index]
+      index += 1
+      if index >= len(self.steps):
+        index = 0
+      nsteps += 1
+    return nsteps
+
+
+  def timeStep(self, dtStable):
+    """
+    Adjust stable time step for advancing forward in time.
+    """
+    self.dt = self.steps[self.index]
+    self.index += 1
+    if self.index >= len(self.steps):
+      self.index = 0
+    return self.dt
+
+  
+  # PRIVATE METHODS ////////////////////////////////////////////////////
+
+  def _configure(self):
+    """
+    Set members based using inventory.
+    """
+    TimeStep._configure(self)
+    self.totalTime = self.inventory.totalTime
+    self.filename = self.inventory.filename
+    return
+
+
+  def _readSteps(self):
+    """
+    Read time step sizes from file.
+    """
+    fin = open(self.filename, "r")
+    lines = fin.readlines()
+    fin.close()
+
+    from pyre.units.unitparser import parser
+    unitparser = parser()
+
+    self.steps = []
+    for line in lines:
+      fields = line.split()
+      if line[0] != "#" and len(fields) > 0:
+        if line[0:5] != "units":
+          try:
+            value = float(fields[0])
+          except ValueError:
+            raise IOError("Unable to time step specification '%s'.\n"
+                          "Expected floating point value." % line.rstrip())
+          self.steps.append(value*units)
+        else:
+          if len(fields) != 3:
+            raise IOError("Unable to parse units specification.\n"
+                          "Expected 'units = VALUE', got '%s'." % line.rstrip())
+          try:
+            units = unitparser.parse(fields[2])
+          except NameError:
+            raise IOError("Unable to parse units specification.\n"
+                          "Expected 'units = VALUE', got '%s'." % line.rstrip())            
+    if len(self.steps) == 0:
+      raise IOError("No time step size values found in time step file '%s'." % \
+                      self.filename)
+    return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def time_step():
+  """
+  Factory associated with TimeStepUser.
+  """
+  return TimeStepUser()
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am	2008-07-06 22:06:55 UTC (rev 12377)
@@ -13,6 +13,8 @@
 subpackage = problems
 include $(top_srcdir)/subpackage.am
 
+SUBDIRS = data
+
 TESTS = testproblems.py
 dist_check_SCRIPTS = testproblems.py
 

Added: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/problems/TestTimeStep.py
+
+## @brief Unit testing of TimeStep object.
+
+import unittest
+
+from pyre.units.time import second
+
+from pylith.problems.TimeStep import TimeStep
+
+# ----------------------------------------------------------------------
+class TestTimeStep(unittest.TestCase):
+  """
+  Unit testing of TimeStep object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    tstep = TimeStep()
+    tstep._configure()
+    return
+    
+  
+  def test_preinitialize(self):
+    """
+    Test preinitialize().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+    tstep.preinitialize()
+    return
+
+
+  def test_verifyConfiguration(self):
+    """
+    Test verifyConfiguration().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+    tstep.preinitialize()
+    tstep.verifyConfiguration()
+    return
+
+
+  def test_initialize(self):
+    """
+    Test initialize().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+    tstep.preinitialize()
+    tstep.initialize()
+    return
+
+
+
+  def test_numTimeSteps(self):
+    """
+    Test numTimeSteps().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+    try:
+      tstep.numTimeSteps()
+    except NotImplementedError:
+      # do nothing
+      x = None
+    return
+    
+
+  def test_timeStep(self):
+    """
+    Test timeStep().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+
+    self.assertEqual(0.5*second, tstep.timeStep(0.5*second))
+    return
+
+
+  def test_currentStep(self):
+    """
+    Test currentStep().
+    """
+    tstep = TimeStep()
+    tstep._configure()
+
+    self.assertEqual(0.0*second, tstep.currentStep())
+
+    tstep.dt = 1.0e-4*second
+    self.assertEqual(1.0e-4*second, tstep.currentStep())
+
+    return
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,105 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/problems/TestTimeStepAdapt.py
+
+## @brief Unit testing of TimeStepAdapt object.
+
+import unittest
+from pylith.problems.TimeStepAdapt import TimeStepAdapt
+
+from pyre.units.time import second
+
+# ----------------------------------------------------------------------
+class TestTimeStepAdapt(unittest.TestCase):
+  """
+  Unit testing of TimeStepAdapt object.
+  """
+
+  def test_numTimeSteps(self):
+    """
+    Test numTimeSteps().
+    """
+    tstep = TimeStepAdapt()
+    tstep._configure()
+
+    self.assertEqual(1, tstep.numTimeSteps())
+
+    tstep.totalTime = 4.0*second
+    tstep.maxDt = 2.0*second
+    self.assertEqual(3, tstep.numTimeSteps())
+
+    return
+
+
+  def test_timeStep(self):
+    """
+    Test timeStep().
+    """
+    tstep = TimeStepAdapt()
+    tstep._configure()
+    
+    tstep.adaptSkip = 2
+
+    # Set time step
+    dt = 0.5*second
+    self.assertEqual(dt, tstep.timeStep(dt))
+
+    # Time step should not change
+    self.assertEqual(dt, tstep.timeStep(2.0*second))
+
+    # Reduce time step even if should have skipped
+    dt = 0.2*second
+    self.assertEqual(dt, tstep.timeStep(dt))
+
+    # Skip adjusting time step
+    self.assertEqual(dt, tstep.timeStep(0.5*second))
+
+    # Skip adjusting time step
+    self.assertEqual(dt, tstep.timeStep(0.5*second))
+
+    # Adjust time step
+    dt = 0.8*second
+    self.assertEqual(dt, tstep.timeStep(dt))
+
+    # Skip adjusting time step
+    self.assertEqual(dt, tstep.timeStep(2.0*second))
+
+    # Skip adjusting time step
+    self.assertEqual(dt, tstep.timeStep(2.0*second))
+
+    # Adjust time step with value bigger than max
+    dt = 1.0*second
+    self.assertEqual(dt, tstep.timeStep(2.0*second))
+
+    return
+
+
+  def test_currentStep(self):
+    """
+    Test currentStep().
+    """
+    tstep = TimeStepAdapt()
+    tstep._configure()
+    tstep.maxDt = 10.0*second
+    tstep.dt = tstep.maxDt
+    
+    self.assertEqual(10.0*second, tstep.currentStep())
+
+    dt = 4.0*second
+    tstep.timeStep(dt)
+    self.assertEqual(dt, tstep.currentStep())
+
+    return
+
+
+# End of file 

Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -15,6 +15,7 @@
 ## @brief Unit testing of TimeStepUniform object.
 
 import unittest
+from pylith.problems.TimeStepUniform import TimeStepUniform
 
 from pyre.units.time import second
 
@@ -28,10 +29,9 @@
     """
     Test numTimeSteps().
     """
-    from pylith.problems.TimeStepUniform import TimeStepUniform
     tstep = TimeStepUniform()
-
     tstep._configure()
+
     self.assertEqual(1, tstep.numTimeSteps())
 
     tstep.totalTime = 4.0*second
@@ -45,10 +45,9 @@
     """
     Test timeStep().
     """
-    from pylith.problems.TimeStepUniform import TimeStepUniform
     tstep = TimeStepUniform()
-
     tstep._configure()
+
     self.assertEqual(1.0*second, tstep.timeStep(0.5*second))
 
     tstep.dt = 1.0e-4*second
@@ -61,10 +60,9 @@
     """
     Test currentStep().
     """
-    from pylith.problems.TimeStepUniform import TimeStepUniform
     tstep = TimeStepUniform()
-
     tstep._configure()
+
     self.assertEqual(1.0*second, tstep.currentStep())
 
     tstep.dt = 1.0e-4*second

Added: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/problems/TestTimeStepUser.py
+
+## @brief Unit testing of TimeStepUser object.
+
+import unittest
+from pylith.problems.TimeStepUser import TimeStepUser
+
+from pyre.units.time import second,year
+
+stepsE = [1.0*year, 2.0*year, 3.0*year]
+
+# ----------------------------------------------------------------------
+class TestTimeStepUser(unittest.TestCase):
+  """
+  Unit testing of TimeStepUser object.
+  """
+
+  def test_constructor(self):
+    """
+    Test constructor.
+    """
+    tstep = TimeStepUser()
+    tstep._configure()
+    return
+
+
+  def test_initialize(self):
+    """
+    Test initialize().
+    """
+    tstep = TimeStepUser()
+    tstep._configure()
+
+    tstep.filename = "data/timesteps.txt"
+    tstep.preinitialize()
+    tstep.initialize()
+
+    for stepE, step in zip(stepsE, tstep.steps):
+      self.assertEqual(stepE, step)
+    return
+
+
+  def test_numTimeSteps(self):
+    """
+    Test numTimeSteps().
+    """
+    tstep = TimeStepUser()
+    tstep._configure()
+
+    tstep.filename = "data/timesteps.txt"
+    tstep.preinitialize()
+    tstep.initialize()
+
+    self.assertEqual(1, tstep.numTimeSteps())
+
+    tstep.totalTime = 7.0*year
+    self.assertEqual(5, tstep.numTimeSteps())
+    return
+
+
+  def test_timeStep(self):
+    """
+    Test timeStep().
+    """
+    tstep = TimeStepUser()
+    tstep._configure()
+
+    tstep.filename = "data/timesteps.txt"
+    tstep.preinitialize()
+    tstep.initialize()
+
+    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
+
+
+  def test_currentStep(self):
+    """
+    Test currentStep().
+    """
+    tstep = TimeStepUser()
+    tstep._configure()
+
+    tstep.filename = "data/timesteps.txt"
+    tstep.preinitialize()
+    tstep.initialize()
+
+    tstep.timeStep(0.0*second)
+    self.assertEqual(1.0*year, tstep.currentStep())
+    return
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/problems/data/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/data/Makefile.am	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/data/Makefile.am	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,30 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+#                           Brad T. Aagaard
+#                        U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+dist_noinst_DATA = \
+	timesteps.txt
+
+noinst_TMP =
+
+# 'export' the input files by performing a mock install
+export_datadir = $(top_builddir)/unittests/pytests/problems/data
+export-data: $(dist_noinst_DATA)
+	if [ "X$(top_srcdir)" != "X$(top_builddir)" ]; then for f in $(dist_noinst_DATA); do $(install_sh_DATA) $(srcdir)/$$f $(export_datadir); done; fi
+
+clean-data:
+	if [ "X$(top_srcdir)" != "X$(top_builddir)" ]; then for f in $(dist_noinst_DATA) $(noinst_TMP); do $(RM) $(RM_FLAGS) $(export_datadir)/$$f; done; fi
+
+BUILT_SOURCES = export-data
+clean-local: clean-data
+
+
+# End of file 

Added: short/3D/PyLith/trunk/unittests/pytests/problems/data/timesteps.txt
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/data/timesteps.txt	                        (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/data/timesteps.txt	2008-07-06 22:06:55 UTC (rev 12377)
@@ -0,0 +1,11 @@
+# File with time step sizes.
+
+# Units of values
+units = year
+
+# Values
+1.0 # Comment
+2.0
+3.0
+
+# Another comment

Modified: short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py	2008-07-05 00:56:02 UTC (rev 12376)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py	2008-07-06 22:06:55 UTC (rev 12377)
@@ -37,9 +37,13 @@
     """
     Run the application.
     """
+    from pylith.utils.PetscManager import PetscManager
+    petsc = PetscManager()
+    petsc.initialize()
 
     unittest.TextTestRunner(verbosity=2).run(self._suite())
 
+    petsc.finalize()
     return
 
 
@@ -52,9 +56,18 @@
 
     suite = unittest.TestSuite()
 
+    from TestTimeStep import TestTimeStep
+    suite.addTest(unittest.makeSuite(TestTimeStep))
+
     from TestTimeStepUniform import TestTimeStepUniform
     suite.addTest(unittest.makeSuite(TestTimeStepUniform))
 
+    from TestTimeStepUser import TestTimeStepUser
+    suite.addTest(unittest.makeSuite(TestTimeStepUser))
+
+    from TestTimeStepAdapt import TestTimeStepAdapt
+    suite.addTest(unittest.makeSuite(TestTimeStepAdapt))
+
     return suite
 
 



More information about the cig-commits mailing list