From e30b570757eac7fc8b4dd9396b9a8c5b7621d05b Mon Sep 17 00:00:00 2001 From: "Micah D. Gale" Date: Tue, 17 Sep 2024 11:46:09 -0500 Subject: [PATCH] Added enum for material libraries types. --- montepy/__init__.py | 2 +- montepy/particle.py | 34 ++++++++++++++++++++++++++++++-- montepy/surfaces/surface_type.py | 6 +++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/montepy/__init__.py b/montepy/__init__.py index 3d67eaaf..560e46b2 100644 --- a/montepy/__init__.py +++ b/montepy/__init__.py @@ -28,7 +28,7 @@ from .input_parser.input_reader import read_input # top level -from montepy.particle import Particle +from montepy.particle import Particle, LibraryType from montepy.universe import Universe from montepy.cell import Cell from montepy.mcnp_problem import MCNP_Problem diff --git a/montepy/particle.py b/montepy/particle.py index 21359266..864fb40a 100644 --- a/montepy/particle.py +++ b/montepy/particle.py @@ -1,9 +1,9 @@ # Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved. -from enum import Enum, unique +from enum import StrEnum, unique @unique -class Particle(Enum): +class Particle(StrEnum): """ Supported MCNP supported particles. @@ -53,3 +53,33 @@ def __lt__(self, other): def __str__(self): return self.name.lower() + + +@unique +class LibraryType(StrEnum): + """ + + Taken from section of 5.6.1 of LA-UR-22-30006 + """ + + def __new__(cls, value, particle=None): + obj = str.__new__(cls) + obj._value_ = value + obj._particle_ = particle + return obj + + NEUTRON = ("NLIB", Particle.NEUTRON) + PHOTO_ATOMIC = ("PLIB", None) + PHOTO_NUCLEAR = ("PNLIB", None) + ELECTRON = ("ELIB", Particle.ELECTRON) + PROTON = ("HLIB", Particle.PROTON) + ALPHA_PARTICLE = ("ALIB", Particle.ALPHA_PARTICLE) + HELION = ("SLIB", Particle.HELION) + TRITON = ("TLIB", Particle.TRITON) + DEUTERON = ("DLIB", Particle.DEUTERON) + + def __str__(self): + return self.name.lower() + + def __lt__(self, other): + return self.value < other.value diff --git a/montepy/surfaces/surface_type.py b/montepy/surfaces/surface_type.py index bd440c53..c74c1fba 100644 --- a/montepy/surfaces/surface_type.py +++ b/montepy/surfaces/surface_type.py @@ -1,9 +1,9 @@ # Copyright 2024, Battelle Energy Alliance, LLC All Rights Reserved. -from enum import unique, Enum +from enum import unique, StrEnum -# @unique -class SurfaceType(str, Enum): +@unique +class SurfaceType(StrEnum): """ An enumeration of the surface types allowed.