Skip to main content

conspire/geometry/mesh/smooth/laplace/
mod.rs

1#[cfg(test)]
2mod test;
3
4use crate::{
5    geometry::mesh::{Mesh, differential::laplace::Weighting},
6    math::Scalar,
7};
8
9impl<const D: usize> Mesh<D> {
10    pub fn laplace_smooth(
11        &mut self,
12        iterations: usize,
13        scale: Scalar,
14        weighting: Weighting,
15        preserve_boundary: bool,
16        preserve_interfaces: bool,
17    ) {
18        let adjacency = (preserve_boundary || preserve_interfaces)
19            .then(|| self.constrained_adjacency(preserve_boundary, preserve_interfaces));
20        for _ in 0..iterations {
21            let laplacian = match &adjacency {
22                Some(adjacency) => self.laplacian_over(adjacency, weighting),
23                None => self.laplacian(weighting),
24            };
25            self.coordinates
26                .iter_mut()
27                .zip(laplacian)
28                .for_each(|(x, u)| *x -= u * scale)
29        }
30    }
31}