From 81189b89c7ba48bad1b5f3575d103b9ac01fff86 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 20 Feb 2024 14:37:48 +0100 Subject: [PATCH] PerforationData: template Scalar type --- opm/simulators/wells/BlackoilWellModelGeneric.hpp | 4 ++-- opm/simulators/wells/BlackoilWellModelRestart.cpp | 4 ++-- opm/simulators/wells/BlackoilWellModelRestart.hpp | 6 +++--- opm/simulators/wells/MultisegmentWell.hpp | 2 +- opm/simulators/wells/MultisegmentWell_impl.hpp | 2 +- opm/simulators/wells/PerforationData.hpp | 8 ++++---- opm/simulators/wells/SingleWellState.cpp | 4 ++-- opm/simulators/wells/SingleWellState.hpp | 6 +++--- opm/simulators/wells/StandardWell.hpp | 2 +- opm/simulators/wells/StandardWell_impl.hpp | 2 +- opm/simulators/wells/WellFilterCake.cpp | 1 + opm/simulators/wells/WellInterface.hpp | 3 +-- opm/simulators/wells/WellInterfaceFluidSystem.cpp | 2 +- opm/simulators/wells/WellInterfaceFluidSystem.hpp | 2 +- opm/simulators/wells/WellInterfaceGeneric.cpp | 4 ++-- opm/simulators/wells/WellInterfaceGeneric.hpp | 8 ++++---- opm/simulators/wells/WellInterfaceIndices.cpp | 2 +- opm/simulators/wells/WellInterfaceIndices.hpp | 2 +- opm/simulators/wells/WellInterface_impl.hpp | 3 ++- opm/simulators/wells/WellState.cpp | 13 +++++++------ opm/simulators/wells/WellState.hpp | 14 +++++++------- tests/test_wellmodel.cpp | 10 +++++----- tests/test_wellstate.cpp | 7 ++++--- 23 files changed, 57 insertions(+), 54 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index e1e13c456..bb0848528 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -193,7 +193,7 @@ public: bool forceShutWellByName(const std::string& wellname, const double simulation_time); - const std::vector& perfData(const int well_idx) const + const std::vector>& perfData(const int well_idx) const { return well_perf_data_[well_idx]; } const Parallel::Communication& comm() const { return comm_; } @@ -450,7 +450,7 @@ protected: std::optional last_run_wellpi_{}; std::vector wells_ecl_; - std::vector> well_perf_data_; + std::vector>> well_perf_data_; /// Connection index mappings class ConnectionIndexMap diff --git a/opm/simulators/wells/BlackoilWellModelRestart.cpp b/opm/simulators/wells/BlackoilWellModelRestart.cpp index 796933623..176387c27 100644 --- a/opm/simulators/wells/BlackoilWellModelRestart.cpp +++ b/opm/simulators/wells/BlackoilWellModelRestart.cpp @@ -71,7 +71,7 @@ template void BlackoilWellModelRestart:: loadRestartConnectionData(const std::vector& phs, const data::Well& rst_well, - const std::vector& old_perf_data, + const std::vector>& old_perf_data, SingleWellState& ws) const { auto& perf_data = ws.perf_data; @@ -130,7 +130,7 @@ loadRestartWellData(const std::string& well_name, const bool handle_ms_well, const std::vector& phs, const data::Well& rst_well, - const std::vector& old_perf_data, + const std::vector>& old_perf_data, SingleWellState& ws) const { const auto np = phs.size(); diff --git a/opm/simulators/wells/BlackoilWellModelRestart.hpp b/opm/simulators/wells/BlackoilWellModelRestart.hpp index b67970587..d78c925bd 100644 --- a/opm/simulators/wells/BlackoilWellModelRestart.hpp +++ b/opm/simulators/wells/BlackoilWellModelRestart.hpp @@ -38,7 +38,7 @@ class GroupAndNetworkValues; template class GroupState; class GuideRate; class GuideRateConfig; -struct PerforationData; +template struct PerforationData; struct PhaseUsage; template class SingleWellState; template class WellState; @@ -76,7 +76,7 @@ private: //! \brief Loads per-connection data from restart structures. void loadRestartConnectionData(const std::vector& phs, const data::Well& rst_well, - const std::vector& old_perf_data, + const std::vector>& old_perf_data, SingleWellState& ws) const; //! \brief Loads per-segment data from restart structures. @@ -90,7 +90,7 @@ private: const bool handle_ms_well, const std::vector& phs, const data::Well& rst_well, - const std::vector& old_perf_data, + const std::vector>& old_perf_data, SingleWellState& ws) const; //! \brief Loads per-group data from restart structures. diff --git a/opm/simulators/wells/MultisegmentWell.hpp b/opm/simulators/wells/MultisegmentWell.hpp index d197cc43d..084636ef3 100644 --- a/opm/simulators/wells/MultisegmentWell.hpp +++ b/opm/simulators/wells/MultisegmentWell.hpp @@ -76,7 +76,7 @@ namespace Opm const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); void init(const PhaseUsage* phase_usage_arg, const std::vector& depth_arg, diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 37114c62a..62172dacd 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -65,7 +65,7 @@ namespace Opm const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : Base(well, pw_info, time_step, param, rate_converter, pvtRegionIdx, num_components, num_phases, index_of_well, perf_data) , MSWEval(static_cast&>(*this)) , regularize_(false) diff --git a/opm/simulators/wells/PerforationData.hpp b/opm/simulators/wells/PerforationData.hpp index 5a92d6bc9..38504e893 100644 --- a/opm/simulators/wells/PerforationData.hpp +++ b/opm/simulators/wells/PerforationData.hpp @@ -22,15 +22,15 @@ #include -namespace Opm -{ +namespace Opm { /// Static data associated with a well perforation. +template struct PerforationData { int cell_index{}; - double connection_transmissibility_factor{}; - double connection_d_factor{}; + Scalar connection_transmissibility_factor{}; + Scalar connection_d_factor{}; int satnum_id{}; /// \brief The original index of the perforation in ECL Schedule std::size_t ecl_index{}; diff --git a/opm/simulators/wells/SingleWellState.cpp b/opm/simulators/wells/SingleWellState.cpp index ac9fe1c27..68c62fb2a 100644 --- a/opm/simulators/wells/SingleWellState.cpp +++ b/opm/simulators/wells/SingleWellState.cpp @@ -34,7 +34,7 @@ SingleWellState(const std::string& name_, const ParallelWellInfo& pinfo, bool is_producer, Scalar pressure_first_connection, - const std::vector& perf_input, + const std::vector>& perf_input, const PhaseUsage& pu_, Scalar temp) : name(name_) @@ -138,7 +138,7 @@ void SingleWellState::updateStatus(Well::Status new_status) template void SingleWellState:: -reset_connection_factors(const std::vector& new_perf_data) +reset_connection_factors(const std::vector>& new_perf_data) { if (this->perf_data.size() != new_perf_data.size()) { throw std::invalid_argument { diff --git a/opm/simulators/wells/SingleWellState.hpp b/opm/simulators/wells/SingleWellState.hpp index 8383e1ee0..e78cd4c20 100644 --- a/opm/simulators/wells/SingleWellState.hpp +++ b/opm/simulators/wells/SingleWellState.hpp @@ -33,7 +33,7 @@ namespace Opm { -struct PerforationData; +template struct PerforationData; class SummaryState; class Well; @@ -44,7 +44,7 @@ public: const ParallelWellInfo& pinfo, bool is_producer, Scalar presssure_first_connection, - const std::vector& perf_input, + const std::vector>& perf_input, const PhaseUsage& pu, Scalar temp); @@ -120,7 +120,7 @@ public: /// \param[in] new_perf_data New perforation data. Only /// PerforationData::connection_transmissibility_factor actually /// used (overwrites existing internal values). - void reset_connection_factors(const std::vector& new_perf_data); + void reset_connection_factors(const std::vector>& new_perf_data); void update_producer_targets(const Well& ecl_well, const SummaryState& st); void update_injector_targets(const Well& ecl_well, const SummaryState& st); void update_targets(const Well& ecl_well, const SummaryState& st); diff --git a/opm/simulators/wells/StandardWell.hpp b/opm/simulators/wells/StandardWell.hpp index a88bf3eed..923f3126f 100644 --- a/opm/simulators/wells/StandardWell.hpp +++ b/opm/simulators/wells/StandardWell.hpp @@ -128,7 +128,7 @@ namespace Opm const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); virtual void init(const PhaseUsage* phase_usage_arg, const std::vector& depth_arg, diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index aaeca7e5b..2578dc166 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -78,7 +78,7 @@ namespace Opm const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : Base(well, pw_info, time_step, param, rate_converter, pvtRegionIdx, num_components, num_phases, index_of_well, perf_data) , StdWellEval(static_cast&>(*this)) , regularize_(false) diff --git a/opm/simulators/wells/WellFilterCake.cpp b/opm/simulators/wells/WellFilterCake.cpp index 9ae8f4e2c..bb12dc184 100644 --- a/opm/simulators/wells/WellFilterCake.cpp +++ b/opm/simulators/wells/WellFilterCake.cpp @@ -25,6 +25,7 @@ #include +#include #include #include diff --git a/opm/simulators/wells/WellInterface.hpp b/opm/simulators/wells/WellInterface.hpp index 25018ed43..2d9384749 100644 --- a/opm/simulators/wells/WellInterface.hpp +++ b/opm/simulators/wells/WellInterface.hpp @@ -60,7 +60,6 @@ namespace Opm { #include -#include #include namespace Opm @@ -142,7 +141,7 @@ public: const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); /// Virtual destructor virtual ~WellInterface() = default; diff --git a/opm/simulators/wells/WellInterfaceFluidSystem.cpp b/opm/simulators/wells/WellInterfaceFluidSystem.cpp index 51aeb45db..8dae9df55 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.cpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.cpp @@ -53,7 +53,7 @@ WellInterfaceFluidSystem(const Well& well, const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : WellInterfaceGeneric(well, parallel_well_info, time_step, pvtRegionIdx, num_components, num_phases, index_of_well, perf_data) diff --git a/opm/simulators/wells/WellInterfaceFluidSystem.hpp b/opm/simulators/wells/WellInterfaceFluidSystem.hpp index 4949066dd..eacd611ca 100644 --- a/opm/simulators/wells/WellInterfaceFluidSystem.hpp +++ b/opm/simulators/wells/WellInterfaceFluidSystem.hpp @@ -75,7 +75,7 @@ protected: const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); // updating the voidage rates in well_state when requested void calculateReservoirRates(SingleWellState& ws) const; diff --git a/opm/simulators/wells/WellInterfaceGeneric.cpp b/opm/simulators/wells/WellInterfaceGeneric.cpp index 1b186bdca..4c472462d 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.cpp +++ b/opm/simulators/wells/WellInterfaceGeneric.cpp @@ -60,7 +60,7 @@ WellInterfaceGeneric(const Well& well, const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : well_ecl_(well) , parallel_well_info_(pw_info) , current_step_(time_step) @@ -143,7 +143,7 @@ adaptRatesForVFP(std::vector& rates) const } template -const std::vector& +const std::vector>& WellInterfaceGeneric::perforationData() const { return *perf_data_; diff --git a/opm/simulators/wells/WellInterfaceGeneric.hpp b/opm/simulators/wells/WellInterfaceGeneric.hpp index 715ef8290..c8d16cf1e 100644 --- a/opm/simulators/wells/WellInterfaceGeneric.hpp +++ b/opm/simulators/wells/WellInterfaceGeneric.hpp @@ -37,7 +37,7 @@ namespace Opm class DeferredLogger; class GuideRate; class ParallelWellInfo; -struct PerforationData; +template struct PerforationData; struct PhaseUsage; class SummaryState; template class VFPProperties; @@ -57,10 +57,10 @@ public: const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); /// \brief Get the perforations of the well - const std::vector& perforationData() const; + const std::vector>& perforationData() const; /// Well name. const std::string& name() const; @@ -286,7 +286,7 @@ protected: // the index of well in Wells struct int index_of_well_; - const std::vector* perf_data_; + const std::vector>* perf_data_; // the vectors used to describe the inflow performance relationship (IPR) // Q = IPR_A - BHP * IPR_B diff --git a/opm/simulators/wells/WellInterfaceIndices.cpp b/opm/simulators/wells/WellInterfaceIndices.cpp index b0d672922..e564cef04 100644 --- a/opm/simulators/wells/WellInterfaceIndices.cpp +++ b/opm/simulators/wells/WellInterfaceIndices.cpp @@ -43,7 +43,7 @@ WellInterfaceIndices(const Well& well, const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : WellInterfaceFluidSystem(well, parallel_well_info, time_step, diff --git a/opm/simulators/wells/WellInterfaceIndices.hpp b/opm/simulators/wells/WellInterfaceIndices.hpp index 0671ba4b7..c87c6590c 100644 --- a/opm/simulators/wells/WellInterfaceIndices.hpp +++ b/opm/simulators/wells/WellInterfaceIndices.hpp @@ -63,7 +63,7 @@ protected: const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data); + const std::vector>& perf_data); }; } diff --git a/opm/simulators/wells/WellInterface_impl.hpp b/opm/simulators/wells/WellInterface_impl.hpp index b8011d0eb..391eeb6bc 100644 --- a/opm/simulators/wells/WellInterface_impl.hpp +++ b/opm/simulators/wells/WellInterface_impl.hpp @@ -40,6 +40,7 @@ #include +#include #include #include @@ -60,7 +61,7 @@ namespace Opm const int num_components, const int num_phases, const int index_of_well, - const std::vector& perf_data) + const std::vector>& perf_data) : WellInterfaceIndices(well, pw_info, time_step, diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index 42708dc9a..d88fc656c 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include @@ -150,7 +151,7 @@ template void WellState::base_init(const std::vector& cellPressures, const std::vector& wells_ecl, const std::vector>& parallel_well_info, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state) { // clear old name mapping @@ -172,7 +173,7 @@ template void WellState::initSingleProducer(const Well& well, const ParallelWellInfo& well_info, Scalar pressure_first_connection, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const SummaryState& summary_state) { const auto& pu = this->phase_usage_; @@ -201,7 +202,7 @@ template void WellState::initSingleInjector(const Well& well, const ParallelWellInfo& well_info, Scalar pressure_first_connection, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const SummaryState& summary_state) { const auto& pu = this->phase_usage_; @@ -228,7 +229,7 @@ void WellState::initSingleInjector(const Well& well, template void WellState::initSingleWell(const std::vector& cellPressures, const Well& well, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const ParallelWellInfo& well_info, const SummaryState& summary_state) { @@ -253,7 +254,7 @@ void WellState::init(const std::vector& cellPressures, const std::vector>& parallel_well_info, const int report_step, const WellState* prevState, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state) { // call init on base class @@ -423,7 +424,7 @@ void WellState::resize(const std::vector& wells_ecl, const Schedule& schedule, const bool handle_ms_well, const std::size_t numCells, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state) { const std::vector tmp(numCells, 0.0); // <- UGLY HACK to pass the size diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index a80b5dc2f..5541ab475 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -52,6 +51,7 @@ namespace Opm { class ParallelWellInfo; +template struct PerforationData; class Schedule; enum class WellStatus; @@ -102,7 +102,7 @@ public: const std::vector>& parallel_well_info, const int report_step, const WellState* prevState, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state); void resize(const std::vector& wells_ecl, @@ -110,7 +110,7 @@ public: const Schedule& schedule, const bool handle_ms_well, const std::size_t numCells, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state); void setCurrentWellRates(const std::string& wellName, @@ -379,25 +379,25 @@ private: void base_init(const std::vector& cellPressures, const std::vector& wells_ecl, const std::vector>& parallel_well_info, - const std::vector>& well_perf_data, + const std::vector>>& well_perf_data, const SummaryState& summary_state); void initSingleWell(const std::vector& cellPressures, const Well& well, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const ParallelWellInfo& well_info, const SummaryState& summary_state); void initSingleProducer(const Well& well, const ParallelWellInfo& well_info, Scalar pressure_first_connection, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const SummaryState& summary_state); void initSingleInjector(const Well& well, const ParallelWellInfo& well_info, Scalar pressure_first_connection, - const std::vector& well_perf_data, + const std::vector>& well_perf_data, const SummaryState& summary_state); }; diff --git a/tests/test_wellmodel.cpp b/tests/test_wellmodel.cpp index 24a61994c..96b1982c6 100644 --- a/tests/test_wellmodel.cpp +++ b/tests/test_wellmodel.cpp @@ -83,7 +83,7 @@ struct SetupTest { std::shared_ptr python; std::unique_ptr schedule; std::unique_ptr summaryState; - std::vector> well_perf_data; + std::vector>> well_perf_data; int current_timestep; }; @@ -125,8 +125,8 @@ BOOST_AUTO_TEST_CASE(TestStandardWellInput) { rateConverter.reset(new RateConverterType (phaseUsage, std::vector(10, 0))); - Opm::PerforationData dummy; - std::vector pdata(well.getConnections().size(), dummy); + Opm::PerforationData dummy; + std::vector> pdata(well.getConnections().size(), dummy); for (auto c = 0*pdata.size(); c < pdata.size(); ++c) { pdata[c].ecl_index = c; } @@ -160,8 +160,8 @@ BOOST_AUTO_TEST_CASE(TestBehavoir) { // Compute reservoir volumes for RESV controls. rateConverter.reset(new RateConverterType (phaseUsage, std::vector(10, 0))); - Opm::PerforationData dummy; - std::vector pdata(wells_ecl[w].getConnections().size(), dummy); + Opm::PerforationData dummy; + std::vector> pdata(wells_ecl[w].getConnections().size(), dummy); for (auto c = 0*pdata.size(); c < pdata.size(); ++c) { pdata[c].ecl_index = c; } diff --git a/tests/test_wellstate.cpp b/tests/test_wellstate.cpp index 7e929c31f..274098c80 100644 --- a/tests/test_wellstate.cpp +++ b/tests/test_wellstate.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -106,7 +107,7 @@ struct Setup + std::to_string(k) + " not found in grid (well = " + well.name() + ")."); OPM_THROW(std::runtime_error, msg); } else { - Opm::PerforationData pd; + Opm::PerforationData pd; pd.cell_index = active_index; pd.connection_transmissibility_factor = completion.CF(); pd.connection_d_factor = completion.dFactor(); @@ -132,7 +133,7 @@ struct Setup std::shared_ptr python; Opm::Schedule sched; Opm::SummaryState st; - std::vector> well_perf_data; + std::vector>> well_perf_data; }; namespace { @@ -581,7 +582,7 @@ BOOST_AUTO_TEST_CASE(TESTPerfData) { BOOST_AUTO_TEST_CASE(TestSingleWellState) { Opm::ParallelWellInfo pinfo; - std::vector connections = {{0,1,1,0,0},{1,1,1,0,1},{2,1,1,0,2}}; + std::vector> connections = {{0,1,1,0,0},{1,1,1,0,1},{2,1,1,0,2}}; Opm::PhaseUsage pu; // This is totally bonkers, but the pu needs a complete deck to initialize properly