pub struct Grid<const D: usize> { /* private fields */ }
Expand description
Representation of a cartesian mesh.
Coupe can partition grids (also called cartesian meshes) faster and consuming less memory than unstructured meshes.
Example
You can feed grids to topologic algorithms, thanks to the Topology
trait. You can also partition them directly with, eg., RCB:
// Define a 2-by-2 grid.
let side = std::num::NonZeroUsize::new(2).unwrap();
let grid = Grid::new_2d(side, side);
// All cells have the same weight.
let mut partition = [0; 4];
let weights = [1.0; 4];
// Run 2 iterations of RCB.
grid.rcb(&mut partition, &weights, 2);
// There are 4 parts, their order is unspecified.
partition.sort();
assert_eq!(partition, [0, 1, 2, 3]);
Implementations§
source§impl Grid<2>
impl Grid<2>
sourcepub fn new_2d(width: NonZeroUsize, height: NonZeroUsize) -> Self
pub fn new_2d(width: NonZeroUsize, height: NonZeroUsize) -> Self
Define a new 2D grid.
sourcepub fn rcb<W>(self, partition: &mut [usize], weights: &[W], iter_count: usize)where
W: Send + Sync + PartialOrd + Num + Sum + AsPrimitive<f64>,
f64: AsPrimitive<W>,
pub fn rcb<W>(self, partition: &mut [usize], weights: &[W], iter_count: usize)where W: Send + Sync + PartialOrd + Num + Sum + AsPrimitive<f64>, f64: AsPrimitive<W>,
Run RCB on the 2D grid.
Weights and partition indices are row major.
source§impl Grid<3>
impl Grid<3>
sourcepub fn new_3d(
width: NonZeroUsize,
height: NonZeroUsize,
depth: NonZeroUsize
) -> Self
pub fn new_3d( width: NonZeroUsize, height: NonZeroUsize, depth: NonZeroUsize ) -> Self
Define a new 3D grid.
sourcepub fn rcb<W>(self, partition: &mut [usize], weights: &[W], iter_count: usize)where
W: Send + Sync + PartialOrd + Num + Sum + AsPrimitive<f64>,
f64: AsPrimitive<W>,
pub fn rcb<W>(self, partition: &mut [usize], weights: &[W], iter_count: usize)where W: Send + Sync + PartialOrd + Num + Sum + AsPrimitive<f64>, f64: AsPrimitive<W>,
Run RCB on the 3D grid.
Weights and partition indices are row-then-column major.
Trait Implementations§
source§impl<const D: usize, E> Topology<E> for Grid<D>where
E: One,
impl<const D: usize, E> Topology<E> for Grid<D>where E: One,
§type Neighbors<'a> = GridNeighbors<D, E>
where
Self: 'a
type Neighbors<'a> = GridNeighbors<D, E> where Self: 'a
Return type for
Topology::neighbors
. Read moresource§fn neighbors(&self, vertex: usize) -> Self::Neighbors<'_>
fn neighbors(&self, vertex: usize) -> Self::Neighbors<'_>
An iterator over the neighbors of the given vertex.
source§fn lambda_cut<W>(&self, partition: &[usize], weights: W) -> W::Itemwhere
Self: Sync,
W: IntoParallelIterator,
W::Iter: IndexedParallelIterator,
W::Item: Sum + Mul<Output = W::Item> + FromPrimitive,
fn lambda_cut<W>(&self, partition: &[usize], weights: W) -> W::Itemwhere Self: Sync, W: IntoParallelIterator, W::Iter: IndexedParallelIterator, W::Item: Sum + Mul<Output = W::Item> + FromPrimitive,
The λ-1 cut (lambda-1 cut) of a partition. Read more
impl<const D: usize> Copy for Grid<D>
Auto Trait Implementations§
impl<const D: usize> RefUnwindSafe for Grid<D>
impl<const D: usize> Send for Grid<D>
impl<const D: usize> Sync for Grid<D>
impl<const D: usize> Unpin for Grid<D>
impl<const D: usize> UnwindSafe for Grid<D>
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
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.