import numpy as np
import openmc
import materials_for_mc as m4mc
openmc.config['cross_sections'] = '/home/jon/nuclear_data/cross_sections.xml'
mat = openmc.Material()
mat.add_nuclide('Li6',1)
mat.set_density('g/cm3', 20.)
openmc_energies, openmc_xs = openmc.calculate_cexs(mat, [1], temperature=294)
openmc_xs=openmc_xs[0]
mat1 = m4mc.Material()
mat1.add_nuclide('Li6',1)
mat1.set_density('g/cm3',20.)
mat1.temperature = "294"
mat1.read_nuclides_from_json({'Li6':'tests/Li6.json'})
mat1.calculate_macroscopic_xs(mt_filter=[1])
my_macro = mat1.macroscopic_xs_neutron[1]
my_energies = mat1.unified_energy_grid_neutron()
import matplotlib.pyplot as plt
plt.plot(openmc_energies, openmc_xs, label='OpenMC', linestyle='--')
plt.plot(mat1.unified_energy_grid_neutron(),my_macro, label='My code', linestyle='-.')
plt.xlabel('Energy (eV)')
plt.ylabel('Cross Section (barns)')
plt.title('Li6 Neutron Macroscopic Cross Section Comparison')
plt.legend()
plt.xscale('log')
plt.yscale('log')
plt.grid(True)
plt.show()
import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=my_energies,
y=my_macro,
name='mycode (total)',
line=dict(dash='dashdot', width=2)
)
)
for mt in list(mat1.macroscopic_xs_neutron.keys()):
my_macro = mat1.macroscopic_xs_neutron[mt]
if my_macro[0] != 0 and mt != 1: fig.add_trace(
go.Scatter(
x=my_energies,
y=my_macro,
name=f'MT={mt}',
line=dict(dash='dashdot', width=1),
visible='legendonly' )
)
fig.add_trace(
go.Scatter(
x=openmc_energies,
y=openmc_xs,
name='OpenMC (total)',
line=dict(dash='dash', width=2)
)
)
fig.update_layout(
title='Li6 Neutron Macroscopic Cross Section Comparison',
xaxis_title='Energy (eV)',
yaxis_title='Cross Section (barns)',
xaxis_type='log',
yaxis_type='log',
legend=dict(
yanchor="top",
y=0.99,
xanchor="left",
x=0.01
),
hovermode='closest'
)
fig.update_xaxes(gridcolor='lightgray')
fig.update_yaxes(gridcolor='lightgray')
fig.write_html('compare_macroscopic_total_to_openmc.html')