@@ -606,7 +606,9 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
606
606
Δcv_v = FT (CAP. cv_v (params)) - cv_d
607
607
T_0 = FT (CAP. T_0 (params))
608
608
R_d = FT (CAP. R_d (params))
609
+ ΔR_v = FT (CAP. R_v (params)) - R_d
609
610
cp_d = FT (CAP. cp_d (params))
611
+ Δcp_v = FT (CAP. cp_v (params)) - cp_d
610
612
# This term appears a few times in the Jacobian, and is technically
611
613
# minus ∂e_int_∂q_tot
612
614
∂e_int_∂q_tot = T_0 * (Δcv_v - R_d) - FT (CAP. e_int_v0 (params))
@@ -625,6 +627,14 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
625
627
TD. gas_constant_air (thermo_params, ᶜts) / TD. cv_m (thermo_params, ᶜts),
626
628
)
627
629
630
+ # Using abs2 because ^2 results in allocation
631
+ ᶜ∂kappa_m∂q_tot = @. lazy (
632
+ (
633
+ ΔR_v * TD. cv_m (thermo_params, ᶜts) -
634
+ Δcv_v * TD. gas_constant_air (thermo_params, ᶜts)
635
+ ) / abs2 (TD. cv_m (thermo_params, ᶜts)),
636
+ )
637
+
628
638
if use_derivative (topography_flag)
629
639
@. ∂ᶜK_∂ᶜuₕ = DiagonalMatrixRow (
630
640
adjoint (CTh (ᶜuₕ)) + adjoint (ᶜinterp (ᶠu₃)) * g³ʰ (ᶜgⁱʲ),
@@ -681,7 +691,13 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
681
691
if MatrixFields. has_field (Y, @name (c. ρq_tot))
682
692
∂ᶠu₃_err_∂ᶜρq_tot = matrix[@name (f. u₃), @name (c. ρq_tot)]
683
693
@. ∂ᶠu₃_err_∂ᶜρq_tot =
684
- dtγ * ᶠp_grad_matrix ⋅ DiagonalMatrixRow (ᶜkappa_m * ∂e_int_∂q_tot)
694
+ dtγ * ᶠp_grad_matrix ⋅ DiagonalMatrixRow ((
695
+ ᶜkappa_m * ∂e_int_∂q_tot +
696
+ ᶜ∂kappa_m∂q_tot * (
697
+ cp_d * T_0 + ᶜspecific. e_tot - ᶜK - ᶜΦ +
698
+ ∂e_int_∂q_tot * ᶜspecific. q_tot
699
+ )
700
+ ))
685
701
end
686
702
687
703
∂ᶠu₃_err_∂ᶜuₕ = matrix[@name (f. u₃), @name (c. uₕ)]
@@ -806,8 +822,13 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
806
822
∂ᶜρe_tot_err_∂ᶜρq_tot = matrix[@name (c. ρe_tot), @name (c. ρq_tot)]
807
823
∂ᶜρq_tot_err_∂ᶜρ = matrix[@name (c. ρq_tot), @name (c. ρ)]
808
824
@. ∂ᶜρe_tot_err_∂ᶜρq_tot +=
809
- dtγ * ᶜdiffusion_h_matrix ⋅
810
- DiagonalMatrixRow (ᶜkappa_m * ∂e_int_∂q_tot / ᶜρ)
825
+ dtγ * ᶜdiffusion_h_matrix ⋅ DiagonalMatrixRow ((
826
+ ᶜkappa_m * ∂e_int_∂q_tot / ᶜρ +
827
+ ᶜ∂kappa_m∂q_tot * (
828
+ cp_d * T_0 + ᶜspecific. e_tot - ᶜK - ᶜΦ +
829
+ ∂e_int_∂q_tot * ᶜspecific. q_tot
830
+ )
831
+ ))
811
832
@. ∂ᶜρq_tot_err_∂ᶜρ =
812
833
dtγ * ᶜdiffusion_h_matrix ⋅
813
834
DiagonalMatrixRow (- (ᶜspecific. q_tot) / ᶜρ)
@@ -904,6 +925,15 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
904
925
TD. cv_m (thermo_params, ᶜtsʲs.:(1 )),
905
926
)
906
927
928
+ # Note this is the derivative of R_m / cp_m with respect to q_tot
929
+ # but we call it ∂kappa_m∂q_totʲ
930
+ ᶜ∂kappa_m∂q_totʲ = @. lazy (
931
+ (
932
+ ΔR_v * TD. cp_m (thermo_params, ᶜtsʲs.:(1 )) -
933
+ Δcp_v * TD. gas_constant_air (thermo_params, ᶜtsʲs.:(1 ))
934
+ ) / abs2 (TD. cp_m (thermo_params, ᶜtsʲs.:(1 ))),
935
+ )
936
+
907
937
∂ᶜq_totʲ_err_∂ᶜq_totʲ =
908
938
matrix[@name (c. sgsʲs.:(1 ). q_tot), @name (c. sgsʲs.:(1 ). q_tot)]
909
939
@. ∂ᶜq_totʲ_err_∂ᶜq_totʲ =
@@ -932,10 +962,15 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
932
962
@. ∂ᶜmseʲ_err_∂ᶜq_totʲ =
933
963
dtγ * (
934
964
- DiagonalMatrixRow (
935
- adjoint (ᶜinterp (ᶠu³ʲs.:(1 ))) *
936
- ᶜgradᵥ_ᶠΦ *
937
- Y. c. ρ *
938
- ᶜkappa_mʲ / ((ᶜkappa_mʲ + 1 ) * ᶜp) * ∂e_int_∂q_tot,
965
+ adjoint (ᶜinterp (ᶠu³ʲs.:(1 ))) * ᶜgradᵥ_ᶠΦ * Y. c. ρ / ᶜp *
966
+ (
967
+ (ᶜkappa_mʲ / (ᶜkappa_mʲ + 1 ) * ∂e_int_∂q_tot) +
968
+ ᶜ∂kappa_m∂q_totʲ * (
969
+ Y. c. sgsʲs.:(1 ). mse - ᶜΦ +
970
+ cp_d * T_0 +
971
+ ∂e_int_∂q_tot * Y. c. sgsʲs.:(1 ). q_tot
972
+ )
973
+ ),
939
974
)
940
975
)
941
976
@@ -977,8 +1012,14 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
977
1012
),
978
1013
) / ᶠJ,
979
1014
) ⋅ ᶠinterp_matrix () ⋅ DiagonalMatrixRow (
980
- ᶜJ * ᶜkappa_mʲ * (ᶜρʲs.:(1 ))^ 2 / ((ᶜkappa_mʲ + 1 ) * ᶜp) *
981
- ∂e_int_∂q_tot,
1015
+ ᶜJ * (ᶜρʲs.:(1 ))^ 2 / ᶜp * (
1016
+ ᶜkappa_mʲ / (ᶜkappa_mʲ + 1 ) * ∂e_int_∂q_tot +
1017
+ ᶜ∂kappa_m∂q_totʲ * (
1018
+ Y. c. sgsʲs.:(1 ). mse - ᶜΦ +
1019
+ cp_d * T_0 +
1020
+ ∂e_int_∂q_tot * Y. c. sgsʲs.:(1 ). q_tot
1021
+ )
1022
+ ),
982
1023
)
983
1024
@. ᶠbidiagonal_matrix_ct3_2 =
984
1025
DiagonalMatrixRow (ᶠinterp (ᶜρʲs.:(1 ) * ᶜJ) / ᶠJ) ⋅
@@ -1045,8 +1086,14 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
1045
1086
dtγ * DiagonalMatrixRow (
1046
1087
ᶠgradᵥ_ᶜΦ * ᶠinterp (Y. c. ρ) / (ᶠinterp (ᶜρʲs.:(1 )))^ 2 ,
1047
1088
) ⋅ ᶠinterp_matrix () ⋅ DiagonalMatrixRow (
1048
- ᶜkappa_mʲ * (ᶜρʲs.:(1 ))^ 2 / ((ᶜkappa_mʲ + 1 ) * ᶜp) *
1049
- ∂e_int_∂q_tot,
1089
+ (ᶜρʲs.:(1 ))^ 2 / ᶜp * (
1090
+ ᶜkappa_mʲ / (ᶜkappa_mʲ + 1 ) * ∂e_int_∂q_tot +
1091
+ ᶜ∂kappa_m∂q_totʲ * (
1092
+ Y. c. sgsʲs.:(1 ). mse - ᶜΦ +
1093
+ cp_d * T_0 +
1094
+ ∂e_int_∂q_tot * Y. c. sgsʲs.:(1 ). q_tot
1095
+ )
1096
+ ),
1050
1097
)
1051
1098
∂ᶠu₃ʲ_err_∂ᶜmseʲ =
1052
1099
matrix[@name (f. sgsʲs.:(1 ). u₃), @name (c. sgsʲs.:(1 ). mse)]
@@ -1154,7 +1201,13 @@ function update_implicit_equation_jacobian!(A, Y, p, dtγ, t)
1154
1201
1155
1202
@. ∂ᶜρe_tot_err_∂ᶜρq_tot +=
1156
1203
dtγ * ᶜadvdivᵥ_matrix () ⋅ ∂ᶜupdraft_mass_flux_∂ᶜscalar ⋅
1157
- DiagonalMatrixRow (ᶜkappa_m * ∂e_int_∂q_tot / ᶜρ)
1204
+ DiagonalMatrixRow ((
1205
+ ᶜkappa_m * ∂e_int_∂q_tot / ᶜρ +
1206
+ ᶜ∂kappa_m∂q_tot * (
1207
+ cp_d * T_0 + ᶜspecific. e_tot - ᶜK - ᶜΦ +
1208
+ ∂e_int_∂q_tot * ᶜspecific. q_tot
1209
+ )
1210
+ ))
1158
1211
1159
1212
@. ∂ᶜρe_tot_err_∂ᶜρe_tot +=
1160
1213
dtγ * ᶜadvdivᵥ_matrix () ⋅ ∂ᶜupdraft_mass_flux_∂ᶜscalar ⋅
0 commit comments