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:
ID | Name | Symbol | Mesh Tag |
---|---|---|---|
0 | unknown (special meshtal case) | NONE | unknown |
1 | neutron | n | neutron |
2 | photon | p | photon |
3 | electron | e | electron |
4 | negative muon | | | mu_minus |
5 | anti neutron | q | Aneutron |
6 | electron neutrino | u | nu_e |
7 | muon neutrino | v | nu_m |
8 | positron | f | *NONE |
9 | proton | h | proton |
10 | lambda baryon | l | lambda0 |
11 | positive sigma baryon | + | sigma+ |
12 | negative sigma baryon | - | sigma- |
13 | cascade; xi baryon | x | xi0 |
14 | negative cascade; negative xi baryon | y | xi_minus |
15 | omega baryon | o | omega- |
16 | positive muon | ! | mu_plus |
17 | anti electron neutrino | < | Anu_e |
18 | anti muon neutrino | > | Anu_m |
19 | anti proton | g | Aproton |
20 | positive pion | / | pi_plus |
21 | neutral pion | z | pi_zero |
22 | positive kaon | k | k_plus |
23 | kaon, short | % | k0_short |
24 | kaon, long | ^ | k0_long |
25 | anti lambda baryon | b | Alambda0 |
26 | anti positive sigma baryon | _ | Asigma+ |
27 | anti negative sigma baryon | ~ | Asigma- |
28 | anti cascade; anti neutral xi baryon | c | Axi0 |
29 | positive cascade; positive xi baryon | w | xi_plus |
30 | anti omega | @ | Aomega- |
31 | deuteron | d | deuteron |
32 | triton | t | triton |
33 | helion | s | helion |
34 | alpha particle | a | alpha |
35 | negative pion | * | pi_minus |
36 | negative kaon | ? | k_minus |
37 | heavy 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
impl Particle
pub fn id(&self) -> u8
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
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
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"));