Esempio n. 1
0
def convert_to_serpent_tra(isoname, lib_temp):
    metastable_flag = 0
    if isoname[-2] == 'm':
        new_isoname = isoname[:-1]
        if int(isoname[-1]) == 1:
            serpent_name = nucname.serpent(new_isoname) + lib_temp
            metastable_flag = 1
        else:
            metastable_flag = int(isoname[-1])
    else:
        serpent_name = nucname.serpent(isoname) + lib_temp
    return serpent_name, metastable_flag
Esempio n. 2
0
def _mat_to_nucs(mat):
    nucs = []
    template = '<nuclide name="{nuc}" wo="{mass}" />'
    for nuc, mass in mat.comp.items():
        nucs.append(template.format(nuc=nucname.serpent(nuc), mass=mass*100))
    nucs = "\n    ".join(nucs)
    return nucs
Esempio n. 3
0
def test_serpent():
    assert_equal(nucname.serpent(942390), "Pu-239")
    assert_equal(nucname.serpent(952421), "Am-242m")

    assert_equal(nucname.serpent("Pu-239"), "Pu-239")

    assert_equal(nucname.serpent(94239), "Pu-239")
    assert_equal(nucname.serpent(95642), "Am-242")
    assert_equal(nucname.serpent(95242), "Am-242m")
    assert_equal(nucname.serpent(92636), "U-236m")

    assert_equal(nucname.serpent(2390940), "Pu-239")
    assert_equal(nucname.serpent(2420951), "Am-242m")
Esempio n. 4
0
def test_serpent():
    assert_equal(nucname.serpent(942390), "Pu-239")
    assert_equal(nucname.serpent(952421), "Am-242m")

    assert_equal(nucname.serpent("Pu-239"), "Pu-239")

    assert_equal(nucname.serpent(94239), "Pu-239")
    assert_equal(nucname.serpent(95642), "Am-242")
    assert_equal(nucname.serpent(95242), "Am-242m")
    assert_equal(nucname.serpent(92636), "U-236m")

    assert_equal(nucname.serpent(2390940), "Pu-239")
    assert_equal(nucname.serpent(2420951), "Am-242m")
Esempio n. 5
0
def photon_source_hdf5_to_mesh(mesh, filename, tags):
    """This function reads in an hdf5 file produced by photon_source_to_hdf5
    and tags the requested data to the mesh of a PyNE Mesh object. Any
    combinations of nuclides and decay times are allowed. The photon source
    file is assumed to be in mesh.__iter__() order

    Parameters
    ----------
    mesh : PyNE Mesh
       The object containing the imesh instance to be tagged.
    filename : str
        The path of the hdf5 version of the photon source file.
    tags: dict
        A dictionary were the keys are tuples with two values. The first is a
        string denoting an nuclide in any form that is understood by
        pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all
        nuclides. The second is a string denoting the decay time as it appears
        in the file (e.g. 'shutdown', '1 h' '3 d'). The values of the
        dictionary are the requested tag names for the combination of nuclide
        and decay time. For example if one wanted tags for the photon source
        densities from U235 at shutdown and from all nuclides at 1 hour, the
        dictionary could be:

        tags = {('U-235', 'shutdown') : 'tag1', ('TOTAL', '1 h') : 'tag2'}
    """
    # find number of energy groups
    with tb.openFile(filename) as h5f:
        num_e_groups = len(h5f.root.data[0][3])

    # create a dict of tag handles for all keys of the tags dict
    tag_handles = {}
    for tag_name in tags.values():
        tag_handles[tag_name] = \
            mesh.mesh.createTag(tag_name, num_e_groups, float)

    # iterate through each requested nuclide/dectay time
    for cond in tags.keys():
        with tb.openFile(filename) as h5f:
            # Convert nuclide to the form found in the ALARA phtn_src
            # file, which is similar to the Serpent form. Note this form is
            # different from the ALARA input nuclide form found in nucname.
            if cond[0] != "TOTAL":
                nuc = serpent(cond[0]).lower()
            else:
                nuc = "TOTAL"
            # create of array of rows that match the nuclide/decay criteria
            matched_data = h5f.root.data.readWhere(
                "(nuc == '{0}') & (time == '{1}')".format(nuc, cond[1]))

        idx = 0
        for i, _, ve in mesh:
            if matched_data[idx][0] == i:
                tag_handles[tags[cond]][ve] = matched_data[idx][3]
                idx += 1
            else:
                tag_handles[tags[cond]][ve] = [0] * num_e_groups
