Files
rustytorch/crates/specialized/rtx-cfd/src/solvers/incompressible/embedded3/grid.rs
T
Omar SobhandClaude Fable 5.1 6526a3bd38
CI / Format Check (push) Failing after 3s
Performance Benchmarks / Run Benchmarks (push) Failing after 4s
CI / Build (ubuntu-latest) (push) Failing after 3s
Documentation / Build API Documentation (push) Failing after 4s
Documentation / Build User Guide (push) Successful in 6s
CI / Clippy Check (push) Failing after 27s
CI / Build CPU-Only (Explicit) (push) Failing after 1m10s
CI / Build (macos-latest) (push) Canceled after 0s
CI / Python Bindings (maturin) (macos-latest) (push) Canceled after 0s
CI / Test (macos-latest) (push) Canceled after 0s
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Python Bindings (maturin) (ubuntu-latest) (push) Canceled after 0s
CI / WASM Build + Size Check (push) Canceled after 0s
CI / Distributed Training Tests (push) Canceled after 0s
CI / CI Success (push) Canceled after 0s
rtx-cfd embedded3 item 1: the Poisson core as poisson/{problem, hierarchy, pcg} (≤ 385 lines each; the periodic wrap built once into neighbour arrays); gate 1 HELD: nz=1 bit-identical to the 2D solver (lex + red-black, cached/uncached, iterations) and every extrusion case bit-identical to the three_d oracle, planes within 1.4e-11
Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-17 14:50:18 -05:00

84 lines
1.8 KiB
Rust

//! The uniform Cartesian grid and its index conventions.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Grid {
pub nx: usize,
pub ny: usize,
pub nz: usize,
pub dx: f64,
pub dy: f64,
pub dz: f64,
}
impl Grid {
/// Cubic cells of spacing `h`.
#[must_use]
pub fn cubic(nx: usize, ny: usize, nz: usize, h: f64) -> Self {
Self {
nx,
ny,
nz,
dx: h,
dy: h,
dz: h,
}
}
#[inline]
#[must_use]
pub fn cells(&self) -> usize {
self.nx * self.ny * self.nz
}
#[inline]
#[must_use]
pub fn cell(&self, k: usize, j: usize, i: usize) -> usize {
(k * self.ny + j) * self.nx + i
}
/// `(k, j, i)` of a cell index.
#[inline]
#[must_use]
pub fn kji(&self, idx: usize) -> (usize, usize, usize) {
let nxy = self.nx * self.ny;
(idx / nxy, (idx % nxy) / self.nx, idx % self.nx)
}
/// The u face west of cell `(k, j, i)`; `i = nx` is the east face of the last cell.
#[inline]
#[must_use]
pub fn uface(&self, k: usize, j: usize, i: usize) -> usize {
(k * self.ny + j) * (self.nx + 1) + i
}
#[inline]
#[must_use]
pub fn vface(&self, k: usize, j: usize, i: usize) -> usize {
(k * (self.ny + 1) + j) * self.nx + i
}
#[inline]
#[must_use]
pub fn wface(&self, k: usize, j: usize, i: usize) -> usize {
(k * self.ny + j) * self.nx + i
}
#[inline]
#[must_use]
pub fn n_ufaces(&self) -> usize {
(self.nx + 1) * self.ny * self.nz
}
#[inline]
#[must_use]
pub fn n_vfaces(&self) -> usize {
self.nx * (self.ny + 1) * self.nz
}
#[inline]
#[must_use]
pub fn n_wfaces(&self) -> usize {
self.nx * self.ny * (self.nz + 1)
}
}