def make_libgroup_micro(nameoflib): libgroup = temp_libgroup(tempdata) openmclib = {} for tt in tempdata: for n in libgroup[tt]: scatter = np.zeros((len(ENERGIES) - 1, len(ENERGIES) - 1, 2), dtype=np.double) if (n in openmclib): openmclib[n].set_total(libgroup[tt][n].stot, temperature=tt) openmclib[n].set_absorption(libgroup[tt][n].sabs, temperature=tt) scatter += libgroup[tt][n].xsmatrix*1.0 openmclib[n].set_scatter_matrix(scatter, temperature=tt) openmclib[n].set_fission(libgroup[tt][n].sf, temperature=tt) openmclib[n].set_nu_fission(libgroup[tt][n].nusf, temperature=tt) openmclib[n].set_chi(libgroup[tt][n].schi, temperature=tt) else: openmclib[n] = openmc.XSdata(n, groups, temperatures=tempdata) if (libgroup[tt][n].xsmatrix.shape[-1] < 2): openmclib[n].order = 0 else: openmclib[n].order = 1 openmclib[n].order = 1 openmclib[n].set_total(libgroup[tt][n].stot, temperature=tt) openmclib[n].set_absorption(libgroup[tt][n].sabs, temperature=tt) scatter += libgroup[tt][n].xsmatrix*1.0 openmclib[n].set_scatter_matrix(scatter, temperature=tt) openmclib[n].set_fission(libgroup[tt][n].sf, temperature=tt) openmclib[n].set_nu_fission(libgroup[tt][n].nusf, temperature=tt) openmclib[n].set_chi(libgroup[tt][n].schi, temperature=tt) mg_cross_sections_file = openmc.MGXSLibrary(groups) mg_cross_sections_file.add_xsdatas([openmclib[o] for o in openmclib]) mg_cross_sections_file.export_to_hdf5(nameoflib)
def create_library(): # Instantiate the energy group data and file object groups = openmc.mgxs.EnergyGroups(group_edges=[0.0, 0.625, 20.0e6]) mg_cross_sections_file = openmc.MGXSLibrary(groups) # Make the base, isotropic data nu = [2.50, 2.50] fiss = np.array([0.002817, 0.097]) capture = [0.008708, 0.02518] absorption = np.add(capture, fiss) scatter = np.array([[[0.31980, 0.06694, 0.003], [0.004555, -0.0003972, 0.00002]], [[0.00000, 0.00000, 0.000], [0.424100, 0.05439000, 0.0025]]]) total = [0.33588, 0.54628] chi = [1., 0.] mat_1 = openmc.XSdata('mat_1', groups) mat_1.order = 2 mat_1.set_nu_fission(np.multiply(nu, fiss)) mat_1.set_absorption(absorption) mat_1.set_scatter_matrix(scatter) mat_1.set_total(total) mat_1.set_chi(chi) mg_cross_sections_file.add_xsdata(mat_1) # Write the file mg_cross_sections_file.export_to_hdf5('2g.h5')
def prepare_temperature_independed_mg(libgroup, conc, namenuclide, tempdata, groups, mattemp): """ Prepare multigroup data for calculation based with temperature independent constant Paramertres: ----------- libgroup : dictionary {temperature : dictonary { name of nuclide : element groupsection class }}; :param conc: dict - dictionary with name of material : np.array - R*8 concentration of nuclide; :param namenuclide: - a list of nuclide names; :param temperature: - dictionary with name of material : temperature value; :return: - dictionary with name of material : openmc.MGXS class element """ # TEMPERATURE INDEPENDET CASE openmclib = {} for name, val in conc.items(): openmclib[name] = openmc.XSdata(name, groups, temperatures=[tempdata[0]]) openmclib[name].order = 1 stot = np.zeros(len(ENERGIES) - 1, dtype=np.double) sabs = np.zeros(len(ENERGIES) - 1, dtype=np.double) scapt = np.zeros(len(ENERGIES) - 1, dtype=np.double) sf = np.zeros(len(ENERGIES) - 1, dtype=np.double) nusf = np.zeros(len(ENERGIES) - 1, dtype=np.double) chi = np.zeros(len(ENERGIES) - 1, dtype=np.double) scatter = np.zeros((len(ENERGIES) - 1, len(ENERGIES) - 1, 2), dtype=np.double) concentration = 0.0 for n, v in zip(namenuclide, val): for el in temp_interolate(tempdata, mattemp[name]): tt = el[0] wt = el[1] if (n in libgroup[tt].keys()): stot += libgroup[tt][n].stot * v * wt sabs += libgroup[tt][n].sabs * v * wt scapt += libgroup[tt][n].scapt * v * wt sf += libgroup[tt][n].sf * v * wt nusf += libgroup[tt][n].nusf * v * wt scatter += libgroup[tt][n].xsmatrix * v * wt if (n in libgroup[tempdata[0]].keys()): if (libgroup[tempdata[0]][n].sf.sum() > 0): concentration += v chi += libgroup[tempdata[0]][n].schi * v if (concentration > 0): chi = chi / concentration openmclib[name].set_total(stot, temperature=tempdata[0]) openmclib[name].set_absorption(sabs, temperature=tempdata[0]) openmclib[name].set_scatter_matrix(scatter, temperature=tempdata[0]) openmclib[name].set_fission(sf, temperature=tempdata[0]) openmclib[name].set_nu_fission(nusf, temperature=tempdata[0]) openmclib[name].set_chi(chi, temperature=tempdata[0]) return openmclib
def set_it(name, groups, order, fission, nu, absorption, scatt, total, chi): xsd = openmc.XSdata(name, groups) xsd.order = order if fission is not None: xsd.set_fission(fission[:]) if nu is not None and fission is not None: xsd.set_nu_fission(np.multiply(nu, fission)) xsd.set_absorption(absorption[:]) xsd.set_scatter_matrix(scatt[:, :, :]) xsd.set_total(total[:]) if chi is not None: xsd.set_chi(chi[:]) return xsd
def build_openmc_xs_lib(name, groups, temperatures, xsdict, micro=True): """Build an Openm XSdata based on dictionary values""" xsdata = openmc.XSdata(name, groups, temperatures=temperatures) xsdata.order = 0 for tt in temperatures: xsdata.set_absorption(xsdict[tt]['absorption'][name], temperature=tt) xsdata.set_scatter_matrix(xsdict[tt]['scatter'][name], temperature=tt) xsdata.set_total(xsdict[tt]['total'][name], temperature=tt) if (name in xsdict[tt]['nu-fission'].keys()): xsdata.set_nu_fission(xsdict[tt]['nu-fission'][name], temperature=tt) xsdata.set_chi(np.array([1., 0.]), temperature=tt) return xsdata
def build_mgxs_library(convert): # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups(group_edges=[1e-5, 0.625, 20.0e6]) # Instantiate the 2-group (C5G7) cross section data uo2_xsdata = openmc.XSdata('UO2', groups) uo2_xsdata.order = 2 uo2_xsdata.set_total([2., 2.]) uo2_xsdata.set_absorption([1., 1.]) scatter_matrix = np.array([[[0.75, 0.25], [0.00, 1.00]], [[0.75 / 3., 0.25 / 3.], [0.00 / 3., 1.00 / 3.]], [[0.75 / 4., 0.25 / 4.], [0.00 / 4., 1.00 / 4.]]]) scatter_matrix = np.rollaxis(scatter_matrix, 0, 3) uo2_xsdata.set_scatter_matrix(scatter_matrix) uo2_xsdata.set_fission([0.5, 0.5]) uo2_xsdata.set_nu_fission([1., 1.]) uo2_xsdata.set_chi([1., 0.]) mg_cross_sections_file = openmc.MGXSLibrary(groups) mg_cross_sections_file.add_xsdatas([uo2_xsdata]) if convert is not None: if isinstance(convert[0], list): for conv in convert: if conv[0] in ['legendre', 'tabular', 'histogram']: mg_cross_sections_file = \ mg_cross_sections_file.convert_scatter_format( conv[0], conv[1]) elif conv[0] in ['angle', 'isotropic']: mg_cross_sections_file = \ mg_cross_sections_file.convert_representation( conv[0], conv[1], conv[1]) elif convert[0] in ['legendre', 'tabular', 'histogram']: mg_cross_sections_file = \ mg_cross_sections_file.convert_scatter_format( convert[0], convert[1]) elif convert[0] in ['angle', 'isotropic']: mg_cross_sections_file = \ mg_cross_sections_file.convert_representation( convert[0], convert[1], convert[1]) mg_cross_sections_file.export_to_hdf5()
def create_library(): # Instantiate the energy group data and file object groups = openmc.mgxs.EnergyGroups(group_edges=[0.0, 0.625, 20.0e6]) mg_cross_sections_file = openmc.MGXSLibrary(groups, 6) # Make the base, isotropic data nu = np.array([2.50, 2.50]) fiss = np.array([0.002817, 0.097]) capture = np.array([0.008708, 0.02518]) absorption = capture + fiss scatter = np.array([[[0.31980, 0.06694], [0.004555, -0.0003972]], [[0.00000, 0.00000], [0.424100, 0.05439000]]]) total = np.array([0.33588, 0.54628]) chi = np.array([1., 0.]) decay_rate = np.array( [0.013336, 0.032739, 0.12078, 0.30278, 0.84949, 2.853]) delayed_yield = np.array([ 0.00055487, 0.00286407, 0.00273429, 0.0061305, 0.00251342, 0.00105286 ]) inv_vel = 1.0 / np.array([1.4e9, 4.4e5]) mat_1 = openmc.XSdata('mat_1', groups, num_delayed_groups=6) mat_1.order = 1 mat_1.set_fission(fiss) mat_1.set_kappa_fission(fiss * 200e6) mat_1.set_nu_fission(nu * fiss) mat_1.set_beta(delayed_yield / 2.5) mat_1.set_decay_rate(decay_rate) mat_1.set_absorption(absorption) mat_1.set_scatter_matrix(scatter) mat_1.set_total(total) mat_1.set_chi(chi) mat_1.set_inverse_velocity(inv_vel) mg_cross_sections_file.add_xsdata(mat_1) # Write the file mg_cross_sections_file.export_to_hdf5('2g.h5')
def _build_inputs(self): # Define materials water = openmc.Material(1) water.add_nuclide('H1', 2.0) water.add_nuclide('O16', 1.0) water.add_nuclide('B10', 0.0001) if self.is_ce: water.add_s_alpha_beta('c_H_in_H2O') water.set_density('g/cc', 1.0) fuel = openmc.Material(2) fuel.add_nuclide('U235', 1.0) fuel.add_nuclide('Mo99', 0.1) fuel.set_density('g/cc', 4.5) materials = openmc.Materials((water, fuel)) if not self.is_ce: materials.cross_sections = 'mg_lib.h5' materials.export_to_xml() cyl = openmc.ZCylinder(surface_id=1, r=1.0, boundary_type='vacuum') top_sphere = openmc.Sphere(surface_id=2, z0=5., r=1., boundary_type='vacuum') top_plane = openmc.ZPlane(surface_id=3, z0=5.) bottom_sphere = openmc.Sphere(surface_id=4, z0=-5., r=1., boundary_type='vacuum') bottom_plane = openmc.ZPlane(surface_id=5, z0=-5.) # Define geometry inside_cyl = openmc.Cell(1, fill=fuel, region=-cyl & -top_plane & +bottom_plane) top_hemisphere = openmc.Cell(2, fill=water, region=-top_sphere & +top_plane) bottom_hemisphere = openmc.Cell(3, fill=water, region=-bottom_sphere & -top_plane) root = openmc.Universe(0, cells=(inside_cyl, top_hemisphere, bottom_hemisphere)) geometry = openmc.Geometry(root) geometry.export_to_xml() # Set up stochastic volume calculation ll, ur = root.bounding_box vol_calcs = [ openmc.VolumeCalculation(list(root.cells.values()), 100000), openmc.VolumeCalculation([water, fuel], 100000, ll, ur), openmc.VolumeCalculation([root], 100000, ll, ur), openmc.VolumeCalculation(list(root.cells.values()), 100), openmc.VolumeCalculation([water, fuel], 100, ll, ur), openmc.VolumeCalculation(list(root.cells.values()), 100) ] vol_calcs[3].set_trigger(self.exp_std_dev, 'std_dev') vol_calcs[4].set_trigger(self.exp_rel_err, 'rel_err') vol_calcs[5].set_trigger(self.exp_variance, 'variance') # Define settings settings = openmc.Settings() settings.run_mode = 'volume' if not self.is_ce: settings.energy_mode = 'multi-group' settings.volume_calculations = vol_calcs settings.export_to_xml() # Create the MGXS file if necessary if not self.is_ce: groups = openmc.mgxs.EnergyGroups(group_edges=[0., 20.e6]) mg_xs_file = openmc.MGXSLibrary(groups) nu = [2.] fiss = [1.] capture = [1.] absorption_fissile = np.add(fiss, capture) absorption_other = capture scatter = np.array([[[1.]]]) total_fissile = np.add(absorption_fissile, np.sum(scatter[:, :, 0], axis=1)) total_other = np.add(absorption_other, np.sum(scatter[:, :, 0], axis=1)) chi = [1.] for iso in ['H1', 'O16', 'B10', 'Mo99', 'U235']: mat = openmc.XSdata(iso, groups) mat.order = 0 mat.atomic_weight_ratio = \ openmc.data.atomic_mass(iso) / openmc.data.NEUTRON_MASS mat.set_scatter_matrix(scatter) if iso == 'U235': mat.set_nu_fission(np.multiply(nu, fiss)) mat.set_absorption(absorption_fissile) mat.set_total(total_fissile) mat.set_chi(chi) else: mat.set_absorption(absorption_other) mat.set_total(total_other) mg_xs_file.add_xsdata(mat) mg_xs_file.export_to_hdf5('mg_lib.h5')
def prepare_mg(libgroup, conc, namenuclide, tempdata, groups, mattemp): """ Prepare multigroup data for calculation based with temperature independent constant Paramertres: ----------- libgroup : dictionary {temperature : dictonary { name of nuclide : element groupsection class }}; :param conc: dict - dictionary with name of material : np.array - R*8 concentration of nuclide; :param namenuclide: - a list of nuclide names; :param temperature: - dictionary with name of material : temperature value; :return: - dictionary with name of material : openmc.MGXS class element """ # TEMPERATURE INDEPENDET CASE openmclib = {} t0 = time.time() nsize = len([k for k in conc]) values = np.array([v for v in conc.values()]) values = values.reshape(nsize, len(values[0])) indices = nsize * [(tempdata[0], 1.0)] indarray=np.zeros((nsize, 2), dtype = np.int) wgtarray=np.zeros((nsize, 2), dtype = np.double) stot = np.zeros((nsize, len(ENERGIES) - 1), dtype=np.double) sabs = np.zeros((nsize,len(ENERGIES) - 1), dtype=np.double) scapt = np.zeros((nsize,len(ENERGIES) - 1), dtype=np.double) sf = np.zeros((nsize,len(ENERGIES) - 1), dtype=np.double) nusf = np.zeros((nsize,len(ENERGIES) - 1), dtype=np.double) chi = np.zeros((nsize,len(ENERGIES) - 1), dtype=np.double) scatter = np.zeros((nsize,len(ENERGIES) - 1, len(ENERGIES) - 1, 2), dtype=np.double) for i, name in enumerate(mattemp.keys()): openmclib[name] = openmc.XSdata(name, groups, temperatures=[tempdata[0]]) openmclib[name].order = 1 indices[i] = temp_interolate(tempdata, mattemp[name]) indarray[i, 0]= indices[i][0][0];indarray[i, 1]= indices[i][1][0] wgtarray[i, 0]= indices[i][0][1];wgtarray[i, 1]= indices[i][1][1] nuclind = np.zeros((len(namenuclide), len(tempdata)), dtype=np.int) for i, n in enumerate(namenuclide): for j, tt in enumerate(tempdata): if (n in libgroup[tt].keys()): nuclind[i][j] = i + 1 t1 = time.time() for i in range(nsize): for ind in range(len(namenuclide)): for j in [0, 1]: if (nuclind[ind][indarray[i, j]] > 0): stot[i, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].stot * values[i, ind] * wgtarray[i, j] sabs[i, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].sabs * values[i, ind] * wgtarray[i, j] scapt[i, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].scapt * values[i, ind] * wgtarray[i, j] sf[i, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].sf * values[i, ind] * wgtarray[i, j] nusf[i, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].nusf * values[i, ind] * wgtarray[i, j] scatter[i, :, :] += libgroup[tempdata[indarray[i, j]]][namenuclide[ind]].xsmatrix * values[i, ind] * wgtarray[i, j] concentration = 0.0 if (namenuclide[ind] in libgroup[tempdata[0]].keys()): if (libgroup[tempdata[0]][namenuclide[ind]].sf.sum() > 0): concentration += values[i, ind] chi[i, :] += libgroup[tempdata[0]][namenuclide[ind]].schi * values[i, ind] for i, name in enumerate(conc.keys()): openmclib[name]._total[0]=stot[i, :] openmclib[name]._absorption[0]=sabs[i, :] openmclib[name]._scatter_matrix[0]=scatter[i, :, :] openmclib[name]._fission[0]=sf[i, :] if (sum(sf[i, :]) > 0): openmclib[name]._fissionable = True openmclib[name]._nu_fission[0]=nusf[i, :] openmclib[name]._chi[0]=chi[i, :] return openmclib
L = 2.0 dx = L/nxbins dy = L/nybins dz = L/nzbins groups = openmc.mgxs.EnergyGroups(np.logspace(-5,7,3)) # Make all cross sections XSDATAS = [] for i in range(nxbins): for j in range(nybins): for k in range(nzbins): xsname = str(i)+"."+str(j)+"."+str(k) xs = openmc.XSdata(xsname, groups) xs.order = 0 # Get position at center x = i*dx + 0.5*dx y = j*dy + 0.5*dy z = k*dz + 0.5*dz # Get XS values Et = x + y + z + 1.0 Ec = 0.3*Et Es = 0.7*Et # assign XSs xs.set_total([Et,Et], temperature=294.) xs.set_absorption([Ec,Ec], temperature=294.) xs.set_nu_fission([0.0,0.0], temperature=294.) sct_matrx = [[[0.5*Es, 0.5*Es],
import openmc import openmc.mgxs import numpy as np ############################################################################### # Exporting to OpenMC mg_cross_sections.xml File ############################################################################### # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups(np.logspace(-11,1,8)) # Instantiate the 7-group C5G7 cross section data uo2_xsdata = openmc.XSdata('uo2.300k', groups) uo2_xsdata.order = 0 uo2_xsdata.total = np.array([1.779490E-01, 3.298050E-01, 4.803880E-01, 5.543670E-01, 3.118010E-01, 3.951680E-01, 5.644060E-01]) uo2_xsdata.absorption = np.array([8.02480E-03, 3.71740E-03, 2.67690E-02, 9.62360E-02, 3.00200E-02, 1.11260E-01, 2.82780E-01]) uo2_xsdata.scatter = np.array([[[1.275370E-01, 4.237800E-02, 9.437400E-06, 5.516300E-09, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 3.244560E-01, 1.631400E-03, 3.142700E-09, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 4.509400E-01, 2.679200E-03, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 0.000000E-00, 4.525650E-01, 5.566400E-03, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 0.000000E-00, 1.252500E-04, 2.714010E-01, 1.025500E-02, 1.002100E-08], [0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 1.296800E-03, 2.658020E-01, 1.680900E-02], [0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 8.545800E-03, 2.730800E-01]]]) uo2_xsdata.fission = np.array([7.212060E-03, 8.193010E-04, 6.453200E-03, 1.856480E-02, 1.780840E-02, 8.303480E-02, 2.160040E-01]) uo2_xsdata.nu_fission = np.array([2.005998E-02, 2.027303E-03, 1.570599E-02, 4.518301E-02, 4.334208E-02, 2.020901E-01, 5.257105E-01]) uo2_xsdata.chi = np.array([5.87910E-01, 4.11760E-01, 3.39060E-04, 1.17610E-07, 0.000000E-00, 0.000000E-00, 0.000000E-00]) mox43_xsdata = openmc.XSdata('mox43.300k', groups) mox43_xsdata.order = 0 mox43_xsdata.total = np.array([1.787310E-01, 3.308490E-01, 4.837720E-01, 5.669220E-01, 4.262270E-01, 6.789970E-01, 6.828520E-01]) mox43_xsdata.absorption = np.array([8.43390E-03, 3.75770E-03, 2.79700E-02, 1.04210E-01, 1.39940E-01, 4.09180E-01, 4.09350E-01])
def create_library(): # Instantiate the energy group data and file object groups = openmc.mgxs.EnergyGroups(group_edges=[0.0, 0.625, 20.0e6]) n_dg = 2 mg_cross_sections_file = openmc.MGXSLibrary(groups) mg_cross_sections_file.num_delayed_groups = n_dg beta = np.array([0.003, 0.003]) one_m_beta = 1. - np.sum(beta) nu = [2.50, 2.50] fiss = np.array([0.002817, 0.097]) capture = [0.008708, 0.02518] absorption = np.add(capture, fiss) scatter = np.array([[[0.31980, 0.06694], [0.004555, -0.0003972]], [[0.00000, 0.00000], [0.424100, 0.05439000]]]) total = [0.33588, 0.54628] chi = [1., 0.] # Make the base data that uses chi & nu-fission vectors with a beta mat_1 = openmc.XSdata('mat_1', groups) mat_1.order = 1 mat_1.num_delayed_groups = 2 mat_1.set_beta(beta) mat_1.set_nu_fission(np.multiply(nu, fiss)) mat_1.set_absorption(absorption) mat_1.set_scatter_matrix(scatter) mat_1.set_total(total) mat_1.set_chi(chi) mg_cross_sections_file.add_xsdata(mat_1) # Make a version that uses prompt and delayed version of nufiss and chi mat_2 = openmc.XSdata('mat_2', groups) mat_2.order = 1 mat_2.num_delayed_groups = 2 mat_2.set_prompt_nu_fission(one_m_beta * np.multiply(nu, fiss)) delay_nu_fiss = np.zeros((n_dg, groups.num_groups)) for dg in range(n_dg): for g in range(groups.num_groups): delay_nu_fiss[dg, g] = beta[dg] * nu[g] * fiss[g] mat_2.set_delayed_nu_fission(delay_nu_fiss) mat_2.set_absorption(absorption) mat_2.set_scatter_matrix(scatter) mat_2.set_total(total) mat_2.set_chi_prompt(chi) mat_2.set_chi_delayed(np.stack([chi] * n_dg)) mg_cross_sections_file.add_xsdata(mat_2) # Make a version that uses a nu-fission matrix with a beta mat_3 = openmc.XSdata('mat_3', groups) mat_3.order = 1 mat_3.num_delayed_groups = 2 mat_3.set_beta(beta) mat_3.set_nu_fission(np.outer(np.multiply(nu, fiss), chi)) mat_3.set_absorption(absorption) mat_3.set_scatter_matrix(scatter) mat_3.set_total(total) mg_cross_sections_file.add_xsdata(mat_3) # Make a version that uses prompt and delayed version of the nufiss matrix mat_4 = openmc.XSdata('mat_4', groups) mat_4.order = 1 mat_4.num_delayed_groups = 2 mat_4.set_prompt_nu_fission(one_m_beta * np.outer(np.multiply(nu, fiss), chi)) delay_nu_fiss = np.zeros((n_dg, groups.num_groups, groups.num_groups)) for dg in range(n_dg): for g in range(groups.num_groups): for go in range(groups.num_groups): delay_nu_fiss[dg, g, go] = beta[dg] * nu[g] * fiss[g] * chi[go] mat_4.set_delayed_nu_fission(delay_nu_fiss) mat_4.set_absorption(absorption) mat_4.set_scatter_matrix(scatter) mat_4.set_total(total) mg_cross_sections_file.add_xsdata(mat_4) # Make the base data that uses chi & nu-fiss vectors with a group-wise beta mat_5 = openmc.XSdata('mat_5', groups) mat_5.order = 1 mat_5.num_delayed_groups = 2 mat_5.set_beta(np.stack([beta] * groups.num_groups)) mat_5.set_nu_fission(np.multiply(nu, fiss)) mat_5.set_absorption(absorption) mat_5.set_scatter_matrix(scatter) mat_5.set_total(total) mat_5.set_chi(chi) mg_cross_sections_file.add_xsdata(mat_5) # Make a version that uses a nu-fission matrix with a group-wise beta mat_6 = openmc.XSdata('mat_6', groups) mat_6.order = 1 mat_6.num_delayed_groups = 2 mat_6.set_beta(np.stack([beta] * groups.num_groups)) mat_6.set_nu_fission(np.outer(np.multiply(nu, fiss), chi)) mat_6.set_absorption(absorption) mat_6.set_scatter_matrix(scatter) mat_6.set_total(total) mg_cross_sections_file.add_xsdata(mat_6) # Write the file mg_cross_sections_file.export_to_hdf5('2g.h5')
# OpenMC simulation parameters batches = 100 inactive = 10 particles = 1000 ############################################################################### # Exporting to OpenMC mgxs.xml file ############################################################################### # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups(group_edges=[1E-11, 0.0635E-6, 10.0E-6, 1.0E-4, 1.0E-3, 0.5, 1.0, 20.0]) # Instantiate the 7-group (C5G7) cross section data uo2_xsdata = openmc.XSdata('UO2.300K', groups) uo2_xsdata.order = 0 uo2_xsdata.total = [0.1779492, 0.3298048, 0.4803882, 0.5543674, 0.3118013, 0.3951678, 0.5644058] uo2_xsdata.absorption = [8.0248E-03, 3.7174E-03, 2.6769E-02, 9.6236E-02, 3.0020E-02, 1.1126E-01, 2.8278E-01] uo2_xsdata.scatter = [[[0.1275370, 0.0423780, 0.0000094, 0.0000000, 0.0000000, 0.0000000, 0.0000000], [0.0000000, 0.3244560, 0.0016314, 0.0000000, 0.0000000, 0.0000000, 0.0000000], [0.0000000, 0.0000000, 0.4509400, 0.0026792, 0.0000000, 0.0000000, 0.0000000], [0.0000000, 0.0000000, 0.0000000, 0.4525650, 0.0055664, 0.0000000, 0.0000000], [0.0000000, 0.0000000, 0.0000000, 0.0001253, 0.2714010, 0.0102550, 0.0000000], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0012968, 0.2658020, 0.0168090], [0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0000000, 0.0085458, 0.2730800]]] uo2_xsdata.fission = [7.21206E-03, 8.19301E-04, 6.45320E-03, 1.85648E-02, 1.78084E-02, 8.30348E-02, 2.16004E-01]
def get_xsdata(self, domain, xsdata_name, nuclide='total', xs_type='macro', xs_id='1m', order=None, tabular_legendre=None, tabular_points=33): """Generates an openmc.XSdata object describing a multi-group cross section data set for eventual combination in to an openmc.MGXSLibrary object (i.e., the library). Parameters ---------- domain : openmc.Material or openmc.Cell or openmc.Universe The domain for spatial homogenization xsdata_name : str Name to apply to the "xsdata" entry produced by this method nuclide : str A nuclide name string (e.g., 'U-235'). Defaults to 'total' to obtain a material-wise macroscopic cross section. xs_type: {'macro', 'micro'} Provide the macro or micro cross section in units of cm^-1 or barns. Defaults to 'macro'. If the Library object is not tallied by nuclide this will be set to 'macro' regardless. xs_ids : str Cross section set identifier. Defaults to '1m'. order : int Scattering order for this data entry. Default is None, which will set the XSdata object to use the order of the Library. tabular_legendre : None or bool Flag to denote whether or not the Legendre expansion of the scattering angular distribution is to be converted to a tabular representation by OpenMC. A value of `True` means that it is to be converted while a value of `False` means that it will not be. Defaults to `None` which leaves the default behavior of OpenMC in place (the distribution is converted to a tabular representation). tabular_points : int This parameter is not used unless the ``tabular_legendre`` parameter is set to `True`. In this case, this parameter sets the number of equally-spaced points in the domain of [-1,1] to be used in building the tabular distribution. Default is `33`. Returns ------- xsdata : openmc.XSdata Multi-Group Cross Section data set object. Raises ------ ValueError When the Library object is initialized with insufficient types of cross sections for the Library. See also -------- Library.create_mg_library() """ cv.check_type('domain', domain, (openmc.Material, openmc.Cell, openmc.Cell)) cv.check_type('xsdata_name', xsdata_name, basestring) cv.check_type('nuclide', nuclide, basestring) cv.check_value('xs_type', xs_type, ['macro', 'micro']) cv.check_type('xs_id', xs_id, basestring) cv.check_type('order', order, (type(None), Integral)) if order is not None: cv.check_greater_than('order', order, 0, equality=True) cv.check_less_than('order', order, 10, equality=True) cv.check_type('tabular_legendre', tabular_legendre, (type(None), bool)) if tabular_points is not None: cv.check_greater_than('tabular_points', tabular_points, 1) # Make sure statepoint has been loaded if self._sp_filename is None: msg = 'A StatePoint must be loaded before calling ' \ 'the create_mg_library() function' raise ValueError(msg) # If gathering material-specific data, set the xs_type to macro if not self.by_nuclide: xs_type = 'macro' # Build & add metadata to XSdata object name = xsdata_name if nuclide is not 'total': name += '_' + nuclide name += '.' + xs_id xsdata = openmc.XSdata(name, self.energy_groups) if order is None: # Set the order to the Library's order (the defualt behavior) xsdata.order = self.legendre_order else: # Set the order of the xsdata object to the minimum of # the provided order or the Library's order. xsdata.order = min(order, self.legendre_order) # Set the tabular_legendre option if needed if tabular_legendre is not None: xsdata.tabular_legendre = {'enable': tabular_legendre, 'num_points': tabular_points} if nuclide is not 'total': xsdata.zaid = self._nuclides[nuclide][0] xsdata.awr = self._nuclides[nuclide][1] # Now get xs data itself if 'nu-transport' in self.mgxs_types and self.correction == 'P0': mymgxs = self.get_mgxs(domain, 'nu-transport') xsdata.set_total_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) elif 'total' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'total') xsdata.set_total_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) if 'absorption' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'absorption') xsdata.set_absorption_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) if 'fission' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'fission') xsdata.set_fission_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) if 'kappa-fission' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'kappa-fission') xsdata.set_kappa_fission_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) # For chi and nu-fission we can either have only a nu-fission matrix # provided, or vectors of chi and nu-fission provided if 'nu-fission matrix' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'nu-fission matrix') xsdata.set_nu_fission_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) else: if 'chi' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'chi') xsdata.set_chi_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) if 'nu-fission' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'nu-fission') xsdata.set_nu_fission_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) # If multiplicity matrix is available, prefer that if 'multiplicity matrix' in self.mgxs_types: mymgxs = self.get_mgxs(domain, 'multiplicity matrix') xsdata.set_multiplicity_mgxs(mymgxs, xs_type=xs_type, nuclide=[nuclide]) using_multiplicity = True # multiplicity wil fall back to using scatter and nu-scatter elif ((('scatter matrix' in self.mgxs_types) and ('nu-scatter matrix' in self.mgxs_types))): scatt_mgxs = self.get_mgxs(domain, 'scatter matrix') nuscatt_mgxs = self.get_mgxs(domain, 'nu-scatter matrix') xsdata.set_multiplicity_mgxs(nuscatt_mgxs, scatt_mgxs, xs_type=xs_type, nuclide=[nuclide]) using_multiplicity = True else: using_multiplicity = False if using_multiplicity: nuscatt_mgxs = self.get_mgxs(domain, 'nu-scatter matrix') xsdata.set_scatter_mgxs(nuscatt_mgxs, xs_type=xs_type, nuclide=[nuclide]) else: if 'nu-scatter matrix' in self.mgxs_types: nuscatt_mgxs = self.get_mgxs(domain, 'nu-scatter matrix') xsdata.set_scatter_mgxs(nuscatt_mgxs, xs_type=xs_type, nuclide=[nuclide]) # Since we are not using multiplicity, then # scattering multiplication (nu-scatter) must be # accounted for approximately by using an adjusted # absorption cross section. if 'total' in self.mgxs_types: xsdata.absorption = \ np.subtract(xsdata.total, np.sum(xsdata.scatter[0, :, :], axis=1)) return xsdata
def create_library(): # Instantiate the energy group data and file object groups = openmc.mgxs.EnergyGroups(group_edges=[0.0, 0.625, 20.0e6]) mg_cross_sections_file = openmc.MGXSLibrary(groups) # Make the base, isotropic data nu = [2.50, 2.50] fiss = np.array([0.002817, 0.097]) capture = [0.008708, 0.02518] absorption = np.add(capture, fiss) scatter = np.array([[[0.31980, 0.06694], [0.004555, -0.0003972]], [[0.00000, 0.00000], [0.424100, 0.05439000]]]) total = [0.33588, 0.54628] chi = [1., 0.] mat_1 = openmc.XSdata('mat_1', groups) mat_1.order = 1 mat_1.set_nu_fission(np.multiply(nu, fiss)) mat_1.set_absorption(absorption) mat_1.set_scatter_matrix(scatter) mat_1.set_total(total) mat_1.set_chi(chi) mg_cross_sections_file.add_xsdata(mat_1) # Make a version of mat-1 which has a tabular representation of the # scattering vice Legendre with 33 points mat_2 = mat_1.convert_scatter_format('tabular', 33) mat_2.name = 'mat_2' mg_cross_sections_file.add_xsdata(mat_2) # Make a version of mat-1 which has a histogram representation of the # scattering vice Legendre with 33 bins mat_3 = mat_1.convert_scatter_format('histogram', 33) mat_3.name = 'mat_3' mg_cross_sections_file.add_xsdata(mat_3) # Make a version which uses a fission matrix vice chi & nu-fission mat_4 = openmc.XSdata('mat_4', groups) mat_4.order = 1 mat_4.set_nu_fission(np.outer(np.multiply(nu, fiss), chi)) mat_4.set_absorption(absorption) mat_4.set_scatter_matrix(scatter) mat_4.set_total(total) mg_cross_sections_file.add_xsdata(mat_4) # Make an angle-dependent version of mat_1 with 2 polar and 2 azim. angles mat_5 = mat_1.convert_representation('angle', 2, 2) mat_5.name = 'mat_5' mg_cross_sections_file.add_xsdata(mat_5) # Make a copy of mat_1 for testing microscopic cross sections mat_6 = openmc.XSdata('mat_6', groups) mat_6.order = 1 mat_6.set_nu_fission(np.multiply(nu, fiss)) mat_6.set_absorption(absorption) mat_6.set_scatter_matrix(scatter) mat_6.set_total(total) mat_6.set_chi(chi) mg_cross_sections_file.add_xsdata(mat_6) # Write the file mg_cross_sections_file.export_to_hdf5('2g.h5')
from math import log10 import numpy as np import openmc import openmc.mgxs ############################################################################### # Create multigroup data # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups( group_edges=[1e-5, 0.0635, 10.0, 1.0e2, 1.0e3, 0.5e6, 1.0e6, 20.0e6]) # Instantiate the 7-group (C5G7) cross section data uo2_xsdata = openmc.XSdata('UO2', groups) uo2_xsdata.order = 0 uo2_xsdata.set_total([ 0.1779492, 0.3298048, 0.4803882, 0.5543674, 0.3118013, 0.3951678, 0.5644058 ]) uo2_xsdata.set_absorption([ 8.0248E-03, 3.7174E-03, 2.6769E-02, 9.6236E-02, 3.0020E-02, 1.1126E-01, 2.8278E-01 ]) scatter_matrix = np.array([[[ 0.1275370, 0.0423780, 0.0000094, 0.0000000, 0.0000000, 0.0000000, 0.0000000 ], [ 0.0000000, 0.3244560, 0.0016314, 0.0000000, 0.0000000, 0.0000000, 0.0000000 ], [ 0.0000000, 0.0000000, 0.4509400, 0.0026792, 0.0000000, 0.0000000, 0.0000000 ], [
import openmc import openmc.mgxs import numpy as np ############################################################################### # Exporting to OpenMC mg_cross_sections.xml File ############################################################################### # Instantiate the energy group data groups = openmc.mgxs.EnergyGroups(np.logspace(-5, 7, 8)) # Instantiate the 7-group C5G7 cross section data uo2_xsdata = openmc.XSdata('uo2', groups) uo2_xsdata.order = 0 uo2_xsdata.set_total( np.array([1.779490E-01, 3.298050E-01, 4.803880E-01, 5.543670E-01, 3.118010E-01, 3.951680E-01, 5.644060E-01])) uo2_xsdata.set_absorption( np.array([8.02480E-03, 3.71740E-03, 2.67690E-02, 9.62360E-02, 3.00200E-02, 1.11260E-01, 2.82780E-01])) scatter_matrix = \ [[[1.275370E-01, 4.237800E-02, 9.437400E-06, 5.516300E-09, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 3.244560E-01, 1.631400E-03, 3.142700E-09, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 4.509400E-01, 2.679200E-03, 0.000000E-00, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 0.000000E-00, 4.525650E-01, 5.566400E-03, 0.000000E-00, 0.000000E-00], [0.000000E-00, 0.000000E-00, 0.000000E-00, 1.252500E-04, 2.714010E-01, 1.025500E-02, 1.002100E-08], [0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 1.296800E-03, 2.658020E-01, 1.680900E-02], [0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 0.000000E-00, 8.545800E-03, 2.730800E-01]]] scatter_matrix = np.array(scatter_matrix) scatter_matrix = np.rollaxis(scatter_matrix, 0, 3) uo2_xsdata.set_scatter_matrix(scatter_matrix)