You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/basics/Composition.md
+8-170Lines changed: 8 additions & 170 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -248,173 +248,11 @@ solving. In summary: these problems are structurally modified, but could be
248
248
more efficient and more stable.
249
249
250
250
## Components with discontinuous dynamics
251
-
When modeling, e.g., impacts, saturations or Coulomb friction, the dynamic equations are discontinuous in either the state or one of its derivatives. This causes the solver to take very small steps around the discontinuity, and sometimes leads to early stopping due to `dt <= dt_min`. The correct way to handle such dynamics is to tell the solver about the discontinuity by means of a root-finding equation. [`ODEsystem`](@ref)s accept a keyword argument `continuous_events`
where equations can be added that evaluate to 0 at discontinuities.
257
-
258
-
To model events that have an effect on the state, provide `events::Pair{Vector{Equation}, Vector{Equation}}` where the first entry in the pair is a vector of equations describing event conditions, and the second vector of equations describe the effect on the state. The effect equations must be of the form
The system below illustrates how this can be used to model Coulomb friction
265
-
```@example events
266
-
using ModelingToolkit, OrdinaryDiffEq, Plots
267
-
function UnitMassWithFriction(k; name)
268
-
@variables t x(t)=0 v(t)=0
269
-
D = Differential(t)
270
-
eqs = [
271
-
D(x) ~ v
272
-
D(v) ~ sin(t) - k*sign(v) # f = ma, sinusoidal force acting on the mass, and Coulomb friction opposing the movement
273
-
]
274
-
ODESystem(eqs, t; continuous_events=[v ~ 0], name) # when v = 0 there is a discontinuity
275
-
end
276
-
@named m = UnitMassWithFriction(0.7)
277
-
prob = ODEProblem(m, Pair[], (0, 10pi))
278
-
sol = solve(prob, Tsit5())
279
-
plot(sol)
280
-
```
281
-
282
-
### Example: Bouncing ball
283
-
In the documentation for DifferentialEquations, we have an example where a bouncing ball is simulated using callbacks which has an `affect!` on the state. We can model the same system using ModelingToolkit like this
284
-
285
-
```@example events
286
-
@variables t x(t)=1 v(t)=0
287
-
D = Differential(t)
288
-
289
-
root_eqs = [x ~ 0] # the event happens at the ground x(t) = 0
290
-
affect = [v ~ -v] # the effect is that the velocity changes sign
0 commit comments