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

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

devel/unstructured : more fixes to mixed precision

File size: 2.1 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, u0 = mesh.field_mass(), mesh.field_u()  # flow initally at rest
21h0[:] = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+
22            np.exp(-2.*(x2*x2+yy*yy)))
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
34print 'types : yy, u0, h0, u0', yy.dtype, u0.dtype, h0.dtype, u0.dtype
35
36flow=flow0
37for i in range(10):
38    h,u=flow
39    print 'types : h,u', h.dtype, u.dtype
40    caldyn.bwd_fast_slow(flow, 0.)
41    plt.figure(); plt.pcolor(mesh.x,mesh.y,caldyn.qv)
42    plt.colorbar(); plt.title('potential vorticity')
43    plt.savefig('fig_RSW_2D/%02d.png'%i)
44#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h)
45#    plt.colorbar(); plt.title('h')
46#    plt.show()
47#    plt.pcolor(x,y,vcomp(u)/dx)
48#    plt.colorbar(); plt.title('v')
49#    plt.show()
50    for j in range(5):
51        unst.elapsed=0.
52        flow = scheme.advance(flow,N)
53        h,u=flow
54        print 'types : h,u', h.dtype, u.dtype
55        # flops
56        # mass flux : 1add+1mul per edge          =>  4
57        # div U     : 4 add per cell              =>  4
58        # KE        : 4*(2add+1mul) per cell      => 12
59        # grad KE   : 1 add per edge              =>  2
60        # grad h    : 1 add per edge              =>  2
61        # qv    : 4+4+1 add +4mul + 1div per cell => 10
62        # qu    : 1add+1mul per edge              =>  4
63        # TrisK : 4add+4mul+4add+1add per edge    => 26
64        # Total :                                    64 FLOPS/cell
65        print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed)
66        print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9
67        unst.setvar('elapsed',0.)
Note: See TracBrowser for help on using the repository browser.