From f01cf74591d8b61a1d8b2332cbf6d5cd476e9b6a Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 4 Aug 2021 14:19:02 +0200 Subject: [PATCH] Merge two perforation data members in WellState --- opm/simulators/wells/PerfData.cpp | 24 +++++++++------ opm/simulators/wells/PerfData.hpp | 6 ++++ opm/simulators/wells/WellState.cpp | 49 +++++++++++++++--------------- opm/simulators/wells/WellState.hpp | 1 - 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/opm/simulators/wells/PerfData.cpp b/opm/simulators/wells/PerfData.cpp index 5d822d9e3..1b53e1875 100644 --- a/opm/simulators/wells/PerfData.cpp +++ b/opm/simulators/wells/PerfData.cpp @@ -24,16 +24,20 @@ namespace Opm { -PerfData::PerfData(std::size_t num_perf, bool injector_, const PhaseUsage& pu_arg): - pu(pu_arg), - injector(injector_), - pressure(num_perf), - rates(num_perf), - phase_rates(num_perf * pu.num_phases), - solvent_rates(num_perf), - polymer_rates(num_perf), - brine_rates(num_perf), - prod_index(num_perf * pu.num_phases) +PerfData::PerfData(std::size_t num_perf, bool injector_, const PhaseUsage& pu_arg) + : pu(pu_arg) + , injector(injector_) + , pressure(num_perf) + , rates(num_perf) + , phase_rates(num_perf * pu.num_phases) + , solvent_rates(num_perf) + , polymer_rates(num_perf) + , brine_rates(num_perf) + , prod_index(num_perf * pu.num_phases) + , cell_index(num_perf) + , connection_transmissibility_factor(num_perf) + , satnum_id(num_perf) + , ecl_index(num_perf) { if (injector) { this->water_throughput.resize(num_perf); diff --git a/opm/simulators/wells/PerfData.hpp b/opm/simulators/wells/PerfData.hpp index b663bfe72..b68bed88e 100644 --- a/opm/simulators/wells/PerfData.hpp +++ b/opm/simulators/wells/PerfData.hpp @@ -48,6 +48,12 @@ public: std::vector brine_rates; std::vector prod_index; + std::vector cell_index; + std::vector connection_transmissibility_factor; + std::vector satnum_id; + std::vector ecl_index; + + // The water_throughput, skin_pressure and water_velocity variables are only // used for injectors to check the injectivity. std::vector water_throughput; diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index 3439f8ad6..90b31b35a 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -42,7 +42,6 @@ void WellState::base_init(const std::vector& cellPressures, this->wellMap_.clear(); this->perfdata.clear(); this->status_.clear(); - this->well_perf_data_.clear(); this->parallel_well_info_.clear(); this->wellrates_.clear(); this->bhp_.clear(); @@ -94,11 +93,10 @@ void WellState::initSingleWell(const std::vector& cellPressures, const int np = pu.num_phases; this->status_.add(well.name(), Well::Status::OPEN); - this->well_perf_data_.add(well.name(), well_perf_data); this->parallel_well_info_.add(well.name(), well_info); this->wellrates_.add(well.name(), std::vector(np, 0)); this->well_potentials_.add(well.name(), std::vector(np, 0)); - const int num_perf_this_well = well_info->communication().sum(well_perf_data_[w].size()); + const int num_perf_this_well = well_info->communication().sum(well_perf_data.size()); this->segment_state.add(well.name(), SegmentState{}); this->perfdata.add(well.name(), PerfData{static_cast(num_perf_this_well), well.isInjector(), this->phase_usage_}); this->bhp_.add(well.name(), 0.0); @@ -123,8 +121,8 @@ void WellState::initSingleWell(const std::vector& cellPressures, const double inj_surf_rate = well.isInjector() ? inj_controls.surface_rate : 0.0; // To avoid a "maybe-uninitialized" warning. - const double local_pressure = well_perf_data_[w].empty() ? - 0 : cellPressures[well_perf_data_[w][0].cell_index]; + const double local_pressure = well_perf_data.empty() ? + 0 : cellPressures[well_perf_data[0].cell_index]; const double global_pressure = well_info->broadcastFirstPerforationValue(local_pressure); if (well.getStatus() == Well::Status::OPEN) { @@ -288,8 +286,14 @@ void WellState::init(const std::vector& cellPressures, const int num_perf_this_well = well_info[2]; const int global_num_perf_this_well = ecl_well.getConnections().num_open(); auto& perf_data = this->perfData(w); + const auto& perf_input = well_perf_data[w]; for (int perf = 0; perf < num_perf_this_well; ++perf) { + perf_data.cell_index[perf] = perf_input[perf].cell_index; + perf_data.connection_transmissibility_factor[perf] = perf_input[perf].connection_transmissibility_factor; + perf_data.satnum_id[perf] = perf_input[perf].satnum_id; + perf_data.ecl_index[perf] = perf_input[perf].ecl_index; + if (wells_ecl[w].getStatus() == Well::Status::OPEN) { for (int p = 0; p < this->numPhases(); ++p) { perf_data.phase_rates[this->numPhases()*perf + p] = wellRates(w)[p] / double(global_num_perf_this_well); @@ -601,19 +605,18 @@ void WellState::reportConnections(std::vector& connections, const int* globalCellIdxMap) const { using rt = data::Rates::opt; - const auto& pd = this->well_perf_data_[well_index]; - const int num_perf_well = pd.size(); - connections.resize(num_perf_well); const auto& perf_data = this->perfData(well_index); + const int num_perf_well = perf_data.size(); + connections.resize(num_perf_well); const auto& perf_rates = perf_data.rates; const auto& perf_pressure = perf_data.pressure; for( int i = 0; i < num_perf_well; ++i ) { - const auto active_index = this->well_perf_data_[well_index][i].cell_index; + const auto active_index = perf_data.cell_index[i]; auto& connection = connections[ i ]; connection.index = globalCellIdxMap[active_index]; connection.pressure = perf_pressure[i]; connection.reservoir_rate = perf_rates[i]; - connection.trans_factor = pd[i].connection_transmissibility_factor; + connection.trans_factor = perf_data.connection_transmissibility_factor[i]; } assert(num_perf_well == int(connections.size())); @@ -659,7 +662,7 @@ void WellState::reportConnections(std::vector& connections, ++local_comp_index; } - assert(local_comp_index == this->well_perf_data_[well_index].size()); + assert(local_comp_index == this->perfdata[well_index].size()); } void WellState::initWellStateMSWell(const std::vector& wells_ecl, @@ -1032,41 +1035,37 @@ void WellState::updateWellsDefaultALQ( const std::vector& wells_ecl ) } void WellState::resetConnectionTransFactors(const int well_index, - const std::vector& well_perf_data) + const std::vector& new_perf_data) { - if (this->well_perf_data_[well_index].size() != well_perf_data.size()) { + if (this->perfdata[well_index].size() != new_perf_data.size()) { throw std::invalid_argument { "Size mismatch for perforation data in well " + std::to_string(well_index) }; } - auto connID = std::size_t{0}; - auto dst = this->well_perf_data_[well_index].begin(); - for (const auto& src : well_perf_data) { - if (dst->cell_index != src.cell_index) { + auto& perf_data = this->perfData(well_index); + for (std::size_t conn_index = 0; conn_index < new_perf_data.size(); conn_index++) { + + if (perf_data.cell_index[conn_index] != static_cast(new_perf_data[conn_index].cell_index)) { throw std::invalid_argument { "Cell index mismatch in connection " - + std::to_string(connID) + + std::to_string(conn_index) + " of well " + std::to_string(well_index) }; } - if (dst->satnum_id != src.satnum_id) { + if (perf_data.satnum_id[conn_index] != new_perf_data[conn_index].satnum_id) { throw std::invalid_argument { "Saturation function table mismatch in connection " - + std::to_string(connID) + + std::to_string(conn_index) + " of well " + std::to_string(well_index) }; } - dst->connection_transmissibility_factor = - src.connection_transmissibility_factor; - - ++dst; - ++connID; + perf_data.connection_transmissibility_factor[conn_index] = new_perf_data[conn_index].connection_transmissibility_factor; } } diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index 9aec91607..d8ac6b40b 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -363,7 +363,6 @@ private: bool do_glift_optimization_; WellContainer status_; - WellContainer> well_perf_data_; WellContainer parallel_well_info_; WellContainer bhp_; WellContainer thp_;