Resolving @paulromano comments

This commit is contained in:
Adam Nelson 2016-11-16 21:47:07 -05:00
parent 625903e968
commit b8d9fe461f
3 changed files with 40 additions and 68 deletions

View file

@ -186,3 +186,9 @@ K_BOLTZMANN = 8.6173324e-5
# Used for converting units in ACE data
EV_PER_MEV = 1.0e6
# Avogadro's constant from CODATA 2010
AVOGADRO = 6.02214129E23
# Neutron mass from CODATA 2010 in units of amu
NEUTRON_MASS = 1.008664916

View file

@ -664,17 +664,12 @@ class Material(object):
sum_percent = 0.
awrs = []
n = -1
for nuclide in nuclides.items():
n += 1
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)
if not percent_in_atom:
nuc_densities[n] = -nuc_densities[n] / awrs[-1]
for n, nuclide in enumerate(nuclides.items()):
awr = openmc.data.atomic_mass(nuclide[0])
if awr is not None:
awrs.append(awr / openmc.data.NEUTRON_MASS)
else:
raise ValueError(nuclide[0] + " not in library")
raise ValueError(nuclide[0] + " is invalid")
# Now that we have the awr, lets finish calculating densities
sum_percent = np.sum(nuc_densities)
@ -686,7 +681,7 @@ class Material(object):
sum_percent += x * awrs[n]
sum_percent = 1. / sum_percent
density = -density * sum_percent * \
sc.Avogadro / sc.value('neutron mass in u') * 1.E-24
openmc.data.AVOGADRO / openmc.data.NEUTRON_MASS * 1.E-24
nuc_densities = density * nuc_densities
nuclides = OrderedDict()

View file

@ -15,42 +15,18 @@ UNITY_MT = -1
XI_MT = -2
# MTs to combine to generate associated plot_types
PLOT_TYPES_MT = {'total': (2, 3,),
'scatter': (2, 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),
'elastic': (2,),
'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,
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),
'unity': (UNITY_MT,),
'slowing-down power': (2, 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, XI_MT),
'damage': (444,)}
_INELASTIC = [mt for mt in openmc.data.SUM_RULES[3] if mt not in [5, 27]]
PLOT_TYPES_MT = {'total': openmc.data.SUM_RULES[1],
'scatter': [2] + _INELASTIC,
'elastic': [2],
'inelastic': _INELASTIC,
'fission': [18],
'absorption': [27], 'capture': [101],
'nu-fission': [18],
'nu-scatter': [2] + _INELASTIC,
'unity': [UNITY_MT],
'slowing-down power': [2] + _INELASTIC + [XI_MT],
'damage': [444]}
# Operations to use when combining MTs the first np.add is used in reference
# to zero
PLOT_TYPES_OP = {'total': (np.add,),
@ -84,8 +60,7 @@ PLOT_TYPES_LINEAR = {'nu-fission / fission', 'nu-scatter / scatter',
def plot_xs(this, types, divisor_types=None, temperature=294., axis=None,
energy_range=(1.E-5, 20.E6), sab_name=None, cross_sections=None,
enrichment=None, **kwargs):
sab_name=None, cross_sections=None, enrichment=None, **kwargs):
"""Creates a figure of continuous-energy cross sections for this item
Parameters
@ -106,8 +81,6 @@ def plot_xs(this, types, divisor_types=None, temperature=294., axis=None,
axis : matplotlib.axes, optional
A previously generated axis to use for plotting. If not specified,
a new axis and figure will be generated.
energy_range : tuple of floats
Energy range (in eV) to plot the cross section within
sab_name : str, optional
Name of S(a,b) library to apply to MT=2 data when applicable; only used
for items which are instances of openmc.Element or openmc.Nuclide
@ -212,10 +185,10 @@ def plot_xs(this, types, divisor_types=None, temperature=294., axis=None,
ylabel = 'Macroscopic Cross Section [1/cm]'
ax.set_ylabel(ylabel)
ax.legend(loc='best')
ax.set_xlim(energy_range)
# Set to the most likely expected range
ax.set_xlim((1.E-5, 20.E6))
if this.name is not None:
title = 'Cross Section for ' + this.name
ax.set_title(title)
ax.set_title('Cross Section for ' + this.name)
return fig
@ -246,7 +219,7 @@ def calculate_xs(this, types, temperature=294., sab_name=None,
Returns
-------
energy_grid : numpy.array
energy_grid : numpy.ndarray
Energies at which cross sections are calculated, in units of eV
data : numpy.ndarray
Cross sections calculated at the energy grid described by energy_grid
@ -302,7 +275,7 @@ def _calculate_xs_element(this, types, temperature=294., sab_name=None,
Returns
-------
energy_grid : numpy.array
energy_grid : numpy.ndarray
Energies at which cross sections are calculated, in units of eV
data : numpy.ndarray
Macroscopic cross sections calculated at the energy grid described
@ -381,7 +354,7 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
Returns
-------
energy_grid : numpy.array
energy_grid : numpy.ndarray
Energies at which cross sections are calculated, in units of eV
data : numpy.ndarray
Cross sections calculated at the energy grid described by
@ -405,6 +378,7 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
mts.append((line,))
yields.append((False,))
ops.append(())
print(mts)
# Load the library
library = openmc.data.DataLibrary.from_xml(cross_sections)
@ -427,7 +401,7 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
for t in range(len(data_Ts)):
# Take off the "K" and convert to a float
data_Ts[t] = float(data_Ts[t][:-1])
min_delta = np.finfo(np.float64).max
min_delta = float('inf')
closest_t = -1
for t in data_Ts:
if abs(data_Ts[t] - T) < min_delta:
@ -496,7 +470,6 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
funcs.append(nuc[mt].xs[nucT])
elif mt in nuc:
if yield_check:
found_it = False
for prod in nuc[mt].products:
if prod.particle == 'neutron' and \
prod.emission_mode == 'total':
@ -504,9 +477,8 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
[nuc[mt].xs[nucT], prod.yield_],
[np.multiply])
funcs.append(func)
found_it = True
break
if not found_it:
else:
for prod in nuc[mt].products:
if prod.particle == 'neutron' and \
prod.emission_mode == 'prompt':
@ -514,11 +486,10 @@ def _calculate_xs_nuclide(this, types, temperature=294., sab_name=None,
[nuc[mt].xs[nucT],
prod.yield_], [np.multiply])
funcs.append(func)
found_it = True
break
if not found_it:
# Assume the yield is 1
funcs.append(nuc[mt].xs[nucT])
else:
# Assume the yield is 1
funcs.append(nuc[mt].xs[nucT])
else:
funcs.append(nuc[mt].xs[nucT])
elif mt == UNITY_MT:
@ -557,7 +528,7 @@ def _calculate_xs_material(this, types, temperature=294., cross_sections=None):
Returns
-------
energy_grid : numpy.array
energy_grid : numpy.ndarray
Energies at which cross sections are calculated, in units of eV
data : numpy.ndarray
Macroscopic cross sections calculated at the energy grid described
@ -602,8 +573,8 @@ def _calculate_xs_material(this, types, temperature=294., cross_sections=None):
# Condense the data for every nuclide
# First create a union energy grid
energy_grid = E[0]
for n in range(1, len(E)):
energy_grid = np.union1d(energy_grid, E[n])
for grid in E[1:]:
energy_grid = np.union1d(energy_grid, grid)
# Now we can combine all the nuclidic data
data = np.zeros((len(types), len(energy_grid)))