|
| 1 | +# https://www.electronics-tutorials.ws/accircuits/power-factor-correction.html |
| 2 | +# https://www.youtube.com/watch?v=YZcBkFdstEU |
| 3 | + |
| 4 | +import math |
| 5 | + |
| 6 | + |
| 7 | +def shunt_capacitor_power_factor_correction( |
| 8 | + voltage: float, |
| 9 | + frequency: float, |
| 10 | + real_power: float, |
| 11 | + current_power_factor: float, |
| 12 | + expected_power_factor: float, |
| 13 | +) -> float: |
| 14 | + """ |
| 15 | + Calculate shunt capacitor that will be added in order to achieve the |
| 16 | + expected power factor |
| 17 | +
|
| 18 | + Examples: |
| 19 | + >>> shunt_capacitor_power_factor_correction(120,60,4000,0.8,0.95) |
| 20 | + 0.00031043753362948597 |
| 21 | + >>> shunt_capacitor_power_factor_correction(150,50,2000,0.6,0.87) |
| 22 | + 0.00021690547192207782 |
| 23 | + >>> shunt_capacitor_power_factor_correction(115,0,800,0.6,0.87) |
| 24 | + Traceback (most recent call last): |
| 25 | + ... |
| 26 | + ValueError: frequency is zero dc circuit |
| 27 | + >>> shunt_capacitor_power_factor_correction(0,60,800,0.6,0.87) |
| 28 | + Traceback (most recent call last): |
| 29 | + ... |
| 30 | + ValueError: voltage is zero no excitation |
| 31 | + """ |
| 32 | + |
| 33 | + |
| 34 | + if ( |
| 35 | + not isinstance(current_power_factor, (int, float)) |
| 36 | + or not isinstance(expected_power_factor, (int, float)) |
| 37 | + or current_power_factor < -1 |
| 38 | + or current_power_factor > 1 |
| 39 | + or expected_power_factor < -1 |
| 40 | + or expected_power_factor > 1 |
| 41 | + ): |
| 42 | + raise ValueError("power_factor must be a valid float value between -1 and 1.") |
| 43 | + |
| 44 | + if frequency == 0: |
| 45 | + raise ValueError("frequency is zero dc circuit") |
| 46 | + |
| 47 | + if voltage == 0: |
| 48 | + raise ValueError("voltage is zero no excitation") |
| 49 | + |
| 50 | + current_theta = math.acos(current_power_factor) |
| 51 | + expected_theta = math.acos(expected_power_factor) |
| 52 | + |
| 53 | + current_apparent_power = real_power / current_power_factor |
| 54 | + current_reactive_power = current_apparent_power * math.sin(current_theta) |
| 55 | + expected_apparent_power = real_power / expected_power_factor |
| 56 | + expected_reactive_power = expected_apparent_power * math.sin(expected_theta) |
| 57 | + |
| 58 | + """ |
| 59 | + The difference between the new and old reactive powers is due to the |
| 60 | + parallel addition of the capacitor to the load |
| 61 | + """ |
| 62 | + change_reactive_power = current_reactive_power - expected_reactive_power |
| 63 | + |
| 64 | + return change_reactive_power / (2 * math.pi * frequency * (voltage**2)) |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +def shunt_inductor_power_factor_correction( |
| 69 | + voltage: float, |
| 70 | + frequency: float, |
| 71 | + real_power: float, |
| 72 | + current_power_factor: float, |
| 73 | + expected_power_factor: float, |
| 74 | +) -> float: |
| 75 | + """ |
| 76 | + Calculate shunt capacitor that will be added in order to achieve the |
| 77 | + expected power factor |
| 78 | +
|
| 79 | + Examples: |
| 80 | + >>> shunt_inductor_power_factor_correction(120,60,4000,0.8,0.95) |
| 81 | + 0.02266540783980564 |
| 82 | + >>> shunt_inductor_power_factor_correction(120,60,4000,-0.8,-0.4) |
| 83 | + 0.006195660726930193 |
| 84 | + >>> shunt_inductor_power_factor_correction(115,0,800,-0.6,0.87) |
| 85 | + Traceback (most recent call last): |
| 86 | + ... |
| 87 | + ValueError: frequency is zero dc circuit |
| 88 | + >>> shunt_inductor_power_factor_correction(0,60,800,-0.6,0.87) |
| 89 | + Traceback (most recent call last): |
| 90 | + ... |
| 91 | + ValueError: voltage is zero no excitation |
| 92 | + """ |
| 93 | + |
| 94 | + if ( |
| 95 | + not isinstance(current_power_factor, (int, float)) |
| 96 | + or not isinstance(expected_power_factor, (int, float)) |
| 97 | + or current_power_factor < -1 |
| 98 | + or current_power_factor > 1 |
| 99 | + or expected_power_factor < -1 |
| 100 | + or expected_power_factor > 1 |
| 101 | + ): |
| 102 | + raise ValueError("power_factor must be a valid float value between -1 and 1.") |
| 103 | + |
| 104 | + if frequency == 0: |
| 105 | + raise ValueError("frequency is zero dc circuit") |
| 106 | + |
| 107 | + if voltage == 0: |
| 108 | + raise ValueError("voltage is zero no excitation") |
| 109 | + |
| 110 | + current_theta = math.acos(current_power_factor) |
| 111 | + expected_theta = math.acos(expected_power_factor) |
| 112 | + |
| 113 | + current_apparent_power = real_power / current_power_factor |
| 114 | + current_reactive_power = current_apparent_power * math.sin(current_theta) |
| 115 | + expected_apparent_power = real_power / expected_power_factor |
| 116 | + expected_reactive_power = expected_apparent_power * math.sin(expected_theta) |
| 117 | + |
| 118 | + """ |
| 119 | + The difference between the new and old reactive powers is due to the |
| 120 | + parallel addition of the inductor to the load |
| 121 | + """ |
| 122 | + change_reactive_power = current_reactive_power - expected_reactive_power |
| 123 | + |
| 124 | + return (voltage**2) / ( 2 * math.pi * frequency * change_reactive_power ) |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == "__main__": |
| 129 | + import doctest |
| 130 | + |
| 131 | + doctest.testmod() |
0 commit comments