armi.bookkeeping.db.layout module

Groundwork for ARMI Database, version 3.4.

When interacting with the database file, the Layout class is used to help map the hierarchical Composite Reactor Model to the flat representation in Database3.

This module also stores packing/packing tools to support Database3, as well as datbase versioning information.

class armi.bookkeeping.db.layout.Layout(version: Tuple[int, int], h5group=None, comp=None)[source]

Bases: object

The Layout class describes the hierarchical layout of the Composite Reactor model in a flat representation for Database3.

A Layout is built by starting at the root of a composite tree and recursively appending each node in the tree to a list of data. So the data will be ordered by depth-first search: [r, c, a1, a1b1, a1b1c1, a1b1c2, a1b2, a1b2c1, …, a2, …].

The layout is also responsible for storing Component attributes, like location, material, and temperatures, which aren’t stored as Parameters. Temperatures, specifically, are rather complicated in ARMI.

Notes

  • Elements in Layout are stored in depth-first order. This permits use of algorithms such as Pre-Order Tree Traversal for efficient traversal of regions of the model.

  • indexInData increases monotonically within each object type. For example, the data for all HexBlock children of a given parent are stored contiguously within the HexBlock group, and will not be interleaved with data from the HexBlock children of any of the parent’s siblings.

  • Aside from the hierarchy, there is no guarantee what order objects are stored in the layout. The Core is not necessarily the first child of the Reactor, and is not guaranteed to use the zeroth grid.

writeToDB(h5group)[source]
static computeAncestors(serialNum, numChildren, depth=1) List[Optional[int]][source]

Return a list containing the serial number of the parent corresponding to each object at the given depth.

Depth in this case means how many layers to reach up to find the desired ancestor. A depth of 1 will yield the direct parent of each element, depth of 2 would yield the elemen’s parent’s parent, and so on.

The zero-th element will always be None, as the first object is the root element and so has no parent. Subsequent depths will result in more Nones.

This function is useful for forming a lightweight sense of how the database contents stitch together, without having to go to the trouble of fully unpacking the Reactor model.

Parameters
  • serialNum (List of int) – List of serial numbers for each object/element, as laid out in Layout

  • numChildren (List of int) – List of numbers of children for each object/element, as laid out in Layout

Note

This is not using a recursive approach for a couple of reasons. First, the iterative form isn’t so bad; we just need two stacks. Second, the interface of the recursive function would be pretty unwieldy. We are progressively consuming two lists, of which we would need to keep passing down with an index/cursor, or progressively slice them as we go, which would be pretty inefficient.

static allSubclasses(cls) set[source]

Find all subclasses of the given class, in any namespace.

armi.bookkeeping.db.layout.replaceNonesWithNonsense(data: numpy.ndarray, paramName: str, nones: Optional[numpy.ndarray] = None) numpy.ndarray[source]

Replace instances of None with nonsense values that can be detected/recovered when reading.

Parameters
  • data – The numpy array containing None values that need to be replaced.

  • paramName – The name of the parameter who’s data we are treating. Only used for diagnostics.

  • nones – An array containing the index locations on the None elements. It is a little strange to pass these, in but we find these indices to determine whether we need to call this function in the first place, so might as well pass it in, so that we don’t need to perform the operation again.

Notes

This only supports situations where the data is a straight-up None, or a valid, database-storable numpy array (or easily convertable to one (e.g. tuples/lists with numerical values)). This does not support, for instance, a numpy ndarray with some Nones in it.

For example, the following is supported:

[[1, 2, 3], None, [7, 8, 9]]

However, the following is not:

[[1, 2, 3], [4, None, 6], [7, 8, 9]]

See also

replaceNonsenseWithNones

Reverses this operation.

armi.bookkeeping.db.layout.replaceNonsenseWithNones(data: numpy.ndarray, paramName: str) numpy.ndarray[source]

Replace special nonsense values with None.

This essentially reverses the operations performed by replaceNonesWithNonsense().

Parameters
  • data – The array from the database that contains special None nonsense values.

  • paramName – The param name who’s data we are dealing with. Only used for diagnostics.