Hello,
I am trying to have a SDESystem
instead of ODESystem
for my acausal framework.
The following block of code fails:
using ModelingToolkit, Plots, DifferentialEquations, StochasticDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
@connector function myconnect(;name)
vars = @variables begin
x(t), [input = true]
y(t), [input = true]
z(t), [input = true]
end
noiseeqs = [
]
SDESystem(Equation[], noiseeqs,t, vars, [];name=name)
end
function source(;name,x_,y_,z_)
@named port = myconnect()
para = @parameters begin
end
vars = @variables begin
x(t)
y(t)
z(t)
end
eqs = [
D(x) ~ 0
D(y) ~ 0
D(z) ~ 0
port.x ~ x_ # Outflow is negative
port.y ~ y_
port.z ~ z_
]
noiseeqs = [
0.1*x,
0.1*y,
0.1*z,
0,
0,
0
]
compose(SDESystem(eqs,noiseeqs ,t, vars, para;name),port)
end
function mycomp(;name)
@named _in = myconnect()
@named _out = myconnect()
para = @parameters begin
end
vars = @variables begin
x(t)
y(t)
z(t)
end
eqs = [
D(x) ~ x*cos(-t)
_out.x ~ x
D(y) ~ y*sin(-t)
_out.y ~ y
D(z) ~ Base.ifelse(t>10,z*(cos(t)),0)
_out.z ~ z
]
noiseeqs = [
0.1*x,
0,
0.1*y,
0,
0.1*z,
0
]
compose(SDESystem(eqs,noiseeqs,t, vars, para;name),_in,_out)
end
function sink(;name)
@named port = myconnect()
para = @parameters begin
end
vars = @variables begin
x(t)
y(t)
z(t)
end
eqs = [
port.x ~ x # Outflow is negative
port.y ~ y
port.z ~ z
]
noiseeqs = [
0,
0,
0
]
compose(SDESystem(eqs,noiseeqs ,t, vars, para;name),port)
end
@named src = source(x_ = 1,y_=2,z_=3)
@named comp = mycomp()
@named snk = sink()
eqs = [
connect(src.port,comp._in)
connect(comp._out,snk.port)
]
systems = [src,comp,snk]
@named model = SDESystem(eqs,t, systems=systems)
with the error:
ERROR: MethodError: no method matching SDESystem(::Vector{Equation}, ::Num; systems::Vector{SDESystem}, name::Symbol)
The type `SDESystem` exists, but no method is defined for this combination of argument types when trying to construct it.
This is my first time trying acausal system with SDE so I am sure many things are wrong here.
I am also not sure if an SDE can be made using the acausal framework.
Any guidance here would be very helpful.