@@ -294,9 +294,13 @@ function jacobian_dae_sparsity(sys::AbstractODESystem)
294
294
end
295
295
296
296
function W_sparsity (sys:: AbstractODESystem )
297
- jac_sparsity = jacobian_sparsity (sys)
297
+ if has_tearing_state (sys)
298
+ jac_sparsity = jacobian_sparsity (sys)
299
+ else
300
+ jac = calculate_jacobian (sys; sparse = true )
301
+ jac_sparsity = sparse ((! iszero). (jac))
302
+ end
298
303
(n, n) = size (jac_sparsity)
299
-
300
304
M = calculate_massmatrix (sys)
301
305
M_sparsity = M isa UniformScaling ? sparse (I (n)) : sparse ((! iszero). (M))
302
306
jac_sparsity .|| M_sparsity
@@ -408,14 +412,8 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
408
412
409
413
if sparse
410
414
uElType = u0 === nothing ? Float64 : eltype (u0)
411
- if jac
412
- jac_prototype = similar (calculate_jacobian (sys; sparse), uElType)
413
- else
414
- jac_prototype = similar (jacobian_sparsity (sys), uElType)
415
- end
416
415
W_prototype = similar (W_sparsity (sys), uElType)
417
416
else
418
- jac_prototype = nothing
419
417
W_prototype = nothing
420
418
end
421
419
@@ -427,9 +425,8 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
427
425
tgrad = _tgrad === nothing ? nothing : _tgrad,
428
426
mass_matrix = _M,
429
427
jac_prototype = W_prototype,
430
- W_prototype = W_prototype,
431
428
observed = observedfun,
432
- sparsity = sparsity ? jacobian_sparsity (sys) : nothing ,
429
+ sparsity = sparsity ? W_sparsity (sys) : nothing ,
433
430
analytic = analytic,
434
431
initialization_data)
435
432
end
0 commit comments