From d8c9157e35f6f324c63f0c34a987fa1637e5fdaf Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 19:07:56 +1000 Subject: [PATCH 01/52] Fix Coverity CID 38534 --- src/Backends/Helmholtz/FlashRoutines.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 01d3c8d4d6..2c440500c6 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -504,6 +504,9 @@ void FlashRoutines::PT_Q_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS, parame IO.rhomolar_vap = CubicInterp(env.T, env.rhomolar_vap, imax-1, imax, imax+1, imax+2, static_cast(IO.T)); IO.p = CubicInterp(env.rhomolar_vap, env.p, imax-1, imax, imax+1, imax+2, IO.rhomolar_vap); } + else{ + throw ValueError(); + } IO.rhomolar_liq = CubicInterp(env.rhomolar_vap, env.rhomolar_liq, imax-1, imax, imax+1, imax+2, IO.rhomolar_vap); if (quality == SATURATED_VAPOR){ From 0b96d388595f4ec2ff891751f96b47e374088197 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 19:09:11 +1000 Subject: [PATCH 02/52] Fix Coverity CID 38624 --- src/CoolPropLib.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index 7097c22cd9..f7cbdc7311 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -67,9 +67,7 @@ double convert_from_kSI_to_SI(long iInput, double value) return value; default: throw CoolProp::ValueError(format("index [%d] is invalid in convert_from_kSI_to_SI",iInput).c_str()); - break; } - return _HUGE; } double convert_from_SI_to_kSI(long iInput, double value) From 6bd986e97958dd7b66e7ba7c397f0a374d0e4ea8 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 20:06:35 +1000 Subject: [PATCH 03/52] Fix Coverity CID 38619 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 2672b90fb4..55a12200d1 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -174,27 +174,19 @@ double IncompressibleFluid::psat(double T, double x){ switch (p_sat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.evaluate(p_sat.coeffs, T, x, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL: return baseExponential(p_sat, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL: return baseLogexponential(p_sat, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL: return exp(poly.evaluate(p_sat.coeffs, T, x, 0, 0, Tbase, xbase)); - break; case IncompressibleData::INCOMPRESSIBLE_POLYOFFSET: return basePolyOffset(p_sat, T, x); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,p_sat.type)); - break; default: throw ValueError(format("%s (%d): Your function type \"[%d]\" is unknown.",__FILE__,__LINE__,p_sat.type)); - break; } - return _HUGE; } /// Freezing temperature as a function of pressure and composition. double IncompressibleFluid::Tfreeze( double p, double x){ From 0fbed17b50c0ecd1bc1985e5f35add7762f98c1a Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 20:08:17 +1000 Subject: [PATCH 04/52] Fix Coverity CID 38618 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 55a12200d1..2e5aea048e 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -65,7 +65,6 @@ double IncompressibleFluid::basePolyOffset(IncompressibleData data, double y, do return poly.evaluate(coeffs, in, 0, offset); } throw ValueError(format("%s (%d): You have to provide a vector (1D matrix) of coefficients, not (%d,%d).",__FILE__,__LINE__,r,c)); - return _HUGE; } From af3107ed9a36bd9d1983aa55ff7b4b87ea9603de Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 22:14:30 +1000 Subject: [PATCH 05/52] Fix Coverity CID 38616 --- include/AbstractState.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/AbstractState.h b/include/AbstractState.h index 2d97175cf9..ab79d4b071 100644 --- a/include/AbstractState.h +++ b/include/AbstractState.h @@ -306,7 +306,7 @@ class AbstractState { public: - AbstractState(){clear();}; + AbstractState():_fluid_type(FLUID_TYPE_UNDEFINED),_phase(iphase_unknown),_rhospline(-_HUGE),_dsplinedp(-_HUGE),_dsplinedh(-_HUGE){clear();} virtual ~AbstractState(){}; /// A factory function to return a pointer to a new-allocated instance of one of the backends. From a44ac2c7ace683cf13596403d2c84d722ba1a575 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 22:36:51 +1000 Subject: [PATCH 06/52] Fix Coverity CID 38623 --- src/Backends/Helmholtz/FlashRoutines.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 2c440500c6..bc41101f94 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -676,12 +676,12 @@ void FlashRoutines::PHSU_D_flash(HelmholtzEOSMixtureBackend &HEOS, parameters ot public: HelmholtzEOSMixtureBackend *HEOS; - CoolPropDbl r, eos, rhomolar, value, T; + CoolPropDbl rhomolar, value; int other; solver_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl rhomolar, CoolPropDbl value, int other) : HEOS(HEOS), rhomolar(rhomolar), value(value), other(other){}; double call(double T){ - this->T = T; + CoolPropDbl eos; switch(other) { case iP: @@ -696,8 +696,7 @@ void FlashRoutines::PHSU_D_flash(HelmholtzEOSMixtureBackend &HEOS, parameters ot throw ValueError(format("Input not supported")); } - r = eos - value; - return r; + return eos - value; }; }; From 31e5e6638e82ce6d07e776524ac5f74da97fd4db Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 22:39:49 +1000 Subject: [PATCH 07/52] Fix Coverity CID 38621 --- src/Backends/Helmholtz/Fluids/Ancillaries.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp index a8ff3354e6..b0a659f820 100644 --- a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp +++ b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp @@ -226,18 +226,14 @@ CoolPropDbl MeltingLineVariables::evaluate(int OF, int GIVEN, CoolPropDbl value) { public: MeltingLinePiecewisePolynomialInTrSegment *part; - CoolPropDbl r, given_p, calc_p, T; + CoolPropDbl given_p; solver_resid(MeltingLinePiecewisePolynomialInTrSegment *part, CoolPropDbl p) : part(part), given_p(p){}; double call(double T){ - this->T = T; - - calc_p = part->evaluate(T); + CoolPropDbl calc_p = part->evaluate(T); // Difference between the two is to be driven to zero - r = given_p - calc_p; - - return r; + return given_p - calc_p; }; }; From 4ae7040d910b78abfd0d2675e07c78b2744653a1 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 22:46:07 +1000 Subject: [PATCH 08/52] Fix Coverity CID 38615 --- include/CoolPropFluid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/CoolPropFluid.h b/include/CoolPropFluid.h index 2b25cce456..c2897bd8a9 100644 --- a/include/CoolPropFluid.h +++ b/include/CoolPropFluid.h @@ -452,7 +452,7 @@ class CoolPropFluid { std::string ECSReferenceFluid; ///< A string that gives the name of the fluids that should be used for the ECS method for transport properties double ECS_qd; ///< The critical qd parameter for the Olchowy-Sengers cross-over term public: - CoolPropFluid(){}; + CoolPropFluid():ECS_qd(-_HUGE){}; ~CoolPropFluid(){}; EquationOfState &EOS() {return EOSVector[0];}; ///< Get a reference to the equation of state std::vector EOSVector; ///< The equations of state that could be used for this fluid From 725f706c6ea5a5210fcb2905c59ce9af2af7b877 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 22:52:20 +1000 Subject: [PATCH 09/52] Fix Coverity CID 38614 --- src/Backends/Helmholtz/FlashRoutines.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index bc41101f94..d68dbf0f61 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -639,7 +639,7 @@ void FlashRoutines::HSU_D_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolP public: HelmholtzEOSMixtureBackend &HEOS; - CoolPropDbl rhomolar_spec, Qd, Qo; + CoolPropDbl rhomolar_spec; parameters other; CoolPropDbl value; Residual(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl rhomolar_spec, parameters other, CoolPropDbl value) : HEOS(HEOS), rhomolar_spec(rhomolar_spec), other(other), value(value){}; @@ -648,9 +648,9 @@ void FlashRoutines::HSU_D_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolP HelmholtzEOSMixtureBackend &SatL = HEOS.get_SatL(), &SatV = HEOS.get_SatV(); // Quality from density - Qd = (1/HEOS.rhomolar()-1/SatL.rhomolar())/(1/SatV.rhomolar()-1/SatL.rhomolar()); + CoolPropDbl Qd = (1 / HEOS.rhomolar() - 1 / SatL.rhomolar()) / (1 / SatV.rhomolar() - 1 / SatL.rhomolar()); // Quality from other parameter (H,S,U) - Qo = (value-SatL.keyed_output(other))/(SatV.keyed_output(other)-SatL.keyed_output(other)); + CoolPropDbl Qo = (value - SatL.keyed_output(other)) / (SatV.keyed_output(other) - SatL.keyed_output(other)); // Residual is the difference between the two return Qo-Qd; } From 94f261975a3d9cba222d070fbd50fe6a78608655 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 23:04:25 +1000 Subject: [PATCH 10/52] Fix Coverity CID 38612 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 2e5aea048e..6067eb6c63 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -102,15 +102,11 @@ double IncompressibleFluid::c (double T, double p, double x){ case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: //throw NotImplementedError("Here you should implement the polynomial."); return poly.evaluate(specific_heat.coeffs, T, x, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for specific heat.",__FILE__,__LINE__,specific_heat.type)); - break; } - return _HUGE; } /// Viscosity as a function of temperature, pressure and composition. From 40ebfb5a55e034e634c162a385466b1372726d6b Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 23:07:12 +1000 Subject: [PATCH 11/52] Fix Coverity CID 38611 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 6067eb6c63..974185484e 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -188,27 +188,19 @@ double IncompressibleFluid::Tfreeze( double p, double x){ switch (T_freeze.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.evaluate(T_freeze.coeffs, p, x, 0, 0, 0.0, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL: return baseExponential(T_freeze, x, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL: return baseLogexponential(T_freeze, x, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL: return exp(poly.evaluate(T_freeze.coeffs, p, x, 0, 0, 0.0, xbase)); - break; case IncompressibleData::INCOMPRESSIBLE_POLYOFFSET: return basePolyOffset(T_freeze, p, x); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,T_freeze.type)); - break; default: throw ValueError(format("%s (%d): Your function type \"[%d]\" is unknown.",__FILE__,__LINE__,T_freeze.type)); - break; } - return _HUGE; } From c32f05312aacaae93f5af66497d21b1767ca60e9 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 23:14:29 +1000 Subject: [PATCH 12/52] Fix Coverity CID 38609 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 974185484e..c6aca3358b 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -247,15 +247,11 @@ double IncompressibleFluid::dhdTatPxdT(double T, double p, double x){ switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.integral(specific_heat.coeffs, T, x, 0, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for entropy.",__FILE__,__LINE__,specific_heat.type)); - break; } - return _HUGE; } From 358757df84b08b0fd058a3aeb73aee95b6207a07 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 23:38:37 +1000 Subject: [PATCH 13/52] Fix Coverity CID 38607 --- src/Backends/Helmholtz/FlashRoutines.cpp | 3 +-- src/Backends/Helmholtz/VLERoutines.cpp | 3 +-- src/Backends/Helmholtz/VLERoutines.h | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index d68dbf0f61..e7802572ae 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -251,8 +251,7 @@ void FlashRoutines::QT_flash(HelmholtzEOSMixtureBackend &HEOS) else if (!(HEOS.components[0].EOS().pseudo_pure)) { // Set some imput options - SaturationSolvers::saturation_T_pure_Akasaka_options options; - options.use_guesses = false; + SaturationSolvers::saturation_T_pure_Akasaka_options options(false); // Actually call the solver SaturationSolvers::saturation_T_pure_Maxwell(HEOS, HEOS._T, options); diff --git a/src/Backends/Helmholtz/VLERoutines.cpp b/src/Backends/Helmholtz/VLERoutines.cpp index d4cafde2ee..6b2851364b 100644 --- a/src/Backends/Helmholtz/VLERoutines.cpp +++ b/src/Backends/Helmholtz/VLERoutines.cpp @@ -725,9 +725,8 @@ void SaturationSolvers::saturation_D_pure(HelmholtzEOSMixtureBackend &HEOS, Cool void SaturationSolvers::saturation_T_pure(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, saturation_T_pure_options &options) { // Set some imput options - SaturationSolvers::saturation_T_pure_Akasaka_options _options; + SaturationSolvers::saturation_T_pure_Akasaka_options _options(false); _options.omega = 1.0; - _options.use_guesses = false; try{ // Actually call the solver SaturationSolvers::saturation_T_pure_Maxwell(HEOS, T, _options); diff --git a/src/Backends/Helmholtz/VLERoutines.h b/src/Backends/Helmholtz/VLERoutines.h index 986e755f00..25cd0a5f5a 100644 --- a/src/Backends/Helmholtz/VLERoutines.h +++ b/src/Backends/Helmholtz/VLERoutines.h @@ -11,7 +11,7 @@ namespace SaturationSolvers struct saturation_T_pure_Akasaka_options{ bool use_guesses; ///< true to start off at the values specified by rhoL, rhoV CoolPropDbl omega, rhoL, rhoV, pL, pV; - saturation_T_pure_Akasaka_options(){omega = _HUGE; rhoV = _HUGE; rhoL = _HUGE; pV = _HUGE, pL = _HUGE;} + saturation_T_pure_Akasaka_options(bool use_guesses=false):use_guesses(use_guesses),omega(_HUGE),rhoV(_HUGE),rhoL(_HUGE),pV(_HUGE),pL(_HUGE){} }; struct saturation_T_pure_options{ bool use_guesses; ///< true to start off at the values specified by rhoL, rhoV From ae6e516754791ec0462ca58ef9b3ed8d0f6dd81f Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Fri, 6 Mar 2015 23:55:56 +1000 Subject: [PATCH 14/52] Tried to fix Coverity CID 38605 --- include/Configuration.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/include/Configuration.h b/include/Configuration.h index 88e63ceec8..dc5381b613 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -45,13 +45,6 @@ std::string config_key_to_string(configuration_keys keys); class ConfigurationItem { public: - enum ConfigurationDataTypes {CONFIGURATION_NOT_DEFINED_TYPE = 0, - CONFIGURATION_BOOL_TYPE, - CONFIGURATION_DOUBLE_TYPE, - CONFIGURATION_INTEGER_TYPE, - CONFIGURATION_STRING_TYPE, - CONFIGURATION_ENDOFLIST_TYPE}; - ConfigurationDataTypes type; /// Cast to boolean operator bool() const { check_data_type(CONFIGURATION_BOOL_TYPE); return v_bool; }; @@ -149,14 +142,26 @@ class ConfigurationItem #endif // !defined(SWIG) protected: + enum ConfigurationDataTypes { + CONFIGURATION_NOT_DEFINED_TYPE = 0, + CONFIGURATION_BOOL_TYPE, + CONFIGURATION_DOUBLE_TYPE, + CONFIGURATION_INTEGER_TYPE, + CONFIGURATION_STRING_TYPE, + CONFIGURATION_ENDOFLIST_TYPE + }; void check_data_type(ConfigurationDataTypes type) const { if (type != this->type){ throw ValueError(format("type does not match")); } }; - double v_double; - bool v_bool; - int v_integer; + ConfigurationDataTypes type; + union { + double v_double; + bool v_bool; + int v_integer; + + }; std::string v_string; configuration_keys key; }; From cd1443d9922ccf8d7f48034c9ea37534dba1ce4e Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 12:27:41 +1000 Subject: [PATCH 15/52] Fix Coverity CID 38603 --- src/Backends/Helmholtz/FlashRoutines.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index e7802572ae..98dc697810 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -1217,16 +1217,16 @@ void FlashRoutines::HS_flash_twophase(HelmholtzEOSMixtureBackend &HEOS, CoolProp public: HelmholtzEOSMixtureBackend &HEOS; - CoolPropDbl hmolar, smolar, Qs, Qh; + CoolPropDbl hmolar, smolar; Residual(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl hmolar_spec, CoolPropDbl smolar_spec) : HEOS(HEOS), hmolar(hmolar_spec), smolar(smolar_spec){}; double call(double T){ HEOS.update(QT_INPUTS, 0, T); HelmholtzEOSMixtureBackend &SatL = HEOS.get_SatL(), &SatV = HEOS.get_SatV(); // Quality from entropy - Qs = (smolar-SatL.smolar())/(SatV.smolar()-SatL.smolar()); + CoolPropDbl Qs = (smolar-SatL.smolar())/(SatV.smolar()-SatL.smolar()); // Quality from enthalpy - Qh = (hmolar-SatL.hmolar())/(SatV.hmolar()-SatL.hmolar()); + CoolPropDbl Qh = (hmolar-SatL.hmolar())/(SatV.hmolar()-SatL.hmolar()); // Residual is the difference between the two return Qh-Qs; } From a4bf9fb3ece6fac8a01242ac13bb5c2732154b37 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 12:30:40 +1000 Subject: [PATCH 16/52] Fix Coverity CID 38601 --- src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 055881e54b..5c9d71b570 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1899,7 +1899,6 @@ CoolPropDbl HelmholtzEOSMixtureBackend::solver_rho_Tp(CoolPropDbl T, CoolPropDbl throw ValueError(format("solver_rho_Tp was unable to find a solution for T=%10Lg, p=%10Lg, with guess value %10Lg",T,p,rhomolar_guess)); } - return _HUGE; } } } From 53fb1bd75c351c5d78ea3f20b4a9932548af4242 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 12:34:07 +1000 Subject: [PATCH 17/52] Fix Coverity CID 38599 --- src/Backends/Helmholtz/VLERoutines.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Backends/Helmholtz/VLERoutines.cpp b/src/Backends/Helmholtz/VLERoutines.cpp index 6b2851364b..0aa456b1c4 100644 --- a/src/Backends/Helmholtz/VLERoutines.cpp +++ b/src/Backends/Helmholtz/VLERoutines.cpp @@ -11,14 +11,13 @@ void SaturationSolvers::saturation_critical(HelmholtzEOSMixtureBackend &HEOS, pa class inner_resid : public FuncWrapper1D{ public: HelmholtzEOSMixtureBackend *HEOS; - CoolPropDbl T, desired_p, rhomolar_liq, calc_p, rhomolar_crit; + CoolPropDbl T, desired_p; inner_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl T, CoolPropDbl desired_p) : HEOS(HEOS), T(T), desired_p(desired_p){}; double call(double rhomolar_liq){ - this->rhomolar_liq = rhomolar_liq; HEOS->SatL->update(DmolarT_INPUTS, rhomolar_liq, T); - calc_p = HEOS->SatL->p(); + CoolPropDbl calc_p = HEOS->SatL->p(); std::cout << format("inner p: %0.16Lg; res: %0.16Lg", calc_p, calc_p - desired_p) << std::endl; return calc_p - desired_p; } From bdeb976f89cf4d9c90803d48303dff1e705ad543 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 12:56:12 +1000 Subject: [PATCH 18/52] Fix Coverity CID 38598 Commented out the (seemingly unused and dead) parts that responsible for derivative. --- src/Backends/Helmholtz/FlashRoutines.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index 208512168f..27fc6ef375 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -125,25 +125,22 @@ class FlashRoutines{ class solver_TP_resid : public FuncWrapper1D { public: - CoolPropDbl T, p, r, peos, rhomolar, rhor, tau, R_u, delta, dalphar_dDelta; + CoolPropDbl T, p, rhor, tau, R_u; HelmholtzEOSMixtureBackend *HEOS; - solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p){ - this->HEOS = &HEOS; this->T = T; this->p = p; this->rhor = HEOS.get_reducing_state().rhomolar; - this->tau = HEOS.get_reducing_state().T/T; this->R_u = HEOS.gas_constant(); - }; + solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p): + HEOS(&HEOS),T(T),p(p),rhor(HEOS.get_reducing_state().rhomolar), + tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()) {} double call(double rhomolar){ - this->rhomolar = rhomolar; - delta = rhomolar/rhor; // needed for derivative +// CoolPropDbl delta = rhomolar/rhor; // needed for derivative HEOS->update_DmolarT_direct(rhomolar, T); - peos = HEOS->p(); - r = (peos-p)/p; - return r; + CoolPropDbl peos = HEOS->p(); + return (peos-p)/p; }; - double deriv(double rhomolar){ +/* double deriv(double rhomolar){ // dp/drho|T / pspecified return R_u*T*(1+2*delta*HEOS->dalphar_dDelta()+pow(delta, 2)*HEOS->d2alphar_dDelta2())/p; - }; + };*/ }; /** A residual function for the f(P, Y) solver From 2be5f6b4a6a4ac0eda95685865be60e039e67138 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:05:12 +1000 Subject: [PATCH 19/52] Fix Coverity CID 38597 No need to initialize cached_component_string; its default constructor creates an empty string --- src/Backends/REFPROP/REFPROPMixtureBackend.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/REFPROP/REFPROPMixtureBackend.h b/src/Backends/REFPROP/REFPROPMixtureBackend.h index 683c4a7f2a..eda9bb86f0 100644 --- a/src/Backends/REFPROP/REFPROPMixtureBackend.h +++ b/src/Backends/REFPROP/REFPROPMixtureBackend.h @@ -36,7 +36,7 @@ class REFPROPMixtureBackend : public AbstractState { CoolPropDbl call_phi0dll(long itau, long idelta); public: - REFPROPMixtureBackend(){cached_component_string = ""; instance_counter++;}; + REFPROPMixtureBackend():Ncomp(0),_mole_fractions_set(false) {instance_counter++;} /// The instantiator /// @param fluid_names The vector of strings of the fluid components, without file ending From 766f7636fcd403510dea46d61d379cf2fe58bac2 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:12:27 +1000 Subject: [PATCH 20/52] Fix Coverity CID 38596 --- src/Backends/Helmholtz/Fluids/Ancillaries.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp index b0a659f820..ccc88af09e 100644 --- a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp +++ b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp @@ -256,18 +256,14 @@ CoolPropDbl MeltingLineVariables::evaluate(int OF, int GIVEN, CoolPropDbl value) { public: MeltingLinePiecewisePolynomialInThetaSegment *part; - CoolPropDbl r, given_p, calc_p, T; + CoolPropDbl given_p; solver_resid(MeltingLinePiecewisePolynomialInThetaSegment *part, CoolPropDbl p) : part(part), given_p(p){}; double call(double T){ - this->T = T; - - calc_p = part->evaluate(T); + CoolPropDbl calc_p = part->evaluate(T); // Difference between the two is to be driven to zero - r = given_p - calc_p; - - return r; + return given_p - calc_p; }; }; From 85b35ea828c4b0ef7f1028045cb48785e8ef9846 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:25:05 +1000 Subject: [PATCH 21/52] Fix Coverity CID 38595 --- src/Backends/Helmholtz/ReducingFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Helmholtz/ReducingFunctions.h b/src/Backends/Helmholtz/ReducingFunctions.h index 18fe89d0f2..13ee371386 100644 --- a/src/Backends/Helmholtz/ReducingFunctions.h +++ b/src/Backends/Helmholtz/ReducingFunctions.h @@ -31,7 +31,7 @@ class ReducingFunction protected: std::size_t N; public: - ReducingFunction(){}; + ReducingFunction():N(0){}; virtual ~ReducingFunction(){}; /// A factory function to generate the requiredreducing function From 9d1c7f4f167727c606f8e162035aa4f9084c73f3 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:27:45 +1000 Subject: [PATCH 22/52] Fix Coverity CID 38594 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index c6aca3358b..662321112f 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -114,27 +114,19 @@ double IncompressibleFluid::visc(double T, double p, double x){ switch (viscosity.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.evaluate(viscosity.coeffs, T, x, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL: return baseExponential(viscosity, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL: return baseLogexponential(viscosity, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL: return exp(poly.evaluate(viscosity.coeffs, T, x, 0, 0, Tbase, xbase)); - break; case IncompressibleData::INCOMPRESSIBLE_POLYOFFSET: return basePolyOffset(viscosity, T, x); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,viscosity.type)); - break; default: throw ValueError(format("%s (%d): Your function type \"[%d]\" is unknown.",__FILE__,__LINE__,viscosity.type)); - break; } - return _HUGE; } /// Thermal conductivity as a function of temperature, pressure and composition. double IncompressibleFluid::cond(double T, double p, double x){ From 9184e9e9bd9bb65be084e6a55325856c9fda0279 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:29:55 +1000 Subject: [PATCH 23/52] Fix Coverity CID 38592 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 662321112f..760664821d 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -133,27 +133,19 @@ double IncompressibleFluid::cond(double T, double p, double x){ switch (conductivity.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.evaluate(conductivity.coeffs, T, x, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL: return baseExponential(conductivity, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL: return baseLogexponential(conductivity, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL: return exp(poly.evaluate(conductivity.coeffs, T, x, 0, 0, Tbase, xbase)); - break; case IncompressibleData::INCOMPRESSIBLE_POLYOFFSET: return basePolyOffset(conductivity, T, x); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,conductivity.type)); - break; default: throw ValueError(format("%s (%d): Your function type \"[%d]\" is unknown.",__FILE__,__LINE__,conductivity.type)); - break; } - return _HUGE; } /// Saturation pressure as a function of temperature and composition. double IncompressibleFluid::psat(double T, double x){ From 01cd7571a6ec2083c903445924402599d855183b Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:42:09 +1000 Subject: [PATCH 24/52] Fix Coverity CID 38590 use_guesses seems to be unused --- src/Backends/Helmholtz/VLERoutines.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Backends/Helmholtz/VLERoutines.h b/src/Backends/Helmholtz/VLERoutines.h index 25cd0a5f5a..44b0f67959 100644 --- a/src/Backends/Helmholtz/VLERoutines.h +++ b/src/Backends/Helmholtz/VLERoutines.h @@ -14,9 +14,8 @@ namespace SaturationSolvers saturation_T_pure_Akasaka_options(bool use_guesses=false):use_guesses(use_guesses),omega(_HUGE),rhoV(_HUGE),rhoL(_HUGE),pV(_HUGE),pL(_HUGE){} }; struct saturation_T_pure_options{ - bool use_guesses; ///< true to start off at the values specified by rhoL, rhoV CoolPropDbl omega, rhoL, rhoV, pL, pV, p, T; - saturation_T_pure_options(){omega = _HUGE; rhoV = _HUGE; rhoL = _HUGE; rhoL = _HUGE; pV = _HUGE, pL = _HUGE; T = _HUGE;} + saturation_T_pure_options():omega(_HUGE),rhoV(_HUGE),rhoL(_HUGE),pV(_HUGE),pL(_HUGE),p(_HUGE),T(_HUGE){} }; struct saturation_D_pure_options{ From 4b576746eafb55605498b548f287544ec6bcbf0d Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:44:45 +1000 Subject: [PATCH 25/52] Fix Coverity CID 38589 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 760664821d..7a4a950a66 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -197,15 +197,11 @@ double IncompressibleFluid::drhodTatPx (double T, double p, double x){ switch (density.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.derivative(density.coeffs, T, x, 0, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,density.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for density.",__FILE__,__LINE__,density.type)); - break; } - return _HUGE; } /// Partial derivative of entropy // with respect to temperature at constant pressure and composition From 46d36d12d6bd20684e19130a1b045510adb02941 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 13:47:02 +1000 Subject: [PATCH 26/52] Fix Coverity CID 38587 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 7a4a950a66..0fe99f63a7 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -73,27 +73,19 @@ double IncompressibleFluid::rho (double T, double p, double x){ switch (density.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.evaluate(density.coeffs, T, x, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_EXPONENTIAL: return baseExponential(density, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_LOGEXPONENTIAL: return baseLogexponential(density, T, 0.0); - break; case IncompressibleData::INCOMPRESSIBLE_EXPPOLYNOMIAL: return exp(poly.evaluate(density.coeffs, T, x, 0, 0, Tbase, xbase)); - break; case IncompressibleData::INCOMPRESSIBLE_POLYOFFSET: return basePolyOffset(density, T, x); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,density.type)); - break; default: throw ValueError(format("%s (%d): Your function type \"[%d]\" is unknown.",__FILE__,__LINE__,density.type)); - break; } - return _HUGE; } /// Heat capacities as a function of temperature, pressure and composition. From 982ff514784eccafcfb67cbe5fbf4b15a55b2e63 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 14:17:37 +1000 Subject: [PATCH 27/52] Tried to fix Coverity CID 38586 --- include/Ancillaries.h | 14 ++++++++++---- src/Backends/Helmholtz/Fluids/Ancillaries.cpp | 15 +++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/Ancillaries.h b/include/Ancillaries.h index 3d0d873487..9c04d7525a 100644 --- a/include/Ancillaries.h +++ b/include/Ancillaries.h @@ -82,15 +82,21 @@ class SaturationAncillaryFunction private: Eigen::MatrixXd num_coeffs, ///< Coefficients for numerator in rational polynomial den_coeffs; ///< Coefficients for denominator in rational polynomial - std::vector n, t, s; - bool using_tau_r; - CoolPropDbl Tmax, Tmin, reducing_value, T_r, max_abs_error; + std::vector n, t, s; // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL + union{ + CoolPropDbl max_abs_error; // For TYPE_RATIONAL_POLYNOMIAL + struct{ // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL + bool using_tau_r; + CoolPropDbl reducing_value, T_r; + std::size_t N; + }; + }; + CoolPropDbl Tmax, Tmin; enum ancillaryfunctiontypes{TYPE_NOT_SET = 0, TYPE_NOT_EXPONENTIAL, TYPE_EXPONENTIAL, TYPE_RATIONAL_POLYNOMIAL}; ancillaryfunctiontypes type; - std::size_t N; public: SaturationAncillaryFunction(){type = TYPE_NOT_SET;}; diff --git a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp index ccc88af09e..a3231d998f 100644 --- a/src/Backends/Helmholtz/Fluids/Ancillaries.cpp +++ b/src/Backends/Helmholtz/Fluids/Ancillaries.cpp @@ -16,6 +16,7 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ std::string type = cpjson::get_string(json_code,"type"); if (!type.compare("rational_polynomial")) { + this->type = TYPE_RATIONAL_POLYNOMIAL; num_coeffs = vec_to_eigen(cpjson::get_double_array(json_code["A"])); den_coeffs = vec_to_eigen(cpjson::get_double_array(json_code["B"])); max_abs_error = cpjson::get_double(json_code,"max_abs_error"); @@ -30,7 +31,13 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ } else { + if (!type.compare("rhoLnoexp")) + this->type = TYPE_NOT_EXPONENTIAL; + else + this->type = TYPE_EXPONENTIAL; n = cpjson::get_double_array(json_code["n"]); + N = n.size(); + s = n; t = cpjson::get_double_array(json_code["t"]); Tmin = cpjson::get_double(json_code,"Tmin"); Tmax = cpjson::get_double(json_code,"Tmax"); @@ -39,14 +46,6 @@ SaturationAncillaryFunction::SaturationAncillaryFunction(rapidjson::Value &json_ T_r = cpjson::get_double(json_code,"T_r"); } - if (!type.compare("rational_polynomial")) - this->type = TYPE_RATIONAL_POLYNOMIAL; - else if (!type.compare("rhoLnoexp")) - this->type = TYPE_NOT_EXPONENTIAL; - else - this->type = TYPE_EXPONENTIAL; - this->N = n.size(); - s = n; }; double SaturationAncillaryFunction::evaluate(double T) From a7d33d5f770c9947b1776316e5a617ac96bb33d1 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 14:28:46 +1000 Subject: [PATCH 28/52] Fix Coverity CID 38585 --- include/CoolPropTools.h | 2 +- src/CoolPropTools.cpp | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/include/CoolPropTools.h b/include/CoolPropTools.h index 2175ab6e18..4823f2068d 100644 --- a/include/CoolPropTools.h +++ b/include/CoolPropTools.h @@ -579,7 +579,7 @@ template void normalize_vector(std::vector &x) std::vector B; public: double a,b,c,d; - SplineClass(); + SplineClass():Nconstraints(0),A(4, std::vector(4, 0)),B(4,0),a(_HUGE),b(_HUGE),c(_HUGE),d(_HUGE){} bool build(void); bool add_value_constraint(double x, double y); void add_4value_constraints(double x1, double x2, double x3, double x4, double y1, double y2, double y3, double y4); diff --git a/src/CoolPropTools.cpp b/src/CoolPropTools.cpp index b6c1df335d..4d865cac03 100644 --- a/src/CoolPropTools.cpp +++ b/src/CoolPropTools.cpp @@ -239,12 +239,6 @@ std::string strjoin(const std::vector &strings, const std::string & } -SplineClass::SplineClass() -{ - Nconstraints = 0; - A.resize(4, std::vector(4, 0)); - B.resize(4,0); -} bool SplineClass::build() { if (Nconstraints == 4) From f7af3b2199f752cc4bf8cad6c8ef368b750210ad Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 15:03:23 +1000 Subject: [PATCH 29/52] Fix Coverity CID 38583 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 0fe99f63a7..ccdc2f5da6 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -367,15 +367,11 @@ double IncompressibleFluid::T_c (double Cmass, double p, double x){ switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.solve_limits(specific_heat.coeffs, x, c_raw, Tmin, Tmax, 0, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for inverse specific heat.",__FILE__,__LINE__,specific_heat.type)); - break; } - return _HUGE; } /* From c479e098c2b0e563d84222fb3a44a758ee263826 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 15:34:54 +1000 Subject: [PATCH 30/52] Fix Coverity CID 38581 --- src/Backends/Incompressible/IncompressibleBackend.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index b04a2b3305..5a52162c5a 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -326,16 +326,9 @@ CoolPropDbl IncompressibleBackend::HmassP_flash(CoolPropDbl hmass, CoolPropDbl p protected: double p,x,h_in; IncompressibleBackend* backend; - protected: - HmassP_residual(){}; public: - HmassP_residual(IncompressibleBackend* backend, const double &p, const double &x, const double &h_in){ - this->p=p; - this->x=x; - this->h_in = h_in; - this->backend=backend; - } - virtual ~HmassP_residual(){}; + HmassP_residual(IncompressibleBackend* backend, const double &p, const double &x, const double &h_in) + : p(p),x(x),h_in(h_in),backend(backend){} double call(double target){ return backend->raw_calc_hmass(target,p,x) - h_in; //fluid.u(target,p,x)+ p / fluid.rho(target,p,x) - h_in; } From 9314a7a7eddfe153d6d09d202f4df9d461e8f2f7 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 16:33:20 +1000 Subject: [PATCH 31/52] Fix Coverity CID 38580 --- src/Backends/Incompressible/IncompressibleBackend.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleBackend.cpp b/src/Backends/Incompressible/IncompressibleBackend.cpp index 5a52162c5a..effadc6758 100644 --- a/src/Backends/Incompressible/IncompressibleBackend.cpp +++ b/src/Backends/Incompressible/IncompressibleBackend.cpp @@ -357,16 +357,9 @@ CoolPropDbl IncompressibleBackend::PSmass_flash(CoolPropDbl p, CoolPropDbl smass protected: double p,x,s_in; IncompressibleBackend* backend; - protected: - PSmass_residual(){}; public: - PSmass_residual(IncompressibleBackend* backend, const double &p, const double &x, const double &s_in){ - this->p = p; - this->x = x; - this->s_in = s_in; - this->backend = backend; - } - virtual ~PSmass_residual(){}; + PSmass_residual(IncompressibleBackend* backend, const double &p, const double &x, const double &s_in) + : p(p),x(x),s_in(s_in),backend(backend){} double call(double target){ return backend->raw_calc_smass(target,p,x) - s_in; } From 21f44a8a934b40bb6bc3c1bdcfe7ffe26ded59da Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 16:50:45 +1000 Subject: [PATCH 32/52] Fix Coverity CID 38579 --- .../Helmholtz/HelmholtzEOSMixtureBackend.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 5c9d71b570..2131637558 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1642,14 +1642,13 @@ CoolPropDbl HelmholtzEOSMixtureBackend::solver_for_rho_given_T_oneof_HSU(CoolPro { public: int other; - CoolPropDbl T, value, r, eos, rhomolar; + CoolPropDbl T, value; HelmholtzEOSMixtureBackend *HEOS; - solver_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl T, CoolPropDbl value, int other){ - this->HEOS = HEOS; this->T = T; this->value = value; this->other = other; - }; + solver_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl T, CoolPropDbl value, int other) + : HEOS(HEOS),T(T),value(value),other(other){} double call(double rhomolar){ - this->rhomolar = rhomolar; + CoolPropDbl eos; switch(other) { case iSmolar: @@ -1662,8 +1661,7 @@ CoolPropDbl HelmholtzEOSMixtureBackend::solver_for_rho_given_T_oneof_HSU(CoolPro throw ValueError(format("Input not supported")); } - r = eos-value; - return r; + return eos-value; }; }; solver_resid resid(this, T, value, other); From cc62abca744bb2a86225e0dfeeeb26e0ed18f532 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 16:53:55 +1000 Subject: [PATCH 33/52] Fix Coverity CID 38578 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index ccdc2f5da6..2705f00cf2 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -202,15 +202,11 @@ double IncompressibleFluid::dsdTatPxdT(double T, double p, double x){ switch (specific_heat.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.integral(specific_heat.coeffs, T, x, 0, -1, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for entropy.",__FILE__,__LINE__,specific_heat.type)); - break; } - return _HUGE; } /// Partial derivative of enthalpy // with respect to temperature at constant pressure and composition From 81e18a0a083617e21dbab9152fb7ee3296210c30 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 16:57:11 +1000 Subject: [PATCH 34/52] Fix Coverity CID 38574 --- src/CoolPropLib.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CoolPropLib.cpp b/src/CoolPropLib.cpp index f7cbdc7311..4b96fc9b14 100644 --- a/src/CoolPropLib.cpp +++ b/src/CoolPropLib.cpp @@ -97,9 +97,7 @@ double convert_from_SI_to_kSI(long iInput, double value) return value; default: throw CoolProp::ValueError(format("index [%d] is invalid in convert_from_SI_to_kSI", iInput).c_str()); - break; } - return _HUGE; } EXPORT_CODE long CONVENTION redirect_stdout(const char* file){ From b91f62cb51acba2c746f1070f8720b09bf20dcf5 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 17:05:44 +1000 Subject: [PATCH 35/52] Fix Coverity CID 38573 --- .../Helmholtz/HelmholtzEOSMixtureBackend.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 2131637558..76c3cfb145 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1797,20 +1797,17 @@ CoolPropDbl HelmholtzEOSMixtureBackend::solver_rho_Tp(CoolPropDbl T, CoolPropDbl class solver_TP_resid : public FuncWrapper1D { public: - CoolPropDbl T, p, r, peos, rhomolar, rhor, tau, R_u, delta, dalphar_dDelta; + CoolPropDbl T, p, rhor, tau, R_u, delta; HelmholtzEOSMixtureBackend *HEOS; - solver_TP_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl T, CoolPropDbl p){ - this->HEOS = HEOS; this->T = T; this->p = p; this->rhor = HEOS->get_reducing_state().rhomolar; - this->tau = HEOS->get_reducing_state().T/T; this->R_u = HEOS->gas_constant(); - }; + solver_TP_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl T, CoolPropDbl p) + : HEOS(HEOS),T(T),p(p),delta(_HUGE),rhor(HEOS->get_reducing_state().rhomolar), + tau(HEOS->get_reducing_state().T/T),R_u(HEOS->gas_constant()){} double call(double rhomolar){ - this->rhomolar = rhomolar; delta = rhomolar/rhor; // needed for derivative HEOS->update_DmolarT_direct(rhomolar, T); - peos = HEOS->p(); - r = (peos-p)/p; - return r; + CoolPropDbl peos = HEOS->p(); + return (peos-p)/p; }; double deriv(double rhomolar){ // dp/drho|T / pspecified From 82ff4004c112647ad319917e19e0b62a21a6ca11 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 17:28:28 +1000 Subject: [PATCH 36/52] Fix Coverity CID 38570 --- src/Backends/Incompressible/IncompressibleFluid.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Backends/Incompressible/IncompressibleFluid.cpp b/src/Backends/Incompressible/IncompressibleFluid.cpp index 2705f00cf2..bf01599056 100644 --- a/src/Backends/Incompressible/IncompressibleFluid.cpp +++ b/src/Backends/Incompressible/IncompressibleFluid.cpp @@ -347,15 +347,11 @@ double IncompressibleFluid::T_rho (double Dmass, double p, double x){ switch (density.type) { case IncompressibleData::INCOMPRESSIBLE_POLYNOMIAL: return poly.solve_limits(density.coeffs, x, d_raw, Tmin, Tmax, 0, 0, 0, Tbase, xbase); - break; case IncompressibleData::INCOMPRESSIBLE_NOT_SET: throw ValueError(format("%s (%d): The function type is not specified (\"[%d]\"), are you sure the coefficients have been set?",__FILE__,__LINE__,specific_heat.type)); - break; default: throw ValueError(format("%s (%d): There is no predefined way to use this function type \"[%d]\" for inverse density.",__FILE__,__LINE__,specific_heat.type)); - break; } - return _HUGE; } /// Temperature as a function of heat capacities as a function of temperature, pressure and composition. double IncompressibleFluid::T_c (double Cmass, double p, double x){ From 993b684168c8327b0eeadf425895bf8b72f996a1 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 17:42:07 +1000 Subject: [PATCH 37/52] Fix Coverity CID 38568 --- include/CoolPropFluid.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/CoolPropFluid.h b/include/CoolPropFluid.h index c2897bd8a9..23fa0aebd1 100644 --- a/include/CoolPropFluid.h +++ b/include/CoolPropFluid.h @@ -300,13 +300,13 @@ class TransportPropertyData epsilon_over_k; ///< The Lennard-Jones 12-6 \f$ \varepsilon/k \f$ parameter ViscosityHardcodedEnum hardcoded_viscosity; ///< Hardcoded flags for the viscosity ConductivityHardcodedEnum hardcoded_conductivity; ///< Hardcoded flags for the conductivity - TransportPropertyData(){hardcoded_viscosity = VISCOSITY_NOT_HARDCODED; - hardcoded_conductivity = CONDUCTIVITY_NOT_HARDCODED; - viscosity_using_ECS = false; - conductivity_using_ECS = false; - viscosity_model_provided = false; - conductivity_model_provided = false; - }; + TransportPropertyData():hardcoded_viscosity(VISCOSITY_NOT_HARDCODED), + hardcoded_conductivity(CONDUCTIVITY_NOT_HARDCODED), + viscosity_using_ECS(false), + conductivity_using_ECS(false), + viscosity_model_provided(false), + conductivity_model_provided(false), + sigma_eta(_HUGE),epsilon_over_k(_HUGE){} }; struct Ancillaries From 16b13f3f0f0b48bae23ae0f3729645876176fe73 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 20:41:24 +1000 Subject: [PATCH 38/52] Fix Coverity CID 38567 Add some const methods to allow passing const ref --- include/CoolPropFluid.h | 3 +- .../Helmholtz/HelmholtzEOSMixtureBackend.h | 5 ++-- src/Backends/Helmholtz/VLERoutines.h | 28 ++++++++----------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/CoolPropFluid.h b/include/CoolPropFluid.h index 23fa0aebd1..e698f89921 100644 --- a/include/CoolPropFluid.h +++ b/include/CoolPropFluid.h @@ -454,7 +454,8 @@ class CoolPropFluid { public: CoolPropFluid():ECS_qd(-_HUGE){}; ~CoolPropFluid(){}; - EquationOfState &EOS() {return EOSVector[0];}; ///< Get a reference to the equation of state + const EquationOfState &EOS() const {return EOSVector[0];} ///< Get a reference to the equation of state + EquationOfState &EOS() {return EOSVector[0];} ///< Get a reference to the equation of state std::vector EOSVector; ///< The equations of state that could be used for this fluid std::string name; ///< The name of the fluid diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h index 18dae262c0..3e9edaebb0 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.h @@ -81,8 +81,9 @@ class HelmholtzEOSMixtureBackend : public AbstractState { const CoolProp::SimpleState &calc_state(const std::string &state); - std::vector &get_components(){return components;}; - std::vector &get_K(){return K;}; + const std::vector &get_components() const {return components;} + std::vector &get_components(){return components;} + std::vector &get_K(){ return K; }; std::vector &get_lnK(){return lnK;}; HelmholtzEOSMixtureBackend &get_SatL(){return *SatL;}; HelmholtzEOSMixtureBackend &get_SatV(){return *SatV;}; diff --git a/src/Backends/Helmholtz/VLERoutines.h b/src/Backends/Helmholtz/VLERoutines.h index 44b0f67959..e2cc824567 100644 --- a/src/Backends/Helmholtz/VLERoutines.h +++ b/src/Backends/Helmholtz/VLERoutines.h @@ -44,7 +44,7 @@ namespace SaturationSolvers @param p Pressure [Pa] @param i Index of component [-] */ - static CoolPropDbl Wilson_lnK_factor(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p, std::size_t i){ + static CoolPropDbl Wilson_lnK_factor(const HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p, std::size_t i){ const EquationOfState &EOS = HEOS.get_components()[i].EOS(); return log(EOS.reduce.p/p)+5.373*(1 + EOS.acentric)*(1-EOS.reduce.T/T); }; @@ -130,19 +130,13 @@ namespace SaturationSolvers public: int input_type; double T, p, beta; - const std::vector *z; - std::vector *K; - HelmholtzEOSMixtureBackend *HEOS; + const std::vector &z; + std::vector &K; + const HelmholtzEOSMixtureBackend &HEOS; - WilsonK_resid(HelmholtzEOSMixtureBackend &HEOS, double beta, double imposed_value, int input_type, const std::vector &z, std::vector &K){ - this->z = &z; this->K = &K; this->HEOS = &HEOS; this->beta = beta; this->input_type = input_type; - if (input_type == imposed_T){ - this->T = imposed_value; - } - else{ - this->p = imposed_value; - } - }; + WilsonK_resid(const HelmholtzEOSMixtureBackend &HEOS, double beta, double imposed_value, int input_type, const std::vector &z, std::vector &K) + : z(z), K(K), HEOS(HEOS), beta(beta), input_type(input_type), + T(imposed_value), p(imposed_value){} // if input_type == imposed_T -> use T, else use p; init both double call(double input_value){ double summer = 0; if (input_type == imposed_T){ @@ -151,12 +145,12 @@ namespace SaturationSolvers else{ T = input_value; // Iterate on temperature, pressure imposed } - for (unsigned int i = 0; i< (*z).size(); i++) { - (*K)[i] = exp(Wilson_lnK_factor(*HEOS,T,p,i)); - summer += (*z)[i]*((*K)[i]-1)/(1-beta+beta*(*K)[i]); + for (unsigned int i = 0; i< z.size(); i++) { + K[i] = exp(Wilson_lnK_factor(HEOS,T,p,i)); + summer += z[i]*(K[i]-1)/(1-beta+beta*K[i]); } return summer; - }; + } }; inline double saturation_preconditioner(HelmholtzEOSMixtureBackend &HEOS, double input_value, int input_type, const std::vector &z) { From c99805cc79fbe466c69dbc0e76d81759dc8d58ba Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sat, 7 Mar 2015 23:04:07 +1000 Subject: [PATCH 39/52] Fix Coverity CID 38566 --- src/HumidAirProp.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index 237d27bd24..b51c4f769d 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -1013,19 +1013,16 @@ double DewpointTemperature(double T, double p, double psi_w) class WetBulbSolver : public CoolProp::FuncWrapper1D { private: - double _T,_p,_W,LHS,RHS,v_bar_w,M_ha; + double _p,_W,LHS; public: - WetBulbSolver(double T, double p, double psi_w){ - _T = T; - _p = p; - _W = epsilon*psi_w/(1-psi_w); - + WetBulbSolver(double T, double p, double psi_w) + : _p(p),_W(epsilon*psi_w/(1-psi_w)) + { //These things are all not a function of Twb - v_bar_w = MolarVolume(T,p,psi_w); - M_ha = MM_Water()*psi_w+(1-psi_w)*0.028966; + double v_bar_w = MolarVolume(T,p,psi_w), + M_ha = MM_Water()*psi_w+(1-psi_w)*0.028966; LHS = MolarEnthalpy(T,p,psi_w,v_bar_w)*(1+_W)/M_ha; - }; - ~WetBulbSolver(){}; + } double call(double Twb) { double epsilon=0.621945; @@ -1066,7 +1063,7 @@ class WetBulbSolver : public CoolProp::FuncWrapper1D M_ha_wb = MM_Water()*psi_wb+(1-psi_wb)*0.028966; v_bar_wb=MolarVolume(Twb,_p,psi_wb); - RHS = (MolarEnthalpy(Twb,_p,psi_wb,v_bar_wb)*(1+W_s_wb)/M_ha_wb+(_W-W_s_wb)*h_w); + double RHS = (MolarEnthalpy(Twb,_p,psi_wb,v_bar_wb)*(1+W_s_wb)/M_ha_wb+(_W-W_s_wb)*h_w); if (!ValidNumber(LHS-RHS)){throw CoolProp::ValueError();} return LHS - RHS; } From 60b6bfca0d1c99505fd577d17ce9813f80b4046e Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sun, 8 Mar 2015 11:11:10 +1000 Subject: [PATCH 40/52] Fix Coverity CID 38565 --- include/Ancillaries.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Ancillaries.h b/include/Ancillaries.h index 9c04d7525a..fb5fd617ea 100644 --- a/include/Ancillaries.h +++ b/include/Ancillaries.h @@ -30,7 +30,7 @@ class SurfaceTensionCorrelation std::size_t N; std::string BibTeX; - SurfaceTensionCorrelation(){}; + SurfaceTensionCorrelation():Tc(_HUGE),N(0){} SurfaceTensionCorrelation(rapidjson::Value &json_code) { a = cpjson::get_long_double_array(json_code["a"]); From a0f5c37d146dac4e2b071fd84eca618692b1b5fb Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sun, 8 Mar 2015 23:27:29 +1000 Subject: [PATCH 41/52] Fix Coverity CID 38564 --- src/Backends/Helmholtz/FlashRoutines.cpp | 33 +++++++++++------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 98dc697810..406e1e842e 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -972,45 +972,42 @@ void FlashRoutines::HSU_P_flash_singlephase_Brent(HelmholtzEOSMixtureBackend &HE public: HelmholtzEOSMixtureBackend *HEOS; - CoolPropDbl r, eos, p, value, T, rhomolar; + CoolPropDbl p, value; int other; int iter; - CoolPropDbl r0, r1, T1, T0, eos0, eos1, pp; + CoolPropDbl eos0, eos1; solver_resid(HelmholtzEOSMixtureBackend *HEOS, CoolPropDbl p, CoolPropDbl value, int other) : - HEOS(HEOS), p(p), value(value), other(other) + HEOS(HEOS), p(p), value(value), other(other), iter(0), eos0(-_HUGE), eos1(-_HUGE) { - iter = 0; // Specify the state to avoid saturation calls, but only if phase is subcritical - if (HEOS->phase() == iphase_liquid || HEOS->phase() == iphase_gas ){ - HEOS->specify_phase(HEOS->phase()); + switch (CoolProp::phases phase = HEOS->phase()) { + case iphase_liquid: case iphase_gas: + HEOS->specify_phase(phase); } - }; + } double call(double T){ - this->T = T; - // Run the solver with T,P as inputs; HEOS->update(PT_INPUTS, p, T); - rhomolar = HEOS->rhomolar(); + CoolPropDbl rhomolar = HEOS->rhomolar(); HEOS->update(DmolarT_INPUTS, rhomolar, T); // Get the value of the desired variable - eos = HEOS->keyed_output(other); - pp = HEOS->p(); + CoolPropDbl eos = HEOS->keyed_output(other); // Difference between the two is to be driven to zero - r = eos - value; - + CoolPropDbl r = eos - value; + // Store values for later use if there are errors if (iter == 0){ - r0 = r; T0 = T; eos0 = eos; + eos0 = eos; } else if (iter == 1){ - r1 = r; T1 = T; eos1 = eos; + eos1 = eos; } else{ - r0 = r1; T0 = T1; eos0 = eos1; - r1 = r; T1 = T; eos1 = eos; + eos0 = eos1; + eos1 = eos; } iter++; From 3a201ca7ded07f13bcbd4a17a23915b926e0581a Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sun, 8 Mar 2015 23:41:40 +1000 Subject: [PATCH 42/52] Fix Coverity CID 38531 @ibell: still, there's possibly need to sanitize the imax range adjustment --- src/Backends/Helmholtz/FlashRoutines.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.cpp b/src/Backends/Helmholtz/FlashRoutines.cpp index 406e1e842e..9c7f7f4ab9 100644 --- a/src/Backends/Helmholtz/FlashRoutines.cpp +++ b/src/Backends/Helmholtz/FlashRoutines.cpp @@ -484,7 +484,11 @@ void FlashRoutines::PT_Q_flash_mixtures(HelmholtzEOSMixtureBackend &HEOS, parame // Shift the solution if needed to ensure that imax+2 and imax-1 are both in range if (imax+2 >= env.T.size()){ imax--; } - else if (imax-1 < 0){ imax++; } + else if (imax == 0){ imax++; } + // Here imax+2 or imax-1 is still possibly out of range: + // 1. If imax initially is 1, and env.T.size() <= 3, then imax will become 0. + // 2. If imax initially is 0, and env.T.size() <= 2, then imax will become MAX_UINT. + // 3. If imax+2 initially is more than env.T.size(), then single decrement will not bring it to range SaturationSolvers::newton_raphson_saturation NR; SaturationSolvers::newton_raphson_saturation_options IO; From 6498bb002a33debd24c2d805dc355eb6fdb39188 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sun, 8 Mar 2015 23:47:27 +1000 Subject: [PATCH 43/52] Fix Coverity CID 38530 A real error --- src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 76c3cfb145..6a38ccfbb5 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1407,6 +1407,7 @@ void HelmholtzEOSMixtureBackend::T_phase_determination_pure_or_pseudopure(int ot else if (value < SatL->calc_hmolar()){ this->_phase = iphase_liquid; return; } + break; } case iUmolar: { From cc0dc74f5ad61ba391a889625416ecde86785ccd Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Sun, 8 Mar 2015 23:53:59 +1000 Subject: [PATCH 44/52] Fix Coverity CID 38528 iter cannot ever become greater than 100; useless check --- src/HumidAirProp.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index b51c4f769d..ab848d6f57 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -909,7 +909,6 @@ double MolarEntropy(double T, double p, double psi_w, double v_bar) y1=y2; x1=x2; x2=x3; } iter=iter+1; - if (iter>100){ return _HUGE; } } if (FlagUseIdealGasEnthalpyCorrelations){ From 99f17f0a38ba78ed5f088907a4daec69c22211bb Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 11:41:18 +1000 Subject: [PATCH 45/52] Fix Coverity CID 38620 --- src/PolyMath.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PolyMath.cpp b/src/PolyMath.cpp index 674a78d4f6..3c7d3c1424 100644 --- a/src/PolyMath.cpp +++ b/src/PolyMath.cpp @@ -472,22 +472,21 @@ double Polynomial2DFrac::evaluate(const Eigen::MatrixXd &coefficients, const dou double posExp = 0;// then the positive exponents for(int i=0; i>firstExponent; i--) { // only for firstExponent<0 - c=tmpCoeffs.cols(); if (c>0) { negExp += tmpCoeffs(0,0); removeColumn(tmpCoeffs, 0); } negExp /= x_in-x_base; + c=tmpCoeffs.cols(); } for(int i=0; i0 - c = tmpCoeffs.cols(); newCoeffs = Eigen::MatrixXd::Zero(r,c+1); newCoeffs.block(0,1,r,c) = tmpCoeffs.block(0,0,r,c); tmpCoeffs = Eigen::MatrixXd(newCoeffs); + c = tmpCoeffs.cols(); } - c = tmpCoeffs.cols(); if (c>0) posExp += Eigen::poly_eval( Eigen::RowVectorXd(tmpCoeffs), x_in-x_base ); return negExp+posExp; } From 9db00ac550a2c87217c8eb2e1806bb12f5c75b50 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 11:54:48 +1000 Subject: [PATCH 46/52] Revert "Fix Coverity CID 38598" This reverts commit bdeb976f89cf4d9c90803d48303dff1e705ad543. --- src/Backends/Helmholtz/FlashRoutines.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index 27fc6ef375..208512168f 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -125,22 +125,25 @@ class FlashRoutines{ class solver_TP_resid : public FuncWrapper1D { public: - CoolPropDbl T, p, rhor, tau, R_u; + CoolPropDbl T, p, r, peos, rhomolar, rhor, tau, R_u, delta, dalphar_dDelta; HelmholtzEOSMixtureBackend *HEOS; - solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p): - HEOS(&HEOS),T(T),p(p),rhor(HEOS.get_reducing_state().rhomolar), - tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()) {} + solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p){ + this->HEOS = &HEOS; this->T = T; this->p = p; this->rhor = HEOS.get_reducing_state().rhomolar; + this->tau = HEOS.get_reducing_state().T/T; this->R_u = HEOS.gas_constant(); + }; double call(double rhomolar){ -// CoolPropDbl delta = rhomolar/rhor; // needed for derivative + this->rhomolar = rhomolar; + delta = rhomolar/rhor; // needed for derivative HEOS->update_DmolarT_direct(rhomolar, T); - CoolPropDbl peos = HEOS->p(); - return (peos-p)/p; + peos = HEOS->p(); + r = (peos-p)/p; + return r; }; -/* double deriv(double rhomolar){ + double deriv(double rhomolar){ // dp/drho|T / pspecified return R_u*T*(1+2*delta*HEOS->dalphar_dDelta()+pow(delta, 2)*HEOS->d2alphar_dDelta2())/p; - };*/ + }; }; /** A residual function for the f(P, Y) solver From e2685a22ba850507c42ba2848d6e62768d360850 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 12:03:46 +1000 Subject: [PATCH 47/52] Fix Coverity CID 38598 (for real) Proper fix; retains deriv (replaces bdeb976f89cf4d9c90803d48303dff1e705ad543) --- src/Backends/Helmholtz/FlashRoutines.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index 208512168f..f9b3b0bb57 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -125,20 +125,17 @@ class FlashRoutines{ class solver_TP_resid : public FuncWrapper1D { public: - CoolPropDbl T, p, r, peos, rhomolar, rhor, tau, R_u, delta, dalphar_dDelta; + CoolPropDbl T, p, rhor, tau, R_u, delta; HelmholtzEOSMixtureBackend *HEOS; - solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p){ - this->HEOS = &HEOS; this->T = T; this->p = p; this->rhor = HEOS.get_reducing_state().rhomolar; - this->tau = HEOS.get_reducing_state().T/T; this->R_u = HEOS.gas_constant(); - }; + solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p): + HEOS(&HEOS),T(T),p(p),rhor(HEOS.get_reducing_state().rhomolar), + tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()) {} double call(double rhomolar){ - this->rhomolar = rhomolar; delta = rhomolar/rhor; // needed for derivative HEOS->update_DmolarT_direct(rhomolar, T); - peos = HEOS->p(); - r = (peos-p)/p; - return r; + CoolPropDbl peos = HEOS->p(); + return (peos-p)/p; }; double deriv(double rhomolar){ // dp/drho|T / pspecified From fcd330e557836ac9c39ed680f93f26ee32e2b954 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 12:11:31 +1000 Subject: [PATCH 48/52] Leftover for CID 38598 --- src/Backends/Helmholtz/FlashRoutines.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index f9b3b0bb57..d471f203c3 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -130,7 +130,7 @@ class solver_TP_resid : public FuncWrapper1D solver_TP_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl T, CoolPropDbl p): HEOS(&HEOS),T(T),p(p),rhor(HEOS.get_reducing_state().rhomolar), - tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()) {} + tau(HEOS.get_reducing_state().T/T),R_u(HEOS.gas_constant()),delta(-_HUGE) {} double call(double rhomolar){ delta = rhomolar/rhor; // needed for derivative HEOS->update_DmolarT_direct(rhomolar, T); From 9d9be5e64148ebda09d631f877feb3c6c03b27b1 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 12:17:20 +1000 Subject: [PATCH 49/52] Fix Coverity CID 38563 --- src/HumidAirProp.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/HumidAirProp.cpp b/src/HumidAirProp.cpp index ab848d6f57..c915be9be0 100644 --- a/src/HumidAirProp.cpp +++ b/src/HumidAirProp.cpp @@ -231,7 +231,7 @@ static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) class BrentSolverResids : public CoolProp::FuncWrapper1D { private: - double pp_water, psi_w, p, r; + double pp_water, psi_w, p; public: BrentSolverResids(double psi_w, double p) : psi_w(psi_w), p(p) { pp_water = psi_w*p; }; ~BrentSolverResids(){}; @@ -250,8 +250,7 @@ static double Secant_Tdb_at_saturated_W(double psi_w, double p, double T_guess) double f = f_factor(T, p); double pp_water_calc = f*p_ws; double psi_w_calc = pp_water_calc/p; - r = (psi_w_calc - psi_w)/psi_w; - return r; + return (psi_w_calc - psi_w)/psi_w; } }; From d470157314ca82611a6352d21025fae34c5c5d2a Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 13:38:49 +1000 Subject: [PATCH 50/52] Refactor solver function interfaces, to allow more verbose requirements for deriv --- include/PolyMath.h | 2 +- include/Solvers.h | 27 +++++++++++++------ src/Backends/Helmholtz/FlashRoutines.h | 2 +- .../Helmholtz/HelmholtzEOSMixtureBackend.cpp | 2 +- src/Solvers.cpp | 16 +---------- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/PolyMath.h b/include/PolyMath.h index 20edc08dc7..77baa2d981 100644 --- a/include/PolyMath.h +++ b/include/PolyMath.h @@ -164,7 +164,7 @@ class Polynomial2D { }; -class Poly2DResidual : public FuncWrapper1D { +class Poly2DResidual : public FuncWrapper1DWithDeriv { protected: enum dims {iX, iY}; Eigen::MatrixXd coefficients; diff --git a/include/Solvers.h b/include/Solvers.h index 61c011b6e9..d521318adb 100644 --- a/include/Solvers.h +++ b/include/Solvers.h @@ -11,10 +11,14 @@ namespace CoolProp class FuncWrapper1D { public: - FuncWrapper1D(){}; virtual ~FuncWrapper1D(){}; virtual double call(double) = 0; - virtual double deriv(double){throw NotImplementedError("deriv function not implemented");}; +}; + +class FuncWrapper1DWithDeriv : public FuncWrapper1D +{ +public: + virtual double deriv(double) = 0; }; class FuncWrapperND @@ -30,14 +34,21 @@ class FuncWrapperND double Brent(FuncWrapper1D* f, double a, double b, double macheps, double t, int maxiter, std::string &errstr); double Secant(FuncWrapper1D* f, double x0, double dx, double ftol, int maxiter, std::string &errstring); double BoundedSecant(FuncWrapper1D* f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter, std::string &errstring); -double Newton(FuncWrapper1D* f, double x0, double ftol, int maxiter, std::string &errstring); +double Newton(FuncWrapper1DWithDeriv* f, double x0, double ftol, int maxiter, std::string &errstring); // Single-Dimensional solvers -double Brent(FuncWrapper1D &f, double a, double b, double macheps, double t, int maxiter, std::string &errstr); -double Secant(FuncWrapper1D &f, double x0, double dx, double ftol, int maxiter, std::string &errstring); -double BoundedSecant(FuncWrapper1D &f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter, std::string &errstring); -double Newton(FuncWrapper1D &f, double x0, double ftol, int maxiter, std::string &errstring); - +inline double Brent(FuncWrapper1D &f, double a, double b, double macheps, double t, int maxiter, std::string &errstr){ + return Brent(&f, a, b, macheps, t, maxiter, errstr); +} +inline double Secant(FuncWrapper1D &f, double x0, double dx, double ftol, int maxiter, std::string &errstring){ + return Secant(&f, x0, dx, ftol, maxiter, errstring); +} +inline double BoundedSecant(FuncWrapper1D &f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter, std::string &errstring){ + return BoundedSecant(&f, x0, xmin, xmax, dx, ftol, maxiter, errstring); +} +inline double Newton(FuncWrapper1DWithDeriv &f, double x0, double ftol, int maxiter, std::string &errstring){ + return Newton(&f, x0, ftol, maxiter, errstring); +} // Multi-Dimensional solvers std::vector NDNewtonRaphson_Jacobian(FuncWrapperND *f, const std::vector &x0, double tol, int maxiter, std::string *errstring); diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index d471f203c3..d28e303925 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -122,7 +122,7 @@ class FlashRoutines{ /** A residual function for the rho(T,P) solver */ -class solver_TP_resid : public FuncWrapper1D +class solver_TP_resid : public FuncWrapper1DWithDeriv { public: CoolPropDbl T, p, rhor, tau, R_u, delta; diff --git a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp index 6a38ccfbb5..5588cfc77a 100644 --- a/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp +++ b/src/Backends/Helmholtz/HelmholtzEOSMixtureBackend.cpp @@ -1795,7 +1795,7 @@ CoolPropDbl HelmholtzEOSMixtureBackend::solver_rho_Tp(CoolPropDbl T, CoolPropDbl phases phase; // Define the residual to be driven to zero - class solver_TP_resid : public FuncWrapper1D + class solver_TP_resid : public FuncWrapper1DWithDeriv { public: CoolPropDbl T, p, rhor, tau, R_u, delta; diff --git a/src/Solvers.cpp b/src/Solvers.cpp index cd5230c037..9e3715555b 100644 --- a/src/Solvers.cpp +++ b/src/Solvers.cpp @@ -86,7 +86,7 @@ In the newton function, a 1-D Newton-Raphson solver is implemented using exact s @param errstring A pointer to the std::string that returns the error from Secant. Length is zero if no errors are found @returns If no errors are found, the solution, otherwise the value _HUGE, the value for infinity */ -double Newton(FuncWrapper1D* f, double x0, double ftol, int maxiter, std::string &errstring) +double Newton(FuncWrapper1DWithDeriv* f, double x0, double ftol, int maxiter, std::string &errstring) { double x, dx, fval=999; int iter=1; @@ -382,18 +382,4 @@ double Brent(FuncWrapper1D* f, double a, double b, double macheps, double t, int return b; } -// Single-Dimensional solvers -double Brent(FuncWrapper1D &f, double a, double b, double macheps, double t, int maxiter, std::string &errstr){ - return Brent(&f, a, b, macheps, t, maxiter, errstr); -} -double Secant(FuncWrapper1D &f, double x0, double dx, double ftol, int maxiter, std::string &errstring){ - return Secant(&f, x0, dx, ftol, maxiter, errstring); -} -double BoundedSecant(FuncWrapper1D &f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter, std::string &errstring){ - return BoundedSecant(&f, x0, xmin, xmax, dx, ftol, maxiter, errstring); -} -double Newton(FuncWrapper1D &f, double x0, double ftol, int maxiter, std::string &errstring){ - return Newton(&f, x0, ftol, maxiter, errstring); -} - }; /* namespace CoolProp */ From 746f56a53aaf601894090f4807aab61818ad87e7 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 14:07:58 +1000 Subject: [PATCH 51/52] Remove MSVC warnings on msgpack --- include/CPmsgpack.h | 11 +++++++++++ src/Backends/Tabular/TabularBackends.h | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 include/CPmsgpack.h diff --git a/include/CPmsgpack.h b/include/CPmsgpack.h new file mode 100644 index 0000000000..3eab99090c --- /dev/null +++ b/include/CPmsgpack.h @@ -0,0 +1,11 @@ +// Workaround MSVC warnings +#ifdef _MSC_VER + #pragma warning(push) + #pragma warning(disable:4267) +#endif + +#include "msgpack.hpp" + +#ifdef _MSC_VER + #pragma warning(pop) +#endif diff --git a/src/Backends/Tabular/TabularBackends.h b/src/Backends/Tabular/TabularBackends.h index 42fef8ebef..4a3372b4b3 100644 --- a/src/Backends/Tabular/TabularBackends.h +++ b/src/Backends/Tabular/TabularBackends.h @@ -2,7 +2,7 @@ #define TABULAR_BACKENDS_H #include "AbstractState.h" -#include "msgpack.hpp" +#include "CPmsgpack.h" #include #include "crossplatform_shared_ptr.h" #include "Exceptions.h" From 3fcca0198c40bd272738f96bca6b8086d0d80d98 Mon Sep 17 00:00:00 2001 From: mikekaganski Date: Mon, 9 Mar 2015 15:05:20 +1000 Subject: [PATCH 52/52] Fix Coverity CID 38562 --- src/Backends/Helmholtz/FlashRoutines.h | 30 ++++---------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/src/Backends/Helmholtz/FlashRoutines.h b/src/Backends/Helmholtz/FlashRoutines.h index d28e303925..d3750b6d26 100644 --- a/src/Backends/Helmholtz/FlashRoutines.h +++ b/src/Backends/Helmholtz/FlashRoutines.h @@ -152,14 +152,10 @@ class PY_singlephase_flash_resid : public FuncWrapper1D HelmholtzEOSMixtureBackend *HEOS; CoolPropDbl p; parameters other; - CoolPropDbl r, eos, value, T, rhomolar; - - int iter; - CoolPropDbl r0, r1, T1, T0, eos0, eos1, pp; + CoolPropDbl value; PY_singlephase_flash_resid(HelmholtzEOSMixtureBackend &HEOS, CoolPropDbl p, parameters other, CoolPropDbl value) : HEOS(&HEOS), p(p), other(other), value(value) { - iter = 0; // Specify the state to avoid saturation calls, but only if phase is subcritical if (HEOS.phase() == iphase_liquid || HEOS.phase() == iphase_gas ){ HEOS.specify_phase(HEOS.phase()); @@ -167,34 +163,16 @@ class PY_singlephase_flash_resid : public FuncWrapper1D }; double call(double T){ - this->T = T; - // Run the solver with T,P as inputs; HEOS->update(PT_INPUTS, p, T); - rhomolar = HEOS->rhomolar(); + CoolPropDbl rhomolar = HEOS->rhomolar(); HEOS->update(DmolarT_INPUTS, rhomolar, T); // Get the value of the desired variable - eos = HEOS->keyed_output(other); - pp = HEOS->p(); + CoolPropDbl eos = HEOS->keyed_output(other); // Difference between the two is to be driven to zero - r = eos - value; - - // Store values for later use if there are errors - if (iter == 0){ - r0 = r; T0 = T; eos0 = eos; - } - else if (iter == 1){ - r1 = r; T1 = T; eos1 = eos; - } - else{ - r0 = r1; T0 = T1; eos0 = eos1; - r1 = r; T1 = T; eos1 = eos; - } - - iter++; - return r; + return eos - value; }; };