Skip to content

Commit ae0af82

Browse files
committed
Add rho*a and u_{3,m} updraft jacobian terms
1 parent 7437cef commit ae0af82

File tree

2 files changed

+71
-12
lines changed

2 files changed

+71
-12
lines changed

reproducibility_tests/ref_counter.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
225
1+
226
22

33
# **README**
44
#
@@ -21,6 +21,9 @@
2121

2222
#=
2323
24+
226
25+
- Add updraft rho*a and u_{3,m} jacobian terms
26+
2427
225
2528
- Move nonhydrostatic pressure drag calculation to precomputed quantities and
2629
remove one reproducibility job

src/prognostic_equations/implicit/implicit_solver.jl

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,14 @@ function ImplicitEquationJacobian(
328328
similar(Y.c, TridiagonalRow),
329329
(@name(c.ρq_tot), @name(c.sgsʲs.:(1).q_tot)) =>
330330
similar(Y.c, TridiagonalRow),
331+
(@name(c.ρe_tot), @name(f.sgsʲs.:(1).u₃)) =>
332+
similar(Y.c, BidiagonalRow_ACT3),
333+
(@name(c.ρq_tot), @name(f.sgsʲs.:(1).u₃)) =>
334+
similar(Y.c, BidiagonalRow_ACT3),
335+
(@name(c.ρe_tot), @name(c.sgsʲs.:(1).ρa)) =>
336+
similar(Y.c, TridiagonalRow),
337+
(@name(c.ρq_tot), @name(c.sgsʲs.:(1).ρa)) =>
338+
similar(Y.c, TridiagonalRow),
331339
)
332340
else
333341
()
@@ -525,6 +533,11 @@ NVTX.@annotate function Wfact!(A, Y, p, dtγ, t)
525533
p.atmos.turbconv_model isa PrognosticEDMFX ?
526534
(; p.precomputed.ᶠu₃⁰,) : (;)
527535
)...,
536+
(
537+
use_derivative(A.sgs_mass_flux_flag) &&
538+
p.atmos.turbconv_model isa PrognosticEDMFX ?
539+
(; p.precomputed.ᶜKʲs) : (;)
540+
)...,
528541
p.core.ᶜΦ,
529542
p.core.ᶠgradᵥ_ᶜΦ,
530543
p.scratch.ᶜtemp_scalar,
@@ -864,6 +877,7 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
864877
end
865878

866879
if p.atmos.turbconv_model isa PrognosticEDMFX
880+
867881
if use_derivative(sgs_advection_flag)
868882
(; ᶜgradᵥ_ᶠΦ, ᶜρʲs, ᶠu³ʲs, ᶜtsʲs) = p
869883
(; bdmr_l, bdmr_r, bdmr) = p
@@ -1068,7 +1082,7 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
10681082
# add updraft mass flux contributions to grid-mean
10691083
if use_derivative(sgs_mass_flux_flag)
10701084

1071-
(; ᶜgradᵥ_ᶠΦ, ᶜρʲs, ᶠu³ʲs, ᶜtsʲs, ᶠu³) = p
1085+
(; ᶜgradᵥ_ᶠΦ, ᶜρʲs, ᶠu³ʲs, ᶜtsʲs, ᶠu³, ᶜKʲs) = p
10721086
(; bdmr_l, bdmr_r, bdmr) = p
10731087
is_third_order = edmfx_upwinding == Val(:third_order)
10741088
ᶠupwind = is_third_order ? ᶠupwind3 : ᶠupwind1
@@ -1088,8 +1102,8 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
10881102

10891103
# Jacobian contributions of updraft massflux to grid-mean
10901104

