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
:
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
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?