API

The following functions are designed for public use.

Modeling Tools

Connectors and Base Components

PowerDynamics.Terminal โ€” Constant
@named t = Terminal()

A ModelingToolkit connector for electrical terminals in power system components.

Represents an electrical connection point with complex voltage and current in dq coordinates. The terminal defines the interface between power system components like buses, lines, and machines.

Variables

  • u_r(t): d-axis voltage component
  • u_i(t): q-axis voltage component
  • i_r(t): d-axis current component (flow variable)
  • i_i(t): q-axis current component (flow variable)

Notes

Current variables are defined as flow variables, meaning they sum to zero at connection points according to Kirchhoff's current law.

See also: BusBar, LineEnd

source
PowerDynamics.BusBar โ€” Constant
@named busbar = BusBar()

A ModelingToolkit model representing the physical connection point within a bus in power systems. It represents the physical busbar where all injectors and lines attach.

Within PowerDynamics.jl, it serves as an interface between the MTK world and the NetworkDynamics world: A MTK model containing a BusBar the highest level is consdered a busmodel (see isbusmodel) and describes the dynamics of an entire bus. It can be transformed in a VertexModel by calling Bus.

See also: Terminal, MTKBus, Bus

source
PowerDynamics.LineEnd โ€” Constant
LineEnd

A ModelingToolkit model representing one end of a transmission line in power systems. It represents the physical connection point at the end of a transmission line.

Within PowerDynamics.jl, it serves as an interface between the MTK world and the NetworkDynamics world: A MTK model containing two LineEnds (named :src and :dst) at the highest level is considered a linemodel (see islinemodel) and describes the dynamics of an entire line. It can be transformed in an EdgeModel by calling Line.

See also: Terminal, MTKLine, Line

source

Bus and Line Construction

PowerDynamics.MTKBus โ€” Function
MTKBus(injectors...; name=:bus)

Create a ModelingToolkit bus system by connecting multiple injector components.

Constructs a bus System by connecting all provided injector components to a central BusBar. Each injector component must satisfy the injector model interface (see isinjectormodel).

Arguments

  • injectors...: Variable number of injector components (generators, loads, etc.)
  • name=:bus: Name for the resulting bus system

Returns

  • An System representing the complete bus with all connected injectors
                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚MTKBus   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
                                 โ”‚        โ”Œโ”คGeneratorโ”‚โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”     โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
MTKBus(oโ”คGeneratorโ”‚, oโ”คLoadโ”‚) => โ”‚โ”‚BusBarโ”œo           โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”˜     โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”     โ”‚
                                 โ”‚        โ””โ”คLoadโ”‚     โ”‚
                                 โ”‚         โ””โ”€โ”€โ”€โ”€โ”˜     โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

See also: Bus, BusBar, isinjectormodel

source
PowerDynamics.MTKLine โ€” Function
MTKLine(branches...; name=:line)

Create a ModelingToolkit line system by connecting multiple branch components.

Constructs a line System by connecting all provided branch components between source and destination line ends in parallel. Each branch component must satisfy the branch model interface.

Arguments

  • branches...: Variable number of branch components (transmission lines, transformers, etc.)
  • name=:line: Name for the resulting line system

Returns

  • An System representing the complete line with all connected branches
                                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                     โ”‚MTKLine   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”‚
                                     โ”‚         โ”Œโ”คBranchAโ”œโ”         โ”‚
         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
MTKLine(oโ”คBranchAโ”œo, oโ”คBranchBโ”œo) => โ”‚โ”‚LineEndโ”œo         oโ”คLineEndโ”‚โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
                                     โ”‚  :src   โ””โ”คBranchBโ”œโ”˜  :dst   โ”‚
                                     โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ”‚
                                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

See also: Line, LineEnd, isbranchmodel

source
PowerDynamics.CompositeInjector โ€” Function
CompositeInjector(systems, eqs=autoconnections(systems); name=Symbol(join(getname.(systems), "_")))

Create an injector object which contains several subsystems. Every subsystem which has a terminal will be connected to a newly created terminal of the composite injector. The subsystems are namespaced within the composite injector.

There are two options for additional connections between the subsystems:

  • interconnections will be created automatically using some name-matching heuristics using autoconnections(systems): It searches all Blocks.RealOutput and Blocks.RealInput, and tries to find a single matching output for each input.
  • alternatively pass connecting equations of the form [connect(sys1.output, sys2.input)] explicitly

