Enum Particle

#[repr(u8)]
pub enum Particle {
Show 38 variants Unknown = 0, Neutron = 1, Photon = 2, Electron = 3, NegativeMuon = 4, AntiNeutron = 5, ElectronNeutrino = 6, MuonNeutrino = 7, Positron = 8, Proton = 9, LambdaBaryon = 10, PosSigmaBaryon = 11, NegSigmaBaryon = 12, XiBaryon = 13, NegXiBaryon = 14, OmegaBaryon = 15, PosMuon = 16, AntiElectronNeutrino = 17, AntiMuonNeutrino = 18, AntiProton = 19, PosPion = 20, NeuPion = 21, PosKaon = 22, ShortKaon = 23, LongKaon = 24, AntiLambdaBaryon = 25, AntiPosSigmaBaryon = 26, AntiNegSigmaBaryon = 27, AntiNeuXiBaryon = 28, PosXiBaryon = 29, AntiOmega = 30, Deuteron = 31, Triton = 32, Helion = 33, Alpha = 34, NegPion = 35, NegKaon = 36, HeavyIon = 37,
}
Expand description

Complete collection of MCNP particle variants

The particle is set to Particle::Unknown by default, and can be inferred from several possible identifiers. If the desired behaviour is simply to set any failed conversions to Particle::Unknown, then the from_str() and from_id() associated functions are implemented for convenience.

// Failing convenience functions are  set to the Unknown variant
assert_eq!(Particle::Unknown, Particle::from_str("invalid string"));
assert_eq!(Particle::Unknown, Particle::from_id(56));

Otherwise, Particle implements TryFrom<&str> and TryFrom<u8> to ensure the failing case is handled.

// From the particle symbol
assert_eq!(Particle::Alpha, Particle::try_from("a").unwrap());

// From the particle number
assert_eq!(Particle::Alpha, Particle::try_from("34").unwrap());
assert_eq!(Particle::Alpha, Particle::try_from(34).unwrap());

// From the meshtal tag
assert_eq!(Particle::Alpha, Particle::try_from("alpha").unwrap());

// From the full name given in the user manual
assert_eq!(Particle::Alpha, Particle::try_from("alpha particle").unwrap());

For reference, a full list of valid MCNP particle identifiers is shown below:

IDNameSymbolMesh Tag
0unknown (special meshtal case)NONEunknown
1neutronnneutron
2photonpphoton
3electroneelectron
4negative muon|mu_minus
5anti neutronqAneutron
6electron neutrinounu_e
7muon neutrinovnu_m
8positronf*NONE
9protonhproton
10lambda baryonllambda0
11positive sigma baryon+sigma+
12negative sigma baryon-sigma-
13cascade; xi baryonxxi0
14negative cascade; negative xi baryonyxi_minus
15omega baryonoomega-
16positive muon!mu_plus
17anti electron neutrino<Anu_e
18anti muon neutrino>Anu_m
19anti protongAproton
20positive pion/pi_plus
21neutral pionzpi_zero
22positive kaonkk_plus
23kaon, short%k0_short
24kaon, long^k0_long
25anti lambda baryonbAlambda0
26anti positive sigma baryon_Asigma+
27anti negative sigma baryon~Asigma-
28anti cascade; anti neutral xi baryoncAxi0
29positive cascade; positive xi baryonwxi_plus
30anti omega@Aomega-
31deuteronddeuteron
32tritonttriton
33helionshelion
34alpha particleaalpha
35negative pion*pi_minus
36negative kaon?k_minus
37heavy ions#heavyion

*Note that the positron particle designator is invalid on the FMESH card because it is treated as an electron. It therefore has no meshtal output tag.

Variants§

§

Unknown = 0

§

Neutron = 1

§

Photon = 2

§

Electron = 3

§

NegativeMuon = 4

§

AntiNeutron = 5

§

ElectronNeutrino = 6

§

MuonNeutrino = 7

§

Positron = 8

§

Proton = 9

§

LambdaBaryon = 10

§

PosSigmaBaryon = 11

§

NegSigmaBaryon = 12

§

XiBaryon = 13

§

NegXiBaryon = 14

§

OmegaBaryon = 15

§

PosMuon = 16

§

AntiElectronNeutrino = 17

§

AntiMuonNeutrino = 18

§

AntiProton = 19

§

PosPion = 20

§

NeuPion = 21

§

PosKaon = 22

§

ShortKaon = 23

§

LongKaon = 24

§

AntiLambdaBaryon = 25

§

AntiPosSigmaBaryon = 26

§

AntiNegSigmaBaryon = 27

§

AntiNeuXiBaryon = 28

§

PosXiBaryon = 29

§

AntiOmega = 30

§

Deuteron = 31

§

Triton = 32

§

Helion = 33

§

Alpha = 34

§

NegPion = 35

§

NegKaon = 36

§

HeavyIon = 37

Implementations§

§

impl Particle

pub fn id(&self) -> u8

An alternative to using Neutron as u8

For the case where particle.id() is prefereable to particle as u8, which may be more intuitive or imporve code readability. Panics on invalid values.

// These two statements are equivalent
assert_eq!(Particle::Electron as u8, Particle::Electron.id());

pub fn from_id(s: u8) -> Self

Convert from any valid particle id

If the value given is outside of the number of possible variant, the returned value will be Particle::Unknown.

// From a valid particle id
assert_eq!(Particle::Neutron, Particle::from_id(1));

// Invalid inputs return the Unknown variant (0-37 are valid)
assert_eq!(Particle::Unknown, Particle::from_id(41));

pub fn from_str(s: &str) -> Self

Convert from any valid designator, name, or meshtal output tag

If the particle type can not be inferred from the provided string the Particle::Unknown variant is returned. All inputs are insensitive to case.

// From the particle symbol/designator
assert_eq!(Particle::LambdaBaryon, Particle::from_str("l"));

// From the particle number
assert_eq!(Particle::LambdaBaryon, Particle::from_str("10"));

// From the meshtal tag
assert_eq!(Particle::LambdaBaryon, Particle::from_str("lambda0"));

// From the full name given in the user manual
assert_eq!(Particle::LambdaBaryon, Particle::from_str("lambda baryon"));

// Invalid inputs return the Unknown variant
assert_eq!(Particle::Unknown, Particle::from_str("invalid input"));

Trait Implementations§

§

impl Clone for Particle

§

fn clone(&self) -> Particle

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Particle

§

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

Formats the value using the given formatter. Read more
§

impl Default for Particle

§

fn default() -> Particle

Returns the “default value” for a type. Read more
§

impl Ord for Particle

§

fn cmp(&self, other: &Particle) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl PartialEq for Particle

§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for Particle

§

fn partial_cmp(&self, other: &Particle) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl TryFrom<&str> for Particle

Convert from any valid designator, name, or meshtal output tag

§

type Error = Error

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

fn try_from(s: &str) -> Result<Self, Self::Error>

Performs the conversion.
§

impl TryFrom<u8> for Particle

Convert from any valid numerical designator

§

type Error = Error

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

fn try_from(v: u8) -> Result<Self, Self::Error>

Performs the conversion.
§

impl Copy for Particle

§

impl Eq for Particle

§

impl StructuralPartialEq for Particle

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
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> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,