GridPACK’s power flow module provides a parallel Newton-Raphson AC power flow solver built on top of PETSc. TheDocumentation 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.
PFAppModule class in the gridpack::powerflow namespace encapsulates every phase of a power flow calculation—reading and partitioning the network, initializing internal data structures, solving the nonlinear system, and writing results—so that the same object can serve as a standalone solver or as the first stage in a larger workflow such as contingency analysis or dynamic simulation initialization.
Setting up and running a power flow
Open the configuration file
Parse the XML input deck and obtain a cursor pointing at the
Powerflow block. The configuration object is created once in the calling program and passed by pointer to all module calls.Read and partition the network
Create an empty The optional
PFNetwork and pass it to readNetwork(). The method reads the PSS/E RAW file named in the networkConfiguration field and partitions the network across MPI ranks.idx argument selects a specific Powerflow block when the input file contains more than one.Initialize exchange buffers
Call
initialize() to set up internal indices and the MPI exchange buffers used during matrix assembly. This must be called before solve().Solve the power flow
Two solvers are available. The default hand-coded Newton-Raphson loop is recommended for production use because it applies direct LU factorization once per iteration and avoids spurious divergence checks.Both return
false if the solver catches an error during the iteration.Write and export results
Write bus voltages and branch flows to standard output or a file:Export structured results to JSON or CSV via
ResultsExporter:XML configuration reference
ThePowerflow block controls all solver parameters. Below is a complete annotated example:
When
outputFormat is json, two files are written: <outputFile>_buses.json and <outputFile>_branches.json. When set to csv, the suffixes become _buses.csv and _branches.csv.PSS/E input format versions
GridPACK supports PSS/E RAW files for versions 23, 33, 34, 35, and 36. For v30+ files the parser automatically reads the version number from the third field of the RAW file header, so no special tag is needed in most cases. Version-specific tags take precedence over auto-detection and are retained for backward compatibility.Newton-Raphson solver details
The hand-codedsolve() routine runs a Newton-Raphson iteration loop controlled by maxIteration and tolerance. The dampingFactor parameter (default 1.0) scales each correction vector before it is applied to bus voltages and angles. Setting it below 1.0 reduces the step size and can improve convergence for heavily loaded or poorly initialized networks. A value of 1.0 is recommended for RAW files that already store a converged operating point.
The initStart parameter controls initialization:
warm(default): reads voltage magnitude (VM) and angle (VA) directly from the PSS/E RAW bus section.flat: sets all bus voltages to1.0pu and all angles to0degrees, useful when stored voltages are unreliable.
Q-limit enforcement and PV→PQ bus switching
Whenqlim is true (default), the solver checks each PV bus after Newton-Raphson convergence. If a generator’s reactive output exceeds its Qmax or Qmin limits by more than qlimDeadband (default 0.1 Mvar), the bus is converted to a PQ bus and the power flow is re-solved. The outer switching loop runs up to maxQlimIterations (default 3) times. The deadband prevents oscillation in cases where the required Q is close to a limit.
Switched shunt control
WhenSwitchedShunt is enabled, buses with switched shunt data are monitored after each Newton-Raphson convergence. Two control modes are supported:
| MODSW value | Behavior |
|---|---|
1 (discrete) | Switches one capacitor or reactor bank step per controller iteration. Cycle detection locks shunts that oscillate between two states. |
2 (continuous) | Adjusts susceptance B smoothly toward the [VSWLO, VSWHI] deadband midpoint. |
SWREM field regulate voltage at the specified remote bus rather than the local bus. The initial susceptance value BINIT is absorbed into the fixed bus shunt admittance during network setup, consistent with commercial power system tools.
Load tap changer (LTC) transformer control
WhenLTC is enabled, transformers with COD1=1 in their PSS/E data automatically adjust their tap ratios to regulate voltage at the controlled bus within the [VMI, VMA] deadband. Tap ratios are adjusted by one discrete step per controller iteration, bounded by [RMI, RMA]. The step size is derived from the tap range and number of tap positions (NTP), or read from the STEP field when available. Cycle detection prevents tap hunting.
Area interchange control
WhenAreaInterchange is enabled, the solver computes actual MW exports for each area by summing tie-line flows across area boundaries. If the export deviates from the desired value (PDES) by more than the tolerance (PTOL), the solver adjusts real power generation at the area’s slack bus (ISW) and re-solves. This outer loop runs up to 10 iterations.
Running the standalone binary
The pre-builtpf.x binary reads configuration from input.xml by default. Pass a filename as the first argument to override:
<suppressOutput>true</suppressOutput> to the Powerflow block.
Island detection
After callingsolve(), the method getIslandCount() returns the number of electrical islands in the network. A value greater than 1 indicates the network is fragmented. hasLoneBus() identifies any bus that has become completely isolated with no active branch connections. These checks are useful before attempting a post-contingency re-solve.
ZIP load model
The power flow module supports voltage-dependent ZIP loads. The load power at voltageV is computed as:
Contingency analysis
Run N-1 contingency screening using PFAppModule as the base solver.
Dynamic simulation
Initialize transient stability simulation from a converged power flow.