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