mirror of
https://github.com/CoolProp/CoolProp.git
synced 2026-01-23 12:58:03 -05:00
Refactor saturation TTSE and allow for more outputs
Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
This commit is contained in:
@@ -20,35 +20,12 @@ class TTSEBackend : public TabularBackend
|
||||
TTSEBackend(shared_ptr<CoolProp::AbstractState> AS) : TabularBackend (AS) {}
|
||||
void update(CoolProp::input_pairs input_pair, double val1, double val2);
|
||||
double evaluate_single_phase_hmolarp(parameters output, std::size_t i, std::size_t j);
|
||||
double evaluate_saturation(parameters output)
|
||||
{
|
||||
std::size_t iL = cached_saturation_iL, iV = cached_saturation_iV;
|
||||
double logp = log(_p);
|
||||
switch(output){
|
||||
case iT:
|
||||
{
|
||||
double TV = CubicInterp(pure_saturation.logpV, pure_saturation.TV, iV-2, iV-1, iV, iV+1, logp);
|
||||
double TL = CubicInterp(pure_saturation.logpL, pure_saturation.TL, iL-2, iL-1, iL, iL+1, logp);
|
||||
return _Q*TV + (1-_Q)*TL;
|
||||
}
|
||||
case iDmolar:
|
||||
{
|
||||
double rhoV = exp(CubicInterp(pure_saturation.logpV, pure_saturation.logrhomolarV, iV-2, iV-1, iV, iV+1, logp));
|
||||
double rhoL = exp(CubicInterp(pure_saturation.logpL, pure_saturation.logrhomolarL, iL-2, iL-1, iL, iL+1, logp));
|
||||
if (!ValidNumber(rhoV)){throw ValueError("rhoV is invalid");}
|
||||
if (!ValidNumber(rhoL)){throw ValueError("rhoL is invalid");}
|
||||
return 1/(_Q/rhoV + (1-_Q)/rhoL);
|
||||
}
|
||||
default:
|
||||
throw ValueError("can't be something other than T or rho");
|
||||
}
|
||||
}
|
||||
long double calc_T(void){
|
||||
if (using_single_phase_table){
|
||||
return evaluate_single_phase_hmolarp(iT, cached_single_phase_i, cached_single_phase_j);
|
||||
}
|
||||
else{
|
||||
return evaluate_saturation(iT);
|
||||
return pure_saturation.evaluate(iT, _p, _Q, cached_saturation_iL, cached_saturation_iV);
|
||||
}
|
||||
}
|
||||
long double calc_rhomolar(void){
|
||||
@@ -56,7 +33,7 @@ class TTSEBackend : public TabularBackend
|
||||
return evaluate_single_phase_hmolarp(iDmolar, cached_single_phase_i, cached_single_phase_j);
|
||||
}
|
||||
else{
|
||||
return evaluate_saturation(iDmolar);
|
||||
return pure_saturation.evaluate(iDmolar, _p, _Q, cached_saturation_iL, cached_saturation_iV);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -183,6 +183,40 @@ class PureFluidSaturationTableData{
|
||||
std::swap(*this, temp); // Swap
|
||||
this->AS = temp.AS; // Reconnect the AbstractState pointer
|
||||
};
|
||||
double evaluate(parameters output, double p, double Q, std::size_t iL, std::size_t iV)
|
||||
{
|
||||
double logp = log(p);
|
||||
switch(output){
|
||||
case iT:
|
||||
{
|
||||
double TV = CubicInterp(logpV, this->TV, iV-2, iV-1, iV, iV+1, logp);
|
||||
double TL = CubicInterp(logpL, this->TL, iL-2, iL-1, iL, iL+1, logp);
|
||||
return Q*TV + (1-Q)*TL;
|
||||
}
|
||||
case iSmolar:
|
||||
{
|
||||
double sV = CubicInterp(logpV, smolarV, iV-2, iV-1, iV, iV+1, logp);
|
||||
double sL = CubicInterp(logpL, smolarL, iL-2, iL-1, iL, iL+1, logp);
|
||||
return Q*sV + (1-Q)*sL;
|
||||
}
|
||||
case iHmolar:
|
||||
{
|
||||
double hV = CubicInterp(logpV, hmolarV, iV-2, iV-1, iV, iV+1, logp);
|
||||
double hL = CubicInterp(logpL, hmolarL, iL-2, iL-1, iL, iL+1, logp);
|
||||
return Q*hV + (1-Q)*hL;
|
||||
}
|
||||
case iDmolar:
|
||||
{
|
||||
double rhoV = exp(CubicInterp(logpV, logrhomolarV, iV-2, iV-1, iV, iV+1, logp));
|
||||
double rhoL = exp(CubicInterp(logpL, logrhomolarL, iL-2, iL-1, iL, iL+1, logp));
|
||||
if (!ValidNumber(rhoV)){throw ValueError("rhoV is invalid");}
|
||||
if (!ValidNumber(rhoL)){throw ValueError("rhoL is invalid");}
|
||||
return 1/(Q/rhoV + (1-Q)/rhoL);
|
||||
}
|
||||
default:
|
||||
throw ValueError("can't be something other than T or rho");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** \brief This class holds the data for a single-phase interpolation table that is regularly spaced
|
||||
|
||||
Reference in New Issue
Block a user