Skip to content

Events

Event definitions and their effects on the network. Scheduling in time is done by tops.simulator.EventSchedule.

Events: discrete changes to the power system during simulation (line switching, short circuits, etc.).

Events of a model are defined in a ModelEvents subclass, which is set as the model's events_class. Event methods may modify the model they belong to, but other parts of the system are only affected through the effects they return (e.g. AdmittanceChange), which are applied by PowerSystemModel.apply_effect.

Scheduling events in time is handled by tops.simulator.EventSchedule.

DeadBusWarning

Bases: RuntimeWarning

Buses have no admittance left (e.g. a bay node whose switches are all open), so they are pinned to 0 V.

Silence with warnings.filterwarnings('ignore', category=DeadBusWarning), or turn the pinning off with PowerSystemModel.pin_dead_buses = False.

AdmittanceChange

Bases: NamedTuple

Change in the reduced bus admittance matrix. Rows and columns are indices in the reduced system.

data instance-attribute

data

rows instance-attribute

rows

cols instance-attribute

cols

ModelEvents

ModelEvents(mdl)

Base class for the events of a model (or of the buses).

Event methods take the unit name (and possibly keyword arguments), and return a list of effects. Only methods listed in actions can be triggered by name (e.g. from an event table given to the Simulator).

Source code in src/tops/events.py
def __init__(self, mdl):
    self.mdl = mdl

actions class-attribute instance-attribute

actions = ()

mdl instance-attribute

mdl = mdl

unit_names

unit_names()
Source code in src/tops/events.py
def unit_names(self):
    return self.mdl.par['name']

apply

apply(unit, action, **kwargs)
Source code in src/tops/events.py
def apply(self, unit, action, **kwargs):
    self.check(unit, action)
    return getattr(self, action)(unit, **kwargs)

check

check(unit, action)
Source code in src/tops/events.py
def check(self, unit, action):
    if action not in self.actions:
        raise ValueError(f'{type(self).__name__} has no event "{action}". Available events: {self.actions}')
    self._unit_idx(unit)

BusEvents

BusEvents(bus_names, bus_idx_red)

Bases: ModelEvents

Events at buses: short circuits through a fixed fault admittance.

Source code in src/tops/events.py
def __init__(self, bus_names, bus_idx_red):
    super().__init__(mdl=None)
    self.reset(bus_names, bus_idx_red)

actions class-attribute instance-attribute

actions = ('short_circuit', 'clear_short_circuit')

reset

reset(bus_names, bus_idx_red)

Clear all faults, e.g. when the power system model is initialized again.

Source code in src/tops/events.py
def reset(self, bus_names, bus_idx_red):
    """Clear all faults, e.g. when the power system model is initialized again."""
    self.bus_names = bus_names
    self.bus_idx_red = bus_idx_red
    self.y_fault = np.zeros(len(bus_names), dtype=complex)

unit_names

unit_names()
Source code in src/tops/events.py
def unit_names(self):
    return self.bus_names

short_circuit

short_circuit(bus, y=1000000.0)
Source code in src/tops/events.py
def short_circuit(self, bus, y=1e6):
    idx = self._unit_idx(bus)
    if self.y_fault[idx] != 0:
        return []
    idx_red = self._bus_idx_red(bus)
    self.y_fault[idx] = y
    return [AdmittanceChange(np.array([y]), idx_red, idx_red)]

clear_short_circuit

clear_short_circuit(bus)
Source code in src/tops/events.py
def clear_short_circuit(self, bus):
    idx = self._unit_idx(bus)
    if self.y_fault[idx] == 0:
        return []
    idx_red = self._bus_idx_red(bus)
    y = self.y_fault[idx]
    self.y_fault[idx] = 0
    return [AdmittanceChange(np.array([-y]), idx_red, idx_red)]