Skip to content

Commit 1de3e76

Browse files
committed
Add a manual example of converting graph to eqs
1 parent 6cb4f23 commit 1de3e76

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/index_reduction.jl

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ edges, vars, vars_asso = sys2bigraph(pendulum)
3535

3636
edges, assign, vars_asso, eqs_asso = ModelingToolkit.pantelides(pendulum)
3737

38+
function new_system(sys, assign, vars_asso, eqs_asso)
39+
end
40+
3841
@test sort.(edges) == sort.([
3942
[5, 3], # 1
4043
[6, 4], # 2
@@ -47,7 +50,7 @@ edges, assign, vars_asso, eqs_asso = ModelingToolkit.pantelides(pendulum)
4750
[2, 1, 6, 5, 11, 10], # 9
4851
])
4952
# [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
50-
# [x, y, w, z, x', y', w', z', T, x'', y'']
53+
# [x, y, w, z, x', y', w', z', T, x'', y''] -- how can I get this vector of symbols?
5154
@test vars_asso == [5, 6, 7, 8, 10, 11, 0, 0, 0, 0, 0]
5255
#1: D(x) ~ w
5356
#2: D(y) ~ z
@@ -61,3 +64,38 @@ edges, assign, vars_asso, eqs_asso = ModelingToolkit.pantelides(pendulum)
6164
#9: D(6) -> 0 ~ 2xx'' + 2x'x' + 2yy'' + 2y'y'
6265
# [1, 2, 3, 4, 5, 6, 7, 8, 9]
6366
@test eqs_asso == [7, 8, 0, 0, 6, 9, 0, 0, 0]
67+
68+
using ModelingToolkit
69+
@parameters t L g
70+
@variables x(t) y(t) w(t) z(t) T(t) xˍt(t) yˍt(t)
71+
@derivatives D'~t
72+
idx1_pendulum = [D(x) ~ w,
73+
D(y) ~ z,
74+
D(w) ~ T*x,
75+
D(z) ~ T*y - g,
76+
#0 ~ x^2 + y^2 - L^2,
77+
#0 ~ 2x*w + 2y*z,
78+
#D(xˍt) ~ D(w),
79+
D(xˍt) ~ T*x,
80+
# D(D(x)) ~ D(w) and substitute the rhs
81+
#D(D(x)) ~ T*x,
82+
# D(D(y)) ~ D(z) and substitute the rhs
83+
#D(D(y)) ~ T*y - g,
84+
D(yˍt) ~ T*y - g,
85+
# 2x*D(D(x)) + 2*D(x)*D(x) + 2y*D(D(y)) + 2*D(y)*D(y) and
86+
# substitute the rhs
87+
0 ~ 2x*(T*x) + 2*xˍt*xˍt + 2y*(T*y - g) + 2*yˍt*yˍt]
88+
idx1_pendulum = ODESystem(idx1_pendulum, t, [x, y, w, z, xˍt, yˍt, T], [L, g])
89+
first_order_idx1_pendulum = ode_order_lowering(idx1_pendulum)
90+
91+
using OrdinaryDiffEq
92+
using LinearAlgebra
93+
# [x, y, w, z, xˍt, yˍt, T]
94+
#M = Diagonal([1, 1, 1, 1, 1, 1, 0])
95+
prob = ODEProblem(ODEFunction(first_order_idx1_pendulum),
96+
# [x, y, w, z, xˍt, yˍt, T]
97+
[1, 0, 0, 0, 0, 0, 0.0],# 0, 0, 0, 0],
98+
(0, 100.0),
99+
[1, 9.8],
100+
mass_matrix=calculate_massmatrix(first_order_idx1_pendulum))
101+
sol = solve(prob, Rodas5())

0 commit comments

Comments
 (0)