Skip to content

Commit

Permalink
rm ; & test driv
Browse files Browse the repository at this point in the history
  • Loading branch information
DANA-Laboratory committed Jan 9, 2017
1 parent 95898cc commit dc61799
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 103 deletions.
56 changes: 29 additions & 27 deletions test/CoolProp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ export PropsSI, PhaseSI, get_global_param_string, get_parameter_information_stri
export propssi, phasesi, k2f, f2k, hapropssi, cair_sat, set_reference_state
export abstractstate_factory, abstractstate_free, abstractstate_set_fractions, abstractstate_update, abstractstate_keyed_output, abstractstate_specify_phase, abstractstate_unspecify_phase, abstractstate_update_and_common_out!, abstractstate_update_and_5_out!, abstractstate_update_and_1_out!, abstractstate_set_binary_interaction_double, abstractstate_set_cubic_alpha_c, abstractstate_set_fluid_parameter_double, abstractstate_output
export saturation_ancillary, set_departure_functions
export AbstractState_first_saturation_deriv
export abstractstate_first_saturation_deriv, abstractstate_first_partial_deriv, abstractstate_build_phase_envelope, abstractstate_get_phase_envelope_data!, abstractstate_build_spinodal, abstractstate_get_spinodal_data!, abstractState_all_critical_points!
errcode = Ref{Clong}(0)

const buffer_length = 20000
message_buffer = Array(UInt8, buffer_length)

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"];
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"]

include("CoolPropHighLevel.jl");
include("CoolPropConfig.jl");
include("CoolPropInformation.jl");
include("CoolPropHighLevel.jl")
include("CoolPropConfig.jl")
include("CoolPropInformation.jl")

# ---------------------------------
# Getter and setter for debug level
Expand Down Expand Up @@ -44,28 +45,29 @@ function set_debug_level(level::Integer) # change ::Int to ::Integer to make set
ccall( (:set_debug_level, "CoolProp"), Void, (Cint,), level)
end

include("CoolPropHA.jl");
include("CoolPropLowLevel.jl");
include("CoolPropHA.jl")
include("CoolPropLowLevel.jl")

