"""М5. Фільтрокомпенсувальний пристрій (ФКП): реактивна потужність, налаштовані фільтри, частотна характеристика імпедансу вузла, гармонічні напруги після фільтра; контрольний випадок — конденсаторна батарея без реакторів.""" import math import numpy as np def q_comp(p_mw: float, cos1: float, cos2: float) -> float: """Потрібна реактивна потужність, Мвар: P·(tg φ₁ − tg φ₂).""" return p_mw * (math.tan(math.acos(cos1)) - math.tan(math.acos(cos2))) def branch(q_mvar: float, u_kv: float, h_t: float, qf: float = 30.0) -> dict: """Фільтр, налаштований на h_t, з потужністю q_mvar на основній частоті: X_C − X_L = U²/Q, X_L = X_C/h_t².""" xc = u_kv ** 2 / q_mvar * h_t ** 2 / (h_t ** 2 - 1) xl = xc / h_t ** 2 r = h_t * xl / qf c_uF = 1 / (2 * math.pi * 50 * xc) * 1e6 l_mH = xl / (2 * math.pi * 50) * 1e3 return {"q": q_mvar, "h_t": h_t, "xc": xc, "xl": xl, "r": r, "C_uF": c_uF, "L_mH": l_mH, "u_c1": h_t ** 2 / (h_t ** 2 - 1)} def z_branch(b: dict, h: float) -> complex: return complex(b["r"], h * b["xl"] - b["xc"] / h) R_LOAD = 6.0 # Ом, активне навантаження вузла (≈ U²/P для 17 МВт), демпфує резонанси def z_node(h: np.ndarray, x_s: float, branches: list[dict], r_s_ratio: float = 0.1, r_load: float = R_LOAD) -> np.ndarray: """Імпеданс вузла 10 кВ на частоті h·50 Гц: мережа (R_s + jhX_s; R_s = 0,1·X_s·√h), активне навантаження r_load і фільтри — паралельно.""" out = [] for hh in np.atleast_1d(h): y = 1 / complex(r_s_ratio * x_s * math.sqrt(hh), hh * x_s) + (1 / r_load if r_load else 0) y += sum(1 / z_branch(b, hh) for b in branches) out.append(1 / y) return np.array(out) def resonances(x_s: float, branches: list[dict]) -> list[float]: """Паралельні резонанси (максимуми |Z|) у діапазоні h = 1,5…30.""" hh = np.arange(1.5, 30, 0.01) z = np.abs(z_node(hh, x_s, branches)) idx = [i for i in range(1, len(z) - 1) if z[i] > z[i - 1] and z[i] > z[i + 1] and z[i] > 1.5 * hh[i] * x_s] return [float(round(hh[i], 2)) for i in idx] def harmonic_voltages(i_h: dict, x_s: float, branches: list[dict], u_kv: float, u_bg: dict | None = None) -> dict: """U_h, % U₁ від джерела струмів i_h (А) і фонових напруг мережі u_bg (% — діють через подільник мережа/вузол).""" uph = u_kv * 1e3 / math.sqrt(3) out = {} for h, ih in i_h.items(): zn = z_node(np.array([h]), x_s, branches)[0] u = ih * abs(zn) / uph * 100 if u_bg and h in u_bg: zs = complex(0.1 * x_s * math.sqrt(h), h * x_s) u = math.hypot(u, u_bg[h] * abs(zn / zs)) out[h] = u return out def thd_of(u: dict) -> float: return math.sqrt(sum(x ** 2 for x in u.values()))