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

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

devel/unstructured : fix RSW_2D test case for mixed precision

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,192,1,1
14Lx,Ly,g,f = 8.,12.,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)))
25flow0=(h0,u0)
26
27cfl = .8
28dt = cfl/math.sqrt((nx/Lx)**2+(ny/Ly)**2)
29
30T=10.
31N=int(T/dt)+1
32dt=T/N
33print N,dt,Lx/nx
34scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=np_num)
35
36print 'types : yy, u0, h0, u0', yy.dtype, u0.dtype, h0.dtype, u0.dtype
37
38flow=flow0
39for i in range(10):
40    h,u=flow
41    print 'types : h,u', h.dtype, u.dtype
42    caldyn.bwd_fast_slow(flow, zero)
43    plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv)
44    plt.colorbar(); plt.title('potential vorticity')
45    plt.savefig('fig_RSW_2D/%02d.png'%i)
46#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h)
47#    plt.colorbar(); plt.title('h')
48#    plt.show()
49#    plt.pcolor(x,y,vcomp(u)/dx)
50#    plt.colorbar(); plt.title('v')
51#    plt.show()
52    for j in range(5):
53        unst.elapsed=0.
54        flow = scheme.advance(flow,N)
55        h,u=flow
56        print 'types : h,u', h.dtype, u.dtype
57        # flops
58        # mass flux : 1add+1mul per edge          =>  4
59        # div U     : 4 add per cell              =>  4
60        # KE        : 4*(2add+1mul) per cell      => 12
61        # grad KE   : 1 add per edge              =>  2
62        # grad h    : 1 add per edge              =>  2
63        # qv    : 4+4+1 add +4mul + 1div per cell => 10
64        # qu    : 1add+1mul per edge              =>  4
65        # TrisK : 4add+4mul+4add+1add per edge    => 26
66        # Total :                                    64 FLOPS/cell
67        print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed)
68        print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9
69        unst.setvar('elapsed',0.)
Note: See TracBrowser for help on using the repository browser.