Add test for borrowing FPY, update documentation

This commit is contained in:
Paul Romano 2020-06-16 20:57:24 -05:00
parent 19aa88cfe2
commit ff58c199b1
3 changed files with 60 additions and 13 deletions

View file

@ -82,7 +82,7 @@ element has the following attributes:
------------------------------------
The ``<neutron_fission_yields>`` element provides yields of fission products for
fissionable nuclides. It has the follow sub-elements:
fissionable nuclides. Normally, it has the follow sub-elements:
:energies:
Energies in [eV] at which yields for products are tabulated
@ -100,3 +100,11 @@ fissionable nuclides. It has the follow sub-elements:
:data:
Independent yields for each fission product
In the event that a nuclide doesn't have any known fission product yields, it is
possible to have that nuclide borrow yields from another nuclide by indicating
the other nuclide in a single `parent` attribute. For example:
.. code-block:: xml
<neutron_fission_yields parent="U235"/>

View file

@ -155,15 +155,16 @@ class Nuclide:
return self.yield_data.energies
@classmethod
def from_xml(cls, element, root, fission_q=None):
def from_xml(cls, element, root=None, fission_q=None):
"""Read nuclide from an XML element.
Parameters
----------
element : xml.etree.ElementTree.Element
XML element to read nuclide data from
root : xml.etree.ElementTree.Element
Root XML element for chain file
root : None or xml.etree.ElementTree.Element
Root XML element for chain file (only used when fission product
yields are borrowed from another parent)
fission_q : None or float
User-supplied fission Q value [eV].
Will be read from the element if not given

View file

@ -2,7 +2,7 @@
import xml.etree.ElementTree as ET
import numpy
import numpy as np
import pytest
from openmc.deplete import nuclide
@ -81,6 +81,44 @@ def test_from_xml():
u235.yield_energies = [0.0253, 5e5]
def test_fpy_parent():
"""Test reading nuclide data with FPY borrowed from another nuclide."""
data = """
<depletion_chain>
<nuclide name="U235" reactions="1">
<reaction type="fission" Q="193405400.0"/>
<neutron_fission_yields>
<energies>0.0253</energies>
<fission_yields energy="0.0253">
<products>Te134 Zr100 Xe138</products>
<data>0.062155 0.0497641 0.0481413</data>
</fission_yields>
</neutron_fission_yields>
</nuclide>
<nuclide name="U238" reactions="1">
<reaction type="fission" Q="200.0e6"/>
<neutron_fission_yields parent="U235"/>
</nuclide>
</depletion_chain>
"""
root = ET.fromstring(data)
elems = root.findall('nuclide')
u235 = nuclide.Nuclide.from_xml(elems[0], root)
u238 = nuclide.Nuclide.from_xml(elems[1], root)
# Make sure U238 yield is same as U235
assert np.array_equal(u238.yield_data.energies, u235.yield_data.energies)
assert np.array_equal(u238.yield_data.yield_matrix, u235.yield_data.yield_matrix)
# Make sure XML element created has single attribute
elem = u238.to_xml_element()
fpy_elem = elem.find('neutron_fission_yields')
assert fpy_elem.get('parent') == 'U235'
assert len(fpy_elem) == 0
def test_to_xml_element():
"""Test writing nuclide data to an XML element."""
@ -134,11 +172,11 @@ def test_fission_yield_distribution():
act_dist = yield_dict[exp_ene]
for exp_prod, exp_yield in exp_dist.items():
assert act_dist[exp_prod] == exp_yield
exp_yield = numpy.array([
exp_yield = np.array([
[4.08e-12, 1.71e-12, 7.85e-4],
[1.32e-12, 0.0, 1.12e-3],
[5.83e-8, 2.69e-8, 4.54e-3]])
assert numpy.array_equal(yield_dist.yield_matrix, exp_yield)
assert np.array_equal(yield_dist.yield_matrix, exp_yield)
# Test the operations / special methods for fission yield
orig_yields = yield_dist[0.0253]
@ -151,18 +189,18 @@ def test_fission_yield_distribution():
# Scale and increment fission yields
mod_yields = orig_yields * 2
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
assert np.array_equal(orig_yields.yields * 2, mod_yields.yields)
mod_yields += orig_yields
assert numpy.array_equal(orig_yields.yields * 3, mod_yields.yields)
assert np.array_equal(orig_yields.yields * 3, mod_yields.yields)
mod_yields = 2.0 * orig_yields
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
assert np.array_equal(orig_yields.yields * 2, mod_yields.yields)
mod_yields = numpy.float64(2.0) * orig_yields
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
mod_yields = np.float64(2.0) * orig_yields
assert np.array_equal(orig_yields.yields * 2, mod_yields.yields)
# Failure modes for adding, multiplying yields
similar = numpy.empty_like(orig_yields.yields)
similar = np.empty_like(orig_yields.yields)
with pytest.raises(TypeError):
orig_yields + similar
with pytest.raises(TypeError):