Skip to content

Commit 5f93405

Browse files
author
Brad Carman
committed
added system diagrams to lecture 1
1 parent 6b39ffd commit 5f93405

File tree

8 files changed

+33
-6
lines changed

8 files changed

+33
-6
lines changed

docs/Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"
1313
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
1414

1515
[compat]
16-
DataInterpolations = "4"
16+
DataInterpolations = "5"
1717
DifferentialEquations = "7"
1818
Documenter = "1"
1919
ForwardDiff = "0.10"
2020
ModelingToolkit = "9"
2121
ModelingToolkitStandardLibrary = "2"
22-
OrdinaryDiffEq = "6"
22+
OrdinaryDiffEq = "=6.74.1"
2323
Plots = "1"
2424
Setfield = "1"
2525
Sundials = "4"

docs/make.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Documenter, ModelingToolkitCourse
2+
# NOTE: OrdinaryDiffEq limited to v6.74.1 because of bug https://github.com/SciML/OrdinaryDiffEq.jl/issues/2250
23

34
pages = [
45
"Home" => "index.md",
@@ -26,5 +27,10 @@ makedocs(sitename = "ModelingToolkit Course",
2627
canonical = "https://docs.sciml.ai/ModelingToolkitCourse/stable/"),
2728
pages = pages)
2829

30+
#=
31+
using LiveServer
32+
serve(dir="build")
33+
=#
34+
2935
deploydocs(repo = "github.com/SciML/ModelingToolkitCourse.git";
3036
push_preview = true)

docs/src/img/MassSpringDamper.png

78.7 KB
Loading

docs/src/img/System1.png

44 KB
Loading

docs/src/img/System2.png

71.2 KB
Loading

docs/src/img/System3.png

60.2 KB
Loading

docs/src/lectures/lecture1.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,18 @@ Now the `Mass` and `Damper` components can be assembled in a system and connecte
384384
end
385385
386386
@mtkbuild sys = System(;v=100, m=5, d=3)
387+
nothing # hide
388+
```
389+
390+
![mass-damper](../img/System1.png)
391+
392+
Here we arrive at the following equations
393+
```@example l1
387394
full_equations(sys)
388395
```
389396

390397
As can be seen we arrive at the same equation as derived previously. Now it would be easy to define a system that adds a spring, or has a series of connected masses, springs, dampers, etc.
391398

392-
393399
The `Damper` component created previously was a little incomplete because it only had one port. In reality a damper or spring will be connected between 2 objects, for example the car frame and the wheel. Therefore a proper component will define 2 ports so that the component can be as analogous with real life as possible. In the example below the component is defined properly with 2 ports. Note the velocity of the component `v` is defined as a relative velocity between the 2 ports. It's easy to understand how this works if it's assumed that `port_b` is connected to a stationary reference frame.
394400

395401
```@example l1
@@ -550,6 +556,13 @@ Now let's assemble a *mass-spring-damper* system with the full collection of com
550556
end
551557
552558
@mtkbuild sys = System()
559+
```
560+
561+
![mass-spring-damper](../img/System2.png)
562+
563+
Solving the system gives a plot of the 2 solved uknowns.
564+
565+
```@example l1
553566
prob = ODEProblem(sys, [], (0, 10))
554567
sol = solve(prob)
555568
plot(sol)
@@ -620,6 +633,8 @@ end
620633
nothing # hide
621634
```
622635

636+
![MassSpringDamper component](../img/MassSpringDamper.png)
637+
623638
As an example, the `MassSpringDamper` component can be connected in series to make a complex system. One can imagine then how this enables easy construction of complex models that can be quickly modified, extremely useful for the application of model based design.
624639

625640
```@example l1
@@ -644,6 +659,14 @@ As an example, the `MassSpringDamper` component can be connected in series to ma
644659
end
645660
646661
@mtkbuild sys = System()
662+
nothing #hide
663+
```
664+
665+
![Composite System](../img/System3.png)
666+
667+
Solving this complex system gives
668+
669+
```@example l1
647670
prob = ODEProblem(sys, [], (0, 2))
648671
sol = solve(prob)
649672
plot(sol; idxs=[sys.msd1.spring.x, sys.msd2.spring.x, sys.msd3.spring.x])

docs/src/lectures/lecture2.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ import ModelingToolkitStandardLibrary.Blocks as B
353353
using DataInterpolations
354354
mass_flow_fun = LinearInterpolation(sol_x[ṁ], sol_x.t)
355355
356-
include("volume.jl") # <-- missing Volume component from MTKSL (will be released in new version)
357-
358356
function MassVolume(; name, dx, drho, dm)
359357
360358
pars = @parameters begin
@@ -373,7 +371,7 @@ function MassVolume(; name, dx, drho, dm)
373371
systems = @named begin
374372
fluid = IC.HydraulicFluid(; density = 876, bulk_modulus = 1.2e9)
375373
mass = T.Mass(;v=dx,m=M,g=-g)
376-
vol = Volume(;area=A, x=x₀, p=p_int, dx, drho, dm) # <-- missing Volume component from MTKSL (will be released in new version)
374+
vol = IC.Volume(;area=A, x=x₀, p=p_int, dx, drho, dm)
377375
mass_flow = IC.MassFlow(;p_int)
378376
mass_flow_input = B.TimeVaryingFunction(;f = mass_flow_fun)
379377
end

0 commit comments

Comments
 (0)