A fix for Coverity CIDs 38532 & 38536

@ibell: I'm afraid here is some not finished function. It deliberately
treats its input as T, regardless of ykey actual value; it defined r (I
commented it out) but used p as return value. It makes some
calculations, but they seem to be useless, as only p matters. (I'm not
sure if there's some side effects of those calls, though.)
I cleaned it up a bit, to make it more transparent. Please take a look.
This commit is contained in:
mikekaganski
2015-03-09 22:12:32 +10:00
parent 72f1bd2c5c
commit 84bd9b9dc9

View File

@@ -32,37 +32,38 @@ void SaturationSolvers::saturation_critical(HelmholtzEOSMixtureBackend &HEOS, pa
HelmholtzEOSMixtureBackend *HEOS;
parameters ykey;
CoolPropDbl y;
CoolPropDbl r, T, rhomolar_liq, rhomolar_vap, value, p, gL, gV, rhomolar_crit;
int other;
CoolPropDbl rhomolar_crit;
outer_resid(HelmholtzEOSMixtureBackend &HEOS, CoolProp::parameters ykey, CoolPropDbl y)
: HEOS(&HEOS), ykey(ykey), y(y){
rhomolar_crit = HEOS.rhomolar_critical();
};
: HEOS(&HEOS), ykey(ykey), y(y), rhomolar_crit(HEOS.rhomolar_critical()) {};
double call(double rhomolar_vap){
this->y = y;
// Calculate the other variable (T->p or p->T) for given vapor density
if (ykey == iT){
CoolPropDbl T, p, rhomolar_liq;
switch (ykey){
case iT: {
T = y;
HEOS->SatV->update(DmolarT_INPUTS, rhomolar_vap, y);
this->p = HEOS->SatV->p();
std::cout << format("outer p: %0.16Lg",this->p) << std::endl;
p = HEOS->SatV->p();
std::cout << format("outer p: %0.16Lg", p) << std::endl;
inner_resid inner(HEOS, T, p);
std::string errstr2;
rhomolar_liq = Brent(inner, rhomolar_crit*1.5, rhomolar_crit*(1+1e-8), LDBL_EPSILON, 1e-10, 100, errstr2);
rhomolar_liq = Brent(inner, rhomolar_crit*1.5, rhomolar_crit*(1 + 1e-8), LDBL_EPSILON, 1e-10, 100, errstr2);
break;
}
default:
throw ValueError("Wrong input for outer_resid");
}
HEOS->SatL->update(DmolarT_INPUTS, rhomolar_liq, T);
HEOS->SatV->update(DmolarT_INPUTS, rhomolar_vap, T);
// Calculate the Gibbs functions for liquid and vapor
gL = HEOS->SatL->gibbsmolar();
gV = HEOS->SatV->gibbsmolar();
CoolPropDbl gL = HEOS->SatL->gibbsmolar();
CoolPropDbl gV = HEOS->SatV->gibbsmolar();
// Residual is difference in Gibbs function
r = gL - gV;
// r = gL - gV;
return this->p;
return p;
};
};
outer_resid resid(HEOS, iT, y);