pub struct Bca<'a> { /* private fields */ }Expand description
The BCA engine for one beam, target and configuration.
Holds borrowed, read-only inputs and precomputed per-layer and per-pair
data, so it is Sync and shared by all worker threads.
Implementations§
Source§impl<'a> Bca<'a>
impl<'a> Bca<'a>
Sourcepub fn with_crystal(
self,
target: CrystalTarget,
regions: &[usize],
) -> Result<Self, BcaError>
pub fn with_crystal( self, target: CrystalTarget, regions: &[usize], ) -> Result<Self, BcaError>
Use the crystal flight model in regions (see the module docs). The
regions are indices into the geometry’s regions: layer indices of a
stack, flat voxel indices of a voxel grid.
§Errors
BcaError::InvalidConfig if the configuration is not the constant
free path without weak collisions, a region does not exist or already
belongs to a crystal, a search parameter is not finite and positive, a
region’s material lacks a lattice element, or its atom density differs
from the lattice’s by more than 5 %.
Sourcepub fn crystal_metadata(&self) -> Vec<CrystalMetadata>
pub fn crystal_metadata(&self) -> Vec<CrystalMetadata>
Run metadata of every crystal (Bca::with_crystal order): lattice,
orientation, search parameters and the thermal model with its target
temperature. Empty for an amorphous engine.
Source§impl<'a> Bca<'a>
impl<'a> Bca<'a>
Sourcepub fn new(
beam: Beam,
geometry: &'a dyn Geometry,
config: BcaConfig,
stopping: &'a (dyn ElectronicStopping + Sync),
table: &'a ScatteringTable,
) -> Result<Self, BcaError>
pub fn new( beam: Beam, geometry: &'a dyn Geometry, config: BcaConfig, stopping: &'a (dyn ElectronicStopping + Sync), table: &'a ScatteringTable, ) -> Result<Self, BcaError>
Validate the inputs and precompute per-layer and per-pair data.
- Every layer material must have
E_d,E_bandE_sset for every element (checked withcrate::material::Material::unset_energies), so a run never fails half way for a missing parameter. - The scattering table fixes the screening function and length convention; the same table serves every projectile/target pair, since the angle depends on the reduced variables only.
- Target atoms use, at each face, the
E_sof their element in the material they leave from; an element absent from that material uses itsE_sin the first material that contains it. geometryis aStackor aVoxelGrid(or any otherGeometry); its default entry point must lie in the target (Bca::with_entry_pointchanges it).
Sourcepub fn with_divergence(self, divergence: Divergence) -> Result<Self, BcaError>
pub fn with_divergence(self, divergence: Divergence) -> Result<Self, BcaError>
Give the beam an angular spread about its nominal direction (opt-in;
the default is Divergence::None, which changes nothing).
Each primary’s initial direction is the nominal
Beam::direction deflected by Divergence::sample_direction and
conditioned on pointing into the target (positive depth component):
a deflected direction with dir[0] <= 0 is rejected and redrawn, up
to MAX_DIVERGENCE_ATTEMPTS attempts, after which the history
fails with BcaError::BeamDivergence. The draws come from a copy of
the history’s stream positioned at word 2^65
(DIVERGENCE_STREAM_WORD), a segment disjoint from the transport
draws, the thermal segment (2^66) and the crystal-shift segment
(2^67), so the spread changes no other draw of the history. The
spread is a property of the beam: it applies to the primary from the
entry point, including while it crosses an amorphous layer; recoils
keep their collision-generated directions. The nominal orientation
convention (and the crystal orientation built from it) is unchanged.
Errors with BcaError::InvalidBeam when the parameters fail
Divergence::validate.
Sourcepub fn divergence_metadata(&self) -> Option<DivergenceMetadata>
pub fn divergence_metadata(&self) -> Option<DivergenceMetadata>
Metadata of the beam divergence; None without one.
Sourcepub fn divergence(&self) -> Divergence
pub fn divergence(&self) -> Divergence
The beam divergence (Divergence::None unless set by
Bca::with_divergence).
Sourcepub fn primary_direction(&self, index: u64) -> Result<[f64; 3], BcaError>
pub fn primary_direction(&self, index: u64) -> Result<[f64; 3], BcaError>
The initial direction of primary index of this engine’s run: what
Bca::run gives that history (the stream is
crate::rng::stream(seed, index)). The nominal direction without
divergence; otherwise the inward-conditioned divergent sample.
Sourcepub fn with_entry_point(self, pos: [f64; 3]) -> Result<Self, BcaError>
pub fn with_entry_point(self, pos: [f64; 3]) -> Result<Self, BcaError>
Start primaries at pos instead of the geometry’s default entry point.
pos must lie in the target (for a voxel grid this selects the
incident voxel explicitly; on a shared face the voxel with the higher
index owns the point).
Sourcepub fn species_z(&self) -> Vec<u8> ⓘ
pub fn species_z(&self) -> Vec<u8> ⓘ
Atomic numbers of the particle species, by species index (index 0 is the beam).
Sourcepub fn run<T, N>(&self, new_tally: N) -> Result<T, BcaError>
pub fn run<T, N>(&self, new_tally: N) -> Result<T, BcaError>
Run all beam.count histories in parallel on the current rayon pool
and return the merged tally. Bit-identical at any thread count when the
tally’s merge is order-independent of scheduling (it is called in
chunk order). If a history fails, the error of the lowest failing
index is returned.
Sourcepub fn run_range<T, N>(
&self,
first_index: u64,
count: u64,
new_tally: N,
) -> Result<T, BcaError>
pub fn run_range<T, N>( &self, first_index: u64, count: u64, new_tally: N, ) -> Result<T, BcaError>
Bca::run for the global primary indices
first_index..first_index + count (instead of 0..beam.count):
primary first_index + k uses the stream
stream(seed, first_index + k) and reports that index to the tally
hooks. A run cut into consecutive ranges draws exactly the histories of
one longer run; this is what lets the fluence steps of a dynamic run
continue the global stream. run is run_range(0, beam.count, ..).
Sourcepub fn history<T: BcaTally>(
&self,
tally: &mut T,
rng: &mut ParticleRng,
index: u64,
) -> Result<EnergyBudget, HistoryError>
pub fn history<T: BcaTally>( &self, tally: &mut T, rng: &mut ParticleRng, index: u64, ) -> Result<EnergyBudget, HistoryError>
Simulate primary index and its cascade with the given stream (use
crate::rng::stream(seed, index) for results consistent with
Bca::run). Returns the history’s energy budget.
Sourcepub fn history_in<T: BcaTally>(
&self,
buffers: &mut HistoryBuffers,
tally: &mut T,
rng: &mut ParticleRng,
index: u64,
) -> Result<EnergyBudget, HistoryError>
pub fn history_in<T: BcaTally>( &self, buffers: &mut HistoryBuffers, tally: &mut T, rng: &mut ParticleRng, index: u64, ) -> Result<EnergyBudget, HistoryError>
Bca::history in caller-owned working memory. Identical results;
reusing buffers across histories removes the per-history
allocations (Bca::run does this per worker chunk).
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Bca<'a>
impl<'a> !UnwindSafe for Bca<'a>
impl<'a> Freeze for Bca<'a>
impl<'a> Send for Bca<'a>
impl<'a> Sync for Bca<'a>
impl<'a> Unpin for Bca<'a>
impl<'a> UnsafeUnpin for Bca<'a>
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> 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