Skip to main content

VoxelGrid

Struct VoxelGrid 

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

A regular 3D grid of voxels, each filled by one material. See the module docs for the origin, flattening order, face ownership, boundary behaviour and the traversal algorithm.

use lindhard::geometry::{Boundary, Geometry, VoxelGrid};
use lindhard::material::Material;

let si = Material::from_atom_fractions(&[(14, 1.0)], None).unwrap();
let c = Material::from_atom_fractions(&[(6, 1.0)], None).unwrap();
// 2 x 1 x 1 voxels of 10 nm: silicon in front of carbon.
let grid = VoxelGrid::new(
    vec![si, c],
    [2, 1, 1],
    [1e-8; 3],
    vec![0, 1],
    [Boundary::Vacuum, Boundary::Periodic, Boundary::Periodic],
)
.unwrap();
assert_eq!(grid.locate([1.5e-8, 0.5e-8, 0.5e-8]), Some(1));

Implementations§

Source§

impl VoxelGrid

Source

pub fn new( materials: Vec<Material>, dims: [usize; 3], spacing_m: [f64; 3], cells: Vec<u32>, boundaries: [Boundary; 3], ) -> Result<Self, GeometryError>

Build a grid of dims voxels of edge lengths spacing_m, where voxel i + nx (j + ny k) has material cells[...] (an index into materials), with boundaries per axis [x, y, z].

Every dimension must be nonzero, every spacing finite and positive with a finite extent n h, the voxel count must not overflow, and every material index must exist.

Source

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

Voxels per axis [nx, ny, nz].

Source

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

Voxel edge lengths [hx, hy, hz], m.

Source

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

Box size [Lx, Ly, Lz] = n h, m.

Source

pub fn boundary(&self, axis: usize) -> Boundary

Boundary behaviour of axis axis (0 = x, 1 = y, 2 = z).

Source

pub fn flat_index(&self, ijk: [usize; 3]) -> Option<usize>

Flat region index of voxel (i, j, k), or None out of range.

Source

pub fn voxel_of(&self, region: usize) -> [usize; 3]

Voxel (i, j, k) of a flat region index.

Source

pub fn cell_material(&self, ijk: [usize; 3]) -> Option<usize>

Material index of voxel (i, j, k), or None out of range.

Trait Implementations§

Source§

impl Clone for VoxelGrid

Source§

fn clone(&self) -> VoxelGrid

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 VoxelGrid

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Geometry for VoxelGrid

Source§

fn flight( &self, region: usize, pos: [f64; 3], dir: [f64; 3], limit: f64, ) -> Flight

The traversal behind Geometry::exit. Without an event, the region is the voxel the DDA has reached at the limit: same-material faces up to and including the limit have been crossed, so a flight ending exactly on a face is in the voxel beyond it along dir. A periodic wrap is always an event, so a clear flight never wraps.

Source§

fn n_materials(&self) -> usize

Number of distinct materials.
Source§

fn material(&self, index: usize) -> &Material

Material index (0..n_materials()).
Source§

fn n_regions(&self) -> usize

Number of regions.
Source§

fn material_index(&self, region: usize) -> usize

Index of the material filling region.
Source§

fn locate(&self, pos: [f64; 3]) -> Option<usize>

The region containing pos, or None outside the target (or for a non-finite position). Ownership of shared faces: see the module docs.
Source§

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

Where a beam enters by default: the origin for a Stack, the centre of the front face for a VoxelGrid.
Source§

fn exit( &self, region: usize, pos: [f64; 3], dir: [f64; 3], limit: f64, ) -> Option<Exit>

The first event along the straight flight from pos (inside region, or on one of its faces) in the unit direction dir, if it happens at a path length of at most limit; otherwise None. The event is a change of material, a periodic wrap, or leaving the target. Read more
Source§

fn in_vacuum(&self, pos: [f64; 3]) -> bool

Whether pos lies outside the target in vacuum, used to skip weak- collision partners that would lie beyond a surface. For a Stack this is in front of the front face only (as in the M0 engine).
Source§

fn as_stack(&self) -> Option<&Stack>

This geometry as a layered Stack, if it is one. Tallies defined per layer (dose, depth-dose, interface transmission) need it.
Source§

impl PartialEq for VoxelGrid

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VoxelGrid

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V