Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:

script:
# See https://stackoverflow.com/a/34140498 for why "python -m" is needed.
- python -m pytest -v -s
- python3 -m pytest -v -s
- cd tests/js && npm test
- cd $TRAVIS_BUILD_DIR

Expand Down
2 changes: 2 additions & 0 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ The following psychrometric functions are currently available across all the sup
|`GetDryAirEnthalpy`|Return dry-air enthalpy given dry-bulb temperature.|
|`GetDryAirDensity`|Return dry-air density given dry-bulb temperature and pressure.|
|`GetDryAirVolume`|Return dry-air volume given dry-bulb temperature and pressure.|
|`GetTDryBulbFromEnthalpyAndHumRatio`|Return dry bulb temperature from enthalpy and humidity ratio.|
|`GetHumRatioFromEnthalpyAndTDryBulb`|Return humidity ratio from enthalpy and dry-bulb temperature.|
|`GetSatVapPres`|Return saturation vapor pressure given dry-bulb temperature.|
|`GetSatHumRatio`|Return humidity ratio of saturated air given dry-bulb temperature and pressure.|
|`GetSatAirEnthalpy`|Return saturated air enthalpy given dry-bulb temperature and pressure.|
Expand Down
30 changes: 30 additions & 0 deletions src/c/psychrolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,36 @@ double GetDryAirVolume // (o) Dry air volume ft³ lb⁻¹ [IP] or in m
return R_DA_SI * GetTKelvinFromTCelsius(TDryBulb) / Pressure;
}

// Return dry bulb temperature from enthalpy and humidity ratio.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for temperature.
double GetTDryBulbFromEnthalpyAndHumRatio // (o) Dry-bulb temperature in °F [IP] or °C [SI]
( double MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, double HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
)
{
ASSERT (HumRatio >= 0., "Humidity ratio is negative")

if (isIP())
return (MoistAirEnthalpy - 1061.0 * HumRatio) / (0.240 + 0.444 * HumRatio);
else
return (MoistAirEnthalpy / 1000.0 - 2501.0 * HumRatio) / (1.006 + 1.86 * HumRatio);
}

// Return humidity ratio from enthalpy and dry-bulb temperature.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.
double GetHumRatioFromEnthalpyAndTDryBulb // (o) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
( double MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, double TDryBulb // (i) Dry-bulb temperature in °F [IP] or °C [SI]
)
{
if (isIP())
return (MoistAirEnthalpy - 0.240 * TDryBulb) / (1061.0 + 0.444 * TDryBulb);
else
return (MoistAirEnthalpy / 1000.0 - 1.006 * TDryBulb) / (2501.0 + 1.86 * TDryBulb);
}


/******************************************************************************************************
* Saturated Air Calculations
Expand Down
26 changes: 18 additions & 8 deletions src/c/psychrolib.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,28 @@ double GetHumRatioFromSpecificHum // (o) Humidity ratio in lb_H₂O lb_Dry_Air
* Dry Air Calculations
*****************************************************************************************************/

double GetDryAirEnthalpy // (o) Dry air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
double GetDryAirEnthalpy // (o) Dry air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
);

double GetDryAirDensity // (o) Dry air density in lb ft⁻³ [IP] or kg m⁻³ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
double GetDryAirDensity // (o) Dry air density in lb ft⁻³ [IP] or kg m⁻³ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
);

double GetDryAirVolume // (o) Dry air volume ft³ lb⁻¹ [IP] or in m³ kg⁻¹ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
double GetDryAirVolume // (o) Dry air volume ft³ lb⁻¹ [IP] or in m³ kg⁻¹ [SI]
( double TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, double Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
);

double GetTDryBulbFromEnthalpyAndHumRatio // (o) Dry-bulb temperature in °F [IP] or °C [SI]
( double MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, double HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
);

double GetHumRatioFromEnthalpyAndTDryBulb // (o) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
( double MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, double TDryBulb // (i) Dry-bulb temperature in °F [IP] or °C [SI]
);


