@@ -46,7 +46,7 @@ This function is dispatched based on the type of the vertical diffusion model
4646 for scalars. Zero-flux boundary conditions are explicitly applied.
4747 - **Note on mass conservation for `q_tot` diffusion**: The current implementation
4848 also modifies the tendency of total moist air density `Yₜ.c.ρ` based on the
49- diffusion tendency of total specific humidity `ρq_tot`:
49+ diffusion tendency of total specific humidity `ρq_tot`:
5050 `Yₜ.c.ρ -= ᶜρχₜ_diffusion_for_q_tot`.
5151
5252Arguments for all methods:
@@ -58,7 +58,7 @@ Arguments for all methods:
5858- `t`: Current simulation time (not directly used in diffusion calculations).
5959- `vert_diff_model` (for dispatched methods): The specific vertical diffusion model instance.
6060
61- Modifies components of tendency vector `Yₜ.c` (e.g., `Yₜ.c.uₕ`, `Yₜ.c.ρe_tot`, `Yₜ.c.ρ`, and
61+ Modifies components of tendency vector `Yₜ.c` (e.g., `Yₜ.c.uₕ`, `Yₜ.c.ρe_tot`, `Yₜ.c.ρ`, and
6262various tracer fields such as `Yₜ.c.ρq_tot`).
6363"""
6464
@@ -96,24 +96,28 @@ function vertical_diffusion_boundary_layer_tendency!(
9696
9797 ᶜρχₜ_diffusion = p. scratch. ᶜtemp_scalar
9898 ᶜK_h_scaled = p. scratch. ᶜtemp_scalar_2
99- for (ᶜρχₜ, ᶜχ, χ_name) in matching_subfields (Yₜ. c, ᶜspecific)
100- χ_name == :e_tot && continue
101- if χ_name in (:q_rai , :q_sno , :n_rai )
102- @. ᶜK_h_scaled = α_vert_diff_tracer * ᶜK_h
103- else
104- @. ᶜK_h_scaled = ᶜK_h
105- end
106- ᶜdivᵥ_ρχ = Operators. DivergenceF2C (
107- top = Operators. SetValue (C3 (0 )),
108- bottom = Operators. SetValue (C3 (0 )),
109- )
110- @. ᶜρχₜ_diffusion =
111- ᶜdivᵥ_ρχ (- (ᶠinterp (Y. c. ρ) * ᶠinterp (ᶜK_h_scaled) * ᶠgradᵥ (ᶜχ)))
112- @. ᶜρχₜ -= ᶜρχₜ_diffusion
113- # Only add contribution from total water diffusion to mass tendency
114- # (exclude contributions from diffusion of condensate, precipitation)
115- if χ_name == :q_tot
116- @. Yₜ. c. ρ -= ᶜρχₜ_diffusion
99+ UU. unrolled_foreach (filter (is_tracer_var, propertynames (Yₜ. c))) do ρχ_name
100+ ᶜρχ = getproperty (Y. c, ρχ_name)
101+ ᶜρχₜ = getproperty (Yₜ. c, ρχ_name)
102+ ᶜχ = @. lazy (specific (ᶜρχ, Y. c. ρ))
103+ if ρχ_name != :ρe_tot
104+ if χ_name in (:q_rai , :q_sno , :n_rai )
105+ @. ᶜK_h_scaled = α_vert_diff_tracer * ᶜK_h
106+ else
107+ @. ᶜK_h_scaled = ᶜK_h
108+ end
109+ ᶜdivᵥ_ρχ = Operators. DivergenceF2C (
110+ top = Operators. SetValue (C3 (0 )),
111+ bottom = Operators. SetValue (C3 (0 )),
112+ )
113+ @. ᶜρχₜ_diffusion =
114+ ᶜdivᵥ_ρχ (- (ᶠinterp (Y. c. ρ) * ᶠinterp (ᶜK_h_scaled) * ᶠgradᵥ (ᶜχ)))
115+ @. ᶜρχₜ -= ᶜρχₜ_diffusion
116+ # Only add contribution from total water diffusion to mass tendency
117+ # (exclude contributions from diffusion of condensate, precipitation)
118+ if χ_name == :q_tot
119+ @. Yₜ. c. ρ -= ᶜρχₜ_diffusion
120+ end
117121 end
118122 end
119123end
0 commit comments