openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
699 stars 444 forks source link

Print warning if no natural isotopes when using add_element and wrote unit test #2938

Closed cxtherineyu closed 1 week ago

cxtherineyu commented 4 weeks ago

Description

When adding nuclides to a material with add_element, OpenMC will silently do nothing if there are no natural nuclides of that element (e.g., plutonium, technetium). It would be nice if the user encountered a warning about this, because if the user was trying to do this in the first place, they did not realize/recognize that there aren't actually any natural isotopes for that element.

I created a custom Warning class called 'NoNaturalIsotopesWarning' so warnings can be correctly filtered by the end user instead of just calling Warnings.warn("").

I added a check here in the expand method to check the length of nuclides found and print a warning if len(natural_nuclides) == 0.

Fixes # 2926

Checklist