diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 9af1166db..4dbcfbb0d 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -3606,9 +3606,8 @@ namespace Opm }; // Make the flo() function. - auto flo_type = table.getFloType(); - auto flo = [flo_type](const std::vector& rates) { - return detail::getFlo(rates[Water], rates[Oil], rates[Gas], flo_type); + auto flo = [&table](const std::vector& rates) { + return detail::getFlo(table, rates[Water], rates[Oil], rates[Gas]); }; // Make the frates() function. @@ -3830,9 +3829,8 @@ namespace Opm }; // Make the flo() function. - auto flo_type = table.getFloType(); - auto flo = [flo_type](const std::vector& rates) { - return detail::getFlo(rates[Water], rates[Oil], rates[Gas], flo_type); + auto flo = [&table](const std::vector& rates) { + return detail::getFlo(table, rates[Water], rates[Oil], rates[Gas]); }; // Make the frates() function. diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index 026f69fd3..8d092924b 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -3726,9 +3726,8 @@ namespace Opm }; // Make the flo() function. - auto flo_type = table.getFloType(); - auto flo = [flo_type](const std::vector& rates) { - return detail::getFlo(rates[Water], rates[Oil], rates[Gas], flo_type); + auto flo = [&table](const std::vector& rates) { + return detail::getFlo(table, rates[Water], rates[Oil], rates[Gas]); }; // Make the frates() function. @@ -3932,9 +3931,8 @@ namespace Opm }; // Make the flo() function. - auto flo_type = table.getFloType(); - auto flo = [flo_type](const std::vector& rates) { - return detail::getFlo(rates[Water], rates[Oil], rates[Gas], flo_type); + auto flo = [&table](const std::vector& rates) { + return detail::getFlo(table, rates[Water], rates[Oil], rates[Gas]); }; // Make the frates() function. diff --git a/opm/simulators/wells/VFPHelpers.hpp b/opm/simulators/wells/VFPHelpers.hpp index 87a0a6f5a..3214fcb95 100644 --- a/opm/simulators/wells/VFPHelpers.hpp +++ b/opm/simulators/wells/VFPHelpers.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -40,11 +41,14 @@ namespace detail { /** * Returns zero if input value is NaN of INF */ -inline double zeroIfNanInf(const double& value) { +inline double zeroIfNanInf(const double& value, const std::string& rate, const VFPProdTable& table) { const bool nan_or_inf = std::isnan(value) || std::isinf(value); if (nan_or_inf) { - OpmLog::warning("NAN_OR_INF_VFP", "NAN or INF value encountered during VFP calculation, the value is set to zero"); + std::string msg = "Problem with VFPPROD keyword table " + std::to_string(table.getTableNum()) + "\n" + + "In " + table.location().filename + " line " + std::to_string(table.location().lineno) + "\n" + "Nan or inf encountered while calculating " + rate + " - using zero"; + OpmLog::warning("NAN_OR_INF_VFP", msg); } return nan_or_inf ? 0.0 : value; @@ -55,11 +59,14 @@ inline double zeroIfNanInf(const double& value) { * Returns zero if input value is NaN or INF */ template -inline EvalWell zeroIfNanInf(const EvalWell& value) { +inline EvalWell zeroIfNanInf(const EvalWell& value, const std::string& rate, const VFPProdTable& table) { const bool nan_or_inf = std::isnan(value.value()) || std::isinf(value.value()); if (nan_or_inf) { - OpmLog::warning("NAN_OR_INF_VFP_EVAL", "NAN or INF Evalution encountered during VFP calculation, the Evalution is set to zero"); + std::string msg = "Problem with VFPPROD keyword table " + std::to_string(table.getTableNum()) + "\n" + + "In " + table.location().filename + " line " + std::to_string(table.location().lineno) + "\n" + "Nan or inf encountered while calculating " + rate + " - using zero"; + OpmLog::warning("NAN_OR_INF_VFP_EVAL", msg); } using Toolbox = MathToolbox; @@ -74,21 +81,20 @@ inline EvalWell zeroIfNanInf(const EvalWell& value) { * @return Production rate of oil, gas or liquid. */ template -static T getFlo(const T& aqua, const T& liquid, const T& vapour, - const VFPProdTable::FLO_TYPE& type) { +static T getFlo(const VFPProdTable& table, const T& aqua, const T& liquid, const T& vapour) { + auto type = table.getFloType(); switch (type) { - case VFPProdTable::FLO_OIL: - //Oil = liquid phase - return liquid; - case VFPProdTable::FLO_LIQ: - //Liquid = aqua + liquid phases - return aqua + liquid; - case VFPProdTable::FLO_GAS: - //Gas = vapor phase - return vapour; - case VFPProdTable::FLO_INVALID: //Intentional fall-through - default: - OPM_THROW(std::logic_error, "Invalid FLO_TYPE: '" << type << "'"); + case VFPProdTable::FLO_TYPE::FLO_OIL: + //Oil = liquid phase + return liquid; + case VFPProdTable::FLO_TYPE::FLO_LIQ: + //Liquid = aqua + liquid phases + return aqua + liquid; + case VFPProdTable::FLO_TYPE::FLO_GAS: + //Gas = vapor phase + return vapour; + default: + throw std::logic_error("Invalid FLO_TYPE"); } } @@ -100,21 +106,20 @@ static T getFlo(const T& aqua, const T& liquid, const T& vapour, * @return Production rate of oil, gas or liquid. */ template -static T getFlo(const T& aqua, const T& liquid, const T& vapour, - const VFPInjTable::FLO_TYPE& type) { +static T getFlo(const VFPInjTable& table, const T& aqua, const T& liquid, const T& vapour) { + auto type = table.getFloType(); switch (type) { - case VFPInjTable::FLO_OIL: - //Oil = liquid phase - return liquid; - case VFPInjTable::FLO_WAT: - //Liquid = aqua phase - return aqua; - case VFPInjTable::FLO_GAS: - //Gas = vapor phase - return vapour; - case VFPInjTable::FLO_INVALID: //Intentional fall-through - default: - OPM_THROW(std::logic_error, "Invalid FLO_TYPE: '" << type << "'"); + case VFPInjTable::FLO_TYPE::FLO_OIL: + //Oil = liquid phase + return liquid; + case VFPInjTable::FLO_TYPE::FLO_WAT: + //Liquid = aqua phase + return aqua; + case VFPInjTable::FLO_TYPE::FLO_GAS: + //Gas = vapor phase + return vapour; + default: + throw std::logic_error("Invalid FLO_TYPE"); } } @@ -129,23 +134,23 @@ static T getFlo(const T& aqua, const T& liquid, const T& vapour, * @return Production rate of oil, gas or liquid. */ template -static T getWFR(const T& aqua, const T& liquid, const T& vapour, - const VFPProdTable::WFR_TYPE& type) { +static T getWFR(const VFPProdTable& table, const T& aqua, const T& liquid, const T& vapour) { + auto type = table.getWFRType(); switch(type) { - case VFPProdTable::WFR_WOR: { - //Water-oil ratio = water / oil - T wor = aqua / liquid; - return zeroIfNanInf(wor); - } - case VFPProdTable::WFR_WCT: - //Water cut = water / (water + oil) - return zeroIfNanInf(aqua / (aqua + liquid)); - case VFPProdTable::WFR_WGR: - //Water-gas ratio = water / gas - return zeroIfNanInf(aqua / vapour); - case VFPProdTable::WFR_INVALID: //Intentional fall-through - default: - OPM_THROW(std::logic_error, "Invalid WFR_TYPE: '" << type << "'"); + case VFPProdTable::WFR_TYPE::WFR_WOR: + //Water-oil ratio = water / oil + return zeroIfNanInf(aqua/liquid, "WOR", table); + + case VFPProdTable::WFR_TYPE::WFR_WCT: + //Water cut = water / (water + oil) + return zeroIfNanInf(aqua / (aqua + liquid), "WCT", table); + + case VFPProdTable::WFR_TYPE::WFR_WGR: + //Water-gas ratio = water / gas + return zeroIfNanInf(aqua / vapour, "WGR", table); + + default: + throw std::logic_error("Invalid WFR_TYPE"); } } @@ -159,21 +164,20 @@ static T getWFR(const T& aqua, const T& liquid, const T& vapour, * @return Production rate of oil, gas or liquid. */ template -static T getGFR(const T& aqua, const T& liquid, const T& vapour, - const VFPProdTable::GFR_TYPE& type) { +static T getGFR(const VFPProdTable& table, const T& aqua, const T& liquid, const T& vapour) { + auto type = table.getGFRType(); switch(type) { - case VFPProdTable::GFR_GOR: - // Gas-oil ratio = gas / oil - return zeroIfNanInf(vapour / liquid); - case VFPProdTable::GFR_GLR: - // Gas-liquid ratio = gas / (oil + water) - return zeroIfNanInf(vapour / (liquid + aqua)); - case VFPProdTable::GFR_OGR: - // Oil-gas ratio = oil / gas - return zeroIfNanInf(liquid / vapour); - case VFPProdTable::GFR_INVALID: //Intentional fall-through - default: - OPM_THROW(std::logic_error, "Invalid GFR_TYPE: '" << type << "'"); + case VFPProdTable::GFR_TYPE::GFR_GOR: + // Gas-oil ratio = gas / oil + return zeroIfNanInf(vapour / liquid, "GOR", table); + case VFPProdTable::GFR_TYPE::GFR_GLR: + // Gas-liquid ratio = gas / (oil + water) + return zeroIfNanInf(vapour / (liquid + aqua), "GLR", table); + case VFPProdTable::GFR_TYPE::GFR_OGR: + // Oil-gas ratio = oil / gas + return zeroIfNanInf(liquid / vapour, "OGR", table); + default: + throw std::logic_error("Invalid GFR_TYPE"); } } @@ -510,9 +514,9 @@ inline VFPEvaluation bhp(const VFPProdTable& table, const double& thp, const double& alq) { //Find interpolation variables - double flo = detail::getFlo(aqua, liquid, vapour, table.getFloType()); - double wfr = detail::getWFR(aqua, liquid, vapour, table.getWFRType()); - double gfr = detail::getGFR(aqua, liquid, vapour, table.getGFRType()); + double flo = detail::getFlo(table, aqua, liquid, vapour); + double wfr = detail::getWFR(table, aqua, liquid, vapour); + double gfr = detail::getGFR(table, aqua, liquid, vapour); //First, find the values to interpolate between //Recall that flo is negative in Opm, so switch sign. @@ -537,7 +541,7 @@ inline VFPEvaluation bhp(const VFPInjTable& table, const double& vapour, const double& thp) { //Find interpolation variables - double flo = detail::getFlo(aqua, liquid, vapour, table.getFloType()); + double flo = detail::getFlo(table, aqua, liquid, vapour); //First, find the values to interpolate between auto flo_i = detail::findInterpData(flo, table.getFloAxis()); diff --git a/opm/simulators/wells/VFPInjProperties.cpp b/opm/simulators/wells/VFPInjProperties.cpp index 6a2863acb..0fe49f5d9 100644 --- a/opm/simulators/wells/VFPInjProperties.cpp +++ b/opm/simulators/wells/VFPInjProperties.cpp @@ -54,7 +54,7 @@ double VFPInjProperties::thp(int table_id, const VFPInjTable& table = detail::getTable(m_tables, table_id); //Find interpolation variables - double flo = detail::getFlo(aqua, liquid, vapour, table.getFloType()); + double flo = detail::getFlo(table, aqua, liquid, vapour); const std::vector thp_array = table.getTHPAxis(); int nthp = thp_array.size(); diff --git a/opm/simulators/wells/VFPInjProperties.hpp b/opm/simulators/wells/VFPInjProperties.hpp index 8a14010fc..b2b719cec 100644 --- a/opm/simulators/wells/VFPInjProperties.hpp +++ b/opm/simulators/wells/VFPInjProperties.hpp @@ -68,7 +68,7 @@ public: EvalWell bhp = 0.0 * aqua; //Find interpolation variables - EvalWell flo = detail::getFlo(aqua, liquid, vapour, table.getFloType()); + EvalWell flo = detail::getFlo(table, aqua, liquid, vapour); //First, find the values to interpolate between //Value of FLO is negative in OPM for producers, but positive in VFP table diff --git a/opm/simulators/wells/VFPProdProperties.cpp b/opm/simulators/wells/VFPProdProperties.cpp index 41d369f06..971a0e366 100644 --- a/opm/simulators/wells/VFPProdProperties.cpp +++ b/opm/simulators/wells/VFPProdProperties.cpp @@ -53,9 +53,9 @@ double VFPProdProperties::thp(int table_id, } else { // The usual case. // Recall that production rate is negative in Opm, so switch the sign. - flo = -detail::getFlo(aqua, liquid, vapour, table.getFloType()); - wfr = detail::getWFR(aqua, liquid, vapour, table.getWFRType()); - gfr = detail::getGFR(aqua, liquid, vapour, table.getGFRType()); + flo = -detail::getFlo(table, aqua, liquid, vapour); + wfr = detail::getWFR(table, aqua, liquid, vapour); + gfr = detail::getGFR(table, aqua, liquid, vapour); } const std::vector thp_array = table.getTHPAxis(); @@ -181,16 +181,16 @@ calculateBhpWithTHPTarget(const std::vector& ipr_a, const double aqua_bhp_limit = rates_bhp_limit[Water]; const double liquid_bhp_limit = rates_bhp_limit[Oil]; const double vapour_bhp_limit = rates_bhp_limit[Gas]; - const double flo_bhp_limit = detail::getFlo(aqua_bhp_limit, liquid_bhp_limit, vapour_bhp_limit, table.getFloType() ); + const double flo_bhp_limit = detail::getFlo(table, aqua_bhp_limit, liquid_bhp_limit, vapour_bhp_limit ); const double aqua_bhp_middle = rates_bhp_middle[Water]; const double liquid_bhp_middle = rates_bhp_middle[Oil]; const double vapour_bhp_middle = rates_bhp_middle[Gas]; - const double flo_bhp_middle = detail::getFlo(aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle, table.getFloType() ); + const double flo_bhp_middle = detail::getFlo(table, aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle ); // we use the ratios based on the middle value of bhp_limit and bhp_safe_limit - const double wfr = detail::getWFR(aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle, table.getWFRType()); - const double gfr = detail::getGFR(aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle, table.getGFRType()); + const double wfr = detail::getWFR(table, aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle); + const double gfr = detail::getGFR(table, aqua_bhp_middle, liquid_bhp_middle, vapour_bhp_middle); // we get the flo sampling points from the table, // then extend it with zero and rate under bhp_limit for extrapolation diff --git a/opm/simulators/wells/VFPProdProperties.hpp b/opm/simulators/wells/VFPProdProperties.hpp index 153fd0d5f..e624dc2cd 100644 --- a/opm/simulators/wells/VFPProdProperties.hpp +++ b/opm/simulators/wells/VFPProdProperties.hpp @@ -74,9 +74,9 @@ public: EvalWell bhp = 0.0 * aqua; //Find interpolation variables - EvalWell flo = detail::getFlo(aqua, liquid, vapour, table.getFloType()); - EvalWell wfr = detail::getWFR(aqua, liquid, vapour, table.getWFRType()); - EvalWell gfr = detail::getGFR(aqua, liquid, vapour, table.getGFRType()); + EvalWell flo = detail::getFlo(table, aqua, liquid, vapour); + EvalWell wfr = detail::getWFR(table, aqua, liquid, vapour); + EvalWell gfr = detail::getGFR(table, aqua, liquid, vapour); //First, find the values to interpolate between //Value of FLO is negative in OPM for producers, but positive in VFP table diff --git a/tests/test_vfpproperties.cpp b/tests/test_vfpproperties.cpp index b62e4944f..d3772f8ca 100644 --- a/tests/test_vfpproperties.cpp +++ b/tests/test_vfpproperties.cpp @@ -194,10 +194,10 @@ struct TrivialFixture { inline void initProperties() { table.reset(new Opm::VFPProdTable(1, 1000.0, - Opm::VFPProdTable::FLO_OIL, - Opm::VFPProdTable::WFR_WOR, - Opm::VFPProdTable::GFR_GOR, - Opm::VFPProdTable::ALQ_UNDEF, + Opm::VFPProdTable::FLO_TYPE::FLO_OIL, + Opm::VFPProdTable::WFR_TYPE::WFR_WOR, + Opm::VFPProdTable::GFR_TYPE::GFR_GOR, + Opm::VFPProdTable::ALQ_TYPE::ALQ_UNDEF, flo_axis, thp_axis, wfr_axis, @@ -231,7 +231,7 @@ private: int nz; int nu; int nv; - Opm::VFPProdTable::array_type data; + std::vector data; };