From 714f4ff2cc0706e706cbe4e29f293bcfb195a60b Mon Sep 17 00:00:00 2001 From: Sam Shaner Date: Tue, 22 Dec 2015 14:10:13 -0800 Subject: [PATCH] removed num_score_bins from tallies.py and removed duplicate scores from tests --- openmc/statepoint.py | 7 +-- openmc/summary.py | 2 - openmc/tallies.py | 68 +++++++++---------------- tests/test_many_scores/results_true.dat | 12 ----- tests/test_many_scores/tallies.xml | 6 +-- tests/test_score_MT/inputs_true.dat | 2 +- tests/test_score_MT/results_true.dat | 24 --------- tests/test_score_MT/test_score_MT.py | 1 - 8 files changed, 29 insertions(+), 93 deletions(-) diff --git a/openmc/statepoint.py b/openmc/statepoint.py index 1ff0584a7..4c1737963 100644 --- a/openmc/statepoint.py +++ b/openmc/statepoint.py @@ -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 diff --git a/openmc/summary.py b/openmc/summary.py index 4b1088e82..c14f9073d 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -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 diff --git a/openmc/tallies.py b/openmc/tallies.py index cd7bc338e..dfc03d50a 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -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 diff --git a/tests/test_many_scores/results_true.dat b/tests/test_many_scores/results_true.dat index 0d5dd6e32..ae5430e30 100644 --- a/tests/test_many_scores/results_true.dat +++ b/tests/test_many_scores/results_true.dat @@ -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 diff --git a/tests/test_many_scores/tallies.xml b/tests/test_many_scores/tallies.xml index 2df5597d0..b8a154f1a 100644 --- a/tests/test_many_scores/tallies.xml +++ b/tests/test_many_scores/tallies.xml @@ -4,9 +4,9 @@ - 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 diff --git a/tests/test_score_MT/inputs_true.dat b/tests/test_score_MT/inputs_true.dat index 3789a69cb..b361c28cf 100644 --- a/tests/test_score_MT/inputs_true.dat +++ b/tests/test_score_MT/inputs_true.dat @@ -1 +1 @@ -63295b9d510370e65e63a3db627d47d286f5479e53c8eabeda9a5cb25ffe35becb636835aadad11691e34c23292fe11b5f688daee76d76ceac4b5dfd2f9ede4c \ No newline at end of file +7270299e4a4dde19d250825b0124fa36b60df847f046e058ccdfc74d4690beaaaaf387e050f596cb3445caf793d6a390ddb2d19650a3dccd4eb60056ae3b1477 \ No newline at end of file diff --git a/tests/test_score_MT/results_true.dat b/tests/test_score_MT/results_true.dat index 44656963f..04b9c5ca5 100644 --- a/tests/test_score_MT/results_true.dat +++ b/tests/test_score_MT/results_true.dat @@ -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 diff --git a/tests/test_score_MT/test_score_MT.py b/tests/test_score_MT/test_score_MT.py index dae86d418..fb8aa7cfb 100644 --- a/tests/test_score_MT/test_score_MT.py +++ b/tests/test_score_MT/test_score_MT.py @@ -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]