Skip to content

Commit b1f1112

Browse files
committed
Add comments and tests
1 parent 7720991 commit b1f1112

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/systems/diffeqs/first_order_transform.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function ode_order_lowering(eqs, iv, states)
5959
end
6060
end
6161

62+
# we want to order the equations and variables to be `(diff, alge)`
6263
return (vcat(diff_eqs, alge_eqs), vcat(diff_vars, alge_vars))
6364
end
6465

test/lowering_solving.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
using ModelingToolkit, OrdinaryDiffEq, Test
1+
using ModelingToolkit, OrdinaryDiffEq, Test, LinearAlgebra
22

33
@parameters t σ ρ β
4-
@variables x(t) y(t) z(t)
4+
@variables x(t) y(t) z(t) k(t)
55
@derivatives D'~t
66

77
eqs = [D(D(x)) ~ σ*(y-x),
88
D(y) ~ x*-z)-y,
99
D(z) ~ x*y - β*z]
1010

11-
sys = ODESystem(eqs)
12-
sys = ode_order_lowering(sys)
11+
sys′ = ODESystem(eqs)
12+
sys = ode_order_lowering(sys′)
13+
14+
eqs2 = [0 ~ x*y - k,
15+
D(D(x)) ~ σ*(y-x),
16+
D(y) ~ x*-z)-y,
17+
D(z) ~ x*y - β*z]
18+
sys2 = ODESystem(eqs2, t, [x, y, z, k], sys′.ps)
19+
sys2 = ode_order_lowering(sys2)
20+
# test equation/varible ordering
21+
ModelingToolkit.calculate_massmatrix(sys2) == Diagonal([1, 1, 1, 1, 0])
1322

1423
u0 = [D(x) => 2.0,
1524
x => 1.0,

0 commit comments

Comments
 (0)