CCPP SciDoc v7.0.x  v7.0.0
Common Community Physics Package Developed at DTC
 
Loading...
Searching...
No Matches
rrtmgp_sw_main.F90
1
3
6 use mpi_f08
7 use machine, only: kind_phys, kind_dbl_prec
8 use mo_optical_props, only: ty_optical_props_2str
10 use mo_rte_sw, only: rte_sw
11 use mo_gas_concentrations, only: ty_gas_concs
12 use mo_fluxes_byband, only: ty_fluxes_byband
13 use radiation_tools, only: check_error_msg
14 use rrtmgp_sw_gas_optics, only: sw_gas_props,rrtmgp_sw_gas_optics_init
15 use rrtmgp_sw_cloud_optics, only: sw_cloud_props, rrtmgp_sw_cloud_optics_init, a0r, a0s, &
16 a1s, b0r, b0s, b1s, c0r, c0s
17 use gfs_rrtmgp_pre, only: istr_h2o, istr_co2, istr_o3, istr_n2o, istr_ch4, &
18 istr_o2, istr_ccl4, istr_cfc11, istr_cfc12, istr_cfc22, &
19 eps, oneminus, ftiny
21 use rrtmgp_sampling, only: sampled_mask, draw_samples
22 use mo_rte_kind, only: rte_wp => wp
23 implicit none
24
25 public rrtmgp_sw_main_init, rrtmgp_sw_main_run
26
27contains
28
32 subroutine rrtmgp_sw_main_init(rrtmgp_root_dir, rrtmgp_sw_file_gas, rrtmgp_sw_file_clouds,&
33 active_gases_array, nrghice, mpicomm, mpirank, mpiroot, nLay, rrtmgp_phys_blksz, &
34 errmsg, errflg)
35
36 ! Inputs
37 character(len=128),intent(in) :: &
38 rrtmgp_root_dir, & !< RTE-RRTMGP root directory
39 rrtmgp_sw_file_clouds, & !< RRTMGP file containing K-distribution data
40 rrtmgp_sw_file_gas
41 character(len=*), dimension(:), intent(in), optional :: &
42 active_gases_array
43 integer, intent(inout) :: &
44 nrghice
45 type(mpi_comm),intent(in) :: &
46 mpicomm
47 integer,intent(in) :: &
48 mpirank, & !< Current MPI rank
49 mpiroot, & !< Master MPI rank
50 rrtmgp_phys_blksz, & !< Number of horizontal points to process at once.
51 nlay
52 ! Outputs
53 character(len=*), intent(out) :: &
54 errmsg
55 integer, intent(out) :: &
56 errflg
57
58 ! Initialize CCPP error handling variables
59 errmsg = ''
60 errflg = 0
61
62 ! RRTMGP shortwave gas-optics (k-distribution) initialization
63 call rrtmgp_sw_gas_optics_init(rrtmgp_root_dir, rrtmgp_sw_file_gas, active_gases_array,&
64 mpicomm, mpirank, mpiroot, errmsg, errflg)
65
66 ! RRTMGP shortwave cloud-optics initialization
67 call rrtmgp_sw_cloud_optics_init(rrtmgp_root_dir, rrtmgp_sw_file_clouds, &
68 nrghice, mpicomm, mpirank, mpiroot, errmsg, errflg)
69
70 end subroutine rrtmgp_sw_main_init
71
75 subroutine rrtmgp_sw_main_run(doSWrad, doSWclrsky, top_at_1, &
76 nCol, nDay, nLay, nGases, rrtmgp_phys_blksz, idx, icseed_sw, iovr, iovr_convcld, &
77 iovr_max, iovr_maxrand, iovr_rand, iovr_dcorr, iovr_exp, iovr_exprand, isubc_sw, &
78 iSFC, sfc_alb_nir_dir, sfc_alb_nir_dif, sfc_alb_uvvis_dir, sfc_alb_uvvis_dif, coszen,&
79 p_lay, p_lev, t_lay, t_lev, vmr_o2, vmr_h2o, vmr_o3, vmr_ch4, vmr_n2o, vmr_co2, &
80 cld_frac, cld_lwp, cld_reliq, cld_iwp, cld_reice, cld_swp, cld_resnow, cld_rwp, &
81 cld_rerain, precip_frac, cld_cnv_lwp, cld_cnv_reliq, cld_cnv_iwp, cld_cnv_reice, &
82 cld_pbl_lwp, cld_pbl_reliq, cld_pbl_iwp, cld_pbl_reice, cloud_overlap_param, &
83 active_gases_array, aersw_tau, aersw_ssa, aersw_g, solcon, scmpsw, &
84 fluxswUP_allsky, fluxswDOWN_allsky, fluxswUP_clrsky, fluxswDOWN_clrsky, cldtausw, &
85 errmsg, errflg)
86
87 ! Inputs
88 logical, intent(in) :: &
89 doswrad, & ! Flag to perform shortwave calculation
90 doswclrsky, & ! Flag to compute clear-sky fluxes
91 top_at_1 ! Flag for vertical ordering convention
92 integer,intent(in) :: &
93 ncol, & ! Number of horizontal points
94 nday, & ! Number of daytime points
95 nlay, & ! Number of vertical grid points.
96 ngases, & ! Number of active gases
97 rrtmgp_phys_blksz, & ! Number of horizontal points to process at once.
98 iovr, & ! Choice of cloud-overlap method
99 iovr_convcld, & ! Choice of convective cloud-overlap
100 iovr_max, & ! Flag for maximum cloud overlap method
101 iovr_maxrand, & ! Flag for maximum-random cloud overlap method
102 iovr_rand, & ! Flag for random cloud overlap method
103 iovr_dcorr, & ! Flag for decorrelation-length cloud overlap method
104 iovr_exp, & ! Flag for exponential cloud overlap method
105 iovr_exprand, & ! Flag for exponential-random cloud overlap method
106 isubc_sw, & !
107 isfc
108 integer,intent(in),dimension(:) :: &
109 idx ! Index array for daytime points
110 integer,intent(in),dimension(:) :: &
111 icseed_sw ! Seed for random number generation for shortwave radiation
112 real(kind_phys), dimension(:), intent(in) :: &
113 sfc_alb_nir_dir, & ! Surface albedo (direct)
114 sfc_alb_nir_dif, & ! Surface albedo (diffuse)
115 sfc_alb_uvvis_dir, & ! Surface albedo (direct)
116 sfc_alb_uvvis_dif, & ! Surface albedo (diffuse)
117 coszen ! Cosize of SZA
118 real(kind_phys), dimension(:,:), intent(in) :: &
119 p_lay, & ! Pressure @ model layer-centers (Pa)
120 t_lay, & ! Temperature (K)
121 p_lev, & ! Pressure @ model layer-interfaces (Pa)
122 t_lev, & ! Temperature @ model levels (K)
123 vmr_o2, & ! Molar-mixing ratio oxygen
124 vmr_h2o, & ! Molar-mixing ratio water vapor
125 vmr_o3, & ! Molar-mixing ratio ozone
126 vmr_ch4, & ! Molar-mixing ratio methane
127 vmr_n2o, & ! Molar-mixing ratio nitrous oxide
128 vmr_co2 ! Molar-mixing ratio carbon dioxide
129 real(kind_phys), dimension(:,:), intent(in) :: &
130 cld_frac, & ! Cloud-fraction for stratiform clouds
131 cld_lwp, & ! Water path for stratiform liquid cloud-particles
132 cld_reliq, & ! Effective radius for stratiform liquid cloud-particles
133 cld_iwp, & ! Water path for stratiform ice cloud-particles
134 cld_reice, & ! Effective radius for stratiform ice cloud-particles
135 cld_swp, & ! Water path for snow hydrometeors
136 cld_resnow, & ! Effective radius for snow hydrometeors
137 cld_rwp, & ! Water path for rain hydrometeors
138 cld_rerain, & ! Effective radius for rain hydrometeors
139 precip_frac, & ! Precipitation fraction
140 cloud_overlap_param !
141 real(kind_phys), dimension(:,:), intent(in), optional :: &
142 cld_cnv_lwp, & ! Water path for convective liquid cloud-particles
143 cld_cnv_reliq, & ! Effective radius for convective liquid cloud-particles
144 cld_cnv_iwp, & ! Water path for convective ice cloud-particles
145 cld_cnv_reice, & ! Effective radius for convective ice cloud-particles
146 cld_pbl_lwp, & ! Water path for PBL liquid cloud-particles
147 cld_pbl_reliq, & ! Effective radius for PBL liquid cloud-particles
148 cld_pbl_iwp, & ! Water path for PBL ice cloud-particles
149 cld_pbl_reice ! Effective radius for PBL ice cloud-particles
150 real(kind_phys), dimension(:,:,:), intent(in) :: &
151 aersw_tau, & ! Aerosol optical depth
152 aersw_ssa, & ! Aerosol single scattering albedo
153 aersw_g ! Aerosol asymmetry paramter
154 character(len=*), dimension(:), intent(in) :: &
155 active_gases_array ! List of active gases from namelist as array
156 real(kind_phys), intent(in) :: &
157 solcon ! Solar constant
158
159 ! Outputs
160 character(len=*), intent(out) :: &
161 errmsg ! CCPP error message
162 integer, intent(out) :: &
163 errflg ! CCPP error flag
164 real(kind_phys), dimension(:,:), intent(inout) :: &
165 cldtausw ! Approx 10.mu band layer cloud optical depth
166 real(kind_phys), dimension(:,:), intent(inout) :: &
167 fluxswup_allsky, & ! RRTMGP upward all-sky flux profiles (W/m2)
168 fluxswdown_allsky, & ! RRTMGP downward all-sky flux profiles (W/m2)
169 fluxswup_clrsky, & ! RRTMGP upward clear-sky flux profiles (W/m2)
170 fluxswdown_clrsky ! RRTMGP downward clear-sky flux profiles (W/m2)
171 type(cmpfsw_type), dimension(:), intent(inout) :: &
172 scmpsw ! 2D surface fluxes, components:
173 ! uvbfc - total sky downward uv-b flux (W/m2)
174 ! uvbf0 - clear sky downward uv-b flux (W/m2)
175 ! nirbm - downward nir direct beam flux (W/m2)
176 ! nirdf - downward nir diffused flux (W/m2)
177 ! visbm - downward uv+vis direct beam flux (W/m2)
178 ! visdf - downward uv+vis diffused flux (W/m2)
179
180 ! Local variables
181 type(cmpfsw_type), dimension(rrtmgp_phys_blksz) :: scmpsw_clrsky, scmpsw_allsky
182 type(ty_fluxes_byband) :: flux_allsky, flux_clrsky
183 real(kind_phys) :: tau_rain, tau_snow, ssa_rain, ssa_snow, asy_rain, asy_snow, &
184 tau_prec, asy_prec, ssa_prec, asyw, ssaw, za1, za2, flux_dir, flux_dif
185 real(kind_phys), dimension(rrtmgp_phys_blksz) :: zcf0, zcf1
186 real(kind_dbl_prec), dimension(sw_gas_props%get_ngpt()) :: rng1d
187 real(rte_wp), dimension(sw_gas_props%get_ngpt(),nLay,rrtmgp_phys_blksz) :: rng3d,rng3d2
188 real(kind_dbl_prec), dimension(sw_gas_props%get_ngpt()*nLay) :: rng2d
189 logical, dimension(rrtmgp_phys_blksz,nLay,sw_gas_props%get_ngpt()) :: maskmcica
190 logical :: cloudy_column, clear_column, dogp_sgs_pbl, dogp_sgs_cnv
191 real(rte_wp), dimension(sw_gas_props%get_nband(),rrtmgp_phys_blksz) :: &
192 sfc_alb_dir, sfc_alb_dif
193 real(rte_wp), dimension(rrtmgp_phys_blksz,nLay+1,sw_gas_props%get_nband()),target :: &
194 fluxsw_up_allsky, fluxsw_up_clrsky, fluxsw_dn_dir_clrsky, fluxsw_dn_allsky, &
195 fluxsw_dn_clrsky, fluxsw_dn_dir_allsky
196 integer :: iband, ibd, ibd_uv, icol, igas, ilay, ix, ix2, iblck
197 integer, dimension(rrtmgp_phys_blksz) :: ipseed_sw, icols
198 type(random_stat) :: rng_stat
199 real(kind_phys), dimension(2,sw_gas_props%get_nband()) :: bandlimits
200 real(kind_phys), dimension(2), parameter :: &
201 nir_uvvis_bnd = (/12850,16000/), &
202 uvb_bnd = (/29000,38000/)
203 real(rte_wp), dimension(rrtmgp_phys_blksz,sw_gas_props%get_ngpt()) :: toa_src_sw
204
205 type(ty_gas_concs) :: gas_concs
206 type(ty_optical_props_2str) :: sw_optical_props_accum, sw_optical_props_aerosol_local, &
207 sw_optical_props_cloudsbyband, sw_optical_props_cnvcloudsbyband, &
208 sw_optical_props_pblcloudsbyband, sw_optical_props_precipbyband, &
209 sw_optical_props_clouds
210
211 ! Initialize CCPP error handling variables
212 errmsg = ''
213 errflg = 0
214
215 if (.not. doswrad) return
216
217 ! Do we have convective cloud properties?
218 dogp_sgs_cnv = .false.
219 if (present(cld_cnv_lwp) .and. present(cld_cnv_reliq) .and. &
220 present(cld_cnv_iwp) .and. present(cld_cnv_reice)) then
221 dogp_sgs_cnv = .true.
222 endif
223 ! Do we have pbl cloud prperties?
224 dogp_sgs_pbl = .false.
225 if (present(cld_pbl_lwp) .and. present(cld_pbl_reliq) .and. &
226 present(cld_pbl_iwp) .and. present(cld_pbl_reice)) then
227 dogp_sgs_pbl = .true.
228 endif
229
230 ! ty_gas_concs
231 call check_error_msg('rrtmgp_sw_main_gas_concs_init',gas_concs%init(active_gases_array))
232
233 ! ty_optical_props
234 call check_error_msg('rrtmgp_sw_main_accumulated_optics_init',&
235 sw_optical_props_accum%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props))
236 call check_error_msg('rrtmgp_sw_main_cloud_optics_init',&
237 sw_optical_props_cloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props%get_band_lims_wavenumber()))
238 call check_error_msg('rrtmgp_sw_main_precip_optics_init',&
239 sw_optical_props_precipbyband%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props%get_band_lims_wavenumber()))
240 call check_error_msg('rrtmgp_sw_mian_cloud_sampling_init', &
241 sw_optical_props_clouds%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props))
242 call check_error_msg('rrtmgp_sw_main_aerosol_optics_init',&
243 sw_optical_props_aerosol_local%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props%get_band_lims_wavenumber()))
244 if (dogp_sgs_cnv) then
245 call check_error_msg('rrtmgp_sw_main_cnv_cloud_optics_init',&
246 sw_optical_props_cnvcloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props%get_band_lims_wavenumber()))
247 endif
248 if (dogp_sgs_pbl) then
249 call check_error_msg('rrtmgp_sw_main_pbl_cloud_optics_init',&
250 sw_optical_props_pblcloudsbyband%alloc_2str(rrtmgp_phys_blksz, nlay, sw_gas_props%get_band_lims_wavenumber()))
251 endif
252
253 if (nday .gt. 0) then
254
255 bandlimits = sw_gas_props%get_band_lims_wavenumber()
256 ! ######################################################################################
257 !
258 ! Loop over all (daylit) columns...
259 !
260 ! ######################################################################################
261 do icol=1,nday,rrtmgp_phys_blksz
262 !ix = idx(iCol)
263 !ix2 = idx(iCol + rrtmgp_phys_blksz - 1)
264 icols = idx(icol:icol + rrtmgp_phys_blksz - 1)
265
266 ! Create clear/cloudy indicator
267 zcf0(:) = 1._kind_phys
268 zcf1(:) = 1._kind_phys
269 do iblck = 1, rrtmgp_phys_blksz
270 do ilay=1,nlay
271 zcf0(iblck) = min(zcf0(iblck), 1._kind_phys - cld_frac(icols(iblck),ilay))
272 enddo
273 if (zcf0(iblck) <= ftiny) zcf0(iblck) = 0._kind_phys
274 if (zcf0(iblck) > oneminus) zcf0(iblck) = 1._kind_phys
275 zcf1(iblck) = 1._kind_phys - zcf0(iblck)
276 enddo
277 cloudy_column = any(zcf1 .gt. eps)
278 clear_column = .true.
279 if (cloudy_column) clear_column = .false.
280
281 ! ###################################################################################
282 !
283 ! Initialize/reset
284 !
285 ! ###################################################################################
286 sw_optical_props_clouds%tau = 0._kind_phys
287 sw_optical_props_clouds%ssa = 0._kind_phys
288 sw_optical_props_clouds%g = 0._kind_phys
289 sw_optical_props_accum%tau = 0._kind_phys
290 sw_optical_props_accum%ssa = 0._kind_phys
291 sw_optical_props_accum%g = 0._kind_phys
292 sw_optical_props_cloudsbyband%tau = 0._kind_phys
293 sw_optical_props_cloudsbyband%ssa = 0._kind_phys
294 sw_optical_props_cloudsbyband%g = 0._kind_phys
295 sw_optical_props_precipbyband%tau = 0._kind_phys
296 sw_optical_props_precipbyband%ssa = 0._kind_phys
297 sw_optical_props_precipbyband%g = 0._kind_phys
298 if (dogp_sgs_cnv) then
299 sw_optical_props_cnvcloudsbyband%tau = 0._kind_phys
300 sw_optical_props_cnvcloudsbyband%ssa = 0._kind_phys
301 sw_optical_props_cnvcloudsbyband%g = 0._kind_phys
302 endif
303 if (dogp_sgs_pbl) then
304 sw_optical_props_pblcloudsbyband%tau = 0._kind_phys
305 sw_optical_props_pblcloudsbyband%ssa = 0._kind_phys
306 sw_optical_props_pblcloudsbyband%g = 0._kind_phys
307 endif
308 scmpsw_clrsky= cmpfsw_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
309 scmpsw_allsky= cmpfsw_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
310 cldtausw = 0._kind_phys
311
312 ! ty_fluxes_byband
313 fluxsw_up_allsky = 0._rte_wp
314 fluxsw_dn_allsky = 0._rte_wp
315 fluxsw_dn_dir_allsky = 0._rte_wp
316 fluxsw_up_clrsky = 0._rte_wp
317 fluxsw_dn_clrsky = 0._rte_wp
318 flux_allsky%bnd_flux_up => fluxsw_up_allsky
319 flux_allsky%bnd_flux_dn => fluxsw_dn_allsky
320 flux_allsky%bnd_flux_dn_dir => fluxsw_dn_dir_allsky
321 flux_clrsky%bnd_flux_up => fluxsw_up_clrsky
322 flux_clrsky%bnd_flux_dn => fluxsw_dn_clrsky
323
324 ! ###################################################################################
325 !
326 ! Set gas-concentrations
327 !
328 ! ###################################################################################
329 call check_error_msg('rrtmgp_sw_main_set_vmr_o2', &
330 gas_concs%set_vmr(trim(active_gases_array(istr_o2)), real(vmr_o2(icols,:), kind=rte_wp)))
331 call check_error_msg('rrtmgp_sw_main_set_vmr_co2', &
332 gas_concs%set_vmr(trim(active_gases_array(istr_co2)),real(vmr_co2(icols,:), kind=rte_wp)))
333 call check_error_msg('rrtmgp_sw_main_set_vmr_ch4', &
334 gas_concs%set_vmr(trim(active_gases_array(istr_ch4)),real(vmr_ch4(icols,:), kind=rte_wp)))
335 call check_error_msg('rrtmgp_sw_main_set_vmr_n2o', &
336 gas_concs%set_vmr(trim(active_gases_array(istr_n2o)),real(vmr_n2o(icols,:), kind=rte_wp)))
337 call check_error_msg('rrtmgp_sw_main_set_vmr_h2o', &
338 gas_concs%set_vmr(trim(active_gases_array(istr_h2o)),real(vmr_h2o(icols,:), kind=rte_wp)))
339 call check_error_msg('rrtmgp_sw_main_set_vmr_o3', &
340 gas_concs%set_vmr(trim(active_gases_array(istr_o3)), real(vmr_o3(icols,:), kind=rte_wp)))
341
342 ! ###################################################################################
343 !
344 ! Compute gas-optics
345 !
346 ! ###################################################################################
347
348 call check_error_msg('rrtmgp_sw_main_gas_optics',sw_gas_props%gas_optics(&
349 real(p_lay(icols,:), kind=rte_wp), & ! IN - Pressure @ layer-centers (Pa)
350 real(p_lev(icols,:), kind=rte_wp), & ! IN - Pressure @ layer-interfaces (Pa)
351 real(t_lay(icols,:), kind=rte_wp), & ! IN - Temperature @ layer-centers (K)
352 gas_concs, & ! IN - RRTMGP DDT: trace gas volumne mixing-ratios
353 sw_optical_props_accum, & ! OUT - RRTMGP DDT: Shortwave optical properties, by
354 ! spectral point (tau,ssa,g)
355 toa_src_sw)) ! OUT - TOA incident shortwave radiation (spectral)
356 ! Scale incident flux
357 do iblck = 1, rrtmgp_phys_blksz
358 toa_src_sw(iblck,:) = toa_src_sw(iblck,:)*solcon / sum(toa_src_sw(iblck,:))
359 enddo
360
361 ! ###################################################################################
362 !
363 ! Set surface albedo
364 !
365 ! Use near-IR albedo for bands with wavenumbers extending to 12850cm-1
366 ! Use uv-vis albedo for bands with wavenumbers greater than 16000cm-1
367 ! For overlapping band, average near-IR and us-vis albedos.
368 !
369 ! ###################################################################################
370 do iblck = 1, rrtmgp_phys_blksz
371 do iband=1,sw_gas_props%get_nband()
372 if (bandlimits(1,iband) .lt. nir_uvvis_bnd(1)) then
373 sfc_alb_dir(iband,iblck) = sfc_alb_nir_dir(icols(iblck))
374 sfc_alb_dif(iband,iblck) = sfc_alb_nir_dif(icols(iblck))
375 endif
376 if (bandlimits(1,iband) .eq. nir_uvvis_bnd(1)) then
377 sfc_alb_dir(iband,iblck) = 0.5_kind_phys*(sfc_alb_nir_dir(icols(iblck)) + &
378 sfc_alb_uvvis_dir(icols(iblck)))
379 sfc_alb_dif(iband,iblck) = 0.5_kind_phys*(sfc_alb_nir_dif(icols(iblck)) + &
380 sfc_alb_uvvis_dif(icols(iblck)))
381 ibd = iband
382 endif
383 if (bandlimits(1,iband) .ge. nir_uvvis_bnd(2)) then
384 sfc_alb_dir(iband,iblck) = sfc_alb_uvvis_dir(icols(iblck))
385 sfc_alb_dif(iband,iblck) = sfc_alb_uvvis_dif(icols(iblck))
386 endif
387 if (bandlimits(1,iband) .eq. uvb_bnd(1)) ibd_uv = iband
388 enddo
389 enddo
390
391 ! ###################################################################################
392 !
393 ! Compute optics for cloud(s) and precipitation, sample clouds...
394 !
395 ! ###################################################################################
396 if (cloudy_column) then
397 ! Gridmean/mp-clouds
398 call check_error_msg('rrtmgp_sw_main_cloud_optics',sw_cloud_props%cloud_optics(&
399 real(cld_lwp(icols,:), kind=rte_wp), & ! IN - Cloud liquid water path
400 real(cld_iwp(icols,:), kind=rte_wp), & ! IN - Cloud ice water path
401 real(cld_reliq(icols,:),kind=rte_wp), & ! IN - Cloud liquid effective radius
402 real(cld_reice(icols,:),kind=rte_wp), & ! IN - Cloud ice effective radius
403 sw_optical_props_cloudsbyband)) ! OUT - RRTMGP DDT: Shortwave optical properties,
404 ! in each band (tau,ssa,g)
405 cldtausw(icols,:) = sw_optical_props_cloudsbyband%tau(:,:,11)
406
407 ! Include convective clouds?
408 if (dogp_sgs_cnv) then
409 ! Compute
410 call check_error_msg('rrtmgp_sw_main_cnv_cloud_optics',sw_cloud_props%cloud_optics(&
411 real(cld_cnv_lwp(icols,:), kind=rte_wp), & ! IN - Convective cloud liquid water path (g/m2)
412 real(cld_cnv_iwp(icols,:), kind=rte_wp), & ! IN - Convective cloud ice water path (g/m2)
413 real(cld_cnv_reliq(icols,:),kind=rte_wp), & ! IN - Convective cloud liquid effective radius (microns)
414 real(cld_cnv_reice(icols,:),kind=rte_wp), & ! IN - Convective cloud ice effective radius (microns)
415 sw_optical_props_cnvcloudsbyband)) ! OUT - RRTMGP DDT containing convective cloud radiative properties
416 ! in each band
417 ! Increment
418 call check_error_msg('rrtmgp_sw_main_increment_cnvclouds_to_clouds',&
419 sw_optical_props_cnvcloudsbyband%increment(sw_optical_props_cloudsbyband))
420 endif
421
422 ! Include PBL clouds?
423 if (dogp_sgs_pbl) then
424 ! Compute
425 call check_error_msg('rrtmgp_sw_main_pbl_cloud_optics',sw_cloud_props%cloud_optics(&
426 real(cld_pbl_lwp(icols,:), kind=rte_wp), & ! IN - PBL cloud liquid water path (g/m2)
427 real(cld_pbl_iwp(icols,:), kind=rte_wp), & ! IN - PBL cloud ice water path (g/m2)
428 real(cld_pbl_reliq(icols,:), kind=rte_wp), & ! IN - PBL cloud liquid effective radius (microns)
429 real(cld_pbl_reice(icols,:), kind=rte_wp), & ! IN - PBL cloud ice effective radius (microns)
430 sw_optical_props_pblcloudsbyband)) ! OUT - RRTMGP DDT containing PBL cloud radiative properties
431 ! in each band
432 ! Increment
433 call check_error_msg('rrtmgp_sw_main_increment_pblclouds_to_clouds',&
434 sw_optical_props_pblcloudsbyband%increment(sw_optical_props_cloudsbyband))
435 endif
436
437 ! Cloud precipitation optics: rain and snow(+groupel)
438 do iblck = 1, rrtmgp_phys_blksz
439 do ilay=1,nlay
440 if (cld_frac(icols(iblck),ilay) .gt. ftiny) then
441 ! Rain/Snow optical depth (No band dependence)
442 tau_rain = cld_rwp(icols(iblck),ilay)*a0r
443 if (cld_swp(icols(iblck),ilay) .gt. 0. .and. cld_resnow(icols(iblck),ilay) .gt. 10._kind_phys) then
444 tau_snow = cld_swp(icols(iblck),ilay)*1.09087*(a0s + a1s/(1.0315*cld_resnow(icols(iblck),ilay))) ! fu's formula
445 else
446 tau_snow = 0._kind_phys
447 endif
448
449 ! Rain/Snow single-scattering albedo and asymmetry (Band dependent)
450 do iband=1,sw_gas_props%get_nband()
451 ! By species
452 ssa_rain = tau_rain*(1.-b0r(iband))
453 asy_rain = ssa_rain*c0r(iband)
454 ssa_snow = tau_snow*(1.-(b0s(iband)+b1s(iband)*1.0315*cld_resnow(icols(iblck),ilay)))
455 asy_snow = ssa_snow*c0s(iband)
456 ! Combine
457 tau_prec = max(1.e-12_kind_phys, tau_rain + tau_snow)
458 ssa_prec = max(1.e-12_kind_phys, ssa_rain + ssa_snow)
459 asy_prec = max(1.e-12_kind_phys, asy_rain + asy_snow)
460 asyw = asy_prec/max(1.e-12_kind_phys, ssa_prec)
461 ssaw = min(1._kind_phys-0.000001, ssa_prec/tau_prec)
462 za1 = asyw * asyw
463 za2 = ssaw * za1
464 sw_optical_props_precipbyband%tau(iblck,ilay,iband) = (1._kind_phys - za2) * tau_prec
465 sw_optical_props_precipbyband%ssa(iblck,ilay,iband) = (ssaw - za2) / (1._kind_phys - za2)
466 sw_optical_props_precipbyband%g(iblck,ilay,iband) = asyw/(1+asyw)
467 enddo
468 endif
469 enddo
470 enddo
471 ! Increment
472 call check_error_msg('rrtmgp_sw_main_increment_precip_to_clouds',&
473 sw_optical_props_precipbyband%increment(sw_optical_props_cloudsbyband))
474
475 ! ###################################################################################
476 !
477 ! Cloud-sampling
478 !
479 ! ###################################################################################
480 ! Change random number seed value for each radiation invocation (isubc_sw =1 or 2).
481 if(isubc_sw == 1) then ! advance prescribed permutation seed
482 do iblck = 1, rrtmgp_phys_blksz
483 ipseed_sw(iblck) = sw_gas_props%get_ngpt() + icols(iblck)
484 enddo
485 elseif (isubc_sw == 2) then ! use input array of permutation seeds
486 do iblck = 1, rrtmgp_phys_blksz
487 ipseed_sw(iblck) = icseed_sw(icols(iblck))
488 enddo
489 endif
490
491 ! Call RNG
492 do iblck = 1, rrtmgp_phys_blksz
493 call random_setseed(ipseed_sw(iblck),rng_stat)
494 ! Use same rng for each layer
495 if (iovr == iovr_max) then
496 call random_number(rng1d,rng_stat)
497 do ilay=1,nlay
498 rng3d(:,ilay,iblck) = rng1d
499 enddo
500 else
501 do ilay=1,nlay
502 call random_number(rng1d,rng_stat)
503 rng3d(:,ilay,iblck) = rng1d
504 enddo
505 endif
506 enddo
507
508 ! Cloud-overlap.
509 ! Maximum-random, random or maximum.
510 if (iovr == iovr_maxrand .or. iovr == iovr_rand .or. iovr == iovr_max) then
511 call sampled_mask(rng3d, real(cld_frac(icols,:), kind=rte_wp), maskmcica)
512 endif
513 ! Exponential decorrelation length overlap
514 if (iovr == iovr_dcorr) then
515 do iblck = 1, rrtmgp_phys_blksz
516 ! Generate second RNG
517 call random_setseed(ipseed_sw(iblck),rng_stat)
518 call random_number(rng2d,rng_stat)
519 rng3d2(:,:,iblck) = reshape(source = rng2d,shape=[sw_gas_props%get_ngpt(),nlay])
520 enddo
521 !
522 call sampled_mask(rng3d, real(cld_frac(icols,:), kind=rte_wp), &
523 maskmcica, overlap_param = real(cloud_overlap_param(icols,1:nlay-1), kind=rte_wp),&
524 randoms2 = rng3d2)
525 endif
526 ! Exponential or Exponential-random
527 if (iovr == iovr_exp .or. iovr == iovr_exprand) then
528 call sampled_mask(rng3d, real(cld_frac(icols,:), kind=rte_wp), &
529 maskmcica, overlap_param = real(cloud_overlap_param(icols,1:nlay-1), kind=rte_wp))
530 endif
531 ! Sampling. Map band optical depth to each g-point using McICA
532 call check_error_msg('rrtmgp_sw_main_cloud_sampling',&
533 draw_samples(maskmcica, .true., &
534 sw_optical_props_cloudsbyband, sw_optical_props_clouds))
535 endif ! cloudy_column
536
537 ! ###################################################################################
538 !
539 ! Compute clear-sky fluxes (gaseous+aerosol)
540 !
541 ! ###################################################################################
542 ! Increment optics (always)
543 sw_optical_props_aerosol_local%tau = aersw_tau(icols,:,:)
544 sw_optical_props_aerosol_local%ssa = aersw_ssa(icols,:,:)
545 sw_optical_props_aerosol_local%g = aersw_g(icols,:,:)
546 call check_error_msg('rrtmgp_sw_main_increment_aerosol_to_clrsky', &
547 sw_optical_props_aerosol_local%increment(sw_optical_props_accum))
548
549 ! Compute clear-sky fluxes (Yes for no-clouds. Optional for cloudy scenes)
550 if (clear_column .or. doswclrsky) then
551 call check_error_msg('rrtmgp_sw_main_rte_sw_clrsky',rte_sw( &
552 sw_optical_props_accum, & ! IN - optical-properties
553 top_at_1, & ! IN - veritcal ordering flag
554 real(coszen(icols), kind=rte_wp), & ! IN - Cosine of solar zenith angle
555 toa_src_sw, & ! IN - incident solar flux at TOA
556 sfc_alb_dir, & ! IN - Shortwave surface albedo (direct)
557 sfc_alb_dif, & ! IN - Shortwave surface albedo (diffuse)
558 flux_clrsky)) ! OUT - Fluxes, clear-sky, 3D (1,nLay,nBand)
559
560 ! Store fluxes
561 fluxswup_clrsky(icols,:) = sum(flux_clrsky%bnd_flux_up, dim=3)
562 fluxswdown_clrsky(icols,:) = sum(flux_clrsky%bnd_flux_dn, dim=3)
563
564 ! Compute surface downward beam/diffused flux components
565 do iblck = 1, rrtmgp_phys_blksz
566 do iband=1,sw_gas_props%get_nband()
567 flux_dir = flux_clrsky%bnd_flux_dn(iblck,isfc,iband)
568 flux_dif = 0._kind_phys
569 ! Near-IR bands
570 if (iband < ibd) then
571 scmpsw_clrsky(iblck)%nirbm = scmpsw_clrsky(iblck)%nirbm + flux_dir
572 scmpsw_clrsky(iblck)%nirdf = scmpsw_clrsky(iblck)%nirdf + flux_dif
573 endif
574 ! Transition band
575 if (iband == ibd) then
576 scmpsw_clrsky(iblck)%nirbm = scmpsw_clrsky(iblck)%nirbm + flux_dir*0.5_kind_phys
577 scmpsw_clrsky(iblck)%nirdf = scmpsw_clrsky(iblck)%nirdf + flux_dif*0.5_kind_phys
578 scmpsw_clrsky(iblck)%visbm = scmpsw_clrsky(iblck)%visbm + flux_dir*0.5_kind_phys
579 scmpsw_clrsky(iblck)%visdf = scmpsw_clrsky(iblck)%visdf + flux_dif*0.5_kind_phys
580 endif
581 ! UV-VIS bands
582 if (iband > ibd) then
583 scmpsw_clrsky(iblck)%visbm = scmpsw_clrsky(iblck)%visbm + flux_dir
584 scmpsw_clrsky(iblck)%visdf = scmpsw_clrsky(iblck)%visdf + flux_dif
585 endif
586 ! uv-b surface downward flux
587 scmpsw_clrsky(iblck)%uvbfc = flux_clrsky%bnd_flux_dn(iblck,isfc,ibd_uv)
588 enddo
589 enddo
590 else
591 fluxswup_clrsky(icols,:) = 0._kind_phys
592 fluxswdown_clrsky(icols,:) = 0._kind_phys
593 scmpsw = cmpfsw_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
594 endif
595
596 ! ###################################################################################
597 !
598 ! All-sky fluxes (clear-sky + clouds + precipitation)
599 !
600 ! ###################################################################################
601 if (cloudy_column) then
602 ! Delta scale
603 !call check_error_msg('rrtmgp_sw_main_delta_scale',sw_optical_props_clouds%delta_scale())
604
605 ! Increment
606 call check_error_msg('rrtmgp_sw_main_increment_clouds_to_clrsky', &
607 sw_optical_props_clouds%increment(sw_optical_props_accum))
608
609 ! Compute fluxes
610 call check_error_msg('rrtmgp_sw_main_rte_sw_allsky',rte_sw( &
611 sw_optical_props_accum, & ! IN - optical-properties
612 top_at_1, & ! IN - veritcal ordering flag
613 real(coszen(icols), kind=rte_wp), & ! IN - Cosine of solar zenith angle
614 toa_src_sw, & ! IN - incident solar flux at TOA
615 sfc_alb_dir, & ! IN - Shortwave surface albedo (direct)
616 sfc_alb_dif, & ! IN - Shortwave surface albedo (diffuse)
617 flux_allsky)) ! OUT - Fluxes, clear-sky, 3D (1,nLay,nBand)
618
619 ! Store fluxes
620 fluxswup_allsky(icols,:) = sum(flux_allsky%bnd_flux_up, dim=3)
621 fluxswdown_allsky(icols,:) = sum(flux_allsky%bnd_flux_dn, dim=3)
622
623 ! Compute and store downward beam/diffused flux components
624 do iblck = 1, rrtmgp_phys_blksz
625 ! Loop over bands, sum fluxes...
626 do iband=1,sw_gas_props%get_nband()
627 flux_dir = flux_allsky%bnd_flux_dn_dir(iblck,isfc,iband)
628 flux_dif = flux_allsky%bnd_flux_dn(iblck,isfc,iband) - flux_allsky%bnd_flux_dn_dir(iblck,isfc,iband)
629 ! Near-IR bands
630 if (iband < ibd) then
631 scmpsw_allsky(iblck)%nirbm = scmpsw_allsky(iblck)%nirbm + flux_dir
632 scmpsw_allsky(iblck)%nirdf = scmpsw_allsky(iblck)%nirdf + flux_dif
633 endif
634 ! Transition band
635 if (iband == ibd) then
636 scmpsw_allsky(iblck)%nirbm = scmpsw_allsky(iblck)%nirbm + flux_dir*0.5_kind_phys
637 scmpsw_allsky(iblck)%nirdf = scmpsw_allsky(iblck)%nirdf + flux_dif*0.5_kind_phys
638 scmpsw_allsky(iblck)%visbm = scmpsw_allsky(iblck)%visbm + flux_dir*0.5_kind_phys
639 scmpsw_allsky(iblck)%visdf = scmpsw_allsky(iblck)%visdf + flux_dif*0.5_kind_phys
640 endif
641 ! UV-VIS bands
642 if (iband > ibd) then
643 scmpsw_allsky(iblck)%visbm = scmpsw_allsky(iblck)%visbm + flux_dir
644 scmpsw_allsky(iblck)%visdf = scmpsw_allsky(iblck)%visdf + flux_dif
645 endif
646 ! uv-b surface downward flux
647 scmpsw_allsky(iblck)%uvbfc = flux_allsky%bnd_flux_dn(iblck,isfc,ibd_uv)
648 enddo
649 ! Store surface downward beam/diffused flux components
650 if (zcf1(iblck) .gt. eps) then
651 scmpsw(icols(iblck))%nirbm = scmpsw_allsky(iblck)%nirbm
652 scmpsw(icols(iblck))%nirdf = scmpsw_allsky(iblck)%nirdf
653 scmpsw(icols(iblck))%visbm = scmpsw_allsky(iblck)%visbm
654 scmpsw(icols(iblck))%visdf = scmpsw_allsky(iblck)%visdf
655 scmpsw(icols(iblck))%uvbfc = flux_allsky%bnd_flux_dn(iblck,isfc,ibd_uv)
656 else
657 scmpsw(icols(iblck))%nirbm = scmpsw_clrsky(iblck)%nirbm
658 scmpsw(icols(iblck))%nirdf = scmpsw_clrsky(iblck)%nirdf
659 scmpsw(icols(iblck))%visbm = scmpsw_clrsky(iblck)%visbm
660 scmpsw(icols(iblck))%visdf = scmpsw_clrsky(iblck)%visdf
661 scmpsw(icols(iblck))%uvbfc = flux_clrsky%bnd_flux_dn(iblck,isfc,ibd_uv)
662 endif
663 scmpsw(icols(iblck))%uvbf0 = flux_clrsky%bnd_flux_dn(iblck,isfc,ibd_uv)
664 enddo
665 else ! No clouds
666 fluxswup_allsky(icols,:) = sum(flux_clrsky%bnd_flux_up, dim=3)
667 fluxswdown_allsky(icols,:) = sum(flux_clrsky%bnd_flux_dn, dim=3)
668 do iblck = 1, rrtmgp_phys_blksz
669 scmpsw(icols(iblck))%nirbm = scmpsw_clrsky(iblck)%nirbm
670 scmpsw(icols(iblck))%nirdf = scmpsw_clrsky(iblck)%nirdf
671 scmpsw(icols(iblck))%visbm = scmpsw_clrsky(iblck)%visbm
672 scmpsw(icols(iblck))%visdf = scmpsw_clrsky(iblck)%visdf
673 scmpsw(icols(iblck))%uvbfc = flux_clrsky%bnd_flux_dn(iblck,isfc,ibd_uv)
674 scmpsw(icols(iblck))%uvbf0 = flux_clrsky%bnd_flux_dn(iblck,isfc,ibd_uv)
675 enddo
676 endif
677 !
678 enddo ! nday
679 else
680 fluxswup_allsky(:,:) = 0._kind_phys
681 fluxswdown_allsky(:,:) = 0._kind_phys
682 fluxswup_clrsky(:,:) = 0._kind_phys
683 fluxswdown_clrsky(:,:) = 0._kind_phys
684 scmpsw = cmpfsw_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
685 endif
686 end subroutine rrtmgp_sw_main_run
687end module rrtmgp_sw_main
This module calculates random numbers using the Mersenne twister.
This module is for specifying the band structures and program parameters used by the RRTMG-SW scheme.
Definition radsw_param.f:62
This module contains tools for radiation.
This module provides a simple implementation of sampling for the Monte Carlo Independent Pixel Approx...
This module contains the cloud optics properties calculation for RRTMGP-SW.
This module contains a routine to initialize the k-distribution data used by the RRTMGP shortwave rad...
This module contain the RRTMGP-SW radiation scheme.
derived type for special components of surface SW fluxes