Skip to content

Commit 5469bd7

Browse files
committed
Remove the error when no differential variables are not present
1 parent 9a32fa3 commit 5469bd7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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)