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

Fugacity functions update #35

Merged
merged 5 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "CoolProp"
uuid = "e084ae63-2819-5025-826e-f8e611a84251"
version = "0.1.1"
version = "0.2.0"

[deps]
CoolProp_jll = "3351c21f-4feb-5f29-afb9-f4fcb0e27549"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
CoolProp_jll = "6.5"
CoolProp_jll = "6.6"
julia = "1.3"
Unitful="1"

Expand Down
59 changes: 58 additions & 1 deletion src/CoolProp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,63 @@ function AbstractState_update(handle::Clong, input_pair::AbstractString, value1:
return nothing
end

#TODO: these functions will not work with CoolProp_jll 6.5. Needs new version released of current master from Sept 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove TODO comment

"""
AbstractState_get_fugacity(handle::Clong, i::Integer)

Return the fugacity of species `i`

# Arguments
* `handle`: The integer handle for the state class stored in memory
* `i`: The index of the species

# Example
```julia
julia> handle = AbstractState_factory("HEOS", "Water&Ethanol");
julia> pq_inputs = get_input_pair_index("PQ_INPUTS");
julia> t = get_param_index("T");
julia> AbstractState_set_fractions(handle, [0.4, 0.6]);
julia> AbstractState_update(handle, pq_inputs, 101325, 0);
julia> AbstractState_get_fugacity(handle, 0)
30227.119385400914
julia> AbstractState_free(handle);
```
"""
function AbstractState_get_fugacity(handle::Clong, i::Integer)
buffer_length = length(message_buffer)
output = ccall( (:AbstractState_get_fugacity, libcoolprop), Cdouble, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return output
end

"""
AbstractState_get_fugacity_coefficient(handle::Clong, i::Real)

Return the fugacity coefficient of species `i`

# Arguments
* `handle`: The integer handle for the state class stored in memory
* `i`: The index of the species

# Example
```julia
julia> handle = AbstractState_factory("HEOS", "Water&Ethanol");
julia> pq_inputs = get_input_pair_index("PQ_INPUTS");
julia> t = get_param_index("T");
julia> AbstractState_set_fractions(handle, [0.4, 0.6]);
julia> AbstractState_update(handle, pq_inputs, 101325, 0);
julia> AbstractState_get_fugacity_coefficient(handle, 0)
0.7457961851803392
julia> AbstractState_free(handle);
```
"""
function AbstractState_get_fugacity_coefficient(handle::Clong, i::Integer) #TODO: maybe type this as an integer?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove TODO comment

buffer_length = length(message_buffer)
output = ccall( (:AbstractState_get_fugacity_coefficient, libcoolprop), Cdouble, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return output
end

"""
AbstractState_keyed_output(handle::Clong, param::Clong)

Expand Down Expand Up @@ -1435,7 +1492,7 @@ function AbstractState_all_critical_points(handle::Clong, length::Integer)
return AbstractState_all_critical_points(handle, length, T, p, rhomolar, stable)
end

for symorigin = [:PropsSI, :PhaseSI, :K2F, :F2K, :HAPropsSI, :AbstractState_factory, :AbstractState_free, :AbstractState_set_fractions, :AbstractState_get_mole_fractions, :AbstractState_get_mole_fractions_satState, :AbstractState_update, :AbstractState_keyed_output, :AbstractState_output, :AbstractState_specify_phase, :AbstractState_unspecify_phase, :AbstractState_update_and_common_out, :AbstractState_update_and_1_out, :AbstractState_update_and_5_out, :AbstractState_set_binary_interaction_double, :AbstractState_set_cubic_alpha_C, :AbstractState_set_fluid_parameter_double, :AbstractState_first_saturation_deriv, :AbstractState_first_partial_deriv, :AbstractState_build_phase_envelope, :AbstractState_build_spinodal, :AbstractState_all_critical_points, :AbstractState_get_phase_envelope_data, :AbstractState_get_spinodal_data]
for symorigin = [:PropsSI, :PhaseSI, :K2F, :F2K, :HAPropsSI, :AbstractState_factory, :AbstractState_free, :AbstractState_set_fractions, :AbstractState_get_mole_fractions, :AbstractState_get_mole_fractions_satState, :AbstractState_update, :AbstractState_get_fugacity, :AbstractState_get_fugacity_coefficient, :AbstractState_keyed_output, :AbstractState_output, :AbstractState_specify_phase, :AbstractState_unspecify_phase, :AbstractState_update_and_common_out, :AbstractState_update_and_1_out, :AbstractState_update_and_5_out, :AbstractState_set_binary_interaction_double, :AbstractState_set_cubic_alpha_C, :AbstractState_set_fluid_parameter_double, :AbstractState_first_saturation_deriv, :AbstractState_first_partial_deriv, :AbstractState_build_phase_envelope, :AbstractState_build_spinodal, :AbstractState_all_critical_points, :AbstractState_get_phase_envelope_data, :AbstractState_get_spinodal_data]
sym = Symbol(lowercase(string(symorigin)))
@eval const $sym = $symorigin
@eval export $sym, $symorigin
Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const coolproptrivialparameters = ["ACENTRIC", "DIPOLE_MOMENT", "FH", "FRACTION_
"TMIN", "TTRIPLE", "T_FREEZE", "T_REDUCING"];
const trivalwithnumval = ["FH","GWP100","PMIN","TMIN","P_REDUCING","PCRIT","GWP20","GAS_CONSTANT","PMAX","RHOCRIT","TCRIT","T_REDUCING","ACENTRIC","GWP500","RHOMOLAR_REDUCING","TMAX","TTRIPLE","PH","M","PTRIPLE","RHOMOLAR_CRITICAL","ODP","HH"];
const fails_any_props_trivals = ["DIPOLE_MOMENT","FRACTION_MAX","FRACTION_MIN","RHOMASS_REDUCING","T_FREEZE"];
const fails_critical_point = ["R134a","R116","R236EA","R1234ze(E)","SulfurDioxide","n-Pentane","R11","CycloPropane","Cyclopentane","MDM","n-Nonane","Oxygen","DimethylCarbonate","R41","R227EA","R245fa","trans-2-Butene","MM","Air","R236FA","SES36","Fluorine","n-Undecane","Isohexane","IsoButane","R1234ze(Z)","HydrogenChloride"];
const fails_tcrit_eq_treducing = ["R134a","R116","R1234ze(E)","n-Pentane","R11","n-Nonane","MDM","Oxygen","R41","MM","Fluorine","n-Undecane","Isohexane","Helium","IsoButane","HydrogenChloride"];
const fails_critical_point = ["DiethylEther","R134a","R116","SulfurDioxide","n-Pentane","R11","CycloPropane","MDM","n-Nonane","Oxygen","DimethylCarbonate","R41","R227EA","R245fa","trans-2-Butene","n-Propane","MM","Air","R236FA","Neon","SES36","Fluorine","n-Undecane","Isohexane","MD4M","IsoButane","D5","Ammonia","R1234ze(Z)","HydrogenChloride","R236EA","R1234ze(E)","Cyclopentane"];
const fails_tcrit_eq_treducing = ["R134a","R116","n-Pentane","R11","n-Nonane","MDM","Oxygen","R41","MM","Fluorine","n-Undecane","Isohexane","Helium","IsoButane","HydrogenChloride","R1234ze(E)","Ammonia"];

function compare_sets(fails,reference)
failsset = Set(fails)
Expand Down Expand Up @@ -58,7 +58,8 @@ include("testLow.jl");
@test K2F(F2K(100)) ≈ 100
#HAPropsSI
dt=1e-3;
@test (HAPropsSI("H", "T", 300+dt, "P", 100000, "Y", 1e-20) - HAPropsSI("H", "T", 300-dt, "P", 100000, "Y", 1e-20))/2/dt ≈ HAPropsSI("C", "T", 300, "P", 100000, "Y", 1e-20) atol =2e-9
const Y0 = 1e-16
@test (HAPropsSI("H", "T", 300+dt, "P", 100000, "Y", Y0) - HAPropsSI("H", "T", 300-dt, "P", 100000, "Y", Y0))/2/dt ≈ HAPropsSI("C", "T", 300, "P", 100000, "Y", Y0) atol =2e-9
#PropsSI
h0 = -15870000.0; # J/kg
s0 = 3887.0; #J/kg
Expand Down
3 changes: 3 additions & 0 deletions test/testLow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ gas_frac = [0.0, 0.0]
AbstractState_get_mole_fractions_satState(handle, "gas", gas_frac)
liq_frac = [0.0, 0.0]
AbstractState_get_mole_fractions_satState(handle, "liquid", liq_frac)
i = 0 #index of water in mixture
AbstractState_get_fugacity(handle, i)
AbstractState_get_fugacity_coefficient(handle, i)
if (haskey(ENV, "includelocalwrapper") && ENV["includelocalwrapper"]=="on")
T, p, rhomolar, hmolar, smolar = AbstractState_update_and_common_out(handle, pq_inputs, [101325.0], [0.0], 1)
temp_, p, rhomolar, hmolar, smolar = AbstractState_update_and_common_out(handle, "PQ_INPUTS", [101325.0], [0.0], 1)
Expand Down
Loading