Fix edge_edge_mollifier_gradient_wrt_x to use ∇_rest ε_x#239
Draft
Huangzizhou wants to merge 1 commit into
Draft
Fix edge_edge_mollifier_gradient_wrt_x to use ∇_rest ε_x#239Huangzizhou wants to merge 1 commit into
Huangzizhou wants to merge 1 commit into
Conversation
`edge_edge_mollifier_gradient_wrt_x` returns the gradient of the EE parallel mollifier with respect to rest positions, computed via the chain rule ∇_rest m = ∂m/∂ε · ∇_rest ε (since m depends on rest only through eps_x). The second factor was incorrectly using `edge_edge_mollifier_gradient(positions, eps_x)` (which returns ∇_position m via cross_squarednorm chain) instead of `edge_edge_mollifier_threshold_gradient(rest)` (which returns ∇_rest ε). The sister function `edge_edge_mollifier_gradient_jacobian_wrt_x` already used the correct factor; this restores consistency between the two. Adds a regression test under tests/src/tests/potential/ that constructs a 4-vertex/2-edge scene with a single mollified EE pair and FD-checks the full 12x12 analytic shape_derivative against centered FD of gradient at fixed collision set (same convention as test_barrier_potential.cpp:377-391). Without the fix, the test shows rel ≈ 1.4-2.6e-2 across the three z_twist values; with the fix, rel ≈ 3-5e-4. Threshold is 5e-3. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
edge_edge_mollifier_gradient_wrt_xreturns the gradient of the EE parallel mollifier with respect to rest positions, computed as∇_rest m = ∂m/∂ε · ∇_rest ε(sincemdepends on rest only througheps_x). The second factor was usingedge_edge_mollifier_gradient(positions, eps_x)(returns∇_position m) instead ofedge_edge_mollifier_threshold_gradient(rest)(returns∇_rest ε).Sister function
edge_edge_mollifier_gradient_jacobian_wrt_xalready used the correct factor; this restores consistency between the two.if (ee_cross_norm_sqr < eps_x) { return edge_edge_mollifier_derivative_wrt_eps_x( ee_cross_norm_sqr, eps_x) - * edge_edge_mollifier_gradient(ea0, ea1, eb0, eb1, eps_x); + * edge_edge_mollifier_threshold_gradient( + ea0_rest, ea1_rest, eb0_rest, eb1_rest); }Why it matters
The existing IPC
shape_derivativetest (test_barrier_potential.cpp:248) uses a stacked-cube scene that doesn't trigger the mollifier branch, so the bug was invisible to existing coverage. It surfaces on near-parallel EE pairs neardhat— in a polyfem shape-optimization transient adjoint, this produced a ~400× per-pair inflation and an ~10⁸× sign-flipped end-to-end gradient.Test plan
New regression test
tests/src/tests/potential/ipc_test_ee_near_parallel_shape_derivative.cppconstructs a 4-vertex / 2-edge scene with a single mollified EE pair (y_sep = 9.99e-4,z_twist ∈ {5e-3, 1e-2, 2e-2}) and FD-checks the full 12×12 analyticshape_derivativeagainst centered FD ofgradientat fixed collision set (same convention astest_barrier_potential.cpp:377-391).🤖 Generated with Claude Code