API Reference
Power Flow Algorithm
HyDistFlow.TimeDomainPowerFlow.PowerFlow.adaptive_damped_newton
— Functionadaptive_damped_newton(baseMVA, bus, gen, load, pvarray, Ybus, V0, ref, p, tol0, max_it0, alg="")
Solve power flow using an adaptive damped Newton-Raphson method.
This function implements a Newton-Raphson method with adaptive damping factor to improve convergence in difficult cases. The damping factor is automatically adjusted based on the mismatch norm during iterations.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixload
: Load data matrixpvarray
: PV array dataYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indexp
: Vector of bus indicestol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Linear solver algorithm (optional)
Returns
V
: Final voltage solution vectorconverged
: Boolean indicating convergence statusi
: Number of iterations performed
HyDistFlow.TimeDomainPowerFlow.PowerFlow.currentinjectionpf
— Functioncurrentinjectionpf(baseMVA, bus, gen, load, pvarray, Ybus, V0, ref, p, tol0, max_it0, alg="")
Solve power flow using the Current Injection method, particularly suitable for resistive networks.
Arguments
baseMVA
: Base MVA for power system normalizationbus
: Matrix containing bus datagen
: Matrix containing generator dataload
: Matrix containing load datapvarray
: Array of PV bus informationYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference (slack) bus indexp
: Array of PQ bus indicestol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm variant (optional)
Returns
V
: Final complex voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performed
Description
This function implements the Current Injection power flow method, which is particularly effective for networks with high R/X ratios (resistive networks). The method works by:
- Converting power injections to current injections
- Calculating current mismatches
- Solving for voltage updates using the real part of the admittance matrix
- Iterating until convergence or maximum iterations reached
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpf
— Functionnewtonpf(baseMVA::Float64, bus::Matrix{Float64}, gen::Matrix{Float64},
Ybus::SparseArrays.SparseMatrixCSC{ComplexF64}, V0::Vector{ComplexF64},
ref::Vector{Int}, pv::Vector{Int}, pq::Vector{Int},
tol0::Float64, max_it0::Int, alg::String="bicgstab")
Solve AC power flow using Newton-Raphson method.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indicespv
: PV bus indicespq
: PQ bus indicestol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm specification for linear solver (default: "bicgstab")
Returns
V
: Final voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performednorm_history
: Array of norm values for each iteration
Description
This function implements the Newton-Raphson method to solve AC power flow equations. It iteratively updates voltage magnitudes and angles until the power mismatch falls below the specified tolerance or the maximum number of iterations is reached.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpf
— Functionnewtonpf(baseMVA::Float64, bus::Matrix{Float64}, gen::Matrix{Float64},
load::Matrix{Float64}, pvarray, Ybus::SparseArrays.SparseMatrixCSC{ComplexF64}, V0::Vector{ComplexF64},
ref::Vector{Int}, pv::Vector{Int}, pq::Vector{Int},
tol0::Float64, max_it0::Int, alg::String="bicgstab")
Solve AC power flow using Newton-Raphson method with load and PV array models.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixload
: Load data matrixpvarray
: PV array dataYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indicespv
: PV bus indicespq
: PQ bus indicestol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm specification for linear solver (default: "bicgstab")
Returns
V
: Final voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performednorm_history
: Array of norm values for each iteration
Description
This function implements the Newton-Raphson method to solve AC power flow equations with load and PV array models. It iteratively updates voltage magnitudes and angles until the power mismatch falls below the specified tolerance or the maximum number of iterations is reached.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpf_gpu
— Functionnewtonpf_gpu(baseMVA, bus, gen, load, Ybus, V0, ref, pv, pq, tol0, max_it0, alg="gpuLU")
Solve AC power flow using Newton's method with GPU acceleration.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixload
: Load data matrixYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indexpv
: Vector of PV bus indicespq
: Vector of PQ bus indicestol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm specification for linear solver (default: "gpuLU")
Returns
V
: Final voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performed
Description
This function implements the Newton-Raphson method to solve AC power flow equations using GPU acceleration. It iteratively updates voltage magnitudes and angles until the power mismatch falls below the specified tolerance or the maximum number of iterations is reached.
The algorithm:
- Initializes voltage values and transfers data to GPU
- Calculates initial power mismatches
- Constructs the Jacobian matrix for each iteration
- Updates voltage values using Newton's method
- Checks convergence based on power mismatch norm
Notes
- This implementation uses GPU acceleration for improved performance
- The Jacobian matrix is constructed in block form with partial derivatives
- The function handles both real and reactive power balance constraints
- Data is transferred between CPU and GPU as needed for computation
DC Power Flow Algorithm
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtondcpf
— Functionnewtondcpf(baseMVA, bus, gen, load, pvarray, Ybus, V0, ref, p, tol0, max_it0, alg="")
Solve DC power flow using Newton's method.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixload
: Load data matrixpvarray
: PV array dataYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indexp
: Vector of indices for buses to be included in the calculationtol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm specification for linear solver (optional)
Returns
V
: Final voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performed
Description
This function implements the Newton-Raphson method to solve DC power flow equations. It iteratively updates voltage values until the power mismatch falls below the specified tolerance or the maximum number of iterations is reached.
The algorithm:
- Initializes voltage values from the provided starting point
- Calculates initial power mismatches
- Constructs the Jacobian matrix for each iteration
- Updates voltage values using Newton's method
- Checks convergence based on power mismatch norm
Notes
- The Jacobian matrix represents the partial derivatives of power with respect to voltage
- This implementation handles both real power balance constraints
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtondcpf_sp
— Functionnewtondcpf_sp(baseMVA, bus, gen, load, pvarray, Ybus, V0, ref, p, tol0, max_it0, alg="")
Solve DC power flow using Newton's method with sparse matrices.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrixgen
: Generator data matrixload
: Load data matrixpvarray
: PV array dataYbus
: Bus admittance matrixV0
: Initial voltage vectorref
: Reference bus indexp
: Vector of indices for buses to be included in the calculationtol0
: Convergence tolerancemax_it0
: Maximum number of iterationsalg
: Algorithm specification (optional)
Returns
V
: Final voltage vector solutionconverged
: Boolean indicating whether the algorithm convergedi
: Number of iterations performed
Description
This function solves DC power flow using Newton's method. In DC systems, power P = V * I, where I = G * V (G is the conductance matrix). The function iteratively updates voltage magnitudes until the power mismatch falls below the specified tolerance or the maximum number of iterations is reached.
The algorithm:
- Initializes voltage values from the provided starting point
- Calculates initial power mismatches
- Constructs the Jacobian matrix for each iteration
- Updates voltage values using Newton's method
- Checks convergence based on power mismatch norm
Notes
- For DC systems, only active power is considered
- The Jacobian matrix represents the partial derivatives of power with respect to voltage
Linear Problem Solution Algorithm
GPU Acceleration
HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_pv_power_gpu
— Methodcalculate_pv_power_gpu(pvarray_gpu, bus_gpu, Vm_gpu, baseMVA)
Calculate power injections from PV arrays and their derivatives with respect to voltage magnitude using GPU acceleration.
Arguments
pvarray_gpu
: PV array data matrix on GPU with columns representing PV parametersbus_gpu
: Bus data matrix on GPU with columns representing bus parametersVm_gpu
: Vector of bus voltage magnitudes on GPUbaseMVA
: Base MVA for the system
Returns
Spv
: Vector of complex power injections from PV arraysdSpv_dVm
: Sparse matrix of partial derivatives of PV power injections with respect to voltage magnitude
Description
This function computes the power injections from PV arrays using a modified power function model that relates voltage to current output. It also calculates the derivatives of these injections with respect to voltage magnitude for use in power flow Jacobian calculations.
The function filters active PV arrays, maps them to their connected buses, and calculates their power output based on the current voltage conditions.
Notes
- Power output is calculated using a modified power function model with parameters a, b, and c
- The model accounts for the nonlinear relationship between voltage and current in PV arrays
- Results are converted to per-unit on system MVA base
- Only real power is considered (no reactive power from PV arrays)
- Calculations are partially performed on CPU for complex operations
Constants Used (assumed to be defined elsewhere)
- PVINSERVICE: Column index for PV array service status
- BUSI: Column index for bus number in busgpu matrix
- PVBUS: Column index for connected bus number in pvarraygpu matrix
- BASEKV: Column index for base voltage in busgpu matrix
- PVVOC: Column index for open circuit voltage in pvarraygpu matrix
- PVISC: Column index for short circuit current in pvarraygpu matrix
- PVAREA: Column index for PV array area in pvarraygpu matrix
- PVVMPP: Column index for maximum power point voltage in pvarraygpu matrix
HyDistFlow.TimeDomainPowerFlow.PowerFlow.create_bus_mapping
— Methodcreate_bus_mapping(bus_gpu, BUS_I)
Create a mapping dictionary from bus numbers to their indices in the bus matrix.
Arguments
bus_gpu
: Bus data matrix on GPU with columns representing bus parametersBUS_I
: Column index for bus number in bus_gpu matrix
Returns
bus_to_idx
: Dictionary mapping bus numbers to their indices in the bus matrix
Description
This function creates a dictionary that maps bus identification numbers to their corresponding indices in the bus matrix. This mapping is useful for quickly finding the position of a specific bus in the data structures.
Notes
- The function transfers bus data from GPU to CPU for processing
- Bus numbers may not be sequential or start from 1, hence the need for this mapping
HyDistFlow.TimeDomainPowerFlow.PowerFlow.find_bus_indices
— Methodfind_bus_indices(bus_to_idx, active_pv, PV_BUS)
Find the indices of buses to which PV arrays are connected.
Arguments
bus_to_idx
: Dictionary mapping bus numbers to their indices in the bus matrixactive_pv
: PV array data matrix with columns representing PV parametersPV_BUS
: Column index for connected bus number in active_pv matrix
Returns
valid_pv
: Boolean array indicating which PV arrays are connected to valid busesbus_indices
: Array of bus indices corresponding to each valid PV array
Description
This function identifies which buses in the system have PV arrays connected to them. It returns a boolean mask indicating which PV arrays are connected to valid buses, and an array of the corresponding bus indices for those valid connections.
Notes
- The function processes data entirely on CPU for better dictionary lookup performance
- PV arrays connected to non-existent buses are marked as invalid
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbus_gpu
— MethodmakeSbus_gpu(baseMVA, bus_gpu, gen_gpu, gen, Vm_gpu, load_gpu, pvarray_gpu; dc=false, Sg=nothing, return_derivative=false)
Build the vector of complex bus power injections using GPU acceleration.
Arguments
baseMVA
: Base MVA for the systembus_gpu
: Bus data matrix on GPU with columns representing bus parametersgen_gpu
: Generator data matrix on GPU with columns representing generator parametersgen
: Generator data matrix on CPU with columns representing generator parametersVm_gpu
: Vector of bus voltage magnitudes on GPUload_gpu
: Load data matrix on GPU with columns representing load parameterspvarray_gpu
: PV array data matrix on GPU with columns representing PV parameters
Keyword Arguments
dc
: Boolean indicating whether to use DC power flow assumptions (default: false)Sg
: Optional pre-computed generator complex power injections (default: nothing)return_derivative
: Boolean indicating whether to return derivative of Sbus with respect to Vm (default: false)
Returns
- If
return_derivative=false
: Vector of complex bus power injections (Sbus) - If
return_derivative=true
: Sparse matrix of partial derivatives of power injections with respect to voltage magnitude (dSbus_dVm)
Description
This function computes the vector of complex bus power injections (Sbus) for power flow analysis using GPU acceleration. It accounts for ZIP load models (constant power, constant current, and constant impedance components), generator injections, and PV array injections.
When return_derivative=true
, it returns the partial derivatives of the power injections with respect to voltage magnitude, which is useful for power flow Jacobian calculations.
Notes
- All power values are converted to per-unit on system MVA base
- The function handles ZIP load models with percentages specified in load_gpu
- Generator status is considered when computing injections
- When dc=true, voltage magnitudes are set to 1.0 p.u.
- PV array injections are calculated separately and added to the total bus injections
Constants Used (assumed to be defined elsewhere)
- LOADCND: Column index for load bus number in loadgpu matrix
- LOADPPERCENT: Column index for constant power percentage in loadgpu matrix
- LOADIPERCENT: Column index for constant current percentage in loadgpu matrix
- LOADZPERCENT: Column index for constant impedance percentage in loadgpu matrix
- GEN_STATUS: Column index for generator status in gen matrix
- GEN_BUS: Column index for generator bus number in gen matrix
- PG: Column index for real power output in gen_gpu matrix
- QG: Column index for reactive power output in gen_gpu matrix
- PVINSERVICE: Column index for PV array service status in pvarray_gpu matrix
HyDistFlow.TimeDomainPowerFlow.PowerFlow.process_pv_connections
— Methodprocess_pv_connections(bus_gpu, active_pv, BUS_I, PV_BUS)
Process the connections between PV arrays and buses in the power system.
Arguments
bus_gpu
: Bus data matrix on GPU with columns representing bus parametersactive_pv
: PV array data matrix with columns representing PV parametersBUS_I
: Column index for bus number in bus_gpu matrixPV_BUS
: Column index for connected bus number in active_pv matrix
Returns
valid_pv
: Boolean array indicating which PV arrays are connected to valid busesbus_indices
: Array of bus indices corresponding to each valid PV array
Description
This function coordinates the process of mapping PV arrays to their connected buses in the power system. It creates a mapping from bus numbers to indices, then uses this mapping to identify which PV arrays are connected to valid buses in the system.
Notes
- This is a wrapper function that calls createbusmapping and findbusindices
- The function handles the complete process of validating PV-to-bus connections
HyDistFlow.TimeDomainPowerFlow.PowerFlow.Sd_gpu
— TypeSd_gpu
A mutable structure to store ZIP load model components on GPU.
Fields
z
: Complex vector on GPU representing constant impedance component of loadi
: Complex vector on GPU representing constant current component of loadp
: Complex vector on GPU representing constant power component of load
This structure is used to store the components of the ZIP load model in GPU memory for efficient power flow calculations.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzip_gpu
— MethodmakeSdzip_gpu(baseMVA, bus_gpu, pw_1, pw_2, pw_3)
Create a ZIP load model structure on GPU from bus data and ZIP percentages.
Arguments
baseMVA
: Base MVA for the systembus_gpu
: Bus data matrix on GPU with columns representing bus parameterspw_1
: Vector of constant power percentages for active powerpw_2
: Vector of constant current percentages for active powerpw_3
: Vector of constant impedance percentages for active power
Returns
sd
: An Sd_gpu structure containing the ZIP load model components
Description
This function creates a ZIP (constant impedance, constant current, constant power) load model on the GPU for power flow calculations. It converts the load data from the bus matrix to per-unit values based on the system MVA base and the specified percentages for each component.
The function assumes that the same percentage distribution applies to both active and reactive power, so it uses the same percentages (pw1, pw2, pw_3) for both P and Q components.
Notes
- All power values are converted to per-unit on system MVA base
- PD and QD columns in bus_gpu represent the total active and reactive power demand
- pw1, pw2, pw_3 represent the percentages of constant power, constant current, and constant impedance components
Other Functions
HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_pv_power
— Methodcalculate_pv_power(pvarray, bus, Vm, baseMVA)
Calculate power injection from PV arrays and its derivative with respect to voltage magnitude.
Arguments
pvarray
: PV array data matrix with columns representing PV parametersbus
: Bus data matrix with columns representing bus parametersVm
: Vector of bus voltage magnitudesbaseMVA
: Base MVA for the system
Returns
Spv
: Vector of complex power injections from PV arraysdSpv_dVm
: Sparse matrix of partial derivatives of PV power injections with respect to voltage magnitude
Description
This function calculates the power injection from PV arrays based on a modified power function model that accounts for the PV array characteristics including open circuit voltage, short circuit current, and maximum power point voltage. It also computes the derivatives of these injections with respect to bus voltage magnitudes, which are needed for power flow Jacobian calculations.
The PV model uses a modified power function with correction terms to better represent the current-voltage characteristics of PV panels: I = Isc * (1 - (V/Voc)^a)^b * (1 - c * ((V/Vmpp) - 1)^2)
Notes
- Only active PV arrays (PVINSERVICE > 0) are considered
- The function maps PV arrays to their respective buses using the bus numbering
- Power output is converted to per-unit on system MVA base
- Only real power (no reactive power) is considered for PV arrays
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbus
— FunctionmakeSbus(baseMVA, bus, gen, Vm, Sg=nothing, return_derivative=false)
Build the vector of complex bus power injections (simplified version without PV arrays).
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrix with columns representing bus parametersgen
: Generator data matrix with columns representing generator parametersVm
: Vector of bus voltage magnitudes
Keyword Arguments
Sg
: Optional pre-computed generator complex power injections (default: nothing)return_derivative
: Boolean indicating whether to return derivative of Sbus with respect to Vm (default: false)
Returns
- If
return_derivative=false
: Vector of complex bus power injections (Sbus) - If
return_derivative=true
: Sparse matrix of partial derivatives of power injections with respect to voltage magnitude (dSbus_dVm)
Description
This is a simplified version of the makeSbus function that does not include PV array contributions. It computes the vector of complex bus power injections (Sbus) for power flow analysis, accounting for ZIP load models and generator injections.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbus
— MethodmakeSbus(baseMVA, bus, gen, Vm, load::Matrix{Float64}, pvarray; dc=false, Sg=nothing, return_derivative=false)
Build the vector of complex bus power injections, including PV array contributions.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrix with columns representing bus parametersgen
: Generator data matrix with columns representing generator parametersVm
: Vector of bus voltage magnitudesload
: Load data matrix with columns representing load parameterspvarray
: PV array data matrix with columns representing PV parameters
Keyword Arguments
dc
: Boolean indicating whether to use DC power flow assumptions (default: false)Sg
: Optional pre-computed generator complex power injections (default: nothing)return_derivative
: Boolean indicating whether to return derivative of Sbus with respect to Vm (default: false)
Returns
- If
return_derivative=false
: Vector of complex bus power injections (Sbus) - If
return_derivative=true
: Sparse matrix of partial derivatives of power injections with respect to voltage magnitude (dSbus_dVm)
Description
This function computes the vector of complex bus power injections (Sbus) for power flow analysis. It accounts for ZIP load models, generator injections, and PV array contributions.
When return_derivative=true
, it returns the partial derivatives of the power injections with respect to voltage magnitude, which is useful for power flow Jacobian calculations.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.Sd
— TypeSd
A mutable structure to store ZIP load model components.
Fields
z
: Complex vector representing constant impedance component of loadi
: Complex vector representing constant current component of loadp
: Complex vector representing constant power component of load
This structure is used to store the components of the ZIP load model for efficient power flow calculations.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzip
— MethodmakeSdzip(baseMVA, bus, pw_1, pw_2, pw_3)
Create a ZIP load model structure from bus data and specified ZIP percentages.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrix with columns representing bus parameterspw_1
: Vector of constant power percentages for active powerpw_2
: Vector of constant current percentages for active powerpw_3
: Vector of constant impedance percentages for active power
Returns
sd
: An Sd structure containing the ZIP load model components
Description
This function creates a ZIP (constant impedance, constant current, constant power) load model for power flow calculations. It converts the load data from the bus matrix to per-unit values based on the system MVA base and the specified percentages for each component.
The function assumes that the same percentage distribution applies to both active and reactive power, so it uses the same percentages (pw1, pw2, pw_3) for both P and Q components.
Notes
- All power values are converted to per-unit on system MVA base
- PD and QD columns in bus represent the total active and reactive power demand
- pw1, pw2, pw_3 represent the percentages of constant power, constant current, and constant impedance components
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzip
— MethodmakeSdzip(baseMVA, bus)
Create a ZIP load model structure from bus data with default constant power model.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrix with columns representing bus parameters
Returns
sd
: An Sd structure containing the ZIP load model components
Description
This is a simplified version of the makeSdzip function that assumes a constant power model (100% constant power, 0% constant current, 0% constant impedance).
Notes
- All power values are converted to per-unit on system MVA base
- PD and QD columns in bus represent the total active and reactive power demand
- By default, all load is modeled as constant power (P-Q) load
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeYbus
— MethodmakeYbus(baseMVA, bus, branch)
Build the bus admittance matrix and branch admittance matrices.
Arguments
baseMVA
: Base MVA for the systembus
: Bus data matrix with columns representing bus parametersbranch
: Branch data matrix with columns representing branch parameters
Returns
Ybus
: Bus admittance matrixYf
: Branch admittance matrix for "from" end of branchesYt
: Branch admittance matrix for "to" end of branches
Description
This function builds the bus admittance matrix (Ybus) and branch admittance matrices (Yf and Yt) for a given power system network. The admittance matrices are essential components for power flow and other power system analyses.
The function:
- Computes branch series admittances and line charging susceptances
- Handles tap ratios and phase shifters
- Incorporates bus shunt admittances
- Builds connection matrices between branches and buses
- Constructs the complete bus admittance matrix
Notes
- All admittance values are in per-unit on system MVA base
- Requires buses to be numbered consecutively (internal ordering)
- Branch status values determine which branches are in service
HyDistFlow.TimeDomainPowerFlow.PowerFlow.merge_results
— Methodmerge_results(results)
Merge power flow calculation results from multiple isolated islands.
Arguments
results
: An array of JPC objects containing power flow results for different islands
Returns
merged_result
: A single JPC object containing the combined resultsarea
: The number of islands that were merged
Description
This function combines power flow results from multiple isolated islands into a single comprehensive result. It merges all data matrices (buses, branches, generators, etc.) from the individual island results and sorts them by their ID numbers.
The function:
- Creates a new JPC object to hold the merged results
- Combines basic result fields like success status and iteration counts
- Merges all data matrices from the input results
- Sorts the merged matrices by their first column (typically ID numbers)
Notes
- Assumes all input results use the same base MVA
- Success is determined by the logical AND of all individual results' success flags
- Iteration count is the maximum of all individual results' iteration counts
HyDistFlow.TimeDomainPowerFlow.PowerFlow.extract_bus_data
— MethodExtract bus data from your data structure
HyDistFlow.TimeDomainPowerFlow.PowerFlow.generate_matpower_report
— FunctionFormat power flow calculation results as MATPOWER-style report and save to a text file
HyDistFlow.TimeDomainPowerFlow.PowerFlow.write_branch_data
— MethodWrite branch data section
HyDistFlow.TimeDomainPowerFlow.PowerFlow.write_bus_data
— MethodWrite bus data section
HyDistFlow.TimeDomainPowerFlow.PowerFlow.write_system_summary
— MethodWrite system summary section
HyDistFlow.TimeDomainPowerFlow.PowerFlow.dcpfsoln
— Methoddcpfsoln(baseMVA::Float64, bus0::Matrix{Float64}, gen0::Matrix{Float64},
branch0::Matrix{Float64}, load0::Matrix{Float64}, Ybus, Yf, Yt, V, ref, p)
Update power system state variables after a DC power flow solution.
Arguments
baseMVA::Float64
: Base MVA value for the systembus0::Matrix{Float64}
: Initial bus data matrixgen0::Matrix{Float64}
: Initial generator data matrixbranch0::Matrix{Float64}
: Initial branch data matrixload0::Matrix{Float64}
: Load data matrixYbus
: Bus admittance matrixYf
: From-bus branch admittance matrixYt
: To-bus branch admittance matrixV
: Complex bus voltage vector solutionref
: Reference (slack) bus indicesp
: P bus indices
Returns
bus
: Updated bus data matrixgen
: Updated generator data matrixbranch
: Updated branch data matrix with power flows
Description
This function updates the power system state variables after a DC power flow solution has been obtained. It performs the following operations:
- Updates bus voltage magnitudes
- Updates generator reactive power (Qg) for generators at PV and slack buses
- Distributes reactive power proportionally among multiple generators at the same bus
- Respects generator reactive power limits
- Updates active power (Pg) for generators at slack buses
- Calculates branch power flows
- Expands the branch matrix if needed to store power flow results
The function handles special cases like multiple generators at the same bus and generators with identical reactive power limits.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.pfsoln
— MethodUpdate power flow solution with computed voltage values and calculate generator outputs and branch flows. For the version with load data as a separate parameter.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.pfsoln
— MethodUpdate power flow solution with computed voltage values and calculate generator outputs and branch flows. Standard version without separate load data parameter.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.process_result
— MethodProcess power flow calculation results and generate a report. This function merges results, extracts execution time, and creates a MATPOWER format report.
Parameters:
- results: Array containing calculation results and timing information
- isolated: Information about isolated parts of the network
- file_path: Path where the report will be saved
HyDistFlow.TimeDomainPowerFlow.PowerFlow.analyze_voltage_results
— Methodanalyze_voltage_results(results::NamedTuple, case::JuliaPowerCase, reference_file::String;
tolerance_mag::Float64=1e-4, tolerance_ang::Float64=1e-3,
output_dir::String="./results", save_pdf::Bool=true)
Analyze voltage differences between power flow calculation results and reference file, generate comparison reports and charts. Supports both original format and AC/DC mixed format. Parameters:
- results: NamedTuple containing results in JPC format (typically the return value of power flow calculation)
- case: Original JuliaPowerCase object, used to get node names and ID mappings
- reference_file: Path to Excel file containing reference voltage values
- tolerance_mag: Tolerance for voltage magnitude comparison (default: 1e-4)
- tolerance_ang: Tolerance for voltage angle comparison (default: 1e-3)
- output_dir: Output directory (default: "./results")
- save_pdf: Whether to save plots in PDF format in addition to PNG (default: true)
Returns:
- DataFrame or NamedTuple containing comparison results
HyDistFlow.TimeDomainPowerFlow.PowerFlow.compare_voltage_results
— Methodcompare_voltage_results(results::NamedTuple, case::JuliaPowerCase, reference_file::String;
tolerance_mag::Float64=1e-4, tolerance_ang::Float64=1e-3)
Compare power flow calculation results in JPC format with reference voltage values, using JuliaPowerCase for node mapping. Supports both original format and new format with mixed AC/DC data. Parameters:
- results: NamedTuple containing results in JPC format (typically the return value of power flow calculation)
- case: Original JuliaPowerCase object, used to get node names and ID mappings
- reference_file: Path to Excel file containing reference voltage values
- tolerance_mag: Tolerance for voltage magnitude comparison (default: 1e-4)
- tolerance_ang: Tolerance for voltage angle comparison (default: 1e-3)
Returns:
- NamedTuple containing comparison results, including ac and dc DataFrames
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_voltage_results
— Methodget_bus_voltage_results(results::NamedTuple, case::JuliaPowerCase)
Extract bus voltage information from power flow calculation results in JPC format, and map to node names in JuliaPowerCase. Parameters:
- results: NamedTuple containing results in JPC format (typically the return value of power flow calculation)
- case: Original JuliaPowerCase object, used to get node names and ID mappings
Returns:
- DataFrame containing bus voltage results
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_voltage_results_acdc
— Methodget_bus_voltage_results_acdc(results::NamedTuple, case::JuliaPowerCase)
Extract both AC and DC bus voltage information from power flow calculation results in JPC format, and map to node names in JuliaPowerCase. Parameters:
- results: NamedTuple containing results in JPC format (typically the return value of power flow calculation)
- case: Original JuliaPowerCase object, used to get node names and ID mappings
Returns:
- NamedTuple containing AC and DC bus voltage results as two DataFrames: ac and dc
HyDistFlow.TimeDomainPowerFlow.PowerFlow.plot_voltage_comparison
— Functionplot_voltage_comparison(comparison_results, output_file::String="voltage_comparison.png";
show_plot::Bool=true)
Plot voltage magnitude and angle comparison curves between calculated and reference values. Supports both original format and AC/DC mixed format. Parameters:
- comparison_results: Can be a DataFrame or a NamedTuple containing ac and dc DataFrames
- outputfile: Path to save the chart file (default: "voltagecomparison.png")
- show_plot: Whether to display the chart (default: true)
Returns:
- Generated chart object or NamedTuple containing chart objects
HyDistFlow.TimeDomainPowerFlow.PowerFlow.plot_voltage_errors
— Functionplot_voltage_errors(comparison_results, output_file::String="voltage_errors.png";
show_plot::Bool=true)
Plot voltage magnitude and angle error curves. Supports both original format and AC/DC mixed format. Parameters:
- comparison_results: Can be a DataFrame or a NamedTuple containing ac and dc DataFrames
- outputfile: Path to save the chart file (default: "voltageerrors.png")
- show_plot: Whether to display the chart (default: true)
Returns:
- Generated chart object or NamedTuple containing chart objects
HyDistFlow.TimeDomainPowerFlow.PowerFlow.save_comparison_results
— Methodsave_comparison_results(comparison_results, output_file::String)
Save comparison results to an Excel file. Supports both original format and AC/DC mixed format. Parameters:
- comparison_results: Can be a DataFrame or a NamedTuple containing ac and dc DataFrames
- output_file: Output file path
HyDistFlow.TimeDomainPowerFlow.PowerFlow.rundcpf
— MethodMain function to call the DC power flow function Input: case file Output: results of the power flow as a dictionary Example: bus, gen, branch = rundcpf(casefile)
HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_droop_voltage
— Functioncalculate_droop_voltage(P_dc, k_p, U_dc_ref=1.0, U_dc_min=0.95, U_dc_max=1.05)
Calculate DC voltage with droop control using the equation: Udc = Udcref - kp * P_dc Limits the output voltage to be within specified minimum and maximum values.
Parameters:
- P_dc: DC power
- k_p: Droop coefficient
- Udcref: Reference DC voltage (default: 1.0 p.u.)
- Udcmin: Minimum allowed DC voltage (default: 0.95 p.u.)
- Udcmax: Maximum allowed DC voltage (default: 1.05 p.u.)
Returns:
- Limited DC voltage value
HyDistFlow.TimeDomainPowerFlow.PowerFlow.runhpf
— Methodrunhpf(jpc, opt)
Run hybrid power flow calculation for integrated AC/DC systems. Iteratively solves AC and DC power flow while updating converter power exchanges. Supports different converter control modes.
Parameters:
- jpc: JPC object containing both AC and DC system data
- opt: Options for power flow calculation
Returns:
- Updated JPC object with power flow results
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_ac_load!
— Methodupdate_ac_load!(result_jpc, jpc1, ac_bus_id, P_ac)
Helper function to update AC side load with power from converter. Creates a new load if none exists at the specified bus.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- acbusid: ID of the AC bus to update
- P_ac: AC power to add to the load
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_dc_load!
— Methodupdate_dc_load!(result_jpc, jpc2, dc_bus_id, P_dc)
Helper function to update DC side load with power from converter. Creates a new load if none exists at the specified bus.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc2: JPC object for DC system
- dcbusid: ID of the DC bus to update
- P_dc: DC power to add to the load
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_1_converters!
— Methodupdate_mode_1_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode constant δs, Us (CONV_MODE==1). These converters have fixed AC voltage angle and magnitude, and the power is calculated from AC side.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_3_converters!
— Methodupdate_mode_3_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode constant Ps, Us (CONV_MODE==3). These converters have fixed active power and AC voltage magnitude.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_4_converters!
— Methodupdate_mode_4_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode constant Udc, Qs (CONV_MODE==4). These converters have fixed DC voltage and reactive power.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_5_converters!
— Methodupdate_mode_5_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode constant Udc, Us (CONV_MODE==5). These converters have fixed DC voltage and AC voltage magnitude.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_6_converters!
— Methodupdate_mode_6_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode Droop Udc, Constant Qs (CONV_MODE==6). These converters use DC voltage droop control and maintain constant reactive power.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_7_converters!
— Methodupdate_mode_7_converters!(result_jpc, jpc1, jpc2, current_power_values)
Update converters with mode Droop Udc, Constant Us (CONV_MODE==7). These converters use DC voltage droop control and maintain constant AC voltage magnitude.
Parameters:
- result_jpc: Main JPC object containing all system data
- jpc1: JPC object for AC system
- jpc2: JPC object for DC system
- currentpowervalues: Dictionary to store current power values for convergence check
HyDistFlow.TimeDomainPowerFlow.PowerFlow.I0_from_V012
— MethodI0_from_V012(V012, Y)
Calculate zero sequence current from sequence voltages and admittance matrix.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.I1_from_V012
— MethodI1_from_V012(V012, Y)
Calculate positive sequence current from sequence voltages and admittance matrix.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.I2_from_V012
— MethodI2_from_V012(V012, Y)
Calculate negative sequence current from sequence voltages and admittance matrix.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.I_from_SV_elementwise
— MethodI_from_SV_elementwise(S, V)
Calculate current from complex power and voltage: I = conj(S/V).
HyDistFlow.TimeDomainPowerFlow.PowerFlow.SVabc_from_SV012
— MethodSVabc_from_SV012(S012, V012; n_res=nothing, idx=nothing)
Convert sequence components of power and voltage to phase components.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.S_from_VI_elementwise
— MethodS_from_VI_elementwise(v, i)
Calculate complex power from voltage and current: S = V * conj(I).
HyDistFlow.TimeDomainPowerFlow.PowerFlow.V1_from_jpc
— MethodV1_from_jpc(jpc)
Extract positive sequence voltage from JPC structure.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.V_from_I
— MethodV_from_I(Y, I)
Calculate voltage from current using V = Y\I.
HyDistFlow.TimeDomainPowerFlow.PowerFlow._clean_up
— Function_clean_up(net, res=true)
Clean up temporary data structures after power flow calculation.
HyDistFlow.TimeDomainPowerFlow.PowerFlow._get_p_q_gen_results_3ph
— Method_get_p_q_gen_results_3ph(case, jpc_3ph, jpc0, jpc1, jpc2)
Calculate active and reactive power for generators in three-phase system.
HyDistFlow.TimeDomainPowerFlow.PowerFlow._sum_by_group_nvals
— Method_sum_by_group_nvals(bus, vals...)
Group values by bus and sum them within each group for multiple value arrays.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.combine_X012
— Methodcombine_X012(X0, X1, X2)
Combine zero, positive, and negative sequence components into one matrix.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.current_from_voltage_results
— Methodcurrent_from_voltage_results(y_0_pu, y_1_pu, v_012_pu)
Calculate sequence currents from sequence voltages and admittance matrices.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.extratct_jpc_3ph
— Methodextratct_jpc_3ph(jpc_3ph::PowerFlow.JPC_3ph)
Extract individual sequence components from a three-phase JPC object.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_branch_flows_3ph
— Methodget_branch_flows_3ph(jpc0, jpc1, jpc2)
Calculate branch flows for three-phase system.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_branch_results_3ph
— Methodget_branch_results_3ph(jpc_3ph, jpc0, jpc1, jpc2, pq_buses)
Extract branch results and write them to the appropriate dataframes.
Parameters: results: result of runpf loadflow calculation p: dict to store "resline" and "restrafo" Dataframes
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_results_3ph
— Methodget_bus_results_3ph(case, jpc_3ph, bus_pq)
Store three-phase bus results in the appropriate fields.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_v_results_3ph
— Methodget_bus_v_results_3ph(jpc_3ph, jpc0, jpc1, jpc2)
Calculate and store three-phase voltage results for all buses.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_elements
— Methodget_elements(params, case::JuliaPowerCase, element, phase, typ)
This function is used to get the elements of the load mapping. Automatically skips elements that don't exist in case.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_ext_grid_results_3ph
— Methodget_ext_grid_results_3ph(case, jpc_3ph, jpc0, jpc1, jpc2)
Calculate and store three-phase external grid results.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_full_branch_zero
— Methodget_full_branch_zero(jpc_3ph)
Add non-service branches to zero sequence branch data.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_gen_results_3ph
— Methodget_gen_results_3ph(case, jpc_3ph, jpc0, jpc1, jpc2, pq_bus)
Calculate and store three-phase generator results.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_internal_variables
— Methodget_internal_variables(jpc::JPC)
Retrieve stored internal variables for a JPC object.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_p_q_b
— Functionget_p_q_b(case, jpc_3ph, element, suffix=nothing)
Get active and reactive power values and bus indices for a specific element.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_p_q_b_3ph
— Methodget_p_q_b_3ph(net, element)
Get three-phase active and reactive power values and bus indices for a specific element.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_p_q_results_3ph
— Methodget_p_q_results_3ph(case, jpc_3ph::PowerFlow.JPC_3ph)
Calculate and aggregate active and reactive power results for three-phase system.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_pf_variables_from_JPC
— Methodget_pf_variables_from_JPC(jpc::JPC)
Extract power flow variables from JPC structure.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_pp_gen_results_3ph
— Methodget_pp_gen_results_3ph(case, jpc_3ph, jpc0, jpc1, jpc2, b, pA, qA, pB, qB, pC, qC)
Calculate and store three-phase generator results.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_y_bus
— Methodget_y_bus(jpc0, jpc1, jpc2)
Build admittance matrices for zero, positive, and negative sequence networks.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.load_mapping
— Methodload_mapping(case::JuliaPowerCase, jpc1::JPC)
Maps loads from the case to the power flow model, handling both wye and delta connections for all three phases.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.phase_shift_unit_operator
— Methodphase_shift_unit_operator(angle_deg)
Create a complex number representing a phase shift of the given angle in degrees.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.phase_to_sequence
— Methodphase_to_sequence(Xabc)
Transform phase components (a, b, c) to sequence components (zero, positive, negative).
HyDistFlow.TimeDomainPowerFlow.PowerFlow.robust_process
— Methodrobust_process(net, jpc)
Process network and JPC data to ensure robust operation.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.run_newton_raphson_pf
— Methodrun_newton_raphson_pf(jpc::JPC, opt)
Run Newton-Raphson power flow calculation.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.runupf
— Methodrunupf(case, jpc_3ph, gs_eg, bs_eg, opt)
This function is used to run a local unbalanced power flow analysis on unsymmetrical load nodes
#Step1: find the unbalanced nodes in the system #Step2: find the interface branches of the unbalanced nodes and balanced nodes
HyDistFlow.TimeDomainPowerFlow.PowerFlow.sequence_to_phase
— Methodsequence_to_phase(X012)
Transform sequence components (zero, positive, negative) to phase components (a, b, c).
HyDistFlow.TimeDomainPowerFlow.PowerFlow.sum_by_group
— Methodsum_by_group(bus, first_val, second_val)
Group values by bus and sum them within each group.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.write_pq_results_to_element
— Functionwrite_pq_results_to_element(case, jpc_3ph, element, suffix=nothing)
Write power results to the specified element in jpc_3ph.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.write_pq_results_to_element_3ph
— Methodwrite_pq_results_to_element_3ph(net, element)
Get pmw and qmvar for a specific pq element ("load", "sgen"...). This function basically writes values from element table to res_element table.
Parameters: net: pandapower network element: element name (str) Returns: net with updated results
HyDistFlow.TimeDomainPowerFlow.PowerFlow.total_load
— Methodtotal_load(bus, load)
Calculate the total fixed and dispatchable load at each bus in the system, considering ZIP load model.
Arguments
bus
: Bus data matrix containing bus informationload
: Load data matrix containing load model percentages
Returns
Pd
: Vector of real power demand at each busQd
: Vector of reactive power demand at each bus (if want_Q=1)
This function computes the total load at each bus using the ZIP load model, which represents loads as a combination of constant impedance (Z), constant current (I), and constant power (P) components. The percentages for each component are specified in the load matrix.
HyDistFlow.TimeDomainPowerFlow.PowerFlow.total_load
— Methodtotal_load(bus)
Calculate the total fixed and dispatchable load at each bus in the system using default ZIP parameters.
Arguments
bus
: Bus data matrix containing bus information
Returns
Pd
: Vector of real power demand at each busQd
: Vector of reactive power demand at each bus (if want_Q=1)
This is an overloaded version of total_load
that uses default ZIP model parameters. It computes the total load at each bus using the standard ZIP load model with default percentages for constant impedance (Z), constant current (I), and constant power (P) components.