Network Module

The Net module provides functionality for creating and manipulating power system network models in Julia. It includes features for defining buses, branches, transformers, prosumers, and shunts, as well as methods for running power flow analysis.

# Import the Net module
  using Sparlectra
  using BenchmarkTools
  net = Net(name = "case5", baseMVA = 100.0)
  addBus!(net = net, busName = "B1", busType = "PQ", vn_kV = 110.0, vm_pu = 1.0, va_deg = 0.0)
  addBus!(net = net, busName = "B2", busType = "PQ", vn_kV = 110.0, vm_pu = 1.0, va_deg = 0.0)
  addBus!(net = net, busName = "B3", busType = "PQ", vn_kV = 110.0, vm_pu = 1.0, va_deg = 0.0)
  addBus!(net = net, busName = "B4", busType = "PQ", vn_kV = 110.0, vm_pu = 1.0, va_deg = 0.0)
  addBus!(net = net, busName = "B5", busType = "Slack", vn_kV = 110.0, vm_pu = 1.0, va_deg = 0.0)

  addACLine!(net = net, fromBus = "B1", toBus = "B2", length = 25.0, r = 0.2, x = 0.39)
  addACLine!(net = net, fromBus = "B1", toBus = "B3", length = 25.0, r = 0.2, x = 0.39)
  addACLine!(net = net, fromBus = "B2", toBus = "B4", length = 25.0, r = 0.2, x = 0.39)
  addACLine!(net = net, fromBus = "B3", toBus = "B4", length = 25.0, r = 0.2, x = 0.39)
  addACLine!(net = net, fromBus = "B4", toBus = "B5", length = 25.0, r = 0.2, x = 0.39)

  addProsumer!(net = net, busName = "B1", type = "ENERGYCONSUMER", p = 1.0, q = 2.0)
  addProsumer!(net = net, busName = "B2", type = "ENERGYCONSUMER", p = 1.0, q = 2.0)
  addProsumer!(net = net, busName = "B3", type = "ENERGYCONSUMER", p = 1.0, q = 2.0)

  addProsumer!(net = net, busName = "B5", type = "SYNCHRONMASCHINE", referencePri = "B5", vm_pu = 1.0, va_deg = 0.0)
  addProsumer!(net = net, busName = "B1", type = "GENERATOR", p = 1.1, q = 2.0)

  # Run power flow
  tol = 1e-6
  maxIte = 10  
  etime = @elapsed begin
    ite, erg = runpf!(net, maxIte, tol, 0)
  end
  if erg != 0
    @warn "Power flow did not converge"        
  else
    calcNetLosses!(net)
    printACPFlowResults(net, etime, ite, tol)
  end
  
Sparlectra.add2WTrafo!Method

Add a two-winding transformer to the network.

Arguments

  • net::Net: The network to which the transformer will be added.
  • fromBus::String: The name of the bus where the transformer originates.
  • toBus::String: The name of the bus where the transformer terminates.
  • sn_mva::Float64: Rated power of the transformer.
  • vk_percent::Float64: Voltage regulation percent of the transformer.
  • vkr_percent::Float64: Voltage regulation percent of the transformer.
  • pfe_kw::Float64: Iron loss of the transformer.
  • i0_percent::Float64: No-load current percent of the transformer.
  • status::Int: The status of the transformer. Default is 1.
source
Sparlectra.addACLine!Method

addACLine!: Adds an AC line segment to the network.

Parameters:

  • net::Net: Network object.
  • fromBus::String: Name of the "from" bus.
  • toBus::String: Name of the "to" bus.
  • length::Float64: Length of the line segment.
  • r::Float64: Resistance per Meter of the line segment.
  • x::Float64: Reactance per Meter of the line segment.
  • b::Union{Nothing,Float64} = nothing: Susceptance per Meter of the line segment (default is nothing).
  • c_nf_per_km::Union{Nothing,Float64} = nothing: Capacitance per Meter of the line segment in nF/km (default is nothing).
  • tanδ::Union{Nothing,Float64} = nothing: Tangent of the loss angle (default is nothing).
  • ratedS::Union{Nothing, Float64}= nothing: Rated power of the line segment in MVA (default is nothing).
  • status::Int = 1: Status of the line segment (default is 1).
