Fix transport properties for bicubic and TTSE; closes #520

Also implement PQ inputs
This commit is contained in:
Ian Bell
2015-03-15 00:45:20 -06:00
parent f0a40f3bcc
commit 091cc43f27
5 changed files with 44 additions and 8 deletions

View File

@@ -213,6 +213,20 @@ void CoolProp::BicubicBackend::update(CoolProp::input_pairs input_pair, double v
}
break;
}
case PQ_INPUTS:{
std::size_t iL = 0, iV = 0;
CoolPropDbl hL = 0, hV = 0;
_p = val1; _Q = val2;
pure_saturation.is_inside(_p, iQ, _Q, iL, iV, hL, hV);
using_single_phase_table = false;
if(!is_in_closed_range(0.0,1.0,static_cast<double>(_Q))){
throw ValueError("vapor quality is not in (0,1)");
}
else{
cached_saturation_iL = iL; cached_saturation_iV = iV;
}
break;
}
default:
throw ValueError("input pair is not currently supported");
}

View File

@@ -136,12 +136,12 @@ class BicubicBackend : public TabularBackend
double evaluate_single_phase_pT(parameters output, std::size_t i, std::size_t j){
return evaluate_single_phase(single_phase_logpT, coeffs_pT, output, _T, _p, i, j);
};
double evaluate_single_phase_pT_transport(parameters output, std::size_t i, std::size_t j){
return evaluate_single_phase_transport(single_phase_logpT, output, _T, _p, i, j);
}
double evaluate_single_phase_phmolar_transport(parameters output, std::size_t i, std::size_t j){
return evaluate_single_phase_transport(single_phase_logph, output, _T, _p, i, j);
}
return evaluate_single_phase_transport(single_phase_logph, output, _hmolar, _p, i, j);
};
double evaluate_single_phase_pT_transport(parameters output, std::size_t i, std::size_t j){
return evaluate_single_phase_transport(single_phase_logpT, output, _T, _p, i, j);
};
};
double do_one();

View File

@@ -112,7 +112,7 @@ double CoolProp::TTSEBackend::evaluate_single_phase_transport(SinglePhaseGridded
}
double x1 = table.xvec[i], x2 = table.xvec[i+1], y1 = table.yvec[j], y2 = table.yvec[j+1];
double f11 = (*f)[i][j], f12 = (*f)[i][j+1], f21 = (*f)[i+1][j], f22 = (*f)[i+1][j+1];
double val = 1/((x2-x1)*(y2-y1))*( f11*(x2- x1)*(y2 - y)
double val = 1/((x2-x1)*(y2-y1))*( f11*(x2 - x)*(y2 - y)
+f21*(x - x1)*(y2 - y)
+f12*(x2 - x)*(y - y1)
+f22*(x - x1)*(y - y1));

View File

@@ -105,6 +105,8 @@ void CoolProp::PureFluidSaturationTableData::build(shared_ptr<CoolProp::Abstract
pL[i] = p; TL[i] = AS->T(); rhomolarL[i] = AS->rhomolar();
hmolarL[i] = AS->hmolar(); smolarL[i] = AS->smolar(); umolarL[i] = AS->umolar();
logpL[i] = log(p); logrhomolarL[i] = log(rhomolarL[i]);
viscL[i] = AS->viscosity(); condL[i] = AS->conductivity();
logviscL[i] = log(viscL[i]);
}
catch(std::exception &e){
// That failed for some reason, go to the next pair
@@ -117,6 +119,8 @@ void CoolProp::PureFluidSaturationTableData::build(shared_ptr<CoolProp::Abstract
pV[i] = p; TV[i] = AS->T(); rhomolarV[i] = AS->rhomolar();
hmolarV[i] = AS->hmolar(); smolarV[i] = AS->smolar(); umolarV[i] = AS->umolar();
logpV[i] = log(p); logrhomolarV[i] = log(rhomolarV[i]);
viscV[i] = AS->viscosity(); condV[i] = AS->conductivity();
logviscV[i] = log(viscV[i]);
}
catch(std::exception &e){
// That failed for some reason, go to the next pair

View File

@@ -21,7 +21,7 @@
* See http://stackoverflow.com/a/148610
* See http://stackoverflow.com/questions/147267/easy-way-to-use-variables-of-enum-types-as-string-in-c#202511
*/
#define LIST_OF_SATURATION_VECTORS X(TL) X(pL) X(logpL) X(hmolarL) X(smolarL) X(umolarL) X(rhomolarL) X(logrhomolarL) X(TV) X(pV) X(logpV) X(hmolarV) X(smolarV) X(umolarV) X(rhomolarV) X(logrhomolarV)
#define LIST_OF_SATURATION_VECTORS X(TL) X(pL) X(logpL) X(hmolarL) X(smolarL) X(umolarL) X(rhomolarL) X(logrhomolarL) X(viscL) X(condL) X(logviscL) X(TV) X(pV) X(logpV) X(hmolarV) X(smolarV) X(umolarV) X(rhomolarV) X(logrhomolarV) X(viscV) X(condV) X(logviscV)
namespace CoolProp{
@@ -58,7 +58,7 @@ class PureFluidSaturationTableData{
switch(other){
case iT: yvecL = &TL; yvecV = &TV; break;
case iHmolar: yvecL = &hmolarL; yvecV = &hmolarV; break;
//case iT: yvecL = &TL; yvecV = &TV; break;
case iQ: yvecL = &TL; yvecV = &TV; break;
//case iT: yvecL = &TL; yvecV = &TV; break;
default: throw ValueError("invalid input for other in is_inside");
}
@@ -69,6 +69,7 @@ class PureFluidSaturationTableData{
// be different
bisect_vector(pV, p, iV);
bisect_vector(pL, p, iL);
if (other == iQ){return true;}
iVplus = std::min(iV+1, N-1);
iLplus = std::min(iL+1, N-1);
// Find the bounding values for the other variable
@@ -164,6 +165,23 @@ class PureFluidSaturationTableData{
if (!ValidNumber(rhoL)){throw ValueError("rhoL is invalid");}
return 1/(Q/rhoV + (1-Q)/rhoL);
}
case iconductivity:
{
double kV = CubicInterp(logpV, condV, iV-2, iV-1, iV, iV+1, logp);
double kL = CubicInterp(logpL, condL, iL-2, iL-1, iL, iL+1, logp);
if (!ValidNumber(kV)){throw ValueError("kV is invalid");}
if (!ValidNumber(kL)){throw ValueError("kL is invalid");}
return Q*kV + (1-Q)*kL;
}
case iviscosity:
{
double muV = exp(CubicInterp(logpV, logviscV, iV-2, iV-1, iV, iV+1, logp));
double muL = exp(CubicInterp(logpL, logviscL, iL-2, iL-1, iL, iL+1, logp));
if (!ValidNumber(muV)){throw ValueError("muV is invalid");}
if (!ValidNumber(muL)){throw ValueError("muL is invalid");}
return 1/(Q/muV + (1-Q)/muL);
}
default:
throw ValueError("can't be something other than T or rho");
}