pub struct LevelSet {
pub tree: QuadTree,
pub delta: f64,
}Expand description
Signed-distance level-set function stored on a QuadTree.
Variable index 0 of each leaf cell contains the level-set value φ. The
tree must have been constructed with n_vars >= 1.
The narrow band is the set of cells where |φ| < delta. Only narrow-
band cells are updated during reinitialization and advection, which makes
these algorithms O(N_interface) rather than O(N_total).
Fields§
§tree: QuadTreeThe underlying quad-tree (n_vars == 1, storing φ).
delta: f64Narrow-band half-width in physical units.
Implementations§
Source§impl LevelSet
impl LevelSet
Sourcepub fn new(tree: QuadTree, phi0: impl Fn(f64, f64) -> f64) -> Self
pub fn new(tree: QuadTree, phi0: impl Fn(f64, f64) -> f64) -> Self
Create a new level-set by evaluating phi0(x, y) on every leaf of
an already-constructed quad-tree (must have n_vars >= 1).
phi0 should return a signed distance (positive outside, negative
inside) but any smooth function is accepted.
Sourcepub fn set_delta(&mut self, delta: f64)
pub fn set_delta(&mut self, delta: f64)
Override the narrow-band half-width (default: 3 × coarsest cell size).
Sourcepub fn reinitialize(&mut self, n_iters: usize)
pub fn reinitialize(&mut self, n_iters: usize)
Sussman reinitialization: solve ∂φ/∂τ + sign(φ₀)(|∇φ|−1) = 0
for n_iters pseudo-time steps using first-order Godunov upwind.
Only narrow-band cells (|φ| < delta) are updated.
Sourcepub fn advect(
&mut self,
vx: &dyn Fn(f64, f64, f64) -> f64,
vy: &dyn Fn(f64, f64, f64) -> f64,
t: f64,
dt: f64,
)
pub fn advect( &mut self, vx: &dyn Fn(f64, f64, f64) -> f64, vy: &dyn Fn(f64, f64, f64) -> f64, t: f64, dt: f64, )
First-order upwind advection: ∂φ/∂t + v·∇φ = 0.
vx(x, y, t) and vy(x, y, t) are the advecting velocity components.
Only narrow-band cells are updated. The time step dt must satisfy the
CFL condition dt * max(|v|) / dx < 1.
Sourcepub fn interface_cells(&self) -> Vec<CellId>
pub fn interface_cells(&self) -> Vec<CellId>
Return the IDs of all interface cells: leaf cells where φ changes sign among the cell and its face-neighbours.
Equivalently: cells where |φ| < delta and at least one neighbour
has the opposite sign of φ.
Sourcepub fn gradient(&self, id: CellId) -> Option<(f64, f64)>
pub fn gradient(&self, id: CellId) -> Option<(f64, f64)>
Compute the first-order centred gradient (∂φ/∂x, ∂φ/∂y) at a leaf cell.
Sourcepub fn narrow_band_count(&self) -> usize
pub fn narrow_band_count(&self) -> usize
Statistics: number of narrow-band leaf cells.
Auto Trait Implementations§
impl Freeze for LevelSet
impl RefUnwindSafe for LevelSet
impl Send for LevelSet
impl Sync for LevelSet
impl Unpin for LevelSet
impl UnsafeUnpin for LevelSet
impl UnwindSafe for LevelSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more