Changeset 682 for codes/icosagcm/devel/Python/test/py/test_xios.py
- Timestamp:
- 02/16/18 18:06:01 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/test/py/test_xios.py
r680 r682 3 3 import dynamico.unstructured as unst 4 4 import dynamico.xios as xios 5 from dynamico.meshes import MPAS_Format, Unstructured_Mesh, radian 5 #from dynamico.meshes import MPAS_Format, Unstructured_Mesh, radian 6 from dynamico.meshes import radian, MPAS_Format, Unstructured_Mesh, Unstructured_PMesh as PMesh, Local_Mesh as Mesh 6 7 7 8 from mpi4py import MPI … … 11 12 12 13 import numpy as np 14 import cProfile 15 import re 13 16 14 17 def boundaries(degree,points,lon,lat): … … 28 31 #----------------------------- read MPAS mesh -------------------------------- 29 32 30 grid, llm, nqdyn, nqtot = 10242, 1,1,1 # 2562, 10242, 4096233 grid, llm, nqdyn, nqtot = 2562, 4,1,1 # 2562, 10242, 40962 31 34 Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4 32 35 N, T, courant = 40, 10800., 1.2 # simulation length = N*T … … 36 39 print 'Reading MPAS mesh ...' 37 40 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 38 mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 41 #mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 42 pmesh = PMesh(comm,meshfile) 43 mesh = Mesh(pmesh, llm, nqdyn, radius, f) 44 ni_glo = pmesh.dim_primal.n 45 ni_loc = len(mesh.primal_own_glo) 39 46 print '...Done' 40 47 … … 43 50 #--------------------------------- initialize XIOS -------------------------- 44 51 45 def setup_domain(cat,id, degree,vertex,lon,lat,lon_v,lat_v ): # cat in 'domain','domaingroup'52 def setup_domain(cat,id, degree,vertex,lon,lat,lon_v,lat_v, ncell_glo=None, index_glo=None, displ=None): # cat in 'domain','domaingroup' 46 53 bnd_lon, bnd_lat = boundaries(degree, vertex, lon_v, lat_v) 47 ncell_tot, nvertex = bnd_lon.shape 54 ncell, nvertex = bnd_lon.shape 55 if ncell_glo is None : 56 ncell_glo = ncell 57 index_glo = np.arange(ncell, dtype=np.int32) 58 displ = 0 48 59 mesh = xios.Handle(cat,id) 49 60 mesh.set_attr(type='unstructured') 50 mesh.set_attr(ni_glo=ncell_tot, ibegin=0, ni=ncell_tot) 51 mesh.set_attr(i_index=np.arange(ncell_tot,dtype=np.int32)) 61 mesh.set_attr(ni_glo=ncell_glo, ni=ncell, ibegin=displ, i_index=index_glo) 52 62 mesh.set_attr(lonvalue_1d=lon, latvalue_1d=lat) 53 63 mesh.set_attr(nvertex=nvertex,bounds_lon_1d=bnd_lon, bounds_lat_1d=bnd_lat) … … 60 70 levp1.set_attr(n_glo=llm+1, value=np.arange(llm+1)) 61 71 nq.set_attr(n_glo=nqtot, value=np.arange(nqtot)) 62 mesh_i=setup_domain('domaingroup','i', mesh.primal_deg, mesh.primal_vertex-1, lon_i, lat_i, lon_v, lat_v) # primal mesh 72 # primal mesh 73 mesh_i=setup_domain('domaingroup','i', mesh.primal_own_deg, mesh.primal_vertex, 74 lon_i[mesh.primal_own_loc], lat_i[mesh.primal_own_loc], 75 lon_v, lat_v, 76 pmesh.dim_primal.n, mesh.primal_own_glo, mesh.displ) 77 # mesh_i=setup_domain('domaingroup','i', mesh.primal_deg, mesh.primal_vertex-1, lon_i, lat_i, lon_v, lat_v) # primal mesh 63 78 # mesh_v=setup_domain('domain','v', mesh.dual_deg, mesh.dual_vertex-1, lon_v, lat_v, lon_i, lat_i) # dual mesh 64 79 … … 92 107 xios.context_close_definition() 93 108 109 lat_ik, junk = np.meshgrid(lat_i, np.arange(llm), indexing='xy') 110 111 def send_field1_primal(name, data): 112 # print 'send_field1_primal :', data.shape 113 data = data[mesh.primal_own_loc] 114 data = np.ascontiguousarray(data) 115 print 'send_field1_primal :', data.shape 116 xios.send_field(name, data) 117 def send_field2_primal(name, data): 118 # print 'send_field2_primal :', data.shape 119 data = data[:,mesh.primal_own_loc] 120 data = np.ascontiguousarray(data) 121 print 'send_field2_primal :', data.shape 122 xios.send_field(name, data) 123 94 124 no_error=True 95 125 try: … … 100 130 xios.update_calendar(i) 101 131 print 'send_field', i 102 xios.send_field('ps', lat_i) 132 send_field1_primal('ps', lat_i) 133 send_field2_primal('theta', lat_ik) 103 134 except: 104 135 print 'An error has occured, trying to close XIOS properly'
Note: See TracChangeset
for help on using the changeset viewer.