Esempio n. 6
0
def photon_source_hdf5_to_mesh(mesh, filename, tags):
    """This function reads in an hdf5 file produced by photon_source_to_hdf5
    and tags the requested data to the mesh of a PyNE Mesh object. Any
    combinations of nuclides and decay times are allowed. The photon source
    file is assumed to be in mesh.__iter__() order

    Parameters
    ----------
    mesh : PyNE Mesh
       The object containing the imesh instance to be tagged.
    filename : str
        The path of the hdf5 version of the photon source file.
    tags: dict
        A dictionary were the keys are tuples with two values. The first is a
        string denoting an nuclide in any form that is understood by
        pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all
        nuclides. The second is a string denoting the decay time as it appears
        in the file (e.g. 'shutdown', '1 h' '3 d'). The values of the
        dictionary are the requested tag names for the combination of nuclide
        and decay time. For example if one wanted tags for the photon source
        densities from U235 at shutdown and from all nuclides at 1 hour, the
        dictionary could be:

        tags = {('U-235', 'shutdown') : 'tag1', ('TOTAL', '1 h') : 'tag2'}
    """
    # find number of energy groups
    with tb.openFile(filename) as h5f:
        num_e_groups = len(h5f.root.data[0][3])

    # create a dict of tag handles for all keys of the tags dict
    tag_handles = {}
    for tag_name in tags.values():
        tag_handles[tag_name] = \
            mesh.mesh.createTag(tag_name, num_e_groups, float)

    # iterate through each requested nuclide/dectay time
    for cond in tags.keys():
        with tb.openFile(filename) as h5f:
            # Convert nuclide to the form found in the ALARA phtn_src
            # file, which is similar to the Serpent form. Note this form is
            # different from the ALARA input nuclide form found in nucname.
            if cond[0] != "TOTAL":
                nuc = serpent(cond[0]).lower()
            else:
                nuc = "TOTAL"
            # create of array of rows that match the nuclide/decay criteria
            matched_data = h5f.root.data.readWhere(
                "(nuc == '{0}') & (time == '{1}')".format(nuc, cond[1]))

        idx = 0
        for i, _, ve in mesh:
            if matched_data[idx][0] == i:
                tag_handles[tags[cond]][ve] = matched_data[idx][3]
                idx += 1
            else:
                tag_handles[tags[cond]][ve] = [0] * num_e_groups
Esempio n. 7
0
def _mat_to_nucs(mat):
    """Convert a ``pyne.material.Material`` into OpenMC ``materials.xml`` format.

    Parameters
    ----------
    mat : ``pyne.material.Material``
        Material to convert.

    Returns
    -------
    nucs : string
        OpenMC-friendly XML tag with material composition.
    """
    nucs = []
    template = '<nuclide name="{nuc}" wo="{mass}" />'
    for nuc, mass in mat.comp.items():
        nucs.append(template.format(nuc=nucname.serpent(nuc), mass=mass*100))
    nucs = "\n    ".join(nucs)
    return nucs
