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

add fugacity funcs compatible with Sept 2023 CoolProp master branch #33

Closed
Closed
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
59 changes: 57 additions & 2 deletions src/CoolProp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function _get_unit(param::AbstractString)
end
# Otherwise use the normal parameter info
unit_str = "-"
try
try
unit_str = get_parameter_information_string(param, "units")
catch
end
Expand Down Expand Up @@ -852,6 +852,61 @@ 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
"""
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)
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?
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 @@ -1345,7 +1400,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_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_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
8 changes: 7 additions & 1 deletion test/testLow.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using CoolProp
using Test

#low
@info "********* Low Level Api *********"
const HEOS_BACKEND_FAMILY = "HEOS"
Expand Down Expand Up @@ -65,6 +68,9 @@ pq_inputs = get_input_pair_index("PQ_INPUTS")
t = get_param_index("T")
AbstractState_set_fractions(handle, [0.4, 0.6])
AbstractState_update(handle,pq_inputs,101325, 0)
i = 0 #index of water in mixture
f_0 = AbstractState_get_fugacity(handle, i)
fc_0 = 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 All @@ -81,7 +87,7 @@ else
out1=[0.0]; out2=[0.0]; out3=[0.0]; out4=[0.0]; out5=[0.0]; out1_=[0.0]
AbstractState_update_and_5_out(handle, pq_inputs, [101325.0], [0.0],1, [t, t, t, t, t], out1, out2, out3, out4, out5)
AbstractState_update_and_5_out(handle, "PQ_INPUTS", [101325.0], [0.0],1, ["T", "T", "T", "T", "T"], out1_, out2, out3, out4, out5)
end
end
if Sys.isapple()
@test AbstractState_keyed_output(handle,t) ≈ 352.3522212978604
@test AbstractState_output(handle,"T") ≈ 352.3522212978604
Expand Down