diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b812f78..f3cda35 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,6 +5,7 @@ Change Log -------- - [refacto] have a structure in cpp for the buses - [refacto] have the id_grid_to_solver and id_solver_to_grid etc. directly in the solver and NOT in the gridmodel. +- [refacto] put some method in the DataGeneric as well as some attribute (_status for example) - support 3w trafo (as modeled in pandapower) - improve speed by not performing internal checks (keep check for boundaries and all for python API instead) [see `TODO DEBUG MODE` in c++ code] @@ -13,8 +14,6 @@ Change Log - a mode to do both `Computer` and `SecurityAnalysisCPP` - use the "multi slack hack" (see issue #50) for SecurityAnalysis or Computer for example - code `helm` powerflow method -- possibility to read CGMES files -- possibility to read XIIDM files - interface with gridpack (to enforce q limits for example) - maybe have a look at suitesparse "sliplu" tools ? - easier building (get rid of the "make" part) @@ -30,8 +29,9 @@ Change Log these cases. - [ADDED] sets of methods to extract the main component of a grid and perform powerflow only on this one. +- [ADDED] possibility to set / retrieve the names of each elements of the grid. - [IMPROVED] now performing the new grid2op `create_test_suite` -- [IMPROVED] now lightsim2grid properly throw BackendError +- [IMPROVED] now lightsim2grid properly throw `BackendError` [0.7.5] 2023-10-05 -------------------- diff --git a/lightsim2grid/gridmodel/from_pypowsybl.py b/lightsim2grid/gridmodel/from_pypowsybl.py index 3e1b703..39d2a2d 100644 --- a/lightsim2grid/gridmodel/from_pypowsybl.py +++ b/lightsim2grid/gridmodel/from_pypowsybl.py @@ -26,8 +26,8 @@ def _aux_get_bus(bus_df, df, conn_key="connected", bus_key="bus_id"): tmp_bus_id[mask_disco] = df.iloc[first_el_co][bus_key] # assign a "random" bus to disco element bus_id = bus_df.loc[tmp_bus_id.values]["bus_id"].values # deactivate the element not on the main component - wrong_component = bus_df.loc[tmp_bus_id.values]["connected_component"].values != 0 - mask_disco[wrong_component] = True + # wrong_component = bus_df.loc[tmp_bus_id.values]["connected_component"].values != 0 + # mask_disco[wrong_component] = True # assign bus -1 to disconnected elements bus_id[mask_disco] = -1 return bus_id , mask_disco.values @@ -38,8 +38,11 @@ def init(net : pypo.network, slack_bus_id: int = None, sn_mva = 100., sort_index=True, - f_hz = 50.): + f_hz = 50., + only_main_component=True): model = GridModel() + # model.set_f_hz(f_hz) + # for substation # network.get_voltage_levels()["substation_id"] # network.get_substations() @@ -84,6 +87,7 @@ def init(net : pypo.network, for gen_id, is_disco in enumerate(gen_disco): if is_disco: model.deactivate_gen(gen_id) + model.set_gen_names(df_gen.index) # for loads if sort_index: @@ -98,6 +102,7 @@ def init(net : pypo.network, for load_id, is_disco in enumerate(load_disco): if is_disco: model.deactivate_load(load_id) + model.set_load_names(df_load.index) # for lines if sort_index: @@ -141,6 +146,7 @@ def init(net : pypo.network, for line_id, (is_or_disc, is_ex_disc) in enumerate(zip(lor_disco, lex_disco)): if is_or_disc or is_ex_disc: model.deactivate_powerline(line_id) + model.set_line_names(df_line.index) # for trafo if sort_index: @@ -176,6 +182,7 @@ def init(net : pypo.network, for t_id, (is_or_disc, is_ex_disc) in enumerate(zip(tor_disco, tex_disco)): if is_or_disc or is_ex_disc: model.deactivate_trafo(t_id) + model.set_trafo_names(df_trafo.index) # for shunt if sort_index: @@ -192,6 +199,7 @@ def init(net : pypo.network, for shunt_id, disco in enumerate(sh_disco): if disco: model.deactivate_shunt(shunt_id) + model.set_shunt_names(df_trafo.index) # for hvdc (TODO not tested yet) df_dc = net.get_hvdc_lines().sort_index() @@ -218,6 +226,7 @@ def init(net : pypo.network, for hvdc_id, (is_or_disc, is_ex_disc) in enumerate(zip(hvdc_from_disco, hvdc_to_disco)): if is_or_disc or is_ex_disc: model.deactivate_hvdc(hvdc_id) + model.set_dcline_names(df_sations.index) # storage units (TODO not tested yet) if sort_index: @@ -232,6 +241,7 @@ def init(net : pypo.network, for batt_id, disco in enumerate(batt_disco): if disco: model.deactivate_storage(batt_id) + model.set_storage_names(df_batt.index) # TODO dist slack if gen_slack_id is None and slack_bus_id is None: @@ -262,6 +272,6 @@ def init(net : pypo.network, # raise RuntimeError("Impossible currently to init a grid with tap changers at the moment.") # and now deactivate all elements and nodes not in the main component - # TODO DC LINE: one side might be in the connected comp and not the other ! - model.consider_only_main_component() + if only_main_component: + model.consider_only_main_component() return model diff --git a/src/DataDCLine.cpp b/src/DataDCLine.cpp index 4569456..977f961 100644 --- a/src/DataDCLine.cpp +++ b/src/DataDCLine.cpp @@ -15,7 +15,8 @@ DataDCLine::StateRes DataDCLine::get_state() const std::vector loss_percent(loss_percent_.begin(), loss_percent_.end()); std::vector loss_mw(loss_mw_.begin(), loss_mw_.end()); std::vector status = status_; - DataDCLine::StateRes res(from_gen_.get_state(), + DataDCLine::StateRes res(names_, + from_gen_.get_state(), to_gen_.get_state(), loss_percent, loss_mw, @@ -25,11 +26,12 @@ DataDCLine::StateRes DataDCLine::get_state() const void DataDCLine::set_state(DataDCLine::StateRes & my_state){ reset_results(); - from_gen_.set_state(std::get<0>(my_state)); - to_gen_.set_state(std::get<1>(my_state)); - std::vector & loss_percent = std::get<2>(my_state); - std::vector & loss_mw = std::get<3>(my_state); - std::vector & status = std::get<4>(my_state); + names_ = std::get<0>(my_state); + from_gen_.set_state(std::get<1>(my_state)); + to_gen_.set_state(std::get<2>(my_state)); + std::vector & loss_percent = std::get<3>(my_state); + std::vector & loss_mw = std::get<4>(my_state); + std::vector & status = std::get<5>(my_state); status_ = status; loss_percent_ = RealVect::Map(&loss_percent[0], loss_percent.size()); loss_mw_ = RealVect::Map(&loss_mw[0], loss_percent.size()); diff --git a/src/DataDCLine.h b/src/DataDCLine.h index 042791c..fbcba63 100644 --- a/src/DataDCLine.h +++ b/src/DataDCLine.h @@ -30,6 +30,7 @@ class DataDCLine : public DataGeneric public: // members int id; // id of the dcline + std::string name; bool connected; int bus_or_id; int bus_ex_id; @@ -53,6 +54,7 @@ class DataDCLine : public DataGeneric DCLineInfo(const DataDCLine & r_data_dcline, int my_id): id(-1), + name(""), connected(false), bus_or_id(-1), bus_ex_id(-1), @@ -76,6 +78,9 @@ class DataDCLine : public DataGeneric if((my_id >= 0) & (my_id < r_data_dcline.nb())) { id = my_id; + if(r_data_dcline.names_.size()){ + name = r_data_dcline.names_[my_id]; + } loss_pct = r_data_dcline.loss_percent_(my_id); loss_mw = r_data_dcline.loss_mw_(my_id); @@ -108,6 +113,7 @@ class DataDCLine : public DataGeneric public: typedef std::tuple< + std::vector, DataGen::StateRes, DataGen::StateRes, std::vector, // loss_percent diff --git a/src/DataGen.cpp b/src/DataGen.cpp index 3d06445..b110ff5 100644 --- a/src/DataGen.cpp +++ b/src/DataGen.cpp @@ -58,25 +58,25 @@ DataGen::StateRes DataGen::get_state() const std::vector status = status_; std::vector slack_bus = gen_slackbus_; std::vector slack_weight = gen_slack_weight_; - DataGen::StateRes res(turnedoff_gen_pv_, p_mw, vm_pu, min_q, max_q, bus_id, status, slack_bus, slack_weight); + DataGen::StateRes res(names_, turnedoff_gen_pv_, p_mw, vm_pu, min_q, max_q, bus_id, status, slack_bus, slack_weight); return res; } -void DataGen::set_state(DataGen::StateRes & my_state ) +void DataGen::set_state(DataGen::StateRes & my_state) { reset_results(); - - turnedoff_gen_pv_ = std::get<0>(my_state); + names_ = std::get<0>(my_state); + turnedoff_gen_pv_ = std::get<1>(my_state); // the generators themelves - std::vector & p_mw = std::get<1>(my_state); - std::vector & vm_pu = std::get<2>(my_state); - std::vector & min_q = std::get<3>(my_state); - std::vector & max_q = std::get<4>(my_state); - std::vector & bus_id = std::get<5>(my_state); - std::vector & status = std::get<6>(my_state); - std::vector & slack_bus = std::get<7>(my_state); - std::vector & slack_weight = std::get<8>(my_state); + std::vector & p_mw = std::get<2>(my_state); + std::vector & vm_pu = std::get<3>(my_state); + std::vector & min_q = std::get<4>(my_state); + std::vector & max_q = std::get<5>(my_state); + std::vector & bus_id = std::get<6>(my_state); + std::vector & status = std::get<7>(my_state); + std::vector & slack_bus = std::get<8>(my_state); + std::vector & slack_weight = std::get<9>(my_state); // TODO check sizes // input data diff --git a/src/DataGen.h b/src/DataGen.h index a4c41cd..d125bf2 100644 --- a/src/DataGen.h +++ b/src/DataGen.h @@ -39,6 +39,7 @@ class DataGen: public DataGeneric // members // TODO add some const here (value should not be changed !) !!! int id; // id of the generator + std::string name; bool connected; int bus_id; bool is_slack; @@ -56,6 +57,7 @@ class DataGen: public DataGeneric GenInfo(const DataGen & r_data_gen, int my_id): id(-1), + name(""), connected(false), bus_id(-1), is_slack(false), @@ -73,6 +75,9 @@ class DataGen: public DataGeneric if((my_id >= 0) & (my_id < r_data_gen.nb())) { id = my_id; + if(r_data_gen.names_.size()){ + name = r_data_gen.names_[my_id]; + } connected = r_data_gen.status_[my_id]; bus_id = r_data_gen.bus_id_[my_id]; is_slack = r_data_gen.gen_slackbus_[my_id]; @@ -101,6 +106,7 @@ class DataGen: public DataGeneric public: typedef std::tuple< + std::vector, bool, std::vector, // p_mw std::vector, // vm_pu_ diff --git a/src/DataGeneric.h b/src/DataGeneric.h index 85e8e1e..e3ccd6b 100644 --- a/src/DataGeneric.h +++ b/src/DataGeneric.h @@ -98,9 +98,15 @@ class DataGeneric : public BaseConstants virtual void get_graph(std::vector > & res) const {}; virtual void disconnect_if_not_in_main_component(std::vector & busbar_in_main_component) {}; + void set_names(const std::vector & names){ + names_ = names; + } + /**"define" the destructor for compliance with clang (otherwise lots of warnings)**/ virtual ~DataGeneric() {}; - + protected: + std::vector names_; + protected: /** activation / deactivation of elements diff --git a/src/DataLine.cpp b/src/DataLine.cpp index 541df7d..2f63c5b 100644 --- a/src/DataLine.cpp +++ b/src/DataLine.cpp @@ -77,20 +77,20 @@ DataLine::StateRes DataLine::get_state() const std::vector branch_from_id(bus_or_id_.begin(), bus_or_id_.end()); std::vector branch_to_id(bus_ex_id_.begin(), bus_ex_id_.end()); std::vector status = status_; - DataLine::StateRes res(branch_r, branch_x, branch_hor, branch_hex, branch_from_id, branch_to_id, status); + DataLine::StateRes res(names_, branch_r, branch_x, branch_hor, branch_hex, branch_from_id, branch_to_id, status); return res; } void DataLine::set_state(DataLine::StateRes & my_state) { reset_results(); - - std::vector & branch_r = std::get<0>(my_state); - std::vector & branch_x = std::get<1>(my_state); - std::vector & branch_h_or = std::get<2>(my_state); - std::vector & branch_h_ex = std::get<3>(my_state); - std::vector & branch_from_id = std::get<4>(my_state); - std::vector & branch_to_id = std::get<5>(my_state); - std::vector & status = std::get<6>(my_state); + names_ = std::get<0>(my_state); + std::vector & branch_r = std::get<1>(my_state); + std::vector & branch_x = std::get<2>(my_state); + std::vector & branch_h_or = std::get<3>(my_state); + std::vector & branch_h_ex = std::get<4>(my_state); + std::vector & branch_from_id = std::get<5>(my_state); + std::vector & branch_to_id = std::get<6>(my_state); + std::vector & status = std::get<7>(my_state); // TODO check sizes // now assign the values diff --git a/src/DataLine.h b/src/DataLine.h index 85ecd4f..08dd20d 100644 --- a/src/DataLine.h +++ b/src/DataLine.h @@ -38,6 +38,7 @@ class DataLine : public DataGeneric public: // members int id; // id of the line + std::string name; bool connected; int bus_or_id; int bus_ex_id; @@ -61,6 +62,7 @@ class DataLine : public DataGeneric LineInfo(const DataLine & r_data_line, int my_id): id(my_id), + name(""), connected(false), bus_or_id(-1), bus_ex_id(-1), @@ -84,6 +86,9 @@ class DataLine : public DataGeneric if((my_id >= 0) & (my_id < r_data_line.nb())) { id = my_id; + if(r_data_line.names_.size()){ + name = r_data_line.names_[my_id]; + } connected = r_data_line.status_[my_id]; bus_or_id = r_data_line.bus_or_id_.coeff(my_id); bus_ex_id = r_data_line.bus_ex_id_.coeff(my_id); @@ -117,6 +122,7 @@ class DataLine : public DataGeneric public: typedef std::tuple< + std::vector, std::vector, // branch_r std::vector, // branch_x std::vector, // branch_h diff --git a/src/DataLoad.cpp b/src/DataLoad.cpp index 041d53e..e29249b 100644 --- a/src/DataLoad.cpp +++ b/src/DataLoad.cpp @@ -26,17 +26,17 @@ DataLoad::StateRes DataLoad::get_state() const std::vector q_mvar(q_mvar_.begin(), q_mvar_.end()); std::vector bus_id(bus_id_.begin(), bus_id_.end()); std::vector status = status_; - DataLoad::StateRes res(p_mw, q_mvar, bus_id, status); + DataLoad::StateRes res(names_, p_mw, q_mvar, bus_id, status); return res; } void DataLoad::set_state(DataLoad::StateRes & my_state ) { reset_results(); - - std::vector & p_mw = std::get<0>(my_state); - std::vector & q_mvar = std::get<1>(my_state); - std::vector & bus_id = std::get<2>(my_state); - std::vector & status = std::get<3>(my_state); + names_ = std::get<0>(my_state); + std::vector & p_mw = std::get<1>(my_state); + std::vector & q_mvar = std::get<2>(my_state); + std::vector & bus_id = std::get<3>(my_state); + std::vector & status = std::get<4>(my_state); // TODO check sizes // input data diff --git a/src/DataLoad.h b/src/DataLoad.h index aebd6b5..f4d7689 100644 --- a/src/DataLoad.h +++ b/src/DataLoad.h @@ -44,6 +44,7 @@ class DataLoad : public DataGeneric // members // TODO add some const here (value should not be changed !) !!! int id; // id of the generator + std::string name; bool connected; int bus_id; @@ -57,6 +58,7 @@ class DataLoad : public DataGeneric LoadInfo(const DataLoad & r_data_load, int my_id): id(-1), + name(""), connected(false), bus_id(-1), target_p_mw(0.), @@ -70,6 +72,9 @@ class DataLoad : public DataGeneric if((my_id >= 0) & (my_id < r_data_load.nb())) { id = my_id; + if(r_data_load.names_.size()){ + name = r_data_load.names_[my_id]; + } connected = r_data_load.status_[my_id]; bus_id = r_data_load.bus_id_[my_id]; @@ -112,6 +117,7 @@ class DataLoad : public DataGeneric // regular implementation public: typedef std::tuple< + std::vector, std::vector, // p_mw std::vector, // q_mvar std::vector, // bus_id diff --git a/src/DataSGen.cpp b/src/DataSGen.cpp index dc9a2b8..3b46038 100644 --- a/src/DataSGen.cpp +++ b/src/DataSGen.cpp @@ -44,22 +44,23 @@ DataSGen::StateRes DataSGen::get_state() const std::vector q_max(q_max_mvar_.begin(), q_max_mvar_.end()); std::vector bus_id(bus_id_.begin(), bus_id_.end()); std::vector status = status_; - DataSGen::StateRes res(p_mw, q_mvar, p_min, p_max, q_min, q_max, bus_id, status); + DataSGen::StateRes res(names_, p_mw, q_mvar, p_min, p_max, q_min, q_max, bus_id, status); return res; } void DataSGen::set_state(DataSGen::StateRes & my_state ) { reset_results(); - - std::vector & p_mw = std::get<0>(my_state); - std::vector & q_mvar = std::get<1>(my_state); - std::vector & p_min = std::get<2>(my_state); - std::vector & p_max = std::get<3>(my_state); - std::vector & q_min = std::get<4>(my_state); - std::vector & q_max = std::get<5>(my_state); - std::vector & bus_id = std::get<6>(my_state); - std::vector & status = std::get<7>(my_state); + + names_ = std::get<0>(my_state); + std::vector & p_mw = std::get<1>(my_state); + std::vector & q_mvar = std::get<2>(my_state); + std::vector & p_min = std::get<3>(my_state); + std::vector & p_max = std::get<4>(my_state); + std::vector & q_min = std::get<5>(my_state); + std::vector & q_max = std::get<6>(my_state); + std::vector & bus_id = std::get<7>(my_state); + std::vector & status = std::get<8>(my_state); auto size = p_mw.size(); DataGeneric::check_size(p_mw, size, "p_mw"); DataGeneric::check_size(q_mvar, size, "q_mvar"); diff --git a/src/DataSGen.h b/src/DataSGen.h index c2a5c7e..3d45b93 100644 --- a/src/DataSGen.h +++ b/src/DataSGen.h @@ -42,6 +42,7 @@ class DataSGen: public DataGeneric // members // TODO add some const here (value should not be changed !) !!! int id; // id of the generator + std::string name; bool connected; int bus_id; @@ -61,6 +62,7 @@ class DataSGen: public DataGeneric SGenInfo(const DataSGen & r_data_sgen, int my_id): id(-1), + name(""), connected(false), bus_id(-1), min_q_mvar(0.), @@ -78,6 +80,9 @@ class DataSGen: public DataGeneric if((my_id >= 0) & (my_id < r_data_sgen.nb())) { id = my_id; + if(r_data_sgen.names_.size()){ + name = r_data_sgen.names_[my_id]; + } connected = r_data_sgen.status_[my_id]; bus_id = r_data_sgen.bus_id_[my_id]; @@ -124,6 +129,7 @@ class DataSGen: public DataGeneric public: typedef std::tuple< + std::vector, std::vector, // p_mw std::vector, // q_mvar std::vector, // p_min diff --git a/src/DataShunt.cpp b/src/DataShunt.cpp index 42e057f..42a03f8 100644 --- a/src/DataShunt.cpp +++ b/src/DataShunt.cpp @@ -25,18 +25,18 @@ DataShunt::StateRes DataShunt::get_state() const std::vector q_mvar(q_mvar_.begin(), q_mvar_.end()); std::vector bus_id(bus_id_.begin(), bus_id_.end()); std::vector status = status_; - DataShunt::StateRes res(p_mw, q_mvar, bus_id, status); + DataShunt::StateRes res(names_, p_mw, q_mvar, bus_id, status); return res; } void DataShunt::set_state(DataShunt::StateRes & my_state ) { reset_results(); - - std::vector & p_mw = std::get<0>(my_state); - std::vector & q_mvar = std::get<1>(my_state); - std::vector & bus_id = std::get<2>(my_state); - std::vector & status = std::get<3>(my_state); + names_ = std::get<0>(my_state); + std::vector & p_mw = std::get<1>(my_state); + std::vector & q_mvar = std::get<2>(my_state); + std::vector & bus_id = std::get<3>(my_state); + std::vector & status = std::get<4>(my_state); // TODO check sizes // input data diff --git a/src/DataShunt.h b/src/DataShunt.h index 31e030c..1096a57 100644 --- a/src/DataShunt.h +++ b/src/DataShunt.h @@ -38,6 +38,7 @@ class DataShunt : public DataGeneric // members // TODO add some const here (value should not be changed !) !!! int id; // id of the generator + std::string name; bool connected; int bus_id; @@ -51,6 +52,7 @@ class DataShunt : public DataGeneric ShuntInfo(const DataShunt & r_data_shunt, int my_id): id(-1), + name(""), connected(false), bus_id(-1), target_p_mw(0.), @@ -64,6 +66,9 @@ class DataShunt : public DataGeneric if((my_id >= 0) & (my_id < r_data_shunt.nb())) { id = my_id; + if(r_data_shunt.names_.size()){ + name = r_data_shunt.names_[my_id]; + } connected = r_data_shunt.status_[my_id]; bus_id = r_data_shunt.bus_id_[my_id]; @@ -105,6 +110,7 @@ class DataShunt : public DataGeneric public: typedef std::tuple< + std::vector, std::vector, // p_mw std::vector, // q_mvar std::vector, // bus_id diff --git a/src/DataTrafo.cpp b/src/DataTrafo.cpp index 568f0e9..22cdce1 100644 --- a/src/DataTrafo.cpp +++ b/src/DataTrafo.cpp @@ -65,22 +65,23 @@ DataTrafo::StateRes DataTrafo::get_state() const std::vector ratio(ratio_.begin(), ratio_.end()); std::vector shift(shift_.begin(), shift_.end()); std::vector is_tap_hv_side = is_tap_hv_side_; - DataTrafo::StateRes res(branch_r, branch_x, branch_h, bus_hv_id, bus_lv_id, status, ratio, is_tap_hv_side, shift); + DataTrafo::StateRes res(names_, branch_r, branch_x, branch_h, bus_hv_id, bus_lv_id, status, ratio, is_tap_hv_side, shift); return res; } void DataTrafo::set_state(DataTrafo::StateRes & my_state) { reset_results(); - std::vector & branch_r = std::get<0>(my_state); - std::vector & branch_x = std::get<1>(my_state); - std::vector & branch_h = std::get<2>(my_state); - std::vector & bus_hv_id = std::get<3>(my_state); - std::vector & bus_lv_id = std::get<4>(my_state); - std::vector & status = std::get<5>(my_state); - std::vector & ratio = std::get<6>(my_state); - std::vector & is_tap_hv_side = std::get<7>(my_state); - std::vector & shift = std::get<8>(my_state); + names_ = std::get<0>(my_state); + std::vector & branch_r = std::get<1>(my_state); + std::vector & branch_x = std::get<2>(my_state); + std::vector & branch_h = std::get<3>(my_state); + std::vector & bus_hv_id = std::get<4>(my_state); + std::vector & bus_lv_id = std::get<5>(my_state); + std::vector & status = std::get<6>(my_state); + std::vector & ratio = std::get<7>(my_state); + std::vector & is_tap_hv_side = std::get<8>(my_state); + std::vector & shift = std::get<9>(my_state); auto size = branch_r.size(); DataGeneric::check_size(branch_r, size, "branch_r"); diff --git a/src/DataTrafo.h b/src/DataTrafo.h index f162f60..5afc240 100644 --- a/src/DataTrafo.h +++ b/src/DataTrafo.h @@ -38,6 +38,7 @@ class DataTrafo : public DataGeneric public: // members int id; // id of the generator + std::string name; bool connected; int bus_hv_id; int bus_lv_id; @@ -62,6 +63,7 @@ class DataTrafo : public DataGeneric TrafoInfo(const DataTrafo & r_data_trafo, int my_id): id(-1), + name(""), connected(false), bus_hv_id(-1), bus_lv_id(-1), @@ -86,6 +88,9 @@ class DataTrafo : public DataGeneric if((my_id >= 0) & (my_id < r_data_trafo.nb())) { id = my_id; + if(r_data_trafo.names_.size()){ + name = r_data_trafo.names_[my_id]; + } connected = r_data_trafo.status_[my_id]; bus_hv_id = r_data_trafo.bus_hv_id_.coeff(my_id); bus_lv_id = r_data_trafo.bus_lv_id_.coeff(my_id); @@ -120,6 +125,7 @@ class DataTrafo : public DataGeneric public: typedef std::tuple< + std::vector, std::vector, // branch_r std::vector, // branch_x std::vector, // branch_h diff --git a/src/GridModel.h b/src/GridModel.h index 1b45073..28740fd 100644 --- a/src/GridModel.h +++ b/src/GridModel.h @@ -286,6 +286,31 @@ class GridModel : public DataGeneric const DataShunt & get_shunts() const {return shunts_;} const std::vector & get_bus_status() const {return bus_status_;} + void set_line_names(const std::vector & names){ + powerlines_.set_names(names); + } + void set_dcline_names(const std::vector & names){ + dc_lines_.set_names(names); + } + void set_trafo_names(const std::vector & names){ + trafos_.set_names(names); + } + void set_gen_names(const std::vector & names){ + generators_.set_names(names); + } + void set_load_names(const std::vector & names){ + loads_.set_names(names); + } + void set_storage_names(const std::vector & names){ + storages_.set_names(names); + } + void set_sgen_names(const std::vector & names){ + sgens_.set_names(names); + } + void set_shunt_names(const std::vector & names){ + shunts_.set_names(names); + } + //deactivate a powerline (disconnect it) void deactivate_powerline(int powerline_id) {powerlines_.deactivate(powerline_id, topo_changed_); } void reactivate_powerline(int powerline_id) {powerlines_.reactivate(powerline_id, topo_changed_); } diff --git a/src/help_fun_msg.cpp b/src/help_fun_msg.cpp index 6a3fe40..a33c1b6 100644 --- a/src/help_fun_msg.cpp +++ b/src/help_fun_msg.cpp @@ -633,7 +633,7 @@ const std::string DocSolver::get_computation_time = R"mydelimiter( )mydelimiter"; const std::string DocIterator::id = R"mydelimiter( - Get the ideas of the element. Ids are integer from 0 to n-1 (if `n` denotes the number of such elements on the grid.) + Get the id of the element. Ids are integer from 0 to n-1 (if `n` denotes the number of such elements on the grid.) Examples -------- @@ -657,6 +657,34 @@ const std::string DocIterator::id = R"mydelimiter( )mydelimiter"; +const std::string DocIterator::name = R"mydelimiter( + Get the name of the element. Names are string that should be unique. But if you really want things unique, use the `id` + + .. warning:: + Names are optional and might not be set when reading the grid. + + Examples + -------- + We give the example only for generators, but it works similarly for every other types of objects + in a :class:`lightsim2grid.gridmodel.GridModel`. + + This gives something like: + + .. code-block:: python + + import grid2op + from lightsim2grid import LightSimBackend + + env_name = ... # eg. "l2rpn_case14_test" + env = grid2op.make(env_name, backend=LightSimBackend()) + + grid_model = env.backend._grid + + first_gen = grid_model.get_generators()[0] # or get_loads for loads, etc. + first_gen.name + +)mydelimiter"; + const std::string DocIterator::connected = R"mydelimiter( Get the status (True = connected, False = disconnected) of each element of a :class:`lightsim2grid.gridmodel.GridModel` diff --git a/src/help_fun_msg.h b/src/help_fun_msg.h index 17fa719..3f503b1 100644 --- a/src/help_fun_msg.h +++ b/src/help_fun_msg.h @@ -69,6 +69,7 @@ struct DocIterator // generic functions static const std::string only_avail_res; static const std::string id; + static const std::string name; static const std::string connected; static const std::string bus_id; static const std::string target_p_mw; diff --git a/src/main.cpp b/src/main.cpp index d0918d0..88221a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -405,6 +405,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "GenInfo", DocIterator::GenInfo.c_str()) .def_readonly("id", &DataGen::GenInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataGen::GenInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataGen::GenInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_id", &DataGen::GenInfo::bus_id, DocIterator::bus_id.c_str()) .def_readonly("is_slack", &DataGen::GenInfo::is_slack, DocIterator::is_slack.c_str()) @@ -429,6 +430,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "SGenInfo", DocIterator::SGenInfo.c_str()) .def_readonly("id", &DataSGen::SGenInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataSGen::SGenInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataSGen::SGenInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_id", &DataSGen::SGenInfo::bus_id, DocIterator::bus_id.c_str()) .def_readonly("min_q_mvar", &DataSGen::SGenInfo::min_q_mvar, DocIterator::min_q_mvar.c_str()) @@ -453,6 +455,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "LoadInfo", DocIterator::LoadInfo.c_str()) .def_readonly("id", &DataLoad::LoadInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataLoad::LoadInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataLoad::LoadInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_id", &DataLoad::LoadInfo::bus_id, DocIterator::bus_id.c_str()) .def_readonly("target_p_mw", &DataLoad::LoadInfo::target_p_mw, DocIterator::target_p_mw.c_str()) @@ -473,6 +476,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "ShuntInfo", DocIterator::ShuntInfo.c_str()) .def_readonly("id", &DataShunt::ShuntInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataShunt::ShuntInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataShunt::ShuntInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_id", &DataShunt::ShuntInfo::bus_id, DocIterator::bus_id.c_str()) .def_readonly("target_p_mw", &DataShunt::ShuntInfo::target_p_mw, DocIterator::target_p_mw.c_str()) @@ -493,6 +497,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "TrafoInfo", DocIterator::TrafoInfo.c_str()) .def_readonly("id", &DataTrafo::TrafoInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataTrafo::TrafoInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataTrafo::TrafoInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_hv_id", &DataTrafo::TrafoInfo::bus_hv_id, DocIterator::bus_hv_id.c_str()) .def_readonly("bus_lv_id", &DataTrafo::TrafoInfo::bus_lv_id, DocIterator::bus_lv_id.c_str()) @@ -524,6 +529,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "LineInfo", DocIterator::LineInfo.c_str()) .def_readonly("id", &DataLine::LineInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataLine::LineInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataLine::LineInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_or_id", &DataLine::LineInfo::bus_or_id, DocIterator::bus_or_id.c_str()) .def_readonly("bus_ex_id", &DataLine::LineInfo::bus_ex_id, DocIterator::bus_ex_id.c_str()) @@ -554,6 +560,7 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) py::class_(m, "DCLineInfo", DocIterator::DCLineInfo.c_str()) .def_readonly("id", &DataDCLine::DCLineInfo::id, DocIterator::id.c_str()) + .def_readonly("name", &DataDCLine::DCLineInfo::name, DocIterator::name.c_str()) .def_readonly("connected", &DataDCLine::DCLineInfo::connected, DocIterator::connected.c_str()) .def_readonly("bus_or_id", &DataDCLine::DCLineInfo::bus_or_id, DocIterator::bus_or_id.c_str()) .def_readonly("bus_ex_id", &DataDCLine::DCLineInfo::bus_ex_id, DocIterator::bus_ex_id.c_str()) @@ -662,6 +669,16 @@ PYBIND11_MODULE(lightsim2grid_cpp, m) .def("assign_slack_to_most_connected", &GridModel::assign_slack_to_most_connected, "TODO") .def("consider_only_main_component", &GridModel::consider_only_main_component, "TODO and TODO DC LINE: one side might be in the connected comp and not the other !") + // names + .def("set_line_names", &GridModel::set_line_names, "TODO") + .def("set_dcline_names", &GridModel::set_dcline_names, "TODO") + .def("set_trafo_names", &GridModel::set_trafo_names, "TODO") + .def("set_gen_names", &GridModel::set_gen_names, "TODO") + .def("set_load_names", &GridModel::set_load_names, "TODO") + .def("set_storage_names", &GridModel::set_storage_names, "TODO") + .def("set_sgen_names", &GridModel::set_sgen_names, "TODO") + .def("set_shunt_names", &GridModel::set_shunt_names, "TODO") + .def("deactivate_bus", &GridModel::deactivate_bus, DocGridModel::_internal_do_not_use.c_str()) .def("reactivate_bus", &GridModel::reactivate_bus, DocGridModel::_internal_do_not_use.c_str())