From 5e74610d0e111ff7dd70de4cfa4023c5d29f2127 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Thu, 5 Mar 2015 21:47:36 -0700 Subject: [PATCH] Fix unexplained crashes with setting of reference state; See #524 --- include/Helmholtz.h | 2 +- .../Helmholtz/HelmholtzEOSMixtureBackend.cpp | 19 +++++-------------- src/CoolProp.cpp | 5 +---- src/Tests/CoolProp-Tests.cpp | 2 +- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/include/Helmholtz.h b/include/Helmholtz.h index c1f20fde60..848064e39f 100644 --- a/include/Helmholtz.h +++ b/include/Helmholtz.h @@ -584,7 +584,7 @@ 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){this->a1 += a1; this->a2 += a2; this->reference = ref; enabled = true;} //Destructor ~IdealHelmholtzEnthalpyEntropyOffset(){}; diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index c4553466ed..055881e54b 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -37,11 +37,8 @@ static int deriv_counter = 0; namespace CoolProp { HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(const std::vector &component_names, bool generate_SatL_and_SatV) { - std::vector components; - components.resize(component_names.size()); - - for (unsigned int i = 0; i < components.size(); ++i) - { + std::vector components(component_names.size()); + for (unsigned int i = 0; i < components.size(); ++i){ components[i] = get_library().get(component_names[i]); } @@ -64,18 +61,12 @@ void HelmholtzEOSMixtureBackend::set_components(const std::vector // Copy the components this->components = components; this->N = components.size(); - - if (components.size() == 1){ - is_pure_or_pseudopure = true; + + is_pure_or_pseudopure = (components.size() == 1); + if (is_pure_or_pseudopure){ mole_fractions = std::vector(1, 1); } else{ - is_pure_or_pseudopure = false; - } - - // Set the excess Helmholtz energy if a mixture - if (!is_pure_or_pseudopure) - { // Set the mixture parameters - binary pair reducing functions, departure functions, F_ij, etc. set_mixture_parameters(); } diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index ee4aa3170f..e0ddfefbd8 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -704,9 +704,7 @@ double saturation_ancillary(const std::string &fluid_name, const std::string &ou } void set_reference_stateS(const std::string &Ref, const std::string &reference_state) { - std::vector _comps(1, Ref); - CoolProp::HelmholtzEOSMixtureBackend HEOS(_comps); - + CoolProp::HelmholtzEOSMixtureBackend HEOS(std::vector(1,Ref)); if (!reference_state.compare("IIR")) { HEOS.update(QT_INPUTS, 0, 273.15); @@ -741,7 +739,6 @@ void set_reference_stateS(const std::string &Ref, const std::string &reference_s double deltas = HEOS.smass() - 0; // offset from 0 kJ/kg/K entropy double delta_a1 = deltas/(HEOS.gas_constant()/HEOS.molar_mass()); double delta_a2 = -deltah/(HEOS.gas_constant()/HEOS.molar_mass()*HEOS.get_reducing_state().T); - if (get_debug_level() > 5){std::cout << format("[set_reference_stateD] delta_a1 %g delta_a2 %g\n",delta_a1, delta_a2);} // Change the value in the library for the given fluid set_fluid_enthalpy_entropy_offset(Ref, delta_a1, delta_a2, "NBP"); } diff --git a/src/Tests/CoolProp-Tests.cpp b/src/Tests/CoolProp-Tests.cpp index adbbe7c65f..4714ee9af2 100644 --- a/src/Tests/CoolProp-Tests.cpp +++ b/src/Tests/CoolProp-Tests.cpp @@ -1439,7 +1439,7 @@ TEST_CASE("Test that reference states yield proper values using low-level interf } } } -TEST_CASE("Test that reference states are correct", "[reference_states_states]") +TEST_CASE("Test that reference states are correct", "[reference_states]") { std::vector fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),','); for (std::size_t i = 0; i < fluids.size(); ++i)