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

Sk/refactor sw rte #410

Closed
wants to merge 12 commits into from
58 changes: 52 additions & 6 deletions src/optics/AtmosphericStates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using ..Vmrs

export AbstractAtmosphericState,
AtmosphericState,
AtmosphericStatec,
GrayAtmosphericState,
setup_gray_as_pr_grid,
setup_gray_as_alt_grid,
Expand Down Expand Up @@ -44,9 +45,8 @@ struct AtmosphericState{
FTA2D <: AbstractArray{FT, 2},
CLDP <: Union{AbstractArray{FT, 2}, Nothing},
CLDM <: Union{AbstractArray{Bool, 2}, Nothing},
RND <: Union{AbstractArray{FT, 2}, Nothing},
CMASK <: Union{AbstractCloudMask, Nothing},
VMR <: AbstractVmr{FT},
VMR <: AbstractVmr,
} <: AbstractAtmosphericState{FT, FTA1D}
"longitude, in degrees (`ncol`), optional"
lon::FTA1DN
Expand Down Expand Up @@ -76,10 +76,6 @@ struct AtmosphericState{
cld_path_ice::CLDP
"cloud fraction"
cld_frac::CLDP
"random number storage for longwave bands `(nlay, ncol)`"
random_lw::RND
"random number storage for shortwave bands `(nlay, ncol)`"
random_sw::RND
"cloud mask (longwave), = true if clouds are present"
cld_mask_lw::CLDM
"cloud mask (shortwave), = true if clouds are present"
Expand All @@ -96,4 +92,54 @@ struct AtmosphericState{
ngas::Int
end
Adapt.@adapt_structure AtmosphericState

struct AtmosphericStatec{FTVA1DN, FTVA1D, FTA1D, CLDP, CLDM, CMASK, VMR}
lon::FTVA1DN
lat::FTVA1DN
p_lay::FTA1D
p_lev::FTA1D
t_lay::FTA1D
t_lev::FTA1D
t_sfc::FTVA1D
col_dry::FTA1D
vmr::VMR
cld_r_eff_liq::CLDP
cld_r_eff_ice::CLDP
cld_path_liq::CLDP
cld_path_ice::CLDP
cld_frac::CLDP
cld_mask_lw::CLDM
cld_mask_sw::CLDM
cld_mask_type::CMASK
ice_rgh::Int
nlay::Int
ncol::Int
ngas::Int
end
Adapt.@adapt_structure AtmosphericStatec

AtmosphericStatec(as::AtmosphericState, gcol::Int) = AtmosphericStatec(
isnothing(as.lon) ? nothing : view(as.lon, gcol:gcol),
isnothing(as.lat) ? nothing : view(as.lat, gcol:gcol),
view(as.p_lay, :, gcol),
view(as.p_lev, :, gcol),
view(as.t_lay, :, gcol),
view(as.t_lev, :, gcol),
view(as.t_sfc, gcol:gcol),
view(as.col_dry, :, gcol),
Vmrs.get_col_view(as.vmr, gcol),
isnothing(as.cld_r_eff_liq) ? nothing : view(as.cld_r_eff_liq, :, gcol),
isnothing(as.cld_r_eff_ice) ? nothing : view(as.cld_r_eff_ice, :, gcol),
isnothing(as.cld_path_liq) ? nothing : view(as.cld_path_liq, :, gcol),
isnothing(as.cld_path_ice) ? nothing : view(as.cld_path_ice, :, gcol),
isnothing(as.cld_frac) ? nothing : view(as.cld_frac, :, gcol),
isnothing(as.cld_mask_lw) ? nothing : view(as.cld_mask_lw, :, gcol),
isnothing(as.cld_mask_sw) ? nothing : view(as.cld_mask_sw, :, gcol),
as.cld_mask_type,
as.ice_rgh,
as.nlay,
as.ncol,
as.ngas,
)

end
34 changes: 27 additions & 7 deletions src/optics/BCs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module BCs
using DocStringExtensions
using Adapt

export LwBCs, SwBCs
export LwBCs, SwBCs, SwBCsc

"""
LwBCs{FT,FTA1D,FTA2DN}
Expand All @@ -29,25 +29,45 @@ Shortwave boundary conditions
$(DocStringExtensions.FIELDS)
"""
struct SwBCs{FT, FTA1D, FTA1DN, FTA2D}
"zenith angle `(ncol)`"
zenith::FTA1D
"cosine of zenith angle `(ncol)`"
cos_zenith::FTA1D
"top of atmosphere flux `(ncol)`"
toa_flux::FTA1D
"surface albedo for specular (direct) radiation `(nbnd, ncol)`"
sfc_alb_direct::FTA2D
"incident diffuse flux at top of domain `[W/m2]` `(ncol, ngpt)`"
"incident diffuse flux at top of domain `[W/m2]` `(ngpt, ncol)`"
inc_flux_diffuse::FTA1DN
"surface albedo for diffuse radiation `(nbnd, ncol)`"
sfc_alb_diffuse::FTA2D
end
SwBCs(zenith, toa_flux, sfc_alb_direct, inc_flux_diffuse, sfc_alb_diffuse) =
SwBCs{eltype(zenith), typeof(zenith), typeof(inc_flux_diffuse), typeof(sfc_alb_direct)}(
zenith,
SwBCs(cos_zenith, toa_flux, sfc_alb_direct, inc_flux_diffuse, sfc_alb_diffuse) =
SwBCs{eltype(cos_zenith), typeof(cos_zenith), typeof(inc_flux_diffuse), typeof(sfc_alb_direct)}(
cos_zenith,
toa_flux,
sfc_alb_direct,
inc_flux_diffuse,
sfc_alb_diffuse,
)
Adapt.@adapt_structure SwBCs

struct SwBCsc{FTVA1D, FTA1D, FTA1DN}
cos_zenith::FTVA1D
toa_flux::FTVA1D
sfc_alb_direct::FTA1D
inc_flux_diffuse::FTA1DN
sfc_alb_diffuse::FTA1D
end
Adapt.@adapt_structure SwBCsc

function SwBCsc(swbcs::SwBCs, gcol::Int)
inc_flux_diffuse = swbcs.inc_flux_diffuse isa Nothing ? nothing : view(swbcs.inc_flux_diffuse, :, gcol)
return SwBCsc(
view(swbcs.cos_zenith, gcol:gcol),
view(swbcs.toa_flux, gcol:gcol),
view(swbcs.sfc_alb_direct, :, gcol),
inc_flux_diffuse,
view(swbcs.sfc_alb_diffuse, :, gcol),
)
end

end
Loading