armi.reactor.parameters.resolveCollections module
Machinery that makes the Parameter system and ARMI composite model play nicely together.
The contained metaclass is useful for maintaining a hierarchy of ParameterCollection classes, which mimic the
hierarchy of ArmiObject s to which they apply. Some ArmiObject subclasses define their own parameters, while
others do not, so we do not want to blindly create a ParameterCollectionClass for each ArmiObject subclass.
Instead, we want to be able to skip generations when no additional parameters were requested for that level. For
instance if we have a hierarchy like: ArmiObject <- A <- B, where ArmiObject and B define
parameters, while A does not define any parameters of its own, we want to have a ArmiObjectParameterCollection
and a BParameterCollection (with BParameterCollection being a subclass of ArmiObjectParameterCollection).
ArmiObject and A will both share the ArmiObjectParameterCollection, while B will use
BParameterCollection. BParameterCollection will contain all of the parameters defined in
ArmiObjectParameterCollection, plus whatever additional parameters were defined on B.
The above scenario should behave rather intuitively for someone used to classes and inheritance, but maintaining this
hierarchy by hand would be onerous and error-prone. What if one day we decide to add some parameters to A? We need
to remember to add a new class for its parameters, and make sure to make BParameterCollection a subclass of that new
ParameterCollection class. With the below metaclass, we needn’t worry ourselves with any of that; it is taken care
of automatically.
If you want to know how the sausage is made, the ResolveParametersMeta metaclass is responsible for forming a
hierarchy of ParameterCollection classes that correspond to the related hierarchy of classes inheriting the root
ArmiObject class. It should be rare for an ARMI developer not engaged directly with Framework development to need to
know exactly how this works, but a proficient ARMI developer must keep in mind the following rules about how this system
behaves in practice:
When defining subclasses of
ArmiObject, defining a class attribute calledpDefsof theParameterDefinitionCollectiontype signals to the system that this is a Parameter Class.When defining a Parameter Class, it will trigger the creation of a new
ParameterCollectionclass, which will be derived from theParameterCollectionclass of the most immediate Parameter Class ancestor the new class’s inheritance tree.All classes derived from
ArmiObjectwill receive an associated subclass ofParameterCollection, which will ultimately include all of the relevant Parameters for that class. The specific class is theParameterCollectionsubclass defined for the most immediate Parameter Class in the classes inheritance tree.Parameter definitions can be added to a Parameter Class’s
pDefsuntil Parameters have been “compiled” for it. After compiling parameters, thepDefsare locked, and any attempts at defining additional parameters will cause an error.ArmiObjects cannot be instantiated until after parameters have been compiled.
- class armi.reactor.parameters.resolveCollections.ResolveParametersMeta(name, bases, attrs)[source]
Bases:
typeMetaclass for automatically defining associated ParameterCollection classes.
Any class invoking this metaclass will automatically create an associated sub-class of the
ParameterCollectiontype, if it has a class attribute calledpDefsthat is an instance ofParameterDefinitionCollection. This new class will itself be a subclass of theParameterCollectionclass that is associated with the invoking class’s parent.If no
pDefsclass attribute is present, the invoking class will adopt theParameterCollectionclass associated with it’s parent, orNoneif it cannot find one.The associated
ParameterCollectionwill be stored on the new class’sparamCollectionTypeattribute.For example, when this metaclass is applied to the
Blockclass it will create a new class namedBlockParameterCollection, and add it as a class attribute calledBlock.paramCollectionType. TheBlockParameterCollectionclass will itself be a subclass ofArmiObjectParameterCollection, which it would have found from theCompositeclass from which theBlockclass inherits. TheCompositeclass, on the other hand, would have obtained theArmiObjectParameterCollectionfrom it’s parent (ArmiObject), since it does not have apDefsattribute of its own.