Skip to content

Commit

Permalink
Merge #2302
Browse files Browse the repository at this point in the history
2302: Delete old TC params struct r=trontrytel a=trontrytel

This PR:
- Deletes the old EDMF parameter struct
- Creates a new parameter struct for `TurbulenceConvectionParameters` parameters. This struct is flat and does not store any thermodynamics or microphysics parameters.
- Moves all the EDMF relevant parameters out of `ClimaAtmosParameters` and into `TurbulenceConvectionParameters`

`@szy21` - could you double check if I moved all the edmf parameters?
`@nefrathenrici` - does that look reasonable?

Co-authored-by: Anna Jaruga <ajaruga@caltech.edu>
  • Loading branch information
bors[bot] and trontrytel authored Oct 27, 2023
2 parents 2c4c00d + 19502dc commit a01efa2
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 158 deletions.
4 changes: 0 additions & 4 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# API

```@docs
ClimaAtmos.TurbulenceConvection.Parameters
```

## Initial conditions

### General
Expand Down
3 changes: 0 additions & 3 deletions src/ClimaAtmos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ include(joinpath("parameterized_tendencies", "radiation", "RRTMGPInterface.jl"))
import .RRTMGPInterface as RRTMGPI
include(joinpath("parameterized_tendencies", "radiation", "radiation.jl"))

include(joinpath("TurbulenceConvection", "TurbulenceConvection.jl"))
import .TurbulenceConvection as TC

include(joinpath("cache", "prognostic_edmf_precomputed_quantities.jl"))
include(joinpath("cache", "diagnostic_edmf_precomputed_quantities.jl"))
include(joinpath("cache", "precomputed_quantities.jl"))
Expand Down
81 changes: 0 additions & 81 deletions src/TurbulenceConvection/Parameters.jl

This file was deleted.

9 changes: 0 additions & 9 deletions src/TurbulenceConvection/TurbulenceConvection.jl

This file was deleted.

2 changes: 1 addition & 1 deletion src/cache/diagnostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ function set_diagnostic_edmf_precomputed_quantities_env_closures!(Y, p, t)
)

turbconv_params = CAP.turbconv_params(params)
c_m = TCP.tke_ed_coeff(turbconv_params)
c_m = CAP.tke_ed_coeff(turbconv_params)
@. ᶜK_u = c_m * ᶜmixing_length * sqrt(max(ᶜtke⁰, 0))
@. ᶜK_h = ᶜK_u / ᶜprandtl_nvec

Expand Down
2 changes: 1 addition & 1 deletion src/cache/prognostic_edmf_precomputed_quantities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function set_prognostic_edmf_precomputed_quantities_closures!(Y, p, t)
)

turbconv_params = CAP.turbconv_params(params)
c_m = TCP.tke_ed_coeff(turbconv_params)
c_m = CAP.tke_ed_coeff(turbconv_params)
@. ᶜK_u = c_m * ᶜmixing_length * sqrt(max(ᶜtke⁰, 0))
@. ᶜK_h = ᶜK_u / ᶜprandtl_nvec

Expand Down
1 change: 0 additions & 1 deletion src/initial_conditions/InitialConditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import ClimaCore: Fields, Geometry
import LinearAlgebra: norm_sqr

import ..Parameters as CAP
import ..TurbulenceConvection as TC
import Thermodynamics as TD
import AtmosphericProfilesLibrary as APL
import SciMLBase
Expand Down
55 changes: 46 additions & 9 deletions src/parameters/Parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,44 @@ import ClimaCore as CC
import Insolation.Parameters as IP
import Thermodynamics as TD
import CloudMicrophysics as CM
import SurfaceFluxes as SF

abstract type AbstractClimaAtmosParameters end
const ACAP = AbstractClimaAtmosParameters

abstract type AbstractTurbulenceConvectionParameters end
const ATCP = AbstractTurbulenceConvectionParameters

Base.broadcastable(param_set::ACAP) = tuple(param_set)
Base.broadcastable(param_set::ATCP) = tuple(param_set)

