source: codes/icosagcm/devel/Python/test/py/slice_GW_hydro.py @ 622

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

devel : tests for unstructured-mesh prototype

File size: 2.0 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, m0ik,gas0):
14    caldyn_thermo = unst.thermo_entropy
15    g = mesh.dx/metric.dx_g0
16    caldyn = unst.Caldyn_HPE(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),:] = 100.*mesh.dx # Doppler shift 100 m/s
28    flow0=(m0ik,S0ik,u0)
29
30    #T, courant = 60., 1.
31    T, courant = 60., 2.9
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    flow=flow0
40    for i in range(10):
41        time1=time.time()
42        flow = scheme.advance(flow,nt)
43        time2=time.time()
44        m,S,u = flow
45        print 'ms per time step : ', 1000*(time2-time1)/nt
46        print 'ptop, model top (m) :', unst.getvar('ptop'), caldyn.geopot.max()/unst.getvar('g')
47        junk,fast,slow = caldyn.bwd_fast_slow(flow, 0.)
48        zz=caldyn.geopot[:,0:llm]/metric.g0/1000
49        plt.figure(figsize=(12,3))
50        ucomp = mesh.ucomp(u)
51        plt.pcolor(xx,zz,ucomp[0,:,:]/dx)
52        plt.ylim(0,10.)
53        plt.colorbar()
54        plt.title("u(t = %f s)" % ((i+1)*dt*nt))
55        plt.savefig('fig_slice_GW_hydro/%02d.png'%i)
56        plt.close()
57
58Lx, nx, llm = 3e5, 300, 20
59nqdyn, ny, dx = 1, 1, Lx/nx
60mesh = unst.Cartesian_mesh(nx,ny,llm,nqdyn,nx*dx,ny*dx,0.)
61xx,ll = mesh.xx[:,0,:]/1000, mesh.ll[:,0,:]
62metric, thermo, BC, m0ik, gas0, Phi0_il, u0_jk = DCMIP.DCMIP31(Lx, nx, llm)
63
64run(mesh,metric,thermo,BC,unst.eta_lag,  m0ik,gas0)
Note: See TracBrowser for help on using the repository browser.