Innovenergy_trunk/csharp/Lib/StatusApi/Phases/AcPhase.cs

35 lines
799 B
C#
Raw Normal View History

using static DecimalMath.DecimalEx;
namespace InnovEnergy.Lib.StatusApi.Phases;
2023-02-23 15:16:37 +00:00
public record AcPhase(Decimal Voltage, Decimal Current, Decimal Phi)
2023-02-22 13:46:36 +00:00
: Phase(Voltage, Current)
{
2023-02-23 15:16:37 +00:00
public Decimal ApparentPower => Voltage * Current;
public Decimal ActivePower => ApparentPower * PowerFactor;
public Decimal ReactivePower => ApparentPower * Sin(Phi);
public Decimal PowerFactor => Cos(Phi);
2023-02-22 13:46:36 +00:00
public static AcPhase FromActiveReactive
(
Decimal activePower,
2023-02-23 15:16:37 +00:00
Decimal reactivePower,
2023-02-22 13:46:36 +00:00
Decimal voltage,
Decimal current
)
{
2023-02-23 15:16:37 +00:00
var phi = ATan2(reactivePower, activePower);
2023-02-22 13:46:36 +00:00
return new AcPhase
(
Voltage: voltage,
Current: current,
2023-02-23 15:16:37 +00:00
Phi: phi
2023-02-22 13:46:36 +00:00
);
}
2023-02-23 15:16:37 +00:00
}