Skip to content

Fix left-handed MAPAXES placing the model in the wrong location - #60

Merged
cpgr merged 1 commit into
masterfrom
mapaxes-orientation
Aug 13, 2026
Merged

Fix left-handed MAPAXES placing the model in the wrong location#60
cpgr merged 1 commit into
masterfrom
mapaxes-orientation

Conversation

@cpgr

@cpgr cpgr commented Aug 13, 2026

Copy link
Copy Markdown
Owner

A MAPAXES keyword may define a left-handed pair of axes. Applying it as specified mirrors the grid's orientation, giving every element a negative Jacobian. The reader compensated by negating the x-axis vector before the transform, which does restore positive Jacobians -- but by mirroring the model into the wrong place.

For the grid reported in issue #37 (MAPAXES -10000 9000 -10000 10000 -9000 10000, local extent 0..20000), Petrel reports bounds of x: -10000..10000. The reader produced x: -30000..-10000: right shape, wrong place, and with healthy looking Jacobians giving no hint that anything was wrong.

Handedness is a property of the node ordering, not the node positions, so fix it in the ordering: apply the transform exactly as MAPAXES specifies, then reverse the j index order, which relabels cells without moving them. This is the same mechanism the reader already used for grids whose COORD is in decreasing order, which is why that path always produced correct geometry -- it just ran before the transform and so never saw an inversion introduced by MAPAXES.

The new orientation test uses the determinant of the lateral (i, j) direction vectors rather than per-axis monotonicity, so it stays correct when a rotation leaves x varying along j rather than along i.

The pre-existing monotonicity checks are kept as they are. They also canonicalise the index order rather than only the handedness: a grid with both axes decreasing is already right-handed but still needs both indices reversed to match the conventional ordering.

Adds mapaxes_lefthanded.grdecl covering the exact case from the issue. Its four PORO values are distinct so the gold pins which cell landed where, not just the bounding box -- a mirrored copy of that symmetric grid has an identical bounding box. Verified that this test fails on master, with all four cells misplaced.

gold/simple_cube_mapaxes.e is regenerated: its MAPAXES is also left-handed (a reflection swapping x and y), so the old gold encoded the mirrored output. The replacement was checked against the analytic transform -- every cell centroid at (local_y, local_x) with its properties -- rather than blessed from program output.

Also drops the flip_x/flip_y locals, which were assigned but never read, and extracts the shared axis-reversal into _reverseGridAxis.

A MAPAXES keyword may define a left-handed pair of axes. Applying it as
specified mirrors the grid's orientation, giving every element a negative
Jacobian. The reader compensated by negating the x-axis vector before the
transform, which does restore positive Jacobians -- but by mirroring the
model into the wrong place.

For the grid reported in issue #37 (MAPAXES -10000 9000 -10000 10000
-9000 10000, local extent 0..20000), Petrel reports bounds of
x: -10000..10000. The reader produced x: -30000..-10000: right shape,
wrong place, and with healthy looking Jacobians giving no hint that
anything was wrong.

Handedness is a property of the node ordering, not the node positions, so
fix it in the ordering: apply the transform exactly as MAPAXES specifies,
then reverse the j index order, which relabels cells without moving them.
This is the same mechanism the reader already used for grids whose COORD
is in decreasing order, which is why that path always produced correct
geometry -- it just ran before the transform and so never saw an inversion
introduced by MAPAXES.

The new orientation test uses the determinant of the lateral (i, j)
direction vectors rather than per-axis monotonicity, so it stays correct
when a rotation leaves x varying along j rather than along i.

The pre-existing monotonicity checks are kept as they are. They also
canonicalise the index order rather than only the handedness: a grid with
both axes decreasing is already right-handed but still needs both indices
reversed to match the conventional ordering.

Adds mapaxes_lefthanded.grdecl covering the exact case from the issue. Its
four PORO values are distinct so the gold pins which cell landed where,
not just the bounding box -- a mirrored copy of that symmetric grid has an
identical bounding box. Verified that this test fails on master, with all
four cells misplaced.

gold/simple_cube_mapaxes.e is regenerated: its MAPAXES is also left-handed
(a reflection swapping x and y), so the old gold encoded the mirrored
output. The replacement was checked against the analytic transform --
every cell centroid at (local_y, local_x) with its properties -- rather
than blessed from program output.

Also drops the flip_x/flip_y locals, which were assigned but never read,
and extracts the shared axis-reversal into _reverseGridAxis.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@cpgr
cpgr merged commit d51cb0d into master Aug 13, 2026
1 check passed
@cpgr
cpgr deleted the mapaxes-orientation branch August 13, 2026 21:13
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