Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transposing pinMgFluxes so that the leading dimension represents pin index #1937

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand All @@ -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)]
drewj-tp marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -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()
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 @@ -31,6 +31,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
Loading