Skip to content

Commit

Permalink
tidy up some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Aug 15, 2024
1 parent eeb8d69 commit 8d4ad7e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
23 changes: 20 additions & 3 deletions docs/src/examples/kinematic_loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ connections = [connect(j2.frame_b, b2.frame_a)
@named fourbar_analytic = ODESystem(connections, t, systems = [world; systems])
fourbar_analytic = complete(fourbar_analytic)
ssys = structural_simplify(IRSystem(fourbar_analytic))
prob = ODEProblem(ssys, [], (0.0, 1.4399))
ssys_analytic = structural_simplify(IRSystem(fourbar_analytic))
prob = ODEProblem(ssys_analytic, [], (0.0, 1.4399))
sol2 = solve(prob, FBDF(autodiff=true)) # about 4x faster than the simulation above
plot!(sol2, idxs=[j2.s]) # Plot the same coordinate as above
```
Expand All @@ -182,4 +182,21 @@ Multibody.render(fourbar_analytic, sol2; x=-2, y = 2, z = 3, filename = "fourbar
nothing # hide
```

![animation](fourbar_analytic.gif)
![animation](fourbar_analytic.gif)

While the version with a cut joint were solving for
```@example kinloop
length(unknowns(ssys))
```
variables, the version with the joint assembly solved for only
```@example kinloop
length(unknowns(ssys_analytic))
```
variables.

We can also inspect the mass matrices of the two systems to see how many nonlinear algebraic equations the solver has to deal with
```@example kinloop
using LinearAlgebra
diag(ssys.mass_matrix), diag(ssys_analytic.mass_matrix)
```
A 1 on the diagonal indicates a differential equation, while a 0 indicates an algebraic equation. The cut-joint version has 6 nonlinear algebraic equations, while the joint assembly version has only 1. Both of them have 2 differential equations (position and velocity), corresponding to the 1 degree of freedom in the mechanism. Nonlinear algebraic equations are more expensive to solve than differential equations.
2 changes: 2 additions & 0 deletions docs/src/examples/swing.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ import GLMakie
Multibody.render(model, sol; z = -5, filename = "simple_swing.gif") # Use "simple_swing.mp4" for a video file
nothing # hide
```

![animation](simple_swing.gif)

This makes for a rather interesting-looking springy pendulum!


Expand Down
1 change: 1 addition & 0 deletions docs/src/examples/wheel.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ prob = ODEProblem(ssys, [], (0, 6))
sol = solve(prob, Tsit5())
render(model, sol, framerate=30, filename="car.gif", x=6, z=6, y=5)
nothing # hide
```

![car animation](car.gif)

0 comments on commit 8d4ad7e

Please sign in to comment.