Skip to main content

Bca

Struct Bca 

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

Source

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

Source

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>

Source

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_b and E_s set for every element (checked with crate::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_s of their element in the material they leave from; an element absent from that material uses its E_s in the first material that contains it.
  • geometry is a Stack or a VoxelGrid (or any other Geometry); its default entry point must lie in the target (Bca::with_entry_point changes it).
Source

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.

Source

pub fn divergence_metadata(&self) -> Option<DivergenceMetadata>

Metadata of the beam divergence; None without one.

Source

pub fn divergence(&self) -> Divergence

The beam divergence (Divergence::None unless set by Bca::with_divergence).

Source

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.

Source

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

Source

pub fn beam(&self) -> &Beam

The beam.

Source

pub fn config(&self) -> &BcaConfig

The configuration.

Source

pub fn species_z(&self) -> Vec<u8> ⓘ

Atomic numbers of the particle species, by species index (index 0 is the beam).

Source

pub fn run<T, N>(&self, new_tally: N) -> Result<T, BcaError>
where T: BcaTally, N: Fn() -> T + Sync,

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.

Source

pub fn run_range<T, N>( &self, first_index: u64, count: u64, new_tally: N, ) -> Result<T, BcaError>
where T: BcaTally, N: Fn() -> T + Sync,

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, ..).

Source

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.

Source

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§

Source§

impl Debug for Bca<'_>

Source§

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

Formats the value using the given formatter. Read more

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