Changeset 694 for codes/icosagcm


Ignore:
Timestamp:
05/04/18 18:00:44 (6 years ago)
Author:
dubos
Message:

devel/unstructured : higher-level interface to XIOS

Location:
codes/icosagcm/devel
Files:
1 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • codes/icosagcm/devel/Python/src/setup.py

    r626 r694  
    44setup(  name = "DYNAMICO kernels for unstructured mesh", 
    55        ext_modules = cythonize([ 
    6             Extension("xios",["xios.pyx"],libraries=["xios"]), 
     6            Extension("cxios",["cxios.pyx"],libraries=["xios"]), 
    77            Extension("unstructured",["unstructured.pyx"],libraries=["icosa","xios"]) 
    88            ]) 
  • codes/icosagcm/devel/Python/test/py/test_xios.py

    r682 r694  
    1 #print 'import dynamico' 
    2 #import dynamico 
    31import dynamico.unstructured as unst 
    42import 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 
     3from dynamico.meshes import radian, MPAS_Format, Unstructured_PMesh as PMesh, Local_Mesh as Mesh 
    74 
    85from mpi4py import MPI 
     
    1411import cProfile 
    1512import 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<nvertex 
    27             bnd_lon[ij,k]=bnd_lon[ij,nb-1] 
    28             bnd_lat[ij,k]=bnd_lat[ij,nb-1] 
    29     return bnd_lon, bnd_lat 
    3013 
    3114#----------------------------- read MPAS mesh -------------------------------- 
     
    3922print 'Reading MPAS mesh ...' 
    4023meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid) 
    41 #mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f) 
    4224pmesh = PMesh(comm,meshfile) 
    4325mesh = Mesh(pmesh, llm, nqdyn, radius, f) 
    44 ni_glo = pmesh.dim_primal.n 
    45 ni_loc = len(mesh.primal_own_glo) 
    4626print '...Done' 
    4727 
    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 ---------------------------------------- 
    4929 
    50 #--------------------------------- initialize XIOS -------------------------- 
     30context=xios.XIOS_Context(pmesh,mesh,nqtot) 
    5131 
    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  
     32lat_i = radian*mesh.lat_i 
    10933lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='xy') 
    11034 
    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      
    12435no_error=True 
    12536try: 
    12637    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) 
    13139        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) 
    13442except: 
    13543    print 'An error has occured, trying to close XIOS properly' 
    13644    no_error=False 
    137 # CALL xios_recv_field(name,field)                                                                                                                        
    138 # CALL xios_send_field(name,field_tmp)                                                                                                                    
    13945 
    14046print 'xios.context_finalize()' 
    141 xios.context_finalize() 
    142  
     47context.finalize() 
    14348print 'xios.finalize()' 
    14449xios.finalize() 
    145  
    14650print 'Done' 
    14751 
  • codes/icosagcm/devel/make_python

    r662 r694  
    9696    cd $DYNAMICO_ROOT 
    9797 
    98     for module in xios unstructured meshes dyn time_step DCMIP; do 
     98    for module in cxios unstructured meshes dyn time_step DCMIP; do 
    9999        echo "from dynamico import $module" 
    100100        LD_PRELOAD=$PYTHON_PRELOAD python -c "from dynamico import $module" 
Note: See TracChangeset for help on using the changeset viewer.