Skip to content

Commit 245c14d

Browse files
authored
Separate Static and Kinetic Coefficients of Friction (#177)
- Add separate static and kinetic friction coefficients (mu_s, mu_k) to tangential collisions. - Added `smooth_mu`, `smooth_mu_derivative`, `smooth_mu_f0`, `smooth_mu_f1`, `smooth_mu_f2`, `smooth_mu_f1_over_x`, and `smooth_mu_f2_x_minus_f1_over_x3` functions in `smooth_mu.cpp` and `smooth_mu.hpp` to handle the transition between static and kinetic friction smoothly. - Implemented unit tests for the smooth friction functions in `test_smooth_mu.cpp`, including gradient and Hessian checks using finite difference methods. - Introduced smooth friction mollifier functions: `smooth_mu_a0`, `smooth_mu_a1`, `smooth_mu_a2`, `smooth_mu_a1_over_x`, and `smooth_mu_a2_x_minus_mu_a1_over_x3` in `adhesion.cpp` and `adhesion.hpp`. - Refactored existing friction mollifier functions for improved clarity and performance. - Added unit tests for the new smooth friction mollifier functions to ensure correctness and stability. - Enhance documentation for adhesion and friction modules with new `smooth_mu` functions. - Update bindings to include new `smooth_mu` functionalities.
1 parent 71532a0 commit 245c14d

32 files changed

+6401
-95
lines changed

docs/source/cpp-api/adhesion.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ Functions
2727
- The first derivative of the tangential adhesion mollifier function divided by y.
2828
* - :func:`tangential_adhesion_f2_x_minus_f1_over_x3`
2929
- The second derivative of the tangential adhesion mollifier function times y minus the first derivative all divided by y cubed.
30+
* - :func:`smooth_mu_a0`
31+
- Compute the value of the ∫ μ(y) a₁(y) dy, where a₁ is the first derivative of the smooth tangential adhesion mollifier.
32+
* - :func:`smooth_mu_a1`
33+
- Compute the value of the μ(y) a₁(y), where a₁ is the first derivative of the smooth tangential adhesion mollifier.
34+
* - :func:`smooth_mu_a2`
35+
- Compute the value of d/dy (μ(y) a₁(y)), where a₁ is the first derivative of the smooth tangential adhesion mollifier.
36+
* - :func:`smooth_mu_a1_over_x`
37+
- Compute the value of the μ(y) a₁(y) / y, where a₁ is the first derivative of the smooth tangential adhesion mollifier.
38+
* - :func:`smooth_mu_a2_x_minus_mu_a1_over_x3`
39+
- Compute the value of the [(d/dy μ(y) a₁(y)) ⋅ y - μ(y) a₁(y)] / y³, where a₁ and a₂ are the first and second derivatives of the smooth tangential adhesion mollifier.
3040

3141

3242
Normal Adhesion Potential

docs/source/cpp-api/friction.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@ Smooth Mollifier
88
.. doxygenfunction:: smooth_friction_f1
99
.. doxygenfunction:: smooth_friction_f2
1010
.. doxygenfunction:: smooth_friction_f1_over_x
11-
.. doxygenfunction:: smooth_friction_f2_x_minus_f1_over_x3
11+
.. doxygenfunction:: smooth_friction_f2_x_minus_f1_over_x3
12+
13+
Smooth :math:`\mu`
14+
------------------
15+
16+
.. doxygenfunction:: smooth_mu
17+
.. doxygenfunction:: smooth_mu_derivative
18+
19+
.. doxygenfunction:: smooth_mu_f0
20+
.. doxygenfunction:: smooth_mu_f1
21+
.. doxygenfunction:: smooth_mu_f2
22+
.. doxygenfunction:: smooth_mu_f1_over_x
23+
.. doxygenfunction:: smooth_mu_f2_x_minus_f1_over_x3

docs/source/python-api/adhesion.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ Tangential Adhesion Potential
1616
.. autofunction:: ipctk.tangential_adhesion_f1
1717
.. autofunction:: ipctk.tangential_adhesion_f2
1818
.. autofunction:: ipctk.tangential_adhesion_f1_over_x
19-
.. autofunction:: ipctk.tangential_adhesion_f2_x_minus_f1_over_x3
19+
.. autofunction:: ipctk.tangential_adhesion_f2_x_minus_f1_over_x3
20+
21+
Smooth :math:`\mu`
22+
------------------
23+
24+
.. autofunction:: ipctk.smooth_mu_a0
25+
.. autofunction:: ipctk.smooth_mu_a1
26+
.. autofunction:: ipctk.smooth_mu_a2
27+
.. autofunction:: ipctk.smooth_mu_a1_over_x
28+
.. autofunction:: ipctk.smooth_mu_a2_x_minus_mu_a1_over_x3

docs/source/python-api/friction.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,15 @@ Smooth Mollifier
88
.. autofunction:: ipctk.smooth_friction_f1
99
.. autofunction:: ipctk.smooth_friction_f2
1010
.. autofunction:: ipctk.smooth_friction_f1_over_x
11-
.. autofunction:: ipctk.smooth_friction_f2_x_minus_f1_over_x3
11+
.. autofunction:: ipctk.smooth_friction_f2_x_minus_f1_over_x3
12+
13+
Smooth :math:`\mu`
14+
------------------
15+
16+
.. autofunction:: ipctk.smooth_mu
17+
.. autofunction:: ipctk.smooth_mu_derivative
18+
.. autofunction:: ipctk.smooth_mu_f0
19+
.. autofunction:: ipctk.smooth_mu_f1
20+
.. autofunction:: ipctk.smooth_mu_f2
21+
.. autofunction:: ipctk.smooth_mu_f1_over_x
22+
.. autofunction:: ipctk.smooth_mu_f2_x_minus_f1_over_x3

notebooks/separate_mu.ipynb

Lines changed: 5447 additions & 0 deletions
Large diffs are not rendered by default.

python/src/adhesion/adhesion.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,102 @@ void define_adhesion(py::module_& m)
142142
The second derivative of the tangential adhesion mollifier function times y minus the first derivative all divided by y cubed.
143143
)ipc_Qu8mg5v7",
144144
"y"_a, "eps_a"_a);
145+
146+
m.def(
147+
"smooth_mu_a0", &smooth_mu_a0,
148+
R"ipc_Qu8mg5v7(
149+
Compute the value of the ∫ μ(y) a₁(y) dy, where a₁ is the first derivative of the smooth tangential adhesion mollifier.
150+
151+
Note:
152+
The `a0`/`a1` are unrelated to the `a0`/`a1` in the normal adhesion.
153+
154+
Parameters:
155+
y: The tangential relative speed.
156+
mu_s: Coefficient of static adhesion.
157+
mu_k: Coefficient of kinetic adhesion.
158+
eps_a: Velocity threshold below which static adhesion force is applied.
159+
160+
Returns:
161+
The value of the integral at y.
162+
)ipc_Qu8mg5v7",
163+
"y"_a, "mu_s"_a, "mu_k"_a, "eps_a"_a);
164+
165+
m.def(
166+
"smooth_mu_a1", &smooth_mu_a1,
167+
R"ipc_Qu8mg5v7(
168+
Compute the value of the μ(y) a₁(y), where a₁ is the first derivative of the smooth tangential adhesion mollifier.
169+
170+
Note:
171+
The `a1` is unrelated to the `a1` in the normal adhesion.
172+
173+
Parameters:
174+
y: The tangential relative speed.
175+
mu_s: Coefficient of static adhesion.
176+
mu_k: Coefficient of kinetic adhesion.
177+
eps_a: Velocity threshold below which static adhesion force is applied.
178+
179+
Returns:
180+
The value of the product at y.
181+
)ipc_Qu8mg5v7",
182+
"y"_a, "mu_s"_a, "mu_k"_a, "eps_a"_a);
183+
184+
m.def(
185+
"smooth_mu_a2", &smooth_mu_a2,
186+
R"ipc_Qu8mg5v7(
187+
Compute the value of d/dy (μ(y) a₁(y)), where a₁ is the first derivative of the smooth tangential adhesion mollifier.
188+
189+
Note:
190+
The `a1`/`a2` are unrelated to the `a1`/`a2` in the normal adhesion.
191+
192+
Parameters:
193+
y: The tangential relative speed.
194+
mu_s: Coefficient of static adhesion.
195+
mu_k: Coefficient of kinetic adhesion.
196+
eps_a: Velocity threshold below which static adhesion force is applied.
197+
198+
Returns:
199+
The value of the derivative at y.
200+
)ipc_Qu8mg5v7",
201+
"y"_a, "mu_s"_a, "mu_k"_a, "eps_a"_a);
202+
203+
m.def(
204+
"smooth_mu_a1_over_x", &smooth_mu_a1_over_x,
205+
R"ipc_Qu8mg5v7(
206+
Compute the value of the μ(y) a₁(y) / y, where a₁ is the first derivative of the smooth tangential adhesion mollifier.
207+
208+
Notes:
209+
The `x` in the function name refers to the parameter `y`.
210+
The `a1` is unrelated to the `a1` in the normal adhesion.
211+
212+
Parameters:
213+
y: The tangential relative speed.
214+
mu_s: Coefficient of static adhesion.
215+
mu_k: Coefficient of kinetic adhesion.
216+
eps_a: Velocity threshold below which static adhesion force is applied.
217+
218+
Returns:
219+
The value of the product at y.
220+
)ipc_Qu8mg5v7",
221+
"y"_a, "mu_s"_a, "mu_k"_a, "eps_a"_a);
222+
223+
m.def(
224+
"smooth_mu_a2_x_minus_mu_a1_over_x3",
225+
&smooth_mu_a2_x_minus_mu_a1_over_x3,
226+
R"ipc_Qu8mg5v7(
227+
Compute the value of the [(d/dy μ(y) a₁(y)) ⋅ y - μ(y) a₁(y)] / y³, where a₁ and a₂ are the first and second derivatives of the smooth tangential adhesion mollifier.
228+
229+
Notes:
230+
The `x` in the function name refers to the parameter `y`.
231+
The `a1`/`a2` are unrelated to the `a1`/`a2` in the normal adhesion.
232+
233+
Parameters:
234+
y: The tangential relative speed.
235+
mu_s: Coefficient of static adhesion.
236+
mu_k: Coefficient of kinetic adhesion.
237+
eps_a: Velocity threshold below which static adhesion force is applied.
238+
239+
Returns:
240+
The value of the expression at y.
241+
)ipc_Qu8mg5v7",
242+
"y"_a, "mu_s"_a, "mu_k"_a, "eps_a"_a);
145243
}