const PropsSI = propssi;
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;
const AbstractState_unspecify_phase = abstractstate_unspecify_phase;
const AbstractState_update_and_common_out = abstractstate_update_and_common_out!;
const AbstractState_update_and_1_out = abstractstate_update_and_1_out!;
const AbstractState_update_and_5_out = abstractstate_update_and_5_out!;
const AbstractState_set_binary_interaction_double = abstractstate_set_binary_interaction_double;
const AbstractState_set_cubic_alpha_C = abstractstate_set_cubic_alpha_c;
const AbstractState_set_fluid_parameter_double = abstractstate_set_fluid_parameter_double;
const set_reference_stateS = set_reference_state;
const set_reference_stateD = set_reference_state;
const PropsSI = propssi
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
const AbstractState_unspecify_phase = abstractstate_unspecify_phase
const AbstractState_update_and_common_out = abstractstate_update_and_common_out!
const AbstractState_update_and_1_out = abstractstate_update_and_1_out!
const AbstractState_update_and_5_out = abstractstate_update_and_5_out!
const AbstractState_set_binary_interaction_double = abstractstate_set_binary_interaction_double
const AbstractState_set_cubic_alpha_C = abstractstate_set_cubic_alpha_c
const AbstractState_set_fluid_parameter_double = abstractstate_set_fluid_parameter_double
const set_reference_stateS = set_reference_state
const set_reference_stateD = set_reference_state
const AbstractState_first_saturation_deriv = abstractstate_first_saturation_deriv
end #module
8 changes: 8 additions & 0 deletions test/CoolPropLowLevel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ Calculate a saturation derivative from the AbstractState using integer values fo
* `of`: The parameter of which the derivative is being taken
* `wrt`: The derivative with with respect to this parameter
# Example
```julia
julia> as = AbstractState_factory("HEOS", "Water");
julia> AbstractState_update(as, "PQ_INPUTS", 15e5, 0)
julia> abstractstate_first_saturation_deriv(as, get_param_index("Hmolar"), get_param_index("P"))
0.0025636362140578207
```
# Ref
double CoolProp::AbstractState_first_saturation_deriv(const long handle, const long Of, const long Wrt, long* errcode, char* message_buffer, const long buffer_length);
"""
Expand Down
154 changes: 79 additions & 75 deletions test/testLow.jl
Original file line number Diff line number Diff line change
@@ -1,78 +1,78 @@
#low
info("********* Low Level Api *********")
const HEOS_BACKEND_FAMILY = "HEOS";
const HEOS_BACKEND_FAMILY = "HEOS"
const REFPROP_BACKEND_FAMILY = "REFPROP";#Need Install
const INCOMP_BACKEND_FAMILY = "INCOMP";
const IF97_BACKEND_FAMILY = "IF97";
const INCOMP_BACKEND_FAMILY = "INCOMP"
const IF97_BACKEND_FAMILY = "IF97"
const TREND_BACKEND_FAMILY = "TREND";#Not Imple
const TTSE_BACKEND_FAMILY = "TTSE";
const BICUBIC_BACKEND_FAMILY = "BICUBIC";
const SRK_BACKEND_FAMILY = "SRK";
const PR_BACKEND_FAMILY = "PR";
const TTSE_BACKEND_FAMILY = "TTSE"
const BICUBIC_BACKEND_FAMILY = "BICUBIC"
const SRK_BACKEND_FAMILY = "SRK"
const PR_BACKEND_FAMILY = "PR"
const VTPR_BACKEND_FAMILY = "VTPR";#Need Install
HEOS = AbstractState_factory(HEOS_BACKEND_FAMILY, "R245fa");
TTSE = AbstractState_factory(HEOS_BACKEND_FAMILY * "&" * TTSE_BACKEND_FAMILY, "R245fa");
BICU = AbstractState_factory(HEOS_BACKEND_FAMILY * "&" * BICUBIC_BACKEND_FAMILY, "R245fa");
SRK = AbstractState_factory(SRK_BACKEND_FAMILY, "R245fa");
PR = AbstractState_factory(PR_BACKEND_FAMILY, "R245fa");
PT_INPUTS = get_input_pair_index("PT_INPUTS");
AbstractState_update(HEOS, PT_INPUTS, 101325, 300);
AbstractState_update(TTSE, PT_INPUTS, 101325, 300);
AbstractState_update(BICU, PT_INPUTS, 101325, 300);
AbstractState_update(SRK, PT_INPUTS, 101325, 300);
AbstractState_update(PR, PT_INPUTS, 101325, 300);
rhmolar = get_param_index("DMOLAR");
println("HEOS:", AbstractState_keyed_output(HEOS, rhmolar));
@time AbstractState_keyed_output(HEOS, rhmolar);
println("TTSE:", AbstractState_keyed_output(TTSE, rhmolar));
@time AbstractState_keyed_output(TTSE, rhmolar);
println("BICU:", AbstractState_keyed_output(BICU, rhmolar));
@time AbstractState_keyed_output(BICU, rhmolar);
println("SRK:", AbstractState_keyed_output(SRK, rhmolar));
@time AbstractState_keyed_output(SRK, rhmolar);
println("PR:", AbstractState_keyed_output(PR, rhmolar));
@time AbstractState_keyed_output(PR, rhmolar);
AbstractState_free(HEOS);
AbstractState_free(TTSE);
AbstractState_free(BICU);
AbstractState_free(SRK);
AbstractState_free(PR);
IF97 = AbstractState_factory(IF97_BACKEND_FAMILY, "");
pin = 101325;
tin = 308.15;
println("IF97::Water property for PT_INPUTS $pin $tin");
AbstractState_update(IF97, PT_INPUTS, pin, tin);
HEOS = AbstractState_factory(HEOS_BACKEND_FAMILY, "R245fa")
TTSE = AbstractState_factory(HEOS_BACKEND_FAMILY * "&" * TTSE_BACKEND_FAMILY, "R245fa")
BICU = AbstractState_factory(HEOS_BACKEND_FAMILY * "&" * BICUBIC_BACKEND_FAMILY, "R245fa")
SRK = AbstractState_factory(SRK_BACKEND_FAMILY, "R245fa")
PR = AbstractState_factory(PR_BACKEND_FAMILY, "R245fa")
PT_INPUTS = get_input_pair_index("PT_INPUTS")
AbstractState_update(HEOS, PT_INPUTS, 101325, 300)
AbstractState_update(TTSE, PT_INPUTS, 101325, 300)
AbstractState_update(BICU, PT_INPUTS, 101325, 300)
AbstractState_update(SRK, PT_INPUTS, 101325, 300)
AbstractState_update(PR, PT_INPUTS, 101325, 300)
rhmolar = get_param_index("DMOLAR")
println("HEOS:", AbstractState_keyed_output(HEOS, rhmolar))
@time AbstractState_keyed_output(HEOS, rhmolar)
println("TTSE:", AbstractState_keyed_output(TTSE, rhmolar))
@time AbstractState_keyed_output(TTSE, rhmolar)
println("BICU:", AbstractState_keyed_output(BICU, rhmolar))
@time AbstractState_keyed_output(BICU, rhmolar)
println("SRK:", AbstractState_keyed_output(SRK, rhmolar))
@time AbstractState_keyed_output(SRK, rhmolar)
println("PR:", AbstractState_keyed_output(PR, rhmolar))
@time AbstractState_keyed_output(PR, rhmolar)
AbstractState_free(HEOS)
AbstractState_free(TTSE)
AbstractState_free(BICU)
AbstractState_free(SRK)
AbstractState_free(PR)
IF97 = AbstractState_factory(IF97_BACKEND_FAMILY, "")
pin = 101325
tin = 308.15
println("IF97::Water property for PT_INPUTS $pin $tin")
AbstractState_update(IF97, PT_INPUTS, pin, tin)
for p in "PTHDSAUCO"
pi = get_param_index("$p");
println("IF97 $p = ", AbstractState_keyed_output(IF97, pi));
pi = get_param_index("$p")
println("IF97 $p = ", AbstractState_keyed_output(IF97, pi))
end
qin = 0.5;
qin = 0.5
try
println("IF97::Water property for QT_INPUTS $qin $tin")
QT_INPUTS = get_input_pair_index("QT_INPUTS");
AbstractState_update(IF97, QT_INPUTS, qin, tin);
QT_INPUTS = get_input_pair_index("QT_INPUTS")
AbstractState_update(IF97, QT_INPUTS, qin, tin)
for p in "PTHDSAUQ"
pi = get_param_index("$p");
println("IF97 $p = ", AbstractState_keyed_output(IF97, pi));
pi = get_param_index("$p")
println("IF97 $p = ", AbstractState_keyed_output(IF97, pi))
end
catch
warn("QT_INPUTS not ready");
warn("QT_INPUTS not ready")
end
AbstractState_free(IF97);
AbstractState_free(IF97)
#AbstractState_output AbstractState_set_fractions AbstractState_specify_phase
handle = AbstractState_factory("HEOS", "Water&Ethanol");
pq_inputs = get_input_pair_index("PQ_INPUTS");
t = get_param_index("T");
AbstractState_set_fractions(handle, [0.4, 0.6]);
AbstractState_update(handle,pq_inputs,101325, 0);
temp = [0.0]; p = [0.0]; rhomolar = [0.0]; hmolar = [0.0]; smolar = [0.0]; temp_=[0.0]; out=[0.0]; out_=[0.0];
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, temp_, p, rhomolar, hmolar, smolar);
AbstractState_update_and_1_out(handle, pq_inputs, [101325.0], [0.0],1, t, out);
AbstractState_update_and_1_out(handle, "PQ_INPUTS", [101325.0], [0.0],1, "T", out_);
out1=[0.0]; out2=[0.0]; out3=[0.0]; out4=[0.0]; out5=[0.0]; out1_=[0.0];
AbstractState_update_and_5_out(handle, pq_inputs, [101325.0], [0.0],1, [t, t, t, t, t], out1, out2, out3, out4, out5);
AbstractState_update_and_5_out(handle, "PQ_INPUTS", [101325.0], [0.0],1, ["T", "T", "T", "T", "T"], out1_, out2, out3, out4, out5);
handle = AbstractState_factory("HEOS", "Water&Ethanol")
pq_inputs = get_input_pair_index("PQ_INPUTS")
t = get_param_index("T")
AbstractState_set_fractions(handle, [0.4, 0.6])
AbstractState_update(handle,pq_inputs,101325, 0)
temp = [0.0]; p = [0.0]; rhomolar = [0.0]; hmolar = [0.0]; smolar = [0.0]; temp_=[0.0]; out=[0.0]; out_=[0.0]
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, temp_, p, rhomolar, hmolar, smolar)
AbstractState_update_and_1_out(handle, pq_inputs, [101325.0], [0.0],1, t, out)
AbstractState_update_and_1_out(handle, "PQ_INPUTS", [101325.0], [0.0],1, "T", out_)
out1=[0.0]; out2=[0.0]; out3=[0.0]; out4=[0.0]; out5=[0.0]; out1_=[0.0]
AbstractState_update_and_5_out(handle, pq_inputs, [101325.0], [0.0],1, [t, t, t, t, t], out1, out2, out3, out4, out5)
AbstractState_update_and_5_out(handle, "PQ_INPUTS", [101325.0], [0.0],1, ["T", "T", "T", "T", "T"], out1_, out2, out3, out4, out5)
if is_apple()
@test_approx_eq AbstractState_keyed_output(handle,t) 352.3522212978604
@test_approx_eq AbstractState_output(handle,"T") 352.3522212978604
Expand All @@ -93,26 +93,30 @@ else
@test_approx_eq out1_[1] 352.3522212991724
end
for phase in ["phase_liquid", "phase_gas", "phase_twophase", "phase_supercritical", "phase_supercritical_gas", "phase_supercritical_liquid", "phase_critical_point", "phase_unknown", "phase_not_imposed"]
AbstractState_specify_phase(handle, phase);
AbstractState_specify_phase(handle, phase)
end
#AbstractState_set_binary_interaction_double AbstractState_set_fractions
AbstractState_free(handle);
handle = AbstractState_factory("HEOS", "Water&Ethanol");
AbstractState_set_binary_interaction_double(handle, 0, 1, "betaT", 0.987);
pq_inputs = get_input_pair_index("PQ_INPUTS");
t = get_param_index("T");
AbstractState_set_fractions(handle, [0.4, 0.6]);
AbstractState_update(handle, pq_inputs, 101325, 0);
res = AbstractState_keyed_output(handle,t);
AbstractState_free(handle);
AbstractState_free(handle)
handle = AbstractState_factory("HEOS", "Water&Ethanol")
AbstractState_set_binary_interaction_double(handle, 0, 1, "betaT", 0.987)
pq_inputs = get_input_pair_index("PQ_INPUTS")
t = get_param_index("T")
AbstractState_set_fractions(handle, [0.4, 0.6])
AbstractState_update(handle, pq_inputs, 101325, 0)
res = AbstractState_keyed_output(handle,t)
AbstractState_free(handle)
#AbstractState_set_cubic_alpha_C AbstractState_set_fluid_parameter_double
handle = AbstractState_factory("SRK", "Ethanol");
handle = AbstractState_factory("SRK", "Ethanol")
#AbstractState_set_cubic_alpha_C http://www.cjche.com.cn/EN/article/downloadArticleFile.do?attachType=PDF&id=1635
try
#do not export on all machines
AbstractState_set_cubic_alpha_C(handle, 0, "TWU", 1.0, 1.0, 1.0);
AbstractState_set_cubic_alpha_C(handle, 0, "TWU", 1.0, 1.0, 1.0)
catch err
warn("AbstractState_set_cubic_alpha_C fails with: $err")
end
AbstractState_set_fluid_parameter_double(handle, 0, "c", 1.0);
AbstractState_free(handle);
AbstractState_set_fluid_parameter_double(handle, 0, "c", 1.0)
AbstractState_free(handle)
handle = AbstractState_factory("HEOS", "Water")
AbstractState_update(handle, "PQ_INPUTS", 15e5, 0)
@test_approx_eq abstractstate_first_saturation_deriv(handle, get_param_index("Hmolar"), get_param_index("P")) 0.0025636362140578207
AbstractState_free(handle)
6 changes: 5 additions & 1 deletion test/testThrows.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ if (branchname == "nightly")
@test_throws ErrorException AbstractState_set_cubic_alpha_C(handle, 0, instr, 0.0, 0.0, 0.0)
end
if (haskey(ENV, "testCoolProp") && ENV["testCoolProp"]=="on")
@test_throws ErrorException saturation_ancillary(instr,"I", 1, "T", 300.0)
@test_throws ErrorException saturation_ancillary(instr, "I", 1, "T", 300.0)
@test_throws ErrorException saturation_ancillary("R410A", instr, 1, "T", 300.0)
end
AbstractState_free(handle)
handle = AbstractState_factory("HEOS", "Water")
AbstractState_update(handle, "PQ_INPUTS", 15e5, 0)
@test_throws ErrorException AbstractState_first_saturation_deriv(inhandle, 1%Clong, 2%Clong)
@test_throws ErrorException AbstractState_first_saturation_deriv(handle, inhandle, 2%Clong)

0 comments on commit dc61799

Please sign in to comment.