def __init__(self, Vbase, SourceBus, reg_bus, reg_phase): # The Voltage base self.Vbase = Vbase # V self.SourceBus = SourceBus # Voltage regulator nodes self.reg_bus = reg_bus self.reg_Phase = reg_phase # (1) get the bus dict (self.bus_dict, self.N_bus, self.threePbus) = Bus.Bus_gen() # (2) get the Z and C bus (self.Zbus, self.Cbus) = ZandC.gen_ZC(self.Vbase) # (3) the bus -> phase dict self.bus_phase_dict = dict() self.bus_phase_dict[SourceBus] = [1, 2, 3] # (4) the bus -> downstream bus dictionary self.downstream_dict = dict() # (5) transistion bus, having both abc and 012 variables self.transistion_bus = set() # (6) line data, read from file self.line_data = pd.read_csv("data/line data.csv", header=None) self.N_lines = len(self.line_data.index) # open the file self.fd = open('ieee123_yalmip.m', 'w') # first line, MATLAB function declare self.fd.write('clear;\n') self.fd.write('clc;\n') self.fd.write('close all;\n') self.fd.write('\n')
def bus_phase(SourceBus): # get bus_dict from external (bus_dict, N_bus, threePbus) = Bus.Bus_gen() bus_phase_dict = dict() bus_phase_dict[SourceBus] = [1,2,3] # iterate over lines line_data = pd.read_csv("data/line data.csv", header=None) N_lines = len(line_data.index) for l in range(N_lines): to_bus = str(line_data.iloc[l, 1]) phase = [] to_PhaseA = str(to_bus) + '.1' to_PhaseB = str(to_bus) + '.2' to_PhaseC = str(to_bus) + '.3' # init the no. of phases phase = [] if to_PhaseA in bus_dict: phase.append(1) if to_PhaseB in bus_dict: phase.append(2) if to_PhaseC in bus_dict: phase.append(3) bus_phase_dict[to_bus] = phase return bus_phase_dict
def gen_Y(Vbase): # call bus_gen function # get the bus dict , N_bus and 3-phase bus (bus_dict, N_bus, threePbus) = Bus.Bus_gen() ## init the Zbus and Cbus matrix Zbus = np.zeros((N_bus, N_bus), dtype=complex) Cbus = np.zeros((N_bus, N_bus), dtype=complex) # add line data to Zbus and Cbus (Zbus, Cbus) = ZC_line(bus_dict, Vbase, threePbus, Zbus, Cbus) # add transformer data to Zbus and Cbus (Zbus, Cbus) = ZC_transformer(bus_dict, Vbase, threePbus, Zbus, Cbus) # add capacitor data to Zbus and Cbus (Zbus, Cbus) = ZC_capacitor(bus_dict, Vbase, threePbus, Zbus, Cbus) # convert to Ybus from Zbus and Cbus Ybus = np.linalg.inv(Zbus) + Cbus sio.savemat('data/Ybus.mat', {"Ybus": Ybus}) return (Ybus)
def loadApproximate(): # Voltage base Vbase = 4160 / np.sqrt(3) # get bus dict (bus_dict, Nbus, threePbus) = Bus.Bus_gen() # init the constant Z loads Yloads = np.zeros((Nbus, Nbus), dtype=complex) # init the constant PQ loads PQloads = np.zeros((Nbus), dtype=complex) # read load data from file loads = pd.read_csv('data/loads data.csv') N_loads = len(loads.index) # delta to wye alpha = np.cos(np.pi / 6) + 1j * np.sin(np.pi / 6) beta = np.cos(-np.pi / 6) + 1j * np.sin(-np.pi / 6) M = np.array([[beta, 0, alpha], [alpha, beta, 0], [0, alpha, beta] ]) / np.sqrt(3) # iterate over loads for i in range(N_loads): bus = str(loads.iloc[i, 0]) load_type = str(loads.iloc[i, 1]) # three phase load in W (convert from kW) load_A = 1000 * (float(loads.iloc[i, 2]) + 1j * float(loads.iloc[i, 3])) load_B = 1000 * (float(loads.iloc[i, 4]) + 1j * float(loads.iloc[i, 5])) load_C = 1000 * (float(loads.iloc[i, 6]) + 1j * float(loads.iloc[i, 7])) # three phase node node_A = bus + '.1' node_B = bus + '.2' node_C = bus + '.3' # Wye connection # constant PQ if load_type == 'Y-PQ': if node_A in bus_dict: PQloads[bus_dict[node_A] - 1] = load_A if node_B in bus_dict: PQloads[bus_dict[node_B] - 1] = load_B if node_C in bus_dict: PQloads[bus_dict[node_C] - 1] = load_C # constant I elif load_type == 'Y-I': # split half to PQ and other half to Z if node_A in bus_dict: PQloads[bus_dict[node_A] - 1] = load_A / 2 if node_B in bus_dict: PQloads[bus_dict[node_B] - 1] = load_B / 2 if node_C in bus_dict: PQloads[bus_dict[node_C] - 1] = load_C / 2 Y_A = load_A / (Vbase * Vbase * 2) Y_B = load_B / (Vbase * Vbase * 2) Y_C = load_C / (Vbase * Vbase * 2) if node_A in bus_dict: Yloads[bus_dict[node_A] - 1, bus_dict[node_A] - 1] = Y_A if node_B in bus_dict: Yloads[bus_dict[node_B] - 1, bus_dict[node_B] - 1] = Y_B if node_C in bus_dict: Yloads[bus_dict[node_C] - 1, bus_dict[node_C] - 1] = Y_C # constant Z elif load_type == 'Y-Z': Y_A = load_A / (Vbase * Vbase) Y_B = load_B / (Vbase * Vbase) Y_C = load_C / (Vbase * Vbase) if node_A in bus_dict: Yloads[bus_dict[node_A] - 1, bus_dict[node_A] - 1] = Y_A if node_B in bus_dict: Yloads[bus_dict[node_B] - 1, bus_dict[node_B] - 1] = Y_B if node_C in bus_dict: Yloads[bus_dict[node_C] - 1, bus_dict[node_C] - 1] = Y_C # Delta connection else: delta_load = np.array([load_A, load_B, load_C]) delta_load = np.dot(M, delta_load) # constant PQ if load_type == 'D-PQ': if node_A in bus_dict: PQloads[bus_dict[node_A] - 1] = delta_load[0] if node_B in bus_dict: PQloads[bus_dict[node_B] - 1] = delta_load[1] if node_C in bus_dict: PQloads[bus_dict[node_C] - 1] = delta_load[2] # constant Z elif load_type == 'D-Z': Y_A = delta_load[0] / (Vbase * Vbase) Y_B = delta_load[1] / (Vbase * Vbase) Y_C = delta_load[2] / (Vbase * Vbase) if node_A in bus_dict: Yloads[bus_dict[node_A] - 1, bus_dict[node_A] - 1] = Y_A if node_B in bus_dict: Yloads[bus_dict[node_B] - 1, bus_dict[node_B] - 1] = Y_B if node_C in bus_dict: Yloads[bus_dict[node_C] - 1, bus_dict[node_C] - 1] = Y_C # constant I elif load_type == 'D-I': # split half to PQ and other half to Z if node_A in bus_dict: PQloads[bus_dict[node_A] - 1] = delta_load[0] / 2 if node_B in bus_dict: PQloads[bus_dict[node_B] - 1] = delta_load[1] / 2 if node_C in bus_dict: PQloads[bus_dict[node_C] - 1] = delta_load[2] / 2 Y_A = delta_load[0] / (Vbase * Vbase * 2) Y_B = delta_load[1] / (Vbase * Vbase * 2) Y_C = delta_load[2] / (Vbase * Vbase * 2) if node_A in bus_dict: Yloads[bus_dict[node_A] - 1, bus_dict[node_A] - 1] = Y_A if node_B in bus_dict: Yloads[bus_dict[node_B] - 1, bus_dict[node_B] - 1] = Y_B if node_C in bus_dict: Yloads[bus_dict[node_C] - 1, bus_dict[node_C] - 1] = Y_C sio.savemat('data/Yloads.mat', {"Yloads": Yloads}) sio.savemat('data/PQloads.mat', {"PQloads": PQloads})
def v_DER_sensivity(der_list, f): # downstream and upstream dict (downstream_dict, upstream_dict) = bus_trace(SourceBus) # get bus_dict busnames = Bus.getBus() (bus_dict, N_bus, threePbus) = Bus.Bus_gen() print(bus_dict) # impedance between bus and DER for bus in busnames: # check if any DER is downstream of the bus hasDER = False for der in der_list: if bus in upstream_dict[der]: hasDER = True # hasDER is true, the bus has downstream DER if hasDER: for der in der_list: if bus in upstream_dict[der]: f.write('Ze' + bus + der + ' = ') length = len(upstream_dict[der]) for i in range(length-1): bus_f = upstream_dict[der][i] bus_t = upstream_dict[der][i+1] f.write('Ze' + bus_f + bus_t + ' + ') # last line segment, connected to DER bus_f = upstream_dict[der][-1] f.write('Ze' + bus_f + der + ' + ') f.write('0;\n') # delta V nodeA = bus + '.1' nodeB = bus + '.2' nodeC = bus + '.3' if nodeA in bus_dict.keys(): f.write('Cons = [Cons, DeltaV(' + str(bus_dict[nodeA]) + ') == ') for der in der_list: if bus in upstream_dict[der]: f.write('DER' + der + '(1) * Ze' + bus + der + "(1, 1)' + Ze" + bus + der + '(1, 1) * DER' + der + "(1)' + ") f.write('0];\n') if nodeB in bus_dict.keys(): f.write('Cons = [Cons, DeltaV(' + str(bus_dict[nodeB]) + ') == ') for der in der_list: if bus in upstream_dict[der]: f.write('DER' + der + '(2) * Ze' + bus + der + "(2, 2)' + Ze" + bus + der + '(2, 2) * DER' + der + "(2)' + ") f.write('0];\n') if nodeC in bus_dict.keys(): f.write('Cons = [Cons, DeltaV(' + str(bus_dict[nodeC]) + ') ==') for der in der_list: if bus in upstream_dict[der]: f.write('DER' + der + '(3) * Ze' + bus + der + "(3, 3)' + Ze" + bus + der + '(3, 3) * DER' + der + "(3)' + ") f.write('0];\n') f.write('\n') # finally the voltage constraint f.write('Cons = [Cons, v_lb <= vPF + DeltaV <= v_ub];\n')