Documentation of UrbanFireXDT
Documentation of UrbanFireXDT
Loading...
Searching...
No Matches
python_module.hpp
Go to the documentation of this file.
1
9#ifndef PYTHON_MODULE_HPP
10#define PYTHON_MODULE_HPP
11
12#include <atomic>
13#include <condition_variable>
14#include <mutex>
15#include <thread>
16
17#include <pybind11/pybind11.h>
18#include <pybind11/stl.h> // for converting C++ containers like std::map
19
20#include "cache_helper.hpp"
21#include "components.h"
22#include "global.h"
24#include "simulation_logic.h"
25#include "units.h"
26
27namespace pyconn {
35 double ev_soc;
36 double ev_soe;
37 double ev_maxP_kW;
39 std::vector<double> ev_future_max_power_kW;
40 std::vector<double> ev_future_max_consumption_kWh;
41 std::vector<double> ev_future_min_consumption_kWh;
42 // required energy until departure
43 };
52 unsigned long controlUnitID;
53 unsigned long internalID;
54 bool has_pv;
58 unsigned long timestepID;
59 // BS
60 double bs_soc;
61 double bs_soe;
62 double bs_maxP_kW;
64 // HP
67 std::vector<double> hp_future_max_power_kW;
68 std::vector<double> hp_future_min_power_kW;
69 std::vector<double> hp_future_max_consumption_kWh;
70 std::vector<double> hp_future_min_consumption_kWh;
71 //double hp_cumulative_energy_kWh;
72 // EVs
73 std::vector<SimulationEVState> ev_states;
74 unsigned long n_EVs;
75 // environmental data
77 float pv_kWp;
80 };
81
82 // ---------------------------
83 // Thread & shared state
84 // ---------------------------
85 inline std::thread g_sim_worker;
86 inline std::atomic<bool> g_sim_started{false};
87 inline std::atomic<bool> g_sim_finished{false};
88
89 inline std::atomic<bool> g_simulation_main_part_started;
90 inline std::atomic<bool> g_simulation_idling;
91 inline std::mutex g_mtx_simulation;
92 inline std::condition_variable g_cv_sim_state_update;
93 inline std::atomic<bool> g_next_step_requested;
94 inline std::atomic<bool> g_worker_threads_shutdown_cmd{false};
95 inline std::atomic<unsigned long> g_atomic_next_tsID;
96 inline std::atomic<bool> g_restart_simulation{false};
97 // keep these alive for the worker's entire lifetime
98 inline float expansion_matrix_rel_freq[16][16] = {0};
99 inline unsigned long expansion_matrix_abs_freq[16][16] = {0};
100 inline unsigned long scenario_id;
101
124 inline void initialize_simulation(pybind11::dict args) {
125 std::string config_filepath;
126
127 if (g_sim_started.load()) {
128 throw std::runtime_error("Simulation already running. Call vacuum() before re-initializing.");
129 }
130
131 // --------------------------
132 // Equivalent of command line parsing
133 // --------------------------
134
135 if (args.contains("config")) {
136 config_filepath = args["config"].cast<std::string>();
137 } else {
138 config_filepath = "../config/simulation_config.json";
139 }
140
141 if (args.contains("pvar")) {
142 //Global::set_pvar_vals(true, args["pvar"].cast<int>());
143 throw std::runtime_error("Parameter variations cannot be defined when using the python interface!");
144 } else {
145 Global::set_pvar_vals(false, 0);
146 }
147
148 if (args.contains("scenario")) {
149 scenario_id = args["scenario"].cast<unsigned long>();
150 } else {
151 scenario_id = 1;
152 }
153
154 if (args.contains("stop-on-cc-err") && args["stop-on-cc-err"].cast<bool>()) {
156 } else {
158 }
159
160 if (args.contains("n_threads")) {
161 unsigned int n_threads = args["n_threads"].cast<uint>();
162 Global::set_n_threads(n_threads);
163 if (n_threads == 1) {
164 std::cerr << "Warning: Defining only 1 working thread is useless.\n";
165 }
166 } else {
168 }
169
170 if (args.contains("work-stealing") && args["work-stealing"].cast<bool>()) {
172 }
173
174 if (args.contains("max-parallel-opti-vars")) {
175 unsigned long n_vars = args["max-parallel-opti-vars"].cast<unsigned long>();
177 }
178
179 if (args.contains("cu-output")) {
180 std::string cu_output = args["cu-output"].cast<std::string>();
181 if (cu_output == "no" || cu_output == "off") {
183 } else if (cu_output == "single") {
185 } else if (cu_output == "sl") {
187 } else {
188 throw std::invalid_argument("Invalid option for cu-output");
189 }
190 } else {
192 }
193
194 if (args.contains("st-output")) {
195 std::string st_output = args["st-output"].cast<std::string>();
196 if (st_output == "no" || st_output == "off") {
198 } else if (st_output == "on") {
200 } else {
201 throw std::invalid_argument("Invalid option for st-output");
202 }
203 } else {
205 }
206
207 if (args.contains("ccmd-output")) {
208 std::string val = args["ccmd-output"].cast<std::string>();
209 if (val == "no" || val == "off") {
211 } else if (val == "all" || val == "on") {
213 } else {
214 throw std::invalid_argument("Invalid option for ccmd-output");
215 }
216 } else {
218 }
219
220 if (args.contains("ev-output")) {
221 std::string val = args["ev-output"].cast<std::string>();
222 if (val == "no" || val == "off") {
224 } else if (val == "all") {
226 } else {
227 throw std::invalid_argument("Invalid option for ev-output");
228 }
229 } else {
231 }
232
233 if (args.contains("repetitions")) {
234 throw std::runtime_error("Repetitions cannot be defined when using the python interface");
235 } else {
237 }
238
239 if (args.contains("seed")) {
240 unsigned int seed = args["seed"].cast<unsigned int>();
241 Global::set_seed(seed);
242 EVFSM::SetSeed(seed);
243 }
244
245 if (args.contains("weekly-metrics")) {
246 std::string wm_mode = args["weekly-metrics"].cast<std::string>();
247 if (wm_mode == "off" || wm_mode == "no") {
249 } else if (wm_mode == "on" || wm_mode == "yes") {
251 } else {
252 throw std::invalid_argument("Invalid option for weekly-metrics");
253 }
254 }
255
256 if (args.contains("cu-output-selection")) {
257 std::string selected_CUs_str = args["cu-output-selection"].cast<std::string>();
258 std::stringstream strstr(selected_CUs_str);
259 std::string token;
260 while (std::getline(strstr, token, ',')) {
261 try {
262 global::unitIDs_selected_for_output.push_back(std::stoul(token));
263 } catch (...) {
264 throw std::invalid_argument("Invalid cu-output-selection token: " + token);
265 }
266 }
267 }
268
269 // Flush interval
270 if (args.contains("suof")) {
271 global::n_ts_between_flushs = args["suof"].cast<unsigned long>();
272 } else {
274 }
275
276 std::cout << "Initializing the simulation for scenario ID " << scenario_id << std::endl;
277
278 // Initialize statics
280
281 // Load configuration
282 if (!configld::load_config_file(scenario_id, config_filepath)) {
283 throw std::runtime_error("Error loading config file.");
284 }
286 throw std::runtime_error("Error loading expansion matrix.");
287 }
289 throw std::runtime_error("Invalid expansion matrix.");
290 }
291
294
296 throw std::runtime_error("Error loading database.");
297 }
298
300 std::cerr << "\nThese variables are NOT initialized:" << std::endl;
303 std::cerr << "" << std::endl;
304 throw std::runtime_error("Some global variables are not initialized!");
305 }
306
308
309 // ---------------------------
310 // Launch the simulation worker thread
311 // ---------------------------
312 g_sim_started.store(true);
313 g_sim_finished.store(false);
314 g_simulation_idling = false;
315 g_next_step_requested = false; // stop before executing first step
316 g_simulation_main_part_started = false; // for SAC planning, no interactive mode is given -> sim. should not wait there!
317 g_restart_simulation = false;
318
319 g_sim_worker = std::thread([](){
320 try {
321 const bool retval = simulation::runCompleteSimulation(
325 );
326 if (!retval) {
327 // Throwing an error kills all other processes
328 throw std::runtime_error("Error during simulation run!");
329 }
330 } catch (const std::exception& e) {
331 std::cerr << "Exception in simulation worker: " << e.what() << std::endl;
332 } catch (...) {
333 std::cerr << "Unknown exception in simulation worker." << std::endl;
334 }
335 });
336 }
337
343 inline unsigned long get_next_timestep_id() {
344 if (!g_sim_started) {
345 throw std::runtime_error("Error: Simulation has not been started!");
346 }
347
348 return g_atomic_next_tsID;
349 }
350
358 inline bool simulation_finished() {
359 // Fast path: if already finished, return immediately
360 if (g_sim_finished.load()) return true;
361 // Otherwise wait until the sim is no longer idling (or it finishes while waiting)
362 std::unique_lock<std::mutex> lock_obj(g_mtx_simulation);
363 g_cv_sim_state_update.wait(lock_obj, [] {
364 return !g_next_step_requested.load() && ( g_simulation_idling.load() || g_sim_finished.load() );
365 });
366 return g_sim_finished.load();
367 }
368
378 inline SimulationControlUnitState getState(unsigned long controlUnitID) {
379 // Wait until simulation is idling (or finished)
380 std::unique_lock<std::mutex> lock_obj(g_mtx_simulation);
381 g_cv_sim_state_update.wait(lock_obj, [] {
382 return g_simulation_idling.load() || g_sim_finished.load();
383 });
384
386 ControlUnit* cu = ControlUnit::GetInstancePublicIDWE( controlUnitID );
387 // No check for validity of the pointer `cu` required, as otherwise an exception is thrown
388 s.controlUnitID = controlUnitID;
389 s.internalID = cu->get_internal_id();
390 s.has_pv = cu->has_pv();
391 s.has_cntrl_bs = cu->has_bs();
392 s.has_cntrl_hp = cu->has_hp();
393 s.has_cntrl_evchst = cu->has_cs();
394 s.timestepID = get_next_timestep_id();
395 // BS
396 s.bs_soc = cu->has_bs() ? cu->get_component_BS()->get_SOC() : 0.0; // State of Charge BS
397 s.bs_soe = cu->has_bs() ? cu->get_component_BS()->get_SOE() : 0.0; // State of Energy BS
398 s.bs_maxP_kW = cu->has_bs() ? cu->get_component_BS()->get_maxP_kW() : 0.0; // Max possible charging/discharging power
399 s.bs_maxE_kWh = cu->has_bs() ? cu->get_component_BS()->get_maxE_kWh() : 0.0; // Max possible energy capacity
400 // HP
401 s.hp_rated_power_kW = cu->has_hp() ? cu->get_component_HP()->get_rated_power_without_AUX() : 0.0; // Rated power of the heat pump in kW
402 s.hp_current_demand_kW = cu->has_hp() ? cu->get_component_HP()->get_currentDemand_kW() : 0.0; // Current demand of the heat pump in kW
403 s.hp_future_max_power_kW = cu->has_hp() ? *cu->get_component_HP()->get_future_max_power_kW() : std::vector<double>{};
404 s.hp_future_min_power_kW = cu->has_hp() ? *cu->get_component_HP()->get_future_min_power_kW() : std::vector<double>{};
405 s.hp_future_max_consumption_kWh = cu->has_hp() ? *cu->get_component_HP()->get_future_max_consumption_kWh() : std::vector<double>{};
406 s.hp_future_min_consumption_kWh = cu->has_hp() ? *cu->get_component_HP()->get_future_min_consumption_kWh() : std::vector<double>{};
407 //s.hp_cumulative_energy_kWh = cu->has_hp() ? cu->get_component_HP()->get_total_consumption_kWh() : -1.0; //TODO: subtract actual demand
408 // EVs
409 s.ev_states.clear();
410 if (cu->has_cs()) {
411 const ComponentCS* cs = cu->get_component_CS();
412 const std::vector<const EVFSM*>& ev_list = cs->get_listOfEVs();
413
414 for (size_t i = 0; i < 3; ++i) { // 3 EVs
415 SimulationEVState ev_state_struct{};
416
417 if (i < ev_list.size()) {
418 const EVFSM* ev = ev_list[i];
419
420 ev_state_struct.ev_state = ev->get_current_state();
421 ev_state_struct.ev_current_demand_kW = ev->get_currentDemand_kW();
422
423 // SOC / SOE
424 const ComponentBS* battery = ev->get_battery();
425 ev_state_struct.ev_soc = battery ? battery->get_SOC() : 0.0;
426 ev_state_struct.ev_soe = battery ? battery->get_SOE() : 0.0;
427 ev_state_struct.ev_maxP_kW = battery ? battery->get_maxP_kW() : 0.0;
428 ev_state_struct.ev_maxE_kWh = battery ? battery->get_maxE_kWh() : 0.0;
429 // Future power / energy
430 ev_state_struct.ev_future_max_power_kW = *ev->get_future_max_power_kW();
431 ev_state_struct.ev_future_max_consumption_kWh = *ev->get_future_max_consumption_kWh();
432 ev_state_struct.ev_future_min_consumption_kWh = *ev->get_future_min_consumption_kWh();
433 } else {
434 // If there is no EV, leave default values
435 }
436 s.ev_states.push_back(ev_state_struct);
437 }
438 }
439 s.n_EVs = cu->has_cs() ? cu->get_component_CS()->get_n_EVs() : 0;
440 // environmental data
441 s.pv_currentGeneration_kW = cu->get_component_PV() != NULL ? cu->get_component_PV()->get_currentGeneration_kW() : 0.0;
442 s.pv_kWp = cu->get_component_PV() != NULL ? cu->get_component_PV()->get_kWp() : 0.0;
443 s.household_demand = cu->get_current_demand_wo_BS_or_gen_kW();
445 s.electricity_price = global::eprices_local_ts[g_atomic_next_tsID - 1];
446 } else {
447 s.electricity_price = Global::get_demand_tariff();
448 }
449 return s;
450 }
451
463 inline void sendCommands(unsigned long controlUnitID, pybind11::dict commands) {
464 if (!g_sim_started) {
465 throw std::runtime_error("Error: Simulation has not been started!");
466 }
467
468 // Wait until simulation is idling (or finished)
469 std::unique_lock<std::mutex> lock_obj(g_mtx_simulation);
470 g_cv_sim_state_update.wait(lock_obj, [] {
471 return !g_next_step_requested.load() && ( g_simulation_idling.load() || g_sim_finished.load() );
472 });
473
474 ControlUnit* cu = ControlUnit::GetInstancePublicIDWE( controlUnitID );
475 // process the commands
476 double p_bs_kW = 0.0;
477 double p_hp_kW = 0.0;
478 std::vector<double> p_ev_kW;
479 if (commands.contains("p_bs_kW")) {
480 p_bs_kW = commands["p_bs_kW"].cast<double>();
481 }
482 if (commands.contains("p_hp_kW")) {
483 p_hp_kW = commands["p_hp_kW"].cast<double>();
484 }
485 if (commands.contains("p_ev_kW")) {
486 p_ev_kW = commands["p_ev_kW"].cast<std::vector<double>>();
487 }
488
489 // send commands to the control unit
490 cu->send_control_commands_from_py_interface(p_bs_kW, p_hp_kW, p_ev_kW);
491 }
492
502 inline void run_one_step() {
503 //std::cout << " 1) [ID = " << g_atomic_next_tsID << "] g_simulation_idling = " << g_simulation_idling << " -- g_sim_finished = " << g_sim_finished.load() << std::endl;
504 if (!g_sim_started) {
505 throw std::runtime_error("Error: Simulation has not been started!");
506 }
507 if (g_sim_finished) {
508 throw std::runtime_error("Error: Simulation already finished!");
509 }
510
511 {
512 std::unique_lock<std::mutex> lock_obj(pyconn::g_mtx_simulation);
513 // Wait until the simulation consumed the flag (set it back to false)
514 g_cv_sim_state_update.wait(lock_obj, [] {
515 return g_simulation_idling.load() || g_sim_finished.load();
516 });
517 // update flag and notify all
519 lock_obj.unlock();
520 g_cv_sim_state_update.notify_all();
521 lock_obj.lock();
522 // Wait (again) until the simulation consumed the flag (set it back to false)
523 // only required by this function as it blocks until the simulation step is finished
524 g_cv_sim_state_update.wait(lock_obj, [] {
525 return !g_next_step_requested.load() && ( g_simulation_idling.load() || g_sim_finished.load() );
526 });
527 }
528 //std::cout << " 2) [ID = " << g_atomic_next_tsID << "] g_simulation_idling = " << g_simulation_idling << " -- g_sim_finished = " << g_sim_finished.load() << std::endl;
529 }
530
537 if (!g_sim_started) {
538 throw std::runtime_error("Error: Simulation has not been started!");
539 }
540
541 {
542 // Wait until simulation is idling (or finished)
543 std::unique_lock<std::mutex> lock_obj(g_mtx_simulation);
544 g_cv_sim_state_update.wait(lock_obj, [] {
545 return g_simulation_idling.load() || g_sim_finished.load();
546 });
547
549 g_sim_finished = false;
550 g_simulation_idling = false;
552 }
553 g_cv_sim_state_update.notify_all();
554 }
555
566 inline void vacuum() {
567 if (!g_sim_started) {
568 throw std::runtime_error("Error: Simulation has not been started!");
569 }
570 if (!g_sim_finished) {
571 throw std::runtime_error("Error: Simulation has not been finished!");
572 }
573
574 // Send shutdown command
577
578 // Join worker thread if still running
579 if (g_sim_worker.joinable()) {
580 try {
581 g_sim_worker.join();
582 } catch (...) {
583 // avoid throwing from vacuum; just ensure join attempt
584 }
585 }
586
587 // cleanup like in main()
597
598 g_sim_started.store(false);
599 g_sim_finished.store(false);
600 }
601
602}
603
604#endif
Definition components.h:188
double get_maxP_kW() const
Returns the maximum available capacity of the battery. For the current power, see ComponentBS::get_cu...
Definition components.h:200
double get_SOC() const
Returns the current state of charge of the battery.
Definition components.h:194
double get_maxE_kWh() const
Returns the maximum available capacity of the battery. For the current state of energy / charge,...
Definition components.h:199
double get_SOE() const
Returns the current amount of energy stored in the battery. Equivalent to ComponentBS::get_currentCha...
Definition components.h:195
Definition components.h:337
std::vector< const EVFSM * > get_listOfEVs() const
Returns a reference to the internal list of EVs.
Definition components.h:352
unsigned long get_n_EVs() const
Returns the number of connected EVs if the component is enabled, otherwise 0 is returned.
Definition components.cpp:843
float get_rated_power_without_AUX() const
Definition components.h:264
static void VacuumStaticVariables()
Definition components.cpp:786
const std::vector< double > * get_future_max_consumption_kWh() const
Definition components.h:63
const std::vector< double > * get_future_min_power_kW() const
Definition components.h:281
const std::vector< double > * get_future_min_consumption_kWh() const
Definition components.h:73
const std::vector< double > * get_future_max_power_kW() const
Definition components.h:274
double get_currentDemand_kW() const
Definition components.h:252
double get_kWp() const
Returns the total peak power, summed over all sections. See also ComponentPV::get_kWp_per_section().
Definition components.h:141
float get_currentGeneration_kW() const
Definition components.h:142
Definition units.h:162
const ComponentHP * get_component_HP() const
Returns a pointer to heat pump component, or nullptr if no such component is added.
Definition units.h:231
bool has_cs() const
Returns true, if the unit has an EV charging station connected (in data or simulated)
Definition units.cpp:345
double get_current_demand_wo_BS_or_gen_kW() const
Returns the current local demand of all components excluding the BESS and also not considering the lo...
Definition units.h:199
const ComponentPV * get_component_PV() const
Returns a pointer to PV component, or nullptr if no such component is added.
Definition units.h:233
bool has_bs() const
Returns true, if the control unit has a battery storage system attachted (in data or simulated).
Definition units.cpp:325
bool has_hp() const
Returns true, if the control unit has a heat pump attachted (in data or simulated).
Definition units.cpp:335
size_t get_internal_id() const
Returns the (consecutive) internal ID of the control unit.
Definition units.h:212
static ControlUnit * GetInstancePublicIDWE(unsigned long unitID)
Returns instance with a public unitID. Throws an error, if untiID is not defined.
Definition units.cpp:1597
static void ResetAllInternalStates()
Definition units.cpp:1616
const ComponentCS * get_component_CS() const
Returns a pointer to EV charging station component, or nullptr if no such component is added.
Definition units.h:232
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:1567
bool has_pv() const
Returns true, if the control unit has a PV attachted (in data or simulated).
Definition units.cpp:315
const ComponentBS * get_component_BS() const
Returns a pointer to battery storage component, or nullptr if no such component is added.
Definition units.h:230
Definition components.h:431
static void SetSeed(unsigned int seed)
Sets the seed for the EVFSM-class random number generator.
Definition components.cpp:1489
const std::vector< double > * get_future_max_consumption_kWh() const
Definition components.h:63
EVState get_current_state() const
Definition components.h:437
const ComponentBS * get_battery() const
Returns a reference to the battery component of the EV.
Definition components.h:445
const std::vector< double > * get_future_max_power_kW() const
Returns the maximum power of this EV per time step in the controller horizon. Attention: Returned obj...
Definition components.h:442
const std::vector< double > * get_future_min_consumption_kWh() const
Definition components.h:73
static void VacuumStaticVariables()
Definition components.cpp:1485
double get_currentDemand_kW() const
Gets the current charging power in kW; Only valid after calling EVFSM::setDemandToProfileData() or EV...
Definition components.h:443
static void set_compute_weekly_metrics(bool mode)
Definition global.cpp:560
static bool get_use_prices_time_series_ia()
Return weather the electricity prices time series (if it is available in the data) should be used or ...
Definition global.h:286
static void set_repetitions_selected(bool value)
Definition global.cpp:576
static bool AllVariablesInitialized()
Definition global.cpp:260
static void set_stop_on_cc_err(bool value)
Definition global.cpp:607
static const std::string & get_structure_database_name()
Definition global.h:293
static void set_max_parallel_opti_vars(unsigned long value)
Definition global.cpp:1219
static void set_output_mode_per_cu(global::OutputModePerCU mode)
Definition global.cpp:1156
static void InitializeStaticVariables()
Definition global.cpp:247
static float get_demand_tariff()
Definition global.h:266
static void set_pvar_vals(bool pvar_set, int pvarID)
Definition global.cpp:567
static void set_n_threads(unsigned int value)
Definition global.cpp:592
static void DeleteStaticVariables()
Definition global.cpp:251
static void set_create_substation_output(bool value)
Definition global.cpp:1244
static const std::string & get_input_path()
Definition global.h:291
static const std::string & get_cache_dir_path()
Returns the path for the cache directory - it this was NOT set, it will return the default value whic...
Definition global.h:295
static void set_create_control_cmd_output(bool value)
Definition global.cpp:1251
static void set_work_stealing(bool value)
Definition global.cpp:600
static void set_create_ev_detailed_output(bool value)
Definition global.cpp:1258
static void set_seed(unsigned int value)
Definition global.cpp:552
static void PrintUninitializedVariables()
Prints all variable names to stdout, that are not initialized.
Definition global.cpp:355
static HPProfileIDCache & GetInstance()
Definition cache_helper.hpp:39
void setCacheFilename(const std::string &filename)
Definition cache_helper.hpp:47
void saveCacheFile()
Definition cache_helper.hpp:77
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:1912
void setCacheFilename(const std::string &filename)
Definition cache_helper.hpp:187
static PVProfileIDCache & GetInstance()
Definition cache_helper.hpp:179
void saveCacheFile()
Definition cache_helper.hpp:221
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:146
bool load_config_file(unsigned long scenario_id, std::string &filepath)
Load the config file, that is passed as command line argument.
bool load_data_from_central_database(const char *filepath)
Load the complete simulation structure from the central database, and also load the recorded time ser...
Definition setup_and_dataloading.cpp:1247
void output_variable_values(std::ostream &current_outstream)
Outputs the current simulation configuration and all parameter settings to the specified output strea...
Definition setup_and_dataloading.cpp:1693
bool load_expansion_matrix(float expansion_matrix[16][16])
Definition sac_planning.cpp:164
bool verify_expansion_matrix(float expansion_matrix[16][16])
Definition sac_planning.cpp:219
unsigned long n_ts_between_flushs
Number of timesteps between the flush of the output buffers.
Definition global.h:53
void print_uninitialized_variables()
Prints all variable names to stdout, that are not initialized.
Definition global.cpp:69
bool all_variables_initialized()
Checks if all variables are initialized.
Definition global.cpp:14
void vacuum()
Deletes all global variables in the end.
Definition global.cpp:30
const float * eprices_local_ts
Reference to the time series of the energy prices (for residential customers) for grid demanded energ...
Definition global.h:60
std::vector< unsigned long > unitIDs_selected_for_output
A vector containing a list of all unitIDs selected for output. If this vector is empty (as it is by d...
Definition global.h:62
Definition python_module.hpp:27
void vacuum()
Cleans up the simulation, finished the working thread and releases resources.
Definition python_module.hpp:566
std::atomic< bool > g_next_step_requested
Flag indicating that a new simulation step should be executed.
Definition python_module.hpp:93
std::atomic< bool > g_simulation_idling
Flag indicating whether the simulation is currently idling or working.
Definition python_module.hpp:90
unsigned long expansion_matrix_abs_freq[16][16]
Variable storing the expansion matrix with absolute frequencies - if using as stand-alone simulation,...
Definition python_module.hpp:99
void initialize_simulation(pybind11::dict args)
Initializes and starts the simulation from Python.
Definition python_module.hpp:124
void sendCommands(unsigned long controlUnitID, pybind11::dict commands)
Sends a control command to a given control unit.
Definition python_module.hpp:463
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()
Definition python_module.hpp:95
std::atomic< bool > g_sim_started
States if the working thread for the simulation has been started.
Definition python_module.hpp:86
std::atomic< bool > g_simulation_main_part_started
Flag indicating whether the simulation has finished the SAC planning and addition.
Definition python_module.hpp:89
void run_one_step()
Executes a single simulation time step.
Definition python_module.hpp:502
unsigned long scenario_id
Variable storing the selected scenario ID - if using as stand-alone simulation, this is placed inside...
Definition python_module.hpp:100
SimulationControlUnitState getState(unsigned long controlUnitID)
Retrieves the state of a control unit.
Definition python_module.hpp:378
std::atomic< bool > g_restart_simulation
Flag indicating to restart the simulation after a reset of all internal states.
Definition python_module.hpp:96
bool simulation_finished()
Checks if the simulation reached its end.
Definition python_module.hpp:358
std::mutex g_mtx_simulation
Mutex protecting synchronization between the simulation thread and Python calls.
Definition python_module.hpp:91
std::condition_variable g_cv_sim_state_update
Condition variable to notify and to wait for changes in the simulation / python code state.
Definition python_module.hpp:92
unsigned long get_next_timestep_id()
Returns the timestep ID of the next time step.
Definition python_module.hpp:343
float expansion_matrix_rel_freq[16][16]
Variable storing the expansion matrix with relative frequencies - if using as stand-alone simulation,...
Definition python_module.hpp:98
void reset_simulation_to_start()
Resets the simulation and all internal states to the first time step.
Definition python_module.hpp:536
std::thread g_sim_worker
The worker thread for the simulation that is started by pyconn::initialize_simulation()
Definition python_module.hpp:85
std::atomic< bool > g_worker_threads_shutdown_cmd
Flag indicating that all worker threads should shoutdown and the simulation should be finished....
Definition python_module.hpp:94
std::atomic< bool > g_sim_finished
States if the simulation has reached its final state (and cannot proceed anymore, or must be reseted ...
Definition python_module.hpp:87
bool runCompleteSimulation(float expansion_matrix_rel_freq[16][16], unsigned long expansion_matrix_abs_freq[16][16], const unsigned long scenario_id)
Definition simulation_logic.cpp:471
Represents the state of a single control unit during a simulation time step.
Definition python_module.hpp:51
std::vector< double > hp_future_min_consumption_kWh
Definition python_module.hpp:70
unsigned long internalID
Definition python_module.hpp:53
std::vector< SimulationEVState > ev_states
Definition python_module.hpp:73
double bs_soc
Definition python_module.hpp:60
bool has_cntrl_bs
Definition python_module.hpp:55
unsigned long timestepID
Definition python_module.hpp:58
unsigned long controlUnitID
Definition python_module.hpp:52
float pv_currentGeneration_kW
Definition python_module.hpp:76
double household_demand
Definition python_module.hpp:78
float hp_rated_power_kW
Definition python_module.hpp:65
unsigned long n_EVs
Definition python_module.hpp:74
double electricity_price
Definition python_module.hpp:79
float pv_kWp
Definition python_module.hpp:77
double bs_soe
Definition python_module.hpp:61
double bs_maxE_kWh
Definition python_module.hpp:63
bool has_pv
Definition python_module.hpp:54
std::vector< double > hp_future_max_consumption_kWh
Definition python_module.hpp:69
bool has_cntrl_evchst
Definition python_module.hpp:57
bool has_cntrl_hp
Definition python_module.hpp:56
double bs_maxP_kW
Definition python_module.hpp:62
std::vector< double > hp_future_max_power_kW
Definition python_module.hpp:67
std::vector< double > hp_future_min_power_kW
Definition python_module.hpp:68
double hp_current_demand_kW
Definition python_module.hpp:66
Represents the state of a single EV during a simulation time step.
Definition python_module.hpp:32
double ev_maxE_kWh
Definition python_module.hpp:38
std::vector< double > ev_future_min_consumption_kWh
Definition python_module.hpp:41
double ev_current_demand_kW
Definition python_module.hpp:34
std::vector< double > ev_future_max_power_kW
Definition python_module.hpp:39
double ev_soc
Definition python_module.hpp:35
std::vector< double > ev_future_max_consumption_kWh
Definition python_module.hpp:40
double ev_soe
Definition python_module.hpp:36
double ev_maxP_kW
Definition python_module.hpp:37
EVState ev_state
Definition python_module.hpp:33
EVState
Definition vehicles.h:42