diff --git a/openmc/__init__.py b/openmc/__init__.py index 026ccce114..a0492ee408 100644 --- a/openmc/__init__.py +++ b/openmc/__init__.py @@ -13,10 +13,10 @@ from openmc.settings import * from openmc.surface import * from openmc.universe import * from openmc.mesh import * -from openmc.mgxs_library import * from openmc.filter import * from openmc.trigger import * from openmc.tallies import * +from openmc.mgxs_library import * from openmc.cmfd import * from openmc.executor import * from openmc.statepoint import * diff --git a/openmc/mgxs/library.py b/openmc/mgxs/library.py index ee11d0ef64..5685681e43 100644 --- a/openmc/mgxs/library.py +++ b/openmc/mgxs/library.py @@ -11,6 +11,7 @@ import numpy as np import openmc import openmc.mgxs import openmc.checkvalue as cv +from openmc.tallies import ESTIMATOR_TYPES if sys.version_info[0] >= 3: @@ -39,7 +40,7 @@ class Library(object): mgxs_types : Iterable of str The types of cross sections in the library (e.g., ['total', 'scatter']) name : str, optional - Name of the multi-group cross section. library Used as a label to + Name of the multi-group cross section library. Used as a label to identify tallies in OpenMC 'tallies.xml' file. Attributes @@ -64,6 +65,9 @@ class Library(object): The highest legendre moment in the scattering matrices (default is 0) energy_groups : openmc.mgxs.EnergyGroups Energy group structure for energy condensation + estimator : str or None + The tally estimator used to compute multi-group cross sections. If None, + the default for each MGXS type is used. tally_trigger : openmc.Trigger An (optional) tally precision trigger given to each tally used to compute the cross section @@ -102,6 +106,7 @@ class Library(object): self._sp_filename = None self._keff = None self._sparse = False + self._estimator = None self.name = name self.openmc_geometry = openmc_geometry @@ -206,6 +211,10 @@ class Library(object): def tally_trigger(self): return self._tally_trigger + @property + def estimator(self): + return self._estimator + @property def num_groups(self): return self.energy_groups.num_groups @@ -327,6 +336,11 @@ class Library(object): cv.check_type('tally trigger', tally_trigger, openmc.Trigger) self._tally_trigger = tally_trigger + @estimator.setter + def estimator(self, estimator): + cv.check_value('estimator', estimator, ESTIMATOR_TYPES) + self._estimator = estimator + @sparse.setter def sparse(self, sparse): """Convert tally data from NumPy arrays to SciPy list of lists (LIL) @@ -368,9 +382,11 @@ class Library(object): mgxs.domain_type = self.domain_type mgxs.energy_groups = self.energy_groups mgxs.by_nuclide = self.by_nuclide + if self.estimator is not None: + mgxs.estimator = self.estimator # If a tally trigger was specified, add it to the MGXS - if self.tally_trigger: + if self.tally_trigger is not None: mgxs.tally_trigger = self.tally_trigger # Specify whether to use a transport ('P0') correction diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 7aa12d0418..d68dc508f2 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -13,6 +13,7 @@ import numpy as np import openmc import openmc.checkvalue as cv +from openmc.tallies import ESTIMATOR_TYPES from openmc.mgxs import EnergyGroups if sys.version_info[0] >= 3: @@ -39,7 +40,6 @@ MGXS_TYPES = ['total', 'inverse-velocity', 'prompt-nu-fission'] - # Supported domain types DOMAIN_TYPES = ['cell', 'distribcell', @@ -102,7 +102,7 @@ class MGXS(object): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section @@ -144,11 +144,11 @@ class MGXS(object): def __init__(self, domain=None, domain_type=None, energy_groups=None, by_nuclide=False, name=''): - self._name = '' self._rxn_type = None self._by_nuclide = None self._nuclides = None + self._estimator = 'tracklength' self._domain = None self._domain_type = None self._energy_groups = None @@ -160,6 +160,7 @@ class MGXS(object): self._loaded_sp = False self._derived = False self._hdf5_key = None + self._valid_estimators = ESTIMATOR_TYPES self.name = name self.by_nuclide = by_nuclide @@ -250,7 +251,7 @@ class MGXS(object): @property def estimator(self): - return 'tracklength' + return self._estimator @property def tallies(self): @@ -368,6 +369,11 @@ class MGXS(object): cv.check_iterable_type('nuclides', nuclides, basestring) self._nuclides = nuclides + @estimator.setter + def estimator(self, estimator): + cv.check_value('estimator', estimator, self._valid_estimators) + self._estimator = estimator + @domain.setter def domain(self, domain): cv.check_type('domain', domain, _DOMAINS) @@ -1643,7 +1649,7 @@ class MatrixMGXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section @@ -1692,10 +1698,6 @@ class MatrixMGXS(MGXS): return [[energy], [energy, energyout]] - @property - def estimator(self): - return 'analog' - def get_xs(self, in_groups='all', out_groups='all', subdomains='all', nuclides='all', xs_type='macro', order_groups='increasing', @@ -2072,7 +2074,7 @@ class TotalXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2190,7 +2192,7 @@ class TransportXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2233,6 +2235,8 @@ class TransportXS(MGXS): super(TransportXS, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'transport' + self._estimator = 'analog' + self._valid_estimators = ['analog'] @property def scores(self): @@ -2245,10 +2249,6 @@ class TransportXS(MGXS): energyout_filter = openmc.Filter('energyout', group_edges) return [[energy_filter], [energy_filter], [energyout_filter]] - @property - def estimator(self): - return 'analog' - @property def rxn_rate_tally(self): if self._rxn_rate_tally is None: @@ -2320,7 +2320,7 @@ class NuTransportXS(TransportXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2441,7 +2441,7 @@ class AbsorptionXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2557,7 +2557,7 @@ class CaptureXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2679,7 +2679,7 @@ class FissionXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2790,7 +2790,7 @@ class NuFissionXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -2906,7 +2906,7 @@ class KappaFissionXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -3019,7 +3019,7 @@ class ScatterXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -3134,7 +3134,7 @@ class NuScatterXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -3177,10 +3177,8 @@ class NuScatterXS(MGXS): super(NuScatterXS, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'nu-scatter' - - @property - def estimator(self): - return 'analog' + self._estimator = 'analog' + self._valid_estimators = ['analog'] class ScatterMatrixXS(MatrixMGXS): @@ -3268,7 +3266,7 @@ class ScatterMatrixXS(MatrixMGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -3314,6 +3312,8 @@ class ScatterMatrixXS(MatrixMGXS): self._correction = 'P0' self._legendre_order = 0 self._hdf5_key = 'scatter matrix' + self._estimator = 'analog' + self._valid_estimators = ['analog'] def __deepcopy__(self, memo): clone = super(ScatterMatrixXS, self).__deepcopy__(memo) @@ -3929,7 +3929,7 @@ class NuScatterMatrixXS(ScatterMatrixXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -4051,7 +4051,7 @@ class MultiplicityMatrixXS(MatrixMGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -4094,6 +4094,8 @@ class MultiplicityMatrixXS(MatrixMGXS): super(MultiplicityMatrixXS, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'multiplicity matrix' + self._estimator = 'analog' + self._valid_estimators = ['analog'] @property def scores(self): @@ -4198,7 +4200,7 @@ class NuFissionMatrixXS(MatrixMGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -4242,6 +4244,8 @@ class NuFissionMatrixXS(MatrixMGXS): groups, by_nuclide, name) self._rxn_type = 'nu-fission' self._hdf5_key = 'nu-fission matrix' + self._estimator = 'analog' + self._valid_estimators = ['analog'] class Chi(MGXS): @@ -4313,7 +4317,7 @@ class Chi(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -4355,6 +4359,8 @@ class Chi(MGXS): groups=None, by_nuclide=False, name=''): super(Chi, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'chi' + self._estimator = 'analog' + self._valid_estimators = ['analog'] @property def scores(self): @@ -4372,10 +4378,6 @@ class Chi(MGXS): def tally_keys(self): return ['nu-fission-in', 'nu-fission-out'] - @property - def estimator(self): - return 'analog' - @property def rxn_rate_tally(self): if self._rxn_rate_tally is None: @@ -4803,7 +4805,7 @@ class ChiPrompt(Chi): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : 'analog' The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -4918,7 +4920,7 @@ class InverseVelocity(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys @@ -5052,7 +5054,7 @@ class PromptNuFissionXS(MGXS): tally_keys : list of str The keys into the tallies dictionary for each tally used to compute the multi-group cross section - estimator : {'tracklength', 'analog'} + estimator : {'tracklength', 'collision', 'analog'} The tally estimator used to compute the multi-group cross section tallies : collections.OrderedDict OpenMC tallies needed to compute the multi-group cross section. The keys diff --git a/openmc/tallies.py b/openmc/tallies.py index c68b0faacb..f645fa1624 100644 --- a/openmc/tallies.py +++ b/openmc/tallies.py @@ -40,6 +40,9 @@ _SCORE_CLASSES = (basestring, CrossScore, AggregateScore) _NUCLIDE_CLASSES = (basestring, Nuclide, CrossNuclide, AggregateNuclide) _FILTER_CLASSES = (Filter, CrossFilter, AggregateFilter) +# Valid types of estimators +ESTIMATOR_TYPES = ['tracklength', 'collision', 'analog'] + def reset_auto_tally_id(): """Reset counter for auto-generated tally IDs.""" @@ -387,8 +390,7 @@ class Tally(object): @estimator.setter def estimator(self, estimator): - cv.check_value('estimator', estimator, - ['analog', 'tracklength', 'collision']) + cv.check_value('estimator', estimator, ESTIMATOR_TYPES) self._estimator = estimator @triggers.setter