-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriver_code.f90
367 lines (314 loc) · 13.1 KB
/
driver_code.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
!>@author
!>Paul Connolly, The University of Manchester
!>@brief
!>drivers and physics code for the thermal cloud model
module drivers
use numerics_type
use variables
private
public :: model_driver_2d
contains
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>calls IO and runs model microphysics and advection for a number of steps
!>writes to output file, solves for the microphysics over one time-step,
!> then advects particles
!>@param[in] nq: number of q fields
!>@param[in] nprec: number of precipitation arrays
!>@param[in] ncat: number of categories
!>@param[in] n_mode: number of modes
!>@param[in] ip: number of horizontal levels
!>@param[in] kp: number of vertical levels
!>@param[in] ord: order of advection scheme
!>@param[in] o_halo: halos required for advection scheme
!>@param[in] runtime
!>@param[in] dt - timestep
!>@param[in] cvis: coefficient for viscosity
!>@param[in] c_s, c_e: start and end indices for a category
!>@param[in] inc, iqc, inr, iqr, ini, iqi, iai: indices for cloud number and mass
!>@param[in] cat_am,cat_c, cat_r, cat_i: category index for cloud and rain, ice
!>@param[in] q_name: name of categories
!>@param[in] dx,dz - grid spacing
!>@param[in] dx2,dz2 - grid spacing
!>@param[inout] q, qold, theta, th_old, pressure,
!> x,xn,z,zn, temperature, rho, u,w, delsq, vis
!>@param[inout] precip
!>@param[inout] new_file
!>@param[inout] micro_init - flag to initialise microphysics
!>@param[in] advection_scheme
!>@param[in] monotone - flag for monotonic advection
!>@param[in] viscous_dissipation - flag for smagorinsky-lilly scheme
!>@param[in] microphysics_flag - flag for calling microphysics
!>@param[in] ice_flag - flag for ice microphysics on / off
!>@param[in] hm_flag - flag for switching on / off hm process
!>@param[in] wr_flag - flag for switching on / off warm rain process
!>@param[in] rm_flag - flag for switching on / off riming process
!>@param[in] theta_flag - flag for advecting theta dry
!>@param[in] mass_ice - mass of a single ice crystal (override)
!>@param[in] output_interval - output interval
!>@param[inout] k
!>@param[inout] dsm_by_dz_z_eq_zc
!>@param[inout] b
!>@param[inout] del_gamma_mac
!>@param[inout] del_c_s
!>@param[inout] del_c_t
!>@param[inout] epsilon_therm
!>@param[in] w_peak
!>@param[in] z_offset
!>@param[inout] therm_init
subroutine model_driver_2d(nq,nprec,ncat, n_mode, &
ip,kp,ord,o_halo,runtime, &
dt,cvis, &
c_s, c_e, &
inc, iqc, inr, iqr, ini, iqi, iai, &
cat_am,cat_c, cat_r, cat_i, &
q_name, &
q,qold, precip,theta,th_old, p,dx,dz,dx2,dz2,x,xn,z,zn,t,rho,&
u,w,delsq, vis, &
new_file,micro_init,advection_scheme, monotone, &
viscous_dissipation, &
microphysics_flag,ice_flag, hm_flag,wr_flag, rm_flag, &
theta_flag,mass_ice, &
output_interval, &
! variables associated with thermal properties
k,dsm_by_dz_z_eq_zc,b,del_gamma_mac, &
del_c_s,del_c_t,epsilon_therm,w_peak,z_offset, therm_init)
use numerics_type
use thermal
use io_module
use advection_2d
use advection_s_2d, only : mpdata_2d, mpdata_vec_2d
use micro_module
use w_micro_module
use p_micro_module
implicit none
integer(i4b), intent(in) :: nq,nprec,ncat, ip,kp, ord, o_halo, advection_scheme, &
inc, iqc, inr, iqr, ini, iqi, iai, &
n_mode, cat_am,cat_c, cat_r, cat_i
real(wp), intent(in) :: runtime, output_interval, dt, dx,dz, cvis
integer(i4b), dimension(ncat), intent(in) :: c_s, c_e
character(len=20), dimension(nq) :: q_name
real(wp), dimension(-o_halo+1:kp+o_halo,-o_halo+1:ip+o_halo,nq), intent(inout) :: q, &
qold
real(wp), dimension(1:kp,1:ip,nprec), intent(inout) :: precip
real(wp), dimension(-o_halo+1:kp+o_halo), intent(inout) :: z,zn, dz2
real(wp), dimension(-o_halo+1:ip+o_halo), intent(inout) :: x,xn, dx2
real(wp), dimension(-o_halo+1:kp+o_halo,-o_halo+1:ip+o_halo), intent(inout) :: &
theta, th_old, p, t,rho,u,w
real(wp), dimension(1:kp,1:ip), intent(inout) :: delsq
real(wp), dimension(-o_halo+1:kp+o_halo,-o_halo+1:ip+o_halo), intent(inout) :: vis
logical, intent(inout) :: new_file, micro_init,therm_init
logical, intent(in) :: monotone,ice_flag, hm_flag,wr_flag, rm_flag, &
theta_flag, viscous_dissipation
integer(i4b), intent(in) :: microphysics_flag
real(wp), intent(in) :: mass_ice
! variables associated with thermals:
real(wp), intent(inout) :: k,dsm_by_dz_z_eq_zc,b,del_gamma_mac,del_c_s,del_c_t, &
epsilon_therm
real(wp), intent(in) :: w_peak, z_offset
! local variables
integer(i4b) :: nt, i, j, l,m,nsteps, iter
real(wp) :: time, time_last_output, output_time
real(wp), dimension(-o_halo+1:kp+o_halo,-o_halo+1:ip+o_halo) :: rhoa,theta_ref
! fudge because dynamics is solenoidal for rhoa=const
rhoa=1._wp
theta_ref=0._wp
time_last_output=-output_interval
output_time=output_interval
nt=ceiling(runtime / real(dt,kind=wp) )
do i=1,nt
time=real(i-1,wp)*dt
print *,'time-step ',i,' of ',nt, ' time=',time
! wind / thermal properties:
call thermal_2d(time,ip,kp,o_halo,k,dsm_by_dz_z_eq_zc, &
b,del_gamma_mac,del_c_s,del_c_t, &
epsilon_therm,x,xn,z,zn,dx,dz,u,w,w_peak,z_offset, therm_init)
if (time-time_last_output >= output_interval) then
! output:
call output_2d(time,nq,nprec,ip,kp,q_name, q(1:kp,1:ip,:),&
precip(1:kp,1:ip,:), &
theta(1:kp,1:ip),p(1:kp,1:ip), &
x(1:ip),xn(1:ip),z(1:kp),zn(1:kp), &
t(1:kp,1:ip),u(1:kp,1:ip),w(1:kp,1:ip),new_file)
time_last_output=time
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! advection !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
nsteps=ceiling(dt/(0.7_wp*dz)*maxval(sqrt(u**2+w**2)))
select case (advection_scheme)
case (0) ! upstream
do iter=1,nsteps
do j=1,nq
! set halos
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
! advection
call first_order_upstream_2d(dt/real(nsteps,wp), &
dx,dz,ip,kp,o_halo,u(:,:),w(:,:), &
q(:,:,j))
enddo
if(theta_flag) then
! set halos
call set_halos_2d(ip,kp,o_halo,theta)
! advection
call first_order_upstream_2d(dt/real(nsteps,wp), &
dx,dz,ip,kp,o_halo,u(:,:),w(:,:), &
theta(:,:))
endif
enddo
case(1) ! mpdata
do iter=1,nsteps
do j=1,nq
! set halos
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
! advection
call mpdata(4,ip,kp,o_halo,xn,zn,dx,dz,dt/real(nsteps,wp),u(:,:), &
w(:,:),q(:,:,j),monotone)
enddo
if(theta_flag) then
! set halos
call set_halos_2d(ip,kp,o_halo,theta)
! advection
call mpdata(4,ip,kp,o_halo,xn,zn,dx,dz,dt/real(nsteps,wp),u(:,:), &
w(:,:),theta(:,:),monotone)
endif
enddo
case(2) ! mpdata
do iter=1,nsteps
do j=1,nq
! set halos
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
! advection
call mpdata_2d(dt/real(nsteps,wp),dx2,dz2,dx2,dz2,&
rhoa(:,1),rhoa(:,1),&
ip,kp,o_halo,o_halo,u,w,q(:,:,j),4,monotone,0)
enddo
if(theta_flag) then
! set halos
call set_halos_2d(ip,kp,o_halo,theta)
! advection
call mpdata_2d(dt/real(nsteps,wp),dx2,dz2,dx2,dz2,&
rhoa(:,1),rhoa(:,1),&
ip,kp,o_halo,o_halo,u,w,theta(:,:),4,monotone,0)
endif
enddo
case(3) ! mpdata sfvt
do iter=1,nsteps
do j=1,nq
! set halos
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
enddo
do j=1,ncat
! advection sfvt
call mpdata_vec_2d(dt/real(nsteps,wp),dx2,dz2,dx2,dz2,&
rhoa(:,1),rhoa(:,1),&
ip,kp,c_e(j)-c_s(j)+1,o_halo,o_halo,u,w,&
q(:,:,c_s(j):c_e(j)),4,monotone,0)
enddo
if(theta_flag) then
! set halos
call set_halos_2d(ip,kp,o_halo,theta)
! advection
call mpdata_2d(dt/real(nsteps,wp),dx2,dz2,dx2,dz2,&
rhoa(:,1),rhoa(:,1),&
ip,kp,o_halo,o_halo,u,w,theta(:,:),4,monotone,0)
endif
enddo
case default
print *, 'error'
stop
end select
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! mixing !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(viscous_dissipation) then
call smagorinsky(ip,kp,o_halo,cvis,u,w,vis,dx,dz)
call set_halos_2d(ip,kp,o_halo,vis)
do l=1,5
call set_halos_2d(ip,kp,o_halo,theta)
do j=1,nq
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
enddo
! set previous values (for dissipation)
qold=q
th_old=theta
! call dissipation(ip,kp,o_halo,dt,0.5_wp*(theta+th_old),delsq,dx,dz)
call dissipation(ip,kp,o_halo,dt,theta,delsq,vis,dx,dz)
theta(1:kp,1:ip)=theta(1:kp,1:ip)+dt/5._wp*delsq
if(microphysics_flag.le.3) then
do j=1,nq
call set_halos_2d(ip,kp,o_halo,q(:,:,j))
! call dissipation(ip,kp,o_halo,dt,0.5_wp*(q(:,:,j)+qold(:,:,j)), &
! delsq,dx,dz)
call dissipation(ip,kp,o_halo,dt,q(:,:,j), &
delsq,vis,dx,dz)
q(1:kp,1:ip,j)=q(1:kp,1:ip,j)+dt/5._wp*&
delsq(1:kp,1:ip)
enddo
endif
if((microphysics_flag .eq. 2).or.(microphysics_flag .eq. 3)) then
! inhomogeneous mixing assumption:
q(1:kp,1:ip,inc)=&
min(max( qold(1:kp,1:ip,inc)* &
(q(1:kp,1:ip,iqc)/qold(1:kp,1:ip,iqc)+1.e-15_wp),0._wp), &
q(1:kp,1:ip,inc))
! add the aerosol in cloud water to aerosol
endif
th_old=theta
qold=q
enddo
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! solve microphysics. initialise constants that are commonly used, if needed
if (microphysics_flag .eq. 1) then
call microphysics_2d(nq,ip,kp,o_halo,dt,dz,q(:,:,:),precip(:,:,:),&
theta(:,:),p(:,:), &
zn(:),theta_ref,rho(:,:),w(:,:),micro_init,hm_flag,mass_ice, &
theta_flag)
else if (microphysics_flag .eq. 2) then
call w_microphysics_2d(nq,ip,kp,o_halo,dt,dz,q(:,:,:),precip(:,:,:),&
theta(:,:),p(:,:), &
zn(:),theta_ref,rho(:,:),w(:,:),micro_init,hm_flag,mass_ice, &
theta_flag)
else if (microphysics_flag .eq. 3) then
call p_microphysics_2d(nq,ncat,n_mode,c_s,c_e, inc, iqc,inr,iqr,&
ini,iqi,iai,cat_am,cat_c, cat_r, cat_i,nprec,&
ip,kp,o_halo,dt,dz2,dz2,q(:,:,:),precip(:,:,:),&
theta(:,:),p(:,:), &
zn(:),theta_ref,&
rho(:,:),rho(:,:),w(:,:),micro_init,hm_flag,mass_ice, &
ice_flag, wr_flag, rm_flag,theta_flag,0.0_wp,1,0,0,0,.false., &
.false.,.true.)
endif
enddo
end subroutine model_driver_2d
!>@author
!>Paul J. Connolly, The University of Manchester
!>@brief
!>set halos 2-d
!>@param[in] ip, kp: number of grid points
!>@param[in] o_halo: halos required for advection scheme
!>@param[inout] psi: field to set
subroutine set_halos_2d(ip,kp,o_halo,psi)
use numerics_type
implicit none
! arguments:
integer(i4b), intent(in) :: ip, kp, o_halo
real(wp), dimension(-o_halo+1:kp+o_halo,-o_halo+1:ip+o_halo), intent(inout) :: psi
integer(i4b) :: i,k
do i=1,ip
! top
psi(kp+1:kp+o_halo,i)=psi(kp,i)
! bottom
psi(-o_halo+1:0,i)=psi(1,i)
enddo
do k=1,kp
! left
psi(k,-o_halo+1:0)=psi(k,ip-o_halo+1:ip)
! right
psi(k,ip+1:ip+o_halo)=psi(k,1:o_halo)
enddo
end subroutine set_halos_2d
end module drivers