@@ -196,6 +196,10 @@ function jacobian_cache(alg::ManualSparseJacobian, Y, atmos)
196196 name -> (@name (c. ρe_tot), name) => similar (Y. c, TridiagonalRow),
197197 available_condensate_mass_names,
198198 )... ,
199+ MatrixFields. unrolled_map (
200+ name -> (@name (c. ρq_tot), name) => similar (Y. c, TridiagonalRow),
201+ available_condensate_mass_names,
202+ )... ,
199203 (@name (c. uₕ), @name (c. uₕ)) =>
200204 ! isnothing (atmos. turbconv_model) ||
201205 ! disable_momentum_vertical_diffusion (
@@ -213,6 +217,14 @@ function jacobian_cache(alg::ManualSparseJacobian, Y, atmos)
213217 name -> (name, name) => similar (Y. c, TridiagonalRow),
214218 diffused_scalar_names,
215219 )... ,
220+ MatrixFields. unrolled_map (
221+ name -> (@name (c. ρe_tot), name) => similar (Y. c, TridiagonalRow),
222+ available_condensate_mass_names,
223+ )... ,
224+ MatrixFields. unrolled_map (
225+ name -> (@name (c. ρq_tot), name) => similar (Y. c, TridiagonalRow),
226+ available_condensate_mass_names,
227+ )... ,
216228 (@name (c. ρe_tot), @name (c. ρq_tot)) =>
217229 similar (Y. c, TridiagonalRow),
218230 MatrixFields. unrolled_map (
@@ -347,8 +359,10 @@ function jacobian_cache(alg::ManualSparseJacobian, Y, atmos)
347359 ! (atmos. moisture_model isa DryModel)
348360 gs_scalar_subalg = if ! (atmos. moisture_model isa DryModel)
349361 MatrixFields. BlockLowerTriangularSolve (
350- @name (c. ρq_tot),
351362 available_condensate_mass_names... ,
363+ alg₂ = MatrixFields. BlockLowerTriangularSolve (
364+ @name (c. ρq_tot),
365+ ),
352366 )
353367 else
354368 MatrixFields. BlockDiagonalSolve ()
@@ -588,51 +602,21 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
588602 (@name (c. ρq_rim), @name (ᶜwᵢ), FT (1 )),
589603 (@name (c. ρb_rim), @name (ᶜwᵢ), FT (1 )),
590604 )
605+ internal_energy_func (name) =
606+ (name == @name (c. ρq_liq) || name == @name (c. ρq_rai)) ? TD. internal_energy_liquid :
607+ (name == @name (c. ρq_ice) || name == @name (c. ρq_sno)) ? TD. internal_energy_ice :
608+ nothing
591609 if ! (p. atmos. moisture_model isa DryModel) || use_derivative (diffusion_flag)
592610 ∂ᶜρe_tot_err_∂ᶜρe_tot = matrix[@name (c. ρe_tot), @name (c. ρe_tot)]
593611 @. ∂ᶜρe_tot_err_∂ᶜρe_tot = zero (typeof (∂ᶜρe_tot_err_∂ᶜρe_tot)) - (I,)
594612 end
595613
596614 if ! (p. atmos. moisture_model isa DryModel)
597- # TODO : tetsing explicit vs implicit
598- # @. ∂ᶜρe_tot_err_∂ᶜρe_tot +=
599- # dtγ * -(ᶜprecipdivᵥ_matrix()) ⋅
600- # DiagonalMatrixRow(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ) ⋅ ᶠright_bias_matrix() ⋅
601- # DiagonalMatrixRow(
602- # -(1 + ᶜkappa_m) / ᶜρ * ifelse(
603- # ᶜh_tot == 0,
604- # (Geometry.WVector(FT(0)),),
605- # p.precomputed.ᶜwₕhₜ / ᶜh_tot,
606- # ),
607- # )
608-
609615 ∂ᶜρe_tot_err_∂ᶜρq_tot = matrix[@name (c. ρe_tot), @name (c. ρq_tot)]
610616 @. ∂ᶜρe_tot_err_∂ᶜρq_tot = zero (typeof (∂ᶜρe_tot_err_∂ᶜρq_tot))
611- # TODO : tetsing explicit vs implicit
612- # @. ∂ᶜρe_tot_err_∂ᶜρq_tot =
613- # dtγ * -(ᶜprecipdivᵥ_matrix()) ⋅
614- # DiagonalMatrixRow(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ) ⋅ ᶠright_bias_matrix() ⋅
615- # DiagonalMatrixRow(
616- # -(ᶜkappa_m) * ∂e_int_∂q_tot / ᶜρ * ifelse(
617- # ᶜh_tot == 0,
618- # (Geometry.WVector(FT(0)),),
619- # p.precomputed.ᶜwₕhₜ / ᶜh_tot,
620- # ),
621- # )
622617
623618 ∂ᶜρq_tot_err_∂ᶜρq_tot = matrix[@name (c. ρq_tot), @name (c. ρq_tot)]
624619 @. ∂ᶜρq_tot_err_∂ᶜρq_tot = zero (typeof (∂ᶜρq_tot_err_∂ᶜρq_tot)) - (I,)
625- # TODO : testing explicit vs implicit
626- # @. ∂ᶜρq_tot_err_∂ᶜρq_tot =
627- # dtγ * -(ᶜprecipdivᵥ_matrix()) ⋅
628- # DiagonalMatrixRow(ᶠinterp(ᶜρ * ᶜJ) / ᶠJ) ⋅ ᶠright_bias_matrix() ⋅
629- # DiagonalMatrixRow(
630- # -1 / ᶜρ * ifelse(
631- # ᶜq_tot == 0,
632- # (Geometry.WVector(FT(0)),),
633- # p.precomputed.ᶜwₜqₜ / ᶜq_tot,
634- # ),
635- # ) - (I,)
636620
637621 # This scratch variable computation could be skipped if no tracers are present
638622 @. p. scratch. ᶜbidiagonal_adjoint_matrix_c3 =
@@ -641,6 +625,7 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
641625
642626 MatrixFields. unrolled_foreach (tracer_info) do (ρχₚ_name, wₚ_name, _)
643627 MatrixFields. has_field (Y, ρχₚ_name) || return
628+
644629 ∂ᶜρχₚ_err_∂ᶜρχₚ = matrix[ρχₚ_name, ρχₚ_name]
645630 ᶜwₚ = MatrixFields. get_field (p. precomputed, wₚ_name)
646631 # TODO : come up with read-able names for the intermediate computations...
@@ -650,6 +635,24 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
650635 @. ∂ᶜρχₚ_err_∂ᶜρχₚ =
651636 p. scratch. ᶜbidiagonal_adjoint_matrix_c3 ⋅
652637 p. scratch. ᶠband_matrix_wvec - (I,)
638+
639+ if ρχₚ_name in
640+ (@name (c. ρq_liq), @name (c. ρq_ice), @name (c. ρq_rai), @name (c. ρq_sno))
641+ ∂ᶜρq_tot_err_∂ᶜρq = matrix[@name (c. ρq_tot), ρχₚ_name]
642+ @. ∂ᶜρq_tot_err_∂ᶜρq =
643+ p. scratch. ᶜbidiagonal_adjoint_matrix_c3 ⋅
644+ p. scratch. ᶠband_matrix_wvec
645+
646+ ∂ᶜρe_tot_err_∂ᶜρq = matrix[@name (c. ρe_tot), ρχₚ_name]
647+ e_int_func = internal_energy_func (ρχₚ_name)
648+ @. ∂ᶜρe_tot_err_∂ᶜρq =
649+ p. scratch. ᶜbidiagonal_adjoint_matrix_c3 ⋅
650+ p. scratch. ᶠband_matrix_wvec ⋅
651+ DiagonalMatrixRow (
652+ e_int_func (thermo_params, p. precomputed. ᶜts) + ᶜΦ +
653+ $ (Kin (ᶜwₚ, p. precomputed. ᶜu)),
654+ )
655+ end
653656 end
654657
655658 end
@@ -719,7 +722,7 @@ function update_jacobian!(alg::ManualSparseJacobian, cache, Y, p, dtγ, t)
719722 for (q_name, e_int_q, ∂cv∂q) in microphysics_tracers
720723 MatrixFields. has_field (Y, q_name) || continue
721724 ∂ᶜρe_tot_err_∂ᶜρq = matrix[@name (c. ρe_tot), q_name]
722- @. ∂ᶜρe_tot_err_∂ᶜρq =
725+ @. ∂ᶜρe_tot_err_∂ᶜρq + =
723726 dtγ * ᶜdiffusion_h_matrix ⋅
724727 DiagonalMatrixRow ((ᶜkappa_m * (e_int_q - ∂cv∂q * (T - T_0)) - R_v * T) / ᶜρ)
725728 end
0 commit comments