Skip to content

Commit e1ca368

Browse files
docs: add docs for @component and @connector
1 parent c5cc07a commit e1ca368

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/systems/abstractsystem.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,6 +2471,26 @@ function component_post_processing(expr, isconnector)
24712471
end
24722472
end
24732473

2474+
"""
2475+
$(TYPEDSIGNATURES)
2476+
2477+
Mark a system constructor function as building a component. For example,
2478+
2479+
```julia
2480+
@component function AddOne(; name)
2481+
@variables in(t) out(t)
2482+
eqs = [out ~ in + 1]
2483+
return System(eqs, t, [in, out], []; name)
2484+
end
2485+
```
2486+
2487+
ModelingToolkit systems are either components or connectors. Components define dynamics of
2488+
the model. Connectors are used to connect components together. See the
2489+
[Model building reference](@ref model_building_api) section of the documentation for more
2490+
information.
2491+
2492+
See also: [`@connector`](@ref).
2493+
"""
24742494
macro component(expr)
24752495
esc(component_post_processing(expr, false))
24762496
end

src/systems/connectors.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,37 @@ function get_connection_type(s)
2020
getmetadata(s, VariableConnectType, Equality)
2121
end
2222

23+
"""
24+
$(TYPEDSIGNATURES)
25+
26+
Mark a system constructor function as building a connector. For example,
27+
28+
```julia
29+
@connector function ElectricalPin(; name, v = nothing, i = nothing)
30+
@variables begin
31+
v(t) = v, [description = "Potential at the pin [V]"]
32+
i(t) = i, [connect = Flow, description = "Current flowing into the pin [A]"]
33+
end
34+
return System(Equation[], t, [v, i], []; name)
35+
end
36+
```
37+
38+
Since connectors only declare variables, the equivalent shorthand syntax can also be used:
39+
40+
```julia
41+
@connector Pin begin
42+
v(t), [description = "Potential at the pin [V]"]
43+
i(t), [connect = Flow, description = "Current flowing into the pin [A]"]
44+
end
45+
```
46+
47+
ModelingToolkit systems are either components or connectors. Components define dynamics of
48+
the model. Connectors are used to connect components together. See the
49+
[Model building reference](@ref model_building_api) section of the documentation for more
50+
information.
51+
52+
See also: [`@component`](@ref).
53+
"""
2354
macro connector(expr)
2455
esc(component_post_processing(expr, true))
2556
end

0 commit comments

Comments
 (0)