Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find the intersection of relative humidity and enthalpy lines #70

Open
heymikid opened this issue Dec 28, 2020 · 1 comment
Open

Find the intersection of relative humidity and enthalpy lines #70

heymikid opened this issue Dec 28, 2020 · 1 comment

Comments

@heymikid
Copy link

I am enjoying this library. Thank you for making it available.

I had to find the intersection point between RH lines and moist air enthalpy lines. I was using the js version and ended up writing this outside the library, following the bisection search code found in GetTWetBulbFromHumRatio.

You may consider adding this (and another one like it - to find the intersection of TWetBulb with RH) to the library itself if you wish.

function GetTDryBulbFromEnthalpyRelHum(MoistAirEnthalpy, RelHum, Pressure) {
  /*
  We want to determine the psychrometric properties from the moist air enthalpy 
  and relative humidity. These two lines (RH(T), h(T)) cross at one point. We find TDryBulb of this point.
  */
  var T_TOLERANCE = 1E-10;     

  var TDryBulbInf, TDryBulbSup, TDryBulb;
  var HumRatio, currRelHum;
  var index = 1;
  
  //initial guesses
  TDryBulbInf = psychrolib.GetTDryBulbFromEnthalpyAndHumRatio(MoistAirEnthalpy, 0);
  TDryBulbSup = psychrolib.GetTWetBulbFromRelHum(TDryBulbInf, 0, Pressure) - 2; //wet bulb T is above the enthalpy line, not good enough for high target RH. -2deg is enough to cover it
  TDryBulb = (TDryBulbSup + TDryBulbInf) / 2.;

  //bisection loop
  while ((TDryBulbInf - TDryBulbSup) > T_TOLERANCE) {
    //compute the relative humidity for the current guess of TDryBulb (first get Humidity Ratio)
    HumRatio = psychrolib.GetHumRatioFromEnthalpyAndTDryBulb(MoistAirEnthalpy, TDryBulb);
    currRelHum = psychrolib.GetRelHumFromHumRatio(TDryBulb,HumRatio, Pressure);

    //get new bounds
    if (currRelHum < RelHum)
      TDryBulbInf = TDryBulb;
    else
      TDryBulbSup = TDryBulb;

    //new guess for TDryBulb
    TDryBulb = (TDryBulbSup + TDryBulbInf) / 2.;

    if (index > MAX_ITER_COUNT)
      throw new Error("Convergence not reached. Stopping.");

    index++;
  }
  return TDryBulb;
}

@dmey
Copy link
Contributor

dmey commented Jul 10, 2021

Thanks @heymikid -- would you be willing to submit a PR for this for most/all supported languages? I am a bit short of time at the moment...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants