1 import numpy as np 2 import pandas as pd 3 4 from pyelec import impedance 5 6 # ---------------------------------------------------------------------------------------------------------------------- 7 # Given data 8 9 # fundamental frequency and frequency range 10 f_1 = 50.0 # Hz 11 f_range = np.array([f_1 * i for i in range(1, 24, 2)]) 12 13 # capacitor 14 C = 77.0e-6 # F 15 16 # transformer 17 R_tr = 8.7494e-3 # ohm 18 X_tr_0 = 26.8336e-3 # ohm 19 L_tr = X_tr_0 / (2.0 * np.pi * f_1) 20 21 # ---------------------------------------------------------------------------------------------------------------------- 22 23 # impedance cable nr. 1 (connection cable of each capacitor bank stage) 24 Z_cab1 = [] 25 for f in f_range: 26 cable = impedance.Cable( 27 length=9.0, # m 28 section=50.0, # mm^2 29 material='Cu', 30 temperature=40.0, # conductor temperature, °C 31 frequency=f, 32 ) 33 cable.set_skin_effect(ks=0.435) 34 d_c = np.sqrt(4 * 50.0 / np.pi) 35 cable.set_proximity_effect(kp=0.37, d_c=d_c, s=d_c+2.0, type=('sector-shaped', 3)) 36 cable.set_cable_reactance(K=0.0514) 37 Z_cab1.append(cable.Z) 38 Z_cab1 = np.array(Z_cab1) 39 40 # impedance cable nr. 2 (cable between the main switch board and the capacitor bank) 41 Z_cab2 = [] 42 for f in f_range: 43 cable = impedance.Cable( 44 length=40.0, 45 section=70.0, 46 material='Cu', 47 temperature=40.0, 48 frequency=f, 49 ) 50 cable.set_skin_effect(ks=0.435) 51 d_c = np.sqrt(4 * 70.0 / np.pi) 52 cable.set_proximity_effect(kp=0.37, d_c=d_c, s=d_c+2.0, type=('sector-shaped', 3)) 53 cable.set_cable_reactance(K=0.0514) 54 Z_cab2.append(cable.Z / 2.0) 55 Z_cab2 = np.array(Z_cab2) 56 57 # impedance transformer 58 Z_tr = np.array([complex(R_tr, 2.0 * np.pi * f * L_tr) for f in f_range]) 59 60 # impedance of capacitors in capacitor bank (note: equivalent star connection will be used! -> divide by 3) 61 # stage 1 and stage 2 62 Z_cap12 = np.array([complex(0.0, -1 / (2.0 * np.pi * f * C)) for f in f_range]) / 3.0 63 # stage 3 and stage 4 (2 parallel capacitors per phase) 64 Z_cap34 = Z_cap12 / 2.0 65 66 # impedance capacitor bank + cable nr. 1 67 Z_st1 = Z_st2 = Z_cab1 + Z_cap12 68 Z_st3 = Z_st4 = Z_cab1 + Z_cap34 69 70 71 class Combination: 72 def __init__(self, name, stages, Z_stages, U_l1, I_l1, I_lh): 73 # id of the combination 74 self.name = name 75 # id of the stages in the combination 76 self.stages = stages 77 self.num_stages = len(Z_stages) 78 # harmonic impedances of active stages in the combination 79 self.Z_h_stages = [Z[1:] for Z in Z_stages] 80 # fundamental impedance of active stages in the combination 81 self.Z_1_stages = [Z[0] for Z in Z_stages] 82 # fundamental voltage across parallel circuit of combination and transformer 83 self.U_1_par = None 84 # fundamental current in each stage of the combination 85 self.I_1_stages = None 86 # fundamental voltage across capacitor in each stage of the combination 87 self.U_1_cap_stages = None 88 # effective value of fundamental current through capacitors in each stage of the combination (3 ph. delta) 89 self.I_eff_1_cap_stages = None 90 # effective value of fundamental voltage across capacitors in each stage of the combination (3 ph. delta) 91 self.U_eff_1_cap_stages = None 92 # harmonic equivalent impedance of the combination 93 self.Z_h_comb = None 94 # harmonic equivalent impedance of parallel circuit of combination and transformer 95 self.Z_h_par = None 96 # harmonic equivalent impedance of the whole network 97 self.Z_h_nw = None 98 # harmonic current in each stage of the combination 99 self.I_h_stages = None 100 # harmonic voltage across the capacitor in each stage of the combination 101 self.U_h_cap_stages = None 102 # effective value of harmonic current through capacitors in each stage of the combination (3 ph. delta) 103 self.I_eff_h_cap_stages = None 104 # effective value of harmonic voltage across capacitors in each stage of the combination (3 ph. delta) 105 self.U_eff_h_cap_stages = None 106 self.I_df = None 107 self.U_df = None 108 self.df = None 109 110 self._calc_fundamental_voltage(U_l1, I_l1) 111 self._calc_fundamental_stage_currents() 112 self._calc_fundamental_capacitor_voltages() 113 self._calc_fundamental_effective_currents() 114 self._calc_fundamental_effective_voltages() 115 116 self._calc_harmonic_network_impedance() 117 self._calc_harmonic_stage_currents(I_lh) 118 self._calc_harmonic_capacitor_voltages() 119 self._calc_harmonic_effective_currents() 120 self._calc_harmonic_effective_voltages() 121 122 self._create_current_data_frame() 123 self._create_voltage_data_frame() 124 self._create_data_frame() 125 126 def _calc_fundamental_voltage(self, U_l1, I_l1): 127 dU_1 = Z_cab2[0] * I_l1 # voltage drop across cable nr. 2 (cable between main switch board and capacitor bank) 128 self.U_1_par = U_l1 / np.sqrt(3) + dU_1 # voltage across parallel circuit combination // transformer 129 130 def _calc_fundamental_stage_currents(self): 131 # fundamental line current in each stage (star connection) 132 self.I_1_stages = [self.U_1_par / Z for Z in self.Z_1_stages] 133 134 def _calc_fundamental_effective_currents(self): 135 # effective value of phase currents through capacitors in each stage (delta connection) 136 self.I_eff_1_cap_stages = [np.abs(I) / np.sqrt(3) for I in self.I_1_stages] 137 138 def _calc_fundamental_capacitor_voltages(self): 139 # fundamental voltage across capacitors in each stage (star connection) 140 self.U_1_cap_stages = [(Z - Z_cab1[0]) * I for Z, I in zip(self.Z_1_stages, self.I_1_stages)] 141 142 def _calc_fundamental_effective_voltages(self): 143 # effective value of fundamental voltage across capacitors in each stage (delta connection) 144 self.U_eff_1_cap_stages = [np.abs(U) * np.sqrt(3) for U in self.U_1_cap_stages] 145 146 def _calc_harmonic_network_impedance(self): 147 if len(self.Z_h_stages) == 1: 148 self.Z_h_comb = self.Z_h_stages[0] 149 if len(self.Z_h_stages) > 1: 150 Y_stages = [1 / Z for Z in self.Z_h_stages] 151 Y_comb = np.zeros((len(f_range[1:]),)) 152 for Y_stage in Y_stages: 153 Y_comb = np.add(Y_comb, Y_stage) 154 self.Z_h_comb = 1 / Y_comb 155 Y_par = 1 / Z_tr[1:] + 1 / self.Z_h_comb 156 self.Z_h_par = 1 / Y_par 157 self.Z_h_nw = self.Z_h_par + Z_cab2[1:] 158 159 def _calc_harmonic_stage_currents(self, I_h): 160 # harmonic voltage across network 161 U_h = self.Z_h_nw * I_h 162 # harmonic voltage drop across cable nr. 2 163 dU_h = Z_cab2[1:] * I_h 164 # harmonic voltage across parallel circuit of combination and transformer 165 U_par_h = U_h - dU_h 166 # harmonic current through each stage 167 self.I_h_stages = [U_par_h / Z for Z in self.Z_h_stages] 168 169 def _calc_harmonic_capacitor_voltages(self): 170 # harmonic voltage across the capacitor of each stage 171 self.U_h_cap_stages = [(Z - Z_cab1[1:]) * I for Z, I in zip(self.Z_h_stages, self.I_h_stages)] 172 173 def _calc_harmonic_effective_currents(self): 174 # effective value of harmonic phase current through the capacitors of each stage (3 ph. delta connection) 175 self.I_eff_h_cap_stages = [np.abs(I) / np.sqrt(3) for I in self.I_h_stages] 176 177 def _calc_harmonic_effective_voltages(self): 178 # effective value of harmonic line voltage across the capacitors of each stage (3 ph. delta connection) 179 self.U_eff_h_cap_stages = [np.abs(U) * np.sqrt(3) for U in self.U_h_cap_stages] 180 181 def _create_current_data_frame(self): 182 index_I = [f'I{i}' for i in self.stages] 183 columns = [f'{f} Hz' for f in f_range] 184 185 data_I_0 = np.array([self.I_eff_1_cap_stages]) 186 data_I_h = np.array([I_h for I_h in self.I_eff_h_cap_stages]) 187 data_I = np.concatenate((data_I_0.T, data_I_h), axis=1) 188 189 self.I_df = pd.DataFrame(data=data_I, index=index_I, columns=columns) 190 self.I_df['RMS'] = np.sqrt(np.sum(data_I ** 2, axis=1, where=np.isfinite(data_I))) 191 192 def _create_voltage_data_frame(self): 193 index_U = [f'U{i}' for i in self.stages] 194 columns = [f'{f} Hz' for f in f_range] 195 196 data_U_0 = np.array([self.U_eff_1_cap_stages]) 197 data_U_h = np.array([U_h for U_h in self.U_eff_h_cap_stages]) 198 data_U = np.concatenate((data_U_0.T, data_U_h), axis=1) 199 200 self.U_df = pd.DataFrame(data=data_U, index=index_U, columns=columns) 201 self.U_df['RMS'] = np.sqrt(np.sum(data_U ** 2, axis=1, where=np.isfinite(data_U))) 202 203 def _create_data_frame(self): 204 self.df = pd.concat([self.I_df, self.U_df]) 205 206 207 if __name__ == '__main__': 208 I_h = np.array([2.35, 5.78, 4.62, 1.18, 3.12, 1.9, 0.3, 0.3, 0.23, np.nan, 0.19]) 209 comb6 = Combination( 210 name='comb6', 211 stages=(1, 2, 3, 4), 212 Z_stages=(Z_st1, Z_st2, Z_st3, Z_st4), 213 U_l1=402.0, 214 I_l1=99.33, 215 I_lh=I_h 216 ) 217 print(comb6.I_df) 218 print(comb6.U_df) 219