# MTK: connection of flow variable forces it to zero

**URL:** <https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [September 3, 2024, 8:06am UTC](https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976 "2024-09-03T08:06:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [September 3, 2024, 8:06am UTC](https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976/1 "2024-09-03T08:06:32Z")

</div>

Hello,  
I encountered some problem in MTK which I could recreate in the following MWE:

```julia
using Pkg
pkg"activate --temp"
pkg"add ModelingToolkit"
using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as Dt

@connector Connector begin
    potential(t)
    flow(t), [connect=Flow]
end
@mtkmodel Storage begin
    @components begin
        pin = Connector()
    end
    @variables begin
        potential(t)
    end
    @equations begin
        Dt(potential) ~ pin.flow
    end
end

@named storage = Storage()
@named pin = Connector()
@parameters begin
    inputflow
end
@variables begin
    outputpotential(t)
end
eqs = [inputflow ~ pin.flow,
       outputpotential ~ pin.potential,
       connect(pin, storage.pin)]
@named sys = ODESystem(eqs, t; systems=[pin, storage])

structural_simplify(sys)

```

Which leads to an error of `structural_simplify` because the system is overconstraint:

```julia
ERROR: ExtraEquationsSystemException: The system is unbalanced. There are 6 highest order derivative variables and 7 equations.
More equations than variables, here are the potential extra equation(s):
 0 ~ pin₊flow(t)

```

It even points out an equation, but I don’t know where this equation is coming from in the first place. I think I have some deep misunderstand about how flow connectors work. I thought I would model the following system, which should cleanly reduce to just a single ODE:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/7/d7a9c59830272a23af002565ae5a3c3f7f2ee944.png)

What am I doing wrong here? Where does the `0 ~ pin₊flow(t)` constraint come from?

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [September 3, 2024, 8:24am UTC](https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976/2 "2024-09-03T08:24:16Z")

</div>

```julia
@mtkmodel Fixed begin
    @components begin
        pin = Connector()
    end
    @parameters begin
        inputflow
    end
    @variables begin
        outputpotential(t)
    end
    @equations begin
        inputflow ~ pin.flow
        outputpotential ~ pin.potential
    end
end
@named storage = Storage()
@named fixed = Fixed()
eqs = [connect(storage.pin, fixed.pin)]
@named sys = ODESystem(eqs, t; systems=[storage, fixed])
simp = structural_simplify(sys)
full_equations(simp)

```

Interestingly, once I define another subsystem and don’t mix connections and equations it works…

---

<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:** [September 3, 2024, 10:25am UTC](https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976/3 "2024-09-03T10:25:05Z")

</div>

Open an issue. I at least cannot eyeball it.

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [September 3, 2024, 10:56am UTC](https://discourse.julialang.org/t/mtk-connection-of-flow-variable-forces-it-to-zero/118976/4 "2024-09-03T10:56:21Z")

</div>

Allright thanks, issue opened [`connect` can lead to wrong flow equations · Issue #3008 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/issues/3008)
