Simulator¶
The simulation loop, event scheduling and result recording.
Simulator
¶
Simulator(
ps,
dt=0.005,
solver=dps_sol.ModifiedEulerDAE,
t_end=np.inf,
log_fun=None,
ode_fun=None,
events=None,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ps
|
Initialized PowerSystemModel. |
required | |
events
|
Events to apply during the simulation, as a table (list with header row, or DataFrame) with columns t, category, model, unit, action, or t, event, unit. See EventSchedule. |
None
|
Source code in src/tops/simulator.py
EventSchedule
¶
Events to be applied at given times.
Events are given as a table (list with header row, or DataFrame) with columns t, category, model, unit, action, e.g. [0.1, 'lines', 'Line', 'L1-2', 'disconnect'] or [0.1, 'buses', '', 'B1', 'short_circuit']. The model column is ignored for category 'buses'. An optional column kwargs holds a dict of arguments for the action, or None, e.g. [0.1, 'buses', '', 'B1', 'short_circuit', {'y': 100}]; they are kept in the list kwargs, one per event.
Alternatively, the table has columns t, event, unit (and optionally kwargs), where event is an event function of the power system model, e.g. [0.1, ps.lines.Line.events.disconnect, 'L1-2'] or [0.1, ps.bus_events.short_circuit, 'B1']. Such events are kept as (t, event, unit).
Used by the Simulator, or directly in a custom simulation loop:
schedule = EventSchedule(events)
schedule.check(ps)
while t < t_end:
schedule.apply_due(ps, t)
...
Source code in src/tops/simulator.py
Events
¶
Events given as a list of (t, ('line', line_name, action)).
Kept for backwards compatibility. Events can instead be given to the Simulator (Simulator(ps, ..., events=...)).
Source code in src/tops/simulator.py
update
¶
Source code in src/tops/simulator.py
InterfacerDirect
¶
ResultKeeper
¶
Stores the states and algebraic variables at every step, and the outputs given as keyword arguments.
Add it as an interface function of the Simulator:
res = ResultKeeper(sim, speed=ps.gen.GEN.speed)
sim.interface_functions['results'] = res.update
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sim
|
The Simulator. Create the ResultKeeper before the simulation starts. |
required | |
kwargs
|
Functions f(x, v) to store at every step, e.g. ps.gen.GEN.speed. Kept in store[name]. |
{}
|
Source code in src/tops/simulator.py
update
¶
Source code in src/tops/simulator.py
calculate
¶
Calculate a function of the states and algebraic variables at every stored step, after the simulation.
The events of the Simulator are replayed, so that e.g. the current of a line is zero while it is disconnected. Changes made in other ways during the simulation (set_input, or ps.apply_event in an interface function) are not replayed. The model is left as it was before the call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fun
|
Function f(x, v), e.g. ps.gen.GEN.speed or ps.lines.Line.p_from. |
required |
Returns:
| Type | Description |
|---|---|
|
Array with one row per stored step and one column per unit. |