Mappers sit at the boundary between the network topology layer and the linear-algebra layer. After each Newton-Raphson iteration (or time step), component state on every MPI rank is assembled into globally-indexed distributedDocumentation 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.
Matrix and Vector objects that the solvers consume. The mappers handle all inter-rank index coordination through Global Arrays so that application code never has to manage global offsets manually.
How mappers work
Each mapper is constructed once from ashared_ptr to the network and reused across solver iterations. On construction the mapper calls contributions() to count which buses and branches will contribute elements, then sets up Global Array offset tables. Subsequent mapToVector / mapToMatrix calls iterate over active local components, invoke their matVecInterface methods, and scatter the results into the distributed object.
Component implements matVecInterface
Each bus and branch class overrides
vectorSize, vectorValues, matrixDiagSize, matrixDiagValues, matrixForwardSize, matrixForwardValues, etc. to report the size and values of their contribution.Factory sets the computation mode
Call
factory.setMode(MODE_CONSTANT) before mapping so that every component fills values appropriate for the current phase (e.g., Y-matrix assembly vs. residual evaluation).Mapper builds the algebraic object
Call
mapper.mapToMatrix(Y) or mapper.mapToVector(b). The mapper zeroes the object, iterates over contributing components, and scatters their values into the distributed layout.BusVectorMap
gridpack::mapper::BusVectorMap<_network> assembles a distributed Vector (or RealVector) from bus contributions. Only active (non-ghost) buses whose vectorSize returns true contribute elements.
Component interface required
Your bus class must implement:mapToBus calls setValues on each contributing bus after retrieving the global elements from the distributed vector.
FullMatrixMap
gridpack::mapper::FullMatrixMap<_network> assembles a distributed Matrix (or RealMatrix) from both bus diagonal blocks and branch off-diagonal blocks. Buses contribute diagonal blocks; branches contribute forward and reverse off-diagonal blocks.
Dense matrix variant
Passtrue to request a dense matrix, useful for small problems or debugging:
Component interface required
Buses must implement:Bus1 side; the reverse direction corresponds to the Bus2 side.
matrixForwardSize and matrixReverseSize return false to indicate that a branch contributes no off-diagonal elements. A branch can contribute to one direction but not the other.GenVectorMap and GenMatrixMap
For state-estimation and other problems where some variables are associated with branches (not just buses), GridPACK provides generalized mappers ingen_vector_map.hpp and gen_matrix_map.hpp. These use matrixNumRows / matrixNumCols from GenMatVecInterface instead of the block-based MatVecInterface.
The sMode pattern
Application components often need to fill different values depending on the current computation phase (Y-matrix build, Jacobian evaluation, residual evaluation, etc.). The convention is:
vectorValues and matrixDiagValues check the mode flag (stored via setMode) to know which values to compute:
Complete usage example
Math module: solvers
LinearSolver, NonlinearSolver, and DAESolver classes that consume mapper output.
Factory pattern
Use BaseFactory to initialize components and call setMode before each mapping pass.