endf_format 0.0.4

ENDF-6 Format Rust Library
Documentation
//! Module defining currently defined ENDF SubLibrary.
//!
//! ENDF sub-libraries are described in section `0.3.2`and table 3 of ENDF-6
//! Formats Manual.
//!
//! `ENDF-6 Formats Manual` available at
//! <https://www.nndc.bnl.gov/csewg/docs/endf-manual.pdf>
//!
//! > The sub-library distinguishes between different incident particles and
//! > types of data using `NSUB = 10*IPART+ITYPE`.

use std::fmt::{Display, Formatter};

/// ENDF SubLibrary.
///
/// > The sub-library distinguishes between different incident particles and
/// > types of data using `NSUB = 10*IPART+ITYPE`.
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[non_exhaustive]
pub enum SubLibrary {
    PhotoNuclear,
    PhotoFissionProductYields,
    PhotoAtomicInteraction,
    RadioactiveDecay,
    SpontaneousFissionProductYields,
    AtomicRelaxation,
    Neutron,
    NeutronFissionProductYields,
    ThermalNeutronScattering,
    NeutronStandards,
    ElectroAtomicInteraction,
    Proton,
    ProtonFissionProductYields,
    Deuteron,
    Triton,
    Helion,
    Alpha,
}

impl SubLibrary {
    /// Returns the sub-library corresponding to specified `NSUB` if available.
    pub fn from_nsub(nsub: u32) -> Option<Self> {
        match nsub {
            0 => Some(Self::PhotoNuclear),
            1 => Some(Self::PhotoFissionProductYields),
            3 => Some(Self::PhotoAtomicInteraction),
            4 => Some(Self::RadioactiveDecay),
            5 => Some(Self::SpontaneousFissionProductYields),
            6 => Some(Self::AtomicRelaxation),
            10 => Some(Self::Neutron),
            11 => Some(Self::NeutronFissionProductYields),
            12 => Some(Self::ThermalNeutronScattering),
            19 => Some(Self::NeutronStandards),
            113 => Some(Self::ElectroAtomicInteraction),
            10010 => Some(Self::Proton),
            10011 => Some(Self::ProtonFissionProductYields),
            10020 => Some(Self::Deuteron),
            10030 => Some(Self::Triton),
            20030 => Some(Self::Helion),
            20040 => Some(Self::Alpha),
            _ => None,
        }
    }

    /// Returns the name of the sub-library.
    pub fn name(&self) -> String {
        match self {
            Self::PhotoNuclear => "Photo-Nuclear Data".into(),
            Self::PhotoFissionProductYields => "Photo-Induced Fission Product Yields".into(),
            Self::PhotoAtomicInteraction => "Photo-Atomic Interaction Data".into(),
            Self::RadioactiveDecay => "Radioactive Decay Data".into(),
            Self::SpontaneousFissionProductYields => "Spontaneous Fission Product Yields".into(),
            Self::AtomicRelaxation => "Atomic Relaxation Data".into(),
            Self::Neutron => "Incident-Neutron Data".into(),
            Self::NeutronFissionProductYields => "Neutron-Induced Fission Product Yields".into(),
            Self::ThermalNeutronScattering => "Thermal Neutron Scattering Data".into(),
            Self::NeutronStandards => "Neutron Standards Data".into(),
            Self::ElectroAtomicInteraction => "Electro-Atomic Interaction Data".into(),
            Self::Proton => "Incident-Proton Data".into(),
            Self::ProtonFissionProductYields => "Proton-Induced Fission Product Yields".into(),
            Self::Deuteron => "Incident-Deuteron Data".into(),
            Self::Triton => "Incident-Triton Data".into(),
            Self::Helion => "Incident-Helion Data".into(),
            Self::Alpha => "Incident-Alpha Data".into(),
        }
    }

    /// Returns the sub-library identifier `NSUB`.
    pub fn nsub(&self) -> u32 {
        match self {
            Self::PhotoNuclear => 0,
            Self::PhotoFissionProductYields => 1,
            Self::PhotoAtomicInteraction => 3,
            Self::RadioactiveDecay => 4,
            Self::SpontaneousFissionProductYields => 5,
            Self::AtomicRelaxation => 6,
            Self::Neutron => 10,
            Self::NeutronFissionProductYields => 11,
            Self::ThermalNeutronScattering => 12,
            Self::NeutronStandards => 19,
            Self::ElectroAtomicInteraction => 113,
            Self::Proton => 10010,
            Self::ProtonFissionProductYields => 10011,
            Self::Deuteron => 10020,
            Self::Triton => 10030,
            Self::Helion => 20030,
            Self::Alpha => 20040,
        }
    }

    /// Returns the sub-library `IPART`.
    pub fn ipart(&self) -> u32 {
        match self {
            Self::PhotoNuclear => 0,
            Self::PhotoFissionProductYields => 0,
            Self::PhotoAtomicInteraction => 0,
            Self::RadioactiveDecay => 0,
            Self::SpontaneousFissionProductYields => 0,
            Self::AtomicRelaxation => 0,
            Self::Neutron => 1,
            Self::NeutronFissionProductYields => 1,
            Self::ThermalNeutronScattering => 1,
            Self::NeutronStandards => 1,
            Self::ElectroAtomicInteraction => 11,
            Self::Proton => 1001,
            Self::ProtonFissionProductYields => 1001,
            Self::Deuteron => 1002,
            Self::Triton => 1003,
            Self::Helion => 2003,
            Self::Alpha => 2004,
        }
    }

    /// Returns the sub-library `ITYPE`
    pub fn itype(&self) -> u32 {
        match self {
            Self::PhotoNuclear => 0,
            Self::PhotoFissionProductYields => 1,
            Self::PhotoAtomicInteraction => 3,
            Self::RadioactiveDecay => 4,
            Self::SpontaneousFissionProductYields => 5,
            Self::AtomicRelaxation => 6,
            Self::Neutron => 0,
            Self::NeutronFissionProductYields => 1,
            Self::ThermalNeutronScattering => 2,
            Self::NeutronStandards => 9,
            Self::ElectroAtomicInteraction => 3,
            Self::Proton => 0,
            Self::ProtonFissionProductYields => 1,
            Self::Deuteron => 0,
            Self::Triton => 0,
            Self::Helion => 0,
            Self::Alpha => 0,
        }
    }
}

impl Display for SubLibrary {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{} (NSUB = {})", self.name(), self.nsub())
    }
}