def generate_material_trace(mat, Endf_MT_number):
    if type(Endf_MT_number) == int:
        Endf_MT_number = [Endf_MT_number]
    Energy, data = openmc.calculate_cexs(mat, 'material', Endf_MT_number)
    cross_section = data[0]

    trace1 = Scatter(x=Energy,
                     y=cross_section,
                     mode='lines',
                     name=mat.name + ' MT ' + str(Endf_MT_number[0]))
    return trace1
Exemple #2
0
carbon_reactor_grade = openmc.Material()
carbon_reactor_grade.add_element('B', 0.000001, percent_type='wo')
carbon_reactor_grade.add_element('C', 0.999999, percent_type='wo')
carbon_reactor_grade.set_density('g/cm3', 1.70)

# Tungsten
tungsten = openmc.Material()
tungsten.set_density('g/cm3', 19.3)
tungsten.add_element('W', 1.0)

Endf_MT16_number = [16]  # (n,2n)
Endf_MT2_number = [2]  # (n, elastic scatter)
Endf_MT18_number = [18]  # (n,fission)
Endf_MT102_number = [102]  # (n,gamma)

energy_beryllium, data = openmc.calculate_cexs(beryllium, 'material',
                                               Endf_MT16_number)
cross_section_beryllium = data[0]

energy_uranium, data = openmc.calculate_cexs(uranium235, 'material',
                                             Endf_MT18_number)
cross_section_uranium = data[0]

energy_carbon, data = openmc.calculate_cexs(carbon_reactor_grade, 'material',
                                            Endf_MT2_number)
cross_section_carbon = data[0]

energy_tungsten, data = openmc.calculate_cexs(tungsten, 'material',
                                              Endf_MT102_number)
cross_section_tungsten = data[0]

traces = []
    )  # this material defaults to a density of 1g/cm3

    try:
        element_object.add_element(element_name, 1.0, percent_type='ao')
    except ValueError:
        print("The cross section files for the isotopes of ", element_name,
              " don't exist")
        continue

    try:
        atomic_weight(element_name)
    except ValueError:
        print('There are no natural isotopes of ', element_name)
        continue

    energy, cross_sections = openmc.calculate_cexs(element_object, 'material',
                                                   [Endf_MT_number])
    cross_section = cross_sections[0]
    if cross_section.sum() != 0.0:
        fig.add_trace(
            go.Scatter(x=energy,
                       y=cross_section,
                       mode='lines',
                       name=element_name + ' MT ' + str(Endf_MT_number)))
    else:
        print('Element ', element_name,
              ' has no cross section data for MT number', Endf_MT_number)

