Skip to content

Rest shape measure#229

Open
udaykusupati wants to merge 9 commits intoipc-sim:mainfrom
udaykusupati:rest_shape_measure
Open

Rest shape measure#229
udaykusupati wants to merge 9 commits intoipc-sim:mainfrom
udaykusupati:rest_shape_measure

Conversation

@udaykusupati
Copy link
Copy Markdown
Contributor

@udaykusupati udaykusupati commented May 1, 2026

Description

For all the primitives, using quadrature on the rest shape instead of on the autodiff/differentiable parameters of the collision mesh. This feature is enabled by adding a use_rest_shape_measure parameter in SmoothParams
Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

This was necessary for a 2D GCP case where spurious gradients appear when integrating on the deformation coordinates.
However, no explicit testing was done, except gradient visualization

Checklist

  • I have followed the project style guide
  • My code follows the clang-format style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

❌ Patch coverage is 89.78102% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.78%. Comparing base (e400bb0) to head (b29f157).

Files with missing lines Patch % Lines
src/ipc/smooth_contact/primitives/point3.cpp 74.19% 8 Missing ⚠️
src/ipc/smooth_contact/primitives/edge2.cpp 88.88% 3 Missing ⚠️
src/ipc/smooth_contact/primitives/face.cpp 89.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   95.84%   95.78%   -0.06%     
==========================================
  Files         160      160              
  Lines       16611    16686      +75     
  Branches      923      937      +14     
==========================================
+ Hits        15921    15983      +62     
- Misses        690      703      +13     
Flag Coverage Δ
unittests 95.78% <89.78%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zfergus zfergus requested a review from Copilot May 1, 2026 15:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an option to use rest-shape (non-differentiated) quadrature measures for smooth-contact primitives to avoid spurious gradients from integrating over deformed collision mesh parameters.

Changes:

  • Introduces use_rest_shape_measure in SmoothContactParameters to toggle rest-shape quadrature weights.
  • Updates Point2/Point3/Edge2/Edge3 to use rest-shape length/area weights and to drop derivative contributions from the measure when enabled.
  • Refactors Face primitive evaluation to return rest-shape area (and zero derivatives) when enabled.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/ipc/smooth_contact/common.hpp Adds use_rest_shape_measure toggle to parameters.
src/ipc/smooth_contact/primitives/point3.hpp Stores a cached rest-shape quadrature weight for Point3.
src/ipc/smooth_contact/primitives/point3.cpp Computes/uses rest-shape Point3 weight; removes measure derivatives when enabled.
src/ipc/smooth_contact/primitives/point2.hpp Stores a cached rest-shape length measure for Point2.
src/ipc/smooth_contact/primitives/point2.cpp Passes a “measure” into point2 terms and switches between rest/deformed measures.
src/ipc/smooth_contact/primitives/face.hpp Changes Face evaluation API to instance methods and stores rest area.
src/ipc/smooth_contact/primitives/face.cpp Computes rest area; returns constant measure / zero derivatives when enabled.
src/ipc/smooth_contact/primitives/edge3.hpp Stores cached rest-shape squared edge length.
src/ipc/smooth_contact/primitives/edge3.cpp Uses rest/deformed squared-length weight and drops its derivatives when enabled.
src/ipc/smooth_contact/primitives/edge2.hpp Stores cached rest-shape edge length.
src/ipc/smooth_contact/primitives/edge2.cpp Returns rest length / zero derivatives when enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -99,6 +99,8 @@ struct SmoothContactParameters {
double beta_n = 0;
int r = 2;

Comment on lines +64 to +77
if (m_params.use_rest_shape_measure) {
// Rest-shape vertex area measure: sum of squared rest 1-ring edge
// lengths / 3 Constant quadrature weight per the paper (Eq. 13), never
// differentiated through
const Eigen::MatrixXd& rp = mesh.rest_positions();
m_rest_weight = 0.0;
for (int a = 0; a < edges.rows(); a++) {
const Eigen::RowVector3d t =
rp.row(local_to_global_vids[edges(a, 1)])
- rp.row(local_to_global_vids[edges(a, 0)]);
m_rest_weight += t.squaredNorm();
}
m_rest_weight /= 3.0;
}
Comment thread src/ipc/smooth_contact/primitives/face.hpp
Comment on lines +53 to +54
double Face::potential(
Eigen::ConstRef<Eigen::Vector3d> d, Eigen::ConstRef<Vector9d> x) const
Comment on lines +64 to +65
Vector12d Face::grad(
Eigen::ConstRef<Eigen::Vector3d> d, Eigen::ConstRef<Vector9d> x) const
Comment on lines +79 to +80
Matrix12d Face::hessian(
Eigen::ConstRef<Eigen::Vector3d> d, Eigen::ConstRef<Vector9d> x) const
Comment on lines +162 to +166
const double measure = m_params.use_rest_shape_measure
? m_rest_measure
: ((x.segment<DIM>(DIM) - x.segment<DIM>(0)).norm()
+ (x.segment<DIM>(2 * DIM) - x.segment<DIM>(0)).norm())
/ 2.0;
Comment on lines +190 to +193
const T measure = m_params.use_rest_shape_measure
? T(m_rest_measure)
: ((X.row(2) - X.row(1)).norm() + (X.row(3) - X.row(1)).norm())
/ 2.0;
Comment on lines +229 to +232
const T measure = m_params.use_rest_shape_measure
? T(m_rest_measure)
: ((X.row(2) - X.row(1)).norm() + (X.row(3) - X.row(1)).norm())
/ 2.0;
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.

3 participants