1
1
using OrdinaryDiffEq, ModelingToolkit, Test, SparseArrays
2
2
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)
5
5
brusselator_f (x, y, t) = (((x- 0.3 )^ 2 + (y- 0.6 )^ 2 ) <= 0.1 ^ 2 ) * (t >= 1.1 ) * 5.
6
6
limit (a, N) = ModelingToolkit. ifelse (a == N+ 1 , 1 , ModelingToolkit. ifelse (a == 0 , N, a))
7
7
function brusselator_2d_loop (du, u, p, t)
@@ -40,11 +40,12 @@ sys = modelingtoolkitize(prob_ode_brusselator_2d)
40
40
41
41
# test sparse jacobian pattern only.
42
42
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 ]
44
45
45
46
# test sparse jacobian
46
47
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 ]
48
49
49
50
# test when not sparse
50
51
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)
55
56
56
57
# test when u0 is nothing
57
58
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
59
61
60
62
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
62
65
63
66
# test when u0 is not Float64
64
67
u0 = similar (init_brusselator_2d (xyd_brusselator), Float32)
0 commit comments