Esempio n. 8
0
 def _make_omc_input(self, state):
     pwd = self.pwd(state)
     ctx = self.context(state)
     rc = self.rc
     # settings
     settings = SETTINGS_TEMPLATE.format(**ctx)
     with open(os.path.join(pwd, 'settings.xml'), 'w') as f:
         f.write(settings)
     # materials
     valid_nucs = self.nucs_in_cross_sections()
     core_nucs = set(ctx['core_transmute'])
     ctx['_fuel_nucs'] = _mat_to_nucs(rc.fuel_material[valid_nucs])
     ctx['_clad_nucs'] = _mat_to_nucs(rc.clad_material[valid_nucs])
     ctx['_cool_nucs'] = _mat_to_nucs(rc.cool_material[valid_nucs])
     materials = MATERIALS_TEMPLATE.format(**ctx)
     with open(os.path.join(pwd, 'materials.xml'), 'w') as f:
         f.write(materials)
     # geometry
     ctx['lattice'] = ctx['lattice'].strip().replace('\n', '\n      ')
     ctx['_latt_shape0'] = ctx['lattice_shape'][0]
     ctx['_latt_shape1'] = ctx['lattice_shape'][1]
     ctx['_latt_x_pitch'] = ctx['unit_cell_pitch'] * ctx['lattice_shape'][0]
     ctx['_latt_y_pitch'] = ctx['unit_cell_pitch'] * ctx['lattice_shape'][1]
     ctx['_latt_x_half_pitch'] = ctx['_latt_x_pitch'] / 2.0
     ctx['_latt_y_half_pitch'] = ctx['_latt_y_pitch'] / 2.0
     geometry = GEOMETRY_TEMPLATE.format(**ctx)
     with open(os.path.join(pwd, 'geometry.xml'), 'w') as f:
         f.write(geometry)
     # tallies
     ctx['_egrid'] = " ".join(map(str, sorted(ctx['group_structure'])))
     ctx['_cds_egrid'] = " ".join(map(str, sorted(self.cinderds.src_group_struct)))
     ctx['_eafds_egrid'] = " ".join(map(str, sorted(self.eafds.src_group_struct)))
     ctx['_omcds_egrid'] = " ".join(map(str, sorted(self.omcds.src_group_struct)))
     nucs = core_nucs & valid_nucs
     ctx['_nucs'] = " ".join([nucname.serpent(nuc) for nuc in sorted(nucs)])
     tallies = TALLIES_TEMPLATE.format(**ctx)
     with open(os.path.join(pwd, 'tallies.xml'), 'w') as f:
         f.write(tallies)
     # plots
     plots = PLOTS_TEMPLATE.format(**ctx)
     with open(os.path.join(pwd, 'plots.xml'), 'w') as f:
         f.write(plots)
Esempio n. 9
0
    def rem_elements(self, inflow):
        """Updates Materialflow object `inflow` after removal target isotopes
        with specific efficiency in single component of fuel reprocessing
        system and returns waste stream Materialflow object.

        Parameters
        ----------
        inflow : Materialflow obj
            Target material stream to remove poisons from.

        Returns
        -------
        Materialflow object
            Waste stream from the reprocessing system component.

        """
        waste_nucvec = {}
        out_nucvec = {}
        # print("Xe concentration in inflow before % f g" % inflow['Xe136'])
        # print("Current time %f" % (t))
        for iso in inflow.comp.keys():
            el_name = pyname.serpent(iso).split('-')[0]
            if el_name in self.efficiency:
                # Evaluate removal efficiency for el_name (float)
                self.efficiency[el_name] = self.calc_rem_efficiency(el_name)
                out_nucvec[iso] = \
                    float(inflow.comp[iso]) * \
                    float(1.0 - self.efficiency[el_name])
                waste_nucvec[iso] = \
                    float(inflow[iso]) * self.efficiency[el_name]
            else:
                out_nucvec[iso] = float(inflow.comp[iso])
                waste_nucvec[iso] = 0.0  # zeroes everywhere else
        waste = Materialflow(waste_nucvec)
        inflow.mass = float(inflow.mass - waste.mass)
        inflow.comp = out_nucvec
        inflow.norm_comp()
        print("Xe concentration in inflow after %f g" % inflow['Xe136'])
        print("Waste mass %f g\n" % waste.mass)
        del out_nucvec, waste_nucvec, el_name
        return waste
Esempio n. 10
0
burnup_plot = False
calculate_post_burnup = False
find_mix = True

isotopes = [
    '922330', '922340', '922350', '922360', '922370', '922380', '922390',
    '932340', '932350', '932360', '932370', '932380', '932390', '932400',
    '942350', '942360', '942370', '942380', '942390', '942400', '942410',
    '942420', '942430', '952400', '952410', '952420', '952421', '952430',
    '952440', '962420', '962430', '962440', '962450'
]
# 92 U, 93 Np, 94 Pu, 95 Am, 96 Cm
iso_names = []
for i, iso in enumerate(isotopes):
    try:
        iso_names.append(nucname.serpent(iso))
    except:
        iso_names.append(iso)
