SimulationThread#
- class wattson.powergrid.simulator.threads.simulation_thread.SimulationThread(power_grid_model: PowerGridModel, *, iteration_required_event: Event | None = None, automatic_simulation_interval_seconds: float = 10, on_iteration_start_callback: Callable[[], None] | None = None, on_iteration_sync_callback: Callable[[bool], None] | None = None, on_iteration_completed_callback: Callable[[bool], None] | None = None, on_value_update_callback: Callable[[GridValue, Any, Any], None] | None = None, on_value_change_callback: Callable[[GridValue, Any, Any], None] | None = None, on_value_state_change_callback: Callable[[GridValue], None] | None = None, on_protection_equipment_triggered_callback: Callable[[GridElement, str], None] | None = None, on_protection_equipment_cleared_callback: Callable[[GridElement, str], None] | None = None, **kwargs)#
Bases:
Thread
This thread handles simulating the power grid, i.e., calculating the current grid state.
Methods
This constructor should always be called with keyword arguments.
The actual simulation calculation is done in a thread.
set_iteration_required
Start the thread's activity.
Requests stopping the simulation thread and joins the thread for the given timeout in seconds.
- __init__(power_grid_model: PowerGridModel, *, iteration_required_event: Event | None = None, automatic_simulation_interval_seconds: float = 10, on_iteration_start_callback: Callable[[], None] | None = None, on_iteration_sync_callback: Callable[[bool], None] | None = None, on_iteration_completed_callback: Callable[[bool], None] | None = None, on_value_update_callback: Callable[[GridValue, Any, Any], None] | None = None, on_value_change_callback: Callable[[GridValue, Any, Any], None] | None = None, on_value_state_change_callback: Callable[[GridValue], None] | None = None, on_protection_equipment_triggered_callback: Callable[[GridElement, str], None] | None = None, on_protection_equipment_cleared_callback: Callable[[GridElement, str], None] | None = None, **kwargs)#
This constructor should always be called with keyword arguments. Arguments are:
group should be None; reserved for future extension when a ThreadGroup class is implemented.
target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.
name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.
args is a list or tuple of arguments for the target invocation. Defaults to ().
kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.
If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.
- run() None #
The actual simulation calculation is done in a thread. :return:
- start(wait_for_event: Event | None = None)#
Start the thread’s activity.
It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.
This method will raise a RuntimeError if called more than once on the same thread object.
- stop(timeout: float | None = None)#
Requests stopping the simulation thread and joins the thread for the given timeout in seconds. After this method, is_alive() can be used to determine whether the thread actually stopped.
- Parameters:
timeout (Optional[float], optional) – The (optional) timeout for joining the thread. (Default value = None)