Changeset 680 for codes/icosagcm/devel/Python/test
- Timestamp:
- 02/09/18 16:24:33 (6 years ago)
- Location:
- codes/icosagcm/devel/Python/test/py
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/test/py/DCMIP2008c5.py
r679 r680 4 4 from dynamico import DCMIP 5 5 from dynamico import meshes 6 from dynamico.meshes import MPAS_Mesh as Mesh7 6 import math as math 8 7 import matplotlib.pyplot as plt … … 45 44 nqdyn, preff, Treff = 1, 1e5, 300. 46 45 thermo = dyn.Ideal_perfect(Cpd, Rd, preff, Treff) 47 mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f) 46 meshfile = meshes.MPAS_Format('grids/x1.%d.grid.nc'%grid) 47 mesh = meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 48 48 lev,levp1 = np.arange(llm),np.arange(llm+1) 49 49 lon_i, lat_i, lon_e, lat_e = mesh.lon_i, mesh.lat_i, mesh.lon_e, mesh.lat_e -
codes/icosagcm/devel/Python/test/py/NH_3D_DCMIP31.py
r678 r680 4 4 from dynamico import DCMIP 5 5 from dynamico import meshes 6 from dynamico.meshes import MPAS_Mesh as Mesh7 6 import math as math 8 7 import matplotlib.pyplot as plt … … 49 48 nqdyn, preff, Treff = 1, 1e5, 300. 50 49 thermo = dyn.Ideal_perfect(Cpd, Rd, preff, Treff) 51 mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f) 50 meshfile = meshes.MPAS_Format('grids/x1.%d.grid.nc'%grid) 51 mesh = meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 52 52 lev,levp1 = np.arange(llm),np.arange(llm+1) 53 53 lat_ik,k_i = np.meshgrid(mesh.lat_i,lev, indexing='ij') -
codes/icosagcm/devel/Python/test/py/RSW2_MPAS_W02.py
r666 r680 1 1 print 'Loading DYNAMICO modules ...' 2 2 from dynamico import unstructured as unst 3 from dynamico.meshes import MPAS_ Mesh as Mesh3 from dynamico.meshes import MPAS_Format, Unstructured_Mesh as Mesh 4 4 from dynamico import time_step 5 5 print '...Done' … … 19 19 def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter 20 20 print 'Reading MPAS mesh ...' 21 mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f) 21 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 22 mesh = Mesh(meshfile, llm, nqdyn, radius, f) 22 23 print '...Done' 23 24 lon, lat = mesh.lon_i, mesh.lat_i -
codes/icosagcm/devel/Python/test/py/RSW_MPAS_W02.py
r672 r680 1 1 print 'Loading DYNAMICO modules ...' 2 2 from dynamico import unstructured as unst 3 from dynamico.meshes import MPAS_ Mesh asMesh3 from dynamico.meshes import MPAS_Format, Unstructured_Mesh 4 4 from dynamico import time_step 5 5 print '...Done' … … 19 19 def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter 20 20 print 'Reading MPAS mesh ...' 21 mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f) 21 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 22 mesh=Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 22 23 print '...Done' 23 24 lon, lat = mesh.lon_i, mesh.lat_i -
codes/icosagcm/devel/Python/test/py/partition.py
r672 r680 57 57 # Helper functions to plot unstructured graph 58 58 59 def patches(degree, bounds, lon, lat):60 for i in range(degree.size):61 nb_edge=degree[i]62 bounds_cell = bounds[i,0:nb_edge]63 lat_cell = lat[bounds_cell]64 lon_cell = lon[bounds_cell]65 orig=lon_cell[0]66 lon_cell = lon_cell-orig+180.67 lon_cell = np.mod(lon_cell,360.)68 lon_cell = lon_cell+orig-180.69 # if np.abs(lon_cell-orig).max()>10. :70 # print '%d patches :'%mpi_rank, lon_cell71 lonlat_cell = np.zeros((nb_edge,2))72 lonlat_cell[:,0],lonlat_cell[:,1] = lon_cell,lat_cell73 polygon = Polygon(lonlat_cell, True)74 yield polygon75 76 def plot_mesh(ax, clim, degree, bounds, lon, lat, data):77 nb_vertex = lon.size # global78 p = list(patches(degree, bounds, lon, lat))79 print '%d : plot_mesh %d %d %d'%( mpi_rank, degree.size, len(p), len(data) )80 p = PatchCollection(p, linewidth=0.01)81 p.set_array(data) # set values at each polygon (cell)82 p.set_clim(clim)83 ax.add_collection(p)84 85 59 def local_mesh(get_mycells): 86 mydegree, mybounds = [get_mycells(x) for x in nEdgesOnCell, verticesOnCell] 60 # mydegree, mybounds = [get_mycells(x) for x in nEdgesOnCell, verticesOnCell] 61 mydegree, mybounds = [get_mycells(x) for x in primal_deg, primal_vertex] 87 62 print '%d : len(mydegree)=%d'%(mpi_rank, len(mydegree)) 88 63 vertex_list = sorted(set(unst.list_stencil(mydegree,mybounds))) … … 94 69 return vertex_list, mydegree, mybounds, mylon, mylat 95 70 71 def members(struct, *names): return [struct.__dict__ [name] for name in names] 72 96 73 #--------------- read MPAS grid file ---------------# 97 74 98 #grid = 'x1.2562'99 grid = 'x1.10242'75 grid = 'x1.2562' 76 #grid = 'x1.10242' 100 77 #grid = 'x4.163842' 101 78 print 'Reading MPAS file %s ...'%grid 102 79 103 nc = cdf.Dataset('grids/%s.grid.nc'%grid, "r") 104 dim_cell, dim_edge, dim_vertex = [ 105 parallel.PDim(nc.dimensions[name], comm) 106 for name in 'nCells','nEdges','nVertices'] 107 edge_degree = parallel.CstPArray1D(dim_edge, np.int32, 2) 108 vertex_degree = parallel.CstPArray1D(dim_vertex, np.int32, 3) 109 nEdgesOnCell, verticesOnCell, edgesOnCell, cellsOnCell, latCell = [ 110 parallel.PArray(dim_cell, nc.variables[var]) 111 for var in 'nEdgesOnCell', 'verticesOnCell', 'edgesOnCell', 'cellsOnCell', 'latCell' ] 112 cellsOnVertex, edgesOnVertex, kiteAreasOnVertex, lonVertex, latVertex = [ 113 parallel.PArray(dim_vertex, nc.variables[var]) 114 for var in 'cellsOnVertex', 'edgesOnVertex', 'kiteAreasOnVertex', 'lonVertex', 'latVertex'] 115 nEdgesOnEdge, cellsOnEdge, edgesOnEdge, verticesOnEdge, weightsOnEdge = [ 116 parallel.PArray(dim_edge, nc.variables[var]) 117 for var in 'nEdgesOnEdge', 'cellsOnEdge', 'edgesOnEdge', 'verticesOnEdge', 'weightsOnEdge'] 80 meshfile = meshes.MPAS_Format('grids/%s.grid.nc'%grid) 81 pmesh = meshes.Unstructured_PMesh(comm, meshfile) 82 lmesh = meshes.Local_Mesh(pmesh) 118 83 119 # Indices start at 0 on the C/Python side and at 1 on the Fortran/MPAS side 120 # hence an offset of 1 is added/substracted where needed. 121 for x in (verticesOnCell, edgesOnCell, cellsOnCell, cellsOnVertex, edgesOnVertex, 122 cellsOnEdge, edgesOnEdge, verticesOnEdge) : x.data = x.data-1 123 edge2cell, cell2edge, edge2vertex, vertex2edge, cell2cell, edge2edge = [ 124 meshes.Stencil_glob(a,b) for a,b in 125 (edge_degree, cellsOnEdge), (nEdgesOnCell, edgesOnCell), 126 (edge_degree, verticesOnEdge), (vertex_degree, edgesOnVertex), 127 (nEdgesOnCell, cellsOnCell), (nEdgesOnEdge, edgesOnEdge) ] 84 (primal_deg, primal_vertex, dim_vertex, dim_cell, cell_owner, 85 lonVertex, latVertex, lonCell, latCell) = members( 86 pmesh, 'primal_deg', 'primal_vertex', 'dim_dual', 'dim_primal', 'primal_owner', 87 'lon_v', 'lat_v', 'lon_i', 'lat_i') 128 88 129 #---------------- partition edges and cells ------------------# 130 131 print 'Partitioning ...' 132 133 edge_owner = unst.partition_mesh(nEdgesOnEdge, edgesOnEdge, mpi_size) 134 edge_owner = parallel.LocPArray1D(dim_edge, edge_owner) 135 cell_owner = meshes.partition_from_stencil(edge_owner, nEdgesOnCell, edgesOnCell) 136 cell_owner = parallel.LocPArray1D(dim_cell, cell_owner) 137 138 #--------------------- construct halos -----------------------# 139 140 print 'Constructing halos ...' 141 142 def chain(start, links): 143 for link in links: 144 start = link(start).neigh_set 145 yield start 146 147 edges_E0 = meshes.find_my_cells(edge_owner) 148 cells_C0, edges_E1, vertices_V1, edges_E2, cells_C1 = chain( 149 edges_E0, ( edge2cell, cell2edge, edge2vertex, vertex2edge, edge2cell) ) 150 151 edges_E0, edges_E1, edges_E2 = meshes.progressive_list(edges_E0, edges_E1, edges_E2) 152 cells_C0, cells_C1 = meshes.progressive_list(cells_C0, cells_C1) 153 154 print 'E2,E1,E0 ; C1,C0 : ', map(len, (edges_E2, edges_E1, edges_E0, cells_C1, cells_C0)) 155 156 #com_edges = parallel.Halo_Xchange(24, dim_edge, edges_E2, dim_edge.get(edges_E2, edge_owner)) 157 158 mycells, halo_cells = cells_C0, cells_C1 159 get_mycells, get_halo_cells = dim_cell.getter(mycells), dim_cell.getter(halo_cells) 160 com_cells = parallel.Halo_Xchange(42, dim_cell, halo_cells, get_halo_cells(cell_owner)) 161 162 local_num, total_num = np.zeros(1), np.zeros(1) 89 local_num, total_num, com_cells = np.zeros(1), np.zeros(1), lmesh.com_primal 163 90 local_num[0]=com_cells.own_len 164 91 comm.Reduce(local_num, total_num, op=MPI.SUM, root=0) … … 167 94 #---------------------------- plot -----------------------------# 168 95 169 if True: 170 print 'Plotting ...' 96 print 'Plotting ...' 171 97 172 173 98 halo_vertex_list, mydegree, mybounds, mylon, mylat = local_mesh(com_cells.get_all) 99 buf = parallel.LocalArray1(com_cells) 174 100 175 176 177 178 179 plot_mesh(ax,[-math.pi/2,math.pi/2], mydegree, mybounds, mylon, mylat, buf.data)180 181 182 101 fig, ax = plt.subplots() 102 buf.read_own(latCell) # reads only own values 103 buf.data = np.cos(10.*buf.data) 104 buf.update() # updates halo 105 lmesh.plot(ax,[-math.pi/2,math.pi/2], mydegree, mybounds, mylon, mylat, buf.data) 106 plt.xlim(-190.,190.) 107 plt.ylim(-90.,90.) 108 plt.savefig('fig_partition/A%03d.pdf'%mpi_rank, dpi=1600) 183 109 184 185 186 187 plot_mesh(ax,[0,mpi_rank+1], mydegree, mybounds, mylon, mylat, buf.data)188 189 190 110 fig, ax = plt.subplots() 111 buf.read_own(cell_owner) 112 buf.update() 113 lmesh.plot(ax,[0,mpi_rank+1], mydegree, mybounds, mylon, mylat, buf.data) 114 plt.xlim(-190.,190.) 115 plt.ylim(-90.,90.) 116 plt.savefig('fig_partition/B%03d.pdf'%mpi_rank, dpi=1600) -
codes/icosagcm/devel/Python/test/py/test_xios.py
r663 r680 1 1 #print 'import dynamico' 2 2 #import dynamico 3 print 'import dynamico.unstructured'4 3 import dynamico.unstructured as unst 5 print 'import dynamico.xios'6 4 import dynamico.xios as xios 7 print 'Done.' 8 from dynamico.meshes import MPAS_Mesh as Mesh, radian 5 from dynamico.meshes import MPAS_Format, Unstructured_Mesh, radian 9 6 10 7 from mpi4py import MPI … … 38 35 def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter 39 36 print 'Reading MPAS mesh ...' 40 mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f) 37 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 38 mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 41 39 print '...Done' 42 40 43 41 lon_i, lat_i, lon_v, lat_v = [x*radian for x in mesh.lon_i, mesh.lat_i, mesh.lon_v, mesh.lat_v] 44 #lon_i, lat_i, lon_v, lat_v = mesh.lon_i, mesh.lat_i, mesh.lon_v, mesh.lat_v45 42 46 43 #--------------------------------- initialize XIOS --------------------------
Note: See TracChangeset
for help on using the changeset viewer.