mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Style and changed sampling to produce ResonanceRange objects
This commit is contained in:
parent
1beab30db6
commit
c22b36e0c8
4 changed files with 113 additions and 111 deletions
File diff suppressed because one or more lines are too long
|
|
@ -233,7 +233,7 @@ class IncidentNeutron(EqualityMixin):
|
|||
|
||||
@property
|
||||
def resonance_covariance(self):
|
||||
return self._resoncance_covariance
|
||||
return self._resonance_covariance
|
||||
|
||||
@property
|
||||
def summed_reactions(self):
|
||||
|
|
@ -298,8 +298,9 @@ class IncidentNeutron(EqualityMixin):
|
|||
|
||||
@resonance_covariance.setter
|
||||
def resonance_covariance(self, resonance_covariance):
|
||||
cv.check_type('resonances', resonances, res_cov.ResonanceCovariance)
|
||||
self._resonacne_covariance = resonance_covariance
|
||||
cv.check_type('resonance covariance', resonance_covariance,
|
||||
res_cov.ResonanceCovariances)
|
||||
self._resonance_covariance = resonance_covariance
|
||||
|
||||
@summed_reactions.setter
|
||||
def summed_reactions(self, summed_reactions):
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from collections import defaultdict, MutableSequence, Iterable
|
||||
import warnings
|
||||
import io
|
||||
import copy
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
|
@ -55,13 +56,6 @@ class ResonanceCovariances(Resonances):
|
|||
Distinct energy ranges for resonance data
|
||||
"""
|
||||
|
||||
def __init__(self, ranges):
|
||||
self.ranges = ranges
|
||||
|
||||
def __iter__(self):
|
||||
for r in self.ranges:
|
||||
yield r
|
||||
|
||||
@property
|
||||
def ranges(self):
|
||||
return self._ranges
|
||||
|
|
@ -204,13 +198,16 @@ class ResonanceCovarianceRange:
|
|||
self.parameters_subset = parameters_subset
|
||||
self.cov_subset = cov_subset
|
||||
|
||||
def sample_resonance_parameters(self, n_samples, use_subset=False):
|
||||
"""Return a IncidentNeutron object with n_samples of xs
|
||||
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
|
||||
|
||||
|
|
@ -236,7 +233,6 @@ class ResonanceCovarianceRange:
|
|||
mpar = self.mpar
|
||||
samples = []
|
||||
|
||||
|
||||
# Handling MLBW sampling
|
||||
if formalism == 'mlbw' or formalism == 'slbw':
|
||||
if mpar == 3:
|
||||
|
|
@ -258,9 +254,11 @@ class ResonanceCovarianceRange:
|
|||
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']
|
||||
'captureWidth', 'fissionWidth', 'competitiveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
samples.append(sample_params)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
elif mpar == 4:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth', 'fissionWidth']
|
||||
|
|
@ -281,9 +279,11 @@ class ResonanceCovarianceRange:
|
|||
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']
|
||||
'captureWidth', 'fissionWidth', 'competitiveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
samples.append(sample_params)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
elif mpar == 5:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth',
|
||||
|
|
@ -305,9 +305,11 @@ class ResonanceCovarianceRange:
|
|||
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']
|
||||
'captureWidth', 'fissionWidth', 'competitveWidth']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
samples.append(sample_params)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
# Handling RM Sampling
|
||||
if formalism == 'rm':
|
||||
|
|
@ -331,7 +333,9 @@ class ResonanceCovarianceRange:
|
|||
columns = ['energy', 'L', 'J', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidthA', 'fissionWidthB']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
samples.append(sample_params)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
elif mpar == 5:
|
||||
param_list = ['energy', 'neutronWidth', 'captureWidth',
|
||||
|
|
@ -354,38 +358,12 @@ class ResonanceCovarianceRange:
|
|||
columns = ['energy', 'L', 'J', 'neutronWidth',
|
||||
'captureWidth', 'fissionWidthA', 'fissionWidthB']
|
||||
sample_params = pd.DataFrame.from_records(records, columns=columns)
|
||||
samples.append(sample_params)
|
||||
res_range = copy.copy(resonances)
|
||||
res_range.parameters = sample_params
|
||||
samples.append(res_range)
|
||||
|
||||
self.samples = samples
|
||||
|
||||
def reconstruct(self, energies, resonances, sampleN):
|
||||
"""Evaluate the cross section at specified energies for an already
|
||||
sampled set of resonance parameters.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
energies : float or Iterable of float
|
||||
Energies at which the cross section should be evaluated
|
||||
resonances : openmc.data.Resonance object
|
||||
Corresponding resonance range with File 2 data. Used for
|
||||
reconstruction method
|
||||
sampleN : int
|
||||
Index of sample of resonance parameters to be used
|
||||
|
||||
Returns
|
||||
-------
|
||||
3-tuple of float or numpy.ndarray
|
||||
Elastic, capture, and fission cross sections at the specified
|
||||
energies
|
||||
|
||||
"""
|
||||
if self.samples[sampleN] is None:
|
||||
raise ValueError("Sample of resonance parameters has not been set.")
|
||||
sample_parameters = self.samples[sampleN]
|
||||
xs_array = resonances.reconstruct(energies, use_sample = True,
|
||||
sample_parameters = sample_parameters)
|
||||
return xs_array
|
||||
|
||||
|
||||
class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
||||
"""Multi-level Breit-Wigner resolved resonance formalism covariance data.
|
||||
|
|
@ -436,7 +414,9 @@ class MultiLevelBreitWignerCovariance(ResonanceCovarianceRange):
|
|||
items : list
|
||||
Items from the CONT record at the start of the resonance range
|
||||
subsection
|
||||
resonances : openmc.data.IncidentNeutron.Resonance object
|
||||
file2params : openmc.data.ResonanceRange object
|
||||
Corresponding resonance range with File 2 data. Used for
|
||||
reconstruction method
|
||||
|
||||
Returns
|
||||
-------
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def sm150():
|
|||
def gd154():
|
||||
"""Gd154 ENDF data (contains Reich Moore resonance range)"""
|
||||
filename = os.path.join(_ENDF_DATA, 'neutrons', 'n-064_Gd_154.endf')
|
||||
return openmc.data.IncidentNeutron.from_endf(filename, get_covariance = True)
|
||||
return openmc.data.IncidentNeutron.from_endf(filename, covariance = True)
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
|
|
@ -96,11 +96,12 @@ def am244():
|
|||
endf_file = os.path.join(_ENDF_DATA, 'neutrons', 'n-095_Am_244.endf')
|
||||
return openmc.data.IncidentNeutron.from_njoy(endf_file)
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def ti50():
|
||||
"""Ti50 ENDF data (contains Multi-level Breit-Wigner resonance range)"""
|
||||
filename = os.path.join(_ENDF_DATA, 'neutrons', 'n-022_Ti_050.endf')
|
||||
return openmc.data.IncidentNeutron.from_endf(filename, get_covariance=True)
|
||||
return openmc.data.IncidentNeutron.from_endf(filename, covariance=True)
|
||||
|
||||
|
||||
def test_attributes(pu239):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue