Skip to content

Commit 4de8fa5

Browse files
committed
Fix tests
1 parent 0b35390 commit 4de8fa5

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

test/jacobiansparsity.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using OrdinaryDiffEq, ModelingToolkit, Test, SparseArrays
22

3-
N = 32
4-
const xyd_brusselator = range(0,stop=1,length=N)
3+
N = 3
4+
xyd_brusselator = range(0,stop=1,length=N)
55
brusselator_f(x, y, t) = (((x-0.3)^2 + (y-0.6)^2) <= 0.1^2) * (t >= 1.1) * 5.
66
limit(a, N) = ModelingToolkit.ifelse(a == N+1, 1, ModelingToolkit.ifelse(a == 0, N, a))
77
function brusselator_2d_loop(du, u, p, t)
@@ -40,11 +40,12 @@ sys = modelingtoolkitize(prob_ode_brusselator_2d)
4040

4141
# test sparse jacobian pattern only.
4242
prob = ODEProblem(sys, u0, (0, 11.5), sparse=true, jac=false)
43-
@test findnz(Symbolics.jacobian_sparsity(map(x->x.rhs, equations(sys)), states(sys)))[1:2] == findnz(prob.f.jac_prototype)[1:2]
43+
JP = prob.f.jac_prototype
44+
@test findnz(Symbolics.jacobian_sparsity(map(x->x.rhs, equations(sys)), states(sys)))[1:2] == findnz(JP)[1:2]
4445

4546
# test sparse jacobian
4647
prob = ODEProblem(sys, u0, (0, 11.5), sparse=true, jac=true)
47-
@test findnz(calculate_jacobian(sys))[1:2] == findnz(prob.f.jac_prototype)[1:2]
48+
@test findnz(calculate_jacobian(sys, sparse=true))[1:2] == findnz(prob.f.jac_prototype)[1:2]
4849

4950
# test when not sparse
5051
prob = ODEProblem(sys, u0, (0, 11.5), sparse=false, jac=true)
@@ -55,10 +56,12 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse=false, jac=false)
5556

5657
# test when u0 is nothing
5758
f = DiffEqBase.ODEFunction(sys, u0=nothing, sparse=true, jac=true)
58-
@test f.jac_prototype == nothing
59+
@test findnz(f.jac_prototype)[1:2] == findnz(JP)[1:2]
60+
@test eltype(f.jac_prototype) == Float64
5961

6062
f = DiffEqBase.ODEFunction(sys, u0=nothing, sparse=true, jac=false)
61-
@test f.jac_prototype == nothing
63+
@test findnz(f.jac_prototype)[1:2] == findnz(JP)[1:2]
64+
@test eltype(f.jac_prototype) == Float64
6265

6366
# test when u0 is not Float64
6467
u0 = similar(init_brusselator_2d(xyd_brusselator), Float32)

0 commit comments

Comments
 (0)