From 5f99b9e43147bb5e15b20a121d7d44a0abc7cf7b Mon Sep 17 00:00:00 2001 From: Gabriele Bozzola Date: Wed, 18 Sep 2024 16:51:52 -0700 Subject: [PATCH] Add insolation_tuple only when needed `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. --- src/cache/cache.jl | 8 ++++++- .../radiation/radiation.jl | 21 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/cache/cache.jl b/src/cache/cache.jl index 3217b926761..155344dae4f 100644 --- a/src/cache/cache.jl +++ b/src/cache/cache.jl @@ -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) diff --git a/src/parameterized_tendencies/radiation/radiation.jl b/src/parameterized_tendencies/radiation/radiation.jl index aa47ffbd610..b8593e087ec 100644 --- a/src/parameterized_tendencies/radiation/radiation.jl +++ b/src/parameterized_tendencies/radiation/radiation.jl @@ -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, @@ -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