private PVTEntry GetEntryAtPressureAndProperty( double pressure, double targetPropVal, Func <PVTEntry, double> propGetter) { PVTEntry liqEntry = GetEntryAtSatPressure(pressure, SaturationRegion.Liquid); PVTEntry vapEntry = GetEntryAtSatPressure(pressure, SaturationRegion.Vapor); if (vapEntry != null && liqEntry != null && propGetter(vapEntry) >= targetPropVal && propGetter(liqEntry) <= targetPropVal) { double liqFac = (propGetter(vapEntry) - targetPropVal) / (propGetter(vapEntry) - propGetter(liqEntry)); LiquidVaporEntryFactory fac = new LiquidVaporEntryFactory(vapEntry, liqEntry, liqFac); return(fac.BuildThermoEntry()); } double fx(double x) { PVTEntry entry = GetEntryAtTemperatureAndPressure(x, pressure); return(entry != null?propGetter(entry) - targetPropVal : double.NaN); } Range tempRange = GetTemperatureRange(pressure); SolverResult temperature = NewtonsMethod.Solve(fx, tempRange); return(temperature.ReachedMaxGuesses ? null : GetEntryAtTemperatureAndPressure(temperature.Value, pressure)); }
public LiquidVaporEntryFactory(PVTEntry vapEntry, PVTEntry liqEntry, double liquidFraction) { _container = new ThreePhaseEntry() { VaporEntry = vapEntry ?? throw new ArgumentNullException(nameof(vapEntry)), LiquidEntry = liqEntry ?? throw new ArgumentNullException(nameof(liqEntry)), SolidEntry = null }; if (liquidFraction < 0 || liquidFraction > 1) { throw new ArgumentOutOfRangeException(nameof(liquidFraction), "Must be between 0 and 1"); } _liquidFraction = liquidFraction; }