For example, one could create a composite injector with three subsystems:

  • a generator,
  • a controller, and
  • a load;

which is augmented with 2 connection equations

  • one for the measurements (generator -> controller), and
  • one for the actuation (controller -> generator).

The returned model contains a new terminal :terminal at the toplevel, thus satisfying the injector interface, see isinjectormodel). It can be used as such in the MTKBus constructor.

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ CompositeInjector                  โ”‚
    โ”‚              โ•ญโ”€โ”€โ”€โ†’โ”€โ”€โ”€โ•ฎ measurementsโ”‚
    โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”   โ”Œโ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
(t) โ”‚  oโ”€โ”ค Generator โ”‚   โ”‚ Controller โ”‚  โ”‚
 oโ”€โ”€โ”ผโ”€โ”€โ”ค โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”˜   โ””โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
    โ”‚  โ”‚           โ•ฐโ”€โ”€โ”€โ†โ”€โ”€โ”€โ•ฏ actuation   โ”‚
    โ”‚  โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”                        โ”‚
    โ”‚  oโ”€โ”ค Load โ”‚                        โ”‚
    โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                        โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
source

Base Unit Calculations

PowerDynamics.Ibase โ€” Function
Ibase(S, V)

Calculates current pu base based on Sbase and Vbase: Ibase = Sbase/Vbase.

source
PowerDynamics.Zbase โ€” Function
Zbase(S, V)

Calculates impedance pu base based on Sbase and Vbase: Zbase = Vbaseยฒ/Sbase.

source
PowerDynamics.Ybase โ€” Function
Ybase(S, V)

Calculates admittance pu base based on Sbase and Vbase: Ybase = Sbase/Vbaseยฒ.

source

Network Components

PowerDynamics.Bus โ€” Function
Bus(sys::System; verbose=false, name=getname(sys), kwargs...)

Create a VertexModel from an System that satisfies the bus model interface.

Arguments

  • sys::System: The system must satisfy the bus model interface (see isbusmodel)
  • verbose::Bool=false: Enable verbose output during creation
  • name: Name for the bus (defaults to system name)
  • kwargs...: Additional keyword arguments passed to the Bus constructor

Returns


                                          โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
                                          โ•‘ VertexModel (compiled)  โ•‘
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      Network   โ•‘  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ•‘
    โ”‚MTKBus   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚     interface  โ•‘  โ”‚MTKBus   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚ โ•‘
    โ”‚        โ”Œโ”คGeneratorโ”‚โ”‚                โ•‘  โ”‚        โ”Œโ”คGeneratorโ”‚โ”‚ โ•‘
    โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚      current โ”€โ”€โ”€โ”€โ†’โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚ โ•‘
Bus(โ”‚โ”‚BusBarโ”œo           โ”‚) =>            โ•‘  โ”‚โ”‚BusBarโ”œo           โ”‚ โ•‘
    โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”     โ”‚      voltage โ†โ”€โ”€โ”€โ”€โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”     โ”‚ โ•‘
    โ”‚        โ””โ”คLoadโ”‚     โ”‚                โ•‘  โ”‚        โ””โ”คLoadโ”‚     โ”‚ โ•‘
    โ”‚         โ””โ”€โ”€โ”€โ”€โ”˜     โ”‚                โ•‘  โ”‚         โ””โ”€โ”€โ”€โ”€โ”˜     โ”‚ โ•‘
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ•‘  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ•‘
                                          โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

See also: MTKBus

source
Bus(template::VertexModel; copy=true, vidx=nothing, pf=nothing, name=template.name, pairs...)

Similar to the Bus constructor, but takes a pre-compiled VertexModel. It copies the VertexModel and applies the keyword arguments. This is usefull when you want to create new bus models based on a template.

source
PowerDynamics.Line โ€” Function
Line(sys::System; verbose=false, name=getname(sys), kwargs...)

Create an EdgeModel from a System that satisfies the line model interface.

Arguments

  • sys::System: The system must satisfy the line model interface (see islinemodel)
  • verbose::Bool=false: Enable verbose output during creation
  • name: Name for the line (defaults to system name)
  • kwargs...: Additional keyword arguments passed to the Line constructor

