Referring to @baggepinnen 's past response to the question about the possibility to model a delay using ModelingToolkit, I was just wondering if there has been any progress in this direction. Something along the line of delay(…) operator in Modelica.
Or what is the recommendation in the meantime? I am considering a cascade of water dams, wherein each dam is modelled (more or less as a plain hydraulic tank) using ModelingToolkit, but then a simple one-directional interaction between two neighbour dams is that the outflow from one constitutes an inflow to the other, surely with some (transport) delay.
DDEs are done via using the call at a different time:
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)
prob = DDEProblem(sys,
[x₀ => 1.0, x₁ => 1.0, x₂(t) => 1.0],
tspan,
constant_lags = [tau])
3 Likes