source
Sparlectra.addBranch!Method

addBranch!: Adds a branch to the network.

Parameters:

  • net::Net: Network object.
  • from::Int: Index of the "from" bus.
  • to::Int: Index of the "to" bus.
  • branch::AbstractBranch: Branch object to add.
  • status::Int = 1: Status of the branch (default is 1).
  • ratio::Union{Nothing,Float64} = nothing: Ratio of the branch (default is nothing).
  • side::Union{Nothing,Int} = nothing: Side of the branch (default is nothing).
  • vn_kV::Union{Nothing,Float64} = nothing: Nominal voltage of the branch in kV (default is nothing).
source
Sparlectra.addBus!Method

addBus!: Adds a bus to the network.

Parameters:

  • net::Net: Network object.
  • busName::String: Name of the bus.
  • busType::String: Type of the bus (e.g., "Slack", "PQ", "PV").
  • vn_kV::Float64: Nominal voltage of the bus in kV.
  • vm_pu::Float64 = 1.0: Voltage magnitude of the bus in per unit (default is 1.0).
  • va_deg::Float64 = 0.0: Voltage angle of the bus in degrees (default is 0.0).
  • vmin_pu::Union{Nothing,Float64} = nothing: Minimum voltage limit in per unit (default is network's vmin_pu).
  • vmax_pu::Union{Nothing,Float64} = nothing: Maximum voltage limit in per unit (default is network's vmax_pu).
  • isAux::Bool = false: Boolean indicating if the bus is auxiliary (default is false).
  • oBusIdx::Union{Nothing,Int} = nothing: Original bus index (default is nothing).
  • zone::Union{Nothing,Int} = nothing: Zone index (default is nothing).
  • area::Union{Nothing,Int} = nothing: Area index (default is nothing).
  • ratedS::Union{Nothing,Float64} = nothing: Rated power of the bus in MVA (default is nothing).
source
Sparlectra.addBusGenPower!Method

Update the active and reactive power of a generator connected to a bus in the network.

Arguments

  • net::Net: The network object.
  • busName::String: The name of the bus.
  • p::Union{Nothing, Float64}: The active power to update. Default is nothing.
  • q::Union{Nothing, Float64}: The reactive power to update. Default is nothing.

Note: the corresponding prosumer object will not be updated.

Examples

net = run_acpflow(max_ite= 7,tol = 1e-6, casefile='a_case.m') # run the power flow on the network and get the network object
updateBusPower!(net = net, busName = "Bus1", p = 0.5, q = 0.2) # Update the power of Bus1 to 0.5 MW and 0.2 MVar
run_net_acpflow(net = net, max_ite= 7,tol = 1e-6) # rerun the power flow with the updated network
source
Sparlectra.addBusLoadPower!Method

Update the active and reactive power of a load connected to a bus in the network.

Arguments

  • net::Net: The network object.
  • busName::String: The name of the bus.
  • p::Union{Nothing, Float64}: The active power to update. Default is nothing.
  • q::Union{Nothing, Float64}: The reactive power to update. Default is nothing.

Note: the corresponding prosumer object will not be updated.

Examples

net = run_acpflow(max_ite= 7,tol = 1e-6, casefile='a_case.m') # run the power flow on the network and get the network object
updateBusPower!(net = net, busName = "Bus1", p = 0.5, q = 0.2) # Update the power of Bus1 to 0.5 MW and 0.2 MVar
run_net_acpflow(net = net, max_ite= 7,tol = 1e-6) # rerun the power flow with the updated network
source
Sparlectra.addBusShuntPower!Method

Update the active and reactive power of a shunt connected to a bus in the network.

Arguments

  • net::Net: The network object.
  • busName::String: The name of the bus.
  • p::Float64: The active power to update.
  • q::Float64: The reactive power to update.

Examples

net = run_acpflow(max_ite= 7,tol = 1e-6, casefile='a_case.m') # run the power flow on the network and get the network object
updateBusPower!(net = net, busName = "Bus1", p = 0.5, q = 0.2) # Update the power of Bus1 to 0.5 MW and 0.2 MVar
run_net_acpflow(net = net, max_ite= 7,tol = 1e-6) # rerun the power flow with the updated network
source
Sparlectra.addPIModelACLine!Method
addPIModelACLine!(; net::Net, fromBus::String, toBus::String, r_pu::Float64, x_pu::Float64, b_pu::Float64, status::Int, ratedS::Union{Nothing,Float64}=nothing)

Adds a PI model AC line to the network.

Arguments

  • net::Net: The network.
  • fromBus::String: The name of the bus where the line starts.
  • toBus::String: The name of the bus where the line ends.
  • r_pu::Float64: The per unit resistance of the line.
  • x_pu::Float64: The per unit reactance of the line.
  • b_pu::Float64: The per unit total line charging susceptance of the line.
  • status::Int: The status of the line. 1 = in service, 0 = out of service.
  • ratedS::Union{Nothing,Float64}: The rated power of the line.

Example

addPIModelACLine!(net = network, fromBus = "Bus1", toBus = "Bus2", r_pu = 0.01, x_pu = 0.1, b_pu = 0.02, status = 1, ratedS = 100.0)
source
Sparlectra.addPIModelTrafo!Method

Add a transformer with PI model to the network.

Arguments

  • net::Net: The network to which the transformer will be added.
  • fromBus::String: The name of the bus where the transformer originates.
  • toBus::String: The name of the bus where the transformer terminates.
  • r_pu::Float64: The per-unit resistance of the transformer.
  • x_pu::Float64: The per-unit reactance of the transformer.
  • b_pu::Float64: The per-unit susceptance of the transformer.
  • status::Int: The status of the transformer.
  • ratedU::Union{Nothing, Float64}: Rated voltage of the transformer. Default is nothing.
  • ratedS::Union{Nothing, Float64}: Rated apparent power of the transformer. Default is nothing.
  • ratio::Union{Nothing, Float64}: Ratio of the transformer. Default is nothing.
  • shift_deg::Union{Nothing, Float64}: Phase shift angle of the transformer. Default is nothing.
  • isAux::Bool: Whether the transformer is an auxiliary transformer. Default is false.
source
Sparlectra.addProsumer!Method

Add a prosumer (combination of a producer and consumer) to the network.

Arguments

  • net::Net: The network to which the prosumer will be added.
  • busName::String: The name of the bus where the prosumer is connected.
  • type::String: The type of the prosumer.
  • p::Union{Nothing, Float64}: Active power produced or consumed. Default is nothing.
  • q::Union{Nothing, Float64}: Reactive power produced or consumed. Default is nothing.
  • pMin::Union{Nothing, Float64}: Minimum active power. Default is nothing.
  • pMax::Union{Nothing, Float64}: Maximum active power. Default is nothing.
  • qMin::Union{Nothing, Float64}: Minimum reactive power. Default is nothing.
  • qMax::Union{Nothing, Float64}: Maximum reactive power. Default is nothing.
  • referencePri::Union{Nothing, String}: Reference bus for the prosumer. Default is nothing.
  • vm_pu::Union{Nothing, Float64}: Voltage magnitude setpoint. Default is nothing.
  • va_deg::Union{Nothing, Float64}: Voltage angle setpoint. Default is nothing.
source
Sparlectra.addShunt!Method

addShunt!: Adds a shunt to the network.

Parameters:

  • net::Net: Network object.
  • busName::String: Name of the bus to which the shunt is added.
  • pShunt::Float64: Active power of the shunt in MW.
  • qShunt::Float64: Reactive power of the shunt in MVar.
  • in_service::Int = 1: Indicator for shunt's in-service status (default is 1).
source
Sparlectra.geNetBusIdxMethod

geNetBusIdx: Gets the index of a bus in the network.

Parameters:

  • net::Net: Network object.
  • busName::String: Name of the bus.

Returns:

  • Int: Index of the bus in the network.
source
Sparlectra.getBusTypeMethod

Get the type of a specific bus in the network.

Arguments

  • net::Net: The network from which to retrieve the bus type.
  • busName::String: The name of the bus.

Returns

The type of the specified bus.

source
Sparlectra.getNetOrigBusIdxMethod

getNetOrigBusIdx: Gets the original index of a bus in the network.

Parameters:

  • net::Net: Network object.
  • busName::String: Name of the bus.

Returns:

  • Int: Original index of the bus in the network.
source
Sparlectra.getTotalLossesMethod

Get the total losses in the network.

Arguments

  • net::Net: The network from which to retrieve the losses.

Returns

A tuple (pLosses::Float64, qLosses::Float64) containing the total active and reactive power losses in the network.

source
Sparlectra.get_bus_vn_kVMethod

Get the voltage magnitude of a specific bus in the network.

Arguments

  • net::Net: The network from which to retrieve the voltage magnitude.
  • busName::String: The name of the bus.

Returns

The voltage magnitude of the specified bus.

source
Sparlectra.get_vn_kVMethod

Get the voltage magnitude of a specific bus in the network.

Arguments

  • net::Net: The network from which to retrieve the voltage magnitude.
  • busIdx::Int: The index of the bus.

Returns

The voltage magnitude of the specified bus.

source
Sparlectra.hasBusInNetMethod

hasBusInNet: Checks if a bus exists in the network.

Parameters:

  • net::Net: Network object.
  • busName::String: Name of the bus to check.

Returns:

  • Bool: True if the bus exists in the network, otherwise false.
source
Sparlectra.lockNet!Method

Lock or unlock the network.

Arguments

  • net::Net: The network to be locked or unlocked.
  • locked::Bool: Boolean indicating whether to lock the network.
source
Sparlectra.setBranchStatus!Method

Set the status of a branch in the network.

Arguments

  • net::Net: The network object.
  • fromBus::String: The name of the bus where the branch originates.
  • toBus::String: The name of the bus where the branch terminates.
  • status::Int: The new status of the branch.

Examples

net = run_acpflow(max_ite= 7,tol = 1e-6, casefile='a_case.m') # run the power flow on the network and get the network object
setBranchStatus!(net, "Bus1", "Bus2", 1)  # Set the status of the branch from Bus1 to Bus2 to 1.
run_net_acpflow(net = net, max_ite= 7,tol = 1e-6) # rerun the power flow with the updated network
source
Sparlectra.setTotalLosses!Method

Set the total losses in the network.

Arguments

  • net::Net: The network to which the losses will be added.
  • pLosses::Float64: Total active power losses.
  • qLosses::Float64: Total reactive power losses.
source
Sparlectra.updateBranchParameters!Method
updateBranchParameters!(;net::Net, fromBus::String, toBus::String, branch::AbstractBranch)

Updates the parameters of a branch in the network.

Arguments

  • net::Net: The network.
  • fromBus::String: The name of the bus where the branch starts.
  • toBus::String: The name of the bus where the branch ends.
  • branch::BranchModel: The branch with the updated parameters.

Example

updateBranchParameters!(net = network, fromBus = "Bus1", toBus = "Bus2", branch = updatedBranch)
source
Sparlectra.validate!Method

Validate the network configuration.

Arguments

  • net::Net: The network to be validated.

Returns

A tuple (valid::Bool, message::String) where valid is a boolean indicating whether the network is valid, and message is a string containing an error message if the network is invalid.

source