Skip to content

Commit a7c387a

Browse files
Merge pull request #1062 from lamorton/fix_998a
Ensure explicit time-dependence for all ODESystem variables
2 parents 387e7e7 + 52b5068 commit a7c387a

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/systems/diffeqs/odesystem.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,19 @@ struct ODESystem <: AbstractODESystem
7373
type: type of the system
7474
"""
7575
connection_type::Any
76+
77+
function ODESystem(deqs, iv, dvs, ps, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, structure, connection_type)
78+
check_dependence(dvs,iv)
79+
new(deqs, iv, dvs, ps, observed, tgrad, jac, Wfact, Wfact_t, name, systems, defaults, structure, connection_type)
80+
end
7681
end
7782

83+
function check_dependence(dvs,iv)
84+
for dv in dvs
85+
isequal(iv, iv_from_nested_derivative(dv)) || throw(ArgumentError("Variable $dv is not a function of independent variable $iv."))
86+
end
87+
end
88+
7889
function ODESystem(
7990
deqs::AbstractVector{<:Equation}, iv, dvs, ps;
8091
observed = Num[],

test/lowering_solving.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ eqs = [D(x) ~ σ*(y-x),
4848
lorenz1 = ODESystem(eqs,name=:lorenz1)
4949
lorenz2 = ODESystem(eqs,name=:lorenz2)
5050

51-
@variables α
51+
@variables α(t)
5252
@parameters γ
5353
connections = [0 ~ lorenz1.x + lorenz2.y + α*γ]
5454
connected = ODESystem(connections,t,[α],[γ],systems=[lorenz1,lorenz2])

test/odesystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ ode = ODESystem(eq)
318318

319319
end
320320

321+
#Issue 998
322+
@parameters t
323+
pars = []
324+
vars = @variables((u1,))
325+
der = Differential(t)
326+
eqs = [
327+
der(u1) ~ 1,
328+
]
329+
@test_throws ArgumentError ODESystem(eqs,t,vars,pars)
330+
321331
@variables x(t)
322332
D = Differential(t)
323333
@parameters M b k

test/reactionsystem.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ end
189189

190190
# test for https://github.com/SciML/ModelingToolkit.jl/issues/436
191191
@parameters t
192-
@variables S I
192+
@variables S(t) I(t)
193193
rxs = [Reaction(1,[S],[I]), Reaction(1.1,[S],[I])]
194194
rs = ReactionSystem(rxs, t, [S,I], [])
195195
js = convert(JumpSystem, rs)
@@ -202,7 +202,7 @@ jprob = JumpProblem(rs, dprob, Direct(), save_positions=(false,false))
202202

203203

204204
@parameters k1 k2
205-
@variables R
205+
@variables R(t)
206206
rxs = [Reaction(k1*S, [S,I], [I], [2,3], [2]),
207207
Reaction(k2*R, [I], [R]) ]
208208
rs = ReactionSystem(rxs, t, [S,I,R], [k1,k2])

0 commit comments

Comments
 (0)