예제 #1
0
파일: alara.py 프로젝트: smpark7/pyne
def mesh_to_geom(mesh, geom_file, matlib_file):
    """This function reads the materials of a PyNE mesh object and prints the
    geometry and materials portion of an ALARA input file, as well as a
    corresponding matlib file. If the mesh is structured, xyz ordering is used
    (z changing fastest). If the mesh is unstructured the mesh_iterate order is
    used.

    Parameters
    ----------
    mesh : PyNE Mesh object
        The Mesh object containing the materials to be printed.
    geom_file : str
        The name of the file to print the geometry and material blocks.
    matlib_file : str
        The name of the file to print the matlib.
    """
    # Create geometry information header. Note that the shape of the geometry
    # (rectangular) is actually inconsequential to the ALARA calculation so
    # unstructured meshes are not adversely affected.
    geometry = u"geometry rectangular\n\n"

    # Create three strings in order to create all ALARA input blocks in a
    # single mesh iteration.
    volume = u"volume\n"  # volume input block
    mat_loading = u"mat_loading\n"  # material loading input block
    mixture = u""  # mixture blocks
    matlib = u""  # ALARA material library string

    for i, mat, ve in mesh:
        volume += u"    {0: 1.6E}    zone_{1}\n".format(
            mesh.elem_volume(ve), i)
        mat_loading += u"    zone_{0}    mix_{0}\n".format(i)
        matlib += u"mat_{0}    {1: 1.6E}    {2}\n".format(
            i, mesh.density[i], len(mesh.comp[i]))
        mixture += (u"mixture mix_{0}\n"
                    u"    material mat_{0} 1 1\nend\n\n".format(i))

        for nuc, comp in mesh.comp[i].items():
            matlib += u"{0}    {1: 1.6E}    {2}\n".format(
                alara(nuc), comp * 100.0, znum(nuc))
        matlib += u"\n"

    volume += u"end\n\n"
    mat_loading += u"end\n\n"

    with open(geom_file, 'w') as f:
        f.write(geometry + volume + mat_loading + mixture)

    with open(matlib_file, 'w') as f:
        f.write(matlib)
예제 #2
0
파일: alara.py 프로젝트: NukespudWork/pyne
def mesh_to_geom(mesh, geom_file, matlib_file):
    """This function reads the materials of a PyNE mesh object and prints the
    geometry and materials portion of an ALARA input file, as well as a
    corresponding matlib file. If the mesh is structured, xyz ordering is used
    (z changing fastest). If the mesh is unstructured iMesh.iterate order is
    used. 

    Parameters
    ----------
    mesh : PyNE Mesh object
        The Mesh object containing the materials to be printed.
    geom_file : str
        The name of the file to print the geometry and material blocks.
    matlib_file : str
        The name of the file to print the matlib.
    """
    # Create geometry information header. Note that the shape of the geometry
    # (rectangular) is actually inconsequential to the ALARA calculation so
    # unstructured meshes are not adversely affected. 
    geometry = "geometry rectangular\n\n"

    # Create three strings in order to create all ALARA input blocks in a
    # single mesh iteration.
    volume = "volume\n" # volume input block
    mat_loading = "mat_loading\n" # material loading input block
    mixture = "" # mixture blocks
    matlib = "" # ALARA material library string

    for i, mat, ve in mesh:
        volume += "    {0: 1.6E}    zone_{1}\n".format(mesh.elem_volume(ve), i)
        mat_loading += "    zone_{0}    mix_{0}\n".format(i)
        matlib += "mat_{0}    {1: 1.6E}    {2}\n".format(i, mesh.density[i], 
                                                         len(mesh.comp[i]))
        mixture += ("mixture mix_{0}\n"
                    "    material mat_{0} 1 1\nend\n\n".format(i))

        for nuc, comp in mesh.comp[i].iteritems():
            matlib += "{0}    {1: 1.6E}    {2}\n".format(alara(nuc), comp*100.0, 
                                                         znum(nuc))
        matlib += "\n"

    volume += "end\n\n"
    mat_loading += "end\n\n"

    with open(geom_file, 'w') as f:
        f.write(geometry + volume + mat_loading + mixture)
    
    with open(matlib_file, 'w') as f:
        f.write(matlib)
