ElectricGrid.CharpolyCoefMethod
α = CharpolyCoef(λ)

Description

given the roots, this function finds the coefficients

Return Values

  • α: vector of length(λ)
source
ElectricGrid.CheckParametersMethod
CheckParameters(parameters, num_sources, num_loads, num_connections, CM, ts, verbosity)

Checks the parameter dict for completeness.

Gets parameters and controls the entries based on the given inputs num_sources, num_loads, num_connections, CM and ts. Messages can be suppressed by verbosity.

Arguments

  • parameters::Dict: dict containing all parameters of the node
  • num_sources::Int: number of sources
  • num_loads::Int: number of loads
  • num_connections::Int: number of connections
  • CM::Matrix: connectivity matrix describing the connections in the grid
source
ElectricGrid.CheckPowerBalanceMethod
p_load_total, q_load_total, s_load_total, s_source_total = CheckPowerBalance(parameters)

Description

Determines based on the parameters of the grid the total power (active and reactive) drawn from all load and the total power provided by the sources. Thereby, steady state is assumed.

Arguments

  • parameters::Dict: Dictonary to define the parameter of the grid.
  • num_sources::Int: Number of sources in the electric power grid.
  • num_loads::Int: Number of loads in the electric power grid.
  • CM::Matrix: Conectivity matrix to define the structure of the electric power grid.

