Innovenergy_trunk/csharp/Lib/Units/Composite/AcPhase.cs

66 lines
2.1 KiB
C#
Raw Normal View History

using static DecimalMath.DecimalEx;
namespace InnovEnergy.Lib.Units.Composite;
2023-03-01 09:52:21 +00:00
public record AcPhase : IBus
{
private readonly Voltage _Voltage;
public Voltage Voltage
{
get => _Voltage;
init => _Voltage = value >= 0m ? value : throw new ArgumentException("RMS value cannot be negative");
}
private readonly Current _Current;
public Current Current
{
get => _Current;
init => _Current = value >= 0m ? value : throw new ArgumentException("RMS value cannot be negative");
}
public Angle Phi { get; init; }
2023-02-26 18:19:16 +00:00
public ApparentPower ApparentPower => Voltage.Value * Current.Value ;
public Power ActivePower => ApparentPower.Value * PowerFactor;
2023-02-26 14:39:55 +00:00
public ReactivePower ReactivePower => ApparentPower.Value * Sin(Phi);
public Decimal PowerFactor => Cos(Phi);
2023-02-26 18:19:16 +00:00
// public static AcPhase operator |(AcPhase left, AcPhase right)
// {
// // the Voltages of two phases are expected to be in phase and equal
//
// var v = left.Voltage | right.Voltage;
//
// // currents (RMS) can be different and out of phase
// // https://www.johndcook.com/blog/2020/08/17/adding-phase-shifted-sine-waves/
//
// // IF
// // left(t) = ILeft sin(ωt)
// // right(t) = IRight sin(ωt + φ).
// // sum(t) = left(t) + right(t) = ISum sin(ωt + ψ).
//
// // THEN
// // ψ = arctan( IRight * sin(φ) / (ILeft + IRight cos(φ)) ).
// // C = IRight * sin(φ) / sin(ψ).
//
// // in this calculation left(t) has zero phase shift.
// // we can shift both waves by -left.Phi, so
// // φ := right.phi - left.phi
//
//
// var phi = right.Phi - left.Phi;
// var phiSum = ATan2(right.Current * Sin(phi), left.Current + right.Current * Cos(phi));
// var iSum = right.Current * Sin(phi) / Sin(phiSum);
//
// return new AcPhase
// {
// Voltage = v,
// Current = iSum,
// Phi = phiSum
// };
// }
}