Returns


                                             โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
                                             โ•‘ EdgeModel (compiled)         โ•‘
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     src โ•‘ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ•‘ dst
     โ”‚MTKLine   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          โ”‚  vertex โ•‘ โ”‚MTKLine   โ”Œโ”€โ”€โ”€โ”€โ”          โ”‚ โ•‘ vertex
     โ”‚         โ”Œโ”คBranchAโ”œโ”         โ”‚         โ•‘ โ”‚         โ”Œโ”ค    โ”œโ”         โ”‚ โ•‘
     โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚     u โ”€โ”€โ”€โ†’โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ†โ”€โ”€โ”€ u
Line(โ”‚โ”‚LineEndโ”œo         oโ”คLineEndโ”‚โ”‚) =>     โ•‘ โ”‚โ”‚LineEndโ”œo      oโ”คLineEndโ”‚โ”‚ โ•‘
     โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚     i โ†โ”€โ”€โ”€โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”Œโ”€โ”€โ”€โ”€โ”โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚โ”€โ”€โ”€โ†’ i
     โ”‚  :src   โ””โ”คBranchBโ”œโ”˜  :dst   โ”‚         โ•‘ โ”‚         โ””โ”ค    โ”œโ”˜         โ”‚ โ•‘
     โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜          โ”‚         โ•‘ โ”‚          โ””โ”€โ”€โ”€โ”€โ”˜          โ”‚ โ•‘
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ•‘ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ•‘
                                             โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

See also: MTKLine

source
PowerDynamics.simplify_mtkbus โ€” Function
simplify_mtkbus(sys::System; busbar=:busbar)

Structurally simplify a bus model System by eliminating equations.

Closely matches what VertexModel does, but returns the System after the simplifications rather than compiling it into a VertexModel.

source
PowerDynamics.simplify_mtkline โ€” Function
simplify_mtkline(sys::System; src=:src, dst=:dst)

Structurally simplify a line model System by eliminating equations.

Closely matches what EdgeModel does, but returns the System after the simplifications rather than compiling it into an EdgeModel.

source

Interface Checking Functions

PowerDynamics.isinjectormodel โ€” Function
isinjectormodel(sys::System)

Check if a System satisfies the injector model interface.

An injector model must contain a Terminal named :terminal. Injector models represent components like generators, loads, and other devices that connect to a single bus. They can have arbitrary internal complexity as long as they have exactly one terminal.

   (t)    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    oโ”€โ”€โ”€โ”€โ”€โ”ค Injector โ”‚
:terminal โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

See also: Terminal

source
PowerDynamics.isbusmodel โ€” Function
isbusmodel(sys::System)

Check if a System satisfies the bus model interface.

A bus model must contain a component named :busbar that satisfies the busbar interface. Bus models represent the complete dynamics of a power system bus and can be transformed into a VertexModel using Bus.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚BusModel     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚           โ”Œโ”€โ”ค Injector 1 โ”‚โ”‚
โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ”‚โ”‚ BusBar โ”œโ”€o               โ”‚
โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚               โ”‚
โ”‚ :busbar   โ”” ...           โ”‚
โ”‚                           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Note: The BusModel musst contain exaclty one BusBar, the rest of the structure is free. For example, you could also put a Brach between an injector and a Busbar or have multiple injectors and controllers connected.

See also: Bus, BusBar, MTKBus

source
PowerDynamics.isbranchmodel โ€” Function
isbranchmodel(sys::System)

Check if a System satisfies the branch model interface.

A branch model must contain two Terminal components named :src and :dst. Branch models represent two-port network elements like transmission lines, transformers, and other connecting devices.

 (t) โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” (t)
  oโ”€โ”€โ”ค Branch โ”œโ”€โ”€o
:src โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ :dst

See also: Terminal

source
PowerDynamics.islinemodel โ€” Function
islinemodel(sys::System)

Check if a System satisfies the line model interface.

A line model must contain two components named :src and :dst that both satisfy the line end interface. Line models represent transmission lines and can be transformed into an EdgeModel using Line.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚LineModel     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚            โ”Œโ”€โ”ค Branch โ”œโ”€โ”            โ”‚
โ”‚โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”โ”‚
โ”‚โ”‚ LineEnd โ”œโ”€o            oโ”€โ”ค LineEnd โ”‚โ”‚
โ”‚โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚            โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜โ”‚
โ”‚   :src     โ””    ....    โ”˜    :dst    โ”‚
โ”‚                                      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Note: Between the LineEnds there can be arbeitrary structures, for example branches in series or parallel.

