Added kwargs to plots, switched to taking a file string for the cross_sections.xml file instead of an initialized DataLibrary, and avoided precision issues when calculating the inelastic xs

This commit is contained in:
Adam Nelson 2016-11-11 05:20:38 -05:00
parent 2fa70ee582
commit 7524637e23
4 changed files with 55 additions and 32 deletions

View file

@ -261,7 +261,8 @@ class Element(object):
return isotopes
def plot_xs(self, types, divisor_types=None, temperature=294.,
Erange=(1.E-5, 20.E6), enrichment=None, cross_sections=None):
Erange=(1.E-5, 20.E6), enrichment=None, cross_sections=None,
**kwargs):
"""Creates a figure of continuous-energy microscopic cross sections
for this element
@ -286,6 +287,9 @@ class Element(object):
(natural composition).
cross_sections : str, optional
Location of cross_sections.xml file. Default is None.
**kwargs
All keyword arguments are passed to
:func:`matplotlib.pyplot.figure`.
Returns
-------
@ -319,22 +323,16 @@ class Element(object):
data = data_new
# Generate the plot
fig = plt.figure()
fig = plt.figure(**kwargs)
ax = fig.add_subplot(111)
iE_max = np.searchsorted(E, Erange[1])
min_data = np.finfo(np.float64).max
max_data = np.finfo(np.float64).min
for i in range(len(data)):
if np.sum(data[i, :]) > 0.:
ax.loglog(E, data[i, :], label=types[i])
min_data = min(min_data, np.min(data[i, :iE_max]))
max_data = max(max_data, np.max(data[i, :iE_max]))
ax.set_xlabel('Energy [eV]')
ax.set_ylabel('Elemental Cross Section [1/cm]')
ax.legend(loc='best')
ax.set_xlim(Erange)
ax.set_ylim(min_data, max_data)
if self.name is not None:
title = 'Cross Section for ' + self.name
ax.set_title(title)
@ -426,7 +424,7 @@ class Element(object):
if sab_name:
sab = openmc.data.ThermalScattering.from_hdf5(sab_name)
for nuc in sab.nuclides:
sabs[nuc] = library.get_by_materials(sab_name)['path']
sabs[nuc] = library.get_by_material(sab_name)['path']
# Now we can create the data sets to be plotted
xs = []

View file

@ -657,7 +657,7 @@ class Material(object):
n = -1
for nuclide in nuclides.items():
n += 1
lib = library.get_by_materials(nuclide[0])
lib = library.get_by_material(nuclide[0])
if lib is not None:
nuc = openmc.data.IncidentNeutron.from_hdf5(lib['path'])
awrs.append(nuc.atomic_weight_ratio)
@ -688,7 +688,7 @@ class Material(object):
return nuclides
def plot_xs(self, types, divisor_types=None, temperature=294.,
Erange=(1.E-5, 20.E6), cross_sections=None):
Erange=(1.E-5, 20.E6), cross_sections=None, **kwargs):
"""Creates a figure of continuous-energy macroscopic cross sections
for this material
@ -709,6 +709,9 @@ class Material(object):
Energy range (in eV) to plot the cross section within
cross_sections : str, optional
Location of cross_sections.xml file. Default is None.
**kwargs
All keyword arguments are passed to
:func:`matplotlib.pyplot.figure`.
Returns
-------
@ -742,22 +745,16 @@ class Material(object):
data = data_new
# Generate the plot
fig = plt.figure()
fig = plt.figure(**kwargs)
ax = fig.add_subplot(111)
iE_max = np.searchsorted(E, Erange[1])
min_data = np.finfo(np.float64).max
max_data = np.finfo(np.float64).min
for i in range(len(data)):
if np.sum(data[i, :]) > 0.:
ax.loglog(E, data[i, :], label=types[i])
min_data = min(min_data, np.min(data[i, :iE_max]))
max_data = max(max_data, np.max(data[i, :iE_max]))
ax.set_xlabel('Energy [eV]')
ax.set_ylabel('Macroscopic Cross Section [1/cm]')
ax.legend(loc='best')
ax.set_xlim(Erange)
ax.set_ylim(min_data, max_data)
if self.name is not None:
title = 'Macroscopic Cross Section for ' + self.name
ax.set_title(title)
@ -846,9 +843,9 @@ class Material(object):
for sab_name in self._sab:
sab = openmc.data.ThermalScattering.from_hdf5(
library.get_by_materials(sab_name)['path'])
library.get_by_material(sab_name)['path'])
for nuc in sab.nuclides:
sabs[nuc] = library.get_by_materials(sab_name)['path']
sabs[nuc] = library.get_by_material(sab_name)['path']
# Now we can create the data sets to be plotted
xs = []

