Skip to content

Commit 7d56584

Browse files
committed
Test Jacobian sparsity with observed derivative
1 parent d5fd2b6 commit 7d56584

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/jacobiansparsity.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,18 @@ end
139139
@test J == prob.f.jac(prob.u0, prob.p, 1.0)
140140
@test J prob.f.jac(prob.u0, prob.p, 1.0)
141141
end
142+
143+
# https://github.com/SciML/ModelingToolkit.jl/issues/3871
144+
@testset "Issue#3871: Sparsity with observed derivatives" begin
145+
t = ModelingToolkit.t_nounits
146+
D = ModelingToolkit.D_nounits
147+
@variables x(t) y(t)
148+
@mtkcompile sys = System([D(x) ~ x * D(y), D(y) ~ x - y], t)
149+
@test ModelingToolkit.jacobian_sparsity(sys) == [1 1; 1 1] # all nonzero
150+
J1 = calculate_jacobian(sys)
151+
J2 = isequal(unknowns(sys)[1], x) ? [2x-y -x; 1 -1] : [-1 1; -x 2x-y] # analytical result
152+
@test isequal(J1, J2)
153+
prob = ODEProblem(sys, [x => 1.0, y => 0.0], (0.0, 1.0); jac = true, sparse = true)
154+
sol = solve(prob, FBDF())
155+
@test SciMLBase.successful_retcode(sol)
156+
end

0 commit comments

Comments
 (0)