From 29d142b5e4d1c78ba90f603a0f27c4cfdbb0ed96 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 19 Feb 2024 14:00:51 +0100 Subject: [PATCH] VFPProdProperties: template Scalar type --- opm/simulators/wells/VFPProdProperties.cpp | 135 ++++++++++++--------- opm/simulators/wells/VFPProdProperties.hpp | 70 ++++++----- opm/simulators/wells/VFPProperties.hpp | 5 +- opm/simulators/wells/WellGroupHelpers.cpp | 2 +- opm/simulators/wells/WellGroupHelpers.hpp | 4 +- tests/test_vfpproperties.cpp | 8 +- 6 files changed, 119 insertions(+), 105 deletions(-) diff --git a/opm/simulators/wells/VFPProdProperties.cpp b/opm/simulators/wells/VFPProdProperties.cpp index ce19ba245..8114d5b03 100644 --- a/opm/simulators/wells/VFPProdProperties.cpp +++ b/opm/simulators/wells/VFPProdProperties.cpp @@ -31,21 +31,21 @@ namespace Opm { - - - -double VFPProdProperties::thp(int table_id, - const double& aqua, - const double& liquid, - const double& vapour, - const double& bhp_arg, - const double& alq) const { +template +Scalar VFPProdProperties:: +thp(const int table_id, + const Scalar aqua, + const Scalar liquid, + const Scalar vapour, + const Scalar bhp_arg, + const Scalar alq) const +{ const VFPProdTable& table = detail::getTable(m_tables, table_id); // Find interpolation variables. - double flo = 0.0; - double wfr = 0.0; - double gfr = 0.0; + Scalar flo = 0.0; + Scalar wfr = 0.0; + Scalar gfr = 0.0; if (aqua == 0.0 && liquid == 0.0 && vapour == 0.0) { // All zero, likely at initial state. // Set FLO variable to minimum to avoid extrapolation. @@ -71,51 +71,56 @@ double VFPProdProperties::thp(int table_id, auto wfr_i = detail::findInterpData( wfr, table.getWFRAxis()); auto gfr_i = detail::findInterpData( gfr, table.getGFRAxis()); auto alq_i = detail::findInterpData( alq, table.getALQAxis()); - std::vector bhp_array(nthp); - for (int i=0; i bhp_array(nthp); + for (int i = 0; i < nthp; ++i) { auto thp_i = detail::findInterpData(thp_array[i], thp_array); bhp_array[i] = detail::interpolate(table, flo_i, thp_i, wfr_i, gfr_i, alq_i).value; } - double retval = detail::findTHP(bhp_array, thp_array, bhp_arg); - return retval; + return detail::findTHP(bhp_array, thp_array, bhp_arg); } - -double VFPProdProperties::bhp(int table_id, - const double& aqua, - const double& liquid, - const double& vapour, - const double& thp_arg, - const double& alq, - const double& explicit_wfr, - const double& explicit_gfr, - const bool use_expvfp) const { +template +Scalar VFPProdProperties:: +bhp(const int table_id, + const Scalar aqua, + const Scalar liquid, + const Scalar vapour, + const Scalar thp_arg, + const Scalar alq, + const Scalar explicit_wfr, + const Scalar explicit_gfr, + const bool use_expvfp) const +{ const VFPProdTable& table = detail::getTable(m_tables, table_id); detail::VFPEvaluation retval = detail::bhp(table, aqua, liquid, vapour, thp_arg, alq, explicit_wfr,explicit_gfr, use_expvfp); return retval.value; } - -const VFPProdTable& VFPProdProperties::getTable(const int table_id) const { +template +const VFPProdTable& +VFPProdProperties::getTable(const int table_id) const +{ return detail::getTable(m_tables, table_id); } -bool VFPProdProperties::hasTable(const int table_id) const { +template +bool VFPProdProperties::hasTable(const int table_id) const +{ return detail::hasTable(m_tables, table_id); } - -std::vector -VFPProdProperties:: -bhpwithflo(const std::vector& flos, +template +std::vector +VFPProdProperties:: +bhpwithflo(const std::vector& flos, const int table_id, - const double wfr, - const double gfr, - const double thp, - const double alq, - const double dp) const + const Scalar wfr, + const Scalar gfr, + const Scalar thp, + const Scalar alq, + const Scalar dp) const { // Get the table const VFPProdTable& table = detail::getTable(m_tables, table_id); @@ -124,7 +129,7 @@ bhpwithflo(const std::vector& flos, const auto gfr_i = detail::findInterpData( gfr, table.getGFRAxis()); const auto alq_i = detail::findInterpData( alq, table.getALQAxis()); //assume constant - std::vector bhps(flos.size(), 0.); + std::vector bhps(flos.size(), 0.); for (std::size_t i = 0; i < flos.size(); ++i) { // Value of FLO is negative in OPM for producers, but positive in VFP table const auto flo_i = detail::findInterpData(-flos[i], table.getFloAxis()); @@ -137,13 +142,13 @@ bhpwithflo(const std::vector& flos, return bhps; } -double -VFPProdProperties:: +template +Scalar VFPProdProperties:: minimumBHP(const int table_id, - const double thp, - const double wfr, - const double gfr, - const double alq) const + const Scalar thp, + const Scalar wfr, + const Scalar gfr, + const Scalar alq) const { // Get the table const VFPProdTable& table = detail::getTable(m_tables, table_id); @@ -152,22 +157,24 @@ minimumBHP(const int table_id, return retval.second; } - - -void VFPProdProperties::addTable(const VFPProdTable& new_table) { +template +void VFPProdProperties::addTable(const VFPProdTable& new_table) +{ this->m_tables.emplace( new_table.getTableNum(), new_table ); } +template template -EvalWell VFPProdProperties::bhp(const int table_id, - const EvalWell& aqua, - const EvalWell& liquid, - const EvalWell& vapour, - const double& thp, - const double& alq, - const double& explicit_wfr, - const double& explicit_gfr, - const bool use_expvfp) const +EvalWell VFPProdProperties:: +bhp(const int table_id, + const EvalWell& aqua, + const EvalWell& liquid, + const EvalWell& vapour, + const Scalar thp, + const Scalar alq, + const Scalar explicit_wfr, + const Scalar explicit_gfr, + const bool use_expvfp) const { //Get the table const VFPProdTable& table = detail::getTable(m_tables, table_id); @@ -197,10 +204,18 @@ EvalWell VFPProdProperties::bhp(const int table_id, return bhp; } +template class VFPProdProperties; + #define INSTANCE(...) \ - template __VA_ARGS__ VFPProdProperties::bhp<__VA_ARGS__>(const int, \ - const __VA_ARGS__&, const __VA_ARGS__&, const __VA_ARGS__&, \ - const double&, const double&, const double&, const double&, const bool) const; + template __VA_ARGS__ VFPProdProperties::bhp<__VA_ARGS__>(const int, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const double, \ + const double, \ + const double, \ + const double, \ + const bool) const; INSTANCE(DenseAd::Evaluation) INSTANCE(DenseAd::Evaluation) diff --git a/opm/simulators/wells/VFPProdProperties.hpp b/opm/simulators/wells/VFPProdProperties.hpp index d5a72975a..65f6d0583 100644 --- a/opm/simulators/wells/VFPProdProperties.hpp +++ b/opm/simulators/wells/VFPProdProperties.hpp @@ -34,9 +34,9 @@ class VFPProdTable; * water fraction, gas fraction, and artificial lift for production VFP tables, and similarly * the BHP as a function of the rate and tubing head pressure. */ +template class VFPProdProperties { public: - VFPProdProperties() = default; /** * Takes *no* ownership of data. */ @@ -60,15 +60,15 @@ public: * input ADB objects. */ template - EvalWell bhp(const int table_id, + EvalWell bhp(const int table_id, const EvalWell& aqua, const EvalWell& liquid, const EvalWell& vapour, - const double& thp, - const double& alq, - const double& explicit_wfr, - const double& explicit_gfr, - const bool use_expvfp) const; + const Scalar thp, + const Scalar alq, + const Scalar explicit_wfr, + const Scalar explicit_gfr, + const bool use_expvfp) const; /** * Linear interpolation of bhp as a function of the input parameters @@ -82,15 +82,15 @@ public: * @return The bottom hole pressure, interpolated/extrapolated linearly using * the above parameters from the values in the input table. */ - double bhp(int table_id, - const double& aqua, - const double& liquid, - const double& vapour, - const double& thp, - const double& alq, - const double& explicit_wfr, - const double& explicit_gfr, - const bool use_expvfp) const; + Scalar bhp(const int table_id, + const Scalar aqua, + const Scalar liquid, + const Scalar vapour, + const Scalar thp, + const Scalar alq, + const Scalar explicit_wfr, + const Scalar explicit_gfr, + const bool use_expvfp) const; /** * Linear interpolation of thp as a function of the input parameters @@ -104,12 +104,12 @@ public: * @return The tubing hole pressure, interpolated/extrapolated linearly using * the above parameters from the values in the input table. */ - double thp(int table_id, - const double& aqua, - const double& liquid, - const double& vapour, - const double& bhp, - const double& alq) const; + Scalar thp(const int table_id, + const Scalar aqua, + const Scalar liquid, + const Scalar vapour, + const Scalar bhp, + const Scalar alq) const; /** * Returns the table associated with the ID, or throws an exception if @@ -125,33 +125,31 @@ public: /** * Returns true if no vfp tables are in the current map */ - bool empty() const { + bool empty() const + { return m_tables.empty(); } /** * Returns minimum bhp for given thp, wfr, gfr and alq */ - double minimumBHP(const int table_id, const double thp, - const double wfr, const double gfr, const double alq) const; + Scalar minimumBHP(const int table_id, const Scalar thp, + const Scalar wfr, const Scalar gfr, const Scalar alq) const; + protected: // calculate a group bhp values with a group of flo rate values - std::vector bhpwithflo(const std::vector& flos, + std::vector bhpwithflo(const std::vector& flos, const int table_id, - const double wfr, - const double gfr, - const double thp, - const double alq, - const double dp) const; + const Scalar wfr, + const Scalar gfr, + const Scalar thp, + const Scalar alq, + const Scalar dp) const; // Map which connects the table number with the table itself std::map> m_tables; }; - - - -} //namespace - +} // namespace Opm #endif /* OPM_AUTODIFF_VFPPRODPROPERTIES_HPP_ */ diff --git a/opm/simulators/wells/VFPProperties.hpp b/opm/simulators/wells/VFPProperties.hpp index 4d5755fb3..b6e51d0cc 100644 --- a/opm/simulators/wells/VFPProperties.hpp +++ b/opm/simulators/wells/VFPProperties.hpp @@ -68,7 +68,8 @@ public: /** * Returns the VFP properties for production wells */ - const VFPProdProperties* getProd() const { + const VFPProdProperties* getProd() const + { return &m_prod; } @@ -94,7 +95,7 @@ public: private: VFPInjProperties m_inj; - VFPProdProperties m_prod; + VFPProdProperties m_prod; const WellState& well_state_; }; diff --git a/opm/simulators/wells/WellGroupHelpers.cpp b/opm/simulators/wells/WellGroupHelpers.cpp index b2f970dd3..bb1e55856 100644 --- a/opm/simulators/wells/WellGroupHelpers.cpp +++ b/opm/simulators/wells/WellGroupHelpers.cpp @@ -811,7 +811,7 @@ WellGroupHelpers:: computeNetworkPressures(const Network::ExtNetwork& network, const WellState& well_state, const GroupState& group_state, - const VFPProdProperties& vfp_prod_props, + const VFPProdProperties& vfp_prod_props, const Schedule& schedule, const int report_time_step) { diff --git a/opm/simulators/wells/WellGroupHelpers.hpp b/opm/simulators/wells/WellGroupHelpers.hpp index 47b291f1e..70754640b 100644 --- a/opm/simulators/wells/WellGroupHelpers.hpp +++ b/opm/simulators/wells/WellGroupHelpers.hpp @@ -37,7 +37,7 @@ template class GroupState; namespace Network { class ExtNetwork; } struct PhaseUsage; class Schedule; -class VFPProdProperties; +template class VFPProdProperties; template class WellState; class FieldPropsManager; @@ -202,7 +202,7 @@ public: computeNetworkPressures(const Network::ExtNetwork& network, const WellState& well_state, const GroupState& group_state, - const VFPProdProperties& vfp_prod_props, + const VFPProdProperties& vfp_prod_props, const Schedule& schedule, const int report_time_step); diff --git a/tests/test_vfpproperties.cpp b/tests/test_vfpproperties.cpp index 4f33b7403..44e17b047 100644 --- a/tests/test_vfpproperties.cpp +++ b/tests/test_vfpproperties.cpp @@ -208,7 +208,7 @@ struct TrivialFixture { alq_axis, data)); - properties = std::make_shared(); + properties = std::make_shared>(); properties->addTable( *table ); } @@ -219,7 +219,7 @@ struct TrivialFixture { - std::shared_ptr properties; + std::shared_ptr> properties; std::shared_ptr table; std::vector table_ids; @@ -612,7 +612,7 @@ VFPPROD \n\ auto deck = parser.parseString(table_str); bool gaslift_active = false; Opm::VFPProdTable table(deck["VFPPROD"].front(), gaslift_active, units); - Opm::VFPProdProperties properties; + Opm::VFPProdProperties properties; properties.addTable( table ); const int n = 5; //Number of points to check per axis @@ -673,7 +673,7 @@ BOOST_AUTO_TEST_CASE(ParseInterpolateRealisticVFPPROD) bool gaslift_active = false; Opm::VFPProdTable table(deck["VFPPROD"].front(), gaslift_active, units); - Opm::VFPProdProperties properties; + Opm::VFPProdProperties properties; properties.addTable(table); //Do some rudimentary testing