simplify AcPhase
This commit is contained in:
parent
5e9e9c560a
commit
438563fef8
|
@ -218,33 +218,12 @@ public class TruConvertAcDevice
|
|||
(
|
||||
Ac: new ThreePhaseAcConnection
|
||||
(
|
||||
AcPhase.FromActiveReactive(
|
||||
activePower: powerAcL1,
|
||||
apparentPower: apparentPowerAcL1,
|
||||
voltage: gridVoltageL1,
|
||||
current: phaseCurrentL1),
|
||||
|
||||
AcPhase.FromActiveReactive(
|
||||
activePower: powerAcL2,
|
||||
apparentPower: apparentPowerAcL2,
|
||||
voltage: gridVoltageL2,
|
||||
current: phaseCurrentL2),
|
||||
|
||||
AcPhase.FromActiveReactive(
|
||||
activePower: powerAcL3,
|
||||
apparentPower: apparentPowerAcL3,
|
||||
voltage: gridVoltageL3,
|
||||
current: phaseCurrentL3),
|
||||
|
||||
new AcPhase(gridVoltageL1,phaseCurrentL1, ACos(powerAcL1/apparentPowerAcL1)),
|
||||
new AcPhase(gridVoltageL2,phaseCurrentL2, ACos(powerAcL2/apparentPowerAcL2)),
|
||||
new AcPhase(gridVoltageL3,phaseCurrentL3, ACos(powerAcL3/apparentPowerAcL3)),
|
||||
gridFrequency // Gird Frequency
|
||||
),
|
||||
|
||||
|
||||
Dc: new DcConnection
|
||||
(
|
||||
dcVoltage,
|
||||
dcCurrent
|
||||
),
|
||||
Dc: new DcConnection(dcVoltage, dcCurrent),
|
||||
|
||||
SerialNumber : acSerialNumber.GetInt32(2009).ToString(),
|
||||
|
||||
|
|
|
@ -1,76 +1,35 @@
|
|||
using DecimalMath;
|
||||
using static DecimalMath.DecimalEx;
|
||||
|
||||
namespace InnovEnergy.Lib.StatusApi.Phases;
|
||||
|
||||
|
||||
public record AcPhase
|
||||
(
|
||||
Decimal Voltage,
|
||||
Decimal Current,
|
||||
Decimal Phi ,
|
||||
Decimal ApparentPower,
|
||||
Decimal ActivePower,
|
||||
Decimal ReactivePower,
|
||||
Decimal PowerFactor
|
||||
)
|
||||
public record AcPhase(Decimal Voltage, Decimal Current, Decimal Phi)
|
||||
: Phase(Voltage, Current)
|
||||
{
|
||||
|
||||
public Decimal ApparentPower => Voltage * Current;
|
||||
public Decimal ActivePower => ApparentPower * PowerFactor;
|
||||
public Decimal ReactivePower => ApparentPower * Sin(Phi);
|
||||
public Decimal PowerFactor => Cos(Phi);
|
||||
|
||||
public static AcPhase FromActiveReactive
|
||||
(
|
||||
Decimal activePower,
|
||||
Decimal apparentPower,
|
||||
Decimal reactivePower,
|
||||
Decimal voltage,
|
||||
Decimal current
|
||||
)
|
||||
{
|
||||
var reactivePower = Sqrt(Math.Abs(apparentPower * apparentPower - activePower * activePower ));
|
||||
var phi = ATan2(reactivePower, activePower);
|
||||
var phi = ATan2(reactivePower, activePower);
|
||||
|
||||
return new AcPhase
|
||||
(
|
||||
Voltage: voltage,
|
||||
Current: current,
|
||||
Phi: phi,
|
||||
ApparentPower: apparentPower,
|
||||
ActivePower: activePower,
|
||||
ReactivePower: reactivePower,
|
||||
PowerFactor: Cos(phi)
|
||||
Phi: phi
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static AcPhase CreateInstance(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);
|
||||
|
||||
// public Decimal ReactivePower {get; init;}
|
||||
// public Decimal ApparentPower {get; }
|
||||
// public Decimal ActivePower {get; }
|
||||
// public Decimal PowerFactor {get; init;}
|
||||
|
||||
}
|
Loading…
Reference in New Issue