source: codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py @ 773

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

devel/Python : fix RSW_2D testcase

File size: 2.9 KB
Line 
1from dynamico import meshes
2from dynamico import unstructured as unst
3from dynamico import time_step
4from dynamico import precision as prec
5
6import math as math
7import matplotlib.pyplot as plt
8import numpy as np
9import netCDF4 as cdf
10
11#--------------------------------- Main program -----------------------------
12
13nx,ny,llm,nqdyn=128,128,1,1
14Lx,Ly,g,f = 8.,8.,1.,1.
15dx,dy=Lx/nx,Ly/ny
16
17filename, llm, nqdyn, g, f, radius = 'cart_%03d_%03d.nc'%(nx,ny), 1, 1, 1., 1., None
18unst.setvar('g',g)
19
20print 'Reading Cartesian mesh ...'
21meshfile = meshes.DYNAMICO_Format(filename)
22
23def coriolis(lon,lat):
24   return f+0.*lon
25
26mesh=meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, coriolis)
27caldyn = unst.Caldyn_RSW(mesh)
28
29#xx = (mesh.lat_i-nx/2.)*dx
30#yy = (mesh.lon_i-ny/2.)*dy
31xx,yy = mesh.lat_i, mesh.lon_i
32
33x1,x2,yy = xx-1., xx+1., yy
34u0 = mesh.field_u()  # flow initally at rest
35h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+
36            np.exp(-2.*(x2*x2+yy*yy)))
37#h0 = 1+0.1*(np.exp(-5.*yy*yy))
38
39flow0=prec.asnum([h0,u0])
40
41cfl = .8
42dt = cfl/math.sqrt((nx/Lx)**2+(ny/Ly)**2)
43
44T=10.
45N=int(T/dt)+1
46dt=T/N
47print N,dt,Lx/nx
48#scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num)
49scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num)
50
51flow=flow0
52
53def minmax(name, x): print('Min/max %s :'%name, x.min(), x.max() )
54def reshape(data): return data.reshape((nx,ny))
55
56x, y = map(reshape, (xx,yy) )
57
58for i in range(10):
59    h,u=flow
60    flow, fast, slow = caldyn.bwd_fast_slow(flow, prec.zero)
61    junk, du_fast = fast
62    dh, du_slow = slow
63#    minmax('lon',mesh.lon_i)
64#    minmax('lat',mesh.lat_i)
65#    minmax('x',xx)
66#    minmax('y',yy)
67    minmax('PV', caldyn.qv-1.)
68#    minmax('geopot', caldyn.geopot)
69#    minmax('du_fast', du_fast)
70    plt.figure(); plt.pcolor(x,y,reshape(caldyn.qv))
71    plt.colorbar(); plt.title('potential vorticity')
72    plt.savefig('fig_RSW_2D_mesh/%03d.png'%i)
73    plt.close()
74#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h)
75#    plt.colorbar(); plt.title('h')
76#    plt.show()
77#    plt.pcolor(x,y,vcomp(u)/dx)
78#    plt.colorbar(); plt.title('v')
79#    plt.show()
80    for j in range(5):
81        unst.elapsed=0.
82        flow = scheme.advance(flow,N)
83#        flow = scheme.advance(flow,5)
84        # flops
85        # mass flux : 1add+1mul per edge          =>  4
86        # div U     : 4 add per cell              =>  4
87        # KE        : 4*(2add+1mul) per cell      => 12
88        # grad KE   : 1 add per edge              =>  2
89        # grad h    : 1 add per edge              =>  2
90        # qv    : 4+4+1 add +4mul + 1div per cell => 10
91        # qu    : 1add+1mul per edge              =>  4
92        # TrisK : 4add+4mul+4add+1add per edge    => 26
93        # Total :                                    64 FLOPS/cell
94        print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed)
95        print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9
96        unst.setvar('elapsed',0.)
Note: See TracBrowser for help on using the repository browser.