private void InterpolateProperties( Func <PVTEntry, double> getter, Action <double> setter, ThreePhaseEntry container) { double num = 0; if (container.VaporEntry != null) { num += getter(container.VaporEntry) * VaporMassFraction; } if (container.LiquidEntry != null) { num += getter(container.LiquidEntry) * LiquidMassFraction; } if (container.SolidEntry != null) { num += getter(container.SolidEntry) * SolidMassFraction; } setter(num); }
/// <summary> /// /// </summary> /// <param name="container"></param> /// <param name="vaporMassFraction"></param> /// <param name="liquidMassFraction"></param> /// <param name="solidMassFraction"></param> public PVTEntry(ThreePhaseEntry container, double vaporMassFraction, double liquidMassFraction, double solidMassFraction) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (container.VaporEntry != null && container.VaporEntry.Region != Region.Vapor) { throw new ArgumentOutOfRangeException(nameof(container.VaporEntry), "Must be vapor!"); } if (container.LiquidEntry != null && container.LiquidEntry.Region != Region.Liquid) { throw new ArgumentOutOfRangeException(nameof(container.LiquidEntry), "Must be liquid!"); } if (container.SolidEntry != null && container.SolidEntry.Region != Region.Solid) { throw new ArgumentOutOfRangeException(nameof(container.SolidEntry), "Must be solid!"); } if (vaporMassFraction + liquidMassFraction + solidMassFraction != 1) { throw new ArgumentException("Fractions do not up to 1!"); } VaporMassFraction = vaporMassFraction; LiquidMassFraction = liquidMassFraction; SolidMassFraction = solidMassFraction; UpdateRegion(); InterpolateProperties((x) => x.Temperature, (x) => Temperature = x, container); InterpolateProperties((x) => x.Pressure, (x) => Pressure = x, container); InterpolateProperties((x) => x.SpecificVolume, (x) => SpecificVolume = x, container); Density = 1 / SpecificVolume; InterpolateProperties((x) => x.InternalEnergy, (x) => InternalEnergy = x, container); InterpolateProperties((x) => x.Enthalpy, (x) => Enthalpy = x, container); InterpolateProperties((x) => x.Entropy, (x) => Entropy = x, container); InterpolateProperties((x) => x.IsochoricHeatCapacity, (x) => IsochoricHeatCapacity = x, container); InterpolateProperties((x) => x.IsobaricHeatCapacity, (x) => IsobaricHeatCapacity = x, container); InterpolateProperties((x) => x.SpeedOfSound, (x) => SpeedOfSound = x, container); }