| 1 | // Copyright Jerome Benoit. 2021-2024. 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 | // eslint-disable-next-line @typescript-eslint/no-extraneous-class |
| 11 | export class ACElectricUtils { |
| 12 | private constructor () { |
| 13 | // This is intentional |
| 14 | } |
| 15 | |
| 16 | static amperagePerPhaseFromPower (nbOfPhases: number, P: number, V: number, cosPhi = 1): number { |
| 17 | const amperage = ACElectricUtils.amperageTotalFromPower(P, V, cosPhi) |
| 18 | const amperagePerPhase = amperage / nbOfPhases |
| 19 | if (amperage % nbOfPhases === 0) { |
| 20 | return amperagePerPhase |
| 21 | } |
| 22 | return Math.round(amperagePerPhase) |
| 23 | } |
| 24 | |
| 25 | static amperageTotal (nbOfPhases: number, Iph: number): number { |
| 26 | return nbOfPhases * Iph |
| 27 | } |
| 28 | |
| 29 | static amperageTotalFromPower (P: number, V: number, cosPhi = 1): number { |
| 30 | const amperage = P / (V * cosPhi) |
| 31 | if (cosPhi === 1 && P % V === 0) { |
| 32 | return amperage |
| 33 | } |
| 34 | return Math.round(amperage) |
| 35 | } |
| 36 | |
| 37 | static powerPerPhase (V: number, Iph: number, cosPhi = 1): number { |
| 38 | const powerPerPhase = V * Iph * cosPhi |
| 39 | if (cosPhi === 1) { |
| 40 | return powerPerPhase |
| 41 | } |
| 42 | return Math.round(powerPerPhase) |
| 43 | } |
| 44 | |
| 45 | static powerTotal (nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number { |
| 46 | return nbOfPhases * ACElectricUtils.powerPerPhase(V, Iph, cosPhi) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Targeted to DC related values calculation. |
| 52 | */ |
| 53 | // eslint-disable-next-line @typescript-eslint/no-extraneous-class |
| 54 | export class DCElectricUtils { |
| 55 | private constructor () { |
| 56 | // This is intentional |
| 57 | } |
| 58 | |
| 59 | static amperage (P: number, V: number): number { |
| 60 | const amperage = P / V |
| 61 | if (P % V === 0) { |
| 62 | return amperage |
| 63 | } |
| 64 | return Math.round(amperage) |
| 65 | } |
| 66 | |
| 67 | static power (V: number, I: number): number { |
| 68 | return V * I |
| 69 | } |
| 70 | } |