e2nIEE / pandapower
1
# -*- coding: utf-8 -*-
2

3
# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
4
# and Energy System Technology (IEE), Kassel. All rights reserved.
5

6 1
import math
7 1
import numpy as np
8 1
from itertools import product
9

10 1
import pandapower.auxiliary as aux
11 1
from pandapower.build_bus import _build_bus_ppc
12 1
from pandapower.build_gen import _build_gen_ppc
13
#from pandapower.pd2ppc import _ppc2ppci, _init_ppc
14 1
from pandapower.pypower.idx_brch import BR_B, BR_R, BR_X, F_BUS, T_BUS, branch_cols, BR_STATUS, SHIFT, TAP
15 1
from pandapower.pypower.idx_bus import BASE_KV, BS, GS, BUS_TYPE
16 1
from pandapower.build_branch import _calc_tap_from_dataframe, _transformer_correction_factor, _calc_nominal_ratio_from_dataframe,\
17
     get_trafo_values, _trafo_df_from_trafo3w, _calc_branch_values_from_trafo_df
18 1
from pandapower.build_branch import _switch_branches, _branches_with_oos_buses, _initialize_branch_lookup, _end_temperature_correction_factor
19

20 1
def _pd2ppc_zero(net, sequence=0):
21 1
    from pandapower.pd2ppc import _ppc2ppci, _init_ppc
22

23
    """
24
    Builds the ppc data structure for zero impedance system. Includes the impedance values of
25
    lines and transformers, but no load or generation data.
26

27
    For short-circuit calculation, the short-circuit impedance of external grids is also considered.
28
    """
29
    # select elements in service (time consuming, so we do it once)
30 1
    net["_is_elements"] = aux._select_is_elements_numba(net, sequence=sequence)
31

32 1
    ppc = _init_ppc(net, sequence)
33

34 1
    _build_bus_ppc(net, ppc)
35 1
    _build_gen_ppc(net, ppc)
36 1
    _add_gen_sc_impedance_zero(net, ppc)
37 1
    _add_ext_grid_sc_impedance_zero(net, ppc)
38 1
    _build_branch_ppc_zero(net, ppc)
39

40
    # adds auxilary buses for open switches at branches
41 1
    _switch_branches(net, ppc)
42

43
    # add auxilary buses for out of service buses at in service lines.
44
    # Also sets lines out of service if they are connected to two out of service buses
45 1
    _branches_with_oos_buses(net, ppc)
46 1
    if hasattr(net, "_isolated_buses"):
47 1
        ppc["bus"][net._isolated_buses, BUS_TYPE] = 4.
48

49
    # generates "internal" ppci format (for powerflow calc) from "external" ppc format and updates the bus lookup
50
    # Note: Also reorders buses and gens in ppc
51 1
    ppci = _ppc2ppci(ppc, net)
52
    #net._ppc0 = ppc    <--Obsolete. now covered in _init_ppc
53 1
    return ppc, ppci
54

55 1
def _build_branch_ppc_zero(net, ppc):
56
    """
57
    Takes the empty ppc network and fills it with the zero imepdance branch values. The branch
58
    datatype will be np.complex 128 afterwards.
59

60
    .. note:: The order of branches in the ppc is:
61
            1. Lines
62
            2. Transformers
63

64
    **INPUT**:
65
        **net** -The pandapower format network
66

67
        **ppc** - The PYPOWER format network to fill in values
68

69
    """
70 1
    length = _initialize_branch_lookup(net)
71 1
    lookup = net._pd2ppc_lookups["branch"]
72 1
    mode = net._options["mode"]
73 1
    ppc["branch"] = np.zeros(shape=(length, branch_cols), dtype=np.complex128)
74 1
    if mode == "sc":
75 1
        from pandapower.shortcircuit.idx_brch import branch_cols_sc
76 1
        branch_sc = np.empty(shape=(length, branch_cols_sc), dtype=float)
77 1
        branch_sc.fill(np.nan)
78 1
        ppc["branch"] = np.hstack((ppc["branch"], branch_sc ))
79 1
    ppc["branch"][:, :13] = np.array([0, 0, 0, 0, 0, 250, 250, 250, 1, 0, 1, -360, 360])
