MONC
flux_budget.F90
Go to the documentation of this file.
1 
11  use state_mod, only : model_state_type
13  implicit none
14 
15 #ifndef TEST_MODE
16  private
17 #endif
18 
19  real(kind=default_precision), dimension(:), allocatable :: th_flux_values, th_gradient, th_diff, th_buoyancy, th_tendency, &
32  real(kind=default_precision), dimension(:,:), allocatable :: q_flux_values, q_gradient, q_diff, q_buoyancy, q_tendency
35 
39 
41 
43 contains
44 
48  type(iterator_type) :: iterator
49  type(mapentry_type) :: mapentry
50  integer :: current_index, total_number_published_fields
51 
52  flux_budget_get_descriptor%name="flux_budget"
53  flux_budget_get_descriptor%version=0.1
57 
61  total_number_published_fields=c_size(heat_flux_fields) + c_size(q_flux_fields) + c_size(uw_vw_fields) + &
64  allocate(flux_budget_get_descriptor%published_fields(total_number_published_fields))
65 
66  current_index=1
68  do while (c_has_next(iterator))
69  mapentry=c_next_mapentry(iterator)
70  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
71  current_index=current_index+1
72  end do
74  do while (c_has_next(iterator))
75  mapentry=c_next_mapentry(iterator)
76  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
77  current_index=current_index+1
78  end do
80  do while (c_has_next(iterator))
81  mapentry=c_next_mapentry(iterator)
82  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
83  current_index=current_index+1
84  end do
85  iterator=c_get_iterator(tke_fields)
86  do while (c_has_next(iterator))
87  mapentry=c_next_mapentry(iterator)
88  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
89  current_index=current_index+1
90  end do
92  do while (c_has_next(iterator))
93  mapentry=c_next_mapentry(iterator)
94  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
95  current_index=current_index+1
96  end do
98  do while (c_has_next(iterator))
99  mapentry=c_next_mapentry(iterator)
100  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
101  current_index=current_index+1
102  end do
103  iterator=c_get_iterator(mse_fields)
104  do while (c_has_next(iterator))
105  mapentry=c_next_mapentry(iterator)
106  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
107  current_index=current_index+1
108  end do
109  iterator=c_get_iterator(qt_fields)
110  do while (c_has_next(iterator))
111  mapentry=c_next_mapentry(iterator)
112  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
113  current_index=current_index+1
114  end do
115  iterator=c_get_iterator(scalar_fields)
116  do while (c_has_next(iterator))
117  mapentry=c_next_mapentry(iterator)
118  flux_budget_get_descriptor%published_fields(current_index)=mapentry%key
119  current_index=current_index+1
120  end do
121  end function flux_budget_get_descriptor
122 
125  subroutine initialisation_callback(current_state)
126  type(model_state_type), target, intent(inout) :: current_state
127 
128  call initialise_theta_flux_diagnostics(current_state)
129  call initialise_q_flux_diagnostics(current_state)
130  call initialise_uw_vw_diagnostics(current_state)
131  call initialise_prognostic_budget_diagnostics(current_state)
132  call initialise_thetal_diagnostics(current_state)
133  call initialise_mse_diagnostics(current_state)
134  call initialise_qt_diagnostics(current_state)
135  call initialise_scalar_diagnostics(current_state)
136  call initialise_tke_diagnostics(current_state)
137  diagnostic_generation_frequency=options_get_integer(current_state%options_database, "sampling_frequency")
138  end subroutine initialisation_callback
139 
142  subroutine timestep_callback(current_state)
143  type(model_state_type), target, intent(inout) :: current_state
144 
145  if (mod(current_state%timestep, diagnostic_generation_frequency) == 0) then
146  if (current_state%first_timestep_column) then
155  call clear_scalars()
156  end if
157  if (.not. current_state%halo_column) then
164  if (some_qt_diagnostics_enabled) call compute_qt_for_column(current_state)
166  call compute_scalars_for_column(current_state)
167  end if
168  end if
169  end subroutine timestep_callback
170 
173  subroutine finalisation_callback(current_state)
174  type(model_state_type), target, intent(inout) :: current_state
175 
176  if (allocated(th_flux_values)) deallocate(th_flux_values)
177  if (allocated(th_gradient)) deallocate(th_gradient)
178  if (allocated(th_diff)) deallocate(th_diff)
179  if (allocated(th_buoyancy)) deallocate(th_buoyancy)
180  if (allocated(th_tendency)) deallocate(th_tendency)
181  if (allocated(q_flux_values)) deallocate(q_flux_values)
182  if (allocated(q_gradient)) deallocate(q_gradient)
183  if (allocated(q_diff)) deallocate(q_diff)
184  if (allocated(q_buoyancy)) deallocate(q_buoyancy)
185  if (allocated(q_tendency)) deallocate(q_tendency)
186 
187  if (allocated(uw_advection)) deallocate(uw_advection)
188  if (allocated(vw_advection)) deallocate(vw_advection)
189  if (allocated(uw_viscosity)) deallocate(uw_viscosity)
190  if (allocated(vw_viscosity)) deallocate(vw_viscosity)
191  if (allocated(uw_buoyancy)) deallocate(uw_buoyancy)
192  if (allocated(vw_buoyancy)) deallocate(vw_buoyancy)
193  if (allocated(uw_tendency)) deallocate(uw_tendency)
194  if (allocated(vw_tendency)) deallocate(vw_tendency)
195  if (allocated(uw_w)) deallocate(uw_w)
196  if (allocated(vw_w)) deallocate(vw_w)
197 
198  if (allocated(sres)) deallocate(sres)
199  if (allocated(buoy)) deallocate(buoy)
200  if (allocated(wke)) deallocate(wke)
201  if (allocated(wp)) deallocate(wp)
202  if (allocated(tend)) deallocate(tend)
203 
204  if (allocated(tu_su)) deallocate(tu_su)
205  if (allocated(uu_advection)) deallocate(uu_advection)
206  if (allocated(uu_viscosity)) deallocate(uu_viscosity)
207  if (allocated(wu_u)) deallocate(wu_u)
208  if (allocated(tv_sv)) deallocate(tv_sv)
209  if (allocated(vv_advection)) deallocate(vv_advection)
210  if (allocated(vv_viscosity)) deallocate(vv_viscosity)
211  if (allocated(wv_v)) deallocate(wv_v)
212  if (allocated(tw_sw)) deallocate(tw_sw)
213  if (allocated(ww_advection)) deallocate(ww_advection)
214  if (allocated(ww_viscosity)) deallocate(ww_viscosity)
215  if (allocated(ww_buoyancy)) deallocate(ww_buoyancy)
216 
217  if (allocated(u_thetal)) deallocate(u_thetal)
218  if (allocated(us_thetal)) deallocate(us_thetal)
219  if (allocated(u_thetal_advection)) deallocate(u_thetal_advection)
221  if (allocated(wu_thetal)) deallocate(wu_thetal)
222  if (allocated(v_thetal)) deallocate(v_thetal)
223  if (allocated(vs_thetal)) deallocate(vs_thetal)
224  if (allocated(v_thetal_advection)) deallocate(v_thetal_advection)
226  if (allocated(wv_thetal)) deallocate(wv_thetal)
227  if (allocated(w_thetal)) deallocate(w_thetal)
228  if (allocated(ws_thetal)) deallocate(ws_thetal)
229  if (allocated(w_thetal_advection)) deallocate(w_thetal_advection)
231  if (allocated(w_thetal_buoyancy)) deallocate(w_thetal_buoyancy)
232  if (allocated(ww_thetal)) deallocate(ww_thetal)
233  if (allocated(thetal_thetal)) deallocate(thetal_thetal)
234  if (allocated(sthetal_thetal)) deallocate(sthetal_thetal)
235  if (allocated(thetal_thetal_advection)) deallocate(thetal_thetal_advection)
236  if (allocated(thetal_thetal_diffusion)) deallocate(thetal_thetal_diffusion)
237  if (allocated(wthetal_thetal)) deallocate(wthetal_thetal)
238 
239  if (allocated(u_mse)) deallocate(u_mse)
240  if (allocated(us_mse)) deallocate(us_mse)
241  if (allocated(u_mse_advection)) deallocate(u_mse_advection)
242  if (allocated(u_mse_viscosity_diffusion)) deallocate(u_mse_viscosity_diffusion)
243  if (allocated(wu_mse)) deallocate(wu_mse)
244  if (allocated(v_mse)) deallocate(v_mse)
245  if (allocated(vs_mse)) deallocate(vs_mse)
246  if (allocated(v_mse_advection)) deallocate(v_mse_advection)
247  if (allocated(v_mse_viscosity_diffusion)) deallocate(v_mse_viscosity_diffusion)
248  if (allocated(wv_mse)) deallocate(wv_mse)
249  if (allocated(w_mse)) deallocate(w_mse)
250  if (allocated(ws_mse)) deallocate(ws_mse)
251  if (allocated(w_mse_advection)) deallocate(w_mse_advection)
252  if (allocated(w_mse_viscosity_diffusion)) deallocate(w_mse_viscosity_diffusion)
253  if (allocated(w_mse_buoyancy)) deallocate(w_mse_buoyancy)
254  if (allocated(ww_mse)) deallocate(ww_mse)
255  if (allocated(mse_mse)) deallocate(mse_mse)
256  if (allocated(smse_mse)) deallocate(smse_mse)
257  if (allocated(mse_mse_advection)) deallocate(mse_mse_advection)
258  if (allocated(mse_mse_diffusion)) deallocate(mse_mse_diffusion)
259  if (allocated(wmse_mse)) deallocate(wmse_mse)
260 
261  if (allocated(us_qt)) deallocate(us_qt)
262  if (allocated(u_qt_advection)) deallocate(u_qt_advection)
263  if (allocated(u_qt_viscosity_diffusion)) deallocate(u_qt_viscosity_diffusion)
264  if (allocated(wu_qt)) deallocate(wu_qt)
265  if (allocated(vs_qt)) deallocate(vs_qt)
266  if (allocated(v_qt_advection)) deallocate(v_qt_advection)
267  if (allocated(v_qt_viscosity_diffusion)) deallocate(v_qt_viscosity_diffusion)
268  if (allocated(wv_qt)) deallocate(wv_qt)
269  if (allocated(w_qt)) deallocate(w_qt)
270  if (allocated(ws_qt)) deallocate(ws_qt)
271  if (allocated(w_qt_advection)) deallocate(w_qt_advection)
272  if (allocated(w_qt_viscosity_diffusion)) deallocate(w_qt_viscosity_diffusion)
273  if (allocated(w_qt_buoyancy)) deallocate(w_qt_buoyancy)
274  if (allocated(ww_qt)) deallocate(ww_qt)
275  if (allocated(qt_qt)) deallocate(qt_qt)
276  if (allocated(sqt_qt)) deallocate(sqt_qt)
277  if (allocated(qt_qt_advection)) deallocate(qt_qt_advection)
278  if (allocated(qt_qt_diffusion)) deallocate(qt_qt_diffusion)
279  if (allocated(wqt_qt)) deallocate(wqt_qt)
280  end subroutine finalisation_callback
281 
283  subroutine populate_field_names()
284  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_transport_local", .false.)
285  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_gradient_local", .false.)
286  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_dissipation_local", .false.)
287  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_buoyancy_local", .false.)
288  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_tendency_local", .false.)
289 
290  call set_published_field_enabled_state(q_flux_fields, "q_flux_transport_local", .false.)
291  call set_published_field_enabled_state(q_flux_fields, "q_flux_gradient_local", .false.)
292  call set_published_field_enabled_state(q_flux_fields, "q_flux_dissipation_local", .false.)
293  call set_published_field_enabled_state(q_flux_fields, "q_flux_buoyancy_local", .false.)
294  call set_published_field_enabled_state(q_flux_fields, "q_flux_tendency_local", .false.)
295 
296  call set_published_field_enabled_state(tke_fields, "resolved_shear_production_local", .false.)
297  call set_published_field_enabled_state(tke_fields, "resolved_buoyant_production_local", .false.)
298  call set_published_field_enabled_state(tke_fields, "resolved_turbulent_transport_local", .false.)
299  call set_published_field_enabled_state(tke_fields, "resolved_pressure_transport_local", .false.)
300  call set_published_field_enabled_state(tke_fields, "tke_tendency_local", .false.)
301 
302  call set_published_field_enabled_state(uw_vw_fields, "uw_advection_local", .false.)
303  call set_published_field_enabled_state(uw_vw_fields, "vw_advection_local", .false.)
304  call set_published_field_enabled_state(uw_vw_fields, "uw_viscosity_local", .false.)
305  call set_published_field_enabled_state(uw_vw_fields, "vw_viscosity_local", .false.)
306  call set_published_field_enabled_state(uw_vw_fields, "uw_buoyancy_local", .false.)
307  call set_published_field_enabled_state(uw_vw_fields, "vw_buoyancy_local", .false.)
308  call set_published_field_enabled_state(uw_vw_fields, "uw_tendency_local", .false.)
309  call set_published_field_enabled_state(uw_vw_fields, "vw_tendency_local", .false.)
310  call set_published_field_enabled_state(uw_vw_fields, "uw_w_local", .false.)
311  call set_published_field_enabled_state(uw_vw_fields, "vw_w_local", .false.)
312 
313  call set_published_field_enabled_state(prognostic_budget_fields, "tu_su_local", .false.)
314  call set_published_field_enabled_state(prognostic_budget_fields, "uu_advection_local", .false.)
315  call set_published_field_enabled_state(prognostic_budget_fields, "uu_viscosity_local", .false.)
317  call set_published_field_enabled_state(prognostic_budget_fields, "tv_sv_local", .false.)
318  call set_published_field_enabled_state(prognostic_budget_fields, "vv_advection_local", .false.)
319  call set_published_field_enabled_state(prognostic_budget_fields, "vv_viscosity_local", .false.)
321  call set_published_field_enabled_state(prognostic_budget_fields, "tw_sw_local", .false.)
322  call set_published_field_enabled_state(prognostic_budget_fields, "ww_advection_local", .false.)
323  call set_published_field_enabled_state(prognostic_budget_fields, "ww_viscosity_local", .false.)
324  call set_published_field_enabled_state(prognostic_budget_fields, "ww_buoyancy_local", .false.)
325 
326  call set_published_field_enabled_state(thetal_fields, "u_thetal_local", .false.)
327  call set_published_field_enabled_state(thetal_fields, "us_thetal_local", .false.)
328  call set_published_field_enabled_state(thetal_fields, "u_thetal_advection_local", .false.)
329  call set_published_field_enabled_state(thetal_fields, "u_thetal_viscosity_diffusion_local", .false.)
330  call set_published_field_enabled_state(thetal_fields, "wu_thetal_local", .false.)
331  call set_published_field_enabled_state(thetal_fields, "v_thetal_local", .false.)
332  call set_published_field_enabled_state(thetal_fields, "vs_thetal_local", .false.)
333  call set_published_field_enabled_state(thetal_fields, "v_thetal_advection_local", .false.)
334  call set_published_field_enabled_state(thetal_fields, "v_thetal_viscosity_diffusion_local", .false.)
335  call set_published_field_enabled_state(thetal_fields, "wv_thetal_local", .false.)
336  call set_published_field_enabled_state(thetal_fields, "w_thetal_local", .false.)
337  call set_published_field_enabled_state(thetal_fields, "ws_thetal_local", .false.)
338  call set_published_field_enabled_state(thetal_fields, "w_thetal_advection_local", .false.)
339  call set_published_field_enabled_state(thetal_fields, "w_thetal_viscosity_diffusion_local", .false.)
340  call set_published_field_enabled_state(thetal_fields, "ww_thetal_buoyancy_local", .false.)
341  call set_published_field_enabled_state(thetal_fields, "ww_thetal_local", .false.)
342  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_local", .false.)
343  call set_published_field_enabled_state(thetal_fields, "sthetal_thetal_local", .false.)
344  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_advection_local", .false.)
345  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_diffusion_local", .false.)
346  call set_published_field_enabled_state(thetal_fields, "wthetal_thetal_local", .false.)
347 
348  call set_published_field_enabled_state(mse_fields, "u_mse_local", .false.)
349  call set_published_field_enabled_state(mse_fields, "us_mse_local", .false.)
350  call set_published_field_enabled_state(mse_fields, "u_mse_advection_local", .false.)
351  call set_published_field_enabled_state(mse_fields, "u_mse_viscosity_diffusion_local", .false.)
352  call set_published_field_enabled_state(mse_fields, "wu_mse_local", .false.)
353  call set_published_field_enabled_state(mse_fields, "v_mse_local", .false.)
354  call set_published_field_enabled_state(mse_fields, "vs_mse_local", .false.)
355  call set_published_field_enabled_state(mse_fields, "v_mse_advection_local", .false.)
356  call set_published_field_enabled_state(mse_fields, "v_mse_viscosity_diffusion_local", .false.)
357  call set_published_field_enabled_state(mse_fields, "wv_mse_local", .false.)
358  call set_published_field_enabled_state(mse_fields, "w_mse_local", .false.)
359  call set_published_field_enabled_state(mse_fields, "ws_mse_local", .false.)
360  call set_published_field_enabled_state(mse_fields, "w_mse_advection_local", .false.)
361  call set_published_field_enabled_state(mse_fields, "w_mse_viscosity_diffusion_local", .false.)
362  call set_published_field_enabled_state(mse_fields, "ww_mse_buoyancy_local", .false.)
363  call set_published_field_enabled_state(mse_fields, "ww_mse_local", .false.)
364  call set_published_field_enabled_state(mse_fields, "mse_mse_local", .false.)
365  call set_published_field_enabled_state(mse_fields, "smse_mse_local", .false.)
366  call set_published_field_enabled_state(mse_fields, "mse_mse_advection_local", .false.)
367  call set_published_field_enabled_state(mse_fields, "mse_mse_diffusion_local", .false.)
368  call set_published_field_enabled_state(mse_fields, "wmse_mse_local", .false.)
369 
370  call set_published_field_enabled_state(qt_fields, "us_qt_local", .false.)
371  call set_published_field_enabled_state(qt_fields, "u_qt_advection_local", .false.)
372  call set_published_field_enabled_state(qt_fields, "u_qt_viscosity_diffusion_local", .false.)
373  call set_published_field_enabled_state(qt_fields, "wu_qt_local", .false.)
374  call set_published_field_enabled_state(qt_fields, "vs_qt_local", .false.)
375  call set_published_field_enabled_state(qt_fields, "v_qt_advection_local", .false.)
376  call set_published_field_enabled_state(qt_fields, "v_qt_viscosity_diffusion_local", .false.)
377  call set_published_field_enabled_state(qt_fields, "wv_qt_local", .false.)
378  call set_published_field_enabled_state(qt_fields, "w_qt_local", .false.)
379  call set_published_field_enabled_state(qt_fields, "ws_qt_local", .false.)
380  call set_published_field_enabled_state(qt_fields, "w_qt_advection_local", .false.)
381  call set_published_field_enabled_state(qt_fields, "w_qt_viscosity_diffusion_local", .false.)
382  call set_published_field_enabled_state(qt_fields, "ww_qt_buoyancy_local", .false.)
383  call set_published_field_enabled_state(qt_fields, "ww_qt_local", .false.)
384  call set_published_field_enabled_state(qt_fields, "qt_qt_local", .false.)
385  call set_published_field_enabled_state(qt_fields, "sqt_qt_local", .false.)
386  call set_published_field_enabled_state(qt_fields, "qt_qt_advection_local", .false.)
387  call set_published_field_enabled_state(qt_fields, "qt_qt_diffusion_local", .false.)
388  call set_published_field_enabled_state(qt_fields, "wqt_qt_local", .false.)
389 
390  call set_published_field_enabled_state(scalar_fields, "mflux_local", .true.)
391  end subroutine populate_field_names
392 
397  subroutine field_information_retrieval_callback(current_state, name, field_information)
398  type(model_state_type), target, intent(inout) :: current_state
399  character(len=*), intent(in) :: name
400  type(component_field_information_type), intent(out) :: field_information
401 
402  ! Field description is the same regardless of the specific field being retrieved
403  field_information%field_type=component_array_field_type
404  field_information%data_type=component_double_data_type
405 
406  if (is_field_heat_flux(name) .or. is_field_uw_vw(name) .or. is_field_prognostic_budget(name) &
407  .or. is_field_thetal(name) .or. is_field_mse(name) .or. is_field_qt(name) .or. is_field_scalar(name) &
408  .or. is_field_tke_flux(name)) then
409  field_information%number_dimensions=1
410  field_information%dimension_sizes(1)=current_state%local_grid%size(z_index)
411  if (is_field_heat_flux(name)) then
412  field_information%enabled=get_published_field_enabled_state(heat_flux_fields, name)
413  else if (is_field_uw_vw(name)) then
414  field_information%enabled=get_published_field_enabled_state(uw_vw_fields, name)
415  else if (is_field_prognostic_budget(name)) then
416  field_information%enabled=get_published_field_enabled_state(prognostic_budget_fields, name)
417  else if (is_field_thetal(name)) then
418  field_information%enabled=get_published_field_enabled_state(thetal_fields, name)
419  else if (is_field_tke_flux(name)) then
420  field_information%enabled=get_published_field_enabled_state(tke_fields, name)
421  else if (is_field_mse(name)) then
422  field_information%enabled=get_published_field_enabled_state(mse_fields, name)
423  else if (is_field_qt(name)) then
424  field_information%enabled=get_published_field_enabled_state(qt_fields, name)
425  else if (is_field_scalar(name)) then
426  field_information%enabled=get_published_field_enabled_state(scalar_fields, name)
427  end if
428  else if (is_field_q_flux(name)) then
429  field_information%number_dimensions=2
430  field_information%dimension_sizes(1)=current_state%local_grid%size(z_index)
431  field_information%dimension_sizes(2)=current_state%number_q_fields
432  field_information%enabled=get_published_field_enabled_state(q_flux_fields, name)
433  end if
435 
438  subroutine initialise_scalar_diagnostics(current_state)
439  type(model_state_type), target, intent(inout) :: current_state
440 
441  wmfcrit=options_get_real(current_state%options_database, "wmfcrit")
442  end subroutine initialise_scalar_diagnostics
443 
447  subroutine initialise_qt_diagnostics(current_state)
448  type(model_state_type), target, intent(inout) :: current_state
449 
450  integer :: column_size
451  logical :: us_qt_enabled, u_qt_advection_enabled, u_qt_viscosity_diffusion_enabled, &
452  wu_qt_enabled, vs_qt_enabled, v_qt_advection_enabled, &
453  v_qt_viscosity_diffusion_enabled, wv_qt_enabled, w_qt_enabled, ws_qt_enabled, &
454  w_qt_advection_enabled, w_qt_viscosity_diffusion_enabled, w_qt_buoyancy_enabled, ww_qt_enabled, &
455  qt_qt_enabled, sqt_qt_enabled, qt_qt_advection_enabled, &
456  qt_qt_diffusion_enabled, wqt_qt_enabled
457 
458  column_size=current_state%local_grid%size(z_index)
459 
460  us_qt_enabled=current_state%u%active .and. current_state%th%active
461  u_qt_advection_enabled=is_component_field_available("u_advection") .and. &
462  is_component_field_available("th_advection") .and. us_qt_enabled
463  u_qt_viscosity_diffusion_enabled=is_component_field_available("u_viscosity") .and. &
464  is_component_field_available("th_diffusion") .and. us_qt_enabled
465  wu_qt_enabled=current_state%w%active .and. us_qt_enabled
466 
467  some_qt_diagnostics_enabled=us_qt_enabled
468 
469  if (us_qt_enabled) then
470  call set_published_field_enabled_state(qt_fields, "us_qt_local", .true.)
471  allocate(us_qt(column_size))
472  end if
473  if (u_qt_advection_enabled) then
474  call set_published_field_enabled_state(qt_fields, "u_qt_advection_local", .true.)
475  allocate(u_qt_advection(column_size))
476  end if
477  if (u_qt_viscosity_diffusion_enabled) then
478  call set_published_field_enabled_state(qt_fields, "u_qt_viscosity_diffusion_local", .true.)
479  allocate(u_qt_viscosity_diffusion(column_size))
480  end if
481  if (wu_qt_enabled) then
482  call set_published_field_enabled_state(qt_fields, "wu_qt_local", .true.)
483  allocate(wu_qt(column_size))
484  end if
485 
486  vs_qt_enabled=current_state%v%active .and. current_state%th%active
487  v_qt_advection_enabled=is_component_field_available("v_advection") .and. &
488  is_component_field_available("th_advection") .and. vs_qt_enabled
489  v_qt_viscosity_diffusion_enabled=is_component_field_available("v_viscosity") .and. &
490  is_component_field_available("th_diffusion") .and. vs_qt_enabled
491  wv_qt_enabled=current_state%w%active .and. vs_qt_enabled
492 
494 
495  if (vs_qt_enabled) then
496  call set_published_field_enabled_state(qt_fields, "vs_qt_local", .true.)
497  allocate(vs_qt(column_size))
498  end if
499  if (v_qt_advection_enabled) then
500  call set_published_field_enabled_state(qt_fields, "v_qt_advection_local", .true.)
501  allocate(v_qt_advection(column_size))
502  end if
503  if (v_qt_viscosity_diffusion_enabled) then
504  call set_published_field_enabled_state(qt_fields, "v_qt_viscosity_diffusion_local", .true.)
505  allocate(v_qt_viscosity_diffusion(column_size))
506  end if
507  if (wv_qt_enabled) then
508  call set_published_field_enabled_state(qt_fields, "wv_qt_local", .true.)
509  allocate(wv_qt(column_size))
510  end if
511 
512  w_qt_enabled=current_state%w%active .and. current_state%th%active
513  ws_qt_enabled=w_qt_enabled
514  w_qt_advection_enabled=is_component_field_available("w_advection") .and. &
515  is_component_field_available("th_advection") .and. w_qt_enabled
516  w_qt_viscosity_diffusion_enabled=is_component_field_available("w_viscosity") .and. &
517  is_component_field_available("th_diffusion") .and. w_qt_enabled
518  w_qt_buoyancy_enabled=current_state%th%active .and. is_component_field_available("w_buoyancy")
519  ww_qt_enabled=w_qt_enabled
520 
522 
523  if (w_qt_enabled) then
524  call set_published_field_enabled_state(qt_fields, "w_qt_local", .true.)
525  allocate(w_qt(column_size))
526  end if
527  if (ws_qt_enabled) then
528  call set_published_field_enabled_state(qt_fields, "ws_qt_local", .true.)
529  allocate(ws_qt(column_size))
530  end if
531  if (w_qt_advection_enabled) then
532  call set_published_field_enabled_state(qt_fields, "w_qt_advection_local", .true.)
533  allocate(w_qt_advection(column_size))
534  end if
535  if (w_qt_viscosity_diffusion_enabled) then
536  call set_published_field_enabled_state(qt_fields, "w_qt_viscosity_diffusion_local", .true.)
537  allocate(w_qt_viscosity_diffusion(column_size))
538  end if
539  if (w_qt_buoyancy_enabled) then
540  call set_published_field_enabled_state(qt_fields, "w_qt_buoyancy_local", .true.)
541  allocate(w_qt_buoyancy(column_size))
542  end if
543  if (ww_qt_enabled) then
544  call set_published_field_enabled_state(qt_fields, "ww_qt_local", .true.)
545  allocate(ww_qt(column_size))
546  end if
547 
548  qt_qt_enabled=current_state%th%active
549  sqt_qt_enabled=qt_qt_enabled
550  qt_qt_advection_enabled=is_component_field_available("qt_advection") .and. qt_qt_enabled
551  qt_qt_diffusion_enabled=is_component_field_available("qt_diffusion") .and. qt_qt_enabled
552  wqt_qt_enabled=current_state%w%active .and. qt_qt_enabled
553 
555 
556  if (qt_qt_enabled) then
557  call set_published_field_enabled_state(qt_fields, "qt_qt_local", .true.)
558  allocate(qt_qt(column_size))
559  end if
560  if (sqt_qt_enabled) then
561  call set_published_field_enabled_state(qt_fields, "sqt_qt_local", .true.)
562  allocate(sqt_qt(column_size))
563  end if
564  if (qt_qt_advection_enabled) then
565  call set_published_field_enabled_state(qt_fields, "qt_qt_advection_local", .true.)
566  allocate(qt_qt_advection(column_size))
567  end if
568  if (qt_qt_diffusion_enabled) then
569  call set_published_field_enabled_state(qt_fields, "qt_qt_diffusion_local", .true.)
570  allocate(qt_qt_diffusion(column_size))
571  end if
572  if (wqt_qt_enabled) then
573  call set_published_field_enabled_state(qt_fields, "wqt_qt_local", .true.)
574  allocate(wqt_qt(column_size))
575  end if
576  end subroutine initialise_qt_diagnostics
577 
581  subroutine initialise_mse_diagnostics(current_state)
582  type(model_state_type), target, intent(inout) :: current_state
583 
584  integer :: column_size
585  logical :: u_mse_enabled, us_mse_enabled, u_mse_advection_enabled, u_mse_viscosity_diffusion_enabled, &
586  wu_mse_enabled, v_mse_enabled, vs_mse_enabled, v_mse_advection_enabled, &
587  v_mse_viscosity_diffusion_enabled, wv_mse_enabled, w_mse_enabled, ws_mse_enabled, &
588  w_mse_advection_enabled, w_mse_viscosity_diffusion_enabled, w_mse_buoyancy_enabled, ww_mse_enabled, &
589  mse_mse_enabled, smse_mse_enabled, mse_mse_advection_enabled, &
590  mse_mse_diffusion_enabled, wmse_mse_enabled
591 
592  column_size=current_state%local_grid%size(z_index)
593 
594  u_mse_enabled=current_state%u%active .and. current_state%th%active
595  us_mse_enabled=u_mse_enabled
596  u_mse_advection_enabled=is_component_field_available("u_advection") .and. &
597  is_component_field_available("th_advection") .and. u_mse_enabled
598  u_mse_viscosity_diffusion_enabled=is_component_field_available("u_viscosity") .and. &
599  is_component_field_available("th_diffusion") .and. u_mse_enabled
600  wu_mse_enabled=current_state%w%active .and. u_mse_enabled
601 
602  some_mse_diagnostics_enabled=u_mse_enabled
603 
604  if (u_mse_enabled) then
605  call set_published_field_enabled_state(mse_fields, "u_mse_local", .true.)
606  allocate(u_mse(column_size))
607  end if
608  if (us_mse_enabled) then
609  call set_published_field_enabled_state(mse_fields, "us_mse_local", .true.)
610  allocate(us_mse(column_size))
611  end if
612  if (u_mse_advection_enabled) then
613  call set_published_field_enabled_state(mse_fields, "u_mse_advection_local", .true.)
614  allocate(u_mse_advection(column_size))
615  end if
616  if (u_mse_viscosity_diffusion_enabled) then
617  call set_published_field_enabled_state(mse_fields, "u_mse_viscosity_diffusion_local", .true.)
618  allocate(u_mse_viscosity_diffusion(column_size))
619  end if
620  if (wu_mse_enabled) then
621  call set_published_field_enabled_state(mse_fields, "wu_mse_local", .true.)
622  allocate(wu_mse(column_size))
623  end if
624 
625  v_mse_enabled=current_state%v%active .and. current_state%th%active
626  vs_mse_enabled=v_mse_enabled
627  v_mse_advection_enabled=is_component_field_available("v_advection") .and. &
628  is_component_field_available("th_advection") .and. v_mse_enabled
629  v_mse_viscosity_diffusion_enabled=is_component_field_available("v_viscosity") .and. &
630  is_component_field_available("th_diffusion") .and. v_mse_enabled
631  wv_mse_enabled=current_state%w%active .and. v_mse_enabled
632 
634 
635  if (v_mse_enabled) then
636  call set_published_field_enabled_state(mse_fields, "v_mse_local", .true.)
637  allocate(v_mse(column_size))
638  end if
639  if (vs_mse_enabled) then
640  call set_published_field_enabled_state(mse_fields, "vs_mse_local", .true.)
641  allocate(vs_mse(column_size))
642  end if
643  if (v_mse_advection_enabled) then
644  call set_published_field_enabled_state(mse_fields, "v_mse_advection_local", .true.)
645  allocate(v_mse_advection(column_size))
646  end if
647  if (v_mse_viscosity_diffusion_enabled) then
648  call set_published_field_enabled_state(mse_fields, "v_mse_viscosity_diffusion_local", .true.)
649  allocate(v_mse_viscosity_diffusion(column_size))
650  end if
651  if (wv_mse_enabled) then
652  call set_published_field_enabled_state(mse_fields, "wv_mse_local", .true.)
653  allocate(wv_mse(column_size))
654  end if
655 
656  w_mse_enabled=current_state%w%active .and. current_state%th%active
657  ws_mse_enabled=w_mse_enabled
658  w_mse_advection_enabled=is_component_field_available("w_advection") .and. &
659  is_component_field_available("th_advection") .and. w_mse_enabled
660  w_mse_viscosity_diffusion_enabled=is_component_field_available("w_viscosity") .and. &
661  is_component_field_available("th_diffusion") .and. w_mse_enabled
662  w_mse_buoyancy_enabled=current_state%th%active .and. is_component_field_available("w_buoyancy")
663  ww_mse_enabled=w_mse_enabled
664 
666 
667  if (w_mse_enabled) then
668  call set_published_field_enabled_state(mse_fields, "w_mse_local", .true.)
669  allocate(w_mse(column_size))
670  end if
671  if (ws_mse_enabled) then
672  call set_published_field_enabled_state(mse_fields, "ws_mse_local", .true.)
673  allocate(ws_mse(column_size))
674  end if
675  if (w_mse_advection_enabled) then
676  call set_published_field_enabled_state(mse_fields, "w_mse_advection_local", .true.)
677  allocate(w_mse_advection(column_size))
678  end if
679  if (w_mse_viscosity_diffusion_enabled) then
680  call set_published_field_enabled_state(mse_fields, "w_mse_viscosity_diffusion_local", .true.)
681  allocate(w_mse_viscosity_diffusion(column_size))
682  end if
683  if (w_mse_buoyancy_enabled) then
684  call set_published_field_enabled_state(mse_fields, "w_mse_buoyancy_local", .true.)
685  allocate(w_mse_buoyancy(column_size))
686  end if
687  if (ww_mse_enabled) then
688  call set_published_field_enabled_state(mse_fields, "ww_mse_local", .true.)
689  allocate(ww_mse(column_size))
690  end if
691 
692  mse_mse_enabled=current_state%th%active
693  smse_mse_enabled=mse_mse_enabled
694  mse_mse_advection_enabled=is_component_field_available("mse_advection") .and. mse_mse_enabled
695  mse_mse_diffusion_enabled=is_component_field_available("mse_diffusion") .and. mse_mse_enabled
696  wmse_mse_enabled=current_state%w%active .and. mse_mse_enabled
697 
699 
700  if (mse_mse_enabled) then
701  call set_published_field_enabled_state(mse_fields, "mse_mse_local", .true.)
702  allocate(mse_mse(column_size))
703  end if
704  if (smse_mse_enabled) then
705  call set_published_field_enabled_state(mse_fields, "smse_mse_local", .true.)
706  allocate(smse_mse(column_size))
707  end if
708  if (mse_mse_advection_enabled) then
709  call set_published_field_enabled_state(mse_fields, "mse_mse_advection_local", .true.)
710  allocate(mse_mse_advection(column_size))
711  end if
712  if (mse_mse_diffusion_enabled) then
713  call set_published_field_enabled_state(mse_fields, "mse_mse_diffusion_local", .true.)
714  allocate(mse_mse_diffusion(column_size))
715  end if
716  if (wmse_mse_enabled) then
717  call set_published_field_enabled_state(mse_fields, "wmse_mse_local", .true.)
718  allocate(wmse_mse(column_size))
719  end if
720  end subroutine initialise_mse_diagnostics
721 
724  subroutine initialise_thetal_diagnostics(current_state)
725  type(model_state_type), target, intent(inout) :: current_state
726 
727  integer :: column_size
728  logical :: u_thetal_enabled, us_thetal_enabled, u_thetal_advection_enabled, u_thetal_viscosity_diffusion_enabled, &
729  wu_thetal_enabled, v_thetal_enabled, vs_thetal_enabled, v_thetal_advection_enabled, &
730  v_thetal_viscosity_diffusion_enabled, wv_thetal_enabled, w_thetal_enabled, ws_thetal_enabled, &
731  w_thetal_advection_enabled, w_thetal_viscosity_diffusion_enabled, w_thetal_buoyancy_enabled, ww_thetal_enabled, &
732  thetal_thetal_enabled, sthetal_thetal_enabled, thetal_thetal_advection_enabled, &
733  thetal_thetal_diffusion_enabled, wthetal_thetal_enabled
734 
735  column_size=current_state%local_grid%size(z_index)
736 
737  u_thetal_enabled=current_state%u%active .and. current_state%th%active
738  us_thetal_enabled=u_thetal_enabled
739  u_thetal_advection_enabled=is_component_field_available("u_advection") .and. &
740  is_component_field_available("th_advection") .and. u_thetal_enabled
741  u_thetal_viscosity_diffusion_enabled=is_component_field_available("u_viscosity") .and. &
742  is_component_field_available("th_diffusion") .and. u_thetal_enabled
743  wu_thetal_enabled=current_state%w%active .and. u_thetal_enabled
744 
745  some_thetal_diagnostics_enabled=u_thetal_enabled
746 
747  if (u_thetal_enabled) then
748  call set_published_field_enabled_state(thetal_fields, "u_thetal_local", .true.)
749  allocate(u_thetal(column_size))
750  end if
751  if (us_thetal_enabled) then
752  call set_published_field_enabled_state(thetal_fields, "us_thetal_local", .true.)
753  allocate(us_thetal(column_size))
754  end if
755  if (u_thetal_advection_enabled) then
756  call set_published_field_enabled_state(thetal_fields, "u_thetal_advection_local", .true.)
757  allocate(u_thetal_advection(column_size))
758  end if
759  if (u_thetal_viscosity_diffusion_enabled) then
760  call set_published_field_enabled_state(thetal_fields, "u_thetal_viscosity_diffusion_local", .true.)
761  allocate(u_thetal_viscosity_diffusion(column_size))
762  end if
763  if (wu_thetal_enabled) then
764  call set_published_field_enabled_state(thetal_fields, "wu_thetal_local", .true.)
765  allocate(wu_thetal(column_size))
766  end if
767 
768  v_thetal_enabled=current_state%v%active .and. current_state%th%active
769  vs_thetal_enabled=v_thetal_enabled
770  v_thetal_advection_enabled=is_component_field_available("v_advection") .and. &
771  is_component_field_available("th_advection") .and. v_thetal_enabled
772  v_thetal_viscosity_diffusion_enabled=is_component_field_available("v_viscosity") .and. &
773  is_component_field_available("th_diffusion") .and. v_thetal_enabled
774  wv_thetal_enabled=current_state%w%active .and. v_thetal_enabled
775 
777 
778  if (v_thetal_enabled) then
779  call set_published_field_enabled_state(thetal_fields, "v_thetal_local", .true.)
780  allocate(v_thetal(column_size))
781  end if
782  if (vs_thetal_enabled) then
783  call set_published_field_enabled_state(thetal_fields, "vs_thetal_local", .true.)
784  allocate(vs_thetal(column_size))
785  end if
786  if (v_thetal_advection_enabled) then
787  call set_published_field_enabled_state(thetal_fields, "v_thetal_advection_local", .true.)
788  allocate(v_thetal_advection(column_size))
789  end if
790  if (v_thetal_viscosity_diffusion_enabled) then
791  call set_published_field_enabled_state(thetal_fields, "v_thetal_viscosity_diffusion_local", .true.)
792  allocate(v_thetal_viscosity_diffusion(column_size))
793  end if
794  if (wv_thetal_enabled) then
795  call set_published_field_enabled_state(thetal_fields, "wv_thetal_local", .true.)
796  allocate(wv_thetal(column_size))
797  end if
798 
799  w_thetal_enabled=current_state%w%active .and. current_state%th%active
800  ws_thetal_enabled=w_thetal_enabled
801  w_thetal_advection_enabled=is_component_field_available("w_advection") .and. &
802  is_component_field_available("th_advection") .and. w_thetal_enabled
803  w_thetal_viscosity_diffusion_enabled=is_component_field_available("w_viscosity") .and. &
804  is_component_field_available("th_diffusion") .and. w_thetal_enabled
805  w_thetal_buoyancy_enabled=current_state%th%active .and. is_component_field_available("w_buoyancy")
806  ww_thetal_enabled=w_thetal_enabled
807 
809 
810  if (w_thetal_enabled) then
811  call set_published_field_enabled_state(thetal_fields, "w_thetal_local", .true.)
812  allocate(w_thetal(column_size))
813  end if
814  if (ws_thetal_enabled) then
815  call set_published_field_enabled_state(thetal_fields, "ws_thetal_local", .true.)
816  allocate(ws_thetal(column_size))
817  end if
818  if (w_thetal_advection_enabled) then
819  call set_published_field_enabled_state(thetal_fields, "w_thetal_advection_local", .true.)
820  allocate(w_thetal_advection(column_size))
821  end if
822  if (w_thetal_viscosity_diffusion_enabled) then
823  call set_published_field_enabled_state(thetal_fields, "w_thetal_viscosity_diffusion_local", .true.)
824  allocate(w_thetal_viscosity_diffusion(column_size))
825  end if
826  if (w_thetal_buoyancy_enabled) then
827  call set_published_field_enabled_state(thetal_fields, "w_thetal_buoyancy_local", .true.)
828  allocate(w_thetal_buoyancy(column_size))
829  end if
830  if (ww_thetal_enabled) then
831  call set_published_field_enabled_state(thetal_fields, "ww_thetal_local", .true.)
832  allocate(ww_thetal(column_size))
833  end if
834 
835  thetal_thetal_enabled=current_state%th%active
836  sthetal_thetal_enabled=thetal_thetal_enabled
837  thetal_thetal_advection_enabled=is_component_field_available("th_advection") .and. thetal_thetal_enabled
838  thetal_thetal_diffusion_enabled=is_component_field_available("th_diffusion") .and. thetal_thetal_enabled
839  wthetal_thetal_enabled=current_state%w%active .and. thetal_thetal_enabled
840 
842 
843  if (thetal_thetal_enabled) then
844  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_local", .true.)
845  allocate(thetal_thetal(column_size))
846  end if
847  if (sthetal_thetal_enabled) then
848  call set_published_field_enabled_state(thetal_fields, "sthetal_thetal_local", .true.)
849  allocate(sthetal_thetal(column_size))
850  end if
851  if (thetal_thetal_advection_enabled) then
852  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_advection_local", .true.)
853  allocate(thetal_thetal_advection(column_size))
854  end if
855  if (thetal_thetal_diffusion_enabled) then
856  call set_published_field_enabled_state(thetal_fields, "thetal_thetal_diffusion_local", .true.)
857  allocate(thetal_thetal_diffusion(column_size))
858  end if
859  if (wthetal_thetal_enabled) then
860  call set_published_field_enabled_state(thetal_fields, "wthetal_thetal_local", .true.)
861  allocate(wthetal_thetal(column_size))
862  end if
863  end subroutine initialise_thetal_diagnostics
864 
868  type(model_state_type), target, intent(inout) :: current_state
869 
870  integer :: column_size
871  logical :: tu_su_enabled, uu_advection_enabled, uu_viscosity_enabled, wu_u_enabled, tv_sv_enabled, vv_advection_enabled, &
872  vv_viscosity_enabled, wv_v_enabled, tw_sw_enabled, ww_advection_enabled, ww_viscosity_enabled, ww_buoyancy_enabled
873 
874  tu_su_enabled=current_state%u%active
875  uu_advection_enabled=is_component_field_available("u_advection") .and. current_state%u%active
876  uu_viscosity_enabled=is_component_field_available("u_viscosity") .and. current_state%u%active
877  wu_u_enabled=current_state%u%active .and. current_state%w%active
878  tv_sv_enabled=current_state%v%active
879  vv_advection_enabled=is_component_field_available("v_advection") .and. current_state%v%active
880  vv_viscosity_enabled=is_component_field_available("v_viscosity") .and. current_state%v%active
881  wv_v_enabled=current_state%v%active .and. current_state%w%active
882  tw_sw_enabled=current_state%w%active
883  ww_advection_enabled=is_component_field_available("w_advection") .and. current_state%w%active
884  ww_viscosity_enabled=is_component_field_available("w_viscosity") .and. current_state%w%active
885  ww_buoyancy_enabled=is_component_field_available("w_buoyancy") .and. current_state%w%active
886 
887  some_prognostic_budget_diagnostics_enabled=tu_su_enabled .or. tv_sv_enabled .or. tw_sw_enabled
888 
889  column_size=current_state%local_grid%size(z_index)
890 
891  if (tu_su_enabled) then
892  call set_published_field_enabled_state(prognostic_budget_fields, "tu_su_local", .true.)
893  allocate(tu_su(column_size))
894  end if
895  if (uu_advection_enabled) then
896  call set_published_field_enabled_state(prognostic_budget_fields, "uu_advection_local", .true.)
897  allocate(uu_advection(column_size))
898  end if
899  if (uu_viscosity_enabled) then
900  call set_published_field_enabled_state(prognostic_budget_fields, "uu_viscosity_local", .true.)
901  allocate(uu_viscosity(column_size))
902  end if
903  if (wu_u_enabled) then
905  allocate(wu_u(column_size))
906  end if
907  if (tv_sv_enabled) then
908  call set_published_field_enabled_state(prognostic_budget_fields, "tv_sv_local", .true.)
909  allocate(tv_sv(column_size))
910  end if
911  if (vv_advection_enabled) then
912  call set_published_field_enabled_state(prognostic_budget_fields, "vv_advection_local", .true.)
913  allocate(vv_advection(column_size))
914  end if
915  if (vv_viscosity_enabled) then
916  call set_published_field_enabled_state(prognostic_budget_fields, "vv_viscosity_local", .true.)
917  allocate(vv_viscosity(column_size))
918  end if
919  if (wv_v_enabled) then
921  allocate(wv_v(column_size))
922  end if
923  if (tw_sw_enabled) then
924  call set_published_field_enabled_state(prognostic_budget_fields, "tw_sw_local", .true.)
925  allocate(tw_sw(column_size))
926  end if
927  if (ww_advection_enabled) then
928  call set_published_field_enabled_state(prognostic_budget_fields, "ww_advection_local", .true.)
929  allocate(ww_advection(column_size))
930  end if
931  if (ww_viscosity_enabled) then
932  call set_published_field_enabled_state(prognostic_budget_fields, "ww_viscosity_local", .true.)
933  allocate(ww_viscosity(column_size))
934  end if
935  if (ww_buoyancy_enabled) then
936  call set_published_field_enabled_state(prognostic_budget_fields, "ww_buoyancy_local", .true.)
937  allocate(ww_buoyancy(column_size))
938  end if
940 
943  subroutine initialise_uw_vw_diagnostics(current_state)
944  type(model_state_type), target, intent(inout) :: current_state
945 
946  integer :: column_size
947  logical :: uw_advection_term_enabled, vw_advection_term_enabled, uw_viscosity_term_enabled, &
948  vw_viscosity_term_enabled, uw_buoyancy_term_enabled, vw_buoyancy_term_enabled, uw_tendency_term_enabled, &
949  vw_tendency_term_enabled, uw_w_term_enabled, vw_w_term_enabled
950 
951  uw_advection_term_enabled=is_component_field_available("w_advection") .and. is_component_field_available("u_advection") &
952  .and. current_state%w%active
953  vw_advection_term_enabled=is_component_field_available("w_advection") .and. is_component_field_available("v_advection") &
954  .and. current_state%w%active
955  uw_viscosity_term_enabled=is_component_field_available("w_viscosity") .and. is_component_field_available("u_viscosity") &
956  .and. current_state%w%active
957  vw_viscosity_term_enabled=is_component_field_available("w_viscosity") .and. is_component_field_available("v_viscosity") &
958  .and. current_state%w%active
959  uw_buoyancy_term_enabled=is_component_field_available("w_buoyancy")
960  vw_buoyancy_term_enabled=is_component_field_available("w_buoyancy")
961  uw_tendency_term_enabled=current_state%w%active .and. current_state%u%active
962  vw_tendency_term_enabled=current_state%w%active .and. current_state%v%active
963  uw_w_term_enabled=current_state%w%active .and. current_state%u%active
964  vw_w_term_enabled=current_state%w%active .and. current_state%v%active
965 
966  some_uw_vw_diagnostics_enabled=uw_buoyancy_term_enabled .or. vw_buoyancy_term_enabled .or. uw_w_term_enabled &
967  .or. vw_w_term_enabled .or. uw_advection_term_enabled .or. vw_advection_term_enabled .or. uw_viscosity_term_enabled .or. &
968  vw_viscosity_term_enabled
969 
970  column_size=current_state%local_grid%size(z_index)
971 
972  if (uw_advection_term_enabled) then
973  call set_published_field_enabled_state(uw_vw_fields, "uw_advection_local", .true.)
974  allocate(uw_advection(column_size))
975  end if
976  if (vw_advection_term_enabled) then
977  call set_published_field_enabled_state(uw_vw_fields, "vw_advection_local", .true.)
978  allocate(vw_advection(column_size))
979  end if
980  if (uw_viscosity_term_enabled) then
981  call set_published_field_enabled_state(uw_vw_fields, "uw_viscosity_local", .true.)
982  allocate(uw_viscosity(column_size))
983  end if
984  if (vw_viscosity_term_enabled) then
985  call set_published_field_enabled_state(uw_vw_fields, "vw_viscosity_local", .true.)
986  allocate(vw_viscosity(column_size))
987  end if
988  if (uw_buoyancy_term_enabled) then
989  call set_published_field_enabled_state(uw_vw_fields, "uw_buoyancy_local", .true.)
990  allocate(uw_buoyancy(column_size))
991  end if
992  if (vw_buoyancy_term_enabled) then
993  call set_published_field_enabled_state(uw_vw_fields, "vw_buoyancy_local", .true.)
994  allocate(vw_buoyancy(column_size))
995  end if
996  if (uw_tendency_term_enabled) then
997  call set_published_field_enabled_state(uw_vw_fields, "uw_tendency_local", .true.)
998  allocate(uw_tendency(column_size))
999  end if
1000  if (vw_tendency_term_enabled) then
1001  call set_published_field_enabled_state(uw_vw_fields, "vw_tendency_local", .true.)
1002  allocate(vw_tendency(column_size))
1003  end if
1004  if (uw_w_term_enabled) then
1005  call set_published_field_enabled_state(uw_vw_fields, "uw_w_local", .true.)
1006  allocate(uw_w(column_size))
1007  end if
1008  if (vw_w_term_enabled) then
1009  call set_published_field_enabled_state(uw_vw_fields, "vw_w_local", .true.)
1010  allocate(vw_w(column_size))
1011  end if
1012  end subroutine initialise_uw_vw_diagnostics
1013 
1016  subroutine initialise_tke_diagnostics(current_state)
1017  type(model_state_type), target, intent(inout) :: current_state
1018  integer :: column_size
1019  logical :: sres_enabled, wp_enabled, wke_enabled, buoy_enabled, tend_enabled
1020 
1021  column_size=current_state%local_grid%size(z_index)
1022 
1023  sres_enabled=current_state%u%active .and. current_state%v%active
1024  wke_enabled=current_state%w%active
1025  buoy_enabled=current_state%w%active
1026  wp_enabled=current_state%w%active
1027  tend_enabled=current_state%w%active
1028 
1029  some_tke_diagnostics_enabled=wp_enabled .or. sres_enabled .or. wke_enabled .or. buoy_enabled .or. tend_enabled
1030 
1031  if (wp_enabled) then
1032  call set_published_field_enabled_state(tke_fields, "resolved_pressure_transport_local", .true.)
1033  allocate(wp(column_size))
1034  end if
1035  if (tend_enabled) then
1036  call set_published_field_enabled_state(tke_fields, "tke_tendency_local", .true.)
1037  allocate(tend(column_size))
1038  end if
1039  if (sres_enabled) then
1040  call set_published_field_enabled_state(tke_fields, "resolved_shear_production_local", .true.)
1041  allocate(sres(column_size))
1042  end if
1043  if (wke_enabled) then
1044  call set_published_field_enabled_state(tke_fields, "resolved_turbulent_transport_local", .true.)
1045  allocate(wke(column_size))
1046  end if
1047  if (buoy_enabled) then
1048  call set_published_field_enabled_state(tke_fields, "resolved_buoyant_production_local", .true.)
1049  allocate(buoy(column_size))
1050  end if
1051 
1052  end subroutine initialise_tke_diagnostics
1053 
1056  subroutine initialise_q_flux_diagnostics(current_state)
1057  type(model_state_type), target, intent(inout) :: current_state
1058 
1059  logical :: q_flux_term_enabled, q_tendency_term_enabled, q_gradient_term_enabled, q_diff_enabled, &
1060  q_buoyancy_enabled
1061 
1062  q_flux_term_enabled=current_state%number_q_fields .gt. 0 .and. current_state%w%active
1063  q_tendency_term_enabled=current_state%number_q_fields .gt. 0 .and. current_state%w%active
1064  q_gradient_term_enabled=is_component_field_available("w_advection") .and. is_component_field_available("q_advection") &
1065  .and. current_state%w%active .and. current_state%number_q_fields .gt. 0
1066  q_diff_enabled=is_component_field_available("q_diffusion") .and. is_component_field_available("w_viscosity") &
1067  .and. current_state%w%active .and. current_state%number_q_fields .gt. 0
1068  q_buoyancy_enabled=is_component_field_available("w_buoyancy") .and. current_state%number_q_fields .gt. 0
1069 
1070  some_q_flux_diagnostics_enabled=q_flux_term_enabled .or. q_buoyancy_enabled
1071 
1072  if (q_flux_term_enabled) then
1073  call set_published_field_enabled_state(q_flux_fields, "q_flux_transport_local", .true.)
1074  allocate(q_flux_values(current_state%local_grid%size(z_index), current_state%number_q_fields))
1075  end if
1076  if (q_tendency_term_enabled) then
1077  call set_published_field_enabled_state(q_flux_fields, "q_flux_tendency_local", .true.)
1078  allocate(q_tendency(current_state%local_grid%size(z_index), current_state%number_q_fields))
1079  end if
1080  if (q_gradient_term_enabled) then
1081  call set_published_field_enabled_state(q_flux_fields, "q_flux_gradient_local", .true.)
1082  allocate(q_gradient(current_state%local_grid%size(z_index), current_state%number_q_fields))
1083  end if
1084  if (q_diff_enabled) then
1085  call set_published_field_enabled_state(q_flux_fields, "q_flux_dissipation_local", .true.)
1086  allocate(q_diff(current_state%local_grid%size(z_index), current_state%number_q_fields))
1087  end if
1088  if (q_buoyancy_enabled) then
1089  call set_published_field_enabled_state(q_flux_fields, "q_flux_buoyancy_local", .true.)
1090  allocate(q_buoyancy(current_state%local_grid%size(z_index), current_state%number_q_fields))
1091  end if
1092  end subroutine initialise_q_flux_diagnostics
1093 
1096  subroutine initialise_theta_flux_diagnostics(current_state)
1097  type(model_state_type), target, intent(inout) :: current_state
1098 
1099  logical :: th_flux_term_enabled, th_tendency_term_enabled, th_diff_enabled, th_gradient_term_enabled, th_buoyancy_enabled
1100 
1101  th_flux_term_enabled=current_state%th%active .and. current_state%w%active
1102  th_tendency_term_enabled=current_state%th%active .and. current_state%w%active
1103  th_gradient_term_enabled=is_component_field_available("w_advection") .and. is_component_field_available("th_advection") &
1104  .and. current_state%w%active .and. current_state%th%active
1105  th_diff_enabled=is_component_field_available("th_diffusion") .and. is_component_field_available("w_viscosity") &
1106  .and. current_state%w%active .and. current_state%th%active
1107  th_buoyancy_enabled=is_component_field_available("w_buoyancy") .and. current_state%th%active
1108 
1109  some_theta_flux_diagnostics_enabled=th_flux_term_enabled .or. th_buoyancy_enabled
1110 
1111  if (th_flux_term_enabled) then
1112  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_transport_local", .true.)
1113  allocate(th_flux_values(current_state%local_grid%size(z_index)))
1114  end if
1115  if (th_tendency_term_enabled) then
1116  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_tendency_local", .true.)
1117  allocate(th_tendency(current_state%local_grid%size(z_index)))
1118  end if
1119  if (th_diff_enabled) then
1120  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_dissipation_local", .true.)
1121  allocate(th_diff(current_state%local_grid%size(z_index)))
1122  end if
1123  if (th_gradient_term_enabled) then
1124  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_gradient_local", .true.)
1125  allocate(th_gradient(current_state%local_grid%size(z_index)))
1126  end if
1127  if (th_buoyancy_enabled) then
1128  call set_published_field_enabled_state(heat_flux_fields, "heat_flux_buoyancy_local", .true.)
1129  allocate(th_buoyancy(current_state%local_grid%size(z_index)))
1130  end if
1131  end subroutine initialise_theta_flux_diagnostics
1132 
1134  subroutine clear_qt()
1135  if (allocated(us_qt)) us_qt=0.0_default_precision
1136  if (allocated(u_qt_advection)) u_qt_advection=0.0_default_precision
1137  if (allocated(u_qt_viscosity_diffusion)) u_qt_viscosity_diffusion=0.0_default_precision
1138  if (allocated(wu_qt)) wu_qt=0.0_default_precision
1139  if (allocated(vs_qt)) vs_qt=0.0_default_precision
1140  if (allocated(v_qt_advection)) v_qt_advection=0.0_default_precision
1141  if (allocated(v_qt_viscosity_diffusion)) v_qt_viscosity_diffusion=0.0_default_precision
1142  if (allocated(wv_qt)) wv_qt=0.0_default_precision
1143  if (allocated(w_qt)) w_qt=0.0_default_precision
1144  if (allocated(ws_qt)) ws_qt=0.0_default_precision
1145  if (allocated(w_qt_advection)) w_qt_advection=0.0_default_precision
1146  if (allocated(w_qt_viscosity_diffusion)) w_qt_viscosity_diffusion=0.0_default_precision
1147  if (allocated(w_qt_buoyancy)) w_qt_buoyancy=0.0_default_precision
1148  if (allocated(ww_qt)) ww_qt=0.0_default_precision
1149  if (allocated(qt_qt)) qt_qt=0.0_default_precision
1150  if (allocated(sqt_qt)) sqt_qt=0.0_default_precision
1151  if (allocated(qt_qt_advection)) qt_qt_advection=0.0_default_precision
1152  if (allocated(qt_qt_diffusion)) qt_qt_diffusion=0.0_default_precision
1153  if (allocated(wqt_qt)) wqt_qt=0.0_default_precision
1154  end subroutine clear_qt
1155 
1159  subroutine compute_qt_for_column(current_state)
1160  type(model_state_type), target, intent(inout) :: current_state
1161 
1162  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1, qtpr, qtprp1
1163  type(component_field_value_type) :: u_advection, u_viscosity, th_advection, th_diffusion, v_advection, v_viscosity, &
1164  w_advection, w_viscosity, w_buoyancy
1165  integer :: k
1166 
1167  if (is_component_field_available("u_advection")) u_advection=get_component_field_value(current_state, "u_advection")
1168  if (is_component_field_available("u_viscosity")) u_viscosity=get_component_field_value(current_state, "u_viscosity")
1169  if (is_component_field_available("th_advection")) th_advection=get_component_field_value(current_state, "th_advection")
1170  if (is_component_field_available("th_diffusion")) th_diffusion=get_component_field_value(current_state, "th_diffusion")
1171  if (is_component_field_available("v_advection")) v_advection=get_component_field_value(current_state, "v_advection")
1172  if (is_component_field_available("v_viscosity")) v_viscosity=get_component_field_value(current_state, "v_viscosity")
1173  if (is_component_field_available("w_advection")) w_advection=get_component_field_value(current_state, "w_advection")
1174  if (is_component_field_available("w_viscosity")) w_viscosity=get_component_field_value(current_state, "w_viscosity")
1175  if (is_component_field_available("w_buoyancy")) w_buoyancy=get_component_field_value(current_state, "w_buoyancy")
1176 
1177  do k=1, current_state%local_grid%size(z_index)
1178  upr(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x)
1179  uprm1(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)
1180  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
1181  upr(k)=upr(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1182  uprm1(k)=uprm1(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1183  end if
1184  vpr(k)=current_state%v%data(k,current_state%column_local_y,current_state%column_local_x)
1185  vprm1(k)=current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)
1186  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
1187  vpr(k)=vpr(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1188  vprm1(k)=vprm1(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1189  end if
1190 
1191  qtpr(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x)
1192  qtprp1(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x+1)
1193  if (allocated(current_state%global_grid%configuration%vertical%olthbar)) then
1194  qtpr(k)=qtpr(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1195  qtprp1(k)=qtprp1(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1196  end if
1197  end do
1198  do k=2, current_state%local_grid%size(z_index)-1
1199  if (allocated(us_qt)) us_qt(k)=us_qt(k)+0.5*(upr(k)+uprm1(k))*&
1200  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(qtpr(k)+qtprp1(k))*&
1201  current_state%su%data(k,current_state%column_local_y,current_state%column_local_x)
1202  if (allocated(u_qt_advection)) u_qt_advection(k)=u_qt_advection(k)+0.5*(upr(k)+uprm1(k))*&
1203  th_advection%real_1d_array(k)+0.5*(qtpr(k)+qtprp1(k))*u_advection%real_1d_array(k)
1205  (qtpr(k)+qtprp1(k))*u_viscosity%real_1d_array(k)+0.5*(upr(k)+uprm1(k))*th_diffusion%real_1d_array(k)
1206  if (allocated(wu_qt)) wu_qt(k)=wu_qt(k)+&
1207  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(upr(k+1)+upr(k)+&
1208  uprm1(k+1)+uprm1(k))*0.5*(qtpr(k+1)+qtpr(k))
1209 
1210  if (allocated(vs_qt)) vs_qt(k)=vs_qt(k)+0.5*(vpr(k)+vprm1(k))*&
1211  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(qtpr(k)+qtprp1(k))*&
1212  current_state%sv%data(k,current_state%column_local_y,current_state%column_local_x)
1213  if (allocated(v_qt_advection)) v_qt_advection(k)=v_qt_advection(k)+0.5*(vpr(k)+vprm1(k))*&
1214  th_advection%real_1d_array(k)+0.5*(qtpr(k)+qtprp1(k))*v_advection%real_1d_array(k)
1216  (qtpr(k)+qtprp1(k))*v_viscosity%real_1d_array(k)+0.5*(vpr(k)+vprm1(k))*th_diffusion%real_1d_array(k)
1217  if (allocated(wv_qt)) wv_qt(k)=wv_qt(k)+&
1218  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(vpr(k+1)+vpr(k)+&
1219  vprm1(k+1)+vprm1(k))*0.5*(qtpr(k+1)+qtpr(k))
1220 
1221  if (allocated(w_qt)) w_qt(k)=w_qt(k)+&
1222  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(qtpr(k)+qtpr(k+1))
1223  if (allocated(ws_qt)) ws_qt(k)=ws_qt(k)+&
1224  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1225  (current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+&
1226  current_state%sth%data(k+1,current_state%column_local_y,current_state%column_local_x))+0.5*(qtpr(k)+qtpr(k+1))*&
1227  current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)
1228  if (allocated(w_qt_advection)) w_qt_advection(k)=w_qt_advection(k)+&
1229  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(th_advection%real_1d_array(k)+&
1230  th_advection%real_1d_array(k+1))+0.5*(qtpr(k)+qtpr(k+1))*w_advection%real_1d_array(k)
1232  (qtpr(k)+qtpr(k+1))*w_viscosity%real_1d_array(k)+&
1233  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1234  (th_diffusion%real_1d_array(k)+th_diffusion%real_1d_array(k+1))
1235  if (allocated(w_qt_buoyancy)) w_qt_buoyancy(k)=w_qt_buoyancy(k)+0.5*(qtpr(k+1)+qtpr(k))*&
1236  w_buoyancy%real_1d_array(k)
1237  if (allocated(wv_qt)) ww_qt(k)=ww_qt(k)+0.5*&
1238  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1239  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*0.5*(&
1240  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1241  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*qtpr(k)
1242 
1243  if (allocated(qt_qt)) qt_qt(k)=qt_qt(k)+qtpr(k)*qtpr(k)
1244  if (allocated(sqt_qt)) sqt_qt(k)=sqt_qt(k)+2.0*qtpr(k)*&
1245  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)
1246  if (allocated(qt_qt_advection)) qt_qt_advection(k)=qt_qt_advection(k)+2.0*qtpr(k)*&
1247  th_advection%real_1d_array(k)
1248  if (allocated(qt_qt_diffusion)) qt_qt_diffusion(k)=qt_qt_diffusion(k)+2.0*qtpr(k)*&
1249  th_diffusion%real_1d_array(k)
1250  if (allocated(wqt_qt)) wqt_qt(k)=wqt_qt(k)+&
1251  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(qtpr(k+1)+qtpr(k))*0.5*(&
1252  qtpr(k+1)+qtpr(k))
1253  end do
1254 
1255  if (allocated(u_advection%real_1d_array)) deallocate(u_advection%real_1d_array)
1256  if (allocated(u_viscosity%real_1d_array)) deallocate(u_viscosity%real_1d_array)
1257  if (allocated(th_advection%real_1d_array)) deallocate(th_advection%real_1d_array)
1258  if (allocated(th_diffusion%real_1d_array)) deallocate(th_diffusion%real_1d_array)
1259  if (allocated(v_advection%real_1d_array)) deallocate(v_advection%real_1d_array)
1260  if (allocated(v_viscosity%real_1d_array)) deallocate(v_viscosity%real_1d_array)
1261  if (allocated(w_advection%real_1d_array)) deallocate(w_advection%real_1d_array)
1262  if (allocated(w_viscosity%real_1d_array)) deallocate(w_viscosity%real_1d_array)
1263  if (allocated(w_buoyancy%real_1d_array)) deallocate(w_buoyancy%real_1d_array)
1264  end subroutine compute_qt_for_column
1265 
1267  subroutine clear_scalars()
1268  mflux=0.0_default_precision
1269  end subroutine clear_scalars
1270 
1273  subroutine compute_scalars_for_column(current_state)
1274  type(model_state_type), target, intent(inout) :: current_state
1275 
1276  integer :: k
1277 
1278  do k=2, current_state%local_grid%size(z_index)-1
1279  if (current_state%w%data(k, current_state%column_local_y,current_state%column_local_x) .gt. wmfcrit) then
1280  mflux=mflux+current_state%global_grid%configuration%vertical%rho(k)*&
1281  current_state%global_grid%configuration%vertical%dzn(k)*&
1282  current_state%w%data(k, current_state%column_local_y,current_state%column_local_x)
1283  end if
1284  end do
1285  end subroutine compute_scalars_for_column
1286 
1288  subroutine clear_mse()
1289  if (allocated(u_mse)) u_mse=0.0_default_precision
1290  if (allocated(us_mse)) us_mse=0.0_default_precision
1291  if (allocated(u_mse_advection)) u_mse_advection=0.0_default_precision
1292  if (allocated(u_mse_viscosity_diffusion)) u_mse_viscosity_diffusion=0.0_default_precision
1293  if (allocated(wu_mse)) wu_mse=0.0_default_precision
1294  if (allocated(v_mse)) v_mse=0.0_default_precision
1295  if (allocated(vs_mse)) vs_mse=0.0_default_precision
1296  if (allocated(v_mse_advection)) v_mse_advection=0.0_default_precision
1297  if (allocated(v_mse_viscosity_diffusion)) v_mse_viscosity_diffusion=0.0_default_precision
1298  if (allocated(wv_mse)) wv_mse=0.0_default_precision
1299  if (allocated(w_mse)) w_mse=0.0_default_precision
1300  if (allocated(ws_mse)) ws_mse=0.0_default_precision
1301  if (allocated(w_mse_advection)) w_mse_advection=0.0_default_precision
1302  if (allocated(w_mse_viscosity_diffusion)) w_mse_viscosity_diffusion=0.0_default_precision
1303  if (allocated(w_mse_buoyancy)) w_mse_buoyancy=0.0_default_precision
1304  if (allocated(ww_mse)) ww_mse=0.0_default_precision
1305  if (allocated(mse_mse)) mse_mse=0.0_default_precision
1306  if (allocated(smse_mse)) smse_mse=0.0_default_precision
1307  if (allocated(mse_mse_advection)) mse_mse_advection=0.0_default_precision
1308  if (allocated(mse_mse_diffusion)) mse_mse_diffusion=0.0_default_precision
1309  if (allocated(wmse_mse)) wmse_mse=0.0_default_precision
1310  end subroutine clear_mse
1311 
1315  subroutine compute_mse_for_column(current_state)
1316  type(model_state_type), target, intent(inout) :: current_state
1317 
1318  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1, msepr, mseprp1
1319  type(component_field_value_type) :: u_advection, u_viscosity, th_advection, th_diffusion, v_advection, v_viscosity, &
1320  w_advection, w_viscosity, w_buoyancy
1321  integer :: k
1322 
1323  if (is_component_field_available("u_advection")) u_advection=get_component_field_value(current_state, "u_advection")
1324  if (is_component_field_available("u_viscosity")) u_viscosity=get_component_field_value(current_state, "u_viscosity")
1325  if (is_component_field_available("th_advection")) th_advection=get_component_field_value(current_state, "th_advection")
1326  if (is_component_field_available("th_diffusion")) th_diffusion=get_component_field_value(current_state, "th_diffusion")
1327  if (is_component_field_available("v_advection")) v_advection=get_component_field_value(current_state, "v_advection")
1328  if (is_component_field_available("v_viscosity")) v_viscosity=get_component_field_value(current_state, "v_viscosity")
1329  if (is_component_field_available("w_advection")) w_advection=get_component_field_value(current_state, "w_advection")
1330  if (is_component_field_available("w_viscosity")) w_viscosity=get_component_field_value(current_state, "w_viscosity")
1331  if (is_component_field_available("w_buoyancy")) w_buoyancy=get_component_field_value(current_state, "w_buoyancy")
1332 
1333  do k=1, current_state%local_grid%size(z_index)
1334  upr(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x)
1335  uprm1(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)
1336  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
1337  upr(k)=upr(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1338  uprm1(k)=uprm1(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1339  end if
1340  vpr(k)=current_state%v%data(k,current_state%column_local_y,current_state%column_local_x)
1341  vprm1(k)=current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)
1342  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
1343  vpr(k)=vpr(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1344  vprm1(k)=vprm1(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1345  end if
1346  msepr(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x)
1347  mseprp1(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x+1)
1348  if (allocated(current_state%global_grid%configuration%vertical%olthbar)) then
1349  msepr(k)=msepr(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1350  mseprp1(k)=mseprp1(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1351  end if
1352  end do
1353  do k=2, current_state%local_grid%size(z_index)-1
1354  if (allocated(u_mse)) u_mse(k)=u_mse(k)+0.5*(upr(k)+uprm1(k))*msepr(k)
1355  if (allocated(us_mse)) us_mse(k)=us_mse(k)+0.5*(upr(k)+uprm1(k))*&
1356  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(msepr(k)+mseprp1(k))*&
1357  current_state%su%data(k,current_state%column_local_y,current_state%column_local_x)
1358  if (allocated(u_mse_advection)) u_mse_advection(k)=u_mse_advection(k)+0.5*(upr(k)+uprm1(k))*&
1359  th_advection%real_1d_array(k)+0.5*(msepr(k)+mseprp1(k))*u_advection%real_1d_array(k)
1361  (msepr(k)+mseprp1(k))*u_viscosity%real_1d_array(k)+0.5*(upr(k)+uprm1(k))*th_diffusion%real_1d_array(k)
1362  if (allocated(wu_mse)) wu_mse(k)=wu_mse(k)+&
1363  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(upr(k+1)+upr(k)+&
1364  uprm1(k+1)+uprm1(k))*0.5*(msepr(k+1)+msepr(k))
1365 
1366  if (allocated(v_mse)) v_mse(k)=v_mse(k)+0.5*(vpr(k)+vprm1(k))*msepr(k)
1367  if (allocated(vs_mse)) vs_mse(k)=vs_mse(k)+0.5*(vpr(k)+vprm1(k))*&
1368  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(msepr(k)+mseprp1(k))*&
1369  current_state%sv%data(k,current_state%column_local_y,current_state%column_local_x)
1370  if (allocated(v_mse_advection)) v_mse_advection(k)=v_mse_advection(k)+0.5*(vpr(k)+vprm1(k))*&
1371  th_advection%real_1d_array(k)+0.5*(msepr(k)+mseprp1(k))*v_advection%real_1d_array(k)
1373  (msepr(k)+mseprp1(k))*v_viscosity%real_1d_array(k)+0.5*(vpr(k)+vprm1(k))*th_diffusion%real_1d_array(k)
1374  if (allocated(wv_mse)) wv_mse(k)=wv_mse(k)+&
1375  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(vpr(k+1)+vpr(k)+&
1376  vprm1(k+1)+vprm1(k))*0.5*(msepr(k+1)+msepr(k))
1377 
1378  if (allocated(w_mse)) w_mse(k)=w_mse(k)+&
1379  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(msepr(k)+msepr(k+1))
1380  if (allocated(ws_mse)) ws_mse(k)=ws_mse(k)+&
1381  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1382  (current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+&
1383  current_state%sth%data(k+1,current_state%column_local_y,current_state%column_local_x))+0.5*(msepr(k)+msepr(k+1))*&
1384  current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)
1385  if (allocated(w_mse_advection)) w_mse_advection(k)=w_mse_advection(k)+&
1386  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(th_advection%real_1d_array(k)+&
1387  th_advection%real_1d_array(k+1))+0.5*(msepr(k)+msepr(k+1))*w_advection%real_1d_array(k)
1389  (msepr(k)+msepr(k+1))*w_viscosity%real_1d_array(k)+&
1390  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1391  (th_diffusion%real_1d_array(k)+th_diffusion%real_1d_array(k+1))
1392  if (allocated(w_mse_buoyancy)) w_mse_buoyancy(k)=w_mse_buoyancy(k)+0.5*(msepr(k+1)+msepr(k))*&
1393  w_buoyancy%real_1d_array(k)
1394  if (allocated(wv_mse)) ww_mse(k)=ww_mse(k)+0.5*&
1395  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1396  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*0.5*(&
1397  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1398  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*msepr(k)
1399 
1400  if (allocated(mse_mse)) mse_mse(k)=mse_mse(k)+msepr(k)*msepr(k)
1401  if (allocated(smse_mse)) smse_mse(k)=smse_mse(k)+2.0*msepr(k)*&
1402  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)
1403  if (allocated(mse_mse_advection)) mse_mse_advection(k)=mse_mse_advection(k)+2.0*msepr(k)*&
1404  th_advection%real_1d_array(k)
1405  if (allocated(mse_mse_diffusion)) mse_mse_diffusion(k)=mse_mse_diffusion(k)+2.0*msepr(k)*&
1406  th_diffusion%real_1d_array(k)
1407  if (allocated(wmse_mse)) wmse_mse(k)=wmse_mse(k)+&
1408  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(msepr(k+1)+msepr(k))*0.5*(&
1409  msepr(k+1)+msepr(k))
1410  end do
1411 
1412  if (allocated(u_advection%real_1d_array)) deallocate(u_advection%real_1d_array)
1413  if (allocated(u_viscosity%real_1d_array)) deallocate(u_viscosity%real_1d_array)
1414  if (allocated(th_advection%real_1d_array)) deallocate(th_advection%real_1d_array)
1415  if (allocated(th_diffusion%real_1d_array)) deallocate(th_diffusion%real_1d_array)
1416  if (allocated(v_advection%real_1d_array)) deallocate(v_advection%real_1d_array)
1417  if (allocated(v_viscosity%real_1d_array)) deallocate(v_viscosity%real_1d_array)
1418  if (allocated(w_advection%real_1d_array)) deallocate(w_advection%real_1d_array)
1419  if (allocated(w_viscosity%real_1d_array)) deallocate(w_viscosity%real_1d_array)
1420  if (allocated(w_buoyancy%real_1d_array)) deallocate(w_buoyancy%real_1d_array)
1421  end subroutine compute_mse_for_column
1422 
1424  subroutine clear_thetal()
1425  if (allocated(u_thetal)) u_thetal=0.0_default_precision
1426  if (allocated(us_thetal)) us_thetal=0.0_default_precision
1427  if (allocated(u_thetal_advection)) u_thetal_advection=0.0_default_precision
1428  if (allocated(u_thetal_viscosity_diffusion)) u_thetal_viscosity_diffusion=0.0_default_precision
1429  if (allocated(wu_thetal)) wu_thetal=0.0_default_precision
1430  if (allocated(v_thetal)) v_thetal=0.0_default_precision
1431  if (allocated(vs_thetal)) vs_thetal=0.0_default_precision
1432  if (allocated(v_thetal_advection)) v_thetal_advection=0.0_default_precision
1433  if (allocated(v_thetal_viscosity_diffusion)) v_thetal_viscosity_diffusion=0.0_default_precision
1434  if (allocated(wv_thetal)) wv_thetal=0.0_default_precision
1435  if (allocated(w_thetal)) w_thetal=0.0_default_precision
1436  if (allocated(ws_thetal)) ws_thetal=0.0_default_precision
1437  if (allocated(w_thetal_advection)) w_thetal_advection=0.0_default_precision
1438  if (allocated(w_thetal_viscosity_diffusion)) w_thetal_viscosity_diffusion=0.0_default_precision
1439  if (allocated(w_thetal_buoyancy)) w_thetal_buoyancy=0.0_default_precision
1440  if (allocated(ww_thetal)) ww_thetal=0.0_default_precision
1441  if (allocated(thetal_thetal)) thetal_thetal=0.0_default_precision
1442  if (allocated(sthetal_thetal)) sthetal_thetal=0.0_default_precision
1443  if (allocated(thetal_thetal_advection)) thetal_thetal_advection=0.0_default_precision
1444  if (allocated(thetal_thetal_diffusion)) thetal_thetal_diffusion=0.0_default_precision
1445  if (allocated(wthetal_thetal)) wthetal_thetal=0.0_default_precision
1446  end subroutine clear_thetal
1447 
1450  subroutine compute_thetal_for_column(current_state)
1451  type(model_state_type), target, intent(inout) :: current_state
1452 
1453  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1, thlpr, thlprp1
1454  type(component_field_value_type) :: u_advection, u_viscosity, th_advection, th_diffusion, v_advection, v_viscosity, &
1455  w_advection, w_viscosity, w_buoyancy
1456  integer :: k
1457 
1458  if (is_component_field_available("u_advection")) u_advection=get_component_field_value(current_state, "u_advection")
1459  if (is_component_field_available("u_viscosity")) u_viscosity=get_component_field_value(current_state, "u_viscosity")
1460  if (is_component_field_available("th_advection")) th_advection=get_component_field_value(current_state, "th_advection")
1461  if (is_component_field_available("th_diffusion")) th_diffusion=get_component_field_value(current_state, "th_diffusion")
1462  if (is_component_field_available("v_advection")) v_advection=get_component_field_value(current_state, "v_advection")
1463  if (is_component_field_available("v_viscosity")) v_viscosity=get_component_field_value(current_state, "v_viscosity")
1464  if (is_component_field_available("w_advection")) w_advection=get_component_field_value(current_state, "w_advection")
1465  if (is_component_field_available("w_viscosity")) w_viscosity=get_component_field_value(current_state, "w_viscosity")
1466  if (is_component_field_available("w_buoyancy")) w_buoyancy=get_component_field_value(current_state, "w_buoyancy")
1467 
1468  do k=1, current_state%local_grid%size(z_index)
1469  upr(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x)
1470  uprm1(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)
1471  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
1472  upr(k)=upr(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1473  uprm1(k)=uprm1(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1474  end if
1475  vpr(k)=current_state%v%data(k,current_state%column_local_y,current_state%column_local_x)
1476  vprm1(k)=current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)
1477  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
1478  vpr(k)=vpr(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1479  vprm1(k)=vprm1(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1480  end if
1481  thlpr(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x)
1482  thlprp1(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x+1)
1483  if (allocated(current_state%global_grid%configuration%vertical%olthbar)) then
1484  thlpr(k)=thlpr(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1485  thlprp1(k)=thlprp1(k)-current_state%global_grid%configuration%vertical%olthbar(k)
1486  end if
1487  end do
1488  do k=2, current_state%local_grid%size(z_index)-1
1489  if (allocated(u_thetal)) u_thetal(k)=u_thetal(k)+0.5*(upr(k)+uprm1(k))*thlpr(k)
1490  if (allocated(us_thetal)) us_thetal(k)=us_thetal(k)+0.5*(upr(k)+uprm1(k))*&
1491  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(thlpr(k)+thlprp1(k))*&
1492  current_state%su%data(k,current_state%column_local_y,current_state%column_local_x)
1493  if (allocated(u_thetal_advection)) u_thetal_advection(k)=u_thetal_advection(k)+0.5*(upr(k)+uprm1(k))*&
1494  th_advection%real_1d_array(k)+0.5*(thlpr(k)+thlprp1(k))*u_advection%real_1d_array(k)
1496  (thlpr(k)+thlprp1(k))*u_viscosity%real_1d_array(k)+0.5*(upr(k)+uprm1(k))*th_diffusion%real_1d_array(k)
1497  if (allocated(wu_thetal)) wu_thetal(k)=wu_thetal(k)+&
1498  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(upr(k+1)+upr(k)+&
1499  uprm1(k+1)+uprm1(k))*0.5*(thlpr(k+1)+thlpr(k))
1500 
1501  if (allocated(v_thetal)) v_thetal(k)=v_thetal(k)+0.5*(vpr(k)+vprm1(k))*thlpr(k)
1502  if (allocated(vs_thetal)) vs_thetal(k)=vs_thetal(k)+0.5*(vpr(k)+vprm1(k))*&
1503  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(thlpr(k)+thlprp1(k))*&
1504  current_state%sv%data(k,current_state%column_local_y,current_state%column_local_x)
1505  if (allocated(v_thetal_advection)) v_thetal_advection(k)=v_thetal_advection(k)+0.5*(vpr(k)+vprm1(k))*&
1506  th_advection%real_1d_array(k)+0.5*(thlpr(k)+thlprp1(k))*v_advection%real_1d_array(k)
1508  (thlpr(k)+thlprp1(k))*v_viscosity%real_1d_array(k)+0.5*(vpr(k)+vprm1(k))*th_diffusion%real_1d_array(k)
1509  if (allocated(wv_thetal)) wv_thetal(k)=wv_thetal(k)+&
1510  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.25*(vpr(k+1)+vpr(k)+&
1511  vprm1(k+1)+vprm1(k))*0.5*(thlpr(k+1)+thlpr(k))
1512 
1513  if (allocated(w_thetal)) w_thetal(k)=w_thetal(k)+&
1514  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(thlpr(k)+thlpr(k+1))
1515  if (allocated(ws_thetal)) ws_thetal(k)=ws_thetal(k)+&
1516  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1517  (current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+&
1518  current_state%sth%data(k+1,current_state%column_local_y,current_state%column_local_x))+0.5*(thlpr(k)+thlpr(k+1))*&
1519  current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)
1521  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(th_advection%real_1d_array(k)+&
1522  th_advection%real_1d_array(k+1))+0.5*(thlpr(k)+thlpr(k+1))*w_advection%real_1d_array(k)
1524  (thlpr(k)+thlpr(k+1))*w_viscosity%real_1d_array(k)+&
1525  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*&
1526  (th_diffusion%real_1d_array(k)+th_diffusion%real_1d_array(k+1))
1527  if (allocated(w_thetal_buoyancy)) w_thetal_buoyancy(k)=w_thetal_buoyancy(k)+0.5*(thlpr(k+1)+thlpr(k))*&
1528  w_buoyancy%real_1d_array(k)
1529  if (allocated(wv_thetal)) ww_thetal(k)=ww_thetal(k)+0.5*&
1530  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1531  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*0.5*(&
1532  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1533  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*thlpr(k)
1534 
1535  if (allocated(thetal_thetal)) thetal_thetal(k)=thetal_thetal(k)+thlpr(k)*thlpr(k)
1536  if (allocated(sthetal_thetal)) sthetal_thetal(k)=sthetal_thetal(k)+2.0*thlpr(k)*&
1537  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)
1538  if (allocated(thetal_thetal_advection)) thetal_thetal_advection(k)=thetal_thetal_advection(k)+2.0*thlpr(k)*&
1539  th_advection%real_1d_array(k)
1540  if (allocated(thetal_thetal_diffusion)) thetal_thetal_diffusion(k)=thetal_thetal_diffusion(k)+2.0*thlpr(k)*&
1541  th_diffusion%real_1d_array(k)
1542  if (allocated(wthetal_thetal)) wthetal_thetal(k)=wthetal_thetal(k)+&
1543  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(thlpr(k+1)+thlpr(k))*0.5*(&
1544  thlpr(k+1)+thlpr(k))
1545  end do
1546 
1547  if (allocated(u_advection%real_1d_array)) deallocate(u_advection%real_1d_array)
1548  if (allocated(u_viscosity%real_1d_array)) deallocate(u_viscosity%real_1d_array)
1549  if (allocated(th_advection%real_1d_array)) deallocate(th_advection%real_1d_array)
1550  if (allocated(th_diffusion%real_1d_array)) deallocate(th_diffusion%real_1d_array)
1551  if (allocated(v_advection%real_1d_array)) deallocate(v_advection%real_1d_array)
1552  if (allocated(v_viscosity%real_1d_array)) deallocate(v_viscosity%real_1d_array)
1553  if (allocated(w_advection%real_1d_array)) deallocate(w_advection%real_1d_array)
1554  if (allocated(w_viscosity%real_1d_array)) deallocate(w_viscosity%real_1d_array)
1555  if (allocated(w_buoyancy%real_1d_array)) deallocate(w_buoyancy%real_1d_array)
1556  end subroutine compute_thetal_for_column
1557 
1560  if (allocated(tu_su)) tu_su=0.0_default_precision
1561  if (allocated(uu_advection)) uu_advection=0.0_default_precision
1562  if (allocated(uu_viscosity)) uu_viscosity=0.0_default_precision
1563  if (allocated(wu_u)) wu_u=0.0_default_precision
1564  if (allocated(tv_sv)) tv_sv=0.0_default_precision
1565  if (allocated(vv_advection)) vv_advection=0.0_default_precision
1566  if (allocated(vv_viscosity)) vv_viscosity=0.0_default_precision
1567  if (allocated(wv_v)) wv_v=0.0_default_precision
1568  if (allocated(tw_sw)) tw_sw=0.0_default_precision
1569  if (allocated(ww_advection)) ww_advection=0.0_default_precision
1570  if (allocated(ww_viscosity)) ww_viscosity=0.0_default_precision
1571  if (allocated(ww_buoyancy)) ww_buoyancy=0.0_default_precision
1572  end subroutine clear_prognostic_budgets
1573 
1576  subroutine compute_prognostic_budgets_for_column(current_state)
1577  type(model_state_type), target, intent(inout) :: current_state
1578 
1579  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1
1580  type(component_field_value_type) :: u_advection, u_viscosity, v_advection, v_viscosity, w_advection, w_viscosity, w_buoyancy
1581  integer :: k
1582 
1583  if (is_component_field_available("u_advection")) u_advection=get_component_field_value(current_state, "u_advection")
1584  if (is_component_field_available("u_viscosity")) u_viscosity=get_component_field_value(current_state, "u_viscosity")
1585  if (is_component_field_available("v_advection")) v_advection=get_component_field_value(current_state, "v_advection")
1586  if (is_component_field_available("v_viscosity")) v_viscosity=get_component_field_value(current_state, "v_viscosity")
1587  if (is_component_field_available("w_advection")) w_advection=get_component_field_value(current_state, "w_advection")
1588  if (is_component_field_available("w_viscosity")) w_viscosity=get_component_field_value(current_state, "w_viscosity")
1589  if (is_component_field_available("w_buoyancy")) w_buoyancy=get_component_field_value(current_state, "w_buoyancy")
1590 
1591  do k=1, current_state%local_grid%size(z_index)
1592  upr(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x)
1593  uprm1(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)
1594  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
1595  upr(k)=upr(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1596  uprm1(k)=uprm1(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1597  end if
1598  vpr(k)=current_state%v%data(k,current_state%column_local_y,current_state%column_local_x)
1599  vprm1(k)=current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)
1600  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
1601  vpr(k)=vpr(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1602  vprm1(k)=vprm1(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1603  end if
1604  end do
1605  do k=2, current_state%local_grid%size(z_index)-1
1606  if (allocated(tu_su)) tu_su(k)=tu_su(k)+2.0*upr(k)*current_state%su%data(k,current_state%column_local_y,&
1607  current_state%column_local_x)
1608  if (allocated(uu_advection)) uu_advection(k)=uu_advection(k)+2.0*upr(k)*u_advection%real_1d_array(k)
1609  if (allocated(uu_viscosity)) uu_viscosity(k)=uu_viscosity(k)+2.0*upr(k)*u_viscosity%real_1d_array(k)
1610  if (allocated(wu_u)) wu_u(k)=wu_u(k)+0.25*(upr(k)+upr(k+1)+uprm1(k)+uprm1(k+1))*0.25*&
1611  (upr(k)+upr(k+1)+uprm1(k)+uprm1(k+1))*current_state%w%data(k,current_state%column_local_y,&
1612  current_state%column_local_x)
1613  if (allocated(tv_sv)) tv_sv(k)=tv_sv(k)+2.0*vpr(k)*current_state%sv%data(k,current_state%column_local_y,&
1614  current_state%column_local_x)
1615  if (allocated(vv_advection)) vv_advection(k)=vv_advection(k)+2.0*vpr(k)*v_advection%real_1d_array(k)
1616  if (allocated(vv_viscosity)) uu_viscosity(k)=vv_viscosity(k)+2.0*vpr(k)*v_viscosity%real_1d_array(k)
1617  if (allocated(wv_v)) wv_v(k)=wv_v(k)+0.25*(vpr(k)+vpr(k+1)+vprm1(k)+vprm1(k+1))*0.25*&
1618  (vpr(k)+vpr(k+1)+vprm1(k)+vprm1(k+1))*current_state%w%data(k,current_state%column_local_y,&
1619  current_state%column_local_x)
1620  if (allocated(tw_sw)) tw_sw(k)=tw_sw(k)+2.0*current_state%w%data(k,current_state%column_local_y,&
1621  current_state%column_local_x)*current_state%sw%data(k,current_state%column_local_y,&
1622  current_state%column_local_x)
1623  if (allocated(ww_advection)) ww_advection(k)=ww_advection(k)+2.0*current_state%w%data(k,current_state%column_local_y,&
1624  current_state%column_local_x)*w_advection%real_1d_array(k)
1625  if (allocated(ww_viscosity)) ww_viscosity(k)=ww_viscosity(k)+2.0*current_state%w%data(k,current_state%column_local_y,&
1626  current_state%column_local_x)*w_viscosity%real_1d_array(k)
1627  if (allocated(ww_buoyancy)) ww_buoyancy(k)=ww_buoyancy(k)+2.0*current_state%w%data(k,current_state%column_local_y,&
1628  current_state%column_local_x)*w_buoyancy%real_1d_array(k)
1629  end do
1630 
1631  if (allocated(u_advection%real_1d_array)) deallocate(u_advection%real_1d_array)
1632  if (allocated(u_viscosity%real_1d_array)) deallocate(u_viscosity%real_1d_array)
1633  if (allocated(v_advection%real_1d_array)) deallocate(v_advection%real_1d_array)
1634  if (allocated(v_viscosity%real_1d_array)) deallocate(v_viscosity%real_1d_array)
1635  if (allocated(w_advection%real_1d_array)) deallocate(w_advection%real_1d_array)
1636  if (allocated(w_viscosity%real_1d_array)) deallocate(w_viscosity%real_1d_array)
1637  if (allocated(w_buoyancy%real_1d_array)) deallocate(w_buoyancy%real_1d_array)
1639 
1640 
1642  subroutine clear_uw_vw()
1643  if (allocated(uw_advection)) uw_advection=0.0_default_precision
1644  if (allocated(vw_advection)) vw_advection=0.0_default_precision
1645  if (allocated(uw_viscosity)) uw_viscosity=0.0_default_precision
1646  if (allocated(vw_viscosity)) vw_viscosity=0.0_default_precision
1647  if (allocated(uw_buoyancy)) uw_buoyancy=0.0_default_precision
1648  if (allocated(vw_buoyancy)) vw_buoyancy=0.0_default_precision
1649  if (allocated(uw_tendency)) uw_tendency=0.0_default_precision
1650  if (allocated(vw_tendency)) vw_tendency=0.0_default_precision
1651  if (allocated(uw_w)) uw_w=0.0_default_precision
1652  if (allocated(vw_w)) vw_w=0.0_default_precision
1653  end subroutine clear_uw_vw
1655  subroutine clear_tke()
1656  if (allocated(sres)) sres=0.0_default_precision
1657  if (allocated(wke)) wke=0.0_default_precision
1658  if (allocated(wp)) wp=0.0_default_precision
1659  if (allocated(buoy)) buoy=0.0_default_precision
1660  if (allocated(tend)) tend=0.0_default_precision
1661  end subroutine clear_tke
1662 
1665  subroutine compute_uw_vw_for_column(current_state)
1666  type(model_state_type), target, intent(inout) :: current_state
1667 
1668  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1
1669  type(component_field_value_type) :: w_advection, v_advection, u_advection, w_viscosity, v_viscosity, u_viscosity, &
1670  w_buoyancy
1671  integer :: k
1672 
1673  if (is_component_field_available("w_advection")) w_advection=get_component_field_value(current_state, "w_advection")
1674  if (is_component_field_available("v_advection")) v_advection=get_component_field_value(current_state, "v_advection")
1675  if (is_component_field_available("u_advection")) u_advection=get_component_field_value(current_state, "u_advection")
1676  if (is_component_field_available("w_viscosity")) w_viscosity=get_component_field_value(current_state, "w_viscosity")
1677  if (is_component_field_available("v_viscosity")) v_viscosity=get_component_field_value(current_state, "v_viscosity")
1678  if (is_component_field_available("u_viscosity")) u_viscosity=get_component_field_value(current_state, "u_viscosity")
1679  if (is_component_field_available("w_buoyancy")) w_buoyancy=get_component_field_value(current_state, "w_buoyancy")
1680 
1681  do k=1, current_state%local_grid%size(z_index)
1682  upr(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x)
1683  uprm1(k)=current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)
1684  if (allocated(current_state%global_grid%configuration%vertical%olubar)) then
1685  upr(k)=upr(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1686  uprm1(k)=uprm1(k)-(current_state%global_grid%configuration%vertical%olubar(k)-current_state%ugal)
1687  end if
1688  vpr(k)=current_state%v%data(k,current_state%column_local_y,current_state%column_local_x)
1689  vprm1(k)=current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)
1690  if (allocated(current_state%global_grid%configuration%vertical%olvbar)) then
1691  vpr(k)=vpr(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1692  vprm1(k)=vprm1(k)-(current_state%global_grid%configuration%vertical%olvbar(k)-current_state%vgal)
1693  end if
1694  end do
1695  do k=2, current_state%local_grid%size(z_index)-1
1696  if (allocated(uw_advection)) uw_advection(k)=uw_advection(k)+0.5*(upr(k)+uprm1(k))*0.5*&
1697  (w_advection%real_1d_array(k)+w_advection%real_1d_array(k-1))+0.25*(&
1698  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1699  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1700  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1701  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*u_advection%real_1d_array(k)
1702  if (allocated(vw_advection)) vw_advection(k)=vw_advection(k)+0.5*(vpr(k)+vprm1(k))*0.5*&
1703  (w_advection%real_1d_array(k)+w_advection%real_1d_array(k-1))+0.25*(&
1704  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1705  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1706  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1707  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*v_advection%real_1d_array(k)
1708  if (allocated(uw_viscosity)) uw_viscosity(k)=uw_viscosity(k)+0.5*(upr(k)+uprm1(k))*0.5*&
1709  (w_viscosity%real_1d_array(k)+w_viscosity%real_1d_array(k-1))+0.25*(&
1710  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1711  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1712  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1713  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*u_viscosity%real_1d_array(k)
1714  if (allocated(vw_viscosity)) vw_viscosity(k)=vw_viscosity(k)+0.5*(vpr(k)+vprm1(k))*0.5*&
1715  (w_viscosity%real_1d_array(k)+w_viscosity%real_1d_array(k-1))+0.25*(&
1716  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1717  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1718  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1719  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*v_viscosity%real_1d_array(k)
1720  if (allocated(uw_buoyancy)) uw_buoyancy(k)=uw_buoyancy(k)+0.5*(upr(k)+uprm1(k))*0.5*(&
1721  w_buoyancy%real_1d_array(k)+w_buoyancy%real_1d_array(k-1))
1722  if (allocated(vw_buoyancy)) vw_buoyancy(k)=vw_buoyancy(k)+0.5*(vpr(k)+vprm1(k))*0.5*(&
1723  w_buoyancy%real_1d_array(k)+w_buoyancy%real_1d_array(k-1))
1724  if (allocated(uw_tendency)) uw_tendency(k)=uw_tendency(k)+0.25*(&
1725  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1726  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1727  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1728  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*&
1729  current_state%su%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(&
1730  current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)+&
1731  current_state%sw%data(k-1,current_state%column_local_y,current_state%column_local_x))*0.5*(upr(k)+uprm1(k))
1732  if (allocated(vw_tendency)) vw_tendency(k)=vw_tendency(k)+0.25*(&
1733  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
1734  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)+&
1735  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x+1)+&
1736  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x+1))*&
1737  current_state%sv%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*(&
1738  current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)+&
1739  current_state%sw%data(k-1,current_state%column_local_y,current_state%column_local_x))*0.5*(vpr(k)+vprm1(k))
1740  if (allocated(uw_w)) uw_w(k)=uw_w(k)+0.25*(upr(k)+upr(k+1)+uprm1(k)+uprm1(k+1))*&
1741  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*&
1742  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)
1743  if (allocated(vw_w)) vw_w(k)=vw_w(k)+0.25*(vpr(k)+vpr(k+1)+vprm1(k)+vprm1(k+1))*&
1744  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*&
1745  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)
1746  end do
1747 
1748  if (allocated(u_advection%real_1d_array)) deallocate(u_advection%real_1d_array)
1749  if (allocated(u_viscosity%real_1d_array)) deallocate(u_viscosity%real_1d_array)
1750  if (allocated(v_advection%real_1d_array)) deallocate(v_advection%real_1d_array)
1751  if (allocated(v_viscosity%real_1d_array)) deallocate(v_viscosity%real_1d_array)
1752  if (allocated(w_advection%real_1d_array)) deallocate(w_advection%real_1d_array)
1753  if (allocated(w_viscosity%real_1d_array)) deallocate(w_viscosity%real_1d_array)
1754  if (allocated(w_buoyancy%real_1d_array)) deallocate(w_buoyancy%real_1d_array)
1755  end subroutine compute_uw_vw_for_column
1756 
1757 
1760  subroutine compute_tke_for_column(current_state)
1761  type(model_state_type), target, intent(inout) :: current_state
1762 
1763  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: upr, vpr, uprm1, vprm1, &
1764  uu_tendency,vv_tendency,ww_tendency
1765  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: umean, wu_umean, vmean, wv_vmean, &
1766  w_pprime_at_p, rke1, w_qvprime_at_w, w_qclprime_at_w, w_thprime_at_w, wq, rho, rec_rho, rhon, rec_rhon, &
1767  uw_tot, vw_tot,w_upr_at_w,w_vpr_at_w, w_buoyancy
1768  real(kind=default_precision) :: u_at_p, v_at_p, w_at_p
1769  real(kind=default_precision) :: c_virtual
1770 
1771  integer :: k, n
1772 
1773  c_virtual = (ratio_mol_wts-1.0_default_precision)
1774 
1775  !Resolved diagnostics
1776 ! ***********************Buoyant production 1/2 ***************************
1777 
1778  do k=1, current_state%local_grid%size(z_index)
1779  rho(k)=current_state%global_grid%configuration%vertical%rho(k)
1780  rhon(k)=current_state%global_grid%configuration%vertical%rhon(k)
1781  rec_rho(k)=1.0_default_precision/rho(k)
1782  rec_rhon(k)=1.0_default_precision/rhon(k)
1783  enddo
1784 
1785 
1786 ! ***********************TKE Tendency ***************************
1787 
1788  do k=2, current_state%local_grid%size(z_index)
1789 
1790  uu_tendency(k) = ((current_state%u%data(k,current_state%column_local_y,current_state%column_local_x) - &
1791  current_state%global_grid%configuration%vertical%olubar(k) )**2 - &
1792  (current_state%zu%data(k,current_state%column_local_y,current_state%column_local_x) - &
1793  current_state%global_grid%configuration%vertical%olzubar(k) )**2 ) / &
1794  current_state%dtm
1795 
1796  vv_tendency(k) = ((current_state%v%data(k,current_state%column_local_y,current_state%column_local_x) - &
1797  current_state%global_grid%configuration%vertical%olvbar(k) )**2 - &
1798  (current_state%zv%data(k,current_state%column_local_y,current_state%column_local_x) - &
1799  current_state%global_grid%configuration%vertical%olzvbar(k) )**2 ) / &
1800  current_state%dtm
1801 
1802  ww_tendency(k) = (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x) * &
1803  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x) - &
1804  current_state%zw%data(k,current_state%column_local_y,current_state%column_local_x) * &
1805  current_state%zw%data(k,current_state%column_local_y,current_state%column_local_x)) / &
1806  current_state%dtm
1807 
1808  enddo
1809 
1810  uu_tendency(1) = -uu_tendency(2)
1811  vv_tendency(1) = -vv_tendency(2)
1812 
1813  if (allocated(tend)) then
1814  do k=2, current_state%local_grid%size(z_index)-1
1815  tend(k)=tend(k) + 0.5_default_precision * (&
1816  0.5_default_precision * (uu_tendency(k)+uu_tendency(k+1)) + &
1817  0.5_default_precision * (vv_tendency(k)+vv_tendency(k+1)) + &
1818  ww_tendency(k) )
1819  enddo
1820  end if
1821 
1822 ! ***********************Shear production ***************************
1823 
1824  do k=2, current_state%local_grid%size(z_index)-1
1825 
1826  umean(k)=(current_state%global_grid%configuration%vertical%olubar(k+1) -&
1827  current_state%global_grid%configuration%vertical%olubar(k))* &
1828  current_state%global_grid%configuration%vertical%rdzn(k+1)
1829 
1830  w_upr_at_w(k) =current_state%w%data(k,current_state%column_local_y,current_state%column_local_x) * &
1831  (0.25_default_precision * ( &
1832  (current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1) - &
1833  current_state%global_grid%configuration%vertical%olubar(k)) + &
1834  (current_state%u%data(k+1,current_state%column_local_y,current_state%column_local_x) - &
1835  current_state%global_grid%configuration%vertical%olubar(k+1)) + &
1836  (current_state%u%data(k,current_state%column_local_y,current_state%column_local_x) - &
1837  current_state%global_grid%configuration%vertical%olubar(k)) + &
1838  (current_state%u%data(k+1,current_state%column_local_y,current_state%column_local_x-1)- &
1839  current_state%global_grid%configuration%vertical%olubar(k+1)) ) )
1840 
1841  vmean(k)=(current_state%global_grid%configuration%vertical%olvbar(k+1) - &
1842  current_state%global_grid%configuration%vertical%olvbar(k)) * &
1843  current_state%global_grid%configuration%vertical%rdzn(k+1)
1844 
1845  w_vpr_at_w(k) =current_state%w%data(k,current_state%column_local_y,current_state%column_local_x) * &
1846  (0.25_default_precision * ( &
1847  (current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x) - &
1848  current_state%global_grid%configuration%vertical%olvbar(k)) + &
1849  (current_state%v%data(k+1,current_state%column_local_y,current_state%column_local_x) - &
1850  current_state%global_grid%configuration%vertical%olvbar(k+1)) + &
1851  (current_state%v%data(k,current_state%column_local_y,current_state%column_local_x) - &
1852  current_state%global_grid%configuration%vertical%olvbar(k)) + &
1853  (current_state%v%data(k+1,current_state%column_local_y-1,current_state%column_local_x)- &
1854  current_state%global_grid%configuration%vertical%olvbar(k+1)) ) )
1855 
1856  wu_umean(k)=(w_upr_at_w(k)*umean(k))
1857  wv_vmean(k)= (w_vpr_at_w(k)*vmean(k))
1858 
1859  if (allocated(sres)) then
1860  sres(k)=sres(k) - (wv_vmean(k) + wu_umean(k))
1861  end if
1862 
1863  end do
1864  sres(1)=0.0_default_precision
1865  sres(current_state%local_grid%size(z_index))=0.0_default_precision
1866 
1867  do k=2, current_state%local_grid%size(z_index)
1868 
1869 ! *********************** Pressure transport ***************************
1870  !In current state - p=p/rho (rho here is on same levels as p)
1871  ! Note - calculating on z levels (i.e. w)
1872  ! So need w'p' on p levels
1873 
1874  w_pprime_at_p(k) = 0.5 * &
1875  (current_state%w%data(k, current_state%column_local_y,current_state%column_local_x) + &
1876  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x)) * &
1877  (current_state%global_grid%configuration%vertical%rhon(k) * &
1878  current_state%p%data(k,current_state%column_local_y,current_state%column_local_x))
1879 
1880  u_at_p = 0.5_default_precision * &
1881  ((current_state%u%data(k,current_state%column_local_y,current_state%column_local_x-1)- &
1882  current_state%global_grid%configuration%vertical%olubar(k)) + &
1883  (current_state%u%data(k,current_state%column_local_y,current_state%column_local_x) - &
1884  current_state%global_grid%configuration%vertical%olubar(k)))
1885 
1886  v_at_p = 0.5_default_precision * &
1887  ((current_state%v%data(k,current_state%column_local_y-1,current_state%column_local_x)- &
1888  current_state%global_grid%configuration%vertical%olvbar(k)) + &
1889  (current_state%v%data(k,current_state%column_local_y,current_state%column_local_x) - &
1890  current_state%global_grid%configuration%vertical%olvbar(k)))
1891 
1892  w_at_p = 0.5_default_precision * &
1893  (current_state%w%data(k, current_state%column_local_y,current_state%column_local_x) + &
1894  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))
1895 
1896  rke1(k)= 0.5_default_precision * w_at_p * &
1897  ( u_at_p*u_at_p + v_at_p*v_at_p + w_at_p*w_at_p) * rec_rhon(k)
1898 
1899  end do
1900 
1901  w_pprime_at_p(current_state%local_grid%size(z_index)) = 0.0_default_precision
1902  ! Zero gradient at surface
1903  w_pprime_at_p(1)=w_pprime_at_p(2)
1904  if (allocated(wp)) then
1905  do k=1, current_state%local_grid%size(z_index)-1
1906  wp(k)= wp(k) - ((w_pprime_at_p(k+1) - w_pprime_at_p(k)) * &
1907  current_state%global_grid%configuration%vertical%rdzn(k+1) * rec_rho(k))
1908  end do
1909  end if
1910 
1911  rke1(current_state%local_grid%size(z_index)) = 0.0_default_precision
1912  ! Zero gradient at surface
1913  rke1(1)=rke1(2)
1914 
1915  if (allocated(wke)) then
1916  do k=1, current_state%local_grid%size(z_index)-1
1917  wke(k) = wke(k) -(rho(k) * (rke1(k+1) - rke1(k) ) * &
1918  current_state%global_grid%configuration%vertical%rdzn(k+1))
1919  end do
1920  end if
1921 
1922 ! *********************** Subgrid buoyant production***************************
1923 !!!Using buoyancy.F90
1924 
1925 #ifdef W_ACTIVE
1926  if (.not. current_state%passive_th .and. current_state%th%active) then
1927  do k=2,current_state%local_grid%size(z_index)-1
1928  w_buoyancy(k)=(0.5_default_precision*current_state%global_grid%configuration%vertical%buoy_co(k)) * &
1929  ((current_state%th%data(k, current_state%column_local_y, current_state%column_local_x) - &
1930  current_state%global_grid%configuration%vertical%olthbar(k)) + &
1931  (current_state%th%data(k+1, current_state%column_local_y, current_state%column_local_x) - &
1932  current_state%global_grid%configuration%vertical%olthbar(k+1)))
1933  end do
1934  end if
1935 
1936  if (.not. current_state%passive_q .and. current_state%number_q_fields .gt. 0) then
1937  if (current_state%use_anelastic_equations) then
1938  do n=1,current_state%number_q_fields
1939  do k=2,current_state%local_grid%size(z_index)-1
1940  w_buoyancy(k) = w_buoyancy(k) + &
1941  (0.5_default_precision*current_state%global_grid%configuration%vertical%buoy_co(k)) * &
1942  current_state%cq(n) * &
1943  (current_state%global_grid%configuration%vertical%thref(k)*&
1944  (current_state%q(n)%data(k, current_state%column_local_y, current_state%column_local_x) - &
1945  current_state%global_grid%configuration%vertical%olqbar(k,n)) + &
1946  current_state%global_grid%configuration%vertical%thref(k+1) * &
1947  (current_state%q(n)%data(k+1, current_state%column_local_y, current_state%column_local_x) - &
1948  current_state%global_grid%configuration%vertical%olqbar(k+1,n)))
1949  end do
1950  end do
1951  else
1952  do n=1,current_state%number_q_fields
1953  do k=2,current_state%local_grid%size(z_index)-1
1954  w_buoyancy(k) = w_buoyancy(k) + &
1955  g*0.5_default_precision*current_state%cq(n)*&
1956  (current_state%q(n)%data(k, current_state%column_local_y, current_state%column_local_x) -&
1957  current_state%global_grid%configuration%vertical%olqbar(k,n) + &
1958  current_state%q(n)%data(k+1, current_state%column_local_y, current_state%column_local_x)- &
1959  current_state%global_grid%configuration%vertical%olqbar(k,n))
1960  end do
1961  end do
1962  end if
1963  end if
1964 
1965  do k=2, current_state%local_grid%size(z_index)-1
1966  if (allocated(buoy)) then
1967  buoy(k) = buoy(k) + &
1968  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x) * &
1969  w_buoyancy(k)
1970  end if
1971  end do
1972 
1973 #endif
1974 
1975  buoy(1) = 0.0_default_precision
1976  buoy(current_state%local_grid%size(z_index)) = 0.0_default_precision
1977 
1978  end subroutine compute_tke_for_column
1979 
1981  subroutine clear_q_fluxes()
1982  if (allocated(q_flux_values)) q_flux_values=0.0_default_precision
1983  if (allocated(q_gradient)) q_gradient=0.0_default_precision
1984  if (allocated(q_diff)) q_diff=0.0_default_precision
1985  if (allocated(q_buoyancy)) q_buoyancy=0.0_default_precision
1986  if (allocated(q_tendency)) q_tendency=0.0_default_precision
1987  end subroutine clear_q_fluxes
1988 
1991  subroutine compute_q_flux_for_column(current_state)
1992  type(model_state_type), target, intent(inout) :: current_state
1993 
1994  integer :: k, n
1995  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: qpr
1996  type(component_field_value_type) :: w_advection_published_value, q_advection_published_value, w_viscosity_published_value, &
1997  q_diffusion_published_value, w_buoyancy_published_value
1998 
1999  if (allocated(q_gradient)) then
2000  w_advection_published_value=get_component_field_value(current_state, "w_advection")
2001  q_advection_published_value=get_component_field_value(current_state, "q_advection")
2002  end if
2003  if (allocated(q_diff)) then
2004  w_viscosity_published_value=get_component_field_value(current_state, "w_viscosity")
2005  q_diffusion_published_value=get_component_field_value(current_state, "q_diffusion")
2006  end if
2007  if (allocated(q_buoyancy)) then
2008  w_buoyancy_published_value=get_component_field_value(current_state, "w_buoyancy")
2009  end if
2010 
2011  do n=1, current_state%number_q_fields
2012  do k=1, current_state%local_grid%size(z_index)
2013  qpr(k)=current_state%q(n)%data(k,current_state%column_local_y,current_state%column_local_x)
2014  if (allocated(current_state%global_grid%configuration%vertical%olqbar)) then
2015  qpr(k)=qpr(k)-current_state%global_grid%configuration%vertical%olqbar(k,n)
2016  end if
2017  end do
2018  do k=2, current_state%local_grid%size(z_index)-1
2019  if (allocated(q_flux_values)) q_flux_values(k,n)=q_flux_values(k,n)+&
2020  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*&
2021  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(qpr(k)+qpr(k+1))
2022  if (allocated(q_tendency)) q_tendency(k,n)=q_tendency(k,n)+0.5*&
2023  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2024  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2025  current_state%sq(n)%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*&
2026  qpr(k)*(current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)+&
2027  current_state%sw%data(k-1,current_state%column_local_y,current_state%column_local_x))
2028  if (allocated(q_gradient)) then
2029  q_gradient(k,n)=q_gradient(k,n)+qpr(k)*0.5*(w_advection_published_value%real_1d_array(k)+&
2030  w_advection_published_value%real_1d_array(k-1))+0.5*&
2031  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2032  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2033  q_advection_published_value%real_2d_array(k, n)
2034  end if
2035  if (allocated(q_diff)) then
2036  q_diff(k,n)=q_diff(k,n)+qpr(k)*0.5*(w_viscosity_published_value%real_1d_array(k)+&
2037  w_viscosity_published_value%real_1d_array(k-1))+&
2038  0.5*(current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2039  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2040  q_diffusion_published_value%real_2d_array(k,n)
2041  end if
2042  if (allocated(q_buoyancy)) then
2043  q_buoyancy(k,n)=q_buoyancy(k,n)+qpr(k)*0.5*(w_buoyancy_published_value%real_1d_array(k)+&
2044  w_buoyancy_published_value%real_1d_array(k-1))
2045  end if
2046  end do
2047  end do
2048  if (allocated(w_advection_published_value%real_1d_array)) deallocate(w_advection_published_value%real_1d_array)
2049  if (allocated(q_advection_published_value%real_2d_array)) deallocate(q_advection_published_value%real_2d_array)
2050  if (allocated(w_viscosity_published_value%real_1d_array)) deallocate(w_viscosity_published_value%real_1d_array)
2051  if (allocated(q_diffusion_published_value%real_2d_array)) deallocate(q_diffusion_published_value%real_2d_array)
2052  if (allocated(w_buoyancy_published_value%real_1d_array)) deallocate(w_buoyancy_published_value%real_1d_array)
2053  end subroutine compute_q_flux_for_column
2054 
2056  subroutine clear_theta_fluxes()
2057  if (allocated(th_flux_values)) th_flux_values=0.0_default_precision
2058  if (allocated(th_tendency)) th_tendency=0.0_default_precision
2059  if (allocated(th_gradient)) th_gradient=0.0_default_precision
2060  if (allocated(th_diff)) th_diff=0.0_default_precision
2061  if (allocated(th_buoyancy)) th_buoyancy=0.0_default_precision
2062  end subroutine clear_theta_fluxes
2063 
2066  subroutine compute_theta_flux_for_column(current_state)
2067  type(model_state_type), target, intent(inout) :: current_state
2068 
2069  integer :: k
2070  real(kind=default_precision), dimension(current_state%local_grid%size(Z_INDEX)) :: thpr
2071  type(component_field_value_type) :: w_advection_published_value, th_advection_published_value, w_viscosity_published_value, &
2072  th_diffusion_published_value, w_buoyancy_published_value
2073 
2074  do k=1, current_state%local_grid%size(z_index)
2075  thpr(k)=current_state%th%data(k,current_state%column_local_y,current_state%column_local_x)
2076  if (allocated(current_state%global_grid%configuration%vertical%olthbar)) then
2077  thpr(k)=thpr(k)-current_state%global_grid%configuration%vertical%olthbar(k)
2078  end if
2079  end do
2080  if (allocated(th_gradient)) then
2081  w_advection_published_value=get_component_field_value(current_state, "w_advection")
2082  th_advection_published_value=get_component_field_value(current_state, "th_advection")
2083  end if
2084  if (allocated(th_diff)) then
2085  w_viscosity_published_value=get_component_field_value(current_state, "w_viscosity")
2086  th_diffusion_published_value=get_component_field_value(current_state, "th_diffusion")
2087  end if
2088  if (allocated(th_buoyancy)) then
2089  w_buoyancy_published_value=get_component_field_value(current_state, "w_buoyancy")
2090  end if
2091  do k=2, current_state%local_grid%size(z_index)-1
2092  if (allocated(th_flux_values)) th_flux_values(k)=th_flux_values(k)+&
2093  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*&
2094  current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)*0.5*(thpr(k)+thpr(k+1))
2095  if (allocated(th_tendency)) th_tendency(k)=th_tendency(k)+0.5*&
2096  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2097  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2098  current_state%sth%data(k,current_state%column_local_y,current_state%column_local_x)+0.5*&
2099  thpr(k)*(current_state%sw%data(k,current_state%column_local_y,current_state%column_local_x)+&
2100  current_state%sw%data(k-1,current_state%column_local_y,current_state%column_local_x))
2101  if (allocated(th_gradient)) then
2102  th_gradient(k)=th_gradient(k)+thpr(k)*0.5*(w_advection_published_value%real_1d_array(k)+&
2103  w_advection_published_value%real_1d_array(k-1))+0.5*&
2104  (current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2105  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2106  th_advection_published_value%real_1d_array(k)
2107  end if
2108  if (allocated(th_diff)) then
2109  th_diff(k)=th_diff(k)+thpr(k)*0.5*(w_viscosity_published_value%real_1d_array(k)+&
2110  w_viscosity_published_value%real_1d_array(k-1))+&
2111  0.5*(current_state%w%data(k,current_state%column_local_y,current_state%column_local_x)+&
2112  current_state%w%data(k-1,current_state%column_local_y,current_state%column_local_x))*&
2113  th_diffusion_published_value%real_1d_array(k)
2114  end if
2115  if (allocated(th_buoyancy)) then
2116  th_buoyancy(k)=th_buoyancy(k)+thpr(k)*0.5*(w_buoyancy_published_value%real_1d_array(k)+&
2117  w_buoyancy_published_value%real_1d_array(k-1))
2118  end if
2119  end do
2120  if (allocated(w_advection_published_value%real_1d_array)) deallocate(w_advection_published_value%real_1d_array)
2121  if (allocated(th_advection_published_value%real_1d_array)) deallocate(th_advection_published_value%real_1d_array)
2122  if (allocated(w_viscosity_published_value%real_1d_array)) deallocate(w_viscosity_published_value%real_1d_array)
2123  if (allocated(th_diffusion_published_value%real_1d_array)) deallocate(th_diffusion_published_value%real_1d_array)
2124  if (allocated(w_buoyancy_published_value%real_1d_array)) deallocate(w_buoyancy_published_value%real_1d_array)
2125  end subroutine compute_theta_flux_for_column
2126 
2130  logical function is_field_heat_flux(name)
2131  character(len=*), intent(in) :: name
2132 
2133  is_field_heat_flux=c_contains(heat_flux_fields, name)
2134  end function is_field_heat_flux
2135 
2139  logical function is_field_tke_flux(name)
2140  character(len=*), intent(in) :: name
2141 
2142  is_field_tke_flux=c_contains(tke_fields, name)
2143  end function is_field_tke_flux
2144 
2148  logical function is_field_q_flux(name)
2149  character(len=*), intent(in) :: name
2150 
2151  is_field_q_flux=c_contains(q_flux_fields, name)
2152  end function is_field_q_flux
2153 
2157  logical function is_field_uw_vw(name)
2158  character(len=*), intent(in) :: name
2159 
2160  is_field_uw_vw=c_contains(uw_vw_fields, name)
2161  end function is_field_uw_vw
2162 
2166  logical function is_field_prognostic_budget(name)
2167  character(len=*), intent(in) :: name
2168 
2170  end function is_field_prognostic_budget
2171 
2175  logical function is_field_thetal(name)
2176  character(len=*), intent(in) :: name
2177 
2178  is_field_thetal=c_contains(thetal_fields, name)
2179  end function is_field_thetal
2180 
2184  logical function is_field_mse(name)
2185  character(len=*), intent(in) :: name
2186 
2187  is_field_mse=c_contains(mse_fields, name)
2188  end function is_field_mse
2189 
2193  logical function is_field_qt(name)
2194  character(len=*), intent(in) :: name
2195 
2196  is_field_qt=c_contains(qt_fields, name)
2197  end function is_field_qt
2198 
2202  logical function is_field_scalar(name)
2203  character(len=*), intent(in) :: name
2204 
2205  is_field_scalar=c_contains(scalar_fields, name)
2206  end function is_field_scalar
2207 
2212  subroutine field_value_retrieval_callback(current_state, name, field_value)
2213  type(model_state_type), target, intent(inout) :: current_state
2214  character(len=*), intent(in) :: name
2215  type(component_field_value_type), intent(out) :: field_value
2216 
2217  if (name .eq. "heat_flux_transport_local" .and. allocated(th_flux_values)) then
2218  call set_published_field_value(field_value, real_1d_field=th_flux_values)
2219  else if (name .eq. "heat_flux_gradient_local" .and. allocated(th_gradient)) then
2220  call set_published_field_value(field_value, real_1d_field=th_gradient)
2221  else if (name .eq. "heat_flux_dissipation_local" .and. allocated(th_diff)) then
2222  call set_published_field_value(field_value, real_1d_field=th_diff)
2223  else if (name .eq. "heat_flux_buoyancy_local" .and. allocated(th_buoyancy)) then
2224  call set_published_field_value(field_value, real_1d_field=th_buoyancy)
2225  else if (name .eq. "heat_flux_tendency_local" .and. allocated(th_tendency)) then
2226  call set_published_field_value(field_value, real_1d_field=th_tendency)
2227  else if (name .eq. "q_flux_transport_local" .and. allocated(q_flux_values)) then
2228  call set_published_field_value(field_value, real_2d_field=q_flux_values)
2229  else if (name .eq. "q_flux_gradient_local" .and. allocated(q_gradient)) then
2230  call set_published_field_value(field_value, real_2d_field=q_gradient)
2231  else if (name .eq. "q_flux_dissipation_local" .and. allocated(q_diff)) then
2232  call set_published_field_value(field_value, real_2d_field=q_diff)
2233  else if (name .eq. "q_flux_buoyancy_local" .and. allocated(q_buoyancy)) then
2234  call set_published_field_value(field_value, real_2d_field=q_buoyancy)
2235  else if (name .eq. "q_flux_tendency_local" .and. allocated(q_tendency)) then
2236  call set_published_field_value(field_value, real_2d_field=q_tendency)
2237  else if (name .eq. "uw_advection_local" .and. allocated(uw_advection)) then
2238  call set_published_field_value(field_value, real_1d_field=uw_advection)
2239  else if (name .eq. "vw_advection_local" .and. allocated(vw_advection)) then
2240  call set_published_field_value(field_value, real_1d_field=vw_advection)
2241  else if (name .eq. "uw_viscosity_local" .and. allocated(uw_viscosity)) then
2242  call set_published_field_value(field_value, real_1d_field=uw_viscosity)
2243  else if (name .eq. "vw_viscosity_local" .and. allocated(vw_viscosity)) then
2244  call set_published_field_value(field_value, real_1d_field=vw_viscosity)
2245  else if (name .eq. "uw_buoyancy_local" .and. allocated(uw_buoyancy)) then
2246  call set_published_field_value(field_value, real_1d_field=uw_buoyancy)
2247  else if (name .eq. "vw_buoyancy_local" .and. allocated(vw_buoyancy)) then
2248  call set_published_field_value(field_value, real_1d_field=vw_buoyancy)
2249  else if (name .eq. "uw_tendency_local" .and. allocated(uw_tendency)) then
2250  call set_published_field_value(field_value, real_1d_field=uw_tendency)
2251  else if (name .eq. "vw_tendency_local" .and. allocated(vw_tendency)) then
2252  call set_published_field_value(field_value, real_1d_field=vw_tendency)
2253  else if (name .eq. "uw_w_local" .and. allocated(uw_w)) then
2254  call set_published_field_value(field_value, real_1d_field=uw_w)
2255  else if (name .eq. "vw_w_local" .and. allocated(vw_w)) then
2256  call set_published_field_value(field_value, real_1d_field=vw_w)
2257  else if (name .eq. "resolved_pressure_transport_local" .and. allocated(wp)) then
2258  call set_published_field_value(field_value, real_1d_field=wp)
2259  else if (name .eq. "tke_tendency_local" .and. allocated(tend)) then
2260  call set_published_field_value(field_value, real_1d_field=tend)
2261  else if (name .eq. "resolved_shear_production_local" .and. allocated(sres)) then
2262  call set_published_field_value(field_value, real_1d_field=sres)
2263  else if (name .eq. "resolved_turbulent_transport_local" .and. allocated(wke)) then
2264  call set_published_field_value(field_value, real_1d_field=wke)
2265  else if (name .eq. "resolved_buoyant_production_local" .and. allocated(buoy)) then
2266  call set_published_field_value(field_value, real_1d_field=buoy)
2267  else if (name .eq. "tu_su_local" .and. allocated(tu_su)) then
2268  call set_published_field_value(field_value, real_1d_field=tu_su)
2269  else if (name .eq. "uu_advection_local" .and. allocated(uu_advection)) then
2270  call set_published_field_value(field_value, real_1d_field=uu_advection)
2271  else if (name .eq. "uu_viscosity_local" .and. allocated(uu_viscosity)) then
2272  call set_published_field_value(field_value, real_1d_field=uu_viscosity)
2273  else if (name .eq. "wu_u_local" .and. allocated(wu_u)) then
2274  call set_published_field_value(field_value, real_1d_field=wu_u)
2275  else if (name .eq. "tv_sv_local" .and. allocated(tv_sv)) then
2276  call set_published_field_value(field_value, real_1d_field=tv_sv)
2277  else if (name .eq. "vv_advection_local" .and. allocated(vv_advection)) then
2278  call set_published_field_value(field_value, real_1d_field=vv_advection)
2279  else if (name .eq. "vv_viscosity_local" .and. allocated(vv_viscosity)) then
2280  call set_published_field_value(field_value, real_1d_field=vv_viscosity)
2281  else if (name .eq. "wv_v_local" .and. allocated(wv_v)) then
2282  call set_published_field_value(field_value, real_1d_field=wv_v)
2283  else if (name .eq. "tw_sw_local" .and. allocated(tw_sw)) then
2284  call set_published_field_value(field_value, real_1d_field=tw_sw)
2285  else if (name .eq. "ww_advection_local" .and. allocated(ww_advection)) then
2286  call set_published_field_value(field_value, real_1d_field=ww_advection)
2287  else if (name .eq. "ww_viscosity_local" .and. allocated(ww_viscosity)) then
2288  call set_published_field_value(field_value, real_1d_field=ww_viscosity)
2289  else if (name .eq. "ww_buoyancy_local" .and. allocated(ww_buoyancy)) then
2290  call set_published_field_value(field_value, real_1d_field=ww_buoyancy)
2291  else if (name .eq. "u_thetal_local" .and. allocated(u_thetal)) then
2292  call set_published_field_value(field_value, real_1d_field=u_thetal)
2293  else if (name .eq. "us_thetal_local" .and. allocated(us_thetal)) then
2294  call set_published_field_value(field_value, real_1d_field=us_thetal)
2295  else if (name .eq. "u_thetal_advection_local" .and. allocated(u_thetal_advection)) then
2296  call set_published_field_value(field_value, real_1d_field=u_thetal_advection)
2297  else if (name .eq. "u_thetal_viscosity_diffusion_local" .and. allocated(u_thetal_viscosity_diffusion)) then
2298  call set_published_field_value(field_value, real_1d_field=u_thetal_viscosity_diffusion)
2299  else if (name .eq. "wu_thetal_local" .and. allocated(wu_thetal)) then
2300  call set_published_field_value(field_value, real_1d_field=wu_thetal)
2301  else if (name .eq. "v_thetal_local" .and. allocated(v_thetal)) then
2302  call set_published_field_value(field_value, real_1d_field=v_thetal)
2303  else if (name .eq. "vs_thetal_local" .and. allocated(vs_thetal)) then
2304  call set_published_field_value(field_value, real_1d_field=vs_thetal)
2305  else if (name .eq. "v_thetal_advection_local" .and. allocated(v_thetal_advection)) then
2306  call set_published_field_value(field_value, real_1d_field=v_thetal_advection)
2307  else if (name .eq. "v_thetal_viscosity_diffusion_local" .and. allocated(v_thetal_viscosity_diffusion)) then
2308  call set_published_field_value(field_value, real_1d_field=v_thetal_viscosity_diffusion)
2309  else if (name .eq. "wv_thetal_local" .and. allocated(wv_thetal)) then
2310  call set_published_field_value(field_value, real_1d_field=wv_thetal)
2311  else if (name .eq. "w_thetal_local" .and. allocated(w_thetal)) then
2312  call set_published_field_value(field_value, real_1d_field=w_thetal)
2313  else if (name .eq. "ws_thetal_local" .and. allocated(ws_thetal)) then
2314  call set_published_field_value(field_value, real_1d_field=ws_thetal)
2315  else if (name .eq. "w_thetal_advection_local" .and. allocated(w_thetal_advection)) then
2316  call set_published_field_value(field_value, real_1d_field=w_thetal_advection)
2317  else if (name .eq. "w_thetal_viscosity_diffusion_local" .and. allocated(w_thetal_viscosity_diffusion)) then
2318  call set_published_field_value(field_value, real_1d_field=w_thetal_viscosity_diffusion)
2319  else if (name .eq. "w_thetal_buoyancy_local" .and. allocated(w_thetal_buoyancy)) then
2320  call set_published_field_value(field_value, real_1d_field=w_thetal_buoyancy)
2321  else if (name .eq. "ww_thetal_local" .and. allocated(ww_thetal)) then
2322  call set_published_field_value(field_value, real_1d_field=ww_thetal)
2323  else if (name .eq. "thetal_thetal_local" .and. allocated(thetal_thetal)) then
2324  call set_published_field_value(field_value, real_1d_field=thetal_thetal)
2325  else if (name .eq. "sthetal_thetal_local" .and. allocated(sthetal_thetal)) then
2326  call set_published_field_value(field_value, real_1d_field=sthetal_thetal)
2327  else if (name .eq. "thetal_thetal_advection_local" .and. allocated(thetal_thetal_advection)) then
2328  call set_published_field_value(field_value, real_1d_field=thetal_thetal_advection)
2329  else if (name .eq. "thetal_thetal_diffusion_local" .and. allocated(thetal_thetal_diffusion)) then
2330  call set_published_field_value(field_value, real_1d_field=thetal_thetal_diffusion)
2331  else if (name .eq. "wthetal_thetal_local" .and. allocated(wthetal_thetal)) then
2332  call set_published_field_value(field_value, real_1d_field=wthetal_thetal)
2333  else if (name .eq. "u_mse_local" .and. allocated(u_mse)) then
2334  call set_published_field_value(field_value, real_1d_field=u_mse)
2335  else if (name .eq. "us_mse_local" .and. allocated(us_mse)) then
2336  call set_published_field_value(field_value, real_1d_field=us_mse)
2337  else if (name .eq. "u_mse_advection_local" .and. allocated(u_mse_advection)) then
2338  call set_published_field_value(field_value, real_1d_field=u_mse_advection)
2339  else if (name .eq. "u_mse_viscosity_diffusion_local" .and. allocated(u_mse_viscosity_diffusion)) then
2340  call set_published_field_value(field_value, real_1d_field=u_mse_viscosity_diffusion)
2341  else if (name .eq. "wu_mse_local" .and. allocated(wu_mse)) then
2342  call set_published_field_value(field_value, real_1d_field=wu_mse)
2343  else if (name .eq. "v_mse_local" .and. allocated(v_mse)) then
2344  call set_published_field_value(field_value, real_1d_field=v_mse)
2345  else if (name .eq. "vs_mse_local" .and. allocated(vs_mse)) then
2346  call set_published_field_value(field_value, real_1d_field=vs_mse)
2347  else if (name .eq. "v_mse_advection_local" .and. allocated(v_mse_advection)) then
2348  call set_published_field_value(field_value, real_1d_field=v_mse_advection)
2349  else if (name .eq. "v_mse_viscosity_diffusion_local" .and. allocated(v_mse_viscosity_diffusion)) then
2350  call set_published_field_value(field_value, real_1d_field=v_mse_viscosity_diffusion)
2351  else if (name .eq. "wv_mse_local" .and. allocated(wv_mse)) then
2352  call set_published_field_value(field_value, real_1d_field=wv_mse)
2353  else if (name .eq. "w_mse_local" .and. allocated(w_mse)) then
2354  call set_published_field_value(field_value, real_1d_field=w_mse)
2355  else if (name .eq. "ws_mse_local" .and. allocated(ws_mse)) then
2356  call set_published_field_value(field_value, real_1d_field=ws_mse)
2357  else if (name .eq. "w_mse_advection_local" .and. allocated(w_mse_advection)) then
2358  call set_published_field_value(field_value, real_1d_field=w_mse_advection)
2359  else if (name .eq. "w_mse_viscosity_diffusion_local" .and. allocated(w_mse_viscosity_diffusion)) then
2360  call set_published_field_value(field_value, real_1d_field=w_mse_viscosity_diffusion)
2361  else if (name .eq. "w_mse_buoyancy_local" .and. allocated(w_mse_buoyancy)) then
2362  call set_published_field_value(field_value, real_1d_field=w_mse_buoyancy)
2363  else if (name .eq. "ww_mse_local" .and. allocated(ww_mse)) then
2364  call set_published_field_value(field_value, real_1d_field=ww_mse)
2365  else if (name .eq. "mse_mse_local" .and. allocated(mse_mse)) then
2366  call set_published_field_value(field_value, real_1d_field=mse_mse)
2367  else if (name .eq. "smse_mse_local" .and. allocated(smse_mse)) then
2368  call set_published_field_value(field_value, real_1d_field=smse_mse)
2369  else if (name .eq. "mse_mse_advection_local" .and. allocated(mse_mse_advection)) then
2370  call set_published_field_value(field_value, real_1d_field=mse_mse_advection)
2371  else if (name .eq. "mse_mse_diffusion_local" .and. allocated(mse_mse_diffusion)) then
2372  call set_published_field_value(field_value, real_1d_field=mse_mse_diffusion)
2373  else if (name .eq. "wmse_mse_local" .and. allocated(wmse_mse)) then
2374  call set_published_field_value(field_value, real_1d_field=wmse_mse)
2375  else if (name .eq. "us_qt_local" .and. allocated(us_qt)) then
2376  call set_published_field_value(field_value, real_1d_field=us_qt)
2377  else if (name .eq. "u_qt_advection_local" .and. allocated(u_qt_advection)) then
2378  call set_published_field_value(field_value, real_1d_field=u_qt_advection)
2379  else if (name .eq. "u_qt_viscosity_diffusion_local" .and. allocated(u_qt_viscosity_diffusion)) then
2380  call set_published_field_value(field_value, real_1d_field=u_qt_viscosity_diffusion)
2381  else if (name .eq. "wu_qt_local" .and. allocated(wu_qt)) then
2382  call set_published_field_value(field_value, real_1d_field=wu_qt)
2383  else if (name .eq. "vs_qt_local" .and. allocated(vs_qt)) then
2384  call set_published_field_value(field_value, real_1d_field=vs_qt)
2385  else if (name .eq. "v_qt_advection_local" .and. allocated(v_qt_advection)) then
2386  call set_published_field_value(field_value, real_1d_field=v_qt_advection)
2387  else if (name .eq. "v_qt_viscosity_diffusion_local" .and. allocated(v_qt_viscosity_diffusion)) then
2388  call set_published_field_value(field_value, real_1d_field=v_qt_viscosity_diffusion)
2389  else if (name .eq. "wv_qt_local" .and. allocated(wv_qt)) then
2390  call set_published_field_value(field_value, real_1d_field=wv_qt)
2391  else if (name .eq. "w_qt_local" .and. allocated(w_qt)) then
2392  call set_published_field_value(field_value, real_1d_field=w_qt)
2393  else if (name .eq. "ws_qt_local" .and. allocated(ws_qt)) then
2394  call set_published_field_value(field_value, real_1d_field=ws_qt)
2395  else if (name .eq. "w_qt_advection_local" .and. allocated(w_qt_advection)) then
2396  call set_published_field_value(field_value, real_1d_field=w_qt_advection)
2397  else if (name .eq. "w_qt_viscosity_diffusion_local" .and. allocated(w_qt_viscosity_diffusion)) then
2398  call set_published_field_value(field_value, real_1d_field=w_qt_viscosity_diffusion)
2399  else if (name .eq. "w_qt_buoyancy_local" .and. allocated(w_qt_buoyancy)) then
2400  call set_published_field_value(field_value, real_1d_field=w_qt_buoyancy)
2401  else if (name .eq. "ww_qt_local" .and. allocated(ww_qt)) then
2402  call set_published_field_value(field_value, real_1d_field=ww_qt)
2403  else if (name .eq. "qt_qt_local" .and. allocated(qt_qt)) then
2404  call set_published_field_value(field_value, real_1d_field=qt_qt)
2405  else if (name .eq. "sqt_qt_local" .and. allocated(sqt_qt)) then
2406  call set_published_field_value(field_value, real_1d_field=sqt_qt)
2407  else if (name .eq. "qt_qt_advection_local" .and. allocated(qt_qt_advection)) then
2408  call set_published_field_value(field_value, real_1d_field=qt_qt_advection)
2409  else if (name .eq. "qt_qt_diffusion_local" .and. allocated(qt_qt_diffusion)) then
2410  call set_published_field_value(field_value, real_1d_field=qt_qt_diffusion)
2411  else if (name .eq. "wqt_qt_local" .and. allocated(wqt_qt)) then
2412  call set_published_field_value(field_value, real_1d_field=wqt_qt)
2413  else if (name .eq. "mflux_local") then
2414  field_value%scalar_real=mflux
2415  end if
2416  end subroutine field_value_retrieval_callback
2417 
2422  subroutine set_published_field_value(field_value, real_1d_field, real_2d_field)
2423  type(component_field_value_type), intent(inout) :: field_value
2424  real(kind=default_precision), dimension(:), optional :: real_1d_field
2425  real(kind=default_precision), dimension(:,:), optional :: real_2d_field
2426 
2427  if (present(real_1d_field)) then
2428  allocate(field_value%real_1d_array(size(real_1d_field)), source=real_1d_field)
2429  else if (present(real_2d_field)) then
2430  allocate(field_value%real_2d_array(size(real_2d_field, 1), size(real_2d_field, 2)), source=real_2d_field)
2431  end if
2432  end subroutine set_published_field_value
2433 
2438  subroutine set_published_field_enabled_state(collection, field_name, enabled_state)
2439  type(hashmap_type), intent(inout) :: collection
2440  character(len=*), intent(in) :: field_name
2441  logical, intent(in) :: enabled_state
2442 
2443  call c_put_logical(collection, field_name, enabled_state)
2444  end subroutine set_published_field_enabled_state
2445 
2450  logical function get_published_field_enabled_state(collection, field_name)
2451  type(hashmap_type), intent(inout) :: collection
2452  character(len=*), intent(in) :: field_name
2453 
2454  get_published_field_enabled_state=c_get_logical(collection, field_name)
2456 end module flux_budget_mod
flux_budget_mod::timestep_callback
subroutine timestep_callback(current_state)
Timestep call back, this will deduce the diagnostics for the current (non halo) column.
Definition: flux_budget.F90:143
flux_budget_mod::v_qt_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable v_qt_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::compute_tke_for_column
subroutine compute_tke_for_column(current_state)
Computes the TKE diagnostics for a specific column.
Definition: flux_budget.F90:1761
flux_budget_mod
Flux budget component which produces diagnostic data for the flux aspects of the model.
Definition: flux_budget.F90:2
flux_budget_mod::w_qt_advection
real(kind=default_precision), dimension(:), allocatable w_qt_advection
Definition: flux_budget.F90:19
flux_budget_mod::sres
real(kind=default_precision), dimension(:), allocatable sres
Definition: flux_budget.F90:19
flux_budget_mod::w_mse
real(kind=default_precision), dimension(:), allocatable w_mse
Definition: flux_budget.F90:19
flux_budget_mod::clear_scalars
subroutine clear_scalars()
Clears the scalar diagnostics.
Definition: flux_budget.F90:1268
flux_budget_mod::wu_qt
real(kind=default_precision), dimension(:), allocatable wu_qt
Definition: flux_budget.F90:19
flux_budget_mod::q_diff
real(kind=default_precision), dimension(:,:), allocatable q_diff
Definition: flux_budget.F90:32
flux_budget_mod::clear_q_fluxes
subroutine clear_q_fluxes()
Clears the Q flux diagnostics, called at the start of a timestep.
Definition: flux_budget.F90:1982
flux_budget_mod::some_thetal_diagnostics_enabled
logical some_thetal_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::initialisation_callback
subroutine initialisation_callback(current_state)
Initialisation call back.
Definition: flux_budget.F90:126
flux_budget_mod::is_field_heat_flux
logical function is_field_heat_flux(name)
Determines whether a specific published field is a heat flux field.
Definition: flux_budget.F90:2131
flux_budget_mod::wu_mse
real(kind=default_precision), dimension(:), allocatable wu_mse
Definition: flux_budget.F90:19
flux_budget_mod::compute_q_flux_for_column
subroutine compute_q_flux_for_column(current_state)
Computes the Q flux diagnostics for a specific column.
Definition: flux_budget.F90:1992
flux_budget_mod::compute_thetal_for_column
subroutine compute_thetal_for_column(current_state)
Computes the thetal diagnostics for a specific column.
Definition: flux_budget.F90:1451
flux_budget_mod::uw_vw_fields
type(hashmap_type) uw_vw_fields
Definition: flux_budget.F90:33
flux_budget_mod::compute_scalars_for_column
subroutine compute_scalars_for_column(current_state)
Computes the scalar diagnostics for a specific column.
Definition: flux_budget.F90:1274
registry_mod::is_component_field_available
logical function, public is_component_field_available(name)
Determines whether a specific published field is available or not.
Definition: registry.F90:135
flux_budget_mod::vw_advection
real(kind=default_precision), dimension(:), allocatable vw_advection
Definition: flux_budget.F90:19
flux_budget_mod::qt_qt_advection
real(kind=default_precision), dimension(:), allocatable qt_qt_advection
Definition: flux_budget.F90:19
flux_budget_mod::th_tendency
real(kind=default_precision), dimension(:), allocatable th_tendency
Definition: flux_budget.F90:19
flux_budget_mod::wv_mse
real(kind=default_precision), dimension(:), allocatable wv_mse
Definition: flux_budget.F90:19
flux_budget_mod::is_field_qt
logical function is_field_qt(name)
Determines whether a specific published field is a mse field.
Definition: flux_budget.F90:2194
collections_mod
Collection data structures.
Definition: collections.F90:7
flux_budget_mod::w_qt_buoyancy
real(kind=default_precision), dimension(:), allocatable w_qt_buoyancy
Definition: flux_budget.F90:19
flux_budget_mod::tke_fields
type(hashmap_type) tke_fields
Definition: flux_budget.F90:33
grids_mod::x_index
integer, parameter, public x_index
Definition: grids.F90:14
optionsdatabase_mod::options_get_integer
integer function, public options_get_integer(options_database, key, index)
Retrieves an integer value from the database that matches the provided key.
Definition: optionsdatabase.F90:217
flux_budget_mod::v_qt_advection
real(kind=default_precision), dimension(:), allocatable v_qt_advection
Definition: flux_budget.F90:19
flux_budget_mod::scalar_fields
type(hashmap_type) scalar_fields
Definition: flux_budget.F90:33
flux_budget_mod::initialise_mse_diagnostics
subroutine initialise_mse_diagnostics(current_state)
Initialises the mse diagnostics. For now we are assuming mse is the same as theta,...
Definition: flux_budget.F90:582
flux_budget_mod::qt_qt_diffusion
real(kind=default_precision), dimension(:), allocatable qt_qt_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::initialise_q_flux_diagnostics
subroutine initialise_q_flux_diagnostics(current_state)
Initialises the Q field flux diagnostic areas and enabled flags depending upon the configuration of t...
Definition: flux_budget.F90:1057
flux_budget_mod::diagnostic_generation_frequency
integer diagnostic_generation_frequency
Definition: flux_budget.F90:40
flux_budget_mod::u_mse_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable u_mse_viscosity_diffusion
Definition: flux_budget.F90:19
grids_mod::y_index
integer, parameter, public y_index
Definition: grids.F90:14
flux_budget_mod::ww_advection
real(kind=default_precision), dimension(:), allocatable ww_advection
Definition: flux_budget.F90:19
collections_mod::c_has_next
Definition: collections.F90:586
collections_mod::hashmap_type
A hashmap structure, the same as a map but uses hashing for greatly improved performance when storing...
Definition: collections.F90:94
flux_budget_mod::th_buoyancy
real(kind=default_precision), dimension(:), allocatable th_buoyancy
Definition: flux_budget.F90:19
collections_mod::c_size
Returns the number of elements in the collection.
Definition: collections.F90:428
flux_budget_mod::v_thetal
real(kind=default_precision), dimension(:), allocatable v_thetal
Definition: flux_budget.F90:19
flux_budget_mod::u_thetal_advection
real(kind=default_precision), dimension(:), allocatable u_thetal_advection
Definition: flux_budget.F90:19
flux_budget_mod::thetal_thetal_diffusion
real(kind=default_precision), dimension(:), allocatable thetal_thetal_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::u_mse_advection
real(kind=default_precision), dimension(:), allocatable u_mse_advection
Definition: flux_budget.F90:19
flux_budget_mod::some_theta_flux_diagnostics_enabled
logical some_theta_flux_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::sqt_qt
real(kind=default_precision), dimension(:), allocatable sqt_qt
Definition: flux_budget.F90:19
flux_budget_mod::field_value_retrieval_callback
subroutine field_value_retrieval_callback(current_state, name, field_value)
Field value retrieval callback, this returns the value of a specific published field.
Definition: flux_budget.F90:2213
flux_budget_mod::compute_uw_vw_for_column
subroutine compute_uw_vw_for_column(current_state)
Computes the uw uv diagnostics for a specific column.
Definition: flux_budget.F90:1666
flux_budget_mod::us_thetal
real(kind=default_precision), dimension(:), allocatable us_thetal
Definition: flux_budget.F90:19
flux_budget_mod::qt_fields
type(hashmap_type) qt_fields
Definition: flux_budget.F90:33
flux_budget_mod::q_buoyancy
real(kind=default_precision), dimension(:,:), allocatable q_buoyancy
Definition: flux_budget.F90:32
flux_budget_mod::mse_mse
real(kind=default_precision), dimension(:), allocatable mse_mse
Definition: flux_budget.F90:19
flux_budget_mod::wu_thetal
real(kind=default_precision), dimension(:), allocatable wu_thetal
Definition: flux_budget.F90:19
flux_budget_mod::w_mse_buoyancy
real(kind=default_precision), dimension(:), allocatable w_mse_buoyancy
Definition: flux_budget.F90:19
flux_budget_mod::field_information_retrieval_callback
subroutine field_information_retrieval_callback(current_state, name, field_information)
Field information retrieval callback, this returns information for a specific components published fi...
Definition: flux_budget.F90:398
flux_budget_mod::uw_advection
real(kind=default_precision), dimension(:), allocatable uw_advection
Definition: flux_budget.F90:19
flux_budget_mod::wthetal_thetal
real(kind=default_precision), dimension(:), allocatable wthetal_thetal
Definition: flux_budget.F90:19
flux_budget_mod::vs_qt
real(kind=default_precision), dimension(:), allocatable vs_qt
Definition: flux_budget.F90:19
flux_budget_mod::wmfcrit
real(kind=default_precision) wmfcrit
Definition: flux_budget.F90:31
flux_budget_mod::flux_budget_get_descriptor
type(component_descriptor_type) function, public flux_budget_get_descriptor()
Provides the descriptor back to the caller and is used in component registration.
Definition: flux_budget.F90:48
flux_budget_mod::is_field_q_flux
logical function is_field_q_flux(name)
Determines whether a specific published field is a q flux field.
Definition: flux_budget.F90:2149
grids_mod::global_grid_type
Defines the global grid.
Definition: grids.F90:107
flux_budget_mod::q_tendency
real(kind=default_precision), dimension(:,:), allocatable q_tendency
Definition: flux_budget.F90:32
flux_budget_mod::u_thetal_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable u_thetal_viscosity_diffusion
Definition: flux_budget.F90:19
collections_mod::mapentry_type
Definition: collections.F90:46
flux_budget_mod::uu_viscosity
real(kind=default_precision), dimension(:), allocatable uu_viscosity
Definition: flux_budget.F90:19
flux_budget_mod::initialise_thetal_diagnostics
subroutine initialise_thetal_diagnostics(current_state)
Initialises the thetal diagnostics.
Definition: flux_budget.F90:725
monc_component_mod
Interfaces and types that MONC components must specify.
Definition: monc_component.F90:6
flux_budget_mod::clear_mse
subroutine clear_mse()
Clears the mse diagnostics.
Definition: flux_budget.F90:1289
flux_budget_mod::uu_advection
real(kind=default_precision), dimension(:), allocatable uu_advection
Definition: flux_budget.F90:19
flux_budget_mod::th_flux_values
real(kind=default_precision), dimension(:), allocatable th_flux_values
Definition: flux_budget.F90:19
flux_budget_mod::uw_tendency
real(kind=default_precision), dimension(:), allocatable uw_tendency
Definition: flux_budget.F90:19
flux_budget_mod::populate_field_names
subroutine populate_field_names()
Populates the published field names in the appropriate map.
Definition: flux_budget.F90:284
flux_budget_mod::u_thetal
real(kind=default_precision), dimension(:), allocatable u_thetal
Definition: flux_budget.F90:19
flux_budget_mod::set_published_field_value
subroutine set_published_field_value(field_value, real_1d_field, real_2d_field)
Sets the published field value from the temporary diagnostic values held by this component.
Definition: flux_budget.F90:2423
flux_budget_mod::v_thetal_advection
real(kind=default_precision), dimension(:), allocatable v_thetal_advection
Definition: flux_budget.F90:19
flux_budget_mod::us_qt
real(kind=default_precision), dimension(:), allocatable us_qt
Definition: flux_budget.F90:19
collections_mod::c_contains
Determines whether or not a map contains a specific key.
Definition: collections.F90:447
flux_budget_mod::some_qt_diagnostics_enabled
logical some_qt_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::is_field_thetal
logical function is_field_thetal(name)
Determines whether a specific published field is a thetal field.
Definition: flux_budget.F90:2176
flux_budget_mod::compute_theta_flux_for_column
subroutine compute_theta_flux_for_column(current_state)
Computes the heat flux diagnostics for a specific column.
Definition: flux_budget.F90:2067
flux_budget_mod::mflux
real(kind=default_precision) mflux
Definition: flux_budget.F90:31
flux_budget_mod::wv_qt
real(kind=default_precision), dimension(:), allocatable wv_qt
Definition: flux_budget.F90:19
flux_budget_mod::tw_sw
real(kind=default_precision), dimension(:), allocatable tw_sw
Definition: flux_budget.F90:19
flux_budget_mod::u_qt_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable u_qt_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::uw_buoyancy
real(kind=default_precision), dimension(:), allocatable uw_buoyancy
Definition: flux_budget.F90:19
flux_budget_mod::q_flux_values
real(kind=default_precision), dimension(:,:), allocatable q_flux_values
Definition: flux_budget.F90:32
flux_budget_mod::u_mse
real(kind=default_precision), dimension(:), allocatable u_mse
Definition: flux_budget.F90:19
flux_budget_mod::mse_mse_diffusion
real(kind=default_precision), dimension(:), allocatable mse_mse_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::tu_su
real(kind=default_precision), dimension(:), allocatable tu_su
Definition: flux_budget.F90:19
flux_budget_mod::wmse_mse
real(kind=default_precision), dimension(:), allocatable wmse_mse
Definition: flux_budget.F90:19
flux_budget_mod::us_mse
real(kind=default_precision), dimension(:), allocatable us_mse
Definition: flux_budget.F90:19
flux_budget_mod::initialise_scalar_diagnostics
subroutine initialise_scalar_diagnostics(current_state)
Initialises the scalar diagnostics.
Definition: flux_budget.F90:439
flux_budget_mod::thetal_fields
type(hashmap_type) thetal_fields
Definition: flux_budget.F90:33
science_constants_mod
Scientific constant values used throughout simulations. Each has a default value and this can be over...
Definition: scienceconstants.F90:3
flux_budget_mod::wv_v
real(kind=default_precision), dimension(:), allocatable wv_v
Definition: flux_budget.F90:19
flux_budget_mod::sthetal_thetal
real(kind=default_precision), dimension(:), allocatable sthetal_thetal
Definition: flux_budget.F90:19
flux_budget_mod::some_uw_vw_diagnostics_enabled
logical some_uw_vw_diagnostics_enabled
Definition: flux_budget.F90:36
collections_mod::c_get_logical
Gets a specific logical element out of the list, stack, queue or map with the corresponding key.
Definition: collections.F90:409
registry_mod::get_component_field_value
type(component_field_value_type) function, public get_component_field_value(current_state, name)
Retrieves the value wrapper of a components published field.
Definition: registry.F90:144
flux_budget_mod::q_flux_fields
type(hashmap_type) q_flux_fields
Definition: flux_budget.F90:33
flux_budget_mod::smse_mse
real(kind=default_precision), dimension(:), allocatable smse_mse
Definition: flux_budget.F90:19
grids_mod::z_index
integer, parameter, public z_index
Grid index parameters.
Definition: grids.F90:14
flux_budget_mod::vv_advection
real(kind=default_precision), dimension(:), allocatable vv_advection
Definition: flux_budget.F90:19
flux_budget_mod::clear_prognostic_budgets
subroutine clear_prognostic_budgets()
Clears the prognostic (uu, vv, ww) budgets.
Definition: flux_budget.F90:1560
flux_budget_mod::is_field_tke_flux
logical function is_field_tke_flux(name)
Determines whether a specific published field is a TKE budget field.
Definition: flux_budget.F90:2140
flux_budget_mod::initialise_qt_diagnostics
subroutine initialise_qt_diagnostics(current_state)
Initialises the qt diagnostics. For now we are assuming qt is the same as theta, which needs updating...
Definition: flux_budget.F90:448
collections_mod::iterator_type
Definition: collections.F90:51
flux_budget_mod::compute_prognostic_budgets_for_column
subroutine compute_prognostic_budgets_for_column(current_state)
Computes the prognostic (uu, vv, ww) budgets for a specific column.
Definition: flux_budget.F90:1577
flux_budget_mod::q_gradient
real(kind=default_precision), dimension(:,:), allocatable q_gradient
Definition: flux_budget.F90:32
flux_budget_mod::wp
real(kind=default_precision), dimension(:), allocatable wp
Definition: flux_budget.F90:19
flux_budget_mod::vv_viscosity
real(kind=default_precision), dimension(:), allocatable vv_viscosity
Definition: flux_budget.F90:19
flux_budget_mod::mse_fields
type(hashmap_type) mse_fields
Definition: flux_budget.F90:33
science_constants_mod::ratio_mol_wts
real(kind=default_precision), public ratio_mol_wts
Definition: scienceconstants.F90:13
flux_budget_mod::get_published_field_enabled_state
logical function get_published_field_enabled_state(collection, field_name)
Retrieves whether a published field is enabled or not.
Definition: flux_budget.F90:2451
flux_budget_mod::ws_thetal
real(kind=default_precision), dimension(:), allocatable ws_thetal
Definition: flux_budget.F90:19
monc_component_mod::component_field_value_type
Wrapper type for the value returned for a published field from a component.
Definition: monc_component.F90:22
state_mod::model_state_type
The ModelState which represents the current state of a run.
Definition: state.F90:39
flux_budget_mod::is_field_prognostic_budget
logical function is_field_prognostic_budget(name)
Determines whether a specific published field is a uu, vv or ww field.
Definition: flux_budget.F90:2167
flux_budget_mod::v_thetal_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable v_thetal_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::ww_viscosity
real(kind=default_precision), dimension(:), allocatable ww_viscosity
Definition: flux_budget.F90:19
flux_budget_mod::vw_buoyancy
real(kind=default_precision), dimension(:), allocatable vw_buoyancy
Definition: flux_budget.F90:19
monc_component_mod::component_field_information_type
Definition: monc_component.F90:31
flux_budget_mod::some_q_flux_diagnostics_enabled
logical some_q_flux_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::vs_mse
real(kind=default_precision), dimension(:), allocatable vs_mse
Definition: flux_budget.F90:19
flux_budget_mod::vw_viscosity
real(kind=default_precision), dimension(:), allocatable vw_viscosity
Definition: flux_budget.F90:19
flux_budget_mod::tend
real(kind=default_precision), dimension(:), allocatable tend
Definition: flux_budget.F90:19
flux_budget_mod::uw_viscosity
real(kind=default_precision), dimension(:), allocatable uw_viscosity
Definition: flux_budget.F90:19
flux_budget_mod::initialise_prognostic_budget_diagnostics
subroutine initialise_prognostic_budget_diagnostics(current_state)
Initialises the prognostic (uu, vv, ww) budget diagnostics.
Definition: flux_budget.F90:868
flux_budget_mod::is_field_scalar
logical function is_field_scalar(name)
Determines whether a specific published field is a scalar field.
Definition: flux_budget.F90:2203
flux_budget_mod::v_mse_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable v_mse_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::th_diff
real(kind=default_precision), dimension(:), allocatable th_diff
Definition: flux_budget.F90:19
grids_mod::local_grid_type
Defined the local grid, i.e. the grid held on this process after decomposition.
Definition: grids.F90:118
flux_budget_mod::thetal_thetal_advection
real(kind=default_precision), dimension(:), allocatable thetal_thetal_advection
Definition: flux_budget.F90:19
flux_budget_mod::ww_mse
real(kind=default_precision), dimension(:), allocatable ww_mse
Definition: flux_budget.F90:19
flux_budget_mod::w_mse_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable w_mse_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::v_mse_advection
real(kind=default_precision), dimension(:), allocatable v_mse_advection
Definition: flux_budget.F90:19
flux_budget_mod::ww_qt
real(kind=default_precision), dimension(:), allocatable ww_qt
Definition: flux_budget.F90:19
flux_budget_mod::qt_qt
real(kind=default_precision), dimension(:), allocatable qt_qt
Definition: flux_budget.F90:19
flux_budget_mod::compute_qt_for_column
subroutine compute_qt_for_column(current_state)
Computes the qt diagnostics for a specific column. For now we are assuming qt is the same as theta,...
Definition: flux_budget.F90:1160
flux_budget_mod::set_published_field_enabled_state
subroutine set_published_field_enabled_state(collection, field_name, enabled_state)
Sets the published value enabled state in the provided collection map.
Definition: flux_budget.F90:2439
flux_budget_mod::wu_u
real(kind=default_precision), dimension(:), allocatable wu_u
Definition: flux_budget.F90:19
flux_budget_mod::prognostic_budget_fields
type(hashmap_type) prognostic_budget_fields
Definition: flux_budget.F90:33
flux_budget_mod::buoy
real(kind=default_precision), dimension(:), allocatable buoy
Definition: flux_budget.F90:19
flux_budget_mod::ws_mse
real(kind=default_precision), dimension(:), allocatable ws_mse
Definition: flux_budget.F90:19
flux_budget_mod::clear_uw_vw
subroutine clear_uw_vw()
Clears the uw uv diagnostics.
Definition: flux_budget.F90:1643
flux_budget_mod::ww_thetal
real(kind=default_precision), dimension(:), allocatable ww_thetal
Definition: flux_budget.F90:19
flux_budget_mod::w_thetal_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable w_thetal_viscosity_diffusion
Definition: flux_budget.F90:19
datadefn_mod
Contains common definitions for the data and datatypes used by MONC.
Definition: datadefn.F90:2
flux_budget_mod::initialise_tke_diagnostics
subroutine initialise_tke_diagnostics(current_state)
Initialises the TKE diagnostics.
Definition: flux_budget.F90:1017
flux_budget_mod::w_qt_viscosity_diffusion
real(kind=default_precision), dimension(:), allocatable w_qt_viscosity_diffusion
Definition: flux_budget.F90:19
flux_budget_mod::clear_theta_fluxes
subroutine clear_theta_fluxes()
Clears the heat flux diagnostics at the start of a timestep.
Definition: flux_budget.F90:2057
flux_budget_mod::w_qt
real(kind=default_precision), dimension(:), allocatable w_qt
Definition: flux_budget.F90:19
flux_budget_mod::compute_mse_for_column
subroutine compute_mse_for_column(current_state)
Computes the mse diagnostics for a specific column. For now we are assuming mse is the same as theta,...
Definition: flux_budget.F90:1316
flux_budget_mod::u_qt_advection
real(kind=default_precision), dimension(:), allocatable u_qt_advection
Definition: flux_budget.F90:19
flux_budget_mod::tv_sv
real(kind=default_precision), dimension(:), allocatable tv_sv
Definition: flux_budget.F90:19
collections_mod::c_get_iterator
Definition: collections.F90:581
registry_mod
MONC component registry.
Definition: registry.F90:5
flux_budget_mod::thetal_thetal
real(kind=default_precision), dimension(:), allocatable thetal_thetal
Definition: flux_budget.F90:19
flux_budget_mod::ww_buoyancy
real(kind=default_precision), dimension(:), allocatable ww_buoyancy
Definition: flux_budget.F90:19
flux_budget_mod::some_tke_diagnostics_enabled
logical some_tke_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::w_thetal_advection
real(kind=default_precision), dimension(:), allocatable w_thetal_advection
Definition: flux_budget.F90:19
flux_budget_mod::some_mse_diagnostics_enabled
logical some_mse_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::w_thetal_buoyancy
real(kind=default_precision), dimension(:), allocatable w_thetal_buoyancy
Definition: flux_budget.F90:19
flux_budget_mod::v_mse
real(kind=default_precision), dimension(:), allocatable v_mse
Definition: flux_budget.F90:19
flux_budget_mod::heat_flux_fields
type(hashmap_type) heat_flux_fields
Definition: flux_budget.F90:33
flux_budget_mod::clear_thetal
subroutine clear_thetal()
Clears the thetal diagnostics.
Definition: flux_budget.F90:1425
registry_mod::get_component_field_information
type(component_field_information_type) function, public get_component_field_information(current_state, name)
Retrieves information about a components published field which includes its type and size.
Definition: registry.F90:165
flux_budget_mod::mse_mse_advection
real(kind=default_precision), dimension(:), allocatable mse_mse_advection
Definition: flux_budget.F90:19
flux_budget_mod::vs_thetal
real(kind=default_precision), dimension(:), allocatable vs_thetal
Definition: flux_budget.F90:19
flux_budget_mod::clear_tke
subroutine clear_tke()
Clears the TKE diagnostics.
Definition: flux_budget.F90:1656
flux_budget_mod::vw_w
real(kind=default_precision), dimension(:), allocatable vw_w
Definition: flux_budget.F90:19
collections_mod::c_next_mapentry
Definition: collections.F90:606
flux_budget_mod::initialise_theta_flux_diagnostics
subroutine initialise_theta_flux_diagnostics(current_state)
Initialises the heat flux diagnostic areas and enabled flags depending upon the configuration of the ...
Definition: flux_budget.F90:1097
flux_budget_mod::vw_tendency
real(kind=default_precision), dimension(:), allocatable vw_tendency
Definition: flux_budget.F90:19
grids_mod
Functionality to support the different types of grid and abstraction between global grids and local o...
Definition: grids.F90:5
flux_budget_mod::some_prognostic_budget_diagnostics_enabled
logical some_prognostic_budget_diagnostics_enabled
Definition: flux_budget.F90:36
flux_budget_mod::clear_qt
subroutine clear_qt()
Clears the qt diagnostics.
Definition: flux_budget.F90:1135
flux_budget_mod::wv_thetal
real(kind=default_precision), dimension(:), allocatable wv_thetal
Definition: flux_budget.F90:19
flux_budget_mod::is_field_uw_vw
logical function is_field_uw_vw(name)
Determines whether a specific published field is a uw or uv field.
Definition: flux_budget.F90:2158
flux_budget_mod::wqt_qt
real(kind=default_precision), dimension(:), allocatable wqt_qt
Definition: flux_budget.F90:19
flux_budget_mod::uw_w
real(kind=default_precision), dimension(:), allocatable uw_w
Definition: flux_budget.F90:19
flux_budget_mod::finalisation_callback
subroutine finalisation_callback(current_state)
Finalisation call back.
Definition: flux_budget.F90:174
optionsdatabase_mod
Manages the options database. Contains administration functions and deduce runtime options from the c...
Definition: optionsdatabase.F90:7
flux_budget_mod::w_thetal
real(kind=default_precision), dimension(:), allocatable w_thetal
Definition: flux_budget.F90:19
flux_budget_mod::w_mse_advection
real(kind=default_precision), dimension(:), allocatable w_mse_advection
Definition: flux_budget.F90:19
flux_budget_mod::th_gradient
real(kind=default_precision), dimension(:), allocatable th_gradient
Definition: flux_budget.F90:19
flux_budget_mod::wke
real(kind=default_precision), dimension(:), allocatable wke
Definition: flux_budget.F90:19
collections_mod::c_put_logical
Puts a logical key-value pair into the map.
Definition: collections.F90:357
monc_component_mod::component_descriptor_type
Description of a component.
Definition: monc_component.F90:42
monc_component_mod::component_double_data_type
integer, parameter, public component_double_data_type
Definition: monc_component.F90:16
optionsdatabase_mod::options_get_real
real(kind=default_precision) function, public options_get_real(options_database, key, index)
Retrieves a real value from the database that matches the provided key.
Definition: optionsdatabase.F90:91
datadefn_mod::default_precision
integer, parameter, public default_precision
MPI communication type which we use for the prognostic and calculation data.
Definition: datadefn.F90:17
state_mod
The model state which represents the current state of a run.
Definition: state.F90:2
flux_budget_mod::initialise_uw_vw_diagnostics
subroutine initialise_uw_vw_diagnostics(current_state)
Initialises the UW and VW diagnostics.
Definition: flux_budget.F90:944
flux_budget_mod::ws_qt
real(kind=default_precision), dimension(:), allocatable ws_qt
Definition: flux_budget.F90:19
monc_component_mod::component_array_field_type
integer, parameter, public component_array_field_type
Definition: monc_component.F90:15
flux_budget_mod::is_field_mse
logical function is_field_mse(name)
Determines whether a specific published field is a mse field.
Definition: flux_budget.F90:2185
science_constants_mod::g
real(kind=default_precision), public g
Definition: scienceconstants.F90:13