Skip to content

Commit

Permalink
Transposing pinMgFluxes so that the leading dimension represents pin …
Browse files Browse the repository at this point in the history
…index (#1937)
  • Loading branch information
zachmprince authored Oct 9, 2024
1 parent 6dd28a1 commit 3d0b871
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions armi/physics/neutronics/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
""",
Expand All @@ -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,
Expand All @@ -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,
Expand Down
31 changes: 8 additions & 23 deletions armi/reactor/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,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
Expand All @@ -367,28 +364,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.")
Expand Down
24 changes: 20 additions & 4 deletions armi/reactor/tests/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1715,13 +1715,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()
Expand Down
1 change: 1 addition & 0 deletions doc/release/0.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ API Changes
#. Allowing for unknown Flags when opening a DB. (`PR#1844 <https://github.com/terrapower/armi/pull/1835>`_)
#. Removing ``assemblyLists.py`` and the ``AssemblyList`` class. (`PR#1891 <https://github.com/terrapower/armi/pull/1891>`_)
#. Removing ``Assembly.rotatePins`` and ``Block.rotatePins``. Prefer ``Assembly.rotate`` and ``Block.rotate``. (`PR#1846 <https://github.com/terrapower/armi/1846`_)
#. Transposing ``pinMgFluxes`` parameters so that leading dimension is pin index (`PR#1937 <https://github.com/terrapower/armi/pull/1937>`)
#. TBD

Bug Fixes
Expand Down

0 comments on commit 3d0b871

Please sign in to comment.