source: codes/icosagcm/devel/Python/test/py/RSW_2D_mesh.py @ 798

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

unstructured/test : fix inversion of xx,yy in RSW_2D_mesh and NH_3D_bubble_parallel

File size: 2.8 KB
RevLine 
[719]1from dynamico import meshes
2from dynamico import unstructured as unst
3from dynamico import time_step
[756]4from dynamico import precision as prec
[719]5
6import math as math
7import matplotlib.pyplot as plt
8import numpy as np
9import netCDF4 as cdf
10
11#--------------------------------- Main program -----------------------------
12
13nx,ny,llm,nqdyn=128,128,1,1
14Lx,Ly,g,f = 8.,8.,1.,1.
15dx,dy=Lx/nx,Ly/ny
16
[759]17filename, llm, nqdyn, g, f, radius = 'cart_%03d_%03d.nc'%(nx,ny), 1, 1, 1., 1., None
[719]18unst.setvar('g',g)
19
20print 'Reading Cartesian mesh ...'
[756]21meshfile = meshes.DYNAMICO_Format(filename)
[719]22
23def coriolis(lon,lat):
24   return f+0.*lon
25
26mesh=meshes.Unstructured_Mesh(meshfile, llm, nqdyn, radius, coriolis)
27caldyn = unst.Caldyn_RSW(mesh)
28
[776]29xx,yy = mesh.lon_i, mesh.lat_i
[719]30
31x1,x2,yy = xx-1., xx+1., yy
[747]32u0 = mesh.field_u()  # flow initally at rest
[719]33h0 = 1+0.1*(np.exp(-2.*(x1*x1+yy*yy))+
34            np.exp(-2.*(x2*x2+yy*yy)))
[773]35#h0 = 1+0.1*(np.exp(-5.*yy*yy))
36
[756]37flow0=prec.asnum([h0,u0])
[719]38
39cfl = .8
40dt = cfl/math.sqrt((nx/Lx)**2+(ny/Ly)**2)
41
[773]42T=10.
[719]43N=int(T/dt)+1
44dt=T/N
45print N,dt,Lx/nx
[747]46#scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, precision=unst.np_num)
47scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num)
[719]48
49flow=flow0
50
51def minmax(name, x): print('Min/max %s :'%name, x.min(), x.max() )
52def reshape(data): return data.reshape((nx,ny))
53
54x, y = map(reshape, (xx,yy) )
55
56for i in range(10):
57    h,u=flow
[756]58    flow, fast, slow = caldyn.bwd_fast_slow(flow, prec.zero)
[719]59    junk, du_fast = fast
60    dh, du_slow = slow
61#    minmax('lon',mesh.lon_i)
62#    minmax('lat',mesh.lat_i)
63#    minmax('x',xx)
64#    minmax('y',yy)
65    minmax('PV', caldyn.qv-1.)
66#    minmax('geopot', caldyn.geopot)
67#    minmax('du_fast', du_fast)
68    plt.figure(); plt.pcolor(x,y,reshape(caldyn.qv))
69    plt.colorbar(); plt.title('potential vorticity')
[747]70    plt.savefig('fig_RSW_2D_mesh/%03d.png'%i)
71    plt.close()
[719]72#    plt.figure(); plt.pcolor(mesh.x,mesh.y,h)
73#    plt.colorbar(); plt.title('h')
74#    plt.show()
75#    plt.pcolor(x,y,vcomp(u)/dx)
76#    plt.colorbar(); plt.title('v')
77#    plt.show()
78    for j in range(5):
79        unst.elapsed=0.
80        flow = scheme.advance(flow,N)
[747]81#        flow = scheme.advance(flow,5)
[719]82        # flops
83        # mass flux : 1add+1mul per edge          =>  4
84        # div U     : 4 add per cell              =>  4
85        # KE        : 4*(2add+1mul) per cell      => 12
86        # grad KE   : 1 add per edge              =>  2
87        # grad h    : 1 add per edge              =>  2
88        # qv    : 4+4+1 add +4mul + 1div per cell => 10
89        # qu    : 1add+1mul per edge              =>  4
90        # TrisK : 4add+4mul+4add+1add per edge    => 26
91        # Total :                                    64 FLOPS/cell
92        print i,j, unst.elapsed, 100.*(1.-unst.getvar('elapsed')/unst.elapsed)
93        print 'GFlops', 64*(N*nx*ny)/unst.elapsed/1e9
94        unst.setvar('elapsed',0.)
Note: See TracBrowser for help on using the repository browser.