[cig-commits] r15423 - in short/3D/PyLith/trunk: pylith/feassemble pylith/problems unittests/pytests/problems
brad at geodynamics.org
brad at geodynamics.org
Fri Jul 3 10:16:48 PDT 2009
Author: brad
Date: 2009-07-03 10:16:47 -0700 (Fri, 03 Jul 2009)
New Revision: 15423
Modified:
short/3D/PyLith/trunk/pylith/feassemble/IntegratorElasticity.py
short/3D/PyLith/trunk/pylith/problems/TimeStep.py
short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py
short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py
short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py
short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
Log:
Added check to make sure user specified time step is less than stable time step.
Modified: short/3D/PyLith/trunk/pylith/feassemble/IntegratorElasticity.py
===================================================================
--- short/3D/PyLith/trunk/pylith/feassemble/IntegratorElasticity.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/pylith/feassemble/IntegratorElasticity.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -115,6 +115,7 @@
Integrator.finalize(self)
self.materialObj.finalize()
self.output.finalize()
+ self._modelMemoryUse()
return
@@ -136,6 +137,8 @@
return field
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
def _initializeOutput(self, totalTime, numTimeSteps, normalizer):
"""
Initialize output.
@@ -146,4 +149,12 @@
return
+ def _modelMemoryUse(self):
+ """
+ Model memory allocation.
+ """
+ self.materialObj.perfLogger.logFields("Output", self.outputFields())
+ return
+
+
# End of file
Modified: short/3D/PyLith/trunk/pylith/problems/TimeStep.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStep.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStep.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -35,6 +35,7 @@
"""
PetscComponent.__init__(self, name, facility="time_step")
from pyre.units.time import second
+ self.timeScale = 1.0*second
self.totalTime = 0.0*second
self.dt = 0.0*second
self.totalTimeN = 0.0 # Nondimensionalized total time
@@ -76,6 +77,7 @@
timeScale = normalizer.timeScale()
self.totalTimeN = normalizer.nondimensionalize(self.totalTime, timeScale)
self.dtN = normalizer.nondimensionalize(self.dt, timeScale)
+ self.timeScale = timeScale
self._eventLogger.eventEnd(logEvent)
return
@@ -136,6 +138,20 @@
return
+ def _stableTimeStep(self, mesh, integrators):
+ """
+ Get stable time step.
+ """
+ dtStable = 1.0e+30
+ for integrator in integrators:
+ dt = integrator.stableTimeStep(mesh)
+ if dt < dtStable:
+ dtStable = dt
+
+ return dtStable
+
+
+
# FACTORIES ////////////////////////////////////////////////////////////
def time_step():
Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepAdapt.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -113,11 +113,7 @@
"""
Adjust stable time step for advancing forward in time.
"""
- dtStable = 1.0e+30
- for integrator in integrators:
- dt = integrator.stableTimeStep(mesh)
- if dt < dtStable:
- dtStable = dt
+ dtStable = self._stableTimeStep(mesh, integrators)
if self.skipped < self.adaptSkip and \
self.dtN != 0.0 and \
Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -79,6 +79,12 @@
"""
Adjust stable time step for advancing forward in time.
"""
+ dtStable = self._stableTimeStep(mesh, integrators)
+ if dtStable < self.dtN:
+ raise RuntimeError("Current nondimensionalized time step of %12.4e "
+ "exceeds the nondimensionalized stable time "
+ "step of %12.4e." % (self.dtN, dtStable))
+
return self.dtN
Modified: short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUser.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -158,6 +158,13 @@
self.index += 1
elif self.loopSteps:
self.index = 0
+
+ dtStable = self._stableTimeStep(mesh, integrators)
+ if dtStable < self.dtN:
+ raise RuntimeError("Current time step of %s exceeds the stable time "
+ "step of %s." % (self.dtN*self.timeScale,
+ dtStable*self.timeScale))
+
return self.dtN
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepAdapt.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -19,6 +19,7 @@
from pyre.units.time import second
+# ----------------------------------------------------------------------
class Integrator:
def __init__(self, dt):
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -21,6 +21,18 @@
from pyre.units.time import second
# ----------------------------------------------------------------------
+class Integrator:
+
+ def __init__(self, dt):
+ self.dt = dt
+ return
+
+
+ def stableTimeStep(self, mesh):
+ return self.dt
+
+
+# ----------------------------------------------------------------------
class TestTimeStepUniform(unittest.TestCase):
"""
Unit testing of TimeStepUniform object.
@@ -63,14 +75,23 @@
"""
tstep = self.tstep
- integrators = None
+ integrators = [Integrator(4.0),
+ Integrator(8.0)]
mesh = None
self.assertEqual(1.0, tstep.timeStep(mesh, integrators))
- tstep.dtN = 1.0e-4
- self.assertEqual(1.0e-4, tstep.timeStep(mesh, integrators))
+ tstep.dtN = 0.5
+ self.assertEqual(0.5, tstep.timeStep(mesh, integrators))
+ caught = False
+ try:
+ tstep.dtN = 10.0
+ tstep.timeStep(mesh, integrators)
+ except RuntimeError:
+ caught = True
+ self.failUnless(caught)
+
return
Modified: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py 2009-07-03 01:29:30 UTC (rev 15422)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUser.py 2009-07-03 17:16:47 UTC (rev 15423)
@@ -22,6 +22,17 @@
stepsE = [2*1.0, 2*2.0, 2*3.0]
# ----------------------------------------------------------------------
+class Integrator:
+
+ def __init__(self, dt):
+ self.dt = dt
+
+
+ def stableTimeStep(self, mesh):
+ return self.dt
+
+
+# ----------------------------------------------------------------------
class TestTimeStepUser(unittest.TestCase):
"""
Unit testing of TimeStepUser object.
@@ -89,7 +100,8 @@
step2 = 2.0 / 0.5 # nondimensionalize
step3 = 3.0 / 0.5 # nondimensionalize
- integrators = None
+ integrators = [Integrator(40.0),
+ Integrator(80.0)]
mesh = None
self.assertEqual(step1, tstep.timeStep(mesh, integrators))
@@ -105,6 +117,16 @@
self.assertEqual(step3, tstep.timeStep(mesh, integrators))
self.assertEqual(step1, tstep.timeStep(mesh, integrators))
self.assertEqual(step2, tstep.timeStep(mesh, integrators))
+
+ integrators = [Integrator(0.01),
+ Integrator(8.0)]
+ caught = False
+ try:
+ tstep.timeStep(mesh, integrators)
+ except RuntimeError:
+ caught = True
+ self.failUnless(caught)
+
return
@@ -114,7 +136,8 @@
"""
tstep = self.tstep
- integrators = None
+ integrators = [Integrator(4.0),
+ Integrator(8.0)]
mesh = None
tstep.timeStep(mesh, integrators)
More information about the CIG-COMMITS
mailing list