From 8afb9efe6093bfe0fe40ee848dfe62c8d215416b Mon Sep 17 00:00:00 2001 From: Ian Bell Date: Sun, 6 Dec 2015 15:18:05 -0700 Subject: [PATCH] Move PQ and QT inputs into the base tabular update function --- src/Backends/Tabular/BicubicBackend.cpp | 54 ++------------------ src/Backends/Tabular/TTSEBackend.cpp | 53 ++----------------- src/Backends/Tabular/TabularBackends.cpp | 65 ++++++++++++++++++++++++ src/Backends/Tabular/TabularBackends.h | 2 +- 4 files changed, 72 insertions(+), 102 deletions(-) diff --git a/src/Backends/Tabular/BicubicBackend.cpp b/src/Backends/Tabular/BicubicBackend.cpp index 64917b13..208c370a 100644 --- a/src/Backends/Tabular/BicubicBackend.cpp +++ b/src/Backends/Tabular/BicubicBackend.cpp @@ -302,57 +302,9 @@ void CoolProp::BicubicBackend::update(CoolProp::input_pairs input_pair, double v } break; } - case PQ_INPUTS:{ - std::size_t iL = 0, iV = 0; - _p = val1; _Q = val2; - using_single_phase_table = false; - if (!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ - throw ValueError("vapor quality is not in (0,1)"); - } - else{ - CoolPropDbl TL = _HUGE, TV = _HUGE; - if (is_mixture){ - std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iP, _p); - if (intersect.empty()){ throw ValueError(format("p [%g Pa] is not within phase envelope", _p)); } - iV = intersect[0].first; iL = intersect[1].first; - } - else{ - bool it_is_inside = pure_saturation.is_inside(iP, _p, iQ, _Q, iL, iV, TL, TV); - if (!it_is_inside){ - throw ValueError("Not possible to determine whether pressure is inside or not"); - } - } - _T = _Q*TV + (1-_Q)*TL; - cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; - } - break; - } - case QT_INPUTS:{ - std::size_t iL = 0, iV = 0; - _Q = val1; _T = val2; - - using_single_phase_table = false; - if(!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ - throw ValueError("vapor quality is not in (0,1)"); - } - else{ - CoolPropDbl pL = _HUGE, pV = _HUGE; - if (is_mixture){ - std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iT, _T); - if (intersect.empty()){ throw ValueError(format("T [%g K] is not within phase envelope", _T)); } - iV = intersect[0].first; iL = intersect[1].first; - pL = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iL); - pV = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iV); - _p = _Q*pV + (1-_Q)*pL; - } - else{ - pure_saturation.is_inside(iT, _T, iQ, _Q, iL, iV, pL, pV); - } - _p = _Q*pV + (1-_Q)*pL; - cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; - } - break; - } + case PQ_INPUTS: + case QT_INPUTS: + TabularBackend::update(input_pair, val1, val2); break; default: throw ValueError("Sorry, but this set of inputs is not supported for Bicubic backend"); } diff --git a/src/Backends/Tabular/TTSEBackend.cpp b/src/Backends/Tabular/TTSEBackend.cpp index aee1dc1b..9cc8cfc1 100644 --- a/src/Backends/Tabular/TTSEBackend.cpp +++ b/src/Backends/Tabular/TTSEBackend.cpp @@ -224,56 +224,9 @@ void CoolProp::TTSEBackend::update(CoolProp::input_pairs input_pair, double val1 } break; } - case PQ_INPUTS:{ - std::size_t iL = 0, iV = 0; - _p = val1; _Q = val2; - using_single_phase_table = false; - if (!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ - throw ValueError("vapor quality is not in (0,1)"); - } - else{ - CoolPropDbl TL = _HUGE, TV = _HUGE; - if (is_mixture){ - std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iP, _p); - if (intersect.empty()){ throw ValueError(format("p [%g Pa] is not within phase envelope", _p)); } - iV = intersect[0].first; iL = intersect[1].first; - } - else{ - bool it_is_inside = pure_saturation.is_inside(iP, _p, iQ, _Q, iL, iV, TL, TV); - if (!it_is_inside){ - throw ValueError("Not possible to determine whether pressure is inside or not"); - } - } - _T = _Q*TV + (1-_Q)*TL; - cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; - } - break; - } - case QT_INPUTS:{ - std::size_t iL = 0, iV = 0; - _Q = val1; _T = val2; - - using_single_phase_table = false; - if(!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ - throw ValueError("vapor quality is not in (0,1)"); - } - else{ - CoolPropDbl pL = _HUGE, pV = _HUGE; - if (is_mixture){ - std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iT, _T); - if (intersect.empty()){ throw ValueError(format("T [%g K] is not within phase envelope", _T)); } - iV = intersect[0].first; iL = intersect[1].first; - pL = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iL); - pV = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iV); - } - else{ - pure_saturation.is_inside(iT, _T, iQ, _Q, iL, iV, pL, pV); - } - _p = _Q*pV + (1-_Q)*pL; - cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; - } - break; - } + case PQ_INPUTS: + case QT_INPUTS: + TabularBackend::update(input_pair, val1, val2); break; default: throw ValueError("Sorry, but this set of inputs is not supported for TTSE backend"); } diff --git a/src/Backends/Tabular/TabularBackends.cpp b/src/Backends/Tabular/TabularBackends.cpp index ec96f3c5..5bffbac5 100644 --- a/src/Backends/Tabular/TabularBackends.cpp +++ b/src/Backends/Tabular/TabularBackends.cpp @@ -648,6 +648,71 @@ CoolPropDbl CoolProp::TabularBackend::calc_first_two_phase_deriv(parameters Of, } } +void CoolProp::TabularBackend::update(CoolProp::input_pairs input_pair, double val1, double val2) +{ + + PureFluidSaturationTableData &pure_saturation = dataset->pure_saturation; + PhaseEnvelopeData & phase_envelope = dataset->phase_envelope; + SinglePhaseGriddedTableData &single_phase_logph = dataset->single_phase_logph; + SinglePhaseGriddedTableData &single_phase_logpT = dataset->single_phase_logpT; + + switch (input_pair) + { + case PQ_INPUTS:{ + std::size_t iL = 0, iV = 0; + _p = val1; _Q = val2; + using_single_phase_table = false; + if (!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ + throw ValueError("vapor quality is not in (0,1)"); + } + else{ + CoolPropDbl TL = _HUGE, TV = _HUGE; + if (is_mixture){ + std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iP, _p); + if (intersect.empty()){ throw ValueError(format("p [%g Pa] is not within phase envelope", _p)); } + iV = intersect[0].first; iL = intersect[1].first; + } + else{ + bool it_is_inside = pure_saturation.is_inside(iP, _p, iQ, _Q, iL, iV, TL, TV); + if (!it_is_inside){ + throw ValueError("Not possible to determine whether pressure is inside or not"); + } + } + _T = _Q*TV + (1-_Q)*TL; + cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; + } + break; + } + case QT_INPUTS:{ + std::size_t iL = 0, iV = 0; + _Q = val1; _T = val2; + + using_single_phase_table = false; + if (!is_in_closed_range(0.0, 1.0, static_cast(_Q))){ + throw ValueError("vapor quality is not in (0,1)"); + } + else{ + CoolPropDbl pL = _HUGE, pV = _HUGE; + if (is_mixture){ + std::vector > intersect = PhaseEnvelopeRoutines::find_intersections(phase_envelope, iT, _T); + if (intersect.empty()){ throw ValueError(format("T [%g K] is not within phase envelope", _T)); } + iV = intersect[0].first; iL = intersect[1].first; + pL = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iL); + pV = PhaseEnvelopeRoutines::evaluate(phase_envelope, iP, iT, _T, iV); + } + else{ + pure_saturation.is_inside(iT, _T, iQ, _Q, iL, iV, pL, pV); + } + _p = _Q*pV + (1-_Q)*pL; + cached_saturation_iL = iL; cached_saturation_iV = iV; _phase = iphase_twophase; + } + break; + } + default: + throw ValueError("Sorry, but this set of inputs is not supported for Bicubic backend"); + } +} + void CoolProp::TabularDataSet::write_tables(const std::string &path_to_tables) { make_dirs(path_to_tables); diff --git a/src/Backends/Tabular/TabularBackends.h b/src/Backends/Tabular/TabularBackends.h index 1cc15b68..48de92a4 100644 --- a/src/Backends/Tabular/TabularBackends.h +++ b/src/Backends/Tabular/TabularBackends.h @@ -830,7 +830,7 @@ class TabularBackend : public AbstractState bool using_mole_fractions(void){return true;} bool using_mass_fractions(void){return false;} bool using_volu_fractions(void){return false;} - void update(CoolProp::input_pairs input_pair, double Value1, double Value2){}; + void update(CoolProp::input_pairs input_pair, double Value1, double Value2); void set_mole_fractions(const std::vector &mole_fractions){this->AS->set_mole_fractions(mole_fractions);}; void set_mass_fractions(const std::vector &mass_fractions){ throw NotImplementedError("set_mass_fractions not implemented for Tabular backends"); }; const std::vector & get_mole_fractions(){return AS->get_mole_fractions();};