Add barrier stiffness and simplify tangential API#215
Conversation
Introduce a barrier stiffness (kappa) to BarrierPotential: new constructors, member, getters/setters, and scale operator/gradient/hessian by stiffness. Remove the redundant normal_stiffness parameter from tangential collision constructors and tangential potential interfaces, updating all call sites, headers, and implementations accordingly. Update Python bindings, tutorials, examples (ogc, solver), and tests (test_ipc) to match the new API and default stiffness usage; also move a notebook to python/examples. Miscellaneous formatting/import cleanups and adjustments to pybind argument lists to reflect the simplified tangential API.
There was a problem hiding this comment.
Pull request overview
This PR updates IPC’s contact modeling APIs by embedding barrier stiffness directly into BarrierPotential and simplifying the tangential/friction interfaces by removing the redundant normal-stiffness parameter, with corresponding updates across C++, Python bindings, docs, examples, and tests.
Changes:
- Add barrier stiffness (
kappa) as state inipc::BarrierPotentialand apply it internally when evaluating energy/derivatives. - Remove
normal_stiffnessfrom tangential collision construction and tangential potential/force interfaces, updating call sites accordingly. - Update Python bindings, tutorials/examples, and tests to use the new signatures and stiffness behavior.
Reviewed changes
Copilot reviewed 39 out of 39 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/src/tests/potential/test_friction_potential.cpp | Updates friction potential test for new barrier/tangential APIs (currently still passes removed arg). |
| tests/src/tests/potential/test_barrier_potential.cpp | Updates barrier potential tests for new BarrierPotential(dhat, kappa, ...) ctor. |
| tests/src/tests/potential/test_adhesion_potentials.cpp | Updates adhesion tests for new normal potential force-magnitude signature. |
| tests/src/tests/friction/test_friction.cpp | Updates friction test construction to pass stiffness via BarrierPotential. |
| tests/src/tests/friction/test_force_jacobian.cpp | Updates force-jacobian test call sites (currently still passes removed arg to tangential build). |
| tests/src/tests/collisions/test_normal_collisions.cpp | Updates barrier usage in collision tests to pass stiffness. |
| tests/src/tests/barrier/test_barrier.cpp | Adjusts barrier derivative testing approach and FD settings (tolerance risk). |
| src/ipc/potentials/tangential_potential.hpp | Removes normal_stiffness from tangential force/jacobian API. |
| src/ipc/potentials/tangential_potential.cpp | Implements tangential force/jacobian changes using new normal potential API. |
| src/ipc/potentials/normal_potential.hpp | Removes barrier_stiffness parameter from the normal-potential force magnitude interfaces. |
| src/ipc/potentials/normal_adhesion_potential.hpp | Updates adhesion potential overrides to match new interface. |
| src/ipc/potentials/normal_adhesion_potential.cpp | Implements updated overrides for new interface. |
| src/ipc/potentials/barrier_potential.hpp | Adds stiffness member/accessors; updates ctor and normal-force magnitude overrides. |
| src/ipc/potentials/barrier_potential.cpp | Stores stiffness and applies it internally to energy/derivatives and force magnitude. |
| src/ipc/collisions/tangential/*.{hpp,cpp} | Removes stiffness argument from tangential collision initialization and propagation. |
| python/tests/test_ipc.py | Updates Python test to construct BarrierPotential with stiffness. |
| python/src/potentials/tangential_potential.cpp | Updates pybind signatures/docs for tangential potential API change. |
| python/src/potentials/normal_potential.cpp | Updates exposed argument list but leaves stale doc references (needs cleanup). |
| python/src/potentials/barrier_potential.cpp | Updates ctor binding but does not expose stiffness property and needs kw-only consideration. |
| python/src/collisions/tangential/*.cpp | Updates pybind constructors/build overloads for removed stiffness arg. |
| python/examples/solver.py | Updates example to new stiffness semantics (currently has enum typo). |
| python/examples/ogc.py | Updates example to pass stiffness into BarrierPotential instead of scaling forces externally. |
| docs/source/tutorials/simulation.rst | Updates tutorial snippets for new ctor and tangential build signature (stiffness not introduced in snippet). |
| docs/source/tutorials/getting_started.rst | Updates tutorial snippets/text for stiffness (equation/snippet consistency issues). |
Comments suppressed due to low confidence (2)
python/src/potentials/barrier_potential.cpp:36
- C++ adds
BarrierPotential::stiffness()andset_stiffness(), but the Python bindings only exposedhatandbarrierproperties. Consider adding a.def_property("stiffness", ...)so Python users can read/update the stiffness after construction (consistent with the new C++ API).
.def_property(
"dhat", &BarrierPotential::dhat, &BarrierPotential::set_dhat,
"Barrier activation distance.")
.def_property(
python/src/potentials/normal_potential.cpp:82
- The Python docstring for
NormalPotential.force_magnitude_gradient()still mentionsbarrier_stiffness, but the exposed signature is now(distance_squared, distance_squared_gradient, dmin). Please remove/update the stale parameter description to avoid confusing Python users.
"force_magnitude_gradient",
&NormalPotential::force_magnitude_gradient,
R"ipc_Qu8mg5v7(
Compute the gradient of the force magnitude for a collision.
Parameters:
distance_squared: The squared distance between elements.
distance_squared_gradient: The gradient of the squared distance.
dmin: The minimum distance offset to the barrier.
barrier_stiffness: The stiffness of the barrier.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| tangential_collisions.build( | ||
| mesh, V0, collisions, BarrierPotential(dhat), barrier_stiffness, mu); | ||
| mesh, V0, collisions, BarrierPotential(dhat, barrier_stiffness), | ||
| barrier_stiffness, mu); | ||
|
|
There was a problem hiding this comment.
TangentialCollisions::build() no longer takes a separate normal/barrier stiffness for normal-force magnitude. This call still passes barrier_stiffness as an extra argument, which will not compile and also double-specifies stiffness (it’s already embedded in BarrierPotential(dhat, barrier_stiffness)). Remove the extra barrier_stiffness argument and pass only mu after the normal potential.
python/examples/solver.py
Outdated
| C, | ||
| collision_mesh, | ||
| vertices, | ||
| project_hessian_to_psd=ipctk.PSDProjectionMethod.CLAM, |
There was a problem hiding this comment.
ipctk.PSDProjectionMethod does not have a CLAM value (the enum is CLAMP, ABS, NONE). This will raise at runtime. Use ipctk.PSDProjectionMethod.CLAMP here.
| project_hessian_to_psd=ipctk.PSDProjectionMethod.CLAM, | |
| project_hessian_to_psd=ipctk.PSDProjectionMethod.CLAMP, |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #215 +/- ##
=======================================
Coverage 96.96% 96.96%
=======================================
Files 158 158
Lines 24659 24663 +4
Branches 883 883
=======================================
+ Hits 23910 23914 +4
Misses 749 749
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
* Add barrier stiffness and simplify tangential API Introduce a barrier stiffness (kappa) to BarrierPotential: new constructors, member, getters/setters, and scale operator/gradient/hessian by stiffness. Remove the redundant normal_stiffness parameter from tangential collision constructors and tangential potential interfaces, updating all call sites, headers, and implementations accordingly. Update Python bindings, tutorials, examples (ogc, solver), and tests (test_ipc) to match the new API and default stiffness usage; also move a notebook to python/examples. Miscellaneous formatting/import cleanups and adjustments to pybind argument lists to reflect the simplified tangential API.
* Support configurable vertex derivative layout Add a VERTEX_DERIVATIVE_LAYOUT constant to ipc::config and include Eigen. Update local_to_global.hpp to parameterize all assembly helpers (gradient, sparse gradient, Hessian triplets, Jacobian triplets, MatrixCache Hessian) with an optional GlobalOrder template (defaulting to VERTEX_DERIVATIVE_LAYOUT). Implement both RowMajor and ColMajor indexing code paths and add static_asserts and detailed doc comments. Also include ipc/config.hpp, convert LocalThreadMatStorage to a struct with docs, and adjust MatrixCache-based hessian assembly to respect the chosen global ordering. * Add barrier stiffness and simplify tangential API (#215) * Add barrier stiffness and simplify tangential API Introduce a barrier stiffness (kappa) to BarrierPotential: new constructors, member, getters/setters, and scale operator/gradient/hessian by stiffness. Remove the redundant normal_stiffness parameter from tangential collision constructors and tangential potential interfaces, updating all call sites, headers, and implementations accordingly. Update Python bindings, tutorials, examples (ogc, solver), and tests (test_ipc) to match the new API and default stiffness usage; also move a notebook to python/examples. Miscellaneous formatting/import cleanups and adjustments to pybind argument lists to reflect the simplified tangential API. * Remove assert(false) if the meshes has non-manifold edges * Add alias for Eigen::last = Eigen::indexing::last * Apply EIGEN_DONT_VECTORIZE to ipc_toolkit Disable Eigen vectorization to avoid alignment issues. Place EIGEN_DONT_VECTORIZE on the ipc_toolkit target as PUBLIC because setting it on the Eigen target or making it PRIVATE caused crashes. * Fix friction force jacobian tests * Handle single-node LBVH in broad-phase queries Detect lbvh.size() == 1 and treat the root as a leaf in both single and batched query traversals, performing intersection tests and adding candidate collisions as appropriate * Add as<T> cast helpers to CollisionStencil * Add analytic plane-vertex collision support (#216) * Integrate analytic plane-vertex primitives into the collision pipeline. * Add PlaneVertexCandidate, normal and tangential plane-vertex collisions, and pv handling in builders. * Add CollisionMesh::planes and Python bindings (Hyperplane, PlaneVertex*). * Remove old implicits module and update CMake, tests, and small API/format fixes. * Refactor conservative rescaling initialization in CCD classes and update documentation * Apply suggestions from code review * Handle ColMajor global ordering in local_to_global Use total global vertex/row/col counts when computing column-major indices and validate buffer sizes. Add optional n_total_verts, n_total_rows and n_total_cols parameters (default -1) that are required for ColMajor storage and throw an error if omitted. Include logger header, assert grad size divisibility, and update MatrixCache/triplet indexing accordingly. Add test_local_to_global.cpp to tests CMakeLists. * Add braces to nested loops in test * Support ColMajor DOF layout in derivatives and tests Add tests/dof_layout.hpp with helpers to flatten, unflatten, and reorder gradients/hessians so finite-difference tests work for both VERTEX_DERIVATIVE_LAYOUT settings. Pass mesh.num_vertices() (n_total_verts) into shape_derivative and local_*_to_global_triplets so global DOF indices are computed correctly for column-major layouts. * Support vertex-to-dof matrix layout and tests Use VERTEX_DERIVATIVE_LAYOUT to map vertex-level sparse matrices into per-dof sparse matrices, computing triplets with n_rows/n_cols and constructing M_dof with the correct dimensions. Move the function declaration in the header and add unit tests (including Catch2 generators and config include) that verify sparsity pattern and the M_dof * x == flatten(M_V * V) semantics. * Add configurable vertex derivative layout option Introduce IPC_TOOLKIT_VERTEX_DERIVATIVE_LAYOUT CMake cache option (default RowMajor) with allowed values ColMajor and RowMajor, and mark it advanced. Export the value into src/ipc/config.hpp.in so VERTEX_DERIVATIVE_LAYOUT is set to the chosen Eigen layout at configure time. * Add vertex derivative layout docs Describe row-major default and new CMake cache option IPC_TOOLKIT_VERTEX_DERIVATIVE_LAYOUT (RowMajor or ColMajor), with build examples, affected APIs, and an experimental feature warning.
Description
Type of change