mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Style, changed sampling/subset methods to return new objects
This commit is contained in:
parent
010acb8d1f
commit
5381ad46bc
4 changed files with 848 additions and 239 deletions
File diff suppressed because one or more lines are too long
|
|
@ -71,8 +71,8 @@ def float_endf(s):
|
|||
return float(_ENDF_FLOAT_RE.sub(r'\1e\2', s))
|
||||
|
||||
|
||||
def int_endf(s):
|
||||
"""Conver string to int. Used for INTG records where blank entries
|
||||
def _int_endf(s):
|
||||
"""Convert string to int. Used for INTG records where blank entries
|
||||
indicate a 0.
|
||||
|
||||
Parameters
|
||||
|
|
@ -267,10 +267,11 @@ def get_tab2_record(file_obj):
|
|||
|
||||
return params, Tabulated2D(breakpoints, interpolation)
|
||||
|
||||
|
||||
def get_intg_record(file_obj):
|
||||
"""
|
||||
Return data from an INTG record in an ENDF-6 file. Used to store the
|
||||
covariance matrix in a compact format.
|
||||
Return data from an INTG record in an ENDF-6 file. Used to store the
|
||||
covariance matrix in a compact format.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -285,8 +286,8 @@ def get_intg_record(file_obj):
|
|||
# determine how many items are in list and NDIGIT
|
||||
items = get_cont_record(file_obj)
|
||||
ndigit = int(items[2])
|
||||
npar = int(items[3]) # Number of parameters
|
||||
nlines = int(items[4]) # Lines to read
|
||||
npar = int(items[3]) # Number of parameters
|
||||
nlines = int(items[4]) # Lines to read
|
||||
NROW_RULES = {2: 18, 3: 12, 4: 11, 5: 9, 6: 8}
|
||||
nrow = NROW_RULES[ndigit]
|
||||
|
||||
|
|
@ -294,24 +295,23 @@ def get_intg_record(file_obj):
|
|||
corr = np.identity(npar)
|
||||
for i in range(nlines):
|
||||
line = file_obj.readline()
|
||||
ii = int_endf(line[:5]) - 1 #-1 to account for 0 indexing
|
||||
jj = int_endf(line[5:10]) - 1
|
||||
ii = _int_endf(line[:5]) - 1 # -1 to account for 0 indexing
|
||||
jj = _int_endf(line[5:10]) - 1
|
||||
factor = 10**ndigit
|
||||
for j in range(nrow):
|
||||
if jj+j >= ii:
|
||||
break
|
||||
element = int_endf(line[11+(ndigit+1)*j:11+(ndigit+1)*(j+1)])
|
||||
element = _int_endf(line[11+(ndigit+1)*j:11+(ndigit+1)*(j+1)])
|
||||
if element > 0:
|
||||
corr[ii, jj] = (element+0.5)/factor
|
||||
elif element < 0:
|
||||
corr[ii, jj] = (element-0.5)/factor
|
||||
|
||||
#Symmetrize the correlation matrix
|
||||
# Symmetrize the correlation matrix
|
||||
corr = corr + corr.T - np.diag(corr.diagonal())
|
||||
return corr
|
||||
|
||||
|
||||
|
||||
def get_evaluations(filename):
|
||||
"""Return a list of all evaluations within an ENDF file.
|
||||
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ class IncidentNeutron(EqualityMixin):
|
|||
@resonance_covariance.setter
|
||||
def resonance_covariance(self, resonance_covariance):
|
||||
cv.check_type('resonance covariance', resonance_covariance,
|
||||
res_cov.ResonanceCovariances)
|
||||
res_cov.ResonanceCovariances)
|
||||
self._resonance_covariance = resonance_covariance
|
||||
|
||||
@summed_reactions.setter
|
||||
|
|
@ -767,7 +767,7 @@ class IncidentNeutron(EqualityMixin):
|
|||
be the filename for the ENDF file.
|
||||
|
||||
covariance : bool
|
||||
Flag to indicate whether or not covariance data from File 32 should be
|
||||
Flag to indicate whether or not covariance data from File 32 should be
|
||||
retrieved
|
||||
|
||||
Returns
|
||||
|
|
@ -802,7 +802,9 @@ class IncidentNeutron(EqualityMixin):
|
|||
data.resonances = res.Resonances.from_endf(ev)
|
||||
|
||||
if (32, 151) in ev.section and covariance:
|
||||
data.resonance_covariance = res_cov.ResonanceCovariances.from_endf(ev, data.resonances)
|
||||
data.resonance_covariance = (
|
||||
res_cov.ResonanceCovariances.from_endf(ev, data.resonances)
|
||||
)
|
||||
|
||||
# Read each reaction
|
||||
for mf, mt, nc, mod in ev.reaction_list:
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ from .resonance import Resonances
|
|||
|
||||
|
||||
def _add_file2_contributions(file32params, file2params):
|
||||
"""Function for aiding in adding resonance parameters from File 2 that are
|
||||
"""Function for aiding in adding resonance parameters from File 2 that are
|
||||
not always present in File 32. Uses already imported resonance data.
|
||||
|
||||
Paramaters
|
||||
----------
|
||||
file32params : pandas.Dataframe
|
||||
Incomplete set of resonance parameters contained in File 32.
|
||||
Incomplete set of resonance parameters contained in File 32.
|
||||
file2params : pandas.Dataframe
|
||||
Resonance parameters from File 2. Ordered by energy.
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ def _add_file2_contributions(file32params, file2params):
|
|||
-------
|
||||
parameters : pandas.Dataframe
|
||||
Complete set of parameters ordered by L-values and then energy
|
||||
|
||||
"""
|
||||
# Use l-values and competitiveWidth from File 2 data
|
||||
# Re-sort File 2 by energy to match File 32
|
||||
|
|
@ -54,6 +55,7 @@ class ResonanceCovariances(Resonances):
|
|||
----------
|
||||
ranges : list of openmc.data.ResonanceCovarianceRange
|
||||
Distinct energy ranges for resonance data
|
||||
|
||||
"""
|
||||
|
||||
@property
|
||||
|
|
@ -63,8 +65,8 @@ class ResonanceCovariances(Resonances):
|
|||
@ranges.setter
|
||||
def ranges(self, ranges):
|
||||
cv.check_type('resonance ranges', ranges, MutableSequence)
|
||||
self._ranges = cv.CheckedList(ResonanceCovarianceRange, 'resonance range',
|
||||
ranges)
|
||||
self._ranges = cv.CheckedList(ResonanceCovarianceRange,
|
||||
'resonance range', ranges)
|
||||
|
||||
@classmethod
|
||||
def from_endf(cls, ev, resonances):
|
||||
|
|
@ -75,8 +77,8 @@ class ResonanceCovariances(Resonances):
|
|||
ev : openmc.data.endf.Evaluation
|
||||
ENDF evaluation
|
||||
resonances : openmc.data.Resonance object
|
||||
openmc.data.Resonanance object generated from the same evaluation used
|
||||
to import values not contained in File 32
|
||||
openmc.data.Resonanance object generated from the same evaluation
|
||||
used to import values not contained in File 32
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -88,39 +90,40 @@ class ResonanceCovariances(Resonances):
|
|||
|
||||
# Determine whether discrete or continuous representation
|
||||
items = endf.get_head_record(file_obj)
|
||||
n_isotope = items[4] # Number of isotopes
|
||||
n_isotope = items[4] # Number of isotopes
|
||||
|
||||
ranges = []
|
||||
for iso in range(n_isotope):
|
||||
items = endf.get_cont_record(file_obj)
|
||||
abundance = items[1]
|
||||
fission_widths = (items[3] == 1) # Flag for fission widths
|
||||
n_ranges = items[4] # number of resonance energy ranges
|
||||
fission_widths = (items[3] == 1) # Flag for fission widths
|
||||
n_ranges = items[4] # Number of resonance energy ranges
|
||||
|
||||
for j in range(n_ranges):
|
||||
items = endf.get_cont_record(file_obj)
|
||||
unresolved_flag = items[2] # 0: only scattering radius given
|
||||
# 1: resolved parameters given
|
||||
# 2: unresolved parameters given
|
||||
# Unresolved flags - 0: only scattering radius given
|
||||
# 1: resolved parameters given
|
||||
# 2: unresolved parameters given
|
||||
unresolved_flag = items[2]
|
||||
formalism = items[3] # resonance formalism
|
||||
|
||||
# Throw error for unsupported formalisms
|
||||
if formalism in [0, 7]:
|
||||
raise NotImplementedError('LRF= ', formalism,
|
||||
'covariance not supported for this formalism')
|
||||
error = 'LRF = '+str(formalism)+'covariance not supported '\
|
||||
'for this formalism'
|
||||
raise NotImplementedError(error)
|
||||
|
||||
if unresolved_flag in (0, 1):
|
||||
# resolved resonance region
|
||||
# Resolved resonance region
|
||||
file2params = resonances.ranges[j].parameters
|
||||
erange = _FORMALISMS[formalism].from_endf(ev, file_obj,
|
||||
items, file2params)
|
||||
ranges.append(erange)
|
||||
|
||||
elif unresolved_flag == 2:
|
||||
warn_str = 'Unresolved resonance not supported. '\
|
||||
'Covariance values for the unresolved region not imported.'
|
||||
warnings.warn(warn_str)
|
||||
|
||||
warn = 'Unresolved resonance not supported. Covariance '\
|
||||
'values for the unresolved region not imported.'
|
||||
warnings.warn(warn)
|
||||
|
||||
return cls(ranges)
|
||||
|
||||
|
|
@ -146,7 +149,7 @@ class ResonanceCovarianceRange:
|
|||
covariance : numpy.array
|
||||
The covariance matrix contained within the ENDF evaluation
|
||||
lcomp : int
|
||||
Flag indicating the format of the covariance matrix within the ENDF file
|
||||
Flag indicating format of the covariance matrix within the ENDF file
|
||||
mpar : int
|
||||
Number of parameters in covariance matrix for each individual resonance
|
||||
formalism : str
|
||||
|
|
@ -155,35 +158,47 @@ class ResonanceCovarianceRange:
|
|||
def __init__(self, energy_min, energy_max):
|
||||
self.energy_min = energy_min
|
||||
self.energy_max = energy_max
|
||||
|
||||
def res_subset(self, parameter_str, bounds):
|
||||
|
||||
def res_subset(self, parameter_str, bounds, resonances):
|
||||
"""Produce a subset of resonance parameters and the corresponding
|
||||
covariance matrix to an IncidentNeutron object.
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parameter_str : str
|
||||
parameter to be discriminated
|
||||
(i.e. 'energy', 'captureWidth', 'fissionWidthA'...)
|
||||
bounds : np.array
|
||||
bounds : np.array
|
||||
[low numerical bound, high numerical bound]
|
||||
|
||||
resonances : openmc.data.ResonanceRange object
|
||||
Corresponding resonance range with File 2 data.
|
||||
|
||||
Returns
|
||||
-------
|
||||
parameters_subset : pandas.Dataframe
|
||||
Subset of parameters (maintains indexing of original)
|
||||
cov_subset : np.array
|
||||
Subset of covariance matrix (upper triangular)
|
||||
|
||||
res_range : openmc.data.ResonanceRange
|
||||
ResonanceRange object that contains a subset of parameters
|
||||
(maintains indexing of original)
|
||||
res_cov_range : openmc.data.ResonanceCovarianceRange
|
||||
ResonanceCovarianceRange object that contains a subset of the
|
||||
covariance matrix (upper triangular) as well as parameters
|
||||
|
||||
"""
|
||||
parameters = self.parameters
|
||||
cov = self.covariance
|
||||
mpar = self.mpar
|
||||
# Copy the objects
|
||||
res_range = copy.copy(resonances)
|
||||
res_cov_range = copy.copy(self)
|
||||
|
||||
parameters = res_range.parameters
|
||||
cov = res_cov_range.covariance
|
||||
mpar = res_cov_range.mpar
|
||||
# Create mask
|
||||
mask1 = parameters[parameter_str] >= bounds[0]
|
||||
mask2 = parameters[parameter_str] <= bounds[1]
|
||||
mask = mask1 & mask2
|
||||
parameters_subset = parameters[mask]
|
||||
indices = parameters_subset.index.values
|
||||
# Set the parameters for each object
|
||||
res_range.parameters = parameters[mask]
|
||||
res_cov_range.parameters = parameters[mask]
|
||||
indices = res_cov_range.parameters.index.values
|
||||
# Build subset of covariance
|
||||
sub_cov_dim = len(indices)*mpar
|
||||
cov_subset_vals = []
|
||||
for index1 in indices:
|
||||
|
|
@ -191,54 +206,48 @@ class ResonanceCovarianceRange:
|
|||
for index2 in indices:
|
||||
for j in range(mpar):
|
||||
if index2*mpar+j >= index1*mpar+i:
|
||||
cov_subset_vals.append(cov[index1*mpar+i, index2*mpar+j])
|
||||
|
||||
cov_subset_vals.append(cov[index1*mpar+i,
|
||||
index2*mpar+j])
|
||||
|
||||
cov_subset = np.zeros([sub_cov_dim, sub_cov_dim])
|
||||
tri_indices = np.triu_indices(sub_cov_dim)
|
||||
cov_subset[tri_indices] = cov_subset_vals
|
||||
|
||||
self.parameters_subset = parameters_subset
|
||||
self.cov_subset = cov_subset
|
||||
res_cov_range.covariance = cov_subset
|
||||
|
||||
return res_range, res_cov_range
|
||||
|
||||
def sample_resonance_parameters(self, n_samples, resonances):
|
||||
"""Sample resonance parameters based on the covariances provided
|
||||
within an ENDF evaluation.
|
||||
|
||||
def sample_resonance_parameters(self, n_samples, resonances, use_subset=False):
|
||||
"""Return a list size 'n_samples' of openmc.data.ResonanceRange objects.
|
||||
Each with an indepentenly sampled set of parameters
|
||||
|
||||
Parameters
|
||||
----------
|
||||
n_samples : int
|
||||
The number of samples to produce
|
||||
resonances : openmc.data.ResonanceRange object
|
||||
Corresponding resonance range with File 2 data.
|
||||
use_subset : bool, optional
|
||||
Flag on whether to sample from an already produced subset
|
||||
|
||||
|
||||
Returns
|
||||
-------
|
||||
samples : list of openmc.data.ResonanceCovarianceRange objects
|
||||
samples : list of openmc.data.ResonanceCovarianceRange objects
|
||||
List of samples size `n_samples`
|
||||
|
||||
|
||||
"""
|
||||
warn_str = 'Sampling routine does not guarantee positive values for '\
|
||||
'parameters. This can lead to undefined behavior in the '\
|
||||
'reconstruction routine.'
|
||||
warnings.warn(warn_str)
|
||||
if not use_subset:
|
||||
parameters = self.parameters
|
||||
cov = self.covariance
|
||||
else:
|
||||
if self.parameters_subset is None:
|
||||
raise ValueError('No subset of resonances defined')
|
||||
parameters = self.parameters_subset
|
||||
cov = self.cov_subset
|
||||
parameters = self.parameters
|
||||
cov = self.covariance
|
||||
|
||||
nparams, params = parameters.shape
|
||||
cov = cov + cov.T - np.diag(cov.diagonal()) # symmetrizing covariance matrix
|
||||
# Symmetrizing covariance matrix
|
||||
cov = cov + cov.T - np.diag(cov.diagonal())
|
||||
covsize = cov.shape[0]
|
||||
formalism = self.formalism
|
||||
mpar = self.mpar
|
||||
samples = []
|
||||
|
||||
|
||||
# Handling MLBW sampling
|
||||
if formalism == 'mlbw' or formalism == 'slbw':
|
||||
if mpar == 3:
|
||||
|
|
@ -258,20 +267,22 @@ class ResonanceCovarianceRange:
|
|||
gt = gn + gg + gf
|
||||
records = []
|
||||
for j, E in enumerate(energy):
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j], gn[j],
|
||||
gg[j], gf[j], gx[j]])
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j],
|
||||
gn[j], gg[j], gf[j], gx[j]])
|
||||
columns = ['energy', 'L', 'J', 'totalWidth', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidth', 'competitiveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
sample_params = pd.DataFrame.from_records(records,
|
||||
columns=columns)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range._prepared = False # Set prepared to False to ensure
|
||||
# the sampled parameters are used
|
||||
# in reconstruction
|
||||
# Set _prepared to False to ensure sampled paramaters are
|
||||
# used during construction routine
|
||||
res_range._prepared = False
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
|
||||
elif mpar == 4:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth', 'fissionWidth']
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth',
|
||||
'fissionWidth']
|
||||
mean_array = pd.DataFrame.as_matrix(parameters[param_list])
|
||||
spin = pd.DataFrame.as_matrix(parameters['J'])
|
||||
l_value = pd.DataFrame.as_matrix(parameters['L'])
|
||||
|
|
@ -287,18 +298,19 @@ class ResonanceCovarianceRange:
|
|||
gt = gn + gg + gf
|
||||
records = []
|
||||
for j, E in enumerate(energy):
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j], gn[j],
|
||||
gg[j], gf[j], gx[j]])
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j],
|
||||
gn[j], gg[j], gf[j], gx[j]])
|
||||
columns = ['energy', 'L', 'J', 'totalWidth', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidth', 'competitiveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
sample_params = pd.DataFrame.from_records(records,
|
||||
columns=columns)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range._prepared = False # Set prepared to False to ensure
|
||||
# the sampled parameters are used
|
||||
# in reconstruction
|
||||
# Set _prepared to False to ensure sampled paramaters are
|
||||
# used during construction routine
|
||||
res_range._prepared = False
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
|
||||
elif mpar == 5:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth',
|
||||
'fissionWidth', 'competitiveWidth']
|
||||
|
|
@ -317,15 +329,16 @@ class ResonanceCovarianceRange:
|
|||
gt = gn + gg + gf
|
||||
records = []
|
||||
for j, E in enumerate(energy):
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j], gn[j],
|
||||
gg[j], gf[j], gx[j]])
|
||||
records.append([energy[j], l_value[j], spin[j], gt[j],
|
||||
gn[j], gg[j], gf[j], gx[j]])
|
||||
columns = ['energy', 'L', 'J', 'totalWidth', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidth', 'competitveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
sample_params = pd.DataFrame.from_records(records,
|
||||
columns=columns)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range._prepared = False # Set prepared to False to ensure
|
||||
# the sampled parameters are used
|
||||
# in reconstruction
|
||||
# Set _prepared to False to ensure sampled paramaters are
|
||||
# used during construction routine
|
||||
res_range._prepared = False
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
|
|
@ -351,14 +364,15 @@ class ResonanceCovarianceRange:
|
|||
gg[j], gfa[j], gfb[j]])
|
||||
columns = ['energy', 'L', 'J', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidthA', 'fissionWidthB']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
sample_params = pd.DataFrame.from_records(records,
|
||||
columns=columns)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range._prepared = False # Set prepared to False to ensure
|
||||
# the sampled parameters are used
|
||||
# in reconstruction
|
||||
# Set _prepared to False to ensure sampled paramaters are
|
||||
# used during construction routine
|
||||
res_range._prepared = False
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
|
||||
elif mpar == 5:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth',
|
||||
'fissionWidthA', 'fissionWidthB']
|
||||
|
|
@ -380,15 +394,16 @@ class ResonanceCovarianceRange:
|
|||
gg[j], gfa[j], gfb[j]])
|
||||
columns = ['energy', 'L', 'J', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidthA', 'fissionWidthB']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
sample_params = pd.DataFrame.from_records(records,
|
||||
columns=columns)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range._prepared = False # Set prepared to False to ensure
|
||||
# the sampled parameters are used
|
||||
# in reconstruction
|
||||
# Set _prepared to False to ensure sampled paramaters are
|
||||
# used during construction routine
|
||||
res_range._prepared = False
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
self.samples = samples
|
||||
|
||||
return samples
|
||||
|
||||
|
||||
class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
||||
|
|
@ -411,7 +426,7 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
covariance : numpy.array
|
||||
The covariance matrix contained within the ENDF evaluation
|
||||
lcomp : int
|
||||
Flag indicating the format of the covariance matrix within the ENDF file
|
||||
Flag indicating format of the covariance matrix within the ENDF file
|
||||
mpar : int
|
||||
Number of parameters in covariance matrix for each individual resonance
|
||||
formalism : str
|
||||
|
|
@ -425,7 +440,7 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
self.mpar = mpar
|
||||
self.lcomp = lcomp
|
||||
self.formalism = 'mlbw'
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_endf(cls, ev, file_obj, items, file2params):
|
||||
"""Create MLBW covariance data from an ENDF evaluation.
|
||||
|
|
@ -460,16 +475,16 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
# Other scatter radius parameters
|
||||
items = endf.get_cont_record(file_obj)
|
||||
target_spin = items[0]
|
||||
lcomp = items[3] # Flag for compatibility 0, 1, 2 - 2 is compact form
|
||||
lcomp = items[3] # Flag for compatibility 0, 1, 2 - 2 is compact form
|
||||
nls = items[4] # number of l-values
|
||||
|
||||
# Build covariance matrix for General Resolved Resonance Formats
|
||||
if lcomp == 1:
|
||||
items = endf.get_cont_record(file_obj)
|
||||
num_short_range = items[4] # Number of short range type resonance
|
||||
# covariances
|
||||
num_long_range = items[5] # Number of long range type resonance
|
||||
# covariances
|
||||
# Number of short range type resonance covariances
|
||||
num_short_range = items[4]
|
||||
# Number of long range type resonance covariances
|
||||
num_long_range = items[5]
|
||||
|
||||
# Read resonance widths, J values, etc
|
||||
records = []
|
||||
|
|
@ -498,7 +513,7 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
indices = np.triu_indices(cov_dim)
|
||||
cov[indices] = cov_values
|
||||
|
||||
# Create pandas DataFrame with resonance data, currently
|
||||
# Create pandas DataFrame with resonance data, currently
|
||||
# redundant with data.IncidentNeutron.resonance
|
||||
columns = ['energy', 'J', 'totalWidth', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidth']
|
||||
|
|
@ -507,11 +522,12 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
# Add parameters from File 2
|
||||
parameters = _add_file2_contributions(parameters, file2params)
|
||||
|
||||
elif lcomp == 2: # Compact format - Resonances and individual
|
||||
# uncertainties followed by compact correlations
|
||||
# Compact format - Resonances and individual uncertainties followed by
|
||||
# compact correlations
|
||||
elif lcomp == 2:
|
||||
items, values = endf.get_list_record(file_obj)
|
||||
mean = items
|
||||
num_res = items[5]
|
||||
num_res = items[5]
|
||||
energy = values[0::12]
|
||||
spin = values[1::12]
|
||||
gt = values[2::12]
|
||||
|
|
@ -525,9 +541,9 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
# DAJ/DGT always zero, DGF sometimes none zero [1, 2, 5]
|
||||
res_unc_nonzero = []
|
||||
for j in range(6):
|
||||
if j in [1, 2, 5] and res_unc[j] != 0.0 :
|
||||
if j in [1, 2, 5] and res_unc[j] != 0.0:
|
||||
res_unc_nonzero.append(res_unc[j])
|
||||
elif j in [0,3,4]:
|
||||
elif j in [0, 3, 4]:
|
||||
res_unc_nonzero.append(res_unc[j])
|
||||
par_unc.extend(res_unc_nonzero)
|
||||
|
||||
|
|
@ -549,11 +565,11 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
nparams, params = parameters.shape
|
||||
covsize = cov.shape[0]
|
||||
mpar = int(covsize/nparams)
|
||||
|
||||
|
||||
# Add parameters from File 2
|
||||
parameters = _add_file2_contributions(parameters, file2params)
|
||||
|
||||
elif lcomp == 0 :
|
||||
elif lcomp == 0:
|
||||
cov = np.zeros([4, 4])
|
||||
records = []
|
||||
cov_index = 0
|
||||
|
|
@ -576,12 +592,11 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
cov[cov_index+3, cov_index+3] = cov_values[6]
|
||||
|
||||
cov_index += 4
|
||||
if j < num_res-1: # Pad matrix for additional values
|
||||
if j < num_res-1: # Pad matrix for additional values
|
||||
cov = np.pad(cov, ((0, 4), (0, 4)), 'constant',
|
||||
constant_values=0)
|
||||
|
||||
|
||||
# Create pandas DataFrame with resonance data, currently
|
||||
# Create pandas DataFrame with resonance data, currently
|
||||
# redundant with data.IncidentNeutron.resonance
|
||||
columns = ['energy', 'J', 'totalWidth', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidth']
|
||||
|
|
@ -624,15 +639,17 @@ class SingleLevelBreitWignerCovariance(MultiLevelBreitWignerCovariance):
|
|||
covariance : numpy.array
|
||||
The covariance matrix contained within the ENDF evaluation
|
||||
lcomp : int
|
||||
Flag indicating the format of the covariance matrix within the ENDF file
|
||||
Flag indicating format of the covariance matrix within the ENDF file
|
||||
mpar : int
|
||||
Number of parameters in covariance matrix for each individual resonance
|
||||
formalism : str
|
||||
String descriptor of formalism
|
||||
"""
|
||||
|
||||
def __init__(self, energy_min, energy_max, parameters, covariance, mpar, lcomp):
|
||||
super().__init__(energy_min, energy_max, parameters, covariance, mpar, lcomp)
|
||||
def __init__(self, energy_min, energy_max, parameters, covariance, mpar,
|
||||
lcomp):
|
||||
super().__init__(energy_min, energy_max, parameters, covariance, mpar,
|
||||
lcomp)
|
||||
self.formalism = 'slbw'
|
||||
|
||||
|
||||
|
|
@ -660,14 +677,15 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
covariance : numpy.array
|
||||
The covariance matrix contained within the ENDF evaluation
|
||||
lcomp : int
|
||||
Flag indicating the format of the covariance matrix within the ENDF file
|
||||
Flag indicating format of the covariance matrix within the ENDF file
|
||||
mpar : int
|
||||
Number of parameters in covariance matrix for each individual resonance
|
||||
formalism : str
|
||||
String descriptor of formalism
|
||||
"""
|
||||
|
||||
def __init__(self, energy_min, energy_max, parameters, covariance, mpar, lcomp):
|
||||
def __init__(self, energy_min, energy_max, parameters, covariance, mpar,
|
||||
lcomp):
|
||||
super().__init__(energy_min, energy_max)
|
||||
self.parameters = parameters
|
||||
self.covariance = covariance
|
||||
|
|
@ -677,8 +695,9 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
|
||||
@classmethod
|
||||
def from_endf(cls, ev, file_obj, items, file2params):
|
||||
"""Create Reich-Moore resonance covariance data from an ENDF evaluation.
|
||||
Includes the resonance parameters contained separately in File 32.
|
||||
"""Create Reich-Moore resonance covariance data from an ENDF
|
||||
evaluation. Includes the resonance parameters contained separately in
|
||||
File 32.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
@ -691,8 +710,8 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
Items from the CONT record at the start of the resonance range
|
||||
subsection
|
||||
resonances : openmc.data.Resonance object
|
||||
openmc.data.Resonanance object generated from the same evaluation used
|
||||
to import values not contained in File 32
|
||||
openmc.data.Resonanance object generated from the same evaluation
|
||||
used to import values not contained in File 32
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
@ -712,14 +731,13 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
lcomp = items[3] # Flag for compatibility 0, 1, 2 - 2 is compact form
|
||||
nls = items[4] # Number of l-values
|
||||
|
||||
|
||||
# Build covariance matrix for General Resolved Resonance Formats
|
||||
if lcomp == 1:
|
||||
items = endf.get_cont_record(file_obj)
|
||||
num_short_range = items[4] # Number of short range type resonance
|
||||
# covariances
|
||||
num_long_range = items[5] # Number of long range type resonance
|
||||
# covariances
|
||||
# Number of short range type resonance covariances
|
||||
num_short_range = items[4]
|
||||
# Number of long range type resonance covariances
|
||||
num_long_range = items[5]
|
||||
# Read resonance widths, J values, etc
|
||||
channel_radius = {}
|
||||
scattering_radius = {}
|
||||
|
|
@ -731,7 +749,7 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
num_par_vals = num_res*6
|
||||
res_values = values[:num_par_vals]
|
||||
cov_values = values[num_par_vals:]
|
||||
|
||||
|
||||
energy = res_values[0::6]
|
||||
spin = res_values[1::6]
|
||||
gn = res_values[2::6]
|
||||
|
|
@ -745,7 +763,7 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
|
||||
# Build the upper-triangular covariance matrix
|
||||
cov_dim = mpar*num_res
|
||||
cov = np.zeros([cov_dim,cov_dim])
|
||||
cov = np.zeros([cov_dim, cov_dim])
|
||||
indices = np.triu_indices(cov_dim)
|
||||
cov[indices] = cov_values
|
||||
|
||||
|
|
@ -757,10 +775,11 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
# Add parameters from File 2
|
||||
parameters = _add_file2_contributions(parameters, file2params)
|
||||
|
||||
elif lcomp == 2: # Compact format - Resonances and individual
|
||||
# uncertainties followed by compact correlations
|
||||
# Compact format - Resonances and individual uncertainties followed by
|
||||
# compact correlations
|
||||
elif lcomp == 2:
|
||||
items, values = endf.get_list_record(file_obj)
|
||||
num_res = items[5]
|
||||
num_res = items[5]
|
||||
energy = values[0::12]
|
||||
spin = values[1::12]
|
||||
gn = values[2::12]
|
||||
|
|
@ -789,7 +808,7 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
|
||||
# Determine mpar (number of parameters for each resonance in
|
||||
# covariance matrix)
|
||||
nparams,params = parameters.shape
|
||||
nparams, params = parameters.shape
|
||||
covsize = cov.shape[0]
|
||||
mpar = int(covsize/nparams)
|
||||
|
||||
|
|
@ -800,6 +819,7 @@ class ReichMooreCovariance(ResonanceCovarianceRange):
|
|||
rmc = cls(energy_min, energy_max, parameters, cov, mpar, lcomp)
|
||||
return rmc
|
||||
|
||||
|
||||
_FORMALISMS = {
|
||||
0: ResonanceCovarianceRange,
|
||||
1: SingleLevelBreitWignerCovariance,
|
||||
|
|
@ -807,6 +827,3 @@ _FORMALISMS = {
|
|||
3: ReichMooreCovariance
|
||||
# 7: RMatrixLimitedCovariance
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue