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
impl VoxelGrid
Sourcepub fn new(
materials: Vec<Material>,
dims: [usize; 3],
spacing_m: [f64; 3],
cells: Vec<u32>,
boundaries: [Boundary; 3],
) -> Result<Self, GeometryError>
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.
Sourcepub fn boundary(&self, axis: usize) -> Boundary
pub fn boundary(&self, axis: usize) -> Boundary
Boundary behaviour of axis axis (0 = x, 1 = y, 2 = z).
Trait Implementations§
Source§impl Geometry for VoxelGrid
impl Geometry for VoxelGrid
Source§fn flight(
&self,
region: usize,
pos: [f64; 3],
dir: [f64; 3],
limit: f64,
) -> Flight
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
fn n_materials(&self) -> usize
Source§fn material_index(&self, region: usize) -> usize
fn material_index(&self, region: usize) -> usize
region.Source§fn locate(&self, pos: [f64; 3]) -> Option<usize>
fn locate(&self, pos: [f64; 3]) -> Option<usize>
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]
fn entry_point(&self) -> [f64; 3]
Source§fn exit(
&self,
region: usize,
pos: [f64; 3],
dir: [f64; 3],
limit: f64,
) -> Option<Exit>
fn exit( &self, region: usize, pos: [f64; 3], dir: [f64; 3], limit: f64, ) -> Option<Exit>
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 moreimpl StructuralPartialEq for VoxelGrid
Auto Trait Implementations§
impl Freeze for VoxelGrid
impl RefUnwindSafe for VoxelGrid
impl Send for VoxelGrid
impl Sync for VoxelGrid
impl Unpin for VoxelGrid
impl UnsafeUnpin for VoxelGrid
impl UnwindSafe for VoxelGrid
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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