Skip to content

Commit 3eda1bf

Browse files
authored
Merge pull request #16 from matthew-kapp/master
Examples updated to match MTK v9 macros syntax
2 parents 2d5edf2 + c4c7a82 commit 3eda1bf

File tree

6 files changed

+667
-1063
lines changed

6 files changed

+667
-1063
lines changed

examples/electrical.jl

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
using ModelingToolkit
2+
# using ModelingToolkit: t_nounits as t
23
using ModelingToolkitStandardLibrary.Electrical
34
using ModelingToolkitStandardLibrary.Blocks: Constant
45
using ModelingToolkitDesigner
56
using CairoMakie
67
using GLMakie
78

8-
@component function PassThru2(; name)
9-
@variables t
9+
@mtkmodel PassThru2 begin
1010

11-
systems = @named begin
11+
@components begin
1212
p1 = Pin()
1313
p2 = Pin()
1414
end
1515

16-
eqs = [connect(p1, p2)]
17-
18-
return ODESystem(eqs, t, [], []; name, systems)
16+
@equations begin
17+
connect(p1, p2)
18+
end
1919
end
2020

21-
@component function PassThru3(; name)
22-
@variables t
21+
@mtkmodel PassThru3 begin
2322

24-
systems = @named begin
23+
@components begin
2524
p1 = Pin()
2625
p2 = Pin()
2726
p3 = Pin()
2827
end
2928

30-
eqs = [connect(p1, p2, p3)]
31-
32-
return ODESystem(eqs, t, [], []; name, systems)
29+
@equations begin
30+
connect(p1, p2, p3)
31+
end
3332
end
3433

35-
@component function Circuit(; name)
34+
@mtkmodel Circuit begin
3635

37-
R = 1.0
38-
C = 1.0
39-
V = 1.0
40-
@variables t
36+
@parameters begin
37+
R = 1.0
38+
C = 1.0
39+
V = 1.0
40+
end
4141

42-
systems = @named begin
42+
@components begin
4343
resistor = Resistor(R = R)
4444
capacitor = Capacitor(C = C)
4545
source = Voltage()
@@ -49,36 +49,32 @@ end
4949
pt3 = PassThru3()
5050
end
5151

52-
eqs = [
52+
@equations begin
5353
connect(resistor.p, pt2.p1)
5454
connect(source.p, pt2.p2)
5555
connect(source.n, pt3.p2)
5656
connect(capacitor.n, pt3.p1)
5757
connect(resistor.n, capacitor.p)
5858
connect(ground.g, pt3.p3)
5959
connect(source.V, constant.output)
60-
]
61-
62-
# eqs = [connect(constant.output, source.V)
63-
# connect(source.p, resistor.p)
64-
# connect(resistor.n, capacitor.p)
65-
# connect(capacitor.n, source.n, ground.g)]
60+
end
6661

67-
ODESystem(eqs, t, [], []; systems, name)
62+
# @equations begin
63+
# connect(constant.output, source.V)
64+
# connect(source.p, resistor.p)
65+
# connect(resistor.n, capacitor.p)
66+
# connect(capacitor.n, source.n, ground.g)
67+
# end
6868
end
6969

7070
@named rc = Circuit()
7171

72-
# using OrdinaryDiffEq
73-
# sys = structural_simplify(rc)
74-
# prob = ODEProblem(sys, Pair[], (0, 10.0))
75-
# sol = solve(prob, Tsit5())
76-
7772
path = joinpath(@__DIR__, "design")
7873
design = ODESystemDesign(rc, path)
7974
GLMakie.set_theme!(Theme(; fontsize = 12))
8075
ModelingToolkitDesigner.view(design)
8176

82-
# CairoMakie.set_theme!(Theme(;fontsize=12))
83-
# fig = ModelingToolkitDesigner.view(design, false)
77+
CairoMakie.set_theme!(Theme(;fontsize=12))
78+
fig = ModelingToolkitDesigner.view(design, false)
79+
save(joinpath(@__DIR__, "electrical.svg"), fig; size=(300,300))
8480
# save(joinpath(@__DIR__, "electrical.svg"), fig; resolution=(300,300))

0 commit comments

Comments
 (0)