-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36fb1ab
commit 0f428d2
Showing
5 changed files
with
203 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
# --------------------------------- | ||
# 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. | ||
# Arguments | ||
* `backend`: The backend you will use, `["HEOS", "REFPROP", "INCOMP", "IF97", "TREND", "HEOS&TTSE", "HEOS&BICUBIC", "SRK", "PR", "VTPR"]` etc. | ||
* `fluids`: '&' delimited list of fluids, to get a list of possible values 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` | ||
# Example | ||
```julia | ||
julia> HEOS = abstractstate_factory("HEOS", "R245fa"); | ||
julia> TTSE = abstractstate_factory("HEOS&TTSE", "R245fa"); | ||
julia> BICU = abstractstate_factory("HEOS&BICUBIC", "R245fa"); | ||
julia> SRK = abstractstate_factory("SRK", "R245fa"); | ||
julia> PR = abstractstate_factory("PR", "R245fa"); | ||
``` | ||
""" | ||
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. | ||
# Arguments | ||
* `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. | ||
# Arguments | ||
* `handle`: The integer handle for the state class stored in memory | ||
* `fractions`: The array of fractions | ||
# 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_keyed_output(handle,t) | ||
352.3522212991724 | ||
julia> abstractstate_free(handle); | ||
``` | ||
""" | ||
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. | ||
# Arguments | ||
* `handle`: The integer handle for the state class stored in memory | ||
* `input_pair::Clong`: The integer value for the input pair obtained from get_input_pair_index(param::AbstractString) | ||
* `input_pair::AbstractString`: The name of an input pair | ||
* `value1`: The first input value | ||
* `value2`: The second input value | ||
# 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_keyed_output(handle,t) | ||
352.3522212991724 | ||
julia> abstractstate_free(handle); | ||
``` | ||
""" | ||
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_keyed_output(handle::Clong, param::Clong) | ||
Get an output value from the `abstractstate` using an integer value for the desired output value. | ||
# Arguments | ||
* `handle`: The integer handle for the state class stored in memory | ||
* `param::Clong`: param The integer value for the parameter you want | ||
# Note | ||
See `abstractstate_output` | ||
""" | ||
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 | ||
|
||
""" | ||
abstractstate_output(handle::Clong, param::AbstractString) | ||
Get an output value from the `abstractstate` using an integer value for the desired output value. It is a convenience function that call `abstractstate_keyed_output` | ||
# Arguments | ||
* `handle`: The integer handle for the state class stored in memory | ||
* `param::AbstractString`: The name for the parameter you want | ||
""" | ||
function abstractstate_output(handle::Clong, param::AbstractString) | ||
return abstractstate_keyed_output(handle, get_param_index(param)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters