From 30f5d1a6b855657ce67a787bb67b0b5249c8c5af Mon Sep 17 00:00:00 2001 From: Perry Date: Wed, 17 Jun 2026 21:02:54 -0700 Subject: [PATCH] Avoid copying the whole flux batch in from_multigroup_flux Detect single vs batch from the first flux's ndim and pass the batch through, instead of copying the whole (N, G) array just to read ndim. --- openmc/deplete/microxs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openmc/deplete/microxs.py b/openmc/deplete/microxs.py index 29547b806f..37105ae7e0 100644 --- a/openmc/deplete/microxs.py +++ b/openmc/deplete/microxs.py @@ -567,12 +567,12 @@ class MicroXS: if not np.all(np.diff(energies) > 0): raise ValueError('Energy group boundaries must be in ascending order') - # A 1-D flux is a single domain; 2-D (or a list of 1-D) is a batch - flux_array = np.asarray(multigroup_flux, dtype=float) - if flux_array.ndim not in (1, 2): - raise ValueError('multigroup_flux must be 1-D or 2-D') - single = flux_array.ndim == 1 - fluxes = [flux_array] if single else list(flux_array) + # A 1-D flux is a single domain; 2-D (or a list of 1-D arrays) is a batch + try: + single = {1: True, 2: False}[1 + np.ndim(multigroup_flux[0])] + except (TypeError, IndexError, KeyError): + raise ValueError('multigroup_flux must be 1-D or 2-D') from None + fluxes = [np.asarray(multigroup_flux, dtype=float)] if single else multigroup_flux # check dimension consistency per flux n_groups = len(energies) - 1