def create_generators(self): # max/min_q_mvar/p_mw 4개는 OPF 풀이시 반드시 필요함. # vm_pu 이용해서 현재 전압 맞춰줄 필요가 있음. # <20.07.27.> sn_mva, type 추가 (type이 controllable과 관련있음. p_mw, q_mvar, vm_pu 가 강제됨) # <20.07.27.> vm_pu 의 set point 확인 필요. #min_vm_pu, max_vm_pur -> OPF 필수 pp.create_gen(self.net, self.bus1, p_mw=110, vm_pu=1.07, sn_mva=100 ,min_p_mw=50.0, max_p_mw=200, \ min_q_mvar=-100.0, max_q_mvar=150.0, min_vm_pu=0.95, max_vm_pu=1.07, \ controllable=True, slack=True, type="controllable") pp.create_gen(self.net, self.bus2, p_mw=50, vm_pu=1.05, sn_mva=100,min_p_mw=37.5, max_p_mw=150, \ min_q_mvar=-100.0, max_q_mvar=150.0, min_vm_pu=0.95, max_vm_pu=1.07, \ controllable=True, type="controllable") pp.create_gen(self.net, self.bus3, p_mw=50, vm_pu=1.05, sn_mva=100, min_p_mw=45.0, max_p_mw=180, \ min_q_mvar=-100.0, max_q_mvar=120.0, min_vm_pu=0.95, max_vm_pu=1.07, \ controllable=True, type="controllable")
def add_test_enforce_qlims(net): b1, b2, ln = add_grid_connection(net, zone="test_enforce_qlims") pl = 1200 ql = 1100 ps = -500 qmax = 200. u_set = 1.0 b3 = pp.create_bus(net, zone="test_enforce_qlims", vn_kv=.4) pp.create_line_from_parameters(net, b2, b3, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12, c_nf_per_km=300, imax_ka=.2, df=.8) pp.create_load(net, b3, p_kw=pl, q_kvar=ql) g1 = pp.create_gen(net, b3, p_kw=ps, vm_pu=u_set, max_q_kvar=qmax) net.last_added_case = "test_enforce_qlims" return net
def test_isolated_gen_lookup(): net = pp.create_empty_network() gen_bus = pp.create_bus(net, vn_kv=1., name='gen_bus') slack_bus = pp.create_bus(net, vn_kv=1., name='slack_bus') gen_iso_bus = pp.create_bus(net, vn_kv=1., name='iso_bus') pp.create_line(net, from_bus=slack_bus, to_bus=gen_bus, length_km=1, std_type="48-AL1/8-ST1A 10.0") pp.create_ext_grid(net, bus=slack_bus, vm_pu=1.) pp.create_gen(net, bus=gen_iso_bus, p_mw=1, vm_pu=1., name='iso_gen') pp.create_gen(net, bus=gen_bus, p_mw=1, vm_pu=1., name='oos_gen', in_service=False) pp.create_gen(net, bus=gen_bus, p_mw=2, vm_pu=1., name='gen') pp.rundcpp(net) assert np.allclose(net.res_gen.p_mw.values, [0, 0, 2]) pp.runpp(net) assert np.allclose(net.res_gen.p_mw.values, [0, 0, 2]) pp.create_xward(net, bus=gen_iso_bus, pz_mw=1., qz_mvar=1., ps_mw=1., qs_mvar=1., vm_pu=1., x_ohm=1., r_ohm=.1) pp.create_xward(net, bus=gen_bus, pz_mw=1., qz_mvar=1., ps_mw=1., qs_mvar=1., vm_pu=1., x_ohm=1., r_ohm=.1) pp.create_xward(net, bus=gen_iso_bus, pz_mw=1., qz_mvar=1., ps_mw=1., qs_mvar=1., vm_pu=1., x_ohm=1., r_ohm=.1, in_service=False) pp.rundcpp(net) assert np.allclose(net.res_gen.p_mw.values, [0, 0, 2]) assert np.allclose(net.res_xward.p_mw.values, [0, 2, 0]) pp.runpp(net) assert np.allclose(net.res_gen.p_mw.values, [0, 0, 2]) assert np.allclose(net.res_xward.p_mw.values, [0, 2, 0])
length_km=40., std_type='149-AL1/24-ST1A 110.0') line = net.line #create loads pp.create_load(net, bus2, p_kw=60e3, controllable=False) pp.create_load(net, bus3, p_kw=70e3, controllable=False) pp.create_load(net, bus4, p_kw=10e3, controllable=False) load = net.load #create generators eg = pp.create_ext_grid(net, bus1) g0 = pp.create_gen(net, bus3, p_kw=-80 * 1e3, min_p_kw=-80e3, max_p_kw=0, vm_pu=1.01, name='Generator 0', controllable=True) g1 = pp.create_gen(net, bus4, p_kw=-100 * 1e3, min_p_kw=-100e3, max_p_kw=0, vm_pu=1.01, name='Generator 1', controllable=True) ext_grid = net.ext_grid gen = net.gen ## Loss Minimization
def load_grid(self, path=None, filename=None): """ Load the _grid, and initialize all the member of the class. Note that in order to perform topological modification of the substation of the underlying powergrid, some buses are added to the test case loaded. They are set as "out of service" unless a topological action acts on these specific substations. """ if path is None and filename is None: raise RuntimeError( "You must provide at least one of path or file to laod a powergrid." ) if path is None: full_path = filename elif filename is None: full_path = path else: full_path = os.path.join(path, filename) if not os.path.exists(full_path): raise RuntimeError( "There is no powergrid at \"{}\"".format(full_path)) with warnings.catch_warnings(): # remove deprecationg warnings for old version of pandapower warnings.filterwarnings("ignore", category=DeprecationWarning) self._grid = pp.from_json(full_path) # add the slack bus that is often not modeled as a generator, but i need it for this backend to work bus_gen_added = None i_ref = None self._iref_slack = None self._id_bus_added = None pp.runpp(self._grid, numba=numba_) if np.all(~self._grid.gen["slack"]): # there are not defined slack bus on the data, i need to hack it up a little bit pd2ppc = self._grid._pd2ppc_lookups[ "bus"] # pd2ppc[pd_id] = ppc_id ppc2pd = np.argsort(pd2ppc) # ppc2pd[ppc_id] = pd_id for i, el in enumerate(self._grid._ppc['gen'][:, 0]): if int(el) not in self._grid._pd2ppc_lookups["bus"][ self._grid.gen["bus"].values]: if bus_gen_added is not None: raise RuntimeError( "Impossible to recognize the powergrid") bus_gen_added = ppc2pd[int(el)] i_ref = i break self._iref_slack = i_ref self._id_bus_added = self._grid.gen.shape[0] # see https://matpower.org/docs/ref/matpower5.0/idx_gen.html for details on the comprehension of self._grid._ppc pp.create_gen(self._grid, bus_gen_added, p_mw=self._grid._ppc['gen'][i_ref, 1], vm_pu=self._grid._ppc['gen'][i_ref, 5], min_p_mw=self._grid._ppc['gen'][i_ref, 9], max_p_mw=self._grid._ppc['gen'][i_ref, 8], max_q_mvar=self._grid._ppc['gen'][i_ref, 3], min_q_mvar=self._grid._ppc['gen'][i_ref, 4], slack=True, controllable=True) else: self.slack_id = np.where(self._grid.gen["slack"])[0] pp.runpp(self._grid, numba=numba_) self.__nb_bus_before = self._grid.bus.shape[0] self.__nb_powerline = self._grid.line.shape[0] self._init_bus_load = self.cst_1 * self._grid.load["bus"].values self._init_bus_gen = self.cst_1 * self._grid.gen["bus"].values self._init_bus_lor = self.cst_1 * self._grid.line["from_bus"].values self._init_bus_lex = self.cst_1 * self._grid.line["to_bus"].values t_for = self.cst_1 * self._grid.trafo["hv_bus"].values t_fex = self.cst_1 * self._grid.trafo["lv_bus"].values self._init_bus_lor = np.concatenate( (self._init_bus_lor, t_for)).astype(np.int) self._init_bus_lex = np.concatenate( (self._init_bus_lex, t_fex)).astype(np.int) self._grid["ext_grid"]["va_degree"] = 0.0 # this has the effect to divide by 2 the active power in the added generator, if this generator and the "slack bus" # one are connected to the same bus. # if not, it must not be done. So basically, i create a vector for which p and q for generator must be multiply self._fact_mult_gen = np.ones(self._grid.gen.shape[0]) # self._fact_mult_gen[-1] += 1 # now extract the powergrid self.n_line = copy.deepcopy(self._grid.line.shape[0]) + copy.deepcopy( self._grid.trafo.shape[0]) if "name" in self._grid.line.columns and not self._grid.line[ "name"].isnull().values.any(): self.name_line = [name for name in self._grid.line["name"]] else: self.name_line = [ '{from_bus}_{to_bus}_{id_powerline_me}'.format( **row, id_powerline_me=i) for i, (_, row) in enumerate(self._grid.line.iterrows()) ] if "name" in self._grid.trafo.columns and not self._grid.trafo[ "name"].isnull().values.any(): self.name_line += [ name_traf for name_traf in self._grid.trafo["name"] ] else: transfo = [('{hv_bus}'.format(**row), '{lv_bus}'.format(**row)) for i, (_, row) in enumerate(self._grid.trafo.iterrows())] transfo = [sorted(el) for el in transfo] self.name_line += [ '{}_{}_{}'.format(*el, i + self._grid.line.shape[0]) for i, el in enumerate(transfo) ] self.name_line = np.array(self.name_line) self.n_gen = copy.deepcopy(self._grid.gen.shape[0]) if "name" in self._grid.gen.columns and not self._grid.gen[ "name"].isnull().values.any(): self.name_gen = [name_g for name_g in self._grid.gen["name"]] else: self.name_gen = [ "gen_{bus}_{index_gen}".format(**row, index_gen=i) for i, (_, row) in enumerate(self._grid.gen.iterrows()) ] self.name_gen = np.array(self.name_gen) self.n_load = copy.deepcopy(self._grid.load.shape[0]) if "name" in self._grid.load.columns and not self._grid.load[ "name"].isnull().values.any(): self.name_load = [nl for nl in self._grid.load["name"]] else: self.name_load = [ "load_{bus}_{index_gen}".format(**row, index_gen=i) for i, (_, row) in enumerate(self._grid.load.iterrows()) ] self.name_load = np.array(self.name_load) self.n_sub = copy.deepcopy(self._grid.bus.shape[0]) self.name_sub = [ "sub_{}".format(i) for i, row in self._grid.bus.iterrows() ] self.name_sub = np.array(self.name_sub) # number of elements per substation self.sub_info = np.zeros(self.n_sub, dtype=dt_int) self.load_to_subid = np.zeros(self.n_load, dtype=dt_int) self.gen_to_subid = np.zeros(self.n_gen, dtype=dt_int) self.line_or_to_subid = np.zeros(self.n_line, dtype=dt_int) self.line_ex_to_subid = np.zeros(self.n_line, dtype=dt_int) self.load_to_sub_pos = np.zeros(self.n_load, dtype=dt_int) self.gen_to_sub_pos = np.zeros(self.n_gen, dtype=dt_int) self.line_or_to_sub_pos = np.zeros(self.n_line, dtype=dt_int) self.line_ex_to_sub_pos = np.zeros(self.n_line, dtype=dt_int) pos_already_used = np.zeros(self.n_sub, dtype=dt_int) self._what_object_where = [[] for _ in range(self.n_sub)] # self._grid.line.sort_index(inplace=True) # self._grid.trafo.sort_index(inplace=True) # self._grid.gen.sort_index(inplace=True) # self._grid.load.sort_index(inplace=True) for i, (_, row) in enumerate(self._grid.line.iterrows()): sub_or_id = int(row["from_bus"]) sub_ex_id = int(row["to_bus"]) self.sub_info[sub_or_id] += 1 self.sub_info[sub_ex_id] += 1 self.line_or_to_subid[i] = sub_or_id self.line_ex_to_subid[i] = sub_ex_id self.line_or_to_sub_pos[i] = pos_already_used[sub_or_id] pos_already_used[sub_or_id] += 1 self.line_ex_to_sub_pos[i] = pos_already_used[sub_ex_id] pos_already_used[sub_ex_id] += 1 self._what_object_where[sub_or_id].append(("line", "from_bus", i)) self._what_object_where[sub_ex_id].append(("line", "to_bus", i)) lag_transfo = self._grid.line.shape[0] self._number_true_line = copy.deepcopy(self._grid.line.shape[0]) for i, (_, row) in enumerate(self._grid.trafo.iterrows()): sub_or_id = int(row["hv_bus"]) sub_ex_id = int(row["lv_bus"]) self.sub_info[sub_or_id] += 1 self.sub_info[sub_ex_id] += 1 self.line_or_to_subid[i + lag_transfo] = sub_or_id self.line_ex_to_subid[i + lag_transfo] = sub_ex_id self.line_or_to_sub_pos[i + lag_transfo] = pos_already_used[sub_or_id] pos_already_used[sub_or_id] += 1 self.line_ex_to_sub_pos[i + lag_transfo] = pos_already_used[sub_ex_id] pos_already_used[sub_ex_id] += 1 self._what_object_where[sub_or_id].append(("trafo", "hv_bus", i)) self._what_object_where[sub_ex_id].append(("trafo", "lv_bus", i)) for i, (_, row) in enumerate(self._grid.gen.iterrows()): sub_id = int(row["bus"]) self.sub_info[sub_id] += 1 self.gen_to_subid[i] = sub_id self.gen_to_sub_pos[i] = pos_already_used[sub_id] pos_already_used[sub_id] += 1 self._what_object_where[sub_id].append(("gen", "bus", i)) for i, (_, row) in enumerate(self._grid.load.iterrows()): sub_id = int(row["bus"]) self.sub_info[sub_id] += 1 self.load_to_subid[i] = sub_id self.load_to_sub_pos[i] = pos_already_used[sub_id] pos_already_used[sub_id] += 1 self._what_object_where[sub_id].append(("load", "bus", i)) self._compute_pos_big_topo() self.dim_topo = np.sum(self.sub_info) # utilities for imeplementing apply_action self._corresp_name_fun = {} self._get_vector_inj = {} self._get_vector_inj[ "load_p"] = self._load_grid_load_p_mw #lambda grid: grid.load["p_mw"] self._get_vector_inj[ "load_q"] = self._load_grid_load_q_mvar #lambda grid: grid.load["q_mvar"] self._get_vector_inj[ "prod_p"] = self._load_grid_gen_p_mw #lambda grid: grid.gen["p_mw"] self._get_vector_inj[ "prod_v"] = self._load_grid_gen_vm_pu #lambda grid: grid.gen["vm_pu"] # "hack" to handle topological changes, for now only 2 buses per substation add_topo = copy.deepcopy(self._grid.bus) add_topo.index += add_topo.shape[0] add_topo["in_service"] = False self._grid.bus = pd.concat((self._grid.bus, add_topo)) self.load_pu_to_kv = self._grid.bus["vn_kv"][ self.load_to_subid].values.astype(dt_float) self.prod_pu_to_kv = self._grid.bus["vn_kv"][ self.gen_to_subid].values.astype(dt_float) self.lines_or_pu_to_kv = self._grid.bus["vn_kv"][ self.line_or_to_subid].values.astype(dt_float) self.lines_ex_pu_to_kv = self._grid.bus["vn_kv"][ self.line_ex_to_subid].values.astype(dt_float) self.thermal_limit_a = 1000 * np.concatenate( (self._grid.line["max_i_ka"].values, self._grid.trafo["sn_mva"].values / (np.sqrt(3) * self._grid.trafo["vn_hv_kv"].values))) self.p_or = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.q_or = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.v_or = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.a_or = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.p_ex = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.q_ex = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.v_ex = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.a_ex = np.full(self.n_line, dtype=dt_float, fill_value=np.NaN) self.line_status = np.full(self.n_line, dtype=dt_bool, fill_value=np.NaN) self.load_p = np.full(self.n_load, dtype=dt_float, fill_value=np.NaN) self.load_q = np.full(self.n_load, dtype=dt_float, fill_value=np.NaN) self.load_v = np.full(self.n_load, dtype=dt_float, fill_value=np.NaN) self.prod_p = np.full(self.n_gen, dtype=dt_float, fill_value=np.NaN) self.prod_v = np.full(self.n_gen, dtype=dt_float, fill_value=np.NaN) self.prod_q = np.full(self.n_gen, dtype=dt_float, fill_value=np.NaN) self._nb_bus_before = None # shunts data self.n_shunt = self._grid.shunt.shape[0] self.shunt_to_subid = np.zeros(self.n_shunt, dtype=dt_int) - 1 name_shunt = [] for i, (_, row) in enumerate(self._grid.shunt.iterrows()): bus = int(row["bus"]) name_shunt.append( "shunt_{bus}_{index_shunt}".format(**row, index_shunt=i)) self.shunt_to_subid[i] = bus self.name_shunt = np.array(name_shunt) self.shunts_data_available = True # store the topoid -> objid self._big_topo_to_obj = [(None, None) for _ in range(self.dim_topo)] nm_ = "load" for load_id, pos_big_topo in enumerate(self.load_pos_topo_vect): self._big_topo_to_obj[pos_big_topo] = (load_id, nm_) nm_ = "gen" for gen_id, pos_big_topo in enumerate(self.gen_pos_topo_vect): self._big_topo_to_obj[pos_big_topo] = (gen_id, nm_) nm_ = "lineor" for l_id, pos_big_topo in enumerate(self.line_or_pos_topo_vect): self._big_topo_to_obj[pos_big_topo] = (l_id, nm_) nm_ = "lineex" for l_id, pos_big_topo in enumerate(self.line_ex_pos_topo_vect): self._big_topo_to_obj[pos_big_topo] = (l_id, nm_) # store the topoid -> objid self._big_topo_to_backend = [(None, None, None) for _ in range(self.dim_topo)] for load_id, pos_big_topo in enumerate(self.load_pos_topo_vect): self._big_topo_to_backend[pos_big_topo] = (load_id, load_id, 0) for gen_id, pos_big_topo in enumerate(self.gen_pos_topo_vect): self._big_topo_to_backend[pos_big_topo] = (gen_id, gen_id, 1) for l_id, pos_big_topo in enumerate(self.line_or_pos_topo_vect): if l_id < self.__nb_powerline: self._big_topo_to_backend[pos_big_topo] = (l_id, l_id, 2) else: self._big_topo_to_backend[pos_big_topo] = (l_id, l_id - self.__nb_powerline, 3) for l_id, pos_big_topo in enumerate(self.line_ex_pos_topo_vect): if l_id < self.__nb_powerline: self._big_topo_to_backend[pos_big_topo] = (l_id, l_id, 4) else: self._big_topo_to_backend[pos_big_topo] = (l_id, l_id - self.__nb_powerline, 5) self._topo_vect = self._get_topo_vect() # Create a deep copy of itself in the initial state pp_backend_initial_state = copy.deepcopy(self) # Store it under super private attribute self.__pp_backend_initial_state = pp_backend_initial_state
def test_xward_gen_same_bus(): net = small_example_grid() pp.create_gen(net, 2, 200, 1., slack_weight=2) pp.create_xward(net, 2, 200, 20, 10, 1, 0.02, 0.2, 1, slack_weight=4) with pytest.raises(NotImplementedError): pp.runpp(net, distributed_slack=True)
pp.create_load(net, bus=bus2, p_mw=170000, q_mvar=105356.53752852738, name="Load_2") pp.create_load(net, bus=bus3, p_mw=200000, q_mvar=123948.86768062047, name="Load_3") pp.create_gen(net, bus=bus4, vm_pu=1.02, name="Generator_2", p_mw=-318000, in_service=True) pp.create_load(net, bus=bus4, p_mw=80000, q_mvar=49579.54707224818, name="Load_4") #create lines line_data_12 = { "c_nf_per_km": 616.76, "r_ohm_per_km": 5.33232, "x_ohm_per_km": 26.6616, "max_i_ka": 0.415
def build_case_grid(self): grid = pp.create_empty_network() # Substation bus 1 bus0 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-0-0") bus1 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-1-1") bus2 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-2-2") # Substation bus 2 pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-3-0") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-4-1") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-5-2") pp.create_line_from_parameters( grid, bus0, bus1, length_km=1.0, r_ohm_per_km=0.01 * self.base_unit_z, x_ohm_per_km=1.0 / 3.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(1.0), name="line-0", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus0, bus2, length_km=1.0, r_ohm_per_km=0.01 * self.base_unit_z, x_ohm_per_km=1.0 / 2.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(1.0), name="line-1", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus2, length_km=1.0, r_ohm_per_km=0.01 * self.base_unit_z, x_ohm_per_km=1.0 / 2.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(1.0), name="line-2", type="ol", max_loading_percent=100.0, ) pp.create_load( grid, bus1, p_mw=self.convert_per_unit_to_mw(0.5), name="load-0", controllable=False, ) pp.create_load( grid, bus2, p_mw=self.convert_per_unit_to_mw(1.0), name="load-1", controllable=False, ) pp.create_gen( grid, bus0, p_mw=self.convert_per_unit_to_mw(1.5), min_p_mw=self.convert_per_unit_to_mw(0.0), max_p_mw=self.convert_per_unit_to_mw(2.0), slack=True, name="gen-0", ) return grid
def build_case_grid(self): grid = pp.create_empty_network() # Substation buses 1 bus0 = pp.create_bus( grid, vn_kv=2 * self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-0-0", ) bus1 = pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-1-1", ) bus2 = pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-2-2", ) bus3 = pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-3-3", ) # Substation buses 2 pp.create_bus( grid, vn_kv=2 * self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-4-0", ) pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-5-1", ) pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-6-2", ) pp.create_bus( grid, vn_kv=self.base_unit_v / 1000, min_vm_pu=1.0, max_vm_pu=1.02, name="bus-7-3", ) # Transformer pp.create_transformer_from_parameters( grid, hv_bus=bus0, lv_bus=bus1, name="trafo-0", sn_mva=3.5, vn_hv_kv=2 * self.base_unit_v / 1000, vn_lv_kv=self.base_unit_v / 1000, vk_percent=12.5, vkr_percent=0.0, pfe_kw=0.0, i0_percent=0.0, shift_degree=0.0, max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus2, length_km=1.0, r_ohm_per_km=0.0, x_ohm_per_km=1.0 / 4.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(5.0), name="line-0", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus2, bus3, length_km=1.0, r_ohm_per_km=0.0, x_ohm_per_km=1.0 / 6.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(5.0), name="line-1", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus3, bus1, length_km=1.0, r_ohm_per_km=0.0, x_ohm_per_km=1.0 / 5.0 * self.base_unit_z, c_nf_per_km=0.0, max_i_ka=self.convert_per_unit_to_ka(4.0), name="line-2", type="ol", max_loading_percent=100.0, ) # Loads pp.create_load(grid, bus1, p_mw=2, name="load-0", controllable=False) pp.create_load(grid, bus2, p_mw=3, name="load-1", controllable=False) pp.create_load(grid, bus3, p_mw=6, name="load-2", controllable=False) # Generators pp.create_gen( grid, bus0, p_mw=0, min_p_mw=0, max_p_mw=1, vm_pu=1.01, name="gen-0", controllable=True, slack=True, ) pp.create_gen( grid, bus2, p_mw=0, min_p_mw=0, max_p_mw=5, vm_pu=1.01, name="gen-1", controllable=True, ) pp.create_gen( grid, bus3, p_mw=0, min_p_mw=0, max_p_mw=8, vm_pu=1.01, name="gen-2", controllable=True, ) # External grids pp.create_ext_grid( grid, bus0, va_degree=0.0, name="ext-grid-0", max_p_mw=3.0, min_p_mw=0.0, max_loading_percent=100.0, ) grid.trafo[ "b_pu"] = 28.0 # Empirically: x = vk_percent / 100 * 1 / sn_mva grid.trafo["max_p_pu"] = 3.5 # sn_mva return grid
def test_pwl(): net = pp.create_empty_network() # create buses bus1 = pp.create_bus(net, vn_kv=110., min_vm_pu=0.9, max_vm_pu=1.1) bus2 = pp.create_bus(net, vn_kv=110., min_vm_pu=0.9, max_vm_pu=1.1) bus3 = pp.create_bus(net, vn_kv=110., min_vm_pu=0.9, max_vm_pu=1.1) # create 110 kV lines pp.create_line(net, bus1, bus2, length_km=50., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus2, bus3, length_km=50., std_type='149-AL1/24-ST1A 110.0') # create loads pp.create_load(net, bus2, p_mw=80, controllable=False) # create generators g1 = pp.create_gen(net, bus1, p_mw=80, min_p_mw=0, max_p_mw=80, vm_pu=1.01, slack=True) g2 = pp.create_gen(net, bus3, p_mw=80, min_p_mw=0, max_p_mw=80, vm_pu=1.01) # net.gen["controllable"] = False pp.create_pwl_cost(net, g1, 'gen', [[0, 2, 2], [2, 80, 5]]) pp.create_pwl_cost(net, g2, 'gen', [[0, 2, 2], [2, 80, 5]]) pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert np.isclose(net.res_gen.p_mw.iloc[0], net.res_gen.p_mw.iloc[1]) assert np.isclose(net.res_gen.q_mvar.iloc[0], net.res_gen.q_mvar.iloc[1]) net.pwl_cost.drop(net.pwl_cost.index, inplace=True) g3 = pp.create_gen(net, bus1, p_mw=80, min_p_mw=0, max_p_mw=80, vm_pu=1.01) pp.create_pwl_cost(net, g1, 'gen', [[0, 2, 1.], [2, 80, 8.]]) pp.create_pwl_cost(net, g2, 'gen', [[0, 3, 2.], [3, 80, 14]]) pp.create_pwl_cost(net, g3, 'gen', [[0, 1, 3.], [1, 80, 10.]]) net.load.p_mw = 1 pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert np.isclose(net.res_gen.p_mw.at[g2], 0) assert np.isclose(net.res_gen.p_mw.at[g3], 0) assert np.isclose(net.res_cost, net.res_gen.p_mw.at[g1], atol=1e-4) net.load.p_mw = 3 pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert np.isclose(net.res_gen.p_mw.at[g3], 0) assert np.isclose(net.res_gen.p_mw.at[g1], 2) assert np.isclose(net.res_cost, net.res_gen.p_mw.at[g1] + net.res_gen.p_mw.at[g2] * 2, atol=1e-4) net.load.p_mw = 5 pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert np.isclose(net.res_gen.p_mw.at[g1], 2) assert np.isclose(net.res_gen.p_mw.at[g2], 3) assert np.isclose(net.res_cost, net.res_gen.p_mw.at[g1] + net.res_gen.p_mw.at[g2] * 2 + net.res_gen.p_mw.at[g3] * 3, atol=1e-4)
try: # plt.tight_layout() plt.show() except: pass if __name__ == "__main__": import pandapower as pp net = pp.create_empty_network() b1 = pp.create_bus(net, 10, geodata=(5, 10)) b2 = pp.create_bus(net, 0.4, geodata=(5, 15)) b3 = pp.create_bus(net, 0.4, geodata=(0, 22)) b4 = pp.create_bus(net, 0.4, geodata=(8, 20)) pp.create_gen(net, b1, p_kw=100) pp.create_load(net, b3, p_kw=100) pp.create_ext_grid(net, b4) pp.create_line(net, b2, b3, 2.0, std_type="NAYY 4x50 SE") pp.create_line(net, b2, b4, 2.0, std_type="NAYY 4x50 SE") pp.create_transformer(net, b1, b2, std_type="0.63 MVA 10/0.4 kV") pp.create_transformer(net, b3, b4, std_type="0.63 MVA 10/0.4 kV") bc = create_bus_collection(net, size=0.2, color="k") lc = create_line_collection(net, use_line_geodata=False, color="k", linewidth=3.) lt, bt = create_trafo_symbol_collection(net, size=2, linewidth=3.) load1, load2 = create_load_symbol_collection(net,
def example_simple(): """ Returns the simple example network from the pandapower tutorials. OUTPUT: net - simple example network EXAMPLE: >>> import pandapower.networks >>> net = pandapower.networks.example_simple() """ net = pp.create_empty_network() # create buses bus1 = pp.create_bus(net, name="HV Busbar", vn_kv=110., type="b") bus2 = pp.create_bus(net, name="HV Busbar 2", vn_kv=110., type="b") bus3 = pp.create_bus(net, name="HV Transformer Bus", vn_kv=110., type="n") bus4 = pp.create_bus(net, name="MV Transformer Bus", vn_kv=20., type="n") bus5 = pp.create_bus(net, name="MV Main Bus", vn_kv=20., type="b") bus6 = pp.create_bus(net, name="MV Bus 1", vn_kv=20., type="b") bus7 = pp.create_bus(net, name="MV Bus 2", vn_kv=20., type="b") # create external grid pp.create_ext_grid(net, bus1, vm_pu=1.02, va_degree=50) # create transformer trafo1 = pp.create_transformer(net, bus3, bus4, name="110kV/20kV transformer", std_type="25 MVA 110/20 kV") # create lines line1 = pp.create_line(net, bus1, bus2, length_km=10, std_type="N2XS(FL)2Y 1x300 RM/35 64/110 kV", name="Line 1") line2 = pp.create_line(net, bus5, bus6, length_km=2.0, std_type="NA2XS2Y 1x240 RM/25 12/20 kV", name="Line 2") line3 = pp.create_line(net, bus6, bus7, length_km=3.5, std_type="48-AL1/8-ST1A 20.0", name="Line 3") line4 = pp.create_line(net, bus7, bus5, length_km=2.5, std_type="NA2XS2Y 1x240 RM/25 12/20 kV", name="Line 4") # create bus-bus switches sw1 = pp.create_switch(net, bus2, bus3, et="b", type="CB") sw2 = pp.create_switch(net, bus4, bus5, et="b", type="CB") # create bus-line switches sw3 = pp.create_switch(net, bus5, line2, et="l", type="LBS", closed=True) sw4 = pp.create_switch(net, bus6, line2, et="l", type="LBS", closed=True) sw5 = pp.create_switch(net, bus6, line3, et="l", type="LBS", closed=True) sw6 = pp.create_switch(net, bus7, line3, et="l", type="LBS", closed=False) sw7 = pp.create_switch(net, bus7, line4, et="l", type="LBS", closed=True) sw8 = pp.create_switch(net, bus5, line4, et="l", type="LBS", closed=True) # create load pp.create_load(net, bus7, p_kw=2000, q_kvar=4000, scaling=0.6, name="load") # create generator pp.create_gen(net, bus6, p_kw=-6000, max_q_kvar=3000, min_q_kvar=-3000, vm_pu=1.03, name="generator") # create static generator pp.create_sgen(net, bus7, p_kw=-2000, q_kvar=500, name="static generator") # create shunt pp.create_shunt(net, bus3, q_kvar=-960, p_kw=0, name='Shunt') return net
def example_multivoltage(): """ Returns the multivoltage example network from the pandapower tutorials. OUTPUT: net - multivoltage example network EXAMPLE: >>> import pandapower.networks >>> net = pandapower.networks.example_multivoltage() """ net = pp.create_empty_network() # --- Busses # HV # Double busbar pp.create_bus(net, name='Double Busbar 1', vn_kv=380, type='b') pp.create_bus(net, name='Double Busbar 2', vn_kv=380, type='b') for i in range(10): pp.create_bus(net, name='Bus DB T%s' % i, vn_kv=380, type='n') for i in range(1, 5): pp.create_bus(net, name='Bus DB %s' % i, vn_kv=380, type='n') # Single busbar pp.create_bus(net, name='Single Busbar', vn_kv=110, type='b') for i in range(1, 6): pp.create_bus(net, name='Bus SB %s' % i, vn_kv=110, type='n') for i in range(1, 6): for j in [1, 2]: pp.create_bus(net, name='Bus SB T%s.%s' % (i, j), vn_kv=110, type='n') # Remaining for i in range(1, 5): pp.create_bus(net, name='Bus HV%s' % i, vn_kv=110, type='n') # MV pp.create_bus(net, name='Bus MV0 20kV', vn_kv=20, type='n') for i in range(8): pp.create_bus(net, name='Bus MV%s' % i, vn_kv=10, type='n') # LV pp.create_bus(net, name='Bus LV0', vn_kv=0.4, type='n') for i in range(1, 6): pp.create_bus(net, name='Bus LV1.%s' % i, vn_kv=0.4, type='m') for i in range(1, 5): pp.create_bus(net, name='Bus LV2.%s' % i, vn_kv=0.4, type='m') pp.create_bus(net, name='Bus LV2.2.1', vn_kv=0.4, type='m') pp.create_bus(net, name='Bus LV2.2.2', vn_kv=0.4, type='m') # --- Lines # HV hv_lines = pd.DataFrame() hv_lines['line_name'] = ['HV Line%s' % i for i in range(1, 7)] hv_lines['from_bus'] = [ 'Bus SB 2', 'Bus HV1', 'Bus HV2', 'Bus HV1', 'Bus HV3', 'Bus SB 3' ] hv_lines['to_bus'] = [ 'Bus HV1', 'Bus HV2', 'Bus HV4', 'Bus HV4', 'Bus HV4', 'Bus HV3' ] hv_lines['std_type'] = '184-AL1/30-ST1A 110.0' hv_lines['length'] = [30, 20, 30, 15, 25, 30] hv_lines['parallel'] = [1, 1, 1, 1, 1, 2] for _, hv_line in hv_lines.iterrows(): from_bus = pp.get_element_index(net, "bus", hv_line.from_bus) to_bus = pp.get_element_index(net, "bus", hv_line.to_bus) pp.create_line(net, from_bus, to_bus, length_km=hv_line.length, std_type=hv_line.std_type, name=hv_line.line_name, parallel=hv_line.parallel) # MV mv_lines = pd.DataFrame() mv_lines['line_name'] = ['MV Line%s' % i for i in range(1, 9)] mv_lines['from_bus'] = ['Bus MV%s' % i for i in list(range(7)) + [0]] mv_lines['to_bus'] = ['Bus MV%s' % i for i in list(range(1, 8)) + [7]] mv_lines['length'] = 1.5 mv_lines['std_type'] = 'NA2XS2Y 1x185 RM/25 12/20 kV' for _, mv_line in mv_lines.iterrows(): from_bus = pp.get_element_index(net, "bus", mv_line.from_bus) to_bus = pp.get_element_index(net, "bus", mv_line.to_bus) pp.create_line(net, from_bus, to_bus, length_km=mv_line.length, std_type=mv_line.std_type, name=mv_line.line_name) # LV lv_lines = pd.DataFrame() lv_line_idx = [ '1.1', '1.2', '1.3', '1.4', '1.6', '2.1', '2.2', '2.3', '2.4', '2.2.1', '2.2.2' ] lv_lines['line_name'] = ['LV Line%s' % i for i in lv_line_idx] lv_line_idx = [ '0', '1.1', '1.2', '1.3', '1.4', '0', '2.1', '2.2', '2.3', '2.2', '2.2.1' ] lv_lines['from_bus'] = ['Bus LV%s' % i for i in lv_line_idx] lv_line_idx = [ '1.1', '1.2', '1.3', '1.4', '1.5', '2.1', '2.2', '2.3', '2.4', '2.2.1', '2.2.2' ] lv_lines['to_bus'] = ['Bus LV%s' % i for i in lv_line_idx] lv_lines['length'] = [0.08] * 5 + [0.12] * 6 lv_lines['std_type'] = ['NAYY 4x120 SE'] * 7 + ['15-AL1/3-ST1A 0.4'] * 4 for _, lv_line in lv_lines.iterrows(): from_bus = pp.get_element_index(net, "bus", lv_line.from_bus) to_bus = pp.get_element_index(net, "bus", lv_line.to_bus) pp.create_line(net, from_bus, to_bus, length_km=lv_line.length, std_type=lv_line.std_type, name=lv_line.line_name) # --- Transformer hv_bus = pp.get_element_index(net, "bus", "Bus DB 2") lv_bus = pp.get_element_index(net, "bus", "Bus SB 1") pp.create_transformer_from_parameters(net, hv_bus, lv_bus, sn_kva=300000, vn_hv_kv=380, vn_lv_kv=110, vscr_percent=0.06, vsc_percent=8, pfe_kw=0, i0_percent=0, tp_pos=0, shift_degree=0, name='EHV-HV-Trafo') hv_bus = pp.get_element_index(net, "bus", "Bus MV4") lv_bus = pp.get_element_index(net, "bus", "Bus LV0") pp.create_transformer_from_parameters(net, hv_bus, lv_bus, sn_kva=400, vn_hv_kv=10, vn_lv_kv=0.4, vscr_percent=1.325, vsc_percent=4, pfe_kw=0.95, i0_percent=0.2375, tp_side="hv", tp_mid=0, tp_min=-2, tp_max=2, tp_st_percent=2.5, tp_pos=0, shift_degree=150, name='MV-LV-Trafo') # Trafo3w hv_bus = pp.get_element_index(net, "bus", "Bus HV2") mv_bus = pp.get_element_index(net, "bus", "Bus MV0 20kV") lv_bus = pp.get_element_index(net, "bus", "Bus MV0") pp.create_transformer3w_from_parameters(net, hv_bus, mv_bus, lv_bus, vn_hv_kv=110, vn_mv_kv=20, vn_lv_kv=10, sn_hv_kva=40000, sn_mv_kva=15000, sn_lv_kva=25000, vsc_hv_percent=10.1, vsc_mv_percent=10.1, vsc_lv_percent=10.1, vscr_hv_percent=0.266667, vscr_mv_percent=0.033333, vscr_lv_percent=0.04, pfe_kw=0, i0_percent=0, shift_mv_degree=30, shift_lv_degree=30, tp_side="hv", tp_mid=0, tp_min=-8, tp_max=8, tp_st_percent=1.25, tp_pos=0, name='HV-MV-MV-Trafo') # --- Static generators # HV pp.create_sgen(net, pp.get_element_index(net, "bus", 'Bus SB 5'), p_kw=-20000, q_kvar=-4000, sn_kva=45000, type='WP', name='Wind Park') # MV mv_sgens = pd.DataFrame() mv_sgens['sgen_name'] = [ 'Biogas plant', 'Further MV Generator', 'Industry Generator', 'PV Park' ] mv_sgens['bus'] = ['Bus MV6', 'Bus MV0', 'Bus MV0 20kV', 'Bus MV5'] mv_sgens['p'] = [-500, -500, -15000, -2000] mv_sgens['q'] = [0, -50, -3000, -100] mv_sgens['sn'] = [750, 1000, 20000, 5000] mv_sgens['type'] = ['SGEN', 'SGEN', 'SGEN', 'PV'] for _, sgen in mv_sgens.iterrows(): bus_idx = pp.get_element_index(net, "bus", sgen.bus) pp.create_sgen(net, bus_idx, p_kw=sgen.p, q_kvar=sgen.q, sn_kva=sgen.sn, type=sgen.type, name=sgen.sgen_name) # LV lv_sgens = pd.DataFrame() lv_sgens['sgen_name'] = ['PV'] + ['PV(%s)' % i for i in range(1, 6)] lv_sgens['bus'] = [ 'Bus LV%s' % i for i in ['1.1', '1.3', '2.3', '2.4', '2.2.1', '2.2.2'] ] lv_sgens['p'] = [-6, -5, -5, -5, -5, -5] lv_sgens['q'] = 0 lv_sgens['sn'] = [12, 10, 10, 10, 10, 10] lv_sgens['type'] = 'PV' for _, sgen in lv_sgens.iterrows(): bus_idx = pp.get_element_index(net, "bus", sgen.bus) pp.create_sgen(net, bus_idx, p_kw=sgen.p, q_kvar=sgen.q, sn_kva=sgen.sn, type=sgen.type, name=sgen.sgen_name) # --- Loads # HV hv_loads = pd.DataFrame() hv_loads['load_name'] = ['MV Net %s' % i for i in range(5)] hv_loads['bus'] = ['Bus SB 4', 'Bus HV1', 'Bus HV2', 'Bus HV3', 'Bus HV4'] hv_loads['p'] = 38000 hv_loads['q'] = 6000 for _, load in hv_loads.iterrows(): bus_idx = pp.get_element_index(net, "bus", load.bus) pp.create_load(net, bus_idx, p_kw=load.p, q_kvar=load.q, name=load.load_name) # MV mv_loads = pd.DataFrame() mv_loads['load_name'] = ['Further MV-Rings', 'Industry Load' ] + ['LV Net %s' % i for i in [1, 2, 3, 5, 6, 7]] mv_loads['bus'] = ['Bus MV0', 'Bus MV0 20kV' ] + ['Bus MV%s' % i for i in [1, 2, 3, 5, 6, 7]] mv_loads['p'] = [6000, 18000, 400, 400, 400, 400, 400, 400] mv_loads['q'] = [2000, 4000, 100, 60, 60, 60, 60, 60] for _, load in mv_loads.iterrows(): bus_idx = pp.get_element_index(net, "bus", load.bus) pp.create_load(net, bus_idx, p_kw=load.p, q_kvar=load.q, name=load.load_name) # LV lv_loads = pd.DataFrame() idx = ['', '(1)', '(2)', '(3)', '(4)', '(5)'] lv_loads['load_name'] = ['Further LV-Feeders Load'] + [ 'Residential Load%s' % i for i in idx[0:5] ] + ['Rural Load%s' % i for i in idx[0:6]] lv_loads['bus'] = [ 'Bus LV%s' % i for i in [ '0', '1.1', '1.2', '1.3', '1.4', '1.5', '2.1', '2.2', '2.3', '2.4', '2.2.1', '2.2.2' ] ] lv_loads['p'] = [100] + [10] * 11 lv_loads['q'] = [10] + [3] * 11 for _, load in lv_loads.iterrows(): bus_idx = pp.get_element_index(net, "bus", load.bus) pp.create_load(net, bus_idx, p_kw=load.p, q_kvar=load.q, name=load.load_name) # --- Other # Shunt pp.create_shunt(net, pp.get_element_index(net, "bus", 'Bus HV1'), p_kw=0, q_kvar=-960, name='Shunt') # ExtGrids pp.create_ext_grid(net, pp.get_element_index(net, "bus", 'Double Busbar 1'), vm_pu=1.03, va_degree=0, name='External grid', s_sc_max_mva=10000, rx_max=0.1, rx_min=0.1) # Gen pp.create_gen(net, pp.get_element_index(net, "bus", 'Bus HV4'), vm_pu=1.03, p_kw=-1e5, name='Gas turbine') # Impedance pp.create_impedance(net, pp.get_element_index(net, "bus", 'Bus HV3'), pp.get_element_index(net, "bus", 'Bus HV1'), rft_pu=0.074873, xft_pu=0.198872, sn_kva=100000, name='Impedance') # xwards pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV3'), ps_kw=23942, qs_kvar=-12241.87, pz_kw=2814.571, qz_kvar=0, r_ohm=0, x_ohm=12.18951, vm_pu=1.02616, name='XWard 1') pp.create_xward(net, pp.get_element_index(net, "bus", 'Bus HV1'), ps_kw=3776, qs_kvar=-7769.979, pz_kw=9174.917, qz_kvar=0, r_ohm=0, x_ohm=50.56217, vm_pu=1.024001, name='XWard 2') # --- Switches # HV # Bus-bus switches hv_bus_sw = pd.DataFrame() hv_bus_sw['bus_name'] = ['DB DS%s' % i for i in range(14)] + \ ['DB CB%s' % i for i in range(5)] + \ ['SB DS%s.%s' % (i, j) for i in range(1, 6) for j in range(1, 3)] + \ ['SB CB%s' % i for i in range(1, 6)] hv_bus_sw['from_bus'] = ['Double Busbar %s' % i for i in [2, 1, 2, 1, 2, 1, 2, 1, 2, 1]] + \ ['Bus DB T%s' % i for i in [2, 4, 6, 8, 0, 3, 5, 7, 9]] + \ ['Bus SB T1.1', 'Single Busbar', 'Bus SB T2.1', 'Single Busbar', 'Bus SB T3.1', 'Single Busbar', 'Bus SB T4.1', 'Single Busbar', 'Bus SB T5.1', 'Single Busbar'] + \ ['Bus SB T%s.2' % i for i in range(1, 6)] hv_bus_sw['to_bus'] = ['Bus DB %s' % i for i in ['T0', 'T1', 'T3', 'T3', 'T5', 'T5', 'T7', 'T7', 'T9', 'T9', '1', '2', '3', '4', 'T1', 'T2', 'T4', 'T6', 'T8']] + \ ['Bus SB %s' % i for i in ['1', 'T1.2', '2', 'T2.2', '3', 'T3.2', '4', 'T4.2', '5', 'T5.2']] + \ ['Bus SB T%s.1' % i for i in range(1, 6)] hv_bus_sw['type'] = ['DS'] * 14 + ['CB'] * 5 + ['DS'] * 10 + ['CB'] * 5 hv_bus_sw['et'] = 'b' hv_bus_sw['closed'] = [ bool(i) for i in [1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1] + [1] * 15 ] for _, switch in hv_bus_sw.iterrows(): from_bus = pp.get_element_index(net, "bus", switch.from_bus) to_bus = pp.get_element_index(net, "bus", switch.to_bus) pp.create_switch(net, from_bus, to_bus, et=switch.et, closed=switch.closed, type=switch.type, name=switch.bus_name) # Bus-Line switches hv_buses = net.bus[(net.bus.vn_kv == 380) | (net.bus.vn_kv == 110)].index hv_ls = net.line[(net.line.from_bus.isin(hv_buses)) & (net.line.to_bus.isin(hv_buses))] for _, line in hv_ls.iterrows(): for bus in [line.from_bus, line.to_bus]: pp.create_switch(net, bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[bus], line['name'])) # MV # Bus-line switches mv_buses = net.bus[(net.bus.vn_kv == 10) | (net.bus.vn_kv == 20)].index mv_ls = net.line[(net.line.from_bus.isin(mv_buses)) & (net.line.to_bus.isin(mv_buses))] for _, line in mv_ls.iterrows(): for bus in [line.from_bus, line.to_bus]: pp.create_switch(net, bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[bus], line['name'])) open_switch_id = net.switch[( net.switch.name == 'Switch Bus MV5 - MV Line5')].index net.switch.closed.loc[open_switch_id] = False # LV # Bus-line switches lv_buses = net.bus[net.bus.vn_kv == 0.4].index lv_ls = net.line[(net.line.from_bus.isin(lv_buses)) & (net.line.to_bus.isin(lv_buses))] for _, line in lv_ls.iterrows(): for bus in [line.from_bus, line.to_bus]: pp.create_switch(net, bus, line.name, et='l', closed=True, type='LBS', name='Switch %s - %s' % (net.bus.name.at[bus], line['name'])) # Trafoswitches # HV pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus DB 2'), pp.get_element_index(net, "trafo", 'EHV-HV-Trafo'), et='t', closed=True, type='LBS', name='Switch DB2 - EHV-HV-Trafo') pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus SB 1'), pp.get_element_index(net, "trafo", 'EHV-HV-Trafo'), et='t', closed=True, type='LBS', name='Switch SB1 - EHV-HV-Trafo') # LV pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus MV4'), pp.get_element_index(net, "trafo", 'MV-LV-Trafo'), et='t', closed=True, type='LBS', name='Switch MV4 - MV-LV-Trafo') pp.create_switch(net, pp.get_element_index(net, "bus", 'Bus LV0'), pp.get_element_index(net, "trafo", 'MV-LV-Trafo'), et='t', closed=True, type='LBS', name='Switch LV0 - MV-LV-Trafo') # --- Powerflow # run power flow and generate result tables pp.runpp(net, init='dc', calculate_voltage_angles=True, Numba=False) return net
def test_cost_piecewise_linear_gen_q(): """ Testing a very simple network for the resulting cost value constraints with OPF """ # boundaries: vm_max = 1.05 vm_min = 0.95 # create net net = pp.create_empty_network() pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_gen(net, 1, p_kw=-100, controllable=True, max_p_kw=-5, min_p_kw=-150, max_q_kvar=50, min_q_kvar=-50) pp.create_ext_grid(net, 0) pp.create_load(net, 1, p_kw=20, controllable=False) pp.create_line_from_parameters(net, 0, 1, 50, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=100 * 690) with pytest.raises(ValueError): pp.create_piecewise_linear_cost(net, 0, "gen", np.array([[0, 0], [1, 50], [2, 100]]), type="q") with pytest.raises(ValueError): pp.create_piecewise_linear_cost(net, 0, "gen", np.array([[0, 0], [-1, 50], [-2, 100]]), type="q") with pytest.raises(ValueError): pp.create_piecewise_linear_cost(net, 0, "gen", np.array([[-10, 0], [-200, 50], [-50, 100]]), type="q") pp.create_piecewise_linear_cost(net, 0, "gen", np.array([[-50, 50], [0, 0], [50, -50]]), type="q") # run OPF pp.runopp(net, verbose=False) assert net["OPF_converged"] assert net.res_cost - net.res_gen.q_kvar.values < 1e-3
def test_drop_inactive_elements(): for service in (False, True): net = pp.create_empty_network() bus_sl = pp.create_bus(net, vn_kv=.4, in_service=service) pp.create_ext_grid(net, bus_sl, in_service=service) bus0 = pp.create_bus(net, vn_kv=.4, in_service=service) pp.create_switch(net, bus_sl, bus0, 'b', not service) bus1 = pp.create_bus(net, vn_kv=.4, in_service=service) pp.create_transformer(net, bus0, bus1, in_service=service, std_type='63 MVA 110/20 kV') bus2 = pp.create_bus(net, vn_kv=.4, in_service=service) pp.create_line(net, bus1, bus2, length_km=1, in_service=service, std_type='149-AL1/24-ST1A 10.0') pp.create_load(net, bus2, p_kw=0., in_service=service) pp.create_sgen(net, bus2, p_kw=0., in_service=service) bus3 = pp.create_bus(net, vn_kv=.4, in_service=service) bus4 = pp.create_bus(net, vn_kv=.4, in_service=service) pp.create_transformer3w_from_parameters(net, bus2, bus3, bus4, 0.4, 0.4, 0.4, 100, 50, 50, 3, 3, 3, 1, 1, 1, 5, 1) # drop them tb.drop_inactive_elements(net) sum_of_elements = 0 for element in net.keys(): # skip this one since we expect items here if element == "std_types" or element.startswith("_"): continue try: if service and (element == 'ext_grid' or (element == 'bus' and len(net.bus) == 1)): # if service==True, the 1 ext_grid and its bus are not dropped continue sum_of_elements += len(net[element]) if len(net[element]) > 0: print(element) except TypeError: # _ppc is initialized with None and clashes when checking continue assert sum_of_elements == 0 if service: assert len(net.ext_grid) == 1 assert len(net.bus) == 1 assert bus_sl in net.bus.index.values net = pp.create_empty_network() bus0 = pp.create_bus(net, vn_kv=.4, in_service=True) pp.create_ext_grid(net, bus0, in_service=True) bus1 = pp.create_bus(net, vn_kv=.4, in_service=False) pp.create_line(net, bus0, bus1, length_km=1, in_service=False, std_type='149-AL1/24-ST1A 10.0') gen0 = pp.create_gen(net, bus=bus1, p_kw=1) tb.drop_inactive_elements(net) assert gen0 not in net.gen.index
def simple_test_net(): net = pp.create_empty_network() # I am going to define here the buses which form the system. As there are no transformers, # the voltage is the same in every busbar Bus_Voltage = 110 # in kv Bus_1 = pp.create_bus(net, Bus_Voltage, name='Bus 1-CLARK') Bus_2 = pp.create_bus(net, Bus_Voltage, name='Bus 2-AMHERST') Bus_3 = pp.create_bus(net, Bus_Voltage, name='Bus 3-WINLOCK') Bus_4 = pp.create_bus(net, Bus_Voltage, name='Bus 4-BOWMAN') Bus_5 = pp.create_bus(net, Bus_Voltage, name='Bus 5-TROY') Bus_6 = pp.create_bus(net, Bus_Voltage, name='Bus 6-MAPLE') Bus_7 = pp.create_bus(net, Bus_Voltage, name='Bus 7-GRAND') Bus_8 = pp.create_bus(net, Bus_Voltage, name='Bus 8-WAUTAGA') Bus_9 = pp.create_bus(net, Bus_Voltage, name='Bus 9-CROSS') # Next step is create the generators of the system, we know from the assignment that # Bus 1 is the slack bus along with generation capable of supplying the system should # another generator fall out of operation. Generator1_Pg_MW = 0 Generator2_Pg_MW = 163 Generator3_Pg_MW = 85 # Q generated is 0 for all generators Generator_1 = pp.create_gen(net, Bus_1, Generator1_Pg_MW, slack=True, name='Generator 1') Generator_2 = pp.create_sgen(net, Bus_2, Generator2_Pg_MW, q_mvar=0, name='Generator 2') Generator_3 = pp.create_sgen(net, Bus_3, Generator3_Pg_MW, q_mvar=0, name='Generator 3') # In order to create the loads we need to define the P and Q consumed by each load Load5_Pd_MW = 90 Load5_Qd_MVAR = 30 Load7_Pd_MW = 100 Load7_Qd_MVAR = 35 Load9_Pd_MW = 125 Load9_Qd_MVAR = 50 Load_5 = pp.create_load(net, Bus_5, Load5_Pd_MW, Load5_Qd_MVAR, name='Load 5') Load_7 = pp.create_load(net, Bus_7, Load7_Pd_MW, Load7_Qd_MVAR, name='Load 7') Load_9 = pp.create_load(net, Bus_9, Load9_Pd_MW, Load9_Qd_MVAR, name='Load 9') Line_length = 10 # in km Line_1_4 = pp.create_line(net, Bus_1, Bus_4, Line_length, '149-AL1/24-ST1A 110.0', name='Line 1 to 4') Line_2_8 = pp.create_line(net, Bus_2, Bus_8, Line_length, '149-AL1/24-ST1A 110.0', name='Line 2 to 8') Line_3_6 = pp.create_line(net, Bus_3, Bus_6, Line_length, '149-AL1/24-ST1A 110.0', name='Line 3 to 6') Line_4_5 = pp.create_line(net, Bus_4, Bus_5, Line_length, '149-AL1/24-ST1A 110.0', name='Line 4 to 5') Line_4_9 = pp.create_line(net, Bus_4, Bus_9, Line_length, '149-AL1/24-ST1A 110.0', name='Line 4 to 9') Line_5_6 = pp.create_line(net, Bus_5, Bus_6, Line_length, '149-AL1/24-ST1A 110.0', name='Line 5 to 6') Line_6_7 = pp.create_line(net, Bus_6, Bus_7, Line_length, '149-AL1/24-ST1A 110.0', name='Line 6 to 7') Line_7_8 = pp.create_line(net, Bus_7, Bus_8, Line_length, '149-AL1/24-ST1A 110.0', name='Line 7 to 8') Line_8_9 = pp.create_line(net, Bus_8, Bus_9, Line_length, '149-AL1/24-ST1A 110.0', name='Line 8 to 9') return net
# create load pp.create_load(net, bus7, p_kw=2000, q_kvar=4000, scaling=0.6, name="load") # show load table load = net.load # create static generator pp.create_sgen(net, bus7, p_kw=-2000, q_kvar=500, name="static generator") # show static generator table gen_s = net.sgen # create voltage controlled generator pp.create_gen(net, bus6, p_kw=-6000, max_q_kvar=3000, min_q_kvar=-3000, vm_pu=1.03, name="generator") # show voltage controlled generator table gen_vc = net.gen # create shunt pp.create_shunt(net, bus3, q_kvar=-960, p_kw=0, name='Shunt') # show shunt table shunt = net.shunt
def test_without_ext_grid(): net = pp.create_empty_network() min_vm_pu = 0.95 max_vm_pu = 1.05 # create buses bus1 = pp.create_bus(net, vn_kv=220., geodata=(5, 9)) bus2 = pp.create_bus(net, vn_kv=110., geodata=(6, 10), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus3 = pp.create_bus(net, vn_kv=110., geodata=(10, 9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus4 = pp.create_bus(net, vn_kv=110., geodata=(8, 8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus5 = pp.create_bus(net, vn_kv=110., geodata=(6, 8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) # create 220/110/110 kV 3W-transformer pp.create_transformer3w_from_parameters(net, bus1, bus2, bus5, vn_hv_kv=220, vn_mv_kv=110, vn_lv_kv=110, vk_hv_percent=10., vk_mv_percent=10., vk_lv_percent=10., vkr_hv_percent=0.5, vkr_mv_percent=0.5, vkr_lv_percent=0.5, pfe_kw=100, i0_percent=0.1, shift_mv_degree=0, shift_lv_degree=0, sn_hv_mva=100, sn_mv_mva=50, sn_lv_mva=50) # create 110 kV lines pp.create_line(net, bus2, bus3, length_km=70., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus3, bus4, length_km=50., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus4, bus2, length_km=40., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus4, bus5, length_km=30., std_type='149-AL1/24-ST1A 110.0') # create loads pp.create_load(net, bus2, p_mw=60, controllable=False) pp.create_load(net, bus3, p_mw=70, controllable=False) pp.create_load(net, bus4, p_mw=10, controllable=False) # create generators g1 = pp.create_gen(net, bus1, p_mw=40, min_p_mw=0, min_q_mvar=-20, max_q_mvar=20, slack=True, min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) pp.create_poly_cost(net, g1, 'gen', cp1_eur_per_mw=1000) g2 = pp.create_gen(net, bus3, p_mw=40, min_p_mw=0, min_q_mvar=-20, max_q_mvar=20, vm_pu=1.01, min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu, max_p_mw=40.) pp.create_poly_cost(net, g2, 'gen', cp1_eur_per_mw=2000) g3 = pp.create_gen(net, bus4, p_mw=0.050, min_p_mw=0, min_q_mvar=-20, max_q_mvar=20, vm_pu=1.01, min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu, max_p_mw=0.05) pp.create_poly_cost(net, g3, 'gen', cp1_eur_per_mw=3000) pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert np.isclose(net.res_gen.p_mw.at[g2], 0, atol=1e-5, rtol=1e-5) assert np.isclose(net.res_gen.p_mw.at[g3], 0, atol=1e-5, rtol=1e-5) assert np.isclose(net.res_cost, net.res_gen.p_mw.at[g1] * 1e3) net.trafo3w["max_loading_percent"] = 150. pp.runpm_ac_opf(net) consistency_checks(net, rtol=1e-3) assert 149. < net.res_trafo3w.loading_percent.values[0] < 150.01 assert np.isclose( net.res_cost, net.res_gen.p_mw.at[g1] * 1e3 + net.res_gen.p_mw.at[g2] * 2e3) pp.runpm_dc_opf(net) consistency_checks(net, rtol=1e-3, test_q=False) assert 149. < net.res_trafo3w.loading_percent.values[0] < 150.01 assert np.isclose( net.res_cost, net.res_gen.p_mw.at[g1] * 1e3 + net.res_gen.p_mw.at[g2] * 2e3)
def from_ppc(ppc, f_hz=50, validate_conversion=False): """ This function converts pypower case files to pandapower net structure. INPUT: **ppc** - The pypower case file. OPTIONAL: **f_hz** - The frequency of the network. OUTPUT: **net** EXAMPLE: import pandapower.converter as pc from pypower import case4gs ppc_net = case4gs.case4gs() pp_net = cv.from_ppc(ppc_net, f_hz=60) """ # --- catch common failures if Series(ppc['bus'][:, 9] <= 0).any(): logger.info('There are false baseKV given in the pypower case file.') # --- general_parameters baseMVA = ppc['baseMVA'] # MVA omega = pi * f_hz # 1/s MAX_VAL = 99999. net = pp.create_empty_network(f_hz=f_hz) # --- bus data -> create buses, sgen, load, shunt for i in range(len(ppc['bus'])): # create buses pp.create_bus(net, name=int(ppc['bus'][i, 0]), vn_kv=ppc['bus'][i, 9], type="b", zone=ppc['bus'][i, 6], in_service=bool(ppc['bus'][i, 1] != 4), max_vm_pu=ppc['bus'][i, 11], min_vm_pu=ppc['bus'][i, 12]) # create sgen, load if ppc['bus'][i, 2] > 0: pp.create_load(net, i, p_kw=ppc['bus'][i, 2] * 1e3, q_kvar=ppc['bus'][i, 3] * 1e3) elif ppc['bus'][i, 2] < 0: pp.create_sgen(net, i, p_kw=ppc['bus'][i, 2] * 1e3, q_kvar=ppc['bus'][i, 3] * 1e3, type="") elif ppc['bus'][i, 3] != 0: pp.create_load(net, i, p_kw=ppc['bus'][i, 2] * 1e3, q_kvar=ppc['bus'][i, 3] * 1e3) # create shunt if ppc['bus'][i, 4] != 0 or ppc['bus'][i, 5] != 0: pp.create_shunt(net, i, p_kw=ppc['bus'][i, 4] * 1e3, q_kvar=-ppc['bus'][i, 5] * 1e3) # unused data of ppc: Vm, Va (partwise: in ext_grid), zone # --- gen data -> create ext_grid, gen, sgen for i in range(len(ppc['gen'])): # if in ppc is only one gen -> numpy initially uses one dim array -> change to two dim array if len(ppc["gen"].shape) == 1: ppc["gen"] = array(ppc["gen"], ndmin=2) current_bus_idx = pp.get_element_index(net, 'bus', name=int(ppc['gen'][i, 0])) current_bus_type = int(ppc['bus'][current_bus_idx, 1]) # create ext_grid if current_bus_type == 3: if len(pp.get_connected_elements(net, 'ext_grid', current_bus_idx)) > 0: logger.info('At bus %d an ext_grid already exists. ' % current_bus_idx + 'Because of that generator %d ' % i + 'is converted not as an ext_grid but as a sgen') current_bus_type = 1 else: pp.create_ext_grid(net, bus=current_bus_idx, vm_pu=ppc['gen'][i, 5], va_degree=ppc['bus'][current_bus_idx, 8], in_service=bool(ppc['gen'][i, 7] > 0), max_p_kw=-ppc['gen'][i, 9] * 1e3, min_p_kw=-ppc['gen'][i, 8] * 1e3, max_q_kvar=ppc['gen'][i, 3] * 1e3, min_q_kvar=ppc['gen'][i, 4] * 1e3) if ppc['gen'][i, 4] > ppc['gen'][i, 3]: logger.info( 'min_q_kvar of gen %d must be less than max_q_kvar but is not.' % i) if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]: logger.info( 'max_p_kw of gen %d must be less than min_p_kw but is not.' % i) # create gen elif current_bus_type == 2: pp.create_gen(net, bus=current_bus_idx, vm_pu=ppc['gen'][i, 5], p_kw=-ppc['gen'][i, 1] * 1e3, in_service=bool(ppc['gen'][i, 7] > 0), max_p_kw=-ppc['gen'][i, 9] * 1e3, min_p_kw=-ppc['gen'][i, 8] * 1e3, max_q_kvar=ppc['gen'][i, 3] * 1e3, min_q_kvar=ppc['gen'][i, 4] * 1e3, controllable=True) if ppc['gen'][i, 4] > ppc['gen'][i, 3]: logger.info( 'min_q_kvar of gen %d must be less than max_q_kvar but is not.' % i) if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]: logger.info( 'max_p_kw of gen %d must be less than min_p_kw but is not.' % i) # create sgen if current_bus_type == 1: pp.create_sgen(net, bus=current_bus_idx, p_kw=-ppc['gen'][i, 1] * 1e3, q_kvar=-ppc['gen'][i, 2] * 1e3, type="", in_service=bool(ppc['gen'][i, 7] > 0), max_p_kw=-ppc['gen'][i, 9] * 1e3, min_p_kw=-ppc['gen'][i, 8] * 1e3, max_q_kvar=ppc['gen'][i, 3] * 1e3, min_q_kvar=ppc['gen'][i, 4] * 1e3, controllable=True) if ppc['gen'][i, 4] > ppc['gen'][i, 3]: logger.info( 'min_q_kvar of gen %d must be less than max_q_kvar but is not.' % i) if -ppc['gen'][i, 9] < -ppc['gen'][i, 8]: logger.info( 'max_p_kw of gen %d must be less than min_p_kw but is not.' % i) # unused data of ppc: Vg (partwise: in ext_grid and gen), mBase, Pc1, Pc2, Qc1min, Qc1max, # Qc2min, Qc2max, ramp_agc, ramp_10, ramp_30,ramp_q, apf # --- branch data -> create line, trafo for i in range(len(ppc['branch'])): from_bus = pp.get_element_index(net, 'bus', name=int(ppc['branch'][i, 0])) to_bus = pp.get_element_index(net, 'bus', name=int(ppc['branch'][i, 1])) from_vn_kv = ppc['bus'][from_bus, 9] to_vn_kv = ppc['bus'][to_bus, 9] if (from_vn_kv == to_vn_kv) & ((ppc['branch'][i, 8] == 0) | (ppc['branch'][i, 8] == 1)) & \ (ppc['branch'][i, 9] == 0): Zni = ppc['bus'][to_bus, 9]**2 / baseMVA # ohm max_i_ka = ppc['branch'][i, 5] / ppc['bus'][to_bus, 9] if max_i_ka == 0.0: max_i_ka = MAX_VAL logger.debug( "ppc branch rateA is zero -> Using MAX_VAL instead to calculate " + "maximum branch flow") pp.create_line_from_parameters( net, from_bus=from_bus, to_bus=to_bus, length_km=1, r_ohm_per_km=ppc['branch'][i, 2] * Zni, x_ohm_per_km=ppc['branch'][i, 3] * Zni, c_nf_per_km=ppc['branch'][i, 4] / Zni / omega * 1e9 / 2, max_i_ka=max_i_ka, type='ol', in_service=bool(ppc['branch'][i, 10])) else: if from_vn_kv >= to_vn_kv: hv_bus = from_bus vn_hv_kv = from_vn_kv lv_bus = to_bus vn_lv_kv = to_vn_kv tp_side = 'hv' else: hv_bus = to_bus vn_hv_kv = to_vn_kv lv_bus = from_bus vn_lv_kv = from_vn_kv tp_side = 'lv' if from_vn_kv == to_vn_kv: logger.warning( 'The pypower branch %d (from_bus, to_bus)=(%d, %d) is considered' ' as a transformer because of a ratio != 0 | 1 but it connects ' 'the same voltage level', i, ppc['branch'][i, 0], ppc['branch'][i, 1]) rk = ppc['branch'][i, 2] xk = ppc['branch'][i, 3] zk = (rk**2 + xk**2)**0.5 sn = ppc['branch'][i, 5] * 1e3 if sn == 0.0: sn = MAX_VAL logger.debug( "ppc branch rateA is zero -> Using MAX_VAL instead to calculate " + "apparent power") ratio_1 = 0 if ppc['branch'][i, 8] == 0 else (ppc['branch'][i, 8] - 1) * 100 i0_percent = -ppc['branch'][i, 4] * 100 * baseMVA * 1e3 / sn if i0_percent < 0: logger.info( 'A transformer always behaves inductive consumpting but the ' 'susceptance of pypower branch %d (from_bus, to_bus)=(%d, %d) is ' 'positive.', i, ppc['branch'][i, 0], ppc['branch'][i, 1]) pp.create_transformer_from_parameters( net, hv_bus=hv_bus, lv_bus=lv_bus, sn_kva=sn, vn_hv_kv=vn_hv_kv, vn_lv_kv=vn_lv_kv, vsc_percent=zk * sn / 1e3, vscr_percent=rk * sn / 1e3, pfe_kw=0, i0_percent=i0_percent, shift_degree=ppc['branch'][i, 9], tp_st_percent=abs(ratio_1) if ratio_1 else nan, tp_pos=sign(ratio_1) if ratio_1 else nan, tp_side=tp_side if ratio_1 else None, tp_mid=0 if ratio_1 else nan) # unused data of ppc: rateB, rateC # ToDo: gencost, areas are currently unconverted if validate_conversion: # set logger level to debug logger.setLevel(10) if not validate_from_ppc(ppc, net): logger.error("Validation failed.") return net
def net_3w_trafo_opf(): net = pp.create_empty_network() # create buses bus1 = pp.create_bus(net, vn_kv=220.) bus2 = pp.create_bus(net, vn_kv=110.) bus3 = pp.create_bus(net, vn_kv=110.) bus4 = pp.create_bus(net, vn_kv=110.) bus5 = pp.create_bus(net, vn_kv=110.) pp.create_bus(net, vn_kv=110., in_service=False) # create 220/110 kV transformer pp.create_transformer3w_from_parameters(net, bus1, bus2, bus5, vn_hv_kv=220, vn_mv_kv=110, vn_lv_kv=110, vk_hv_percent=10., vk_mv_percent=10., vk_lv_percent=10., vkr_hv_percent=0.5, vkr_mv_percent=0.5, vkr_lv_percent=0.5, pfe_kw=100, i0_percent=0.1, shift_mv_degree=0, shift_lv_degree=0, sn_hv_mva=100, sn_mv_mva=50, sn_lv_mva=50) # create 110 kV lines pp.create_line(net, bus2, bus3, length_km=70., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus3, bus4, length_km=50., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus4, bus2, length_km=40., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus4, bus5, length_km=30., std_type='149-AL1/24-ST1A 110.0') # create loads pp.create_load(net, bus2, p_mw=60, controllable=False) pp.create_load(net, bus3, p_mw=70, controllable=False) pp.create_sgen(net, bus3, p_mw=10, controllable=False) # create generators pp.create_ext_grid(net, bus1, min_p_mw=0, max_p_mw=1000, max_q_mvar=0.01, min_q_mvar=0) pp.create_gen(net, bus3, p_mw=80, min_p_mw=0, max_p_mw=80, vm_pu=1.01) pp.create_gen(net, bus4, p_mw=80, min_p_mw=0, max_p_mw=80, vm_pu=1.01) net.gen["controllable"] = False return net
bus5, length_km=30., std_type='149-AL1/24-ST1A 110.0') net.line["max_loading_percent"] = 30 #create loads pp.create_load(net, bus2, p_kw=60e3, controllable=False) pp.create_load(net, bus3, p_kw=70e3, controllable=False) pp.create_load(net, bus4, p_kw=10e3, controllable=False) #create generators eg = pp.create_ext_grid(net, bus1, min_p_kw=-1e9, max_p_kw=1e9) g0 = pp.create_gen(net, bus3, p_kw=-80 * 1e3, min_p_kw=-80e3, max_p_kw=0, vm_pu=1.01, controllable=True) g1 = pp.create_gen(net, bus4, p_kw=-100 * 1e3, min_p_kw=-100e3, max_p_kw=0, vm_pu=1.01, controllable=True) costeg = pp.create_polynomial_cost(net, 0, 'ext_grid', np.array([-1, 0])) costgen1 = pp.create_polynomial_cost(net, 0, 'gen', np.array([-1, 0])) costgen2 = pp.create_polynomial_cost(net, 1, 'gen', np.array([-1, 0]))
def tnep_grid(): net = pp.create_empty_network() min_vm_pu = 0.95 max_vm_pu = 1.05 # create buses bus1 = pp.create_bus(net, vn_kv=110., geodata=(5, 9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus2 = pp.create_bus(net, vn_kv=110., geodata=(6, 10), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus3 = pp.create_bus(net, vn_kv=110., geodata=(10, 9), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus4 = pp.create_bus(net, vn_kv=110., geodata=(8, 8), min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) # create 110 kV lines pp.create_line(net, bus1, bus2, length_km=70., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus1, bus3, length_km=50., std_type='149-AL1/24-ST1A 110.0') pp.create_line(net, bus1, bus4, length_km=100., std_type='149-AL1/24-ST1A 110.0') # create loads pp.create_load(net, bus2, p_mw=60) pp.create_load(net, bus3, p_mw=70) pp.create_load(net, bus4, p_mw=50) # create generators g1 = pp.create_gen(net, bus1, p_mw=9.513270, min_p_mw=0, max_p_mw=200, vm_pu=1.01, slack=True) pp.create_poly_cost(net, g1, 'gen', cp1_eur_per_mw=1) g2 = pp.create_gen(net, bus2, p_mw=78.403291, min_p_mw=0, max_p_mw=200, vm_pu=1.01) pp.create_poly_cost(net, g2, 'gen', cp1_eur_per_mw=3) g3 = pp.create_gen(net, bus3, p_mw=92.375601, min_p_mw=0, max_p_mw=200, vm_pu=1.01) pp.create_poly_cost(net, g3, 'gen', cp1_eur_per_mw=3) net.line["max_loading_percent"] = 20 # possible new lines (set out of service in line DataFrame) l1 = pp.create_line(net, bus1, bus4, 10., std_type="305-AL1/39-ST1A 110.0", name="new_line1", max_loading_percent=20., in_service=False) l2 = pp.create_line(net, bus2, bus4, 20., std_type="149-AL1/24-ST1A 110.0", name="new_line2", max_loading_percent=20., in_service=False) l3 = pp.create_line(net, bus3, bus4, 30., std_type='149-AL1/24-ST1A 110.0', name="new_line3", max_loading_percent=20., in_service=False) l4 = pp.create_line(net, bus3, bus4, 40., std_type='149-AL1/24-ST1A 110.0', name="new_line4", max_loading_percent=20., in_service=False) new_line_index = [l1, l2, l3, l4] construction_costs = [10., 20., 30., 45.] # create new line dataframe init_ne_line(net, new_line_index, construction_costs) return net
def build_case_grid(self): grid = pp.create_empty_network() # Buses # Substation bus 1 bus0 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-0-0") bus1 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-1-1") bus2 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-2-2") bus3 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-3-3") bus4 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-4-4") bus5 = pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-5-5") # Substation bus 2 pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-6-0") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-7-1") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-8-2") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-9-3") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-10-4") pp.create_bus(grid, vn_kv=self.base_unit_v / 1000, name="bus-11-5") # Lines pp.create_line_from_parameters( grid, bus0, bus1, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 4.0 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-0", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus0, bus3, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 4.706 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-1", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus0, bus4, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 3.102 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-2", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus2, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 3.846 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-3", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus3, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 8.001 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-4", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus4, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 3.0 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-5", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus1, bus5, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 1.454 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-6", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus2, bus4, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 3.175 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-7", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus2, bus5, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 9.6157 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-8", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus3, bus4, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 2.0 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-9", type="ol", max_loading_percent=100.0, ) pp.create_line_from_parameters( grid, bus4, bus5, length_km=1.0, r_ohm_per_km=1e-3 * self.base_unit_z, # Dummy x_ohm_per_km=1.0 / 3.0 * self.base_unit_z, c_nf_per_km=0.0, # Dummy max_i_ka=self.convert_per_unit_to_ka(2.0), name="line-10", type="ol", max_loading_percent=100.0, ) # Loads pp.create_load( grid, bus3, p_mw=self.convert_per_unit_to_mw(0.9), name="load-0", controllable=False, ) pp.create_load( grid, bus4, p_mw=self.convert_per_unit_to_mw(1.0), name="load-1", controllable=False, ) pp.create_load( grid, bus5, p_mw=self.convert_per_unit_to_mw(0.9), name="load-2", controllable=False, ) # Generators pp.create_gen( grid, bus0, p_mw=self.convert_per_unit_to_mw(1.0), min_p_mw=self.convert_per_unit_to_mw(0.5), max_p_mw=self.convert_per_unit_to_mw(1.5), slack=True, name="gen-0", ) pp.create_gen( grid, bus1, p_mw=self.convert_per_unit_to_mw(0.9), min_p_mw=self.convert_per_unit_to_mw(0.5), max_p_mw=self.convert_per_unit_to_mw(2.0), name="gen-1", ) pp.create_gen( grid, bus2, p_mw=self.convert_per_unit_to_mw(0.9), min_p_mw=self.convert_per_unit_to_mw(0.3), max_p_mw=self.convert_per_unit_to_mw(1.0), name="gen-2", ) return grid
def test_cost_mixed(): """ Testing a very simple network for the resulting cost value constraints with OPF """ vm_max = 1.05 vm_min = 0.95 # create net net = pp.create_empty_network() pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_gen(net, 1, p_mw=-0.1, controllable=True, min_p_mw=0.005, max_p_mw=0.15, max_q_mvar=.05, min_q_mvar=-.05) pp.create_ext_grid(net, 0) pp.create_load(net, 1, p_mw=0.02, controllable=False, max_q_mvar=.05, max_p_mw=0.1, min_p_mw=0.0050, min_q_mvar=-.05) pp.create_line_from_parameters(net, 0, 1, 50, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=100 * 690) # testing some combinations pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=1) pp.runopp(net) assert net["OPF_converged"] assert np.isclose(net.res_cost, net.res_gen.p_mw.values[0]) net.poly_cost.cp1_eur_per_mw.at[0] = 0 net.poly_cost.cp2_eur_per_mw2.at[0] = 1 pp.runopp(net) assert net["OPF_converged"] assert np.isclose(net.res_cost, net.res_gen.p_mw.values**2) net.poly_cost.cp0_eur.at[0] = 1 pp.runopp(net) assert net["OPF_converged"] assert np.isclose(net.res_cost, net.res_gen.p_mw.values**2 + 1) net.load.controllable.at[0] = True pp.runopp(net) assert np.isclose(net.res_cost, net.res_gen.p_mw.values**2 + 1) net.load.controllable.at[0] = False net.pwl_cost.drop(net.pwl_cost.index, inplace=True) pp.create_pwl_cost(net, 0, "ext_grid", [[-1000, 0, -2000], [0, 1000, 2000]], power_type="p") net.poly_cost.cp1_eur_per_mw.at[0] = 1000 net.poly_cost.cp2_eur_per_mw2.at[0] = 0 pp.runopp(net) assert np.isclose(net.res_ext_grid.p_mw.values[0], 0, atol=1e-4) assert np.isclose(net.res_cost, net.res_gen.p_mw.values[0] * 1000, atol=1e-3)
def test_gen_oos(): net = small_example_grid() pp.create_gen(net, 2, 200, 1., slack_weight=2, in_service=False) run_and_assert_numba(net) assert_results_correct(net)
def test_opf_gen_voltage(): """ Testing a simple network with transformer for voltage constraints with OPF using a generator """ # boundaries: vm_max = 1.05 vm_min = 0.95 # ceate net net = pp.create_empty_network() pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75, tap_max=2, vn_lv_kv=0.4, shift_degree=150, tap_neutral=0, vn_hv_kv=10.0, vkr_percent=2.8125, tap_pos=0, tap_side="hv", tap_min=-2, tap_step_percent=2.5, i0_percent=0.68751, sn_mva=0.016, pfe_kw=0.11, name=None, in_service=True, index=None, max_loading_percent=200) pp.create_gen(net, 3, p_mw=0.01, controllable=True, min_p_mw=0, max_p_mw=0.025, max_q_mvar=0.5, min_q_mvar=-0.5) pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=10) pp.create_ext_grid(net, 0) pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=100000) pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=100000) # run OPF for init in ["pf", "flat"]: pp.runopp(net, init=init, calculate_voltage_angles=False) assert net["OPF_converged"] # check and assert result logger.debug("test_opf_gen_voltage") logger.debug("res_gen:\n%s" % net.res_gen) logger.debug("res_bus.vm_pu: \n%s" % net.res_bus.vm_pu) assert max(net.res_bus.vm_pu) < vm_max assert min(net.res_bus.vm_pu) > vm_min
import pandapower as pp net = pp.create_empty_network() min_vm_pu = .95 max_vm_pu = 1.05 # create buses bus1 = pp.create_bus(net, vn_kv=110., min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus2 = pp.create_bus(net, vn_kv=110., min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) bus3 = pp.create_bus(net, vn_kv=110., min_vm_pu=min_vm_pu, max_vm_pu=max_vm_pu) # create 110 kV lines l1 = pp.create_line(net, bus1, bus2, length_km=1., std_type='149-AL1/24-ST1A 110.0') l2 = pp.create_line(net, bus2, bus3, length_km=1., std_type='149-AL1/24-ST1A 110.0') l3 = pp.create_line(net, bus3, bus1, length_km=1., std_type='149-AL1/24-ST1A 110.0') # create loads pp.create_load(net, bus3, p_mw=300) # create generators g1 = pp.create_gen(net, bus1, p_mw=200, min_p_mw=0, max_p_mw=300, controllable=True, slack=True) g2 = pp.create_gen(net, bus2, p_mw=0, min_p_mw=0, max_p_mw=300, controllable=True) g3 = pp.create_gen(net, bus3, p_mw=0, min_p_mw=0, max_p_mw=300, controllable=True) pp.create_poly_cost(net, element=g1, et="gen", cp1_eur_per_mw=30) pp.create_poly_cost(net, element=g2, et="gen", cp1_eur_per_mw=30) pp.create_poly_cost(net, element=g3, et="gen", cp1_eur_per_mw=29.999) pp.runopp(net) print(net.res_gen)
def add_test_oos_bus_with_is_element(net): b1, b2, ln = add_grid_connection(net, zone="test_oos_bus_with_is_element") pl = 1.200 ql = 1.100 ps = -0.500 vm_set_pu = 1.0 pz = 1.200 qz = 1.100 qs = 0.200 vm_pu = 1.06 r_ohm = 50 x_ohm = 70 # OOS buses b3 = pp.create_bus(net, zone="test_oos_bus_with_is_element", vn_kv=0.4, in_service=False) b4 = pp.create_bus(net, zone="test_oos_bus_with_is_element", vn_kv=0.4, in_service=False) b5 = pp.create_bus(net, zone="test_oos_bus_with_is_element", vn_kv=0.4, in_service=False) pp.create_line_from_parameters(net, b2, b3, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12, c_nf_per_km=300, max_i_ka=.2, df=.8) pp.create_line_from_parameters(net, b2, b4, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12, c_nf_per_km=300, max_i_ka=.2, df=.8) pp.create_line_from_parameters(net, b2, b5, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12, c_nf_per_km=300, max_i_ka=.2, df=.8) # in service elements pp.create_load(net, b3, p_mw=pl, q_mvar=ql) pp.create_gen(net, b4, p_mw=ps, vm_pu=vm_set_pu) pp.create_sgen(net, b5, p_mw=ps, q_mvar=ql) pp.create_ward(net, b3, pz_mw=pz, qz_mvar=qz, ps_mw=ps, qs_mvar=qs) pp.create_xward(net, b4, pz_mw=0.5 * pz, qz_mvar=0.5 * qz, ps_mw=0.5 * ps, qs_mvar=0.5 * qs, vm_pu=vm_pu, x_ohm=x_ohm, r_ohm=r_ohm) pp.create_shunt(net, b5, q_mvar=-800, p_mw=0) net.last_added_case = "test_oos_bus_with_is_element" return net
bus1 = pp.create_bus (net, vn_kv=230, name='Bus2', index=1, geodata=None, type='b', zone=1, in_service=True, max_vm_pu=1.1, min_vm_pu=0.9, coords=None) bus2 = pp.create_bus (net, vn_kv=230, name='Bus3', index=2, geodata=None, type='b', zone=1, in_service=True, max_vm_pu=1.1, min_vm_pu=0.9, coords=None) bus3 = pp.create_bus (net, vn_kv=230, name='Bus4', index=3, geodata=None, type='b', zone=1, in_service=True, max_vm_pu=1.1, min_vm_pu=0.9, coords=None) #Load definition load0 = pp.create_load(net, bus0, p_mw=50, q_mvar=30.99, const_z_percent=0, const_i_percent=0, name=None, scaling=1.0, index=0, in_service=True, type=None, controllable=False) load1 = pp.create_load(net, bus1, p_mw=170, q_mvar=105.35, const_z_percent=0, const_i_percent=0, name=None, scaling=1.0, index=1, in_service=True, type=None, controllable=False) load2 = pp.create_load(net, bus2, p_mw=200, q_mvar=123.94, const_z_percent=0, const_i_percent=0, name=None, scaling=1.0, index=2, in_service=True, type=None, controllable=False) load3 = pp.create_load(net, bus3, p_mw=80, q_mvar=49.58, const_z_percent=0, const_i_percent=0, name=None, scaling=1.0, index=3, in_service=True, type=None, controllable=False) #External grid definition pp.create_ext_grid(net, bus0, vm_pu=1.0, va_degree=0.0, name=None, in_service=True, max_p_mw=0, min_p_mw=0, max_q_mvar=100, min_q_mvar=-100, index=0) #Generation definition gen0 = pp.create_gen(net, bus3, p_mw=318, vm_pu=1.02, name=None, index=0, max_q_mvar=100, min_q_mvar=-100, min_p_mw=0, max_p_mw=318, scaling=1.0, type=None, slack=False, controllable=True, in_service=True) #Line definition line0 = pp.create_line_from_parameters(net, from_bus = 0, to_bus = 1, length_km = 1, r_ohm_per_km = 5.33232, x_ohm_per_km = 26.6616, c_nf_per_km = 513.969, max_i_ka = 0.627555, name=None, index=0, type = 'ol', in_service=True, df=1.0, parallel=1, g_us_per_km=0.0, max_loading_percent=100) line1 = pp.create_line_from_parameters(net, from_bus = 0, to_bus = 2, length_km = 1, r_ohm_per_km = 3.93576, x_ohm_per_km = 19.6788, c_nf_per_km = 388.611, max_i_ka = 0.627555, name=None, index=1, type = 'ol', in_service=True, df=1.0, parallel=1, g_us_per_km=0.0, max_loading_percent=100) line2 = pp.create_line_from_parameters(net, from_bus = 1, to_bus = 3, length_km = 1, r_ohm_per_km = 3.93576, x_ohm_per_km = 19.6788, c_nf_per_km = 388.611, max_i_ka = 0.627555, name=None, index=2, type = 'ol', in_service=True, df=1.0, parallel=1, g_us_per_km=0.0, max_loading_percent=100) line3 = pp.create_line_from_parameters(net, from_bus = 2, to_bus = 3, length_km = 1, r_ohm_per_km = 6.72888, x_ohm_per_km = 33.6444, c_nf_per_km = 639.328, max_i_ka = 0.627555, name=None, index=3, type = 'ol', in_service=True, df=1.0, parallel=1, g_us_per_km=0.0, max_loading_percent=100) pp.runpp(net) print(net) print('====bus results===') print(net.res_bus) #Result tables print('====ext grid results===')
def test_opf_gen_loading(): """ Testing a simple network with transformer for loading constraints with OPF using a generator """ # wide open voltage boundaries to make sure they don't interfere with loading constraints vm_max = 1.5 vm_min = 0.5 max_line_loading = 11 # create net net = pp.create_empty_network() pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=10.) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_bus(net, max_vm_pu=vm_max, min_vm_pu=vm_min, vn_kv=.4) pp.create_transformer_from_parameters(net, 0, 1, vk_percent=3.75, tap_max=2, vn_lv_kv=0.4, shift_degree=150, tap_neutral=0, vn_hv_kv=10.0, vkr_percent=2.8125, tap_pos=0, tap_side="hv", tap_min=-2, tap_step_percent=2.5, i0_percent=0.68751, sn_mva=0.016, pfe_kw=0.11, name=None, in_service=True, index=None, max_loading_percent=145) pp.create_gen(net, 3, p_mw=0.01, controllable=True, min_p_mw=0.005, max_p_mw=0.015, max_q_mvar=0.05, min_q_mvar=-0.05) pp.create_poly_cost(net, 0, "gen", cp1_eur_per_mw=-10) pp.create_ext_grid(net, 0) pp.create_poly_cost(net, 0, "ext_grid", cp1_eur_per_mw=.1) pp.create_line_from_parameters(net, 1, 2, 1, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=max_line_loading) pp.create_line_from_parameters(net, 2, 3, 1, name="line2", r_ohm_per_km=0.876, c_nf_per_km=260.0, max_i_ka=0.123, x_ohm_per_km=0.1159876, max_loading_percent=max_line_loading) # run OPF pp.runopp(net, OPF_VIOLATION=1e-1, OUT_LIM_LINE=2, PDIPM_GRADTOL=1e-10, PDIPM_COMPTOL=1e-10, PDIPM_COSTTOL=1e-10, calculate_voltage_angles=False) assert net["OPF_converged"] # assert and check result logger.debug("test_opf_gen_loading") logger.debug("res_gen:\n%s" % net.res_gen) logger.debug("res_line.loading_percent:\n%s" % net.res_line.loading_percent) assert max(net.res_line.loading_percent) < max_line_loading logger.debug("res_trafo.loading_percent:\n%s" % net.res_trafo.loading_percent) assert max(net.res_trafo.loading_percent) < 145 assert max(net.res_bus.vm_pu) < vm_max assert min(net.res_bus.vm_pu) > vm_min