armi.interfaces module
Interfaces are objects of code that interact with ARMI. They read information off the state, perform calculations (or run external codes), and then store the results back in the state.
Learn all about interfaces in Framework Architecture
See also
armi.operators
Schedule calls to various interfaces
armi.plugins
Register various interfaces
- class armi.interfaces.STACK_ORDER[source]
Bases:
object
Constants that help determine the order of modules in the interface stack.
Each module defines an
ORDER
constant that specifies where in this order it should be placed in the Interface Stack.See also
armi.operators.operator.Operator.createInterfaces
,armi.physics.neutronics.globalFlux.globalFluxInterface.ORDER
- BEFORE = -0.1
- AFTER = 0.1
- PREPROCESSING = 1.0
- FUEL_MANAGEMENT = 2.0
- DEPLETION = 3.0
- FUEL_PERFORMANCE = 4.0
- CROSS_SECTIONS = 5.0
- CRITICAL_CONTROL = 6.0
- FLUX = 7.0
- THERMAL_HYDRAULICS = 8.0
- REACTIVITY_COEFFS = 9.0
- TRANSIENT = 10.0
- BOOKKEEPING = 11.0
- POSTPROCESSING = 12.0
- class armi.interfaces.TightCoupler(param, tolerance, maxIters)[source]
Bases:
object
Data structure that defines tight coupling attributes that are implemented within an Interface and called upon when
interactAllCoupled
is called.- Parameters:
param (str) – The name of a parameter defined in the ARMI Reactor model.
tolerance (float) – Defines the allowable error between the current and previous parameter values to determine if the selected coupling parameter has converged.
maxIters (int) – Maximum number of tight coupling iterations allowed
- storePreviousIterationValue(val: [<class 'float'>, <class 'int'>, <class 'list'>, <class 'numpy.ndarray'>])[source]
Stores the previous iteration value of the given parameter.
- Parameters:
val (_SUPPORTED_TYPES) – the value to store. Is commonly equal to interface.getTightCouplingValue()
- Raises:
TypeError – Checks the type of the val against
_SUPPORTED_TYPES
before storing. If invalid, a TypeError is raised.
- isConverged(val: [<class 'float'>, <class 'int'>, <class 'list'>, <class 'numpy.ndarray'>]) bool [source]
Return boolean indicating if the convergence criteria between the current and previous iteration values are met.
- Parameters:
val (_SUPPORTED_TYPES) – The most recent value for computing convergence critera. Is commonly equal to interface.getTightCouplingValue()
- Returns:
True (False) interface is (not) converged
- Return type:
boolean
Notes
On convergence, this class is automatically reset to its initial condition to avoid retaining or holding a stale state. Calling this method will increment a counter that when exceeded will clear the state. A warning will be reported if the state is cleared prior to the convergence criteria being met.
For computing convergence of arrays, only up to 2D is allowed. 3D arrays would arise from considering component level parameters. However, converging on component level parameters is not supported at this time.
- Raises:
ValueError – If the previous iteration value has not been assigned. The
storePreviousIterationValue
method must be called first.RuntimeError – Only support calculating norms for up to 2D arrays.
- class armi.interfaces.Interface(r, cs)[source]
Bases:
object
The eponymous Interface between the ARMI reactor data model and the Plugins.
Construct an interface.
The
r
andcs
arguments are required, but may beNone
, where appropriate for the specificInterface
implementation.- Parameters:
r (Reactor) – A reactor to attach to
cs (Settings) – Settings object to use
- Raises:
RuntimeError – Interfaces derived from Interface must define their name
- classmethod getInputFiles(cs)[source]
Return a MergeableDict containing files that should be considered “input”.
- name: Optional[str] = None
The name of the interface. This is undefined for the base class, and must be overridden by any concrete class that extends this one.
- function = None
The function performed by an Interface. This is not required be be defined by implementations of Interface, but is used to form categories of interfaces.
- class Distribute[source]
Bases:
object
Enum-like return flag for behavior on interface broadcasting with MPI.
- DUPLICATE = 1
- NEW = 2
- SKIP = 4
- distributable()[source]
Return true if this can be MPI broadcast.
Notes
Cases where this isn’t possible include the database interface, where the SQL driver cannot be distributed.
- preDistributeState()[source]
Prepare for distribute state by returning all non-distributable attributes.
Examples
>>> return {'neutronsPerFission',self.neutronsPerFission}
- postDistributeState(toRestore)[source]
Restore non-distributable attributes after a distributeState.
- attachReactor(o, r)[source]
Set this interfaces’ reactor to the reactor passed in and sets default settings.
- Parameters:
r (Reactor object) – The reactor to attach
quiet (bool, optional) – If true, don’t print out the message while attaching
Notes
This runs on all worker nodes as well as the primary.
- detachReactor()[source]
Delete the callbacks to reactor or operator. Useful when pickling, MPI sending, etc. to save memory.
- duplicate()[source]
Duplicate this interface without duplicating some of the large attributes (like the entire reactor).
Makes a copy of interface with detached reactor/operator/settings so that it can be attached to an operator at a later point in time.
- Returns:
The deepcopy of this interface with detached reactor/operator/settings
- Return type:
- getHistoryParams()[source]
Add these params to the history tracker for designated assemblies.
The assembly will get a print out of these params vs. time at EOL.
- interactInit()[source]
Interacts immediately after the interfaces are created.
Notes
BOL interactions on other interfaces will not have occurred here.
- interactCoupled(iteration)[source]
Called repeatedly at each time node/subcycle when tight physics coupling is active.
- getTightCouplingValue()[source]
Abstract method to retrieve the value in which tight coupling will converge on.
- interactDistributeState()[source]
Called after this interface is copied to a different (non-primary) MPI node.
- isRequestedDetailPoint(cycle=None, node=None)[source]
Determine if this interface should interact at this reactor state (cycle/node).
Notes
By default, detail points are either during the requested snapshots, if any exist, or all cycles and nodes if none exist.
This is useful for peripheral interfaces (CR Worth, perturbation theory, transients) that may or may not be requested during a standard run.
If both cycle and node are None, this returns True
- workerOperate(_cmd)[source]
Receive an MPI command and do MPI work on worker nodes.
- Returns:
True if this interface handled the incoming command. False otherwise.
- Return type:
- enabled(flag=None)[source]
Mechanism to allow interfaces to be attached but not running at the interaction points.
Must be implemented on the individual interface level hooks. If given no arguments, returns status of enabled. If arguments, sets enabled to that flag. (True or False)
Notes
These
return
statements are inconsistent, but not wrong.
- bolForce(flag=None)[source]
Run interactBOL even if this interface is disabled.
- Parameters:
flag (boolean, optional) – Will set the bolForce flag to this boolean
- Returns:
true if should run at BOL. No return if you pass an input.
- Return type:
Notes
These
return
statements are inconsistent, but not wrong.
- static specifyInputs(cs) Dict[Union[str, Setting], List[str]] [source]
Return a collection of file names that are considered input files.
This is a static method (i.e. is not called on a particular instance of the class), since it should not require an Interface to actually be constructed. This would require constructing a reactor object, which is expensive.
The files returned by an implementation should be those that one would want copied to a target location when cloning a Case or CaseSuite. These can be absolute paths, relative paths, or glob patterns that will be interpolated relative to the input directory. Absolute paths will not be copied anywhere.
The returned dictionary will enable the source Settings object to be updated to the new file location. While the dictionary keys are recommended to be Setting objects, the name of the setting as a string, e.g., “shuffleLogic”, is still interpreted. If the string name does not point to a valid setting then this will lead to a failure.
Note
This existed before the advent of ARMI plugins. Perhaps it can be better served as a plugin hook. Potential future work.
See also
armi.cases.Case.clone
- Parameters:
cs (Settings) – The case settings for a particular Case
- class armi.interfaces.InputWriter(r=None, externalCodeInterface=None, cs=None)[source]
Bases:
object
Use to write input files of external codes.
- class armi.interfaces.OutputReader(r=None, externalCodeInterface=None, fName=None, cs=None)[source]
Bases:
object
A generic representation of a particular module’s output.
- Variables:
success (bool) – False by default, set to True if the run is considered to have completed without error.
Notes
Should ideally not require r, eci, and fname arguments and would rather just have an apply(reactor) method.
- armi.interfaces.getActiveInterfaceInfo(cs)[source]
Return a list containing information for all of the Interface classes that are present.
This creates a list of tuples, each containing an Interface subclass and appropriate kwargs for adding them to an Operator stack, given case settings. There should be entries for all Interface classes that are returned from implementations of the describeInterfaces() function in modules present in the passed list of packages. The list is sorted by the ORDER specified by the module in which the specific Interfaces are described.
- Parameters:
cs (Settings) – The case settings that activate relevant Interfaces
- class armi.interfaces.InterfaceInfo(order: int, interfaceCls: Interface, kwargs: dict)[source]
Bases:
NamedTuple
Data structure with interface info.
Notes
If kwargs is an empty dictionary, defaults from
armi.operators.operator.Operator.addInterface
will be applied.See also
armi.operators.operator.Operator.createInterfaces
where these ultimately activate various interfaces.
Create new instance of InterfaceInfo(order, interfaceCls, kwargs)