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/src/CoolProp.jl b/src/CoolProp.jl index db630b2..2418248 100644 --- a/src/CoolProp.jl +++ b/src/CoolProp.jl @@ -926,6 +926,62 @@ function AbstractState_update(handle::Clong, input_pair::AbstractString, value1: return nothing end +""" + 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) + 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) @@ -1435,7 +1491,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/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 diff --git a/test/testLow.jl b/test/testLow.jl index e18c218..801e957 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 = 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)