Return Values

  • p_load_total::float: Total active power drawn by all loads (passive components as well as controlled with negative reference value).
  • q_load_total::float: Total reactive power drawn by all loads.
  • sloadtotal::float`: Total apparent power drawn by all loads.
  • s_source_total::float: Total apparent power provided by all sources in steady state.
source
ElectricGrid.ClarkeMagMethod

Description

Scaled L2 norm in αβγ coordinates - intantaneous approximation of rms for 3 phase systems

source
ElectricGrid.ClassicalControlMethod
ClassicalControl(ClassicalPolicy, ElectricGridEnv)

Description

Loops through all of the sources, obtaining measurments from the environment and calculating the actions.

source
ElectricGrid.CustomRunFunction

Wraps the Run function form https://juliareinforcementlearning.org/ to enable turning off the action noise.

source
ElectricGrid.DCLinkVoltagesInitMethod

Initializes the VDC link struct by extracting the structs from the parameterdict and collecting them in a separate struct which will be queried later at runtime.

source
ElectricGrid.DividedDiffMethod
DividedDiff(x, y)

Description

Calculates the coefficients required for Newton interpolation using a divided differences algorithm.

source
ElectricGrid.FaultLevelMethod
R, L = FaultLevel(S, X_R, Vrms; fsys = 50, phase = 3)

Arguments

  • S::Float: 3 phase short-circuit power [VA].
  • X/R::Float: The (Short Circuit) ratio of reactance to resistance.
  • Vrms::Float: Line to Neutral rms voltage of external network [V].

Keyword Arguments

  • fsys::Float: System frequency [Hz].
  • phase::Int: Single or 3 phase system, i.e. phase = 1, or phase = 3.

Return Values

  • R::Float: Effective resistance [Ω].
  • L::Float: Effective inductance [H].

Theory

An external network is often characterised by its Fault level and its X/R ratio. In particular the Fault Level is a measure of the strength of a network. It is the amount of apparent power that the network can supply when a three-phase bolted to ground fault is applied at the point of connection. From these values an effective resistance and inductance can be calculated. Typical values of X/R ratios are in the range of 0.5 to 1.5, for distribution networks. Transmission networks operating at higher voltages tend to have higher X/R ratios.

source
ElectricGrid.FilterDesignMethod
FilterDesign(Sr, fs, fltr; Vrms = 230, Vdc = 800, ΔILf_ILf = 0.15, ΔVCf_VCf = 0.01537)

Description

Designs the filter inductances and capacitances for the sources

Arguments

  • Sr::Float: rated 3 phase Apparent Power [VA]
  • fs::Float:switching frequency
  • fltr::String: topology "LCL", "LC", "L"

Keyword Arguments

  • Vrms::Float: nominal AC rms voltage
  • Vdc::Float: nominal DC voltage
  • ΔILf_ILf::Float: current ripple ratio
  • ΔVCf_VCf::Float: voltage ripple ratio
source
ElectricGrid.FilteringMethod
Filtering(Source::ClassicalControls, num_source, θ)

Description

First order Low pass filter on voltage DQ0 components.

source
ElectricGrid.GenerateAMethod
GenerateA(self::NodeConstructor)

Returns the A matrix by joining the individual sub-matrices together.

source
ElectricGrid.GenerateBMethod
GenerateB(self::NodeConstructor)

Returns the B matrix by joining the individual sub-matrices together.

source
ElectricGrid.GenerateCMMethod
GenerateCM(num_sources, num_loads, S2L_p, S2S_p, L2L_p)

Returns the constructed CM and the total number of connections.

Gets num_sources and num_loads to calculate the total number of elements. Depending on the probabilities S2L_p, S2S_p and L2L_p, the entries are then set in the CM matrix. After the entries have been set randomly, it is checked that all elements have at least one connection and that no subnets have been created.

Arguments

  • num_sources::Int: number of sources
  • num_loads::Int: number of loads
  • S2L_p::Int: probability that a source is connected to a load
  • S2S_p::Int: probability that a source is connected to a source
  • L2L_p::Int: probability that a load is connected to a load

Return Values

  • cntr::Int: number of connections
  • CM::Matrix: connectivity matrix describing the connections in the grid
source
ElectricGrid.GetActionIdsMethod
GetActionIds(self::NodeConstructor)

Creates the State Vector for an related NodeConstructor and outputs it as a list of strings.

source
ElectricGrid.GetFltrDistrMethod
GetFltrDistr(num)

Calculates the distribution of filters based on a Dirichlet distribution and the total num of filters.

source
ElectricGrid.GetOptimizerStatusMethod
optimizer_status = GetOptimizerStatus(model)

Description

Returns the status of the optimizer after the optimization process.

Arguments

  • model::JuMP.Model: JuMP model of the optimization problem.

Return Values

  • optimizer_status::Dict: Dictionary containing the termination status, the primal status and the objective value of the optimization problem.
source
ElectricGrid.GetPQMethod
P, Q = GetPQ(model)

Description

Returns the active and reactive power of all nodes in the grid.

Arguments

  • model::JuMP.Model: JuMP model of the optimization problem.

Return Values

  • P::Vector: Vector containing the active power of all nodes in the grid.
  • Q::Vector: Vector containing the reactive power of all nodes in the grid.
source
ElectricGrid.GetStateIdsMethod
GetStateIds(self::NodeConstructor)

Creates the State Vector for an related NodeConstructor and outputs it as a list of strings.

source
ElectricGrid.GetYBusMethod
GetYBus(self::NodeConstructor)

Returns the Admittance Matrix of the power grid based on the CM matrix and the parameters.

source
ElectricGrid.LearnMethod

hook = Learn(controllers, env, num_episodes = 1 hook=hook)

Description

Executed the given controllers in the environments for num_episodes. Fills thereby the hook. Here the RL agents are training and e.g. action noise is applied.

Arguments

  • controllers::MultiController: Contains controllers and agents
  • env::ElectricGridEnv: mutable struct containing the environment.
  • num_episodes::Int: Number of episodes simulated.
  • hook::DataHook: Stores the data to measure in a DataFrame.

Return Values

  • hook::DataHook: Measured data.
source
ElectricGrid.LuenbergerObserverMethod
LuenbergerObserver(Source::ClassicalControls, num_source)

Description

Discrete time approximate deadbeat Luenberger observer operating in DQ0 frame

source
ElectricGrid.MeasurementsMethod
Measurements(Source::ClassicalControls)

Description

Calculates RMS quantities and Active and Reactive power for every classical source.

source
ElectricGrid.NewtonInterpolationMethod
NewtonInterpolation(coef, x_data, x)

Description

Performs a Newton interpolation. Think of x as the point in time, and x_data as the points in time where we know what values the function takes.

source
ElectricGrid.ObservabilityMethod
O, rank(O) = Observability(C, A)

Description

Finds the observability matrix.

Return Values

  • O: Observability matrix
  • rank(O): rank of O
source
ElectricGrid.PIControllerMethod
PIController(Error_new, Error_Hist, Error_t, Kp, Ki, μ; bias = zeros(length(Error_new)))

Description

Generic PI controller.

source
ElectricGrid.PQControlModeMethod
PQControlMode(Source::ClassicalControls, num_source, pq0)

Description

Wrapper for simple grid following control. A controllable load on the real and imaginary power.

source
ElectricGrid.PVControlModeMethod
PVControlMode(Source::ClassicalControls, num_source, pq0)

Description

Wrapper for more elaborate grid following control. A controllable load on the real power and voltage magnitude.

source
ElectricGrid.ParallelLoadImpedanceMethod

R, LC, X, Z = ParallelLoadImpedance(S, pf, vrms; fsys = 50, typesign = nothing)

Arguments

  • S::Float: 3 phase Apparent Power [VA]
  • pf::Float: power factor. pf > 0 -> inductive load, pf < 0 -> capacitive load
  • Vrms::Float: Line to Neutral rms voltage of external network [V]

Keyword Arguments

  • fsys::Float: system frequency [Hz]
  • type_sign::String: "L" or "C" -> for purely capacitive or inductive loads

Return Values

  • R::Float: resistance [Ω]
  • L_C::Float: inductance [H] or capacitance [F]
  • X::Float: reactance [Ω]
  • Z::Complex: impedance [Ω]

Theory

Converts a Resistance-Inductance Load, or a Resistance-Capacitance Load from power to circuit values, where the components are placed in parallel.

source
ElectricGrid.RampMethod
Ramp(final, μ, i; t_end = 0.02)

Description

Ramps up a signal.

Arguments

  • final: the final value.
  • μ: time step size [s].
  • i: time step.

Keyword Arguments

  • t_end: when the final value should be reached [s].
source
ElectricGrid.RenderHookResultsMethod
RenderHookResults(; hook,
                    states_to_plot = nothing,
                    actions_to_plot = nothing ,
                    episode = 1,
                    power_p_inv = [],
                    power_q_inv = [],
                    power_p_poc = [],
                    power_q_poc = [],
                    v_mag_inv   = [],
                    v_mag_poc   = [],
                    i_mag_inv   = [],
                    i_mag_poc   = [],
                    freq        = [],
                    angles      = [],
                    i_sat       = [],
                    i_err       = [],
                    i_err_t     = [],
                    v_sat       = [],
                    v_err       = [],
                    v_err_t     = [],
                    plot_reward = false,
                    plot_reference = false,
                    vdc_to_plot = [],)

Keyword Arguments

  • episode::Int: episode to plot
  • power_p_inv::Vector{Int}: instantaneous real power at the terminals of the source [W]
  • power_q_inv::Vector{Int}: instantaneousimaginary power at the terminals of the source [VAi]
  • power_p_poc::Vector{Int}: instantaneousreal power at the point of connection of the source [W]
  • power_q_poc::Vector{Int}: instantaneous imaginary power at the point of connection of the source [VAi]
  • v_mag_inv::Vector{Int}: scaled L₂ norm in αβγ coordinates of the 3 phase voltages at the terminals of the source [V]
  • v_mag_poc::Vector{Int}: scaled L₂ norm in αβγ coordinates of the 3 phase voltages at the node just after the first filter inductor and resistor of the source [V]
  • i_mag_inv::Vector{Int}: scaled L₂ norm in αβγ coordinates of the 3 phase currents at the terminals of the source [A]
  • i_mag_poc::Vector{Int}: scaled L₂ norm in αβγ coordinates of the 3 phase currents flowing into the external network of the source [A]
  • freq::Vector{Int}: angular velocity of the 3 phase voltages over the capacior nearest to the source [Hz]
  • angles::Vector{Int}: relative positive phase sequence angles of the 3 phase voltages at the control nodes (measured with respect to the average angle over all the grid-forming sources) [degrees]
  • i_sat::Vector{Int}: normalised and scaled L₂ norm in αβγ coordinates of the degree of nonlinearity (or anti-windup) of the current controller [V]
  • i_err::Vector{Int}: L₂ norm in αβγ coordinates of the current error signal (measured current subtracted from reference current in DQ0 coordinates) [A]
  • i_err_t::Vector{Int}: L₂ norm in αβγ coordinates of the integrated current error signal [As]
  • v_sat::Vector{Int}: normalised and scaled L₂ norm in αβγ coordinates of the degree of nonlinearity (or anti-windup) of the voltage controller [A]
  • v_err::Vector{Int}: L₂ norm in αβγ coordinates of the voltage error signal (measured voltage subtracted from reference voltage in DQ0 coordinates) [V]
  • v_err_t::Vector{Int}: L₂ norm in αβγ coordinates of the integrated voltage error signal [Vs]
  • return_plot::Bool: specifies whether the plot object should be returned.

Note

For quantities denoted by "...mag..." for balanced symmetrical networks in steady state this quantity equals the root-mean-square (rms) of the signal.

source
ElectricGrid.SetupAgentsFunction
SetupAgents(env, custom_agents)

Description

Initialises up the agents that will be controlling the electrical network. It depends on the control_type and mode in the parameter dict. Handles to connect the different controllers to the correcponding sources represended by there indices (for states and actions).

Arguments

  • env::ElectricGridEnv: mutable struct containing the environment.
  • custom_agents::Dict{Agent}: Dict of Agents. The key is used as name in the MultiController.

Return Values

  • Multi_Agent::MultiController: the struct containing the initialised agents
source
ElectricGrid.SimulateMethod

hook = Simulate(controllers, env, num_episodes = 1 hook=hook)

Description

Executed the given controllers in the environments for num_episodes. Fills thereby the hook. In case of RL agents deterministic actions are chosen, e.g., no action noise is used.

Arguments

  • controllers::MultiController: Contains controllers and agents
  • env::ElectricGridEnv: mutable struct containing the environment.
  • num_episodes::Int: Number of episodes simulated.
  • hook::DataHook: Stores the data to measure in a DataFrame.

Return Values

  • hook::DataHook: Measured data.
source
ElectricGrid.SourceInitialiserMethod
SourceInitialiser(env, Source, modes, source_indices)

Description

Initialises all of the sources with droop coefficients and proportional and integral gains.

source
ElectricGrid.StepModeMethod
StepMode(Source::ClassicalControls, num_source; t_end = 0.04)

Description

Open loop control. Produces 3 stepped signals.

source
ElectricGrid.SwingModeMethod
SwingMode(Source::ClassicalControls, num_source; t_end = 0.04)

Description

Open loop control. Produces 3 phase sinusoidal signals.

source
ElectricGrid.SynchronverterModeMethod
SynchronverterMode(Source::ClassicalControls, num_source; pq0_ref = [Source.P[num_source]; Source.Q[num_source]], t_end = 0.04, mode = 2)

Description

Wrapper for enhanced grid forming control.

source
ElectricGrid.VoltageControlModeMethod
VoltageControlMode(Source::ClassicalControls, num_source; t_end = 0.04)

Description

Closed loop voltage control with an inner current loop. Produces 3 phase sinusoidal voltage signals over the filter capacitor.

source
ElectricGrid.plot_rewardresultsMethod
plot_rewardresults(rewardresults = nothing)

# Description
Plots the rewards with time steps on the x-axis and std as a shadowed area around the curve.
Either `rewardresults` or `controllers` have to be defined.

# Keyword Arguments
- `rewardresults::Float64[]`: List containing the rewards for each timestep
- `controllers`: the controllers object returned by `SetupAgents`
source
ElectricGrid.ElectricGridEnvMethod
env(action)

Description

Basic function to interact with an RL agent or other controller. Takes the action and evolvs the system defined by the linear state-space system using that action.

Keyword Arguments

  • action::Vector: Action which is applied to the env. One per source per phase. Will be multiplied with vdc and can be interpreted as modulation index.
source
ElectricGrid.ElectricGridEnvMethod
ElectricGridEnv(...)

Description

Returns an environment consisting of an electrical power grid as control plant, which can interact via this interface with a reinforcement learing agent from https://juliareinforcementlearning.org/

Arguments

Keyword Arguments

  • maxsteps::Int: The number of time steps that the simulation is run.
  • ts::Float: Sampling time by which the environment is evolved per step.
  • action_space::Space: Defines the valide space per action.
  • state_space::Space: Defines the valide space per state. Default is [-1, 1] since the states of the env will be normalized.
  • prepare_action::function(env::ElectricGridEnv): Function to adjust, change, prepare the actions before they are applied to the env during a step(). Per default it returns the action without changes.
  • featurize::function(x:Vector, t:Float; env::ElectricGridEnv, name::String): Function to adjust the state before it is returned by the env. For example here reference values can be added to provide the to an RL agent or other feature engineering to improve the learning.
  • reward_function::function(env::ElectricGridEnv, name::String) ): Function to define the reward for a (named) policy. Return 0 per default.
  • CM::Matrix: Conectivity matrix to define the structure of the electric power grid (for more details see NodeConstructor).
  • num_sources::Int: Number of sources in the electric power grid.
  • num_loads::Int: Number of loads in the electric power grid.
  • parameter::Dict: Dictonary to define the parameter of the grid. Entries can be "grid", "source", "load", "cable". Here, e.g. the electric components are defined.
  • x0::Vector: Initial states which will be used in reset!().
  • t0::Float: Initial time where the env starts from simulating.
  • state_ids::Vector{String}: IDs of the states. Can be used for plotting or collecting trajectories during a simulation with the DataHook.
  • convert_state_to_cpu::Bool: Flag if the states are converted to cpu if calculated one gpu before
  • use_gpu::Bool: Flag if the simulation is done on gpu (if possible).
  • reward::Float: Reward which the action achieved, applied in the env.
  • action::Vector{Float}: Action which is applied to the env.
  • action_ids::Vector{String}: IDs of the actions. Can be used for plotting or collecting trajectories during a simulation with the DataHook.
  • state_action_delay::Int: Specifies the number of simulation steps it is delayed from giving an action to the env to when it is applied to the plant.
  • t_end::Float: Spezifies the end time of an episode. If defined it overwrites maxsteps.
  • verbosity::Int: Defines the level of how much information (warnings, info,...) is printed to the console (0 - nothing, 1 - warn, 2 - debug(warn, info,...)).
  • state_ids_RL::Vector{String}: State IDs which are given to RL agents.
  • action_ids_RL::Vector{String}: Action IDs which are given to RL agents.

Return Values

  • ElectricGridEnv::ElectricGridEnv: Environment an agent can interact with
source
ElectricGrid.MultiControllerMethod

MultiController(agents, action_ids)

Description

Constructs the MultiController providing different subfunctions mappen the correct env indices to the corresponding controllers and agents.

Arguments

  • agents::Dict(NamedPolicy, ids): Contains all the agents as named policys with there corresponding ids.
  • action_ids::Vector{String}: All env action indices.

Return Values

  • Multi_Agent::MultiController: the struct containing the initialised agents
source
ElectricGrid.NodeConstructorMethod
NodeConstructor(;
    num_sources,
    num_loads,
    CM = nothing,
    parameters = nothing,
    S2S_p = 0.1,
    S2L_p = 0.8,
    L2L_p = 0.3,
    ts = 10000,
    verbosity = 0
    )

Create a mutable struct NodeConstructor, which serves as a basis for the creation of an energy grid: num_sources corresponse to the amount of sources and num_loads is the amount of loads in the grid. CM is the connection matrix which indicates how the elements in the grid are connected to each other. To specify the elements of the net in more detail, values for the elements can be passed via parameters. If no connection matrix is entered, it can be generated automatically. S2S_p is the probability that a source is connected to another source and S2L_p is the probability that a source is connected to a load.

source
ElectricGrid.TD3PolicyMethod
TD3Policy(;kwargs...)

Keyword arguments

  • behavior_actor,
  • behavior_critic,
  • target_actor,
  • target_critic,
  • start_policy,
  • γ = 0.99f0,
  • ρ = 0.995f0,
  • batch_size = 32,
  • start_steps = 10000,
  • update_after = 1000,
  • update_freq = 50,
  • policy_freq = 2 # frequency in which the actor performs a gradient update_step and critic target is updated
  • target_act_limit = 1.0, # noise added to actor target
  • target_act_noise = 0.1, # noise added to actor target
  • act_limit = 1.0, # noise added when outputing action
  • act_noise = 0.1, # noise added when outputing action
  • update_step = 0,
  • rng = Random.default_rng(),
source