diff --git a/docs/source/pythonapi/examples/mgxs-part-iii.ipynb b/docs/source/pythonapi/examples/mgxs-part-iii.ipynb index 39980a8fd7..a1eaa7ad82 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 ae015b0a64..eaae92f7c9 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 and therefore 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) 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, diff --git a/openmc/__init__.py b/openmc/__init__.py index 0bde0f5843..557e13039f 100644 --- a/openmc/__init__.py +++ b/openmc/__init__.py @@ -9,8 +9,8 @@ from openmc.plots import * from openmc.settings import * from openmc.surface import * from openmc.universe import * -from openmc.mgxs_library import * from openmc.mesh import * +from openmc.mgxs_library import * from openmc.filter import * from openmc.trigger import * from openmc.tallies import * diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index bf822017c1..84571ce236 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -54,9 +54,9 @@ 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 +183,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 +275,12 @@ 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 set all_domains + # to the input domains + all_domains = domains 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 36d5a00be1..e1c2e62217 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -7,6 +7,7 @@ import os import sys import copy import abc +import itertools import numpy as np @@ -14,7 +15,6 @@ import openmc import openmc.checkvalue as cv from openmc.mgxs import EnergyGroups - if sys.version_info[0] >= 3: basestring = str @@ -41,17 +41,17 @@ MGXS_TYPES = ['total', # Supported domain types -# TODO: Implement Mesh domains DOMAIN_TYPES = ['cell', 'distribcell', 'universe', - 'material'] + 'material', + 'mesh'] # Supported domain classes -# TODO: Implement Mesh domains _DOMAINS = (openmc.Cell, openmc.Universe, - openmc.Material) + openmc.Material, + openmc.Mesh) class MGXS(object): @@ -66,9 +66,9 @@ class MGXS(object): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -86,9 +86,9 @@ class MGXS(object): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -115,9 +115,10 @@ class MGXS(object): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading - tally data from a statepoint file). + tally data from a statepoint file) and the number of mesh cells for + 'mesh' domain types. num_nuclides : int The number of nuclides for which the multi-group cross section is being tracked. This is unity if the by_nuclide attribute is False. @@ -263,6 +264,10 @@ class MGXS(object): # Create a domain Filter object domain_filter = openmc.Filter(self.domain_type, self.domain.id) + # If a mesh domain, give the mesh to the domain filter + if self.domain_type == 'mesh': + domain_filter.mesh = self.domain + # Create each Tally needed to compute the multi group cross section tally_metadata = zip(self.scores, self.tally_keys, self.filters) for score, key, filters in tally_metadata: @@ -378,6 +383,8 @@ class MGXS(object): self._domain_type = 'cell' elif isinstance(domain, openmc.Universe): self._domain_type = 'universe' + elif isinstance(domain, openmc.Mesh): + self._domain_type = 'mesh' @domain_type.setter def domain_type(self, domain_type): @@ -432,9 +439,9 @@ class MGXS(object): ---------- mgxs_type : {'total', 'transport', 'nu-transport', 'absorption', 'capture', 'fission', 'nu-fission', 'kappa-fission', 'scatter', 'nu-scatter', 'scatter matrix', 'nu-scatter matrix', 'multiplicity matrix', 'nu-fission matrix', 'chi', 'chi-prompt', 'inverse-velocity', 'prompt-nu-fission'} The type of multi-group cross section object to return - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -675,6 +682,8 @@ class MGXS(object): self.domain = statepoint.summary.get_universe_by_id(self.domain.id) elif self.domain_type == 'material': self.domain = statepoint.summary.get_material_by_id(self.domain.id) + elif self.domain_type == 'mesh': + self.domain = statepoint.meshes[self.domain.id] else: msg = 'Unable to load data from a statepoint for domain type {0} ' \ 'which is not yet supported'.format(self.domain_type) @@ -682,7 +691,11 @@ class MGXS(object): # Use tally "slicing" to ensure that tallies correspond to our domain # NOTE: This is important if tally merging was used - if self.domain_type != 'distribcell': + if self.domain_type == 'mesh': + filters = [self.domain_type] + 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] filter_bins = [(self.domain.id,)] # Distribcell filters only accept single cell - neglect it when slicing @@ -756,12 +769,19 @@ class MGXS(object): 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 = [] # Construct a collection of the domain filter bins if not isinstance(subdomains, basestring): - cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=2) + cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=3) for subdomain in subdomains: filters.append(self.domain_type) filter_bins.append((subdomain,)) @@ -981,16 +1001,16 @@ class MGXS(object): cv.check_iterable_type('energy_groups', groups, Integral) # Build lists of filters and filter bins to slice - if len(groups) == 0: - filters = [] - filter_bins = [] - else: - filter_bins = [] + filters = [] + filter_bins = [] + + if len(groups) != 0: + energy_bins = [] for group in groups: group_bounds = self.energy_groups.get_group_bounds(group) - filter_bins.append(group_bounds) - filter_bins = [tuple(filter_bins)] - filters = ['energy'] + energy_bins.append(group_bounds) + filter_bins.append(tuple(energy_bins)) + filters.append('energy') # Clone this MGXS to initialize the sliced version slice_xs = copy.deepcopy(self) @@ -1135,6 +1155,9 @@ class MGXS(object): 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 = [range(1, x+1) for x in self.domain.dimension] + subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1168,7 +1191,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 @@ -1270,6 +1293,9 @@ class MGXS(object): elif self.domain_type == 'avg(distribcell)': domain_filter = self.xs_tally.find_filter('avg(distribcell)') subdomains = domain_filter.bins + elif self.domain_type == 'mesh': + xyz = [range(1, x+1) for x in self.domain.dimension] + subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1376,15 +1402,14 @@ class MGXS(object): # Get a Pandas DataFrame for the data df = self.get_pandas_dataframe(groups=groups, xs_type=xs_type) - # Capitalize column label strings - df.columns = df.columns.astype(str) - df.columns = map(str.title, df.columns) - # Export the data using Pandas IO API 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': @@ -1465,7 +1490,10 @@ class MGXS(object): distribcell_paths=distribcell_paths) # Remove nuclide column since it is homogeneous and redundant - df.drop('nuclide', axis=1, inplace=True) + if self.domain_type == 'mesh': + df.drop('nuclide', axis=1, level=0, inplace=True) + else: + df.drop('nuclide', axis=1, inplace=True) # If the user requested a specific set of nuclides elif self.by_nuclide and nuclides != 'all': @@ -1479,7 +1507,10 @@ class MGXS(object): distribcell_paths=distribcell_paths) # Remove the score column since it is homogeneous and redundant - df = df.drop('score', axis=1) + if self.domain_type == 'mesh': + df = df.drop('score', axis=1, level=0) + else: + df = df.drop('score', axis=1) # Override energy groups bounds with indices all_groups = np.arange(self.num_groups, 0, -1, dtype=np.int) @@ -1535,7 +1566,12 @@ class MGXS(object): # Sort the dataframe by domain type id (e.g., distribcell id) and # energy groups such that data is from fast to thermal - df.sort_values(by=[self.domain_type] + columns, inplace=True) + if self.domain_type == 'mesh': + mesh_str = 'mesh {0}'.format(self.domain.id) + df.sort_values(by=[(mesh_str, 'x'), (mesh_str, 'y'), \ + (mesh_str, 'z')] + columns, inplace=True) + else: + df.sort_values(by=[self.domain_type] + columns, inplace=True) return df def get_units(self, xs_type='macro'): @@ -1574,9 +1610,9 @@ class MatrixMGXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -1594,9 +1630,9 @@ class MatrixMGXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -1623,9 +1659,10 @@ class MatrixMGXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading - tally data from a statepoint file). + tally data from a statepoint file) and the number of mesh cells for + 'mesh' domain types. num_nuclides : int The number of nuclides for which the multi-group cross section is being tracked. This is unity if the by_nuclide attribute is False. @@ -1716,13 +1753,20 @@ 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 = [] # Construct a collection of the domain filter bins if not isinstance(subdomains, basestring): cv.check_iterable_type('subdomains', subdomains, Integral, - max_depth=2) + max_depth=3) for subdomain in subdomains: filters.append(self.domain_type) filter_bins.append((subdomain,)) @@ -1884,6 +1928,9 @@ class MatrixMGXS(MGXS): 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 = [range(1, x+1) for x in self.domain.dimension] + subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -1992,9 +2039,9 @@ class TotalXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2012,9 +2059,9 @@ class TotalXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2043,7 +2090,7 @@ class TotalXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2110,9 +2157,9 @@ class TransportXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2130,9 +2177,9 @@ class TransportXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2161,7 +2208,7 @@ class TransportXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2240,9 +2287,9 @@ class NuTransportXS(TransportXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2260,9 +2307,9 @@ class NuTransportXS(TransportXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2291,7 +2338,7 @@ class NuTransportXS(TransportXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2361,9 +2408,9 @@ class AbsorptionXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2381,9 +2428,9 @@ class AbsorptionXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2412,7 +2459,7 @@ class AbsorptionXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2477,9 +2524,9 @@ class CaptureXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2497,9 +2544,9 @@ class CaptureXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2528,7 +2575,7 @@ class CaptureXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2599,9 +2646,9 @@ class FissionXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2619,9 +2666,9 @@ class FissionXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2650,7 +2697,7 @@ class FissionXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2710,9 +2757,9 @@ class NuFissionXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2730,9 +2777,9 @@ class NuFissionXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2761,7 +2808,7 @@ class NuFissionXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2826,9 +2873,9 @@ class KappaFissionXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2846,9 +2893,9 @@ class KappaFissionXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2877,7 +2924,7 @@ class KappaFissionXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -2939,9 +2986,9 @@ class ScatterXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -2959,9 +3006,9 @@ class ScatterXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -2990,7 +3037,7 @@ class ScatterXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -3054,9 +3101,9 @@ class NuScatterXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -3074,9 +3121,9 @@ class NuScatterXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -3105,7 +3152,7 @@ class NuScatterXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -3184,9 +3231,9 @@ class ScatterMatrixXS(MatrixMGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -3208,9 +3255,9 @@ class ScatterMatrixXS(MatrixMGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -3239,7 +3286,7 @@ class ScatterMatrixXS(MatrixMGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -3531,12 +3578,19 @@ 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 = [] # Construct a collection of the domain filter bins if not isinstance(subdomains, basestring): - cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=2) + cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=3) for subdomain in subdomains: filters.append(self.domain_type) filter_bins.append((subdomain,)) @@ -3681,9 +3735,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': @@ -3723,6 +3780,9 @@ class ScatterMatrixXS(MatrixMGXS): 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 = [range(1, x+1) for x in self.domain.dimension] + subdomains = list(itertools.product(*xyz)) else: subdomains = [self.domain.id] @@ -3832,9 +3892,9 @@ class NuScatterMatrixXS(ScatterMatrixXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -3856,9 +3916,9 @@ class NuScatterMatrixXS(ScatterMatrixXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -3887,7 +3947,7 @@ class NuScatterMatrixXS(ScatterMatrixXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -3958,9 +4018,9 @@ class MultiplicityMatrixXS(MatrixMGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -3978,9 +4038,9 @@ class MultiplicityMatrixXS(MatrixMGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -4009,7 +4069,7 @@ class MultiplicityMatrixXS(MatrixMGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -4105,9 +4165,9 @@ class NuFissionMatrixXS(MatrixMGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -4125,9 +4185,9 @@ class NuFissionMatrixXS(MatrixMGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -4156,7 +4216,7 @@ class NuFissionMatrixXS(MatrixMGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -4220,9 +4280,9 @@ class Chi(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -4240,9 +4300,9 @@ class Chi(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -4271,7 +4331,7 @@ class Chi(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -4499,12 +4559,19 @@ 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 = [] # Construct a collection of the domain filter bins if not isinstance(subdomains, basestring): - cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=2) + cv.check_iterable_type('subdomains', subdomains, Integral, max_depth=3) for subdomain in subdomains: filters.append(self.domain_type) filter_bins.append((subdomain,)) @@ -4703,9 +4770,9 @@ class ChiPrompt(Chi): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -4723,9 +4790,9 @@ class ChiPrompt(Chi): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -4754,7 +4821,7 @@ class ChiPrompt(Chi): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int @@ -4818,9 +4885,9 @@ class InverseVelocity(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -4838,9 +4905,9 @@ class InverseVelocity(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -4917,8 +4984,6 @@ class InverseVelocity(MGXS): """ - cv.check_value('xs_type', xs_type, ['macro', 'micro']) - if xs_type == 'macro': return 'second/cm' else: @@ -4954,9 +5019,9 @@ class PromptNuFissionXS(MGXS): Parameters ---------- - domain : openmc.Material or openmc.Cell or openmc.Universe + domain : openmc.Material or openmc.Cell or openmc.Universe or openmc.Mesh The domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} The domain type for spatial homogenization groups : openmc.mgxs.EnergyGroups The energy group structure for energy condensation @@ -4974,9 +5039,9 @@ class PromptNuFissionXS(MGXS): Reaction type (e.g., 'total', 'nu-fission', etc.) by_nuclide : bool If true, computes cross sections for each nuclide in domain - domain : Material or Cell or Universe + domain : Material or Cell or Universe or Mesh Domain for spatial homogenization - domain_type : {'material', 'cell', 'distribcell', 'universe'} + domain_type : {'material', 'cell', 'distribcell', 'universe', 'mesh'} Domain type for spatial homogenization energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation @@ -5005,7 +5070,7 @@ class PromptNuFissionXS(MGXS): is None unless the multi-group cross section has been computed. num_subdomains : int The number of subdomains is unity for 'material', 'cell' and 'universe' - domain types. When the This is equal to the number of cell instances + domain types. This is equal to the number of cell instances for 'distribcell' domain types (it is equal to unity prior to loading tally data from a statepoint file). num_nuclides : int diff --git a/openmc/tallies.py b/openmc/tallies.py index 79e7c56bcb..c68b0faacb 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 = [range(1, x+1) for x in dimension] bins = list(itertools.product(*xyz)) # Create list of 2-tuples for energy boundary bins 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 0000000000..e036b49a26 --- /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 0000000000..e3d7ca6473 --- /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 0000000000..df7a0a5ae8 --- /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()