Esempio n. 1
0
def get_sigma_f_n(iso):
    """Grabs an isotope's fission cross-section from the nuc_data library.

    Args:
        * iso (zzaaam): Isotope name, in appropriate form.

    Returns:
        * sigma_f_n (numpy array): This isotope's fission cross-section pulled from the
          database library file.  If not present in the library, a zero-array is returned.
    """
    with tb.openFile(nuc_data, 'r') as f:
        N = f.root.neutron.xs_mg.fission.coldescrs['xs'].shape[0]
        rows = [np.array(row['xs']) for row in f.root.neutron.xs_mg.fission.where('iso_zz == {0}'.format(iso))]

    if len(rows) == 0:
        # Not fissionable, return zero-array
        sigma_f_n = np.zeros(N, dtype=float)
    elif len(rows) == 1:
        # Return cross-section from file
        sigma_f_n = rows[0]
    else:
        iso_LL = isoname.zzaaam_2_LLAAAM(iso)
        err_str = "The database contains multiple entries for the fission cross-section for {0}!".format(iso_LL)
        raise ValueError(err_str)

    return sigma_f_n
Esempio n. 2
0
def write_H5(h5name = "reactor.h5"):		
	"Writes the reactor to an HDF5 File"

	libfile = tables.openFile(h5name, mode = "w", title = '{0} One Group Library'.format(Reactor))
	lbr = libfile.root

	libfile.createArray(lbr, "Fluence", F, "Time Integrated Flux [n/kb]") 	

	FromIso = [] 
	ToIso = [] 

	#Create Groups
	libfile.createGroup(lbr, "Burnup")
	libfile.createGroup(lbr, "Production")
	libfile.createGroup(lbr, "Destruction")
	libfile.createGroup(lbr, "Transmutation")

	#Fill Groups
	for iso in BUi_F_.keys():
		iso_LL =  isoname.zzaaam_2_LLAAAM(int(iso))
		libfile.createArray("/Burnup", iso_LL, BUi_F_[iso], "Burnup BU(F) for {0} [MWd/kgIHM]".format(iso_LL)) 	
		FromIso.append(iso_LL)

	for iso in pi_F_.keys():
		iso_LL =  isoname.zzaaam_2_LLAAAM(int(iso))
		libfile.createArray("/Production", iso_LL, pi_F_[iso], "Neutron Production Rate p(F) for {0}".format(iso_LL)) 	

	for iso in di_F_.keys():
		iso_LL =  isoname.zzaaam_2_LLAAAM(int(iso))
		libfile.createArray("/Destruction", iso_LL, di_F_[iso], "Neutron Destruction Rate d(F) for {0}".format(iso_LL)) 	

	for i in Tij_F_.keys():
		i_LL =  isoname.zzaaam_2_LLAAAM(int(i))
		libfile.createGroup("/Transmutation", i_LL)
		for j in Tij_F_[i].keys():
			j_LL =  isoname.zzaaam_2_LLAAAM(int(j))
			libfile.createArray("/Transmutation/" + i_LL, j_LL, Tij_F_[i][j], "Transmutation Matrix T(F) from {0} to {1}".format(i_LL, j_LL)) 	
			if int(i) == 922350:
				ToIso.append(j_LL)

	libfile.createArray(lbr, "FromIso_LL", FromIso, "Initial Loading Nuclide List (LL)")
	libfile.createArray(lbr, "FromIso_zz", isoname.LLAAAM_2_zzaaam_List(FromIso), "Initial Loading Nuclide List (zz)")
	libfile.createArray(lbr, "ToIso_LL",   ToIso,   "Transmutation Nuclide List (LL)")
	libfile.createArray(lbr, "ToIso_zz",   isoname.LLAAAM_2_zzaaam_List(ToIso),   "Transmutation Nuclide List (zz)")

	libfile.close()
	return
