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` #2926

Closed aprilnovak closed 1 week ago

aprilnovak commented 1 month 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). 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 weren't actually any natural isotopes for that element.

Alternatives

Print a warning if add_element does not add any nuclides.

Compatibility

New feature, better user experience.

shimwell commented 1 month ago

Perhaps we could add to the element.expand method that is called by material.add_element. We could add a check here in the expand method to check the length of isotopes found and print a warning if len(isotopes) == 0

perhaps something like

warnings.warn(f'No naturally occurring nuclides were found for element {self.name}')

cxtherineyu commented 1 month ago

Is this issue still open? I'd love to attempt to tackle it.

shimwell commented 1 month ago

I think the issue is all yours @cxtherineyu thanks for volunteering

MicahGale commented 1 month ago

My quick two cents. A custom Warning class should be defined so warnings can be correctly filtered by the end user instead of just calling Warnings.warn(""). I think maybe something like: NoNaturalIsotopesWarning