@@ -74,7 +74,7 @@ f = DiffEqBase.ODEFunction(sys, u0 = nothing, sparse = true, jac = false)
74
74
# test when u0 is not Float64
75
75
u0 = similar (init_brusselator_2d (xyd_brusselator), Float32)
76
76
prob_ode_brusselator_2d = ODEProblem (brusselator_2d_loop,
77
- u0, (0.0 , 11.5 ), p)
77
+ u0, (0.0 , 11.5 ), p)
78
78
sys = complete (modelingtoolkitize (prob_ode_brusselator_2d))
79
79
80
80
prob = ODEProblem (sys, u0, (0 , 11.5 ), sparse = true , jac = false )
@@ -94,7 +94,8 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
94
94
@mtkbuild pend = ODESystem (eqs, t)
95
95
96
96
u0 = [x => 1 , y => 0 ]
97
- prob = ODEProblem (pend, u0, (0 , 11.5 ), [g => 1 ], guesses = [λ => 1 ], sparse = true , jac = true )
97
+ prob = ODEProblem (
98
+ pend, u0, (0 , 11.5 ), [g => 1 ], guesses = [λ => 1 ], sparse = true , jac = true )
98
99
jac, jac! = generate_jacobian (pend; expression = Val{false }, sparse = true )
99
100
jac_prototype = ModelingToolkit. jacobian_sparsity (pend)
100
101
W_prototype = ModelingToolkit. W_sparsity (pend)
@@ -109,8 +110,28 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
109
110
@test_throws AssertionError jac! (similar (jac_prototype, Float64), u, p, t)
110
111
111
112
W, W! = generate_W (pend; expression = Val{false }, sparse = true )
112
- γ = .1
113
+ γ = 0 .1
113
114
M = sparse (calculate_massmatrix (pend))
114
115
@test_throws AssertionError W! (similar (jac_prototype, Float64), u, p, γ, t)
115
- @test W! (similar (W_prototype, Float64), u, p, γ, t) == 0.1 * M + jac! (similar (W_prototype, Float64), u, p, t)
116
+ @test W! (similar (W_prototype, Float64), u, p, γ, t) ==
117
+ 0.1 * M + jac! (similar (W_prototype, Float64), u, p, t)
118
+ end
119
+
120
+ @testset " Issue#3556: Numerical accuracy" begin
121
+ t = ModelingToolkit. t_nounits
122
+ D = ModelingToolkit. D_nounits
123
+ @parameters g
124
+ @variables x (t) y (t) [state_priority = 10 ] λ (t)
125
+ eqs = [D (D (x)) ~ λ * x
126
+ D (D (y)) ~ λ * y - g
127
+ x^ 2 + y^ 2 ~ 1 ]
128
+ @mtkbuild pend = ODESystem (eqs, t)
129
+ prob = ODEProblem (pend, [x => 0.0 , D (x) => 1.0 ], (0.0 , 1.0 ), [g => 1.0 ];
130
+ guesses = [y => 1.0 , λ => 1.0 ], jac = true , sparse = true )
131
+ J = deepcopy (prob. f. jac_prototype)
132
+ prob. f. jac (J, prob. u0, prob. p, 1.0 )
133
+ # this currently works but may not continue to do so
134
+ # see https://github.com/SciML/ModelingToolkit.jl/pull/3556#issuecomment-2792664039
135
+ @test J == prob. f. jac (prob. u0, prob. p, 1.0 )
136
+ @test J ≈ prob. f. jac (prob. u0, prob. p, 1.0 )
116
137
end
0 commit comments