API Reference

Power Flow Algorithm

HyDistFlow.TimeDomainPowerFlow.PowerFlow.adaptive_damped_newtonFunction
adaptive_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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • load: Load data matrix
  • pvarray: PV array data
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus index
  • p: Vector of bus indices
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Linear solver algorithm (optional)

Returns

  • V: Final voltage solution vector
  • converged: Boolean indicating convergence status
  • i: Number of iterations performed
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.currentinjectionpfFunction
currentinjectionpf(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 normalization
  • bus: Matrix containing bus data
  • gen: Matrix containing generator data
  • load: Matrix containing load data
  • pvarray: Array of PV bus information
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference (slack) bus index
  • p: Array of PQ bus indices
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm variant (optional)

Returns

  • V: Final complex voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: 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:

  1. Converting power injections to current injections
  2. Calculating current mismatches
  3. Solving for voltage updates using the real part of the admittance matrix
  4. Iterating until convergence or maximum iterations reached
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpfFunction
newtonpf(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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus indices
  • pv: PV bus indices
  • pq: PQ bus indices
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm specification for linear solver (default: "bicgstab")

Returns

  • V: Final voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: Number of iterations performed
  • norm_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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpfFunction
newtonpf(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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • load: Load data matrix
  • pvarray: PV array data
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus indices
  • pv: PV bus indices
  • pq: PQ bus indices
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm specification for linear solver (default: "bicgstab")

Returns

  • V: Final voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: Number of iterations performed
  • norm_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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtonpf_gpuFunction
newtonpf_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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • load: Load data matrix
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus index
  • pv: Vector of PV bus indices
  • pq: Vector of PQ bus indices
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm specification for linear solver (default: "gpuLU")

Returns

  • V: Final voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: 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:

  1. Initializes voltage values and transfers data to GPU
  2. Calculates initial power mismatches
  3. Constructs the Jacobian matrix for each iteration
  4. Updates voltage values using Newton's method
  5. 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
source

DC Power Flow Algorithm

HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtondcpfFunction
newtondcpf(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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • load: Load data matrix
  • pvarray: PV array data
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus index
  • p: Vector of indices for buses to be included in the calculation
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm specification for linear solver (optional)

Returns

  • V: Final voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: 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:

  1. Initializes voltage values from the provided starting point
  2. Calculates initial power mismatches
  3. Constructs the Jacobian matrix for each iteration
  4. Updates voltage values using Newton's method
  5. 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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.newtondcpf_spFunction
newtondcpf_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 system
  • bus: Bus data matrix
  • gen: Generator data matrix
  • load: Load data matrix
  • pvarray: PV array data
  • Ybus: Bus admittance matrix
  • V0: Initial voltage vector
  • ref: Reference bus index
  • p: Vector of indices for buses to be included in the calculation
  • tol0: Convergence tolerance
  • max_it0: Maximum number of iterations
  • alg: Algorithm specification (optional)

Returns

  • V: Final voltage vector solution
  • converged: Boolean indicating whether the algorithm converged
  • i: 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:

  1. Initializes voltage values from the provided starting point
  2. Calculates initial power mismatches
  3. Constructs the Jacobian matrix for each iteration
  4. Updates voltage values using Newton's method
  5. 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
source

Linear Problem Solution Algorithm

GPU Acceleration

HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_pv_power_gpuMethod
calculate_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 parameters
  • bus_gpu: Bus data matrix on GPU with columns representing bus parameters
  • Vm_gpu: Vector of bus voltage magnitudes on GPU
  • baseMVA: Base MVA for the system

Returns

  • Spv: Vector of complex power injections from PV arrays
  • dSpv_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.create_bus_mappingMethod
create_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 parameters
  • BUS_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.find_bus_indicesMethod
find_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 matrix
  • active_pv: PV array data matrix with columns representing PV parameters
  • PV_BUS: Column index for connected bus number in active_pv matrix

Returns

  • valid_pv: Boolean array indicating which PV arrays are connected to valid buses
  • bus_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbus_gpuMethod
makeSbus_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 system
  • bus_gpu: Bus data matrix on GPU with columns representing bus parameters
  • gen_gpu: Generator data matrix on GPU with columns representing generator parameters
  • gen: Generator data matrix on CPU with columns representing generator parameters
  • Vm_gpu: Vector of bus voltage magnitudes on GPU
  • load_gpu: Load data matrix on GPU with columns representing load parameters
  • pvarray_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.process_pv_connectionsMethod
process_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 parameters
  • active_pv: PV array data matrix with columns representing PV parameters
  • BUS_I: Column index for bus number in bus_gpu matrix
  • PV_BUS: Column index for connected bus number in active_pv matrix

Returns

  • valid_pv: Boolean array indicating which PV arrays are connected to valid buses
  • bus_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.Sd_gpuType
Sd_gpu

A mutable structure to store ZIP load model components on GPU.

Fields

  • z: Complex vector on GPU representing constant impedance component of load
  • i: Complex vector on GPU representing constant current component of load
  • p: 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzip_gpuMethod
makeSdzip_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 system
  • bus_gpu: Bus data matrix on GPU with columns representing bus parameters
  • pw_1: Vector of constant power percentages for active power
  • pw_2: Vector of constant current percentages for active power
  • pw_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
source

Other Functions

HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_pv_powerMethod
calculate_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 parameters
  • bus: Bus data matrix with columns representing bus parameters
  • Vm: Vector of bus voltage magnitudes
  • baseMVA: Base MVA for the system

Returns

  • Spv: Vector of complex power injections from PV arrays
  • dSpv_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbusFunction
makeSbus(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 system
  • bus: Bus data matrix with columns representing bus parameters
  • gen: Generator data matrix with columns representing generator parameters
  • Vm: 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSbusMethod
makeSbus(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 system
  • bus: Bus data matrix with columns representing bus parameters
  • gen: Generator data matrix with columns representing generator parameters
  • Vm: Vector of bus voltage magnitudes
  • load: Load data matrix with columns representing load parameters
  • pvarray: 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.SdType
Sd

A mutable structure to store ZIP load model components.

Fields

  • z: Complex vector representing constant impedance component of load
  • i: Complex vector representing constant current component of load
  • p: 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzipMethod
makeSdzip(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 system
  • bus: Bus data matrix with columns representing bus parameters
  • pw_1: Vector of constant power percentages for active power
  • pw_2: Vector of constant current percentages for active power
  • pw_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeSdzipMethod
makeSdzip(baseMVA, bus)

Create a ZIP load model structure from bus data with default constant power model.

Arguments

  • baseMVA: Base MVA for the system
  • bus: 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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.makeYbusMethod
makeYbus(baseMVA, bus, branch)

Build the bus admittance matrix and branch admittance matrices.

Arguments

  • baseMVA: Base MVA for the system
  • bus: Bus data matrix with columns representing bus parameters
  • branch: Branch data matrix with columns representing branch parameters

Returns

  • Ybus: Bus admittance matrix
  • Yf: Branch admittance matrix for "from" end of branches
  • Yt: 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:

  1. Computes branch series admittances and line charging susceptances
  2. Handles tap ratios and phase shifters
  3. Incorporates bus shunt admittances
  4. Builds connection matrices between branches and buses
  5. 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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.merge_resultsMethod
merge_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 results
  • area: 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:

  1. Creates a new JPC object to hold the merged results
  2. Combines basic result fields like success status and iteration counts
  3. Merges all data matrices from the input results
  4. 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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.dcpfsolnMethod
dcpfsoln(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 system
  • bus0::Matrix{Float64}: Initial bus data matrix
  • gen0::Matrix{Float64}: Initial generator data matrix
  • branch0::Matrix{Float64}: Initial branch data matrix
  • load0::Matrix{Float64}: Load data matrix
  • Ybus: Bus admittance matrix
  • Yf: From-bus branch admittance matrix
  • Yt: To-bus branch admittance matrix
  • V: Complex bus voltage vector solution
  • ref: Reference (slack) bus indices
  • p: P bus indices

Returns

  • bus: Updated bus data matrix
  • gen: Updated generator data matrix
  • branch: 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:

  1. Updates bus voltage magnitudes
  2. 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
  3. Updates active power (Pg) for generators at slack buses
  4. Calculates branch power flows
  5. 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.process_resultMethod

Process 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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.analyze_voltage_resultsMethod
analyze_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.compare_voltage_resultsMethod
compare_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_voltage_resultsMethod
get_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.get_bus_voltage_results_acdcMethod
get_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.plot_voltage_comparisonFunction
plot_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.plot_voltage_errorsFunction
plot_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.save_comparison_resultsMethod
save_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.calculate_droop_voltageFunction
calculate_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.runhpfMethod
runhpf(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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_ac_load!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_dc_load!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_1_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_3_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_4_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_5_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_6_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.update_mode_7_converters!Method
update_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
source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.runupfMethod
runupf(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

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.total_loadMethod
total_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 information
  • load: Load data matrix containing load model percentages

Returns

  • Pd: Vector of real power demand at each bus
  • Qd: 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.

source
HyDistFlow.TimeDomainPowerFlow.PowerFlow.total_loadMethod
total_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 bus
  • Qd: 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.

source