[cig-commits] r13462 - in short/3D/PyLith/trunk: pylith/problems unittests/pytests/problems
brad at geodynamics.org
brad at geodynamics.org
Thu Dec 4 13:27:35 PST 2008
Author: brad
Date: 2008-12-04 13:27:35 -0800 (Thu, 04 Dec 2008)
New Revision: 13462
Modified:
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
Log:
Updated time step unit tests for nondimensionalization.
Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py 2008-12-04 20:55:37 UTC (rev 13461)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py 2008-12-04 21:27:35 UTC (rev 13462)
@@ -107,7 +107,7 @@
logEvent = "%sinit" % self._loggingPrefix
self._logger.eventBegin(logEvent)
- TimeStep.initialize(self)
+ TimeStep.initialize(self, normalizer)
self._readSteps()
assert(len(self.steps) > 0)
@@ -116,7 +116,7 @@
# Nondimensionalize time steps
timeScale = normalizer.timeScale()
for i in xrange(len(self.steps)):
- self.steps[i] = normalizer.nondimensional(self.step, timeScale)
+ self.steps[i] = normalizer.nondimensionalize(self.steps[i], timeScale)
# Set current time step
self.dt = self.steps[self.index]
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py 2008-12-04 20:55:37 UTC (rev 13461)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStep.py 2008-12-04 21:27:35 UTC (rev 13462)
@@ -26,6 +26,21 @@
Unit testing of TimeStep object.
"""
+ def setUp(self):
+ from spatialdata.units.Nondimensional import Nondimensional
+ normalizer = Nondimensional()
+ normalizer._configure()
+ normalizer._time = 2.0*second
+ normalizer.initialize()
+
+ tstep = TimeStep()
+ tstep._configure()
+ tstep.preinitialize()
+ tstep.initialize(normalizer)
+ self.tstep = tstep
+ return
+
+
def test_constructor(self):
"""
Test constructor.
@@ -60,10 +75,7 @@
"""
Test initialize().
"""
- tstep = TimeStep()
- tstep._configure()
- tstep.preinitialize()
- tstep.initialize()
+ tstep = self.tstep
return
@@ -72,8 +84,7 @@
"""
Test numTimeSteps().
"""
- tstep = TimeStep()
- tstep._configure()
+ tstep = self.tstep
try:
tstep.numTimeSteps()
except NotImplementedError:
@@ -86,11 +97,11 @@
"""
Test timeStep().
"""
- tstep = TimeStep()
+ tstep = self.tstep
tstep._configure()
integrators = None
- self.assertEqual(0.0*second, tstep.timeStep(integrators))
+ self.assertEqual(0.0, tstep.timeStep(integrators))
return
@@ -98,13 +109,12 @@
"""
Test currentStep().
"""
- tstep = TimeStep()
- tstep._configure()
+ tstep = self.tstep
- self.assertEqual(0.0*second, tstep.currentStep())
+ self.assertEqual(0.0, tstep.currentStep())
- tstep.dt = 1.0e-4*second
- self.assertEqual(1.0e-4*second, tstep.currentStep())
+ tstep.dt = 1.0e-4
+ self.assertEqual(1.0e-4, tstep.currentStep())
return
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py 2008-12-04 20:55:37 UTC (rev 13461)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py 2008-12-04 21:27:35 UTC (rev 13462)
@@ -36,17 +36,42 @@
Unit testing of TimeStepAdapt object.
"""
+ def setUp(self):
+ from spatialdata.units.Nondimensional import Nondimensional
+ normalizer = Nondimensional()
+ normalizer._configure()
+ normalizer._time = 2.0*second
+ normalizer.initialize()
+
+ tstep = TimeStepAdapt()
+ tstep._configure()
+ tstep.preinitialize()
+ tstep.initialize(normalizer)
+ self.tstep = tstep
+ return
+
+
+ def test_initialize(self):
+ """
+ Test initialize().
+ """
+ tstep = self.tstep
+
+ self.assertEqual(0.0, tstep.totalTime)
+ self.assertEqual(0.5, tstep.maxDt)
+ return
+
+
def test_numTimeSteps(self):
"""
Test numTimeSteps().
"""
- tstep = TimeStepAdapt()
- tstep._configure()
+ tstep = self.tstep
self.assertEqual(1, tstep.numTimeSteps())
- tstep.totalTime = 4.0*second
- tstep.maxDt = 2.0*second
+ tstep.totalTime = 4.0
+ tstep.maxDt = 2.0
self.assertEqual(3, tstep.numTimeSteps())
return
@@ -56,28 +81,27 @@
"""
Test timeStep().
"""
- tstep = TimeStepAdapt()
- tstep._configure()
+ tstep = self.tstep
tstep.adaptSkip = 2
- integrators = [Integrator(2.0*second),
- Integrator(0.5*second)]
+ integrators = [Integrator(2.0),
+ Integrator(0.5)]
# Set time step
- dt = 0.5*second / 1.2
+ dt = 0.5 / 1.2
self.assertEqual(dt, tstep.timeStep(integrators))
# Increase stable time step, but time step should not change (skipped)
- integrators[1].dt = 0.8*second
+ integrators[1].dt = 0.8
self.assertEqual(dt, tstep.timeStep(integrators))
# Reduce time step even if though should have skipped
- integrators[1].dt = 0.2*second
- dt = 0.2*second / 1.2
+ integrators[1].dt = 0.2
+ dt = 0.2 / 1.2
self.assertEqual(dt, tstep.timeStep(integrators))
# Skip adjusting time step
- integrators[1].dt = 0.8*second
+ integrators[1].dt = 0.8
self.assertEqual(dt, tstep.timeStep(integrators))
# Skip adjusting time step
@@ -85,18 +109,18 @@
# Adjust time step and stability factor
tstep.stabilityFactor = 2.0
- dt = 0.8*second / 2.0
+ dt = 0.8 / 2.0
self.assertEqual(dt, tstep.timeStep(integrators))
# Skip adjusting time step
- integrators[1].dt = 2.0*second
+ integrators[1].dt = 2.0
self.assertEqual(dt, tstep.timeStep(integrators))
# Skip adjusting time step
self.assertEqual(dt, tstep.timeStep(integrators))
# Adjust time step with value bigger than max
- dt = 1.0*second
+ dt = 0.5
self.assertEqual(dt, tstep.timeStep(integrators))
return
@@ -106,17 +130,16 @@
"""
Test currentStep().
"""
- tstep = TimeStepAdapt()
- tstep._configure()
- tstep.maxDt = 10.0*second
+ tstep = self.tstep
+ tstep.maxDt = 10.0
tstep.dt = tstep.maxDt
- self.assertEqual(10.0*second, tstep.currentStep())
+ self.assertEqual(10.0, tstep.currentStep())
- integrators = [Integrator(3.0*second),
- Integrator(2.4*second)]
- dt = 2.4*second / 1.2
+ integrators = [Integrator(3.0),
+ Integrator(2.4)]
+ dt = 2.4 / 1.2
tstep.timeStep(integrators)
self.assertEqual(dt, tstep.currentStep())
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py 2008-12-04 20:55:37 UTC (rev 13461)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py 2008-12-04 21:27:35 UTC (rev 13462)
@@ -27,6 +27,22 @@
Unit testing of TimeStepUser object.
"""
+ def setUp(self):
+ from spatialdata.units.Nondimensional import Nondimensional
+ normalizer = Nondimensional()
+ normalizer._configure()
+ normalizer._time = 2.0*second
+ normalizer.initialize()
+
+ tstep = TimeStepUser()
+ tstep._configure()
+ tstep.filename = "data/timesteps.txt"
+ tstep.preinitialize()
+ tstep.initialize(normalizer)
+ self.tstep = tstep
+ return
+
+
def test_constructor(self):
"""
Test constructor.
@@ -40,15 +56,11 @@
"""
Test initialize().
"""
- tstep = TimeStepUser()
- tstep._configure()
+ tstep = self.tstep
- tstep.filename = "data/timesteps.txt"
- tstep.preinitialize()
- tstep.initialize()
-
for stepE, step in zip(stepsE, tstep.steps):
- self.assertEqual(stepE, step)
+ valueE = stepE.value / 2.0 # Nondimensionalize
+ self.assertEqual(valueE, step)
return
@@ -56,20 +68,15 @@
"""
Test numTimeSteps().
"""
- tstep = TimeStepUser()
- tstep._configure()
+ tstep = self.tstep
- tstep.filename = "data/timesteps.txt"
- tstep.preinitialize()
- tstep.initialize()
-
self.assertEqual(1, tstep.numTimeSteps())
- tstep.totalTime = 12.0*year
+ tstep.totalTime = (12.0*year).value / 2.0 # nondimensionalize
self.assertEqual(6, tstep.numTimeSteps())
tstep.loopSteps = True
- tstep.totalTime = 7.0*year
+ tstep.totalTime = (7.0*year).value / 2.0 # nondimensionalize
self.assertEqual(5, tstep.numTimeSteps())
return
@@ -78,26 +85,25 @@
"""
Test timeStep().
"""
- tstep = TimeStepUser()
- tstep._configure()
+ tstep = self.tstep
- tstep.filename = "data/timesteps.txt"
- tstep.preinitialize()
- tstep.initialize()
+ step1 = (1.0*year).value / 2.0 # nondimensionalize
+ step2 = (2.0*year).value / 2.0 # nondimensionalize
+ step3 = (3.0*year).value / 2.0 # nondimensionalize
- 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))
+ self.assertEqual(step1, tstep.timeStep(0.5))
+ self.assertEqual(step2, tstep.timeStep(0.5))
+ self.assertEqual(step3, tstep.timeStep(0.5))
+ self.assertEqual(step3, tstep.timeStep(0.5))
+ self.assertEqual(step3, tstep.timeStep(0.5))
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))
+ self.assertEqual(step1, tstep.timeStep(0.5))
+ self.assertEqual(step2, tstep.timeStep(0.5))
+ self.assertEqual(step3, tstep.timeStep(0.5))
+ self.assertEqual(step1, tstep.timeStep(0.5))
+ self.assertEqual(step2, tstep.timeStep(0.5))
return
@@ -105,15 +111,12 @@
"""
Test currentStep().
"""
- tstep = TimeStepUser()
- tstep._configure()
+ tstep = self.tstep
- tstep.filename = "data/timesteps.txt"
- tstep.preinitialize()
- tstep.initialize()
-
- tstep.timeStep(0.0*second)
- self.assertEqual(1.0*year, tstep.currentStep())
+ tstep.timeStep(0.0)
+ stepE = 1.0*year
+ valueE = stepE.value / 2.0 # nondimensionalize
+ self.assertEqual(valueE, tstep.currentStep())
return
More information about the CIG-COMMITS
mailing list