|
44 | 44 | ### Testing on pendulum |
45 | 45 | let |
46 | 46 | @parameters g=9.81 L=1.0 |
47 | | - @variables θ(t) = π / 2 |
| 47 | + @variables θ(t) = π / 2 θ_t(t) |
48 | 48 |
|
49 | | - eqs = [D(D(θ)) ~ -(g / L) * sin(θ)] |
| 49 | + eqs = [D(θ) ~ θ_t |
| 50 | + D(θ_t) ~ -(g / L) * sin(θ)] |
50 | 51 |
|
51 | 52 | @mtkbuild pend = ODESystem(eqs, t) |
52 | 53 |
|
53 | | - u0map = [θ => π / 2, D(θ) => π / 2] |
| 54 | + u0map = [θ => π / 2, θ_t => π / 2] |
54 | 55 | parammap = [:L => 1.0, :g => 9.81] |
55 | 56 | tspan = (0.0, 6.0) |
56 | 57 |
|
|
74 | 75 | end |
75 | 76 | end |
76 | 77 |
|
77 | | -################################################### |
78 | | -### ODESystem with Constraint Equations, DAEs with constraints ### |
79 | | -################################################### |
| 78 | +################################################################## |
| 79 | +### ODESystem with constraint equations, DAEs with constraints ### |
| 80 | +################################################################## |
80 | 81 |
|
81 | 82 | # Cartesian pendulum from the docs. |
82 | 83 | # DAE IVP solved using BoundaryValueDiffEq solvers. |
|
90 | 91 |
|
91 | 92 | tspan = (0.0, 1.5) |
92 | 93 | u0map = [x => 1, y => 0] |
93 | | - parammap = [g => 1] |
94 | | - guesses = [λ => 1] |
| 94 | + pmap = [g => 1] |
| 95 | + guess = [λ => 1] |
95 | 96 |
|
96 | | - prob = ODEProblem(pend, u0map, tspan, pmap; guesses) |
97 | | - sol = solve(prob, Rodas5P()) |
| 97 | + prob = ODEProblem(pend, u0map, tspan, pmap; guesses = guess) |
| 98 | + osol = solve(prob, Rodas5P()) |
98 | 99 |
|
99 | | - bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap; guesses) |
| 100 | + bvp = SciMLBase.BVProblem{true, SciMLBase.AutoSpecialize}(pend, u0map, tspan, parammap; guesses = guess) |
100 | 101 |
|
101 | 102 | for solver in solvers |
102 | | - sol = solve(bvp, solver(), dt = 0.01) |
| 103 | + sol = solve(bvp, solver(), dt = 0.001) |
103 | 104 | @test isapprox(sol.u[end], osol.u[end]; atol = 0.01) |
104 | 105 | conditions = getfield.(equations(pend)[3:end], :rhs) |
105 | | - @test [sol[conditions][1]; sol[x][1] - 1; sol[y][1]] ≈ 0 |
| 106 | + @test isapprox([sol[conditions][1]; sol[x][1] - 1; sol[y][1]], zeros(5), atol = 0.001) |
106 | 107 | end |
107 | 108 |
|
108 | 109 | bvp2 = SciMLBase.BVProblem{false, SciMLBase.FullSpecialize}(pend, u0map, tspan, parammap) |
|
0 commit comments