From d9b6079c567b2c7f87741dad3e22fec5d6624f7b Mon Sep 17 00:00:00 2001 From: zachmprince Date: Mon, 7 Oct 2024 15:09:30 -0600 Subject: [PATCH 1/3] Transposing pinMgFluxes so that the leading dimension represents pin index --- armi/physics/neutronics/parameters.py | 6 +++--- armi/reactor/blocks.py | 31 +++++++-------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/armi/physics/neutronics/parameters.py b/armi/physics/neutronics/parameters.py index ef61fd680..78268b8ba 100644 --- a/armi/physics/neutronics/parameters.py +++ b/armi/physics/neutronics/parameters.py @@ -163,7 +163,7 @@ def _getNeutronicsBlockParams(): "pinMgFluxes", units=f"n/{units.CM}^2/{units.SECONDS}", description=""" - The block-level pin multigroup fluxes. pinMgFluxes[g][i] represents the flux in group g + The block-level pin multigroup fluxes. pinMgFluxes[i, g] represents the flux in group g for pin i. Flux units are the standard n/cm^2/s. The "ARMI pin ordering" is used, which is counter-clockwise from 3 o'clock. """, @@ -175,7 +175,7 @@ def _getNeutronicsBlockParams(): pb.defParam( "pinMgFluxesAdj", units=units.UNITLESS, - description="should be a blank 3-D array, but re-defined later (ng x nPins x nAxialSegments)", + description="should be a blank 3-D array, but re-defined later (nPins x ng x nAxialSegments)", categories=[parameters.Category.pinQuantities], saveToDB=False, default=None, @@ -184,7 +184,7 @@ def _getNeutronicsBlockParams(): pb.defParam( "pinMgFluxesGamma", units=f"#/{units.CM}^2/{units.SECONDS}", - description="should be a blank 3-D array, but re-defined later (ng x nPins x nAxialSegments)", + description="should be a blank 3-D array, but re-defined later (nPins x ng x nAxialSegments)", categories=[parameters.Category.pinQuantities, parameters.Category.gamma], saveToDB=False, default=None, diff --git a/armi/reactor/blocks.py b/armi/reactor/blocks.py index cc18826a0..e0ff29b2c 100644 --- a/armi/reactor/blocks.py +++ b/armi/reactor/blocks.py @@ -346,13 +346,10 @@ def setPinMgFluxes(self, fluxes, adjoint=False, gamma=False): """ Store the pin-detailed multi-group neutron flux. - The [g][i] indexing is transposed to be a list of lists, one for each pin. This makes it - simple to do depletion for each pin, etc. - Parameters ---------- - fluxes : 2-D list of floats - The block-level pin multigroup fluxes. fluxes[g][i] represents the flux in group g for + fluxes : np.ndarray + The block-level pin multigroup fluxes. fluxes[i, g] represents the flux in group g for pin i. Flux units are the standard n/cm^2/s. The "ARMI pin ordering" is used, which is counter-clockwise from 3 o'clock. adjoint : bool, optional @@ -362,28 +359,16 @@ def setPinMgFluxes(self, fluxes, adjoint=False, gamma=False): Outputs ------- - self.p.pinMgFluxes : 2-D array of floats - The block-level pin multigroup fluxes. pinMgFluxes[g][i] represents the flux in group g + self.p.pinMgFluxes : np.ndarray + The block-level pin multigroup fluxes. pinMgFluxes[i, g] represents the flux in group g for pin i. Flux units are the standard n/cm^2/s. The "ARMI pin ordering" is used, which is counter-clockwise from 3 o'clock. """ - pinFluxes = [] - - G, nPins = fluxes.shape - - for pinNum in range(1, nPins + 1): - thisPinFlux = [] - - if self.hasFlags(Flags.FUEL): - pinLoc = self.p.pinLocation[pinNum - 1] - else: - pinLoc = pinNum - - for g in range(G): - thisPinFlux.append(fluxes[g][pinLoc - 1]) - pinFluxes.append(thisPinFlux) + if self.hasFlags(Flags.FUEL): + pinFluxes = fluxes[(np.array(self.p.pinLocation) - 1)] + else: + pinFluxes = fluxes - pinFluxes = np.array(pinFluxes) if gamma: if adjoint: raise ValueError("Adjoint gamma flux is currently unsupported.") From 354fb027280d242cd45b3a93e156e33ca9b61ace Mon Sep 17 00:00:00 2001 From: zachmprince Date: Mon, 7 Oct 2024 15:17:49 -0600 Subject: [PATCH 2/3] Adding change to release notes --- doc/release/0.4.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/release/0.4.rst b/doc/release/0.4.rst index 392d0e0d3..f4e0d2eb4 100644 --- a/doc/release/0.4.rst +++ b/doc/release/0.4.rst @@ -31,6 +31,7 @@ API Changes #. Allowing for unknown Flags when opening a DB. (`PR#1844 `_) #. Removing ``assemblyLists.py`` and the ``AssemblyList`` class. (`PR#1891 `_) #. Removing ``Assembly.rotatePins`` and ``Block.rotatePins``. Prefer ``Assembly.rotate`` and ``Block.rotate``. (`PR#1846 `) #. TBD Bug Fixes From ab569d1be5fc255cfc208a42c29d3f4324e0a19a Mon Sep 17 00:00:00 2001 From: zachmprince Date: Mon, 7 Oct 2024 18:50:40 -0600 Subject: [PATCH 3/3] Modifying test_pinMgFluxes to actually test assignment of parameter --- armi/reactor/blocks.py | 2 +- armi/reactor/tests/test_blocks.py | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/armi/reactor/blocks.py b/armi/reactor/blocks.py index e0ff29b2c..11bb8feb4 100644 --- a/armi/reactor/blocks.py +++ b/armi/reactor/blocks.py @@ -367,7 +367,7 @@ def setPinMgFluxes(self, fluxes, adjoint=False, gamma=False): if self.hasFlags(Flags.FUEL): pinFluxes = fluxes[(np.array(self.p.pinLocation) - 1)] else: - pinFluxes = fluxes + pinFluxes = fluxes[:] if gamma: if adjoint: diff --git a/armi/reactor/tests/test_blocks.py b/armi/reactor/tests/test_blocks.py index 08f729e9a..5fdde20b0 100644 --- a/armi/reactor/tests/test_blocks.py +++ b/armi/reactor/tests/test_blocks.py @@ -1700,13 +1700,29 @@ def test_pinMgFluxes(self): .. warning:: This will likely be pushed to the component level. """ - fluxes = np.ones((33, 10)) + fluxes = np.random.rand(10, 33) + p, g = np.random.randint(low=0, high=[10, 33]) + + # Test without pinLocation + self.block.pinLocation = None self.block.setPinMgFluxes(fluxes) self.block.setPinMgFluxes(fluxes * 2, adjoint=True) self.block.setPinMgFluxes(fluxes * 3, gamma=True) - self.assertEqual(self.block.p.pinMgFluxes[0][2], 1.0) - self.assertEqual(self.block.p.pinMgFluxesAdj[0][2], 2.0) - self.assertEqual(self.block.p.pinMgFluxesGamma[0][2], 3.0) + self.assertEqual(self.block.p.pinMgFluxes.shape, (10, 33)) + self.assertEqual(self.block.p.pinMgFluxes[p, g], fluxes[p, g]) + self.assertEqual(self.block.p.pinMgFluxesAdj.shape, (10, 33)) + self.assertEqual(self.block.p.pinMgFluxesAdj[p, g], fluxes[p, g] * 2) + self.assertEqual(self.block.p.pinMgFluxesGamma.shape, (10, 33)) + self.assertEqual(self.block.p.pinMgFluxesGamma[p, g], fluxes[p, g] * 3) + + # Test with pinLocation + self.block.setType(self.block.getType(), Flags.FUEL) + self.block.p.pinLocation = np.random.choice(10, size=10, replace=False) + 1 + self.block.setPinMgFluxes(fluxes) + self.assertEqual(self.block.p.pinMgFluxes.shape, (10, 33)) + self.assertEqual( + self.block.p.pinMgFluxes[p, g], fluxes[self.block.p.pinLocation[p] - 1, g] + ) def test_getComponentsInLinkedOrder(self): comps = self.block.getComponentsInLinkedOrder()