- Timestamp:
- 01/16/19 15:27:39 (5 years ago)
- Location:
- codes/icosagcm/devel/Python
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/dynamico/meshes.py
r799 r800 315 315 # general case 316 316 return parallel.PArray(pdim, self.nc.variables[name]) 317 def normalize(self, mesh , radius): pass317 def normalize(self, mesh): pass 318 318 319 319 #---------------------- MPAS fully unstructured mesh ------------------------ … … 364 364 name=self.translate[name] 365 365 return parallel.PArray(pdim, self.nc.variables[name]) 366 def normalize(self, mesh , radius):366 def normalize(self, mesh): 367 367 (trisk_deg, trisk, Ai, 368 368 de, le, wee, Av, Riv2) = (mesh.trisk_deg, mesh.trisk, mesh.Ai, 369 369 mesh.de, mesh.le, mesh.wee, mesh.Av, mesh.Riv2) 370 edge_num, dual_num , r2 = de.size, Av.size, radius**2370 edge_num, dual_num = de.size, Av.size 371 371 # fix normalization of wee and Riv2 weights 372 372 for edge1 in range(edge_num): … … 381 381 if abs(r-1.)>1e-6 : print 'error with Riv2 at vertex ', ivertex 382 382 # scale lengths and areas 383 mesh.le, mesh.de, mesh.Av, mesh.Ai = radius*le, radius*de, r2*Av, r2*Ai 383 # this is now done by apply_map_factor 384 # mesh.le, mesh.de, mesh.Av, mesh.Ai = radius*le, radius*de, r2*Av, r2*Ai 384 385 385 386 def compute_ne(num,deg,edges,left,right): … … 421 422 def plot_e(self,data, **kwargs): 422 423 self.plot(self.triedge,data, **kwargs) 424 def apply_map(self, mapping, le, de, Ai, Av): 425 """Before calling apply_map, lat and lon are coordinates in the reference domain. 426 After calling apply_map, lat and lon are coordinates in the physical domain.""" 427 factor_e = mapping.map_factor(self.lon_e, self.lat_e) 428 factor_i = mapping.map_factor(self.lon_i, self.lat_i)**2 429 factor_v = mapping.map_factor(self.lon_v, self.lat_v)**2 430 self.le, self.de, self.Av, self.Ai = factor_e*le, factor_e*de, Av*factor_v, Ai*factor_i 431 self.lon_i, self.lat_i = mapping.map(self.lon_i, self.lat_i) 432 self.lon_v, self.lat_v = mapping.map(self.lon_v, self.lat_v) 433 self.lon_e, self.lat_e = mapping.map(self.lon_e, self.lat_e) 423 434 424 435 class Unstructured_Mesh(Abstract_Mesh): … … 452 463 'Ai', 'Av', 'fv', 'le', 'de', 453 464 'trisk_deg', 'trisk', 'wee', 'Riv2', 'dual_ne') 454 gridfile.normalize(self , radius)465 gridfile.normalize(self) 455 466 max_primal_deg, max_dual_deg, max_trisk_deg = [ x.shape[1] for x in primal_edge, dual_edge, trisk] 456 467 unst.init_mesh(llm, nqdyn, edge_num, primal_num,dual_num, … … 542 553 543 554 class Local_Mesh(Abstract_Mesh): 544 def __init__(self, pmesh, llm, nqdyn, radius, f):555 def __init__(self, pmesh, llm, nqdyn, mapping): 545 556 comm, dim_primal, primal_owner, dim_edge, edge_owner, dim_dual, dual_owner = pmesh.members( 546 557 'comm', 'dim_primal', 'primal_owner', 'dim_edge', 'edge_owner', 'dim_dual', 'dual_owner' ) … … 554 565 get_own_cells, get_all_cells = dim_primal.getter(cells_C0), dim_primal.getter(cells_C1) 555 566 get_all_duals, get_all_edges = dim_dual.getter(vertices_V1), dim_edge.getter(edges_E2) 556 557 self.lon_i, self.lat_i, self.Ai = pmesh.get(get_all_cells, 'lon_i', 'lat_i', 'Ai')558 self.lon_ v, self.lat_v, self.Av = pmesh.get(get_all_duals, 'lon_v', 'lat_v', 'Av')559 self. fv = f(self.lon_v,self.lat_v) # Coriolis parameter560 self.le, self.de, self.lon_e, self.lat_e, self.angle_e = pmesh.get(567 568 # read from mesh file coordinates in reference domain 569 self.lon_i, self.lat_i, Ai = pmesh.get(get_all_cells, 'lon_i', 'lat_i', 'Ai') 570 self.lon_v, self.lat_v, Av = pmesh.get(get_all_duals, 'lon_v', 'lat_v', 'Av') 571 le, de, self.lon_e, self.lat_e, self.angle_e = pmesh.get( 561 572 get_all_edges, 'le', 'de', 'lon_e', 'lat_e', 'angle_e') 573 # map from reference domain to physical domain 574 self.apply_map(mapping, le, de, Ai, Av) 575 # now latitudes and longitudes refer to the physical domain 576 self.fv = mapping.coriolis(self.lon_v,self.lat_v) # Coriolis parameter 562 577 primal_num, dual_num, edge_num = map(len, (cells_C1, vertices_V1, edges_E2)) 563 578 … … 567 582 self.primal_i, self.primal_j = pmesh.get(get_all_cells, 'primal_i', 'primal_j') 568 583 self.dual_i, self.dual_j = pmesh.get(get_all_duals, 'dual_i', 'dual_j') 569 570 584 571 585 # construct local stencils from global stencils … … 624 638 625 639 # normalize and propagate info to Fortran side 626 pmesh.gridfile.normalize(self ,radius)640 pmesh.gridfile.normalize(self) 627 641 unst.init_mesh(llm, nqdyn, self.edge_num, self.primal_num, self.dual_num, 628 642 max_trisk_deg, max_primal_deg, max_dual_deg, -
codes/icosagcm/devel/Python/test/py/Baroclinic_3D_ullrich.py
r797 r800 34 34 from dynamico import DCMIP 35 35 from dynamico import meshes 36 from dynamico import maps 36 37 from dynamico import xios 37 38 from dynamico import precision as prec … … 55 56 return pmesh 56 57 57 def baroclinic_3D(pmesh, Lx,Ly,llm,ztop):58 def baroclinic_3D(pmesh, dx,Lx,Ly,llm,ztop): 58 59 Rd = 287.0 # Gas constant for dryy air (j kg^-1 K^-1) 59 60 T0 = 288.0 # Reference temperature (K) … … 90 91 91 92 def eta(alpha) : return (1.-(lap*ztop*alpha/T0))**(g/(Rd*lap)) # roughly equispaced levels 92 def coriolis(x,y): return f0+beta0*y # here y is 0 at domain center93 94 nqdyn , radius = 1, None95 mesh = meshes.Local_Mesh(pmesh, llm, nqdyn, radius, coriolis)93 94 betaplane = maps.BetaPlaneMap(dx, .5*Lx, .5*Ly, f0, beta0, .5*Ly) 95 nqdyn = 1 96 mesh = meshes.Local_Mesh(pmesh, llm, nqdyn, betaplane) 96 97 97 98 alpha_k = (np.arange(llm) +.5)/llm 98 99 alpha_l = (np.arange(llm+1)+ 0.)/llm 99 x_ik, alpha_ik = np.meshgrid(mesh.lon_i, 100 y_ik, alpha_ik = np.meshgrid(mesh.lat_i +y0, alpha_k, indexing='ij')101 x_il, alpha_il = np.meshgrid(mesh.lon_i, 102 y_il, alpha_il = np.meshgrid(mesh.lat_i +y0, alpha_l, indexing='ij')103 x_ek, alpha_ek = np.meshgrid(mesh.lon_e, 104 y_ek, alpha_ek = np.meshgrid(mesh.lat_e +y0, alpha_k, indexing='ij')100 x_ik, alpha_ik = np.meshgrid(mesh.lon_i, alpha_k, indexing='ij') 101 y_ik, alpha_ik = np.meshgrid(mesh.lat_i, alpha_k, indexing='ij') 102 x_il, alpha_il = np.meshgrid(mesh.lon_i, alpha_l, indexing='ij') 103 y_il, alpha_il = np.meshgrid(mesh.lat_i, alpha_l, indexing='ij') 104 x_ek, alpha_ek = np.meshgrid(mesh.lon_e, alpha_k, indexing='ij') 105 y_ek, alpha_ek = np.meshgrid(mesh.lat_e, alpha_k, indexing='ij') 105 106 106 107 print(np.shape(alpha_k),np.shape(alpha_l)) … … 166 167 class myDavies(Davies): 167 168 def mask(self,x,y): 168 logging.debug('davies dy = %f'% d y)169 return self.mask0(y, .5*Ly,dy)*self.mask0(-y,.5*Ly,dy)169 logging.debug('davies dy = %f'% dx) 170 return self.mask0(y,Ly,dx)*self.mask0(-y,0.,dx) 170 171 171 172 with xios.Client() as client: # setup XIOS which creates the DYNAMICO communicator … … 178 179 nx, ny, llm = args.nx, args.ny, args.llm 179 180 dx = Lx/nx 180 dy = dx 181 182 if True: # physical domain excludes relaxation zone 183 Dy = Ly + dy*2*(args.Davies_N1+args.Davies_N2) 184 print('Dy=%f, Ly = %f'%(Dy,Ly)) 185 else: # physical domain includes relaxation zone 186 Dy=Ly 187 # print('WARNING: Davies_N1 not equal to Davies_N2; average value will be used') 188 181 189 182 unst.setvar('g',g) 190 183 191 184 pmesh = create_pmesh(nx,ny) 192 thermo, mesh, params, flow0, gas0 = baroclinic_3D(pmesh, Lx,Ly,llm, args.ztop)185 thermo, mesh, params, flow0, gas0 = baroclinic_3D(pmesh, dx,Lx,Ly,llm, args.ztop) 193 186 194 187 mass_bl,mass_dak,mass_dbk = meshes.compute_hybrid_coefs(flow0[0]) … … 281 274 # context.send_field_primal('p', drhodz) 282 275 283 context.send_field_primal('theta', gas.s) 276 context.send_field_primal('theta', thermo.T0*exp(gas.s/thermo.Cpd)) 277 284 278 context.send_field_primal('uz', w) 285 279 context.send_field_primal('z', z)
Note: See TracChangeset
for help on using the changeset viewer.