Expand Down
48 changes: 48 additions & 0 deletions src/fortran/psychrolib.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ module psychrolib
public :: GetDryAirEnthalpy
public :: GetDryAirDensity
public :: GetDryAirVolume
public :: GetTDryBulbFromEnthalpyAndHumRatio
public :: GetHumRatioFromEnthalpyAndTDryBulb
public :: GetSatVapPres
public :: GetSatHumRatio
public :: GetSatAirEnthalpy
Expand Down Expand Up @@ -821,6 +823,52 @@ function GetDryAirVolume(TDryBulb, Pressure) result(DryAirVolume)
end if
end function GetDryAirVolume

function GetTDryBulbFromEnthalpyAndHumRatio(MoistAirEnthalpy, HumRatio) result(TDryBulb)
!+ Return dry bulb temperature from enthalpy and humidity ratio.
!+ Reference:
!+ ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30
!+ Notes:
!+ Based on the `GetMoistAirEnthalpy` function, rearranged for temperature.

real, intent(in) :: MoistAirEnthalpy
!+ Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
real, intent(in) :: HumRatio
!+ Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
real :: TDryBulb
!+ Dry-bulb temperature in °F [IP] or °C [SI]

if (HumRatio < 0.0) then
error stop "Error: humidity ratio is negative"
end if

if (isIP()) then
TDryBulb = (MoistAirEnthalpy - 1061.0 * HumRatio) / (0.240 + 0.444 * HumRatio)
else
TDryBulb = (MoistAirEnthalpy / 1000.0 - 2501.0 * HumRatio) / (1.006 + 1.86 * HumRatio)
end if
end function GetTDryBulbFromEnthalpyAndHumRatio

function GetHumRatioFromEnthalpyAndTDryBulb(MoistAirEnthalpy, TDryBulb) result(HumRatio)
!+ Return humidity ratio from enthalpy and dry-bulb temperature.
!+ Reference:
!+ ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30
!+ Notes:
!+ Based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.

real, intent(in) :: MoistAirEnthalpy
!+ Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
real, intent(in) :: TDryBulb
!+ Dry-bulb temperature in °F [IP] or °C [SI]
real :: HumRatio
!+ Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]

if (isIP()) then
HumRatio = (MoistAirEnthalpy - 0.240 * TDryBulb) / (1061.0 + 0.444 * TDryBulb)
else
HumRatio = (MoistAirEnthalpy / 1000.0 - 1.006 * TDryBulb) / (2501.0 + 1.86 * TDryBulb)
end if
end function GetHumRatioFromEnthalpyAndTDryBulb


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Saturated Air Calculations
Expand Down
32 changes: 30 additions & 2 deletions src/js/psychrolib.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,21 +555,49 @@ function Psychrometrics() {
}

// Return dry-air volume given dry-bulb temperature and pressure.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1.
// Notes: eqn 14 for the perfect gas relationship for dry air.
// Eqn 1 for the universal gas constant.
// The factor 144 in IP is for the conversion of Psi = lb in⁻² to lb ft⁻².
this.GetDryAirVolume = function // (o) Dry air volume ft³ lb⁻¹ [IP] or in m³ kg⁻¹ [SI]
( TDryBulb // (i) Dry bulb temperature in °F [IP] or °C [SI]
, Pressure // (i) Atmospheric pressure in Psi [IP] or Pa [SI]
) {

if (this.isIP())
return R_DA_IP * this.GetTRankineFromTFahrenheit(TDryBulb) / (144. * Pressure);
else
return R_DA_SI * this.GetTKelvinFromTCelsius(TDryBulb) / Pressure;
}

// Return dry bulb temperature from enthalpy and humidity ratio.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for temperature.
this.GetTDryBulbFromEnthalpyAndHumRatio = function // (o) Dry-bulb temperature in °F [IP] or °C [SI]
( MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, HumRatio // (i) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
) {
if (!(HumRatio >= 0.))
throw new Error("Humidity ratio is negative");

if (this.isIP())
return (MoistAirEnthalpy - 1061.0 * HumRatio) / (0.240 + 0.444 * HumRatio);
else
return (MoistAirEnthalpy / 1000.0 - 2501.0 * HumRatio) / (1.006 + 1.86 * HumRatio);
}

