Skip to content

Fix JOREK right-end basis orientation - #393

Open
krystophny wants to merge 1 commit into
mainfrom
fix/jorek-right-end-basis
Open

Fix JOREK right-end basis orientation#393
krystophny wants to merge 1 commit into
mainfrom
fix/jorek-right-end-basis

Conversation

@krystophny

Copy link
Copy Markdown
Member

Summary

  • use the positive right-end cubic Bernstein control-offset basis
    3 u^2 (1-u) and its derivative
  • give the synthetic fixtures the signed right-end scale factors stored by
    JOREK
  • preserve the existing nodal values, left-end tangents, array layout, ABI,
    units, and field conventions

The previous right-end basis was -3 u^2 (1-u). JOREK restart files already
store 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

$ fo test test_jorek_bezier_geometry
test_jorek_bezier_geometry                 FAIL       0.06s
Summary: 0 passed, 1 failed, 0 skipped (  0.06s)

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

$ fo test test_jorek_bezier_geometry test_jorek_field_values test_jorek_model303_field
test_jorek_field_values                    PASS       0.05s
test_jorek_model303_field                  PASS       0.05s
test_jorek_bezier_geometry                 PASS       0.05s
Summary: 3 passed, 0 failed, 0 skipped (  0.15s)

$ fo test --all --json
summary: 86 passed, 0 failed, 0 skipped; exit_code: 0

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.

@krystophny
krystophny force-pushed the fix/jorek-right-end-basis branch from e663de5 to 861622a Compare July 17, 2026 11:26

@slopqueue slopqueue Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. [major] src/field/jorek_bezier.f90:636 — The basis(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 to basis(2,2) = 3*(u²-u³) = -3*h11(u) is mathematically correct for the JOREK convention where data%x stores 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). When data%size accounts 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.

  2. [minor] src/field/jorek_bezier.f90:640 — The corresponding derivative(2,2) change from 9u²-6u to 6u - 9u**2 is the derivative of the corrected basis and is also mathematically correct (-3*dh11(u)). No issue, just confirming internal consistency.

  3. [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. The data%size entries with -1.0 values 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*h11 sign. 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

  1. [major] src/field/jorek_bezier.f90:636 — The basis(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 where data%x stores the backward tangent. Impact: Without this fix, geometry interpolation, Jacobian computation, point location, and field values are all wrong near end vertices.

  2. [minor] src/field/jorek_bezier.f90:640 — The derivative(2,2) change is the derivative of the corrected basis and is internally consistent.

  3. [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.

@slopqueue slopqueue Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. [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 derivative 6u - 0) with derivative 9u² - 1.0 entries 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant