diff --git a/src/Backends/Tabular/TTSEBackend.h b/src/Backends/Tabular/TTSEBackend.h index 5cee408a..70ba79c6 100644 --- a/src/Backends/Tabular/TTSEBackend.h +++ b/src/Backends/Tabular/TTSEBackend.h @@ -20,35 +20,12 @@ class TTSEBackend : public TabularBackend TTSEBackend(shared_ptr 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); } } }; diff --git a/src/Backends/Tabular/TabularBackends.h b/src/Backends/Tabular/TabularBackends.h index e33f221f..3c2836f5 100644 --- a/src/Backends/Tabular/TabularBackends.h +++ b/src/Backends/Tabular/TabularBackends.h @@ -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