11using ModelingToolkit, OrdinaryDiffEq, Test
22using ModelingToolkitStandardLibrary. Mechanical. PlanarMechanics
3+ # using Plots
34
45@parameters t
56D = Differential (t)
7+ tspan = (0.0 , 3.0 )
8+
9+ @testset " Free body" begin
10+ @named body = Body (m = 1 , j = 0.1 )
11+ @named model = ODESystem (Equation[],
12+ t,
13+ [],
14+ [],
15+ systems = [body])
16+ sys = structural_simplify (model)
17+ unset_vars = setdiff (states (sys), keys (ModelingToolkit. defaults (sys)))
18+ prob = ODEProblem (sys, unset_vars .=> 0.0 , tspan, []; jac = true )
19+
20+ sol = solve (prob, Rodas5P ())
21+ @test SciMLBase. successful_retcode (sol)
22+
23+ free_falling_displacement = - 0.5 * 9.807 * tspan[2 ]^ 2 # 0.5 * g * t^2
24+ @test sol[body. ry][end ] ≈ free_falling_displacement
25+ # plot(sol, idxs = [body.rx, body.ry])
26+ end
627
728@testset " Pendulum" begin
829 @named ceiling = Fixed ()
@@ -23,7 +44,7 @@ D = Differential(t)
2344 systems = [body, revolute, rod, ceiling])
2445 sys = structural_simplify (model)
2546 unset_vars = setdiff (states (sys), keys (ModelingToolkit. defaults (sys)))
26- prob = ODEProblem (sys, unset_vars .=> 0.0 , ( 0.0 , 60 ) , []; jac = true )
47+ prob = ODEProblem (sys, unset_vars .=> 0.0 , tspan , []; jac = true )
2748 sol = solve (prob, Rodas5P ())
2849
2950 # phi and omega for the pendulum body
0 commit comments