Skip to content

Commit a82a868

Browse files
authored
Merge pull request #1739 from SciML/myb/check
Check states and parameters are actually states and parameters
2 parents 5d94f39 + 8e1f012 commit a82a868

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/utils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ function check_parameters(ps, iv)
126126
for p in ps
127127
isequal(iv, p) &&
128128
throw(ArgumentError("Independent variable $iv not allowed in parameters."))
129+
isparameter(p) ||
130+
throw(ArgumentError("$p is not a parameter."))
129131
end
130132
end
131133

@@ -150,6 +152,8 @@ function check_variables(dvs, iv)
150152
throw(ArgumentError("Independent variable $iv not allowed in dependent variables."))
151153
(is_delay_var(iv, dv) || occursin(iv, dv)) ||
152154
throw(ArgumentError("Variable $dv is not a function of independent variable $iv."))
155+
isparameter(dv) &&
156+
throw(ArgumentError("$dv is not a state. It is a parameter."))
153157
end
154158
end
155159

test/odesystem.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,3 +867,13 @@ let
867867
prob = ODAEProblem(sys4s, [x => 1.0, D(x) => 1.0], (0, 1.0))
868868
@test string.(prob.f.syms) == ["x(t)", "xˍt(t)"]
869869
end
870+
871+
let
872+
@variables t
873+
@parameters P(t) Q(t)
874+
∂t = Differential(t)
875+
876+
eqs = [∂t(Q) ~ 0.2P
877+
∂t(P) ~ -80.0sin(Q)]
878+
@test_throws ArgumentError @named sys = ODESystem(eqs)
879+
end

0 commit comments

Comments
 (0)