source: codes/icosagcm/devel/Python/test/py/test_xios.py @ 759

Last change on this file since 759 was 759, checked in by dubos, 6 years ago

devel/unstructured : towards XIOS output with curvilinear mesh

File size: 1.7 KB
Line 
1import dynamico.unstructured as unst
2import dynamico.xios as xios
3from dynamico.meshes import radian, MPAS_Format, Unstructured_PMesh as PMesh, Local_Mesh as Mesh
4
5from mpi4py import MPI
6comm = MPI.COMM_WORLD
7mpi_rank, mpi_size = comm.Get_rank(), comm.Get_size()
8print '%d/%d starting'%(mpi_rank,mpi_size)
9
10import numpy as np
11import cProfile
12import re
13
14#----------------------------- read MPAS mesh --------------------------------
15
16grid, llm, nqdyn, nqtot = 2562, 4,1,1 # 2562, 10242, 40962 
17Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4
18N, T, courant = 40, 10800., 1.2 # simulation length = N*T
19print 'Omega, planetary PV', Omega, 2*Omega/gh0
20
21def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter                                                                                                               
22print 'Reading MPAS mesh ...'
23meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid)
24pmesh = PMesh(comm,meshfile)
25mesh = Mesh(pmesh, llm, nqdyn, radius, f)
26print '...Done'
27
28#--------------------------------- write some data ----------------------------------------
29
30context=xios.XIOS_Context_Unstructured(pmesh,mesh,nqtot, 3600)
31
32lat_i = radian*mesh.lat_i
33lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='ij')
34
35no_error=True
36try:
37    for i in range(100):
38        context.update_calendar(i)
39        print 'send_field', i, lat_ik.shape
40        context.send_field_primal('ps', lat_i)
41        context.send_field_primal('theta', lat_ik)
42except:
43    print 'An error has occured, trying to close XIOS properly'
44    no_error=False
45
46print 'xios.context_finalize()'
47context.finalize()
48print 'xios.finalize()'
49xios.finalize()
50print 'Done'
51
52if not no_error : raise
Note: See TracBrowser for help on using the repository browser.