From cc571091a3709452d3f4ae9dafac5554c4a5df73 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Sun, 31 Jan 2016 17:47:21 -0500 Subject: [PATCH 1/7] Hotfix for OpenMC-OpenCG lattice conversions with y index reversal for OpenCG --- openmc/opencg_compatible.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openmc/opencg_compatible.py b/openmc/opencg_compatible.py index 0bda48c16..a5573d9eb 100644 --- a/openmc/opencg_compatible.py +++ b/openmc/opencg_compatible.py @@ -922,6 +922,9 @@ def get_opencg_lattice(openmc_lattice): universe_id = universes[z][y][x].id universe_array[z][y][x] = unique_universes[universe_id] + # Reverse y-dimension in array to match ordering in OpenCG + universe_array = universe_array[:, ::-1, :] + opencg_lattice = opencg.Lattice(lattice_id, name) opencg_lattice.dimension = dimension opencg_lattice.width = pitch From ec05e52089cdc8506db4d09cfd253381db2959c1 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Mon, 1 Feb 2016 15:56:40 -0500 Subject: [PATCH 2/7] Fixed issue in Pandas DataFrame compatibility with OpenCG lattice indexing --- openmc/filter.py | 4 +++- openmc/opencg_compatible.py | 3 --- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openmc/filter.py b/openmc/filter.py index a0c777fa0..54814a6b6 100644 --- a/openmc/filter.py +++ b/openmc/filter.py @@ -673,9 +673,11 @@ class Filter(object): # Assign entry to Lattice Multi-index column else: + # Reverse y index per lattice ordering in OpenCG level_dict[lat_id_key][offset] = coords._lattice._id level_dict[lat_x_key][offset] = coords._lat_x - level_dict[lat_y_key][offset] = coords._lat_y + level_dict[lat_y_key][offset] = \ + coords._lattice.dimension[1] - coords._lat_y - 1 level_dict[lat_z_key][offset] = coords._lat_z # Move to next node in LocalCoords linked list diff --git a/openmc/opencg_compatible.py b/openmc/opencg_compatible.py index a5573d9eb..0bda48c16 100644 --- a/openmc/opencg_compatible.py +++ b/openmc/opencg_compatible.py @@ -922,9 +922,6 @@ def get_opencg_lattice(openmc_lattice): universe_id = universes[z][y][x].id universe_array[z][y][x] = unique_universes[universe_id] - # Reverse y-dimension in array to match ordering in OpenCG - universe_array = universe_array[:, ::-1, :] - opencg_lattice = opencg.Lattice(lattice_id, name) opencg_lattice.dimension = dimension opencg_lattice.width = pitch From e413bf30e5f6437ac3a48f78ede9ed2a834a8050 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Mon, 1 Feb 2016 19:24:43 -0500 Subject: [PATCH 3/7] Fixed issue with discrepancy in indexing of y-dimension in lattice universes and offsets --- openmc/summary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/summary.py b/openmc/summary.py index 3e10f8edb..d22e367c9 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -369,7 +369,7 @@ class Summary(object): # Set the distribcell offsets for the lattice if offsets is not None: - lattice.offsets = offsets + lattice.offsets = offsets[:, ::-1, :] # Add the Lattice to the global dictionary of all Lattices self.lattices[index] = lattice From a62dc7868f26ffcbcc8fc78129ec760257c6bc15 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Tue, 2 Feb 2016 15:53:27 -0500 Subject: [PATCH 4/7] Added test for distribcell tallies in an asymmetric lattice --- tests/test_asymmetric_lattice/inputs_true.dat | 1 + .../test_asymmetric_lattice/results_true.dat | 1 + .../test_asymmetric_lattice.py | 127 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 tests/test_asymmetric_lattice/inputs_true.dat create mode 100644 tests/test_asymmetric_lattice/results_true.dat create mode 100644 tests/test_asymmetric_lattice/test_asymmetric_lattice.py diff --git a/tests/test_asymmetric_lattice/inputs_true.dat b/tests/test_asymmetric_lattice/inputs_true.dat new file mode 100644 index 000000000..70073c6bd --- /dev/null +++ b/tests/test_asymmetric_lattice/inputs_true.dat @@ -0,0 +1 @@ +dd39c0ae6327e6e74cb077d56e37c112611b95c4c10d96203e672b3e7f928211cc991ec7ebbf9eeadabd968dcdcb651b250233169b62d43ef6994ab9a46cb34a \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/results_true.dat b/tests/test_asymmetric_lattice/results_true.dat new file mode 100644 index 000000000..d809e6409 --- /dev/null +++ b/tests/test_asymmetric_lattice/results_true.dat @@ -0,0 +1 @@ +7e75ad5b7979e65e52ce564bfbd8fac819013ef8ba35fe184569b452dd9a1ba98d267b6e33d357fdd1c943f201125ff8a4f8601147b87036525870528063dcae \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py new file mode 100644 index 000000000..7b83a590e --- /dev/null +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python + +import os +import sys +import glob +import hashlib +sys.path.insert(0, os.pardir) +from testing_harness import PyAPITestHarness +import openmc +from openmc.source import Source +from openmc.stats import Box + + +class AsymmetricLatticeTestHarness(PyAPITestHarness): + + def _build_inputs(self): + """Build an axis-asymmetric lattice of fuel assemblies""" + + # Build full core geometry from underlying input set + self._input_set.build_default_materials_and_geometry() + + # Extract all universes from the full core geometry + geometry = self._input_set.geometry.geometry + all_univs = geometry.get_all_universes() + print(all_univs.keys()) + + # Extract universes encapsulating fuel and water assemblies + water = all_univs[7] + fuel = all_univs[8] + + # Construct a 3x3 lattice of fuel assemblies + core_lat = openmc.RectLattice(name='3x3 Core Lattice', lattice_id=202) + core_lat.dimension = (3, 3) + core_lat.lower_left = (-32.13, -32.13) + core_lat.pitch = (21.42, 21.42) + core_lat.universes = [[fuel, water, water], + [fuel, fuel, fuel], + [water, water, water]] + + # Create bounding surfaces + min_x = openmc.XPlane(x0=-32.13, boundary_type='reflective') + max_x = openmc.XPlane(x0=+32.13, boundary_type='reflective') + min_y = openmc.YPlane(y0=-32.13, boundary_type='reflective') + max_y = openmc.YPlane(y0=+32.13, boundary_type='reflective') + min_z = openmc.ZPlane(z0=0, boundary_type='reflective') + max_z = openmc.ZPlane(z0=+32.13, boundary_type='reflective') + + # Define root universe + root_univ = openmc.Universe(universe_id=0, name='root universe') + root_cell = openmc.Cell(cell_id=1) + root_cell.region = +min_x & -max_x & +min_y & -max_y & +min_z & -max_z + root_cell.fill = core_lat + root_univ.add_cell(root_cell) + + # Over-ride geometry in the input set with this 3x3 lattice + self._input_set.geometry.geometry.root_universe = root_univ + + # Initialize a "distribcell" filter for the cold fuel pin cell + distrib_filter = openmc.Filter(type='distribcell', bins=[27]) + + # Initialize the tallies + tally = openmc.Tally(name='distribcell tally', tally_id=27) + tally.add_filter(distrib_filter) + tally.add_score('nu-fission') + + # Initialize the tallies file + tallies_file = openmc.TalliesFile() + tallies_file.add_tally(tally) + + # Assign the tallies file to the input set + self._input_set.tallies = tallies_file + + # Specify summary output and correct source sampling box + self._input_set.build_default_settings() + self._input_set.settings.output = {'summary': True} + self._input_set.settings.source = Source(space=Box( + [0, 0, 0], [32.13, 32.13, 32.13])) + + # Write input XML files + self._input_set.export() + + def _get_results(self, hash_output=True): + """Digest info in statepoint and summary and return as a string.""" + + # Read the statepoint file + statepoint = glob.glob(os.path.join(os.getcwd(), self._sp_name))[0] + sp = openmc.StatePoint(statepoint) + + # Read the summary file + summary = glob.glob(os.path.join(os.getcwd(), 'summary.h5'))[0] + su = openmc.Summary(summary) + sp.link_with_summary(su) + + # Extract the tally of interest + tally = sp.get_tally(name='distribcell tally') + + # Create a string of all mean, std. dev. values for both tallies + outstr = '' + outstr += ', '.join(map(str, tally.mean.flatten())) + '\n' + outstr += ', '.join(map(str, tally.std_dev.flatten())) + '\n' + + # Extract fuel assembly lattices from the summary + all_cells = su.openmc_geometry.get_all_cells() + fuel = all_cells[80].fill + core = all_cells[1].fill + + # Append a string of lattice distribcell offsets to the string + outstr += ', '.join(map(str, fuel.offsets.flatten())) + '\n' + outstr += ', '.join(map(str, core.offsets.flatten())) + '\n' + + # Hash the results if necessary + if hash_output: + sha512 = hashlib.sha512() + sha512.update(outstr.encode('utf-8')) + outstr = sha512.hexdigest() + + return outstr + + def _cleanup(self): + super(AsymmetricLatticeTestHarness, self)._cleanup() + f = os.path.join(os.getcwd(), 'tallies.xml') + if os.path.exists(f): os.remove(f) + + +if __name__ == '__main__': + harness = AsymmetricLatticeTestHarness('statepoint.10.h5', True) + harness.main() From dd18376d3f8de550ff2c0e74ea8fd7d8ee301cf9 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Wed, 3 Feb 2016 11:18:50 -0500 Subject: [PATCH 5/7] Made source only fissionable for asymmetric lattice test --- openmc/tallies.py | 2 +- tests/test_asymmetric_lattice/inputs_true.dat | 2 +- tests/test_asymmetric_lattice/results_true.dat | 2 +- .../test_asymmetric_lattice.py | 12 +++++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index 3c4d99c73..3294a1d06 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -2748,7 +2748,7 @@ class Tally(object): bin_indices.append(bin_index) num_bins += 1 - find_filter.bins = set(find_filter.bins[bin_indices]) + find_filter.bins = np.unique(find_filter.bins[bin_indices]) find_filter.num_bins = num_bins # Update the new tally's filter strides diff --git a/tests/test_asymmetric_lattice/inputs_true.dat b/tests/test_asymmetric_lattice/inputs_true.dat index 70073c6bd..552c8d039 100644 --- a/tests/test_asymmetric_lattice/inputs_true.dat +++ b/tests/test_asymmetric_lattice/inputs_true.dat @@ -1 +1 @@ -dd39c0ae6327e6e74cb077d56e37c112611b95c4c10d96203e672b3e7f928211cc991ec7ebbf9eeadabd968dcdcb651b250233169b62d43ef6994ab9a46cb34a \ No newline at end of file +fe07eb28fd0dbb56edaecd510f5e8e4db7271e5c9aecf3d880cce92b69872a0aacf825b8e88cd2e9b1ff709f578b269b1835f53cf2561a390062e1e7e03b5276 \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/results_true.dat b/tests/test_asymmetric_lattice/results_true.dat index d809e6409..0cf2315ea 100644 --- a/tests/test_asymmetric_lattice/results_true.dat +++ b/tests/test_asymmetric_lattice/results_true.dat @@ -1 +1 @@ -7e75ad5b7979e65e52ce564bfbd8fac819013ef8ba35fe184569b452dd9a1ba98d267b6e33d357fdd1c943f201125ff8a4f8601147b87036525870528063dcae \ No newline at end of file +cea61172ecad5554ef86f52d6adad6ad5e21931cf3d67feb37b8bf9d75e618786f638685e458051d4a39afe1a924fd651cf6674a88cf1f1842fd69cd851e1f17 \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py index 7b83a590e..3b9e2029b 100644 --- a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -22,7 +22,6 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): # Extract all universes from the full core geometry geometry = self._input_set.geometry.geometry all_univs = geometry.get_all_universes() - print(all_univs.keys()) # Extract universes encapsulating fuel and water assemblies water = all_univs[7] @@ -55,7 +54,7 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): # Over-ride geometry in the input set with this 3x3 lattice self._input_set.geometry.geometry.root_universe = root_univ - # Initialize a "distribcell" filter for the cold fuel pin cell + # Initialize a "distribcell" filter for the fuel pin cell distrib_filter = openmc.Filter(type='distribcell', bins=[27]) # Initialize the tallies @@ -70,11 +69,14 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): # Assign the tallies file to the input set self._input_set.tallies = tallies_file - # Specify summary output and correct source sampling box + self._input_set.build_default_settings() + + # Specify summary output and correct source sampling box + source = Source(space=Box([-32, -32, 0], [32, 32, 32])) + source.only_fissionable = True + self._input_set.settings.source = source self._input_set.settings.output = {'summary': True} - self._input_set.settings.source = Source(space=Box( - [0, 0, 0], [32.13, 32.13, 32.13])) # Write input XML files self._input_set.export() From cd921b74bf3b7febb34da50a36c7a414170c0f8e Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Wed, 3 Feb 2016 14:14:52 -0500 Subject: [PATCH 6/7] Now setting the source space Box to be fissionable in asymmetric lattice test --- tests/test_asymmetric_lattice/inputs_true.dat | 2 +- tests/test_asymmetric_lattice/results_true.dat | 2 +- tests/test_asymmetric_lattice/test_asymmetric_lattice.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_asymmetric_lattice/inputs_true.dat b/tests/test_asymmetric_lattice/inputs_true.dat index 552c8d039..e3b00b185 100644 --- a/tests/test_asymmetric_lattice/inputs_true.dat +++ b/tests/test_asymmetric_lattice/inputs_true.dat @@ -1 +1 @@ -fe07eb28fd0dbb56edaecd510f5e8e4db7271e5c9aecf3d880cce92b69872a0aacf825b8e88cd2e9b1ff709f578b269b1835f53cf2561a390062e1e7e03b5276 \ No newline at end of file +b9b4222c4beea80fe6083590f6b785303d174972d80671fb661bac8e030db6f4a61648240cfad6162799361fc0e08a23c61d31aff844d978528d6dad5b5fbc63 \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/results_true.dat b/tests/test_asymmetric_lattice/results_true.dat index 0cf2315ea..ec4b88388 100644 --- a/tests/test_asymmetric_lattice/results_true.dat +++ b/tests/test_asymmetric_lattice/results_true.dat @@ -1 +1 @@ -cea61172ecad5554ef86f52d6adad6ad5e21931cf3d67feb37b8bf9d75e618786f638685e458051d4a39afe1a924fd651cf6674a88cf1f1842fd69cd851e1f17 \ No newline at end of file +b5f96919ca474cd1c9c9d0acde3b8aac4a1cf636443c72a38b6c5a4221a8ce3e90182aaef2f664e44b9175ca257a89db2328b63e19388ee0e5006de4b3d92ce6 \ No newline at end of file diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py index 3b9e2029b..0080078aa 100644 --- a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -74,7 +74,7 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): # Specify summary output and correct source sampling box source = Source(space=Box([-32, -32, 0], [32, 32, 32])) - source.only_fissionable = True + source.space.only_fissionable = True self._input_set.settings.source = source self._input_set.settings.output = {'summary': True} From 0439b6cc6d3f7d6f51441f3edfd1c88eface0f88 Mon Sep 17 00:00:00 2001 From: "wbinventor@gmail.com" Date: Thu, 4 Feb 2016 09:13:06 -0500 Subject: [PATCH 7/7] Now require numpy >=1.9 in install_requires per request by @paulromano --- setup.py | 2 +- tests/test_asymmetric_lattice/test_asymmetric_lattice.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 0bf4549c0..87fdff68c 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ kwargs = {'name': 'openmc', if have_setuptools: kwargs.update({ # Required dependencies - 'install_requires': ['numpy', 'h5py', 'matplotlib'], + 'install_requires': ['numpy>=1.9', 'h5py', 'matplotlib'], # Optional dependencies 'extras_require': { diff --git a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py index 0080078aa..5a1d47ef8 100644 --- a/tests/test_asymmetric_lattice/test_asymmetric_lattice.py +++ b/tests/test_asymmetric_lattice/test_asymmetric_lattice.py @@ -69,7 +69,7 @@ class AsymmetricLatticeTestHarness(PyAPITestHarness): # Assign the tallies file to the input set self._input_set.tallies = tallies_file - + # Build default settings self._input_set.build_default_settings() # Specify summary output and correct source sampling box