diff --git a/src/utils/statepoint.py b/src/utils/statepoint.py index 3bed0ed609..73566c3086 100644 --- a/src/utils/statepoint.py +++ b/src/utils/statepoint.py @@ -2,6 +2,8 @@ import struct +import numpy as np + filter_types = {1: 'universe', 2: 'material', 3: 'cell', 4: 'cellborn', 5: 'surface', 6: 'mesh', 7: 'energyin', 8: 'energyout'} @@ -57,6 +59,9 @@ class StatePoint(BinaryFile): def __init__(self, filename): super(StatePoint, self).__init__(filename) + # Set flag for wehther metadata was read + self._metadata = False + # Initialize arrays for meshes and tallies self.meshes = [] self.tallies = [] @@ -83,8 +88,8 @@ class StatePoint(BinaryFile): self.current_batch = self._get_int()[0] # Read batch keff and entropy - keff = self._get_double(self.current_batch) - entropy = self._get_double(self.current_batch) + self.k_batch = self._get_double(self.current_batch) + self.entropy = self._get_double(self.current_batch) # Read global tallies self.n_global_tallies = self._get_int()[0] @@ -109,7 +114,6 @@ class StatePoint(BinaryFile): m.upper_right = self._get_double(n) m.width = self._get_double(n) - # Read number of tallies n_tallies = self._get_int()[0] @@ -150,3 +154,16 @@ class StatePoint(BinaryFile): # Read score bins n_scores = self._get_int()[0] t.scores = [score_types[j] for j in self._get_int(n_scores)] + + # Set flag indicating metadata has already been read + self._metadata = True + + def read_values(self): + # Check whether metadata has been read + if not self._metadata: + self._read_metadata() + + for t in self.tallies: + n = t.n_score_bins * t.n_filter_bins + t.values = np.array(self._get_double(2*n)) + t.values.shape = (t.n_filter_bins, t.n_score_bins, 2) diff --git a/src/utils/statepoint_cmp.py b/src/utils/statepoint_cmp.py new file mode 100755 index 0000000000..5865e265ad --- /dev/null +++ b/src/utils/statepoint_cmp.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +import sys + +from numpy.testing import assert_allclose + +from statepoint import StatePoint + +if len(sys.argv) > 2: + path1 = sys.argv[1] + path2 = sys.argv[2] +else: + raise + +# Create StatePoint objects +sp1 = StatePoint(path1) +sp2 = StatePoint(path2) + +# Read tally results +sp1.read_values() +sp2.read_values() + +# Compare header information +assert sp1.revision == sp2.revision +assert sp1.version == sp2.version +assert sp1.seed == sp2.seed +assert sp1.run_mode == sp2.run_mode +assert sp1.n_particles == sp2.n_particles +assert sp1.n_batches == sp2.n_batches +assert sp1.n_inactive == sp2.n_inactive +assert sp1.gen_per_batch == sp2.gen_per_batch +assert sp1.current_batch == sp2.current_batch + +# Compare keff results +assert_allclose(sp1.k_batch, sp2.k_batch) + +# Compare entropy results +assert_allclose(sp1.entropy, sp2.entropy) + +# Compare global tallies +assert sp1.n_global_tallies == sp2.n_global_tallies +assert_allclose(sp1.global_tallies, sp2.global_tallies) + +# Compare meshes +assert len(sp1.meshes) == len(sp2.meshes) +for m1, m2 in zip(sp1.meshes, sp2.meshes): + assert m1.type == m2.type + assert m1.dimension == m2.dimension + assert m1.lower_left == m2.lower_left + assert m1.upper_right == m2.upper_right + assert m1.width == m2.width + +# Compare tallies +assert len(sp1.tallies) == len(sp2.tallies) +for t1, t2 in zip(sp1.tallies, sp2.tallies): + # Compare size of tallies + assert t1.n_score_bins == t2.n_score_bins + assert t1.n_filter_bins == t2.n_filter_bins + + # Compare filters + assert len(t1.filters) == len(t2.filters) + for f1, f2 in zip(t1.filters, t2.filters): + assert f1.type == f2.type + assert f1.length == f2.length + assert f1.bins == f2.bins + + # Compare nuclide and score bins + assert t1.nuclides == t2.nuclides + assert t1.scores == t2.scores + + # Compare tally results + assert_allclose(t1.values, t2.values)