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 29, 2024
1 parent 9afd559 commit db2413e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 46 deletions.
3 changes: 0 additions & 3 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@ git-tree-sha1 = "10742e0a2e343d13bb04df379e300a83402d4106"
[[era5_cloud.download]]
sha256 = "bb51e2f2d315b487e05a8d38944d4ad937ee4a40c43b68541220c5d54425e24a"
url = "https://caltech.box.com/shared/static/b6ur4ap4vo04j09vdulem96z9fxqlgyn.gz"



4 changes: 2 additions & 2 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ dt_rad:
idealized_clouds:
help: "Use idealized clouds in radiation model [`false` (default), `true`]"
value: false
prescribed_clouds_in_radiation:
help: "Use prescribed clouds in radiation model [`false` (default), `true`]"
prescribe_clouds_in_radiation:
help: "Use prescribed clouds in radiation model. Clouds are read from ERA5 data and updated every time radiation is called. The year 2021 is used and continuously repeated. This mode only affect radiation and is only relevant for the RRTGMP mode. [`false` (default), `true`]"
value: false
insolation:
help: "Insolation used in radiation model [`idealized` (default), `timevarying`, `rcemipii`]"
Expand Down
1 change: 1 addition & 0 deletions config/model_configs/gpu_aquaplanet_dyamond.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ t_end: "8hours"
prescribe_ozone: true
aerosol_radiation: true
prescribed_aerosols: ["CB1", "CB2", "DST01", "DST02", "DST03", "DST04", "OC1", "OC2", "SO4", "SOA", "SSLT01", "SSLT02", "SSLT03", "SSLT04"]
prescribe_clouds_in_radiation: true
toml: [toml/longrun_aquaplanet.toml]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ moist: "equil"
precip_model: "1M"
rad: "allskywithclear"
aerosol_radiation: true
prescribed_clouds_in_radiation: true
prescribe_clouds_in_radiation: true
insolation: "timevarying"
non_orographic_gravity_wave: true
orographic_gravity_wave: "gfdl_restart"
Expand Down
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
26 changes: 20 additions & 6 deletions src/parameterized_tendencies/radiation/RRTMGPInterface.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module RRTMGPInterface

import ..AbstractCloudInRadiation

using RRTMGP
import RRTMGP.AtmosphericStates as AS
using ClimaCore: DataLayouts, Spaces, Fields
Expand All @@ -21,22 +23,34 @@ struct ClearSkyRadiation <: AbstractRRTMGPMode
add_isothermal_boundary_layer::Bool
aerosol_radiation::Bool
end
struct AllSkyRadiation <: AbstractRRTMGPMode
struct AllSkyRadiation{ACR <: AbstractCloudInRadiation} <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
prescribed_clouds::Bool
cloud::ACR
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."
"""
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.
"""
reset_rng_seed::Bool
end
struct AllSkyRadiationWithClearSkyDiagnostics <: AbstractRRTMGPMode
struct AllSkyRadiationWithClearSkyDiagnostics{ACR <: AbstractCloudInRadiation} <: AbstractRRTMGPMode
idealized_h2o::Bool
idealized_clouds::Bool
prescribed_clouds::Bool
cloud::ACR
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."
"""
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.
"""
reset_rng_seed::Bool
end

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
20 changes: 15 additions & 5 deletions src/solver/model_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
@assert idealized_h2o in (true, false)
idealized_clouds = parsed_args["idealized_clouds"]
@assert idealized_clouds in (true, false)
prescribed_clouds = parsed_args["prescribed_clouds_in_radiation"]
@assert prescribed_clouds in (true, false)
@assert !(idealized_clouds && prescribed_clouds)
cloud = get_cloud_in_radiation(parsed_args)
if idealized_clouds && (cloud isa PrescribedCloud)
error("idealized_clouds and prescribe_clouds_in_radiation cannot be true at the same time")
end
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 All @@ -245,6 +246,9 @@ function get_radiation_mode(parsed_args, ::Type{FT}) where {FT}
if !(radiation_name in ("allsky", "allskywithclear")) && reset_rng_seed
@warn "reset_rng_seed does not have any effect with $radiation_name radiation option"
end
if !(radiation_name in ("allsky", "allskywithclear")) && (cloud isa PrescribedCloud)
@warn "prescribe_clouds_in_radiation does not have any effect with $radiation_name radiation option"
end
return if radiation_name == "gray"
RRTMGPI.GrayRadiation(add_isothermal_boundary_layer)
elseif radiation_name == "clearsky"
Expand All @@ -257,7 +261,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 +270,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 +317,12 @@ function get_ozone(parsed_args)
return parsed_args["prescribe_ozone"] ? PrescribedOzone() : IdealizedOzone()
end

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

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

"""
AbstractCloudInRadiation
Describe how cloud properties should be set in radiation.
This is only relevant for RRTGMP.
"""
abstract type AbstractCloudInRadiation end

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

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

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

0 comments on commit db2413e

Please sign in to comment.