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

Fix dewpoint unit (issue Wrong Units on HAPropsSI #39) #40

Merged
merged 1 commit into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 10 additions & 9 deletions src/CoolProp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const _ha_units = Dict(
"Tdb" => Unitful.u"K",
"Twb" => Unitful.u"K",
"Tdp" => Unitful.u"K",
"D" => Unitful.u"K",
"H" => Unitful.u"J/kg",
"Hha" => Unitful.u"J/kg",
"U" => Unitful.u"J/kg",
Expand All @@ -104,9 +105,9 @@ const _ha_units = Dict(
"P_w" => Unitful.u"Pa",
)

function _get_unit(param::AbstractString)
function _get_unit(param::AbstractString, is_ha::Bool)
# First check if it's a humid air parameter
if haskey(_ha_units, param)
if is_ha && haskey(_ha_units, param)
return _ha_units[param]
end
# Otherwise use the normal parameter info
Expand Down Expand Up @@ -135,9 +136,9 @@ end
_si_value(unit, value) = Unitful.ustrip(Unitful.uconvert(unit, value))

function PropsSI(output::AbstractString, name1::AbstractString, value1::Union{Unitful.Quantity,Real}, name2::AbstractString, value2::Union{Unitful.Quantity,Real}, fluid::AbstractString)
unit1 = _get_unit(name1)
unit2 = _get_unit(name2)
outunit = _get_unit(output)
unit1 = _get_unit(name1,false)
unit2 = _get_unit(name2,false)
outunit = _get_unit(output,false)
return PropsSI(output, name1, _si_value(unit1,value1), name2, _si_value(unit2,value2), fluid)*outunit
end

Expand Down Expand Up @@ -713,10 +714,10 @@ function HAPropsSI(output::AbstractString, name1::AbstractString, value1::Real,
end

function HAPropsSI(output::AbstractString, name1::AbstractString, value1::Union{Unitful.Quantity,Real}, name2::AbstractString, value2::Union{Unitful.Quantity,Real}, name3::AbstractString, value3::Union{Unitful.Quantity,Real})
unit1 = _get_unit(name1)
unit2 = _get_unit(name2)
unit3 = _get_unit(name3)
outunit = _get_unit(output)
unit1 = _get_unit(name1,true)
unit2 = _get_unit(name2,true)
unit3 = _get_unit(name3,true)
outunit = _get_unit(output,true)
return HAPropsSI(output, name1, _si_value(unit1,value1), name2, _si_value(unit2,value2), name3, _si_value(unit3,value3))*outunit
end

Expand Down
4 changes: 3 additions & 1 deletion test/testunits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ let fluid="air"

# Test that all parameters return a unit
for param in split(get_global_param_string("parameter_list"),',')
@test CoolProp._get_unit(param) isa FreeUnits
@test CoolProp._get_unit(param,false) isa FreeUnits
end
end

let p=1atm, Tdb = 20°C, φ = 0.6
x = HAPropsSI("HumRat", "Tdb", Tdb, "RH", φ, "P", p) |> g/kg
@test round(g/kg, x; digits=2) == 8.77g/kg
Tdp = HAPropsSI("D", "T", 300K, "P", 101325Pa, "W", 0.01)
@test round(K,Tdp) == 287K
end
Loading