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

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

devel/unstructured : more fixes to mixed precision

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