source: codes/icosagcm/devel/Python/test/py/RSW_2D.py @ 786

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

devel/Python : cosmetic fix in RSW_2D.py

File size: 2.2 KB
Line 
1from dynamico.meshes import Cartesian_mesh as Mesh
2from dynamico import unstructured as unst
3from dynamico import dyn
4from dynamico import time_step
5from dynamico import DCMIP
6from dynamico.precision import zero, np_num
7
8import math as math
9import matplotlib.pyplot as plt
10import numpy as np
11import time
12
13nx,ny,llm,nqdyn=128,128,1,1
14Lx,Ly,g,f = 8.,8.,1.,1.
15dx,dy=Lx/nx,Ly/ny
16
17unst.setvar('g',g)
18mesh = Mesh(nx,ny,llm,nqdyn,Lx,Ly,f)
19caldyn = unst.Caldyn_RSW(mesh)
20
21x1,x2,yy = mesh.xx[:,:,0]-1., mesh.xx[:,:,0]+1., mesh.yy[:,:,0]
22h0, u0 = mesh.field_mass(), mesh.field_u()  # flow initally at rest
23h0[:] = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+
24            np.exp(-2.*(x2*x2+yy*yy)))
25#h0[:] = 1+0.1*(np.exp(-2.*yy*yy))
26
27flow0=(h0,u0)
28
29cfl = .8
30dt = cfl/math.sqrt((nx/Lx)**2+(ny/Ly)**2)
31
32T=10.
33N=int(T/dt)+1
34dt=T/N
35print N,dt,Lx/nx
36scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=np_num)
37
38print 'types : yy, u0, h0, u0', yy.dtype, u0.dtype, h0.dtype, u0.dtype
39
40flow=flow0
41for i in range(10):
42    h,u=flow
43    print 'types : h,u', h.dtype, u.dtype
44    caldyn.bwd_fast_slow(flow, zero)
45    plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv)
46    plt.colorbar(); plt.title('potential vorticity')
47    plt.savefig('fig_RSW_2D/%03d.png'%i)
48#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h)
49#    plt.colorbar(); plt.title('h')
50#    plt.show()
51#    plt.pcolor(x,y,vcomp(u)/dx)
52#    plt.colorbar(); plt.title('v')
53#    plt.show()
54    for j in range(5):
55        unst.elapsed=0.
56        flow = scheme.advance(flow,N)
57        h,u=flow
58        print 'types : h,u', h.dtype, u.dtype
59        # flops
60        # mass flux : 1add+1mul per edge          =>  4
61        # div U     : 4 add per cell              =>  4
62        # KE        : 4*(2add+1mul) per cell      => 12
63        # grad KE   : 1 add per edge              =>  2
64        # grad h    : 1 add per edge              =>  2
65        # qv    : 4+4+1 add +4mul + 1div per cell => 10
66        # qu    : 1add+1mul per edge              =>  4
67        # TrisK : 4add+4mul+4add+1add per edge    => 26
68        # Total :                                    64 FLOPS/cell
69        print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed)
70        print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9
71        unst.setvar('elapsed',0.)
Note: See TracBrowser for help on using the repository browser.