Power System Model

For further information on this topic, please see the Power System Model section of the Manual. Below, we have provided a list of functions that can be used to create, save, and manipulate power system structures, as well as to build AC and DC models of power systems.

To load power system model API functionalities into the current scope, utilize the following command:

using JuliaGrid

Power System
Bus
Branch
Generator

Power System

JuliaGrid.powerSystemFunction
powerSystem(file::String)

The function builds the composite type PowerSystem and populates bus, branch, generator and base fields. Once the composite type PowerSystem has been created, it is possible to add new buses, branches, or generators, or modify the parameters of existing ones.

Argument

It requires a string path to:

  • the HDF5 file with the .h5 extension,
  • the Matpower file with the .m extension.

Returns

The PowerSystem composite type with the following fields:

  • bus: Data related to buses.
  • branch: Data related to branches.
  • generator: Data related to generators.
  • base: Base power and base voltages.
  • model: Data associated with AC and DC analyses.

Units

JuliaGrid stores all data in per-units and radians format which are fixed, the exceptions are base values in volt-amperes and volts. The prefixes for these base values can be changed using the @base macro.

Example

system = powerSystem("case14.h5")
source
powerSystem()

Alternatively, the PowerSystem composite type can be initialized by calling the function without any arguments. This allows the model to be built from scratch and modified as needed. This generates an empty PowerSystem type, with only the base power initialized to 1.0e8 volt-amperes (VA).

Example

system = powerSystem()
source
JuliaGrid.savePowerSystemFunction
savePowerSystem(system::PowerSystem; path::String, reference::String, note::String)

The function saves the power system's data in the HDF5 file using the fields bus, branch, generator, and base from the PowerSystem composite type.

Keywords

The location and file name of the HDF5 file is specified by the mandatory keyword path in the format of "path/name.h5". Additional information can be provided by the optional keywords reference and note, which can be saved along with the power system data.

View HDF5 File

To view the saved HDF5 file, you can use the HDFView software.

Example

system = powerSystem("case14.m")
savePowerSystem(system; path = "D:/case14.h5")
source
JuliaGrid.acModel!Function
acModel!(system::PowerSystem)

The function generates vectors and matrices based on the power system topology and parameters associated with AC analyses.

Updates

The function updates the model.ac field within the PowerSystem composite type, populating the following variables:

  • nodalMatrix: The nodal matrix.
  • nodalMatrixTranspose: The transpose of the nodal matrix.
  • nodalFromFrom: The Y-parameters of the two-port branches.
  • nodalFromTo: The Y-parameters of the two-port branches.
  • nodalToTo: The Y-parameters of the two-port branches.
  • nodalToFrom: The Y-parameters of the two-port branches.
  • admittance: The branch admittances.

Example

system = powerSystem("case14.h5")
acModel!(system)
source
JuliaGrid.dcModel!Function
dcModel!(system::PowerSystem)

The function generates vectors and matrices based on the power system topology and parameters associated with DC analyses.

Updates

The function updates the model.dc field within the PowerSystem composite type, populating the following variables:

  • nodalMatrix: The nodal matrix.
  • admittance: The branch admittances.
  • shiftPower: The active powers related to phase-shifting transformers.

Example

system = powerSystem("case14.h5")
dcModel!(system)
source

Bus

JuliaGrid.addBus!Function
addBus!(system::PowerSystem; label, type, active, reactive, conductance, susceptance,
    magnitude, angle, minMagnitude, maxMagnitude, base, area, lossZone)

The function adds a new bus to the PowerSystem composite type.

Keywords

The bus is defined with the following keywords:

  • label: Unique label for the bus.
  • type: Bus type:
    • type = 1: demand bus (PQ),
    • type = 2: generator bus (PV),
    • type = 3: slack bus (Vθ).
  • active (pu or W): Active power demand at the bus.
  • reactive (pu or VAr): Reactive power demand at the bus.
  • conductance (pu or W): Active power demanded of the shunt element.
  • susceptance (pu or VAr): Reactive power injected/demanded of the shunt element.
  • magnitude (pu or V): Initial value of the bus voltage magnitude.
  • angle (rad or deg): Initial value of the bus voltage angle.
  • minMagnitude (pu or V): Minimum bus voltage magnitude value.
  • maxMagnitude (pu or V): Maximum bus voltage magnitude value.
  • base (V): Voltage base value.
  • area: Area number.
  • lossZone: Loss zone.

