Merge pull request #2218 from joshmay1/cache_rates_tally

Add a cache system for the depletion material reaction rates tally
This commit is contained in:
Andrew Johnson 2022-09-18 20:41:54 -07:00 committed by GitHub
commit 4caeede302
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 3 deletions

View file

@ -175,6 +175,24 @@ class DirectReactionRateHelper(ReactionRateHelper):
self._rate_tally.writable = False
self._rate_tally.scores = scores
self._rate_tally.filters = [MaterialFilter(materials)]
self._rate_tally_means_cache = None
@property
def rate_tally_means(self):
"""The mean results of the tally of every material's reaction rates for this cycle
"""
# If the mean cache is empty, fill it once with this transport cycle's results
if self._rate_tally_means_cache is None:
self._rate_tally_means_cache = self._rate_tally.mean
return self._rate_tally_means_cache
def reset_tally_means(self):
"""Reset the cached mean rate tallies.
.. note::
This step must be performed after each transport cycle
"""
self._rate_tally_means_cache = None
def get_material_rates(self, mat_id, nuc_index, react_index):
"""Return an array of reaction rates for a material
@ -196,7 +214,7 @@ class DirectReactionRateHelper(ReactionRateHelper):
reaction rates in this material
"""
self._results_cache.fill(0.0)
full_tally_res = self._rate_tally.mean[mat_id]
full_tally_res = self.rate_tally_means[mat_id]
for i_tally, (i_nuc, i_react) in enumerate(
product(nuc_index, react_index)):
self._results_cache[i_nuc, i_react] = full_tally_res[i_tally]
@ -278,6 +296,7 @@ class FluxCollapseHelper(ReactionRateHelper):
EnergyFilter(self._energies)
]
self._flux_tally.scores = ['flux']
self._flux_tally_means_cache = None
# Create reaction rate tally
if self._reactions_direct:
@ -285,9 +304,36 @@ class FluxCollapseHelper(ReactionRateHelper):
self._rate_tally.writable = False
self._rate_tally.scores = self._reactions_direct
self._rate_tally.filters = [MaterialFilter(materials)]
self._rate_tally_means_cache = None
if self._nuclides_direct is not None:
self._rate_tally.nuclides = self._nuclides_direct
@property
def rate_tally_means(self):
"""The mean results of the tally of every material's reaction rates for this cycle
"""
# If the mean cache is empty, fill it once with this transport cycle's results
if self._rate_tally_means_cache is None:
self._rate_tally_means_cache = self._rate_tally.mean
return self._rate_tally_means_cache
@property
def flux_tally_means(self):
# If the mean cache is empty, fill it once for this transport cycle's results
if self._flux_tally_means_cache is None:
self._flux_tally_means_cache = self._flux_tally.mean
return self._flux_tally_means_cache
def reset_tally_means(self):
"""Reset the cached mean rate and flux tallies.
.. note::
This step must be performed after each transport cycle
"""
self._flux_tally_means_cache = None
if self._reactions_direct:
self._rate_tally_means_cache = None
def get_material_rates(self, mat_index, nuc_index, react_index):
"""Return an array of reaction rates for a material
@ -312,14 +358,14 @@ class FluxCollapseHelper(ReactionRateHelper):
# Get flux for specified material
shape = (len(self._materials), len(self._energies) - 1)
mean_value = self._flux_tally.mean.reshape(shape)
mean_value = self.flux_tally_means.reshape(shape)
flux = mean_value[mat_index]
# Get direct reaction rates
if self._reactions_direct:
nuclides_direct = self._rate_tally.nuclides
shape = (len(nuclides_direct), len(self._reactions_direct))
rx_rates = self._rate_tally.mean[mat_index].reshape(shape)
rx_rates = self.rate_tally_means[mat_index].reshape(shape)
mat = self._materials[mat_index]

View file

@ -303,6 +303,10 @@ class IndependentOperator(OpenMCOperator):
"""Unused in this case"""
pass
def reset_tally_means(self):
"""Unused in this case"""
pass
def get_material_rates(self, mat_id, nuc_index, react_index):
"""Return 2D array of [nuclide, reaction] reaction rates

View file

@ -507,6 +507,9 @@ class OpenMCOperator(TransportOperator):
fission_ind = rates.index_rx.get("fission")
# Reset the cached material reaction rates tallies
self._rate_helper.reset_tally_means()
# Extract results
for i, mat in enumerate(self.local_mats):
# Get tally index