예제 #3
0
def test_alara():
    assert_equal(nucname.alara(942390), "pu:239")
    assert_equal(nucname.alara(952421), "am:242")

    assert_equal(nucname.alara("PU239"), "pu:239")

    assert_equal(nucname.alara(94239), "pu:239")
    assert_equal(nucname.alara(95242), "am:242")
    assert_equal(nucname.alara(95642), "am:242")
    assert_equal(nucname.alara(92636), "u:236")
    assert_equal(nucname.alara(2000), "he")

    assert_equal(nucname.alara("Am-242m"), "am:242")

    assert_equal(nucname.alara(40020), "he:4")
    assert_equal(nucname.alara(20000), "he")
    assert_equal(nucname.alara(2440961), "cm:244")
    assert_equal(nucname.alara(2390940), "pu:239")
    assert_equal(nucname.alara(2420950), "am:242")
예제 #4
0
def test_alara():
    assert_equal(nucname.alara(942390), "pu:239")
    assert_equal(nucname.alara(952421), "am:242")

    assert_equal(nucname.alara("PU239"), "pu:239")

    assert_equal(nucname.alara(94239), "pu:239")
    assert_equal(nucname.alara(95242), "am:242")
    assert_equal(nucname.alara(95642), "am:242")
    assert_equal(nucname.alara(92636), "u:236")
    assert_equal(nucname.alara(2000), "he")

    assert_equal(nucname.alara("Am-242m"), "am:242")

    assert_equal(nucname.alara(40020), "he:4")
    assert_equal(nucname.alara(20000), "he")
    assert_equal(nucname.alara(2440961), "cm:244")
    assert_equal(nucname.alara(2390940), "pu:239")
    assert_equal(nucname.alara(2420950), "am:242")
예제 #5
0
파일: alara.py 프로젝트: mzweig/pyne
def record_to_geom(mesh, cell_fracs, cell_mats, geom_file, matlib_file, 
                   sig_figs=6):
    """This function preforms the same task as alara.mesh_to_geom, except the
    geometry is on the basis of the stuctured array output of
    dagmc.discretize_geom rather than a PyNE material object with materials.
    This allows for more efficient ALARA runs by minimizing the number of
    materials in the ALARA matlib. This is done by treating mixtures that are
    equal up to <sig_figs> digits to be the same mixture within ALARA.

    Parameters
    ----------
    mesh : PyNE Mesh object
        The Mesh object for which the geometry is discretized.
     cell_fracs : structured array
        The output from dagmc.discretize_geom(). A sorted, one dimensional
        array, each entry containing the following fields:

            :idx: int 
                The volume element index.
            :cell: int
                The geometry cell number.
            :vol_frac: float
                The volume fraction of the cell withing the mesh ve.
            :rel_error: float
                The relative error associated with the volume fraction.

     cell_mats : dict
        Maps geometry cell numbers to PyNE Material objects. Each PyNE material
        object must have the 'mat_number' in Material.metadata.
    geom_file : str
        The name of the file to print the geometry and material blocks.
    matlib_file : str
        The name of the file to print the matlib.
    sig_figs : int
        The number of significant figures that two mixtures must have in common
        to be treated as the same mixture within ALARA.
    """
    # Create geometry information header. Note that the shape of the geometry
    # (rectangular) is actually inconsequential to the ALARA calculation so
    # unstructured meshes are not adversely affected. 
    geometry = "geometry rectangular\n\n"

    # Create three strings in order to create all ALARA input blocks in a
    # single mesh iteration.
    volume = "volume\n" # volume input block
    mat_loading = "mat_loading\n" # material loading input block
    mixture = "" # mixture blocks

    unique_mixtures = []
    for i, mat, ve in mesh:
        volume += "    {0: 1.6E}    zone_{1}\n".format(mesh.elem_volume(ve), i)

        ve_mixture = {}
        for row in cell_fracs[cell_fracs['idx'] == i]:
            if cell_mats[row['cell']].metadata['mat_number'] \
                not in ve_mixture.keys():
                ve_mixture[cell_mats[row['cell']].metadata['mat_number']] = \
                    round(row['vol_frac'], sig_figs)
            else:
                ve_mixture[cell_mats[row['cell']].metadata['mat_number']] += \
                    round(row['vol_frac'], sig_figs)

        if ve_mixture not in unique_mixtures:
            unique_mixtures.append(ve_mixture)
            mixture += "mixture mix_{0}\n".format(
                                           unique_mixtures.index(ve_mixture))
            for key, value in ve_mixture.items():
                mixture += "    material mat_{0} 1 {1}\n".format(key, value)

            mixture += "end\n\n"

        mat_loading += "    zone_{0}    mix_{1}\n".format(i, 
                        unique_mixtures.index(ve_mixture))

    volume += "end\n\n"
    mat_loading += "end\n\n"

    with open(geom_file, 'w') as f:
        f.write(geometry + volume + mat_loading + mixture)
    
    matlib = "" # ALARA material library string

    printed_mats = []
    for mat in cell_mats.values():
        mat_num = mat.metadata['mat_number']
        if mat_num not in printed_mats:
            printed_mats.append(mat_num)
            matlib += "mat_{0}    {1: 1.6E}    {2}\n".format(
                       mat.metadata['mat_number'], mat.density, len(mat.comp))
            for nuc, comp in mat.comp.iteritems():
                matlib += "{0}    {1: 1.6E}    {2}\n".format(alara(nuc), 
                                                      comp*100.0, znum(nuc))
            matlib += "\n"

    with open(matlib_file, 'w') as f:
        f.write(matlib)