Esempio n. 3
0
def _grab_photon_fp_info(raw_data):
    """Grabs the photon fission product info.

    Args:
        * raw_data (str): string of the cinder.dat data file.

    Returns:
        * info_table (list of tuples): elements are tuples that have the form 
          "(index, iso_LL, iso_zz, type, mass)". 
    """
    # Get group sizes
    N_n, N_g = _get_fp_sizes(raw_data)

    # Grab the part of the file that is a neutron fission product yield info
    m_info = re.search(gfp_info_pattern, raw_data, re.DOTALL)
    gfp_info_raw = m_info.group(0)

    # Grab the index, isotope, and type
    iits = re.findall(iit_pattern, gfp_info_raw)

    # Grab the masses 
    masses = re.findall(mass_pattern, gfp_info_raw)

    # Make sure data is the right size
    assert N_g == len(iits) 
    assert N_g == len(masses)

    # Make info table rows 
    info_table = []
    for m in range(N_g):
        iit = iits[m]
        index = int(iit[0])

        iso_zz = isoname.LLAAAM_2_zzaaam(iit[1])
        # Correct for metastable flag
        if 0 != iso_zz%10:
            iso_zz = iso_zz + 2000

        iso_LL = isoname.zzaaam_2_LLAAAM(iso_zz)
        type = fp_type_flag[iit[2]]
        mass = float(masses[m])

        info_row = (index, iso_LL, iso_zz, type, mass)
        info_table.append(info_row)

    return info_table
Esempio n. 4
0
 def test_zzaaam_2_LLAAAM(self):
     assert_equal(isoname.zzaaam_2_LLAAAM(942390), "PU239")
     assert_equal(isoname.zzaaam_2_LLAAAM(952421), "AM242M")
Esempio n. 5
0
def make_neutron_fp_yields(h5_file='nuc_data.h5', data_file='cinder.dat'):
    """Adds the neutron fission product yields to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_file (str): path to the cinder.dat data file.
    """
    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Ensure that the appropriate file structure is present
    _init_fission_products(kdb)

    # Read in cinder data file
    with open(data_file, 'r') as f:
        raw_data = f.read()

    # Get group sizes
    N_n, N_g = _get_fp_sizes(raw_data)

    # get the info table
    info_table = _grab_neutron_fp_info(raw_data)

    # Grab the part of the file that is a neutron fission product yields
    m_yields = re.search(nfp_yields_pattern, raw_data, re.DOTALL)
    nfp_yields_raw = m_yields.group(0)

    # Init the neutron fission product info table
    nfp_table = kdb.createTable('/neutron/fission_products/', 'yields', fp_yields_desc, 
                                'Neutron Fission Product Yields')
    nfprow = nfp_table.row

    # Iterate over all to-isos
    fp_to_iso_pattern = fp_to_iso_base + N_n*fp_to_iso_insert + ")"
    for m_to in re.finditer(fp_to_iso_pattern, nfp_yields_raw):
        to_iso_zz = cinder_2_zzaaam(m_to.group(2))

        # Check matestable state
        if 1 < to_iso_zz%10:
            # Metastable state too high!
            continue
        to_iso_LL = isoname.zzaaam_2_LLAAAM(to_iso_zz)

        # Get the array of yield data
        yields = np.array(m_to.group(3).split(), dtype=float)
        assert len(yields) == N_n

        # Prep rows to the table
        for n in range(N_n):
            info = info_table[n]

            nfprow['index'] = info[0]
            nfprow['from_iso_LL'] = info[1]
            nfprow['from_iso_zz'] = info[2]
            nfprow['to_iso_LL'] = to_iso_LL
            nfprow['to_iso_zz'] = to_iso_zz
            nfprow['mass_frac'] = yields[n]

            nfprow.append()

        # Write the table
        nfp_table.flush()

    # Close the hdf5 file
    kdb.close()