// Return humidity ratio from enthalpy and dry-bulb temperature.
// Reference: ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.
// Notes: based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.
this.GetHumRatioFromEnthalpyAndTDryBulb = function // (o) Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻
( MoistAirEnthalpy // (i) Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
, TDryBulb // (i) Dry-bulb temperature in °F [IP] or °C [SI]
) {
if (this.isIP())
return (MoistAirEnthalpy - 0.240 * TDryBulb) / (1061.0 + 0.444 * TDryBulb);
else
return (MoistAirEnthalpy / 1000.0 - 1.006 * TDryBulb) / (2501.0 + 1.86 * TDryBulb);
}


/******************************************************************************************************
* Saturated Air Calculations
Expand Down
57 changes: 56 additions & 1 deletion src/python/psychrolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import math
from enum import Enum, auto
from typing import Optional


#######################################################################################################
Expand Down Expand Up @@ -119,7 +120,7 @@ def SetUnitSystem(Units: UnitSystem) -> None:
else:
PSYCHROLIB_TOLERANCE = 0.001

def GetUnitSystem() -> UnitSystem:
def GetUnitSystem() -> Optional[UnitSystem]:
"""
Return system of units in use.

Expand Down Expand Up @@ -799,6 +800,60 @@ def GetDryAirVolume(TDryBulb: float, Pressure: float) -> float:
return DryAirVolume


def GetTDryBulbFromEnthalpyAndHumRatio(MoistAirEnthalpy: float, HumRatio: float) -> float:
"""
Return dry bulb temperature from enthalpy and humidity ratio.


Args:
MoistAirEnthalpy : Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
HumRatio : Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]

Returns:
Dry-bulb temperature in °F [IP] or °C [SI]

Reference:
ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30

Notes:
Based on the `GetMoistAirEnthalpy` function, rearranged for temperature.

"""
if HumRatio < 0:
raise ValueError("Humidity ratio is negative")

if isIP():
TDryBulb = (MoistAirEnthalpy - 1061.0 * HumRatio) / (0.240 + 0.444 * HumRatio)
else:
TDryBulb = (MoistAirEnthalpy / 1000.0 - 2501.0 * HumRatio) / (1.006 + 1.86 * HumRatio)
return TDryBulb

def GetHumRatioFromEnthalpyAndTDryBulb(MoistAirEnthalpy: float, TDryBulb: float) -> float:
"""
Return humidity ratio from enthalpy and dry-bulb temperature.


Args:
MoistAirEnthalpy : Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
TDryBulb : Dry-bulb temperature in °F [IP] or °C [SI]

Returns:
Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]

Reference:
ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30.

Notes:
Based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.

"""
if isIP():
HumRatio = (MoistAirEnthalpy - 0.240 * TDryBulb) / (1061.0 + 0.444 * TDryBulb)
else:
HumRatio = (MoistAirEnthalpy / 1000.0 - 1.006 * TDryBulb) / (2501.0 + 1.86 * TDryBulb)
return HumRatio


#######################################################################################################
# Saturated Air Calculations
#######################################################################################################
Expand Down
73 changes: 72 additions & 1 deletion src/vba/psychrolib.bas
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ Function GetSpecificHumFromHumRatio(ByVal HumRatio As Variant) As Variant
' ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 9b
'
'
Dim SpecificHum as Variant
Dim SpecificHum As Variant

On Error GoTo ErrHandler

Expand Down Expand Up @@ -1065,6 +1065,77 @@ ErrHandler:

End Function

Function GetTDryBulbFromEnthalpyAndHumRatio(ByVal MoistAirEnthalpy As Variant, ByVal HumRatio As Variant) As Variant
'
' Return dry bulb temperature from enthalpy and humidity ratio.
'
'
' Args:
' MoistAirEnthalpy : Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
' HumRatio : Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
'
' Returns:
' Dry-bulb temperature in °F [IP] or °C [SI]
'
' Reference:
' ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30
'
' Notes:
' Based on the `GetMoistAirEnthalpy` function, rearranged for temperature.
'

On Error GoTo ErrHandler

If HumRatio < 0 Then
MyMsgBox ("Humidity ratio is negative")
GoTo ErrHandler
End If

If (isIP()) Then
GetTDryBulbFromEnthalpyAndHumRatio = (MoistAirEnthalpy - 1061.0 * HumRatio) / (0.24 + 0.444 * HumRatio)
Else:
GetTDryBulbFromEnthalpyAndHumRatio = (MoistAirEnthalpy / 1000.0 - 2501.0 * HumRatio) / (1.006 + 1.86 * HumRatio)
End If
Exit Function

ErrHandler:
GetTDryBulbFromEnthalpyAndHumRatio = CVErr(xlErrNA)

End Function

Function GetHumRatioFromEnthalpyAndTDryBulb(ByVal MoistAirEnthalpy As Variant, ByVal TDryBulb As Variant) As Variant
'
' Return humidity ratio from enthalpy and dry-bulb temperature.
'
'
' Args:
' MoistAirEnthalpy : Moist air enthalpy in Btu lb⁻¹ [IP] or J kg⁻¹
' TDryBulb : Dry-bulb temperature in °F [IP] or °C [SI]
'
' Returns:
' Humidity ratio in lb_H₂O lb_Air⁻¹ [IP] or kg_H₂O kg_Air⁻¹ [SI]
'
' Reference:
' ASHRAE Handbook - Fundamentals (2017) ch. 1 eqn 30
'
' Notes:
' Based on the `GetMoistAirEnthalpy` function, rearranged for humidity ratio.
'

On Error GoTo ErrHandler

If (isIP()) Then
GetHumRatioFromEnthalpyAndTDryBulb = (MoistAirEnthalpy - 0.24 * TDryBulb) / (1061.0 + 0.444 * TDryBulb)
Else:
GetHumRatioFromEnthalpyAndTDryBulb = (MoistAirEnthalpy / 1000.0 - 1.006 * TDryBulb) / (2501.0 + 1.86 * TDryBulb)
End If
Exit Function

ErrHandler:
GetHumRatioFromEnthalpyAndTDryBulb = CVErr(xlErrNA)

End Function


'******************************************************************************************************
' Saturated Air Calculations
Expand Down
2 changes: 2 additions & 0 deletions tests/js/test_psychrolib_ip.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ it('test_DryAir', function () {
checkRelDiff(psyjs.GetDryAirEnthalpy(77), 18.498, 0.001)
checkRelDiff(psyjs.GetDryAirVolume(77, 14.696), 13.5251, 0.001)
checkRelDiff(psyjs.GetDryAirDensity(77, 14.696), 1/13.5251, 0.001)
expect(psyjs.GetTDryBulbFromEnthalpyAndHumRatio(42.6168, 0.02)).to.be.closeTo(86, 0.05)
checkRelDiff(psyjs.GetHumRatioFromEnthalpyAndTDryBulb(42.6168, 86), 0.02, 0.001)
});


Expand Down
2 changes: 2 additions & 0 deletions tests/js/test_psychrolib_si.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ it('test_DryAir', function () {
checkRelDiff(psyjs.GetDryAirEnthalpy(25), 25148, 0.0003)
checkRelDiff(psyjs.GetDryAirVolume(25, 101325), 0.8443, 0.001)
checkRelDiff(psyjs.GetDryAirDensity(25, 101325), 1/0.8443, 0.001)
expect(psyjs.GetTDryBulbFromEnthalpyAndHumRatio(81316, 0.02)).to.be.closeTo(30, 0.001)
checkRelDiff(psyjs.GetHumRatioFromEnthalpyAndTDryBulb(81316, 30), 0.02, 0.001)
});


Expand Down
2 changes: 2 additions & 0 deletions tests/test_psychrolib_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def test_DryAir(psy):
assert psy.GetDryAirEnthalpy(77) == pytest.approx(18.498, rel = 0.001)
assert psy.GetDryAirVolume(77, 14.696) == pytest.approx(13.5251, rel = 0.001)
assert psy.GetDryAirDensity(77, 14.696) == pytest.approx(1/13.5251, rel = 0.001)
assert psy.GetTDryBulbFromEnthalpyAndHumRatio(42.6168, 0.02) == pytest.approx(85.97, abs = 0.05)
assert psy.GetHumRatioFromEnthalpyAndTDryBulb(42.6168, 86) == pytest.approx(0.02, rel = 0.001)


###############################################################################
Expand Down
Loading