Skip to content

Commit 0783668

Browse files
Merge pull request #536 from SciML/myb/no_error
Remove the error when no differential variables are present
2 parents 9a32fa3 + 83bd862 commit 0783668

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ModelingToolkit"
22
uuid = "961ee093-0014-501f-94e3-6117800e7a78"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "3.14.0"
4+
version = "3.14.1"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/systems/diffeqs/odesystem.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var_from_nested_derivative(x,i=0) = x.op isa Differential ? var_from_nested_deri
8080
iv_from_nested_derivative(x) = x.op isa Differential ? iv_from_nested_derivative(x.args[1]) : x.args[1].op
8181
iv_from_nested_derivative(x::Constant) = missing
8282

83-
function ODESystem(eqs; kwargs...)
83+
function ODESystem(eqs, iv=nothing; kwargs...)
8484
# NOTE: this assumes that the order of algebric equations doesn't matter
8585
diffvars = OrderedSet{Variable}()
8686
allstates = OrderedSet{Variable}()
@@ -89,13 +89,15 @@ function ODESystem(eqs; kwargs...)
8989
diffeq = Equation[]
9090
algeeq = Equation[]
9191
# initial loop for finding `iv`
92-
iv = nothing
93-
for eq in eqs
94-
if !(eq.lhs isa Constant) # assume eq.lhs is either Differential or Constant
95-
iv = iv_from_nested_derivative(eq.lhs)
92+
if iv === nothing
93+
for eq in eqs
94+
if !(eq.lhs isa Constant) # assume eq.lhs is either Differential or Constant
95+
iv = iv_from_nested_derivative(eq.lhs)
96+
break
97+
end
9698
end
9799
end
98-
iv === nothing && throw(ArgumentError("No differential variable detected."))
100+
iv === nothing && throw(ArgumentError("Please pass in independent variables."))
99101
for eq in eqs
100102
for var in vars(eq.rhs for eq eqs)
101103
var isa Variable || continue

test/mass_matrix.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ eqs = [D(y[1]) ~ -k[1]*y[1] + k[3]*y[2]*y[3],
99
0 ~ y[1] + y[2] + y[3] - 1]
1010

1111
sys = ODESystem(eqs,t,y,k)
12+
@test_throws ArgumentError ODESystem(eqs,y)
1213
M = calculate_massmatrix(sys)
1314
@test M == [1 0 0
1415
0 1 0

0 commit comments

Comments
 (0)