1
1
using ModelingToolkit, OrdinaryDiffEq, Test
2
2
using ModelingToolkitStandardLibrary. Mechanical. PlanarMechanics
3
+ # using Plots
3
4
4
5
@parameters t
5
6
D = 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
6
27
7
28
@testset " Pendulum" begin
8
29
@named ceiling = Fixed ()
@@ -23,7 +44,7 @@ D = Differential(t)
23
44
systems = [body, revolute, rod, ceiling])
24
45
sys = structural_simplify (model)
25
46
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 )
27
48
sol = solve (prob, Rodas5P ())
28
49
29
50
# phi and omega for the pendulum body
0 commit comments