예제 #6
0
def record_to_geom(mesh,
                   cell_fracs,
                   cell_mats,
                   geom_file,
                   matlib_file,
                   sig_figs=6,
                   sub_voxel=False):
    """This function preforms the same task as alara.mesh_to_geom, except the
    geometry is on the basis of the stuctured array output of
    dagmc.discretize_geom rather than a PyNE material object with materials.
    This allows for more efficient ALARA runs by minimizing the number of
    materials in the ALARA matlib. This is done by treating mixtures that are
    equal up to <sig_figs> digits to be the same mixture within ALARA.

    Parameters
    ----------
    mesh : PyNE Mesh object
        The Mesh object for which the geometry is discretized.
    cell_fracs : structured array
        The output from dagmc.discretize_geom(). A sorted, one dimensional
        array, each entry containing the following fields:

            :idx: int
                The volume element index.
            :cell: int
                The geometry cell number.
            :vol_frac: float
                The volume fraction of the cell withing the mesh ve.
            :rel_error: float
                The relative error associated with the volume fraction.

    cell_mats : dict
        Maps geometry cell numbers to PyNE Material objects. Each PyNE material
        object must have 'name' specified in Material.metadata.
    geom_file : str
        The name of the file to print the geometry and material blocks.
    matlib_file : str
        The name of the file to print the matlib.
    sig_figs : int
        The number of significant figures that two mixtures must have in common
        to be treated as the same mixture within ALARA.
    sub_voxel : bool
        If sub_voxel is True, the sub-voxel r2s will be used.
    """
    # Create geometry information header. Note that the shape of the geometry
    # (rectangular) is actually inconsequential to the ALARA calculation so
    # unstructured meshes are not adversely affected.
    geometry = "geometry rectangular\n\n"

    # Create three strings in order to create all ALARA input blocks in a
    # single mesh iteration.
    volume = "volume\n"  # volume input block
    mat_loading = "mat_loading\n"  # material loading input block
    mixture = ""  # mixture blocks

    unique_mixtures = []
    if not sub_voxel:
        for i, mat, ve in mesh:
            volume += "    {0: 1.6E}    zone_{1}\n".format(
                mesh.elem_volume(ve), i)

            ve_mixture = {}
            for row in cell_fracs[cell_fracs["idx"] == i]:
                cell_mat = cell_mats[row["cell"]]
                name = cell_mat.metadata["name"]
                if _is_void(name):
                    name = "mat_void"
                if name not in ve_mixture.keys():
                    ve_mixture[name] = np.round(row["vol_frac"], sig_figs)
                else:
                    ve_mixture[name] += np.round(row["vol_frac"], sig_figs)

            if ve_mixture not in unique_mixtures:
                unique_mixtures.append(ve_mixture)
                mixture += "mixture mix_{0}\n".format(
                    unique_mixtures.index(ve_mixture))
                for key, value in ve_mixture.items():
                    mixture += "    material {0} 1 {1}\n".format(key, value)

                mixture += "end\n\n"

            mat_loading += "    zone_{0}    mix_{1}\n".format(
                i, unique_mixtures.index(ve_mixture))
    else:
        ves = list(mesh.iter_ve())
        sve_count = 0
        for row in cell_fracs:
            if len(cell_mats[row["cell"]].comp) != 0:
                volume += "    {0: 1.6E}    zone_{1}\n".format(
                    mesh.elem_volume(ves[row["idx"]]) * row["vol_frac"],
                    sve_count)
                cell_mat = cell_mats[row["cell"]]
                name = cell_mat.metadata["name"]
                if name not in unique_mixtures:
                    unique_mixtures.append(name)
                    mixture += "mixture {0}\n".format(name)
                    mixture += "    material {0} 1 1\n".format(name)
                    mixture += "end\n\n"
                mat_loading += "    zone_{0}    {1}\n".format(sve_count, name)
                sve_count += 1

    volume += "end\n\n"
    mat_loading += "end\n\n"

    with open(geom_file, "w") as f:
        f.write(geometry + volume + mat_loading + mixture)

    matlib = ""  # ALARA material library string

    printed_mats = []
    print_void = False
    for mat in cell_mats.values():
        name = mat.metadata["name"]
        if _is_void(name):
            print_void = True
            continue
        if name not in printed_mats:
            printed_mats.append(name)
            matlib += "{0}    {1: 1.6E}    {2}\n".format(
                name, mat.density, len(mat.comp))
            for nuc, comp in mat.comp.items():
                matlib += "{0}    {1: 1.6E}    {2}\n".format(
                    alara(nuc), comp * 100.0, znum(nuc))
            matlib += "\n"

    if print_void:
        matlib += "# void material\nmat_void 0.0 1\nhe 1 2\n"

    with open(matlib_file, "w") as f:
        f.write(matlib)
