Skip to content

Commit 2ef4752

Browse files
committed
docs: add connect section to Variable metadata
- while here, update the description on setting unit metadata in Contextual-Variables
1 parent ff2a778 commit 2ef4752

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

docs/src/basics/ContextualVariables.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ for which its arguments must be specified each time it is used. This is useful w
4848
PDEs for example, where one may need to use `u(t, x)` in the equations, but will
4949
need to be able to write `u(t, 0.0)` to define a boundary condition at `x = 0`.
5050

51-
## Variable metadata [Experimental/TODO]
51+
## Variable metadata
5252

5353
In many engineering systems, some variables act like “flows” while others do not.
5454
For example, in circuit models you have current which flows, and the related
@@ -69,15 +69,17 @@ the metadata. One can get and set metadata by
6969
```julia
7070
julia> @variables x [unit = u"m^3/s"];
7171

72-
julia> hasmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
72+
julia> hasmetadata(x, VariableUnit)
7373
true
7474

75-
julia> getmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
75+
julia> ModelingToolkit.get_unit(x)
7676
m³ s⁻¹
7777

78-
julia> x = setmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)), u"m/s")
78+
julia> x = setmetadata(x, VariableUnit, u"m/s")
7979
x
8080

81-
julia> getmetadata(x, Symbolics.option_to_metadata_type(Val(:unit)))
81+
julia> ModelingToolkit.get_unit(x)
8282
m s⁻¹
8383
```
84+
85+
See [Symbolic Metadata](@ref symbolic_metadata) for more details on variable metadata.

docs/src/basics/MTKModel_Connector.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ using ModelingToolkit
156156
end
157157
```
158158

159-
Variables (as functions of independent variable) are listed out in the definition. These variables can optionally have initial values and metadata like `description`, `connect` and so on. For more details on setting metadata, check out [Symbolic Metadata](@id symbolic_metadata).
159+
Variables (as functions of independent variable) are listed out in the definition. These variables can optionally have initial values and metadata like `description`, `connect` and so on. For more details on setting metadata, check out [Symbolic Metadata](@ref symbolic_metadata).
160160

161161
Similar to `@mtkmodel`, `@connector` accepts begin blocks of `@components`, `@equations`, `@extend`, `@parameters`, `@structural_parameters`, `@variables`. These keywords mean the same as described above for `@mtkmodel`.
162162
For example, the following `HydraulicFluid` connector is defined with parameters, variables and equations.

docs/src/basics/Variable_metadata.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Symbolic metadata
1+
# [Symbolic Metadata](@id symbolic_metadata)
22

33
It is possible to add metadata to symbolic variables, the metadata will be displayed when calling help on a variable.
44

@@ -39,6 +39,22 @@ help?> u
3939
Symbolics.VariableSource: (:variables, :u)
4040
```
4141

42+
## Connect
43+
44+
Variables in connectors can have `connect` metadata which describes the type of connections.
45+
46+
`Flow` is used for variables that represent physical quantities that "flow" ex:
47+
current in a resistor. These variables sum up to zero in connections.
48+
49+
`Stream` can be specified for variables that flow bi-directionally.
50+
51+
```@example connect
52+
using ModelingToolkit
53+
54+
@variables t, i(t) [connect = Flow]
55+
@variables k(t) [connect = Stream]
56+
```
57+
4258
## Input or output
4359

4460
Designate a variable as either an input or an output using the following

docs/src/tutorials/acausal_components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ component variables. We then simplify this to an ODE by eliminating the
1010
equalities before solving. Let's see this in action.
1111

1212
!!! note
13-
13+
1414
This tutorial teaches how to build the entire RC circuit from scratch.
1515
However, to simulate electric components with more ease, check out the
1616
[ModelingToolkitStandardLibrary.jl](https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/)

0 commit comments

Comments
 (0)