Updates

The function updates the bus field of the PowerSystem composite type.

Default Settings

The default settings for certain keywords are as follows: type = 1, magnitude = 1.0, minMagnitude = 0.9, maxMagnitude = 1.1, and base = 138e3. The rest of the keywords are initialized with a value of zero. However, the user can modify these default settings by utilizing the @bus macro.

Units

By default, the keyword parameters use per-units (pu) and radians (rad) as units, with the exception of the base keyword argument, which is in volts (V). However, users have the option to use other units instead of per-units and radians, or to specify prefixes for base voltage by using the @power and @voltage macros.

Examples

Adding a bus using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", active = 0.25, angle = 0.175, base = 132e3)

Adding a bus using a custom unit system:

@power(MW, MVAr, MVA)
@voltage(pu, deg, kV)
system = powerSystem()

addBus!(system; label = "Bus 1", active = 25.0, angle = 10.026, base = 132.0)
source
JuliaGrid.updateBus!Function
updateBus!(system::PowerSystem, [analysis::Analysis]; kwargs...)

The function allows for the alteration of parameters for an existing bus.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined process avoids the need to completely rebuild vectors and matrices when adjusting these parameters.

Keywords

To update a specific bus, provide the necessary kwargs input arguments in accordance with the keywords specified in the addBus! function, along with their respective values. Ensure that the label keyword matches the label of the existing bus you want to modify. If any keywords are omitted, their corresponding values will remain unchanged.

Updates

The function updates the bus field within the PowerSystem composite type, and in cases where parameters impact variables in the ac field, it automatically adjusts the field. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Units

Units for input parameters can be changed using the same method as described for the addBus! function.

Example

system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
updateBus!(system; label = "Bus 1", active = 0.15, susceptance = 0.15)
source
JuliaGrid.@busMacro
@bus(kwargs...)

The macro generates a template for a bus, which can be utilized to define a bus using the addBus! function.

Keywords

To define the bus template, the kwargs input arguments must be provided in accordance with the keywords specified within the addBus! function, along with their corresponding values.

Units

By default, the keyword parameters use per-units (pu) and radians (rad) as units, with the exception of the base keyword argument, which is in volts (V). However, users have the option to use other units instead of per-units and radians, or to specify prefixes for base voltage by using the @power and @voltage macros.

Examples

Adding a bus template using the default unit system:

system = powerSystem()

@bus(type = 2, active = 0.25, angle = 0.1745)
addBus!(system; label = "Bus 1", reactive = -0.04, base = 132e3)

Adding a bus template using a custom unit system:

@power(MW, MVAr, MVA)
@voltage(pu, deg, kV)
system = powerSystem()

@bus(type = 2, active = 25.0, angle = 10.0, base = 132.0)
addBus!(system; label = "Bus 1", reactive = -4.0)
source

Branch

JuliaGrid.addBranch!Function
addBranch!(system::PowerSystem, [analysis::Analysis]; label, from, to, status,
    resistance, reactance, conductance, susceptance, turnsRatio, shiftAngle,
    minDiffAngle, maxDiffAngle, minFromBus, maxFromBus, minToBus, maxToBus, type)

The function adds a new branch to the PowerSystem composite type. A branch can be added between already defined buses.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined approach circumvents the necessity for completely reconstructing vectors and matrices when adding a new branch.

Keywords

