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