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