The branch is defined with the following keywords:

  • label: Unique label for the branch.
  • from: From-bus label, corresponds to the bus label.
  • to: To-bus label, corresponds to the bus label.
  • status: Operating status of the branch:
    • status = 1: in-service,
    • status = 0: out-of-service.
  • resistance (pu or Ω): Series resistance.
  • reactance (pu or Ω): Series reactance.
  • conductance (pu or S): Total shunt conductance.
  • susceptance (pu or S): Total shunt susceptance.
  • turnsRatio: Transformer off-nominal turns ratio, equal to one for a line.
  • shiftAngle (rad or deg): Transformer phase shift angle, where positive value defines delay.
  • minDiffAngle (rad or deg): Minimum voltage angle difference value between from-bus and to-bus ends.
  • maxDiffAngle (rad or deg): Maximum voltage angle difference value between from-bus and to-bus ends.
  • minFromBus (pu, VA, W, or A): Minimum branch flow rating at the from-bus end.
  • maxFromBus (pu, VA, W, or A): Maximum branch flow rating at the from-bus end.
  • minToBus (pu, VA, W, or A): Minimum branch flow rating at the to-bus end.
  • maxToBus (pu, VA, W, or A): Maximum branch flow rating at the to-bus end.
  • type: Types of minFromBus, maxFromBus, minToBus, and maxToBus branch flow ratings:
    • type = 1: apparent power flow (pu or VA),
    • type = 2: active power flow (pu or W),
    • type = 3: current magnitude flow (pu or A).

Updates

The function updates the branch field within the PowerSystem composite type, and in cases where parameters impact variables in the ac and dc fields, it automatically adjusts the fields. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Default Settings

By default, certain keywords are assigned default values: status = 1, turnsRatio = 1.0, type = 1, minDiffAngle = -2pi, and maxDiffAngle = 2pi. The rest of the keywords are initialized with a value of zero. However, the user can modify these default settings by utilizing the @branch macro.

Units

The default units for the keyword parameters are per-units (pu) and radians (rad). However, the user can choose to use other units besides per-units and radians by utilizing macros such as @power, @voltage, @current, and @parameter.

Examples

Adding a branch using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
addBus!(system; label = "Bus 2", type = 1, active = 0.15, reactive = 0.08)

addBranch!(system; from = "Bus 1", to = "Bus 2", reactance = 0.12, shiftAngle = 0.1745)

Adding a branch using a custom unit system:

@voltage(pu, deg, kV)
system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
addBus!(system; label = "Bus 2", type = 1, active = 0.15, reactive = 0.08)

addBranch!(system; from = "Bus 1", to = "Bus 2", reactance = 0.12, shiftAngle = 10)
source
JuliaGrid.updateBranch!Function
updateBranch!(system::PowerSystem, [analysis::Analysis]; kwargs...)

The function allows for the alteration of parameters for an existing branch.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined process avoids the need to completely rebuild vectors and matrices when adjusting these parameter

Keywords

To update a specific branch, provide the necessary kwargs input arguments in accordance with the keywords specified in the addBranch! function, along with their respective values. Ensure that the label keyword matches the label of the existing branch you want to modify. If any keywords are omitted, their corresponding values will remain unchanged.

Updates

The function updates the branch field within the PowerSystem composite type, and in cases where parameters impact variables in the ac and dc fields, it automatically adjusts the fields. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Units

Units for input parameters can be changed using the same method as described for the addBranch! function.

Example

system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
addBus!(system; label = "Bus 2", type = 1, active = 0.15, reactive = 0.08)

addBranch!(system; label = "Branch 1", from = "Bus 1", to = "Bus 2", reactance = 0.12)
updateBranch!(system; label = "Branch 1", reactance = 0.02, susceptance = 0.062)
source
JuliaGrid.@branchMacro
@branch(kwargs...)

The macro generates a template for a branch, which can be utilized to define a branch using the addBranch! function.

Keywords

To define the branch template, the kwargs input arguments must be provided in accordance with the keywords specified within the addBranch! function, along with their corresponding values.

Units

The default units for the keyword parameters are per-units and radians. However, the user can choose to use other units besides per-units and radians by utilizing macros such as @power, @voltage, and @parameter.

Examples

Adding a branch template using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
addBus!(system; label = "Bus 2", type = 1, active = 0.15, reactive = 0.08)

@branch(reactance = 0.12, shiftAngle = 0.1745)
addBranch!(system; label = "Branch 1", from = "Bus 1", to = "Bus 2")

Adding a branch template using a custom unit system:

@voltage(pu, deg, kV)
system = powerSystem()

