# ModelingToolkit variable metadata for connectors

**URL:** <https://discourse.julialang.org/t/modelingtoolkit-variable-metadata-for-connectors/92056>\
**Category:** Modelling & Simulations\
**Tags:** question, package, modelingtoolkit\
**Created:** [December 23, 2022, 6:21pm UTC](https://discourse.julialang.org/t/modelingtoolkit-variable-metadata-for-connectors/92056 "2022-12-23T18:21:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlxs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlxs4/32/224566_2.png) [@xlxs4](https://discourse.julialang.org/u/xlxs4)\
**Post date:** [December 23, 2022, 6:21pm UTC](https://discourse.julialang.org/t/modelingtoolkit-variable-metadata-for-connectors/92056/1 "2022-12-23T18:21:07Z")

</div>

Hi! In the MTK documentation, specifically page [Contextual Variable Types · ModelingToolkit.jl (sciml.ai)](https://docs.sciml.ai/ModelingToolkit/dev/basics/ContextualVariables/#Variable-metadata-%5BExperimental/TODO%5D) it reads:

> In many engineering systems some variables act like “flows” while others do not. For example, in circuit models you have current which flows, and the related voltage which does not. Or in thermal models you have heat flows. In these cases, the `connect` statement enforces conservation of flow between all of the connected components.

I first came across this in the [Acausal Component-Based Modeling · ModelingToolkit.jl (sciml.ai)](https://docs.sciml.ai/ModelingToolkit/dev/tutorials/acausal_components/#Copy-Paste-Example) tutorial:

```julia
@connector function Pin(;name)
    sts = @variables v(t)=1.0 i(t)=1.0 [connect = Flow]
    ODESystem(Equation[], t, sts, []; name=name)
end

```

I’ve come across [Connectors · Issue #814 · SciML/ModelingToolkit.jl (github.com)](https://github.com/SciML/ModelingToolkit.jl/issues/814).

I understand there’s three different options for the `connect` metadata, `Equality`, `Flow`, and `Stream`, as shown in the source: [ModelingToolkit.jl/variables.jl at master · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/blob/master/src/variables.jl#L16).

Can someone explain what these three options represent and how they could be used? Thanks ^^

---

<div class="post-metadata">

**Author:** ![xlxs4](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xlxs4/32/224566_2.png) [@xlxs4](https://discourse.julialang.org/u/xlxs4)\
**Post date:** [December 23, 2022, 6:24pm UTC](https://discourse.julialang.org/t/modelingtoolkit-variable-metadata-for-connectors/92056/2 "2022-12-23T18:24:28Z")

</div>

P.S.: I came across [Simulating Big Models in Julia with ModelingToolkit | Workshop | JuliaCon 2021 - YouTube](https://youtu.be/HEVOgSLBzWA?t=7972), so I can see how, in the RC circuit example, it was _before_ `[connect = Flow]` was a thing, and how it helped to simplify for this case.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 23, 2022, 9:04pm UTC](https://discourse.julialang.org/t/modelingtoolkit-variable-metadata-for-connectors/92056/3 "2022-12-23T21:04:03Z")

</div>

> [@xlxs4](#):
>
> Can someone explain what these three options represent and how they could be used? Thanks ^^

It needs more docs. Open an issue to put it in the queue. It’s the same as Modelica though:

- Equality variables connect by making values equal. For example, connecting pins in an electrical circuit makes the voltages equal at the junction.
- Flow variables connect by making the sum zero. For example, connecting pins in an electrical circuit makes the current sum to zero at the junction.
- Stream connectors are for fluids. See [Chapter 15 Stream Connectors ‣ Modelica® Language Specification version 3.8-dev](https://specification.modelica.org/master/stream-connectors.html) and [https://build.openmodelica.org/Documentation/Modelica%204.0.0/Resources/Documentation/Fluid/Stream-Connectors-Overview-Rationale.pdf](https://build.openmodelica.org/Documentation/Modelica%204.0.0/Resources/Documentation/Fluid/Stream-Connectors-Overview-Rationale.pdf) .

Fluids are hard man.
