Thermodynamics.jl
Thermodynamics.jl copied to clipboard
Define `get_expensive_vars` or something?
There are some ClimaAtmos functions that call several functions, resulting in several expensive calls. We could either cache the expensive variables in the thermo state, or we could define a getter that efficiently computes all of the variables and returns a struct where it's cached. One advantage of this is that it's use is optional.
For example:
@. ᶜlinear_buoygrad = buoyancy_gradients(
params,
moisture_model,
EnvBuoyGrad(
BuoyGradMean(),
TD.air_temperature(thermo_params, ᶜts⁰), # t_sat
TD.vapor_specific_humidity(thermo_params, ᶜts⁰), # qv_sat
ᶜspecific⁰.q_tot, # qt_sat
TD.dry_pottemp(thermo_params, ᶜts⁰), # θ_sat
TD.liquid_ice_pottemp(thermo_params, ᶜts⁰), # θ_liq_ice_sat
projected_vector_data(
C3,
ᶜgradᵥ(ᶠinterp(TD.virtual_pottemp(thermo_params, ᶜts⁰))),
ᶜlg,
), # ∂θv∂z_unsat
projected_vector_data(C3, ᶜgradᵥ(ᶠinterp(ᶜspecific⁰.q_tot)), ᶜlg), # ∂qt∂z_sat
projected_vector_data(
C3,
ᶜgradᵥ(ᶠinterp(TD.liquid_ice_pottemp(thermo_params, ᶜts⁰))),
ᶜlg,
), # ∂θl∂z_sat
ᶜp, # p
ifelse(TD.has_condensate(thermo_params, ᶜts⁰), 1, 0), # en_cld_frac
ᶜρ⁰, # ρ
),
)
is a massive kernel:
Hyperdiffusion (on the left) is shown for scale. It's called 3 times and each one is 10% of root.
Local notes:
@. ᶜlinear_buoygrad = buoyancy_gradients(
BuoyGradMean(),
thermo_params,
moisture_model,
EnvBuoyGradVars(
ᶜts,
pd(ᶜgradᵥ(ᶠts), ᶜlg,), # ∂θv∂z_unsat
pd(ᶜgradᵥ(TD.total_specific_humidity(thermo_params, ᶠts)), ᶜlg), # ∂qt∂z_sat
pd(ᶜgradᵥ(TD.liquid_ice_pottemp(thermo_params, ᶠts)), ᶜlg,), # ∂θl∂z_sat
),
)
if atmos.moisture_model isa DryModel
@. ᶠts = TD.PhaseDry_ρe(
ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
)
elseif atmos.moisture_model isa EquilMoistModel
@. ᶠts = TD.PhaseEquil_ρeq(
ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
ᶠinterp(TD.total_specific_humidity(thermo_params, ᶜts)),
3,
eltype(thermo_params)(0.003),
)
else
@assert atmos.moisture_model isa NonEquilMoistModel
@. ᶠts = TD.PhaseNonEquil_ρeq(
ᶠinterp(TD.air_temperature(thermo_params, ᶜts)),
ᶠinterp(TD.internal_energy(thermo_params, ᶜts)),
ᶠinterp(TD.PhasePartition(thermo_params, ᶜts)),
)
end