Skip to content

Commit

Permalink
Enforce non-negative percents for material.add_nuclide to prevent uni…
Browse files Browse the repository at this point in the history
…ntended ao/wo flipping (openmc-dev#3075)
  • Loading branch information
johvincau authored Jul 8, 2024
1 parent b11f8b7 commit e74dc50
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openmc/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' \
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e74dc50

Please sign in to comment.