-
Notifications
You must be signed in to change notification settings - Fork 400
Expand file tree
/
Copy pathmpas_atm_iau.F
More file actions
263 lines (205 loc) · 11.1 KB
/
mpas_atm_iau.F
File metadata and controls
263 lines (205 loc) · 11.1 KB
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
! Copyright (c) 2016, Los Alamos National Security, LLC (LANS)
! and the University Corporation for Atmospheric Research (UCAR).
!
! Unless noted otherwise source code is licensed under the BSD license.
! Additional copyright and license information can be found in the LICENSE file
! distributed with this code, or at http://mpas-dev.github.com/license.html
!
#ifdef MPAS_OPENACC
#define MPAS_ACC_TIMER_START(X) call mpas_timer_start(X)
#define MPAS_ACC_TIMER_STOP(X) call mpas_timer_stop(X)
#else
#define MPAS_ACC_TIMER_START(X)
#define MPAS_ACC_TIMER_STOP(X)
#endif
module mpas_atm_iau
use mpas_derived_types
use mpas_pool_routines
use mpas_kind_types
use mpas_dmpar
use mpas_constants
use mpas_log, only : mpas_log_write
use mpas_timer
!public :: atm_compute_iau_coef, atm_add_tend_anal_incr
contains
!==================================================================================================
real (kind=RKIND) function atm_iau_coef(configs, itimestep, dt) result(wgt_iau)
!==================================================================================================
! Compute the coefficient (or weight) for the IAU forcing at itimestep.
implicit none
type (mpas_pool_type), intent(in) :: configs
integer, intent(in) :: itimestep
real (kind=RKIND), intent(in) :: dt
integer :: nsteps_iau ! Total number of time steps where the IAU forcing is applied.
logical, parameter :: debug = .false.
character(len=StrKIND), pointer :: iau_opt
real (kind=RKIND), pointer :: time_window_sec
! type (mpas_pool_type), intent(in) :: configs
! type (MPAS_Time_type) :: startTime, stopTime ! for the entire model integration period
! type (MPAS_Time_type) :: time_begin, time_end ! for the IAU window
! type (MPAS_TimeInterval_type) :: runDuration
! integer :: local_err
! character(len=StrKIND), pointer :: config_start_time, config_run_duration, config_stop_time
! real (kind=RKIND), pointer :: time_window_sec, runtime_window
call mpas_pool_get_config(configs, 'config_IAU_option', iau_opt)
call mpas_pool_get_config(configs, 'config_IAU_window_length_s', time_window_sec)
! Initialization
wgt_iau = 0.
! For config_IAU_option /= 'off', we compute a weighting function here based on the time info in namelist.atmosphere.
! The default option (config_IAU_option = 'on') defines a constant forcing with the same weight
! (= config_IAU_window_length_s/config_dt + 1) during the IAU time window.
! The model is assumed to be further advanced after the forcing (or the filtering) applied (as a free run),
! we need to fill up the weighting function with zeros for the period from the end of the IAU window
! all the way to config_stop_time (or for the rest of config_run_duration).
! call mpas_pool_get_config(configs, 'config_start_time', config_start_time)
! call mpas_pool_get_config(configs, 'config_run_duration', config_run_duration)
! call mpas_pool_get_config(configs, 'config_stop_time', config_stop_time)
! call mpas_pool_get_config(configs, 'config_dt', config_dt)
! call mpas_pool_get_config(configs, 'config_IAU_window_length_s', time_window_sec)
if(trim(iau_opt) == 'on') then ! HA: We should be able to expand this for more options later on.
nsteps_iau = nint(time_window_sec / dt)
!if(debug) call mpas_log_write('atm_compute_iau_coef: nsteps_iau = $i', intArgs=(/nsteps_iau/))
if(itimestep <= nsteps_iau) then
!wgt_iau = 1./nsteps_iau
wgt_iau = 1.0_RKIND / time_window_sec
if(debug) call mpas_log_write('atm_compute_iau_coef: wgt_iau = $r', realArgs=(/wgt_iau/))
end if
end if
end function atm_iau_coef
!==================================================================================================
subroutine update_d2h_pre_add_tend_anal_incr(configs,structs)
!==================================================================================================
implicit none
type (mpas_pool_type), intent(in) :: configs
type (mpas_pool_type), intent(inout) :: structs
type (mpas_pool_type), pointer :: tend
type (mpas_pool_type), pointer :: state
type (mpas_pool_type), pointer :: diag
real (kind=RKIND), dimension(:,:), pointer :: rho_edge, rho_zz, theta_m
real(kind=RKIND),dimension(:,:,:), pointer :: scalars, tend_scalars
call mpas_pool_get_subpool(structs, 'tend', tend)
call mpas_pool_get_subpool(structs, 'state', state)
call mpas_pool_get_subpool(structs, 'diag', diag)
MPAS_ACC_TIMER_START('atm_srk3: physics ACC_data_xfer')
call mpas_pool_get_array(state, 'theta_m', theta_m, 1)
call mpas_pool_get_array(state, 'scalars', scalars, 1)
call mpas_pool_get_array(state, 'rho_zz', rho_zz, 2)
call mpas_pool_get_array(diag , 'rho_edge', rho_edge)
!$acc update self(theta_m, scalars, rho_zz, rho_edge)
call mpas_pool_get_array(tend, 'scalars_tend', tend_scalars)
!$acc update self(tend_scalars)
MPAS_ACC_TIMER_STOP('atm_srk3: physics ACC_data_xfer')
end subroutine update_d2h_pre_add_tend_anal_incr
!==================================================================================================
subroutine atm_add_tend_anal_incr (configs, structs, itimestep, dt, tend_ru, tend_rtheta, tend_rho)
!==================================================================================================
implicit none
type (mpas_pool_type), intent(in) :: configs
type (mpas_pool_type), intent(inout) :: structs
integer, intent(in) :: itimestep
real (kind=RKIND), intent(in) :: dt
real (kind=RKIND), dimension(:,:), intent(inout) :: tend_ru
real (kind=RKIND), dimension(:,:), intent(inout) :: tend_rtheta
real (kind=RKIND), dimension(:,:), intent(inout) :: tend_rho
type (mpas_pool_type), pointer :: tend
type (mpas_pool_type), pointer :: tend_iau
type (mpas_pool_type), pointer :: state
type (mpas_pool_type), pointer :: diag
type (mpas_pool_type), pointer :: mesh
integer :: iEdge, iCell, i, j, k, n
integer, pointer :: nCells, nEdges, nCellsSolve, nEdgesSolve, nVertLevels
integer, pointer:: index_qv
integer, pointer:: moist_start, moist_end
real (kind=RKIND), dimension(:,:), pointer :: rho_edge, rho_zz, theta_m, theta, u, zz, &
tend_th, tend_w
! tend_u, tend_rho, tend_theta, tend_th, tend_w
real(kind=RKIND),dimension(:,:,:), pointer :: scalars, tend_scalars, scalars_amb
real(kind=RKIND),dimension(:,:), pointer:: u_amb, theta_amb, rho_amb
real (kind=RKIND) :: wgt_iau
!
! Compute weight for IAU forcing in this timestep, and return if weight
! is essentially zero.
!
wgt_iau = atm_iau_coef(configs, itimestep, dt)
if (wgt_iau <= 1.0e-12_RKIND) then
return
end if
call mpas_pool_get_subpool(structs, 'tend', tend)
call mpas_pool_get_subpool(structs, 'tend_iau', tend_iau)
call mpas_pool_get_subpool(structs, 'state', state)
call mpas_pool_get_subpool(structs, 'diag', diag)
call mpas_pool_get_subpool(structs, 'mesh', mesh)
call mpas_pool_get_dimension(mesh, 'nCells', nCells)
call mpas_pool_get_dimension(mesh, 'nEdges', nEdges)
call mpas_pool_get_dimension(mesh, 'nCellsSolve', nCellsSolve)
call mpas_pool_get_dimension(mesh, 'nEdgesSolve', nEdgesSolve)
call mpas_pool_get_dimension(mesh, 'nVertLevels', nVertLevels)
call mpas_pool_get_array(mesh, 'zz', zz)
call mpas_pool_get_array(state, 'theta_m', theta_m, 1)
call mpas_pool_get_array(state, 'scalars', scalars, 1)
call mpas_pool_get_array(state, 'rho_zz', rho_zz, 2)
call mpas_pool_get_array(diag , 'rho_edge', rho_edge)
call mpas_pool_get_dimension(state, 'moist_start', moist_start)
call mpas_pool_get_dimension(state, 'moist_end', moist_end)
call mpas_pool_get_dimension(state, 'index_qv', index_qv)
! Joe did not recommend to add w tendecies in IAU.
!call mpas_pool_get_array(tend, 'w', tend_w)
! call mpas_pool_get_array(tend, 'u', tend_u)
! call mpas_pool_get_array(tend, 'rho_zz', tend_rho)
! call mpas_pool_get_array(tend, 'theta_m', tend_theta)
call mpas_pool_get_array(tend, 'scalars_tend', tend_scalars)
call mpas_pool_get_array(tend_iau, 'theta', theta_amb)
call mpas_pool_get_array(tend_iau, 'rho', rho_amb)
call mpas_pool_get_array(tend_iau, 'u', u_amb)
call mpas_pool_get_array(tend_iau, 'scalars', scalars_amb)
!call mpas_pool_get_array(tend_iau, 'w', w_amb)
allocate(theta(nVertLevels,nCellsSolve) )
allocate(tend_th(nVertLevels,nCellsSolve))
! initialize the tendency for potential temperature
tend_th = 0._RKIND
! call mpas_log_write('atm_add_tend_anal_incr: wgt_iau = $r', realArgs=(/wgt_iau/))
! add coupled tendencies for u on edges
do i = 1, nEdgesSolve
do k = 1, nVertLevels
tend_ru(k,i) = tend_ru(k,i) + wgt_iau * rho_edge(k,i) * u_amb(k,i)
enddo
enddo
! add tendencies for rho_zz (instead of rho)
do i = 1, nCellsSolve
do k = 1, nVertLevels
tend_rho(k,i) = tend_rho(k,i) + wgt_iau * rho_amb(k,i)/zz(k,i)
enddo
enddo
! add tendencies for w (tend_w = 0 at k=1 and k=nVertLevelsP1) - Not tested yet
! do i = 1, nCellsSolve
! do k = 2, nVertLevels
! tend_w(k,i) = tend_w(k,i) + wgt_iau * w_amb(k,i)*rho_zz(k,i)
! enddo
! enddo
do i = 1, nCellsSolve
do k = 1, nVertLevels
theta(k,i) = theta_m(k,i) / (1._RKIND + rvord * scalars(index_qv,k,i))
enddo
enddo
! add coupled tendencies for other state variables on cell centers
do i = 1, nCellsSolve
do k = 1, nVertLevels
tend_th(k,i) = tend_th(k,i) + wgt_iau * (theta_amb(k,i)*rho_zz(k,i) + theta(k,i)*rho_amb(k,i)/zz(k,i))
tend_scalars(moist_start:moist_end,k,i) = tend_scalars(moist_start:moist_end,k,i) &
+ wgt_iau * (scalars_amb(moist_start:moist_end,k,i)*rho_zz(k,i) + scalars(moist_start:moist_end,k,i)*rho_amb(k,i)/zz(k,i))
enddo
enddo
!if non-hydrostatic core, convert the tendency for the potential temperature to a
!tendency for the modified potential temperature
do i = 1, nCellsSolve
do k = 1, nVertLevels
tend_th(k,i) = (1. + rvord * scalars(index_qv,k,i)) * tend_th(k,i) &
+ rvord * theta(k,i) * tend_scalars(index_qv,k,i)
tend_rtheta(k,i) = tend_rtheta(k,i) + tend_th(k,i)
enddo
enddo
deallocate(theta)
deallocate(tend_th)
end subroutine atm_add_tend_anal_incr
!==================================================================================================
end module mpas_atm_iau