Skip to content

Commit

Permalink
Merge pull request #2524 from CliMA/zs/cloud_model
Browse files Browse the repository at this point in the history
add option for 0 or 1 cloud fraction
  • Loading branch information
szy21 authored Jan 13, 2024
2 parents 8cd2581 + b7b9316 commit 60d2053
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 8 deletions.
3 changes: 3 additions & 0 deletions config/default_configs/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ apply_limiter:
precip_model:
help: "Precipitation model [`nothing` (default), `0M`]"
value: ~
cloud_model:
help: "Cloud model [`grid_scale`, `quadrature` (default)]"
value: "quadrature"
perf_mode:
help: "A flag for analyzing performance [`PerfStandard` (default), `PerfExperimental`]"
value: "PerfStandard"
Expand Down
1 change: 1 addition & 0 deletions config/longrun_configs/longrun_aquaplanet_dyamond.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dz_bottom: 30.0
dz_top: 3000.0
moist: "equil"
precip_model: "0M"
cloud_model: "grid_scale"
rad: "allskywithclear"
idealized_insolation: false
dt_rad: "1hours"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vert_diff: "true"
idealized_insolation: false
z_max: 45000.0
precip_model: "0M"
cloud_model: "grid_scale"
regression_test: true
surface_temperature: "ZonallyAsymmetric"
job_id: "sphere_aquaplanet_rhoe_equilmoist_allsky_gw_raw_zonallyasymmetric"
Expand Down
24 changes: 22 additions & 2 deletions src/cache/cloud_fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,35 @@ end
"""
Compute the grid scale cloud fraction based on sub-grid scale properties
"""
function set_cloud_fraction!(Y, p, ::DryModel)
function set_cloud_fraction!(Y, p, ::DryModel, _)
(; ᶜmixing_length) = p.precomputed
(; turbconv_model) = p.atmos
if isnothing(turbconv_model)
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
end
@. p.precomputed.ᶜcloud_fraction = 0
end
function set_cloud_fraction!(Y, p, ::Union{EquilMoistModel, NonEquilMoistModel})
function set_cloud_fraction!(
Y,
p,
::Union{EquilMoistModel, NonEquilMoistModel},
::GridScaleCloud,
)
(; params) = p
(; turbconv_model) = p.atmos
(; ᶜts, ᶜmixing_length, ᶜcloud_fraction) = p.precomputed
thermo_params = CAP.thermodynamics_params(params)
if isnothing(turbconv_model)
compute_gm_mixing_length!(ᶜmixing_length, Y, p)
end
@. ᶜcloud_fraction = ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0)
end
function set_cloud_fraction!(
Y,
p,
::Union{EquilMoistModel, NonEquilMoistModel},
::QuadratureCloud,
)
(; SG_quad, params) = p

FT = eltype(params)
Expand Down
19 changes: 13 additions & 6 deletions src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ end
function cloud_fraction_model_callback!(integrator)
Y = integrator.u
p = integrator.p
set_cloud_fraction!(Y, p, p.atmos.moisture_model)
set_cloud_fraction!(Y, p, p.atmos.moisture_model, p.atmos.cloud_model)
end

NVTX.@annotate function rrtmgp_model_callback!(integrator)
Y = integrator.u
p = integrator.p
t = integrator.t

(; ᶜts, sfc_conditions) = p.precomputed
(; ᶜts, ᶜcloud_fraction, sfc_conditions) = p.precomputed
(; params) = p
(; idealized_insolation, idealized_h2o, idealized_clouds) = p.radiation
(; insolation_tuple, ᶠradiation_flux, radiation_model) = p.radiation
Expand Down Expand Up @@ -164,12 +164,19 @@ NVTX.@annotate function rrtmgp_model_callback!(integrator)
radiation_model.center_cloud_fraction,
axes(Y.c),
)
# multiply by 1000 to convert from kg/m^2 to g/m^2
# RRTMGP needs lwp and iwp in g/m^2
kg_to_g_factor = 1000
@. ᶜlwp =
1000 * Y.c.ρ * TD.liquid_specific_humidity(thermo_params, ᶜts) * ᶜΔz
kg_to_g_factor *
Y.c.ρ *
TD.liquid_specific_humidity(thermo_params, ᶜts) *
ᶜΔz / max(ᶜcloud_fraction, eps(FT))
@. ᶜiwp =
1000 * Y.c.ρ * TD.ice_specific_humidity(thermo_params, ᶜts) * ᶜΔz
@. ᶜfrac = ifelse(TD.has_condensate(thermo_params, ᶜts), 1, 0 * ᶜΔz)
kg_to_g_factor *
Y.c.ρ *
TD.ice_specific_humidity(thermo_params, ᶜts) *
ᶜΔz / max(ᶜcloud_fraction, eps(FT))
@. ᶜfrac = ᶜcloud_fraction
end

RRTMGPI.update_fluxes!(radiation_model)
Expand Down
11 changes: 11 additions & 0 deletions src/solver/model_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ function get_precipitation_model(parsed_args)
end
end

function get_cloud_model(parsed_args)
cloud_model = parsed_args["cloud_model"]
return if cloud_model == "grid_scale"
GridScaleCloud()
elseif cloud_model == "quadrature"
QuadratureCloud()
else
error("Invalid cloud_model $(cloud_model)")
end
end

function get_forcing_type(parsed_args)
forcing = parsed_args["forcing"]
@assert forcing in (nothing, "held_suarez")
Expand Down
2 changes: 2 additions & 0 deletions src/solver/type_getters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function get_atmos(config::AtmosConfig, params)
FT = eltype(config)
moisture_model = get_moisture_model(parsed_args)
precip_model = get_precipitation_model(parsed_args)
cloud_model = get_cloud_model(parsed_args)
radiation_mode = get_radiation_mode(parsed_args, FT)
forcing_type = get_forcing_type(parsed_args)

Expand Down Expand Up @@ -57,6 +58,7 @@ function get_atmos(config::AtmosConfig, params)
edmfx_sgs_diffusive_flux,
edmfx_nh_pressure,
precip_model,
cloud_model,
forcing_type,
turbconv_model = get_turbconv_model(FT, parsed_args, turbconv_params),
non_orographic_gravity_wave = get_non_orographic_gravity_wave_model(
Expand Down
6 changes: 6 additions & 0 deletions src/solver/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ struct NoPrecipitation <: AbstractPrecipitationModel end
struct Microphysics0Moment <: AbstractPrecipitationModel end
struct Microphysics1Moment <: AbstractPrecipitationModel end

abstract type AbstractCloudModel end
struct GridScaleCloud <: AbstractCloudModel end
struct QuadratureCloud <: AbstractCloudModel end

abstract type AbstractModelConfig end
struct SingleColumnModel <: AbstractModelConfig end
struct SphericalModel <: AbstractModelConfig end
Expand Down Expand Up @@ -343,6 +347,7 @@ Base.@kwdef struct AtmosModel{
PEM,
MM,
PM,
CM,
F,
S,
RM,
Expand Down Expand Up @@ -370,6 +375,7 @@ Base.@kwdef struct AtmosModel{
perf_mode::PEM = nothing
moisture_model::MM = nothing
precip_model::PM = nothing
cloud_model::CM = nothing
forcing_type::F = nothing
subsidence::S = nothing
radiation_mode::RM = nothing
Expand Down

0 comments on commit 60d2053

Please sign in to comment.