build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.ts
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 powerTotal (nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number {
17 return nbOfPhases * ACElectricUtils.powerPerPhase(V, Iph, cosPhi)
18 }
19
20 static powerPerPhase (V: number, Iph: number, cosPhi = 1): number {
21 const powerPerPhase = V * Iph * cosPhi
22 if (cosPhi === 1) {
23 return powerPerPhase
24 }
25 return Math.round(powerPerPhase)
26 }
27
28 static amperageTotal (nbOfPhases: number, Iph: number): number {
29 return nbOfPhases * Iph
30 }
31
32 static amperageTotalFromPower (P: number, V: number, cosPhi = 1): number {
33 const amperage = P / (V * cosPhi)
34 if (cosPhi === 1 && P % V === 0) {
35 return amperage
36 }
37 return Math.round(amperage)
38 }
39
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
43 if (amperage % nbOfPhases === 0) {
44 return amperagePerPhase
45 }
46 return Math.round(amperagePerPhase)
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 power (V: number, I: number): number {
60 return V * I
61 }
62
63 static amperage (P: number, V: number): number {
64 const amperage = P / V
65 if (P % V === 0) {
66 return amperage
67 }
68 return Math.round(amperage)
69 }
70 }