forked from 1b-agent/fieldcraft-upstream
explicit: deformable contact and friction, verified by bars, sliding blocks, the patch test and Hertz
Segment-to-segment penalty contact between element faces: each secondary face and each main face facing it are projected onto the secondary face's plane, split into triangles, clipped (Sutherland–Hodgman) and integrated with a three-point rule per sub-triangle (Puso–Laursen segmentation, the penalty at the integration points as Fischer–Wriggers), so a uniform pressure gives the consistent nodal forces on both meshes and the contact patch test passes on non-matching meshes. Every contact runs both ways at half the penalty: pairs with each surface as the secondary, general and self contact face against face. A bucket grid of face boxes every increment, faces integrated in parallel and their forces added in face order: the same numbers on any thread count. The penalty per area ε = s γ min(m/A)/Δt² comes from the lumped masses, each node's directional area and the stable increment, bounded by Gershgorin's row sums so contact never shortens the increment. Coulomb friction with exponential decay by a regularised return map at the secondary nodes; rigid walls take Coulomb impulses. Contact work and friction dissipation join the energy balance; each contact reports its peak force, first and last contact, deepest penetration, friction and the nodes adjusted at the start (initial penetrations adjusted strain-free or refused with the node, face and depth); a cap on contact faces. Verified (crates/explicit/tests/contact.rs, tests/oracle/explicit-*): colliding bars (2L/c +1.2%, ρcAv₀/2, KE kept to 0.005%, contact energy back to 8e-5 of it), blocks sliding to a stop on a rigid wall and on a plate under constant and decaying friction (0.005–0.2%), the patch test (σ_zz uniform to 0.06%), two spheres colliding against Hertz (peak +2.3%, duration −0.4%; the oracle case waits for a graded sphere mesher), a free body untouched by general contact, determinism across threads. Oracle measures gain `over` (ratios). Existing fixtures do not move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NmAttHhUZTokgPeEJia8sm
This commit is contained in:
1 parent
ecf947c090
commit
a30d0b5c5b
37 files changed
+2459
-55
No files matched your search
@@ -311,6 +311,32 @@ impl Grid {
|
||||
}
|
||||
}
|
||||
|
||||
/// The boxes that may overlap box `b`: those listed in the cells it overlaps, in box order
|
||||
/// without repeats (into `out`, cleared first).
|
||||
pub fn candidates_in(&self, b: &Aabb, out: &mut Vec<u32>) {
|
||||
out.clear();
|
||||
if self.items.is_empty() || b.iter().flatten().any(|c| !c.is_finite()) {
|
||||
return;
|
||||
}
|
||||
let top = [0, 1, 2].map(|k| self.lowest[k] + self.cell * self.dims[k] as f64);
|
||||
if (0..3).any(|k| b[1][k] < self.lowest[k] || b[0][k] > top[k]) {
|
||||
return;
|
||||
}
|
||||
let (lo, hi) = (self.coordinates(b[0]), self.coordinates(b[1]));
|
||||
for k in lo[2]..=hi[2] {
|
||||
for j in lo[1]..=hi[1] {
|
||||
for i in lo[0]..=hi[0] {
|
||||
let c = self.index([i, j, k]);
|
||||
if let (Some(a), Some(e)) = (self.start.get(c), self.start.get(c + 1)) {
|
||||
out.extend_from_slice(self.items.get(*a..*e).unwrap_or_default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
out.sort_unstable();
|
||||
out.dedup();
|
||||
}
|
||||
|
||||
/// The number of entries (box × cell overlaps).
|
||||
pub fn entries(&self) -> usize {
|
||||
self.items.len()
|
||||
@@ -394,5 +420,12 @@ mod tests {
|
||||
assert!(g.entries() <= MAX_GRID_ITEMS);
|
||||
}
|
||||
assert_eq!(Grid::new(&[], 10).candidates([0.0; 3]), &[] as &[u32]);
|
||||
// Box queries: every box that overlaps, once, in order.
|
||||
let mut found = Vec::new();
|
||||
grid.candidates_in(&[[10.2, 0.2, 0.2], [12.1, 0.4, 0.4]], &mut found);
|
||||
let expected: Vec<u32> = (0..50).filter(|i| boxes[*i as usize][0][0] <= 12.1 && boxes[*i as usize][1][0] >= 10.2).collect();
|
||||
assert!(expected.iter().all(|e| found.contains(e)) && found.windows(2).all(|w| w[0] < w[1]), "{found:?} {expected:?}");
|
||||
grid.candidates_in(&[[-9.0, 0.0, 0.0], [-8.0, 1.0, 1.0]], &mut found);
|
||||
assert!(found.is_empty());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user