[cig-commits] [commit] master: py: Tweak main program a bit. (b05fbed)

cig_noreply at geodynamics.org cig_noreply at geodynamics.org
Wed Jan 14 09:29:42 PST 2015


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

On branch  : master
Link       : https://github.com/geodynamics/specfem1d/compare/2ccfba13481e26296eebf034518cd31d2c727906...33b512de01491f2c70de206939855d95b22febf4

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

commit b05fbedeb03ffe1345613abdbd5c2628b5114235
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date:   Mon Jan 12 19:37:40 2015 -0500

    py: Tweak main program a bit.
    
    Remove some extraneous slicing and np.arange calls. Also fix a bug in
    plotting and snapshotting where the middle point is shown twice.


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

b05fbedeb03ffe1345613abdbd5c2628b5114235
 Python_version/specfem1d.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/Python_version/specfem1d.py b/Python_version/specfem1d.py
index ae46b08..3585f5f 100755
--- a/Python_version/specfem1d.py
+++ b/Python_version/specfem1d.py
@@ -49,40 +49,39 @@ 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)
+    cz = np.concatenate((-grid.z[:0:-1], grid.z))
 
 # Main time loop :
-for it in np.arange(param.nts):
+for it in range(param.nts):
     print 'it = ',it,' (t = ',it*param.dt,'s)'
     if it > 0:
-        u[:] += param.dt*vel[:] + acc[:]*(param.dt**2)/2
-        vel[:] += param.dt/2*acc[:]
-        acc[:] = 0.
+        u += param.dt * vel + acc * param.dt**2 / 2
+        vel += param.dt / 2 * acc
+        acc.fill(0)
 
-    for e in np.arange(param.nSpec):
+    for e in range(param.nSpec):
         acc[param.ibool[e,:]] -= np.dot(Ke[e,:,:], u[param.ibool[e,:]])
 
     acc[param.iSource] += source[it*param.dt]
 #    # Boundary conditions :
 #    acc[0] = 0.
 #    acc[len(acc)-1] = 0.
-    acc[:] /= M[:]
-    vel[:] += param.dt/2*acc[:]
+    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))
+            c = np.concatenate((u[:0:-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)])
-            c = np.append(b, u)
+            c = np.concatenate((u[:0:-1], u))
             plt.plot(cz,c)
             plt.xlim([-max(grid.z),max(grid.z)])
             plt.ylim([-10,10]) #plt.ylim([0,0.01])



More information about the CIG-COMMITS mailing list