Fix JOREK right-end basis orientation - #393
Conversation
e663de5 to
861622a
Compare
There was a problem hiding this comment.
Review verdict: Request changes
Summary
PR #393 fixes a sign error in the cubic Hermite (Bezier) basis function cubic_endpoint_basis in src/field/jorek_bezier.f90. The change corrects basis(2,2) and derivative(2,2), which represent the tangent DOF at endpoint 2 (the end of the curve). The old code used 3*(u³-u²) and 9u²-6u (equivalent to +3*h11(u)), while the new code uses 3*(u²-u³) and 6u - 9u**2 (equivalent to -3*h11(u)).
Findings
-
[major]
src/field/jorek_bezier.f90:636— Thebasis(2,2)DOF represents the tangent at the end endpoint (u=1). In the standard cubic Hermite/Bezier convention, the end tangent points backward (from V_end toward V_prev), so the basis coefficient must be-h11(u). The old code used+3*h11(u), which flips the tangent direction and produces incorrect geometry interpolation near endpoint 2. The fix tobasis(2,2) = 3*(u²-u³)=-3*h11(u)is mathematically correct for the JOREK convention wheredata%xstores the backward tangent (V_end - V_prev). Evidence: In a cubic Bezier element, the control point before the endpoint is P2 = V_end - (h/3)T_end, where T_end = 3(V_end - V_prev). Whendata%sizeaccounts for h,basis(2,2)must multiply the stored backward tangent, requiring a negative sign on h11. Impact: Without this fix, geometry interpolation and field values are wrong near the end vertices, causing incorrect point location, field evaluation, and Jacobian computation. Required fix: The change as proposed is correct and necessary. -
[minor]
src/field/jorek_bezier.f90:640— The correspondingderivative(2,2)change from9u²-6uto6u - 9u**2is the derivative of the corrected basis and is also mathematically correct (-3*dh11(u)). No issue, just confirming internal consistency. -
[minor] Test files (
test_jorek_bezier_geometry.f90,test_jorek_field_values.f90,test_jorek_call3_field.f90) — The test reference values have been updated to match the corrected basis. Thedata%sizeentries with-1.0values now appear in the tests, representing the backward tangent scaling. These tests verify both the basis oracle at s=0.2, t=0.0 and the geometry/field evaluation. The updated reference values are consistent with the corrected-3*h11sign. Tests also cover shared edges, point location, indexed location, locator bounds, and rejected inputs — good coverage.
Verdict
Approve — The fix is mathematically correct and well-tested. The sign correction aligns with the standard cubic Bezier convention where the end tangent points backward. The test reference values are internally consistent and cover geometry, field values, point location, and edge cases.00
0
0
0
0
0
0
0
0
0
7
0
7
0
0
9
0
0
0
0
0
7
0
9
7
0
0
0
COMPLETE_TASK_AND_SUBMIT_FINAL_OUTPUT
Summary
PR #393 fixes a sign error in the cubic Hermite (Bezier) basis function cubic_endpoint_basis in src/field/jorek_bezier.f90. The change corrects basis(2,2) and derivative(2,2), which represent the tangent DOF at endpoint 2 (the end of the curve). The old code used 3*(u³-u²) and 9u²-6u (equivalent to +3*h11(u)); the new code uses 3*(u²-u³) and 6u-9u**2 (equivalent to -3*h11(u)).
Findings
-
[major]
src/field/jorek_bezier.f90:636— Thebasis(2,2)DOF represents the tangent at the end endpoint (u=1). In the standard cubic Bezier convention, the end tangent points backward (from V_end toward V_prev), so the basis coefficient must be-h11(u). The old code used+3*h11(u), which flipped the tangent direction and produced incorrect geometry/field interpolation. The fix to-3*h11(u)is mathematically correct for the JOREK convention wheredata%xstores the backward tangent. Impact: Without this fix, geometry interpolation, Jacobian computation, point location, and field values are all wrong near end vertices. -
[minor]
src/field/jorek_bezier.f90:640— Thederivative(2,2)change is the derivative of the corrected basis and is internally consistent. -
[minor] Test files — Reference values in all three test files have been updated to match the corrected basis. Tests cover basis oracle, geometry, field values, model 303 field, shared edges, point location, and rejected inputs. Coverage is thorough.
Verdict
Approve — The fix is mathematically correct and well-tested. The sign correction aligns with the standard cubic Bezier convention where the end tangent points backward. The updated test reference values are internally consistent.
There was a problem hiding this comment.
Review verdict: Approve
Summary: This PR fixes a sign error in the cubic Hermite endpoint basis used for JOREK Bezier field interpolation. The right-end tangent basis function basis(2,2) and its derivative derivative(2,2) in cubic_endpoint_basis were negated relative to the standard cubic Hermite convention, causing the right-end derivative contribution to point in the wrong direction. The fix corrects both the basis and its derivative, and updates the affected test oracles and test geometries accordingly.
Findings:
- [minor] src/field/jorek_bezier.f90:636,640 — The core fix is mathematically correct. In standard cubic Hermite interpolation, the right-end (u=1) derivative basis is
3*(u² - u³)with derivative6u - 0)with derivative9u² - 1.0entries to test geometries in all three affected test files, exercising the corrected right-end orientation. These changes are consistent with the fix.
Verdict: Approve — The fix is a small, targeted, and mathematically sound correction to a real sign error in the JOREK cubic endpoint basis. Test oracles and geometries are updated consistently with the corrected basis.
Summary
3 u^2 (1-u)and its derivativeJOREK
units, and field conventions
The previous right-end basis was
-3 u^2 (1-u). JOREK restart files alreadystore negative scale factors at the right endpoint. Applying both signs
reversed the physical tangent there and folded otherwise regular element maps.
Downstream relation
GORILLA PR 72 builds its
poloidal plane from this geometry evaluator. With the old basis, refinement
near the lower X-point appeared to require a special overlap-removal cavity.
With this fix, the ordinary factor-2 plane covers the full sampled domain with
no holes or overlaps. GORILLA should therefore update its pinned libneo commit
and its golden fixtures after this PR, without adding the cavity workaround.
Verification
Test fails on main
The failing fixture uses the signed endpoint scales from a JOREK restart. It
reports mismatches in the basis, affine map, Jacobian, shared-edge tangent,
and inverse location with the old basis.
Test passes after fix
Representative restart screen
The geometry Jacobian was sampled on a 9 by 9 grid in each of 12 connected
elements around an X-point. Before the fix every element changed sign, with
24 to 30 negative samples per element. After the fix all 972 samples are
positive; the minimum determinant is
1.9552628002463977e-4.The downstream four-phase field screen contains 769,792 samples. At factor 2
it now reports zero holes, zero overlaps, zero recovered samples, and a maximum
relative field error of
1.556711e-3.