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

Last change on this file since 620 was 617, checked in by dubos, 7 years ago

devel : tests for unstructured-mesh prototype

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