Skip to content

Generalize symbolic indexing of ODE/DDE to multivariate variables #3738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/systems/abstractsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ for traitT in [
elseif is_timeseries_parameter(sys, s)
push!(ts_idxs, timeseries_parameter_index(sys, s).timeseries_idx)
elseif is_time_dependent(sys) && iscall(s) && issym(operation(s)) &&
is_variable(sys, operation(s)(get_iv(sys)))
# DDEs case, to detect x(t - k)
is_variable(sys, operation(s)(get_iv(sys), arguments(s)[2:end]...))
# DDEs case, to detect x(t - k), and x(t - k, arg2, arg3, ...)
push!(ts_idxs, ContinuousTimeseries())
else
if has_index_cache(sys) && (ic = get_index_cache(sys)) !== nothing
Expand Down
5 changes: 4 additions & 1 deletion test/dde.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ prob = SDDEProblem(hayes_modelf, hayes_modelg, [1.0], h, tspan, pmul;
constant_lags = (pmul[1],));
sol = solve(prob, RKMil(), seed = 100)

@variables x(..) delx(t)
@parameters a=-4.0 b=-2.0 c=10.0 α=-1.3 β=-1.2 γ=1.1
@variables x(..)
@variables delx(t, a, b, c, α, β, γ) # equivalent to just delx(t)
@brownians η
τ = 1.0
eqs = [D(x(t)) ~ a * x(t) + b * x(t - τ) + c + (α * x(t) + γ) * η, delx ~ x(t - τ)]
Expand All @@ -88,6 +89,8 @@ eqs = [D(x(t)) ~ a * x(t) + b * x(t - τ) + c + (α * x(t) + γ) * η, delx ~ x(
@test equations(sys) == [D(x(t)) ~ a * x(t) + b * x(t - τ) + c]
@test isequal(ModelingToolkit.get_noise_eqs(sys), [α * x(t) + γ;;])
prob_mtk = SDDEProblem(sys, [x(t) => 1.0 + t], tspan; constant_lags = (τ,));
@test prob_mtk[delx] isa Float64
@test prob_mtk[x(t - τ)] isa Float64
@test_nowarn sol_mtk = solve(prob_mtk, RKMil(), seed = 100)

prob_sa = SDDEProblem(
Expand Down
10 changes: 10 additions & 0 deletions test/odesystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,13 @@ end
prob = ODEProblem(sys, [x => 1.0], (0.0, 1.0))
@test prob.problem_type == "A"
end

# https://github.com/SciML/ModelingToolkit.jl/issues/3737
@testset "ODE with multivariate variables" begin
@parameters k
@variables x(t, k) y(t, k) # equivalent to x(t) and y(t)
@mtkbuild sys = System([D(x) ~ 0, y ~ x + 1], t)
prob = ODEProblem(sys, [x => 0.0], (0.0, 1.0))
@test prob[x] == 0.0 # unknown
@test prob[y] == 1.0 # observed
end
Loading