addBus!(system; label = "Bus 1", type = 3, active = 0.25, reactive = -0.04)
addBus!(system; label = "Bus 2", type = 1,  active = 0.15, reactive = 0.08)

@branch(shiftAngle = 10)
addBranch!(system; label = "Branch 1", from = "Bus 1", to = "Bus 2", reactance = 0.12)
source

Generator

JuliaGrid.addGenerator!Function
addGenerator!(system::PowerSystem, [analysis::Analysis]; label, bus, status,
    active, reactive, magnitude, minActive, maxActive, minReactive, maxReactive,
    lowActive, minLowReactive, maxLowReactive, upActive, minUpReactive, maxUpReactive,
    loadFollowing, reactiveRamp, reserve10min, reserve30min, area)

The function adds a new generator to the PowerSystem composite type. The generator can be added to an already defined bus.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined approach circumvents the necessity for completely reconstructing vectors and matrices when adding a new generator.

Keywords

The generator is defined with the following keywords:

  • label: Unique label for the generator.
  • bus: Label of the bus to which the generator is connected.
  • status: Operating status of the generator:
    • status = 1: in-service,
    • status = 0: out-of-service.
  • active (pu or W): Output active power.
  • reactive (pu or VAr): Output reactive power.
  • magnitude (pu or V): Voltage magnitude setpoint.
  • minActive (pu or W): Minimum allowed output active power value.
  • maxActive (pu or W): Maximum allowed output active power value.
  • minReactive (pu or VAr): Minimum allowed output reactive power value.
  • maxReactive (pu or VAr): Maximum allowed output reactive power value.
  • lowActive (pu or W): Lower allowed active power output value of PQ capability curve.
  • minLowReactive (pu or VAr): Minimum allowed reactive power output value at lowActive value.
  • maxLowReactive (pu or VAr): Maximum allowed reactive power output value at lowActive value.
  • upActive (pu or W): Upper allowed active power output value of PQ capability curve.
  • minUpReactive (pu or VAr): Minimum allowed reactive power output value at upActive value.
  • maxUpReactive (pu or VAr): Maximum allowed reactive power output value at upActive value.
  • loadFollowing (pu/min or W/min): Ramp rate for load following/AG.
  • reserve10min (pu or W): Ramp rate for 10-minute reserves.
  • reserve30min (pu or W): Ramp rate for 30-minute reserves.
  • reactiveRamp (pu/min or VAr/min): Ramp rate for reactive power, two seconds timescale.
  • area: Area participation factor.

Updates

The function updates the generator field within the PowerSystem composite type, and in cases where parameters impact variables in the bus field, it automatically adjusts the field. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Default Settings

By default, certain keywords are assigned default values: status = 1 and magnitude = 1.0 per-unit. The rest of the keywords are initialized with a value of zero. However, the user can modify these default settings by utilizing the @generator macro.

Units

By default, the input units are associated with per-units (pu) as shown. However, users have the option to use other units instead of per-units using the @power and @voltage macros.

Examples

Adding a generator using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", type = 2, active = 0.2, base = 132e3)

addGenerator!(system; bus = "Bus 1", active = 0.5, magnitude = 1.1)

Adding a generator using a custom unit system:

@power(MW, MVAr, MVA)
@voltage(kV, deg, kV)
system = powerSystem()

addBus!(system; label = "Bus 1", type = 2, active = 20, base = 132)

addGenerator!(system; bus = "Bus 1", active = 50, magnitude = 145.2)
source
JuliaGrid.updateGenerator!Function
updateGenerator!(system::PowerSystem, [analysis::Analysis]; kwargs...)

The function allows for the alteration of parameters for an existing generator.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined process avoids the need to completely rebuild vectors and matrices when adjusting these parameter

Keywords

To update a specific generator, provide the necessary kwargs input arguments in accordance with the keywords specified in the addGenerator! function, along with their respective values. Ensure that the label keyword matches the label of the existing generator you want to modify. If any keywords are omitted, their corresponding values will remain unchanged.

Updates

The function updates the generator field within the PowerSystem composite type, and in cases where parameters impact variables in the bus field, it automatically adjusts the field. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Units

