@@ -129,6 +129,46 @@ function build_cache(
129129 sfc_local_geometry =
130130 Fields. level (Fields. local_geometry_field (Y. f), Fields. half)
131131
132+ # Reference enthalpy for hyperdiffusion computation
133+ ᶜz = Fields. coordinate_field (Y. c). z
134+ T_ref = similar (ᶜz)
135+ p_ref = similar (ᶜz)
136+ q_tot_ref = similar (ᶜz)
137+ cv_m = similar (ᶜz)
138+ R_m = similar (ᶜz)
139+ thermo_params = CAP. thermodynamics_params (params)
140+ decay_scale_height = FT (8000 )
141+
142+ # Reference State
143+ temp_profile = TD. TemperatureProfiles. DecayingTemperatureProfile {FT} (
144+ thermo_params,
145+ FT (300 ), # surface temperature
146+ FT (220 ), # top temperature
147+ decay_scale_height, # decay height scale
148+ )
149+
150+ rel_hum_ref =
151+ atmos. moisture_model isa DryModel ? FT (0 ) :
152+ @. FT (0.5 ) * exp (- ᶜz / decay_scale_height)
153+
154+ T_0 = CAP. T_0 (params)
155+ grav = CAP. grav (params)
156+ @. T_ref = first (temp_profile (thermo_params, ᶜz))
157+ @. p_ref = last (temp_profile (thermo_params, ᶜz))
158+ @. q_tot_ref =
159+ TD. q_vap_from_RH_liquid (thermo_params, p_ref, T_ref, rel_hum_ref)
160+ @. cv_m = TD. cv_m (thermo_params, TD. PhasePartition (q_tot_ref, FT (0 ), FT (0 )))
161+ @. R_m = TD. gas_constant_air (
162+ thermo_params,
163+ TD. PhasePartition (q_tot_ref, FT (0 ), FT (0 )),
164+ )
165+
166+ ᶜh_ref = @. TD. total_specific_enthalpy (
167+ cv_m * (T_ref - T_0) + grav * ᶜz,
168+ R_m,
169+ T_ref,
170+ )
171+
132172 core = (
133173 ᶜΦ,
134174 ᶠgradᵥ_ᶜΦ = ᶠgradᵥ .(ᶜΦ),
@@ -139,6 +179,7 @@ function build_cache(
139179 surface_ct3_unit = CT3 .(
140180 unit_basis_vector_data .(CT3, sfc_local_geometry)
141181 ),
182+ ᶜh_ref,
142183 )
143184 external_forcing = external_forcing_cache (Y, atmos, params, start_date)
144185 sfc_setup = surface_setup (params)
0 commit comments