Skip to content

Commit 14350ab

Browse files
add test
1 parent e76352b commit 14350ab

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/downstream/gtpsa.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using OrdinaryDiffEq, ForwardDiff, GTPSA, Test
22

3+
# ODEProblem 1 =======================
4+
35
f!(du, u, p, t) = du .= p .* u
46

57
# Initial variables and parameters
@@ -37,3 +39,38 @@ for i in 1:3
3739
@test Hi_FD GTPSA.hessian(sol_GTPSA.u[end][i], include_params=true)
3840
end
3941

42+
43+
# ODEProblem 2 =======================
44+
pdot!(dq, p, q, params, t) = dq .= [0.0, 0.0, 0.0]
45+
qdot!(dp, p, q, params, t) = dp .= [p[1] / sqrt((1 + p[3])^2 - p[1]^2 - p[2]^2),
46+
p[2] / sqrt((1 + p[3])^2 - p[1]^2 - p[2]^2),
47+
p[3] / sqrt(1 + p[3]^2) - (p[3] + 1)/sqrt((1 + p[3])^2 - p[1]^2 - p[2]^2)]
48+
49+
prob = DynamicalODEProblem(pdot!, qdot!, [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], (0.0, 25.0))
50+
sol = solve(prob, Yoshida6(), dt = 1.0, reltol=1e-16, abstol=1e-16)
51+
52+
desc = Descriptor(6, 2) # 6 variables to 2nd order
53+
dx = vars(desc) # identity map
54+
prob_GTPSA = DynamicalODEProblem(pdot!, qdot!, dx[1:3], dx[4:6], (0.0, 25.0))
55+
sol_GTPSA = solve(prob_GTPSA, Yoshida6(), dt = 1.0, reltol=1e-16, abstol=1e-16)
56+
57+
@test sol.u[end] scalar.(sol_GTPSA.u[end]) # scalar gets 0th order part
58+
59+
# Compare Jacobian against ForwardDiff
60+
J_FD = ForwardDiff.jacobian(zeros(6)) do t
61+
prob = DynamicalODEProblem(pdot!, qdot!, t[1:3], t[4:6], (0.0, 25.0))
62+
sol = solve(prob, Yoshida6(), dt = 1.0, reltol=1e-16, abstol=1e-16)
63+
sol.u[end]
64+
end
65+
66+
@test J_FD GTPSA.jacobian(sol_GTPSA.u[end], include_params=true)
67+
68+
# Compare Hessians against ForwardDiff
69+
for i in 1:6
70+
Hi_FD = ForwardDiff.hessian(zeros(6)) do t
71+
prob = DynamicalODEProblem(pdot!, qdot!, t[1:3], t[4:6], (0.0, 25.0))
72+
sol = solve(prob, Yoshida6(), dt = 1.0, reltol=1e-16, abstol=1e-16)
73+
sol.u[end][i]
74+
end
75+
@test Hi_FD GTPSA.hessian(sol_GTPSA.u[end][i], include_params=true)
76+
end

0 commit comments

Comments
 (0)