From 3b8d9758bf77b5a89d94e3935ea138d60c8ebffa Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 15 Jul 2019 11:53:01 -0500 Subject: [PATCH] Improve array filling/accessing for Operator.__call__ When possible, replaced ``x[:, :, :] = y`` with ``x.fill(y)``. Simple performance tests showed the approaches to be identical with respect to process time. The latter maintains more flexibility; whatever the shape of x becomes, no changes need to be made, so long as x has a ``fill`` method. Replaced ``rates[i, :, :] = ...`` with ``rates[i]`` per reviewer comments --- openmc/deplete/operator.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openmc/deplete/operator.py b/openmc/deplete/operator.py index 586a512cae..73fad50932 100644 --- a/openmc/deplete/operator.py +++ b/openmc/deplete/operator.py @@ -513,7 +513,7 @@ class Operator(TransportOperator): """ rates = self.reaction_rates - rates[:, :, :] = 0.0 + rates.fill(0.0) # Get k and uncertainty k_combined = openmc.capi.keff() @@ -527,7 +527,6 @@ class Operator(TransportOperator): react_ind = [rates.index_rx[react] for react in self.chain.reactions] # Compute fission power - # TODO : improve this calculation # Keep track of energy produced from all reactions in eV per source # particle @@ -545,7 +544,7 @@ class Operator(TransportOperator): slab = materials.index(mat) # Zero out reaction rates and nuclide numbers - number[:] = 0.0 + number.fill(0.0) # Get new number densities for nuc, i_nuc_results in zip(nuclides, nuc_ind): @@ -559,7 +558,7 @@ class Operator(TransportOperator): tally_rates[:, fission_ind], i) # Divide by total number and store - rates[i, :, :] = self._rate_helper.divide_by_adens(number) + rates[i] = self._rate_helper.divide_by_adens(number) # Reduce energy produced from all processes energy = comm.allreduce(energy)