Skip to content

Commit d66c45b

Browse files
committed
Allocate and use a new scratch scalar to resolve overlapping use
1 parent d993c03 commit d66c45b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/cache/temporary_quantities.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function temporary_quantities(Y, atmos)
3535
ᶜtemp_scalar_3 = Fields.Field(FT, center_space),
3636
ᶜtemp_scalar_4 = Fields.Field(FT, center_space),
3737
ᶜtemp_scalar_5 = Fields.Field(FT, center_space),
38+
ᶜtemp_scalar_6 = Fields.Field(FT, center_space),
3839
ᶠtemp_field_level = Fields.level(Fields.Field(FT, face_space), half),
3940
temp_field_level = Fields.level(Fields.Field(FT, center_space), 1),
4041
temp_field_level_2 = Fields.level(Fields.Field(FT, center_space), 1),

src/prognostic_equations/implicit/manual_sparse_jacobian.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
620620
(; vertical_diffusion, smagorinsky_lilly) = p.atmos
621621
(; ᶜp) = p.precomputed
622622
ᶜK_u = p.scratch.ᶜtemp_scalar_4
623-
ᶜK_h = p.scratch.ᶜtemp_scalar_5
623+
ᶜK_h = p.scratch.ᶜtemp_scalar_6
624624
if vertical_diffusion isa DecayWithHeightDiffusion
625625
ᶜK_h .= ᶜcompute_eddy_diffusivity_coefficient(Y.c.ρ, vertical_diffusion)
626626
ᶜK_u = ᶜK_h
@@ -644,17 +644,18 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
644644
@. ᶜK_h = eddy_diffusivity(ᶜK_u, ᶜprandtl_nvec)
645645
end
646646

647-
@. ᶜadvection_matrix =
648-
ᶜadvdivᵥ_matrix() DiagonalMatrixRow(ᶠinterp(ᶜρ) * ᶠinterp(ᶜK_h))
649-
@. ᶜdiffusion_h_matrix = ᶜadvection_matrix ᶠgradᵥ_matrix()
647+
∂ᶠρχ_dif_flux_∂ᶜχ = ᶠp_grad_matrix
648+
@. ∂ᶠρχ_dif_flux_∂ᶜχ =
649+
DiagonalMatrixRow(ᶠinterp(ᶜρ) * ᶠinterp(ᶜK_h)) ᶠgradᵥ_matrix()
650+
@. ᶜdiffusion_h_matrix = ᶜadvdivᵥ_matrix() ∂ᶠρχ_dif_flux_∂ᶜχ
650651
if (
651652
MatrixFields.has_field(Y, @name(c.sgs⁰.ρatke)) ||
652653
!isnothing(p.atmos.turbconv_model) ||
653654
!disable_momentum_vertical_diffusion(p.atmos.vertical_diffusion)
654655
)
655-
@. ᶜadvection_matrix =
656-
ᶜadvdivᵥ_matrix() DiagonalMatrixRow(ᶠinterp(ᶜρ) * ᶠinterp(ᶜK_u))
657-
@. ᶜdiffusion_u_matrix = ᶜadvection_matrix ᶠgradᵥ_matrix()
656+
@. ∂ᶠρχ_dif_flux_∂ᶜχ =
657+
DiagonalMatrixRow(ᶠinterp(ᶜρ) * ᶠinterp(ᶜK_u)) ᶠgradᵥ_matrix()
658+
@. ᶜdiffusion_u_matrix = ᶜadvdivᵥ_matrix() ∂ᶠρχ_dif_flux_∂ᶜχ
658659
end
659660

660661
∂ᶜρe_tot_err_∂ᶜρ = matrix[@name(c.ρe_tot), @name(c.ρ)]

0 commit comments

Comments
 (0)