From 67bf8f528b737ce397233737af5796bdf3e7ca71 Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Mon, 27 Oct 2014 20:10:03 -0400 Subject: [PATCH] Re-implemented set_reference_stateD Closes https://github.com/CoolProp/CoolProp/issues/190 Signed-off-by: Ian Bell --- include/CoolProp.h | 6 +++--- src/CoolProp.cpp | 37 ++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/include/CoolProp.h b/include/CoolProp.h index dafc6d0f..9df4f995 100644 --- a/include/CoolProp.h +++ b/include/CoolProp.h @@ -135,13 +135,13 @@ You might want to start by looking at CoolProp.h */ void set_reference_stateS(std::string FluidName, std::string reference_state); - /// Set the reference state based on a thermodynamic state point + /// Set the reference state based on a thermodynamic state point specified by temperature and molar density /// @param FluidName The name of the fluid /// @param T Temperature at reference state [K] - /// @param rho Density at reference state [mol/m^3] + /// @param rhomolar Density at reference state [mol/m^3] /// @param h0 Enthalpy at reference state [J/kg] /// @param s0 Entropy at references state [J/kg/K] - //void set_reference_stateD(std::string FluidName, double T, double rho, double h0, double s0); + void set_reference_stateD(std::string FluidName, double T, double rhomolar, double h0, double s0); /// Return a string representation of the phase /// @param Name1 The first state variable name, one of "T","D","H",etc. diff --git a/src/CoolProp.cpp b/src/CoolProp.cpp index f62dbc8f..8232b0be 100644 --- a/src/CoolProp.cpp +++ b/src/CoolProp.cpp @@ -813,27 +813,22 @@ void set_reference_stateS(std::string Ref, std::string reference_state) throw ValueError(format("reference state string is invalid: [%s]",reference_state.c_str())); } } -//int set_reference_stateD(std::string Ref, double T, double rho, double h0, double s0) -//{ -// pFluid=Fluids.get_fluid(Ref); -// if (pFluid!=NULL) -// { -// CoolPropStateClassSI CPS(pFluid); -// CPS.update(iT,T,iD,rho); -// // Get current values for the enthalpy and entropy -// double h1 = CPS.h(); -// double s1 = CPS.s(); -// double deltah = h1-h0; // offset from given enthalpy in SI units -// double deltas = s1-s0; // offset from given enthalpy in SI units -// double delta_a1 = deltas/((8314.472)); -// double delta_a2 = -deltah/((8314.472)*pFluid->reduce.T); -// pFluid->phi0list.push_back(new phi0_enthalpy_entropy_offset(delta_a1, delta_a2)); -// return 0; -// } -// else{ -// return -1; -// } -//} +int set_reference_stateD(std::string Ref, double T, double rhomolar, double h0, double s0) +{ + shared_ptr HEOS; + std::vector _comps(1, Ref); + HEOS.reset(new CoolProp::HelmholtzEOSMixtureBackend(_comps)); + + HEOS->update(DmolarT_INPUTS, rhomolar, T); + + // Get current values for the enthalpy and entropy + double deltah = HEOS->hmass() - h0; // offset from specified enthalpy in J/mol + double deltas = HEOS->smass() - s0; // offset from specified entropy in J/mol/K + double delta_a1 = deltas/(8.314472/HEOS->molar_mass()); + double delta_a2 = -deltah/(8.314472/HEOS->molar_mass()*HEOS->get_reducing_state().T); + HEOS->get_components()[0]->pEOS->alpha0.EnthalpyEntropyOffset.set(delta_a1, delta_a2, "custom"); + HEOS->update_states(); +} std::string get_BibTeXKey(std::string Ref, std::string key) {