Skip to content

Commit

Permalink
Add insolation_tuple only when needed
Browse files Browse the repository at this point in the history
`insolation_tuple` was unconditionally added to the cache, even it is
used only by a specific type of insolation. This change ensures that the
value is not added when it not going to be used.
  • Loading branch information
Sbozzolo committed Sep 18, 2024
1 parent 3395e5a commit 5f99b9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/cache/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ function build_cache(

radiation_args =
atmos.radiation_mode isa RRTMGPI.AbstractRRTMGPMode ?
(params, precomputed.ᶜp, prescribe_ozone, aerosol_names) : ()
(
params,
precomputed.ᶜp,
prescribe_ozone,
aerosol_names,
atmos.insolation,
) : ()

hyperdiff = hyperdiffusion_cache(Y, atmos)
rayleigh_sponge = rayleigh_sponge_cache(Y, atmos)
Expand Down
21 changes: 16 additions & 5 deletions src/parameterized_tendencies/radiation/radiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function radiation_model_cache(
params,
ᶜp, # Used for ozone
prescribe_ozone,
aerosol_names;
aerosol_names,
insolation_mode;
interpolation = RRTMGPI.BestFit(),
bottom_extrapolation = RRTMGPI.SameAsInterpolation(),
data_loader = rrtmgp_data_loader,
Expand Down Expand Up @@ -253,11 +254,21 @@ function radiation_model_cache(
kwargs...,
)
end
return merge(
(;
orbital_data,
rrtmgp_model,
ᶠradiation_flux = similar(Y.f, Geometry.WVector{FT}),
),
insolation_cache(insolation_mode, Y),
)
end

insolation_cache(_, _) = (;)
function insolation_cache(::TimeVaryingInsolation, Y)
FT = Spaces.undertype(Y.c)
return (;
orbital_data,
rrtmgp_model,
insolation_tuple = similar(Spaces.level(Y.c, 1), Tuple{FT, FT, FT}),
ᶠradiation_flux = similar(Y.f, Geometry.WVector{FT}),
insolation_tuple = similar(Spaces.level(Y.c, 1), Tuple{FT, FT, FT})
)
end

Expand Down

0 comments on commit 5f99b9e

Please sign in to comment.