80

81 1
    _add_line_sc_impedance_zero(net, ppc)
82 1
    _add_trafo_sc_impedance_zero(net, ppc)
83 1
    if mode == "sc":
84 1
        _add_trafo3w_sc_impedance_zero(net, ppc)
85
    else:
86 1
        if "trafo3w" in lookup:
87 0
            raise NotImplementedError("Three winding transformers are not implemented for unbalanced calculations")
88

89

90 1
def _add_trafo_sc_impedance_zero(net, ppc, trafo_df=None):
91 1
    if trafo_df is None:
92 1
        trafo_df = net["trafo"]
93 1
    branch_lookup = net["_pd2ppc_lookups"]["branch"]
94 1
    if not "trafo" in branch_lookup:
95 1
        return
96 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
97 1
    mode = net["_options"]["mode"]
98 1
    trafo_model = net["_options"]["trafo_model"]
99 1
    f, t = branch_lookup["trafo"]
100 1
    trafo_df["_ppc_idx"] = range(f, t)
101 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
102

103 1
    hv_bus = get_trafo_values(trafo_df, "hv_bus").astype(int)
104 1
    lv_bus = get_trafo_values(trafo_df, "lv_bus").astype(int)
105 1
    in_service = get_trafo_values(trafo_df, "in_service").astype(int)
106 1
    ppc["branch"][f:t, F_BUS] = bus_lookup[hv_bus]
107 1
    ppc["branch"][f:t, T_BUS] = bus_lookup[lv_bus]
108 1
    buses_all, gs_all, bs_all = np.array([], dtype=int), np.array([]), \
109
                                np.array([])
110 1
    if mode == "sc":
111
        # Should be considered as connected for all in_service branches
112 1
        ppc["branch"][f:t, BR_X] = 1e20
113 1
        ppc["branch"][f:t, BR_R] = 1e20
114 1
        ppc["branch"][f:t, BR_B] = 0
115 1
        ppc["branch"][f:t, BR_STATUS] = in_service  
116
    else:
117 1
        ppc["branch"][f:t, BR_STATUS] = 0
118

119 1
    if not "vector_group" in trafo_df:
