Skip to content

Commit

Permalink
more review comments, add CF to new diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
trontrytel committed Dec 5, 2023
1 parent a21141f commit 9e376b0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
6 changes: 3 additions & 3 deletions examples/hybrid/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ if config.parsed_args["check_precipitation"]
)

# cloud fraction diagnostics
@assert !any(isnan, sol.prob.p.precomputed.cloud_fraction[colidx])
@test minimum(sol.prob.p.precomputed.cloud_fraction[colidx]) >= FT(0)
@test maximum(sol.prob.p.precomputed.cloud_fraction[colidx]) <= FT(1)
@assert !any(isnan, sol.prob.p.precomputed.ᶜcloud_fraction[colidx])
@test minimum(sol.prob.p.precomputed.ᶜcloud_fraction[colidx]) >= FT(0)
@test maximum(sol.prob.p.precomputed.ᶜcloud_fraction[colidx]) <= FT(1)
end
end
12 changes: 6 additions & 6 deletions src/cache/cloud_fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ClimaCore.RecursiveApply: rzero, ⊞, ⊠

# TODO: write a test with scalars that are linear with z
"""
Diagnose horizntal covariances based on vertical gradients
Diagnose horizontal covariances based on vertical gradients
(i.e. taking turbulence production as the only term)
"""
function covariance_from_grad(coeff, ᶜmixing_length, ᶜ∇Φ, ᶜ∇Ψ)
Expand All @@ -15,16 +15,16 @@ end
"""
function set_cloud_fraction!(Y, p, ::DryModel)
FT = eltype(Y)
(; cloud_fraction) = p.precomputed
@. cloud_fraction = FT(0)
(; ᶜcloud_fraction) = p.precomputed
@. ᶜcloud_fraction = FT(0)
end
function set_cloud_fraction!(Y, p, ::Union{EquilMoistModel, NonEquilMoistModel})
(; SG_quad, params) = p

FT = eltype(params)
thermo_params = CAP.thermodynamics_params(params)
ᶜdz = Fields.Δz_field(axes(Y.c))
(; ᶜts, ᶜp, cloud_fraction) = p.precomputed
(; ᶜts, ᶜp, ᶜcloud_fraction) = p.precomputed

ᶜqₜ = p.scratch.ᶜtemp_scalar
ᶜθ = p.scratch.ᶜtemp_scalar_2
Expand All @@ -33,7 +33,7 @@ function set_cloud_fraction!(Y, p, ::Union{EquilMoistModel, NonEquilMoistModel})

coeff = FT(2.1) # TODO - move to parameters

@. cloud_fraction = quad_loop(
@. ᶜcloud_fraction = quad_loop(
SG_quad,
ᶜp,
ᶜqₜ,
Expand Down Expand Up @@ -70,7 +70,7 @@ where:
- qt′qt′, θl′θl′, θl′qt′ are the (co)variances of q_tot and liquid ice potential temperature
- thermo params are the thermodynamics parameters
The function trnasforms and imposes additional limits on the quadrature points.
The function transforms and imposes additional limits on the quadrature points.
It returns cloud fraction computed as a sum over quadrature points.
"""
function quad_loop(
Expand Down
2 changes: 1 addition & 1 deletion src/cache/precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function precomputed_quantities(Y, atmos)
ᶜh_tot = similar(Y.c, FT),
sfc_conditions = Fields.Field(SCT, Spaces.level(axes(Y.f), half)),
)
cloud_diagnostics = (; cloud_fraction = similar(Y.c, FT),)
cloud_diagnostics = (; ᶜcloud_fraction = similar(Y.c, FT),)
advective_sgs_quantities =
atmos.turbconv_model isa PrognosticEDMFX ?
(;
Expand Down
2 changes: 1 addition & 1 deletion src/callbacks/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function common_diagnostics(p, ᶜu, ᶜts)
specific_enthalpy = TD.specific_enthalpy.(thermo_params, ᶜts),
buoyancy = CAP.grav(p.params) .* (p.core.ᶜρ_ref .- ᶜρ) ./ ᶜρ,
density = TD.air_density.(thermo_params, ᶜts),
cloud_fraction_gm = p.precomputed.cloud_fraction,
cloud_fraction_gm = p.precomputed.ᶜcloud_fraction,
)
if !(p.atmos.moisture_model isa DryModel)
diagnostics = (;
Expand Down
16 changes: 16 additions & 0 deletions src/diagnostics/core_diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ add_diagnostic_variable!(
end,
)

###
# Cloud fraction (3d)
###
add_diagnostic_variable!(
short_name = "cf",
long_name = "Cloud fraction",
units = "%",
compute! = (out, state, cache, time) -> begin
FT = eltype(cache.precomputed.ᶜcloud_fraction)
if isnothing(out)
return copy(cache.precomputed.ᶜcloud_fraction) .* FT(100)
else
out .= cache.precomputed.ᶜcloud_fraction .* FT(100)
end
end,
)

###
# Relative humidity (3d)
Expand Down

0 comments on commit 9e376b0

Please sign in to comment.