Skip to content

Commit 48afd37

Browse files
committed
Add tests
1 parent 82e31d1 commit 48afd37

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/modelingtoolkitize.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,27 @@ prob = ODEProblem(f, rv0, (0.0, Δt), μ)
160160
sol = solve(prob, Vern8())
161161

162162
modelingtoolkitize(prob)
163+
164+
# Index reduction and mass matrix handling
165+
function pendulum!(du, u, p, t)
166+
x, dx, y, dy, T = u
167+
g, L = p
168+
du[1] = dx
169+
du[2] = T*x
170+
du[3] = dy
171+
du[4] = T*y - g
172+
du[5] = x^2 + y^2 - L^2
173+
return nothing
174+
end
175+
pendulum_fun! = ODEFunction(pendulum!, mass_matrix=Diagonal([1,1,1,1,0]))
176+
u0 = [1.0, 0, 0, 0, 0]
177+
p = [9.8, 1]
178+
tspan = (0, 10.0)
179+
pendulum_prob = ODEProblem(pendulum_fun!, u0, tspan, p)
180+
pendulum_sys = dae_index_lowering(modelingtoolkitize(pendulum_prob))
181+
prob = ODEProblem(pendulum_sys, Pair[], tspan)
182+
sol = solve(prob, Rodas4())
183+
@parameters t
184+
@variables x[1:5](t)
185+
l2 = sol[x[1]].^2 + sol[x[3]].^2
186+
@test all(l->abs(sqrt(l) - 1) < 0.05, l2)

0 commit comments

Comments
 (0)