@@ -211,6 +211,8 @@ affect = [v ~ -v]
211
211
@test getfield (ball, :continuous_events )[] == SymbolicContinuousCallback (Equation[x ~ 0 ], Equation[v ~ - v])
212
212
ball = structural_simplify (ball)
213
213
214
+ @test length (ModelingToolkit. continuous_events (ball)) == 1
215
+
214
216
tspan = (0.0 ,5.0 )
215
217
prob = ODEProblem (ball, Pair[], tspan)
216
218
sol = solve (prob,Tsit5 ())
@@ -305,3 +307,52 @@ prob = ODAEProblem(sys, zeros(2), (0.0, 5.1))
305
307
sol = solve (prob, Tsit5 ())
306
308
@test all (minimum ((0 : 0.1 : 5 ) .- sol. t' , dims= 2 ) .< 0.0001 ) # test that the solver stepped every 0.1s as dictated by event
307
309
@test sol ([0.25 ])[vmeasured][] == sol ([0.23 ])[vmeasured][] # test the hold property
310
+
311
+
312
+
313
+ # # https://github.com/SciML/ModelingToolkit.jl/issues/1528
314
+ Dₜ = Differential (t)
315
+
316
+ @parameters u (t) [input= true ] # Indicate that this is a controlled input
317
+ @parameters y (t) [output= true ] # Indicate that this is a measured output
318
+
319
+ function Mass (; name, m = 1.0 , p = 0 , v = 0 )
320
+ ps = @parameters m= m
321
+ sts = @variables pos (t)= p vel (t)= v
322
+ eqs = Dₜ (pos) ~ vel
323
+ ODESystem (eqs, t, [pos, vel], ps; name)
324
+ end
325
+ function Spring (; name, k = 1e4 )
326
+ ps = @parameters k= k
327
+ @variables x (t)= 0 # Spring deflection
328
+ ODESystem (Equation[], t, [x], ps; name)
329
+ end
330
+ function Damper (; name, c = 10 )
331
+ ps = @parameters c= c
332
+ @variables vel (t)= 0
333
+ ODESystem (Equation[], t, [vel], ps; name)
334
+ end
335
+ function SpringDamper (; name, k= false , c= false )
336
+ spring = Spring (; name= :spring , k)
337
+ damper = Damper (; name= :damper , c)
338
+ compose (
339
+ ODESystem (Equation[], t; name),
340
+ spring, damper)
341
+ end
342
+ connect_sd (sd, m1, m2) = [sd. spring. x ~ m1. pos - m2. pos, sd. damper. vel ~ m1. vel - m2. vel]
343
+ sd_force (sd) = - sd. spring. k * sd. spring. x - sd. damper. c * sd. damper. vel
344
+ @named mass1 = Mass (; m= 1 )
345
+ @named mass2 = Mass (; m= 1 )
346
+ @named sd = SpringDamper (; k= 1000 , c= 10 )
347
+ function Model (u, d= 0 )
348
+ eqs = [
349
+ connect_sd (sd, mass1, mass2)
350
+ Dₜ (mass1. vel) ~ ( sd_force (sd) + u) / mass1. m
351
+ Dₜ (mass2. vel) ~ (- sd_force (sd) + d) / mass2. m
352
+ ]
353
+ @named _model = ODESystem (eqs, t; observed= [y~ mass2. pos])
354
+ @named model = compose (_model, mass1, mass2, sd)
355
+ end
356
+ model = Model (sin (30 t))
357
+ sys = structural_simplify (model)
358
+ @test isempty (ModelingToolkit. continuous_events (sys))
0 commit comments