@@ -112,14 +112,18 @@ prob = ODEProblem(ss, [x => 0.1], (0.0, Tf),
112
112
[kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ])
113
113
# create integrator so callback is evaluated at t=0 and we can test correct param values
114
114
int = 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
116
118
sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
117
119
118
120
ss_nosplit = structural_simplify (sys; split = false )
119
121
prob_nosplit = ODEProblem (ss_nosplit, [x => 0.1 ], (0.0 , Tf),
120
122
[kp => 1.0 ; ud => 2.1 ; ud (k - 1 ) => 2.0 ])
121
123
int = 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
123
127
sol_nosplit = solve (prob_nosplit, Tsit5 (), kwargshandle = KeywordArgSilent)
124
128
# For all inputs in parameters, just initialize them to 0.0, and then set them
125
129
# in the callback.
@@ -145,7 +149,8 @@ function affect!(integrator, saved_values)
145
149
nothing
146
150
end
147
151
saved_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 )
149
154
# kp ud
150
155
prob = ODEProblem (foo!, [0.1 ], (0.0 , Tf), [1.0 , 2.1 , 2.0 ], callback = cb)
151
156
sol2 = solve (prob, Tsit5 ())
@@ -308,8 +313,8 @@ if VERSION >= v"1.7"
308
313
integrator. p[3 ] = ud2
309
314
nothing
310
315
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 )
313
318
cb = CallbackSet (cb1, cb2)
314
319
# kp ud1 ud2
315
320
prob = ODEProblem (foo!, [0.0 ], (0.0 , 1.0 ), [1.0 , 1.0 , 1.0 ], callback = cb)
@@ -438,10 +443,10 @@ y = res.y[:]
438
443
prob = ODEProblem (ssys,
439
444
[model. plant. x => 0.0 ; model. controller. kp => 2.0 ; model. controller. ki => 2.0 ],
440
445
(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
445
450
sol = solve (prob,
446
451
Tsit5 (),
447
452
kwargshandle = KeywordArgSilent,
0 commit comments