Documentation of UrbanFireXDT
Documentation of UrbanFireXDT
Loading...
Searching...
No Matches
Classes | Functions | Variables
pyconn Namespace Reference

Classes

struct  SimulationControlUnitState
 Represents the state of a single control unit during a simulation time step. More...
 
struct  SimulationEVState
 Represents the state of a single EV during a simulation time step. More...
 

Functions

void initialize_simulation (pybind11::dict args)
 Initializes and starts the simulation from Python.
 
unsigned long get_next_timestep_id ()
 Returns the timestep ID of the next time step.
 
bool simulation_finished ()
 Checks if the simulation reached its end.
 
SimulationControlUnitState getState (unsigned long controlUnitID)
 Retrieves the state of a control unit.
 
void sendCommands (unsigned long controlUnitID, pybind11::dict commands)
 Sends a control command to a given control unit.
 
void run_one_step ()
 Executes a single simulation time step.
 
void reset_simulation_to_start ()
 Resets the simulation and all internal states to the first time step.
 
void vacuum ()
 Cleans up the simulation, finished the working thread and releases resources.
 

Variables

std::thread g_sim_worker
 The worker thread for the simulation that is started by pyconn::initialize_simulation()
 
std::atomic< bool > g_sim_started {false}
 States if the working thread for the simulation has been started.
 
std::atomic< bool > g_sim_finished {false}
 States if the simulation has reached its final state (and cannot proceed anymore, or must be reseted to proceed)
 
std::atomic< bool > g_simulation_main_part_started
 Flag indicating whether the simulation has finished the SAC planning and addition.
 
std::atomic< bool > g_simulation_idling
 Flag indicating whether the simulation is currently idling or working.
 
std::mutex g_mtx_simulation
 Mutex protecting synchronization between the simulation thread and Python calls.
 
std::condition_variable g_cv_sim_state_update
 Condition variable to notify and to wait for changes in the simulation / python code state.
 
std::atomic< bool > g_next_step_requested
 Flag indicating that a new simulation step should be executed.
 
std::atomic< bool > g_worker_threads_shutdown_cmd {false}
 Flag indicating that all worker threads should shoutdown and the simulation should be finished. After that, no reset is possible anymore.
 
std::atomic< unsigned long > g_atomic_next_tsID
 Shared variable indicating the next time step ID to be executed when calling pyconn::run_one_step()
 
std::atomic< bool > g_restart_simulation {false}
 Flag indicating to restart the simulation after a reset of all internal states.
 
float expansion_matrix_rel_freq [16][16] = {0}
 Variable storing the expansion matrix with relative frequencies - if using as stand-alone simulation, this is placed inside main and no global variable.
 
unsigned long expansion_matrix_abs_freq [16][16] = {0}
 Variable storing the expansion matrix with absolute frequencies - if using as stand-alone simulation, this is placed inside main and no global variable.
 
unsigned long scenario_id
 Variable storing the selected scenario ID - if using as stand-alone simulation, this is placed inside main and no global variable.
 

Function Documentation

◆ get_next_timestep_id()

unsigned long pyconn::get_next_timestep_id ( )
inline

Returns the timestep ID of the next time step.

Returns
timestep ID of the next time step.

◆ getState()

SimulationControlUnitState pyconn::getState ( unsigned long  controlUnitID)
inline

Retrieves the state of a control unit.

Returns information about the simulated components associated with the given control unit ID.

Parameters
controlUnitIDThe external (public) ID of the control unit.
Returns
A SimulationControlUnitState struct containing the unit’s state.

◆ initialize_simulation()

void pyconn::initialize_simulation ( pybind11::dict  args)
inline

Initializes and starts the simulation from Python.

This function sets up the simulation environment based on a dictionary of options, equivalent to command line arguments used in the standalone executable. Supported options include:

  • "config" (string): Path to JSON configuration file (default: "../config/simulation_config.json")
  • "scenario" (unsigned long): Scenario ID (default: 1)
  • "n_threads" (unsigned int): Number of worker threads
  • "work-stealing" (bool): Enable/disable work stealing
  • "max-parallel-opti-vars" (unsigned long): Max. number of optimization vars processed in parallel
  • "stop-on-cc-err" (bool): Stop on optimization errors
  • "seed" (unsigned int): Seed for random number generation
  • "weekly-metrics" (string): "on"/"off" to enable weekly metrics
  • "cu-output", "st-output", "ccmd-output", "ev-output" (string): Output modes
  • "cu-output-selection" (string): Comma-separated list of control unit IDs for output selection
  • "suof" (unsigned long): Steps until output is flushed (default: 1000)