fig.update_layout(title='Element cross sections ' + str(Endf_MT_number),
                  xaxis={
                      'title': 'Energy (eV)',
                      'range': (0, 14.1e6)
Exemple #4
0
natural_Li2TiO3 = openmc.Material()
natural_Li2TiO3.add_element('Li', 2.0, percent_type='ao')
natural_Li2TiO3.add_element('Ti', 2.0, percent_type='ao')
natural_Li2TiO3.add_element('O', 3.0, percent_type='ao')
natural_Li2TiO3.set_density(
    'g/cm3', 2.899)  # this density was found using crystal volumes function

#natural_Li4SiO4 density 1.8770150075137564 g/cm3
#enriched_Li4SiO4 density 1.8441466011318948 g/cm3 #60% Li6
#natural_Li2SiO3 density 2.619497078021483 g/cm3
#natural_Li2ZrO3 density 2.5288596326567134 g/cm3
#natural_Li2TiO3 density 2.8994147653592983 g/cm3

Endf_MT_number = [205]  # MT number 205 is (n,t) reaction

Energy_natural_Li4SiO4_MT16, data = openmc.calculate_cexs(
    natural_Li4SiO4, 'material', Endf_MT_number)
cross_section_natural_Li4SiO4_MT16 = data[0]

Energy_enriched_Li4SiO4_MT16, data = openmc.calculate_cexs(
    enriched_Li4SiO4, 'material', Endf_MT_number)
cross_section_enriched_Li4SiO4_MT16 = data[0]

Energy_natural_Li2SiO3_MT16, data = openmc.calculate_cexs(
    natural_Li2SiO3, 'material', Endf_MT_number)
cross_section_natural_Li2SiO3_MT16 = data[0]

Energy_natural_Li2ZrO3_MT16, data = openmc.calculate_cexs(
    natural_Li2ZrO3, 'material', Endf_MT_number)
cross_section_natural_Li2ZrO3_MT16 = data[0]

Energy_natural_Li2TiO3_MT16, data = openmc.calculate_cexs(
Exemple #5
0
    openmc_material.set_density('g/cm3', density_value)

    mt_numbers = []
    for entry in reaction_descriptions:
        # print(entry)
        mt_number = int(entry.split(" ")[1])
        if mt_number == 1:
            mt_number = 'total'
        mt_numbers.append(mt_number)
        #mt_numbers.append(entry.split(" ")[-1])

    # print(openmc_material)

    # print(mt_number)
    x_data, y_datas = openmc.calculate_cexs(openmc_material, 'material',
                                            mt_numbers)
    for reaction_description, y_data in zip(reaction_descriptions, y_datas):
        if not np.any(y_data):
            # print('all zero' , reaction_description)
            st.write(reaction_description,
                     ' cross section not found in material')
        # print(y_data)
        else:

            fig.add_trace(
                go.Scatter(y=y_data,
                           x=x_data,
                           name=reaction_description,
                           mode='lines'))

    xaxis_scale = axis_scales.split('-')[0]
Exemple #6
0
def update_output(reaction_names, rows, density_value, fraction_type,
                  xaxis_scale, yaxis_scale):

    if (reaction_names != None) and (rows != None) and (density_value != None):

        no_density = html.H4(
            'Specify a density in g/cm3',
            style={
                "text-align": "center",
                "color": "red"
            },
        )
        if density_value == None:
            return no_density
        elif density_value == 0:
            return no_density
        elif density_value == '':
            return no_density
        else:

            my_mat = Material(name="my_mat")

            for entry in rows:
                if entry["Elements"][-1].isdigit():
                    my_mat.add_nuclide(entry["Elements"],
                                       entry["Fractions"],
                                       percent_type=fraction_type)
                else:
                    my_mat.add_element(entry["Elements"],
                                       entry["Fractions"],
                                       percent_type=fraction_type)

            my_mat.set_density("g/cm3", density_value)
            if len(my_mat.nuclides) == 0:
                no_elements = html.H4(
                    'No elements or isotopes added',
                    style={
                        "text-align": "center",
                        "color": "red"
                    },
                )
                return no_elements
            else:
                energy, xs_data_set = calculate_cexs(my_mat, "material",
                                                     reaction_names)

                global downloaded_data

                downloaded_data = []

                for xs_data, reaction_name in zip(xs_data_set, reaction_names):
                    downloaded_data.append({
                        "y": xs_data,
                        "x": energy,
                        "type": "scatter",
                        "name": f"MT {reaction_name}"
                    })
                energy_units = "eV"
                xs_units = "Macroscopic cross section [1/cm]"
                return [
                    dcc.Graph(
                        config=dict(showSendToCloud=True),
                        figure={
                            "data": downloaded_data,
                            "layout": {
                                "height": 800,
                                # "width":1600,
                                "margin": {
                                    "l": 3,
                                    "r": 2,
                                    "t": 15,
                                    "b": 60
                                },
                                "xaxis": {
                                    "title": {
                                        "text": f"Energy {energy_units}"
                                    },
                                    "type": xaxis_scale,
                                    "tickformat": ".1e",
                                    "tickangle": 45,
                                },
                                "yaxis": {
                                    "automargin": True,
                                    "title": {
                                        "text": xs_units
                                    },
                                    "type": yaxis_scale,
                                    "tickformat": ".1e",
                                },
                                "showlegend": True,
                            },
                        },
                    )
                ]
    else:
        raise dash.exceptions.PreventUpdate
Exemple #7
0
def update_graph_from_mcnp(reaction_names, mcnp_input_text, xaxis_scale,
                           yaxis_scale, density_value):
    """mcnp_input_text is and mcnp material card like the example below
M24  001001  6.66562840e-01
     001002  1.03826667e-04
     008016  3.32540200e-01
     008017  1.26333333e-04
     008018  6.66800000e-04
    """
    no_density = html.H4(
        'Specify a density in g/cm3',
        style={
            "text-align": "center",
            "color": "red"
        },
    )
    no_mcnp_material_text = html.H4(
        'Specify a material card in MCNP format',
        style={
            "text-align": "center",
            "color": "red"
        },
    )
    no_mcnp_reaction = html.H4(
        'Select a reaction',
        style={
            "text-align": "center",
            "color": "red"
        },
    )

    if mcnp_input_text == None:
        return [], no_mcnp_material_text
    elif mcnp_input_text == '':
        return [], no_mcnp_material_text
    elif density_value == None:
        return [], no_density
    elif density_value == 0:
        return [], no_density
    elif density_value == '':
        return [], no_density
    elif reaction_names == None:
        return [], no_mcnp_reaction
    elif reaction_names == []:
        return [], no_mcnp_reaction

    else:
        try:
            # inputs look ok, but if the processing fails then return error

            file_lines = mcnp_input_text.split('\n')
            tokens = file_lines[0].split()
            # makes the first string without the material number
            material_string = f'{" ".join(tokens[1:])} '

            # removes inline comments
            if "$" in material_string:
                position = material_string.find("$")
                material_string = material_string[0:position]
            current_line_number = 1

            while True:
                # end of the file check
                if current_line_number == len(file_lines):
                    break

                while True:
                    # end of the file check
                    if (current_line_number == len(file_lines)):
                        break
                    line = file_lines[current_line_number]
                    # handels mcnp continue line (which is 5 spaces)
                    if line[:5] == "     ":
                        # removes inline comments
                        if "$" in line:
                            line = line[0:line.find("$")]
                        material_string = material_string + line
                    else:  # new cell card
                        break
                    # increment the line number
                    current_line_number = current_line_number + 1
                break

            # removes end of line chars and splits up
            tokens = material_string.replace("\n", "").split()
            if len(tokens) % 2 != 0:
                html.H4(
                    'The material string contains an odd number of zaids and fractions',
                    style={
                        "text-align": "center",
                        "color": "red"
                    },
                )
            zaid_fraction_dict = []
            while len(tokens) != 0:
                nuclide = tokens[0].split(".")
                isotope_name = zaid_to_isotope(nuclide[0])

                fraction = convert_strings_to_numbers(tokens[1])
                # removes two tokens from list
                tokens.pop(0)
                tokens.pop(0)
                zaid_fraction_dict.append({
                    'element': isotope_name,
                    'fraction': fraction
                })

            my_mat = Material(name="my_mat")

            table_contents = []

            for entry in zaid_fraction_dict:
                if entry['fraction'] < 0:
                    fraction_type = 'wo'
                else:
                    fraction_type = 'ao'

                if entry['element'][-1].isdigit():
                    my_mat.add_nuclide(entry['element'],
                                       entry['fraction'],
                                       percent_type=fraction_type)
                else:
                    my_mat.add_element(entry['element'],
                                       entry['fraction'],
                                       percent_type=fraction_type)
                table_contents.append(
                    html.Tr([
                        html.Td(html.Label(f"{entry['element']}"),
                                style={
                                    "width": "25%",
                                    "text-align": "left"
                                }),
                        html.Td(html.Label(f"{entry['fraction']}"),
                                style={
                                    "width": "25%",
                                    "text-align": "left"
                                })
                    ]))

            my_mat.set_density("g/cm3", density_value)

            if len(my_mat.nuclides) == 0:
                no_elements = html.H4(
                    'No elements or isotopes added',
                    style={
                        "text-align": "center",
                        "color": "red"
                    },
                )
                return [], no_elements
            else:
                energy, xs_data_set = calculate_cexs(my_mat, "material",
                                                     reaction_names)

            global mcnp_downloaded_data

            mcnp_downloaded_data = []

            table_of_processed = [
                html.Table(
                    [
                        html.Tr([
                            html.Th('Elements / isotopes',
                                    style={
                                        "width": "25%",
                                        "text-align": "left"
                                    }),
                            html.Th('Fraction',
                                    style={
                                        "width": "25%",
                                        "text-align": "left"
                                    }),
                        ]),
                    ] + table_contents,
                    style={"width": "50%"},
                )
            ]

            for xs_data, reaction_name in zip(xs_data_set, reaction_names):
                mcnp_downloaded_data.append({
                    "y": xs_data,
                    "x": energy,
                    "type": "scatter",
                    "name": f"MT {reaction_name}"
                })

            energy_units = "eV"
            xs_units = "Macroscopic cross section [1/cm]"
            return [
                dcc.Graph(
                    config=dict(showSendToCloud=True),
                    figure={
                        "data": mcnp_downloaded_data,
                        "layout": {
                            "height": 800,
                            # "width":1600,
                            "margin": {
                                "l": 3,
                                "r": 2,
                                "t": 15,
                                "b": 60
                            },
                            "xaxis": {
                                "title": {
                                    "text": f"Energy {energy_units}"
                                },
                                "type": xaxis_scale,
                                "tickformat": ".1e",
                                "tickangle": 45,
                            },
                            "yaxis": {
                                "automargin": True,
                                "title": {
                                    "text": xs_units
                                },
                                "type": yaxis_scale,
                                "tickformat": ".1e",
                            },
                            "showlegend": True,
                        },
                    },
                )
            ], table_of_processed

        except:
            return [], html.H4(
                'There was an error processing the MCNP material format',
                style={
                    "text-align": "center",
                    "color": "red"
                },
            )
import openmc
from plotly.offline import download_plotlyjs, plot
from plotly.graph_objs import Scatter, Layout
from tqdm import tqdm

all_stable_elements = ['Ag', 'Al', 'Ar', 'As', 'Au', 'B', 'Ba', 'Be', 'Bi', 'Br', 'C', 'Ca', 'Cd', 'Ce', 'Cl', 'Co', 'Cr', 'Cs', 'Cu', 'Dy', 'Er', 'Eu', 'F', 'Fe', 'Ga', 'Gd', 'Ge', 'H', 'He', 'Hf', 'Hg', 'Ho', 'I', 'In', 'Ir', 'K', 'Kr', 'La', 'Li', 'Lu', 'Mg', 'Mn', 'Mo', 'N', 'Na', 'Nb', 'Nd', 'Ne', 'Ni', 'O', 'Os', 'P', 'Pa', 'Pb', 'Pd','Po', 'Pr', 'Pt', 'Rb', 'Re', 'Rh', 'Rn', 'Ru', 'S', 'Sb', 'Sc', 'Se', 'Si', 'Sm', 'Sn', 'Sr', 'Ta', 'Tb', 'Te', 'Th', 'Ti', 'Tl', 'Tm', 'U', 'V', 'W', 'Xe', 'Y', 'Yb', 'Zn', 'Zr']
Endf_MT_number = [16,205] # MT number 16 is (n,n2) reaction, MT 205 is (n,t)
traces=[]


for element_name in tqdm(all_stable_elements):
      try:
            element_object = openmc.Material()
            # this material defaults to a density of 1g/cm3
            element_object.add_element(element_name,1.0,percent_type='ao')
            energy, data = openmc.calculate_cexs(element_object, 'material', Endf_MT_number )
            cross_section = data[0]

            traces.append(Scatter(x=energy, 
                              y=cross_section, 
                              mode = 'lines', 
                              name=element_name+' MT '+str(Endf_MT_number[0]))
                        )
      except:
            print('element failed ',element_name)

for element_name in tqdm(all_stable_elements):
      try:
            element_object = openmc.Material()
            # this material defaults to a density of 1g/cm3
            element_object.add_element(element_name,1.0,percent_type='ao')