Skip to content

Commit 2a7df99

Browse files
author
Andrew Johnson
authored
Merge pull request #366 from drewejohnson/bug-sens-ngen
Don't overwrite sensitivity data with _N_GEN variables
2 parents 69c57a5 + 6d4958e commit 2a7df99

File tree

3 files changed

+90
-31
lines changed

3 files changed

+90
-31
lines changed

serpentTools/data/bwr_sens0.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@
7676
ADJ_PERT_KEFF_SENS_E_INT = reshape(ADJ_PERT_KEFF_SENS_E_INT, [2, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
7777
ADJ_PERT_KEFF_SENS_E_INT = permute(ADJ_PERT_KEFF_SENS_E_INT, [4, 3, 2, 1]);
7878

79+
% Effective multiplication factor:
80+
81+
ADJ_PERT_KEFF_SENS_1_GEN = [
82+
0.00000E+00 0.0E+00 8.70984E-02 2.1E-01 -5.39529E-03 7.9E-01 -1.93425E-04 1.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 -5.16380E-03 7.6E-01 -6.34126E-02 8.1E-02 -5.09998E-02 9.0E-02 3.02727E-01 6.0E-02 1.43519E-01 8.3E-02 0.00000E+00 0.0E+00 -6.34103E-05 1.0E+00 -2.55744E-02 4.9E-01 -1.08870E-01 4.0E-01 7.10802E-03 1.0E+00 -1.57546E-02 1.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 -2.26180E-02 7.0E-01 -3.26824E-02 1.2E-01 -1.20262E-01 8.3E-02 0.00000E+00 0.0E+00 4.75881E-02 1.1E-01 0.00000E+00 0.0E+00 2.17649E-03 5.3E-01
83+
];
84+
85+
ADJ_PERT_KEFF_SENS_1_GEN = reshape(ADJ_PERT_KEFF_SENS_1_GEN, [2, SENS_N_ENE, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
86+
ADJ_PERT_KEFF_SENS_1_GEN = permute(ADJ_PERT_KEFF_SENS_1_GEN, [5, 4, 3, 2, 1]);
87+
88+
ADJ_PERT_KEFF_SENS_1_GEN_E_INT = [
89+
0.00000E+00 0.0E+00 -5.58871E-03 1.0E+00 0.00000E+00 0.0E+00 -5.16380E-03 7.6E-01 -1.14412E-01 5.7E-02 4.46246E-01 4.2E-02 -6.34103E-05 1.0E+00 -1.34445E-01 3.4E-01 -8.64658E-03 1.0E+00 0.00000E+00 0.0E+00 -2.26180E-02 7.0E-01 -1.52945E-01 7.3E-02 4.75881E-02 1.1E-01 2.17649E-03 5.3E-01
90+
];
91+
92+
ADJ_PERT_KEFF_SENS_1_GEN_E_INT = reshape(ADJ_PERT_KEFF_SENS_1_GEN_E_INT, [2, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
93+
ADJ_PERT_KEFF_SENS_1_GEN_E_INT = permute(ADJ_PERT_KEFF_SENS_1_GEN_E_INT, [4, 3, 2, 1]);
94+
7995
% Reaction rate ratio:
8096

8197
ADJ_PERT_fis2flx_SENS = [
@@ -92,3 +108,17 @@
92108
ADJ_PERT_fis2flx_SENS_E_INT = reshape(ADJ_PERT_fis2flx_SENS_E_INT, [2, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
93109
ADJ_PERT_fis2flx_SENS_E_INT = permute(ADJ_PERT_fis2flx_SENS_E_INT, [4, 3, 2, 1]);
94110

111+
ADJ_PERT_fis2flx_SENS_1_GEN = [
112+
0.00000E+00 0.0E+00 -1.04396E-01 1.3E-01 8.14309E-04 1.0E+00 -1.89700E-03 1.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 5.08970E-03 6.8E-01 -3.80915E-02 1.5E-01 -3.32722E-02 1.5E-01 -2.24098E-01 7.4E-02 -7.40533E-02 1.5E-01 0.00000E+00 0.0E+00 -2.63575E-04 1.0E+00 -1.82609E-02 8.5E-01 9.13794E-03 1.0E+00 1.05618E-02 1.0E+00 2.10562E-02 1.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 0.00000E+00 0.0E+00 4.73019E-02 4.0E-01 -2.88227E-02 1.3E-01 -7.02287E-02 1.1E-01 0.00000E+00 0.0E+00 1.05040E-02 6.8E-01 0.00000E+00 0.0E+00 5.04490E-04 1.0E+00
113+
];
114+
115+
ADJ_PERT_fis2flx_SENS_1_GEN = reshape(ADJ_PERT_fis2flx_SENS_1_GEN, [2, SENS_N_ENE, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
116+
ADJ_PERT_fis2flx_SENS_1_GEN = permute(ADJ_PERT_fis2flx_SENS_1_GEN, [5, 4, 3, 2, 1]);
117+
118+
ADJ_PERT_fis2flx_SENS_1_GEN_E_INT = [
119+
0.00000E+00 0.0E+00 -1.08269E-03 1.0E+00 0.00000E+00 0.0E+00 5.08970E-03 6.8E-01 -7.13637E-02 1.1E-01 -2.98151E-01 6.5E-02 -2.63575E-04 1.0E+00 -9.12298E-03 1.0E+00 3.16180E-02 1.0E+00 0.00000E+00 0.0E+00 4.73019E-02 4.0E-01 -9.90513E-02 8.8E-02 1.05040E-02 6.8E-01 5.04490E-04 1.0E+00
120+
];
121+
122+
ADJ_PERT_fis2flx_SENS_1_GEN_E_INT = reshape(ADJ_PERT_fis2flx_SENS_1_GEN_E_INT, [2, SENS_N_PERT, SENS_N_ZAI, SENS_N_MAT]);
123+
ADJ_PERT_fis2flx_SENS_1_GEN_E_INT = permute(ADJ_PERT_fis2flx_SENS_1_GEN_E_INT, [4, 3, 2, 1]);
124+

serpentTools/parsers/sensitivity.py

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,44 +56,45 @@ class SensitivityReader(BaseReader):
5656
5757
Parameters
5858
----------
59-
filePath: str
59+
filePath : str
6060
Path to sensitivity file
6161
6262
Attributes
6363
----------
64-
nMat: None or int
64+
nMat : None or int
6565
Number of materials
66-
nZai: None or int
66+
nZai : None or int
6767
Number of perturbed isotopes
68-
nPert: None or int
68+
nPert : None or int
6969
Number of perturbations
70-
nEne: None or int
70+
nEne : None or int
7171
Number of energy groups
72-
nMu: None or int
72+
nMu : None or int
7373
Number of perturbed materials
74-
materials: :py:class:`~collections.OrderedDict`
74+
materials : :class:`~collections.OrderedDict`
7575
Ordered dictionary of materials that have
7676
been perturbed.
77-
zais: :py:class:`~collections.OrderedDict`
77+
zais : :class:`~collections.OrderedDict`
7878
Ordered dictionary of nuclides that
7979
have been perturbed
80-
perts: :py:class:`~collections.OrderedDict`
80+
perts : :class:`~collections.OrderedDict`
8181
Ordered dictionary of reactions that
8282
have been perturbed, e.g `'total xs'`
83-
latGen: int
83+
latGen : int
8484
Number of latent generations used to generate
8585
these sensitivities
86-
energies: None or :py:class:`numpy.array`
86+
energies : None or :class:`numpy.array`
8787
Array of energy bounds for the sensitivities, from
8888
lowest to highest
89-
lethargyWidths: None or :py:class:`numpy.array`
89+
lethargyWidths : None or :class:`numpy.array`
9090
Array of lethargy widths of each energy group.
91-
sensitivities: dict
91+
sensitivities : dict
9292
Dictionary of names of sensitivities and their corresponding
9393
arrays.
94-
energyIntegratedSens: dict
94+
energyIntegratedSens : dict
9595
Dictionary of names of the sensitivities that have been integrated
9696
against energy, and their corresponding arrays
97+
9798
"""
9899

99100
_RECONVERT_ATTR_MAP = {
@@ -143,18 +144,18 @@ def _read(self):
143144
if not throughParams:
144145
chunk0 = chunk[0]
145146
if 'Number' in chunk0:
146-
self.__processNumChunk(chunk)
147+
self._processNumChunk(chunk)
147148
elif 'included' in chunk0:
148149
what = chunk0.split()[1]
149-
self.__processIndexChunk(what, chunk)
150+
self._processIndexChunk(what, chunk)
150151
elif 'energy' in chunk0:
151-
self.__processEnergyChunk(chunk)
152+
self._processEnergyChunk(chunk)
152153
elif 'latent' in chunk0:
153154
split = chunk0.split()
154155
self.latGen = int(split[split.index('latent') - 1])
155156
throughParams = True
156157
continue
157-
self.__processSensChunk(chunk)
158+
self._processSensChunk(chunk)
158159
if self.zais:
159160
old = self.zais
160161
self.zais = OrderedDict()
@@ -164,7 +165,7 @@ def _read(self):
164165
continue
165166
self.zais[int(key)] = value
166167

167-
def __processNumChunk(self, chunk):
168+
def _processNumChunk(self, chunk):
168169
chunk = [line for line in chunk if 'SENS' in line]
169170
for line in chunk:
170171
split = line.split()
@@ -176,7 +177,7 @@ def __processNumChunk(self, chunk):
176177
'Attempted to set attribute {} from number block'.format(
177178
attrN))
178179

179-
def __processIndexChunk(self, what, chunk):
180+
def _processIndexChunk(self, what, chunk):
180181
key = what.lower()
181182
if key not in self._indxMap:
182183
raise SerpentToolsException(
@@ -203,7 +204,7 @@ def __processIndexChunk(self, what, chunk):
203204
raise SerpentToolsException(
204205
"Unexpected index chunk {}".format(chunk))
205206

206-
def __processEnergyChunk(self, chunk):
207+
def _processEnergyChunk(self, chunk):
207208
for line in chunk:
208209
if 'SENS' == line[:4]:
209210
break
@@ -221,7 +222,7 @@ def __processEnergyChunk(self, chunk):
221222
warning("Unanticipated energy setting {}"
222223
.format(splitLine[0]))
223224

224-
def __processSensChunk(self, chunk):
225+
def _processSensChunk(self, chunk):
225226
varName = None
226227
isEnergyIntegrated = False
227228
varName = None
@@ -230,16 +231,44 @@ def __processSensChunk(self, chunk):
230231
continue
231232
if line[:3] == 'ADJ':
232233
fullVarName = line.split()[0]
233-
split = fullVarName.split('_')
234-
pertIndx = split.index('PERT')
235-
sensIndx = split.index('SENS')
236-
varName = '_'.join(split[pertIndx + 1: sensIndx])
237-
isEnergyIntegrated = split[-2:] == ['E', 'INT']
234+
nameProps = self._getAdjVarProps(fullVarName.split("_"))
235+
varName = nameProps.get("name")
236+
237+
if varName is None:
238+
raise ValueError(
239+
"Cannot get response name from {}".format(fullVarName))
240+
241+
isEnergyIntegrated = nameProps.get("energyFlag", False)
242+
latentGen = nameProps.get("latent")
243+
238244
elif varName is not None:
239-
self.__addSens(varName, str2vec(line), isEnergyIntegrated)
245+
self._addSens(
246+
varName, str2vec(line), isEnergyIntegrated, latentGen)
240247
varName = None
241248

242-
def __addSens(self, varName, vec, isEnergyIntegrated):
249+
@staticmethod
250+
def _getAdjVarProps(parts):
251+
props = {}
252+
nameStart = None
253+
254+
for ix, word in enumerate(parts):
255+
if word == "PERT":
256+
nameStart = ix + 1
257+
elif word == "SENS":
258+
if nameStart is None:
259+
raise ValueError(
260+
"Cannot get response name from {}".format(parts))
261+
props["name"] = "_".join(parts[nameStart:ix])
262+
elif word == "INT":
263+
props["energyFlag"] = (parts[ix - 1] == "E")
264+
elif word == "GEN":
265+
props["latent"] = int(parts[ix - 1])
266+
267+
return props
268+
269+
def _addSens(self, varName, vec, isEnergyIntegrated, latentGen):
270+
if latentGen is not None:
271+
return
243272
dest = (self.energyIntegratedSens if isEnergyIntegrated
244273
else self.sensitivities)
245274
newShape = [2, self.nPert, self.nZai, self.nMat]

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def getDataFiles():
3333
'Natural Language :: English',
3434
'Programming Language :: Python',
3535
'Programming Language :: Python :: 3.5',
36-
'Programming Language :: Python :: 3.6'
37-
'Programming Language :: Python :: 3.7'
36+
'Programming Language :: Python :: 3.6',
37+
'Programming Language :: Python :: 3.7',
3838
]
3939

4040
with open('./requirements.txt') as req:

0 commit comments

Comments
 (0)