simplify AcPhase

This commit is contained in:
ig 2023-02-23 16:16:37 +01:00
parent 5e9e9c560a
commit 438563fef8
2 changed files with 14 additions and 76 deletions

View File

@ -218,33 +218,12 @@ public class TruConvertAcDevice
( (
Ac: new ThreePhaseAcConnection Ac: new ThreePhaseAcConnection
( (
AcPhase.FromActiveReactive( new AcPhase(gridVoltageL1,phaseCurrentL1, ACos(powerAcL1/apparentPowerAcL1)),
activePower: powerAcL1, new AcPhase(gridVoltageL2,phaseCurrentL2, ACos(powerAcL2/apparentPowerAcL2)),
apparentPower: apparentPowerAcL1, new AcPhase(gridVoltageL3,phaseCurrentL3, ACos(powerAcL3/apparentPowerAcL3)),
voltage: gridVoltageL1,
current: phaseCurrentL1),
AcPhase.FromActiveReactive(
activePower: powerAcL2,
apparentPower: apparentPowerAcL2,
voltage: gridVoltageL2,
current: phaseCurrentL2),
AcPhase.FromActiveReactive(
activePower: powerAcL3,
apparentPower: apparentPowerAcL3,
voltage: gridVoltageL3,
current: phaseCurrentL3),
gridFrequency // Gird Frequency gridFrequency // Gird Frequency
), ),
Dc: new DcConnection(dcVoltage, dcCurrent),
Dc: new DcConnection
(
dcVoltage,
dcCurrent
),
SerialNumber : acSerialNumber.GetInt32(2009).ToString(), SerialNumber : acSerialNumber.GetInt32(2009).ToString(),

View File

@ -1,76 +1,35 @@
using DecimalMath;
using static DecimalMath.DecimalEx; using static DecimalMath.DecimalEx;
namespace InnovEnergy.Lib.StatusApi.Phases; namespace InnovEnergy.Lib.StatusApi.Phases;
public record AcPhase public record AcPhase(Decimal Voltage, Decimal Current, Decimal Phi)
(
Decimal Voltage,
Decimal Current,
Decimal Phi ,
Decimal ApparentPower,
Decimal ActivePower,
Decimal ReactivePower,
Decimal PowerFactor
)
: Phase(Voltage, Current) : 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 public static AcPhase FromActiveReactive
( (
Decimal activePower, Decimal activePower,
Decimal apparentPower, Decimal reactivePower,
Decimal voltage, Decimal voltage,
Decimal current Decimal current
) )
{ {
var reactivePower = Sqrt(Math.Abs(apparentPower * apparentPower - activePower * activePower )); var phi = ATan2(reactivePower, activePower);
var phi = ATan2(reactivePower, activePower);
return new AcPhase return new AcPhase
( (
Voltage: voltage, Voltage: voltage,
Current: current, Current: current,
Phi: phi, Phi: phi
ApparentPower: apparentPower,
ActivePower: activePower,
ReactivePower: reactivePower,
PowerFactor: Cos(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;}
} }