Beispiel #1
0
def test_set_alpha_branches():
    """Test setting of alpha reaction branching ratios"""
    # Build a mock chain
    chain = Chain()

    parent = nuclide.Nuclide()
    parent.name = "A"

    he4 = nuclide.Nuclide()
    he4.name = "He4"

    ground_tgt = nuclide.Nuclide()
    ground_tgt.name = "B"

    meta_tgt = nuclide.Nuclide()
    meta_tgt.name = "B_m1"

    for ix, nuc in enumerate((parent, ground_tgt, meta_tgt, he4)):
        chain.nuclides.append(nuc)
        chain.nuclide_dict[nuc.name] = ix

    # add reactions to parent
    parent.reactions.append(nuclide.ReactionTuple(
        "(n,a)", ground_tgt.name, 1.0, 0.6))
    parent.reactions.append(nuclide.ReactionTuple(
        "(n,a)", meta_tgt.name, 1.0, 0.4))
    parent.reactions.append(nuclide.ReactionTuple(
        "(n,a)", he4.name, 1.0, 1.0))

    expected_ref = {"A": {"B": 0.6, "B_m1": 0.4}}

    assert chain.get_branch_ratios("(n,a)") == expected_ref

    # alter and check again

    altered = {"A": {"B": 0.5, "B_m1": 0.5}}

    chain.set_branch_ratios(altered, "(n,a)")
    assert chain.get_branch_ratios("(n,a)") == altered

    # make sure that alpha particle still produced
    for r in parent.reactions:
        if r.target == he4.name:
            break
    else:
        raise ValueError("Helium has been removed and should not have been")
Beispiel #2
0
def test_export_to_xml(run_in_tmpdir):
    """Test writing a depletion chain to XML."""

    # Prevent different MPI ranks from conflicting
    filename = 'test{}.xml'.format(comm.rank)

    H1 = nuclide.Nuclide("H1")

    A = nuclide.Nuclide("A")
    A.half_life = 2.36520e4
    A.decay_modes = [
        nuclide.DecayTuple("beta1", "B", 0.6),
        nuclide.DecayTuple("beta2", "C", 0.4)
    ]
    A.reactions = [
        nuclide.ReactionTuple("(n,gamma)", "C", 0.0, 1.0),
        nuclide.ReactionTuple("(n,p)", "B", 0.0, 1.0)
    ]

    B = nuclide.Nuclide("B")
    B.half_life = 3.29040e4
    B.decay_modes = [nuclide.DecayTuple("beta", "A", 1.0)]
    B.reactions = [
        nuclide.ReactionTuple("(n,gamma)", "C", 0.0, 1.0),
        nuclide.ReactionTuple("(n,d)", "A", 0.0, 1.0)
    ]

    C = nuclide.Nuclide("C")
    C.reactions = [
        nuclide.ReactionTuple("fission", None, 2.0e8, 1.0),
        nuclide.ReactionTuple("(n,gamma)", "A", 0.0, 0.7),
        nuclide.ReactionTuple("(n,gamma)", "B", 0.0, 0.3)
    ]
    C.yield_data = nuclide.FissionYieldDistribution(
        {0.0253: {
            "A": 0.0292737,
            "B": 0.002566345
        }})

    chain = Chain()
    chain.nuclides = [H1, A, B, C]
    chain.export_to_xml(filename)

    chain_xml = open(filename, 'r').read()
    assert _TEST_CHAIN == chain_xml
Beispiel #3
0
def test_n_decay_modes():
    """ Test the decay mode count parameter. """

    nuc = nuclide.Nuclide()

    nuc.decay_modes = [
        nuclide.DecayTuple("beta1", "a", 0.5),
        nuclide.DecayTuple("beta2", "b", 0.3),
        nuclide.DecayTuple("beta3", "c", 0.2)
    ]

    assert nuc.n_decay_modes == 3
Beispiel #4
0
def test_n_reaction_paths():
    """ Test the reaction path count parameter. """

    nuc = nuclide.Nuclide()

    nuc.reactions = [
        nuclide.ReactionTuple("(n,2n)", "a", 0.0, 1.0),
        nuclide.ReactionTuple("(n,3n)", "b", 0.0, 1.0),
        nuclide.ReactionTuple("(n,4n)", "c", 0.0, 1.0)
    ]

    assert nuc.n_reaction_paths == 3
Beispiel #5
0
def test_capture_branch_no_rxn():
    """Ensure capture reactions that don't exist aren't created"""
    u4br = {"U234": {"U235": 0.5, "U235_m1": 0.5}}

    chain_file = Path(__file__).parents[1] / "chain_simple.xml"
    chain = Chain.from_xml(chain_file)

    u5m = nuclide.Nuclide("U235_m1")

    chain.nuclides.append(u5m)
    chain.nuclide_dict[u5m.name] = len(chain.nuclides) - 1

    with pytest.raises(AttributeError, match="U234"):
        chain.set_branch_ratios(u4br)
Beispiel #6
0
def test_capture_branch_infer_ground():
    """Ensure the ground state is infered if not given"""
    # Make up a metastable capture transition:
    infer_br = {"Xe135": {"Xe136_m1": 0.5}}
    set_br = {"Xe135": {"Xe136": 0.5, "Xe136_m1": 0.5}}

    chain_file = Path(__file__).parents[1] / "chain_simple.xml"
    chain = Chain.from_xml(chain_file)

    # Create nuclide to be added into the chain
    xe136m = nuclide.Nuclide("Xe136_m1")

    chain.nuclides.append(xe136m)
    chain.nuclide_dict[xe136m.name] = len(chain.nuclides) - 1

    chain.set_branch_ratios(infer_br, "(n,gamma)")

    assert chain.get_branch_ratios("(n,gamma)") == set_br
Beispiel #7
0
def test_to_xml_element():
    """Test writing nuclide data to an XML element."""

    C = nuclide.Nuclide("C")
    C.half_life = 0.123
    C.decay_modes = [
        nuclide.DecayTuple('beta-', 'B', 0.99),
        nuclide.DecayTuple('alpha', 'D', 0.01)
    ]
    C.reactions = [
        nuclide.ReactionTuple('fission', None, 2.0e8, 1.0),
        nuclide.ReactionTuple('(n,gamma)', 'A', 0.0, 1.0)
    ]
    C.yield_data = nuclide.FissionYieldDistribution(
        {0.0253: {
            "A": 0.0292737,
            "B": 0.002566345
        }})
    element = C.to_xml_element()

    assert element.get("half_life") == "0.123"

    decay_elems = element.findall("decay")
    assert len(decay_elems) == 2
    assert decay_elems[0].get("type") == "beta-"
    assert decay_elems[0].get("target") == "B"
    assert decay_elems[0].get("branching_ratio") == "0.99"
    assert decay_elems[1].get("type") == "alpha"
    assert decay_elems[1].get("target") == "D"
    assert decay_elems[1].get("branching_ratio") == "0.01"

    rx_elems = element.findall("reaction")
    assert len(rx_elems) == 2
    assert rx_elems[0].get("type") == "fission"
    assert float(rx_elems[0].get("Q")) == 2.0e8
    assert rx_elems[1].get("type") == "(n,gamma)"
    assert rx_elems[1].get("target") == "A"
    assert float(rx_elems[1].get("Q")) == 0.0

    assert element.find('neutron_fission_yields') is not None
Beispiel #8
0
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].yields *= 2

    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]