|
| 1 | +using OrdinaryDiffEq, OrdinaryDiffEqTaylorSeries, TaylorIntegration, StaticArrays, |
| 2 | + DiffEqDevTools, BenchmarkTools, Plots |
| 3 | + |
| 4 | +@taylorize function pcr3bp!(dq, q, param, t) |
| 5 | + local μ = param[1] |
| 6 | + local onemμ = 1 - μ |
| 7 | + x1 = q[1] - μ |
| 8 | + x1sq = x1^2 |
| 9 | + y = q[2] |
| 10 | + ysq = y^2 |
| 11 | + r1_1p5 = (x1sq + ysq)^1.5 |
| 12 | + x2 = q[1] + onemμ |
| 13 | + x2sq = x2^2 |
| 14 | + r2_1p5 = (x2sq + ysq)^1.5 |
| 15 | + dq[1] = q[3] + q[2] |
| 16 | + dq[2] = q[4] - q[1] |
| 17 | + dq[3] = (-((onemμ * x1) / r1_1p5) - ((μ * x2) / r2_1p5)) + q[4] |
| 18 | + dq[4] = (-((onemμ * y) / r1_1p5) - ((μ * y) / r2_1p5)) - q[3] |
| 19 | + return nothing |
| 20 | +end |
| 21 | + |
| 22 | +const μ = 0.01 |
| 23 | +V(x, y) = -(1 - μ) / sqrt((x - μ)^2 + y^2) - μ / sqrt((x + 1 - μ)^2 + y^2) |
| 24 | +H(x, y, px, py) = (px^2 + py^2) / 2 - (x * py - y * px) + V(x, y) |
| 25 | +H(x) = H(x...) |
| 26 | +J0 = -1.58 |
| 27 | +function py!(q0, J0) |
| 28 | + @assert iszero(q0[2]) && iszero(q0[3]) # q0[2] and q0[3] have to be equal to zero |
| 29 | + q0[4] = q0[1] + sqrt(q0[1]^2 - 2(V(q0[1], q0[2]) - J0)) |
| 30 | + nothing |
| 31 | +end |
| 32 | +q0 = [-0.8, 0.0, 0.0, 0.0] |
| 33 | +py!(q0, J0) |
| 34 | +tspan = (0.0, 2000.0) |
| 35 | +p = SA[μ] |
| 36 | +prob = ODEProblem{true, SciMLBase.FullSpecialize}(pcr3bp!, q0, tspan, p) |
| 37 | + |
| 38 | +ref = solve(prob, Vern9(), abstol = 1e-10, reltol = 1e-10) |
| 39 | + |
| 40 | +@benchmark solve($prob, $(TaylorMethod(25)), abstol = 1e-15) |
| 41 | +@benchmark solve($prob, $(ExplicitTaylor(order = Val(25))), abstol = 1e-15, reltol = 1e-15) |
| 42 | +@benchmark solve($prob, $(Vern9()), abstol = 1e-15, reltol = 1e-15) |
0 commit comments