python/src/bindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ PYBIND11_MODULE(ipctk, m)
8686

8787
// friction
8888
define_smooth_friction_mollifier(m);
89+
define_smooth_mu(m);
8990

9091
// implicits
9192
define_plane_implicit(m);

python/src/collisions/tangential/tangential_collision.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ void define_tangential_collision(py::module_& m)
122122
&TangentialCollision::normal_force_magnitude,
123123
"Normal force magnitude")
124124
.def_readwrite(
125-
"mu", &TangentialCollision::mu,
126-
"Ratio between normal and tangential forces (e.g., friction coefficient)")
125+
"mu_s", &TangentialCollision::mu_s,
126+
"Ratio between normal and static tangential forces (e.g., friction coefficient)")
127+
.def_readwrite(
128+
"mu_k", &TangentialCollision::mu_k,
129+
"Ratio between normal and kinetic tangential forces (e.g., friction coefficient)")
127130
.def_readwrite("weight", &TangentialCollision::weight, "Weight")
128131
.def_property(
129132
"weight_gradient",

python/src/collisions/tangential/tangential_collisions.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,40 @@ void define_tangential_collisions(py::module_& m)
1616
double>(&TangentialCollisions::build),
1717
"mesh"_a, "vertices"_a, "collisions"_a, "normal_potential"_a,
1818
"normal_stiffness"_a, "mu"_a)
19+
.def(
20+
"build",
21+
py::overload_cast<
22+
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
23+
const NormalCollisions&, const NormalPotential&, double, double,
24+
double>(&TangentialCollisions::build),
25+
"mesh"_a, "vertices"_a, "collisions"_a, "normal_potential"_a,
26+
"normal_stiffness"_a, "mu_s"_a, "mu_k"_a)
1927
.def(
2028
"build",
2129
[](TangentialCollisions& self, const CollisionMesh& mesh,
2230
Eigen::ConstRef<Eigen::MatrixXd> vertices,
2331
const NormalCollisions& collisions,
2432
const NormalPotential& normal_potential,
2533
const double normal_stiffness,
26-
Eigen::ConstRef<Eigen::VectorXd> mus) {
34+
Eigen::ConstRef<Eigen::VectorXd> mu_s,
35+
Eigen::ConstRef<Eigen::VectorXd> mu_k) {
2736
self.build(
2837
mesh, vertices, collisions, normal_potential,
29-
normal_stiffness, mus);
38+
normal_stiffness, mu_s, mu_k);
3039
},
3140
"mesh"_a, "vertices"_a, "collisions"_a, "normal_potential"_a,
32-
"normal_stiffness"_a, "mus"_a)
41+
"normal_stiffness"_a, "mu_s"_a, "mu_k"_a)
3342
.def(
3443
"build",
3544
py::overload_cast<
3645
const CollisionMesh&, Eigen::ConstRef<Eigen::MatrixXd>,
3746
const NormalCollisions&, const NormalPotential&, const double,
3847
Eigen::ConstRef<Eigen::VectorXd>,
48+
Eigen::ConstRef<Eigen::VectorXd>,
3949
const std::function<double(double, double)>&>(
4050
&TangentialCollisions::build),
4151
"mesh"_a, "vertices"_a, "collisions"_a, "normal_potential"_a,
42-
"normal_stiffness"_a, "mus"_a, "blend_mu"_a)
52+
"normal_stiffness"_a, "mu_s"_a, "mu_k"_a, "blend_mu"_a)
4353
.def(
4454
"__len__", &TangentialCollisions::size,
4555
"Get the number of friction collisions.")

python/src/friction/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(SOURCES
22
smooth_friction_mollifier.cpp
3+
smooth_mu.cpp
34
)
45

56
target_sources(ipctk PRIVATE ${SOURCES})

0 commit comments

Comments
 (0)