Skip to content

Commit 014a631

Browse files
Updates
1 parent 83b1d73 commit 014a631

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

benchmarks/DynamicalODE/Henon-Heiles_energy_conservation_benchmark.jmd

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,27 @@ function hamilton(du, u, p, t)
6363
return nothing
6464
end
6565

66+
function custom_manifold_jacobian(u, params)
67+
p1, p2, q1, q2 = u
68+
69+
J = zeros(4, 4)
70+
71+
J[1, 1] = 1.0
72+
J[2, 2] = 1.0
73+
J[3, 3] = 1 + 2 * q_2
74+
J[3, 4] = 2 * q1
75+
J[4, 3] = 2 * q1
76+
J[4, 4] = 1 - 4 * q2
77+
78+
return J
79+
end
80+
6681
function g(resid, u, p)
6782
resid[1] = H([u[1], u[2]], [u[3], u[4]], nothing) - E
6883
resid[2:4] .= 0
6984
end
7085

71-
const cb = ManifoldProjection(g, nlopts=Dict(:ftol => 1e-13))
86+
const cb = ManifoldProjection(g, nlopts=Dict(:ftol => 1e-13), manifold_jacobian = custom_manifold_jacobian)
7287
const E = H(iip_p0, iip_q0, nothing)
7388
```
7489

benchmarks/DynamicalODE/Quadrupole_boson_Hamiltonian_energy_conservation_benchmark.jmd

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,27 @@ function hamilton(z, params, t)
6161
)
6262
end
6363

64+
function custom_manifold_jacobian(u, params)
65+
p0, p2, q0, q2 = u
66+
67+
J = zeros(4, 4)
68+
69+
J[1, 1] = A * p0
70+
J[2, 2] = A * p2
71+
72+
J[3, 3] = A * q0 - sqrt(2) * B * (3 * q2^2 - q0^2) + D * q0 * (q0^2 + q2^2) # ∂H/∂q0
73+
J[4, 4] = A * q2 + 6 * B * q0 * q2 + D * q2 * (q0^2 + q2^2) # ∂H/∂q2
74+
75+
return J
76+
end
77+
6478
function g(resid, u, p)
6579
resid[1] = H([u[1],u[2]],[u[3],u[4]],nothing) - E
6680
resid[2:4] .= 0
6781
end
6882

6983
const E = H(iip_p0, iip_q0, nothing)
70-
const cb = ManifoldProjection(g, nlopts=Dict(:ftol=>1e-13));
84+
const cb = ManifoldProjection(g, nlopts=Dict(:ftol=>1e-13), manifold_jacobian = custom_manifold_jacobian);
7185
```
7286

7387
For the comparison we will use the following function

0 commit comments

Comments
 (0)