@@ -172,7 +172,18 @@ function calc_J!(J, integrator, cache, next_step::Bool = false)
172
172
if DiffEqBase. has_jac (f)
173
173
duprev = integrator. duprev
174
174
uf = cache. uf
175
- f. jac (J, duprev, uprev, p, uf. α * uf. invγdt, t)
175
+ # need to do some jank here to account for sparsity pattern of W
176
+ # https://github.com/SciML/OrdinaryDiffEq.jl/issues/2653
177
+
178
+ # we need to set all nzval to a non-zero number
179
+ # otherwise in the following line any zero gets interpreted as a structural zero
180
+ integrator. f. jac_prototype. nzval .= 1.0
181
+ J .= 1.0 .* integrator. f. jac_prototype
182
+ J. nzval .= 0.0
183
+ f. jac (J, uprev, p, t)
184
+ MM = integrator. f. mass_matrix isa UniformScaling ?
185
+ integrator. f. mass_matrix (length (integrator. u)) : integrator. f. mass_matrix
186
+ J .= J .+ MM
176
187
else
177
188
@unpack du1, uf, jac_config = cache
178
189
# using `dz` as temporary array
@@ -183,7 +194,17 @@ function calc_J!(J, integrator, cache, next_step::Bool = false)
183
194
end
184
195
else
185
196
if DiffEqBase. has_jac (f)
197
+ # need to do some jank here to account for sparsity pattern of W
198
+ # https://github.com/SciML/OrdinaryDiffEq.jl/issues/2653
199
+
200
+ # we need to set all nzval to a non-zero number
201
+ # otherwise in the following line any zero gets interpreted as a structural zero
202
+ integrator. f. jac_prototype. nzval .= 1.0
203
+ J .= 1.0 .* integrator. f. jac_prototype
204
+ J. nzval .= 0.0
186
205
f. jac (J, uprev, p, t)
206
+ MM = integrator. f. mass_matrix isa UniformScaling ? integrator. f. mass_matrix (length (integrator. u)) : integrator. f. mass_matrix
207
+ J .= J .+ MM
187
208
else
188
209
@unpack du1, uf, jac_config = cache
189
210
uf. f = nlsolve_f (f, alg)
0 commit comments