See also: Line, LineEnd, MTKBus

source

Power Flow Analysis

Power Flow Bus Types

PowerDynamics.pfSlack โ€” Function
pfSlack(; V=missing, ฮด=missing, u_r=missing, u_i=missing)

Create a slack bus for power flow analysis.

A slack bus maintains constant voltage magnitude and phase angle (or real and imaginary voltage components). Either provide voltage magnitude V and phase angle ฮด, or provide real and imaginary voltage components u_r and u_i.

source
PowerDynamics.pfPV โ€” Function
pfPV(; P, V)

Create a PV bus for power flow analysis.

A PV bus maintains constant active power injection and voltage magnitude. The reactive power and voltage phase angle are determined by the power flow solution.

source
PowerDynamics.pfPQ โ€” Function
pfPQ(; P=0, Q=0)

Create a PQ bus for power flow analysis.

A PQ bus has specified active and reactive power injections. The voltage magnitude and phase angle are determined by the power flow solution.

source

Power Flow Solution Functions

PowerDynamics.solve_powerflow โ€” Function
solve_powerflow(nw::Network;
                pfnw = powerflow_model(nw),
                pfs0 = NWState(nw),
                verbose=true)

Solve the power flow equations for a given network.

Uses find_fixpoint from NetworkDynamics to solve the algebraic power flow equations.

Parameters

  • nw: The dynamic network model
  • pfnw: The power flow network model (default: created from nw)
  • pfs0: Initial state for the power flow calculation
  • verbose: Whether to print the power flow solution

Returns

  • A NWState containing the solved power flow solution

See also initialize_from_pf.

source
PowerDynamics.initialize_from_pf! โ€” Function
initialize_from_pf[!](
    nw::Network;
    verbose = true,
    subverbose = false,
    pfnw = powerflow_model(nw),
    pfs0 = NWState(pfnw),
    pfs = solve_powerflow(nw; pfnw, pfs0, verbose),
    kwargs...
)

Initialize a dynamic network model from a power flow solution.

This function performs a two-step initialization process:

  1. Solve the power flow equations for the network
  2. Use the power flow solution to initialize the dynamic model

There are two versions of this function: a mutating one (!-at the end of name) and a non-mutating version. The mutating version uses initialize_componentwise! internally, the non-mutating one initialize_componentwise. When the mutating version is used, NWState(nw) after initialization will return the same initialized state again, as it is stored in the metadata.

Parameters

  • nw: The dynamic network model to initialize
  • verbose: Whether to print information about the power flow solution (default: true)
  • subverbose: Whether to print detailed information during component initialization (default: false). Can be Vector [VIndex(1), EIndex(3), ...] for selective output
  • pfnw: Power flow network model (default: created from nw using powerflow_model)
  • pfs0: Initial state for power flow calculation (default: created from pfnw)
  • pfs: Power flow solution (default: calculated using solve_powerflow)
  • Additional keyword arguments are passed to initialize_componentwise[!]

Returns

  • A fully initialized network state

See also: solve_powerflow, initialize_componentwise, interface_values

source
PowerDynamics.initialize_from_pf โ€” Function
initialize_from_pf[!](
    nw::Network;
    verbose = true,
    subverbose = false,
    pfnw = powerflow_model(nw),
    pfs0 = NWState(pfnw),
    pfs = solve_powerflow(nw; pfnw, pfs0, verbose),
    kwargs...
)

Initialize a dynamic network model from a power flow solution.

This function performs a two-step initialization process:

  1. Solve the power flow equations for the network
  2. Use the power flow solution to initialize the dynamic model

There are two versions of this function: a mutating one (!-at the end of name) and a non-mutating version. The mutating version uses initialize_componentwise! internally, the non-mutating one initialize_componentwise. When the mutating version is used, NWState(nw) after initialization will return the same initialized state again, as it is stored in the metadata.

Parameters

  • nw: The dynamic network model to initialize
  • verbose: Whether to print information about the power flow solution (default: true)
  • subverbose: Whether to print detailed information during component initialization (default: false). Can be Vector [VIndex(1), EIndex(3), ...] for selective output
  • pfnw: Power flow network model (default: created from nw using powerflow_model)
  • pfs0: Initial state for power flow calculation (default: created from pfnw)
  • pfs: Power flow solution (default: calculated using solve_powerflow)
  • Additional keyword arguments are passed to initialize_componentwise[!]

