From 76838cd8a4088718dac15a5ba4c77a4f1cfe6347 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Sat, 5 Jun 2021 08:52:18 +0200 Subject: [PATCH] Use PerfData for perforation pressure --- .../wells/BlackoilWellModelGeneric.cpp | 10 ++++---- .../wells/MultisegmentWell_impl.hpp | 3 ++- opm/simulators/wells/PerfData.cpp | 18 ++++++++++++++ opm/simulators/wells/PerfData.hpp | 2 ++ opm/simulators/wells/StandardWell_impl.hpp | 6 ++--- opm/simulators/wells/WellState.cpp | 20 +++++++--------- opm/simulators/wells/WellState.hpp | 10 +------- tests/test_wellstate.cpp | 24 +++++++++++++++++-- 8 files changed, 62 insertions(+), 31 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index a8262a7f3..8bdc386eb 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -188,13 +188,15 @@ loadRestartData(const data::Wells& rst_wells, well_state.wellRates(well_index)[i] = rst_well.rates.get(phs[i]); } - auto& perf_pressure = well_state.perfPress(well_index); auto& perf_rates = well_state.perfRates(well_index); auto& perf_phase_rates = well_state.perfPhaseRates(well_index); - const auto& perf_data = this->well_perf_data_[well_index]; - for (std::size_t perf_index = 0; perf_index < perf_data.size(); perf_index++) { - const auto& pd = perf_data[perf_index]; + auto& perf_data = well_state.perfData(well_index); + auto& perf_pressure = perf_data.pressure; + const auto& old_perf_data = this->well_perf_data_[well_index]; + + for (std::size_t perf_index = 0; perf_index < old_perf_data.size(); perf_index++) { + const auto& pd = old_perf_data[perf_index]; const auto& rst_connection = rst_well.connections[pd.ecl_index]; perf_pressure[perf_index] = rst_connection.pressure; perf_rates[perf_index] = rst_connection.reservoir_rate; diff --git a/opm/simulators/wells/MultisegmentWell_impl.hpp b/opm/simulators/wells/MultisegmentWell_impl.hpp index 07e8ee93f..70bb88322 100644 --- a/opm/simulators/wells/MultisegmentWell_impl.hpp +++ b/opm/simulators/wells/MultisegmentWell_impl.hpp @@ -1247,8 +1247,9 @@ namespace Opm // calculating the perforation rate for each perforation that belongs to this segment const EvalWell seg_pressure = this->getSegmentPressure(seg); + auto& perf_data = well_state.perfData(this->index_of_well_); auto& perf_rates = well_state.perfPhaseRates(this->index_of_well_); - auto& perf_press_state = well_state.perfPress(this->index_of_well_); + auto& perf_press_state = perf_data.pressure; for (const int perf : this->segment_perforations_[seg]) { const int cell_idx = well_cells_[perf]; const auto& int_quants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/ 0)); diff --git a/opm/simulators/wells/PerfData.cpp b/opm/simulators/wells/PerfData.cpp index 9bb2d55a4..67dbc363b 100644 --- a/opm/simulators/wells/PerfData.cpp +++ b/opm/simulators/wells/PerfData.cpp @@ -44,5 +44,23 @@ std::size_t PerfData::size() const { return this->pressure.size(); } +bool PerfData::try_assign(const PerfData& other) { + if (this->size() != other.size()) + return false; + + this->pressure = other.pressure; + this->rates = other.rates; + this->phase_rates = other.phase_rates; + this->solvent_rates = other.solvent_rates; + this->polymer_rates = other.polymer_rates; + this->brine_rates = other.brine_rates; + this->water_throughput = other.water_throughput; + this->skin_pressure = other.skin_pressure; + this->water_velocity = other.water_velocity; + this->prod_index = other.prod_index; + + return true; +} + } diff --git a/opm/simulators/wells/PerfData.hpp b/opm/simulators/wells/PerfData.hpp index 68a5b1395..d800d9d6f 100644 --- a/opm/simulators/wells/PerfData.hpp +++ b/opm/simulators/wells/PerfData.hpp @@ -36,6 +36,8 @@ private: public: PerfData(std::size_t num_perf, const PhaseUsage& pu); std::size_t size() const; + bool try_assign(const PerfData& other); + std::vector pressure; std::vector rates; diff --git a/opm/simulators/wells/StandardWell_impl.hpp b/opm/simulators/wells/StandardWell_impl.hpp index e583a6ab1..28bd7abca 100644 --- a/opm/simulators/wells/StandardWell_impl.hpp +++ b/opm/simulators/wells/StandardWell_impl.hpp @@ -463,8 +463,8 @@ namespace Opm } // Store the perforation pressure for later usage. - auto& perf_press = well_state.perfPress(index_of_well_); - perf_press[perf] = well_state.bhp(index_of_well_) + this->perf_pressure_diffs_[perf]; + auto& perf_data = well_state.perfData(this->index_of_well_); + perf_data.pressure[perf] = well_state.bhp(this->index_of_well_) + this->perf_pressure_diffs_[perf]; } @@ -922,7 +922,7 @@ namespace Opm } // Compute the average pressure in each well block - const auto& perf_press = well_state.perfPress(w); + const auto& perf_press = well_state.perfData(w).pressure; auto p_above = this->parallel_well_info_.communicateAboveValues(well_state.bhp(w), perf_press.data(), nperf); diff --git a/opm/simulators/wells/WellState.cpp b/opm/simulators/wells/WellState.cpp index 5e71d77d7..0b134b67d 100644 --- a/opm/simulators/wells/WellState.cpp +++ b/opm/simulators/wells/WellState.cpp @@ -40,7 +40,6 @@ void WellState::base_init(const std::vector& cellPressures, { // clear old name mapping this->wellMap_.clear(); - this->perfpress_.clear(); this->perfdata.clear(); this->perf_skin_pressure_.clear(); this->perf_water_throughput_.clear(); @@ -110,7 +109,6 @@ void WellState::initSingleWell(const std::vector& cellPressures, const int num_perf_this_well = well_info->communication().sum(well_perf_data_[w].size()); this->segment_state.add(well.name(), SegmentState{}); this->perfdata.add(well.name(), PerfData{num_perf_this_well, this->phase_usage_}); - this->perfpress_.add(well.name(), std::vector(num_perf_this_well, -1e100)); this->perfphaserates_.add(well.name(), std::vector(np*num_perf_this_well, 0)); this->perf_skin_pressure_.add(well.name(), std::vector(num_perf_this_well, 0)); this->perf_water_velocity_.add(well.name(), std::vector(num_perf_this_well, 0)); @@ -304,7 +302,7 @@ void WellState::init(const std::vector& cellPressures, const auto& well_info = this->wellMap().at(wname); const int num_perf_this_well = well_info[2]; const int global_num_perf_this_well = ecl_well.getConnections().num_open(); - auto& perf_press = this->perfPress(w); + auto& perf_data = this->perfData(w); auto& phase_rates = this->perfPhaseRates(w); @@ -314,7 +312,7 @@ void WellState::init(const std::vector& cellPressures, phase_rates[this->numPhases()*perf + p] = wellRates(w)[p] / double(global_num_perf_this_well); } } - perf_press[perf] = cellPressures[well_perf_data[w][perf].cell_index]; + perf_data.pressure[perf] = cellPressures[well_perf_data[w][perf].cell_index]; } this->well_reservoir_rates_.add(wname, std::vector(np, 0)); @@ -449,12 +447,9 @@ void WellState::init(const std::vector& cellPressures, // perfPressures if (global_num_perf_same) { - auto& target_press = perfPress(w); - const auto& src_press = prevState->perfPress(well.name()); - for (int perf = 0; perf < num_perf_this_well; ++perf) - { - target_press[perf] = src_press[perf]; - } + auto& perf_data = this->perfData(w); + const auto& prev_perf_data = prevState->perfData(w); + perf_data.try_assign( prev_perf_data ); } // perfSolventRates @@ -710,7 +705,7 @@ void WellState::reportConnections(data::Well& well, well.connections.resize(num_perf_well); const auto& perf_data = this->perfData(well_index); const auto& perf_rates = perf_data.rates; - const auto& perf_pressure = this->perfPress(well_index); + 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; auto& connection = well.connections[ i ]; @@ -816,6 +811,7 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, } + auto& perf_data = this->perfData(w); // for the seg_rates_, now it becomes a recursive solution procedure. { // make sure the information from wells_ecl consistent with wells @@ -849,7 +845,7 @@ void WellState::initWellStateMSWell(const std::vector& wells_ecl, // top segment is always the first one, and its pressure is the well bhp auto& segment_pressure = this->segments(w).pressure; segment_pressure[0] = bhp(w); - const auto& perf_press = this->perfPress(w); + const auto& perf_press = perf_data.pressure; for (int seg = 1; seg < well_nseg; ++seg) { if ( !segment_perforations[seg].empty() ) { const int first_perf = segment_perforations[seg][0]; diff --git a/opm/simulators/wells/WellState.hpp b/opm/simulators/wells/WellState.hpp index afca21e98..59b2e44f1 100644 --- a/opm/simulators/wells/WellState.hpp +++ b/opm/simulators/wells/WellState.hpp @@ -398,14 +398,7 @@ public: std::vector& wellRates(std::size_t well_index) { return wellrates_[well_index]; } const std::vector& wellRates(std::size_t well_index) const { return wellrates_[well_index]; } - /// One pressure per well connection. - std::vector& perfPress(std::size_t well_index) { return perfpress_[well_index]; } - const std::vector& perfPress(std::size_t well_index) const { return perfpress_[well_index]; } - std::vector& perfPress(const std::string& wname) { return perfpress_[wname]; } - const std::vector& perfPress(const std::string& wname) const { return perfpress_[wname]; } - - - std::size_t numPerf(std::size_t well_index) const { return this->perfpress_[well_index].size(); } + std::size_t numPerf(std::size_t well_index) const { return this->perfdata[well_index].size(); } PerfData& perfData(const std::string& wname) { return this->perfdata[wname]; @@ -441,7 +434,6 @@ private: WellContainer> wellrates_; PhaseUsage phase_usage_; WellContainer perfdata; - WellContainer> perfpress_; WellContainer> perfphaserates_; WellContainer is_producer_; // Size equal to number of local wells. diff --git a/tests/test_wellstate.cpp b/tests/test_wellstate.cpp index c132352c9..437590fa8 100644 --- a/tests/test_wellstate.cpp +++ b/tests/test_wellstate.cpp @@ -358,7 +358,8 @@ BOOST_AUTO_TEST_CASE(STOP_well) std::vector pinfos; auto wstate = buildWellState(setup, 0, pinfos); for (std::size_t well_index = 0; well_index < setup.sched.numWells(0); well_index++) { - for (const auto& p : wstate.perfPress(well_index)) + const auto& perf_data = wstate.perfData(well_index); + for (const auto& p : perf_data.pressure) BOOST_CHECK(p > 0); } } @@ -544,7 +545,26 @@ GAS )"; Opm::PhaseUsage pu = Opm::phaseUsageFromDeck(Opm::Parser{}.parseString(deck_string)); - Opm::PerfData pd(100,pu); + Opm::PerfData pd1(3,pu); + Opm::PerfData pd2(3,pu); + Opm::PerfData pd3(2,pu); + + + for (std::size_t i = 0; i < 3; i++) { + pd1.pressure[i] = i+1; + pd2.pressure[i] = 10*(i+1); + } + + BOOST_CHECK(pd1.try_assign(pd2)); + for (std::size_t i = 0; i < 3; i++) { + BOOST_CHECK(pd2.pressure[i] == 10*(i+1)); + BOOST_CHECK(pd1.pressure[i] == 10*(i+1)); + } + + BOOST_CHECK(!pd1.try_assign(pd3)); + for (std::size_t i = 0; i < 3; i++) { + BOOST_CHECK(pd1.pressure[i] == 10*(i+1)); + } }