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
This commit is contained in:
Andrew Johnson 2019-07-15 11:53:01 -05:00
parent d23fa7cf65
commit 3b8d9758bf
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB

View file

@ -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)