View file

@ -98,7 +98,8 @@ class Nuclide(object):
self._scattering = scattering
def plot_xs(self, types, divisor_types=None, temperature=294.,
Erange=(1.E-5, 20.E6), sab_name=None, cross_sections=None):
Erange=(1.E-5, 20.E6), sab_name=None, cross_sections=None,
**kwargs):
"""Creates a figure of continuous-energy cross sections for this
nuclide
@ -121,6 +122,9 @@ class Nuclide(object):
Name of S(a,b) library to apply to MT=2 data when applicable.
cross_sections : str, optional
Location of cross_sections.xml file. Default is None.
**kwargs
All keyword arguments are passed to
:func:`matplotlib.pyplot.figure`.
Returns
-------
@ -154,23 +158,17 @@ class Nuclide(object):
data = data_new
# Generate the plot
fig = plt.figure()
fig = plt.figure(**kwargs)
ax = fig.add_subplot(111)
iE_max = np.searchsorted(E, Erange[1])
min_data = np.finfo(np.float64).max
max_data = np.finfo(np.float64).min
for i in range(len(data)):
to_plot = data[i](E)
if np.sum(to_plot) > 0.:
ax.loglog(E, to_plot, label=types[i])
min_data = min(min_data, np.min(to_plot[:iE_max]))
max_data = max(max_data, np.max(to_plot[:iE_max]))
ax.set_xlabel('Energy [eV]')
ax.set_ylabel('Microscopic Cross Section [b]')
ax.legend(loc='best')
ax.set_xlim(Erange)
ax.set_ylim(min_data, max_data)
if self.name is not None:
title = 'Microscopic Cross Section for ' + self.name
ax.set_title(title)
@ -245,7 +243,7 @@ class Nuclide(object):
# Now we can create the data sets to be plotted
E = []
xs = []
lib = library.get_by_materials(self.name)
lib = library.get_by_material(self.name)
if lib is not None:
nuc = openmc.data.IncidentNeutron.from_hdf5(lib['path'])
# Obtain the nearest temperature

View file

@ -6,7 +6,14 @@ PLOT_TYPES = ['total', 'scatter', 'elastic', 'inelastic', 'fission',
# MTs to combine to generate associated plot_types
PLOT_TYPES_MT = {'total': (2, 3,), 'scatter': (1, 27), 'elastic': (2,),
'inelastic': (1, 27, 2), 'fission': (18,),
'inelastic': (4, 11, 16, 17, 22, 23, 24, 25, 28, 29, 30,
32, 33, 34, 35, 36, 37, 41, 42, 44, 45, 152,
153, 154, 156, 157, 158, 159, 160, 161, 162,
163, 164, 165, 166, 167, 168, 169, 170, 171,
172, 173, 174, 175, 176, 177, 178, 179, 180,
181, 183, 184, 190, 194, 196, 198, 199, 200,
875, 891),
'fission': (18,),
'absorption': (27,), 'capture': (101,),
'nu-fission': (18,),
'nu-scatter': (2, 4, 11, 16, 17, 22, 23, 24, 25, 28, 29, 30,
@ -20,7 +27,18 @@ PLOT_TYPES_MT = {'total': (2, 3,), 'scatter': (1, 27), 'elastic': (2,),
# Operations to use when combining MTs the first np.add is used in reference
# to zero
PLOT_TYPES_OP = {'total': (np.add,), 'scatter': (np.subtract,), 'elastic': (),
'inelastic': (np.subtract, np.subtract),
'inelastic': (np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add, np.add,
np.add, np.add, np.add, np.add),
'fission': (), 'absorption': (),
'capture': (), 'nu-fission': (),
'nu-scatter': (np.add, np.add, np.add, np.add, np.add,
@ -38,7 +56,19 @@ PLOT_TYPES_OP = {'total': (np.add,), 'scatter': (np.subtract,), 'elastic': (),
'unity': ()}
# Whether or not to multiply the reaction by the yield as well
PLOT_TYPES_YIELD = {'total': (False, False), 'scatter': (False, False),
'elastic': (False,), 'inelastic': (False, False, False),
'elastic': (False,),
'inelastic': (False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False,
False, False, False, False, False),
'fission': (False,), 'absorption': (False,),
'capture': (False,), 'nu-fission': (True,),
'nu-scatter': (True, True, True, True, True,