Skip to content

fix: apply chain rule in StructuredGrid2D element gradient - #293

Merged
lachlangrose merged 1 commit into
Loop3D:masterfrom
manduinca:fix/2d-gradient-chain-rule
Aug 4, 2026
Merged

fix: apply chain rule in StructuredGrid2D element gradient#293
lachlangrose merged 1 commit into
Loop3D:masterfrom
manduinca:fix/2d-gradient-chain-rule

Conversation

@manduinca

Copy link
Copy Markdown
Contributor

Fixes #289

StructuredGrid2D.get_element_gradient_for_location returned the shape-function derivatives with respect to local (0-1) cell coordinates, so gradients came out multiplied by step_vector on each axis and were silently resolution-dependent (directionally biased for anisotropic cells). This mirrors the division by step_vector that StructuredGrid3D already 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).

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
lachlangrose merged commit 08e2e19 into Loop3D:master Aug 4, 2026
2 of 3 checks passed
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.

[BUG] StructuredGrid2D.get_element_gradient_for_location omits the chain-rule division by step_vector

2 participants