From 328c6a0e886d0011f3e88b03a53028e7119d0250 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Sat, 13 Aug 2016 17:40:28 -0500 Subject: [PATCH 1/3] Allow estimator to be set for MGXS --- openmc/mgxs/mgxs.py | 74 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index 7aa12d0418..b942351556 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -47,6 +47,10 @@ DOMAIN_TYPES = ['cell', 'material', 'mesh'] +ESTIMATOR_TYPES = ['tracklength', + 'collision', + 'analog'] + # Supported domain classes _DOMAINS = (openmc.Cell, openmc.Universe, @@ -102,7 +106,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 @@ -149,6 +153,7 @@ class MGXS(object): 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 @@ -250,7 +255,7 @@ class MGXS(object): @property def estimator(self): - return 'tracklength' + return self._estimator @property def tallies(self): @@ -368,6 +373,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, ESTIMATOR_TYPES) + self._estimator = estimator + @domain.setter def domain(self, domain): cv.check_type('domain', domain, _DOMAINS) @@ -1643,7 +1653,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 +1702,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 +2078,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 +2196,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 : {'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 @@ -2233,6 +2239,7 @@ class TransportXS(MGXS): super(TransportXS, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'transport' + self._estimator = 'analog' @property def scores(self): @@ -2245,10 +2252,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 +2323,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 : {'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 @@ -2441,7 +2444,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 +2560,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 +2682,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 +2793,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 +2909,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 +3022,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 +3137,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 +3180,7 @@ 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' class ScatterMatrixXS(MatrixMGXS): @@ -3268,7 +3268,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 : {'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 @@ -3314,6 +3314,7 @@ class ScatterMatrixXS(MatrixMGXS): self._correction = 'P0' self._legendre_order = 0 self._hdf5_key = 'scatter matrix' + self._estimator = 'analog' def __deepcopy__(self, memo): clone = super(ScatterMatrixXS, self).__deepcopy__(memo) @@ -3929,7 +3930,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 : {'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 @@ -4051,7 +4052,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 : {'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 @@ -4094,6 +4095,7 @@ class MultiplicityMatrixXS(MatrixMGXS): super(MultiplicityMatrixXS, self).__init__(domain, domain_type, groups, by_nuclide, name) self._rxn_type = 'multiplicity matrix' + self._estimator = '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 : {'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 @@ -4242,6 +4244,7 @@ class NuFissionMatrixXS(MatrixMGXS): groups, by_nuclide, name) self._rxn_type = 'nu-fission' self._hdf5_key = 'nu-fission matrix' + self._estimator = 'analog' class Chi(MGXS): @@ -4313,7 +4316,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 : {'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 @@ -4355,6 +4358,7 @@ 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' @property def scores(self): @@ -4372,10 +4376,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 +4803,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 : {'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 @@ -4918,7 +4918,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 +5052,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 From 8e0f3f4f79fedcbd3892a0164d336f6315f97f45 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 15 Aug 2016 06:47:19 -0500 Subject: [PATCH 2/3] Respond to @wbinventor comments on #704 --- openmc/__init__.py | 2 +- openmc/mgxs/mgxs.py | 32 +++++++++++++++++--------------- openmc/tallies.py | 6 ++++-- 3 files changed, 22 insertions(+), 18 deletions(-) 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/mgxs.py b/openmc/mgxs/mgxs.py index b942351556..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', @@ -47,10 +47,6 @@ DOMAIN_TYPES = ['cell', 'material', 'mesh'] -ESTIMATOR_TYPES = ['tracklength', - 'collision', - 'analog'] - # Supported domain classes _DOMAINS = (openmc.Cell, openmc.Universe, @@ -148,7 +144,6 @@ 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 @@ -165,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 @@ -375,7 +371,7 @@ class MGXS(object): @estimator.setter def estimator(self, estimator): - cv.check_value('estimator', estimator, ESTIMATOR_TYPES) + cv.check_value('estimator', estimator, self._valid_estimators) self._estimator = estimator @domain.setter @@ -2196,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', 'collision', '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 @@ -2240,6 +2236,7 @@ class TransportXS(MGXS): groups, by_nuclide, name) self._rxn_type = 'transport' self._estimator = 'analog' + self._valid_estimators = ['analog'] @property def scores(self): @@ -2323,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', 'collision', '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 @@ -3181,6 +3178,7 @@ class NuScatterXS(MGXS): groups, by_nuclide, name) self._rxn_type = 'nu-scatter' 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', 'collision', '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 @@ -3315,6 +3313,7 @@ class ScatterMatrixXS(MatrixMGXS): 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) @@ -3930,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', 'collision', '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 @@ -4052,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', 'collision', '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 @@ -4096,6 +4095,7 @@ class MultiplicityMatrixXS(MatrixMGXS): by_nuclide, name) self._rxn_type = 'multiplicity matrix' self._estimator = 'analog' + self._valid_estimators = ['analog'] @property def scores(self): @@ -4200,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', 'collision', '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 @@ -4245,6 +4245,7 @@ class NuFissionMatrixXS(MatrixMGXS): self._rxn_type = 'nu-fission' self._hdf5_key = 'nu-fission matrix' self._estimator = 'analog' + self._valid_estimators = ['analog'] class Chi(MGXS): @@ -4316,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', 'collision', '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 @@ -4359,6 +4360,7 @@ class Chi(MGXS): 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): @@ -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', 'collision', '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 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 From 6be762858e14b9e1db69cf1366fbde004dc4cd51 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 16 Aug 2016 09:33:26 -0500 Subject: [PATCH 3/3] Allow estimator to be set for mgxs.Library --- openmc/mgxs/library.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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