@@ -74,7 +74,7 @@ f = DiffEqBase.ODEFunction(sys, u0 = nothing, sparse = true, jac = false)
7474# test when u0 is not Float64
7575u0 = similar (init_brusselator_2d (xyd_brusselator), Float32)
7676prob_ode_brusselator_2d = ODEProblem (brusselator_2d_loop,
77- u0, (0.0 , 11.5 ), p)
77+ u0, (0.0 , 11.5 ), p)
7878sys = complete (modelingtoolkitize (prob_ode_brusselator_2d))
7979
8080prob = 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)
9494 @mtkbuild pend = ODESystem (eqs, t)
9595
9696 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 )
9899 jac, jac! = generate_jacobian (pend; expression = Val{false }, sparse = true )
99100 jac_prototype = ModelingToolkit. jacobian_sparsity (pend)
100101 W_prototype = ModelingToolkit. W_sparsity (pend)
@@ -109,8 +110,28 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
109110 @test_throws AssertionError jac! (similar (jac_prototype, Float64), u, p, t)
110111
111112 W, W! = generate_W (pend; expression = Val{false }, sparse = true )
112- γ = .1
113+ γ = 0 .1
113114 M = sparse (calculate_massmatrix (pend))
114115 @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 )
116137end
0 commit comments