[cig-commits] r12376 - in short/3D/PyLith/trunk: . examples/3d/hex8 examples/3d/tet4 examples/bar_shearwave/hex8 examples/bar_shearwave/quad4 examples/bar_shearwave/tet4 examples/bar_shearwave/tri3 examples/twocells/twohex8 examples/twocells/twoquad4 examples/twocells/twotet4 examples/twocells/twotet4-geoproj examples/twocells/twotri3 pylith pylith/problems unittests/pytests unittests/pytests/problems
brad at geodynamics.org
brad at geodynamics.org
Fri Jul 4 17:56:02 PDT 2008
Author: brad
Date: 2008-07-04 17:56:02 -0700 (Fri, 04 Jul 2008)
New Revision: 12376
Added:
short/3D/PyLith/trunk/pylith/problems/TimeStep.py
short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
short/3D/PyLith/trunk/unittests/pytests/problems/
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
Modified:
short/3D/PyLith/trunk/configure.ac
short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg
short/3D/PyLith/trunk/examples/3d/hex8/savageprescott.cfg
short/3D/PyLith/trunk/examples/3d/tet4/pylithapp.cfg
short/3D/PyLith/trunk/examples/bar_shearwave/hex8/shearwave.cfg
short/3D/PyLith/trunk/examples/bar_shearwave/quad4/shearwave.cfg
short/3D/PyLith/trunk/examples/bar_shearwave/tet4/shearwave.cfg
short/3D/PyLith/trunk/examples/bar_shearwave/tri3/shearwave.cfg
short/3D/PyLith/trunk/examples/twocells/twohex8/pylithapp.cfg
short/3D/PyLith/trunk/examples/twocells/twoquad4/pylithapp.cfg
short/3D/PyLith/trunk/examples/twocells/twotet4-geoproj/pylithapp.cfg
short/3D/PyLith/trunk/examples/twocells/twotet4/pylithapp.cfg
short/3D/PyLith/trunk/examples/twocells/twotri3/pylithapp.cfg
short/3D/PyLith/trunk/pylith/Makefile.am
short/3D/PyLith/trunk/pylith/problems/Explicit.py
short/3D/PyLith/trunk/pylith/problems/Formulation.py
short/3D/PyLith/trunk/pylith/problems/Implicit.py
short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
short/3D/PyLith/trunk/pylith/problems/__init__.py
short/3D/PyLith/trunk/unittests/pytests/Makefile.am
Log:
Added TimeStep to manage time step size. Created TimeStepUniform for uniform time stepping (previous functionality).
Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/configure.ac 2008-07-05 00:56:02 UTC (rev 12376)
@@ -252,6 +252,7 @@
unittests/pytests/materials/data/Makefile
unittests/pytests/meshio/Makefile
unittests/pytests/meshio/data/Makefile
+ unittests/pytests/problems/Makefile
unittests/pytests/topology/Makefile
unittests/pytests/topology/data/Makefile
unittests/pytests/utils/Makefile
Modified: short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/3d/hex8/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -34,14 +34,16 @@
# ----------------------------------------------------------------------
# problem
# ----------------------------------------------------------------------
-[pylithapp.timedependent]
+[pylithapp.timedependent.formulation.time_step]
# Define the total time for the simulation and the default time step size.
total_time = 0.0*s ; total time of simulation
-default_dt = 1.0*s ; time step
+dt = 1.0*s ; time step
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
+[pylithapp.timedependent]
+
# Set materials to an array of 2 materials:
# 'elastic' and 'viscoelastic'
materials = [elastic,viscoelastic]
Modified: short/3D/PyLith/trunk/examples/3d/hex8/savageprescott.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/3d/hex8/savageprescott.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/3d/hex8/savageprescott.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -13,10 +13,7 @@
# problem
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-# Define the total time for the simulation and the default time step size.
-# Overwrite values in pylithapp.cfg
-total_time = 700.0*year ; total time of simulation
-default_dt = 10.0*year ; time step
+formulation.solver.initial_guess_zero = False
# Set bc to an array of 3 boundary conditions: 'x_pos','x_neg', and 'z_neg'.
bc = [x_pos,x_neg,z_neg]
@@ -24,6 +21,12 @@
# Set interfaces to an array of 1 fault: 'fault'.
interfaces = [fault]
+[pylithapp.timedependent.implicit.time_step]
+# Define the total time for the simulation and the default time step size.
+# Overwrite values in pylithapp.cfg
+total_time = 700.0*year ; total time of simulation
+dt = 10.0*year ; time step
+
[pylithapp.timedependent.implicit]
# Set the output to an array of 2 output managers.
# We will output the solution over the domain and the ground surface.
Modified: short/3D/PyLith/trunk/examples/3d/tet4/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/3d/tet4/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/3d/tet4/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -41,6 +41,14 @@
#record_header_32bit = False
# ----------------------------------------------------------------------
+# problem
+# ----------------------------------------------------------------------
+[pylithapp.timedependent.formulation.time_step]
+# Define the total time for the simulation and the default time step size.
+total_time = 0.0*s ; total time of simulation
+dt = 1.0*s ; time step
+
+# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
[pylithapp.timedependent]
Modified: short/3D/PyLith/trunk/examples/bar_shearwave/hex8/shearwave.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/bar_shearwave/hex8/shearwave.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/bar_shearwave/hex8/shearwave.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -40,8 +40,6 @@
# problem
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-total_time = 12.0*s
-default_dt = 0.05*s
dimension = 3
# Change to an explicit time stepping formulation
@@ -63,6 +61,10 @@
# Set materials to an array with 1 material 'elastic'.
materials = [elastic]
+[pylithapp.timedependent.formulation.time_step]
+total_time = 12.0*s
+dt = 0.05*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/bar_shearwave/quad4/shearwave.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/bar_shearwave/quad4/shearwave.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/bar_shearwave/quad4/shearwave.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -41,8 +41,6 @@
# problem
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-total_time = 12.0*s
-default_dt = 0.05*s
dimension = 2
# Change to an explicit time stepping formulation
@@ -64,6 +62,10 @@
# Set materials to an array with 1 material 'elastic'.
materials = [elastic]
+[pylithapp.timedependent.formulation.time_step]
+total_time = 12.0*s
+dt = 0.05*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/bar_shearwave/tet4/shearwave.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/bar_shearwave/tet4/shearwave.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/bar_shearwave/tet4/shearwave.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -42,8 +42,6 @@
# problem
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-total_time = 12.0*s
-default_dt = 0.0333333333333333333*s
dimension = 3
# Change to an explicit time stepping formulation
@@ -65,6 +63,10 @@
# Set materials to an array with 2 materials 'pos' and 'neg'.
materials = [pos,neg]
+[pylithapp.timedependent.formulation.time_step]
+total_time = 12.0*s
+dt = 0.0333333333333333333*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/bar_shearwave/tri3/shearwave.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/bar_shearwave/tri3/shearwave.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/bar_shearwave/tri3/shearwave.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -41,8 +41,6 @@
# problem
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-total_time = 12.0*s
-default_dt = 0.0333333333333333*s
dimension = 2
# Change to an explicit time stepping formulation
@@ -64,6 +62,10 @@
# Set materials to an array with 1 material 'elastic'.
materials = [elastic]
+[pylithapp.timedependent.formulation.time_step]
+total_time = 12.0*s
+dt = 0.0333333333333333*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/twocells/twohex8/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/twohex8/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/twocells/twohex8/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -53,10 +53,12 @@
# The spatial dimension for this problem is 3.
# ----------------------------------------------------------------------
[pylithapp.timedependent]
-total_time = 1.0*year
-default_dt = 0.1*year
dimension = 3
+[pylithapp.timedependent.formulation.time_step]
+total_time = 1.0*year
+dt = 0.1*year
+
# ----------------------------------------------------------------------
# materials
# Specify the material information for the problem.
Modified: short/3D/PyLith/trunk/examples/twocells/twoquad4/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/twoquad4/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/twocells/twoquad4/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -47,16 +47,18 @@
# ----------------------------------------------------------------------
# Specify the problem settings.
# This is a time-dependent problem, so we select this as our problem type.
-# We select a total time of 1 sec, and a time step size of 1 sec, so we
+# We select a total time of 0 sec, and a time step size of 1 sec, so we
# are performing a single time step.
# The spatial dimension for this problem is 2.
# For an implicit formulation (using implicit.cfg), we will perform 1
# implicit time step from t = -1.0 to t = 0.0 (elastic solution step).
[pylithapp.timedependent]
-total_time = 0.0*s
-default_dt = 1.0*s
dimension = 2
+[pylithapp.timedependent.formulation.time_step]
+total_time = 0.0*s
+dt = 1.0*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/twocells/twotet4/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/twotet4/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/twocells/twotet4/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -49,16 +49,18 @@
# ----------------------------------------------------------------------
# Specify the problem settings.
# This is a time-dependent problem, so we select this as our problem type.
-# We select a total time of 1 sec, and a time step size of 1 sec, so we
+# We select a total time of 0 sec, and a time step size of 1 sec, so we
# are performing a single time step.
# The spatial dimension for this problem is 2.
# For an implicit formulation (using implicit.cfg), we will perform 1
# implicit time step from t = -1.0 to t = 0.0 (elastic solution step).
[pylithapp.timedependent]
-total_time = 0.0*s
-default_dt = 1.0*s
dimension = 3
+[pylithapp.timedependent.formulation.time_step]
+total_time = 0.0*s
+dt = 1.0*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/twocells/twotet4-geoproj/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/twotet4-geoproj/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/twocells/twotet4-geoproj/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -60,10 +60,12 @@
# For an implicit formulation (using implicit.cfg), we will perform 1
# implicit time step from t = -1.0 to t = 0.0 (elastic solution step).
[pylithapp.timedependent]
-total_time = 0.0*s
-default_dt = 1.0*s
dimension = 3
+[pylithapp.timedependent.formulation.time_step]
+total_time = 0.0*s
+dt = 1.0*s
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/examples/twocells/twotri3/pylithapp.cfg
===================================================================
--- short/3D/PyLith/trunk/examples/twocells/twotri3/pylithapp.cfg 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/examples/twocells/twotri3/pylithapp.cfg 2008-07-05 00:56:02 UTC (rev 12376)
@@ -53,10 +53,13 @@
# For an implicit formulation (using implicit.cfg), we will perform 1
# implicit time step from t = -1.0 to t = 0.0 (elastic solution step).
[pylithapp.timedependent]
-total_time = 0.0*s
-default_dt = 1.0*s
dimension = 2
+[pylithapp.timedependent.formulation.time_step]
+total_time = 0.0*s
+dt = 1.0*s
+
+
# ----------------------------------------------------------------------
# materials
# ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/Makefile.am 2008-07-05 00:56:02 UTC (rev 12376)
@@ -98,6 +98,8 @@
problems/Implicit.py \
problems/Problem.py \
problems/TimeDependent.py \
+ problems/TimeStep.py \
+ problems/TimeStepUniform.py \
solver/__init__.py \
solver/Solver.py \
solver/SolverLinear.py \
Modified: short/3D/PyLith/trunk/pylith/problems/Explicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Explicit.py 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/problems/Explicit.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -59,16 +59,14 @@
return ElasticityExplicit()
- def initialize(self, dimension, totalTime, dt):
+ def initialize(self, dimension):
"""
Initialize problem for explicit time integration.
"""
logEvent = "%sinit" % self._loggingPrefix
self._logger.eventBegin(logEvent)
- from pyre.units.time import second
- t = 0.0*second
- Formulation.initialize(self, dimension, totalTime, dt)
+ Formulation.initialize(self, dimension)
self._info.log("Creating other fields and matrices.")
self.fields.addReal("dispTpdt")
@@ -90,14 +88,6 @@
return
- def startTime(self, dt):
- """
- Get time at which time stepping should start.
- """
- from pyre.units.time import second
- return 0.0*second
-
-
def prestep(self, t, dt):
"""
Hook for doing stuff before advancing time step.
@@ -145,7 +135,7 @@
return
- def poststep(self, t, dt, totalTime):
+ def poststep(self, t, dt):
"""
Hook for doing stuff after advancing time step.
"""
@@ -158,7 +148,7 @@
bindings.copyRealSection(self.fields.getReal("dispTpdt"),
self.fields.getReal("dispT"))
- Formulation.poststep(self, t, dt, totalTime)
+ Formulation.poststep(self, t, dt)
self._logger.eventEnd(logEvent)
return
Modified: short/3D/PyLith/trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Formulation.py 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/problems/Formulation.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -19,6 +19,7 @@
from pyre.components.Component import Component
from pylith.utils.profiling import resourceUsageString
+from pyre.units.time import second
# ITEM FACTORIES ///////////////////////////////////////////////////////
@@ -56,11 +57,17 @@
## @li None
##
## \b Facilities
+ ## @li \b time_step Time step size manager.
## @li \b solver Algebraic solver.
## @li \b output Output manager associated with solution.
import pyre.inventory
+ from TimeStepUniform import TimeStepUniform
+ timeStep = pyre.inventory.facility("time_step", family="time_step",
+ factory=TimeStepUniform)
+ timeStep.meta['tip'] = "Time step size manager."
+
from pylith.solver.SolverLinear import SolverLinear
solver = pyre.inventory.facility("solver", family="solver",
factory=SolverLinear)
@@ -83,7 +90,6 @@
self.constraints = None
self.fields = None
self.solnField = None
-
return
@@ -131,14 +137,15 @@
return
- def initialize(self, dimension, totalTime, dt):
+ def initialize(self, dimension):
"""
Create integrators for each element family.
"""
logEvent = "%sinit" % self._loggingPrefix
self._logger.eventBegin(logEvent)
- numTimeSteps = 1.0 + int(totalTime / dt)
+ numTimeSteps = self.timeStep.numTimeSteps()
+ totalTime = self.timeStep.totalTime
from pylith.topology.FieldsManager import FieldsManager
self.fields = FieldsManager(self.mesh)
@@ -182,17 +189,35 @@
return
- def stableTimeStep(self):
+ def getStartTime(self):
"""
+ Get start time for simulation.
+ """
+ return 0.0*second
+
+
+ def getTotalTime(self):
+ """
+ Get total time for simulation.
+ """
+ return self.timeStep.totalTime
+
+
+ def getTimeStep(self):
+ """
Get stable time step for advancing forward in time.
"""
logEvent = "%stimestep" % self._loggingPrefix
self._logger.eventBegin(logEvent)
- self._info.log("WARNING: Formulation::stableTimeStep() not implemented.")
- from pyre.units.time import second
- dt = 0.0*second
+ dt = 1.0e+30*second
+ for integrator in self.integrators:
+ stableDt = integrator.stableTimeStep()
+ if dt < stableDt:
+ dt = stableDt
+ dt = self.timeStep.timeStep(dt)
+
self._logger.eventEnd(logEvent)
return dt
@@ -219,13 +244,15 @@
return
- def poststep(self, t, dt, totalTime):
+ def poststep(self, t, dt):
"""
Hook for doing stuff after advancing time step.
"""
logEvent = "%spoststep" % self._loggingPrefix
self._logger.eventBegin(logEvent)
+ totalTime = self.timeStep.totalTime
+
self._info.log("Writing solution fields.")
for output in self.output.components():
output.writeData(t+dt, self.fields)
@@ -266,6 +293,7 @@
Set members based using inventory.
"""
Component._configure(self)
+ self.timeStep = self.inventory.timeStep
self.solver = self.inventory.solver
self.output = self.inventory.output
Modified: short/3D/PyLith/trunk/pylith/problems/Implicit.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Implicit.py 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/problems/Implicit.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -84,14 +84,14 @@
return ElasticityImplicit()
- def initialize(self, dimension, totalTime, dt):
+ def initialize(self, dimension):
"""
Initialize problem for implicit time integration.
"""
logEvent = "%sinit" % self._loggingPrefix
self._logger.eventBegin(logEvent)
- Formulation.initialize(self, dimension, totalTime, dt)
+ Formulation.initialize(self, dimension)
self._info.log("Creating other fields.")
self._debug.log(resourceUsageString())
@@ -119,10 +119,11 @@
return
- def startTime(self, dt):
+ def getStartTime(self):
"""
Get time at which time stepping should start.
"""
+ dt = self.timeStep.currentStep()
return -dt
@@ -181,7 +182,7 @@
return
- def poststep(self, t, dt, totalTime):
+ def poststep(self, t, dt):
"""
Hook for doing stuff after advancing time step.
"""
@@ -198,11 +199,11 @@
disp = self.fields.getSolution()
bindings.addRealSections(disp, disp, dispIncr)
- Formulation.poststep(self, t, dt, totalTime)
+ Formulation.poststep(self, t, dt)
# If finishing first time step, then switch from solving for total
# displacements to solving for incremental displacements
- if self._step0 and (t + dt) < totalTime:
+ if self._step0 and (t + dt) < self.timeStep.totalTime:
self._info.log("Switching from total field solution to incremental " \
"field solution.")
for constraint in self.constraints:
Modified: short/3D/PyLith/trunk/pylith/problems/TimeDependent.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeDependent.py 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/problems/TimeDependent.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -38,8 +38,7 @@
## Python object for managing TimeDependent facilities and properties.
##
## \b Properties
- ## @li \b total_time Time duration for simulation.
- ## @li \b default_dt Default time step.
+ ## None
##
## \b Facilities
## @li \b formulation Formulation for solving PDE.
@@ -47,15 +46,6 @@
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."
-
- dt = pyre.inventory.dimensional("default_dt", default=1.0*second,
- validator=pyre.inventory.greater(0.0*second))
- dt.meta['tip'] = "Default time step for simulation."
-
from Implicit import Implicit
formulation = pyre.inventory.facility("formulation",
family="pde_formulation",
@@ -121,7 +111,7 @@
self._logger.eventBegin(logEvent)
self._info.log("Initializing problem.")
- self.formulation.initialize(self.dimension, self.totalTime, self.dt)
+ self.formulation.initialize(self.dimension)
self._logger.eventEnd(logEvent)
return
@@ -137,32 +127,26 @@
self._info.log("Solving problem.")
self.checkpointTimer.toplevel = app # Set handle for saving state
- dt = self.formulation.stableTimeStep()
- if dt.value == 0.0: # If formulation returns 0.0, use default time step
- dt = self.dt
- t = self.formulation.startTime(self.dt)
- while t.value < self.totalTime.value:
+ t = self.formulation.getStartTime()
+ while t < self.formulation.getTotalTime():
self._info.log("Main time loop, current time is t=%s" % t)
# Checkpoint if necessary
self.checkpointTimer.update(t)
- # Get stable time step
- dt = self.formulation.stableTimeStep()
- if dt.value == 0.0:
- # If formulation returns 0.0, use default time step
- dt = self.dt
+ # Get time step for advancing in time
+ dt = self.formulation.getTimeStep()
- # Do stuff before advancing time step
- self._prestep(t, dt)
+ self._info.log("Preparing to advance solution from time t=%s to t=%s." % (t, t+dt))
+ self.formulation.prestep(t, dt)
- # Advance in time
- self._step(t, dt)
+ self._info.log("Advancing solution from t=%s to t=%s." % (t, t+dt))
+ self.formulation.step(t, dt)
- # Do stuff after advancing time step
- self._poststep(t, dt, self.totalTime)
+ self._info.log("Finishing advancing solution from t=%s to t=%s." % (t, t+dt))
+ self.formulation.poststep(t, dt)
- # Update time step
+ # Update time
t += dt
self._logger.eventEnd(logEvent)
@@ -203,40 +187,11 @@
Set members based using inventory.
"""
Problem._configure(self)
- self.totalTime = self.inventory.totalTime
- self.dt = self.inventory.dt
self.formulation = self.inventory.formulation
self.checkpointTimer = self.inventory.checkpointTimer
return
- def _prestep(self, t, dt):
- """
- Hook for doing stuff before advancing time step.
- """
- self._info.log("Preparing to advance solution from time t=%s." % t)
- self.formulation.prestep(t, dt)
- return
-
-
- def _step(self, t, dt):
- """
- Advance to next time step.
- """
- self._info.log("Advancing solution from t=%s to t=%s." % (t, t+dt))
- self.formulation.step(t, dt)
- return
-
-
- def _poststep(self, t, dt, totalTime):
- """
- Hook for doing stuff after advancing time step.
- """
- self._info.log("Finishing advancing solution to t=%s." % (t+dt))
- self.formulation.poststep(t, dt, totalTime)
- return
-
-
# FACTORIES ////////////////////////////////////////////////////////////
def problem():
Added: short/3D/PyLith/trunk/pylith/problems/TimeStep.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStep.py (rev 0)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStep.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/problems/TimeStep.py
+##
+## @brief Python abstract base class for managing the time step size.
+##
+## Factory: time_step
+
+from pyre.components.Component import Component
+
+from pylith.utils.profiling import resourceUsageString
+
+# TimeStep class
+class TimeStep(Component):
+ """
+ Python abstract base class for managing the time step size.
+
+ Factory: time_step.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="timestep"):
+ """
+ Constructor.
+ """
+ Component.__init__(self, name, facility="time_step")
+ from pyre.units.time import second
+ self.totalTime = 0.0*second
+ return
+
+
+ def preinitialize(self):
+ """
+ Setup time step size algorithm.
+ """
+ self._setupLogging()
+ logEvent = "%spreinit" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def verifyConfiguration(self):
+ """
+ Verify compatibility of configuration.
+ """
+ logEvent = "%sverify" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def initialize(self):
+ """
+ Initialize time step algorithm.
+ """
+ logEvent = "%sinit" % self._loggingPrefix
+ self._logger.eventBegin(logEvent)
+
+ self._logger.eventEnd(logEvent)
+ return
+
+
+ def numTimeSteps(self):
+ """
+ Get number of total time steps (or best guess if adaptive).
+ """
+ raise NotImplementedError("Please implement numTimeSteps().");
+ return 0
+
+
+ def timeStep(self, dtStable):
+ """
+ Adjust stable time step for advancing forward in time.
+ """
+ return dtStable
+
+
+ def currentStep(self):
+ """
+ Get current time step size.
+ """
+ raise NotImplementedError("Please implement currentStep().");
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ Component._configure(self)
+ return
+
+
+ def _setupLogging(self):
+ """
+ Setup event logging.
+ """
+ if not "_loggingPrefix" in dir(self):
+ self._loggingPrefix = ""
+
+ from pylith.utils.EventLogger import EventLogger
+ logger = EventLogger()
+ logger.setClassName("PDE TimeStep")
+ logger.initialize()
+
+ events = ["preinit",
+ "verify",
+ "init"]
+ for event in events:
+ logger.registerEvent("%s%s" % (self._loggingPrefix, event))
+
+ self._logger = logger
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def time_step():
+ """
+ Factory associated with TimeStep.
+ """
+ return TimeStep()
+
+
+# End of file
Added: short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py (rev 0)
+++ short/3D/PyLith/trunk/pylith/problems/TimeStepUniform.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/problems/TimeStepUniform.py
+##
+## @brief Python class for marching forward in time with a uniform time step.
+##
+## Factory: time_step
+
+from TimeStep import TimeStep
+
+from pylith.utils.profiling import resourceUsageString
+
+# TimeStepUniform class
+class TimeStepUniform(TimeStep):
+ """
+ Python abstract base class for marching format in time with a uniform time step.
+
+ Factory: time_step.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(TimeStep.Inventory):
+ """
+ Python object for managing TimeStepUniform facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing TimeStepUniform facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b total_time Time duration for simulation.
+ ## @li \b default_dt Default time step.
+ ##
+ ## \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."
+
+ dt = pyre.inventory.dimensional("dt", default=1.0*second,
+ validator=pyre.inventory.greater(0.0*second))
+ dt.meta['tip'] = "Time step for simulation."
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="timestepuniform"):
+ """
+ Constructor.
+ """
+ TimeStep.__init__(self, name)
+ return
+
+
+ def numTimeSteps(self):
+ """
+ Get number of total time steps (or best guess if adaptive).
+ """
+ nsteps = 1.0 + int(self.totalTime / self.dt)
+ return nsteps
+
+
+ def timeStep(self, dtStable):
+ """
+ Adjust stable time step for advancing forward in time.
+ """
+ return self.dt
+
+
+ def currentStep(self):
+ """
+ Get current time step size.
+ """
+ return self.dt
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ TimeStep._configure(self)
+ self.totalTime = self.inventory.totalTime
+ self.dt = self.inventory.dt
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def time_step():
+ """
+ Factory associated with TimeStepUniform.
+ """
+ return TimeStepUniform()
+
+
+# End of file
Modified: short/3D/PyLith/trunk/pylith/problems/__init__.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/__init__.py 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/pylith/problems/__init__.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -18,7 +18,11 @@
'Explicit',
'Implicit',
'Problem',
- 'TimeDependent']
+ 'TimeDependent',
+ 'TimeStep',
+ 'TimeStepUniform',
+ 'TimeStepUser',
+ 'TimeStepAdapt']
# End of file
Modified: short/3D/PyLith/trunk/unittests/pytests/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/Makefile.am 2008-07-04 22:34:43 UTC (rev 12375)
+++ short/3D/PyLith/trunk/unittests/pytests/Makefile.am 2008-07-05 00:56:02 UTC (rev 12376)
@@ -16,6 +16,7 @@
feassemble \
materials \
meshio \
+ problems \
topology \
utils
Added: short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/Makefile.am 2008-07-05 00:56:02 UTC (rev 12376)
@@ -0,0 +1,25 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# <LicenseText>
+#
+# ----------------------------------------------------------------------
+#
+
+subpackage = problems
+include $(top_srcdir)/subpackage.am
+
+TESTS = testproblems.py
+dist_check_SCRIPTS = testproblems.py
+
+TESTS_ENVIRONMENT = $(PYTHON)
+
+noinst_PYTHON = \
+ TestTimeStepUniform.py
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/TestTimeStepUniform.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/problems/TestTimeStepUniform.py
+
+## @brief Unit testing of TimeStepUniform object.
+
+import unittest
+
+from pyre.units.time import second
+
+# ----------------------------------------------------------------------
+class TestTimeStepUniform(unittest.TestCase):
+ """
+ Unit testing of TimeStepUniform object.
+ """
+
+ def test_numTimeSteps(self):
+ """
+ Test numTimeSteps().
+ """
+ from pylith.problems.TimeStepUniform import TimeStepUniform
+ tstep = TimeStepUniform()
+
+ tstep._configure()
+ self.assertEqual(1, tstep.numTimeSteps())
+
+ tstep.totalTime = 4.0*second
+ tstep.dt = 2.0*second
+ self.assertEqual(3, tstep.numTimeSteps())
+
+ return
+
+
+ def test_timeStep(self):
+ """
+ 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
+ self.assertEqual(1.0e-4*second, tstep.timeStep(0.5*second))
+
+ return
+
+
+ def test_currentStep(self):
+ """
+ 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
+ self.assertEqual(1.0e-4*second, tstep.currentStep())
+
+ return
+
+
+# End of file
Added: short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py
===================================================================
--- short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py (rev 0)
+++ short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py 2008-07-05 00:56:02 UTC (rev 12376)
@@ -0,0 +1,67 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# Brad T. Aagaard
+# U.S. Geological Survey
+#
+# {LicenseText}
+#
+# ======================================================================
+#
+
+## @file unittests/problems/testproblems.py
+
+## @brief Python application for testing problems code.
+
+from pyre.applications.Script import Script
+
+import unittest
+
+class TestApp(Script):
+ """
+ Test application.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="testapp"):
+ """
+ Constructor.
+ """
+ Script.__init__(self, name)
+ return
+
+
+ def main(self):
+ """
+ Run the application.
+ """
+
+ unittest.TextTestRunner(verbosity=2).run(self._suite())
+
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _suite(self):
+ """
+ Setup the test suite.
+ """
+
+ suite = unittest.TestSuite()
+
+ from TestTimeStepUniform import TestTimeStepUniform
+ suite.addTest(unittest.makeSuite(TestTimeStepUniform))
+
+ return suite
+
+
+# ----------------------------------------------------------------------
+if __name__ == '__main__':
+ app = TestApp()
+ app.run()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/unittests/pytests/problems/testproblems.py
___________________________________________________________________
Name: svn:executable
+ *
More information about the cig-commits
mailing list