Esempio n. 6
0
def make_mg_gamma_decay(h5_file='nuc_data.h5', data_file='cinder.dat'):
    """Adds the gamma decay spectrum information to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_file (str): path to the cinder.dat data file.
    """
    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Ensure that the appropriate file structure is present
    _init_multigroup(kdb)

    # Read in cinder data file
    with open(data_file, 'r') as f:
        raw_data = f.read()

    # Get group sizes
    nuclides, G_n, G_p, G_g = _get_groups_sizes(raw_data)

    # Init the gamma absorption table
    gamma_decay_desc['spectrum'] = tb.Float64Col(shape=(G_g, ), pos=4)
    gamma_decay_table = kdb.createTable('/photon/source/', 'decay_spectra', gamma_decay_desc, 
                                        'Gamma decay spectrum [MeV]')
    gdrow = gamma_decay_table.row

    # Init to_iso_pattern
    gamma_decay_pattern = gamma_decay_base + ("\s+("+cinder_float+")")*G_g

    # Iterate through all from isotopes.
    for m_from in re.finditer(from_iso_pattern, raw_data, re.DOTALL):
        from_iso_zz = cinder_2_zzaaam(m_from.group(1))

        # Check matestable state
        if 1 < from_iso_zz%10:
            # Metastable state too high!
            continue
        from_iso_LL = isoname.zzaaam_2_LLAAAM(from_iso_zz)

        # Grab the string for this from_iso in order to get all of the to_isos
        from_iso_part = m_from.group(0)

        # Grab the fission part
        m_gd = re.search(gamma_decay_pattern, from_iso_part)
        if m_gd is None:
            continue

        # Grab base data
        scale = float(m_gd.group(1))
        energy = float(m_gd.group(2))

        # Grab spectrum
        spectrum = np.array(m_gd.groups()[2:], dtype=float)
        assert spectrum.shape == (G_g, )

        # Prepare the row
        gdrow['iso_LL'] = from_iso_LL
        gdrow['iso_zz'] = from_iso_zz

        gdrow['energy'] = energy
        gdrow['scaling_factor'] = scale

        gdrow['spectrum'] = spectrum

        # Write out the row
        gdrow.append()
        gamma_decay_table.flush()

    # Close the hdf5 file
    kdb.close()
Esempio n. 7
0
def make_mg_fission(h5_file='nuc_data.h5', data_file='cinder.dat'):
    """Adds the fission reaction rate cross sections to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_file (str): path to the cinder.dat data file.
    """
    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Ensure that the appropriate file structure is present
    _init_multigroup(kdb)

    # Read in cinder data file
    with open(data_file, 'r') as f:
        raw_data = f.read()

    # Get group sizes
    nuclides, G_n, G_p, G_g = _get_groups_sizes(raw_data)

    # Init the neutron absorption table
    fission_desc['xs'] = tb.Float64Col(shape=(G_n, ), pos=5)
    fission_table = kdb.createTable('/neutron/xs_mg/', 'fission', fission_desc, 
                                    'Neutron fission reaction rate cross sections [barns]')
    frow = fission_table.row

    # Init to_iso_pattern
    fission_pattern = fission_base + ("\s+("+cinder_float+")")*G_n

    # Iterate through all from isotopes.
    for m_from in re.finditer(from_iso_pattern, raw_data, re.DOTALL):
        from_iso_zz = cinder_2_zzaaam(m_from.group(1))

        # Check matestable state
        if 1 < from_iso_zz%10:
            # Metastable state too high!
            continue
        from_iso_LL = isoname.zzaaam_2_LLAAAM(from_iso_zz)

        # Grab the string for this from_iso in order to get all of the to_isos
        from_iso_part = m_from.group(0)

        # Grab the fission part
        m_fission = re.search(fission_pattern, from_iso_part)
        if m_fission is None:
            continue

        # Grab yield indexes
        yield_t = int(m_fission.group(1))
        yield_f = int(m_fission.group(2))
        yield_h = int(m_fission.group(3))

        # Grab XS array
        xs = np.array(m_fission.groups()[3:], dtype=float)
        assert xs.shape == (G_n, )

        # Write fission table row
        frow['iso_LL'] = from_iso_LL
        frow['iso_zz'] = from_iso_zz

        frow['thermal_yield']     = yield_t
        frow['fast_yield']        = yield_f
        frow['high_energy_yield'] = yield_h

        frow['xs'] = xs

        # Write out this row
        frow.append()
        fission_table.flush()

    # Close the hdf5 file
    kdb.close()
