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

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

devel/unstructured : bubble test case with Fortran time stepping

File size: 2.7 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, m0ik,gas0):
15    caldyn_thermo = unst.thermo_entropy
16    g = mesh.dx/metric.dx_g0
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
37    m,S,u=flow0
38
39    if False: # time stepping in Python
40        caldyn = unst.Caldyn_HPE(caldyn_thermo,caldyn_eta, mesh,thermo,BC,g)
41        scheme = time_step.ARK2(caldyn.bwd_fast_slow, dt, a32=0.7)
42        #scheme = time_step.ARK3(caldyn.bwd_fast_slow, dt)
43        def next_flow(m,S,u):
44            m,S,u = scheme.advance((m,S,u),nt)
45            return m,S,u,caldyn.geopot
46    else: # time stepping in Fortran
47        scheme = time_step.ARK2(None, dt, a32=0.7)
48        caldyn_step = unst.caldyn_step_HPE(mesh,scheme,nt, caldyn_thermo,caldyn_eta,thermo,BC,g)
49        def next_flow(m,S,u):
50            caldyn_step.mass[:,:], caldyn_step.theta_rhodz[:,:], caldyn_step.u[:,:] = m,S,u
51            caldyn_step.next()
52            return caldyn_step.mass, caldyn_step.theta_rhodz, caldyn_step.u, caldyn_step.geopot
53       
54    for i in range(10):
55        time1=time.time()
56        m,S,u,geopot = next_flow(m,S,u)
57        time2=time.time()
58        print 'ms per time step : ', 1000*(time2-time1)/nt, 1000*unst.getvar('elapsed')/(nt*(i+1))
59        print 'ptop, model top (m) :', unst.getvar('ptop'), geopot.max()/unst.getvar('g')
60        #        junk,fast,slow = caldyn.bwd_fast_slow(flow, 0.)
61        zz=geopot[:,0:llm]/metric.g0/1000
62        plt.figure(figsize=(12,3))
63        ucomp = mesh.ucomp(u)
64        plt.pcolor(xx,zz,ucomp[0,:,:]/dx)
65        plt.ylim(0,10.)
66        plt.colorbar()
67        plt.title("u(t = %f s)" % ((i+1)*dt*nt))
68        plt.savefig('fig_slice_GW_hydro/%02d.png'%i)
69        plt.close()
70
71Lx, nx, llm = 3e5, 300, 20
72nqdyn, ny, dx = 1, 1, Lx/nx
73mesh = Mesh(nx,ny,llm,nqdyn,nx*dx,ny*dx,0.)
74xx,ll = mesh.xx[:,0,:]/1000, mesh.ll[:,0,:]
75metric, thermo, BC, m0ik, gas0, Phi0_il, u0_jk = DCMIP.DCMIP31(Lx, nx, llm)
76
77run(mesh,metric,thermo,BC,unst.eta_lag,  m0ik,gas0)
Note: See TracBrowser for help on using the repository browser.