mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 05:05:30 -04:00
removed num_score_bins from tallies.py and removed duplicate scores from tests
This commit is contained in:
parent
d713cc0575
commit
714f4ff2cc
8 changed files with 29 additions and 93 deletions
|
|
@ -391,11 +391,6 @@ class StatePoint(object):
|
|||
nuclide = openmc.Nuclide(name.decode().strip())
|
||||
tally.add_nuclide(nuclide)
|
||||
|
||||
# Read score bins
|
||||
n_score_bins = self._f['{0}{1}/n_score_bins'.format(base, tally_key)].value
|
||||
|
||||
tally.num_score_bins = n_score_bins
|
||||
|
||||
scores = self._f['{0}{1}/score_bins'.format(
|
||||
base, tally_key)].value
|
||||
n_user_scores = self._f['{0}{1}/n_user_score_bins'
|
||||
|
|
@ -404,7 +399,7 @@ class StatePoint(object):
|
|||
# Compute and set the filter strides
|
||||
for i in range(n_filters):
|
||||
filter = tally.filters[i]
|
||||
filter.stride = n_score_bins * len(nuclide_names)
|
||||
filter.stride = n_user_scores * len(nuclide_names)
|
||||
|
||||
for j in range(i+1, n_filters):
|
||||
filter.stride *= tally.filters[j].num_bins
|
||||
|
|
|
|||
|
|
@ -524,8 +524,6 @@ class Summary(object):
|
|||
scores = self._f['{0}/score_bins'.format(subbase)].value
|
||||
for score in scores:
|
||||
tally.add_score(score.decode())
|
||||
num_score_bins = self._f['{0}/n_score_bins'.format(subbase)][...]
|
||||
tally.num_score_bins = num_score_bins
|
||||
|
||||
# Read filter metadata
|
||||
num_filters = self._f['{0}/n_filters'.format(subbase)].value
|
||||
|
|
|
|||
|
|
@ -65,10 +65,6 @@ class Tally(object):
|
|||
Type of estimator for the tally
|
||||
triggers : list of openmc.trigger.Trigger
|
||||
List of tally triggers
|
||||
num_score_bins : Integral
|
||||
Total number of scores, accounting for the fact that a single
|
||||
user-specified score, e.g. scatter-P3 or flux-Y2,2, might have multiple
|
||||
bins
|
||||
num_scores : Integral
|
||||
Total number of user-specified scores
|
||||
num_filter_bins : Integral
|
||||
|
|
@ -101,7 +97,6 @@ class Tally(object):
|
|||
self._estimator = None
|
||||
self._triggers = []
|
||||
|
||||
self._num_score_bins = 0
|
||||
self._num_realizations = 0
|
||||
self._with_summary = False
|
||||
|
||||
|
|
@ -124,7 +119,6 @@ class Tally(object):
|
|||
clone.id = self.id
|
||||
clone.name = self.name
|
||||
clone.estimator = self.estimator
|
||||
clone.num_score_bins = self.num_score_bins
|
||||
clone.num_realizations = self.num_realizations
|
||||
clone._sum = copy.deepcopy(self._sum, memo)
|
||||
clone._sum_sq = copy.deepcopy(self._sum_sq, memo)
|
||||
|
|
@ -253,10 +247,6 @@ class Tally(object):
|
|||
def num_scores(self):
|
||||
return len(self._scores)
|
||||
|
||||
@property
|
||||
def num_score_bins(self):
|
||||
return self._num_score_bins
|
||||
|
||||
@property
|
||||
def num_filter_bins(self):
|
||||
num_bins = 1
|
||||
|
|
@ -270,7 +260,7 @@ class Tally(object):
|
|||
def num_bins(self):
|
||||
num_bins = self.num_filter_bins
|
||||
num_bins *= self.num_nuclides
|
||||
num_bins *= self.num_score_bins
|
||||
num_bins *= self.num_scores
|
||||
return num_bins
|
||||
|
||||
@property
|
||||
|
|
@ -313,7 +303,7 @@ class Tally(object):
|
|||
# Reshape the results arrays
|
||||
new_shape = (nonzero(self.num_filter_bins),
|
||||
nonzero(self.num_nuclides),
|
||||
nonzero(self.num_score_bins))
|
||||
nonzero(self.num_scores))
|
||||
|
||||
sum = np.reshape(sum, new_shape)
|
||||
sum_sq = np.reshape(sum_sq, new_shape)
|
||||
|
|
@ -459,9 +449,13 @@ class Tally(object):
|
|||
'not a string'.format(score, self.id)
|
||||
raise ValueError(msg)
|
||||
|
||||
# If the score is already in the Tally, don't add it again
|
||||
# If the score is already in the Tally, raise an error
|
||||
if score in self.scores:
|
||||
return
|
||||
msg = 'Unable to add a duplicate score {0} to Tally ID="{1}" ' \
|
||||
'since duplicate scores are not supported in the OpenMC ' \
|
||||
'Python API'.format(score, self.id)
|
||||
raise ValueError(msg)
|
||||
|
||||
# Normal score strings
|
||||
if isinstance(score, basestring):
|
||||
self._scores.append(score.strip())
|
||||
|
|
@ -469,10 +463,6 @@ class Tally(object):
|
|||
else:
|
||||
self._scores.append(score)
|
||||
|
||||
@num_score_bins.setter
|
||||
def num_score_bins(self, num_score_bins):
|
||||
self._num_score_bins = num_score_bins
|
||||
|
||||
@num_realizations.setter
|
||||
def num_realizations(self, num_realizations):
|
||||
cv.check_type('number of realizations', num_realizations, Integral)
|
||||
|
|
@ -1287,7 +1277,7 @@ class Tally(object):
|
|||
for filter in self.filters:
|
||||
new_shape += (filter.num_bins, )
|
||||
new_shape += (self.num_nuclides,)
|
||||
new_shape += (self.num_score_bins,)
|
||||
new_shape += (self.num_scores,)
|
||||
|
||||
# Reshape the data with one dimension for each filter
|
||||
data = np.reshape(data, new_shape)
|
||||
|
|
@ -1608,18 +1598,16 @@ class Tally(object):
|
|||
|
||||
# Add scores to the new tally
|
||||
if score_product == 'entrywise':
|
||||
new_tally.num_score_bins = self_copy.num_score_bins
|
||||
for self_score in self_copy.scores:
|
||||
new_tally.add_score(self_score)
|
||||
else:
|
||||
new_tally.num_score_bins = self_copy.num_score_bins * other_copy.num_score_bins
|
||||
all_scores = [self_copy.scores, other_copy.scores]
|
||||
for self_score, other_score in itertools.product(*all_scores):
|
||||
new_score = CrossScore(self_score, other_score, binary_op)
|
||||
new_tally.add_score(new_score)
|
||||
|
||||
# Correct each Filter's stride
|
||||
stride = new_tally.num_nuclides * new_tally.num_score_bins
|
||||
stride = new_tally.num_nuclides * new_tally.num_scores
|
||||
for filter in reversed(new_tally.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
|
@ -1727,10 +1715,10 @@ class Tally(object):
|
|||
# Repeat and tile the data by score in preparation for performing
|
||||
# the tensor product across scores.
|
||||
if score_product == 'tensor':
|
||||
self._mean = np.repeat(self.mean, other.num_score_bins, axis=2)
|
||||
self._std_dev = np.repeat(self.std_dev, other.num_score_bins, axis=2)
|
||||
other._mean = np.tile(other.mean, (1, 1, self.num_score_bins))
|
||||
other._std_dev = np.tile(other.std_dev, (1, 1, self.num_score_bins))
|
||||
self._mean = np.repeat(self.mean, other.num_scores, axis=2)
|
||||
self._std_dev = np.repeat(self.std_dev, other.num_scores, axis=2)
|
||||
other._mean = np.tile(other.mean, (1, 1, self.num_scores))
|
||||
other._std_dev = np.tile(other.std_dev, (1, 1, self.num_scores))
|
||||
|
||||
# Add scores to each tally such that each tally contains the complete set
|
||||
# of scores necessary to perform an entrywise product. New scores added
|
||||
|
|
@ -1743,16 +1731,15 @@ class Tally(object):
|
|||
|
||||
# Add scores present in self but not in other to other
|
||||
for score in other_missing_scores:
|
||||
other._mean = np.insert(other.mean, other.num_score_bins, 0, axis=2)
|
||||
other._std_dev = np.insert(other.std_dev, other.num_score_bins, 0, axis=2)
|
||||
other._mean = np.insert(other.mean, other.num_scores, 0, axis=2)
|
||||
other._std_dev = np.insert(other.std_dev, other.num_scores, 0, axis=2)
|
||||
other.add_score(score)
|
||||
|
||||
# Add scores present in other but not in self to self
|
||||
for score in self_missing_scores:
|
||||
self._mean = np.insert(self.mean, self.num_score_bins, 0, axis=2)
|
||||
self._std_dev = np.insert(self.std_dev, self.num_score_bins, 0, axis=2)
|
||||
self._mean = np.insert(self.mean, self.num_scores, 0, axis=2)
|
||||
self._std_dev = np.insert(self.std_dev, self.num_scores, 0, axis=2)
|
||||
self.add_score(score)
|
||||
self.num_score_bins += 1
|
||||
|
||||
# Align other scores with self scores
|
||||
for i, score in enumerate(self.scores):
|
||||
|
|
@ -1763,13 +1750,13 @@ class Tally(object):
|
|||
other._swap_scores(score, other.scores[i])
|
||||
|
||||
# Correct the stride for other filters
|
||||
stride = other.num_nuclides * other.num_score_bins
|
||||
stride = other.num_nuclides * other.num_scores
|
||||
for filter in reversed(other.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
||||
# Correct the stride for self filters
|
||||
stride = self.num_nuclides * self.num_score_bins
|
||||
stride = self.num_nuclides * self.num_scores
|
||||
for filter in reversed(self.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
|
@ -1835,7 +1822,7 @@ class Tally(object):
|
|||
self.filters[filter2_index] = filter1
|
||||
|
||||
# Update the strides for each of the filters
|
||||
stride = self.num_nuclides * self.num_score_bins
|
||||
stride = self.num_nuclides * self.num_scores
|
||||
for filter in reversed(self.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
|
@ -2064,7 +2051,6 @@ class Tally(object):
|
|||
new_tally.estimator = self.estimator
|
||||
new_tally.with_summary = self.with_summary
|
||||
new_tally.num_realization = self.num_realizations
|
||||
new_tally.num_score_bins = self.num_score_bins
|
||||
|
||||
for filter in self.filters:
|
||||
new_tally.add_filter(filter)
|
||||
|
|
@ -2133,7 +2119,6 @@ class Tally(object):
|
|||
new_tally.estimator = self.estimator
|
||||
new_tally.with_summary = self.with_summary
|
||||
new_tally.num_realization = self.num_realizations
|
||||
new_tally.num_score_bins = self.num_score_bins
|
||||
|
||||
for filter in self.filters:
|
||||
new_tally.add_filter(filter)
|
||||
|
|
@ -2203,7 +2188,6 @@ class Tally(object):
|
|||
new_tally.estimator = self.estimator
|
||||
new_tally.with_summary = self.with_summary
|
||||
new_tally.num_realization = self.num_realizations
|
||||
new_tally.num_score_bins = self.num_score_bins
|
||||
|
||||
for filter in self.filters:
|
||||
new_tally.add_filter(filter)
|
||||
|
|
@ -2273,7 +2257,6 @@ class Tally(object):
|
|||
new_tally.estimator = self.estimator
|
||||
new_tally.with_summary = self.with_summary
|
||||
new_tally.num_realization = self.num_realizations
|
||||
new_tally.num_score_bins = self.num_score_bins
|
||||
|
||||
for filter in self.filters:
|
||||
new_tally.add_filter(filter)
|
||||
|
|
@ -2347,7 +2330,6 @@ class Tally(object):
|
|||
new_tally.estimator = self.estimator
|
||||
new_tally.with_summary = self.with_summary
|
||||
new_tally.num_realization = self.num_realizations
|
||||
new_tally.num_score_bins = self.num_score_bins
|
||||
|
||||
for filter in self.filters:
|
||||
new_tally.add_filter(filter)
|
||||
|
|
@ -2549,7 +2531,6 @@ class Tally(object):
|
|||
# Loop over indices in reverse to remove excluded scores
|
||||
for score_index in reversed(score_indices):
|
||||
new_tally.remove_score(self.scores[score_index])
|
||||
new_tally.num_score_bins -= 1
|
||||
|
||||
# NUCLIDES
|
||||
if nuclides:
|
||||
|
|
@ -2589,7 +2570,7 @@ class Tally(object):
|
|||
filter.num_bins = len(filter_bins[i])
|
||||
|
||||
# Correct each Filter's stride
|
||||
stride = new_tally.num_nuclides * new_tally.num_score_bins
|
||||
stride = new_tally.num_nuclides * new_tally.num_scores
|
||||
for filter in reversed(new_tally.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
|
@ -2735,8 +2716,7 @@ class Tally(object):
|
|||
# Determine the shape of data in the new diagonalized Tally
|
||||
num_filter_bins = new_tally.num_filter_bins
|
||||
num_nuclides = new_tally.num_nuclides
|
||||
num_score_bins = new_tally.num_score_bins
|
||||
new_shape = (num_filter_bins, num_nuclides, num_score_bins)
|
||||
new_shape = (num_filter_bins, num_nuclides, num_scores)
|
||||
|
||||
# Determine "base" indices along the new "diagonal", and the factor
|
||||
# by which the "base" indices should be repeated to account for all
|
||||
|
|
@ -2766,7 +2746,7 @@ class Tally(object):
|
|||
new_tally._std_dev[diag_indices, :, :] = self.std_dev
|
||||
|
||||
# Correct each Filter's stride
|
||||
stride = new_tally.num_nuclides * new_tally.num_score_bins
|
||||
stride = new_tally.num_nuclides * new_tally.num_scores
|
||||
for filter in reversed(new_tally.filters):
|
||||
filter.stride = stride
|
||||
stride *= filter.num_bins
|
||||
|
|
|
|||
|
|
@ -11,18 +11,6 @@ tally 1:
|
|||
2.483728E+01
|
||||
5.102293E-01
|
||||
8.710841E-02
|
||||
8.628000E+00
|
||||
2.481430E+01
|
||||
9.329009E-01
|
||||
2.902534E-01
|
||||
5.102293E-01
|
||||
8.710841E-02
|
||||
5.087118E-01
|
||||
8.657086E-02
|
||||
8.632000E+00
|
||||
2.483728E+01
|
||||
9.328366E-01
|
||||
2.902108E-01
|
||||
5.087118E-01
|
||||
8.657086E-02
|
||||
9.212024E+00
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<tally id="1">
|
||||
<filter type="cell" bins="21" />
|
||||
<scores>
|
||||
flux total scatter nu-scatter scatter-2 scatter-p2 nu-scatter-2
|
||||
nu-scatter-p2 transport n1n absorption nu-fission kappa-fission
|
||||
flux-y2 total-y2 scatter-y2 nu-scatter-y2 events delayed-nu-fission
|
||||
flux total scatter nu-scatter scatter-2 nu-scatter-2 transport n1n
|
||||
absorption nu-fission kappa-fission flux-y2 total-y2 scatter-y2
|
||||
nu-scatter-y2 events delayed-nu-fission
|
||||
</scores>
|
||||
</tally>
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
63295b9d510370e65e63a3db627d47d286f5479e53c8eabeda9a5cb25ffe35becb636835aadad11691e34c23292fe11b5f688daee76d76ceac4b5dfd2f9ede4c
|
||||
7270299e4a4dde19d250825b0124fa36b60df847f046e058ccdfc74d4690beaaaaf387e050f596cb3445caf793d6a390ddb2d19650a3dccd4eb60056ae3b1477
|
||||
|
|
@ -7,10 +7,6 @@ tally 1:
|
|||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
1.538090E-03
|
||||
1.381456E-06
|
||||
1.538090E-03
|
||||
1.381456E-06
|
||||
3.974412E-01
|
||||
|
|
@ -19,16 +15,12 @@ tally 1:
|
|||
3.796357E-01
|
||||
5.252455E-06
|
||||
2.290531E-11
|
||||
5.252455E-06
|
||||
2.290531E-11
|
||||
3.359792E-02
|
||||
2.267331E-04
|
||||
2.459115E-02
|
||||
1.233078E-04
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
7.004005E-05
|
||||
1.748739E-09
|
||||
8.104946E-02
|
||||
|
|
@ -42,18 +34,12 @@ tally 2:
|
|||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
2.000000E-01
|
||||
9.000000E-03
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
2.000000E-02
|
||||
2.000000E-04
|
||||
0.000000E+00
|
||||
|
|
@ -64,8 +50,6 @@ tally 2:
|
|||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
tally 3:
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
|
|
@ -73,10 +57,6 @@ tally 3:
|
|||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
1.408027E-03
|
||||
1.849607E-06
|
||||
1.408027E-03
|
||||
1.849607E-06
|
||||
3.946436E-01
|
||||
|
|
@ -85,16 +65,12 @@ tally 3:
|
|||
3.382059E-01
|
||||
2.179241E-05
|
||||
4.749090E-10
|
||||
2.179241E-05
|
||||
4.749090E-10
|
||||
3.146594E-02
|
||||
2.159308E-04
|
||||
4.278352E-02
|
||||
4.094478E-04
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
0.000000E+00
|
||||
1.736514E-04
|
||||
1.245171E-08
|
||||
7.989710E-02
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ class ScoreMTTestHarness(PyAPITestHarness):
|
|||
filt = openmc.Filter(type='cell', bins=(10, 21, 22, 23))
|
||||
tallies = [openmc.Tally(tally_id=i) for i in range(1, 4)]
|
||||
[t.add_filter(filt) for t in tallies]
|
||||
[t.add_score('n2n') for t in tallies]
|
||||
[t.add_score('16') for t in tallies]
|
||||
[t.add_score('51') for t in tallies]
|
||||
[t.add_score('102') for t in tallies]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue