From e74dc5037ebfc575a72ed963c2ab148fc374b5ee Mon Sep 17 00:00:00 2001 From: John Vincent Cauilan <64677361+johvincau@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:29:49 -0500 Subject: [PATCH] Enforce non-negative percents for material.add_nuclide to prevent unintended ao/wo flipping (#3075) --- openmc/material.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openmc/material.py b/openmc/material.py index 6edc372161c..4b871b77d60 100644 --- a/openmc/material.py +++ b/openmc/material.py @@ -519,6 +519,7 @@ def add_nuclide(self, nuclide: str, percent: float, percent_type: str = 'ao'): cv.check_type('nuclide', nuclide, str) cv.check_type('percent', percent, Real) cv.check_value('percent type', percent_type, {'ao', 'wo'}) + cv.check_greater_than('percent', percent, 0, equality=True) if self._macroscopic is not None: msg = 'Unable to add a Nuclide to Material ID="{}" as a ' \ @@ -727,6 +728,7 @@ def add_element(self, element: str, percent: float, percent_type: str = 'ao', cv.check_type('nuclide', element, str) cv.check_type('percent', percent, Real) + cv.check_greater_than('percent', percent, 0, equality=True) cv.check_value('percent type', percent_type, {'ao', 'wo'}) # Make sure element name is just that