2023-02-22 13:46:36 +00:00
|
|
|
using DecimalMath;
|
2023-02-21 06:27:20 +00:00
|
|
|
using static DecimalMath.DecimalEx;
|
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.StatusApi.Phases;
|
|
|
|
|
|
|
|
|
2023-02-22 13:46:36 +00:00
|
|
|
public record AcPhase
|
|
|
|
(
|
|
|
|
Decimal Voltage,
|
|
|
|
Decimal Current,
|
|
|
|
Decimal Phi ,
|
|
|
|
Decimal ApparentPower,
|
|
|
|
Decimal ActivePower,
|
|
|
|
Decimal ReactivePower,
|
|
|
|
Decimal PowerFactor
|
|
|
|
)
|
|
|
|
: Phase(Voltage, Current)
|
2023-02-21 06:27:20 +00:00
|
|
|
{
|
2023-02-22 13:46:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
public static AcPhase FromActiveReactive
|
|
|
|
(
|
|
|
|
Decimal activePower,
|
|
|
|
Decimal reactivePower,
|
|
|
|
Decimal voltage,
|
|
|
|
Decimal current
|
|
|
|
)
|
|
|
|
{
|
|
|
|
var apparentPower = Sqrt(activePower * activePower + reactivePower * reactivePower);
|
|
|
|
var phi = ATan2(reactivePower, activePower);
|
|
|
|
|
|
|
|
return new AcPhase
|
|
|
|
(
|
|
|
|
Voltage: voltage,
|
|
|
|
Current: current,
|
|
|
|
Phi: phi,
|
|
|
|
ApparentPower: apparentPower,
|
|
|
|
ActivePower: activePower,
|
|
|
|
ReactivePower: reactivePower,
|
|
|
|
PowerFactor: Cos(phi)
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static AcPhase FromVoltageCurrentPhi(Decimal voltage, Decimal current, Decimal phi)
|
|
|
|
{
|
|
|
|
|
|
|
|
var powerFactor = Cos(phi);
|
|
|
|
var apparentPower = voltage * current;
|
|
|
|
var activePower = apparentPower * powerFactor;
|
|
|
|
var reactivePower = apparentPower * Sin(phi);
|
|
|
|
|
|
|
|
|
|
|
|
return new AcPhase
|
|
|
|
(
|
|
|
|
voltage,
|
|
|
|
current,
|
|
|
|
phi,
|
|
|
|
apparentPower,
|
|
|
|
activePower,
|
|
|
|
reactivePower,
|
|
|
|
powerFactor
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//public Decimal ApparentPower => Voltage * Current;
|
|
|
|
//public Decimal ActivePower => ApparentPower * PowerFactor;
|
|
|
|
//public Decimal ReactivePower => ApparentPower * Sin(Phi);
|
|
|
|
//public Decimal PowerFactor => Cos(Phi);
|
2023-02-21 06:27:20 +00:00
|
|
|
|
2023-02-22 13:46:36 +00:00
|
|
|
// public Decimal ReactivePower {get; init;}
|
|
|
|
// public Decimal ApparentPower {get; }
|
|
|
|
// public Decimal ActivePower {get; }
|
|
|
|
// public Decimal PowerFactor {get; init;}
|
2023-02-21 06:27:20 +00:00
|
|
|
|
|
|
|
}
|