Skip to content

Commit

Permalink
Fix unexplained crashes with setting of reference state; See #524
Browse files Browse the repository at this point in the history
  • Loading branch information
ibell committed Mar 6, 2015
1 parent 05d209e commit 5e74610
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
2 changes: 1 addition & 1 deletion include/Helmholtz.h
Expand Up @@ -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(){};
Expand Down
19 changes: 5 additions & 14 deletions src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp
Expand Up @@ -37,11 +37,8 @@ static int deriv_counter = 0;
namespace CoolProp {

HelmholtzEOSMixtureBackend::HelmholtzEOSMixtureBackend(const std::vector<std::string> &component_names, bool generate_SatL_and_SatV) {
std::vector<CoolPropFluid> components;
components.resize(component_names.size());

for (unsigned int i = 0; i < components.size(); ++i)
{
std::vector<CoolPropFluid> components(component_names.size());
for (unsigned int i = 0; i < components.size(); ++i){
components[i] = get_library().get(component_names[i]);
}

Expand All @@ -64,18 +61,12 @@ void HelmholtzEOSMixtureBackend::set_components(const std::vector<CoolPropFluid>
// 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<CoolPropDbl>(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();
}
Expand Down
5 changes: 1 addition & 4 deletions src/CoolProp.cpp
Expand Up @@ -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<std::string> _comps(1, Ref);
CoolProp::HelmholtzEOSMixtureBackend HEOS(_comps);

CoolProp::HelmholtzEOSMixtureBackend HEOS(std::vector<std::string>(1,Ref));
if (!reference_state.compare("IIR"))
{
HEOS.update(QT_INPUTS, 0, 273.15);
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/CoolProp-Tests.cpp
Expand Up @@ -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<std::string> fluids = strsplit(CoolProp::get_global_param_string("fluids_list"),',');
for (std::size_t i = 0; i < fluids.size(); ++i)
Expand Down

0 comments on commit 5e74610

Please sign in to comment.