Units for input parameters can be changed using the same method as described for the addBranch! function.

Example

system = powerSystem()

addBus!(system; label = "Bus 1", type = 2, active = 0.2, base = 132e3)

addGenerator!(system; label = "Generator 1", bus = "Bus 1", active = 0.5)
updateGenerator!(system; label = "Generator 1", active = 0.6, reactive = 0.2)
source
JuliaGrid.cost!Function
cost!(system::PowerSystem, [analysis::Analysis]; label, active, reactive,
    piecewise, polynomial)

The function either adds a new cost or modifies an existing one for the active or reactive power generated by the corresponding generator within the PowerSystem composite type. It has the capability to append a cost to an already defined generator.

Arguments

If the Analysis type is omitted, the function applies changes to the PowerSystem composite type only. However, when including the Analysis type, it updates both the PowerSystem and Analysis types. This streamlined approach circumvents the necessity for completely reconstructing vectors and matrices when adding a new branch.

Keywords

The function accepts five keywords:

  • label: Corresponds to the already defined generator label.
  • active: Active power cost model:
    • active = 1: adding or updating cost, and piecewise linear is being used,
    • active = 2: adding or updating cost, and polynomial is being used.
  • reactive: Reactive power cost model:
    • reactive = 1: adding or updating cost, and piecewise linear is being used,
    • reactive = 2: adding or updating cost, and polynomial is being used.
  • piecewise: Cost model defined by input-output points given as Matrix{Float64}:
    • first column (pu, W or VAr): active or reactive power output of the generator,
    • second column (€/hr): cost for the specified active or reactive power output.
  • polynomial: The n-th degree polynomial coefficients given as Vector{Float64}:
    • first element (€/puⁿ-hr, €/Wⁿhr or €/VArⁿ-hr): coefficient of the n-th degree term, ....,
    • penultimate element (€/pu-hr, €/W-hr or €/VAr-hr): coefficient of the first degree term,
    • last element (€/hr): constant coefficient.

Updates

The function updates the generator.cost field within the PowerSystem composite type. Furthermore, it guarantees that any modifications to the parameters are transmitted to the Analysis type.

Units

By default, the input units related with active powers are per-units (pu), but they can be modified using the macro @power.

Examples

Adding a cost using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", active = 0.25, reactive = -0.04, base = 132e3)

addGenerator!(system; label = "Generator 1", bus = "Bus 1", active = 0.5)
cost!(system; label = "Generator 1", active = 2, polynomial = [1100.0; 500.0; 150.0])

Adding a cost using a custom unit system:

@power(MW, MVAr, MVA)
system = powerSystem()

addBus!(system; label = "Bus 1", active = 25, reactive = -4, base = 132e3)

addGenerator!(system; label = "Generator 1", bus = "Bus 1", active = 50, reactive = 10)
cost!(system; label = "Generator 1", active = 2, polynomial = [0.11; 5.0; 150.0])
source
JuliaGrid.@generatorMacro
@generator(kwargs...)

The macro generates a template for a generator, which can be utilized to define a generator using the addGenerator! function.

Keywords

To define the generator template, the kwargs input arguments must be provided in accordance with the keywords specified within the addGenerator! function, along with their corresponding values.

Units

By default, the input units are associated with per-units (pu) as shown. However, users have the option to use other units instead of per-units using the @power and @voltage macros.

Examples

Adding a generator using the default unit system:

system = powerSystem()

addBus!(system; label = "Bus 1", type = 2, active = 0.25, reactive = -0.04, base = 132e3)

@generator(magnitude = 1.1)
addGenerator!(system; label = "Generator 1", bus = "Bus 1", active = 0.5, reactive = 0.1)

Adding a generator using a custom unit system:

@power(MW, MVAr, MVA)
@voltage(kV, deg, kV)
system = powerSystem()

addBus!(system; label = "Bus 1", type = 2, active = 25, reactive = -4, base = 132)

@generator(magnitude = 145.2)
addGenerator!(system; label = "Generator 1", bus = "Bus 1", active = 50, reactive = 10)
source