Returns

  • A fully initialized network state

See also: solve_powerflow, initialize_componentwise, interface_values

source
PowerDynamics.show_powerflow โ€” Function
show_powerflow(s::NWState/Network)

Display power flow results in a tabular format.

Extract and format power flow solution data from a network state, showing bus-level information including voltage magnitudes, phase angles, active power, and reactive power.

source
PowerDynamics.powerflow_model โ€” Function
powerflow_model(cf::NetworkDynamics.ComponentModel; check=:error)

Extract or create a power flow component model from a dynamic component model.

  1. If the component has :pfmodel metadata, use that model (after validation)
  2. If the component is already a valid power flow model (i.e. no ODE, just constraints), return it as-is

Parameters

  • cf: The component model to extract/create a power flow model from
  • check: Validation behavior (:error, :warn, or :none) when model validation fails

Returns

  • A component model suitable for power flow analysis (no dynamics)

Validation

The returned model must satisfy ispfmodel criteria:

  • Either no states or zero mass matrix (no dynamics)

See also: ispfmodel, pfSlack, pfPV, pfPQ

source
powerflow_model(nw::Network; check=:error)

Create a power flow network model from a dynamic network model.

This method applies powerflow_model to all vertex and edge components in the network, creating a new network suitable for steady-state power flow analysis.

Parameters

  • nw: The network to create a power flow model from
  • check: Validation behavior (:error, :warn, or :none) passed to component-level powerflow_model calls

Returns

  • A new Network with the same graph structure but power flow component models

See also: solve_powerflow

source
PowerDynamics.ispfmodel โ€” Function
ispfmodel(cf::NetworkDynamics.ComponentModel)

Check if a component model is suitable for power flow analysis.

A component model is considered a valid power flow model if it has no dynamics, i.e., either no states or a zero mass matrix.

Returns

  • true if the component is suitable for power flow analysis
  • false otherwise
source

Power Flow Model Management Functions

PowerDynamics.get_pfmodel โ€” Function
get_pfmodel(c::NetworkDynamics.ComponentModel)
get_pfmodel(nw::Network, idx::Union{VIndex,EIndex})

Retrieves the power flow model for the component model. May error if no power flow model is present. Use has_pfmodel to check first.

See also: has_pfmodel, set_pfmodel!.

source
PowerDynamics.delete_pfmodel! โ€” Function
delete_pfmodel!(c::NetworkDynamics.ComponentModel)
delete_pfmodel!(nw::Network, idx::Union{VIndex,EIndex})

Removes the power flow model from the component model, or from a component referenced by idx in a network. Returns true if the power flow model existed and was removed, false otherwise.

See also: set_pfmodel!.

source

Power Flow Initialization Constraints

Constraint Types

PowerDynamics.PFInitConstraint โ€” Type
struct PFInitConstraint{F}
PFInitConstraint(f, sym, pfsym, dim)

A representation of an additional constraint that is applied during the initialization phase of a component. In contrast to a InitConstraint, this constraint may access additional variables which are available in the full NWState of the solved power flow!

Crucially, this is only necessary for constraints, which cannot be expressed in terms of the interface variables (voltages and currents).

See also: @pfinitconstraint for a macro to create such constraints, PFInitConstraint, set_pfinitconstraint!, add_pfinitconstraint!

source
PowerDynamics.PFInitFormula โ€” Type
struct PFInitFormula{F}
PFInitFormula(f, outsym, sym, pfsym)

A representation of an initialization formula that is applied during the initialization phase of a component. In contrast to a InitFormula, this formula may access additional variables which are available in the full NWState of the solved power flow!

Crucially, this is only necessary for formulas, which cannot be expressed in terms of the interface variables (voltages and currents).

Similar to InitFormula, this sets defaults rather than adding constraint equations. The formula is applied early in the initialization pipeline before constraints are solved.

See also: @pfinitformula for a macro to create such formulas, PFInitFormula, set_pfinitformula!, add_pfinitformula!

source
PowerDynamics.@pfinitformula โ€” Macro
@pfinitformula expr
@pfinitformula begin
    :var1 = expr1
    :var2 = expr2
end

Create a PFInitFormula using macro syntax. Component variables are accessed with :symbol and power flow state variables with @pf :symbol. Multiple formulas can be defined in a begin...end block.

