mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Merge branch 'develop' into chain-set-branches-general
This commit is contained in:
commit
6c25dbf33b
7 changed files with 352 additions and 12 deletions
|
|
@ -330,7 +330,6 @@ def test_capture_branch_failures(simple_chain):
|
|||
simple_chain.set_branch_ratios(br, "(n,gamma)")
|
||||
|
||||
|
||||
|
||||
def test_set_alpha_branches():
|
||||
"""Test setting of alpha reaction branching ratios"""
|
||||
# Build a mock chain
|
||||
|
|
@ -377,3 +376,55 @@ def test_set_alpha_branches():
|
|||
break
|
||||
else:
|
||||
raise ValueError("Helium has been removed and should not have been")
|
||||
|
||||
|
||||
def test_validate(simple_chain):
|
||||
"""Test the validate method"""
|
||||
|
||||
# current chain is invalid
|
||||
# fission yields do not sum to 2.0
|
||||
with pytest.raises(ValueError, match="Nuclide C.*fission yields"):
|
||||
simple_chain.validate(strict=True, tolerance=0.0)
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not simple_chain.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert not simple_chain.validate(strict=False, quiet=True, tolerance=0.0)
|
||||
assert len(record) == 1
|
||||
assert "Nuclide C" in record[0].message.args[0]
|
||||
|
||||
# Fix fission yields but keep to restore later
|
||||
old_yields = simple_chain["C"].yield_data
|
||||
simple_chain["C"].yield_data = {0.0253: [("A", 1.4), ("B", 0.6)]}
|
||||
|
||||
assert simple_chain.validate(strict=True, tolerance=0.0)
|
||||
with pytest.warns(None) as record:
|
||||
assert simple_chain.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert len(record) == 0
|
||||
|
||||
# Mess up "earlier" nuclide's reactions
|
||||
decay_mode = simple_chain["A"].decay_modes.pop()
|
||||
|
||||
with pytest.raises(ValueError, match="Nuclide A.*decay mode"):
|
||||
simple_chain.validate(strict=True, tolerance=0.0)
|
||||
|
||||
# restore old fission yields
|
||||
simple_chain["C"].yield_data = old_yields
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not simple_chain.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert len(record) == 2
|
||||
assert "Nuclide A" in record[0].message.args[0]
|
||||
assert "Nuclide C" in record[1].message.args[0]
|
||||
|
||||
# restore decay modes
|
||||
simple_chain["A"].decay_modes.append(decay_mode)
|
||||
|
||||
|
||||
def test_validate_inputs():
|
||||
c = Chain()
|
||||
|
||||
with pytest.raises(TypeError, match="tolerance"):
|
||||
c.validate(tolerance=None)
|
||||
|
||||
with pytest.raises(ValueError, match="tolerance"):
|
||||
c.validate(tolerance=-1)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import pytest
|
||||
|
||||
from openmc.deplete import nuclide
|
||||
|
||||
|
||||
|
|
@ -114,3 +116,92 @@ def test_to_xml_element():
|
|||
assert float(rx_elems[1].get("Q")) == 0.0
|
||||
|
||||
assert element.find('neutron_fission_yields') is not None
|
||||
|
||||
|
||||
def test_validate():
|
||||
|
||||
nuc = nuclide.Nuclide()
|
||||
nuc.name = "Test"
|
||||
|
||||
# decay modes: type, target, branching_ratio
|
||||
|
||||
nuc.decay_modes = [
|
||||
nuclide.DecayTuple("type 0", "0", 0.5),
|
||||
nuclide.DecayTuple("type 1", "1", 0.5),
|
||||
]
|
||||
|
||||
# reactions: type, target, Q, branching_ratio
|
||||
nuc.reactions = [
|
||||
nuclide.ReactionTuple("0", "0", 1000, 0.3),
|
||||
nuclide.ReactionTuple("0", "1", 1000, 0.3),
|
||||
nuclide.ReactionTuple("1", "2", 1000, 1.0),
|
||||
nuclide.ReactionTuple("0", "3", 1000, 0.4),
|
||||
]
|
||||
|
||||
# fission yields
|
||||
|
||||
nuc.yield_data = {
|
||||
0.0253: [("0", 1.5), ("1", 0.5)],
|
||||
1e6: [("0", 1.5), ("1", 0.5)],
|
||||
}
|
||||
|
||||
# nuclide is good and should have no warnings raise
|
||||
with pytest.warns(None) as record:
|
||||
assert nuc.validate(strict=True, quiet=False, tolerance=0.0)
|
||||
assert len(record) == 0
|
||||
|
||||
# invalidate decay modes
|
||||
decay = nuc.decay_modes.pop()
|
||||
with pytest.raises(ValueError, match="decay mode"):
|
||||
nuc.validate(strict=True, quiet=False, tolerance=0.0)
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not nuc.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert not nuc.validate(strict=False, quiet=True, tolerance=0.0)
|
||||
assert len(record) == 1
|
||||
assert "decay mode" in record[0].message.args[0]
|
||||
|
||||
# restore decay modes, invalidate reactions
|
||||
nuc.decay_modes.append(decay)
|
||||
reaction = nuc.reactions.pop()
|
||||
|
||||
with pytest.raises(ValueError, match="0 reaction"):
|
||||
nuc.validate(strict=True, quiet=False, tolerance=0.0)
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not nuc.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert not nuc.validate(strict=False, quiet=True, tolerance=0.0)
|
||||
assert len(record) == 1
|
||||
assert "0 reaction" in record[0].message.args[0]
|
||||
|
||||
# restore reactions, invalidate fission yields
|
||||
nuc.reactions.append(reaction)
|
||||
nuc.yield_data[1e6].pop()
|
||||
|
||||
with pytest.raises(ValueError, match=r"fission yields.*1\.0*e"):
|
||||
nuc.validate(strict=True, quiet=False, tolerance=0.0)
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not nuc.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert not nuc.validate(strict=False, quiet=True, tolerance=0.0)
|
||||
assert len(record) == 1
|
||||
assert "1.0" in record[0].message.args[0]
|
||||
|
||||
# invalidate everything, check that error is raised at decay modes
|
||||
|
||||
decay = nuc.decay_modes.pop()
|
||||
reaction = nuc.reactions.pop()
|
||||
|
||||
with pytest.raises(ValueError, match="decay mode"):
|
||||
nuc.validate(strict=True, quiet=False, tolerance=0.0)
|
||||
|
||||
# check for warnings
|
||||
# should be one warning for decay modes, reactions, fission yields
|
||||
|
||||
with pytest.warns(UserWarning) as record:
|
||||
assert not nuc.validate(strict=False, quiet=False, tolerance=0.0)
|
||||
assert not nuc.validate(strict=False, quiet=True, tolerance=0.0)
|
||||
assert len(record) == 3
|
||||
assert "decay mode" in record[0].message.args[0]
|
||||
assert "0 reaction" in record[1].message.args[0]
|
||||
assert "1.0" in record[2].message.args[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue