diff --git a/examples/hybrid/driver.jl b/examples/hybrid/driver.jl index 6d7ea394794..14a96e0ddae 100644 --- a/examples/hybrid/driver.jl +++ b/examples/hybrid/driver.jl @@ -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 diff --git a/src/cache/cloud_fraction.jl b/src/cache/cloud_fraction.jl index 57794507935..b455927aba6 100644 --- a/src/cache/cloud_fraction.jl +++ b/src/cache/cloud_fraction.jl @@ -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, ᶜ∇Φ, ᶜ∇Ψ) @@ -15,8 +15,8 @@ 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 @@ -24,7 +24,7 @@ function set_cloud_fraction!(Y, p, ::Union{EquilMoistModel, NonEquilMoistModel}) 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 @@ -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ₜ, @@ -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( diff --git a/src/cache/precomputed_quantities.jl b/src/cache/precomputed_quantities.jl index f81044a5ca9..2d1aa402895 100644 --- a/src/cache/precomputed_quantities.jl +++ b/src/cache/precomputed_quantities.jl @@ -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 ? (; diff --git a/src/callbacks/callbacks.jl b/src/callbacks/callbacks.jl index 9804c75cb97..b27450e6651 100644 --- a/src/callbacks/callbacks.jl +++ b/src/callbacks/callbacks.jl @@ -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 = (; diff --git a/src/diagnostics/core_diagnostics.jl b/src/diagnostics/core_diagnostics.jl index 007b74da34b..f038e5953e7 100644 --- a/src/diagnostics/core_diagnostics.jl +++ b/src/diagnostics/core_diagnostics.jl @@ -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)