Open drewj-tp opened 1 month ago
Things that could be looked at later
Assembly.iterBlocks
Assembly.iterBlocksBetweenHeights
Block.iterComponentsThatAreLinkedTo
Core.iterAssemblies
Core.iterAssembliesInRing
Core.iterBlocks
Non-exhaustive
Things that could be looked at later
Assembly.iterBlocks
Assembly.iterBlocksBetweenHeights
Block.iterComponentsThatAreLinkedTo
Core.iterAssemblies
Core.iterAssembliesInRing
Core.iterBlocks
If I were to be choosy, I would do Core.iterAssemblies
and Core.iterAssembliesInRing
last. In an ideal world I would wait until we separate out Core
and HexCore
or something.
Just thinking aloud.
If I were to be choosy, I would do Core.iterAssemblies and Core.iterAssembliesInRing last. In an ideal world I would wait until we separate out Core and HexCore or something.
Agree. I don't intend on tackling things outside Composite.iter*
in the first go
Some additional digging.
Composite.getChildren
has an option that also adds the materials to the list of returned things found in the recursive dig. That feels weird.
That mode, includeMaterials=True
is only used twice in armi and internal projects I can access. Both instances are for MPI related distribution and syncing
But Composite.getChildren
is used heavily! And a lot of iteration, e.g., for c in thing.getChildren
. But in a lot of cases, where no arguments are provided, it seems to be a way to just iterate over the children of a composite. Which is naturally supported with __iter__
There are few recursive usage of getChildren
, like for VTK visualization
So maybe some wide-spread improvements could be
for child in parent.getChildren
with plain iteration for child in parent
.generationNum
getChildren
, with materials, to use the recursive iterator
ARMI does a lot of iteration over the composite tree. Understandably so, we have lots of methods that support iterating over children of an object, with some filtering. These usually follow the pattern of
parent.getChildren*
likeComposite.getChildren
,Composite.getChildrenWithFlags
, andComposite.getChildrenOfType
, further expanded to things likeAssembly.getBlocks
.A lot of instances of the usage of these
get*
methods are for iterationhttps://github.com/terrapower/armi/blob/96a5c88d6167cee989378599b6d341c351c291bd/armi/reactor/components/component.py#L965
https://github.com/terrapower/armi/blob/96a5c88d6167cee989378599b6d341c351c291bd/armi/reactor/converters/axialExpansionChanger/expansionData.py#L253
https://github.com/terrapower/armi/blob/96a5c88d6167cee989378599b6d341c351c291bd/armi/reactor/blocks.py#L633
The tradeoff is these
get*
methods create and populate lists, and then return those lists back to the user. This is great if you need to do multiple iterations or check sizing of the returned object, but it's inefficient for iteration.I propose we provide
iter*
methods with similar signatures as theirget*
counterparts that do not return lists of things. Instead, they couldyield
back components, produce afilter
object, etc. something that allows one-pass iteration over things. Theget*
methods could then be distilled tofor backwards compatibility.
Candidate methods
To keep the scope clear, I propose we add, test, and use (where appropriate)
Composite.iterChildren
Composite.iterChildrenWithFlags
Composite.iterChildrenOfType
There are other composite subclasses that I believe could benefit from more iteration methods. But for start, I'll keep the scope limited to
Composite
methods