[cig-commits] [commit] master: py: Simplify homogeneous grid creation a bit. (c4a0a79)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Jan 14 09:29:29 PST 2015
Repository : https://github.com/geodynamics/specfem1d
On branch : master
Link : https://github.com/geodynamics/specfem1d/compare/2ccfba13481e26296eebf034518cd31d2c727906...33b512de01491f2c70de206939855d95b22febf4
>---------------------------------------------------------------
commit c4a0a7956258f984d1e73121a565698dbf78753c
Author: Elliott Sales de Andrade <esalesde at physics.utoronto.ca>
Date: Sun Jan 11 04:25:51 2015 -0500
py: Simplify homogeneous grid creation a bit.
Filling a vector with constants is 2 orders of magnitude faster than
looping through each element. Changing the for loop on z reduces the
function call overhead. Again, the optimization is minor since this is
done only once.
>---------------------------------------------------------------
c4a0a7956258f984d1e73121a565698dbf78753c
Python_version/grid.py | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/Python_version/grid.py b/Python_version/grid.py
index 34e30c2..bee1d63 100644
--- a/Python_version/grid.py
+++ b/Python_version/grid.py
@@ -19,23 +19,25 @@ class OneDimensionalGrid(object):
self.rho=np.zeros((param.nSpec,param.nGLL))
self.mu=np.zeros((param.nSpec,param.nGLL))
self.ticks=np.zeros(param.nSpec+1)
+
if param.gridType == 'homogeneous':
self.ticks = np.linspace(0, param.length, param.nSpec + 1)
- for e in np.arange(param.nSpec):
- for i in np.arange(param.nGLL):
- self.rho[e,i] = param.meanRho
- self.mu[e,i] = param.meanMu
- for i in np.arange(param.nGlob-1)+1:
- if i < param.nGLJ:
- self.z[i] = functions.project_inverse(param.ksiGLJ[i], 0,
- self.ticks)
- if i >= param.nGLL and i < param.nGlob-1:
- self.z[i] = functions.project_inverse(
- param.ksiGLL[i % param.N],
- i // param.N,
- self.ticks)
- else:
- self.z[param.nGlob-1]=self.ticks[len(self.ticks)-1]
+ self.rho.fill(param.meanRho)
+ self.mu.fill(param.meanMu)
+
+ self.z[1:param.nGLJ] = functions.project_inverse(
+ param.ksiGLJ[1:param.nGLJ],
+ 0,
+ self.ticks)
+
+ ksiGLL = param.ksiGLL[1:]
+ for i in range(param.nGLL, param.nGlob, param.N):
+ self.z[i:i + param.N] = functions.project_inverse(ksiGLL,
+ i // param.N,
+ self.ticks)
+
+ self.z[-1] = self.ticks[-1]
+
elif param.gridType == 'gradient':
print "typeOfGrid == 'gradient' Has not been implemented yet"
raise
More information about the CIG-COMMITS
mailing list