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

Extensibility improvements to axial expansion classes #1920

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

drewj-tp
Copy link
Contributor

@drewj-tp drewj-tp commented Sep 30, 2024

What is the change?

A handful of improvements to allow subclasses of axial expansion things more control. A general theme was to take large methods and break them up so subclasses can override at their discretion.

Some documentation has been added to axial expansion related classes. It's by no means complete, nor to the level of #935. But as I fumbled through the code and got helped from @albeanth, I added what I could to the docstrings.
 

Why is the change being made?

I am working on features internally that need more control over performing axial expansion that require these changes.

Closes #1453

Closes #1918


Checklist

  • The release notes have been updated if necessary.
  • The documentation is still up-to-date in the doc folder.
  • The dependencies are still up-to-date in pyproject.toml.

Use early `return` statements to dedent the function. Renamed
to `areAxiallyLinked` to be a bit more declarative, even though
this function lives in the axial expansion routine.

Add some type hints
The values in the linkage dictionaries on `AssemblyAxialLinkage` were
lists of two items where the position meant something: `0` for linked
item below the current thing, and `1` for linked item above the current
thing. Some functionality was based on `links[1] is not None` which is
not super readable unless you're familiar with what's going on.

This introduces a small data class with two attributes: `lower` and
`upper` such that `links.lower is links[0]` and `links.upper is
links[1]`. This improves readability and extensibility by making a more
explicit and declarative thing. The position-based getters and setters
are retained and tested.

The class is "templated" with a `typing.Generic[typing.TypeVar]` that
could be either `Block` or `Component`. This is because the the two
linked dictionaries on the `AssemblyAxialLinkage` class only differ
based on the types of their values. We still need to know lower/upper as
determined by the values, but for the block link dict we want blocks and
then components from the component link dict.
Also rename componentLst to components in
setExpansionFactors in an effort to remove type names from variable names
Single method that iterate over all blocks in an assembly and then
all components in each block is now broken across a per-block method
and a per-component method. This distinction will also allow subclasses
to provide specific expansion methods on a more granular level.
The getSolidComponents produces a list which may not be needed in all situations. Lots
of usage of getSolidComponents was for iteration, e.g.,
`for c in getSolidComponents(b)` where producing an iterable is sufficient.
Move docstring to class definition and outside `__init__` for
consistency.
Useful for testing what you get is what you expect. Tests added
to this effect.

Renamed an internal variable from `componentWFlag` to `candidates` because
the name implied `componentWFlag` was a single component when it was a
(potentially empty) list of components.

Finally, bring out the setting of the target component to a separate
method. This is useful for subclasses that may need custom logic to
determine their target component, but want to perform the same actions
on the setter.
Useful for subclasses to override. Calls back to existing function
for small code change.
@drewj-tp drewj-tp added the enhancement New feature or request label Sep 30, 2024
@drewj-tp drewj-tp self-assigned this Sep 30, 2024
…xial-linkage

* origin/main:
  Alphabetizing Flags.toString results (#1912)
  Organizing test settings files by category (#1914)
This implementation an O(N^2) iteration where each block also iterates over all blocks in the assembly. The use of itertools.chain and itertools.islice provide
a more efficient and streamlined iteration look.

The call signature is for a `Sequence[Block]` which could just as easily be
`Assembly`. We can't use just `Iterable[Block]` because we need to perform
multiple iterations on the object at once. And things like a generator may
get consumed part way through the iteration. And for testing, passing a list
of blocks gets the same behavior as passing one assembly.

Tests for zero blocks, one block, and multiple blocks added.
@john-science john-science marked this pull request as ready for review October 2, 2024 20:18
Copy link
Member

@john-science john-science left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As code cleanup goes, I think this is an improvement. Thanks!

Copy link
Member

@albeanth albeanth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments for you! Looking into the tests now, but wanted to get these comments off to you.

@@ -217,15 +246,21 @@ def _setTargetComponents(self, setFuel):
elif b.hasFlags(Flags.PLENUM) or b.hasFlags(Flags.ACLP):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't comment above, but the content in the if b.p.axialExpTargetComponent block above should be replaced by a call to _setExpansionTarget.

drewj-tp and others added 11 commits October 7, 2024 11:49
…e' into drewj/improve-assem-axial-linkage

* origin/drewj/improve-assem-axial-linkage:
  Apply suggestions from code review
Only really provided for back compatability with the existing list
API. But this is far enough down the axial expansion API, which already
has dubious widespread usage, that we're okay removing this
unceremoniously.
…xial-linkage

* origin/main:
  Adding support for ex-core structures (#1891)
  Fixing edge case in assemblyBlueprint._checkParamConsistency (#1929)
  Improving the robustness of  HexBlock._rotatePins() (#1859)
  Removing unnecessary column in print-out (#1925)
  Updating parameter-related docs (#1919)
@albeanth
Copy link
Member

albeanth commented Oct 8, 2024

@john-science this PR is apart of a larger downstream internal change, so please hold off on merging this. thank you!

john-science and others added 7 commits October 9, 2024 10:54
…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)
…xial-linkage

* origin/main:
  Removing defunct comment from getPinCoordinates (#1931)
…-axial-linkage' into drewj/improve-assem-axial-linkage

* refs/remotes/origin/drewj/improve-assem-axial-linkage:
  Black
  Update armi/reactor/converters/tests/test_axialExpansionChanger.py
…xial-linkage

* origin/main:
  New plugin hook for before reactor construction (#1945)
  Removing DoseResultsMapper (#1952)
  Adding logic so HexAssemblies are hexagonal (#1935)
  Adding Block.getInputHeight (#1927)
  Removing Assembly.doubleResolution (#1951)
  Adding DeprecationWarning for HistoryTrackerInterface (#1950)
  Removing tabulate as a dependency (#1948)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow axial expansion related classes to be more extensible Remove unnecessary spec for dummy block
3 participants