Пример #1
0
def mats_to_alara(inp, output):
    """This function reads in MCNP inp file and prints out an ALARA matlib.
    """
    if output in os.listdir("."):
        os.remove(output)

    mats = read_mcnp_inp(inp)
    mat_count = 0  # number material objects
    multi_count = 0  # number of mulimaterial objects
    for mat in mats:
        if isinstance(mat, Material):
            mat.write_alara(output)
            mat_count += 1
        elif isinstance(mat, MultiMaterial):
            for submat in mat._mats:
                submat.write_alara(output)
                multi_count += 1
    # print out pseudovoid entry
    with open(output, "a") as f:
        f.write("pseudo_void 0 1\nhe 1 2")

    print "{0} single density mats and {1} multi-density mats printed".format(mat_count, multi_count)
Пример #2
0
def mats_to_alara(inp, output):
    """This function reads in MCNP inp file and prints out an ALARA matlib.
    """
    if output in os.listdir('.'):
        os.remove(output)

    mats = read_mcnp_inp(inp)
    mat_count = 0  # number material objects
    multi_count = 0  # number of mulimaterial objects
    for mat in mats:
        if isinstance(mat, Material):
            mat.write_alara(output)
            mat_count += 1
        elif isinstance(mat, MultiMaterial):
            for submat in mat._mats:
                submat.write_alara(output)
                multi_count += 1
    #print out pseudovoid entry
    with open(output, 'a') as f:
        f.write('pseudo_void 0 1\nhe 1 2')


    print '{0} single density mats and {1} multi-density mats printed'\
        .format(mat_count, multi_count)
Пример #3
0
def test_read_mcnp():
    expected_material = Material(nucvec={922350000: 0.04, 922380000: 0.96},
                                 mass=-1.0,
                                 density=19.1,
                                 metadata={"comments": (
                                     " first line of comments second line of "
                                     "comments third line of comments forth "
                                     "line of comments"),
                                           "mat_number": "1",
                                           "name": " leu",
                                           "source": " Some http://URL.com",
                                           "table_ids": {'922350': "15c"}})
    expected_material.mass = -1.0  # to avoid reassignment to +1.0

    expected_multimaterial = MultiMaterial({
        Material(
            {10000000: 0.11189838783149784, 80000000: 0.8881016121685023},
            -1.0, 0.9, 3,
            {"comments":
                 (" Here are comments the comments "
                  "continue here are more even more"),
             "mat_number": "2",
             "name": " water",
             "source": " internet",
             "table_ids": {'10000': "05c"}}): 1,
        Material(
            {10000000: 0.11189838783149784, 80000000: 0.8881016121685023},
            -1.0,
            1.0021552889223864, 3,
            {"comments":
                 (" Here are comments the comments "
                  "continue here are more even more"),
             "mat_number": "2",
             "name": " water",
             "source": " internet",
             "table_ids": {'10000': "05c"}}): 1})

    read_materials = read_mcnp_inp('mcnp_inp.txt')
    assert_equal(expected_material, read_materials[0])
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].comp,
        list(read_materials[1]._mats.keys())[0].comp)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].mass,
        list(read_materials[1]._mats.keys())[0].mass)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].density,
        list(read_materials[1]._mats.keys())[0].density)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].atoms_per_molecule,
        list(read_materials[1]._mats.keys())[0].atoms_per_molecule)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].metadata,
        list(read_materials[1]._mats.keys())[0].metadata)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].comp,
        list(read_materials[1]._mats.keys())[1].comp)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].mass,
        list(read_materials[1]._mats.keys())[1].mass)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].density,
        list(read_materials[1]._mats.keys())[1].density)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].atoms_per_molecule,
        list(read_materials[1]._mats.keys())[1].atoms_per_molecule)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].metadata,
        list(read_materials[1]._mats.keys())[1].metadata)
Пример #4
0
def test_read_mcnp():
    expected_material = Material(nucvec={
        922350000: 0.04,
        922380000: 0.96
    },
                                 mass=-1.0,
                                 density=19.1,
                                 metadata={
                                     "comments":
                                     (" first line of comments second line of "
                                      "comments third line of comments forth "
                                      "line of comments"),
                                     "mat_number":
                                     "1",
                                     "name":
                                     " leu",
                                     "source":
                                     " Some http://URL.com",
                                     "table_ids": {
                                         '922350': "15c"
                                     }
                                 })
    expected_material.mass = -1.0  # to avoid reassignment to +1.0

    expected_multimaterial = MultiMaterial({
        Material({
            10000000: 0.11189838783149784,
            80000000: 0.8881016121685023
        }, -1.0, 0.9, 3, {
                     "comments": (" Here are comments the comments "
                                  "continue here are more even more"),
                     "mat_number":
                     "2",
                     "name":
                     " water",
                     "source":
                     " internet",
                     "table_ids": {
                         '10000': "05c"
                     }
                 }):
        1,
        Material({
            10000000: 0.11189838783149784,
            80000000: 0.8881016121685023
        }, -1.0, 1.0021552889223864, 3, {
                     "comments": (" Here are comments the comments "
                                  "continue here are more even more"),
                     "mat_number":
                     "2",
                     "name":
                     " water",
                     "source":
                     " internet",
                     "table_ids": {
                         '10000': "05c"
                     }
                 }):
        1
    })

    read_materials = read_mcnp_inp('mcnp_inp.txt')
    assert_equal(expected_material, read_materials[0])
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].comp,
        list(read_materials[1]._mats.keys())[0].comp)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].mass,
        list(read_materials[1]._mats.keys())[0].mass)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].density,
        list(read_materials[1]._mats.keys())[0].density)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].atoms_per_molecule,
        list(read_materials[1]._mats.keys())[0].atoms_per_molecule)
    assert_equal(
        list(expected_multimaterial._mats.keys())[0].metadata,
        list(read_materials[1]._mats.keys())[0].metadata)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].comp,
        list(read_materials[1]._mats.keys())[1].comp)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].mass,
        list(read_materials[1]._mats.keys())[1].mass)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].density,
        list(read_materials[1]._mats.keys())[1].density)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].atoms_per_molecule,
        list(read_materials[1]._mats.keys())[1].atoms_per_molecule)
    assert_equal(
        list(expected_multimaterial._mats.keys())[1].metadata,
        list(read_materials[1]._mats.keys())[1].metadata)