@@ -298,44 +298,42 @@ eqs = [yd ~ Sample(dt)(y)
298298 ss = mtkcompile (cl)
299299 ss_nosplit = mtkcompile (cl; split = false )
300300
301- if VERSION >= v " 1.7"
302- prob = ODEProblem (ss, [x => 0.0 , kp => 1.0 ], (0.0 , 1.0 ))
303- prob_nosplit = ODEProblem (ss_nosplit, [x => 0.0 , kp => 1.0 ], (0.0 , 1.0 ))
304- sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
305- sol_nosplit = solve (prob_nosplit, Tsit5 (), kwargshandle = KeywordArgSilent)
306-
307- function foo! (dx, x, p, t)
308- kp, ud1, ud2 = p
309- dx[1 ] = - x[1 ] + ud1 + ud2
310- end
301+ prob = ODEProblem (ss, [x => 0.0 , kp => 1.0 ], (0.0 , 1.0 ))
302+ prob_nosplit = ODEProblem (ss_nosplit, [x => 0.0 , kp => 1.0 ], (0.0 , 1.0 ))
303+ sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
304+ sol_nosplit = solve (prob_nosplit, Tsit5 (), kwargshandle = KeywordArgSilent)
311305
312- function affect1! (integrator)
313- kp = integrator. p[1 ]
314- y = integrator. u[1 ]
315- r = 1.0
316- ud1 = kp * (r - y)
317- integrator. p[2 ] = ud1
318- nothing
319- end
320- function affect2! (integrator)
321- kp = integrator. p[1 ]
322- y = integrator. u[1 ]
323- r = 1.0
324- ud2 = kp * (r - y)
325- integrator. p[3 ] = ud2
326- nothing
327- end
328- cb1 = PeriodicCallback (affect1!, dt; final_affect = true , initial_affect = true )
329- cb2 = PeriodicCallback (affect2!, dt2; final_affect = true , initial_affect = true )
330- cb = CallbackSet (cb1, cb2)
331- # kp ud1 ud2
332- prob = ODEProblem (foo!, [0.0 ], (0.0 , 1.0 ), [1.0 , 1.0 , 1.0 ], callback = cb)
333- sol2 = solve (prob, Tsit5 ())
334-
335- @test sol. u≈ sol2. u atol= 1e-6
336- @test sol_nosplit. u≈ sol2. u atol= 1e-6
306+ function foo! (dx, x, p, t)
307+ kp, ud1, ud2 = p
308+ dx[1 ] = - x[1 ] + ud1 + ud2
337309 end
338310
311+ function affect1! (integrator)
312+ kp = integrator. p[1 ]
313+ y = integrator. u[1 ]
314+ r = 1.0
315+ ud1 = kp * (r - y)
316+ integrator. p[2 ] = ud1
317+ nothing
318+ end
319+ function affect2! (integrator)
320+ kp = integrator. p[1 ]
321+ y = integrator. u[1 ]
322+ r = 1.0
323+ ud2 = kp * (r - y)
324+ integrator. p[3 ] = ud2
325+ nothing
326+ end
327+ cb1 = PeriodicCallback (affect1!, dt; final_affect = true , initial_affect = true )
328+ cb2 = PeriodicCallback (affect2!, dt2; final_affect = true , initial_affect = true )
329+ cb = CallbackSet (cb1, cb2)
330+ # kp ud1 ud2
331+ prob = ODEProblem (foo!, [0.0 ], (0.0 , 1.0 ), [1.0 , 1.0 , 1.0 ], callback = cb)
332+ sol2 = solve (prob, Tsit5 ())
333+
334+ @test sol. u≈ sol2. u atol= 1e-6
335+ @test sol_nosplit. u≈ sol2. u atol= 1e-6
336+
339337 # #
340338 @info " Testing hybrid system with components"
341339 using ModelingToolkitStandardLibrary. Blocks
0 commit comments