iso_names.append('Lumped-Act.')
iso_names.append('FPs')

conc = np.zeros(len(isotopes) + 2)
conc[2] = 0.05
conc[5] = 0.95

nat_conc = copy.deepcopy(conc)
nat_conc[2] = 0.00711  # Weight percent
nat_conc[5] = (1 - 0.00711)

years = 50 / (35 * 1e-6 *
              1e3) / 365.25  # MWd/kg / W/g * MW/W * g/kg / days/year
Esempio n. 11
0
def response_hdf5_to_mesh(mesh, filename, tags, response):
    """This function reads in an hdf5 file produced by response_to_hdf5
    and tags the requested data to the mesh of a PyNE Mesh object. Any
    combinations of nuclides and decay times are allowed. The photon source
    file is assumed to be in mesh.__iter__() order

    Parameters
    ----------
    mesh : PyNE Mesh
       The object containing the PyMOAB instance to be tagged.
    filename : str
        The path of the hdf5 version of the response file.
    tags: dict
        A dictionary were the keys are tuples with two values. The first is a
        string denoting an nuclide in any form that is understood by
        pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all
        nuclides. The second is a string denoting the decay time as it appears
        in the file (e.g. 'shutdown', '1 h' '3 d'). The values of the
        dictionary are the requested tag names for the combination of nuclide
        and decay time. For example if one wanted tags for the photon source
        densities from U235 at shutdown and from all nuclides at 1 hour, the
        dictionary could be:

        tags = {('U-235', 'shutdown') : 'tag1', ('TOTAL', '1 h') : 'tag2'}
    response : str
        The keyword of the response. Supported responses:
            - decay_heat
            - specific_activity
            - alpha_heat
            - beta_heat
            - gamma_heat
            - wdr
            - photon_source
    """

    # create a dict of tag handles for all keys of the tags dict
    tag_handles = {}
    for tag_name in tags.values():

        mesh.tag(tag_name,
                 np.zeros(1, dtype=float),
                 "nat_mesh",
                 size=1,
                 dtype=float)
        tag_handles[tag_name] = mesh.get_tag(tag_name)

    decay_times = _read_h5_dt(filename)

    # iterate through each requested nuclide/dectay time
    for cond in tags.keys():
        with tb.open_file(filename) as h5f:
            # Convert nuclide to the form found in the ALARA response file
            # file, which is similar to the Serpent form. Note this form is
            # different from the ALARA input nuclide form found in nucname.
            if cond[0] != "TOTAL":
                nuc = serpent(cond[0]).lower()
            else:
                nuc = "TOTAL"

            # time match, convert string mathch to float mathch
            dt = _find_dt(cond[1], decay_times)
            # create of array of rows that match the nuclide/decay criteria
            matched_data = h5f.root.data.read_where(
                "(nuc == '{0}') & (time == '{1}')".format(nuc, dt))

        idx = 0
        # index, mat, volume element
        for i, _, ve in mesh:
            if matched_data[idx][0] == i:
                tag_handles[tags[cond]][ve] = matched_data[idx][3]
                idx += 1
            else:
                tag_handles[tags[cond]][ve] = [0]
