Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit bbcaf88

Browse files
committed
hack
1 parent 72bc9d2 commit bbcaf88

File tree

3 files changed

+61
-37
lines changed

3 files changed

+61
-37
lines changed

src/ipc/smooth_contact/collisions/smooth_collision.cpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,45 @@ double SmoothCollisionTemplate<PrimitiveA, PrimitiveB>::operator()(
146146
const double dist = closest_direction.norm();
147147

148148
assert(positions.size() == pA->n_dofs() + pB->n_dofs());
149-
double a1 = pA->potential(closest_direction, positions.head(pA->n_dofs()));
150-
double a2 = pB->potential(-closest_direction, positions.tail(pB->n_dofs()));
151-
double a3 = Math<double>::inv_barrier(dist / Super::dhat(), params.r);
152-
double a4 =
153-
PrimitiveDistanceTemplate<PrimitiveA, PrimitiveB, double>::mollifier(
154-
x, dist * dist);
155149

156-
if (params.r == 0)
157-
logger().error("Invalid param!");
150+
if constexpr (std::is_same_v<PrimitiveA, Edge2> && std::is_same_v<PrimitiveB, Point2> && dim == 2)
151+
{
152+
double a1 = pA->potential(closest_direction, positions.head(pA->n_dofs()));
153+
double a2 = pB->potential(-closest_direction, positions.tail(pB->n_dofs()));
154+
double a3 = Math<double>::inv_barrier(dist / Super::dhat(), params.r);
155+
156+
{
157+
const Vector2<double> p = positions.template segment<2>(4);
158+
const Vector2<double> e0 = positions.template segment<2>(0);
159+
const Vector2<double> e1 = positions.template segment<2>(2);
158160

159-
if (dist < 1e-12)
160-
logger().warn(
161-
"pair distance {:.3e}, dhat {:.3e}, r {}, barrier {:.3e}, mollifier {:.3e}, orient {:.3e} {:.3e}",
162-
dist, Super::dhat(), params.r, a3, a4, a1, a2);
161+
double tangent_term = Math<double>::smooth_heaviside(-(p - e0).dot(e1 - e0) / (p - e0).norm() / (e1 - e0).norm(), params.alpha_t, params.beta_t);
162+
double b0 = Math<double>::inv_barrier((p - e0).norm() / Super::dhat(), params.r);
163+
a3 -= tangent_term * b0;
164+
165+
tangent_term = Math<double>::smooth_heaviside(-(p - e1).dot(e0 - e1) / (p - e1).norm() / (e0 - e1).norm(), params.alpha_t, params.beta_t);
166+
b0 = Math<double>::inv_barrier((p - e1).norm() / Super::dhat(), params.r);
167+
a3 -= tangent_term * b0;
168+
}
163169

164-
return a1 * a2 * a3 * a4;
170+
return a1 * a2 * a3;
171+
}
172+
else
173+
{
174+
double a1 = pA->potential(closest_direction, positions.head(pA->n_dofs()));
175+
double a2 = pB->potential(-closest_direction, positions.tail(pB->n_dofs()));
176+
double a3 = Math<double>::inv_barrier(dist / Super::dhat(), params.r);
177+
double a4 =
178+
PrimitiveDistanceTemplate<PrimitiveA, PrimitiveB, double>::mollifier(
179+
x, dist * dist);
180+
181+
if (dist < 1e-12)
182+
logger().warn(
183+
"pair distance {:.3e}, barrier {:.3e}, mollifier {:.3e}, orient {:.3e} {:.3e}",
184+
dist, a3, a4, a1, a2);
185+
186+
return a1 * a2 * a3 * a4;
187+
}
165188
}
166189

167190
template <typename PrimitiveA, typename PrimitiveB>

src/ipc/smooth_contact/primitives/edge2.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,39 @@ int Edge2::n_vertices() const { return n_edge_neighbors_2d; }
2222

