From 275adbbb6fda2e00ad949c8c4558e2ffd910c454 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Tue, 10 Mar 2015 01:17:44 -0600 Subject: [PATCH] Fixed reference states for real; Closes #524 --- include/Helmholtz.h | 19 +++++++++++++++++-- src/Backends/Helmholtz/Fluids/FluidLibrary.h | 2 +- src/CoolProp.cpp | 15 +++++++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/include/Helmholtz.h b/include/Helmholtz.h index 8d9aa21598..4543a7d14b 100644 --- a/include/Helmholtz.h +++ b/include/Helmholtz.h @@ -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;}; @@ -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) diff --git a/src/Backends/Helmholtz/Fluids/FluidLibrary.h b/src/Backends/Helmholtz/Fluids/FluidLibrary.h index c01052391d..6fd59d4836 100644 --- a/src/Backends/Helmholtz/Fluids/FluidLibrary.h +++ b/src/Backends/Helmholtz/Fluids/FluidLibrary.h @@ -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())); diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index 7f27f86cc4..870a4554da 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -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")) { @@ -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")) { @@ -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 {