@@ -102,11 +102,12 @@ end
102102 (; T_exp_T_lim!, T_lim!, T_exp!, T_imp!, lim!, dss!) = f
103103 (; tableau, newtons_method) = alg
104104 (; a_exp, b_exp, a_imp, b_imp, c_exp, c_imp) = tableau
105- (; U, T_lim, T_exp, T_imp, temp, γ, newtons_method_cache) = cache
105+ (; U, T_lim, T_exp, T_imp, temp, newtons_method_cache) = cache
106106 s = length (b_exp)
107107
108108 t_exp = t + dt * c_exp[i]
109109 t_imp = t + dt * c_imp[i]
110+ dtγ = dt * a_imp[i, i]
110111
111112 if has_T_lim (f) # Update based on limited tendencies from previous stages
112113 assign_fused_increment! (U, u, dt, a_exp, T_lim, Val (i))
@@ -123,20 +124,16 @@ end
123124
124125 if isnothing (T_imp!) || iszero (a_imp[i, i])
125126 i ≠ 1 && cache! (U, p, t_exp)
126- if ! all (iszero, a_imp[:, i]) || ! iszero (b_imp[i])
127- # If its coefficient is 0, T_imp[i] is being treated explicitly.
128- isnothing (T_imp!) || T_imp! (T_imp[i], U, p, t_imp)
129- end
130127 else # Implicit solve
131128 @assert ! isnothing (newtons_method)
132129 i ≠ 1 && cache_imp! (U, p, t_imp)
133130 @. temp = U
134131 implicit_equation_residual! = (residual, Ui) -> begin
135132 T_imp! (residual, Ui, p, t_imp)
136- @. residual = temp + dt * a_imp[i, i] * residual - Ui
133+ @. residual = temp + dtγ * residual - Ui
137134 end
138135 implicit_equation_jacobian! = (jacobian, Ui) -> begin
139- T_imp!. Wfact (jacobian, Ui, p, dt * a_imp[i, i] , t_imp)
136+ T_imp!. Wfact (jacobian, Ui, p, dtγ , t_imp)
140137 end
141138 implicit_equation_cache! = Ui -> cache_imp! (Ui, p, t_imp)
142139 solve_newton! (
@@ -147,21 +144,23 @@ end
147144 implicit_equation_jacobian!,
148145 implicit_equation_cache!,
149146 )
150- if ! all (iszero, a_imp[:, i]) || ! iszero (b_imp[i])
151- # If T_imp[i] is being treated implicitly, ensure that it
152- # exactly satisfies the implicit equation before applying DSS.
153- @. T_imp[i] = (U - temp) / (dt * a_imp[i, i])
154- end
155147 dss! (U, p, t_imp)
156148 cache! (U, p, t_imp)
157149 end
158150
159151 if ! all (iszero, a_exp[:, i]) || ! iszero (b_exp[i])
160- if ! isnothing (T_exp_T_lim!)
161- T_exp_T_lim! (T_exp[i], T_lim[i], U, p, t_exp)
152+ isnothing (T_exp_T_lim!) || T_exp_T_lim! (T_exp[i], T_lim[i], U, p, t_exp)
153+ isnothing (T_lim!) || T_lim! (T_lim[i], U, p, t_exp)
154+ isnothing (T_exp!) || T_exp! (T_exp[i], U, p, t_exp)
155+ end
156+ if ! all (iszero, a_imp[:, i]) || ! iszero (b_imp[i])
157+ if iszero (a_imp[i, i])
158+ # If its coefficient is 0, T_imp[i] is being treated explicitly.
159+ isnothing (T_imp!) || T_imp! (T_imp[i], U, p, t_imp)
162160 else
163- isnothing (T_lim!) || T_lim! (T_lim[i], U, p, t_exp)
164- isnothing (T_exp!) || T_exp! (T_exp[i], U, p, t_exp)
161+ # If T_imp[i] is being treated implicitly, ensure that it
162+ # exactly satisfies the implicit equation after applying DSS.
163+ isnothing (T_imp!) || @. T_imp[i] = (U - temp) / dtγ
165164 end
166165 end
167166
0 commit comments