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