1091-
∂ᶜupdraft_mass_flux_∂ᶜh_tot = ᶠbidiagonal_matrix_ct3
1092-
@. ∂ᶜupdraft_mass_flux_∂ᶜh_tot =
1105+
∂ᶜupdraft_mass_flux_∂ᶜscalar = ᶠbidiagonal_matrix_ct3
1106+
@. ∂ᶜupdraft_mass_flux_∂ᶜscalar =
10931107
DiagonalMatrixRow(
10941108
(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ) * (ᶠu³ʲs.:(1) - ᶠu³),
10951109
) ᶠinterp_matrix()
@@ -1098,7 +1112,7 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
10981112
# Derivative of total energy tendency with respect to updraft MSE
10991113
## grid-mean ρe_tot
11001114
@. ∂ᶜρe_tot_err_∂ᶜρ +=
1101-
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜh_tot
1115+
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11021116
DiagonalMatrixRow(
11031117
(
11041118
-(1 + ᶜkappa_m) * ᶜspecific.e_tot -
@@ -1107,34 +1121,76 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
11071121
)
11081122

11091123
@. ∂ᶜρe_tot_err_∂ᶜρq_tot +=
1110-
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜh_tot
1124+
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11111125
DiagonalMatrixRow(ᶜkappa_m * ∂e_int_∂q_tot / ᶜρ)
11121126

11131127
@. ∂ᶜρe_tot_err_∂ᶜρe_tot +=
1114-
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜh_tot
1128+
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11151129
DiagonalMatrixRow((1 + ᶜkappa_m) / ᶜρ)
11161130

11171131
∂ᶜρe_tot_err_∂ᶜmseʲ =
11181132
matrix[@name(c.ρe_tot), @name(c.sgsʲs.:(1).mse)]
11191133
@. ∂ᶜρe_tot_err_∂ᶜmseʲ =
1120-
-(dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜh_tot)
1134+
-(dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar)
11211135

11221136
## grid-mean ρq_tot
1123-
∂ᶜupdraft_mass_flux_∂ᶜqtot = ∂ᶜupdraft_mass_flux_∂ᶜh_tot
11241137
∂ᶜρq_tot_err_∂ᶜρ = matrix[@name(c.ρq_tot), @name(c.ρ)]
11251138
@. ∂ᶜρq_tot_err_∂ᶜρ +=
1126-
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜqtot
1139+
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11271140
DiagonalMatrixRow(-(ᶜspecific.q_tot) / ᶜρ)
11281141

11291142
∂ᶜρq_tot_err_∂ᶜρq_tot = matrix[@name(c.ρq_tot), @name(c.ρq_tot)]
11301143
@. ∂ᶜρq_tot_err_∂ᶜρq_tot +=
1131-
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜqtot
1144+
dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar
11321145
DiagonalMatrixRow(1 / ᶜρ)
11331146

11341147
∂ᶜρq_tot_err_∂ᶜq_totʲ =
11351148
matrix[@name(c.ρq_tot), @name(c.sgsʲs.:(1).q_tot)]
11361149
@. ∂ᶜρq_tot_err_∂ᶜq_totʲ =
1137-
-(dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜqtot)
1150+
-(dtγ * ᶜadvdivᵥ_matrix() ∂ᶜupdraft_mass_flux_∂ᶜscalar)
1151+
1152+
# grid-mean ∂/∂(u₃ʲ)
1153+
∂ᶜρe_tot_err_∂ᶠu₃ʲ =
1154+
matrix[@name(c.ρe_tot), @name(f.sgsʲs.:(1).u₃)]
1155+
@. ∂ᶜρe_tot_err_∂ᶠu₃ʲ =
1156+
dtγ * -(ᶜadvdivᵥ_matrix()) DiagonalMatrixRow(
1157+
ᶠinterp(
1158+
(Y.c.sgsʲs.:(1).mse + ᶜKʲs.:(1) - ᶜh_tot) *
1159+
ᶜρʲs.:(1) *
1160+
ᶜJ *
1161+
draft_area(Y.c.sgsʲs.:(1).ρa, ᶜρʲs.:(1)),
1162+
) / ᶠJ * (g³³(ᶠgⁱʲ)),
1163+
)
1164+
1165+
1166+
∂ᶜρq_tot_err_∂ᶠu₃ʲ =
1167+
matrix[@name(c.ρq_tot), @name(f.sgsʲs.:(1).u₃)]
1168+
@. ∂ᶜρq_tot_err_∂ᶠu₃ʲ =
1169+
dtγ * -(ᶜadvdivᵥ_matrix()) DiagonalMatrixRow(
1170+
ᶠinterp(
1171+
(Y.c.sgsʲs.:(1).q_tot - ᶜspecific.q_tot) *
1172+
ᶜρʲs.:(1) *
1173+
ᶜJ *
1174+
draft_area(Y.c.sgsʲs.:(1).ρa, ᶜρʲs.:(1)),
1175+
) / ᶠJ * (g³³(ᶠgⁱʲ)),
1176+
)
1177+
1178+
# grid-mean ∂/∂(rho*a)
1179+
∂ᶜρe_tot_err_∂ᶜρa =
1180+
matrix[@name(c.ρe_tot), @name(c.sgsʲs.:(1).ρa)]
1181+
@. ∂ᶜρe_tot_err_∂ᶜρa =
1182+
dtγ * -(ᶜadvdivᵥ_matrix()) DiagonalMatrixRow(
1183+
(ᶠu³ʲs.:(1) - ᶠu³) *
1184+
ᶠinterp((Y.c.sgsʲs.:(1).mse + ᶜKʲs.:(1) - ᶜh_tot)) / ᶠJ,
1185+
) ᶠinterp_matrix() DiagonalMatrixRow(ᶜJ)
1186+
1187+
∂ᶜρq_tot_err_∂ᶜρa =
1188+
matrix[@name(c.ρq_tot), @name(c.sgsʲs.:(1).ρa)]
1189+
@. ∂ᶜρq_tot_err_∂ᶜρa =
1190+
dtγ * -(ᶜadvdivᵥ_matrix()) DiagonalMatrixRow(
1191+
(ᶠu³ʲs.:(1) - ᶠu³) *
1192+
ᶠinterp((Y.c.sgsʲs.:(1).q_tot - ᶜspecific.q_tot)) / ᶠJ,
1193+
) ᶠinterp_matrix() DiagonalMatrixRow(ᶜJ)
11381194

11391195
end
11401196

0 commit comments

Comments
 (0)