source: codes/icosagcm/devel/Python/test/py/RSW_MPAS_W02.py @ 787

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

devel/unstructured : more fixes to mixed precision

File size: 2.9 KB
Line 
1print 'Loading DYNAMICO modules ...'
2from dynamico import unstructured as unst
3from dynamico.precision import asnum
4from dynamico.meshes import MPAS_Format, Unstructured_Mesh
5from dynamico import time_step
6print '...Done'
7
8print 'Loading modules ...'
9import math as math
10import matplotlib.pyplot as plt
11import numpy as np
12print '...Done'
13
14grid, llm, nqdyn = 10242, 1,1 # 2562, 10242, 40962
15Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4
16N, T, courant = 40, 10800., 1.2 # simulation length = N*T
17
18print 'Omega, planetary PV', Omega, 2*Omega/gh0
19
20def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter
21print 'Reading MPAS mesh ...'
22meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid)
23mesh=Unstructured_Mesh(meshfile, llm, nqdyn, radius, f)
24print '...Done'
25lon, lat = mesh.lon_i, mesh.lat_i
26x,y,z = np.cos(lat)*np.cos(lon), np.cos(lat)*np.sin(lon), np.sin(lat)
27
28unst.setvar('g',g)
29caldyn = unst.Caldyn_RSW(mesh)
30
31c0 = math.sqrt(gh0) # phase speed of barotropic mode
32dx = mesh.de.min()
33dt = courant*dx/c0
34nt = int(math.ceil(T/dt))
35dt = T/nt
36#scheme = time_step.RKn_simple(1,caldyn.bwd_fast_slow, dt)
37scheme = time_step.RK4(caldyn.bwd_fast_slow, dt, precision=unst.np_num)
38   
39print dx, dt, dt*c0/dx
40print T, nt
41
42#mesh.plot_e(mesh.le_de) ; plt.title('le/de') ; plt.show()
43#mesh.plot_i(mesh.Ai) ; plt.title('Ai') ; plt.show()
44
45#Phi0 = gh0*(1+0.1*np.exp(-2000.*(y+1.)**2))
46#flow = (Phi0,mesh.field_u())
47#for i in range(N):
48#    h,u=flow
49#    plot_i(h) ; plt.title('h'); plt.show()
50#    junk, fast, slow = caldyn.bwd_fast_slow(flow,0.)
51#    print i
52#    flow = scheme.advance(flow, nt)
53
54u0 = Omega*radius/12. # cf Williamson (1991), p.13
55gh1 = radius*Omega*u0+.5*u0**2
56print 'Williamson (1991) test 2, u0=', u0
57ulon = u0*np.cos(mesh.lat_e)
58Phi0 = gh0 - gh1*(np.sin(mesh.lat_i)**2)
59zeta0 = (2*u0/radius+2*Omega)*np.sin(mesh.lat_v)
60Phi0v = gh0 - (radius*Omega*u0+.5*u0**2)*(np.sin(mesh.lat_v)**2)
61q0 = zeta0/Phi0v
62fu_perp = mesh.ucov2D(0.*ulon,2*Omega*np.sin(mesh.lat_e)*ulon)
63
64flow = asnum([Phi0, mesh.ucov2D(ulon,0.*ulon)])
65print 'type of Phi0,u0 : ', flow[0].dtype, flow[1].dtype
66
67for i in range(N):
68    h,u=flow
69    mesh.plot_i(h-Phi0) ; plt.title('err(gh)'); 
70    plt.savefig('fig_RSW_MPAS_W02/err_gh_%02d.png'%i)
71    plt.close()
72#    junk, fast, slow = caldyn.bwd_fast_slow(flow,0.)
73#    plot_i(slow[0]) ; plt.title('dh/dt'); plt.show()
74#    plot_e(slow[1]+fast[1]) ; plt.title('du/dt'); plt.show()
75#    plt.figure(); plt.plot(fu_perp,slow[1],'.');
76#    plt.xlabel('fu_perp'); plt.ylabel('u_slow'); plt.show()
77#    plt.figure(); plt.plot(fu_perp,fast[1],'.');
78#    plt.xlabel('fu_perp'); plt.ylabel('u_fast'); plt.show()
79#    plot_e(fast[1]) ; plt.title('u_fast'); plt.show()
80#    plot_e(slow[1]) ; plt.title('u_slow'); plt.show()
81#    plt.figure(); plt.plot(q0,caldyn.qv,'.');
82#    plt.xlabel('q0'); plt.ylabel('qv'); plt.show()
83    print i, h.min(), h.max()
84    flow = scheme.advance(flow, nt)
85
86print 'Time spent in DYNAMICO (s) : ', unst.getvar('elapsed')
Note: See TracBrowser for help on using the repository browser.