Line data Source code
1 : module cam_snapshot
2 : !--------------------------------------------------------
3 : ! The purpose of this module is to handle taking the "snapshot" of CAM data.
4 : !
5 : ! This module writes out ALL the state, tend and pbuf fields. It also includes the cam_in and cam_out
6 : ! fields which are used within CAM
7 : !--------------------------------------------------------
8 :
9 : use shr_kind_mod, only: r8 => shr_kind_r8
10 : use cam_history, only: addfld, add_default, outfld
11 : use cam_history, only: cam_history_snapshot_deactivate, cam_history_snapshot_activate
12 : use cam_history_support, only: horiz_only
13 : use cam_abortutils, only: endrun
14 : use physics_buffer, only: physics_buffer_desc, pbuf_get_index, pbuf_get_field, pbuf_get_field_name
15 : use physics_types, only: physics_state, physics_tend, physics_ptend
16 : use camsrfexch, only: cam_out_t, cam_in_t
17 : use ppgrid, only: pcols, begchunk, endchunk
18 : use constituents, only: pcnst
19 : use phys_control, only: phys_getopts
20 : use cam_logfile, only: iulog
21 : use cam_snapshot_common, only: snapshot_type, cam_snapshot_deactivate, cam_snapshot_all_outfld, cam_snapshot_ptend_outfld
22 : use cam_snapshot_common, only: snapshot_type, cam_state_snapshot_init, cam_cnst_snapshot_init, cam_tend_snapshot_init
23 : use cam_snapshot_common, only: cam_ptend_snapshot_init, cam_in_snapshot_init, cam_out_snapshot_init
24 : use cam_snapshot_common, only: cam_pbuf_snapshot_init, snapshot_addfld
25 :
26 : implicit none
27 :
28 : private
29 :
30 : public :: cam_snapshot_init
31 : public :: cam_snapshot_all_outfld_tphysbc, cam_snapshot_all_outfld_tphysac
32 :
33 : private :: cam_tphysbc_snapshot_init, cam_tphysac_snapshot_init
34 :
35 : integer :: ntphysbc_var
36 : integer :: ntphysac_var
37 :
38 : integer :: cam_snapshot_before_num, cam_snapshot_after_num
39 :
40 : ! Note the maximum number of variables for each type
41 : type (snapshot_type) :: tphysbc_snapshot(30)
42 : type (snapshot_type) :: tphysac_snapshot(30)
43 :
44 : contains
45 :
46 0 : subroutine cam_snapshot_init(cam_in_arr, cam_out_arr, pbuf, index)
47 :
48 :
49 : !--------------------------------------------------------
50 : ! This subroutine does the addfld calls for ALL state, tend, ptend, and pbuf fields. It also includes the cam_in and cam_out
51 : ! elements which are used within CAM
52 : !--------------------------------------------------------
53 : type(cam_in_t), intent(in) :: cam_in_arr(begchunk:endchunk)
54 : type(cam_out_t), intent(in) :: cam_out_arr(begchunk:endchunk)
55 : type(physics_buffer_desc), pointer, intent(inout) :: pbuf(:,:)
56 : integer, intent(in) :: index
57 :
58 :
59 : call phys_getopts(cam_snapshot_before_num_out = cam_snapshot_before_num, &
60 768 : cam_snapshot_after_num_out = cam_snapshot_after_num)
61 :
62 :
63 : ! Return if not turned on
64 768 : if (cam_snapshot_before_num <= 0 .and. cam_snapshot_after_num <= 0) return ! No snapshot files are being requested
65 :
66 0 : call cam_state_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
67 0 : call cam_cnst_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
68 0 : call cam_tend_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
69 0 : call cam_ptend_snapshot_init(cam_snapshot_after_num)
70 0 : call cam_in_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, cam_in_arr(index))
71 : call cam_out_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, cam_out_arr(index))
72 0 : call cam_pbuf_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num, pbuf(:,index))
73 0 : call cam_tphysac_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
74 0 : call cam_tphysbc_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
75 :
76 : end subroutine cam_snapshot_init
77 :
78 0 : subroutine cam_snapshot_all_outfld_tphysbc(file_num, state, tend, cam_in, cam_out, pbuf, flx_heat, cmfmc, cmfcme, &
79 0 : zdu, rliq, rice, dlf, dlf2, rliq2, det_s, det_ice, net_flx)
80 :
81 : use time_manager, only: is_first_step, is_first_restart_step
82 :
83 : !--------------------------------------------------------
84 : ! This subroutine does the outfld calls for ALL state, tend and pbuf fields for routines in tphysbc.
85 : ! It also includes the cam_in and cam_out elements which are used within CAM as well as variables which
86 : ! are local to tphysbc.
87 : !--------------------------------------------------------
88 :
89 : integer, intent(in) :: file_num
90 : type(physics_state), intent(in) :: state
91 : type(physics_tend), intent(in) :: tend
92 : type(cam_in_t), intent(in) :: cam_in
93 : type(cam_out_t), intent(in) :: cam_out
94 : type(physics_buffer_desc), pointer, intent(in) :: pbuf(:)
95 : real(r8), intent(in) :: flx_heat(:) ! Heat flux for check_energy_chng.
96 : real(r8), intent(in) :: cmfmc(:,:) ! convective mass flux
97 : real(r8), intent(in) :: cmfcme(:,:) ! cmf condensation - evaporation
98 : real(r8), intent(in) :: zdu(:,:) ! detraining mass flux from deep convection
99 : real(r8), intent(in) :: rliq(:) ! vertical integral of liquid not yet in q(ixcldliq)
100 : real(r8), intent(in) :: rice(:) ! vertical integral of ice not yet in q(ixcldice)
101 : real(r8), intent(in) :: dlf(:,:) ! local copy of DLFZM (copy so need to output)
102 : real(r8), intent(in) :: dlf2(:,:) ! Detraining cld H20 from shallow convections
103 : real(r8), intent(in) :: rliq2(:) ! vertical integral of liquid from shallow scheme
104 : real(r8), intent(in) :: det_s(:) ! vertical integral of detrained static energy from ice
105 : real(r8), intent(in) :: det_ice(:) ! vertical integral of detrained ice
106 : real(r8), intent(in) :: net_flx(:)
107 :
108 : integer :: lchnk
109 :
110 : ! Return if the first timestep as not all fields may be filled in and this will cause a core dump
111 0 : if (is_first_step().or. is_first_restart_step()) return
112 :
113 : ! Return if not turned on
114 0 : if (cam_snapshot_before_num <= 0 .and. cam_snapshot_after_num <= 0) return ! No snapshot files are being requested
115 :
116 0 : lchnk = state%lchnk
117 :
118 0 : call cam_history_snapshot_activate('tphysbc_flx_heat', file_num)
119 0 : call outfld('tphysbc_flx_heat', flx_heat, pcols, lchnk)
120 0 : call cam_history_snapshot_deactivate('tphysbc_flx_heat')
121 :
122 0 : call cam_history_snapshot_activate('tphysbc_cmfmc', file_num)
123 0 : call outfld('tphysbc_cmfmc', cmfmc, pcols, lchnk)
124 0 : call cam_history_snapshot_deactivate('tphysbc_cmfmc')
125 :
126 0 : call cam_history_snapshot_activate('tphysbc_cmfcme', file_num)
127 0 : call outfld('tphysbc_cmfcme', cmfcme, pcols, lchnk)
128 0 : call cam_history_snapshot_deactivate('tphysbc_cmfcme')
129 :
130 0 : call cam_history_snapshot_activate('tphysbc_zdu', file_num)
131 0 : call outfld('tphysbc_zdu', zdu, pcols, lchnk)
132 0 : call cam_history_snapshot_deactivate('tphysbc_zdu')
133 :
134 0 : call cam_history_snapshot_activate('tphysbc_rliq', file_num)
135 0 : call outfld('tphysbc_rliq', rliq, pcols, lchnk)
136 0 : call cam_history_snapshot_deactivate('tphysbc_rliq')
137 :
138 0 : call cam_history_snapshot_activate('tphysbc_rice', file_num)
139 0 : call outfld('tphysbc_rice', rice, pcols, lchnk)
140 0 : call cam_history_snapshot_deactivate('tphysbc_rice')
141 :
142 0 : call cam_history_snapshot_activate('tphysbc_dlf', file_num)
143 0 : call outfld('tphysbc_dlf', dlf, pcols, lchnk)
144 0 : call cam_history_snapshot_deactivate('tphysbc_dlf')
145 :
146 0 : call cam_history_snapshot_activate('tphysbc_dlf2', file_num)
147 0 : call outfld('tphysbc_dlf2', dlf2, pcols, lchnk)
148 0 : call cam_history_snapshot_deactivate('tphysbc_dlf2')
149 :
150 0 : call cam_history_snapshot_activate('tphysbc_rliq2', file_num)
151 0 : call outfld('tphysbc_rliq2', rliq2, pcols, lchnk)
152 0 : call cam_history_snapshot_deactivate('tphysbc_rliq2')
153 :
154 0 : call cam_history_snapshot_activate('tphysbc_det_s', file_num)
155 0 : call outfld('tphysbc_det_s', det_s, pcols, lchnk)
156 0 : call cam_history_snapshot_deactivate('tphysbc_det_s')
157 :
158 0 : call cam_history_snapshot_activate('tphysbc_det_ice', file_num)
159 0 : call outfld('tphysbc_det_ice', det_ice, pcols, lchnk)
160 0 : call cam_history_snapshot_deactivate('tphysbc_det_ice')
161 :
162 0 : call cam_history_snapshot_activate('tphysbc_net_flx', file_num)
163 0 : call outfld('tphysbc_net_flx', net_flx, pcols, lchnk)
164 0 : call cam_history_snapshot_deactivate('tphysbc_net_flx')
165 :
166 0 : call cam_snapshot_all_outfld(file_num, state, tend, cam_in, cam_out, pbuf)
167 :
168 0 : end subroutine cam_snapshot_all_outfld_tphysbc
169 :
170 0 : subroutine cam_snapshot_all_outfld_tphysac(file_num, state, tend, cam_in, cam_out, pbuf, fh2o, surfric, obklen, flx_heat)
171 :
172 0 : use time_manager, only: is_first_step
173 :
174 : !--------------------------------------------------------
175 : ! This subroutine does the outfld calls for ALL state, tend and pbuf fields for routines in tphysac.
176 : ! It also includes the cam_in and cam_out elements which are used within CAM as well as variables which
177 : ! are local to tphysac.
178 : !--------------------------------------------------------
179 :
180 : integer, intent(in) :: file_num
181 : type(physics_state), intent(in) :: state
182 : type(physics_tend), intent(in) :: tend
183 : type(cam_in_t), intent(in) :: cam_in
184 : type(cam_out_t), intent(in) :: cam_out
185 : type(physics_buffer_desc), pointer, intent(in) :: pbuf(:)
186 : real(r8), intent(in) :: fh2o(:) ! h2o flux to balance source from methane chemistry
187 : real(r8), intent(in) :: surfric(:) ! surface friction velocity
188 : real(r8), intent(in) :: obklen(:) ! Obukhov length
189 : real(r8), intent(in) :: flx_heat(:) ! Heat flux for check_energy_chng.
190 :
191 : integer :: lchnk
192 :
193 : ! Return if the first timestep as not all fields may be filled in and this will cause a core dump
194 0 : if (is_first_step()) return
195 :
196 : ! Return if not turned on
197 0 : if (cam_snapshot_before_num <= 0 .and. cam_snapshot_after_num <= 0) return ! No snapshot files are being requested
198 :
199 0 : lchnk = state%lchnk
200 :
201 0 : call cam_history_snapshot_activate('tphysac_fh2o', file_num)
202 0 : call outfld('tphysac_fh2o', fh2o, pcols, lchnk)
203 0 : call cam_history_snapshot_deactivate('tphysac_fh2o')
204 :
205 0 : call cam_history_snapshot_activate('tphysac_surfric', file_num)
206 0 : call outfld('tphysac_surfric', surfric, pcols, lchnk)
207 0 : call cam_history_snapshot_deactivate('tphysac_surfric')
208 :
209 0 : call cam_history_snapshot_activate('tphysac_obklen', file_num)
210 0 : call outfld('tphysac_obklen', obklen, pcols, lchnk)
211 0 : call cam_history_snapshot_deactivate('tphysac_obklen')
212 :
213 0 : call cam_history_snapshot_activate('tphysac_flx_heat', file_num)
214 0 : call outfld('tphysac_flx_heat', flx_heat, pcols, lchnk)
215 0 : call cam_history_snapshot_deactivate('tphysac_flx_heat')
216 :
217 :
218 0 : call cam_snapshot_all_outfld(file_num, state, tend, cam_in, cam_out, pbuf)
219 :
220 0 : end subroutine cam_snapshot_all_outfld_tphysac
221 :
222 0 : subroutine cam_tphysbc_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
223 :
224 : !--------------------------------------------------------
225 : ! This subroutine does the addfld calls for the misc tphysbc physics variables that are passed individually
226 : ! into physics packages
227 : !--------------------------------------------------------
228 :
229 : integer,intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
230 :
231 0 : ntphysbc_var = 0
232 :
233 : !--------------------------------------------------------
234 : ! Add the misc tphysbc variables to the output
235 : ! NOTE - flx_heat is added in tphysac
236 : !--------------------------------------------------------
237 :
238 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
239 0 : 'flx', 'tphysbc_flx_heat', 'unset', horiz_only)
240 :
241 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
242 0 : 'cmfmc', 'tphysbc_cmfmc', 'unset', 'lev')
243 :
244 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
245 0 : 'cmfcme', 'tphysbc_cmfcme', 'unset', 'lev')
246 :
247 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
248 0 : 'zdu', 'tphysbc_zdu', 'unset', 'lev')
249 :
250 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
251 0 : 'rliq', 'tphysbc_rliq', 'unset', horiz_only)
252 :
253 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
254 0 : 'rice', 'tphysbc_rice', 'unset', horiz_only)
255 :
256 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
257 0 : 'dlf', 'tphysbc_dlf', 'unset', 'lev')
258 :
259 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
260 0 : 'dlf2', 'tphysbc_dlf2', 'unset', 'lev')
261 :
262 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
263 0 : 'rliq2', 'tphysbc_rliq2', 'unset', horiz_only)
264 :
265 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
266 0 : 'det_s', 'tphysbc_det_s', 'unset', horiz_only)
267 :
268 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
269 0 : 'det_ice', 'tphysbc_det_ice', 'unset', horiz_only)
270 :
271 : call snapshot_addfld( ntphysbc_var, tphysbc_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
272 0 : 'net_flx', 'tphysbc_net_flx', 'unset', horiz_only)
273 :
274 :
275 0 : end subroutine cam_tphysbc_snapshot_init
276 :
277 0 : subroutine cam_tphysac_snapshot_init(cam_snapshot_before_num, cam_snapshot_after_num)
278 :
279 : !--------------------------------------------------------
280 : ! This subroutine does the addfld calls for the misc tphysac physics variables that are passed individually
281 : ! into physics packages
282 : !--------------------------------------------------------
283 :
284 : integer,intent(in) :: cam_snapshot_before_num, cam_snapshot_after_num
285 :
286 0 : ntphysac_var = 0
287 :
288 : !--------------------------------------------------------
289 : ! Add the misc tphysac variables to the output
290 : !--------------------------------------------------------
291 :
292 : call snapshot_addfld( ntphysac_var, tphysac_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
293 0 : 'fh2o', 'tphysac_fh2o', 'unset', horiz_only)
294 :
295 : call snapshot_addfld( ntphysac_var, tphysac_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
296 0 : 'surfric', 'tphysac_surfric', 'unset', horiz_only)
297 :
298 : call snapshot_addfld( ntphysac_var, tphysac_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
299 0 : 'obklen', 'tphysac_obklen', 'unset', horiz_only)
300 :
301 : call snapshot_addfld( ntphysac_var, tphysac_snapshot, cam_snapshot_before_num, cam_snapshot_after_num, &
302 0 : 'flx', 'tphysac_flx_heat', 'unset', horiz_only)
303 :
304 0 : end subroutine cam_tphysac_snapshot_init
305 :
306 : end module cam_snapshot
|