@@ -235,50 +235,56 @@ end
235
235
# # Delay
236
236
# ==============================================================================
237
237
238
- @mtkmodel DelayModel begin
239
- @components begin
240
- fake_plant = FirstOrder (T = 1e-4 ) # Included due to bug with only discrete-time systems
241
- input = Step (start_time = 2 , smooth = false )
242
- sampler = Sampler (; dt = 1 )
243
- delay = Delay (n = 3 )
244
- zoh = ZeroOrderHold ()
245
- end
246
- @equations begin
247
- connect (input. output, sampler. input)
248
- connect (sampler. output, delay. input)
249
- connect (delay. output, zoh. input)
250
- connect (zoh. output, fake_plant. input)
238
+ @testset " delay" begin
239
+ @mtkmodel DelayModel begin
240
+ @components begin
241
+ fake_plant = FirstOrder (T = 1e-4 ) # Included due to bug with only discrete-time systems
242
+ input = Step (start_time = 2 , smooth = false )
243
+ sampler = Sampler (; dt = 1 )
244
+ delay = Delay (n = 3 )
245
+ zoh = ZeroOrderHold ()
246
+ end
247
+ @equations begin
248
+ connect (input. output, sampler. input)
249
+ connect (sampler. output, delay. input)
250
+ connect (delay. output, zoh. input)
251
+ connect (zoh. output, fake_plant. input)
252
+ end
251
253
end
252
- end
253
254
254
- @mtkbuild m = DelayModel ()
255
- prob = ODEProblem (
256
- m, [m. delay. u (k - 3 ) => 0 , m. delay. u (k - 2 ) => 0 , m. delay. u (k - 1 ) => 0 ], (0.0 , 10.0 ))
257
- sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
255
+ @mtkbuild m = DelayModel ()
256
+ prob = ODEProblem (
257
+ m, [m. delay. u (k - 3 ) => 0 , m. delay. u (k - 2 ) => 0 , m. delay. u (k - 1 ) => 0 ], (
258
+ 0.0 , 10.0 ))
259
+ sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
258
260
259
- @test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (5 ); ones (6 )] atol= 1e-2
261
+ @test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (5 ); ones (6 )] atol= 1e-2
262
+ end
260
263
261
264
# ==============================================================================
262
265
# # Difference
263
266
# ==============================================================================
264
267
using ModelingToolkitStandardLibrary. Blocks
265
- k = ShiftIndex (Clock (t, 1 ))
266
268
267
- @mtkmodel DiffModel begin
268
- @components begin
269
- input = Step (start_time = 2 , smooth = false )
270
- diff = Blocks. Difference (z = k)
271
- zoh = Blocks. ZeroOrderHold ()
272
- plant = FirstOrder (T = 1e-4 ) # Included due to bug with only discrete-time systems
273
- end
274
- @equations begin
275
- connect (input. output, diff. input)
276
- connect (diff. output, zoh. input)
277
- connect (zoh. output, plant. input)
269
+ @testset " Difference" begin
270
+ k = ShiftIndex (Clock (t, 1 ))
271
+
272
+ @mtkmodel DiffModel begin
273
+ @components begin
274
+ input = Step (start_time = 2 , smooth = false )
275
+ diff = Blocks. Difference (z = k)
276
+ zoh = Blocks. ZeroOrderHold ()
277
+ plant = FirstOrder (T = 1e-4 ) # Included due to bug with only discrete-time systems
278
+ end
279
+ @equations begin
280
+ connect (input. output, diff. input)
281
+ connect (diff. output, zoh. input)
282
+ connect (zoh. output, plant. input)
283
+ end
278
284
end
279
- end
280
285
281
- @mtkbuild m = DiffModel ()
282
- prob = ODEProblem (m, Dict (m. diff. u (k - 1 ) => 0 ), (0.0 , 10.0 ))
283
- sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent)
284
- @test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (2 ); 1 ; zeros (8 )] atol= 1e-2
286
+ @mtkbuild m = DiffModel ()
287
+ prob = ODEProblem (m, Dict (m. diff. u (k - 1 ) => 0 ), (0.0 , 10.0 ))
288
+ sol = solve (prob, Tsit5 (), kwargshandle = KeywordArgSilent, dtmax = 0.01 )
289
+ @test reduce (vcat, sol ((0 : 10 ) .+ 1e-2 ))[:]≈ [zeros (2 ); 1 ; zeros (8 )] atol= 1e-2
290
+ end
0 commit comments