source: codes/icosagcm/devel/Python/test/py/RSW2_MPAS_W02.py @ 642

Last change on this file since 642 was 642, checked in by dubos, 7 years ago

devel/unstructured : bubble test case with Fortran time stepping

File size: 3.8 KB
Line 
1print 'Loading modules ...'
2import math as math
3import matplotlib.pyplot as plt
4import numpy as np
5print '...Done'
6
7print 'Loading DYNAMICO modules ...'
8from dynamico import unstructured as unst
9from dynamico.meshes import MPAS_Mesh as Mesh
10from dynamico import time_step
11print '...Done'
12
13grid, llm, nqdyn = 10242, 1,1 # 2562, 10242, 40962
14Omega, radius, g, gh0 = 2.*np.pi/86400., 6.4e6, 1., 2.94e4
15N, T, courant = 40, 10800., 1.2 # simulation length = N*T
16
17print 'Omega, planetary PV', Omega, 2*Omega/gh0
18
19def f(lon,lat): return 2*Omega*np.sin(lat) # Coriolis parameter
20print 'Reading MPAS mesh ...'
21mesh = Mesh('grids/x1.%d.grid.nc'%grid, llm, nqdyn, radius, f)
22print '...Done'
23lon, lat = mesh.lon_i, mesh.lat_i
24x,y,z = np.cos(lat)*np.cos(lon), np.cos(lat)*np.sin(lon), np.sin(lat)
25
26unst.setvar('g',g)
27
28c0 = math.sqrt(gh0) # phase speed of barotropic mode
29dx = mesh.de.min()
30dt = courant*dx/c0
31nt = int(math.ceil(T/dt))
32dt = T/nt
33print dx, dt, dt*c0/dx
34print T, nt
35
36caldyn = unst.Caldyn_RSW(mesh)
37scheme = time_step.RK4(caldyn.bwd_fast_slow, dt)
38#scheme = time_step.RKn_simple(1,caldyn.bwd_fast_slow, dt) # forward Euler scheme
39print dt, scheme.csjl, scheme.cfjl
40step = unst.caldyn_step_TRSW(mesh,scheme,nt)
41
42u0 = Omega*radius/12. # cf Williamson (1991), p.13
43gh1 = radius*Omega*u0+.5*u0**2
44print 'Williamson (1991) test 2, u0=', u0
45ulon = u0*np.cos(mesh.lat_e)
46Phi0 = gh0 - gh1*(np.sin(mesh.lat_i)**2)
47zeta0 = (2*u0/radius+2*Omega)*np.sin(mesh.lat_v)
48Phi0v = gh0 - (radius*Omega*u0+.5*u0**2)*(np.sin(mesh.lat_v)**2)
49q0 = zeta0/Phi0v
50fu_perp = mesh.ucov2D(0.*ulon,2*Omega*np.sin(mesh.lat_e)*ulon)
51
52# initial condition
53step.mass[:]=Phi0
54step.theta_rhodz[:]=Phi0
55step.u[:]=mesh.ucov2D(ulon,0.*ulon)
56
57gh,u = step.mass.copy(), step.u.copy()
58
59print gh.shape, gh.min(), gh.max(), u.min(), u.max()
60flow=gh,u
61
62for i in range(20):
63    if True:
64        step.next()
65        gh,u = step.mass, step.u
66        print i, gh.shape, gh.min(), gh.max(), u.min(), u.max()
67        mesh.plot_i(gh-Phi0) ; plt.title('err(gh)');
68        plt.savefig('fig_RSW2_MPAS_W02/err_gh_%02d.png'%i)
69        plt.close()
70    else:
71        # advance by one time step using dynamico_ARK
72        gh,u = step.mass.copy(), step.u.copy()
73        print i, gh.shape, gh.min(), gh.max(), u.min(), u.max()
74        step.next()
75        gh_now,u_now = step.mass.copy(), step.u.copy()
76        dmass,dhs,du_slow,du_fast = step.drhodz[:], step.dtheta_rhodz[:], step.du_slow[:], step.du_fast[:]
77        du=du_slow+du_fast
78
79        # do the same using caldyn, obtain fast/slow tendencies first
80        gh_ref, uref=flow
81        junk, fast, slow = caldyn.bwd_fast_slow(flow,0.)                                                                     
82        dmass_ref, duslow_ref = slow
83        junk, dufast_ref = fast
84        du_ref = duslow_ref+dufast_ref
85        flow=scheme.next(flow)
86        gh_nowref, u_nowref=flow
87#    mesh.plot_i(gh) ; plt.title('gh');
88#    mesh.plot_i(Phi0) ; plt.title('gh');
89        fig = plt.figure(figsize=(6, 8)) 
90        f, ((ax1, ax2), (ax3, ax4), (ax5,ax6), (ax7,ax8)) = plt.subplots(4,2)
91#        mesh.plot_i(dmass-dhs) ; plt.title('dt*d(gh)/dt');
92        ax1.scatter(duslow_ref,du_slow-duslow_ref) ; ax1.set_title('du_slow');
93        ax2.scatter(dufast_ref,du_fast-dufast_ref) ; ax2.set_title('du_fast');
94        ax3.scatter(du_ref,du-du_ref) ; ax3.set_title('du');
95        ax4.scatter(gh_ref,gh-gh_ref) ; ax4.set_title('gh');
96        ax5.scatter(uref, u-uref) ; ax5.set_title('u');
97        ax6.scatter(dmass_ref,dmass-dmass_ref) ; ax6.set_title('dmass');
98        ax7.scatter(gh_nowref,gh_now-gh_nowref) ; ax7.set_title('gh_now');
99        ax8.scatter(u_nowref,u_now-u_nowref) ; ax8.set_title('u_now');
100        f.subplots_adjust(hspace=1.)
101        plt.savefig('fig_RSW2_MPAS_W02/scatter_%02d.png'%i)
102        plt.close()
103
104print 'Time spent in DYNAMICO (s) : ', unst.getvar('elapsed')
Note: See TracBrowser for help on using the repository browser.