Skip to content

Commit

Permalink
turn cloud into a type
Browse files Browse the repository at this point in the history
  • Loading branch information
szy21 committed Oct 28, 2024
1 parent 9afd559 commit b77939d
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 33 deletions.
44 changes: 19 additions & 25 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,25 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
)
# RRTMGP needs lwp and iwp in g/m^2
kg_to_g_factor = 1000
if radiation_mode.prescribed_clouds
@. ᶜlwp =
kg_to_g_factor *
Y.c.ρ *
p.radiation.prescribed_clouds_field.clwc *
ᶜΔz / max(p.radiation.prescribed_clouds_field.cc, eps(FT))
@. ᶜiwp =
kg_to_g_factor *
Y.c.ρ *
p.radiation.prescribed_clouds_field.ciwc *
ᶜΔz / max(p.radiation.prescribed_clouds_field.cc, eps(FT))
@. ᶜfrac = p.radiation.prescribed_clouds_field.cc
else
@. ᶜlwp =
kg_to_g_factor *
Y.c.ρ *
cloud_diagnostics_tuple.q_liq *
ᶜΔz / max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜiwp =
kg_to_g_factor *
Y.c.ρ *
cloud_diagnostics_tuple.q_ice *
ᶜΔz / max(cloud_diagnostics_tuple.cf, eps(FT))
@. ᶜfrac = cloud_diagnostics_tuple.cf
end
cloud_liquid_water_content =
radiation_mode.cloud isa PrescribedCloud ?
p.radiation.prescribed_clouds_field.clwc :
cloud_diagnostics_tuple.q_liq
cloud_ice_water_content =
radiation_mode.cloud isa PrescribedCloud ?
p.radiation.prescribed_clouds_field.ciwc :
cloud_diagnostics_tuple.q_ice
cloud_fraction =
radiation_mode.cloud isa PrescribedCloud ?
p.radiation.prescribed_clouds_field.cc :
cloud_diagnostics_tuple.cf
@. ᶜlwp =
kg_to_g_factor * Y.c.ρ * cloud_liquid_water_content * ᶜΔz /
max(cloud_fraction, eps(FT))
@. ᶜiwp =
kg_to_g_factor * Y.c.ρ * cloud_ice_water_content * ᶜΔz /
max(cloud_fraction, eps(FT))
@. ᶜfrac = cloud_fraction
end
end

Expand Down
6 changes: 4 additions & 2 deletions src/parameterized_tendencies/radiation/RRTMGPInterface.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module RRTMGPInterface

import ..AbstractCloud

using RRTMGP
import RRTMGP.AtmosphericStates as AS
using ClimaCore: DataLayouts, Spaces, Fields
Expand All @@ -24,7 +26,7 @@ end
struct AllSkyRadiation <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
prescribed_clouds::Bool
cloud::AbstractCloud
add_isothermal_boundary_layer::Bool
aerosol_radiation::Bool
"Reset the RNG seed before calling RRTGMP to a known value (the timestep number). When modeling cloud optics, RRTGMP uses a random number generator. Resetting the seed every time RRTGMP is called to a deterministic value ensures that the simulation is fully reproducible and can be restarted in a reproducible way. Disable this option when running production runs."
Expand All @@ -33,7 +35,7 @@ end
struct AllSkyRadiationWithClearSkyDiagnostics <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
prescribed_clouds::Bool
cloud::AbstractCloud
add_isothermal_boundary_layer::Bool
aerosol_radiation::Bool
"Reset the RNG seed before calling RRTGMP to a known value (the timestep number). When modeling cloud optics, RRTGMP uses a random number generator. Resetting the seed every time RRTGMP is called to a deterministic value ensures that the simulation is fully reproducible and can be restarted in a reproducible way. Disable this option when running production runs."
Expand Down
7 changes: 3 additions & 4 deletions src/parameterized_tendencies/radiation/radiation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ function radiation_model_cache(
cloud_cache = (;)
if (radiation_mode isa RRTMGPI.AllSkyRadiation) ||
(radiation_mode isa RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics)
if radiation_mode.prescribed_clouds
cloud_cache = get_cloud_cache(Y, start_date)
end
cloud_cache = get_cloud_cache(radiation_mode.cloud, Y, start_date)
end
return merge(
(; rrtmgp_model, ᶠradiation_flux = similar(Y.f, Geometry.WVector{FT})),
Expand All @@ -275,7 +273,8 @@ function radiation_model_cache(
)
end

function get_cloud_cache(Y, start_date)
get_cloud_cache(_, _, _) = (;)
function get_cloud_cache(::PrescribedCloud, Y, start_date)
target_space = axes(Y.c)
prescribed_cloud_names = ("cc", "clwc", "ciwc")
prescribed_cloud_names_as_symbols = Symbol.(prescribed_cloud_names)
Expand Down
11 changes: 9 additions & 2 deletions src/solver/model_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
prescribed_clouds = parsed_args["prescribed_clouds_in_radiation"]
@assert prescribed_clouds in (true, false)
@assert !(idealized_clouds && prescribed_clouds)
cloud = get_cloud(parsed_args)
add_isothermal_boundary_layer = parsed_args["add_isothermal_boundary_layer"]
@assert add_isothermal_boundary_layer in (true, false)
aerosol_radiation = parsed_args["aerosol_radiation"]
Expand Down Expand Up @@ -257,7 +258,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
RRTMGPI.AllSkyRadiation(
idealized_h2o,
idealized_clouds,
prescribed_clouds,
cloud,
add_isothermal_boundary_layer,
aerosol_radiation,
reset_rng_seed,
Expand All @@ -266,7 +267,7 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
RRTMGPI.AllSkyRadiationWithClearSkyDiagnostics(
idealized_h2o,
idealized_clouds,
prescribed_clouds,
cloud,
add_isothermal_boundary_layer,
aerosol_radiation,
reset_rng_seed,
Expand Down Expand Up @@ -313,6 +314,12 @@ function get_ozone(parsed_args)
return parsed_args["prescribe_ozone"] ? PrescribedOzone() : IdealizedOzone()
end

function get_cloud(parsed_args)
isnothing(parsed_args["prescribed_clouds_in_radiation"]) && return nothing
return parsed_args["prescribed_clouds_in_radiation"] ? PrescribedCloud() :
InteractiveCloud()
end

function get_forcing_type(parsed_args)
forcing = parsed_args["forcing"]
@assert forcing in (nothing, "held_suarez")
Expand Down
20 changes: 20 additions & 0 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ Refer to ClimaArtifacts for more information on how to obtain the artifact.
"""
struct PrescribedOzone <: AbstractOzone end

"""
AbstractCloud
Describe how cloud properties should be set in radiation.
"""
abstract type AbstractCloud end

"""
InteractiveCloud
Use cloud properties computed in the model
"""
struct InteractiveCloud <: AbstractCloud end

"""
PrescribedCloud
Use monthly-average cloud properties from ERA5.
"""
struct PrescribedCloud <: AbstractCloud end

abstract type AbstractSurfaceTemperature end
struct PrescribedSurfaceTemperature <: AbstractSurfaceTemperature end
Expand Down

0 comments on commit b77939d

Please sign in to comment.