def _get_gen_results_3ph(net, ppc0, ppc1, ppc2, bus_lookup_aranged, pq_bus): ac = net["_options"]["ac"] eg_end = len(net['ext_grid']) gen_end = eg_end + len(net['gen'][net['_is_elements']['gen']]) b, pA, qA, pB, qB, pC, qC = _get_ext_grid_results_3ph( net, ppc0, ppc1, ppc2) # get results for gens if gen_end > eg_end: b, pA, qA, pB, qB, pC, qC = _get_pp_gen_results_3ph( net, ppc0, ppc1, ppc2, b, pA, qA, pB, qB, pC, qC) if not ac: qA, qB, qC = np.copy((np.zeros(len(pA)), ) * 3) b_pp, pA_sum, qA_sum, pB_sum, qB_sum, pC_sum, qC_sum = _sum_by_group_nvals( b.astype(int), pA, qA, pB, qB, pC, qC) b_ppc = bus_lookup_aranged[b_pp] pq_bus[b_ppc, 0] -= pA_sum pq_bus[b_ppc, 1] -= qA_sum pq_bus[b_ppc, 2] -= pB_sum pq_bus[b_ppc, 3] -= qB_sum pq_bus[b_ppc, 4] -= pC_sum pq_bus[b_ppc, 5] -= qC_sum
def _get_p_q_results_3ph(net, bus_lookup_aranged): # results to be filled (bus, p in kw, q in kvar) bus_pq = np.zeros(shape=(len(net["bus"].index), 6), dtype=np.float) b, pA, pB, pC, qA, qB, qC = np.array([]), np.array([]), np.array([]), np.array([]), \ np.array([]), np.array([]), np.array([]) ac = net["_options"]["ac"] # Todo: Voltage dependent loads elements = ["storage", "sgen", "load"] elements_3ph = ["asymmetric_load", "asymmetric_sgen"] for element in elements: sign = -1 if element in ['sgen', 'asymmetric_sgen'] else 1 if len(net[element]): write_pq_results_to_element(net, net._ppc1, element, suffix="3ph") p_el, q_el, bus_el = get_p_q_b(net, element, suffix="3ph") pA = np.hstack([pA, sign * p_el / 3]) pB = np.hstack([pB, sign * p_el / 3]) pC = np.hstack([pC, sign * p_el / 3]) qA = np.hstack( [qA, sign * q_el / 3 if ac else np.zeros(len(p_el / 3))]) qB = np.hstack( [qB, sign * q_el / 3 if ac else np.zeros(len(p_el / 3))]) qC = np.hstack( [qC, sign * q_el / 3 if ac else np.zeros(len(p_el / 3))]) b = np.hstack([b, bus_el]) for element in elements_3ph: sign = -1 if element in ['sgen', 'asymmetric_sgen'] else 1 if len(net[element]): write_pq_results_to_element_3ph(net, element) p_el_A, q_el_A, p_el_B, q_el_B, p_el_C, q_el_C, bus_el = get_p_q_b_3ph( net, element) pA = np.hstack([pA, sign * p_el_A]) pB = np.hstack([pB, sign * p_el_B]) pC = np.hstack([pC, sign * p_el_C]) qA = np.hstack( [qA, sign * q_el_A if ac else np.zeros(len(p_el_A))]) qB = np.hstack( [qB, sign * q_el_B if ac else np.zeros(len(p_el_B))]) qC = np.hstack( [qC, sign * q_el_C if ac else np.zeros(len(p_el_C))]) b = np.hstack([b, bus_el]) # sum pq results from every element to be written to net['bus'] later on b_pp, vp_A, vq_A, vp_B, vq_B, vp_C, vq_C = _sum_by_group_nvals( b.astype(int), pA, qA, pB, qB, pC, qC) b_ppc = bus_lookup_aranged[b_pp] bus_pq[b_ppc, 0] = vp_A bus_pq[b_ppc, 1] = vq_A bus_pq[b_ppc, 2] = vp_B bus_pq[b_ppc, 3] = vq_B bus_pq[b_ppc, 4] = vp_C bus_pq[b_ppc, 5] = vq_C return bus_pq
def _get_gen_results_3ph(net, ppc0, ppc1, ppc2, bus_lookup_aranged, pq_bus): ac = net["_options"]["ac"] eg_end = len(net['ext_grid']) gen_end = eg_end + len(net['gen'][net['_is_elements']['gen']]) b, pA, qA, pB, qB, pC, qC = _get_ext_grid_results_3ph( net, ppc0, ppc1, ppc2) # get results for gens if gen_end > eg_end: b, pA, qA, pB, qB, pC, qC = _get_pp_gen_results_3ph( net, ppc0, ppc1, ppc2, b, pA, qA, pB, qB, pC, qC) if len(net.dcline) > 0: _get_dcline_results(net) b = np.hstack([b, net.dcline[["from_bus", "to_bus"]].values.flatten()]) pDC = -net.res_dcline[["p_from_mw", "p_to_mw"]].values.flatten() / 3 pA = np.hstack([pA, pDC]) pB = np.hstack([pB, pDC]) pC = np.hstack([pC, pDC]) qDC = -net.res_dcline[["q_from_mvar", "q_to_mvar" ]].values.flatten() / 3 qA = np.hstack([qA, qDC]) qB = np.hstack([qB, qDC]) qC = np.hstack([qC, qDC]) if not ac: qA, qB, qC = np.copy((np.zeros(len(pA)), ) * 3) b_pp, pA_sum, qA_sum, pB_sum, qB_sum, pC_sum, qC_sum = _sum_by_group_nvals( b.astype(int), pA, qA, pB, qB, pC, qC) b_ppc = bus_lookup_aranged[b_pp] pq_bus[b_ppc, 0] += pA_sum pq_bus[b_ppc, 1] += qA_sum pq_bus[b_ppc, 2] += pB_sum pq_bus[b_ppc, 3] += qB_sum pq_bus[b_ppc, 4] += pC_sum pq_bus[b_ppc, 5] += qC_sum