[cig-commits] [commit] master: py: Add plotting toggle. (05f9922)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Jan 7 07:56:33 PST 2015


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

On branch  : master
Link       : https://github.com/geodynamics/specfem1d/compare/5ac1833074897dbc9cc286395ddae214ea0452e3...c63d455e0ff0075e43cb487147ab0bc101d4019c

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

commit 05f99229fd501dfd028c72c39c396a0badbc7db5
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date:   Wed Jan 7 02:45:43 2015 -0500

    py: Add plotting toggle.
    
    Disabling plotting results in a 2.66x speedup.


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

05f99229fd501dfd028c72c39c396a0badbc7db5
 Python_version/Par_file                   |  2 ++
 Python_version/defines.py                 |  3 +++
 Python_version/main_for_Python_version.py | 19 +++++++++++--------
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/Python_version/Par_file b/Python_version/Par_file
index eec3492..99c91ef 100644
--- a/Python_version/Par_file
+++ b/Python_version/Par_file
@@ -51,5 +51,7 @@ CFL = 0.45
 #########
 # Plots #
 #########
+# Enable plotting
+PLOT = True
 # One image is displayed each DPLOT time step
 DPLOT = 10
diff --git a/Python_version/defines.py b/Python_version/defines.py
index 611fcc5..f232838 100644
--- a/Python_version/defines.py
+++ b/Python_version/defines.py
@@ -127,6 +127,8 @@ class Parameter(object):
             'SOURCE_TYPE': 'ricker',
             # Decay rate for the ricker
             'DECAY_RATE': 2.628,
+            # Plot grid, source, and periodic results
+            'PLOT': False,
             # One image is displayed each DPLOT time step
             'DPLOT': 10,
         })
@@ -150,6 +152,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.plot = cp.getboolean('global', 'PLOT')
         self.dplot = cp.getfloat('global', 'DPLOT')
 
         self.nGLL = self.N + 1              # Number of GLL points per elements
diff --git a/Python_version/main_for_Python_version.py b/Python_version/main_for_Python_version.py
index 77a0eee..762d484 100644
--- a/Python_version/main_for_Python_version.py
+++ b/Python_version/main_for_Python_version.py
@@ -32,11 +32,13 @@ import functions        # Contains fundamental functions
 # Initialization
 param=Parameter()    # Initialize all the parameters of the run. Store them
 grid=OneDgrid(param) # Initialize the grid from these parameters
-#grid.plotGrid()      # Plot the grid
+if param.plot:
+    grid.plotGrid()
 
 param.dt=functions.estimateDt(grid,param) # estimate the time step in seconds
 source=Source(param) # Initialize the source
-#source.plotSource()  # Plot the source
+if param.plot:
+    source.plotSource()
 
 # Computation of stiffness matrices
 Ke=functions.makeStiffness(grid,param)
@@ -48,11 +50,12 @@ M=functions.makeMass(grid,param)
 u=np.zeros(param.nGlob,dtype='d')
 vel,acc=np.zeros_like(u),np.zeros_like(u)
 
-plt.ion()
-fig=plt.figure()
-plt.hold(False)
-bz=-np.array([i for i in reversed(grid.z)])
-cz=append(bz,grid.z)
+if param.plot:
+    plt.ion()
+    fig = plt.figure()
+    plt.hold(False)
+    bz = -np.array([i for i in reversed(grid.z)])
+    cz = append(bz, grid.z)
 
 # Main time loop :
 for it in np.arange(param.nts):
@@ -72,7 +75,7 @@ for it in np.arange(param.nts):
     acc[:] /= M[:]
     vel[:] += param.dt/2*acc[:]
 
-    if it % param.dplot == 0:
+    if param.plot and it % param.dplot == 0:
         if param.axisym:
             b=np.array([i for i in reversed(u)])
             c=append(b,u)



More information about the CIG-COMMITS mailing list