Performance statistics: add JSON file storage support.
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.ts
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 static amperageTotal(nbOfPhases: number, Iph: number): number {
12 return nbOfPhases * Iph;
13 }
14
15 static powerPerPhase(V: number, Iph: number, cosPhi = 1): number {
16 const powerPerPhase = V * Iph * cosPhi;
17 if (cosPhi === 1) {
18 return powerPerPhase;
19 }
20 return Math.round(powerPerPhase);
21 }
22
23 static powerTotal(nbOfPhases: number, V: number, Iph: number, cosPhi = 1): number {
24 return nbOfPhases * ACElectricUtils.powerPerPhase(V, Iph, cosPhi);
25 }
26
27 static amperageTotalFromPower(P: number, V: number, cosPhi = 1): number {
28 const amperage = P / (V * cosPhi);
29 if (cosPhi === 1 && P % V === 0) {
30 return amperage;
31 }
32 return Math.round(amperage);
33 }
34
35 static amperagePerPhaseFromPower(nbOfPhases: number, P: number, V: number, cosPhi = 1): number {
36 const amperage = ACElectricUtils.amperageTotalFromPower(P, V, cosPhi);
37 const amperagePerPhase = amperage / nbOfPhases;
38 if (amperage % nbOfPhases === 0) {
39 return amperagePerPhase;
40 }
41 return Math.round(amperagePerPhase);
42 }
43 }
44
45 /**
46 * Targeted to DC related values calculation.
47 */
48 export class DCElectricUtils {
49 static power(V: number, I: number): number {
50 return V * I;
51 }
52
53 static amperage(P: number, V: number): number {
54 const amperage = P / V;
55 if (P % V === 0) {
56 return amperage;
57 }
58 return Math.round(amperage);
59 }
60 }