Changeset 747
- Timestamp:
- 10/05/18 13:42:49 (6 years ago)
- Location:
- codes/icosagcm/devel
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/dynamico/meshes.py
r689 r747 11 11 import parallel 12 12 from util import list_stencil, Base_class, inverse_list 13 from precision import zeros 13 14 14 15 radian=180/math.pi 15 16 def zeros(dims): return np.zeros([n for n in dims if n>1], dtype=unst.np_num) 17 16 18 17 #------------------- Hybrid mass-based coordinate ------------- 19 18 … … 170 169 (indexu(x,y+1),.25), 171 170 (indexu(x-1,y+1),.25))) 172 Aiv=np.zeros(nx*ny)+dx*dy # Ai=Av=dx*dy 171 Aiv=np.zeros(nx*ny) 172 Aiv[:]=dx*dy # Ai=Av=dx*dy 173 173 unst.init_mesh(llm,nqdyn,2*nx*ny,nx*ny,nx*ny,4,4,4, 174 174 primal_nb,primal_edge,primal_ne, … … 181 181 def field_z(self,n=1): return zeros((n,self.ny,self.nx,self.llm)) 182 182 def field_w(self,n=1): return zeros((n,self.ny,self.nx,self.llm+1)) 183 def field_u(self,n=1): 184 if n==1: 185 return np.zeros((self.ny,2*self.nx,self.llm)) 186 else: 187 return np.zeros((n,self.ny,2*self.nx,self.llm)) 183 def field_u(self,n=1): return zeros((self.ny,2*self.nx,self.llm)) 188 184 def field_ps(self,n=1): return zeros((n,self.ny,self.nx)) 189 def ucomp(self,u): return u[:,range(0,2*self.nx,2),:] 190 def set_ucomp(self,uv,u): uv[:,range(0,2*self.nx,2),:]=u 185 def ucomp(self,u): 186 return u[range(0,2*self.nx,2),:] if self.ny==1 else u[:,range(0,2*self.nx,2),:] 187 def set_ucomp(self,uv,u): 188 if self.ny==1 : uv[range(0,2*self.nx,2),:]=u 189 else : uv[:,range(0,2*self.nx,2),:]=u 191 190 def vcomp(self,u): return u[:,range(1,2*self.nx,2),:] 192 191 … … 288 287 return self.de*(ulon*np.cos(self.angle_e)+ulat*np.sin(self.angle_e)) 289 288 def ucov3D(self, ulon, ulat): 290 ucov = np.zeros((self.edge_num,ulon.shape[1]))289 ucov = zeros((self.edge_num,ulon.shape[1])) 291 290 for edge in range(self.edge_num): 292 291 angle=self.angle_e[edge] -
codes/icosagcm/devel/Python/dynamico/time_step.py
r615 r747 85 85 def cjl(self,b): # converts Butcher tableau b(j,l) to update coefficients c(j,l) 86 86 return np.array([ b[j+1,:]-b[j,:] for j in range(self.nstage)]) 87 def __init__(self,bwd_fast_slow, dt,nstage, bsjl,bfjl): 87 def __init__(self,precision,bwd_fast_slow, dt,nstage, bsjl,bfjl): 88 if bwd_fast_slow is None: 89 print 'SIRK with Fortran-side time stepping' 90 precision=np.float64 91 else: 92 print 'SIRK with Python-side time stepping at precision ', precision 93 88 94 self.bwd_fast_slow = bwd_fast_slow 89 95 self.dt, self.nstage = dt, nstage 90 self.csjl = dt*self.cjl(bsjl) 91 self.cfjl = dt*self.cjl(bfjl) 92 self.tauj = np.array([dt*bfjl[j,j] for j in range(self.nstage)]) 96 csjl = dt*self.cjl(bsjl) 97 cfjl = dt*self.cjl(bfjl) 98 self.csjl, self.cfjl = [x.astype(precision) for x in csjl, cfjl] 99 self.tauj = np.array([dt*bfjl[j,j] for j in range(self.nstage)], dtype=precision) 100 print 'Types of csjl, cfjl, tauj :', self.csjl.dtype, self.cfjl.dtype, self.tauj.dtype 93 101 def next(self,zj): 94 102 csjl, cfjl, tauj = self.csjl, self.cfjl, self.tauj … … 100 108 for l in range(0,j+1): # here zj is initially y(j) and finally z(j+1) 101 109 zj = [z + csjl[j,l]*s + cfjl[j,l]*f for z,s,f in zip(zj, slowj[l], fastj[l]) ] 110 # print 'SIRK : zj has type ', [ z.dtype for z in zj] 102 111 return zj 103 112 def advance(self, flow, N): … … 113 122 return SIRK(bwd_fast_slow,dt,1,bsjl,bfjl) 114 123 115 def ARK2(bwd_fast_slow, dt, a32 = (3.+2.*np.sqrt(2.))/6.):124 def ARK2(bwd_fast_slow, dt, precision=None, a32 = (3.+2.*np.sqrt(2.))/6.): 116 125 """ ARK2 scheme by Giraldo et al. (2013), noted ARK2(2,3,2) in Weller et al. (2013) """ 117 126 gamma = 1.-1./np.sqrt(2.) … … 120 129 bsjl = np.array([[0,0,0],[2.*gamma,0,0],[1.-a32,a32,0],wj]) 121 130 bfjl = np.array([[0,0,0],[gamma,gamma,0],[delta,delta,gamma],wj]) 122 return SIRK( bwd_fast_slow,dt,3,bsjl,bfjl)131 return SIRK(precision,bwd_fast_slow,dt,3,bsjl,bfjl) 123 132 124 133 def UJ3(bwd_fast_slow, dt): … … 135 144 ######### Explicit RK schemes written as ARK with two identical Butcher tableaus ######## 136 145 137 def RK4(bwd_fast_slow, dt ):146 def RK4(bwd_fast_slow, dt, precision=None): 138 147 """ 4-stage 4th-order RK """ 139 148 bjl = np.array([[0,0,0,0], … … 142 151 [0.,0.,1.,0], 143 152 [1/6.,1/3.,1/3.,1/6.]]) 144 return SIRK( bwd_fast_slow,dt,4,bjl,bjl)153 return SIRK(precision, bwd_fast_slow,dt,4,bjl,bjl) 145 154 146 155 ######### Simplified explicit RK schemes (2nd-order) ######## -
codes/icosagcm/devel/Python/dynamico/wrap.py
r663 r747 11 11 # defines converter functions depending on type of Python argument 12 12 def noop(x): return x 13 py2c = { np.ndarray:loc, np.float64:c_double, float:c_double, int:c_int,13 py2c = { np.ndarray:loc, np.float64:c_double, np.float32:c_float, int:c_int, 14 14 c_void_p:noop, str:noop, c_int:noop } 15 15 -
codes/icosagcm/devel/Python/src/unstructured.pyx
r746 r747 239 239 # h*s = h => uniform buoyancy s=1 => shallow-water 240 240 dh, du_slow, du_fast, hs, buf = self.fmass(), self.fu(), self.fu(), h.copy(), self.geopot 241 assert type(tau) is np_num, 'tau must be of type unstructured.np_num.' 241 242 ker.dynamico_caldyn_unstructured(tau, self.ms, h, hs, u, self.geopot, buf, 242 243 self.s, self.ps, self.pk, self.hflux, self.qv, … … 296 297 left,right,down,up,trisk_deg,trisk, 297 298 Ai, Av, fv, le_de, Riv2, wee): 299 300 print 'Types of Ai, Av, fv, le_de, Riv2, wee : ', Ai.dtype,Av.dtype,fv.dtype,le_de.dtype,Riv2.dtype,wee.dtype 301 for var,varname in zip((Ai,Av,fv,le_de,Riv2,wee), ('Ai','Av','fv','le_de','Riv2','wee')): 302 assert var.dtype == np.float64, '%s must be double precision'%varname 303 298 304 setvars( ('llm','nqdyn','edge_num','primal_num','dual_num', 299 305 'max_trisk_deg','max_primal_deg','max_dual_deg'), -
codes/icosagcm/devel/Python/test/py/DCMIP2008c5.py
r687 r747 136 136 plt.savefig('fig_DCMIP2008c5/Ai.png'); plt.close() 137 137 138 139 if False: # time stepping in Python 138 if False: # time stepping in Python => set precision to np_num 140 139 caldyn = unst.Caldyn_HPE(caldyn_thermo,caldyn_eta, mesh,thermo,params,params.g) 141 scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, a32=0.7)140 scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num, a32=0.7) 142 141 def next_flow(m,S,u): 143 142 m,S,u = scheme.advance((m,S,u),nt) … … 179 178 z, vol = mesh.field_mass(), mesh.field_mass() 180 179 m,S,u,Phi,W = flow0 180 181 print 'types of m,S,u :', m.dtype, S.dtype, u.dtype 182 181 183 caldyn_step.geopot[:,0]=Phi[:,0] 182 184 plots(0) -
codes/icosagcm/devel/Python/test/py/NH_3D_bubble.py
r656 r747 4 4 from dynamico import DCMIP 5 5 from dynamico import meshes 6 from dynamico import precision as prec 6 7 from dynamico.meshes import Cartesian_mesh as Mesh 7 8 import math as math … … 51 52 params.rho_bot = 1e6/gas_bot.v 52 53 53 return thermo, mesh, params, (mass_ik,Sik,ujk,Phi_il,Wil), gas54 return thermo, mesh, params, prec.asnum([mass_ik,Sik,ujk,Phi_il,Wil]), gas 54 55 55 56 #Lx, nx, llm, thetac, T, Nslice, courant = 2000., 100, 50, 30., 5., 10, 2.8 … … 63 64 # compute hybrid coefs from initial distribution of mass 64 65 mass_bl,mass_dak,mass_dbk = meshes.compute_hybrid_coefs(flow0[0]) 66 print 'Type of mass_bl, mass_dak, mass_dbk : ', [x.dtype for x in mass_bl, mass_dak, mass_dbk] 65 67 unst.ker.dynamico_init_hybrid(mass_bl,mass_dak,mass_dbk) 66 68 -
codes/icosagcm/devel/Python/test/py/RSW_2D.py
r632 r747 18 18 19 19 x1,x2,yy = mesh.xx[:,:,0]-1., mesh.xx[:,:,0]+1., mesh.yy[:,:,0] 20 h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 20 h0, u0 = mesh.field_mass(), mesh.field_u() # flow initally at rest 21 h0[:] = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 21 22 np.exp(-2.*(x2*x2+yy*yy))) 22 u0 = mesh.field_u() # flow initally at rest23 23 flow0=(h0,u0) 24 24 … … 32 32 scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt) 33 33 34 print 'types : yy, u0, h0, u0', yy.dtype, u0.dtype, h0.dtype, u0.dtype 35 34 36 flow=flow0 35 37 for i in range(10): 36 38 h,u=flow 39 print 'types : h,u', h.dtype, u.dtype 37 40 caldyn.bwd_fast_slow(flow, 0.) 38 41 plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv) … … 48 51 unst.elapsed=0. 49 52 flow = scheme.advance(flow,N) 53 h,u=flow 54 print 'types : h,u', h.dtype, u.dtype 50 55 # flops 51 56 # mass flux : 1add+1mul per edge => 4 -
codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py
r719 r747 45 45 dx,dy=Lx/nx,Ly/ny 46 46 47 filename, llm, nqdyn, g, f, radius = 'cart128.nc', 1, 1, 1., 1., 1.47 filename, llm, nqdyn, g, f, radius = 'cart128.nc', 1, 1, 1., 1., None 48 48 unst.setvar('g',g) 49 49 … … 64 64 65 65 x1,x2,yy = xx-1., xx+1., yy 66 u0 = mesh.field_u() # flow initally at rest 66 67 h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 67 68 np.exp(-2.*(x2*x2+yy*yy))) 68 u0 = mesh.field_u() # flow initally at rest 69 flow0=(h0,u0) 69 flow0=meshes.asnum([h0,u0]) 70 70 71 71 #print('h0 : ', h0[1234]-1.) … … 79 79 dt=T/N 80 80 print N,dt,Lx/nx 81 scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt) 81 #scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 82 scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 82 83 83 84 flow=flow0 … … 90 91 for i in range(10): 91 92 h,u=flow 92 flow, fast, slow = caldyn.bwd_fast_slow(flow, 0.)93 flow, fast, slow = caldyn.bwd_fast_slow(flow, unst.zero_num) 93 94 junk, du_fast = fast 94 95 dh, du_slow = slow … … 102 103 plt.figure(); plt.pcolor(x,y,reshape(caldyn.qv)) 103 104 plt.colorbar(); plt.title('potential vorticity') 104 plt.savefig('fig_RSW_2D_mesh/%02d.png'%i) 105 plt.savefig('fig_RSW_2D_mesh/%03d.png'%i) 106 plt.close() 105 107 # plt.figure(); plt.pcolor(mesh.x,mesh.y,h) 106 108 # plt.colorbar(); plt.title('h') … … 112 114 unst.elapsed=0. 113 115 flow = scheme.advance(flow,N) 116 # flow = scheme.advance(flow,5) 114 117 # flops 115 118 # mass flux : 1add+1mul per edge => 4 -
codes/icosagcm/devel/Python/test/py/RSW_MPAS_W02.py
r680 r747 1 1 print 'Loading DYNAMICO modules ...' 2 2 from dynamico import unstructured as unst 3 from dynamico.precision import asnum 3 4 from dynamico.meshes import MPAS_Format, Unstructured_Mesh 4 5 from dynamico import time_step … … 34 35 dt = T/nt 35 36 #scheme = time_step.RKn_simple(1,caldyn.bwd_fast_slow, dt) 36 scheme = time_step.RK4(caldyn.bwd_fast_slow, dt )37 scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num) 37 38 38 39 print dx, dt, dt*c0/dx … … 61 62 fu_perp = mesh.ucov2D(0.*ulon,2*Omega*np.sin(mesh.lat_e)*ulon) 62 63 63 flow = (Phi0,mesh.ucov2D(ulon,0.*ulon)) 64 flow = asnum([Phi0, mesh.ucov2D(ulon,0.*ulon)]) 65 print 'type of Phi0,u0 : ', flow[0].dtype, flow[1].dtype 66 64 67 for i in range(N): 65 68 h,u=flow -
codes/icosagcm/devel/Python/test/py/bubble.py
r631 r747 1 import math as math2 import numpy as np3 import matplotlib.pyplot as plt4 import matplotlib.animation as manimation5 6 1 from dynamico.meshes import Cartesian_mesh as Mesh 7 2 import dynamico.dyn as dyn … … 10 5 import dynamico.advect as advect 11 6 from dynamico import unstructured as unst 7 8 import math as math 9 import numpy as np 10 import matplotlib.pyplot as plt 11 import matplotlib.animation as manimation 12 12 13 13 14 def reldiff(a,b): -
codes/icosagcm/devel/Python/test/py/slice_GW_NH.py
r666 r747 29 29 30 30 u0=mesh.field_u() 31 u0[ :,range(0,2*nx,2),:] = u*mesh.dx # Doppler shift by u31 u0[range(0,2*nx,2),:] = u*mesh.dx # Doppler shift by u 32 32 flow0=(m0ik,S0ik,u0,Phi0_il,0*Phi0_il) 33 33 … … 81 81 plt.figure(figsize=(12,3)) 82 82 ucomp = mesh.ucomp(u) 83 plt.pcolor(xx,zz,ucomp[ 0,:,:]/dx)83 plt.pcolor(xx,zz,ucomp[:,:]/dx) 84 84 plt_axes() 85 85 plt.title("u(t = %f s)" % ((i+1)*dt*nt)) -
codes/icosagcm/devel/Python/test/py/slice_GW_hydro.py
r656 r747 23 23 24 24 u0=mesh.field_u() 25 u0[ :,range(0,2*nx,2),:] = 100.*mesh.dx # Doppler shift 100 m/s25 u0[range(0,2*nx,2),:] = 100.*mesh.dx # Doppler shift 100 m/s 26 26 flow0=(m0ik,S0ik,u0) 27 27 … … 60 60 plt.figure(figsize=(12,3)) 61 61 ucomp = mesh.ucomp(u) 62 plt.pcolor(xx,zz,ucomp[ 0,:,:]/dx)62 plt.pcolor(xx,zz,ucomp[:,:]/dx) 63 63 plt.ylim(0,10.) 64 64 plt.colorbar() -
codes/icosagcm/devel/make_icosa
r744 r747 227 227 ./build --job $job 228 228 fi 229 230 # force recompilation of cython modules 231 touch Python/src/*.pyx -
codes/icosagcm/devel/make_python
r721 r747 32 32 update "$x" "$DYNAMICO_ROOT/src/$2/$x" 33 33 done 34 34 35 } 35 36 36 37 function cmd_kernels() # this function is invoked by : './make_python kernels' 37 38 { 39 cmd_clean 38 40 cd $KERNELS 39 41 ./codegen hexagonal hex_master unstructured -
codes/icosagcm/devel/src/unstructured/data_unstructured.F90
r744 r747 205 205 Riv2(:,:)=Riv2_(:,:) 206 206 wee(:,:) = wee_(:,:) 207 PRINT *, MAXVAL(ABS(Ai))208 PRINT *, MAXVAL(ABS(Av))209 PRINT *, MAXVAL(ABS(fv))210 PRINT *, MAXVAL(ABS(le_de))211 PRINT *, MAXVAL(ABS(Riv2))212 PRINT *, MAXVAL(ABS(wee))213 PRINT *, MINVAL(right), MAXVAL(right)214 PRINT *, MINVAL(right), MAXVAL(left)207 PRINT *, 'Max Ai : ', MAXVAL(ABS(Ai)) 208 PRINT *, 'Max Av : ', MAXVAL(ABS(Av)) 209 PRINT *, 'Max fv : ', MAXVAL(ABS(fv)) 210 PRINT *, 'Max le_de : ', MAXVAL(ABS(le_de)) 211 PRINT *, 'Max Riv2 : ', MAXVAL(ABS(Riv2)) 212 PRINT *, 'Max wee : ', MAXVAL(ABS(wee)) 213 PRINT *, MINVAL(right), MAXVAL(right) 214 PRINT *, MINVAL(right), MAXVAL(left) 215 215 PRINT *,' ... Done.' 216 216 IF(nb_threads==0) nb_threads=OMP_GET_MAX_THREADS()
Note: See TracChangeset
for help on using the changeset viewer.