Skip to main content

Grid

Struct Grid 

Source
pub struct Grid { /* private fields */ }
Expand description

A validated rectilinear mesh, Cartesian (metres) or cylindrical (ρ, z in metres, α in radians).

Per-axis arrays such as nodes are indexed by Axis::index ([x, y, z], or [ρ, α, z]). The grid has n[a] node lines along axis a (at least 2) and therefore n[a] − 1 cells.

Implementations§

Source§

impl Grid

Source

pub fn new(lines: [Vec<f64>; 3]) -> Result<Self>

Builds a grid from the node coordinates (metres) of each axis.

Every axis needs at least two lines; the coordinates must be finite and strictly increasing. The total node count must fit in usize.

Source

pub fn cylindrical(lines: [Vec<f64>; 3]) -> Result<Self>

Builds a cylindrical grid from the lines [ρ, α, z]: ρ and z in metres, α in radians.

Besides the checks of new, ρ must be non-negative and the azimuth span α_max − α_min at most 2π. A first ρ line at 0 is the axis (has_axis); an azimuth span of 2π (to a relative 1e-6) closes the circle (is_closed): the first and last α lines are then the same half-plane, and the engine treats the α faces as periodic.

use ems::engine::Grid;
use std::f64::consts::TAU;

let g = Grid::cylindrical([
    vec![0.0, 1e-3, 2e-3],
    (0..=8).map(|j| j as f64 * TAU / 8.0).collect(),
    vec![0.0, 1e-3],
])?;
assert!(g.has_axis() && g.is_closed());
Source

pub fn coordinates(&self) -> Coordinates

The coordinate system.

Source

pub fn is_cylindrical(&self) -> bool

Whether the grid is cylindrical.

Source

pub fn has_axis(&self) -> bool

Whether the grid is cylindrical with its first ρ line at 0 (the z axis lies on the ρ_min face, see design §5.15).

Source

pub fn is_closed(&self) -> bool

Whether the grid is cylindrical and spans the full circle in α.

Source

pub fn with_multigrid(self, rings: &[usize]) -> Result<Self>

Enables azimuthal multigrid on a cylindrical grid (design §5.15.1): each entry of rings is the index of a ρ line; inside each of them (cells i < ring) the α resolution is halved once more, so inside the innermost of L rings only every 2^L-th α line is kept. The rings may be given in any order; an empty list switches multigrid off.

§Errors

Error::Invalid if the grid is not cylindrical, a ring index is repeated or not in 1..=nρ−2 (each zone boundary needs a cell on both sides), the number of α cells is not a multiple of 2^L, or a closed grid would keep fewer than 3 α cells in its coarsest zone.

use ems::engine::Grid;
use std::f64::consts::TAU;

let g = Grid::cylindrical([
    (0..=8).map(|i| i as f64 * 1e-3).collect(),
    (0..=32).map(|j| j as f64 * TAU / 32.0).collect(),
    vec![0.0, 1e-3],
])?
.with_multigrid(&[4, 2])?;
assert_eq!(g.alpha_factor(0), 4); // cells 0, 1: every 4th α line
assert_eq!(g.alpha_factor(3), 2); // cells 2, 3: every 2nd
assert_eq!(g.alpha_factor(4), 1);
Source

pub fn multigrid(&self) -> &[usize]

The multigrid zone boundaries (ρ line indices, outermost first); empty without multigrid (see with_multigrid).

Source

pub fn has_multigrid(&self) -> bool

Whether azimuthal multigrid is enabled.

Source

pub fn alpha_factor(&self, i: usize) -> usize

The azimuthal coarsening factor of radial cell i (between ρ_i and ρ_{i+1}): 1 without multigrid or outside every zone, 2^ℓ inside ℓ zone boundaries. Indices past the last cell use the last cell.

Source

pub fn edge_length(&self, axis: Axis, node: [usize; 3]) -> f64

Physical length [m] of the primary edge along axis starting at node: delta, or ρ_i·Δα_j for an α edge of a cylindrical grid (0 on the axis).

Source

pub fn dual_edge_length(&self, axis: Axis, node: [usize; 3]) -> f64

Physical length [m] of the (in-domain part of the) dual edge along axis through node: dual_delta, or ρ_{i+½}·Δα*_j for an α dual edge of a cylindrical grid.

Source

pub fn dual_face_area(&self, axis: Axis, node: [usize; 3]) -> f64

Area [m²] of the (in-domain part of the) dual face pierced by the primary edge along axis starting at node: the product of the two transverse dual_deltas in Cartesian coordinates; in cylindrical coordinates ρ_{i+½}·Δα*·Δz* (ρ edge), Δρ*·Δz* (α edge) and the annular sector Δα*·(ρ_hi² − ρ_lo²)/2 (z edge, ρ_lo, ρ_hi the dual lines around node i, clamped to the domain).

Source

pub fn face_area(&self, axis: Axis, node: [usize; 3]) -> f64

Area [m²] of the primary face normal to axis whose lowest corner is node: the product of the two transverse deltas in Cartesian coordinates; in cylindrical coordinates ρ_i·Δα·Δz (ρ face, 0 on the axis), Δρ·Δz (α face) and the annular sector Δα·(ρ_{i+1}² − ρ_i²)/2 (z face).

Source

pub fn uniform(cells: [usize; 3], cell_size: [f64; 3]) -> Result<Self>

Uniform grid with cells[a] cells of size cell_size[a] (metres) along each axis, starting at the origin.

Source

pub fn lines(&self, axis: Axis) -> &[f64]

Node coordinates along axis.

Source

pub fn nodes(&self) -> [usize; 3]

Number of nodes per axis, [nx, ny, nz].

Source

pub fn num_nodes(&self) -> usize

Total number of nodes nx·ny·nz (the length of every field array).

Source

pub fn cells(&self) -> [usize; 3]

Number of primary cells per axis, [nx − 1, ny − 1, nz − 1].

Source

pub fn num_cells(&self) -> usize

Total number of primary cells.

Source

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

Linear node index (i·ny + j)·nz + k (z contiguous).

Source

pub fn delta(&self, axis: Axis, i: usize) -> f64

Primary edge length Δ_a(i) = line[i+1] − line[i] along axis, for i < n[axis] − 1 (also the size of cell i along that axis).

Source

pub fn deltas(&self, axis: Axis) -> Vec<f64>

All primary edge lengths of axis (n[axis] − 1 values).

Source

pub fn dual_line(&self, axis: Axis, i: usize) -> f64

Dual node position along axis: midpoint of cell i (i < n[axis] − 1).

Source

pub fn dual_lines(&self, axis: Axis) -> Vec<f64>

All dual node positions of axis (n[axis] − 1 values).

Source

pub fn dual_delta(&self, axis: Axis, i: usize) -> f64

Dual edge length through primary node i along axis: from the midpoint of cell i − 1 to the midpoint of cell i, i.e. (Δ(i−1) + Δ(i)) / 2. At the outer nodes (i = 0, i = n − 1) the dual cell is a half cell and the length is Δ/2 of the single adjacent cell.

Source

pub fn min_delta(&self, axis: Axis) -> f64

Smallest cell size along axis.

Source

pub fn min_deltas(&self) -> [f64; 3]

Smallest cell size per axis.

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

impl PartialEq for Grid

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !Freeze 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> 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> 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.