| 1 | /** |
| 2 | * Rationale: https://wiki.piment-noir.org/doku.php/en:cs:modelling_multi-phased_electrical_system_interconnexion |
| 3 | * Targeted to AC related values calculation. |
| 4 | * To use for DC, always consider cosPhi = 1 and do not use per phase helpers |
| 5 | */ |
| 6 | export default class ElectricUtils { |
| 7 | static ampTotal(nbOfPhases: number, Iph: number): number { |
| 8 | return nbOfPhases * Iph; |
| 9 | } |
| 10 | |
| 11 | static powerPerPhase(V: number, Iph: number, cosPhi = 1): number { |
| 12 | const powerPerPhase = V * Iph * cosPhi; |
| 13 | if (cosPhi === 1) { |
| 14 | return powerPerPhase; |
| 15 | } |
| 16 | return Math.round(powerPerPhase); |
| 17 | } |
| 18 | |
| 19 | static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number { |
| 20 | return nbOfPhases * ElectricUtils.powerPerPhase(V, Iph, cosPhi); |
| 21 | } |
| 22 | |
| 23 | static ampTotalFromPower(P: number, V: number, cosPhi = 1): number { |
| 24 | const power = P / (V * cosPhi); |
| 25 | if (cosPhi === 1 && P % V === 0) { |
| 26 | return power; |
| 27 | } |
| 28 | return Math.round(power); |
| 29 | } |
| 30 | |
| 31 | static ampPerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number { |
| 32 | const power = ElectricUtils.ampTotalFromPower(P, V, cosPhi); |
| 33 | const powerPerPhase = power / nbOfPhases; |
| 34 | if (power % nbOfPhases === 0) { |
| 35 | return powerPerPhase; |
| 36 | } |
| 37 | return Math.round(powerPerPhase); |
| 38 | } |
| 39 | } |