Public API
Power Flow Evaluation Models and AC Solvers
For a conceptual overview, see Evaluation Models vs. Solver Algorithms.
PowerFlows.ACMixedPowerFlow — Type
ACMixedPowerFlow{ACSolver}(; kwargs...) where {ACSolver <: ACPowerFlowSolverType}
ACMixedPowerFlow(; kwargs...)An evaluation model for the AC power flow solved with the Mixed Current-Power Balance (MCPB) formulation in rectangular coordinates.
State per bus: PQ (eᵢ, fᵢ) with the divided complex current balance (I_specᵢ − Y_bus·V)ᵢ / V̄ᵢ, PV (eᵢ, fᵢ) with the real power balance plus the |Vᵢ|² magnitude constraint, REF (P_genᵢ, Q_genᵢ) with (eᵢ, fᵢ) fixed. There are 2 variables per bus, so the system size is 2n.
ACSolver defaults to NewtonRaphsonACPowerFlow. Supported solvers: NewtonRaphsonACPowerFlow, TrustRegionACPowerFlow, and LevenbergMarquardtACPowerFlow. Robust Homotopy and Gradient Descent are rejected at construction — they operate on the polar formulation only.
Unlike ACPolarPowerFlow, this model has no calculate_voltage_stability_factors, calculate_loss_factors, or robust_power_flow options — those post-processing/fallback paths assume the polar state layout and have no mixed current-power equivalent.
Arguments
check_reactive_power_limits::Bool: Defaultfalse.exporter::Union{Nothing, PowerFlowEvaluationModel}: Defaultnothing.generator_slack_participation_factors: Same semantics asACPolarPowerFlow. Defaultnothing.enhanced_flat_start::Bool: Defaulttrue.skip_redistribution::Bool: Defaultfalse.distribute_slack_proportional_to_headroom::Bool: Defaultfalse.network_reductions::Vector{PNM.NetworkReduction}: Default empty.time_steps::Int: Default1.time_step_names::Vector{String}: Default empty.correct_bustypes::Bool: Defaultfalse.control_discrete_devices::Bool: Whether to run discrete device control via λ-continuation. Defaultfalse.solver_settings::Dict{Symbol, Any}: Default empty.
PowerFlows.ACPolarPowerFlow — Type
ACPowerFlow{ACSolver}(; kwargs...) where {ACSolver <: ACPowerFlowSolverType}
ACPowerFlow(; kwargs...)An evaluation model for a standard AC power flow with the specified solver type.
Arguments
ACSolver(type parameter): The AC iterative solver tag, a subtype ofACPowerFlowSolverType(for exampleNewtonRaphsonACPowerFlow,TrustRegionACPowerFlow,LevenbergMarquardtACPowerFlow, orRobustHomotopyPowerFlow). If not specified, defaults toNewtonRaphsonACPowerFlow.check_reactive_power_limits::Bool: Whether to check reactive power limits during the power flow solution. Default isfalse.exporter::Union{Nothing, PowerFlowEvaluationModel}: An optional exporter for the power flow results. If notnothing, it should be aPSSEExportPowerFlow. Default isnothing.calculate_loss_factors::Bool: Whether to calculate loss factors during the power flow solution. Default isfalse.calculate_voltage_stability_factors::Bool: Whether to calculate voltage stability factors. Default isfalse.generator_slack_participation_factors: An optional parameter that specifies the participation factors for generator slack in the power flow solution. Ifnothing, all slack is picked up by the reference bus. If aDict{Tuple{DataType, String}, Float64}, it should map(component_type, component_name)tuples to participation factors. If aVectorof such dictionaries, different participation factors can be used for different time steps. Default isnothing.enhanced_flat_start::Bool: Whether to use enhanced flat start initialization. Default istrue.robust_power_flow::Bool: Whether to use run a DC power flow as a fallback if the initial residual is large. Default isfalse.skip_redistribution::Bool: Whether to skip slack redistribution. Default isfalse.network_reductions::Vector{PNM.NetworkReduction}: Network reductions to apply. Default is an empty vector. APNM.ZeroImpedanceBranchReductionplaced here is routed to PNM's dedicated zero-impedance step; set itsresistance_toleranceto also merge near-zero-impedance branches that carry a tiny nonzero resistance (PSS/E-style).time_steps::Int: Number of time steps to solve. Default is1.time_step_names::Vector{String}: Names for each time step. Default is an empty vector.correct_bustypes::Bool: Whether to automatically correct bus types based on available generation. Default isfalse.control_discrete_devices::Bool: Whether to run discrete device control (tap changers, switched shunts) via λ-continuation. Default isfalse.solver_settings::Dict{Symbol, Any}: Additional keyword arguments to pass to the solver. Default is an empty dictionary.
PowerFlows.ACPolarPowerFlow — Method
ACPowerFlow{ACSolver}(
check_reactive_power_limits::Bool = false,
exporter::Union{Nothing, PowerFlowEvaluationModel} = nothing,
calculate_loss_factors::Bool = false,
generator_slack_participation_factors::Union{
Nothing,
Dict{Tuple{DataType, String}, Float64},
Vector{Dict{Tuple{DataType, String}, Float64}},
} = nothing,
) where {ACSolver <: ACPowerFlowSolverType}An evaluation model for a standard AC power flow with the specified solver type.
Arguments
ACSolver(type parameter): The AC iterative solver tag, a subtype ofACPowerFlowSolverType(for exampleNewtonRaphsonACPowerFloworTrustRegionACPowerFlow). Default isNewtonRaphsonACPowerFlow.check_reactive_power_limits::Bool: Whether to check reactive power limits during the power flow solution. Default isfalse.exporter::Union{Nothing, PowerFlowEvaluationModel}: An optional exporter for the power flow results. If notnothing, it should be aPSSEExportPowerFlow.calculate_loss_factors::Bool: Whether to calculate loss factors during the power flow solution. Default isfalse.generator_slack_participation_factors::Union{Nothing, Dict{Tuple{DataType, String}, Float64}, Vector{Dict{Tuple{DataType, String}, Float64}}}: An optional parameter that specifies the participation factors for generator slack in the power flow solution. Ifnothing, all slack is picked up by the reference bus. If aDict, it should map(component_type, component_name)tuples to participation factors. If aVector, it should contain multiple such dictionaries, allowing for different participation factors for different time steps.
PowerFlows.ACPowerFlow — Type
ACPowerFlow is an alias for ACPolarPowerFlow, kept for backward compatibility with PowerSimulations.jl and external callers. It is a plain type alias (no deprecation warning); polar remains the default AC formulation.
PowerFlows.ACPowerFlowSolverType — Type
An abstract supertype for all AC power flow solver/step strategies. Subtypes: NewtonRaphsonACPowerFlow, TrustRegionACPowerFlow, LevenbergMarquardtACPowerFlow, RobustHomotopyPowerFlow, and GradientDescentACPowerFlow.
The solver is orthogonal to the formulation; see AbstractACPowerFlow, ACPolarPowerFlow, ACRectangularPowerFlow.
PowerFlows.ACRectangularPowerFlow — Type
ACRectangularPowerFlow{ACSolver}(; kwargs...) where {ACSolver <: ACPowerFlowSolverType}
ACRectangularPowerFlow(; kwargs...)An evaluation model for the AC power flow solved with the augmented current-injection (Da Costa) formulation in rectangular coordinates.
State per bus: PQ (eᵢ, fᵢ), PV (eᵢ, fᵢ, Qᵢ), REF (P_genᵢ, Q_genᵢ) with (eᵢ, fᵢ) fixed. Residual is the complex current mismatch ΔIᵢ = I_specᵢ − Y_bus·V. Off-diagonal Jacobian blocks ≡ Y_bus 2×2 real blocks and are constant across iterations.
ACSolver defaults to NewtonRaphsonACPowerFlow. Supported solvers: NewtonRaphsonACPowerFlow, TrustRegionACPowerFlow, and LevenbergMarquardtACPowerFlow. Robust Homotopy and Gradient Descent operate on the polar formulation only and are rejected at construction.
Unlike ACPolarPowerFlow, this model has no calculate_voltage_stability_factors, calculate_loss_factors, or robust_power_flow options — those post-processing/fallback paths assume the polar state layout and have no current-injection equivalent.
Arguments
check_reactive_power_limits::Bool: Defaultfalse.exporter::Union{Nothing, PowerFlowEvaluationModel}: Defaultnothing.generator_slack_participation_factors: Same semantics asACPolarPowerFlow. Defaultnothing.enhanced_flat_start::Bool: Defaulttrue.skip_redistribution::Bool: Defaultfalse.distribute_slack_proportional_to_headroom::Bool: Defaultfalse.network_reductions::Vector{PNM.NetworkReduction}: Default empty.time_steps::Int: Default1.time_step_names::Vector{String}: Default empty.correct_bustypes::Bool: Defaultfalse.control_discrete_devices::Bool: Whether to run discrete device control via λ-continuation. Defaultfalse.solver_settings::Dict{Symbol, Any}: Default empty.
PowerFlows.AbstractDCPowerFlow — Type
An abstract supertype for all DC power flow evaluation models. Subtypes: DCPowerFlow, PTDFDCPowerFlow, and vPTDFDCPowerFlow.
PowerFlows.DCPowerFlow — Type
DCPowerFlow(; kwargs...)An evaluation model for a standard DC power flow.
This provides a fast approximate solution to the AC power flow problem, by solving for the bus voltage angles under some simplifying assumptions (lossless lines, constant voltage magnitudes, etc.). Branch flows are then calculated from the voltage angles. For details, see Wikipedia or section 4 of the MATPOWER docs.
Arguments
exporter::Union{Nothing, PowerFlowEvaluationModel}: An optional exporter for the power flow results. If notnothing, it should be aPSSEExportPowerFlow. Default isnothing.network_reductions::Vector{PNM.NetworkReduction}: Network reductions to apply. Default is an empty vector. APNM.ZeroImpedanceBranchReductionplaced here is routed to PNM's dedicated zero-impedance step; set itsresistance_toleranceto also merge near-zero-impedance branches that carry a tiny nonzero resistance (PSS/E-style).time_steps::Int: Number of time steps to solve. Default is1.time_step_names::Vector{String}: Names for each time step. Default is an empty vector.correct_bustypes::Bool: Whether to automatically correct bus types based on available generation. Default isfalse.lossy_flows::Bool: Controls how branch flows and losses are computed after solving for bus angles. Whentrue, flows are computed from the full π-model arc admittance matrices (Y_ft,Y_tf), giving asymmetricP_from_toandP_to_from; losses are thenP_from_to + P_to_from(exact real-power balance). Whenfalse(default), flows are computed from the losslessBA·θformula (symmetric), and losses are approximated asR·P².generator_slack_participation_factors: An optional parameter that specifies the participation factors for generator slack in the power flow solution. Same semantics asACPolarPowerFlow. Default isnothing.distribute_slack_proportional_to_headroom::Bool: Whether to distribute the slack proportional to generator headroom. Default isfalse.skip_redistribution::Bool: Whether to skip slack redistribution. Default isfalse.
PowerFlows.FDDecoupled — Type
Classic fast-decoupled variant: constant B′/B″ half-iterations. Polar formulation only. See FDVariant, FastDecoupledACPowerFlow.
PowerFlows.FDFixedJacobian — Type
Frozen-Jacobian ("dishonest Newton") variant: the full per-formulation Jacobian is factored once at x0 and reused every iteration. Works with all three AC formulations. See FDVariant, FastDecoupledACPowerFlow.
PowerFlows.FDScheme — Type
Abstract supertype for the B′/B″ construction scheme of the FDDecoupled variant (FDSchemeXB, FDSchemeBX). Carried as the second type parameter of FastDecoupledACPowerFlow and dispatched on during matrix assembly. Only meaningful for FDDecoupled.
PowerFlows.FDSchemeBX — Type
BX scheme: B″ neglects branch resistance, B′ keeps it. See FDScheme.
PowerFlows.FDSchemeXB — Type
XB scheme: B′ neglects branch resistance, B″ keeps it. See FDScheme.
PowerFlows.FDVariant — Type
Abstract supertype for the FastDecoupledACPowerFlow iteration variants (FDDecoupled, FDFixedJacobian). Carried as the first type parameter of the solver so the iteration scheme is selected by multiple dispatch rather than a runtime flag.
PowerFlows.FastDecoupledACPowerFlow — Type
FastDecoupledACPowerFlow{V<:FDVariant, S<:FDScheme} <: ACPowerFlowSolverType
FastDecoupledACPowerFlow (bare: per-formulation defaults)An ACPowerFlowSolverType implementing fixed-slope decoupled Newton-Raphson (the classic fast decoupled power flow). Constant approximate Jacobian factor(s) are built once and reused across all iterations and time steps, while the exact mismatches are evaluated every iteration. This trades the quadratic convergence rate of Newton-Raphson for a linear rate at a fraction of the per-iteration cost — ideal for repeated solves, contingency screening, and as a cheap initializer for the exact-Newton family.
Works with all three AC formulations (ACPolarPowerFlow, ACRectangularPowerFlow, ACMixedPowerFlow).
Type parameters (the iteration options)
V <: FDVariant:FDDecoupled(classic B′/B″ half-iterations; polar only) orFDFixedJacobian(frozen full-formulation Jacobian; all formulations). When the bareFastDecoupledACPowerFlowis used, the variant defaults per formulation:FDDecoupledfor polar,FDFixedJacobianfor rectangular/mixed.S <: FDScheme: B′/B″ scheme,FDSchemeXB(default) orFDSchemeBX. Only meaningful for theFDDecoupledvariant.
ACPowerFlow{FastDecoupledACPowerFlow}() # per-formulation defaults
ACPowerFlow{FastDecoupledACPowerFlow{FDDecoupled, FDSchemeBX}}() # explicit variant + scheme
ACRectangularPowerFlow{FastDecoupledACPowerFlow{FDFixedJacobian, FDSchemeXB}}()Settings (via solver_settings and/or call kwargs)
handoff_solver:nothing(pure FD; default) orNewtonRaphsonACPowerFlow/TrustRegionACPowerFlow/LevenbergMarquardtACPowerFlowfor final refinement totol.handoff_tol::Float64: FD-stage exit ∞-norm when a handoff solver is configured.
See also: ACPowerFlow, NewtonRaphsonACPowerFlow.
PowerFlows.FastDecoupledFixed — Type
Alias for the frozen-Jacobian fast decoupled power flow, FastDecoupledACPowerFlow{FDFixedJacobian,FDSchemeXB} (the scheme is nominal — the fixed-Jacobian variant builds no B′/B″). Works on all three formulations, e.g. ACRectangularPowerFlow{FastDecoupledFixed}().
PowerFlows.FastDecoupledXB — Type
Alias for the classic decoupled fast power flow with the XB scheme, FastDecoupledACPowerFlow{FDDecoupled,FDSchemeXB}. Use as a solver type parameter, e.g. ACPowerFlow{FastDecoupledXB}().
PowerFlows.LevenbergMarquardtACPowerFlow — Type
LevenbergMarquardtACPowerFlow <: ACPowerFlowSolverTypeAn ACPowerFlowSolverType corresponding to the Levenberg-Marquardt iterative method. This is more robust than the basic Newton-Raphson method, but also more computationally intensive. Due to the difficulty of tuning meta parameters, this method may occasionally fail to converge where other methods would succeed.
Works with both the polar (ACPolarPowerFlow) and rectangular current-injection (ACRectangularPowerFlow) formulations.
Marquardt diagonal column scaling (√λ·D damping instead of √λ·I) can be toggled via solver_settings = Dict(:marquardt_scaling => true|false). When unset it defaults on for ACRectangularPowerFlow — whose state columns (e, f, Q, P_gen) are differently scaled, so identity damping is ill-conditioned — and off for ACPolarPowerFlow, leaving the polar solver numerically unchanged.
See also: ACPowerFlow.
PowerFlows.NewtonRaphsonACPowerFlow — Type
NewtonRaphsonACPowerFlow <: ACPowerFlowSolverTypeAn ACPowerFlowSolverType corresponding to a basic Newton-Raphson iterative method. The Newton step is taken verbatim at each iteration: no line search is performed.
Iwamoto step control can be enabled via solver_settings = Dict(:iwamoto => true) in ACPowerFlow. When enabled, each iteration checks whether the full Newton step reduces the residual norm. If it does, the full step is accepted (overhead: 3 dot products). If not, an optimal damping multiplier μ is computed by solving a cubic and the step x += μ·Δx is applied instead, preventing divergence on ill-conditioned or poorly-initialized systems.
Based on: Iwamoto & Tamura, "A Load Flow Calculation Method for Ill-Conditioned Power Systems," IEEE Trans. PAS, 1981.
See also: ACPowerFlow.
PowerFlows.PTDFDCPowerFlow — Type
PTDFDCPowerFlow(; kwargs...)An evaluation model that calculates line flows using the Power Transfer Distribution Factor Matrix.
This approximates the branch flows in the power grid, under some simplifying assumptions (lossless lines, constant voltage magnitudes, etc.). In contrast to DCPowerFlow, branch flows are computed directly from bus power injections, without use of the voltage angles. See section 4 of the MATPOWER docs for details.
Arguments
exporter::Union{Nothing, PowerFlowEvaluationModel}: An optional exporter for the power flow results. If notnothing, it should be aPSSEExportPowerFlow. Default isnothing.calculate_loss_factors::Bool: Whether to calculate DC loss factors after solving. Uses the approximation∂Loss/∂P = 2 · PTDFᵀ · diag(R) · PTDF · P. Default isfalse.network_reductions::Vector{PNM.NetworkReduction}: Network reductions to apply. Default is an empty vector. APNM.ZeroImpedanceBranchReductionplaced here is routed to PNM's dedicated zero-impedance step; set itsresistance_toleranceto also merge near-zero-impedance branches that carry a tiny nonzero resistance (PSS/E-style).time_steps::Int: Number of time steps to solve. Default is1.time_step_names::Vector{String}: Names for each time step. Default is an empty vector.correct_bustypes::Bool: Whether to automatically correct bus types based on available generation. Default isfalse.generator_slack_participation_factors: An optional parameter that specifies the participation factors for generator slack in the power flow solution. Same semantics asACPolarPowerFlow. Default isnothing.distribute_slack_proportional_to_headroom::Bool: Whether to distribute the slack proportional to generator headroom. Default isfalse.skip_redistribution::Bool: Whether to skip slack redistribution. Default isfalse.
PowerFlows.PowerFlowEvaluationModel — Type
An abstract supertype for all types of power flows. Subtypes: AbstractACPowerFlow, AbstractDCPowerFlow, and PSSEExportPowerFlow. The last isn't a power flow in the usual sense, but it is implemented that way (with writing the export file as solving the power flow) for interface reasons.
PowerFlows.RobustHomotopyPowerFlow — Type
RobustHomotopyPowerFlow <: ACPowerFlowSolverTypeAn ACPowerFlowSolverType corresponding to a homotopy iterative method, based on the paper "Improving the robustness of Newton-based power flow methods to cope with poor initial points". This is significantly more robust than Newton-Raphson, but also slower by an order of magnitude or two.
See also: ACPowerFlow.
PowerFlows.TrustRegionACPowerFlow — Type
TrustRegionACPowerFlow <: ACPowerFlowSolverTypeAn ACPowerFlowSolverType corresponding to the Powell dogleg iterative method. This is a bit more robust than the basic Newton-Raphson method and comparably lightweight.
See also: ACPowerFlow.
PowerFlows.vPTDFDCPowerFlow — Type
vPTDFDCPowerFlow(; kwargs...)An evaluation model that calculates line flows using a virtual Power Transfer Distribution Factor Matrix.
This is a replacement for the PTDFDCPowerFlow for large grids, where creating and storing the full PTDF matrix would be infeasible or slow. See the PowerNetworkMatrices.jl docs for details.
Arguments
exporter::Union{Nothing, PowerFlowEvaluationModel}: An optional exporter for the power flow results. If notnothing, it should be aPSSEExportPowerFlow. Default isnothing.calculate_loss_factors::Bool: Whether to calculate DC loss factors after solving. Uses the approximation∂Loss/∂P = 2 · PTDFᵀ · diag(R) · PTDF · P. Default isfalse.network_reductions::Vector{PNM.NetworkReduction}: Network reductions to apply. Default is an empty vector. APNM.ZeroImpedanceBranchReductionplaced here is routed to PNM's dedicated zero-impedance step; set itsresistance_toleranceto also merge near-zero-impedance branches that carry a tiny nonzero resistance (PSS/E-style).time_steps::Int: Number of time steps to solve. Default is1.time_step_names::Vector{String}: Names for each time step. Default is an empty vector.correct_bustypes::Bool: Whether to automatically correct bus types based on available generation. Default isfalse.generator_slack_participation_factors: An optional parameter that specifies the participation factors for generator slack in the power flow solution. Same semantics asACPolarPowerFlow. Default isnothing.distribute_slack_proportional_to_headroom::Bool: Whether to distribute the slack proportional to generator headroom. Default isfalse.skip_redistribution::Bool: Whether to skip slack redistribution. Default isfalse.
Solving Power Flows
PowerFlows.FlowReportingModule.FlowReporting — Type
FlowReporting
Enumeration describing the type of flows reported in power flow results.
Values
- ARC_FLOWS = 0: Report total flows corresponding to arcs.
- BRANCH_FLOWS = 1: Report flows for individual branches.
PowerFlows.solve_and_store_power_flow! — Method
solve_and_store_power_flow!(pf::AbstractDCPowerFlow, system; kwargs...)Solve the DC power flow for pf and store the solution back into system: bus angles, unit voltage magnitudes, and redistributed active generation at the slack/participating buses. Returns true (DC always converges). Only the first time step is written back.
PowerFlows.solve_power_flow — Method
solve_power_flow(
data::Union{PTDFPowerFlowData, vPTDFPowerFlowData, ABAPowerFlowData},
sys::PSY.System,
flow_reporting::FlowReporting,
)Evaluates the power flows on the system's branches by means of the method associated with the PowerFlowData structure data, which can be one of PTDFPowerFlowData, vPTDFPowerFlowData, or ABAPowerFlowData. Returns a dictionary of DataFrames, each containing the flows and bus voltages for the input PSY.System at that time step. The flow_reporting argument determines if flows are reported for arcs (FlowReporting.ARC_FLOWS) or for branches (FlowReporting.BRANCH_FLOWS).
Arguments:
data::Union{PTDFPowerFlowData, vPTDFPowerFlowData, ABAPowerFlowData}:PowerFlowDatastructure containing the system's data per each time_step considered, as well as the associated matrix for the power flow.sys::PSY.System: container gathering the system data.flow_reporting::FlowReporting: Format for reporting flows
Note that data must have been created from the PowerSystems.System sys using one of the PowerFlowData constructors.
Example
using PowerFlows, PowerSystemCaseBuilder
sys = build_system(PSITestSystems, "c_sys14")
data = PowerFlowData(PTDFDCPowerFlow(; time_steps = 2), sys)
d = solve_power_flow(data, sys, FlowReporting.ARC_FLOWS)
display(d["2"]["flow_results"])PowerFlows.solve_power_flow — Method
solve_power_flow(
pf::T,
sys::PSY.System,
flow_reporting::FlowReporting = FlowReporting.ARC_FLOWS,
) where T <: AbstractDCPowerFlowEvaluates the provided DC power flow method pf on the PowerSystems.System sys, returning a dictionary of DataFrames containing the calculated flows and bus angles. The flow_reporting input determines if flows are reported for arcs (FlowReporting.ARC_FLOWS, the default) or for branches (FlowReporting.BRANCH_FLOWS).
Configuration options like time_steps, time_step_names, network_reductions, and correct_bustypes should be set on the power flow object (e.g., DCPowerFlow(; time_steps=2)).
Example
using PowerFlows, PowerSystemCaseBuilder
sys = build_system(PSITestSystems, "c_sys5")
d = solve_power_flow(DCPowerFlow(), sys, FlowReporting.ARC_FLOWS)
display(d["1"]["flow_results"])
display(d["1"]["bus_results"])PowerFlows.solve_and_store_power_flow! — Method
solve_and_store_power_flow!(pf::AbstractACPowerFlow{<:ACPowerFlowSolverType}, system::PSY.System; kwargs...)Solves the power flow in the system and writes the solution into the relevant structs. Updates active and reactive power setpoints for generators and active and reactive power flows for branches (calculated in the From - To direction and in the To - From direction).
Configuration options like time_steps, time_step_names, network_reductions, and correct_bustypes should be set on the ACPowerFlow object.
The bus types can be changed from PV to PQ if the reactive power limits are violated.
Arguments
pf::AbstractACPowerFlow{<:ACPowerFlowSolverType}: the power flow struct, which contains configuration options.system::PSY.System: The power system model, aPowerSystems.Systemstruct.kwargs...: Additional keyword arguments passed to the solver.
When the solve ran with control_discrete_devices, the solved tap ratios / shunt admittances / phase-shifter angles are written back into the system (see write_device_settings!): the stored branch flows are only self-consistent with the mutated device settings, so the input system's controlled devices are updated to the solved values. With no controls active this is a no-op. This write-back only happens for single-period solves; for multiperiod solves (time_steps > 1) it is skipped with a warning, since a PSY component holds one scalar per setting and cannot round-trip a per-time-step schedule — use get_controlled_device_results for the per-time-step schedule instead.
Keyword Arguments
tol: Infinite norm of residuals under which convergence is declared. Default is1e-9.maxIterations: Maximum number of Newton-Raphson iterations. Default is30.
Returns
converged::Bool: Indicates whether the power flow solution converged.- The power flow results are written into the system struct.
Examples
solve_and_store_power_flow!(pf, sys)
# With correct_bustypes enabled
pf = ACPowerFlow(; correct_bustypes = true)
solve_and_store_power_flow!(pf, sys)
# Passing solver keyword arguments
solve_and_store_power_flow!(pf, sys; maxIterations=100)PowerFlows.solve_power_flow — Method
Similar to solve_and_store_power_flow! but does not update the system struct with results. Returns the results in a dictionary of dataframes.
Examples
res = solve_power_flow(pf, sys)
res = solve_power_flow(pf, sys, FlowReporting.BRANCH_FLOWS)PowerFlows.write_device_settings! — Method
write_device_settings!(system, data)Write the solved discrete-control device settings back into the PSY.System: tap ratios (set_tap!), switched-shunt admittances (set_Y!/set_initial_status!, convention-aware — see below), and phase-shifter angles (set_α!). FACTS devices carry no stored setting field in PSY and are skipped. A device no longer present in system is skipped with a @warn (its solved setting is not written back). Mutates the user's system — called by solve_and_store_power_flow! after a converged solve; a no-op when no discrete controls ran.
Switched shunts write back per their sourcing convention (see Metadata sourcing for how psse_convention is determined): PSS/E-parsed (BINIT) components take the solved total straight into Y; PSY API-built components keep Y at the fixed base and write the last-snap block_n into initial_status, since overwriting Y would double-count the status on re-enrollment. A never-snapped API-built device (continuous, or held in its deadband the whole solve) whose block_n cannot reconstruct d.current falls back to the BINIT write (solved total into Y, initial_status zeroed).
No-op for time_steps > 1: a PSY component holds a single scalar setting, but a multiperiod solve produces one setting per time step, so there is no single value to write back without silently discarding all but the last-processed step. Per-time-step results remain available via get_controlled_device_results.
PowerFlows.GradientDescentACPowerFlow — Type
GradientDescentACPowerFlow <: ACPowerFlowSolverTypeAn ACPowerFlowSolverType that solves AC power flow by minimising ½‖F(x)‖² with the Adam optimizer and backtracking line search.
Solver settings (pass via solver_settings Dict)
| Key | Default | Description |
|---|---|---|
:learning_rate | 0.01 | Adam step size η |
:beta1 | 0.9 | 1st moment decay β₁ |
:beta2 | 0.999 | 2nd moment decay β₂ |
:epsilon | 1e-8 | Numerical stability ε |
See also: ACPowerFlow.
PowerFlows.get_hvdc_results — Method
get_hvdc_results(sys::PSY.System, data::ACPowerFlowData)Per-time-step HVDC results from a solved AC power flow, as a NamedTuple of DataFrames: lcc (PowerSystems.TwoTerminalLCCLine lines), vsc (point-to-point PowerSystems.TwoTerminalVSCLine lines), mtdc_converters (PowerSystems.InterconnectingConverter), and mtdc_lines (PowerSystems.TModelHVDCLine DC branches). Each table is the corresponding single-time-step results frame with a time_step column prepended, concatenated over 1:get_time_steps(data); a family absent from the system yields an empty table. Powers are in MW/MVAr; voltages, currents, and taps in p.u.; angles in radians. sys is required because component names are not stored in the solved data. Symmetric to get_controlled_device_results for discrete-control devices.
PSSE Export
PowerFlows.PSSEExportPowerFlow — Method
PSSEExportPowerFlow(psse_version::Symbol, export_dir::AbstractString; kwargs...)An evaluation model for exporting power flow results to PSSE format.
Arguments:
psse_version::Symbol: The version of PSSE to export to. Must be among[:v33, :v35].export_dir::AbstractString: The directory where the PSSE files will be exported.
Optional keyword arguments:
name::AbstractString: The base name for the exported files. Defaults to"export".write_comments::Bool: Whether to write comments in the exported files. Defaults tofalse.overwrite::Bool: Whether to overwrite the file if it exists already. Defaults tofalse.
PowerFlows.PSSEExporter — Type
Structure to perform an export from a Sienna System, plus optional updates from PowerFlowData, to the PSS/E format.
Construct this object from a PowerSystems.System and a PSS/E version, update using update_exporter with any new data as relevant, and perform the export with write_export. Writes a <name>.raw file and a <name>_export_metadata.json file with transformations that had to be made to conform to PSS/E naming rules, which can be parsed by PowerSystems.jl to perform a round trip with the names restored.
Arguments:
base_system::PSY.System: the system to be exported. Later updates may change power flow-related values but may not fundamentally alter the systempsse_version::Symbol: the version of PSS/E to target, must be one of[:v33, :v35]write_comments::Bool = false: whether to add the customary-but-not-in-spec-annotations after a slash on the first line and at group boundariesname::AbstractString = "export": the base name of the exportstep::Any = nothing: optional step data to append to the base export name. User is responsible for updating the step data. If the step data isnothing, it is not used; if it is a tuple or vector, it is joined with _ and concatted; else it is concatted after _.overwrite::Bool = false:trueto silently overwrite existing exports,falseto throw an error if existing results are encountered
PowerFlows.get_psse_export_paths — Method
Calculate the paths of the (raw, metadata) files that would be written by a certain call to write_export
PowerFlows.update_exporter! — Method
Update the PSSEExporter with new data.
Arguments:
exporter::PSSEExporter: the exporter to updatedata::PSY.PowerFlowData: the new data. Must correspond to thePowerSystems.Systemwith which the exporter was constructed.
PowerFlows.update_exporter! — Method
Update the PSSEExporter with new data.
Arguments:
exporter::PSSEExporter: the exporter to updatedata::PSY.System: system containing the new data. Must be fundamentally the samePowerSystems.Systemas the one with which the exporter was constructed, just with different values — this is the user's responsibility, we do not exhaustively verify it.
PowerFlows.write_export — Method
Perform an export from the data contained in a PSSEExporter to the PSS/E file format.