pub struct Grid {Show 14 fields
pub n: [usize; 3],
pub dx: [f64; 3],
pub volume: f64,
pub fluid: Vec<bool>,
pub faces: Vec<Face>,
pub cell_faces: Vec<[[usize; 2]; 3]>,
pub component: Vec<usize>,
pub components: Vec<Vec<usize>>,
pub anchored: Vec<bool>,
pub face_dims: [[usize; 3]; 3],
pub box_cells: BTreeMap<String, usize>,
pub shape_evidence: BTreeMap<String, ShapeEvidence>,
pub pressure_factor: OnceLock<Factor>,
pub pressure_preconditioner: PressurePreconditioner,
/* private fields */
}Expand description
The represented topology of a case: uniform cells, the solid mask,
staggered faces and the fluid components, plus lazily built caches of the
pressure and implicit-momentum operators. Build it with
build; see the module docs for the layout.
Fields§
§n: [usize; 3]Cell counts along x, y and z.
dx: [f64; 3]Cell sizes in meters: domain length over cell count.
volume: f64Cell volume in m3.
fluid: Vec<bool>Per cell, true for fluid and false for solid.
faces: Vec<Face>All faces: x-faces, then y-faces, then z-faces, each block x fastest.
cell_faces: Vec<[[usize; 2]; 3]>Per cell and axis, the indices of its lower and upper faces in
faces. usize::MAX for solid cells. On a one-cell periodic axis
both entries are the same face.
component: Vec<usize>Per cell, the index of its fluid component; usize::MAX for solid
cells.
components: Vec<Vec<usize>>The cells of each fluid component, in breadth-first order from its lowest cell index.
anchored: Vec<bool>Per component, whether it touches an outlet face, which fixes its pressure level. Other components get a mean-zero pressure gauge and must receive zero net flux (CFD-E031).
face_dims: [[usize; 3]; 3]Dimensions of the face array of each axis: n, plus one along that
axis when it is not periodic.
box_cells: BTreeMap<String, usize>Per geometry box ID, the number of cells whose center lies inside it; overlapping boxes share cells.
shape_evidence: BTreeMap<String, ShapeEvidence>Per-shape analytic and represented volumes and adjacent street resolution.
pressure_factor: OnceLock<Factor>IC(0) factor of the pressure operator, built by the first IC(0) pressure solve and reused afterwards. It is only a preconditioner and is not rebuilt if face coefficients change.
pressure_preconditioner: PressurePreconditionerPreconditioner of the pressure solves on this grid, copied from
numerics.pressure_preconditioner.
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn index(n: [usize; 3], p: [usize; 3]) -> usize
pub fn index(n: [usize; 3], p: [usize; 3]) -> usize
Linear index of cell p = [i, j, k] in a grid of n cells:
(k * n[1] + j) * n[0] + i, x fastest. Also indexes a face array with
its face_dims.
Sourcepub fn coord(&self, i: usize) -> [usize; 3]
pub fn coord(&self, i: usize) -> [usize; 3]
The [i, j, k] coordinates of cell index i; the inverse of
index.
Sourcepub fn build(c: &Case) -> Result<Self>
pub fn build(c: &Case) -> Result<Self>
Builds the grid of a case: validates it (an invalid case returns the serialized check report), masks the cells whose centers lie in a box, classifies every face and finds the fluid components.
§Errors
CFD-E028 when a box or prism contains no cell center (the grid would not
represent it) and CFD-E030 when no fluid cell remains. Source and
receptor support are checked separately, by
transport::source_fields and
transport::receptor_weights.
Sourcepub fn mask_topology(c: &Case) -> Result<MaskTopology>
pub fn mask_topology(c: &Case) -> Result<MaskTopology>
Fluid-component and solid-cell counts of the case’s grid, computed from the cell
mask with a union-find over 4 bytes per cell, without building faces or the pressure
operator. Cells connect through shared faces, including periodic wraps, as in
Grid::build. Needs only valid axes (2..4096 cells, or 1..4096 on a
periodic axis, at most 1e8 in total).
Sourcepub fn evidence(&self) -> GeometryEvidence
pub fn evidence(&self) -> GeometryEvidence
The geometry evidence of this grid, as written to geometry.json.
Sourcepub fn face_at(&self, c: &Case, a: usize, q: [isize; 3]) -> Option<usize>
pub fn face_at(&self, c: &Case, a: usize, q: [isize; 3]) -> Option<usize>
Index in faces of the axis-a face at integer position q of that
axis’s face array. Periodic axes wrap; a position outside a
nonperiodic face array is None. c must be the case the grid was
built from.
Sourcepub fn divergence(&self, u: &[f64]) -> Vec<f64>
pub fn divergence(&self, u: &[f64]) -> Vec<f64>
Discrete divergence of the face velocities u (one per face) in 1/s,
per cell; zero for solid cells. The same definition is used by the
pressure operator and the continuity checks.
Sourcepub fn cell_velocity(&self, u: &[f64]) -> Vec<[f64; 3]>
pub fn cell_velocity(&self, u: &[f64]) -> Vec<[f64; 3]>
Cell-centered velocity in m/s: per axis the mean of the cell’s two face velocities; zero for solid cells. Prefer it to reshaping the face arrays by hand.
Sourcepub fn gradient(&self, p: &[f64]) -> Vec<f64>
pub fn gradient(&self, p: &[f64]) -> Vec<f64>
Face-normal gradient of the cell field p, per face: the difference
across interior faces over distance, the difference to a zero value
outside an outlet, and zero on every other face. Its negated
divergence is the operator of
pressure::apply.
Sourcepub fn initial_velocity(&self, c: &Case) -> Vec<f64>
pub fn initial_velocity(&self, c: &Case) -> Vec<f64>
Initial face velocities from Flow::vector at each face center;
zero on wall, slip and blocked faces.
Sourcepub fn enforce_velocity(&self, c: &Case, u: &mut [f64])
pub fn enforce_velocity(&self, c: &Case, u: &mut [f64])
Reapplies the fixed face velocities in place: zero on wall, slip and blocked faces and the case inflow on inlet faces. Interior and outlet faces are left unchanged.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Grid
impl Forget for Grid
impl Move for Grid
impl RefUnwindSafe for Grid
impl Send for Grid
impl Sync for Grid
impl Unpin for Grid
impl UnsafeUnpin for Grid
impl UnwindSafe for Grid
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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