Changeset 756 for codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py
- Timestamp:
- 10/09/18 14:28:53 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py
r747 r756 2 2 from dynamico import unstructured as unst 3 3 from dynamico import time_step 4 from dynamico import precision as prec 4 5 5 6 import math as math … … 7 8 import numpy as np 8 9 import netCDF4 as cdf 9 10 class DYNAMICO_Format(meshes.Mesh_Format):11 """ Netcdf input file handling.12 Creates a dictionary of names corresponding to original data file."""13 14 start_index=1 # indexing starts at 1 as in Fortran15 translate = { 'down_up':'edge_down_up', 'left_right':'edge_left_right' } #new name is edge_left_right16 17 def __init__(self,gridfilename):18 try:19 self.nc = cdf.Dataset(gridfilename, "r")20 print('#NC4: Opening file:',gridfilename)21 except RuntimeError:22 print """ Unable to open grid file %s, maybe you forgot to download it ?23 To do so, go to the 'Python/' dir and execute './get_MPAS_grids.sh'.24 """ % gridfile25 raise26 def get_pdim(self,comm,name):27 if name in self.translate: name = self.translate[name]28 return parallel.PDim(self.nc.dimensions[name], comm)29 def getvar(self,name):30 if name in self.translate: name = self.translate[name]31 return self.nc.variables[name][:]32 def get_pvar(self,pdim,name):33 # provides parallel access to a NetCDF variable, with name translation34 # first deal with special cases35 if name == 'edge_deg': return parallel.CstPArray1D(pdim, np.int32, 2)36 # general case37 if name in self.translate: name = self.translate[name]38 return parallel.PArray(pdim, self.nc.variables[name])39 def normalize(self, mesh, radius): pass40 10 41 11 #--------------------------------- Main program ----------------------------- … … 45 15 dx,dy=Lx/nx,Ly/ny 46 16 47 filename, llm, nqdyn, g, f, radius = 'cart 128.nc', 1, 1, 1., 1., None17 filename, llm, nqdyn, g, f, radius = 'cart_128.nc', 1, 1, 1., 1., None 48 18 unst.setvar('g',g) 49 19 50 20 print 'Reading Cartesian mesh ...' 51 meshfile = DYNAMICO_Format(filename) 52 #print("#NC4: check point: 0") 53 #print(meshfile) 21 meshfile = meshes.DYNAMICO_Format(filename) 54 22 55 23 def coriolis(lon,lat): … … 58 26 mesh=meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, coriolis) 59 27 caldyn = unst.Caldyn_RSW(mesh) 60 #print(caldyn.__dict__.keys())61 28 62 29 xx = (mesh.lat_i-nx/2.)*dx … … 67 34 h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+ 68 35 np.exp(-2.*(x2*x2+yy*yy))) 69 flow0=meshes.asnum([h0,u0]) 70 71 #print('h0 : ', h0[1234]-1.) 72 #print('h0 : ', h0[2345]-1.) 36 flow0=prec.asnum([h0,u0]) 73 37 74 38 cfl = .8 … … 91 55 for i in range(10): 92 56 h,u=flow 93 flow, fast, slow = caldyn.bwd_fast_slow(flow, unst.zero_num)57 flow, fast, slow = caldyn.bwd_fast_slow(flow, prec.zero) 94 58 junk, du_fast = fast 95 59 dh, du_slow = slow
Note: See TracChangeset
for help on using the changeset viewer.