salva2d/geometry/
contact_manager.rs1use crate::counters::Counters;
2use crate::geometry::{self, HGrid, HGridEntry, ParticlesContacts};
3use crate::math::Real;
4use crate::object::Boundary;
5use crate::object::Fluid;
6
7pub struct ContactManager {
9 pub fluid_fluid_contacts: Vec<ParticlesContacts>,
11 pub fluid_boundary_contacts: Vec<ParticlesContacts>,
13 pub boundary_boundary_contacts: Vec<ParticlesContacts>,
15}
16
17impl ContactManager {
18 pub fn new() -> Self {
20 Self {
21 fluid_fluid_contacts: Vec::new(),
22 fluid_boundary_contacts: Vec::new(),
23 boundary_boundary_contacts: Vec::new(),
24 }
25 }
26
27 pub fn ncontacts(&self) -> usize {
31 self.fluid_fluid_contacts
32 .iter()
33 .map(|c| c.len())
34 .sum::<usize>()
35 + self
36 .fluid_boundary_contacts
37 .iter()
38 .map(|c| c.len())
39 .sum::<usize>()
40 + self
41 .boundary_boundary_contacts
42 .iter()
43 .map(|c| c.len())
44 .sum::<usize>()
45 }
46
47 pub fn update_contacts(
49 &mut self,
50 counters: &mut Counters,
51 h: Real,
52 fluids: &[Fluid],
53 boundaries: &[Boundary],
54 hgrid: &HGrid<HGridEntry>,
55 ) {
56 geometry::compute_contacts(
57 counters,
58 h,
59 &fluids,
60 &boundaries,
61 &mut self.fluid_fluid_contacts,
62 &mut self.fluid_boundary_contacts,
63 &mut self.boundary_boundary_contacts,
64 hgrid,
65 );
66 }
67}