Skip to content

Commit

Permalink
PsychroLib 2.3.0 (#47)
Browse files Browse the repository at this point in the history
Adds inverse methods for temperature conversions (GetTFahrenheitFromTRankine and GetTCelsiusFromTKelvin) and GetTDryBulbFromMoistAirVolumeAndHumRatio to calculate dry-bulb temperature given moist air specific volume, humidity ratio, and pressure.

This PR also adds two new constants ZERO_FAHRENHEIT_AS_RANKINE and ZERO_CELSIUS_AS_KELVIN used by the temperature conversion functions.
  • Loading branch information
dmey authored Nov 21, 2019
1 parent ab71aef commit bd71cdd
Show file tree
Hide file tree
Showing 21 changed files with 554 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.3.0
- Add `GetTDryBulbFromMoistAirVolumeAndHumRatio`.
- Add `GetTFahrenheitFromTRankine` and `GetTCelsiusFromTKelvin`.
- Define `ZERO_FAHRENHEIT_AS_RANKINE` and `ZERO_CELSIUS_AS_KELVIN`.

2.2.0
- Add C# support with .NET Standard 1.0 (.NET Core >= 1.0 & .NET Framework >= 4.5).

Expand Down
2 changes: 1 addition & 1 deletion DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This project uses [semantic versioning](https://semver.org/).
We use two branches to record the history of the project. The `master` branch stores the official release history while the `develop` branch serves as an integration branch for features and bug fixes. All new releases are tagged with a version number in `master`.


## How to create and upload a new version to PiPy
## How to create and upload a new version to Pypi

From the command prompt, navigate to `src/python`. Then you can create and upload a new release with the following commands:

Expand Down
3 changes: 3 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ The following psychrometric functions are currently available across all the sup
|Function Name|Description|
|-------------|-----------|
|`GetTRankineFromTFahrenheit`|Utility function to convert temperature to degree Rankine given temperature in degree Fahrenheit.|
|`GetTFahrenheitFromTRankine`|Utility function to convert temperature to degree Fahrenheit given temperature in degree Rankine.|
|`GetTKelvinFromTCelsius`|Utility function to convert temperature to Kelvin given temperature in degree Celsius.|
|`GetTCelsiusFromTKelvin`|Utility function to convert temperature to degree Celsius given temperature in Kelvin.|
|`GetTWetBulbFromTDewPoint`|Return wet-bulb temperature given dry-bulb temperature, dew-point temperature, and pressure.|
|`GetTWetBulbFromRelHum`|Return wet-bulb temperature given dry-bulb temperature, relative humidity, and pressure.|
|`GetRelHumFromTDewPoint`|Return relative humidity given dry-bulb temperature and dew-point temperature.|
Expand Down Expand Up @@ -53,6 +55,7 @@ The following psychrometric functions are currently available across all the sup
|`GetDegreeOfSaturation`|Return the degree of saturation (i.e humidity ratio of the air / humidity ratio of the air at saturation at the same temperature and pressure) given dry-bulb temperature, humidity ratio, and atmospheric pressure.|
|`GetMoistAirEnthalpy`|Return moist air enthalpy given dry-bulb temperature and humidity ratio.|
|`GetMoistAirVolume`|Return moist air specific volume given dry-bulb temperature, humidity ratio, and pressure.|
|`GetTDryBulbFromMoistAirVolumeAndHumRatio`|Return dry-bulb temperature given moist air specific volume, humidity ratio, and pressure.|
|`GetMoistAirDensity`|Return moist air density given humidity ratio, dry bulb temperature, and pressure.|
|`GetStandardAtmPressure`|Return standard atmosphere barometric pressure, given the elevation (altitude).|
|`GetStandardAtmTemperature`|Return standard atmosphere temperature, given the elevation (altitude).|
Expand Down
48 changes: 45 additions & 3 deletions src/c/psychrolib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* PsychroLib (version 2.2.0) (https://github.com/psychrometrics/psychrolib)
* PsychroLib (version 2.3.0) (https://github.com/psychrometrics/psychrolib)
* Copyright (c) 2018 D. Thevenard and D. Meyer for the current library implementation
* Copyright (c) 2017 ASHRAE Handbook — Fundamentals for ASHRAE equations and coefficients
* Licensed under the MIT License.
Expand Down Expand Up @@ -53,10 +53,18 @@
* Global constants
*****************************************************************************************************/

# define ZERO_FAHRENHEIT_AS_RANKINE 459.67 // Zero degree Fahrenheit (°F) expressed as degree Rankine (°R).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.

# define ZERO_CELSIUS_AS_KELVIN 273.15 // Zero degree Celsius (°C) expressed as Kelvin (K).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.

#define R_DA_IP 53.350 // Universal gas constant for dry air (IP version) in ft∙lbf/lb_da/R.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.

#define R_DA_SI 287.042 // Universal gas constant for dry air (SI version) in J/kg_da/K.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.

#define INVALID -99999 // Invalid value.

#define MAX_ITER_COUNT 100 // Maximum number of iterations before exiting while loops.
Expand Down Expand Up @@ -162,12 +170,22 @@ int isIP // (o) 1 if IP, 0 if SI, error otherwise
// Utility function to convert temperature to degree Rankine (°R)
// given temperature in degree Fahrenheit (°F).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
double GetTRankineFromTFahrenheit(double T_F) { return T_F + 459.67; } /* exact */
double GetTRankineFromTFahrenheit(double T_F) { return T_F + ZERO_FAHRENHEIT_AS_RANKINE; } /* exact */

// Utility function to convert temperature to degree Fahrenheit (°F)
// given temperature in degree Rankine (°R).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
double GetTFahrenheitFromTRankine(double T_R) { return T_R - ZERO_FAHRENHEIT_AS_RANKINE; } /* exact */

// Utility function to convert temperature to Kelvin (K)
// given temperature in degree Celsius (°C).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
double GetTKelvinFromTCelsius(double T_C) { return T_C + 273.15; } /* exact */
double GetTKelvinFromTCelsius(double T_C) { return T_C + ZERO_CELSIUS_AS_KELVIN; } /* exact */

// Utility function to convert temperature to degree Celsius (°C)
// given temperature in Kelvin (K).
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
double GetTCelsiusFromTKelvin(double T_K) { return T_K - ZERO_CELSIUS_AS_KELVIN; } /* exact */


/******************************************************************************************************
Expand Down Expand Up @@ -865,6 +883,30 @@ double GetMoistAirVolume // (o) Specific Volume ft³ lb⁻¹ [IP] or in m
return R_DA_SI * GetTKelvinFromTCelsius(TDryBulb) * (1. + 1.607858 * BoundedHumRatio) / Pressure;
}

// Return dry-bulb temperature given moist air specific volume, humidity ratio, and pressure.
// Reference:
// ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 26
// Notes:
// In IP units, R_DA_IP / 144 equals 0.370486 which is the coefficient appearing in eqn 26
// The factor 144 is for the conversion of Psi = lb in⁻² to lb ft⁻².
// Based on the `GetMoistAirVolume` function, rearranged for dry-bulb temperature.
double GetTDryBulbFromMoistAirVolumeAndHumRatio // (o) Dry-bulb temperature in °F [IP] or °C [SI]
( double MoistAirVolume // (i) Specific volume of moist air in ft³ lb⁻¹ of dry air [IP] or in m³ kg⁻¹ of dry air [SI]
, double HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
)
{
double BoundedHumRatio;

ASSERT (HumRatio >= 0., "Humidity ratio is negative")
BoundedHumRatio = max(HumRatio, MIN_HUM_RATIO);

if (isIP())
return GetTFahrenheitFromTRankine(MoistAirVolume * (144 * Pressure) / (R_DA_IP * (1 + 1.607858 * BoundedHumRatio)));
else
return GetTCelsiusFromTKelvin(MoistAirVolume * Pressure / (R_DA_SI * (1 + 1.607858 * BoundedHumRatio)));
}

// Return moist air density given humidity ratio, dry bulb temperature, and pressure.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 11
double GetMoistAirDensity // (o) Moist air density in lb ft⁻³ [IP] or kg m⁻³ [SI]
Expand Down
12 changes: 11 additions & 1 deletion src/c/psychrolib.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// PsychroLib (version 2.2.0) (https://github.com/psychrometrics/psychrolib)
// PsychroLib (version 2.3.0) (https://github.com/psychrometrics/psychrolib)
// Copyright(c) 2018 D.Thevenard and D.Meyer. Licensed under the MIT License.

/******************************************************************************************************
Expand All @@ -22,8 +22,12 @@ enum UnitSystem GetUnitSystem // (o) System of units (SI or IP)

double GetTRankineFromTFahrenheit(double T_F);

double GetTFahrenheitFromTRankine(double T_R);

double GetTKelvinFromTCelsius(double T_C);

double GetTCelsiusFromTKelvin(double T_K);


/******************************************************************************************************
* Conversions between dew point, wet bulb, and relative humidity
Expand Down Expand Up @@ -230,6 +234,12 @@ double GetMoistAirVolume // (o) Specific Volume ft³ lb⁻¹ [IP] or in m
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
);

double GetTDryBulbFromMoistAirVolumeAndHumRatio // (o) Dry-bulb temperature in °F [IP] or °C [SI]
( double MoistAirVolume // (i) Specific volume of moist air in ft³ lb⁻¹ of dry air [IP] or in m³ kg⁻¹ of dry air [SI]
, double HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
);

double GetMoistAirDensity // (o) Moist air density in lb ft⁻³ [IP] or kg m⁻³ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, double HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
Expand Down
6 changes: 3 additions & 3 deletions src/c_sharp/PsychroLib/PsychroLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard1.0</TargetFramework>
<Version>2.2.0</Version>
<Version>2.3.0</Version>
<PackageProjectUrl>https://github.com/psychrometrics/psychrolib</PackageProjectUrl>
<RepositoryUrl>https://github.com/psychrometrics/psychrolib</RepositoryUrl>
<PackageIcon>psychrolib_logo_64.png</PackageIcon>
Expand All @@ -12,8 +12,8 @@
<Company>PsychroLib</Company>
<PackageTags>net,standard,core</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>2.2.0.0</AssemblyVersion>
<FileVersion>2.2.0.0</FileVersion>
<AssemblyVersion>2.3.0</AssemblyVersion>
<FileVersion>2.3.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<None Include="$(SolutionDir)../../assets/psychrolib_logo_64.png">
Expand Down
72 changes: 67 additions & 5 deletions src/c_sharp/PsychroLib/psychrolib.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* PsychroLib (version 2.2.0) (https://github.com/psychrometrics/psychrolib)
* PsychroLib (version 2.3.0) (https://github.com/psychrometrics/psychrolib)
* Copyright (c) 2018 D. Thevenard and D. Meyer, D. Gosnell for the current library implementation
* Copyright (c) 2017 ASHRAE Handbook — Fundamentals for ASHRAE equations and coefficients
* Ported to C# by https://github.com/DJGosnell
Expand All @@ -19,6 +19,18 @@ public class Psychrometrics
* Global constants
*****************************************************************************************************/

/// <summary>
/// Zero degree Fahrenheit (°F) expressed as degree Rankine (°R).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.
/// </summary>
private const double ZERO_FAHRENHEIT_AS_RANKINE = 459.67;

/// <summary>
/// Zero degree Celsius (°C) expressed as Kelvin (K).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 39.
/// </summary>
private const double ZERO_CELSIUS_AS_KELVIN = 273.15;

/// <summary>
/// Universal gas constant for dry air (IP version) in ft lb_Force lb_DryAir⁻¹ R⁻¹.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.
Expand Down Expand Up @@ -102,14 +114,26 @@ public Psychrometrics(UnitSystem unitSystem)

/// <summary>
/// Utility function to convert temperature to degree Rankine (°R)
/// given temperature in degree Fahrenheit(°F).
/// Reference: ASHRAE Handbook - Fundamentals(2017) ch. 1 section 3
/// given temperature in degree Fahrenheit (°F).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tF">Temperature in Fahrenheit (°F)</param>
/// <returns>Rankine (°R)</returns>
public double GetTRankineFromTFahrenheit(double tF)
{
return tF + 459.67; /* exact */
return tF + ZERO_FAHRENHEIT_AS_RANKINE; /* exact */
}

/// <summary>
/// Utility function to convert temperature to degree Fahrenheit (°F)
/// given temperature in degree Rankine (°R).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tR">Temperature in Rankine (°R)</param>
/// <returns>Fahrenheit (°F)</returns>
public double GetTFahrenheitFromTRankine(double tR)
{
return tR - ZERO_FAHRENHEIT_AS_RANKINE; /* exact */
}

/// <summary>
Expand All @@ -121,7 +145,19 @@ public double GetTRankineFromTFahrenheit(double tF)
/// <returns>Rankine (°R)</returns>
public double GetTKelvinFromTCelsius(double tC)
{
return tC + 273.15; /* exact */
return tC + ZERO_CELSIUS_AS_KELVIN; /* exact */
}

/// <summary>
/// Utility function to convert temperature to degree Celsius (°C)
/// given temperature in Kelvin (K).
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 section 3
/// </summary>
/// <param name="tK">Temperature in Rankine (°R)</param>
/// <returns>Celsius (°C)</returns>
public double GetTCelsiusFromTKelvin(double tK)
{
return tK - ZERO_CELSIUS_AS_KELVIN; /* exact */
}


Expand Down Expand Up @@ -890,6 +926,32 @@ public double GetMoistAirVolume(double tDryBulb, double humRatio, double pressur
}


/// <summary>
/// Return dry-bulb temperature given moist air specific volume, humidity ratio, and pressure.
/// Reference:
/// ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 26
/// Notes:
/// In IP units, R_DA_IP / 144 equals 0.370486 which is the coefficient appearing in eqn 26
/// The factor 144 is for the conversion of Psi = lb in⁻² to lb ft⁻².
/// Based on the `GetMoistAirVolume` function, rearranged for dry-bulb temperature.
/// </summary>
/// <param name="MoistAirVolume">Specific volume of moist air in ft³ lb⁻¹ of dry air [IP] or in m³ kg⁻¹ of dry air [SI]</param>
/// <param name="humRatio">Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]</param>
/// <param name="pressure">Atmospheric pressure in Psi [IP] or Pa [SI]</param>
/// <returns>Dry-bulb temperature in °F [IP] or °C [SI]</returns>
public double GetTDryBulbFromMoistAirVolumeAndHumRatio(double MoistAirVolume, double humRatio, double pressure)
{
if (!(humRatio >= 0.0))
throw new InvalidOperationException("Humidity ratio is negative");
var boundedHumRatio = Math.Max(humRatio, MIN_HUM_RATIO);

if (UnitSystem == UnitSystem.IP)
return GetTFahrenheitFromTRankine(MoistAirVolume * (144 * pressure) / (R_DA_IP * (1 + 1.607858 * boundedHumRatio)));

return GetTCelsiusFromTKelvin(MoistAirVolume * pressure / (R_DA_SI * (1 + 1.607858 * boundedHumRatio)));
}


/// <summary>
/// Return moist air density given humidity ratio, dry bulb temperature, and pressure.
/// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn. 11
Expand Down
Loading

0 comments on commit bd71cdd

Please sign in to comment.