2323
double Edge2::potential(const Vector2d& d, const Vector4d& x) const
2424
{
25-
return (x.tail<2>() - x.head<2>()).norm();
25+
return 1.;
26+
// return (x.tail<2>() - x.head<2>()).norm();
2627
}
2728

2829
Vector6d Edge2::grad(const Vector2d& d, const Vector4d& x) const
2930
{
30-
const Vector2d t = x.tail<2>() - x.head<2>();
31-
const double len = t.norm();
32-
Vector6d g;
33-
g.setZero();
34-
g.segment<2>(2) = -t / len;
35-
g.segment<2>(4) = t / len;
36-
return g;
31+
return Vector6d::Zero();
32+
// const Vector2d t = x.tail<2>() - x.head<2>();
33+
// const double len = t.norm();
34+
// Vector6d g;
35+
// g.setZero();
36+
// g.segment<2>(2) = -t / len;
37+
// g.segment<2>(4) = t / len;
38+
// return g;
3739
}
3840

3941
Matrix6d Edge2::hessian(const Vector2d& d, const Vector4d& x) const
4042
{
4143
Matrix6d h;
4244
h.setZero();
43-
#ifdef DERIVATIVES_WITH_AUTODIFF
44-
DiffScalarBase::setVariableCount(4);
45-
using T = ADHessian<4>;
46-
auto xAD = slice_positions<T, 2, 2>(x);
47-
h.block<4, 4>(2, 2) = (xAD.row(0) - xAD.row(1)).norm().getHessian();
48-
#else
49-
const Vector2d t = x.tail<2>() - x.head<2>();
50-
const double norm = t.norm();
51-
h.block<2, 2>(2, 2) =
52-
(Matrix2d::Identity() - t * (1. / norm / norm) * t.transpose()) / norm;
53-
h.block<2, 2>(4, 4) = h.block<2, 2>(2, 2);
54-
h.block<2, 2>(2, 4) = -h.block<2, 2>(2, 2);
55-
h.block<2, 2>(4, 2) = -h.block<2, 2>(2, 2);
56-
#endif
45+
// #ifdef DERIVATIVES_WITH_AUTODIFF
46+
// DiffScalarBase::setVariableCount(4);
47+
// using T = ADHessian<4>;
48+
// auto xAD = slice_positions<T, 2, 2>(x);
49+
// h.block<4, 4>(2, 2) = (xAD.row(0) - xAD.row(1)).norm().getHessian();
50+
// #else
51+
// const Vector2d t = x.tail<2>() - x.head<2>();
52+
// const double norm = t.norm();
53+
// h.block<2, 2>(2, 2) = (Matrix2d::Identity() - t * (1. / norm / norm) * t.transpose()) / norm;
54+
// h.block<2, 2>(4, 4) = h.block<2, 2>(2, 2);
55+
// h.block<2, 2>(2, 4) = -h.block<2, 2>(2, 2);
56+
// h.block<2, 2>(4, 2) = -h.block<2, 2>(2, 2);
57+
// #endif
5758
return h;
5859
}
5960
} // namespace ipc

src/ipc/smooth_contact/primitives/point2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace {
4343
const scalar tangent_term = Math<scalar>::smooth_heaviside(
4444
dn.dot(t0) / t0.norm(), param.alpha_t, param.beta_t);
4545

46-
return tangent_term * t0.norm();
46+
return tangent_term; // * t0.norm();
4747
}
4848
} // namespace
4949

@@ -75,7 +75,7 @@ scalar smooth_point2_term(
7575
* Math<scalar>::smooth_heaviside(tmp - 1., param.alpha_n, 0);
7676
}
7777

78-
return val * ((e0 - v).norm() + (e1 - v).norm()) / 2.;
78+
return val; // * ((e0 - v).norm() + (e1 - v).norm()) / 2.;
7979
}
8080

8181
Point2::Point2(

0 commit comments

Comments
 (0)