Example #1
0
def test_multiple_meshtally_meshtal():
    """Test a meshtal file containing 4 mesh tallies including neutron and
    photon, single energy group and multiple energy group.
    """

    if not HAVE_PYMOAB:
        raise SkipTest

    thisdir = os.path.dirname(__file__)
    meshtal_file = os.path.join(thisdir, "mcnp_meshtal_multiple_meshtal.txt")

    expected_h5m_4 = os.path.join(thisdir, "mcnp_meshtal_tally_4.h5m")
    expected_sm_4 = Mesh(mesh=expected_h5m_4, structured=True)

    expected_h5m_14 = os.path.join(thisdir, "mcnp_meshtal_tally_14.h5m")
    expected_sm_14 = Mesh(mesh=expected_h5m_14, structured=True)

    expected_h5m_24 = os.path.join(thisdir, "mcnp_meshtal_tally_24.h5m")
    expected_sm_24 = Mesh(mesh=expected_h5m_24, structured=True)

    expected_h5m_34 = os.path.join(thisdir, "mcnp_meshtal_tally_34.h5m")
    expected_sm_34 = Mesh(mesh=expected_h5m_34, structured=True)

    tags = {
        4: ["n_result", "n_rel_error", "n_total_result", "n_total_rel_error"],
        14: ["n_result", "n_rel_error", "n_total_result", "n_total_rel_error"],
        24: ["p_result", "p_rel_error", "p_total_result", "p_total_rel_error"],
        34: ["p_result", "p_rel_error", "p_total_result", "p_total_rel_error"]
    }
    meshtal_object = mcnp.Meshtal(meshtal_file, tags)
    assert_equal(meshtal_object.version, '5')
    assert_equal(meshtal_object.tally[4].mats, None)

    # test meshtally 4
    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm_4.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_result[v_e]
        expected = expected_sm_4.n_result[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm_4.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_rel_error[v_e]
        expected = expected_sm_4.n_rel_error[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm_4.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_total_result[v_e]
        expected = expected_sm_4.n_total_result[expected_v_e]
        assert_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm_4.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_total_rel_error[v_e]
        expected = expected_sm_4.n_total_rel_error[expected_v_e]
        assert_equal(written, expected)

    # test meshtally 14
    for v_e, expected_v_e in zip(
            meshtal_object.tally[14].structured_iterate_hex("xyz"),
            expected_sm_14.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[14].n_result[v_e]
        expected = expected_sm_14.n_result[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[14].structured_iterate_hex("xyz"),
            expected_sm_14.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[14].n_rel_error[v_e]
        expected = expected_sm_14.n_rel_error[expected_v_e]
        assert_array_equal(written, expected)

    # test meshtally 24
    for v_e, expected_v_e in zip(
            meshtal_object.tally[24].structured_iterate_hex("xyz"),
            expected_sm_24.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[24].p_result[v_e]
        expected = expected_sm_24.p_result[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[24].structured_iterate_hex("xyz"),
            expected_sm_24.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[24].p_rel_error[v_e]
        expected = expected_sm_24.p_rel_error[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[24].structured_iterate_hex("xyz"),
            expected_sm_24.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[24].p_total_result[v_e]
        expected = expected_sm_24.p_total_result[expected_v_e]
        assert_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[24].structured_iterate_hex("xyz"),
            expected_sm_24.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[24].p_total_rel_error[v_e]
        expected = expected_sm_24.p_total_rel_error[expected_v_e]
        assert_equal(written, expected)

    # test meshtally 34
    for v_e, expected_v_e in zip(
            meshtal_object.tally[34].structured_iterate_hex("xyz"),
            expected_sm_34.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[34].p_result[v_e]
        expected = expected_sm_34.p_result[expected_v_e]
        assert_array_equal(written, expected)

    for v_e, expected_v_e in zip(
            meshtal_object.tally[34].structured_iterate_hex("xyz"),
            expected_sm_34.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[34].p_rel_error[v_e]
        expected = expected_sm_34.p_rel_error[expected_v_e]
        assert_array_equal(written, expected)
Example #2
0
def test_single_meshtally_meshtal():
    """Test a meshtal file containing a single mesh tally.
    """

    if not HAVE_PYMOAB:
        raise SkipTest

    thisdir = os.path.dirname(__file__)
    meshtal_file = os.path.join(thisdir, "mcnp_meshtal_single_meshtal.txt")
    expected_h5m = os.path.join(thisdir, "mcnp_meshtal_single_mesh.h5m")
    expected_sm = Mesh(mesh=expected_h5m, structured=True)

    tags = {
        4: ["n_result", "n_rel_error", "n_total_result", "n_total_rel_error"]
    }

    meshtal_object = mcnp.Meshtal(meshtal_file, tags, meshes_have_mats=True)
    assert_not_equal(meshtal_object.tally[4].mats, None)

    # test Meshtal attributes
    assert_equal(meshtal_object.version, '5.mpi')

    assert_equal(meshtal_object.ld, "09282010")

    assert_equal(meshtal_object.title,
                 "Input file to general test meshtal file")

    assert_equal(meshtal_object.histories, 100000)

    # test MeshTally attributes
    assert_equal(meshtal_object.tally[4].tally_number, 4)
    assert_equal(meshtal_object.tally[4].particle, "neutron")
    assert_equal(meshtal_object.tally[4].dose_response, True)
    assert_equal(meshtal_object.tally[4].x_bounds,
                 (-200.00, -66.67, 66.67, 200.00))
    assert_equal(meshtal_object.tally[4].y_bounds,
                 (-200.00, -120.00, -40.00, 40.00, 120.00, 200.00))
    assert_equal(meshtal_object.tally[4].z_bounds,
                 (-200.00, -50.00, 100.00, 200.00))
    assert_equal(meshtal_object.tally[4].e_bounds,
                 (0.00E+00, 1.00E-01, 2.00E-01, 1.00E+00))

    # test vector tags
    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_result[v_e]
        expected = expected_sm.n_result[expected_v_e]
        assert_array_equal(written, expected)
    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_rel_error[v_e]
        expected = expected_sm.n_rel_error[expected_v_e]
        assert_array_equal(written, expected)

    # test total tag
    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_total_result[v_e]
        expected = expected_sm.n_total_result[expected_v_e]
        assert_equal(written, expected)
    for v_e, expected_v_e in zip(
            meshtal_object.tally[4].structured_iterate_hex("xyz"),
            expected_sm.structured_iterate_hex("xyz")):
        written = meshtal_object.tally[4].n_total_rel_error[v_e]
        expected = expected_sm.n_total_rel_error[expected_v_e]
        assert_equal(written, expected)