armi.reactor.composites module
Implementation of the Composite base class used to define top-level reactor “containers” (e.g. core, assembly, block).
This follows the principles of the Composite Design Pattern to allow the construction of a part/whole hierarchy representing a physical nuclear reactor in a tree strucutre. The Composite class implements the ‘whole’ aspect of the part/whole hierarchy (this is the Composite class in Gang of Four). The Composite has method represents parts of the reactor that contain other parts within them, such as the core, a fuel assembly, or an individual slice of a fuel assembly called a block.
A Composite object acts somewhat like a list: they can be indexed, iterated over, appended, extended, inserted, etc. Each member of the hierarchy knows its children and its parent, so full access to the hierarchy is available from everywhere.
Warning
Because each member of the hierarchy is linked to the entire tree, it is often unsafe to save references to individual members; it can cause large and unexpected memory inefficiencies.
See also
Developer Docs. armi.reactor.armiObject.ArmiObject armi.reactor.components.component.Component
- class armi.reactor.composites.Composite(name)[source]
Bases:
ArmiObjectAn ArmiObject that has children.
This class implements an interface for accessing and managing child objects.
This is a fundamental ARMI state object that generally represents some piece of the nuclear reactor that is made up of other smaller pieces. This object can cache information about its children to help performance.
Details about spatial representation
Spatial representation of a
Compositeis handled through a combination of thespatialLocatorandspatialGridparameters. ThespatialLocatoris a numpy triple representing either:Indices in the parent’s
spatialGrid(for lattices, etc.), used when the dtype is int.Coordinates in the parent’s universe in cm, used when the dtype is float.
The top parent of any composite must have a coordinate-based
spatialLocator. For example, a Reactor and a Pump should both have coordinates based on how far apart they are.The traversal of indices and grids is recursive. The Reactor/Core/Assembly/Block model is handled by putting a 2-D grid (either Theta-R, Hex, or Cartesian) on the Core and individual 1-D Z-meshes on the assemblies. Then, Assemblies have 2-D spatialLocators (i,j,0) and Blocks have 1-D spatiaLocators (0,0,k). These get added to form the global indices. This way, if an assembly is moved, all the blocks immediately and naturally move with it. Individual children may have coordinate-based spatialLocators mixed with siblings in a grid. This allows mixing grid-representation with explicit representation, often useful in advanced assemblies and thermal reactors.
Implementation: Composites are a physical part of the reactor in a hierarchical data model. I_ARMI_CMP0An ARMI reactor model is composed of collections of ARMIObject objects. This class is a child-class of the ARMIObject class and provides a structure allowing a reactor model to be composed of Composites.
This class provides various methods to query and modify the hierarchical ARMI reactor model, including but not limited to, iterating, sorting, and adding or removing child Composites.
- getArea(cold=False, Tc=None)[source]
Get the area of a Composite in cm^2.
- Parameters:
cold (bool, optional) – Compute the area with as-input dimensions instead of thermally-expanded
Tc (float, optional) – Temperature to compute the area at
- getVolumeFractions()[source]
Return volume fractions of each child.
Sets volume or area of missing piece (like coolant) if it exists.
- Returns:
fracs – list of (component, volFrac) tuples
- Return type:
list
See also
test_block.TestBlock.test_consistentAreaWithOverlappingComponentsNotes
void areas can be negative in gaps between fuel/clad/liner(s), but these negative areas are intended to account for overlapping positive areas to insure the total area of components inside the clad is accurate. See test_block.TestBlock.test_consistentAreaWithOverlappingComponents
- getMass(nuclideNames: None | str | list[str] = None) float[source]
Determine the mass in grams of nuclide(s) and/or elements in this object.
This method allows for the querying of the mass of a Composite. If the
nuclideNamesargument is included, it will filter for the mass of those nuclide names and provide the sum of the mass of those nuclides.- Parameters:
nuclideNames – The nuclide/element specifier to get the mass of in the object. If omitted, total mass is returned.
- Returns:
mass – The mass in grams.
- Return type:
float
- getNumberDensity(nucName)[source]
Return the number density of a nuclide in atoms/barn-cm.
This method queries the number density of a specific nuclide within the Composite. It invokes the
getNuclideNumberDensitiesmethod for just the requested nuclide.- Parameters:
nucName (str) – Nuclide name to get number densities for, e.g. ‘U233’
Notes
This can get called very frequently and has to do volume computations so should use some kind of caching that is invalidated by any temperature, composition, etc. changes. Even with caching the volume calls are still somewhat expensive so prefer the methods in see also.
See also
ArmiObject.getNuclideNumberDensitiesMore efficient for >1 specific nuc density is needed.
ArmiObject.getNumberDensitiesMore efficient for when all nucs in object is needed.
- getNuclideNumberDensities(nucNames)[source]
Return a list of number densities in atoms/barn-cm for the nuc names requested.
- Parameters:
nucNames (list of str) – Nuclide names to get number densities for, e.g. [‘U233’, ‘U235’, ‘Pu239’]
Notes
This method provides the capability to query the volume weighted number densities for a list of nuclides within a given Composite. It provides the result in units of atoms/barn-cm. The volume weighting is accomplished by multiplying the number densities within each child Composite by the volume of the child Composite and dividing by the total volume of the Composite.
- setNumberDensity(nucName, val)[source]
Set the number density of this nuclide to this value.
This distributes atom density evenly across all children that contain nucName. If the nuclide doesn’t exist in any of the children, then that’s actually an error. This would only happen if some unnatural nuclide like Pu239 built up in fresh UZr. That should be anticipated and dealt with elsewhere.
- Parameters:
nucName (str) – Nuclide number density to modify
val (float) – Number density to set in atoms/bn-cm (heterogeneous)
- setNumberDensities(numberDensities)[source]
Set one or more multiple number densities. Reset any non-listed nuclides to 0.0.
- Parameters:
numberDensities (dict) – nucName: ndens pairs.
Notes
We’d like to not have to call setNumberDensity for each nuclide because we don’t want to call
getVolumeFractionsfor each nuclide (it’s inefficient).
- updateNumberDensities(numberDensities)[source]
Set one or more multiple number densities. Leaves unlisted number densities alone.
This changes a nuclide number density only on children that already have that nuclide, thereby allowing, for example, actinides to stay in the fuel component when setting block-level values.
The complication is that various number densities are distributed among various components. This sets the number density for each nuclide evenly across all components that contain it.
- Parameters:
numberDensities (dict) – nucName: ndens pairs.
- changeNDensByFactor(factor)[source]
Change the number density of all nuclides within the object by a multiplicative factor.
- calcTotalParam(param, objs=None, volumeIntegrated=False, addSymmetricPositions=False, typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, generationNum=1, calcBasedOnFullObj=False)[source]
Sums up a parameter throughout the object’s children or list of objects.
- Parameters:
param (str) – Name of the block parameter to sum
objs (iterable, optional) – A list of objects to sum over. If None, all children in object will be used
volumeIntegrated (bool, optional) – Integrate over volume
addSymmetricPositions (bool, optional) – If True, will multiply by the symmetry factor of the core (3 for 1/3 models, 1 for full core models)
typeSpec (TypeSpec) – object types to restrict to
generationNum (int, optional) – Which generation to consider. 1 means direct children, 2 means grandchildren. Default: 1.
calcBasedOnFullObj (bool, optional) – Some assemblies or blocks, such as the center assembly in a third-core model, are not modeled as full assemblies or blocks. In the third-core model, objects at these positions are modeled as having 1/3 the volume and thus 1/3 the power. Setting this argument to True will apply the full value of the parameter as if it was a full block or assembly.
- calcAvgParam(param, typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, weightingParam=None, volumeAveraged=True, absolute=True, generationNum=1)[source]
Calculate the child-wide average of a parameter.
- Parameters:
param (str) – The ARMI block parameter that you want to average
typeSpec (TypeSpec) – The child types that should be included in the calculation. Restrict average to a certain child type with this parameter.
weightingParam (None or str, optional) – An optional block param that the average will be weighted against
volumeAveraged (bool, optional) – volume (or height, or area) average this param
absolute (bool, optional) – Returns the average of the absolute value of param
generationNum (int, optional) – Which generation to average over (1 for children, 2 for grandchildren)
is (The weighted sum)
math:: (..) – left<text{x}right> = frac{sum_{i} x_i w_i}{sum_i w_i}
:param where \(i\) is each child: :param \(x_i\) is the param value of the i-th child: :param : :param and \(w_i\) is the weighting param value of the i-th child.:
Warning
If a param is unset/zero on any of the children, this will be included in the average and may significantly perturb results.
- Returns:
The average parameter value.
- Return type:
float
- getMaxParam(param, typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, absolute=True, generationNum=1, returnObj=False)[source]
Find the maximum value for the parameter in this container.
- Parameters:
param (str) – block parameter that will be sought.
typeSpec (TypeSpec) – restricts the search to cover a variety of block types.
absolute (bool) – looks for the largest magnitude value, regardless of sign, default: true
returnObj (bool, optional) – If true, returns the child object as well as the value.
- Returns:
maxVal (float) – The maximum value of the parameter asked for
obj (child object) – The object that has the max (only returned if
returnObj==True)
- getMinParam(param, typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, absolute=True, generationNum=1, returnObj=False)[source]
Find the minimum value for the parameter in this container.
See also
getMaxParamdetails
- getNuclides()[source]
Determine which nuclides are present in this armi object.
- Returns:
nucs – Nuclide names that exist in this ArmiObject
- Return type:
list of str
- iterChildren(deep=False, generationNum=1, predicate: Callable[[ArmiObject], bool] | None = None) Iterator[ArmiObject][source]
Iterate over children objects of this composite.
- Parameters:
deep (bool, optional) – If true, traverse the entire composite tree. Otherwise, go as far as
generationNum.generationNum (int, optional) – Produce composites at this depth. A depth of
1includes children ofself,2is children of children, and so on.predicate (f(Composite) -> bool, optional) – Function to check on a composite before producing it. All items in the iteration will pass this check.
- Return type:
iterator of Composite and/or Component objects
See also
getChildren(),multiple,indexing,sorting,containment,etc.Composites>>> for child in c.getChildren(): ... pass >>> for child in c.iterChildren(): ... pass >>> for child in c: ... pass
If,naturalThefunc:filter command may be sufficient if you do not wish to pass a predicate. The following
are>>> checker = lambda c: len(c.name) % 3 >>> for child in c.getChildren(predicate=checker): ... pass >>> for child in c.iterChildren(predicate=checker): ... pass >>> for child in filter(checker, c): ... pass
If,this
- iterChildrenWithMaterials(*args, **kwargs) Iterator[source]
Produce an iterator that also includes any materials found on descendants.
Arguments are forwarded to
iterChildren()and control the depth of traversal and filtering of objects.This is useful for sending state across MPI tasks where you need a more full representation of the composite tree. Which includes the materials attached to components.
- getChildren(deep=False, generationNum=1, includeMaterials=False, predicate: Callable[[ArmiObject], bool] | None = None) list[ArmiObject][source]
Return the children objects of this composite.
This method retrieves all children within a given Composite object. Children of any generation can be retrieved. This is achieved by visiting all children and calling this method recursively for each generation requested.
If the method is called with
includeMaterials, it will additionally include information about the material for each child. If a function is supplied as thepredicateargument, then this method will be used to evaluate all children as a filter to include or not. For example, if the caller of this method only desires children with a certain flag, or children which only contain a certain material, then thepredicatefunction can be used to perform this filtering.- Parameters:
deep (boolean, optional) – Return all children of all levels.
generationNum (int, optional) – Which generation to return. 1 means direct children, 2 means children of children. Setting this parameter will only return children of this generation, not their parents. Default: Just return direct children.
includeMaterials (bool, optional) – Include the material properties
predicate (callable, optional) – An optional unary predicate to use for filtering results. This can be used to request children of specific types, or with desired attributes. Not all ArmiObjects have the same methods and members, so care should be taken to make sure that the predicate executes gracefully in all cases (e.g., use
getattr(obj, "attribute", None)to access instance attributes). Failure to meet the predicate only affects the object in question; children will still be considered.
See also
iterChildren(),e.g.,just,overExamples
>>> obj.getChildren() [child1, child2, child3]
>>> obj.getChildren(generationNum=2) [grandchild1, grandchild2, grandchild3]
>>> obj.getChildren(deep=True) [child1, child2, child3, grandchild1, grandchild2, grandchild3]
# Assuming that grandchild1 and grandchild3 are Component objects >>> obj.getChildren(deep=True, predicate=lambda o: isinstance(o, Component)) [grandchild1, grandchild3]
- iterChildrenWithFlags(typeSpec: Flag | auto | Sequence[Flag | auto] | None, exactMatch=False) Iterator[ArmiObject][source]
Produce an iterator of children that have given flags.
- getChildrenWithFlags(typeSpec: Flag | auto | Sequence[Flag | auto] | None, exactMatch=False) list[ArmiObject][source]
Get all children that have given flags.
- iterChildrenOfType(typeName: str) Iterator[ArmiObject][source]
Iterate over children that have a specific input type name.
- getChildrenOfType(typeName: str) list[ArmiObject][source]
Produce a list of children that have a specific input type name.
- doChildrenHaveFlags(typeSpec: Flag | auto | Sequence[Flag | auto] | None, deep=False)[source]
Generator that yields True if the next child has given flags.
- Parameters:
typeSpec (TypeSpec) – Requested type of the child
- containsAtLeastOneChildWithFlags(typeSpec: Flag | auto | Sequence[Flag | auto] | None)[source]
Return True if any of the children are of a given type.
- Parameters:
typeSpec (TypeSpec) – Requested type of the children
See also
self.doChildrenHaveFlags,self.containsOnlyChildrenWithFlags
- containsOnlyChildrenWithFlags(typeSpec: Flag | auto | Sequence[Flag | auto] | None)[source]
Return True if all of the children are of a given type.
- Parameters:
typeSpec (TypeSpec) – Requested type of the children
See also
self.doChildrenHaveFlags,self.containsAtLeastOneChildWithFlags
- copyParamsToChildren(paramNames)[source]
Copy param values in paramNames to all children.
- Parameters:
paramNames (list) – List of param names to copy to children
- getFirstComponent(typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Returns a single Component object within this Composite.
- Parameters:
typeSpec (TypeSpec) – Component flags. Will restrict Components to specific ones matching the flags specified.
exact (bool, optional) – Only match exact component labels (names). If True, ‘coolant’ will not match ‘interCoolant’. This has no impact if typeSpec is None.
- Returns:
The first item matching typeSpec and exact criteria
- Return type:
Component
- iterComponents(typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact: bool = False) Iterator[Component][source]
Return an iterator of armi.reactor.component.Component objects within this Composite.
- Parameters:
typeSpec (TypeSpec) – Component flags. Will restrict Components to specific ones matching the flags specified.
exact (bool, optional) – Only match exact component labels (names). If True, ‘coolant’ will not match ‘interCoolant’. This has no impact if typeSpec is None.
- Returns:
items matching typeSpec and exact criteria
- Return type:
iterator of Component
- getComponentNames()[source]
Get all unique component names of this Composite.
- Returns:
A set of all unique component names found in this Composite.
- Return type:
set or str
- getComponentsOfShape(shapeClass)[source]
Return list of components in this block of a particular shape.
- Parameters:
shapeClass (Component) – The class of component, e.g. Circle, Helix, Hexagon, etc.
- Returns:
param – List of components in this block that are of the given shape.
- Return type:
list
- getComponentsOfMaterial(material=None, materialName=None)[source]
Return list of components in this block that are made of a particular material.
Only one of the selectors may be used
- Parameters:
material (armi.materials.material.Material, optional) – The material to match
materialName (str, optional) – The material name to match.
- Returns:
componentsWithThisMat
- Return type:
list
- hasComponents(typeSpec: Flag | auto | Sequence[Flag | auto] | None | List[Flag | auto | Sequence[Flag | auto] | None], exact=False)[source]
Return true if components matching all TypeSpec exist in this object.
- Parameters:
typeSpec (Flags or iterable of Flags) – Component flags to check for
- getComponentByName(name: str) Component[source]
Gets a particular component from this object, based on its name.
- Parameters:
name – The blueprint name of the component to return
- Return type:
Component, c, whose c.name matches name.
- getComponent(typeSpec: Flag | auto | Sequence[Flag | auto] | None, exact: bool = False, quiet: bool = True) Component | None[source]
Get a particular component from this object.
Be careful with multiple similar names in one object.
- Parameters:
typeSpec (flags.Flags or list of Flags) – The type specification of the component to return
exact (boolean, optional) – Demand that the component flags be exactly equal to the typespec. Default: False
quiet (boolean, optional) – Log if the component is not found. Default: True
- Returns:
Component
- Return type:
The component that matches the criteria or None
- Raises:
ValueError – more than one Component matches the typeSpec:
- getComponents(typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Return a list of Component objects within this Composite.
- Parameters:
typeSpec (TypeSpec) – Component flags. Will restrict Components to specific ones matching the flags specified.
exact (bool, optional) – Only match exact component labels (names). If True, ‘coolant’ will not match ‘interCoolant’. This has no impact if typeSpec is None.
- Returns:
items matching typeSpec and exact criteria
- Return type:
list of Component
- getNumComponents(typeSpec: Flag | auto | Sequence[Flag | auto] | None, exact=False)[source]
Get the number of components that have these flags, taking into account multiplicity. Useful for getting nPins even when there are pin detailed cases.
- Parameters:
typeSpec (Flags) – Expected flags of the component to get. e.g. Flags.FUEL
- Returns:
total – the number of components of this type in this object, including multiplicity.
- Return type:
int
- setComponentDimensionsReport()[source]
Makes a summary of the dimensions of the components in this object.
- getBoundingIndices()[source]
Find the 3-D index bounds (min, max) of all children in the spatial grid of this object.
- Returns:
bounds – ((minI, maxI), (minJ, maxJ), (minK, maxK))
- Return type:
tuple
- expandElementalToIsotopics(elementalNuclide)[source]
Expand the density of a specific element to its natural isotopic distribution.
- Parameters:
elementalNuclide (
armi.nucDirectory.nuclideBases.NaturalNuclideelement to) – expand into natural isotopic distribution.
- getAverageTempInC(typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Return the volume-averaged temperature (in degrees Celsius) of the ArmiObject over all children.
- Parameters:
typeSpec (TypeSpec) – Component flags. Will restrict Components to specific ones matching the flags specified.
exact (bool, optional) – Only match exact component labels (names). If True, ‘coolant’ will not match ‘interCoolant’. This has no impact if typeSpec is None.
- Returns:
averageTemperature – Child-averaged temperature (in degrees Celsius)
- Return type:
float
- getDominantMaterial(typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Return the first sample of the most dominant material (by volume) in this object.
- Parameters:
typeSpec (Flags or iterable of Flags, optional) – The types of components to consider (e.g.
[Flags.FUEL, Flags.CONTROL])exact (bool, optional) – Whether or not the TypeSpec is exact
- Returns:
mat – the first instance of the most dominant material (by volume) in this object.
- Return type:
See also
getComponentsOfMaterialGets components that are made of a particular material
gatherMaterialsByVolumeClassifies all materials by volume
- syncMpiState()[source]
Synchronize all parameters of this object and all children to all worker nodes over the network using MPI.
In parallelized runs, if each process has its own copy of the entire reactor hierarchy, this method synchronizes the state of all parameters on all objects.
Parameters need to be handled properly during parallel code execution. This method synchronizes all parameters of the composite object across all processes by cycling through all the children of the Composite and ensuring that their parameters are properly synchronized. If it fails to synchronize, an error message is displayed which alerts the user to which Composite has inconsistent data across the processes.
- Returns:
number of parameters synchronized over all components
- Return type:
int
- getLumpedFissionProductsIfNecessary(nuclides=None)[source]
Return Lumped Fission Product objects that belong to this object or any of its children.
- getLumpedFissionProductCollection()[source]
Get collection of LFP objects. Will work for global or block-level LFP models.
- Returns:
lfps – lfpName keys, lfp object values
- Return type:
object
- requiresLumpedFissionProducts(nuclides=None)[source]
True if any of the nuclides in this object are Lumped nuclides.
- getIntegratedMgFlux(adjoint=False, gamma=False)[source]
Returns the multigroup neutron tracklength in [n-cm/s].
The first entry is the first energy group (fastest neutrons). Each additional group is the next energy group, as set in the ISOTXS library.
- Parameters:
adjoint (bool, optional) – Return adjoint flux instead of real
gamma (bool, optional) – Whether to return the neutron flux or the gamma flux.
- Returns:
integratedFlux – multigroup neutron tracklength in [n-cm/s]
- Return type:
np.ndarray
- getReactionRates(nucName, nDensity=None)[source]
Get the reaction rates of a certain nuclide on this ArmiObject.
- Parameters:
nucName (str) – nuclide name – e.g. ‘U235’
nDensity (float) – number Density
- Returns:
rxnRates – reaction rates (1/s) for nG, nF, n2n, nA and nP
- Return type:
dict
Notes
This is volume integrated NOT (1/cm3-s).
If you set nDensity to 1 this makes 1-group cross section generation easier.
- printContents(includeNuclides=True)[source]
Display information about all the comprising children in this object.
- getBoundingCircleOuterDiameter(Tc=None, cold=False)[source]
Get sum circle bound.
Used to roughly approximate relative size vs. other objects
- retainState(paramsToApply=None)[source]
Restores a state before and after some operation.
- Parameters:
paramsToApply (iterable) – Parameters that should be applied to the state after existing the state retainer. All others will be reverted to their values upon entering.
Notes
This should be used in a with statement.
- paramCollectionType
alias of
ArmiObjectParameterCollection
- class armi.reactor.composites.StateRetainer(composite: Composite, paramsToApply=None)[source]
Bases:
objectRetains state during some operations.
This can be used to temporarily cache state, perform an operation, extract some info, and then revert back to the original state.
A state retainer is faster than restoring state from a database as it reduces the number of IO reads; however, it does use more memory.
This can be used on any object within the composite pattern via with
[rabc].retainState([list], [of], [parameters], [to], [retain]):. Use on an object up in the hierarchy applies to all objects below as well.This is intended to work across MPI, so that if you were to broadcast the reactor the state would be correct; however the exact implication on
parametersmay be unclear.
Create an instance of a StateRetainer.
- Parameters:
composite (Composite) – composite object to retain state (recursively)
paramsToApply (iterable of parameters.Parameter) – Iterable of parameters.Parameter to retain updated values after __exit__. All other parameters are reverted to the original state, i.e. retained at the original value.
- armi.reactor.composites.gatherMaterialsByVolume(objects: List[ArmiObject], typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Compute the total volume of each material in a set of objects and give samples.
- Parameters:
objects (list of ArmiObject) – Objects to look within. This argument allows clients to search though some subset of the three (e.g. when you’re looking for all CLADDING components within FUEL blocks)
typeSpec (TypeSpec) – Flags for the components to look at
exact (bool) – Whether or not the TypeSpec is exact
Notes
This helper method is outside the main ArmiObject tree for the special clients that need to filter both by container type (e.g. Block type) with one set of flags, and Components with another set of flags.
Warning
This is a composition related helper method that will likely be filed into classes/modules that deal specifically with the composition of things in the data model. Thus clients that use it from here should expect to need updates soon.
- armi.reactor.composites.getDominantMaterial(objects: List[ArmiObject], typeSpec: Flag | auto | Sequence[Flag | auto] | None = None, exact=False)[source]
Return the first sample of the most dominant material (by volume) in a set of objects.
Warning
This is a composition related helper method that will likely be filed into classes/modules that deal specifically with the composition of things in the data model. Thus clients that use it from here should expect to need updates soon.