Base.@kwdef struct TurbulenceConvectionParameters{FT} <: ATCP
surface_area::FT
max_area::FT
min_area::FT
tke_ed_coeff::FT
tke_diss_coeff::FT
tke_surf_scale::FT
static_stab_coeff::FT
Prandtl_number_scale::FT
Prandtl_number_0::FT
Ri_crit::FT
smin_ub::FT
smin_rm::FT
min_updraft_top::FT
pressure_normalmode_buoy_coeff1::FT
pressure_normalmode_drag_coeff::FT
entr_tau::FT
entr_coeff::FT
detr_tau::FT
detr_coeff::FT
detr_buoy_coeff::FT
min_area_limiter_scale::FT
min_area_limiter_power::FT
max_area_limiter_scale::FT
max_area_limiter_power::FT
updraft_number::Int
end

Base.@kwdef struct ClimaAtmosParameters{FT, TP, RP, IP, MPP, SFP, TCP} <: ACAP
thermodynamics_params::TP
Expand All @@ -21,15 +54,6 @@ Base.@kwdef struct ClimaAtmosParameters{FT, TP, RP, IP, MPP, SFP, TCP} <: ACAP
f_plane_coriolis_frequency::FT
planet_radius::FT
astro_unit::FT
entr_tau::FT
entr_coeff::FT
detr_tau::FT
detr_coeff::FT
detr_buoy_coeff::FT
min_area_limiter_scale::FT
min_area_limiter_power::FT
max_area_limiter_scale::FT
max_area_limiter_power::FT
c_smag::FT
C_E::FT
C_H::FT
Expand All @@ -51,6 +75,15 @@ end

Base.eltype(::ClimaAtmosParameters{FT}) where {FT} = FT

# Forward TurbulenceConvection parameters
const TCPS = TurbulenceConvectionParameters
for var in fieldnames(TCPS)
@eval $var(ps::ACAP) = $var(turbconv_params(ps))
end
for fn in fieldnames(TCPS)
@eval $(fn)(ps::ATCP) = ps.$(fn)
end

# Forward Thermodynamics parameters
for var in fieldnames(TD.Parameters.ThermodynamicsParameters)
@eval $var(ps::ACAP) = TD.Parameters.$var(thermodynamics_params(ps))
Expand All @@ -63,6 +96,10 @@ end
# Forwarding CloudMicrophysics parameters
ρ_cloud_liq(ps::ACAP) = CM.Parameters.ρ_cloud_liq(microphysics_params(ps))

# Forwarding SurfaceFluxes parameters
von_karman_const(ps::ACAP) =
SF.Parameters.von_karman_const(surface_fluxes_params(ps))

# Insolation parameters
day(ps::ACAP) = IP.day(insolation_params(ps))
tot_solar_irrad(ps::ACAP) = IP.tot_solar_irrad(insolation_params(ps))
Expand Down
10 changes: 3 additions & 7 deletions src/parameters/create_parameters.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import .TurbulenceConvection as TC
import .TurbulenceConvection.Parameters as TCP
import CLIMAParameters as CP
import RRTMGP.Parameters as RP
import SurfaceFluxes as SF
Expand All @@ -9,7 +7,7 @@ import Thermodynamics as TD
import CloudMicrophysics as CM

