From 3c94a733efa86b7af4824734121d70b4c4ee5ef5 Mon Sep 17 00:00:00 2001 From: Sam Shaner Date: Fri, 29 Jul 2016 15:36:58 -0400 Subject: [PATCH 1/9] cleaned up chi equations in python API and added new MGXS to documentation --- docs/source/pythonapi/index.rst | 3 +++ openmc/mgxs/mgxs.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/source/pythonapi/index.rst b/docs/source/pythonapi/index.rst index 36f161b3c..df50eee0b 100644 --- a/docs/source/pythonapi/index.rst +++ b/docs/source/pythonapi/index.rst @@ -269,13 +269,16 @@ Multi-group Cross Sections openmc.mgxs.AbsorptionXS openmc.mgxs.CaptureXS openmc.mgxs.Chi + openmc.mgxs.ChiPrompt openmc.mgxs.FissionXS + openmc.mgxs.InverseVelocity openmc.mgxs.KappaFissionXS openmc.mgxs.MultiplicityMatrixXS openmc.mgxs.NuFissionXS openmc.mgxs.NuFissionMatrixXS openmc.mgxs.NuScatterXS openmc.mgxs.NuScatterMatrixXS + openmc.mgxs.PromptNuFissionXS openmc.mgxs.ScatterXS openmc.mgxs.ScatterMatrixXS openmc.mgxs.TotalXS diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index c359379f4..36d5a00be 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -4209,14 +4209,14 @@ class Chi(MGXS): .. math:: - \langle \nu\sigma_{f,\rightarrow g} \phi \rangle &= \int_{r \in V} dr + \langle \nu\sigma_{f,g' \rightarrow g} \phi \rangle &= \int_{r \in V} dr \int_{4\pi} d\Omega' \int_0^\infty dE' \int_{E_g}^{E_{g-1}} dE \; \chi(E) \nu\sigma_f (r, E') \psi(r, E', \Omega')\\ \langle \nu\sigma_f \phi \rangle &= \int_{r \in V} dr \int_{4\pi} d\Omega' \int_0^\infty dE' \int_0^\infty dE \; \chi(E) \nu\sigma_f (r, E') \psi(r, E', \Omega') \\ - \chi_g &= \frac{\langle \nu\sigma_{f,\rightarrow g} \phi \rangle}{\langle - \nu\sigma_f \phi \rangle} + \chi_g &= \frac{\langle \nu\sigma_{f,g' \rightarrow g} \phi \rangle} + {\langle \nu\sigma_f \phi \rangle} Parameters ---------- @@ -4692,14 +4692,14 @@ class ChiPrompt(Chi): .. math:: - \langle \nu\sigma_{f,\rightarrow g}^p \phi \rangle &= \int_{r \in V} dr - \int_{4\pi} d\Omega' \int_0^\infty dE' \int_{E_g}^{E_{g-1}} dE \; \chi(E) - \nu\sigma_f^p (r, E') \psi(r, E', \Omega')\\ - \langle \nu\sigma_f^p \phi \rangle &= \int_{r \in V} dr \int_{4\pi} - d\Omega' \int_0^\infty dE' \int_0^\infty dE \; \chi(E) \nu\sigma_f^p (r, + \langle \nu^p \sigma_{f,g' \rightarrow g} \phi \rangle &= \int_{r \in V} + dr \int_{4\pi} d\Omega' \int_0^\infty dE' \int_{E_g}^{E_{g-1}} dE \; + \chi(E) \nu^p \sigma_f (r, E') \psi(r, E', \Omega')\\ + \langle \nu^p \sigma_f \phi \rangle &= \int_{r \in V} dr \int_{4\pi} + d\Omega' \int_0^\infty dE' \int_0^\infty dE \; \chi(E) \nu^p \sigma_f (r, E') \psi(r, E', \Omega') \\ - \chi_g^p &= \frac{\langle \nu\sigma_{f,\rightarrow g}^p \phi \rangle}{\langle - \nu\sigma_f^p \phi \rangle} + \chi_g^p &= \frac{\langle \nu^p \sigma_{f,g' \rightarrow g} \phi \rangle} + {\langle \nu^p \sigma_f \phi \rangle} Parameters ---------- From 90cd17c3ec8c0d324d38bbb35a3ca60504a21676 Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Fri, 29 Jul 2016 20:53:27 +0000 Subject: [PATCH 2/9] updated test results --- openmc/mgxs/mgxs.py | 21 +++++++++++++++++++ .../inputs_true.dat | 2 +- .../inputs_true.dat | 2 +- .../inputs_true.dat | 2 +- .../inputs_true.dat | 2 +- .../results_true.dat | 2 +- tests/test_tallies/inputs_true.dat | 2 +- 7 files changed, 27 insertions(+), 6 deletions(-) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 4f87953f5..e3697010b 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -1749,6 +1749,13 @@ class MatrixMGXS(MGXS): cv.check_value('value', value, ['mean', 'std_dev', 'rel_err']) cv.check_value('xs_type', xs_type, ['macro', 'micro']) + # FIXME: Unable to get microscopic xs for mesh domain because the mesh + # cells do not know the nuclide densities in each mesh cell. + if self.domain_type == 'mesh' and xs_type == 'micro': + msg = 'Unable to get micro xs for mesh domain since the mesh ' \ + 'cells do not know the nuclide densities in each mesh cell.' + raise ValueError(msg) + filters = [] filter_bins = [] @@ -3567,6 +3574,13 @@ class ScatterMatrixXS(MatrixMGXS): cv.check_value('value', value, ['mean', 'std_dev', 'rel_err']) cv.check_value('xs_type', xs_type, ['macro', 'micro']) + # FIXME: Unable to get microscopic xs for mesh domain because the mesh + # cells do not know the nuclide densities in each mesh cell. + if self.domain_type == 'mesh' and xs_type == 'micro': + msg = 'Unable to get micro xs for mesh domain since the mesh ' \ + 'cells do not know the nuclide densities in each mesh cell.' + raise ValueError(msg) + filters = [] filter_bins = [] @@ -4538,6 +4552,13 @@ class Chi(MGXS): cv.check_value('value', value, ['mean', 'std_dev', 'rel_err']) cv.check_value('xs_type', xs_type, ['macro', 'micro']) + # FIXME: Unable to get microscopic xs for mesh domain because the mesh + # cells do not know the nuclide densities in each mesh cell. + if self.domain_type == 'mesh' and xs_type == 'micro': + msg = 'Unable to get micro xs for mesh domain since the mesh ' \ + 'cells do not know the nuclide densities in each mesh cell.' + raise ValueError(msg) + filters = [] filter_bins = [] diff --git a/tests/test_mgxs_library_condense/inputs_true.dat b/tests/test_mgxs_library_condense/inputs_true.dat index 181c5c59c..0c648376e 100644 --- a/tests/test_mgxs_library_condense/inputs_true.dat +++ b/tests/test_mgxs_library_condense/inputs_true.dat @@ -1 +1 @@ -e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e +e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e \ No newline at end of file diff --git a/tests/test_mgxs_library_distribcell/inputs_true.dat b/tests/test_mgxs_library_distribcell/inputs_true.dat index 4ad63a947..055ce35a5 100644 --- a/tests/test_mgxs_library_distribcell/inputs_true.dat +++ b/tests/test_mgxs_library_distribcell/inputs_true.dat @@ -1 +1 @@ -2d948f3b12293294eaeca231a3df9d51195379e8bb38dd3e68d3bc512a7d08ed52a1109054ca381684ec127268710f6d6e9210ac8154c9b379608e996627624a +2d948f3b12293294eaeca231a3df9d51195379e8bb38dd3e68d3bc512a7d08ed52a1109054ca381684ec127268710f6d6e9210ac8154c9b379608e996627624a \ No newline at end of file diff --git a/tests/test_mgxs_library_no_nuclides/inputs_true.dat b/tests/test_mgxs_library_no_nuclides/inputs_true.dat index 181c5c59c..0c648376e 100644 --- a/tests/test_mgxs_library_no_nuclides/inputs_true.dat +++ b/tests/test_mgxs_library_no_nuclides/inputs_true.dat @@ -1 +1 @@ -e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e +e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e \ No newline at end of file diff --git a/tests/test_mgxs_library_nuclides/inputs_true.dat b/tests/test_mgxs_library_nuclides/inputs_true.dat index 0bf12fbb2..a15bbee4c 100644 --- a/tests/test_mgxs_library_nuclides/inputs_true.dat +++ b/tests/test_mgxs_library_nuclides/inputs_true.dat @@ -1 +1 @@ -e4a5f03ab6167e96462c4ef537533fe33b98d7878ae00824c5619356bda8d548b3c71af01ba8c88d5a9b46dd1471d331e6f678a164af922200f2ee3642be6340 +e4a5f03ab6167e96462c4ef537533fe33b98d7878ae00824c5619356bda8d548b3c71af01ba8c88d5a9b46dd1471d331e6f678a164af922200f2ee3642be6340 \ No newline at end of file diff --git a/tests/test_mgxs_library_nuclides/results_true.dat b/tests/test_mgxs_library_nuclides/results_true.dat index e89776fe8..3da814604 100644 --- a/tests/test_mgxs_library_nuclides/results_true.dat +++ b/tests/test_mgxs_library_nuclides/results_true.dat @@ -1 +1 @@ -e494320a213b5704a2ac915a2ba504857be91961ceb6735b6ad05d81eb31c44c9584d5bd9d40baececf1dcb5b030e6ecec63cfbd20639baf69bcb596c5c46591 +e494320a213b5704a2ac915a2ba504857be91961ceb6735b6ad05d81eb31c44c9584d5bd9d40baececf1dcb5b030e6ecec63cfbd20639baf69bcb596c5c46591 \ No newline at end of file diff --git a/tests/test_tallies/inputs_true.dat b/tests/test_tallies/inputs_true.dat index f961821aa..17f04238c 100644 --- a/tests/test_tallies/inputs_true.dat +++ b/tests/test_tallies/inputs_true.dat @@ -1 +1 @@ -ca47172a42f6c13b244a763c990cbe4811662708ee03307d810a4542ee34bb5db7cc29d66aea313dad95b9f38a4ff7943ded527cfd0c7c8825372fec40cfc0d0 +ca47172a42f6c13b244a763c990cbe4811662708ee03307d810a4542ee34bb5db7cc29d66aea313dad95b9f38a4ff7943ded527cfd0c7c8825372fec40cfc0d0 \ No newline at end of file From 3986a20b131df7570a1bd33639cdcb5aaf02a086 Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Fri, 29 Jul 2016 21:09:57 +0000 Subject: [PATCH 3/9] removed unnecessary code in mgxs.py --- openmc/mgxs/mgxs.py | 12 ------------ tests/test_mgxs_library_hdf5/inputs_true.dat | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index e3697010b..8d60e521a 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -14,7 +14,6 @@ import numpy as np import openmc import openmc.checkvalue as cv from openmc.mgxs import EnergyGroups -from openmc import Mesh if sys.version_info[0] >= 3: basestring = str @@ -4977,17 +4976,6 @@ class InverseVelocity(MGXS): """ - # Construct a collection of the subdomains to report - if not isinstance(subdomains, basestring): - cv.check_iterable_type('subdomains', subdomains, Integral) - elif self.domain_type == 'distribcell': - subdomains = np.arange(self.num_subdomains, dtype=np.int) - elif self.domain_type == 'mesh': - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) - subdomains = list(itertools.product(*xyz)) - else: - subdomains = [self.domain.id] - if xs_type == 'macro': return 'second/cm' else: diff --git a/tests/test_mgxs_library_hdf5/inputs_true.dat b/tests/test_mgxs_library_hdf5/inputs_true.dat index 181c5c59c..0c648376e 100644 --- a/tests/test_mgxs_library_hdf5/inputs_true.dat +++ b/tests/test_mgxs_library_hdf5/inputs_true.dat @@ -1 +1 @@ -e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e +e2cdca7ea5b3532050af5b12fac26d7ef212d2696bb1b73cdd00929b2243c40d100ad02438c7b090555b49815d0de6c48cf1b4ebf437a48bc80c2d2b4bad292e \ No newline at end of file From 102edb6d65f6b405b156959065ef4193bdf2f98a Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Fri, 29 Jul 2016 21:22:16 +0000 Subject: [PATCH 4/9] replaced mapped lambdas with inline for loops --- openmc/mgxs/mgxs.py | 10 +++++----- openmc/tallies.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 8d60e521a..ad55f9a24 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -694,7 +694,7 @@ class MGXS(object): # NOTE: This is important if tally merging was used if self.domain_type == 'mesh': filters = [self.domain_type] - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) + xyz = [np.arange(1, x+1) for x in self.domain.dimension] filter_bins = [tuple(itertools.product(*xyz))] elif self.domain_type != 'distribcell': filters = [self.domain_type] @@ -1157,7 +1157,7 @@ class MGXS(object): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) + xyz = [np.arange(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1295,7 +1295,7 @@ class MGXS(object): domain_filter = self.xs_tally.find_filter('avg(distribcell)') subdomains = domain_filter.bins elif self.domain_type == 'mesh': - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) + xyz = [np.arange(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1924,7 +1924,7 @@ class MatrixMGXS(MGXS): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) + xyz = [np.arange(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -3773,7 +3773,7 @@ class ScatterMatrixXS(MatrixMGXS): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = map(lambda x: np.arange(1, x+1), self.domain.dimension) + xyz = [np.arange(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] diff --git a/openmc/tallies.py b/openmc/tallies.py index 79e7c56bc..45bc49638 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1293,7 +1293,7 @@ class Tally(object): # Create list of 2- or 3-tuples tuples for mesh cell bins if self_filter.type == 'mesh': dimension = self_filter.mesh.dimension - xyz = map(lambda x: np.arange(1, x+1), dimension) + xyz = [np.arange(1, x+1) for x in dimension] bins = list(itertools.product(*xyz)) # Create list of 2-tuples for energy boundary bins From ef0cbebbaac1a1ae1580b1ae449ad6c1e9833765 Mon Sep 17 00:00:00 2001 From: Sam Shaner Date: Fri, 29 Jul 2016 17:45:35 -0400 Subject: [PATCH 5/9] updated mgxs ipython notebooks noting that the mesh domain type has been added --- docs/source/pythonapi/examples/mgxs-part-iii.ipynb | 2 +- docs/source/pythonapi/examples/mgxs-part-iv.ipynb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/source/pythonapi/examples/mgxs-part-iii.ipynb b/docs/source/pythonapi/examples/mgxs-part-iii.ipynb index 39980a8fd..a1eaa7ad8 100644 --- a/docs/source/pythonapi/examples/mgxs-part-iii.ipynb +++ b/docs/source/pythonapi/examples/mgxs-part-iii.ipynb @@ -574,7 +574,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now we must specify the type of domain over which we would like the `Library` to compute multi-group cross sections. The domain type corresponds to the type of tally filter to be used in the tallies created to compute multi-group cross sections. At the present time, the `Library` supports `\"material,\"` `\"cell,\"` and `\"universe\"` domain types. We will use a `\"cell\"` domain type here to compute cross sections in each of the cells in the fuel assembly geometry.\n", + "Now we must specify the type of domain over which we would like the `Library` to compute multi-group cross sections. The domain type corresponds to the type of tally filter to be used in the tallies created to compute multi-group cross sections. At the present time, the `Library` supports `\"material\"`, `\"cell\"`, `\"universe\"`, and `\"mesh\"` domain types. We will use a `\"cell\"` domain type here to compute cross sections in each of the cells in the fuel assembly geometry.\n", "\n", "**Note:** By default, the `Library` class will instantiate `MGXS` objects for each and every domain (material, cell or universe) in the geometry of interest. However, one may specify a subset of these domains to the `Library.domains` property. In our case, we wish to compute multi-group cross sections in each and every cell since they will be needed in our downstream OpenMOC calculation on the identical combinatorial geometry mesh." ] diff --git a/docs/source/pythonapi/examples/mgxs-part-iv.ipynb b/docs/source/pythonapi/examples/mgxs-part-iv.ipynb index ae015b0a6..5b3bae495 100644 --- a/docs/source/pythonapi/examples/mgxs-part-iv.ipynb +++ b/docs/source/pythonapi/examples/mgxs-part-iv.ipynb @@ -519,9 +519,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Now we must specify the type of domain over which we would like the `Library` to compute multi-group cross sections. The domain type corresponds to the type of tally filter to be used in the tallies created to compute multi-group cross sections. At the present time, the `Library` supports \"material,\" \"cell,\" and \"universe\" domain types. In this simple example, we wish to compute multi-group cross sections only for each material andtherefore will use a \"material\" domain type.\n", + "Now we must specify the type of domain over which we would like the `Library` to compute multi-group cross sections. The domain type corresponds to the type of tally filter to be used in the tallies created to compute multi-group cross sections. At the present time, the `Library` supports \"material\" \"cell\", \"universe\", and \"mesh\" domain types. In this simple example, we wish to compute multi-group cross sections only for each material andtherefore will use a \"material\" domain type.\n", "\n", - "**Note:** By default, the `Library` class will instantiate `MGXS` objects for each and every domain (material, cell or universe) in the geometry of interest. However, one may specify a subset of these domains to the `Library.domains` property." + "**Note:** By default, the `Library` class will instantiate `MGXS` objects for each and every domain (material, cell, universe, or mesh cell) in the geometry of interest. However, one may specify a subset of these domains to the `Library.domains` property." ] }, { @@ -1437,21 +1437,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 2", "language": "python", - "name": "python3" + "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.5.2" + "pygments_lexer": "ipython2", + "version": "2.7.11" } }, "nbformat": 4, From 3a6d2b1aeec30334db4d810f3aef17a4b4a8a85e Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Sat, 30 Jul 2016 19:59:07 +0000 Subject: [PATCH 6/9] changed np.arange to range in mgxs.py and added mesh domain to library.py --- openmc/mgxs/library.py | 14 ++++++++++++-- openmc/mgxs/mgxs.py | 10 +++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index bf822017c..367557158 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -54,9 +54,10 @@ class Library(object): If true, computes cross sections for each nuclide in each domain mgxs_types : Iterable of str The types of cross sections in the library (e.g., ['total', 'scatter']) - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization - domains : Iterable of openmc.Material, openmc.Cell or openmc.Universe + domains : Iterable of openmc.Material, openmc.Cell, openmc.Universe or + openmc.Mesh The spatial domain(s) for which MGXS in the Library are computed correction : {'P0', None} Apply the P0 correction to scattering matrices if set to 'P0' @@ -183,6 +184,8 @@ class Library(object): return self.openmc_geometry.get_all_material_cells() elif self.domain_type == 'universe': return self.openmc_geometry.get_all_universes() + elif self.domain_type == 'mesh': + raise ValueError('Unable to get domains for Mesh domain type') else: raise ValueError('Unable to get domains without a domain type') else: @@ -273,6 +276,11 @@ class Library(object): elif self.domain_type == 'universe': cv.check_iterable_type('domain', domains, openmc.Universe) all_domains = self.openmc_geometry.get_all_universes() + elif self.domain_type == 'mesh': + cv.check_iterable_type('domain', domains, openmc.Mesh) + + # The mesh and geometry are independent, so just return + return else: raise ValueError('Unable to set domains with domain ' 'type "{}"'.format(self.domain_type)) @@ -474,6 +482,8 @@ class Library(object): cv.check_type('domain', domain, (openmc.Cell, Integral)) elif self.domain_type == 'universe': cv.check_type('domain', domain, (openmc.Universe, Integral)) + elif self.domain_type == 'mesh': + cv.check_type('domain', domain, (openmc.Mesh, Integral)) # Check that requested domain is included in library if isinstance(domain, Integral): diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index ad55f9a24..0dadab38a 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -694,7 +694,7 @@ class MGXS(object): # NOTE: This is important if tally merging was used if self.domain_type == 'mesh': filters = [self.domain_type] - xyz = [np.arange(1, x+1) for x in self.domain.dimension] + xyz = [range(1, x+1) for x in self.domain.dimension] filter_bins = [tuple(itertools.product(*xyz))] elif self.domain_type != 'distribcell': filters = [self.domain_type] @@ -1157,7 +1157,7 @@ class MGXS(object): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = [np.arange(1, x+1) for x in self.domain.dimension] + xyz = [range(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1295,7 +1295,7 @@ class MGXS(object): domain_filter = self.xs_tally.find_filter('avg(distribcell)') subdomains = domain_filter.bins elif self.domain_type == 'mesh': - xyz = [np.arange(1, x+1) for x in self.domain.dimension] + xyz = [range(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1924,7 +1924,7 @@ class MatrixMGXS(MGXS): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = [np.arange(1, x+1) for x in self.domain.dimension] + xyz = [range(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -3773,7 +3773,7 @@ class ScatterMatrixXS(MatrixMGXS): elif self.domain_type == 'distribcell': subdomains = np.arange(self.num_subdomains, dtype=np.int) elif self.domain_type == 'mesh': - xyz = [np.arange(1, x+1) for x in self.domain.dimension] + xyz = [range(1, x+1) for x in self.domain.dimension] subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] From 19b5faa4498504978b829beefdcdcb37f20c5cf2 Mon Sep 17 00:00:00 2001 From: Sam Shaner Date: Sat, 30 Jul 2016 16:51:21 -0400 Subject: [PATCH 7/9] fixed issue in exporting mgxs to excel --- openmc/mgxs/library.py | 5 +++-- openmc/mgxs/mgxs.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 367557158..50d568a2d 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -279,8 +279,9 @@ class Library(object): elif self.domain_type == 'mesh': cv.check_iterable_type('domain', domains, openmc.Mesh) - # The mesh and geometry are independent, so just return - return + # The mesh and geometry are independent, so set all_domains + # to the input domains + all_domains = domains else: raise ValueError('Unable to set domains with domain ' 'type "{}"'.format(self.domain_type)) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 0dadab38a..271a78246 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -1192,7 +1192,7 @@ class MGXS(object): # Loop over all subdomains for subdomain in subdomains: - if self.domain_type == 'distribcell': + if self.domain_type == 'distribcell' or self.domain_type == 'mesh': string += '{0: <16}=\t{1}\n'.format('\tSubdomain', subdomain) # Loop over all Nuclides @@ -1407,7 +1407,10 @@ class MGXS(object): if format == 'csv': df.to_csv(filename + '.csv', index=False) elif format == 'excel': - df.to_excel(filename + '.xls', index=False) + if self.domain_type == 'mesh': + df.to_excel(filename + '.xls') + else: + df.to_excel(filename + '.xls', index=False) elif format == 'pickle': df.to_pickle(filename + '.pkl') elif format == 'latex': From 2c2a29143233ed493c0465c2d598e23a5127c794 Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Sat, 30 Jul 2016 21:36:03 +0000 Subject: [PATCH 8/9] added mgxs mesh domain test and fixed issue in getting pandas df mean index for mesh domain --- openmc/mgxs/mgxs.py | 7 +- tests/test_mgxs_library_mesh/inputs_true.dat | 1 + tests/test_mgxs_library_mesh/results_true.dat | 132 ++++++++++++++++++ .../test_mgxs_library_mesh.py | 81 +++++++++++ 4 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 tests/test_mgxs_library_mesh/inputs_true.dat create mode 100644 tests/test_mgxs_library_mesh/results_true.dat create mode 100644 tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 271a78246..f19b50e18 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -3733,9 +3733,12 @@ class ScatterMatrixXS(MatrixMGXS): df['moment'] = moments # Place the moment column before the mean column - mean_index = df.columns.get_loc('mean') columns = df.columns.tolist() - df = df[columns[:mean_index] + ['moment'] + columns[mean_index:-1]] + mean_index = [i for i, s in enumerate(columns) if 'mean' in s][0] + if self.domain_type == 'mesh': + df = df[columns[:mean_index] + [('moment', '')] + columns[mean_index:-1]] + else: + df = df[columns[:mean_index] + ['moment'] + columns[mean_index:-1]] # Select rows corresponding to requested scattering moment if moment != 'all': diff --git a/tests/test_mgxs_library_mesh/inputs_true.dat b/tests/test_mgxs_library_mesh/inputs_true.dat new file mode 100644 index 000000000..e036b49a2 --- /dev/null +++ b/tests/test_mgxs_library_mesh/inputs_true.dat @@ -0,0 +1 @@ +a4cd030bea212e45fdb159e75a7fb3d1947e9bf3d0384ac5d37a72298d67dcfdd1b9eb5c6af8ac6e5983bd5b47de9c17a2ea472b467b7222a4909ee070bf1ca3 \ No newline at end of file diff --git a/tests/test_mgxs_library_mesh/results_true.dat b/tests/test_mgxs_library_mesh/results_true.dat new file mode 100644 index 000000000..e3d7ca647 --- /dev/null +++ b/tests/test_mgxs_library_mesh/results_true.dat @@ -0,0 +1,132 @@ + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.640786 0.044177 +1 1 2 1 1 total 0.660597 0.128423 +2 2 1 1 1 total 0.615276 0.104046 +3 2 2 1 1 total 0.646999 0.186709 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.36665 0.048814 +1 1 2 1 1 total 0.40784 0.096486 +2 2 1 1 1 total 0.36356 0.074111 +3 2 2 1 1 total 0.41456 0.160443 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.366650 0.048814 +1 1 2 1 1 total 0.407840 0.096486 +2 2 1 1 1 total 0.363560 0.074111 +3 2 2 1 1 total 0.414593 0.160436 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.025749 0.002863 +1 1 2 1 1 total 0.028400 0.005275 +2 2 1 1 1 total 0.022988 0.004099 +3 2 2 1 1 total 0.027589 0.010350 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.015861 0.002876 +1 1 2 1 1 total 0.017280 0.004371 +2 2 1 1 1 total 0.014403 0.003542 +3 2 2 1 1 total 0.018061 0.010110 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.009888 0.001077 +1 1 2 1 1 total 0.011121 0.002456 +2 2 1 1 1 total 0.008585 0.001552 +3 2 2 1 1 total 0.009527 0.003659 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.026065 0.002907 +1 1 2 1 1 total 0.029084 0.006430 +2 2 1 1 1 total 0.022596 0.004062 +3 2 2 1 1 total 0.025066 0.009687 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 1.938476 0.211550 +1 1 2 1 1 total 2.177360 0.480780 +2 2 1 1 1 total 1.682799 0.303764 +3 2 2 1 1 total 1.864890 0.715661 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.615037 0.041754 +1 1 2 1 1 total 0.632196 0.123878 +2 2 1 1 1 total 0.592288 0.100439 +3 2 2 1 1 total 0.619410 0.177190 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.584014 0.054315 +1 1 2 1 1 total 0.622514 0.111323 +2 2 1 1 1 total 0.587256 0.084833 +3 2 2 1 1 total 0.613792 0.168612 + mesh 1 group in group out nuclide moment mean std. dev. + x y z +0 1 1 1 1 1 total P0 0.584014 0.054315 +1 1 1 1 1 1 total P1 0.243427 0.025488 +2 1 1 1 1 1 total P2 0.089236 0.007357 +3 1 1 1 1 1 total P3 0.008994 0.005768 +4 1 2 1 1 1 total P0 0.622514 0.111323 +5 1 2 1 1 1 total P1 0.239376 0.042594 +6 1 2 1 1 1 total P2 0.088386 0.017200 +7 1 2 1 1 1 total P3 -0.001243 0.005639 +8 2 1 1 1 1 total P0 0.587256 0.084833 +9 2 1 1 1 1 total P1 0.245120 0.041033 +10 2 1 1 1 1 total P2 0.086784 0.016255 +11 2 1 1 1 1 total P3 0.008660 0.004755 +12 2 2 1 1 1 total P0 0.612950 0.167940 +13 2 2 1 1 1 total P1 0.226176 0.061882 +14 2 2 1 1 1 total P2 0.086593 0.026126 +15 2 2 1 1 1 total P3 0.009672 0.011995 + mesh 1 group in group out nuclide moment mean std. dev. + x y z +0 1 1 1 1 1 total P0 0.584014 0.054315 +1 1 1 1 1 1 total P1 0.243427 0.025488 +2 1 1 1 1 1 total P2 0.089236 0.007357 +3 1 1 1 1 1 total P3 0.008994 0.005768 +4 1 2 1 1 1 total P0 0.622514 0.111323 +5 1 2 1 1 1 total P1 0.239376 0.042594 +6 1 2 1 1 1 total P2 0.088386 0.017200 +7 1 2 1 1 1 total P3 -0.001243 0.005639 +8 2 1 1 1 1 total P0 0.587256 0.084833 +9 2 1 1 1 1 total P1 0.245120 0.041033 +10 2 1 1 1 1 total P2 0.086784 0.016255 +11 2 1 1 1 1 total P3 0.008660 0.004755 +12 2 2 1 1 1 total P0 0.613792 0.168612 +13 2 2 1 1 1 total P1 0.226142 0.061856 +14 2 2 1 1 1 total P2 0.086174 0.025979 +15 2 2 1 1 1 total P3 0.009721 0.012027 + mesh 1 group in group out nuclide mean std. dev. + x y z +0 1 1 1 1 1 total 1.000000 0.088094 +1 1 2 1 1 1 total 1.000000 0.160891 +2 2 1 1 1 1 total 1.000000 0.126864 +3 2 2 1 1 1 total 1.001374 0.305883 + mesh 1 group in group out nuclide mean std. dev. + x y z +0 1 1 1 1 1 total 0.027395 0.004680 +1 1 2 1 1 1 total 0.022914 0.006025 +2 2 1 1 1 1 total 0.019384 0.002846 +3 2 2 1 1 1 total 0.029629 0.006292 + mesh 1 group out nuclide mean std. dev. + x y z +0 1 1 1 1 total 1.0 0.220956 +1 1 2 1 1 total 1.0 0.316565 +2 2 1 1 1 total 1.0 0.132140 +3 2 2 1 1 total 1.0 0.181577 + mesh 1 group out nuclide mean std. dev. + x y z +0 1 1 1 1 total 1.0 0.222246 +1 1 2 1 1 total 1.0 0.316565 +2 2 1 1 1 total 1.0 0.132140 +3 2 2 1 1 total 1.0 0.181577 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 3.610522e-07 3.169931e-08 +1 1 2 1 1 total 3.942353e-07 8.459167e-08 +2 2 1 1 1 total 3.097784e-07 5.252025e-08 +3 2 2 1 1 total 3.799163e-07 1.806470e-07 + mesh 1 group in nuclide mean std. dev. + x y z +0 1 1 1 1 total 0.025735 0.002840 +1 1 2 1 1 total 0.028773 0.006349 +2 2 1 1 1 total 0.022306 0.004010 +3 2 2 1 1 total 0.024549 0.009379 diff --git a/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py b/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py new file mode 100644 index 000000000..df7a0a5ae --- /dev/null +++ b/tests/test_mgxs_library_mesh/test_mgxs_library_mesh.py @@ -0,0 +1,81 @@ +#!/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 +import openmc.mgxs + + +class MGXSTestHarness(PyAPITestHarness): + def _build_inputs(self): + # Generate inputs using parent class routine + super(MGXSTestHarness, self)._build_inputs() + + # Initialize a one-group structure + energy_groups = openmc.mgxs.EnergyGroups(group_edges=[0, 20.]) + + # Initialize MGXS Library for a few cross section types + # for one material-filled cell in the geometry + self.mgxs_lib = openmc.mgxs.Library(self._input_set.geometry) + self.mgxs_lib.by_nuclide = False + + # Test all MGXS types + self.mgxs_lib.mgxs_types = openmc.mgxs.MGXS_TYPES + self.mgxs_lib.energy_groups = energy_groups + self.mgxs_lib.legendre_order = 3 + self.mgxs_lib.domain_type = 'mesh' + + # Instantiate a tally mesh + mesh = openmc.Mesh(mesh_id=1) + mesh.type = 'regular' + mesh.dimension = [2, 2] + mesh.lower_left = [-100., -100.] + mesh.width = [100., 100.] + + self.mgxs_lib.domains = [mesh] + self.mgxs_lib.build_library() + + # Initialize a tallies file + self._input_set.tallies = openmc.Tallies() + self.mgxs_lib.add_to_tallies_file(self._input_set.tallies, merge=False) + self._input_set.tallies.export_to_xml() + + def _get_results(self, hash_output=False): + """Digest info in the statepoint 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) + + # Load the MGXS library from the statepoint + self.mgxs_lib.load_from_statepoint(sp) + + # Build a string from Pandas Dataframe for each 1-group MGXS + outstr = '' + for domain in self.mgxs_lib.domains: + for mgxs_type in self.mgxs_lib.mgxs_types: + mgxs = self.mgxs_lib.get_mgxs(domain, mgxs_type) + df = mgxs.get_pandas_dataframe() + outstr += df.to_string() + '\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(MGXSTestHarness, self)._cleanup() + f = os.path.join(os.getcwd(), 'tallies.xml') + if os.path.exists(f): os.remove(f) + + +if __name__ == '__main__': + harness = MGXSTestHarness('statepoint.10.*', True) + harness.main() From 10795fd00fde7be071f27bb1bf965b43005f62ce Mon Sep 17 00:00:00 2001 From: samuel shaner Date: Sat, 30 Jul 2016 21:37:59 +0000 Subject: [PATCH 9/9] changed np.arange to range in tallies.py --- openmc/tallies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/tallies.py b/openmc/tallies.py index 45bc49638..c68b0faac 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -1293,7 +1293,7 @@ class Tally(object): # Create list of 2- or 3-tuples tuples for mesh cell bins if self_filter.type == 'mesh': dimension = self_filter.mesh.dimension - xyz = [np.arange(1, x+1) for x in dimension] + xyz = [range(1, x+1) for x in dimension] bins = list(itertools.product(*xyz)) # Create list of 2-tuples for energy boundary bins