diff --git a/openmc/deplete/nuclide.py b/openmc/deplete/nuclide.py index c2267fcb2b..767163b057 100644 --- a/openmc/deplete/nuclide.py +++ b/openmc/deplete/nuclide.py @@ -218,9 +218,16 @@ class Nuclide: # Check for use of FPY from other nuclide parent = fpy_elem.get('parent') if parent is not None: + assert root is not None fpy_elem = root.find( './/nuclide[@name="{}"]/neutron_fission_yields'.format(parent) ) + if fpy_elem is None: + raise ValueError( + "Fission product yields for {0} borrow from {1}, but {1} is" + " not present in the chain file or has no yields.".format( + nuc.name, parent + )) nuc._fpy = parent nuc.yield_data = FissionYieldDistribution.from_xml_element(fpy_elem) diff --git a/tests/unit_tests/test_deplete_nuclide.py b/tests/unit_tests/test_deplete_nuclide.py index 4bbdf08101..705beb32a2 100644 --- a/tests/unit_tests/test_deplete_nuclide.py +++ b/tests/unit_tests/test_deplete_nuclide.py @@ -118,6 +118,24 @@ def test_fpy_parent(): assert fpy_elem.get('parent') == 'U235' assert len(fpy_elem) == 0 + data = """ + + + + + + + + + + """ + + # U235 yields are missing, so we should get an exception + root = ET.fromstring(data) + elems = root.findall('nuclide') + with pytest.raises(ValueError, match="yields"): + u238 = nuclide.Nuclide.from_xml(elems[1], root) + def test_to_xml_element(): """Test writing nuclide data to an XML element."""