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

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

devel/Python : cosmetic changes to test cases

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