Skip to content

Commit

Permalink
file for low level api
Browse files Browse the repository at this point in the history
  • Loading branch information
DANA-Laboratory committed Dec 29, 2016
1 parent 36fb1ab commit 6d0084c
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 154 deletions.
162 changes: 9 additions & 153 deletions test/CoolProp.jl
@@ -1,7 +1,7 @@
module CoolProp
using Compat
export PropsSI, PhaseSI, get_global_param_string, get_parameter_information_string,get_fluid_param_string,set_reference_stateS, get_param_index, get_input_pair_index, set_config, F2K, K2F, HAPropsSI, AbstractState_factory, AbstractState_free, AbstractState_set_fractions, AbstractState_update, AbstractState_specify_phase, AbstractState_unspecify_phase, AbstractState_keyed_output, AbstractState_output, 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
export propssi, phasesi, k2f, f2k, hapropssi, cair_sat
export propssi, phasesi, k2f, f2k, hapropssi, cair_sat, abstractstate_factory, abstractstate_free, abstractstate_set_fractions, abstractstate_update, abstractstate_keyed_output, abstractstate_specify_phase
errcode = Ref{Clong}(0)

const buffer_length = 20000
Expand Down Expand Up @@ -54,131 +54,7 @@ end
###

include("CoolPropHA.jl");

# ---------------------------------
# Low-level access
# ---------------------------------

