[cig-commits] [commit] master: py: Factor grid definition into its own file. (3918375)
cig_noreply at geodynamics.org
cig_noreply at geodynamics.org
Wed Jan 7 16:50:48 PST 2015
Repository : https://github.com/geodynamics/specfem1d
On branch : master
Link : https://github.com/geodynamics/specfem1d/compare/c63d455e0ff0075e43cb487147ab0bc101d4019c...81ba23d88e3baad884dd78c47c7581ffe856f7b2
>---------------------------------------------------------------
commit 3918375e87eee0dcb454b3aa91d279d484b9c10b
Author: Elliott Sales de Andrade <quantum.analyst at gmail.com>
Date: Wed Jan 7 04:22:03 2015 -0500
py: Factor grid definition into its own file.
>---------------------------------------------------------------
3918375e87eee0dcb454b3aa91d279d484b9c10b
Python_version/defines.py | 65 --------------------------
Python_version/grid.py | 76 +++++++++++++++++++++++++++++++
Python_version/main_for_Python_version.py | 6 +--
3 files changed, 79 insertions(+), 68 deletions(-)
diff --git a/Python_version/defines.py b/Python_version/defines.py
index 1b6f916..3758828 100644
--- a/Python_version/defines.py
+++ b/Python_version/defines.py
@@ -134,71 +134,6 @@ class Parameter(object):
self.derivGLJ = gll.glj_derivative(self.ksiGLJ)
-class OneDgrid:
- """Contains the grid properties"""
-
- def __init__(self,param):
- """Init"""
- self.param=param
- self.z=np.zeros(param.nGlob)
- 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.invProjection(param.ksiGLJ[i],0,self.ticks)
- if i >= param.nGLL and i < param.nGlob-1:
- self.z[i]=functions.invProjection(param.ksiGLL[i%param.N],i//param.N,self.ticks)
- else:
- self.z[param.nGlob-1]=self.ticks[len(self.ticks)-1]
- elif param.gridType == 'gradient':
- print "typeOfGrid == 'gradient' Has not been implemented yet"
- raise
- elif param.gridType == 'miscellaneous':
- print "typeOfGrid == 'miscellaneous' Has not been implemented yet"
- raise
- elif param.gridType == 'file':
- self.z, self.rho, self.mu = np.loadtxt(param.gridFile, unpack=True)
- self.ticks = np.loadtxt(param.ticksFile)
- else :
- print "Unknown grid's type"
- raise
- # Jacobians at the GLL (and GLJ for the first element in axisym)
- # points (arrays nSpec*(N+1) elements)
- self.dXdKsi = gll.jacobian(self.ticks, param)
- self.dKsiDx = gll.jacobian_inverse(self.ticks, param)
-
- def plotGrid(self,fig=0):
- """Plot the grid
- my_ticks gives the abscissa of the borders
- TODO I should test : _the types of the parameters
- _their sizes"""
- plt.figure(fig)
- sub1=plt.subplot(211)
- plt.hold(True)
- for e in np.arange(self.param.nSpec):
- for i in np.arange(self.param.nGLL):
- plt.plot(self.z[self.param.ibool[e,i]],self.rho[e,i],'b+')
- sub1.set_title(r'$\rho(z)$')
- plt.xticks(self.ticks)
- plt.grid(True)
- sub2=plt.subplot(212)
- for e in np.arange(self.param.nSpec):
- for i in np.arange(self.param.nGLL):
- plt.plot(self.z[self.param.ibool[e,i]],self.mu[e,i],'r+')
- sub2.set_title(r'$\mu(z)$')
- plt.suptitle(" Grid ")
- plt.xticks(self.ticks)
- plt.grid(True)
- plt.show()
- plt.hold(False)
-
class Source:
"""Contains the source properties"""
diff --git a/Python_version/grid.py b/Python_version/grid.py
new file mode 100644
index 0000000..9003831
--- /dev/null
+++ b/Python_version/grid.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+'''
+Definitions of the grid.
+'''
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+import functions
+import gll
+
+
+class OneDimensionalGrid(object):
+ """Contains the grid properties"""
+
+ def __init__(self,param):
+ """Init"""
+ self.param=param
+ self.z=np.zeros(param.nGlob)
+ 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.invProjection(param.ksiGLJ[i],0,self.ticks)
+ if i >= param.nGLL and i < param.nGlob-1:
+ self.z[i]=functions.invProjection(param.ksiGLL[i%param.N],i//param.N,self.ticks)
+ else:
+ self.z[param.nGlob-1]=self.ticks[len(self.ticks)-1]
+ elif param.gridType == 'gradient':
+ print "typeOfGrid == 'gradient' Has not been implemented yet"
+ raise
+ elif param.gridType == 'miscellaneous':
+ print "typeOfGrid == 'miscellaneous' Has not been implemented yet"
+ raise
+ elif param.gridType == 'file':
+ self.z, self.rho, self.mu = np.loadtxt(param.gridFile, unpack=True)
+ self.ticks = np.loadtxt(param.ticksFile)
+ else :
+ print "Unknown grid's type"
+ raise
+ # Jacobians at the GLL (and GLJ for the first element in axisym)
+ # points (arrays nSpec*(N+1) elements)
+ self.dXdKsi = gll.jacobian(self.ticks, param)
+ self.dKsiDx = gll.jacobian_inverse(self.ticks, param)
+
+ def plot(self, fig=0):
+ """Plot the grid
+ my_ticks gives the abscissa of the borders
+ TODO I should test : _the types of the parameters
+ _their sizes"""
+ plt.figure(fig)
+ sub1=plt.subplot(211)
+ plt.hold(True)
+ for e in np.arange(self.param.nSpec):
+ for i in np.arange(self.param.nGLL):
+ plt.plot(self.z[self.param.ibool[e,i]],self.rho[e,i],'b+')
+ sub1.set_title(r'$\rho(z)$')
+ plt.xticks(self.ticks)
+ plt.grid(True)
+ sub2=plt.subplot(212)
+ for e in np.arange(self.param.nSpec):
+ for i in np.arange(self.param.nGLL):
+ plt.plot(self.z[self.param.ibool[e,i]],self.mu[e,i],'r+')
+ sub2.set_title(r'$\mu(z)$')
+ plt.suptitle(" Grid ")
+ plt.xticks(self.ticks)
+ plt.grid(True)
+ plt.show()
+ plt.hold(False)
diff --git a/Python_version/main_for_Python_version.py b/Python_version/main_for_Python_version.py
index 9517585..3d9947b 100644
--- a/Python_version/main_for_Python_version.py
+++ b/Python_version/main_for_Python_version.py
@@ -18,16 +18,16 @@ import numpy as np
import matplotlib.pyplot as plt
from defines import Parameter
-from defines import OneDgrid
from defines import Source
import functions # Contains fundamental functions
+from grid import OneDimensionalGrid
### --- MAIN BODY --- ###
# Initialization
param=Parameter() # Initialize all the parameters of the run. Store them
-grid=OneDgrid(param) # Initialize the grid from these parameters
+grid = OneDimensionalGrid(param)
if param.plot:
- grid.plotGrid()
+ grid.plot()
param.dt=functions.estimateDt(grid,param) # estimate the time step in seconds
source=Source(param) # Initialize the source
More information about the CIG-COMMITS
mailing list