# No method matching get\_connection\_type when connecting components

**URL:** <https://discourse.julialang.org/t/no-method-matching-get-connection-type-when-connecting-components/73990>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [January 3, 2022, 6:56pm UTC](https://discourse.julialang.org/t/no-method-matching-get-connection-type-when-connecting-components/73990 "2022-01-03T18:56:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenrei](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jenrei](https://discourse.julialang.org/u/jenrei)\
**Post date:** [January 3, 2022, 6:56pm UTC](https://discourse.julialang.org/t/no-method-matching-get-connection-type-when-connecting-components/73990/1 "2022-01-03T18:56:57Z")

</div>

Hello,

I’m trying to get a feeling for MTK by converting the electric circuit example for acasual component based modeling to thermal components. Unfortunately I get this error when I’m using `connect`:

```julia
ht_eqs = [
    connect(capacitorA.heatPort, resistor.heatPortA)
    connect(resistor.heatPortB, capacitorB.heatPort)
    ]

ERROR: LoadError: MethodError: no method matching get_connection_type(::Type{HeatPort})

```

I’m not too experienced in Julia so maybe I’m even missing something obvious. Thanks in advance.

Here is my complete example as intended

> **HeatPort Example**
>
> ```julia
> using ModelingToolkit, Plots, DifferentialEquations
> 
> @variables t
> 
> @connector function HeatPort(;name)
> sts = @variables T(t) q(t) [connect = Flow]
> ODESystem(Equation[], t, sts, []; name=name, defaults=[T=>298.15, q=>0.0])
> end
> 
> function HeatCapacitor(;name, m=1.0, cp=2.0)
> @named heatPort = HeatPort()
> @unpack T = heatPort
> ps = @parameters m=m cp=cp
> D = Differential(t)
> eqs = [
> m*cp*D(T) ~ heatPort.q
> ]
> compose(ODESystem(eqs, t, [], ps; name=name), heatPort)
> end
> 
> function HeatResistor(;name, R=1e2)
> @named heatPortA = HeatPort()
> @named heatPortB = HeatPort()
> ps = @parameters R=R
> eqs = [
> 0 ~ heatPortA.q + heatPortB.q
> heatPortA.T - heatPortB.T ~ heatPortA.q * R
> ]
> compose(ODESystem(eqs, t, [], ps; name=name), heatPortA, heatPortB)
> end
> 
> @named capacitorA = HeatCapacitor(m=1.5, cp=2.1)
> @named capacitorB = HeatCapacitor(m=0.75, cp=3.2)
> @named resistor = HeatResistor(R=1e-1)
> 
> ht_eqs = [
> connect(capacitorA.heatPort, resistor.heatPortA)
> connect(resistor.heatPortB, capacitorB.heatPort)
> ]
> 
> @named _ht_model = ODESystem(ht_eqs, t)
> @named ht_model = compose(_ht_model, [capacitorA, capacitorB, resistor])
> 
> sys = structural_simplify(ht_model)
> 
> u0 = [
> capacitorA.T = 50+273.15
> capacitorB.T = 25+273.15
> ]
> 
> prob = ODAEProblem(sys, u0, (0, 100.0))
> sol = solve(prob, Tsit5())
> plot(sol)
> 
> ```

On a side note: Is there any ambition or ongoing project to build something similar to the Modelica Standard Library based on MTK?

---

<div class="post-metadata">

**Author:** ![jenrei](https://avatars.discourse-cdn.com/v4/letter/j/e8c25b/32.png) [@jenrei](https://discourse.julialang.org/u/jenrei)\
**Post date:** [January 4, 2022, 10:12am UTC](https://discourse.julialang.org/t/no-method-matching-get-connection-type-when-connecting-components/73990/2 "2022-01-04T10:12:31Z")

</div>

So the error was linked to my Julia installation. The code, safe minor carelessness, now runs!  
There seems to be a modeling error though as the temperatures of the HeatCapacitor stay on the initial Temperatures. 🤔

> **New Code**
>
> ```julia
> using ModelingToolkit, DifferentialEquations
> 
> @variables t
> 
> @connector function HeatPort(;name)
> sts = @variables T(t) q(t) [connect=Flow]
> ODESystem(Equation[], t, sts, []; name=name, defaults=[T=>298.15, q=>0.0])
> end
> 
> function HeatCapacitor(;name, m=1.0, cp=2.0e3)
> @named heatPort = HeatPort()
> ps = @parameters m=m cp=cp
> sts = @variables T(t)
> D = Differential(t)
> eqs = [
> heatPort.T ~ T
> m*cp*D(T) ~ heatPort.q
> ]
> compose(ODESystem(eqs, t, sts, ps; name=name), heatPort)
> end
> 
> function HeatResistor(;name, R=1e-2)
> @named heatPortA = HeatPort()
> @named heatPortB = HeatPort()
> ps = @parameters R=R
> eqs = [
> 0 ~ heatPortA.q - heatPortB.q
> heatPortB.T - heatPortA.T ~ heatPortA.q * R
> ]
> compose(ODESystem(eqs, t, [], ps; name=name), heatPortA, heatPortB)
> end
> 
> @named capacitorA = HeatCapacitor(m=1.5, cp=2.1e3)
> @named capacitorB = HeatCapacitor(m=0.75, cp=3.2e3)
> @named resistor = HeatResistor(R=1e0)
> 
> ht_eqs = [
> connect(capacitorA.heatPort, resistor.heatPortA)
> connect(resistor.heatPortB, capacitorB.heatPort)
> ]
> 
> @named _ht_model = ODESystem(ht_eqs, t)
> @named ht_model = compose(_ht_model, [capacitorA, capacitorB, resistor])
> 
> sys = structural_simplify(ht_model)
> 
> u0 = [
> capacitorA.T => 50+273.15
> capacitorB.T => 25+273.15
> ]
> 
> prob = ODAEProblem(sys, u0, (0, 100.0))
> sol = solve(prob, Tsit5())
> #sol = solve(prob, Rodas4())
> 
> #plot(sol)
> using UnicodePlots
> 
> lineplot(sol.t, sol[capacitorA.T])
> 
> ```
