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

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

devel/Python : extract pure Python stuff from cython module unstructured.pyx

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