The factory pattern in GridPACK bridges the gap between a freshly-partitioned network (whose components hold only rawDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/GridOPTICS/GridPACK/llms.txt
Use this file to discover all available pages before exploring further.
DataCollection key-value pairs) and a fully-initialized simulation-ready network. gridpack::factory::BaseFactory<_network> provides the generic operations that every application shares; application developers subclass it to add domain-specific initialization logic.
Role of BaseFactory
When a network is first read from an input file and partitioned across MPI ranks, each bus and branch component contains aDataCollection object filled with parsed data. The factory is responsible for:
- Wiring the topology — connecting each branch to its endpoint buses and setting Global Array–based matrix-vector indices (
setComponents). - Loading component data — invoking
load()on each bus and branch so they read their own parameters from theDataCollection(load). - Allocating exchange buffers — enabling ghost-bus updates via
initBusUpdate/updateBuses(setExchange). - Switching computation phases — broadcasting an integer mode flag to every component (
setMode,setBusMode,setBranchMode). - Distributed validation — checking boolean conditions across all ranks (
checkTrue,checkTrueSomewhere).
BaseFactory API
Construction
setMode and related calls.
setComponents
setComponents performs three tasks:
- Sets
Bus1/Bus2pointers on each branch object. - Builds the neighbor-bus and neighbor-branch lists on each bus object.
- Uses Global Arrays to assign globally-unique, contiguous
MatVecIndexvalues to every active bus and branch. These indices are what mappers use to locate rows and columns in distributed matrices.
load
component->load(dataCollection). Each application component reads the parameters it needs from its DataCollection. This is where bus voltage ratings, generator MW limits, branch impedances, and similar data move from the parser’s intermediate format into the component’s own member variables.
Ghost buses and branches receive the same
load() call as active ones. Ghosts must hold valid state because neighboring active components on other ranks may read their data during exchange operations.setExchange
network->updateBuses() or network->updateBranches(). The flag parameter controls whether buffers are allocated inside the network object (true, default) or inside the components themselves (false).
setMode
setMode(mode) on every bus and branch component (or only buses / only branches for the variant forms). The integer mode is application-defined; by convention, applications declare named constants for each computation phase.
setBusMode and setBranchMode allow independent control when buses and branches require different modes simultaneously.
checkTrue / checkTrueSomewhere
checkTrue returns true only if the local flag is true on every MPI rank. checkTrueSomewhere returns true if the flag is true on at least one rank. Internally both perform a Global Arrays GA_Pgroup_igop sum reduction.
saveData
DataCollection objects so that results can be passed to output modules or transferred to a second network for chained computations. saveDataAlsotoOrg additionally updates the original voltage magnitudes, angles, and generator output values stored at parse time.
dumpData
DataCollection to standard output, one rank at a time. Output ordering is not guaranteed due to I/O buffering.
Extending BaseFactory
Application factories inherit fromBaseFactory and add domain-specific initialization phases:
Typical initialization sequence
Network-to-matrix mappers
Use setMode before each mapToMatrix or mapToVector call.
Input parsing and output
Parsers that populate the DataCollection objects that factory.load() reads.