Hello,
I have a toy replication of a problem I have faced.
using ModelingToolkit, DifferentialEquations
@independent_variables t
@connector function myConnector(;name)
vars = @variables begin
x(t), [input = true]
y(t), [input = true]
end
ODESystem(Equation[], t, vars, [];name=name)
end
function Source(;name,x_start,y_start)
@named port = myConnector()
vars = @variables begin
end
para = @parameters begin
end
eqs = [
port.x ~ x_start
port.y ~ y_start
]
compose(ODESystem(eqs, t, vars, para;name),port)
end
function MyFun(;name,Δx,Δy)
@named inport = myConnector()
@named outport = myConnector()
vars = @variables begin
end
para = @parameters begin
end
eqs = [
outport.x ~ inport.x +Δx
outport.y ~ inport.y +Δy
]
compose(ODESystem(eqs, t, vars, para;name),inport,outport)
end
function Sink(;name)
@named port = myConnector()
vars = @variables begin
x(t)
y(t)
end
para = @parameters begin
end
eqs = [
x ~ port.x
y ~ port.y
]
compose(ODESystem(eqs, t, vars, para;name),port)
end
@named src = Source(x_start = 4,y_start = 10)
@named fun = MyFun(Δx = 4,Δy = 1)
@named sink = Sink()
eqs = [
connect(src.port,fun.inport)
connect(fun.outport,sink.port)
]
@named sys = ODESystem(eqs, t, systems=[src,fun,sink])
The error I get is as follows:
ERROR: LoadError: MethodError: no method matching ODESystem(::Matrix{Any}, ::Num, ::Vector{Any}, ::Vector{Any}; name::Symbol)
The fix I found for this was having a space between the +
and Δx
and Δy
. Meaning if I write the function as
function MyFun(;name,Δx,Δy)
@named inport = myConnector()
@named outport = myConnector()
vars = @variables begin
end
para = @parameters begin
end
eqs = [
outport.x ~ inport.x + Δx
outport.y ~ inport.y + Δy
]
compose(ODESystem(eqs, t, vars, para;name),inport,outport)
end
Then the system works.
I am not sure if this is a bug or not.
Thank you.