Skip to content

Commit c35cea8

Browse files
authored
Merge pull request #714 from SciML/myb/order_lowering
Fix order lowering
2 parents 0551172 + 632f426 commit c35cea8

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
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 = "4.4.2"
4+
version = "4.4.3"
55

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

src/systems/diffeqs/first_order_transform.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ function ode_order_lowering(eqs, iv, states)
1515
diff_eqs = Equation[]
1616
diff_vars = []
1717
alge_eqs = Equation[]
18-
alge_vars = []
1918

20-
for (i, (eq, ss)) enumerate(zip(eqs, states))
21-
if _iszero(eq.lhs)
22-
push!(alge_vars, ss)
19+
for (i, eq) enumerate(eqs)
20+
if !isdiffeq(eq)
2321
push!(alge_eqs, eq)
2422
else
2523
var, maxorder = var_from_nested_derivative(eq.lhs)
26-
# only save to the dict when we need to lower the order to save memory
2724
maxorder > get(var_order, var, 1) && (var_order[var] = maxorder)
2825
var′ = lower_varname(var, iv, maxorder - 1)
2926
rhs′ = diff2term(eq.rhs)
@@ -45,5 +42,5 @@ function ode_order_lowering(eqs, iv, states)
4542
end
4643

4744
# we want to order the equations and variables to be `(diff, alge)`
48-
return (vcat(diff_eqs, alge_eqs), vcat(diff_vars, alge_vars))
45+
return (vcat(diff_eqs, alge_eqs), vcat(diff_vars, setdiff(states, diff_vars)))
4946
end

test/odesystem.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ eqs = [D(x) ~ -A*x,
145145
D(y) ~ A*x - B*_x]
146146
de = ODESystem(eqs)
147147
@test begin
148-
local f
148+
local f, du
149149
f = eval(generate_function(de, [x,y], [A,B,C])[2])
150150
du = [0.0,0.0]
151151
f(du, [1.0,2.0], [1,2,3], 0.0)
@@ -225,3 +225,12 @@ using ModelingToolkit
225225
@derivatives D'~t
226226
sys = ODESystem([D(x) ~ a])
227227
@test sys.eqs[1].rhs isa Sym
228+
229+
# issue 708
230+
@parameters t a
231+
@variables x(t) y(t) z(t)
232+
@derivatives D'~t
233+
sys = ODESystem([D(x) ~ y, 0 ~ x + z, 0 ~ x - y], t, [z, y, x], [])
234+
sys2 = ode_order_lowering(sys)
235+
M = ModelingToolkit.calculate_massmatrix(sys2)
236+
@test M == Diagonal([1, 0, 0])

0 commit comments

Comments
 (0)