Skip to content

Commit 2f43019

Browse files
authored
Merge pull request #3768 from CliMA/zs/temp_scalar
use temporary field instead of lazy broadcasting in the implicit solver
2 parents c4e87a6 + 185eb0e commit 2f43019

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/prognostic_equations/implicit/implicit_solver.jl

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ NVTX.@annotate function Wfact!(A, Y, p, dtγ, t)
543543
p.core.ᶜΦ,
544544
p.core.ᶠgradᵥ_ᶜΦ,
545545
p.scratch.ᶜtemp_scalar,
546+
p.scratch.ᶜtemp_scalar_2,
546547
p.scratch.ᶜtemp_C3,
547548
p.scratch.ᶠtemp_CT3,
548549
p.scratch.∂ᶜK_∂ᶜuₕ,
@@ -623,17 +624,17 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
623624
ᶠgⁱʲ = Fields.local_geometry_field(Y.f).gⁱʲ
624625
ᶠlg = Fields.local_geometry_field(Y.f)
625626

626-
ᶜkappa_m = @. lazy(
627-
TD.gas_constant_air(thermo_params, ᶜts) / TD.cv_m(thermo_params, ᶜts),
628-
)
627+
ᶜkappa_m = p.ᶜtemp_scalar
628+
@. ᶜkappa_m =
629+
TD.gas_constant_air(thermo_params, ᶜts) / TD.cv_m(thermo_params, ᶜts)
629630

631+
ᶜ∂kappa_m∂q_tot = p.ᶜtemp_scalar_2
630632
# Using abs2 because ^2 results in allocation
631-
ᶜ∂kappa_m∂q_tot = @. lazy(
633+
@. ᶜ∂kappa_m∂q_tot =
632634
(
633635
ΔR_v * TD.cv_m(thermo_params, ᶜts) -
634636
Δcv_v * TD.gas_constant_air(thermo_params, ᶜts)
635-
) / abs2(TD.cv_m(thermo_params, ᶜts)),
636-
)
637+
) / abs2(TD.cv_m(thermo_params, ᶜts))
637638

638639
if use_derivative(topography_flag)
639640
@. ∂ᶜK_∂ᶜuₕ = DiagonalMatrixRow(
@@ -920,19 +921,19 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
920921
) # Need to wrap ᶠupwind_matrix in this for well-defined boundaries.
921922

922923
ᶠu³ʲ_data = ᶠu³ʲs.:(1).components.data.:1
923-
ᶜkappa_mʲ = @. lazy(
924+
ᶜkappa_mʲ = p.ᶜtemp_scalar
925+
@. ᶜkappa_mʲ =
924926
TD.gas_constant_air(thermo_params, ᶜtsʲs.:(1)) /
925-
TD.cv_m(thermo_params, ᶜtsʲs.:(1)),
926-
)
927+
TD.cv_m(thermo_params, ᶜtsʲs.:(1))
927928

928929
# Note this is the derivative of R_m / cp_m with respect to q_tot
929930
# but we call it ∂kappa_m∂q_totʲ
930-
ᶜ∂kappa_m∂q_totʲ = @. lazy(
931+
ᶜ∂kappa_m∂q_totʲ = p.ᶜtemp_scalar_2
932+
@. ᶜ∂kappa_m∂q_totʲ =
931933
(
932934
ΔR_v * TD.cp_m(thermo_params, ᶜtsʲs.:(1)) -
933935
Δcp_v * TD.gas_constant_air(thermo_params, ᶜtsʲs.:(1))
934-
) / abs2(TD.cp_m(thermo_params, ᶜtsʲs.:(1))),
935-
)
936+
) / abs2(TD.cp_m(thermo_params, ᶜtsʲs.:(1)))
936937

937938
∂ᶜq_totʲ_err_∂ᶜq_totʲ =
938939
matrix[@name(c.sgsʲs.:(1).q_tot), @name(c.sgsʲs.:(1).q_tot)]
@@ -1190,6 +1191,18 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
11901191

11911192
# Derivative of total energy tendency with respect to updraft MSE
11921193
## grid-mean ρe_tot
1194+
ᶜkappa_m = p.ᶜtemp_scalar
1195+
@. ᶜkappa_m =
1196+
TD.gas_constant_air(thermo_params, ᶜts) /
1197+
TD.cv_m(thermo_params, ᶜts)
1198+
1199+
ᶜ∂kappa_m∂q_tot = p.ᶜtemp_scalar_2
1200+
@. ᶜ∂kappa_m∂q_tot =
1201+
(
1202+
ΔR_v * TD.cv_m(thermo_params, ᶜts) -
1203+
Δcv_v * TD.gas_constant_air(thermo_params, ᶜts)
1204+
) / abs2(TD.cv_m(thermo_params, ᶜts))
1205+
11931206
@. ∂ᶜρe_tot_err_∂ᶜρ +=
11941207
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11951208
DiagonalMatrixRow(

0 commit comments

Comments
 (0)