Skip to content

Commit 260b427

Browse files
authored
preallocate q_sfc for snow (#978)
1 parent 8ac0ac3 commit 260b427

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

src/standalone/Snow/Snow.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ density_prog_names(::AbstractDensityModel) = ()
246246
auxiliary_vars(::SnowModel)
247247
248248
Returns the auxiliary variable names for the snow model. These
249-
include the mass fraction in liquid water (`q_l`, unitless),
249+
include the specific humidity at the surface of the snow `(`q_sfc`, unitless),
250+
the mass fraction in liquid water (`q_l`, unitless),
250251
the thermal conductivity (`κ`, W/m/K),
251252
the bulk temperature (`T`, K), the surface temperature (`T_sfc`, K), the bulk snow density (`ρ_snow`, kg/m^3)
252253
the SHF, LHF, and vapor flux (`turbulent_fluxes.shf`, etc),
@@ -259,6 +260,7 @@ clipped values are what are actually applied as boundary fluxes, and are stored
259260
`applied_` fluxes.
260261
"""
261262
auxiliary_vars(::SnowModel) = (
263+
:q_sfc,
262264
:q_l,
263265
,
264266
:T,
@@ -281,6 +283,7 @@ auxiliary_types(::SnowModel{FT}) where {FT} = (
281283
FT,
282284
FT,
283285
FT,
286+
FT,
284287
NamedTuple{(:lhf, :shf, :vapor_flux, :r_ae), Tuple{FT, FT, FT, FT}},
285288
FT,
286289
FT,
@@ -307,6 +310,7 @@ auxiliary_domain_names(::SnowModel) = (
307310
:surface,
308311
:surface,
309312
:surface,
313+
:surface,
310314
)
311315

312316

@@ -328,6 +332,13 @@ function ClimaLand.make_update_aux(model::SnowModel{FT}) where {FT}
328332

329333
@. p.snow.T_sfc = snow_surface_temperature(p.snow.T)
330334

335+
@. p.snow.q_sfc = snow_surface_specific_humidity(
336+
p.snow.T_sfc,
337+
p.snow.q_l,
338+
p.drivers.thermal_state,
339+
parameters,
340+
)
341+
331342
p.snow.water_runoff .=
332343
compute_water_runoff.(
333344
Y.snow.S,

src/standalone/Snow/snow_parameterizations.jl

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,46 @@ end
9191

9292

9393
"""
94-
ClimaLand.surface_specific_humidity(model::SnowModel, Y, p)
94+
ClimaLand.surface_specific_humidity(model::SnowModel, Y, p, _...)
9595
96-
Computes and returns the specific humidity over snow as a weighted
96+
Returns the precomputed specific humidity over snow as a weighted
9797
fraction of the saturated specific humidity over liquid and frozen
9898
water.
9999
100-
This function allocates.
101100
"""
102-
function ClimaLand.surface_specific_humidity(
103-
model::SnowModel,
104-
Y,
105-
p,
106-
T_sfc,
107-
ρ_sfc,
108-
)
109-
thermo_params =
110-
LP.thermodynamic_parameters(model.parameters.earth_param_set)
111-
qsat_over_ice =
112-
Thermodynamics.q_vap_saturation_generic.(
113-
Ref(thermo_params),
114-
T_sfc,
115-
ρ_sfc,
116-
Ref(Thermodynamics.Ice()),
117-
)
118-
qsat_over_liq =
119-
Thermodynamics.q_vap_saturation_generic.(
120-
Ref(thermo_params),
121-
T_sfc,
122-
ρ_sfc,
123-
Ref(Thermodynamics.Liquid()),
124-
)
125-
q_l = p.snow.q_l
126-
return @. qsat_over_ice * (1 - q_l) + q_l * (qsat_over_liq)
101+
function ClimaLand.surface_specific_humidity(model::SnowModel, Y, p, _...)
102+
return p.snow.q_sfc
103+
end
104+
105+
"""
106+
snow_surface_specific_humidity(T_sfc::FT, q_l::FT, atmos_ts, parameters) where {FT}
107+
108+
Computes the snow surface specific humidity at a point, assuming a weighted averaged (by mass fraction)
109+
of the saturated specific humidity over ice and over liquid, at temperature T_sfc.
110+
111+
This approximates the surface air density using an adiabatic approximation and the current atmospheric state.
112+
"""
113+
function snow_surface_specific_humidity(
114+
T_sfc::FT,
115+
q_l::FT,
116+
atmos_ts,
117+
parameters,
118+
) where {FT}
119+
thermo_params = LP.thermodynamic_parameters(parameters.earth_param_set)
120+
ρ_sfc = compute_ρ_sfc(thermo_params, atmos_ts, T_sfc)
121+
qsat_over_ice = Thermodynamics.q_vap_saturation_generic(
122+
thermo_params,
123+
T_sfc,
124+
ρ_sfc,
125+
Thermodynamics.Ice(),
126+
)
127+
qsat_over_liq = Thermodynamics.q_vap_saturation_generic(
128+
thermo_params,
129+
T_sfc,
130+
ρ_sfc,
131+
Thermodynamics.Liquid(),
132+
)
133+
return qsat_over_ice * (1 - q_l) + q_l * (qsat_over_liq)
127134
end
128135

129136
"""

test/standalone/Snow/snow.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import ClimaLand.Parameters as LP
5353
Y, p, coords = ClimaLand.initialize(model)
5454
@test (Y.snow |> propertynames) == (:S, :U)
5555
@test (p.snow |> propertynames) == (
56+
:q_sfc,
5657
:q_l,
5758
,
5859
:T,
@@ -124,6 +125,7 @@ import ClimaLand.Parameters as LP
124125
ρ_sfc,
125126
Ref(Thermodynamics.Ice()),
126127
)
128+
@test p.snow.q_sfc q_sfc
127129
turb_fluxes_copy = copy(p.snow.turbulent_fluxes)
128130
ClimaLand.turbulent_fluxes!(
129131
turb_fluxes_copy,

0 commit comments

Comments
 (0)