Esempio n. 12
0
def photon_source_hdf5_to_mesh(mesh,
                               filename,
                               tags,
                               sub_voxel=False,
                               cell_mats=None):
    """This function reads in an hdf5 file produced by photon_source_to_hdf5
    and tags the requested data to the mesh of a PyNE Mesh object. Any
    combinations of nuclides and decay times are allowed. The photon source
    file is assumed to be in mesh.__iter__() order

    Parameters
    ----------
    mesh : PyNE Mesh
       The object containing the PyMOAB instance to be tagged.
    filename : str
        The path of the hdf5 version of the photon source file.
    tags: dict
        A dictionary were the keys are tuples with two values. The first is a
        string denoting an nuclide in any form that is understood by
        pyne.nucname (e.g. '1001', 'U-235', '242Am') or 'TOTAL' for all
        nuclides. The second is a string denoting the decay time as it appears
        in the file (e.g. 'shutdown', '1 h' '3 d'). The values of the
        dictionary are the requested tag names for the combination of nuclide
        and decay time. For example if one wanted tags for the photon source
        densities from U235 at shutdown and from all nuclides at 1 hour, the
        dictionary could be:

        tags = {('U-235', 'shutdown') : 'tag1', ('TOTAL', '1 h') : 'tag2'}
    sub_voxel: bool, optional
        If the sub_voxel is True, then the sub-voxel r2s will be used.
        Then the photon_source will be interpreted as sub-voxel photon source.
    cell_mats : dict, optional
        cell_mats is required when sub_voxel is True.
        Maps geometry cell numbers to PyNE Material objects.
    """

    # find number of energy groups
    with tb.open_file(filename) as h5f:
        num_e_groups = len(h5f.root.data[0][3])
    max_num_cells = 1
    ve0 = next(mesh.iter_ve())
    if sub_voxel:
        num_vol_elements = len(mesh)
        subvoxel_array = _get_subvoxel_array(mesh, cell_mats)
        # get max_num_cells
        max_num_cells = len(np.atleast_1d(mesh.cell_number[ve0]))

    # create a dict of tag handles for all keys of the tags dict
    tag_handles = {}
    tag_size = num_e_groups * max_num_cells
    for tag_name in tags.values():

        mesh.tag(
            tag_name,
            np.zeros(tag_size, dtype=float),
            "nat_mesh",
            size=tag_size,
            dtype=float,
        )
        tag_handles[tag_name] = mesh.get_tag(tag_name)

    decay_times = _read_h5_dt(filename)

    # iterate through each requested nuclide/dectay time
    for cond in tags.keys():
        with tb.open_file(filename) as h5f:
            # Convert nuclide to the form found in the ALARA phtn_src
            # file, which is similar to the Serpent form. Note this form is
            # different from the ALARA input nuclide form found in nucname.
            if cond[0] != "TOTAL":
                nuc = serpent(cond[0]).lower()
            else:
                nuc = "TOTAL"

            # time match, convert string mathch to float mathch
            dt = _find_dt(cond[1], decay_times)
            # create of array of rows that match the nuclide/decay criteria
            matched_data = h5f.root.data.read_where(
                "(nuc == '{0}') & (time == '{1}')".format(nuc, dt))

        if not sub_voxel:
            idx = 0
            for i, _, ve in mesh:
                if matched_data[idx][0] == i:
                    tag_handles[tags[cond]][ve] = matched_data[idx][3]
                    idx += 1
                else:
                    tag_handles[tags[cond]][ve] = [0] * num_e_groups
        else:
            temp_mesh_data = np.empty(shape=(num_vol_elements, max_num_cells,
                                             num_e_groups),
                                      dtype=float)
            temp_mesh_data.fill(0.0)
            for sve, subvoxel in enumerate(subvoxel_array):
                temp_mesh_data[subvoxel["idx"],
                               subvoxel["scid"], :] = matched_data[sve][3][:]
            for i, _, ve in mesh:
                tag_handles[tags[cond]][ve] = temp_mesh_data[i, :].reshape(
                    max_num_cells * num_e_groups)
Esempio n. 13
0
print(np.log(2)/data.decay_const('922340000')/3.15e7)

print('-------Np-239 to Pu-239 test--------')
print(data.decay_const('932390'))
print(data.decay_children('932390'))

print(data.decay_const('932390'))
print(data.decay_children('932390'))
print(data.branch_ratio(932390,942390))

print('-------U-240 decay test--------')
print(np.log(2)/data.decay_const('922400')/3600)
print(data.branch_ratio('922400','932400', use_metastable=False))

print('-----U234 Capture Test-----')
print(float('922350')-float('922340') == 10)

print('-----Mass Test-----')
print(nucname.anum('922350'))
print('-----Name Test-----')
print(nucname.serpent('922350'))

print('-------U-236 test--------')
print(data.decay_const('922360'))
print(data.half_life('922360')/(3.15e7))

print('-------Np-234 to U-234 test--------')
print(data.decay_const('932340'))
print(data.decay_children('932340'))
print(data.branch_ratio(932340,922340))