| 1 | // Copyright Jerome Benoit. 2021. All Rights Reserved. |
| 2 | |
| 3 | /** |
| 4 | * Rationale: https://wiki.piment-noir.org/doku.php/en:cs:modelling_multi-phased_electrical_system_interconnexion |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * Targeted to AC related values calculation. |
| 9 | */ |
| 10 | export class ACElectricUtils { |
| 11 | private constructor() { |
| 12 | // This is intentional |
| 13 | } |
| 14 | |
| 15 | static amperageTotal(nbOfPhases: number, Iph: number): number { |
| 16 | return nbOfPhases * Iph; |
| 17 | } |
| 18 | |
| 19 | static powerPerPhase(V: number, Iph: number, cosPhi = 1): number { |
| 20 | const powerPerPhase = V * Iph * cosPhi; |
| 21 | if (cosPhi === 1) { |
| 22 | return powerPerPhase; |
| 23 | } |
| 24 | return Math.round(powerPerPhase); |
| 25 | } |
| 26 | |
| 27 | static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number { |
| 28 | return nbOfPhases * ACElectricUtils.powerPerPhase(V, Iph, cosPhi); |
| 29 | } |
| 30 | |
| 31 | static amperageTotalFromPower(P: number, V: number, cosPhi = 1): number { |
| 32 | const amperage = P / (V * cosPhi); |
| 33 | if (cosPhi === 1 && P % V === 0) { |
| 34 | return amperage; |
| 35 | } |
| 36 | return Math.round(amperage); |
| 37 | } |
| 38 | |
| 39 | static amperagePerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number { |
| 40 | const amperage = ACElectricUtils.amperageTotalFromPower(P, V, cosPhi); |
| 41 | const amperagePerPhase = amperage / nbOfPhases; |
| 42 | if (amperage % nbOfPhases === 0) { |
| 43 | return amperagePerPhase; |
| 44 | } |
| 45 | return Math.round(amperagePerPhase); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Targeted to DC related values calculation. |
| 51 | */ |
| 52 | export class DCElectricUtils { |
| 53 | static power(V: number, I: number): number { |
| 54 | return V * I; |
| 55 | } |
| 56 | |
| 57 | static amperage(P: number, V: number): number { |
| 58 | const amperage = P / V; |
| 59 | if (P % V === 0) { |
| 60 | return amperage; |
| 61 | } |
| 62 | return Math.round(amperage); |
| 63 | } |
| 64 | } |