From 1fa84097079f5f484d36fefeb2639f583d883036 Mon Sep 17 00:00:00 2001 From: chris-hampel-CA Date: Tue, 12 Sep 2023 13:55:15 -0600 Subject: [PATCH 1/5] add fugacity funcs compatible with Sept 2023 CoolProp master branch --- src/CoolProp.jl | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- test/testLow.jl | 3 +++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/CoolProp.jl b/src/CoolProp.jl index db630b2..d4db9e8 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -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 +#TODO: update output of example func call +""" + 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, 1) +TODO: update output +julia> AbstractState_free(handle); +``` +""" +function AbstractState_get_fugacity(handle::Clong, i::Integer) #TODO: maybe type this as an integer? + ccall( (:AbstractState_get_fugacity, libcoolprop), Nothing, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length) + raise(errcode, message_buffer) + return nothing +end + +#TODO: update output of example func call +""" + 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, 1) +TODO: update output +julia> AbstractState_free(handle); +``` +""" +function AbstractState_get_fugacity_coefficient(handle::Clong, i::Integer) #TODO: maybe type this as an integer? + ccall( (:AbstractState_get_fugacity_coefficient, libcoolprop), Nothing, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length) + raise(errcode, message_buffer) + return nothing +end + """ AbstractState_keyed_output(handle::Clong, param::Clong) @@ -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 diff --git a/test/testLow.jl b/test/testLow.jl index e18c218..8373f08 100644 --- a/test/testLow.jl +++ b/test/testLow.jl @@ -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 = 1 #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) From 512082e7f6acead49b605767940f11c4df760921 Mon Sep 17 00:00:00 2001 From: chris-hampel-CA Date: Fri, 22 Sep 2023 16:36:20 -0600 Subject: [PATCH 2/5] fix fugacity output type specification --- src/CoolProp.jl | 20 +++++++++----------- test/testLow.jl | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/CoolProp.jl b/src/CoolProp.jl index d4db9e8..0a36da3 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -927,7 +927,6 @@ function AbstractState_update(handle::Clong, input_pair::AbstractString, value1: end #TODO: these functions will not work with CoolProp_jll 6.5. Needs new version released of current master from Sept 2023 -#TODO: update output of example func call """ AbstractState_get_fugacity(handle::Clong, i::Integer) @@ -944,18 +943,17 @@ 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, 1) -TODO: update output +julia> AbstractState_get_fugacity(handle, 0) +30227.119385400914 julia> AbstractState_free(handle); ``` """ -function AbstractState_get_fugacity(handle::Clong, i::Integer) #TODO: maybe type this as an integer? - ccall( (:AbstractState_get_fugacity, libcoolprop), Nothing, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length) +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 nothing + return output end -#TODO: update output of example func call """ AbstractState_get_fugacity_coefficient(handle::Clong, i::Real) @@ -972,15 +970,15 @@ 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, 1) -TODO: update output +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? - ccall( (:AbstractState_get_fugacity_coefficient, libcoolprop), Nothing, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, errcode, message_buffer::Array{UInt8, 1}, buffer_length) + 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 nothing + return output end """ diff --git a/test/testLow.jl b/test/testLow.jl index 8373f08..801e957 100644 --- a/test/testLow.jl +++ b/test/testLow.jl @@ -74,7 +74,7 @@ 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 = 1 #index of water in mixture +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") From 2b7766c71e2000bc18cdfdb9c619db17f1cf066f Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Wed, 6 Dec 2023 09:09:59 +0100 Subject: [PATCH 3/5] Update version and fix test --- Project.toml | 4 ++-- test/runtests.jl | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Project.toml b/Project.toml index 9a2211a..e0a9a80 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "CoolProp" uuid = "e084ae63-2819-5025-826e-f8e611a84251" -version = "0.1.1" +version = "0.2.0" [deps] CoolProp_jll = "3351c21f-4feb-5f29-afb9-f4fcb0e27549" @@ -8,7 +8,7 @@ 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" diff --git a/test/runtests.jl b/test/runtests.jl index 93942e0..3fe0876 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) @@ -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 From 39e55fd2dfaea4e6fde3ac3191cf97b6ae1a64fb Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Wed, 6 Dec 2023 13:49:50 +0100 Subject: [PATCH 4/5] Fix up buffer length for fugacity functions --- src/CoolProp.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CoolProp.jl b/src/CoolProp.jl index 0a36da3..5e4855d 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -949,6 +949,7 @@ 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 @@ -976,6 +977,7 @@ julia> AbstractState_free(handle); ``` """ function AbstractState_get_fugacity_coefficient(handle::Clong, i::Integer) #TODO: maybe type this as an integer? + 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 From 1198e1a3355b414ea1fd5a13527b92addc101c08 Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Thu, 7 Dec 2023 20:10:06 +0100 Subject: [PATCH 5/5] Remove some TODOs --- src/CoolProp.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/CoolProp.jl b/src/CoolProp.jl index 5e4855d..2418248 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -926,7 +926,6 @@ 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) @@ -976,7 +975,7 @@ julia> AbstractState_get_fugacity_coefficient(handle, 0) julia> AbstractState_free(handle); ``` """ -function AbstractState_get_fugacity_coefficient(handle::Clong, i::Integer) #TODO: maybe type this as an integer? +function AbstractState_get_fugacity_coefficient(handle::Clong, i::Integer) 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)