Skip to content

Commit 8a5839a

Browse files
author
Brad Carman
committed
PassThrus
1 parent 8a208f7 commit 8a5839a

File tree

8 files changed

+476
-234
lines changed

8 files changed

+476
-234
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ FileIO = "1.16"
1717
FilterHelpers = "0.2"
1818
GLMakie = "0.8"
1919
ModelingToolkit = "8.50"
20-
ModelingToolkitStandardLibrary = "1.11"
20+
ModelingToolkitStandardLibrary = "1.12"
2121
TOML = "1.0"
2222
julia = "1.6"
2323

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,52 @@ If a component has a double lined box then it is possible to "look under the hoo
9191

9292
Edits made to sub-components can be saved and loaded directly or indirectly.
9393

94+
# Pass Thrus
95+
To generate more esthetic diagrams, one can use as special kind of component called a `PassThru`, which simply defines 2 or more connected `connectors` to serve as a corner, tee, or any other junction. Simply define a component function starting with `PassThru` and ModelingToolkitDesigner.jl will recognize it as a special component type. For example for a corner with 2 connection points:
96+
97+
98+
```julia
99+
@component function PassThru2(;name)
100+
@variables t
101+
102+
systems = @named begin
103+
p1 = Pin()
104+
p2 = Pin()
105+
end
106+
107+
eqs = [
108+
connect(p1, p2)
109+
]
110+
111+
return ODESystem(eqs, t, [], []; name, systems)
112+
end
113+
```
114+
115+
And for a tee with 3 connection points
116+
117+
```julia
118+
@component function PassThru3(;name)
119+
@variables t
120+
121+
systems = @named begin
122+
p1 = Pin()
123+
p2 = Pin()
124+
p3 = Pin()
125+
end
126+
127+
eqs = [
128+
connect(p1, p2, p3)
129+
]
130+
131+
return ODESystem(eqs, t, [], []; name, systems)
132+
end
133+
```
134+
135+
Adding these components to your system will then allow for corners, tees, etc. to be created. When editing is complete, use the toggle switch to hide the `PassThru` details, showing a more esthetic connection diagram.
136+
137+
![step10-11](https://user-images.githubusercontent.com/40798837/229201536-4444a037-18b3-4efd-bc93-d2c182abf533.png)
138+
139+
94140
# Icons
95141
ModelingToolkitDesigner.jl comes with icons for the ModelingToolkitStandardLibrary.jl pre-loaded. For custom components, icons are loaded from the `path` variable supplied to `ODESystemDesign()`. To find the path ModelingToolkitDesign.jl is searching, pass the system of interest to `ODESystemDesign()` and replace the `.toml` with `.png`. For example if we want to make an icon for the `sys.vol` component, we can find the path by running...
96142

@@ -105,10 +151,9 @@ Placing a "FixedVolume.png" file in this location will load that icon.
105151
ModelingToolkitDesigner.jl colors the connections based on `ModelingToolkitDesigner.design_colors`. Colors for the ModelingToolkitStandardLibrary.jl are already loaded. To add a custom connector color, simply use `add_color(system::ODESystem, color::Symbol)` where `system` is a reference to the connector (e.g. `sys.vol.port`) and `color` is a named color from [Colors.jl](https://juliagraphics.github.io/Colors.jl/stable/namedcolors/).
106152

107153
# TODO
108-
109154
- Finish adding icons for the ModelingToolkitStandardLibrary.jl
110155
- Add documentation
111-
- Support more complex connection paths with bends etc.
112156

113157
# [compat]
114-
ModelingToolkit = "8.50" > needed for Domain feature
158+
- ModelingToolkit = "8.50" > needed for Domain feature
159+
- ModelingToolkitStandardLibrary = "1.12" > needed for Hydraulic components

examples/design/Main/Circuit.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
connect(constant.output, source.V)
2-
connect(source.p, resistor.p)
1+
connect(resistor.p, pt2.p1)
2+
connect(source.p, pt2.p2)
3+
connect(source.n, pt3.p2)
4+
connect(capacitor.n, pt3.p1)
35
connect(resistor.n, capacitor.p)
4-
connect(capacitor.n, source.n)
5-
connect(source.n, ground.g)
6+
connect(ground.g, pt3.p3)
7+
connect(source.V, constant.output)

examples/design/Main/Circuit.toml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
[capacitor]
22
n = "S"
3-
x = 0.52
3+
x = 0.51
44
y = 0.29
55

66
[constant]
7-
x = 0.54
8-
y = -0.03
7+
output = "N"
8+
x = 0.71
9+
y = -0.08
910

1011
[ground]
11-
x = 0.43
12+
g = "N"
13+
x = 0.51
14+
y = -0.08
15+
16+
[pt2]
17+
p1 = "N"
18+
p2 = "W"
19+
x = 0.9
20+
y = 0.11
21+
22+
[pt3]
23+
p1 = "N"
24+
p3 = "S"
25+
x = 0.51
1226
y = 0.11
1327

1428
[resistor]
1529
n = "W"
1630
p = "S"
17-
x = 0.8
31+
x = 0.9
1832
y = 0.29
1933

2034
[source]
2135
V = "S"
2236
n = "W"
23-
x = 0.66
37+
x = 0.71
2438
y = 0.11

examples/electrical.jl

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,86 @@ using ModelingToolkitStandardLibrary.Electrical
33
using ModelingToolkitStandardLibrary.Blocks: Constant
44
using ModelingToolkitDesigner
55
using CairoMakie
6+
using GLMakie
7+
8+
@component function PassThru2(;name)
9+
@variables t
10+
11+
systems = @named begin
12+
p1 = Pin()
13+
p2 = Pin()
14+
end
15+
16+
eqs = [
17+
connect(p1, p2)
18+
]
19+
20+
return ODESystem(eqs, t, [], []; name, systems)
21+
end
22+
23+
@component function PassThru3(;name)
24+
@variables t
25+
26+
systems = @named begin
27+
p1 = Pin()
28+
p2 = Pin()
29+
p3 = Pin()
30+
end
31+
32+
eqs = [
33+
connect(p1, p2, p3)
34+
]
35+
36+
return ODESystem(eqs, t, [], []; name, systems)
37+
end
638

739
@component function Circuit(;name)
840

941
R = 1.0
1042
C = 1.0
1143
V = 1.0
1244
@variables t
45+
1346
systems = @named begin
1447
resistor = Resistor(R = R)
1548
capacitor = Capacitor(C = C)
1649
source = Voltage()
1750
constant = Constant(k = V)
1851
ground = Ground()
52+
pt2 = PassThru2()
53+
pt3 = PassThru3()
1954
end
20-
2155

22-
eqs = [connect(constant.output, source.V)
23-
connect(source.p, resistor.p)
24-
connect(resistor.n, capacitor.p)
25-
connect(capacitor.n, source.n, ground.g)]
56+
eqs = [
57+
connect(resistor.p, pt2.p1)
58+
connect(source.p, pt2.p2)
59+
connect(source.n, pt3.p2)
60+
connect(capacitor.n, pt3.p1)
61+
connect(resistor.n, capacitor.p)
62+
connect(ground.g, pt3.p3)
63+
connect(source.V, constant.output)
64+
]
65+
66+
# eqs = [connect(constant.output, source.V)
67+
# connect(source.p, resistor.p)
68+
# connect(resistor.n, capacitor.p)
69+
# connect(capacitor.n, source.n, ground.g)]
2670

2771
ODESystem(eqs, t, [], []; systems, name)
2872
end
2973

3074
@named rc = Circuit()
3175

76+
# using OrdinaryDiffEq
77+
# sys = structural_simplify(rc)
78+
# prob = ODEProblem(sys, Pair[], (0, 10.0))
79+
# sol = solve(prob, Tsit5())
3280

3381
path = joinpath(@__DIR__, "design")
3482
design = ODESystemDesign(rc, path)
83+
GLMakie.set_theme!(Theme(;fontsize=12))
3584
ModelingToolkitDesigner.view(design)
3685

37-
CairoMakie.set_theme!(Theme(;fontsize=12))
38-
fig = ModelingToolkitDesigner.view(design, false)
39-
save(joinpath(@__DIR__, "electrical.svg"), fig; resolution=(400,400))
86+
# CairoMakie.set_theme!(Theme(;fontsize=12))
87+
# fig = ModelingToolkitDesigner.view(design, false)
88+
# save(joinpath(@__DIR__, "electrical.svg"), fig; resolution=(400,400))

0 commit comments

Comments
 (0)