source: codes/icosagcm/devel/Python/test/py/slice_GW_NH.py @ 617

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

devel : tests for unstructured-mesh prototype

File size: 3.4 KB
Line 
1from dynamico import unstructured as unst
2from dynamico import dyn
3from dynamico import time_step
4from dynamico import DCMIP
5
6import math as math
7import matplotlib.pyplot as plt
8import numpy as np
9import time
10
11unst.setvar('nb_threads', 1)
12
13def run(mesh,metric,thermo,BC,caldyn_eta,u, m0ik,gas0,Phi0_il, T=300., courant=2.9):
14    caldyn_thermo = unst.thermo_entropy
15    g = mesh.dx/metric.dx_g0
16    caldyn = unst.Caldyn_NH(caldyn_thermo,caldyn_eta, mesh,metric,thermo,BC,g)
17
18    Sik = m0ik*gas0.s
19    m0ik = m0ik/dx # NB : different definitions of mass field in DYNAMICO / Slice
20    if caldyn_thermo == unst.thermo_theta:
21        theta0 = thermo.T0*np.exp(gas0.s/thermo.Cpd)
22        S0ik = m0ik*theta0
23    else:
24        S0ik = m0ik*gas0.s
25
26    u0=mesh.field_u() 
27    u0[:,range(0,2*nx,2),:] = u*mesh.dx # Doppler shift by u
28    flow0=(m0ik,S0ik,u0,Phi0_il,0*Phi0_il)
29
30    dt = courant*.5*dx/np.sqrt(gas0.c2.max())
31    nt=int(T/dt)+1
32    dt=T/nt
33    print 'nt,dt,dx', nt,dt,dx
34    scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, a32=0.7)
35    #scheme = time_step.ARK3(caldyn.bwd_fast_slow, dt)
36
37#    nt=1 # FIXME
38    flow=flow0
39    for i in range(12):
40        time1=time.time()
41        flow = scheme.advance(flow,nt)
42        time2=time.time()
43        print 'ms per time step : ', 1000*(time2-time1)/nt
44
45        m,S,u,Phi,W = flow
46        w=.5*(W[:,0:llm]+W[:,1:llm+1])/m
47        junk,fast,slow = caldyn.bwd_fast_slow(flow, 0.)
48#        zz=caldyn.geopot[:,0:llm]/metric.g0/1000
49        zz=Phi[:,0:llm]/metric.g0/1000
50        print 'ptop, model top (m) :', unst.getvar('ptop'), Phi.max()/unst.getvar('g')
51
52        def plt_axes():
53            plt.plot(xx,zz[:,llm/4])
54            plt.plot(xx,zz[:,llm/2])
55            plt.plot(xx,zz[:,3*llm/4])
56            plt.ylim(0,ztop/1000.)
57            plt.colorbar()
58
59        plt.figure(figsize=(12,3))
60        ucomp = mesh.ucomp(u)
61        plt.pcolor(xx,zz,caldyn.pk)
62        plt_axes()
63        plt.title("T(t = %f s)" % ((i+1)*dt*nt))
64        plt.savefig('fig_slice_GW_NH/T%02d.png'%i)
65        plt.close()
66
67        plt.figure(figsize=(12,3))
68        ucomp = mesh.ucomp(u)
69        plt.pcolor(xx,zz,ucomp[0,:,:]/dx)
70        plt_axes()
71        plt.title("u(t = %f s)" % ((i+1)*dt*nt))
72        plt.savefig('fig_slice_GW_NH/U%02d.png'%i)
73        plt.close()
74
75        plt.figure(figsize=(12,3))
76        plt.pcolor(xx,zz,w)
77        plt_axes()
78        plt.title("w(t = %f s)" % ((i+1)*dt*nt))
79        plt.savefig('fig_slice_GW_NH/W%02d.png'%i)
80        plt.close()
81
82def deform(x,eta): # x and eta go from 0 to 1
83    h0, dd, xi = 2000., 5000., 4000.
84    cos2=lambda x: np.cos(np.pi*x)**2
85    gauss=lambda x: np.exp(-x*x)
86    xx = x*Lx
87    phis = h0*gauss(xx/dd)*cos2(xx/xi)
88    return (phis/ztop)*np.sin(np.pi*eta)
89
90#Lx, nx, llm = 3e5, 100, 1e4, 30
91Lx, nx, ztop, llm = 2e5, 400, 3e4, 60
92nqdyn, ny, dx = 1, 1, Lx/nx
93mesh = unst.Cartesian_mesh(nx,ny,llm,nqdyn,nx*dx,ny*dx,0.)
94xx,ll = mesh.xx[:,0,:]/1000, mesh.ll[:,0,:]
95
96#metric, thermo, BC, m0ik, gas0, Phi0_il, u0_jk = DCMIP.DCMIP31(Lx, nx, llm, deform=deform, dTheta=1.)
97metric, thermo, BC, m0ik, gas0, Phi0_il, u0_jk = DCMIP.DCMIP21(Lx, nx, llm, deform=deform, h0=0.)
98
99BC.rho_bot = 1e6*BC.rho_bot # large stiffness
100
101mass_bl,mass_dak,mass_dbk = unst.compute_hybrid_coefs(m0ik)
102unst.init_hybrid(mass_bl,mass_dak,mass_dbk)
103
104run(mesh,metric,thermo,BC,unst.eta_mass,20.,  m0ik,gas0,Phi0_il, courant=2.) # lower courant number required if h0=2000m
105#run(mesh,metric,thermo,BC,unst.eta_lag,20.,  m0ik,gas0,Phi0_il)
Note: See TracBrowser for help on using the repository browser.