2023-06-13 11:03:49 +00:00
|
|
|
using InnovEnergy.Lib.Units.Power;
|
2023-04-25 09:27:57 +00:00
|
|
|
using static System.Math;
|
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Units.Composite;
|
|
|
|
|
2023-06-13 11:03:49 +00:00
|
|
|
|
|
|
|
public sealed class AcPower
|
2023-04-25 09:27:57 +00:00
|
|
|
{
|
2023-06-13 11:03:49 +00:00
|
|
|
private AcPower(){}
|
|
|
|
|
|
|
|
public ApparentPower Apparent { get; private init; } = null!;
|
|
|
|
public ActivePower Active { get; private init; } = null!;
|
|
|
|
public ReactivePower Reactive { get; private init; } = null!;
|
|
|
|
public Angle Phi { get; private init; } = null!;
|
|
|
|
public Double CosPhi { get; private init; }
|
2023-05-24 10:04:01 +00:00
|
|
|
|
2023-05-04 07:36:30 +00:00
|
|
|
public static AcPower FromActiveReactiveApparent(ActivePower activePower, ReactivePower reactivePower, ApparentPower apparentPower)
|
|
|
|
{
|
|
|
|
var q = reactivePower.Value;
|
|
|
|
var p = activePower.Value;
|
|
|
|
var s = apparentPower.Value;
|
|
|
|
var phi = Atan2(q, p);
|
|
|
|
|
|
|
|
return new AcPower
|
|
|
|
{
|
|
|
|
Active = p,
|
|
|
|
Reactive = q,
|
|
|
|
Apparent = s,
|
|
|
|
Phi = phi,
|
2023-05-24 10:04:01 +00:00
|
|
|
CosPhi = Cos(phi),
|
2023-05-04 07:36:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AcPower FromActiveReactive(ActivePower activePower, ReactivePower reactivePower)
|
|
|
|
{
|
|
|
|
var q = reactivePower.Value;
|
|
|
|
var p = activePower.Value;
|
|
|
|
var s = Sqrt(p * p + q * q);
|
|
|
|
var phi = Atan2(q, p);
|
|
|
|
|
|
|
|
return new AcPower
|
|
|
|
{
|
|
|
|
Active = p,
|
|
|
|
Reactive = q,
|
|
|
|
Apparent = s,
|
|
|
|
Phi = phi,
|
2023-06-13 11:03:49 +00:00
|
|
|
CosPhi = Cos(phi),
|
2023-05-04 07:36:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public static AcPower FromVoltageCurrentPhi(Voltage voltageRms, Current currentRms, Angle phi)
|
2023-04-25 09:27:57 +00:00
|
|
|
{
|
|
|
|
if (voltageRms < 0) throw new ArgumentException("RMS value cannot be negative", nameof(voltageRms));
|
|
|
|
if (currentRms < 0) throw new ArgumentException("RMS value cannot be negative", nameof(currentRms));
|
|
|
|
|
2023-05-04 07:36:30 +00:00
|
|
|
var cosPhi = Cos(phi.Value);
|
|
|
|
var apparent = voltageRms.Value * currentRms.Value;
|
2023-04-25 09:27:57 +00:00
|
|
|
|
|
|
|
return new AcPower
|
|
|
|
{
|
|
|
|
Apparent = apparent,
|
|
|
|
Active = apparent * cosPhi,
|
2023-05-04 07:36:30 +00:00
|
|
|
Reactive = apparent * Sin(phi.Value),
|
2023-04-25 09:27:57 +00:00
|
|
|
Phi = phi,
|
|
|
|
CosPhi = cosPhi
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-04 07:36:30 +00:00
|
|
|
public static AcPower SumOf(params AcPower[] phases)
|
|
|
|
{
|
|
|
|
var p = phases.Sum(l => l.Active.Value);
|
|
|
|
var q = phases.Sum(l => l.Reactive.Value);
|
|
|
|
var s = Sqrt(p * p + q * q);
|
|
|
|
|
|
|
|
Angle phi = Atan2(q, p);
|
|
|
|
|
|
|
|
return new AcPower
|
|
|
|
{
|
|
|
|
Apparent = s,
|
|
|
|
Active = p,
|
|
|
|
Reactive = q,
|
|
|
|
Phi = phi,
|
|
|
|
CosPhi = Cos(phi.Value)
|
|
|
|
};
|
|
|
|
}
|
2023-06-13 11:03:49 +00:00
|
|
|
|
|
|
|
public static AcPower Null { get; } = FromVoltageCurrentPhi(0, 0, 0);
|
|
|
|
|
|
|
|
public override String ToString() => Active.ToString(); // TODO: show all
|
2023-04-25 09:27:57 +00:00
|
|
|
}
|