Skip to main content

Grid

Struct Grid 

Source
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: f64

Cell 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: PressurePreconditioner

Preconditioner of the pressure solves on this grid, copied from numerics.pressure_preconditioner.

Implementations§

Source§

impl Grid

Source

pub fn count(&self) -> usize

Number of cells, fluid and solid.

Source

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.

Source

pub fn coord(&self, i: usize) -> [usize; 3]

The [i, j, k] coordinates of cell index i; the inverse of index.

Source

pub fn center(&self, i: usize) -> [f64; 3]

Center of cell i in meters.

Source

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.

Source

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).

Source

pub fn evidence(&self) -> GeometryEvidence

The geometry evidence of this grid, as written to geometry.json.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Grid

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Grid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.