Simplify DC current output type handling.
[e-mobility-charging-stations-simulator.git] / src / utils / ElectricUtils.js
1 /**
2 * Targeted to AC related values calculation.
3 * To use for DC, always consider cosPhi = 1 and do not use per phase helpers
4 */
5 export default class ElectricUtils {
6 static ampTotal(nbOfPhases, Iph) {
7 return nbOfPhases * Iph;
8 }
9
10 static powerPerPhase(V, Iph, cosPhi = 1) {
11 const powerPerPhase = V * Iph * cosPhi;
12 if (cosPhi === 1) {
13 return powerPerPhase;
14 }
15 return Math.round(powerPerPhase);
16 }
17
18 static powerTotal(nbOfPhases, V, Iph, cosPhi = 1) {
19 return nbOfPhases * ElectricUtils.powerPerPhase(V, Iph, cosPhi);
20 }
21
22 static ampTotalFromPower(P, V, cosPhi = 1) {
23 const power = P / (V * cosPhi);
24 if (cosPhi === 1 && P % V === 0) {
25 return power;
26 }
27 return Math.round(power);
28 }
29
30 static ampPerPhaseFromPower(nbOfPhases, P, V, cosPhi = 1) {
31 const power = ElectricUtils.ampTotalFromPower(P, V, cosPhi);
32 const powerPerPhase = power / nbOfPhases;
33 if (power % nbOfPhases === 0) {
34 return powerPerPhase;
35 }
36 return Math.round(powerPerPhase);
37 }
38 }