Skip to content

Commit c6540cb

Browse files
author
Brad Carman
committed
ReadMe
1 parent 1ebfa90 commit c6540cb

File tree

10 files changed

+376
-83
lines changed

10 files changed

+376
-83
lines changed

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,96 @@
11
# ModelingToolkitDesigner.jl
22

3-
ModelingToolkitDesigner.jl
3+
The ModelingToolkitDesigner.jl package is a helper tool for visualizing and editing ModelingToolkit.jl system connections. An example system visualization generated from this package is shown below
4+
5+
![example](https://user-images.githubusercontent.com/40798837/228664425-d8150c13-5133-40db-9bed-bfb6f391dc90.svg)
6+
7+
8+
# Tutorial
9+
10+
Let's start with a simple hydraulic system with no connections defined yet...
11+
12+
```julia
13+
using ModelingToolkit
14+
using ModelingToolkitDesigner
15+
using GLMakie
16+
17+
import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC
18+
import ModelingToolkitStandardLibrary.Blocks as B
19+
20+
21+
@parameters t
22+
23+
@component function system(; name)
24+
25+
pars = []
26+
27+
systems = @named begin
28+
stp = B.Step(;height = 10e5, start_time = 0.005)
29+
src = IC.InputSource(;p_int=0)
30+
vol = IC.FixedVolume(;p_int=0, vol=10.0)
31+
res = IC.Pipe(5; p_int=0, area=0.01, length=500.0)
32+
end
33+
34+
eqs = Equation[]
35+
36+
ODESystem(eqs, t, [], pars; name, systems)
37+
end
38+
39+
@named sys = system()
40+
```
41+
42+
Then we can visualize the system using `ODESystemDesign()` and the `view()` functions
43+
44+
```julia
45+
path = "./design" # folder where visualization info is saved and retrieved
46+
design = ODESystemDesign(sys, path);
47+
ModelingToolkitDesigner.view(design)
48+
```
49+
50+
![step 1](https://user-images.githubusercontent.com/40798837/228621071-2044a422-5a5a-4a3b-89fe-7e4d297f9438.png)
51+
52+
Components can then be positioned in several ways:
53+
- keyboard: select component and then use up, down, left, right keys
54+
- mouse: click and drag (currently only 1 component at a time is supported)
55+
- alignment: select and align horrizontal or vertial with respective buttons
56+
57+
![step2-3](https://user-images.githubusercontent.com/40798837/228626821-9e405ec3-e89b-4f30-bfff-ceb761ea6e2f.png)
58+
59+
Nodes/Connectors can be positioned by selecting with the mouse and using the __move node__ button. *Note: Components and Nodes can be de-selected by right clicking anywhere or using the button* __clear selection__
60+
61+
![step4-5](https://user-images.githubusercontent.com/40798837/228626824-06f4d432-ea93-408d-ad1a-ddaa6ddc14e6.png)
62+
63+
Connections can then be made by clicking 2 nodes and using the __connect__ button. One can then click the __save__ button which will store the visualization information in the `path` location in a `.toml` format as well as the connection code in `.jl` format.
64+
65+
![step6-7](https://user-images.githubusercontent.com/40798837/228640663-e263a561-6549-415b-a8ff-b74e78c4bdb9.png)
66+
67+
The connection code can also be obtained with the `connection_code()` function
68+
69+
```julia
70+
julia> connection_code(design)
71+
connect(stp.output, src.input)
72+
connect(src.port, res.port_a)
73+
connect(vol.port, res.port_b)
74+
```
75+
76+
After the original `system()` component function is updated, the connections will be re-drawn automatically when using `ModelingToolkitDesigner.view()`. *Note: CairoMakie vector based images can also be generated by passing `false` to the 2nd argument of `view()` (i.e. the `interactive` variable).
77+
78+
# Hierarchy
79+
If a component has a double lined box then it is possible to "look under the hood". Simply select the component and click __open__.
80+
81+
![step8-9](https://user-images.githubusercontent.com/40798837/228666972-14ea5032-52c6-4447-a97b-383356fbcbcf.png)
82+
83+
Edits made to sub-components can be saved and loaded directly or indirectly.
84+
85+
# Icons
86+
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...
87+
88+
```julia
89+
julia> ODESystemDesign(sys.vol, path).file
90+
"./design\\ModelingToolkitStandardLibrary\\Hydraulic\\IsothermalCompressible\\FixedVolume.toml"
91+
```
92+
93+
Placing a "FixedVolume.png" file in this location will load that icon.
94+
95+
# Colors
96+
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/).
1.85 KB
Loading
Lines changed: 77 additions & 0 deletions
Loading

icons/ModelingToolkitStandardLibrary/Hydraulic/IsothermalCompressible/Pipe.toml

Lines changed: 0 additions & 52 deletions
This file was deleted.
2.42 KB
Loading
Lines changed: 120 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)