} // SatSubRegionAdjust public static double output(IF97Parameters key, double T, double p, SatState State) { double rho; char region = BackwardsRegion3.RegionDetermination(T, p); // if this is a saturated vapor or liquid function, make sure we're on // the correct side of the saturation curve and adjust region before // calculating density. region = SatSubRegionAdjust(State, p, region); rho = 1 / BackwardsRegion3.Region3_v_TP(region, T, p); #if REGION3_ITERATE // Use previous rho value from algebraic equations // as an initial guess to solve rhomass iteratively // with Newton-Raphson rho = rhomass(T, p, rho); #endif switch (key) // return all properties using the new rho value { case IF97Parameters.d: return(rho); case IF97Parameters.h: return(hmass(T, rho)); case IF97Parameters.s: return(smass(T, rho)); case IF97Parameters.u: return(umass(T, rho)); case IF97Parameters.cp: return(cpmass(T, rho)); case IF97Parameters.cv: return(cvmass(T, rho)); case IF97Parameters.w: return(speed_sound(T, rho)); case IF97Parameters.mu: return(visc(T, rho)); case IF97Parameters.tc: return(tcond(T, p, rho)); case IF97Parameters.drhodp: return(drhodp(T, rho)); default: throw new ArgumentException("Bad key to output"); // JPH: changed this to invalid_argument exception } }
public static double RegionOutput(IF97Parameters outkey, double T, double p, SatState State) { IF97REGIONS region = RegionDetermination_TP(T, p); switch (region) { case IF97REGIONS.REGION_1: if (State == SatState.VAPOR) return R2.output(outkey, T, p); // On saturation curve and need the Vapor phase else return R1.output(outkey, T, p); // otherwise, use Liquid Region 1 case IF97REGIONS.REGION_2: if (State == SatState.LIQUID) return R1.output(outkey, T, p); // On saturation curve and need the Liquid phase else return R2.output(outkey, T, p); // otherwise, use Vapor Region 2 case IF97REGIONS.REGION_3: return Region3.output(outkey, T, p, State); case IF97REGIONS.REGION_4: if (State == SatState.VAPOR) { return R2.output(outkey, T, p); } else if (State == SatState.LIQUID) { return R1.output(outkey, T, p); } else { throw new ArgumentOutOfRangeException("Cannot use Region 4 with T and p as inputs"); } case IF97REGIONS.REGION_5: return R5.output(outkey, T, p); } throw new ArgumentOutOfRangeException("Unable to match region"); }
static char SatSubRegionAdjust(SatState State, double p, char subregion) { switch (State) // See if saturated state is requested { // If looking for Saturated Vapor... case SatState.VAPOR: { // ...force below saturation curve if (subregion == 'C') { return('T'); } else if (subregion == 'S') { if (p < 20.5) { return('T'); } else { return('R'); } } else if (subregion == 'U') { if (p < 21.90096265) { return('X'); } else { return('Z'); } } else if (subregion == 'Y') { return('Z'); } break; } // If looking for Saturated Liquid... case SatState.LIQUID: { // ...force above saturation curve if (subregion == 'Z') { if (p > 21.93161551) { return('Y'); } else { return('U'); } } else if (subregion == 'X') { return('U'); } else if ((subregion == 'R') || (subregion == 'K')) { return('S'); } else if (subregion == 'T') { if (p > 19.00881189173929) { return('S'); } else { return('C'); } } break; } case SatState.NONE: default: return(subregion); } return(subregion); // in case no adjustment needs to be made } // SatSubRegionAdjust