Esempio n. 8
0
def make_mg_absorption(h5_file='nuc_data.h5', data_file='cinder.dat'):
    """Adds the absorption reaction rate cross sections to the hdf5 library.

    Keyword Args:
        * h5_file (str): path to hdf5 file.
        * data_file (str): path to the cinder.dat data file.
    """
    # Open the HDF5 File
    kdb = tb.openFile(h5_file, 'a')

    # Ensure that the appropriate file structure is present
    _init_multigroup(kdb)

    # Read in cinder data file
    with open(data_file, 'r') as f:
        raw_data = f.read()

    # Get group sizes
    nuclides, G_n, G_p, G_g = _get_groups_sizes(raw_data)

    # Init the neutron absorption table
    absorption_desc['xs'] = tb.Float64Col(shape=(G_n, ), pos=5)
    absorption_table = kdb.createTable('/neutron/xs_mg/', 'absorption', absorption_desc, 
                                       'Neutron absorption reaction rate cross sections [barns]')
    abrow = absorption_table.row

    # Init to_iso_pattern
    to_iso_pattern = to_iso_base + ("\s+("+cinder_float+")")*G_n

    # Iterate through all from isotopes.
    for m_from in re.finditer(from_iso_pattern, raw_data, re.DOTALL):
        from_iso_zz = cinder_2_zzaaam(m_from.group(1))

        # Check matestable state
        if 1 < from_iso_zz%10:
            # Metastable state too high!
            continue
        from_iso_LL = isoname.zzaaam_2_LLAAAM(from_iso_zz)

        # Grab the string for this from_iso in order to get all of the to_isos
        from_iso_part = m_from.group(0)

        # Iterate over all to_isos
        for m_to in re.finditer(to_iso_pattern, from_iso_part):
            to_iso_zz = cinder_2_zzaaam(m_to.group(1))

            # Check matestable state
            if 1 < to_iso_zz%10:
                # Metastable state too high!
                continue
            to_iso_LL = isoname.zzaaam_2_LLAAAM(to_iso_zz)

            # Munge reaction type
            rx_type = m_to.group(2)
            rx_type = rx_type.strip()

            # Setup XS array
            xs = np.array(m_to.groups()[2:], dtype=float)
            assert xs.shape == (G_n, )

            # Write this row to the absorption table
            abrow['from_iso_LL'] = from_iso_LL
            abrow['from_iso_zz'] = from_iso_zz

            abrow['to_iso_LL'] = to_iso_LL
            abrow['to_iso_zz'] = to_iso_zz

            abrow['reaction_type'] = rx_type
            abrow['xs'] = xs

            abrow.append()

        # Flush this from iso
        absorption_table.flush()

    # Close the hdf5 file
    kdb.close()
def calc_diff(r, n, name=""):
    print "Summary for {0}:".format(name)
    print "Reactor: "
    print repr(r)
    print "NEA: "
    print repr(n)
    print "Fractional Diff: "
    diff = 1.0 - r / n
    print repr(diff)
    print
    return r, n, diff


if __name__ == "__main__":
    raise SystemExit("NEA test cas currently broken... use test_reactormg_regression.py instead.")

    rmg, ms_nea = test_regression()

    r_BU, n_BU, diff_BU = calc_diff(rmg.BUd, 40.0, "Burnup")

    rmg_comp = rmg.mat_prod.mult_by_mass()
    nea_comp = ms_nea.mult_by_mass()

    for key in nea_comp.keys():
        if key in rmg_comp:
            r_, n_, diff_ = calc_diff(rmg_comp[key], nea_comp[key], "Mass of " + isoname.zzaaam_2_LLAAAM(key))

    mss = [MassStream({i: T_it[i][t] for i in T_it.keys()}) for t in range(len(rmg.burn_times))]
    masses = r_mass, s_mass, diff_mass = calc_diff(np.array([ms.mass for ms in mss]), 1.0, "Mass")