Changeset 694 for codes/icosagcm/devel
- Timestamp:
- 05/04/18 18:00:44 (6 years ago)
- Location:
- codes/icosagcm/devel
- Files:
-
- 1 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
codes/icosagcm/devel/Python/src/setup.py
r626 r694 4 4 setup( name = "DYNAMICO kernels for unstructured mesh", 5 5 ext_modules = cythonize([ 6 Extension(" xios",["xios.pyx"],libraries=["xios"]),6 Extension("cxios",["cxios.pyx"],libraries=["xios"]), 7 7 Extension("unstructured",["unstructured.pyx"],libraries=["icosa","xios"]) 8 8 ]) -
codes/icosagcm/devel/Python/test/py/test_xios.py
r682 r694 1 #print 'import dynamico'2 #import dynamico3 1 import dynamico.unstructured as unst 4 2 import dynamico.xios as xios 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 3 from dynamico.meshes import radian, MPAS_Format, Unstructured_PMesh as PMesh, Local_Mesh as Mesh 7 4 8 5 from mpi4py import MPI … … 14 11 import cProfile 15 12 import re 16 17 def boundaries(degree,points,lon,lat):18 n, nvertex = len(degree), degree.max()19 bnd_lon, bnd_lat = np.zeros((n,nvertex)),np.zeros((n,nvertex))20 for ij in range(n):21 nb=degree[ij]22 for k in range(nb):23 vertex = points[ij,k]24 bnd_lon[ij,k]=lon[vertex]25 bnd_lat[ij,k]=lat[vertex]26 for k in range(nb,nvertex): # repeat last vertex if nb<nvertex27 bnd_lon[ij,k]=bnd_lon[ij,nb-1]28 bnd_lat[ij,k]=bnd_lat[ij,nb-1]29 return bnd_lon, bnd_lat30 13 31 14 #----------------------------- read MPAS mesh -------------------------------- … … 39 22 print 'Reading MPAS mesh ...' 40 23 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 41 #mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f)42 24 pmesh = PMesh(comm,meshfile) 43 25 mesh = Mesh(pmesh, llm, nqdyn, radius, f) 44 ni_glo = pmesh.dim_primal.n45 ni_loc = len(mesh.primal_own_glo)46 26 print '...Done' 47 27 48 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] 28 #--------------------------------- write some data ---------------------------------------- 49 29 50 #--------------------------------- initialize XIOS -------------------------- 30 context=xios.XIOS_Context(pmesh,mesh,nqtot) 51 31 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' 53 bnd_lon, bnd_lat = boundaries(degree, vertex, lon_v, lat_v) 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 59 mesh = xios.Handle(cat,id) 60 mesh.set_attr(type='unstructured') 61 mesh.set_attr(ni_glo=ncell_glo, ni=ncell, ibegin=displ, i_index=index_glo) 62 mesh.set_attr(lonvalue_1d=lon, latvalue_1d=lat) 63 mesh.set_attr(nvertex=nvertex,bounds_lon_1d=bnd_lon, bounds_lat_1d=bnd_lat) 64 65 unst.ker.dynamico_setup_xios() 66 67 if True: 68 lev, levp1, nq = [xios.Handle('axis',name) for name in 'lev', 'levp1', 'nq'] 69 lev.set_attr(n_glo=llm, value=np.arange(llm)) 70 levp1.set_attr(n_glo=llm+1, value=np.arange(llm+1)) 71 nq.set_attr(n_glo=nqtot, value=np.arange(nqtot)) 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 78 # mesh_v=setup_domain('domain','v', mesh.dual_deg, mesh.dual_vertex-1, lon_v, lat_v, lon_i, lat_i) # dual mesh 79 80 # CALL xios_set_domain_attr("u",ni_glo=ncell_tot, ibegin=displ, ni=ncell) 81 # CALL xios_set_domain_attr("u", data_dim=1, type='unstructured' , nvertex=2, i_index=ind_glo) 82 # CALL xios_set_domain_attr("u",lonvalue_1d=lon, latvalue_1d=lat, bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat) 83 #mesh_e = xios.Handle('domain','u') 84 85 # works up to that point ! 86 87 dtime = xios.Duration(second=3600.) 88 89 # CALL xios_set_timestep(dtime) 90 if True: 91 calendar=xios.Handle('calendar_wrapper') 92 print (dtime.year, dtime.month, dtime.day, dtime.hour, dtime.second) 93 calendar.set_attr(timestep=dtime) 94 calendar.update_timestep() 95 else: 96 unst.ker.dynamico_xios_set_timestep(3600.) 97 98 # CALL xios_set_fieldgroup_attr("standard_output", freq_op=itau_out*xios_timestep, freq_offset=(itau_out-1)*xios_timestep) 99 if False: 100 std=xios.Handle('fieldgroup','standard_output') 101 std.set_attr(freq_op=dtime) 102 freq_offset = xios.Duration(second=0) 103 std.set_attr(freq_offset=freq_offset) 104 105 if True: 106 print 'xios.context_close_definition()' 107 xios.context_close_definition() 108 32 lat_i = radian*mesh.lat_i 109 33 lat_ik, junk = np.meshgrid(lat_i, np.arange(llm), indexing='xy') 110 34 111 def send_field1_primal(name, data):112 # print 'send_field1_primal :', data.shape113 data = data[mesh.primal_own_loc]114 data = np.ascontiguousarray(data)115 print 'send_field1_primal :', data.shape116 xios.send_field(name, data)117 def send_field2_primal(name, data):118 # print 'send_field2_primal :', data.shape119 data = data[:,mesh.primal_own_loc]120 data = np.ascontiguousarray(data)121 print 'send_field2_primal :', data.shape122 xios.send_field(name, data)123 124 35 no_error=True 125 36 try: 126 37 for i in range(100): 127 if True: 128 unst.ker.dynamico_xios_update_calendar(i) 129 else: 130 xios.update_calendar(i) 38 context.update_calendar(i) 131 39 print 'send_field', i 132 send_field1_primal('ps', lat_i)133 send_field2_primal('theta', lat_ik)40 context.send_field_primal('ps', lat_i) 41 context.send_field_primal('theta', lat_ik) 134 42 except: 135 43 print 'An error has occured, trying to close XIOS properly' 136 44 no_error=False 137 # CALL xios_recv_field(name,field)138 # CALL xios_send_field(name,field_tmp)139 45 140 46 print 'xios.context_finalize()' 141 xios.context_finalize() 142 47 context.finalize() 143 48 print 'xios.finalize()' 144 49 xios.finalize() 145 146 50 print 'Done' 147 51 -
codes/icosagcm/devel/make_python
r662 r694 96 96 cd $DYNAMICO_ROOT 97 97 98 for module in xios unstructured meshes dyn time_step DCMIP; do98 for module in cxios unstructured meshes dyn time_step DCMIP; do 99 99 echo "from dynamico import $module" 100 100 LD_PRELOAD=$PYTHON_PRELOAD python -c "from dynamico import $module"
Note: See TracChangeset
for help on using the changeset viewer.