[cig-commits] [commit] baagaard/feature-output-station-names, baagaard/feature-progress-monitor, master: Started work on progress monitor. (543c146)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Nov 5 15:47:38 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 543c14682b65dad608a610b1352594e796f59415
Author: Brad Aagaard <baagaard at usgs.gov>
Date: Fri Oct 31 14:09:33 2014 -0700
Started work on progress monitor.
>---------------------------------------------------------------
543c14682b65dad608a610b1352594e796f59415
pylith/Makefile.am | 1 +
pylith/problems/ProgressMonitor.py | 141 +++++++++++++++++++++++++++++++++++++
pylith/problems/__init__.py | 4 +-
3 files changed, 145 insertions(+), 1 deletion(-)
diff --git a/pylith/Makefile.am b/pylith/Makefile.am
index bf0ddcc..e1408da 100644
--- a/pylith/Makefile.am
+++ b/pylith/Makefile.am
@@ -143,6 +143,7 @@ nobase_pkgpyexec_PYTHON = \
problems/TimeStepAdapt.py \
problems/TimeStepUniform.py \
problems/TimeStepUser.py \
+ problems/ProgressMonitor.py \
topology/__init__.py \
topology/Distributor.py \
topology/Mesh.py \
diff --git a/pylith/problems/ProgressMonitor.py b/pylith/problems/ProgressMonitor.py
new file mode 100644
index 0000000..8b3f0e7
--- /dev/null
+++ b/pylith/problems/ProgressMonitor.py
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010-2014 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+## @file pylith/solver/ProgressMonitor.py
+##
+## @brief Python PyLith abstract base class for solver.
+##
+## Factory: solver
+
+from pylith.utils.PetscComponent import PetscComponent
+import datetime
+
+# ProgressMonitor class
+class ProgressMonitor(PetscComponent):
+ """
+ Python abstract base class for solver.
+
+ Factory: solver.
+ """
+
+ # INVENTORY //////////////////////////////////////////////////////////
+
+ class Inventory(PetscComponent.Inventory):
+ """
+ Python object for managing ProgressMonitor facilities and properties.
+ """
+
+ ## @class Inventory
+ ## Python object for managing ProgressMonitor facilities and properties.
+ ##
+ ## \b Properties
+ ## @li \b filename Name of output file.
+ ## @li \b t_units Units for simulation time in output.
+ ## @li \b update_percent Frequency of progress updates (percent).
+ ##
+ ## \b Facilities
+ ## @li None
+
+ import pyre.inventory
+
+ filename = pyre.inventory.str("filename", default="progress.txt")
+ filename.meta['tip'] = "Name of output file."
+
+ tUnits = pyre.inventory.str("t_units", default="year")
+ tUnits.meta['tip'] = "Units for simulation time in output."
+
+ updatePercent = pyre.inventory.float("update_percent", default=5.0)
+ updatePercent.meta['tip'] = "Frequency of progress updates (percent)."
+
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="progress_monitor"):
+ """
+ Constructor.
+ """
+ PetscComponent.__init__(self, name, facility="progress_monitor")
+ return
+
+
+ def open(self):
+ self.tPrev = None
+ self.datetimeStart = datetime.datetime.now()
+
+ import pyre.units
+ uparser = pyre.units.parser()
+ self.tSimScale = uparser.parse(self.tUnits)
+
+ try:
+ import pylith.mpi.mpi as mpi
+ self.isMaster = 0 == mpi.rank()
+ except:
+ self.isMaster = True
+ if self.isMaster:
+ self.fout = open(self.filename, "w")
+ self.fout.write("Timestamp Simulation t # timesteps % complete Est. completion\n")
+ return
+
+
+ def close(self):
+ if self.isMaster:
+ self.fout.close()
+ return
+
+
+ def update(self, istep, t, tStart, tEnd):
+ writeUpdate = False
+ if self.tPrev:
+ incrCompleted = (t-self.tPrev) / (tEnd-tStart)
+ else:
+ incrCompleted = 0.0
+ if not self.tPrev or incrCompleted > self.updatePercent/100.0:
+ 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 self.isMaster:
+ self.fout.write("%s %.4f*%s %11d %10.0f %s\n" % (now, tSimNorm, self.tUnits, istep, percentComplete, finished))
+ self.tPrev = t
+ return
+
+
+ # PRIVATE METHODS /////////////////////////////////////////////////////
+
+ def _configure(self):
+ """
+ Set members based using inventory.
+ """
+ PetscComponent._configure(self)
+
+ self.filename = self.inventory.filename
+ self.tUnits = self.inventory.tUnits
+ self.updatePercent = self.inventory.updatePercent
+ return
+
+
+# FACTORIES ////////////////////////////////////////////////////////////
+
+def progress_monitor():
+ """
+ Factory associated with ProgressMonitor.
+ """
+ return ProgressMonitor()
+
+
+# End of file
diff --git a/pylith/problems/__init__.py b/pylith/problems/__init__.py
index 3498d3f..38c2ed2 100644
--- a/pylith/problems/__init__.py
+++ b/pylith/problems/__init__.py
@@ -31,7 +31,9 @@ __all__ = ['EqDeformation',
'TimeStep',
'TimeStepUniform',
'TimeStepUser',
- 'TimeStepAdapt']
+ 'TimeStepAdapt',
+ 'ProgressMonitor',
+]
# End of file
More information about the CIG-COMMITS
mailing list