예제 #7
0
def record_to_geom(mesh,
                   cell_fracs,
                   cell_mats,
                   geom_file,
                   matlib_file,
                   sig_figs=6):
    """This function preforms the same task as alara.mesh_to_geom, except the
    geometry is on the basis of the stuctured array output of
    dagmc.discretize_geom rather than a PyNE material object with materials.
    This allows for more efficient ALARA runs by minimizing the number of
    materials in the ALARA matlib. This is done by treating mixtures that are
    equal up to <sig_figs> digits to be the same mixture within ALARA.

    Parameters
    ----------
    mesh : PyNE Mesh object
        The Mesh object for which the geometry is discretized.
     cell_fracs : structured array
        The output from dagmc.discretize_geom(). A sorted, one dimensional
        array, each entry containing the following fields:

            :idx: int 
                The volume element index.
            :cell: int
                The geometry cell number.
            :vol_frac: float
                The volume fraction of the cell withing the mesh ve.
            :rel_error: float
                The relative error associated with the volume fraction.

     cell_mats : dict
        Maps geometry cell numbers to PyNE Material objects. Each PyNE material
        object must have the 'mat_number' in Material.metadata.
    geom_file : str
        The name of the file to print the geometry and material blocks.
    matlib_file : str
        The name of the file to print the matlib.
    sig_figs : int
        The number of significant figures that two mixtures must have in common
        to be treated as the same mixture within ALARA.
    """
    # Create geometry information header. Note that the shape of the geometry
    # (rectangular) is actually inconsequential to the ALARA calculation so
    # unstructured meshes are not adversely affected.
    geometry = "geometry rectangular\n\n"

    # Create three strings in order to create all ALARA input blocks in a
    # single mesh iteration.
    volume = "volume\n"  # volume input block
    mat_loading = "mat_loading\n"  # material loading input block
    mixture = ""  # mixture blocks

    unique_mixtures = []
    for i, mat, ve in mesh:
        volume += "    {0: 1.6E}    zone_{1}\n".format(mesh.elem_volume(ve), i)

        ve_mixture = {}
        for row in cell_fracs[cell_fracs['idx'] == i]:
            if cell_mats[row['cell']].metadata['mat_number'] \
                not in ve_mixture.keys():
                ve_mixture[cell_mats[row['cell']].metadata['mat_number']] = \
                    round(row['vol_frac'], sig_figs)
            else:
                ve_mixture[cell_mats[row['cell']].metadata['mat_number']] += \
                    round(row['vol_frac'], sig_figs)

        if ve_mixture not in unique_mixtures:
            unique_mixtures.append(ve_mixture)
            mixture += "mixture mix_{0}\n".format(
                unique_mixtures.index(ve_mixture))
            for key, value in ve_mixture.items():
                mixture += "    material mat_{0} 1 {1}\n".format(key, value)

            mixture += "end\n\n"

        mat_loading += "    zone_{0}    mix_{1}\n".format(
            i, unique_mixtures.index(ve_mixture))

    volume += "end\n\n"
    mat_loading += "end\n\n"

    with open(geom_file, 'w') as f:
        f.write(geometry + volume + mat_loading + mixture)

    matlib = ""  # ALARA material library string

    printed_mats = []
    for mat in cell_mats.values():
        mat_num = mat.metadata['mat_number']
        if mat_num not in printed_mats:
            printed_mats.append(mat_num)
            matlib += "mat_{0}    {1: 1.6E}    {2}\n".format(
                mat.metadata['mat_number'], mat.density, len(mat.comp))
            for nuc, comp in mat.comp.iteritems():
                matlib += "{0}    {1: 1.6E}    {2}\n".format(
                    alara(nuc), comp * 100.0, znum(nuc))
            matlib += "\n"

    with open(matlib_file, 'w') as f:
        f.write(matlib)