[cig-commits] [commit] master: py: Add snapshotting option. (85522a6)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Tue Jan 13 08:21:20 PST 2015


Repository : https://github.com/geodynamics/specfem1d

On branch  : master
Link       : https://github.com/geodynamics/specfem1d/compare/067b9384a823b64c0f0fe1aff95de89c7d9d5397...2ccfba13481e26296eebf034518cd31d2c727906

>---------------------------------------------------------------

commit 85522a6f06e8b6882a9fa50aec3d5f90181650c5
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date:   Mon Jan 12 20:56:43 2015 -0500

    py: Add snapshotting option.
    
    The SNAPSHOT option sets the number of time steps between a snapshot.
    Setting this option to 0 disables snapshotting.


>---------------------------------------------------------------

85522a6f06e8b6882a9fa50aec3d5f90181650c5
 Python_version/Par_file     | 7 +++++++
 Python_version/config.py    | 3 +++
 Python_version/specfem1d.py | 9 +++++++++
 3 files changed, 19 insertions(+)

diff --git a/Python_version/Par_file b/Python_version/Par_file
index 99c91ef..a835819 100644
--- a/Python_version/Par_file
+++ b/Python_version/Par_file
@@ -48,6 +48,13 @@ NTS = 20000
 # Courant CFL number
 CFL = 0.45
 
+#############
+# Snapshots #
+#############
+
+# Time steps between snapshot output. Disabled if 0.
+SNAPSHOT = 1000000
+
 #########
 # Plots #
 #########
diff --git a/Python_version/config.py b/Python_version/config.py
index 43789d1..35f2da8 100644
--- a/Python_version/config.py
+++ b/Python_version/config.py
@@ -79,6 +79,8 @@ class Parameter(object):
             'SOURCE_TYPE': 'ricker',
             # Decay rate for the ricker
             'DECAY_RATE': 2.628,
+            # Time steps between snapshots (0 == disabled)
+            'SNAPSHOT': 0,
             # Plot grid, source, and periodic results
             'PLOT': False,
             # One image is displayed each DPLOT time step
@@ -104,6 +106,7 @@ class Parameter(object):
         self.maxAmpl = cp.getfloat('global', 'MAX_AMPL')
         self.sourceType = cp.get('global', 'SOURCE_TYPE').strip("'\"")
         self.decayRate = cp.getfloat('global', 'DECAY_RATE')
+        self.snapshot = cp.getint('global', 'SNAPSHOT')
         self.plot = cp.getboolean('global', 'PLOT')
         self.dplot = cp.getfloat('global', 'DPLOT')
 
diff --git a/Python_version/specfem1d.py b/Python_version/specfem1d.py
index a557c59..76b5d0d 100755
--- a/Python_version/specfem1d.py
+++ b/Python_version/specfem1d.py
@@ -49,6 +49,7 @@ if param.plot:
     plt.ion()
     fig = plt.figure()
     plt.hold(False)
+if param.axisym and (param.plot or param.snapshot):
     bz = -np.array([i for i in reversed(grid.z)])
     cz = np.append(bz, grid.z)
 
@@ -70,6 +71,14 @@ for it in np.arange(param.nts):
     acc[:] /= M[:]
     vel[:] += param.dt/2*acc[:]
 
+    if param.snapshot and (it % param.snapshot == 0 or it == param.nts - 1):
+        name = 'snapshot_forward_normal%05d' % (it, )
+        if param.axisym:
+            c = np.concatenate((u[::-1], u))
+            np.savetxt(name, np.column_stack((cz, c)))
+        else:
+            np.savetxt(name, np.column_stack((grid.z, u)))
+
     if param.plot and it % param.dplot == 0:
         if param.axisym:
             b=np.array([i for i in reversed(u)])



More information about the CIG-COMMITS mailing list