function create_parameter_set(config::AtmosConfig)
# Helper function that creates a parameter struct. If a struct has nested
# Helper function that creates a parameter struct. If a struct has nested
# parameter structs, they must be passed to subparam_structs as a NamedTuple.
function create_parameter_struct(param_struct; subparam_structs = (;))
aliases = string.(fieldnames(param_struct))
Expand Down Expand Up @@ -63,10 +61,8 @@ function create_parameter_set(config::AtmosConfig)
SF.Parameters.SurfaceFluxesParameters;
subparam_structs = (; ufp, thermo_params),
)
turbconv_params = create_parameter_struct(
TCP.TurbulenceConvectionParameters;
subparam_structs = (; microphys_params, surf_flux_params),
)
turbconv_params =
create_parameter_struct(CAP.TurbulenceConvectionParameters;)
return create_parameter_struct(
CAP.ClimaAtmosParameters;
subparam_structs = (;
Expand Down
32 changes: 16 additions & 16 deletions src/prognostic_equations/edmfx_closures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ function surface_flux_tke(
interior_local_geometry,
surface_local_geometry,
)
c_d = TCP.tke_diss_coeff(turbconv_params)
c_m = TCP.tke_ed_coeff(turbconv_params)
k_star² = TCP.tke_surf_scale(turbconv_params)
c_d = CAP.tke_diss_coeff(turbconv_params)
c_m = CAP.tke_ed_coeff(turbconv_params)
k_star² = CAP.tke_surf_scale(turbconv_params)
speed = Geometry._norm(
CA.CT12(u_int, interior_local_geometry),
interior_local_geometry,
Expand Down Expand Up @@ -79,13 +79,13 @@ function ᶠupdraft_nh_pressure(
else
turbconv_params = CAP.turbconv_params(params)
# factor multiplier for pressure buoyancy terms (effective buoyancy is (1-α_b))
α_b = TCP.pressure_normalmode_buoy_coeff1(turbconv_params)
α_b = CAP.pressure_normalmode_buoy_coeff1(turbconv_params)
# factor multiplier for pressure drag
α_d = TCP.pressure_normalmode_drag_coeff(turbconv_params)
α_d = CAP.pressure_normalmode_drag_coeff(turbconv_params)

# Independence of aspect ratio hardcoded: α₂_asp_ratio² = FT(0)

H_up_min = TCP.min_updraft_top(turbconv_params)
H_up_min = CAP.min_updraft_top(turbconv_params)
plume_scale_height = max(updraft_top, H_up_min)

# We also used to have advection term here: α_a * w_up * div_w_up
Expand Down Expand Up @@ -115,7 +115,7 @@ function edmfx_nh_pressure_tendency!(
ᶠlg = Fields.local_geometry_field(Y.f)

turbconv_params = CAP.turbconv_params(params)
a_min = TCP.min_area(turbconv_params)
a_min = CAP.min_area(turbconv_params)

for j in 1:n

Expand Down Expand Up @@ -201,12 +201,12 @@ function mixing_length(
) where {FT}

turbconv_params = CAP.turbconv_params(params)
c_m = TCP.tke_ed_coeff(turbconv_params)
c_d = TCP.tke_diss_coeff(turbconv_params)
smin_ub = TCP.smin_ub(turbconv_params)
smin_rm = TCP.smin_rm(turbconv_params)
c_b = TCP.static_stab_coeff(turbconv_params)
vkc = TCP.von_karman_const(turbconv_params)
c_m = CAP.tke_ed_coeff(turbconv_params)
c_d = CAP.tke_diss_coeff(turbconv_params)
smin_ub = CAP.smin_ub(turbconv_params)
smin_rm = CAP.smin_rm(turbconv_params)
c_b = CAP.static_stab_coeff(turbconv_params)
vkc = CAP.von_karman_const(params)

# compute the maximum mixing length at height z
l_z = ᶜz - z_sfc
Expand Down Expand Up @@ -287,9 +287,9 @@ function turbulent_prandtl_number(
ᶜstrain_rate_norm::FT,
) where {FT}
turbconv_params = CAP.turbconv_params(params)
Ri_c = TCP.Ri_crit(turbconv_params)
ω_pr = TCP.Prandtl_number_scale(turbconv_params)
Pr_n = TCP.Prandtl_number_0(turbconv_params)
Ri_c = CAP.Ri_crit(turbconv_params)
ω_pr = CAP.Prandtl_number_scale(turbconv_params)
Pr_n = CAP.Prandtl_number_0(turbconv_params)
ᶜRi_grad = min(ᶜlinear_buoygrad / max(ᶜstrain_rate_norm, eps(FT)), Ri_c)
if obukhov_length > 0 && ᶜRi_grad > 0 #stable
# CSB (Dan Li, 2019, eq. 75), where ω_pr = ω_1 + 1 = 53.0 / 13.0
Expand Down
Loading

0 comments on commit a01efa2

Please sign in to comment.