15#include <condition_variable>
40template<
class Derived>
56 Derived::InitializeStaticVariables(n);
68 Derived::VacuumInstancesAndStaticVariables();
85 Substation(
unsigned long internal_id,
unsigned long public_id, std::string* name);
90 unsigned long get_id()
const {
return public_id; }
91 const std::string *
get_name()
const {
return name; }
125 const unsigned long internal_id;
126 const unsigned long public_id;
127 const std::string *
const name;
129 std::list<ControlUnit*>* connected_units;
131 double resident_load;
132 double resident_demand;
135 double total_BESS_demand;
136 double pv_gen_total_kW;
137 double bs_gen_total_kW;
138 double chp_gen_total_kW;
139 double wind_gen_total_kW;
140 double unknown_gen_total_kW;
141 double pv_gen_expo_kW;
142 double bs_gen_expo_kW;
143 double chp_gen_expo_kW;
144 double wind_gen_expo_kW;
145 double unknown_gen_expo_kW;
149 static unsigned long st__n_substations;
151 static std::vector<Substation*> st__substation_list;
152 static std::map<unsigned long, unsigned long> public_to_internal_id;
168 static bool InstantiateNewControlUnit(
unsigned long unitID,
unsigned long substation_id,
unsigned long locationID,
bool residential,
unsigned int n_flats);
179 ControlUnit(
unsigned long internalID,
unsigned long publicID,
unsigned long substation_id,
unsigned long locationID,
bool residential,
unsigned int n_flats);
241 void add_ev(
unsigned long carID);
245 void set_exp_pv_params_B(
float kWp_per_m2,
float min_kWp_sec,
float max_kWp_sec,
float max_kWp_unit);
256 void send_control_commands_from_py_interface(
double p_bs_kW,
double p_hp_kW,
const std::vector<double>& p_ev_kW);
286 const unsigned long internal_id;
287 const unsigned long unitID;
289 const unsigned long locationID;
290 const bool residential;
291 const bool generate_output_for_this_unit;
293 std::list<MeasurementUnit*>* connected_units;
305 bool py_control_commands_obtained;
306 double py_cmd_p_bs_kW;
307 double py_cmd_p_hp_kW;
308 std::vector<double> py_cmd_p_ev_kW;
311 double sum_of_consumption_kWh;
312 double sum_of_self_cons_kWh;
313 double sum_of_mu_cons_kWh;
314 double sum_of_feed_into_grid_kWh;
315 double sum_of_grid_demand_kWh;
316 double sum_of_rem_pow_costs_EUR;
317 double sum_of_saved_pow_costs_EUR;
318 double sum_of_feedin_revenue_EUR;
319 double sum_of_emissions_cbgd_kg_CO2eq;
320 double sum_of_emissions_avoi_kg_CO2eq;
321 unsigned long sum_of_errors_in_cntrl;
322 unsigned long sum_of_errors_in_cntrl_cmd_appl;
324 double peak_grid_demand_kW;
326 double sum_of_cweek_consumption_kWh;
327 double sum_of_cweek_self_cons_kWh;
328 double sum_of_cweek_mu_cons_kWh;
329 double sum_of_cweek_feed_into_grid_kWh;
330 double sum_of_cweek_grid_demand_kWh;
331 double sum_of_cweek_rem_pow_costs_EUR;
332 double sum_of_cweek_saved_pow_costs_EUR;
333 double sum_of_cweek_feedin_revenue_EUR;
334 double sum_of_cweek_emissions_cbgd_kg_CO2eq;
335 double sum_of_cweek_emissions_avoi_kg_CO2eq;
336 unsigned long sum_of_cweek_errors_in_cntrl;
337 unsigned long sum_of_cweek_errors_in_cntrl_cmd_appl;
339 double cweek_peak_grid_demand_kW;
341 unsigned long ts_since_last_opti_run;
344 double current_load_vSM_kW;
345 double self_produced_load_kW;
346 double current_total_consumption_kW;
347 double current_PV_feedin_to_grid_kW;
348 double current_BS_feedin_to_grid_kW;
349 double current_CHP_feedin_to_grid_kW;
350 double current_wind_feedin_to_grid_kW;
351 double current_unknown_feedin_to_grid_kW;
353 bool is_expandable_with_pv_cache;
354 bool is_expandable_with_pv_cache_computed;
355 bool is_expandable_with_hp_cache;
356 bool is_expandable_with_hp_cache_computed;
365 static unsigned long st__n_CUs;
366 static std::vector<ControlUnit*> st__cu_list;
367 static std::map<unsigned long, unsigned long> public_to_internal_id;
368 static std::vector<double>* st__empty_vector_for_time_horizon;
371 static std::atomic<unsigned long> optimization_call_counter;
372 static std::atomic<unsigned long> n_curr_optimization_vars;
373 static std::mutex n_curr_optimization_vars_mutex;
374 static std::condition_variable curr_opti_cv;
395 bool has_chp,
const std::string& data_source_path);
398 MeasurementUnit(
size_t internalID,
size_t meUID,
size_t public_unitID, std::string * meterPointName,
size_t locID,
401 bool has_chp,
const std::string& data_source_path);
411 bool has_pv()
const {
return rsm_with_pv_residential || rsm_with_pv_open_space; }
414 bool has_bs()
const {
return rsm_with_bess;}
415 bool has_hp()
const {
return rsm_with_hp; }
464 const unsigned long internal_id;
465 const unsigned long meUID;
467 const std::string *
const meterPointName;
468 const unsigned long locationID;
469 const std::string data_source_path;
471 float current_load_rsm_kW;
474 bool rsm_with_pv_residential;
475 bool rsm_with_pv_open_space;
478 bool rsm_with_evchst;
481 int expansion_combination;
484 int* data_timestepID;
485 float* data_value_demand;
486 float* data_value_feedin;
491 static size_t st__n_MUs;
492 static std::vector<MeasurementUnit*> st__mu_list;
493 static std::map<unsigned long, unsigned long> public_to_internal_id;
512 const float* profile_data;
514 float current_feedin_kW;
Definition optimization_unit_general.hpp:16
static void VacuumInstancesAndStaticVariables()
Clean up all instances and static variables of the derived class.
Definition units.h:67
static void InitializeStaticVariables(unsigned long n)
Initialize the number of instances for the derived class that must be known when simulation is starte...
Definition units.h:55
Definition worker_threads.hpp:108
Definition components.h:188
Definition components.h:337
Definition components.h:247
Definition components.h:136
~ControlUnit()
Definition units.cpp:293
void preprocess_ev_data()
Preprocesses EV data, calls EVFSM::preprocessTourInformation() for all attached EVs....
Definition units.cpp:881
size_t get_sim_comp_cs_possible_n_EVs() const
Returns the number of EVs that would be connected to the charging station component,...
Definition units.cpp:575
void set_exp_bs_maxE_kWh(float value)
Definition units.cpp:920
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
string * get_metrics_string_annual()
Definition units.cpp:618
void set_exp_bs_E_P_ratio(float value)
Definition units.cpp:930
double get_current_BS_demand_kW() const
Returns the current BESS (charging) demand in kW.
Definition units.cpp:464
double get_current_BS_generation_kW() const
Returns the current local BS generation (regardless of self-consumption), always greater or equal to ...
Definition units.cpp:480
static const std::vector< ControlUnit * > & GetArrayOfInstances()
Definition units.h:268
void remove_sim_added_pv()
Removes a simulatively added PV installation.
Definition units.cpp:944
void add_unit(MeasurementUnit *unit)
Definition units.cpp:303
static void ChangeControlHorizonInTS(unsigned int new_horizon)
Sets the optimization horizon (if another value is whished than given by Global::get_control_horizon_...
Definition units.cpp:1634
bool has_wind() const
Returns true, if the control unit has a wind turbine (or many) attachted (in data or simulated).
Definition units.cpp:363
static size_t GetNumberOfCUsWithSimCompEV()
Returns the number of control units that hold a simulatively added (private) EV charging stations.
Definition units.cpp:1665
int get_exp_combi_bit_repr_sim_added() const
Returns the bit representation of the expansion that has been simulatively added. See also namespace ...
Definition units.cpp:447
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_sim_comp_cs_max_P_kW() const
Returns the maximum available charging power of the simulatively added charging station (if the stati...
Definition units.cpp:567
float get_annual_hp_el_cons_kWh()
Returns the annual HP electricity consumption of a heat pump in kWh, if it would be added simulativel...
Definition units.cpp:563
double get_SSR()
Returns the SSR of the CU from the start of the simulation run until the time of function call; most ...
Definition units.cpp:579
static void InitializeStaticVariables(unsigned long n_CUs)
Definition units.cpp:1549
double get_sim_comp_bs_P_kW() const
Returns the maximum power in kW of the battery storage component that is added for the simulation,...
Definition units.cpp:537
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
static size_t GetNumberOfInstances()
Definition units.h:269
string * get_pv_section_string()
Definition units.cpp:775
static size_t GetNumberOfCUsWithSimCompHP()
Returns the number of control units that hold a simulatively added heat pump.
Definition units.cpp:1656
double get_NPV()
Returns the net present value (NPV) of the CU from the start of the simulation run until the time of ...
Definition units.cpp:593
size_t get_unitID() const
returns the unit ID of this control unit as given in the system structure database
Definition units.h:213
static unsigned long GetCurrentNumberOfOptiVars()
Returns the current number of variables used in the currently running (parallel) optimizations....
Definition units.h:276
const ComponentPV * get_component_PV() const
Returns a pointer to PV component, or nullptr if no such component is added.
Definition units.h:233
double get_current_PV_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by a PV installation.
Definition units.h:206
static size_t GetNumberOfCUsWithSimCompPV()
Returns the number of control units that hold a simulatively added PV installation.
Definition units.cpp:1647
double get_current_unknown_generation_kW() const
Returns the current local generation that cannot be attributed to any generation technology (regardle...
Definition units.cpp:514
size_t get_n_MUs()
Definition units.h:211
double get_sim_comp_bs_E_kWh() const
Returns the maximum capacity in kWh of the battery storage component that is added for the simulation...
Definition units.cpp:543
bool has_bs() const
Returns true, if the control unit has a battery storage system attachted (in data or simulated).
Definition units.cpp:325
double get_current_PV_generation_kW() const
Returns the current local PV generation (regardless of self-consumption), always greater or equal to ...
Definition units.cpp:473
bool has_hp() const
Returns true, if the control unit has a heat pump attachted (in data or simulated).
Definition units.cpp:335
float get_annual_heat_demand_th_kWh()
Returns the annual heat demand in (thermal) kWh of all attachted buildings.
Definition units.cpp:549
static ControlUnit * GetInstancePublicID(unsigned long unitID)
Returns instance with a public unitID. Returns NULL, if unitID is out of the given range.
Definition units.cpp:1588
void set_exp_pv_params_B(float kWp_per_m2, float min_kWp_sec, float max_kWp_sec, float max_kWp_unit)
Set the kWp of expanded PV installations in the case of dynamic kWp computation per section.
Definition units.cpp:908
static bool InstantiateNewControlUnit(unsigned long unitID, unsigned long substation_id, unsigned long locationID, bool residential, unsigned int n_flats)
Definition units.cpp:185
void reset_internal_state()
Resets the internal state of the object, without removing added components.
Definition units.cpp:987
size_t get_internal_id() const
Returns the (consecutive) internal ID of the control unit.
Definition units.h:212
double get_current_CHP_generation_kW() const
Returns the current local CHP generation (regardless of self-consumption), always greater or equal to...
Definition units.cpp:489
double get_current_wind_generation_kW() const
Returns the current local wind generation (regardless of self-consumption), always greater or equal t...
Definition units.cpp:501
bool is_expandable_with_hp()
Is a simulated heat pump addable (yes, if geodata or gas consumption data is available)....
Definition units.cpp:398
static const std::string MetricsStringHeaderAnnual
The header for the output string produced by ControlUnit::get_metrics_string_annual()
Definition units.h:376
static double GetAllSimCompBatteriesCharge_kWh()
Returns the charge of all simulatively added battery storage systems at the current ts.
Definition units.cpp:1674
static ControlUnit * GetInstancePublicIDWE(unsigned long unitID)
Returns instance with a public unitID. Throws an error, if untiID is not defined.
Definition units.cpp:1597
void set_exp_pv_params_A(float kWp_static)
Set the kWp of expanded PV installations in the case of static kWp computation per section.
Definition units.cpp:896
bool has_chp() const
Returns true, if the control unit has a combined heat and power (CHP) plant attachted (in data or sim...
Definition units.cpp:355
static void ResetAllInternalStates()
Definition units.cpp:1616
bool compute_next_value(unsigned long ts)
Computes the value for the (next) time step. The parameter 'ts' defines the current time step (starti...
Definition units.cpp:1045
double get_sim_comp_pv_kWp() const
Returns the kWp of the PV-component that is added for the simulation, returns 0 if there is no added ...
Definition units.cpp:531
void change_control_horizon_in_ts(unsigned int new_horizon)
Sets the optimization horizon (if another value is whished than given by Global::get_control_horizon_...
Definition units.cpp:935
double get_SCR()
Returns the SCR of the CU from the start of the simulation run until the time of function call; most ...
Definition units.cpp:586
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 RemoveAllSimAddedComponents()
Removes all simulatively added components from all control units.
Definition units.cpp:1628
size_t get_location_id() const
Returns the location ID of the control unit.
Definition units.h:214
bool has_bs_sim_added() const
Returns true, if the control unit has a simulated battery storage system attachted.
Definition units.cpp:371
double get_current_CHP_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by a CHP.
Definition units.h:208
void remove_sim_added_components()
Remove all components that are added simulatively.
Definition units.cpp:964
static double GetAllSimCompBatteriesCapacity_kWh()
Returns the capacity of all simulatively added battery storage systems.
Definition units.cpp:1683
void add_exp_bs()
Adds a simulated battery storage. Mind: MUST be called after ControlUnit::add_exp_hp() if it is calle...
Definition units.cpp:811
bool is_residential() const
Is this unit a residential unit?
Definition units.h:193
static ControlUnit * GetInstanceInternalID(unsigned long internalID)
Returns the instance with a given internal ID without checking of the boundaries.
Definition units.h:266
size_t get_sim_comp_cs_n_EVs() const
Returns the number of connected EVs if the charging station component is enabled, otherwise 0 is retu...
Definition units.cpp:571
bool is_expandable_with_pv()
Is a simulated PV installation addable (yes, if geodata is available). This function uses caching.
Definition units.cpp:375
string * get_metrics_string_weekly_wr(unsigned long week_number)
Definition units.cpp:695
void add_exp_pv()
Definition units.cpp:783
bool is_sim_expanded
Puplicly accessible member, weather the control unit is expanded or not (required for SAC Planning)....
Definition units.h:235
bool heat_demand_given_in_data() const
Returns true, if the heat demand for this location is given in the input data.
Definition units.cpp:427
double get_current_BS_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by a battery storage system.
Definition units.h:207
void set_exp_bs_maxP_kW(float value)
Definition units.cpp:925
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:1567
int get_exp_combi_bit_repr() const
Returns the bit representation of the current expansion (simulated added components) state (as in dat...
Definition units.cpp:431
double get_current_wind_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by a wind turbine.
Definition units.h:209
void add_exp_cs()
Activates / enables the EV charging station at the control unit.
Definition units.cpp:872
double get_current_load_vSMeter_kW()
Definition units.h:198
bool has_electricity_demand() const
Returns true if there is at least one connected measurement unit (MeasurementUnit) that shows a deman...
Definition units.cpp:307
void set_output_object(CUOutput *output_obj)
Definition units.cpp:892
static unsigned long GetTotalNumberOfOptimizationCalls()
Returns the total number of calls of an optimizer up to now.
Definition units.h:275
double get_mean_annual_MU_el_demand_kWh() const
Returns the mean electricity demand in kWh of all connected MUs over all available years.
Definition units.cpp:518
bool has_pv() const
Returns true, if the control unit has a PV attachted (in data or simulated).
Definition units.cpp:315
void remove_sim_added_bs()
Removes a simulatively added battery storage.
Definition units.cpp:954
void add_exp_hp()
Definition units.cpp:861
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
double get_current_unknown_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by unknown components or not attrib...
Definition units.h:210
static void PreprocessEVData()
Preprocesses EV data (min/max consumption until a given ts, states, ...) for all EVs.
Definition units.cpp:1610
void add_ev(unsigned long carID)
Adds an EV to the charging station (regardless if the charging station is enabled or not)
Definition units.cpp:885
int get_exp_combi_bit_repr_from_MUs() const
Returns the bit representation of the expansion of this unit as defined in the data....
Definition units.cpp:435
static const std::string MetricsStringHeaderWeekly
The header for the output string produced by ControlUnit::get_metrics_string_weekly_wr()
Definition units.h:377
~MeasurementUnit()
Definition units.cpp:1768
bool has_pv() const
Definition units.h:411
unsigned long get_meUID() const
Returns the ID as given in the system structe database.
Definition units.h:406
bool has_pv_open_space() const
Definition units.h:413
static size_t GetNumberOfInstances()
Definition units.h:457
bool load_data()
Load the data as given by the member variable data_source_path. Returns false if an error happend dur...
Definition units.cpp:1784
bool has_hp() const
Definition units.h:415
static bool LoadDataForAllInstances()
Loads the data for all created instances.
Definition units.cpp:1921
static MeasurementUnit * GetInstancePublicID(unsigned long meUID)
Returns instance with public id meUID (or NULL, if the ID is not available)
Definition units.cpp:1968
float get_current_ts_rsm_value() const
Definition units.h:423
static bool InstantiateNewMeasurementUnit(size_t meUID, size_t public_unitID, std::string *meterPointName, size_t locID, bool has_demand, bool has_feedin, bool has_pv_resid, bool has_pv_opens, bool has_bess, bool has_hp, bool has_wind, bool has_evchst, bool has_chp, const std::string &data_source_path)
Definition units.cpp:1705
bool has_evchst() const
Definition units.h:416
bool has_wind() const
Definition units.h:418
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:1912
bool has_pv_residential() const
Definition units.h:412
int get_expansion_combination() const
Definition units.h:419
bool compute_next_value(unsigned long ts)
Definition units.cpp:1880
float get_rsm_load_at_ts(unsigned long ts) const
Definition units.cpp:1890
bool has_feedin() const
Definition units.h:410
unsigned long get_internal_id() const
Returns the (consecutive) internal ID of the measurement unit.
Definition units.h:405
unsigned long get_locationID() const
Returns the ID of the location.
Definition units.h:407
bool has_bs() const
Definition units.h:414
bool has_chp() const
Definition units.h:417
double get_total_demand_kWh() const
Returns the total demand of the measurement unit over the complete time span of data.
Definition units.cpp:1872
const std::string * get_meterPointName() const
Returns the name of the meter point.
Definition units.h:404
float get_rsm_feedin_at_ts(unsigned long ts) const
Definition units.cpp:1902
float get_rsm_demand_at_ts(unsigned long ts) const
Definition units.cpp:1896
bool has_demand() const
Definition units.h:409
static void InitializeStaticVariables(unsigned long n_MUs)
Definition units.cpp:1908
float get_current_feedin_kW()
Definition units.h:506
bool compute_next_value(unsigned long ts)
Definition units.cpp:1998
double get_current_BS_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by all connected battery storage sy...
Definition units.h:104
double get_current_wind_generation_total_kW() const
Returns the current generation (without consideration of self-consumption) in kW that is generated by...
Definition units.h:101
double get_current_unknown_generation_total_kW() const
Returns the current generation (without consideration of self-consumption) in kW that is generated by...
Definition units.h:102
double get_current_BESS_demand() const
Returns the current charging demand of all BESS in all connected units.
Definition units.h:97
void add_unit(ControlUnit *unit)
Definition units.cpp:91
void calc_load()
Definition units.cpp:95
double get_residential_demand() const
Returns the accumulated demand (i.e., only the positive virtual smart meter readings) of all resident...
Definition units.h:94
static void VacuumInstancesAndStaticVariables()
Definition units.cpp:146
static void InitializeStaticVariables(unsigned long n_substations)
Definition units.cpp:142
double get_residential_load() const
Returns the current load at the substation in kW, generated by residential control units only.
Definition units.h:93
double get_other_demand() const
Returns the accumulated demand (i.e., only the positive virtual smart meter readings) of all non-resi...
Definition units.h:95
double get_current_PV_generation_total_kW() const
Returns the current generation (without consideration of self-consumption) in kW that is generated by...
Definition units.h:98
double get_current_unknown_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by unknown components or not attrib...
Definition units.h:107
static Substation * GetInstancePublicID(unsigned long public_id)
Returns the instance with a given public_id.
Definition units.cpp:157
double get_current_CHP_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by all connected CHPs.
Definition units.h:105
static bool InstantiateNewSubstation(unsigned long public_id, std::string *name)
Definition units.cpp:42
const std::list< ControlUnit * > * get_connected_units()
Return the list of connected units (as read only list)
Definition units.h:112
static size_t GetNumberOfInstances()
Definition units.h:122
static const std::vector< Substation * > & GetArrayOfInstances()
Returns the std::vector of all substation instances. The objects itself are mutable,...
Definition units.h:121
double get_current_PV_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by all connected PV installations.
Definition units.h:103
unsigned long get_id() const
Returns the ID of the substation as defined in the system structure database.
Definition units.h:90
unsigned long get_internal_id() const
Returns the internal ID of the substation.
Definition units.h:89
double get_current_wind_feedin_to_grid_kW() const
Returns the current feed-in into the grid in kW that is generated by all connected wind turbines.
Definition units.h:106
double get_current_demand_no_BESS() const
Returns the current demand of all connected units without considering the local generation OR the BES...
Definition units.h:96
const std::string * get_name() const
Returns the name of the substation.
Definition units.h:91
double get_current_BS_generation_total_kW() const
Returns the current generation (without consideration of self-consumption) in kW that is generated by...
Definition units.h:99
double get_current_CHP_generation_total_kW() const
Returns the current generation (without consideration of self-consumption) in kW that is generated by...
Definition units.h:100
double get_station_load() const
Returns the current load at the substation in kW.
Definition units.h:92
~Substation()
Definition units.cpp:86
static Substation * GetInstanceInternalID(unsigned long internal_id)
Returns the instance with a given public_id.
Definition units.h:120
OpenSpacePVOrWindType
Definition units.h:498
@ Wind
Definition units.h:500
@ PV
Definition units.h:499