Parameters
argsA Python dictionary containing simulation options.
Exceptions
std::invalid_argumentIf invalid options are provided.
std::runtime_errorIf required files cannot be loaded or variables remain uninitialized.

◆ reset_simulation_to_start()

void pyconn::reset_simulation_to_start ( )
inline

Resets the simulation and all internal states to the first time step.

All information and collected metrics inside the control units are deleted.

◆ run_one_step()

void pyconn::run_one_step ( )
inline

Executes a single simulation time step.

Advances the simulation by one time step and halts once new control commands can be accepted from Python.

This function returns control back to Python once the step is complete and the system is ready for new interactions.

◆ sendCommands()

void pyconn::sendCommands ( unsigned long  controlUnitID,
pybind11::dict  commands 
)
inline

Sends a control command to a given control unit.

This function can be used from Python to override or inject control signals into the simulation during runtime at the level of the control units (see class ControlUnit for details).

Parameters
controlUnitIDThe external (public) ID of the control unit.
commandThe control value/command to be applied.

◆ simulation_finished()

bool pyconn::simulation_finished ( )
inline

Checks if the simulation reached its end.

If the simulation can proceed, the function run_one_step() can be executed.

Returns
True, if the simulation can proceed and false, if the simulation reached its final state.

◆ vacuum()

void pyconn::vacuum ( )
inline

Cleans up the simulation, finished the working thread and releases resources.

  • Saves cache files for PV/HP profiles
  • Releases all allocated static and dynamic simulation objects
  • Resets global variables
  • Joins the working thread

This function should be called once a simulation is finished.

Variable Documentation

◆ expansion_matrix_abs_freq

unsigned long pyconn::expansion_matrix_abs_freq[16][16] = {0}
inline

Variable storing the expansion matrix with absolute frequencies - if using as stand-alone simulation, this is placed inside main and no global variable.

◆ expansion_matrix_rel_freq

float pyconn::expansion_matrix_rel_freq[16][16] = {0}
inline

Variable storing the expansion matrix with relative frequencies - if using as stand-alone simulation, this is placed inside main and no global variable.

◆ g_atomic_next_tsID

std::atomic<unsigned long> pyconn::g_atomic_next_tsID
inline

Shared variable indicating the next time step ID to be executed when calling pyconn::run_one_step()

◆ g_cv_sim_state_update

std::condition_variable pyconn::g_cv_sim_state_update
inline

Condition variable to notify and to wait for changes in the simulation / python code state.

◆ g_mtx_simulation

std::mutex pyconn::g_mtx_simulation
inline

Mutex protecting synchronization between the simulation thread and Python calls.

◆ g_next_step_requested

std::atomic<bool> pyconn::g_next_step_requested
inline

Flag indicating that a new simulation step should be executed.

◆ g_restart_simulation

std::atomic<bool> pyconn::g_restart_simulation {false}
inline

Flag indicating to restart the simulation after a reset of all internal states.

◆ g_sim_finished

std::atomic<bool> pyconn::g_sim_finished {false}
inline

States if the simulation has reached its final state (and cannot proceed anymore, or must be reseted to proceed)

◆ g_sim_started

std::atomic<bool> pyconn::g_sim_started {false}
inline

States if the working thread for the simulation has been started.

◆ g_sim_worker

std::thread pyconn::g_sim_worker
inline

The worker thread for the simulation that is started by pyconn::initialize_simulation()

◆ g_simulation_idling

std::atomic<bool> pyconn::g_simulation_idling
inline

Flag indicating whether the simulation is currently idling or working.

◆ g_simulation_main_part_started

std::atomic<bool> pyconn::g_simulation_main_part_started
inline

Flag indicating whether the simulation has finished the SAC planning and addition.

◆ g_worker_threads_shutdown_cmd

std::atomic<bool> pyconn::g_worker_threads_shutdown_cmd {false}
inline

Flag indicating that all worker threads should shoutdown and the simulation should be finished. After that, no reset is possible anymore.

◆ scenario_id

unsigned long pyconn::scenario_id
inline

Variable storing the selected scenario ID - if using as stand-alone simulation, this is placed inside main and no global variable.