[cig-commits] [commit] baagaard/feature-output-station-names, baagaard/feature-progress-monitor, master: Added progress monitor to TimeDependent. (1e9f9bb)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Nov 5 15:47:41 PST 2014
Repository : https://github.com/geodynamics/pylith
On branches: baagaard/feature-output-station-names,baagaard/feature-progress-monitor,master
Link : https://github.com/geodynamics/pylith/compare/f33c75b19fd60eedb2a3405db76a1fee333bb1d7...5b6d812b1612809fea3bd331c4e5af98c25a536a
>---------------------------------------------------------------
commit 1e9f9bb22bd082d9a8ba73fe25b0ed5b6f1900d8
Author: Brad Aagaard <baagaard at usgs.gov>
Date: Fri Oct 31 14:49:03 2014 -0700
Added progress monitor to TimeDependent.
>---------------------------------------------------------------
1e9f9bb22bd082d9a8ba73fe25b0ed5b6f1900d8
pylith/problems/ProgressMonitor.py | 15 ++++++++++-----
pylith/problems/TimeDependent.py | 25 ++++++++++++++++++-------
unittests/pytests/problems/Makefile.am | 3 ++-
unittests/pytests/problems/data/Makefile.am | 3 ++-
unittests/pytests/problems/testproblems.py | 3 +++
5 files changed, 35 insertions(+), 14 deletions(-)
diff --git a/pylith/problems/ProgressMonitor.py b/pylith/problems/ProgressMonitor.py
index 8b3f0e7..81c186d 100644
--- a/pylith/problems/ProgressMonitor.py
+++ b/pylith/problems/ProgressMonitor.py
@@ -70,6 +70,7 @@ class ProgressMonitor(PetscComponent):
Constructor.
"""
PetscComponent.__init__(self, name, facility="progress_monitor")
+ self.fout = None
return
@@ -88,17 +89,18 @@ class ProgressMonitor(PetscComponent):
self.isMaster = True
if self.isMaster:
self.fout = open(self.filename, "w")
- self.fout.write("Timestamp Simulation t # timesteps % complete Est. completion\n")
+ self.fout.write("Timestamp Simulation t % complete Est. completion\n")
return
def close(self):
- if self.isMaster:
+ if self.fout:
self.fout.close()
+ self.fout = None
return
- def update(self, istep, t, tStart, tEnd):
+ def update(self, t, tStart, tEnd):
writeUpdate = False
if self.tPrev:
incrCompleted = (t-self.tPrev) / (tEnd-tStart)
@@ -108,9 +110,12 @@ class ProgressMonitor(PetscComponent):
percentComplete = (t-tStart)/(tEnd-tStart)*100.0
tSimNorm = t.value / self.tSimScale.value
now = datetime.datetime.now()
- finished = self.datetimeStart + datetime.timedelta(seconds=100.0/percentComplete * ((now-self.datetimeStart).total_seconds()))
+ if percentComplete > 0.0:
+ finished = self.datetimeStart + datetime.timedelta(seconds=100.0/percentComplete * ((now-self.datetimeStart).total_seconds()))
+ else:
+ finished = "TBD"
if self.isMaster:
- self.fout.write("%s %.4f*%s %11d %10.0f %s\n" % (now, tSimNorm, self.tUnits, istep, percentComplete, finished))
+ self.fout.write("%s %8.2f*%s %10.0f %s\n" % (now, tSimNorm, self.tUnits, percentComplete, finished))
self.tPrev = t
return
diff --git a/pylith/problems/TimeDependent.py b/pylith/problems/TimeDependent.py
index ce2afef..a33e4f1 100644
--- a/pylith/problems/TimeDependent.py
+++ b/pylith/problems/TimeDependent.py
@@ -48,6 +48,7 @@ class TimeDependent(Problem):
##
## \b Facilities
## @li \b formulation Formulation for solving PDE.
+ ## @li \b progress_monitor Simple progress monitor via text file.
## @li \b checkpoint Checkpoint manager.
import pyre.inventory
@@ -56,15 +57,15 @@ class TimeDependent(Problem):
elasticPrestep.meta['tip'] = "Include a static calculation with elastic behavior before time stepping."
from Implicit import Implicit
- formulation = pyre.inventory.facility("formulation",
- family="pde_formulation",
- factory=Implicit)
+ formulation = pyre.inventory.facility("formulation", family="pde_formulation", factory=Implicit)
formulation.meta['tip'] = "Formulation for solving PDE."
+ from ProgressMonitor import ProgressMonitor
+ progressMonitor = pyre.inventory.facility("progress_monitor", family="progress_monitor", factory=ProgressMonitor)
+ formulation.meta['tip'] = "Simple progress monitor via text file."
+
from pylith.utils.CheckpointTimer import CheckpointTimer
- checkpointTimer = pyre.inventory.facility("checkpoint",
- family="checkpointer",
- factory=CheckpointTimer)
+ checkpointTimer = pyre.inventory.facility("checkpoint", family="checkpointer", factory=CheckpointTimer)
checkpointTimer.meta['tip'] = "Checkpoint manager."
@@ -166,12 +167,19 @@ class TimeDependent(Problem):
material.useElasticBehavior(False)
+ if (self.formulation.getTotalTime() > self.formulation.getStartTime()):
+ self.progressMonitor.open()
+
# Normal time loop
t = self.formulation.getStartTime()
timeScale = self.normalizer.timeScale()
while t < self.formulation.getTotalTime():
- self._eventLogger.stagePush("Prestep")
tsec = self.normalizer.dimensionalize(t, timeScale)
+ tStart = self.normalizer.dimensionalize(self.formulation.getStartTime(), timeScale)
+ tEnd = self.normalizer.dimensionalize(self.formulation.getTotalTime(), timeScale)
+ self.progressMonitor.update(tsec, tStart, tEnd)
+
+ self._eventLogger.stagePush("Prestep")
if 0 == comm.rank:
self._info.log("Main time loop, current time is t=%s" % tsec)
@@ -204,6 +212,8 @@ class TimeDependent(Problem):
# Update time
t += dt
+
+ self.progressMonitor.close()
return
@@ -238,6 +248,7 @@ class TimeDependent(Problem):
Problem._configure(self)
self.elasticPrestep = self.inventory.elasticPrestep
self.formulation = self.inventory.formulation
+ self.progressMonitor = self.inventory.progressMonitor
self.checkpointTimer = self.inventory.checkpointTimer
return
diff --git a/unittests/pytests/problems/Makefile.am b/unittests/pytests/problems/Makefile.am
index e737637..1bd9fc4 100644
--- a/unittests/pytests/problems/Makefile.am
+++ b/unittests/pytests/problems/Makefile.am
@@ -27,7 +27,8 @@ noinst_PYTHON = \
TestTimeStep.py \
TestTimeStepAdapt.py \
TestTimeStepUniform.py \
- TestTimeStepUser.py
+ TestTimeStepUser.py \
+ TestProgressMonitor.py
# End of file
diff --git a/unittests/pytests/problems/data/Makefile.am b/unittests/pytests/problems/data/Makefile.am
index a857f28..3caa37d 100644
--- a/unittests/pytests/problems/data/Makefile.am
+++ b/unittests/pytests/problems/data/Makefile.am
@@ -19,7 +19,8 @@
dist_noinst_DATA = \
timesteps.txt
-noinst_TMP =
+noinst_TMP = \
+ progress.txt
# 'export' the input files by performing a mock install
export_datadir = $(top_builddir)/unittests/pytests/problems/data
diff --git a/unittests/pytests/problems/testproblems.py b/unittests/pytests/problems/testproblems.py
index a470d64..7156503 100755
--- a/unittests/pytests/problems/testproblems.py
+++ b/unittests/pytests/problems/testproblems.py
@@ -75,6 +75,9 @@ class TestApp(Script):
from TestTimeStepAdapt import TestTimeStepAdapt
suite.addTest(unittest.makeSuite(TestTimeStepAdapt))
+ from TestProgressMonitor import TestProgressMonitor
+ suite.addTest(unittest.makeSuite(TestProgressMonitor))
+
return suite
More information about the CIG-COMMITS
mailing list