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

34 lines
1.1 KiB
C#

using static System.Math;
namespace InnovEnergy.Lib.Units.Composite;
public class AcPower
{
public Double Apparent { get; internal init; }
public Double Active { get; internal init; }
public Double Reactive { get; internal init; }
public Double Phi { get; internal init; }
public Double CosPhi { get; internal init; }
public static AcPower FromVoltageCurrentPhi(Double voltageRms, Double currentRms, Double phi)
{
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));
phi = NormalizePhi(phi);
var cosPhi = Cos(phi);
var apparent = voltageRms * currentRms;
return new AcPower
{
Apparent = apparent,
Active = apparent * cosPhi,
Reactive = apparent * Sin(phi),
Phi = phi,
CosPhi = cosPhi
};
}
private static Double NormalizePhi(Double phi) => (phi + PI) % Tau - PI; // Tau is 2pi
}