"""
AbstractState_factory(backend::AbstractString, fluids::AbstractString)
Generate an AbstractState instance, return an integer handle to the state class generated to be used in the other low-level accessor functions.
param backend The backend you will use, "HEOS", "REFPROP", etc.
param fluids '&' delimited list of fluids
return A handle to the state class generated
"""
function AbstractState_factory(backend::AbstractString, fluids::AbstractString)
AbstractState = ccall( (:AbstractState_factory, "CoolProp"), Clong, (Ptr{UInt8},Ptr{UInt8},Ref{Clong},Ptr{UInt8},Clong), backend,fluids,errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
end
return AbstractState
end

"""
AbstractState_free(handle::Clong)
Release a state class generated by the low-level interface wrapper.
param handle The integer handle for the state class stored in memory
"""
function AbstractState_free(handle::Clong)
ccall( (:AbstractState_free, "CoolProp"), Void, (Clong,Ref{Clong},Ptr{UInt8},Clong), handle,errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
end
return nothing
end

"""
AbstractState_set_fractions(handle::Clong,fractions::Array)
Set the fractions (mole, mass, volume) for the AbstractState.
param handle The integer handle for the state class stored in memory
param fractions The array of fractions
"""
function AbstractState_set_fractions(handle::Clong,fractions::Array)
ccall( (:AbstractState_set_fractions, "CoolProp"), Void, (Clong,Ptr{Cdouble},Clong,Ref{Clong},Ptr{UInt8},Clong), handle,fractions,length(fractions),errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
end
return nothing
end

"""
AbstractState_update(handle::Clong,input_pair::Clong,value1::Real,value2::Real)
AbstractState_update(handle::Clong,input_pair::AbstractString,value1::Real,value2::Real)
Update the state of the AbstractState.
param handle The integer handle for the state class stored in memory
param input_pair The integer value for the input pair obtained from get_input_pair_index(param::AbstractString)
param value1 The first input value
param value2 The second input value
"""
function AbstractState_update(handle::Clong,input_pair::Clong,value1::Real,value2::Real)
ccall( (:AbstractState_update, "CoolProp"), Void, (Clong,Clong,Cdouble,Cdouble,Ref{Clong},Ptr{UInt8},Clong), handle,input_pair,value1,value2,errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
end
return nothing
end

function AbstractState_update(handle::Clong,input_pair::AbstractString,value1::Real,value2::Real)
AbstractState_update(handle::Clong,get_input_pair_index(input_pair),value1::Real,value2::Real)
return nothing
end

"""
AbstractState_specify_phase(handle::Clong,phase::AbstractString)
Specify the phase to be used for all further calculations.
handle The integer handle for the state class stored in memory
phase The string with the phase to use
errcode The errorcode that is returned (0 = no error, !0 = error)
message_buffer A buffer for the error code
buffer_length The length of the buffer for the error code
"""
function AbstractState_specify_phase(handle::Clong,phase::AbstractString)
ccall( (:AbstractState_specify_phase, "CoolProp"), Void, (Clong,Ptr{UInt8},Ref{Clong},Ptr{UInt8},Clong), handle,phase,errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
end
return nothing
end
include("CoolPropLowLevel.jl");

"""
bstractState_unspecify_phase(handle::Clong)
Expand All @@ -204,33 +80,6 @@ function AbstractState_unspecify_phase(handle::Clong)
return nothing
end

"""
AbstractState_keyed_output(handle::Clong, param::Clong)
AbstractState_output(handle::Clong, param::AbstractString)
Get an output value from the AbstractState using an integer value for the desired output value.
param handle The integer handle for the state class stored in memory
param param The integer value for the parameter you want
"""
function AbstractState_keyed_output(handle::Clong, param::Clong)
output = ccall( (:AbstractState_keyed_output, "CoolProp"), Cdouble, (Clong,Clong,Ref{Clong},Ptr{UInt8},Clong), handle,param,errcode,message_buffer::Array{UInt8,1},buffer_length)
if errcode[] != 0
if errcode[] == 1
error("CoolProp: ", unsafe_string(convert(Ptr{UInt8}, pointer(message_buffer))))
elseif errcode[] == 2
error("CoolProp: message buffer too small")
else # == 3
error("CoolProp: unknown error")
end
elseif output == -Inf
error("CoolProp: no correct state has been set with AbstractState_update")
end
return output
end
function AbstractState_output(handle::Clong, param::AbstractString)
return AbstractState_keyed_output(handle, get_param_index(param))
end

# /**
# * @brief Calculate a saturation derivative from the AbstractState using integer values for the desired parameters
Expand Down Expand Up @@ -520,4 +369,11 @@ const PhaseSI = phasesi;
const K2F = k2f;
const F2K = f2k;
const HAPropsSI = hapropssi;
const AbstractState_factory = abstractstate_factory;
const AbstractState_free = abstractstate_free;
const AbstractState_set_fractions = abstractstate_set_fractions;
const AbstractState_update = abstractstate_update;
const AbstractState_keyed_output = abstractstate_keyed_output;
const AbstractState_output = abstractstate_output;
const AbstractState_specify_phase = abstractstate_specify_phase;
end #module
2 changes: 1 addition & 1 deletion test/CoolPropHighLevel.jl
Expand Up @@ -8,7 +8,7 @@
Return a value that does not depend on the thermodynamic state - this is a convenience function that does the call `PropsSI(output, "", 0, "", 0, fluid)`.
# Arguments
* `fluid::AbstractString`: The name of the fluid that is part of CoolProp, for instance "n-Propane", to get a list of different passible fulid types call `get_global_param_string(key)` with `key` one of the following: `["FluidsList", "incompressible_list_pure", "incompressible_list_solution", "mixture_binary_pairs_list", "predefined_mixtures"]`, also there is a list in CoolProp online documentation [List of Fluids](http://www.coolprop.org/fluid_properties/PurePseudoPure.html#list-of-fluids), or simply type `?fluids`
* `fluid::AbstractString`: The name of the fluid that is part of CoolProp, for instance "n-Propane", to get a list of possible values types call `get_global_param_string(key)` with `key` one of the following: `["FluidsList", "incompressible_list_pure", "incompressible_list_solution", "mixture_binary_pairs_list", "predefined_mixtures"]`, also there is a list in CoolProp online documentation [List of Fluids](http://www.coolprop.org/fluid_properties/PurePseudoPure.html#list-of-fluids), or simply type `?fluids`
* `output::AbstractString`: The name of parameter to evaluate. to see a list type `?parameters`
# Example
Expand Down
3 changes: 3 additions & 0 deletions test/CoolPropInformation.jl
Expand Up @@ -123,6 +123,9 @@ end
get_param_index(param::AbstractString)
Get the index as a long for a parameter "T", "P", etc, for `abstractstate_keyed_output()` function.
# Arguments
* `param`: A string represents parameter name, to see full list check "Table of string inputs to PropsSI function": http://www.coolprop.org/coolprop/HighLevelAPI.html#parameter-table, or simply type `get_global_param_string("parameter_list")`
"""
function get_param_index(param::AbstractString)
val = ccall( (:get_param_index, "CoolProp"), Clong, (Ptr{UInt8},), param)
Expand Down

0 comments on commit 6d0084c

Please sign in to comment.