120 0
        raise ValueError("Vector Group of transformer needs to be specified for zero \
121
                         sequence modelling \n Try : net.trafo[\"vector_group\"] = 'Dyn'" )
122

123 1
    for vector_group, trafos in trafo_df.groupby("vector_group"):
124 1
        ppc_idx = trafos["_ppc_idx"].values.astype(int)
125

126 1
        if vector_group in ["Yy", "Yd", "Dy", "Dd"]:
127 1
            continue
128

129 1
        vk_percent = trafos["vk_percent"].values.astype(float)
130 1
        vkr_percent = trafos["vkr_percent"].values.astype(float)
131 1
        sn_mva = trafos["sn_mva"].values.astype(float)
132
        # Just put pos seq parameter if zero seq parameter is zero
133 1
        if not "vk0_percent" in trafos:
134 0
            raise ValueError("Short circuit voltage of transformer Vk0 needs to be specified for zero \
135
                             sequence modelling \n Try : net.trafo[\"vk0_percent\"] = net.trafo[\"vk_percent\"]" )
136 1
        vk0_percent = trafos["vk0_percent"].values.astype(float) if \
137
            trafos["vk0_percent"].values.astype(float).all() != 0. else \
138
            trafos["vk_percent"].values.astype(float)
139
        # Just put pos seq parameter if zero seq parameter is zero
140 1
        if not "vkr0_percent" in trafos:
141 0
            raise ValueError("Real part of short circuit voltage Vk0(Real) needs to be specified for transformer \
142
                             modelling \n Try : net.trafo[\"vkr0_percent\"] = net.trafo[\"vkr_percent\"]" )
143 1
        vkr0_percent = trafos["vkr0_percent"].values.astype(float) if \
144
            trafos["vkr0_percent"].values.astype(float).all() != 0. else \
145
            trafos["vkr_percent"].values.astype(float)
146 1
        lv_buses = trafos["lv_bus"].values.astype(int)
147 1
        hv_buses = trafos["hv_bus"].values.astype(int)
148 1
        lv_buses_ppc = bus_lookup[lv_buses]
149 1
        hv_buses_ppc = bus_lookup[hv_buses]
150 1
        if not "mag0_percent" in trafos:
151
            # For Shell Type transformers vk0 = vk * 1
152
            #        and mag0_percent = 10 ... 100  Zm0/ Zsc0
153
            # --pg 50 DigSilent Power Factory Transformer manual
154 0
            raise ValueError("Magnetizing impedance to vk0 ratio needs to be specified for transformer \
155
                             modelling  \n Try : net.trafo[\"mag0_percent\"] = 100" )
156 1
        mag0_ratio = trafos.mag0_percent.values.astype(float)
157 1
        if not "mag0_rx" in trafos:
158 0
            raise ValueError("Magnetizing impedance R/X ratio needs to be specified for transformer \
159
                             modelling \n Try : net.trafo[\"mag0_rx\"] = 0 " )
160 1
        mag0_rx = trafos["mag0_rx"].values.astype(float)
161 1
        if not "si0_hv_partial" in trafos:
162 0
            raise ValueError("Zero sequence short circuit impedance partition towards HV side needs to be specified for transformer \
163
                             modelling \n Try : net.trafo[\"si0_hv_partial\"] = 0.9 " )
164 1
        si0_hv_partial = trafos.si0_hv_partial.values.astype(float)
165 1
        parallel = trafos.parallel.values.astype(float)
166 1
        in_service = trafos["in_service"].astype(int)
167

168 1
        ppc["branch"][ppc_idx, F_BUS] = hv_buses_ppc
169 1
        ppc["branch"][ppc_idx, T_BUS] = lv_buses_ppc
170

171 1
        vn_trafo_hv, vn_trafo_lv, shift = _calc_tap_from_dataframe(net, trafos)
172 1
        vn_lv = ppc["bus"][lv_buses_ppc, BASE_KV]
173 1
        ratio = _calc_nominal_ratio_from_dataframe(ppc, trafos, vn_trafo_hv, \
174
                                                   vn_trafo_lv, bus_lookup)
175 1
        ppc["branch"][ppc_idx, TAP] = ratio
176 1
        ppc["branch"][ppc_idx, SHIFT] = shift
177

178
        # zero seq. transformer impedance
179 1
        tap_lv = np.square(vn_trafo_lv / vn_lv) * net.sn_mva
180 1
        if mode == 'pf_3ph':
181
            # =============================================================================
182
            #     Changing base from transformer base to Network base to get Zpu(Net)
183
            #     Zbase = (kV).squared/S_mva
184
            #     Zpu(Net)={Zpu(trafo) * Zb(trafo)} / {Zb(Net)}
185
            #        Note:
186
            #             Network base voltage is Line-Neutral voltage in each phase
187
            #             Line-Neutral voltage= Line-Line Voltage(vn_lv) divided by sq.root(3)
188
            # =============================================================================
189 1
            tap_lv = np.square(vn_trafo_lv / vn_lv) * (3 * net.sn_mva)
190

191 1
        z_sc = vk0_percent / 100. / sn_mva * tap_lv
192 1
        r_sc = vkr0_percent / 100. / sn_mva * tap_lv
193 1
        z_sc = z_sc.astype(float)
194 1
        r_sc = r_sc.astype(float)
195 1
        x_sc = np.sign(z_sc) * np.sqrt(z_sc ** 2 - r_sc ** 2)
196
        # TODO: This equation needs to be checked!
197
        # z0_k = (r_sc + x_sc * 1j) / parallel  * max(1, ratio) **2
198 1
        z0_k = (r_sc + x_sc * 1j) / parallel
199 1
        y0_k = 1 / z0_k #adding admittance for "pi" model
200 1
        if mode == "sc":# or trafo_model == "pi":
201 1
            from pandapower.shortcircuit.idx_bus import C_MAX
202 1
            cmax = net._ppc["bus"][lv_buses_ppc, C_MAX]
203 1
            kt = _transformer_correction_factor(vk_percent, vkr_percent, \
204
                                                sn_mva, cmax)
205 1
            z0_k *= kt
206 1
            y0_k = 1 / z0_k
207
        # =============================================================================
208
        #       Transformer magnetising impedance for zero sequence
209
        # =============================================================================
210 1
        z_m = z_sc * mag0_ratio
211 1
        x_m = z_m / np.sqrt(mag0_rx ** 2 + 1)
212 1
        r_m = x_m * mag0_rx
213 1
        r0_trafo_mag = r_m / parallel
214 1
        x0_trafo_mag = x_m / parallel
215 1
        z0_mag = r0_trafo_mag + x0_trafo_mag * 1j
216
        # =============================================================================
217
        #         Star - Delta conversion ( T model to Pi Model)
218
        #      ----------- |__zc=ZAB__|-----------------
219
        #            _|                   _|
220
        #     za=ZAN|_|                  |_| zb=ZBN
221
        #            |                    |
222
        # =============================================================================
223 1
        z1 = si0_hv_partial * z0_k
224 1
        z2 = (1 - si0_hv_partial) * z0_k
225 1
        z3 = z0_mag
226 1
        z_temp = z1 * z2 + z2 * z3 + z1 * z3
227 1
        za = z_temp / z2
228
#        za = z_temp / (z2+z3)
229 1
        zb = z_temp / z1
230
#        zb = z_temp / (z1+z3)
231 1
        zc = z_temp / z3 # ZAB  Transfer impedance
232
#        zc = z_temp / (z1+z2)  # ZAB  Transfer impedance
233 1
        YAB = 1 / zc.astype(complex)
234 1
        YAN = 1 / za.astype(complex)
235 1
        YBN = 1 / zb.astype(complex)
236

237
#        YAB_AN = (zc + za) /(zc * za).astype(complex)  # Series conn YAB and YAN
238
#        YAB_BN = (zc + zb) / (zc * zb).astype(complex)  # Series conn YAB and YBN
239

240 1
        YAB_AN = 1 / (zc + za).astype(complex)  # Series conn YAB and YAN
241 1
        YAB_BN = 1 / (zc + zb).astype(complex)  # Series conn YAB and YBN
242

243
        # y0_k = 1 / z0_k #adding admittance for "pi" model
244 1
        if vector_group == "Dyn":
245 1
            buses_all = np.hstack([buses_all, lv_buses_ppc])
246 1
            if trafo_model == "pi":
247 1
                y = y0_k # pi model
248
            else:
249 1
                y = (YAB + YBN).astype(complex)  # T model
250 1
            gs_all = np.hstack([gs_all, y.real * in_service]) * int(ppc["baseMVA"])
251 1
            bs_all = np.hstack([bs_all, y.imag * in_service]) * int(ppc["baseMVA"])
252

253 1
        elif vector_group == "YNd":
254 1
            buses_all = np.hstack([buses_all, hv_buses_ppc])
255 1
            if trafo_model == "pi":
256 1
                y = y0_k * ppc["baseMVA"] # pi model
257
            else:
258 0
                y = (YAB_BN + YAN).astype(complex) #T model
259 1
            gs_all = np.hstack([gs_all, y.real * in_service]) * int(ppc["baseMVA"])
260 1
            bs_all = np.hstack([bs_all, y.imag * in_service]) * int(ppc["baseMVA"])
261

262 1
        elif vector_group == "Yyn":
263 1
            buses_all = np.hstack([buses_all, lv_buses_ppc])
264 1
            if trafo_model == "pi":
265 1
                y = 1/(z0_mag+z0_k).astype(complex) #pi model
266
            else:
267
#                y = (YAB_AN + YBN).astype(complex) #T model
268 0
                y = (YAB + YAB_BN + YBN).astype(complex) # T model
269

270 1
            gs_all = np.hstack([gs_all, y.real * in_service]) * int(ppc["baseMVA"])
271 1
            bs_all = np.hstack([bs_all, y.imag * in_service]) * int(ppc["baseMVA"])
272

273 1
        elif vector_group == "YNyn":
274 1
            ppc["branch"][ppc_idx, BR_STATUS] = in_service
275
            # zc = ZAB
276 1
            ppc["branch"][ppc_idx, BR_R] = zc.real
277 1
            ppc["branch"][ppc_idx, BR_X] = zc.imag
278

279 1
            buses_all = np.hstack([buses_all, hv_buses_ppc])
280 1
            gs_all = np.hstack([gs_all, YAN.real * in_service \
281
                                * int(ppc["baseMVA"])])
282 1
            bs_all = np.hstack([bs_all, YAN.imag * in_service \
283
                                * int(ppc["baseMVA"])])
284

285 1
            buses_all = np.hstack([buses_all, lv_buses_ppc])
286 1
            gs_all = np.hstack([gs_all, YBN.real * in_service \
287
                                * int(ppc["baseMVA"])])
288 1
            bs_all = np.hstack([bs_all, YBN.imag * in_service \
289
                                * int(ppc["baseMVA"])])
290

291 1
        elif vector_group == "YNy":
292 1
            buses_all = np.hstack([buses_all, hv_buses_ppc])
293 1
            if trafo_model == "pi":
294 1
                y = 1/(z0_mag+z0_k).astype(complex)* int(ppc["baseMVA"])#pi model
295
            else:
296 0
                y = (YAB_BN + YAN).astype(complex) * int(ppc["baseMVA"])  #T model
297 1
            gs_all = np.hstack([gs_all, y.real * in_service])
298 1
            bs_all = np.hstack([bs_all, y.imag * in_service])
299

300 1
        elif vector_group == "Yzn":
301 1
            buses_all = np.hstack([buses_all, lv_buses_ppc])
302
            #            y = 1/(z0_mag+z0_k).astype(complex)* int(ppc["baseMVA"])#T model
303
            #            y= (za+zb+zc)/((za+zc)*zb).astype(complex)* int(ppc["baseMVA"])#pi model
304 1
            y = (YAB_AN + YBN).astype(complex) * int(ppc["baseMVA"])  #T model
305 1
            gs_all = np.hstack([gs_all, (1.1547) * y.real * in_service \
306
                                * int(ppc["baseMVA"])])
307 1
            bs_all = np.hstack([bs_all, (1.1547) * y.imag * in_service \
308
                                * int(ppc["baseMVA"])])
309

310 0
        elif vector_group[-1].isdigit():
311 0
            raise ValueError("Unknown transformer vector group %s -\
312
                             please specify vector group without \
313
                             phase shift number. Phase shift can be \
314
                             specified in net.trafo.shift_degree" % vector_group)
315
        else:
316 0
            raise ValueError("Transformer vector group %s is unknown\
317
                    / not implemented for three phase load flow" % vector_group)
318

319 1
    buses, gs, bs = aux._sum_by_group(buses_all, gs_all, bs_all)
320 1
    ppc["bus"][buses, GS] += gs
321 1
    ppc["bus"][buses, BS] += bs
322 1
    del net.trafo["_ppc_idx"]
323

324

325 1
def _add_gen_sc_impedance_zero(net, ppc):
326 1
    mode = net["_options"]["mode"]
327 1
    if mode == 'pf_3ph':
328 0
        return
329

330 1
    eg = net["gen"][net._is_elements["gen"]]
331 1
    if len(eg) == 0:
332 1
        return
333 1
    eg_buses = eg.bus.values
334 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
335 1
    eg_buses_ppc = bus_lookup[eg_buses]
336

337 1
    y0_gen = 1 / (1e3 + 1e3*1j)
338
    # buses, gs, bs = aux._sum_by_group(eg_buses_ppc, y0_gen.real, y0_gen.imag)
339 1
    ppc["bus"][eg_buses_ppc, GS] += y0_gen.real
340 1
    ppc["bus"][eg_buses_ppc, BS] += y0_gen.imag
341

342 1
def _add_ext_grid_sc_impedance_zero(net, ppc):
343 1
    mode = net["_options"]["mode"]
344

345 1
    if mode == "sc":
346 1
        from pandapower.shortcircuit.idx_bus import C_MAX, C_MIN
347 1
        case = net._options["case"]
348
    else:
349 1
        case = "max"
350 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
351 1
    eg = net["ext_grid"][net._is_elements["ext_grid"]]
352 1
    if len(eg) == 0:
353 0
        return
354 1
    eg_buses = eg.bus.values
355 1
    eg_buses_ppc = bus_lookup[eg_buses]
356

357 1
    if mode == "sc":
358 1
        c = ppc["bus"][eg_buses_ppc, C_MAX] if case == "max" else ppc["bus"][eg_buses_ppc, C_MIN]
359
    else:
360 1
        c = 1.1
361 1
    if not "s_sc_%s_mva" % case in eg:
362 0
        raise ValueError("short circuit apparent power s_sc_%s_mva needs to be specified for "% case +
363
                         "external grid" )
364 1
    s_sc = eg["s_sc_%s_mva" % case].values
365 1
    if not "rx_%s" % case in eg:
366 0
        raise ValueError("short circuit R/X rate rx_%s needs to be specified for external grid" %
367
                         case)
368 1
    rx = eg["rx_%s" % case].values
369

370 1
    z_grid = c / s_sc
371 1
    if mode == 'pf_3ph':
372 1
        z_grid = c / (s_sc/3)
373 1
    x_grid = z_grid / np.sqrt(rx ** 2 + 1)
374 1
    r_grid = rx * x_grid
375 1
    eg["r"] = r_grid
376 1
    eg["x"] = x_grid
377

378
    # ext_grid zero sequence impedance
379 1
    if case == "max":
380 1
        x0_grid = net.ext_grid["x0x_%s" % case] * x_grid
381 1
        r0_grid = net.ext_grid["r0x0_%s" % case] * x0_grid
382 1
    elif case == "min":
383 1
        x0_grid = net.ext_grid["x0x_%s" % case] * x_grid
384 1
        r0_grid = net.ext_grid["r0x0_%s" % case] * x0_grid
385 1
    y0_grid = 1 / (r0_grid + x0_grid*1j)
386

387 1
    buses, gs, bs = aux._sum_by_group(eg_buses_ppc, y0_grid.values.real, y0_grid.values.imag)
388 1
    ppc["bus"][buses, GS] = gs
389 1
    ppc["bus"][buses, BS] = bs
390

391

392 1
def _add_line_sc_impedance_zero(net, ppc):
393 1
    branch_lookup = net["_pd2ppc_lookups"]["branch"]
394 1
    mode = net["_options"]["mode"]
395 1
    if not "line" in branch_lookup:
396 0
        return
397 1
    line = net["line"]
398 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
399 1
    length = line["length_km"].values
400 1
    parallel = line["parallel"].values
401

402 1
    fb = bus_lookup[line["from_bus"].values]
403 1
    tb = bus_lookup[line["to_bus"].values]
404 1
    baseR = np.square(ppc["bus"][fb, BASE_KV]) / net.sn_mva
405 1
    if mode == 'pf_3ph':
406 1
        baseR = np.square(ppc["bus"][fb, BASE_KV]) / (3*net.sn_mva)
407 1
    f, t = branch_lookup["line"]
408
    # line zero sequence impedance
409 1
    ppc["branch"][f:t, F_BUS] = fb
410 1
    ppc["branch"][f:t, T_BUS] = tb
411 1
    ppc["branch"][f:t, BR_R] = line["r0_ohm_per_km"].values * length / baseR / parallel
412 1
    if mode == "sc":
413
        # temperature correction
414 1
        if net["_options"]["case"] == "min":
415 1
            ppc["branch"][f:t, BR_R] *= _end_temperature_correction_factor(net, short_circuit=True)
416 1
    ppc["branch"][f:t, BR_X] = line["x0_ohm_per_km"].values * length / baseR / parallel
417 1
    ppc["branch"][f:t, BR_B] = (2 * net["f_hz"] * math.pi * line["c0_nf_per_km"].values * 1e-9 * baseR * length * parallel)
418 1
    ppc["branch"][f:t, BR_STATUS] = line["in_service"].astype(int)
419

420

421 1
def _add_trafo3w_sc_impedance_zero(net, ppc):
422 1
    branch_lookup = net["_pd2ppc_lookups"]["branch"]
423 1
    if not "trafo3w" in branch_lookup:
424 1
        return
425 1
    bus_lookup = net["_pd2ppc_lookups"]["bus"]
426 1
    branch = ppc["branch"]
427 1
    f, t = net["_pd2ppc_lookups"]["branch"]["trafo3w"]
428 1
    trafo_df = _trafo_df_from_trafo3w(net, sequence=0)
429 1
    hv_bus = get_trafo_values(trafo_df, "hv_bus").astype(int)
430 1
    lv_bus = get_trafo_values(trafo_df, "lv_bus").astype(int)
431 1
    in_service = get_trafo_values(trafo_df, "in_service").astype(int)
432 1
    branch[f:t, F_BUS] = bus_lookup[hv_bus]
433 1
    branch[f:t, T_BUS] = bus_lookup[lv_bus]
434

435 1
    r, x, _, ratio, shift = _calc_branch_values_from_trafo_df(net, ppc, trafo_df, sequence=0)
436

437 1
    n_t3 = net.trafo3w.shape[0]
438 1
    for t3_ix in np.arange(n_t3):
439 1
        t3 = net.trafo3w.iloc[t3_ix, :]
440
        
441 1
        if t3.vector_group.lower() in set(map(lambda vg: "".join(vg), product("dy", repeat=3))):
442 0
            x[[t3_ix, t3_ix+n_t3, t3_ix+n_t3*2]] = 1e10
443 0
            r[[t3_ix, t3_ix+n_t3, t3_ix+n_t3*2]] = 1e10
444 1
        elif t3.vector_group.lower() == "ynyd":
445
            # Correction for YnYD
446
            # z3->y3
447 1
            ys = 1 / ((x[t3_ix+n_t3*2] * 1j + r[t3_ix+n_t3*2]) * ratio[t3_ix+n_t3*2] ** 2)
448 1
            aux_bus = bus_lookup[lv_bus[t3_ix]]
449 1
            ppc["bus"][aux_bus, BS] += ys.imag
450 1
            ppc["bus"][aux_bus, GS] += ys.real
451

452
            # Set y2/y3 to almost 0 to avoid isolated bus
453 1
            x[[t3_ix+n_t3, t3_ix+n_t3*2]] = 1e10
454 1
            r[[t3_ix+n_t3, t3_ix+n_t3*2]] = 1e10
455 1
        elif t3.vector_group.lower() == "yynd":
456
            # z3->y3
457 1
            ys = 1 / ((x[t3_ix+n_t3*2] * 1j + r[t3_ix+n_t3*2]) * ratio[t3_ix+n_t3*2] ** 2)
458 1
            aux_bus = bus_lookup[lv_bus[t3_ix]]
459 1
            ppc["bus"][aux_bus, BS] += ys.imag
460 1
            ppc["bus"][aux_bus, GS] += ys.real
461

462
            # Set y1/y3 to almost 0 to avoid isolated bus
463 1
            x[[t3_ix, t3_ix+n_t3*2]] = 1e10
464 1
            r[[t3_ix, t3_ix+n_t3*2]] = 1e10
465 1
        elif t3.vector_group.lower() == "ynynd":
466
            # z3->y3
467 1
            ys = 1 / ((x[t3_ix+n_t3*2] * 1j + r[t3_ix+n_t3*2]) * ratio[t3_ix+n_t3*2] ** 2)
468 1
            aux_bus = bus_lookup[lv_bus[t3_ix]]
469 1
            ppc["bus"][aux_bus, BS] += ys.imag
470 1
            ppc["bus"][aux_bus, GS] += ys.real
471

472
            # Set y3 to almost 0 to avoid isolated bus
473 1
            x[t3_ix+n_t3*2] = 1e10
474 1
            r[t3_ix+n_t3*2] = 1e10
475
        else:
476 0
            raise UserWarning(f"{t3.vector_group} not supported yet for trafo3w!")
477

478 1
    branch[f:t, BR_R] = r
479 1
    branch[f:t, BR_X] = x
480 1
    branch[f:t, BR_B] = 0
481 1
    branch[f:t, TAP] = ratio
482 1
    branch[f:t, SHIFT] = shift
483 1
    branch[f:t, BR_STATUS] = in_service

Read our documentation on viewing source code .

Loading