Skip to content

Commit 084561a

Browse files
fix: correctly order unknowns in System constructor
1 parent b394fcf commit 084561a

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/systems/system.jl

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,35 @@ end
190190
function System(eqs::Vector{Equation}, iv; kwargs...)
191191
iv === nothing && return System(eqs; kwargs...)
192192

193-
allunknowns = Set()
193+
diffvars = OrderedSet()
194+
othervars = OrderedSet()
194195
ps = Set()
196+
diffeqs = Equation[]
197+
othereqs = Equation[]
195198
for eq in eqs
196-
collect_vars!(allunknowns, ps, eq, iv)
199+
if !(eq.lhs isa Union{Symbolic, Number})
200+
push!(othereqs, eq)
201+
continue
202+
end
203+
collect_vars!(othervars, ps, eq, iv)
204+
if operation(eq.lhs) isa Differential
205+
var, _ = var_from_nested_derivative(eq.lhs)
206+
if var in diffvars
207+
throw(ArgumentError("""
208+
The differential variable $var is not unique in the system of \
209+
equations.
210+
"""))
211+
end
212+
push!(diffvars, var)
213+
push!(diffeqs, eq)
214+
else
215+
push!(othereqs, eq)
216+
end
197217
end
198218

219+
allunknowns = union(diffvars, othervars)
220+
eqs = [diffeqs; othereqs]
221+
199222
brownians = Set()
200223
for x in allunknowns
201224
x = unwrap(x)

0 commit comments

Comments
 (0)