@@ -3,7 +3,7 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEqTsit5
3
3
using ModelingToolkitStandardLibrary. Blocks
4
4
using ModelingToolkit: t_nounits as t, D_nounits as D
5
5
using OrdinaryDiffEqTsit5: ReturnCode. Success
6
- using JuliaSimCompiler
6
+ using SynchToolkit
7
7
using Test
8
8
Difference = ModelingToolkitSampledData. Difference
9
9
@@ -31,7 +31,7 @@ an integrator with a constant input is often used together with the system under
31
31
32
32
@named model = TestDiscreteOnly ()
33
33
model = complete (model)
34
- ssys = structural_simplify (IRSystem ( model) )
34
+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
35
35
prob = ODEProblem (ssys, [model. x (k- 1 ) => 1.0 ], (0.0 , 10.0 ))
36
36
sol = solve (prob, Tsit5 ())
37
37
@test sol[model. x] == dt .^ (1 : 21 )
53
53
t,
54
54
systems = [sampler, int, intc, c])
55
55
model = complete (iosys)
56
- sys = structural_simplify (IRSystem ( model) )
56
+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
57
57
prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
58
58
int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
59
59
sol = solve (prob, Tsit5 ())
70
70
t,
71
71
systems = [sampler, int, intc, c])
72
72
model = complete (iosys)
73
- sys = structural_simplify (IRSystem ( model) )
73
+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
74
74
prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
75
75
int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
76
76
sol = solve (prob, Tsit5 ())
88
88
t,
89
89
systems = [sampler, int, intc, c])
90
90
model = complete (iosys)
91
- sys = structural_simplify (IRSystem ( model) )
91
+ sys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
92
92
prob = ODEProblem (sys, Pair[int. x (k - 1 ) => 1
93
93
int. u (k - 1 ) => 0 ], (0.0 , 1.0 ))
94
94
sol = solve (prob, Tsit5 ())
128
128
@named model = ClosedLoop ()
129
129
model = complete (model)
130
130
# ci, varmap = infer_clocks(expand_connections(model))
131
- ssys = structural_simplify (IRSystem ( model) )
131
+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
132
132
133
133
Tf = 5
134
134
timevec = 0 : (dt): Tf
197
197
@named model = ClosedLoop ()
198
198
model = complete (model)
199
199
# ci, varmap = infer_clocks(expand_connections(model))
200
- ssys = structural_simplify (IRSystem ( model) )
200
+ ssys = structural_simplify (model; additional_passes = [SynchToolkit . compile_lustre] )
201
201
202
202
Tf = 5
203
203
timevec = 0 : (dt): Tf
256
256
257
257
@named m = DelayModel ()
258
258
m = complete (m)
259
- ssys = structural_simplify (IRSystem (m) )
259
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
260
260
prob = ODEProblem (
261
261
ssys, [m. delay. u (k - 3 ) => 0 , m. delay. u (k - 2 ) => 0 , m. delay. u (k - 1 ) => 0 ], (
262
262
0.0 , 10.0 ))
@@ -289,7 +289,7 @@ using ModelingToolkitStandardLibrary.Blocks
289
289
290
290
@named m = DiffModel ()
291
291
m = complete (m)
292
- ssys = structural_simplify (IRSystem (m) )
292
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
293
293
prob = ODEProblem (ssys, Dict (m. diff. u (k - 1 ) => 0 ), (0.0 , 10.0 ))
294
294
sol = solve (prob, Tsit5 (), dtmax = 0.01 )
295
295
@test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (2 ); 1 ; zeros (8 )] atol= 1e-2
@@ -319,7 +319,7 @@ using Statistics
319
319
320
320
@named m = NoiseModel ()
321
321
m = complete (m)
322
- ssys = structural_simplify (IRSystem (m) )
322
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
323
323
prob = ODEProblem (ssys, [m. noise. y (k- 1 ) => 0 ], (0.0 , 10.0 ))
324
324
sol = solve (prob, Tsit5 ())
325
325
@test ! all (iszero, sol. u)
345
345
346
346
@named m = NoiseModel ()
347
347
m = complete (m)
348
- ssys = structural_simplify (IRSystem (m) )
348
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
349
349
prob = ODEProblem (ssys, [m. noise. y (k- 1 ) => 0 ], (0.0 , 10.0 ))
350
350
sol = solve (prob, Tsit5 ())
351
351
@test ! all (iszero, sol. u)
375
375
376
376
# @named m = PlantModel()
377
377
# m = complete(m)
378
- # ssys = structural_simplify(IRSystem(m) )
378
+ # ssys = structural_simplify(m; additional_passes=[SynchToolkit.compile_lustre] )
379
379
# prob = ODEProblem(ssys, Dict(m.plant.u(k - 1) => 0), (0.0, 10.0))
380
380
# sol = solve(prob, Tsit5(), dtmax = 0.01)
381
381
# @test reduce(vcat, sol((0:10) .+ 1e-2))[:]≈[zeros(2); 1; zeros(8)] atol=1e-2
401
401
end
402
402
@named m = SlewRateLimiterModel ()
403
403
m = complete (m)
404
- ssys = structural_simplify (IRSystem (m) )
404
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
405
405
prob = ODEProblem (ssys, [m. limiter. y (z- 1 ) => 0 ], (0.0 , 2.0 ))
406
406
sol = solve (prob, Tsit5 (), dtmax= 0.01 )
407
407
# plot(sol, idxs=[m.input.output.u, m.limiter.y], title="Slew rate limited sine wave")
457
457
end
458
458
@named m = QuantizationModel ()
459
459
m = complete (m)
460
- ssys = structural_simplify (IRSystem (m) )
460
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
461
461
prob = ODEProblem (ssys, [], (0.0 , 10.0 ))
462
462
sol = solve (prob, Tsit5 (), dtmax= 0.01 )
463
463
y = sol[m. quant. y]
476
476
end
477
477
@named m = QuantizationModel2 ()
478
478
m = complete (m)
479
- ssys = structural_simplify (IRSystem (m) )
479
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
480
480
prob = ODEProblem (ssys, [], (0.0 , 10.0 ))
481
481
sol = solve (prob, Tsit5 (), dtmax= 0.01 )
482
482
y = sol[m. quant. y]
505
505
end
506
506
@named m = OnOffModel ()
507
507
m = complete (m)
508
- ssys = structural_simplify (IRSystem (m) )
508
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
509
509
prob = ODEProblem (ssys, [m. onoff. y (z- 1 ) => 0 ], (0.0 , 4.0 ))
510
510
sol = solve (prob, Tsit5 (), dtmax= 0.1 )
511
511
# plot(sol, idxs=[m.x, m.onoff.y], title="On-off control of an unstable first-order system")
530
530
end
531
531
@named m = ExponentialFilterModel ()
532
532
m = complete (m)
533
- ssys = structural_simplify (IRSystem (m) )
533
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
534
534
prob = ODEProblem (ssys, [m. filter. y (z- 1 ) => 0 ], (0.0 , 10.0 ))
535
535
sol = solve (prob, Tsit5 (), dtmax= 0.1 )
536
536
@test sol (10 , idxs= m. filter. y) ≈ 1 atol= 0.001
558
558
559
559
@named m = MovingAverageFilterModel ()
560
560
m = complete (m)
561
- ssys = structural_simplify (IRSystem (m) )
561
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
562
562
prob = ODEProblem (ssys, [m. filter. u (z- i) => 0 for i = 0 : 3 ], (0.0 , 2.0 ))
563
563
sol = solve (prob, Tsit5 (), dtmax= 0.1 )
564
564
# plot(sol, idxs=m.filter.y)
587
587
end
588
588
@named m = PracticalSamplerModel ()
589
589
m = complete (m)
590
- ssys = structural_simplify (IRSystem (m) )
590
+ ssys = structural_simplify (m; additional_passes = [SynchToolkit . compile_lustre] )
591
591
prob = ODEProblem (ssys, [m. sampling. noise. y (z- 1 ) => 0 ], (0.0 , 2.0 ))
592
592
sol = solve (prob, Tsit5 ())
593
593
0 commit comments