@@ -5,7 +5,6 @@ Updates the value of `p.precomputed.sfc_conditions` based on the current state `
55`t`. This function will only update the surface conditions if the surface_setup
66is not a PrescribedSurface.
77"""
8-
98function update_surface_conditions! (Y, p, t)
109 # Need to extract the field values so that we can do
1110 # a DataLayout broadcast rather than a Field broadcast
@@ -22,17 +21,13 @@ function update_surface_conditions!(Y, p, t)
2221 surface_temp_params = CAP. surface_temp_params (params)
2322 int_ts_values = Fields. field_values (Fields. level (ᶜts, 1 ))
2423 int_u_values = Fields. field_values (Fields. level (ᶜu, 1 ))
25- int_z_values =
26- Fields. field_values (Fields. level (Fields. coordinate_field (Y. c). z, 1 ))
24+ int_z_values = Fields. field_values (Fields. level (Fields. coordinate_field (Y. c). z, 1 ))
2725 sfc_conditions_values = Fields. field_values (sfc_conditions)
2826 wrapped_sfc_setup = sfc_setup_wrapper (sfc_setup)
2927 if p. atmos. sfc_temperature isa ExternalTVColumnSST
30- evaluate! (
31- p. external_forcing. surface_inputs. ts,
32- p. external_forcing. surface_timevaryinginputs. ts,
33- t,
34- )
35- sfc_temp_var = Fields. field_values (p. external_forcing. surface_inputs. ts)
28+ (; surface_inputs, surface_timevaryinginputs) = p. external_forcing
29+ evaluate! (surface_inputs. ts, surface_timevaryinginputs. ts, t)
30+ sfc_temp_var = Fields. field_values (surface_inputs. ts)
3631 elseif p. atmos. surface_model isa SlabOceanSST
3732 sfc_temp_var = Fields. field_values (Y. sfc. T)
3833 else
7267surface_state (sfc_setup_wrapper:: SurfaceState , _, _, _) = sfc_setup_wrapper
7368
7469surface_state (
75- wrapped_sfc_setup:: F ,
76- sfc_local_geometry_values,
77- int_z_values,
78- t,
70+ wrapped_sfc_setup:: F , sfc_local_geometry_values, int_z_values, t,
7971) where {F <: Function } =
8072 wrapped_sfc_setup (sfc_local_geometry_values. coordinates, int_z_values, t)
8173
@@ -97,10 +89,7 @@ function set_dummy_surface_conditions!(p)
9789 @. sfc_conditions. ts = TD. PhaseDry_ρT (thermo_params, FT (1 ), FT (300 ))
9890 else
9991 @. sfc_conditions. ts = TD. PhaseNonEquil_ρTq (
100- thermo_params,
101- FT (1 ),
102- FT (300 ),
103- TD. PhasePartition (FT (0 )),
92+ thermo_params, FT (1 ), FT (300 ), TD. PhasePartition (FT (0 )),
10493 )
10594 @. sfc_conditions. ρ_flux_q_tot = C3 (FT (0 ))
10695 end
@@ -110,8 +99,7 @@ function set_dummy_surface_conditions!(p)
11099 c = p. scratch. ᶠtemp_scalar
111100 # elsewhere known as 𝒢
112101 sfc_local_geometry = Fields. level (Fields. local_geometry_field (c), half)
113- @. sfc_conditions. ρ_flux_uₕ =
114- tensor_from_components (0 , 0 , sfc_local_geometry)
102+ @. sfc_conditions. ρ_flux_uₕ = tensor_from_components (0 , 0 , sfc_local_geometry)
115103end
116104
117105"""
@@ -137,9 +125,7 @@ function set_surface_conditions!(p, surface_conditions, surface_ts)
137125 sfc_local_geometry =
138126 Fields. level (Fields. local_geometry_field (ᶠtemp_scalar), Fields. half)
139127 @. sfc_conditions = atmos_surface_conditions (
140- surface_conditions,
141- surface_ts,
142- sfc_local_geometry,
128+ surface_conditions, surface_ts, sfc_local_geometry,
143129 )
144130end
145131
@@ -179,8 +165,9 @@ function surface_state_to_conditions(
179165 sfc_temp_var,
180166 t,
181167) where {WSS}
182- surf_state =
183- surface_state (wrapped_sfc_setup, surface_local_geometry, interior_z, t)
168+ surf_state = surface_state (wrapped_sfc_setup, surface_local_geometry, interior_z, t)
169+ # The above expression evalutes to:
170+ # surf_state = wrapped_sfc_setup(surface_local_geometry, interior_z, t)
184171 parameterization = surf_state. parameterization
185172 (; coordinates) = surface_local_geometry
186173 FT = eltype (thermo_params)
@@ -190,13 +177,9 @@ function surface_state_to_conditions(
190177
191178 T = if isnothing (sfc_temp_var)
192179 if isnothing (surf_state. T)
193- surface_temperature (
194- atmos. sfc_temperature,
195- coordinates,
196- surface_temp_params,
197- )
180+ surface_temperature (atmos. sfc_temperature, coordinates, surface_temp_params)
198181 else
199- surf_state. T
182+ surf_state. T # T is set to the constant we specified in surface_setups.jl
200183 end
201184 else
202185 sfc_temp_var
@@ -216,40 +199,35 @@ function surface_state_to_conditions(
216199 else
217200 # Assume that the surface is water with saturated air directly
218201 # above it.
219- q_vap_sat =
220- TD. q_vap_saturation_generic (thermo_params, T, ρ, TD. Liquid ())
202+ q_vap_sat = TD. q_vap_saturation_generic (thermo_params, T, ρ, TD. Liquid ())
221203 q_vap = ifelsenothing (surf_state. q_vap, q_vap_sat)
222204 q = TD. PhasePartition (q_vap)
223205 ts = TD. PhaseNonEquil_ρTq (thermo_params, ρ, T, q)
224206 end
225207 else
226- p = surf_state. p
208+ p = surf_state. p # The value we specified in surface_setups.jl
227209 if atmos. moisture_model isa DryModel
228210 ts = TD. PhaseDry_pT (thermo_params, p, T)
229211 else
230212 q_vap = if isnothing (surf_state. q_vap)
231213 # Assume that the surface is water with saturated air directly
232214 # above it.
233215 phase = TD. Liquid ()
234- p_sat =
235- TD. saturation_vapor_pressure (thermo_params, T, phase)
216+ p_sat = TD. saturation_vapor_pressure (thermo_params, T, phase)
236217 ϵ_v =
237- TD. Parameters. R_d (thermo_params) /
238- TD. Parameters. R_v (thermo_params)
218+ TD. Parameters. R_d (thermo_params) / TD. Parameters. R_v (thermo_params)
239219 ϵ_v * p_sat / (p - p_sat * (1 - ϵ_v))
240220 else
241- surf_state. q_vap
221+ surf_state. q_vap # The value we specified in surface_setups.jl
242222 end
243- q = TD. PhasePartition (q_vap)
244- ts = TD. PhaseNonEquil_pTq (thermo_params, p, T, q)
223+ q = TD. PhasePartition (q_vap) # encodes q_tot=q_vap, q_liq=q_ice=0
224+ ts = TD. PhaseNonEquil_pTq (thermo_params, p, T, q) #
245225 end
246226 end
247227
248228 surface_values = SF. StateValues (coordinates. z, SA. SVector (u, v), ts)
249229 interior_values = SF. StateValues (
250- interior_z,
251- SA. SVector (interior_u, interior_v),
252- interior_ts,
230+ interior_z, SA. SVector (interior_u, interior_v), interior_ts,
253231 )
254232
255233 if parameterization isa ExchangeCoefficients
@@ -302,11 +280,7 @@ function surface_state_to_conditions(
302280 end
303281 if isnothing (surf_state. gustiness)
304282 buoyancy_flux = SF. compute_buoyancy_flux (
305- surface_fluxes_params,
306- shf,
307- lhf,
308- interior_ts,
309- ts,
283+ surface_fluxes_params, shf, lhf, interior_ts, ts,
310284 SF. PointValueScheme (),
311285 )
312286 # TODO : We are assuming that the average mixed layer depth is
@@ -322,24 +296,13 @@ function surface_state_to_conditions(
322296 )
323297 if isnothing (parameterization. ustar)
324298 inputs = SF. Fluxes (
325- interior_values,
326- surface_values,
327- shf,
328- lhf,
329- parameterization. z0m,
330- parameterization. z0b,
331- gustiness,
299+ interior_values, surface_values, shf, lhf,
300+ parameterization. z0m, parameterization. z0b, gustiness,
332301 )
333302 else
334303 inputs = SF. FluxesAndFrictionVelocity (
335- interior_values,
336- surface_values,
337- shf,
338- lhf,
339- parameterization. ustar,
340- parameterization. z0m,
341- parameterization. z0m,
342- gustiness,
304+ interior_values, surface_values, shf, lhf, parameterization. ustar,
305+ parameterization. z0m, parameterization. z0m, gustiness,
343306 )
344307 end
345308 end
@@ -424,23 +387,14 @@ function surface_temperature(
424387end
425388
426389"""
427- atmos_surface_conditions(
428- surface_conditions,
429- ts,
430- surface_local_geometry
431- )
390+ atmos_surface_conditions(surface_conditions, ts, surface_local_geometry)
432391
433392Adds local geometry information to the `SurfaceFluxes.SurfaceFluxConditions` struct
434393along with information about the thermodynamic state. The resulting values are the
435394ones actually used by ClimaAtmos operator boundary conditions.
436395"""
437- function atmos_surface_conditions (
438- surface_conditions,
439- ts,
440- surface_local_geometry,
441- )
442- (; ustar, L_MO, buoy_flux, ρτxz, ρτyz, shf, lhf, evaporation) =
443- surface_conditions
396+ function atmos_surface_conditions (surface_conditions, ts, surface_local_geometry)
397+ (; ustar, L_MO, buoy_flux, ρτxz, ρτyz, shf, lhf, evaporation) = surface_conditions
444398
445399 # surface normal
446400 z = surface_normal (surface_local_geometry)
@@ -456,12 +410,7 @@ function atmos_surface_conditions(
456410 obukhov_length = L_MO,
457411 buoyancy_flux = buoy_flux,
458412 # This drops the C3 component of ρ_flux_u, need to add ρ_flux_u₃
459- ρ_flux_uₕ = tensor_from_components (
460- ρτxz,
461- ρτyz,
462- surface_local_geometry,
463- z,
464- ),
413+ ρ_flux_uₕ = tensor_from_components (ρτxz, ρτyz, surface_local_geometry, z),
465414 energy_flux... ,
466415 moisture_flux... ,
467416 )
@@ -490,21 +439,12 @@ function surface_conditions_type(atmos, ::Type{FT}) where {FT}
490439 # NOTE: Technically ρ_flux_q_tot is not really needed for a dry model, but
491440 # SF always has evaporation
492441 moisture_flux_names = (:ρ_flux_q_tot ,)
493- names = (
494- :ts ,
495- :ustar ,
496- :obukhov_length ,
497- :buoyancy_flux ,
498- :ρ_flux_uₕ ,
499- energy_flux_names... ,
500- moisture_flux_names... ,
442+ names = (:ts , :ustar , :obukhov_length , :buoyancy_flux , :ρ_flux_uₕ ,
443+ energy_flux_names... , moisture_flux_names... ,
501444 )
502445 type_tuple = Tuple{
503- atmos. moisture_model isa DryModel ? TD. PhaseDry{FT} :
504- TD. PhaseNonEquil{FT},
505- FT,
506- FT,
507- FT,
446+ atmos. moisture_model isa DryModel ? TD. PhaseDry{FT} : TD. PhaseNonEquil{FT},
447+ FT, FT, FT,
508448 typeof (C3 (FT (0 )) ⊗ C12 (FT (0 ), FT (0 ))),
509449 ntuple (_ -> C3{FT}, Val (length (energy_flux_names)))... ,
510450 ntuple (_ -> C3{FT}, Val (length (moisture_flux_names)))... ,
0 commit comments