-
-
Notifications
You must be signed in to change notification settings - Fork 234
Open
Description
I was wondering if it was somehow possible to use transport delay inside of a ModelingToolkit component. I tried modifing this minamal example using DDEs
using ModelingToolkit, DelayDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
tau = 1;
@parameters p0=0.2 p1=0.2 q0=0.3 q1=0.3 v0=1 v1=1 d0=5 d1=1 d2=1 beta0=1 beta1=1
@variables x₀(t) x₁(t) x₂(..)
eqs = [D(x₀) ~ (v0 / (1 + beta0 * (x₂(t - tau)^2))) * (p0 - q0) * x₀ - d0 * x₀
D(x₁) ~ (v0 / (1 + beta0 * (x₂(t - tau)^2))) * (1 - p0 + q0) * x₀ +
(v1 / (1 + beta1 * (x₂(t - tau)^2))) * (p1 - q1) * x₁ - d1 * x₁
D(x₂(t)) ~ (v1 / (1 + beta1 * (x₂(t - tau)^2))) * (1 - p1 + q1) * x₁ - d2 * x₂(t)]
@mtkbuild sys = System(eqs, t)
tspan = (0.0, 10.0)
prob = DDEProblem(sys,
[x₀ => 1.0, x₁ => 1.0, x₂(t) => 1.0],
tspan,
constant_lags = [tau])
alg = MethodOfSteps(Tsit5())
sol = solve(prob, alg)
using Plots
plot(sol)
to
using ModelingToolkit, DelayDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D
using Plots
# this does not work
tau = 1
@mtkmodel FOL begin
@parameters begin
p0=0.2
p1=0.2
q0=0.3
q1=0.3
v0=1
v1=1
d0=5
d1=1
d2=1
beta0=1
beta1=1
end
@variables begin
x₀(t)
x₁(t)
x₂(..)
end
@equations begin
D(x₀) ~ (v0 / (1 + beta0 * (x₂(t - tau)^2))) * (p0 - q0) * x₀ - d0 * x₀
D(x₁) ~ (v0 / (1 + beta0 * (x₂(t - tau)^2))) * (1 - p0 + q0) * x₀ +
(v1 / (1 + beta1 * (x₂(t - tau)^2))) * (p1 - q1) * x₁ - d1 * x₁
D(x₂(t)) ~ (v1 / (1 + beta1 * (x₂(t - tau)^2))) * (1 - p1 + q1) * x₁ - d2 * x₂(t)
end
end
tspan = (0.0, 10.0)
@mtkbuild sys = FOL()
prob = DDEProblem(sys,
[x₀ => 1.0, x₁ => 1.0, x₂(t) => 1.0],
tspan,
constant_lags = [tau])
alg = MethodOfSteps(Tsit5())
sol = solve(prob, alg)
plot(sol)
and found it does not work as expected. It turned out that ModelingToolkit.jl does no support DDEs in the macro right now, but should be able to lower to System instead of ODESystem.
This issue is a result of a forum discussion.
Metadata
Metadata
Assignees
Labels
No labels