@@ -3,7 +3,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEqTsit5
33using ModelingToolkitStandardLibrary. Blocks
44using ModelingToolkit: t_nounits as t, D_nounits as D
55using OrdinaryDiffEqTsit5: ReturnCode. Success
6- using JuliaSimCompiler
6+ using SynchToolkit
77using Test
88Difference = ModelingToolkitSampledData. Difference
99
@@ -31,7 +31,7 @@ an integrator with a constant input is often used together with the system under
3131
3232 @named model = TestDiscreteOnly ()
3333 model = complete (model)
34- ssys = structural_simplify (IRSystem ( model) )
34+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
3535 prob = ODEProblem (ssys, [model. x (k- 1 ) => 1.0 ], (0.0 , 10.0 ))
3636 sol = solve (prob, Tsit5 ())
3737 @test sol[model. x] == dt .^ (1 : 21 )
5353 t,
5454 systems = [sampler, int, intc, c])
5555 model = complete (iosys)
56- sys = structural_simplify (IRSystem ( model) )
56+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
5757 prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
5858 int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
5959 sol = solve (prob, Tsit5 ())
7070 t,
7171 systems = [sampler, int, intc, c])
7272 model = complete (iosys)
73- sys = structural_simplify (IRSystem ( model) )
73+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
7474 prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
7575 int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
7676 sol = solve (prob, Tsit5 ())
8888 t,
8989 systems = [sampler, int, intc, c])
9090 model = complete (iosys)
91- sys = structural_simplify (IRSystem ( model) )
91+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
9292 prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
9393 int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
9494 sol = solve (prob, Tsit5 ())
128128@named model = ClosedLoop ()
129129model = complete (model)
130130# ci, varmap = infer_clocks(expand_connections(model))
131- ssys = structural_simplify (IRSystem ( model) )
131+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
132132
133133Tf = 5
134134timevec = 0 : (dt): Tf
197197@named model = ClosedLoop ()
198198model = complete (model)
199199# ci, varmap = infer_clocks(expand_connections(model))
200- ssys = structural_simplify (IRSystem ( model) )
200+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
201201
202202Tf = 5
203203timevec = 0 : (dt): Tf
256256
257257 @named m = DelayModel ()
258258 m = complete (m)
259- ssys = structural_simplify (IRSystem (m) )
259+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
260260 prob = ODEProblem (
261261 ssys, [m. delay. u (k - 3 ) => 0 , m. delay. u (k - 2 ) => 0 , m. delay. u (k - 1 ) => 0 ], (
262262 0.0 , 10.0 ))
@@ -289,7 +289,7 @@ using ModelingToolkitStandardLibrary.Blocks
289289
290290 @named m = DiffModel ()
291291 m = complete (m)
292- ssys = structural_simplify (IRSystem (m) )
292+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
293293 prob = ODEProblem (ssys, Dict (m. diff. u (k - 1 ) => 0 ), (0.0 , 10.0 ))
294294 sol = solve (prob, Tsit5 (), dtmax = 0.01 )
295295 @test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (2 ); 1 ; zeros (8 )] atol= 1e-2
@@ -319,7 +319,7 @@ using Statistics
319319
320320 @named m = NoiseModel ()
321321 m = complete (m)
322- ssys = structural_simplify (IRSystem (m) )
322+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
323323 prob = ODEProblem (ssys, [m. noise. y (k- 1 ) => 0 ], (0.0 , 10.0 ))
324324 sol = solve (prob, Tsit5 ())
325325 @test ! all (iszero, sol. u)
345345
346346 @named m = NoiseModel ()
347347 m = complete (m)
348- ssys = structural_simplify (IRSystem (m) )
348+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
349349 prob = ODEProblem (ssys, [m. noise. y (k- 1 ) => 0 ], (0.0 , 10.0 ))
350350 sol = solve (prob, Tsit5 ())
351351 @test ! all (iszero, sol. u)
375375
376376# @named m = PlantModel()
377377# m = complete(m)
378- # ssys = structural_simplify(IRSystem(m) )
378+ # ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre] )
379379# prob = ODEProblem(ssys, Dict(m.plant.u(k - 1) => 0), (0.0, 10.0))
380380# sol = solve(prob, Tsit5(), dtmax = 0.01)
381381# @test reduce(vcat, sol((0:10) .+ 1e-2))[:]≈[zeros(2); 1; zeros(8)] atol=1e-2
401401 end
402402 @named m = SlewRateLimiterModel ()
403403 m = complete (m)
404- ssys = structural_simplify (IRSystem (m) )
404+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
405405 prob = ODEProblem (ssys, [m. limiter. y (z- 1 ) => 0 ], (0.0 , 2.0 ))
406406 sol = solve (prob, Tsit5 (), dtmax= 0.01 )
407407 # plot(sol, idxs=[m.input.output.u, m.limiter.y], title="Slew rate limited sine wave")
457457 end
458458 @named m = QuantizationModel ()
459459 m = complete (m)
460- ssys = structural_simplify (IRSystem (m) )
460+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
461461 prob = ODEProblem (ssys, [], (0.0 , 10.0 ))
462462 sol = solve (prob, Tsit5 (), dtmax= 0.01 )
463463 y = sol[m. quant. y]
476476 end
477477 @named m = QuantizationModel2 ()
478478 m = complete (m)
479- ssys = structural_simplify (IRSystem (m) )
479+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
480480 prob = ODEProblem (ssys, [], (0.0 , 10.0 ))
481481 sol = solve (prob, Tsit5 (), dtmax= 0.01 )
482482 y = sol[m. quant. y]
505505 end
506506 @named m = OnOffModel ()
507507 m = complete (m)
508- ssys = structural_simplify (IRSystem (m) )
508+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
509509 prob = ODEProblem (ssys, [m. onoff. y (z- 1 ) => 0 ], (0.0 , 4.0 ))
510510 sol = solve (prob, Tsit5 (), dtmax= 0.1 )
511511 # plot(sol, idxs=[m.x, m.onoff.y], title="On-off control of an unstable first-order system")
530530 end
531531 @named m = ExponentialFilterModel ()
532532 m = complete (m)
533- ssys = structural_simplify (IRSystem (m) )
533+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
534534 prob = ODEProblem (ssys, [m. filter. y (z- 1 ) => 0 ], (0.0 , 10.0 ))
535535 sol = solve (prob, Tsit5 (), dtmax= 0.1 )
536536 @test sol (10 , idxs= m. filter. y) ≈ 1 atol= 0.001
558558
559559 @named m = MovingAverageFilterModel ()
560560 m = complete (m)
561- ssys = structural_simplify (IRSystem (m) )
561+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
562562 prob = ODEProblem (ssys, [m. filter. u (z- i) => 0 for i = 0 : 3 ], (0.0 , 2.0 ))
563563 sol = solve (prob, Tsit5 (), dtmax= 0.1 )
564564 # plot(sol, idxs=m.filter.y)
587587 end
588588 @named m = PracticalSamplerModel ()
589589 m = complete (m)
590- ssys = structural_simplify (IRSystem (m) )
590+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
591591 prob = ODEProblem (ssys, [m. sampling. noise. y (z- 1 ) => 0 ], (0.0 , 2.0 ))
592592 sol = solve (prob, Tsit5 ())
593593
0 commit comments