From b8e9e25da8cbedc7af7e4826de19c65f7f0497ec Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 17 Nov 2015 20:04:56 -0500 Subject: [PATCH 1/4] Added fine granularity control for MGXS Libraries --- openmc/mgxs/library.py | 52 ++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 4c173f81a9..2a293cb0ba 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -53,6 +53,8 @@ class Library(object): The types of cross sections in the library (e.g., ['total', 'scatter']) domain_type : {'material', 'cell', 'distribcell', 'universe'} Domain type for spatial homogenization + domains : Iterable of Material, Cell or Universe + The spatial domain(s) for which MGXS in the Library are computed correction : 'P0' or None Apply the P0 correction to scattering matrices if set to 'P0' energy_groups : EnergyGroups @@ -80,6 +82,7 @@ class Library(object): self._by_nuclide = None self._mgxs_types = [] self._domain_type = None + self._domains = 'all' self._correction = 'P0' self._energy_groups = None self._tally_trigger = None @@ -105,6 +108,7 @@ class Library(object): clone._by_nuclide = self.by_nuclide clone._mgxs_types = self.mgxs_types clone._domain_type = self.domain_type + clone._domains = self.domains clone._correction = self.correction clone._energy_groups = copy.deepcopy(self.energy_groups, memo) clone._tally_trigger = copy.deepcopy(self.tally_trigger, memo) @@ -153,22 +157,24 @@ class Library(object): def by_nuclide(self): return self._by_nuclide - @property - def domains(self): - if self.domain_type is None: - raise ValueError('Unable to get all domains without a domain type') - - if self.domain_type == 'material': - return self.openmc_geometry.get_all_materials() - elif self.domain_type == 'cell' or self.domain_type == 'distribcell': - return self.openmc_geometry.get_all_material_cells() - elif self.domain_type == 'universe': - return self.openmc_geometry.get_all_universes() - @property def domain_type(self): return self._domain_type + @property + def domains(self): + if self._domains == 'all': + if self.domain_type == 'material': + return self.openmc_geometry.get_all_materials() + elif self.domain_type == 'cell' or self.domain_type == 'distribcell': + return self.openmc_geometry.get_all_material_cells() + elif self.domain_type == 'universe': + return self.openmc_geometry.get_all_universes() + else: + raise ValueError('Unable to get domains without a domain type') + else: + return self._domains + @property def correction(self): return self._correction @@ -223,6 +229,28 @@ class Library(object): cv.check_value('domain type', domain_type, tuple(openmc.mgxs.DOMAIN_TYPES)) self._domain_type = domain_type + @domains.setter + def domains(self, domains): + + # Use all materials, cells or universes in the geometry as domains + if domains == 'all': + self._domains = domains + + # User specified a list of material, cell or universe domains + else: + if self.domain_type == 'material': + cv.check_iterable_type('domain', domains, openmc.Material) + elif self.domain_type == 'cell': + cv.check_iterable_type('domain', domains, openmc.Cell) + elif self.domain_type == 'universe': + cv.check_iterable_type('domain', domains, openmc.Universe) + else: + msg = 'Unable to set domains with ' \ + 'domain type "{}"'.format(self.domain_type) + raise ValueError(msg) + + self._domains = domains + @correction.setter def correction(self, correction): cv.check_value('correction', correction, ('P0', None)) From d74dc64bd01ece1fd85ddaf46b99d8df9409ce85 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 17 Nov 2015 20:09:56 -0500 Subject: [PATCH 2/4] MGXS Library domains setter now works for distribcells --- openmc/mgxs/library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 2a293cb0ba..ee9ffc4fa3 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -166,7 +166,7 @@ class Library(object): if self._domains == 'all': if self.domain_type == 'material': return self.openmc_geometry.get_all_materials() - elif self.domain_type == 'cell' or self.domain_type == 'distribcell': + elif self.domain_type in ['cell', 'distribcell']: return self.openmc_geometry.get_all_material_cells() elif self.domain_type == 'universe': return self.openmc_geometry.get_all_universes() @@ -240,7 +240,7 @@ class Library(object): else: if self.domain_type == 'material': cv.check_iterable_type('domain', domains, openmc.Material) - elif self.domain_type == 'cell': + elif self.domain_type in ['cell', 'distribcell']: cv.check_iterable_type('domain', domains, openmc.Cell) elif self.domain_type == 'universe': cv.check_iterable_type('domain', domains, openmc.Universe) From cfe1f1dfcd420bc235432c3edef5848e45f6076f Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 18 Nov 2015 11:10:31 -0500 Subject: [PATCH 3/4] Added check to MGXS Library domains setter to compare with domains in geometry --- openmc/mgxs/library.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index ee9ffc4fa3..9def79eeb2 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -240,15 +240,24 @@ class Library(object): else: if self.domain_type == 'material': cv.check_iterable_type('domain', domains, openmc.Material) + all_domains = self.openmc_geometry.get_all_materials() elif self.domain_type in ['cell', 'distribcell']: cv.check_iterable_type('domain', domains, openmc.Cell) + all_domains = self.openmc_geometry.get_all_material_cells() elif self.domain_type == 'universe': cv.check_iterable_type('domain', domains, openmc.Universe) + all_domains = self.openmc_geometry.get_all_universes() else: msg = 'Unable to set domains with ' \ 'domain type "{}"'.format(self.domain_type) raise ValueError(msg) + # Check that each domain can be found in the geometry + for domain in domains: + if domain not in all_domains: + msg = 'Domain "{}" could not be found in the geometry' + raise ValueError(msg) + self._domains = domains @correction.setter From 9e4cd5ae2b0c6d437efb6b574c703f41eaf40882 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Wed, 18 Nov 2015 11:57:36 -0500 Subject: [PATCH 4/4] Fixed typo in error checking in MGXS Library domains setter per comment by @nelsonag --- openmc/mgxs/library.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index 9def79eeb2..87c6665b2d 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -255,7 +255,8 @@ class Library(object): # Check that each domain can be found in the geometry for domain in domains: if domain not in all_domains: - msg = 'Domain "{}" could not be found in the geometry' + msg = 'Domain "{}" could not be found in the ' \ + 'geometry.'.format(domain) raise ValueError(msg) self._domains = domains