Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into drewj/improve-assem-a…
Browse files Browse the repository at this point in the history
…xial-linkage

* origin/main:
  Relaxing copyInterfaceInputs to not require a valid Setting (#1934)
  Moving C5G7 into its own test dir (#1941)
  Transposing pinMgFluxes so that the leading dimension represents pin index (#1937)
  • Loading branch information
drewj-tp committed Oct 11, 2024
2 parents dbea10c + f8d3632 commit 142d814
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 58 deletions.
31 changes: 18 additions & 13 deletions armi/cases/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ def copyInterfaceInputs(
enables developers to add new inputs in a plugin-dependent/ modular way.
This function should now be able to handle the updating of:
- a single file (relative or absolute)
- a list of files (relative or absolute), and
- a file entry that has a wildcard processing into multiple files.
Expand All @@ -896,12 +897,12 @@ def copyInterfaceInputs(
The source case settings to find input files
destination : str
The target directory to copy input files to
sourceDir : str (optional)
sourceDir : str, optional
The directory from which to copy files. Defaults to cs.inputDirectory
Returns
-------
newSettings : dict
dict
A new settings object that contains settings for the keys and values that are
either an absolute file path, a list of absolute file paths, or the original
file path if absolute paths could not be resolved
Expand All @@ -927,12 +928,15 @@ def copyInterfaceInputs(
if not isinstance(key, settings.Setting):
try:
key = cs.getSetting(key)
label = key.name
isSetting = True
except NonexistentSetting(key):
raise ValueError(
f"{key} is not a valid setting. Ensure the relevant specifyInputs "
"method uses a correct setting name."
)
label = key.name
runLog.debug(f"{key} is not a valid setting; continuing on anyway.")
label = key
isSetting = False
else:
isSetting = True
label = key.name

newFiles = []
for f in files:
Expand Down Expand Up @@ -977,15 +981,16 @@ def copyInterfaceInputs(

if destFilePath == f:
runLog.debug(
f"No input files for `{label}` setting could be resolved with "
f"the following path: `{sourceFullPath}`. Will not update `{label}`."
f"No input files for `{label}` could be resolved with the "
f"following path: `{sourceFullPath}`. Will not update `{label}`."
)

# Some settings are a single filename. Others are lists of files. Make
# sure we are returning what the setting expects
if len(files) == 1 and not WILDCARD:
newSettings[label] = newFiles[0]
else:
newSettings[label] = newFiles
if isSetting:
if len(files) == 1 and not WILDCARD:
newSettings[label] = newFiles[0]
else:
newSettings[label] = newFiles

return newSettings
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion armi/tests/test_lwrInputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_loadC5G7(self):

# load the reactor
_o, r = test_reactors.loadTestReactor(
os.path.join(TEST_ROOT, "tutorials"),
os.path.join(TEST_ROOT, "c5g7"),
inputFileName=TEST_INPUT_TITLE,
)

Expand Down
2 changes: 1 addition & 1 deletion armi/utils/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_plotCartesianBlock(self):

with TemporaryDirectoryChanger():
cs = settings.Settings(
os.path.join(TEST_ROOT, "tutorials", "c5g7-settings.yaml")
os.path.join(TEST_ROOT, "c5g7", "c5g7-settings.yaml")
)

blueprint = blueprints.loadFromCs(cs)
Expand Down
2 changes: 2 additions & 0 deletions doc/release/0.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ API Changes
#. Removing deprecated method ``prepSearch``. (`PR#1845 <https://github.com/terrapower/armi/pull/1845>`_)
#. Removing unused function ``SkippingXsGen_BuChangedLessThanTolerance``. (`PR#1845 <https://github.com/terrapower/armi/pull/1845>`_)
#. Renaming ``Reactor.moveList`` to ``Reactor.moves``. (`PR#1881 <https://github.com/terrapower/armi/pull/1881>`_)
#. ``copyInterfaceInputs`` no longer requires a valid setting object. (`PR#1934 <https://github.com/terrapower/armi/pull/1934>`_)
#. Removing ``buildEqRingSchedule``. (`PR#1928 <https://github.com/terrapower/armi/pull/1928>`_)
#. 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
26 changes: 13 additions & 13 deletions doc/tutorials/walkthrough_lwr_inputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ to specify their composition. The composition details below are documented in Ta
`NEA/NSC/DOC(96)2 <https://www.oecd-nea.org/upload/docs/application/pdf/2020-01/nsc-doc96-02-rev2.pdf>`_.


.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: start-custom-isotopics
:end-before: end-custom-isotopics
Expand All @@ -64,7 +64,7 @@ position in the grid that has any of the specifiers in this list.
You will see the `<<: *guide_tube` notation below. This means use the
specifications of guide_tube, but make the modifications that apear below.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-custom-isotopics
:end-before: end-block-uo2
Expand All @@ -79,7 +79,7 @@ The next assembly is very similar. We define three separate fuel pins,
each with different ``latticeIDs``, and then use YAML anchors to just
copy the moderator, guide tube, and fission chamber from the previous assembly.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-block-uo2
:end-before: end-block-mox
Expand All @@ -88,7 +88,7 @@ The moderator block
-------------------
The moderator block for the radial and axial reflectors is very simple:

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-block-mox
:end-before: end-block-mod
Expand All @@ -98,7 +98,7 @@ The 3-D Assembly definitions
Now that the pins are defined, we stack them into assemblies, very similar
to what we did in the SFR tutorial. There are three distinct assembly definitions.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-block-mod
:end-before: end-assemblies
Expand All @@ -111,7 +111,7 @@ they would be here alongside the core. We also anchor the core at the global
coordinates (0,0,0). If we wanted the core at some other elevation, we could
adjust that here.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-assemblies
:end-before: end-systems
Expand All @@ -124,7 +124,7 @@ from an XML file. In this tutorial, we define the grid directly with an
textual ``lattice map`` input section. The core map is particularly simple; it
only has 9 assemblies.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-systems
:end-before: end-grid-core
Expand All @@ -134,14 +134,14 @@ Recall that on the ``uo2`` block above we said that we want to apply the grid
with the name ``UO2 grid``, and wanted to fill any ``U`` position with
the ``fuel`` component defined up there. Here's where we define that grid.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-grid-core
:end-before: end-grid-UO2

Similarly, we define the ``MOX grid`` as follows:

.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-grid-UO2
:end-before: end-grid-MOX
Expand All @@ -151,7 +151,7 @@ the assembly.

Nuclide Flags
-------------
.. literalinclude:: ../../armi/tests/tutorials/c5g7-blueprints.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-blueprints.yaml
:language: yaml
:start-after: end-grid-MOX
:end-before: end-nucflags
Expand All @@ -167,7 +167,7 @@ Really, the only thing the settings file does in this case is point to the bluep
file. As we turn this case into an actual run, we may add various cross section
and neutrons options to evaluate the benchmark.

.. literalinclude:: ../../armi/tests/tutorials/c5g7-settings.yaml
.. literalinclude:: ../../armi/tests/c5g7/c5g7-settings.yaml
:language: yaml

Defining fuel management
Expand Down Expand Up @@ -228,5 +228,5 @@ This should show a simple representation of the block.

Here are the full files used in this example:

* :download:`Blueprints <../../armi/tests/tutorials/c5g7-blueprints.yaml>`
* :download:`Settings <../../armi/tests/tutorials/c5g7-settings.yaml>`
* :download:`Blueprints <../../armi/tests/c5g7/c5g7-blueprints.yaml>`
* :download:`Settings <../../armi/tests/c5g7/c5g7-settings.yaml>`
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ armi = [
"tests/1DslabXSByCompTest.yaml",
"tests/armiRun-SHUFFLES.txt",
"tests/armiRun.yaml",
"tests/c5g7",
"tests/c5g7/c5g7-blueprints.yaml",
"tests/c5g7/c5g7-settings.yaml",
"tests/COMPXS.ascii",
"tests/detailedAxialExpansion/armiRun.yaml",
"tests/detailedAxialExpansion/refSmallCoreGrid.yaml",
Expand Down

0 comments on commit 142d814

Please sign in to comment.