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

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

devel/unstructured : update some test cases

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