Unlike constraints, formulas use assignment syntax (:var = expression) to set variable values during initialization. The left-hand side specifies output variables, and the right-hand side can access both component variables and power flow state variables.

See also: PFInitFormula, set_pfinitformula!, add_pfinitformula!

source

Constraint Management Functions

PowerDynamics.add_pfinitconstraint! โ€” Function
add_pfinitconstraint!(c::NetworkDynamics.ComponentModel, constraint::PFInitConstraint) -> Bool
add_pfinitconstraint!(nw::Network, idx::Union{VIndex,EIndex}, constraint) -> Bool

Adds a new initialization constraint which depends on the powerflow solution to the component. If constraints already exist, the new constraint is added to the existing ones. If no constraints exist, this is equivalent to set_pfinitconstraint!.

Returns true if the constraint was successfully added, false if it already exists.

See also set_pfinitconstraint!, delete_pfinitconstraints!.

source
PowerDynamics.add_pfinitformula! โ€” Function
add_pfinitformula!(c::NetworkDynamics.ComponentModel, formula::PFInitFormula) -> Bool
add_pfinitformula!(nw::Network, idx::Union{VIndex,EIndex}, formula) -> Bool

Adds a new initialization formula which depends on the powerflow solution to the component. If formulas already exist, the new formula is added to the existing ones. If no formulas exist, this is equivalent to set_pfinitformula!.

Returns true if the formula was successfully added, false if it already exists.

See also set_pfinitformula!, delete_pfinitformulas!.

source
PowerDynamics.set_pfinitconstraint! โ€” Function
set_pfinitconstraint!(c::NetworkDynamics.ComponentModel, constraint; check=true)
set_pfinitconstraint!(nw::Network, idx::Union{VIndex,EIndex}, constraint; check=true)

Sets initialization constraints which depend on the powerflow solution to the component. Accepts either a single PFInitConstraint or a tuple of PFInitConstraint objects. Overwrites any existing pf constraints. See also delete_pfinitconstraints!, add_pfinitconstraint!.

source
PowerDynamics.set_pfinitformula! โ€” Function
set_pfinitformula!(c::NetworkDynamics.ComponentModel, formula; check=true)
set_pfinitformula!(nw::Network, idx::Union{VIndex,EIndex}, formula; check=true)

Sets initialization formulas which depend on the powerflow solution to the component. Accepts either a single PFInitFormula or a tuple of PFInitFormula objects. Overwrites any existing pf formulas. See also delete_pfinitformulas!, add_pfinitformula!.

source
PowerDynamics.get_pfinitconstraints โ€” Function
get_pfinitconstraints(c::NetworkDynamics.ComponentModel)
get_pfinitconstraints(nw::Network, idx::Union{VIndex,EIndex})

Retrieves the initialization constraints which depend on pf state for the component model. Returns a tuple of constraints, even if only one constraint is present. May error if no constraints are present. Use has_pfinitconstraint to check first.

See also: has_pfinitconstraint, set_pfinitconstraint!.

source
PowerDynamics.get_pfinitformulas โ€” Function
get_pfinitformulas(c::NetworkDynamics.ComponentModel)
get_pfinitformulas(nw::Network, idx::Union{VIndex,EIndex})

Retrieves the initialization formulas which depend on pf state for the component model. Returns a tuple of formulas, even if only one formula is present. May error if no formulas are present. Use has_pfinitformula to check first.

See also: has_pfinitformula, set_pfinitformula!.

source
PowerDynamics.delete_pfinitconstraints! โ€” Function
delete_pfinitconstraints!(c::NetworkDynamics.ComponentModel)
delete_pfinitconstraints!(nw::Network, idx::Union{VIndex,EIndex})

Removes the powerflow dependent initialization constraint from the component model, or from a component referenced by idx in a network. Returns true if the constraint existed and was removed, false otherwise.

See also: set_pfinitconstraint!.

source
PowerDynamics.delete_pfinitformulas! โ€” Function
delete_pfinitformulas!(c::NetworkDynamics.ComponentModel)
delete_pfinitformulas!(nw::Network, idx::Union{VIndex,EIndex})

Removes the powerflow dependent initialization formula from the component model, or from a component referenced by idx in a network. Returns true if the formula existed and was removed, false otherwise.

See also: set_pfinitformula!.

source