fix: apply chain rule in StructuredGrid2D element gradient - #293
Merged
Conversation
StructuredGrid2D.get_element_gradient_for_location returned shape-function derivatives with respect to local (0-1) cell coordinates, so gradients were inflated by step_vector on each axis and became resolution-dependent. Mirror the division by step_vector that StructuredGrid3D already does. Fixes Loop3D#289
lachlangrose
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #289
StructuredGrid2D.get_element_gradient_for_locationreturned the shape-function derivatives with respect to local (0-1) cell coordinates, so gradients came out multiplied bystep_vectoron each axis and were silently resolution-dependent (directionally biased for anisotropic cells). This mirrors the division bystep_vectorthatStructuredGrid3Dalready does at the end of its implementation.Added two regression tests in
test_2d_discrete_support.py: a support-level check with anisotropic cells asserting unit gradients in world units, and an FDI-level check (condensed from the issue's reproducer) asserting the interpolated gradient magnitude stays ~1 across two resolutions. Full test suite passes locally (708 passed).