Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve readability of some assigments #551

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ RRTMGP.jl Release Notes
main
------

### Bug fixes

#### Fix `flux_dn_dir` for non-gray radiation

Prior to this release, `flux_dn_dir` was not correctly set in the two stream
case for non-gray radiation, leading to incorrect values (whatever was in the
memory at initialization). Now, the variable is correctly accumulated over for
ever g-point. Note, however, that only the value at the surface (`[1, :]`) is
updated. PR [#550](https://github.com/CliMA/RRTMGP.jl/pull/550).

v0.19.0
-----
- Compute aero_mask internally and store the array.
Expand Down
4 changes: 2 additions & 2 deletions ext/cuda/rte_longwave_2stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ function rte_lw_2stream_solve_CUDA!(
compute_optical_props!(op, as, src_lw, gcol, igpt, lookup_lw, lookup_lw_cld, lookup_lw_aero)
rte_lw_2stream!(op, flux, src_lw, bcs_lw, gcol, igpt, ibnd, nlev, ncol)
if igpt == 1
map!(x -> x, view(flux_up_lw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_lw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_lw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_lw, :, gcol) .= view(flux_dn, :, gcol)
else
for ilev in 1:nlev
@inbounds flux_up_lw[ilev, gcol] += flux_up[ilev, gcol]
Expand Down
8 changes: 6 additions & 2 deletions ext/cuda/rte_shortwave_1scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,25 @@ function rte_sw_noscat_solve_CUDA!(
flux_up_sw = flux_sw.flux_up
flux_dn_sw = flux_sw.flux_dn
flux_net_sw = flux_sw.flux_net
flux_dn_dir_sw = flux_sw.flux_dn_dir
flux_up = flux.flux_up
flux_dn = flux.flux_dn
flux_dn_dir = flux.flux_dn_dir
μ₀ = bcs_sw.cos_zenith[gcol]
@inbounds begin
for igpt in 1:n_gpt
compute_optical_props!(op, as, gcol, igpt, lookup_sw, nothing)
solar_frac = lookup_sw.solar_src_scaled[igpt]
rte_sw_noscat!(flux, op, bcs_sw, igpt, n_gpt, solar_frac, gcol, nlev)
if igpt == 1
map!(x -> x, view(flux_up_sw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_sw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_sw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_sw, :, gcol) .= view(flux_dn, :, gcol)
view(flux_dn_dir_sw, :, gcol) .= view(flux_dn_dir, :, gcol)
else
for ilev in 1:nlev
flux_up_sw[ilev, gcol] += flux_up[ilev, gcol]
flux_dn_sw[ilev, gcol] += flux_dn[ilev, gcol]
flux_dn_dir_sw[ilev, gcol] += flux_dn_dir[ilev, gcol]
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions ext/cuda/rte_shortwave_2stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ function rte_sw_2stream_solve_CUDA!(
if gcol ≤ ncol
flux_up_sw = flux_sw.flux_up
flux_dn_sw = flux_sw.flux_dn
flux_dn_dir_sw = flux_sw.flux_dn_dir
flux_net_sw = flux_sw.flux_net
flux_up = flux.flux_up
flux_dn = flux.flux_dn
flux_dn_dir = flux.flux_dn_dir
FT = eltype(flux_up)
(; cloud_state, aerosol_state) = as
μ₀ = bcs_sw.cos_zenith[gcol]
Expand All @@ -125,12 +127,14 @@ function rte_sw_2stream_solve_CUDA!(
# rte shortwave solver
rte_sw_2stream!(op, src_sw, bcs_sw, flux, solar_frac, igpt, n_gpt, ibnd, nlev, gcol)
if igpt == 1
map!(x -> x, view(flux_up_sw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_sw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_sw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_sw, :, gcol) .= view(flux_dn, :, gcol)
view(flux_dn_dir_sw, :, gcol) .= view(flux_dn_dir, :, gcol)
else
for ilev in 1:nlev
flux_up_sw[ilev, gcol] += flux_up[ilev, gcol]
flux_dn_sw[ilev, gcol] += flux_dn[ilev, gcol]
flux_dn_dir_sw[ilev, gcol] += flux_dn_dir[ilev, gcol]
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/rte/longwave2stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ function rte_lw_2stream_solve!(
compute_optical_props!(op, as, src_lw, gcol, igpt, lookup_lw, lookup_lw_cld, lookup_lw_aero)
rte_lw_2stream!(op, flux, src_lw, bcs_lw, gcol, igpt, ibnd, nlev, ncol)
if igpt == 1
map!(x -> x, view(flux_up_lw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_lw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_lw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_lw, :, gcol) .= view(flux_dn, :, gcol)
else
for ilev in 1:nlev
@inbounds flux_up_lw[ilev, gcol] += flux_up[ilev, gcol]
Expand Down
9 changes: 6 additions & 3 deletions src/rte/shortwave1scalar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ function rte_sw_noscat_solve!(
n_gpt = length(lookup_sw.solar_src_scaled)
flux_up_sw = flux_sw.flux_up
flux_dn_sw = flux_sw.flux_dn
flux_dn_dir_sw = flux_sw.flux_dn_dir
flux_net_sw = flux_sw.flux_net
(; flux_up, flux_dn) = flux
(; flux_up, flux_dn, flux_dn_dir) = flux
cos_zenith = bcs_sw.cos_zenith
@inbounds begin
for igpt in 1:n_gpt
Expand All @@ -49,12 +50,14 @@ function rte_sw_noscat_solve!(
solar_frac = lookup_sw.solar_src_scaled[igpt]
rte_sw_noscat!(flux, op, bcs_sw, igpt, n_gpt, solar_frac, gcol, nlev)
if igpt == 1
map!(x -> x, view(flux_up_sw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_sw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_sw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_sw, :, gcol) .= view(flux_dn, :, gcol)
view(flux_dn_dir_sw, :, gcol) .= view(flux_dn_dir, :, gcol)
else
for ilev in 1:nlev
flux_up_sw[ilev, gcol] += flux_up[ilev, gcol]
flux_dn_sw[ilev, gcol] += flux_dn[ilev, gcol]
flux_dn_dir_sw[ilev, gcol] += flux_dn_dir[ilev, gcol]
end
end
else
Expand Down
9 changes: 6 additions & 3 deletions src/rte/shortwave2stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ function rte_sw_2stream_solve!(
bld_cld_mask = cloud_state isa CloudState
flux_up_sw = flux_sw.flux_up
flux_dn_sw = flux_sw.flux_dn
flux_dn_dir_sw = flux_sw.flux_dn_dir
flux_net_sw = flux_sw.flux_net
(; flux_up, flux_dn) = flux
(; flux_up, flux_dn, flux_dn_dir) = flux
cos_zenith = bcs_sw.cos_zenith
FT = eltype(flux_up)
if aerosol_state isa AerosolState
Expand All @@ -80,12 +81,14 @@ function rte_sw_2stream_solve!(
# call rte shortwave solver
rte_sw_2stream!(op, src_sw, bcs_sw, flux, solar_frac, igpt, n_gpt, ibnd, nlev, gcol)
if igpt == 1
map!(x -> x, view(flux_up_sw, :, gcol), view(flux_up, :, gcol))
map!(x -> x, view(flux_dn_sw, :, gcol), view(flux_dn, :, gcol))
view(flux_up_sw, :, gcol) .= view(flux_up, :, gcol)
view(flux_dn_sw, :, gcol) .= view(flux_dn, :, gcol)
view(flux_dn_dir_sw, :, gcol) .= view(flux_dn_dir, :, gcol)
else
for ilev in 1:nlev
@inbounds flux_up_sw[ilev, gcol] += flux_up[ilev, gcol]
@inbounds flux_dn_sw[ilev, gcol] += flux_dn[ilev, gcol]
@inbounds flux_dn_dir_sw[ilev, gcol] += flux_dn_dir[ilev, gcol]
end
end
else
Expand Down
Loading