Skip to content

Commit

Permalink
Fixed reference states for real; Closes #524
Browse files Browse the repository at this point in the history
  • Loading branch information
ibell committed Mar 10, 2015
1 parent bb7b446 commit 275adbb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
19 changes: 17 additions & 2 deletions include/Helmholtz.h
Expand Up @@ -571,7 +571,22 @@ class IdealHelmholtzEnthalpyEntropyOffset : public BaseHelmholtzTerm{
IdealHelmholtzEnthalpyEntropyOffset(CoolPropDbl a1, CoolPropDbl a2, const std::string &ref):a1(a1),a2(a2),reference(ref),enabled(true) {}

// Set the values in the class
void set(CoolPropDbl a1, CoolPropDbl a2, const std::string &ref){this->a1 += a1; this->a2 += a2; this->reference = ref; enabled = true;}
void set(CoolPropDbl a1, CoolPropDbl a2, const std::string &ref){
// If it doesn't already exist, just set the values
if (enabled == false){
this->a1 = a1; this->a2 = a2;
enabled = true;
}
else if(ref == "DEF"){
this->a1 = 0.0; this->a2 = 0.0; enabled = false;
}
else{
// Otherwise, increment the values
this->a1 += a1; this->a2 += a2;
enabled = true;
}
this->reference = ref;
}

bool is_enabled() const {return enabled;};

Expand Down Expand Up @@ -1046,7 +1061,7 @@ class IdealHelmholtzContainer
IdealHelmholtzCP0PolyT CP0PolyT;

CoolPropDbl base(const CoolPropDbl &tau, const CoolPropDbl &delta)
{
{
return (Lead.base(tau, delta) + EnthalpyEntropyOffset.base(tau, delta)
+ EnthalpyEntropyOffsetCore.base(tau, delta)
+ LogTau.base(tau, delta) + Power.base(tau, delta)
Expand Down
2 changes: 1 addition & 1 deletion src/Backends/Helmholtz/Fluids/FluidLibrary.h
Expand Up @@ -1204,7 +1204,7 @@ class JSONFluidLibrary
if (!ValidNumber(delta_a1) || !ValidNumber(delta_a2) ){
throw ValueError(format("Not possible to set reference state for fluid %s because offset values are NAN",fluid.c_str()));
}
it2->second.EOSVector[0].alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, ref);
it2->second.EOS().alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, ref);
}
else{
throw ValueError(format("fluid [%s] was not found in JSONFluidLibrary",fluid.c_str()));
Expand Down
15 changes: 11 additions & 4 deletions src/CoolProp.cpp
Expand Up @@ -716,7 +716,9 @@ void set_reference_stateS(const std::string &Ref, const std::string &reference_s
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "IIR");
HEOS.update_states();
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("ASHRAE"))
{
Expand All @@ -729,6 +731,9 @@ void set_reference_stateS(const std::string &Ref, const std::string &reference_s
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "ASHRAE");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("NBP"))
{
Expand All @@ -741,15 +746,17 @@ void set_reference_stateS(const std::string &Ref, const std::string &reference_s
double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T);
// Change the value in the library for the given fluid
set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "NBP");
if (get_debug_level() > 0){
std::cout << format("set offsets to %g and %g\n", delta_a1, delta_a2);
}
}
else if (!reference_state.compare("DEF"))
{
set_fluid_enthalpy_entropy_offset(Ref, 0, 0, "");
set_fluid_enthalpy_entropy_offset(Ref, 0, 0, "DEF");
}
else if (!reference_state.compare("RESET"))
{
HEOS.get_components()[0].EOS().alpha0.EnthalpyEntropyOffset.set(0, 0, "");
HEOS.get_components()[0].EOS().alpha0.EnthalpyEntropyOffsetCore.set(0, 0, "");
set_fluid_enthalpy_entropy_offset(Ref, 0, 0, "RESET");
}
else
{
Expand Down

0 comments on commit 275adbb

Please sign in to comment.