Skip to content

Commit 8251a01

Browse files
committed
useW-sparsity
1 parent e21ac76 commit 8251a01

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/systems/diffeqs/abstractodesystem.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,13 @@ function jacobian_dae_sparsity(sys::AbstractODESystem)
294294
end
295295

296296
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
298303
(n, n) = size(jac_sparsity)
299-
300304
M = calculate_massmatrix(sys)
301305
M_sparsity = M isa UniformScaling ? sparse(I(n)) : sparse((!iszero).(M))
302306
jac_sparsity .|| M_sparsity
@@ -408,14 +412,8 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
408412

409413
if sparse
410414
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
416415
W_prototype = similar(W_sparsity(sys), uElType)
417416
else
418-
jac_prototype = nothing
419417
W_prototype = nothing
420418
end
421419

@@ -427,9 +425,8 @@ function DiffEqBase.ODEFunction{iip, specialize}(sys::AbstractODESystem,
427425
tgrad = _tgrad === nothing ? nothing : _tgrad,
428426
mass_matrix = _M,
429427
jac_prototype = W_prototype,
430-
W_prototype = W_prototype,
431428
observed = observedfun,
432-
sparsity = sparsity ? jacobian_sparsity(sys) : nothing,
429+
sparsity = sparsity ? W_sparsity(sys) : nothing,
433430
analytic = analytic,
434431
initialization_data)
435432
end

src/systems/diffeqs/sdesystem.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,10 +645,8 @@ function DiffEqBase.SDEFunction{iip, specialize}(sys::SDESystem, dvs = unknowns(
645645
M = calculate_massmatrix(sys)
646646
if sparse
647647
uElType = u0 === nothing ? Float64 : eltype(u0)
648-
jac_prototype = similar(calculate_jacobian(sys; sparse), uElType)
649-
W_prototype = similar(jac_prototype .+ M, uElType)
648+
W_prototype = similar(W_sparsity(sys), uElType)
650649
else
651-
jac_prototype = nothing
652650
W_prototype = nothing
653651
end
654652

@@ -664,7 +662,7 @@ function DiffEqBase.SDEFunction{iip, specialize}(sys::SDESystem, dvs = unknowns(
664662
mass_matrix = _M,
665663
jac_prototype = W_prototype,
666664
observed = observedfun,
667-
sparsity = sparsity ? jacobian_sparsity(sys) : nothing,
665+
sparsity = sparsity ? W_sparsity(sys) : nothing,
668666
analytic = analytic,
669667
Wfact = _Wfact === nothing ? nothing : _Wfact,
670668
Wfact_t = _Wfact_t === nothing ? nothing : _Wfact_t,

0 commit comments

Comments
 (0)