@@ -112,14 +112,18 @@ prob = ODEProblem(ss, [x => 0.1], (0.0, Tf),
112112 [kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ])
113113# create integrator so callback is evaluated at t=0 and we can test correct param values
114114int = init (prob, Tsit5 (); kwargshandle = KeywordArgSilent)
115- @test sort (vcat (int. p... )) == [0.1 , 1.0 , 2.0 , 2.1 , 2.1 ] # yd, kp, ud(k-1), ud, Hold(ud)
115+ @test sort (vcat (int. p... )) == [0.1 , 1.0 , 2.1 , 2.1 , 2.1 ] # yd, kp, ud(k-1), ud, Hold(ud)
116+ prob = ODEProblem (ss, [x => 0.1 ], (0.0 , Tf),
117+ [kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ]) # recreate problem to empty saved values
116118sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
117119
118120ss_nosplit = structural_simplify (sys; split = false )
119121prob_nosplit = ODEProblem (ss_nosplit, [x => 0.1 ], (0.0 , Tf),
120122 [kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ])
121123int = init (prob_nosplit, Tsit5 (); kwargshandle = KeywordArgSilent)
122- @test sort (int. p) == [0.1 , 1.0 , 2.0 , 2.1 , 2.1 ] # yd, kp, ud(k-1), ud, Hold(ud)
124+ @test sort (int. p) == [0.1 , 1.0 , 2.1 , 2.1 , 2.1 ] # yd, kp, ud(k-1), ud, Hold(ud)
125+ prob_nosplit = ODEProblem (ss_nosplit, [x => 0.1 ], (0.0 , Tf),
126+ [kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ]) # recreate problem to empty saved values
123127sol_nosplit = solve (prob_nosplit, Tsit5 (), kwargshandle = KeywordArgSilent)
124128# For all inputs in parameters, just initialize them to 0.0, and then set them
125129# in the callback.
@@ -145,7 +149,8 @@ function affect!(integrator, saved_values)
145149 nothing
146150end
147151saved_values = SavedValues (Float64, Vector{Float64})
148- cb = PeriodicCallback (Base. Fix2 (affect!, saved_values), 0.1 ; final_affect = true )
152+ cb = PeriodicCallback (
153+ Base. Fix2 (affect!, saved_values), 0.1 ; final_affect = true , initial_affect = true )
149154# kp ud
150155prob = ODEProblem (foo!, [0.1 ], (0.0 , Tf), [1.0 , 2.1 , 2.0 ], callback = cb)
151156sol2 = solve (prob, Tsit5 ())
@@ -308,8 +313,8 @@ if VERSION >= v"1.7"
308313 integrator. p[3 ] = ud2
309314 nothing
310315 end
311- cb1 = PeriodicCallback (affect1!, dt; final_affect = true )
312- cb2 = PeriodicCallback (affect2!, dt2; final_affect = true )
316+ cb1 = PeriodicCallback (affect1!, dt; final_affect = true , initial_affect = true )
317+ cb2 = PeriodicCallback (affect2!, dt2; final_affect = true , initial_affect = true )
313318 cb = CallbackSet (cb1, cb2)
314319 # kp ud1 ud2
315320 prob = ODEProblem (foo!, [0.0 ], (0.0 , 1.0 ), [1.0 , 1.0 , 1.0 ], callback = cb)
@@ -438,10 +443,10 @@ y = res.y[:]
438443prob = ODEProblem (ssys,
439444 [model. plant. x => 0.0 ; model. controller. kp => 2.0 ; model. controller. ki => 2.0 ],
440445 (0.0 , Tf))
441-
442- @test prob . ps[Hold (ssys. holder. input. u)] == 1 # constant output * kp issue https://github.com/SciML/ModelingToolkit.jl/issues/2356
443- @test prob . ps[ssys. controller. x] == 0 # c2d
444- @test prob . ps[Sample (d)(ssys. sampler. input. u)] == 0 # disc state
446+ int = init (prob, Tsit5 (); kwargshandle = KeywordArgSilent)
447+ @test int . ps[Hold (ssys. holder. input. u)] == 2 # constant output * kp issue https://github.com/SciML/ModelingToolkit.jl/issues/2356
448+ @test int . ps[ssys. controller. x] == 1 # c2d
449+ @test int . ps[Sample (d)(ssys. sampler. input. u)] == 0 # disc state
445450sol = solve (prob,
446451 Tsit5 (),
447452 kwargshandle = KeywordArgSilent,
0 commit comments