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

Adapt buffer length #34

Merged
merged 5 commits into from
Sep 24, 2023
Merged
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
29 changes: 26 additions & 3 deletions src/CoolProp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ using CoolProp_jll
####################################################################################################################

errcode = Ref{Clong}(0)
const buffer_length = 20000
message_buffer = Array{UInt8}(undef, buffer_length)
const message_buffer = Array{UInt8}(undef, 32768) #2^15

const inputs_to_get_global_param_string = ["version", "gitrevision", "errstring", "warnstring", "FluidsList", "incompressible_list_pure", "incompressible_list_solution", "mixture_binary_pairs_list", "parameter_list", "predefined_mixtures", "HOME", "cubic_fluids_schema"]

Expand Down Expand Up @@ -172,6 +171,7 @@ julia> PhaseSI("T", 300, "P", 3541, "Water")
CoolProp::PhaseSI(const std::string &, double, const std::string &, double, const std::string&)
"""
function PhaseSI(name1::AbstractString, value1::Real, name2::AbstractString, value2::Real, fluid::AbstractString)
buffer_length = length(message_buffer)
val = ccall( (:PhaseSI, libcoolprop), Int32, (Cstring, Cdouble, Cstring, Cdouble, Cstring, Ptr{UInt8}, Int), name1, value1, name2, value2, fluid, message_buffer::Array{UInt8, 1}, buffer_length)
val = unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer::Array{UInt8, 1})))
if val == ""
Expand Down Expand Up @@ -445,6 +445,7 @@ ref CoolProp::get_global_param_string
* `key`: A string represents parameter name, could be one of $inputs_to_get_global_param_string
"""
function get_global_param_string(key::AbstractString)
buffer_length = length(message_buffer)
val = ccall( (:get_global_param_string, libcoolprop), Clong, (Cstring, Ptr{UInt8}, Int), key, message_buffer::Array{UInt8, 1}, buffer_length)
if val == 0
error("CoolProp: ", get_global_param_string("errstring"))
Expand Down Expand Up @@ -475,6 +476,7 @@ A tabular output for this function is available with `?CoolProp_parameters`
"""
function get_parameter_information_string(key::AbstractString, outtype::AbstractString)
message_buffer[1:length(outtype)+1] = [Vector{UInt8}(outtype); 0x00]
buffer_length = length(message_buffer)
val = ccall( (:get_parameter_information_string, libcoolprop), Clong, (Cstring, Ptr{UInt8}, Int), key, message_buffer::Array{UInt8, 1}, buffer_length)
if val == 0
error("CoolProp: ", get_global_param_string("errstring"))
Expand Down Expand Up @@ -509,6 +511,7 @@ ParamName | Description
A tabular output for this function is available with `?CoolProp_fluids`
"""
function get_fluid_param_string(fluid::AbstractString, param::AbstractString)
buffer_length = length(message_buffer)
val = ccall( (:get_fluid_param_string, libcoolprop), Clong, (Cstring, Cstring, Ptr{UInt8}, Int), fluid, param, message_buffer::Array{UInt8, 1}, buffer_length)
if val == 0
error("CoolProp: ", get_global_param_string("errstring"))
Expand Down Expand Up @@ -770,6 +773,7 @@ julia> PR = AbstractState_factory("PR", "R245fa");
```
"""
function AbstractState_factory(backend::AbstractString, fluids::AbstractString)
buffer_length = length(message_buffer)
AbstractState = ccall( (:AbstractState_factory, libcoolprop), Clong, (Cstring, Cstring, Ref{Clong}, Ptr{UInt8}, Clong), backend, fluids, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return AbstractState
Expand All @@ -784,6 +788,7 @@ Release a state class generated by the low-level interface wrapper.
* `handle`: The integer handle for the state class stored in memory
"""
function AbstractState_free(handle::Clong)
buffer_length = length(message_buffer)
ccall( (:AbstractState_free, libcoolprop), Nothing, (Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -811,6 +816,7 @@ julia> AbstractState_free(handle);
```
"""
function AbstractState_set_fractions(handle::Clong, fractions::Array{Float64})
buffer_length = length(message_buffer)
ccall( (:AbstractState_set_fractions, libcoolprop), Nothing, (Clong, Ptr{Cdouble}, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, fractions, length(fractions), errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -842,6 +848,7 @@ julia> AbstractState_free(handle);
```
"""
function AbstractState_update(handle::Clong, input_pair::Clong, value1::Real, value2::Real)
buffer_length = length(message_buffer)
ccall( (:AbstractState_update, libcoolprop), Nothing, (Clong, Clong, Cdouble, Cdouble, Ref{Clong}, Ptr{UInt8}, Clong), handle, input_pair, value1, value2, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand All @@ -865,6 +872,7 @@ Get an output value from the `AbstractState` using an integer value for the desi
See `AbstractState_output`
"""
function AbstractState_keyed_output(handle::Clong, param::Clong)
buffer_length = length(message_buffer)
output = ccall( (:AbstractState_keyed_output, libcoolprop), Cdouble, (Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, param, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
if output == -Inf
Expand Down Expand Up @@ -924,6 +932,7 @@ julia> AbstractState_free(heos);
```
"""
function AbstractState_specify_phase(handle::Clong, phase::AbstractString)
buffer_length = length(message_buffer)
ccall( (:AbstractState_specify_phase, libcoolprop), Nothing, (Clong, Cstring, Ref{Clong}, Ptr{UInt8}, Clong), handle, phase, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand All @@ -938,6 +947,7 @@ Unspecify the phase to be used for all further calculations.
* `handle`: The integer handle for the state class stored in memory
"""
function AbstractState_unspecify_phase(handle::Clong)
buffer_length = length(message_buffer)
ccall( (:AbstractState_unspecify_phase, libcoolprop), Nothing, (Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -973,6 +983,7 @@ julia> AbstractState_free(handle);
```
"""
function AbstractState_update_and_common_out(handle::Clong, input_pair::Clong, value1::Array{Float64}, value2::Array{Float64}, length::Integer, T::Array{Float64}, p::Array{Float64}, rhomolar::Array{Float64}, hmolar::Array{Float64}, smolar::Array{Float64})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_update_and_common_out, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Clong, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Clong}, Ptr{UInt8}, Clong), handle, input_pair, value1, value2, length, T, p, rhomolar, hmolar, smolar, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return T, p, rhomolar, hmolar, smolar
Expand Down Expand Up @@ -1008,6 +1019,7 @@ Update the state of the AbstractState and get one output value (temperature, pre
* `out`: The array for output
"""
function AbstractState_update_and_1_out(handle::Clong, input_pair::Clong, value1::Array{Float64}, value2::Array{Float64}, length::Integer, output::Clong, out::Array{Float64})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_update_and_1_out, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Clong, Clong, Ref{Cdouble}, Ref{Clong}, Ptr{UInt8}, Clong), handle, input_pair, value1, value2, length, output, out, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return out
Expand Down Expand Up @@ -1047,6 +1059,7 @@ Update the state of the AbstractState and get an output value five common output
* `out5`: The array for the fifth output
"""
function AbstractState_update_and_5_out(handle::Clong, input_pair::Clong, value1::Array{Float64}, value2::Array{Float64}, length::Integer, outputs::Array{Clong}, out1::Array{Float64}, out2::Array{Float64}, out3::Array{Float64}, out4::Array{Float64}, out5::Array{Float64})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_update_and_5_out, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Clong, Ref{Clong}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Clong}, Ptr{UInt8}, Clong), handle, input_pair, value1, value2, length, outputs, out1, out2, out3, out4, out5, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return out1, out2, out3, out4, out5
Expand Down Expand Up @@ -1093,6 +1106,7 @@ julia> AbstractState_free(handle);
```
"""
function AbstractState_set_binary_interaction_double(handle::Clong, i::Integer, j::Integer, parameter::AbstractString, value::Real)
buffer_length = length(message_buffer)
ccall( (:AbstractState_set_binary_interaction_double, libcoolprop), Nothing, (Clong, Clong, Clong, Cstring, Cdouble, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, j, parameter, value, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand All @@ -1112,6 +1126,7 @@ Set cubic's alpha function parameters.
* `c3`: the third parameter for the alpha function
"""
function AbstractState_set_cubic_alpha_C(handle::Clong, i::Integer, parameter::AbstractString, c1::Real, c2::Real, c3::Real)
buffer_length = length(message_buffer)
ccall( (:AbstractState_set_cubic_alpha_C, libcoolprop), Nothing, (Clong, Clong, Cstring, Cdouble, Cdouble, Cdouble, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, parameter, c1, c2, c3, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand All @@ -1129,6 +1144,7 @@ Set some fluid parameter (ie volume translation for cubic). Currently applied to
* `value`: the value of the parameter
"""
function AbstractState_set_fluid_parameter_double(handle::Clong, i::Integer, parameter::AbstractString, value::Real)
buffer_length = length(message_buffer)
ccall( (:AbstractState_set_fluid_parameter_double, libcoolprop), Nothing, (Clong, Clong, Cstring, Cdouble, Ref{Clong}, Ptr{UInt8}, Clong), handle, i, parameter, value, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -1156,6 +1172,7 @@ julia> AbstractState_first_saturation_deriv(as, get_param_index("Hmolar"), get_p
double CoolProp::AbstractState_first_saturation_deriv(const long handle, const long Of, const long Wrt, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_first_saturation_deriv(handle::Clong, of::Clong, wrt::Clong)
buffer_length = length(message_buffer)
output = ccall( (:AbstractState_first_saturation_deriv, libcoolprop), Cdouble, (Clong, Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, of, wrt, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
if output == -Inf
Expand Down Expand Up @@ -1189,7 +1206,8 @@ julia> AbstractState_first_partial_deriv(as, get_param_index("Hmolar"), get_para
double CoolProp::AbstractState_first_partial_deriv(const long handle, const long Of, const long Wrt, const long Constant, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_first_partial_deriv(handle::Clong, of::Clong, wrt::Clong, constant::Clong)
output = ccall( (:AbstractState_first_partial_deriv, libcoolprop), Cdouble, (Clong, Clong, Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, of, wrt, constant, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
buffer_length = length(message_buffer)
utput = ccall( (:AbstractState_first_partial_deriv, libcoolprop), Cdouble, (Clong, Clong, Clong, Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, of, wrt, constant, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
if output == -Inf
error("CoolProp: no correct state has been set with AbstractState_update")
Expand All @@ -1213,6 +1231,7 @@ If there is an error in an update call for one of the inputs, no change in the o
CoolPRop::AbstractState_build_phase_envelope(const long handle, const char* level, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_build_phase_envelope(handle::Clong, level::AbstractString)
buffer_length = length(message_buffer)
ccall( (:AbstractState_build_phase_envelope, libcoolprop), Nothing, (Clong, Cstring, Ref{Clong}, Ptr{UInt8}, Clong), handle, level, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -1251,6 +1270,7 @@ If there is an error in an update call for one of the inputs, no change in the o
CoolProp::AbstractState_get_phase_envelope_data(const long handle, const long length, double* T, double* p, double* rhomolar_vap, double* rhomolar_liq, double* x, double* y, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_get_phase_envelope_data(handle::Clong, length::Integer, T::Array{Float64}, p::Array{Float64}, rhomolar_vap::Array{Float64}, rhomolar_liq::Array{Float64}, x::Array{Float64}, y::Array{Float64})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_get_phase_envelope_data, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Clong}, Ptr{UInt8}, Clong), handle, length, T, p, rhomolar_vap, rhomolar_liq, x, y, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return T, p, rhomolar_vap, rhomolar_liq, x, y
Expand All @@ -1274,6 +1294,7 @@ Build the spinodal.
CoolProp::AbstractState_build_spinodal(const long handle, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_build_spinodal(handle::Clong)
buffer_length = length(message_buffer)
ccall( (:AbstractState_build_spinodal, libcoolprop), Nothing, (Clong, Ref{Clong}, Ptr{UInt8}, Clong), handle, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return nothing
Expand Down Expand Up @@ -1304,6 +1325,7 @@ julia> tau, delta, m1 = AbstractState_get_spinodal_data(HEOS, 127);
CoolProp::AbstractState_get_spinodal_data(const long handle, const long length, double* tau, double* delta, double* M1, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_get_spinodal_data(handle::Clong, length::Integer, tau::Array{Float64}, delta::Array{Float64}, m1::Array{Float64})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_get_spinodal_data, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Clong}, Ptr{UInt8}, Clong), handle, length, tau, delta, m1, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return tau, delta, m1;
Expand Down Expand Up @@ -1334,6 +1356,7 @@ If there is an error in an update call for one of the inputs, no change in the o
CoolProp::AbstractState_all_critical_points(const long handle, const long length, double* T, double* p, double* rhomolar, long* stable, long* errcode, char* message_buffer, const long buffer_length);
"""
function AbstractState_all_critical_points(handle::Clong, length::Integer, T::Array{Float64}, p::Array{Float64}, rhomolar::Array{Float64}, stable::Array{Clong})
buffer_length = Base.length(message_buffer)
ccall( (:AbstractState_all_critical_points, libcoolprop), Nothing, (Clong, Clong, Ref{Cdouble}, Ref{Cdouble}, Ref{Cdouble}, Ref{Clong}, Ref{Clong}, Ptr{UInt8}, Clong), handle, length, T, p, rhomolar, stable, errcode, message_buffer::Array{UInt8, 1}, buffer_length)
raise(errcode, message_buffer)
return T, p, rhomolar, stable
Expand Down