2014-03-18 05:23:05 -05:00
|
|
|
/*
|
|
|
|
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
2017-10-06 03:59:42 -05:00
|
|
|
Copyright 2017 IRIS AS
|
2014-03-18 05:23:05 -05:00
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
|
|
|
#define OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|
|
|
|
|
2021-04-27 15:26:08 -05:00
|
|
|
#include <opm/simulators/wells/ALQState.hpp>
|
2021-08-03 13:05:14 -05:00
|
|
|
#include <opm/simulators/wells/SingleWellState.hpp>
|
2021-04-28 03:22:29 -05:00
|
|
|
#include <opm/simulators/wells/GlobalWellInfo.hpp>
|
2021-05-30 12:39:26 -05:00
|
|
|
#include <opm/simulators/wells/SegmentState.hpp>
|
2021-05-07 04:21:58 -05:00
|
|
|
#include <opm/simulators/wells/WellContainer.hpp>
|
2016-09-20 02:43:58 -05:00
|
|
|
#include <opm/core/props/BlackoilPhases.hpp>
|
2021-05-20 05:03:38 -05:00
|
|
|
#include <opm/simulators/wells/PerforationData.hpp>
|
2021-06-04 07:12:54 -05:00
|
|
|
#include <opm/simulators/wells/PerfData.hpp>
|
2021-05-20 05:03:38 -05:00
|
|
|
#include <opm/output/data/Wells.hpp>
|
2019-03-25 08:43:36 -05:00
|
|
|
|
2021-05-12 16:20:40 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
|
2019-11-13 16:16:11 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
|
2019-03-25 08:43:36 -05:00
|
|
|
|
2021-05-25 05:57:11 -05:00
|
|
|
#include <dune/common/version.hh>
|
|
|
|
#include <dune/common/parallel/mpihelper.hh>
|
|
|
|
|
2021-03-01 08:43:43 -06:00
|
|
|
#include <functional>
|
2020-10-09 06:38:33 -05:00
|
|
|
#include <map>
|
2021-04-28 03:22:29 -05:00
|
|
|
#include <optional>
|
2020-10-09 06:38:33 -05:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2014-03-18 05:23:05 -05:00
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
class ParallelWellInfo;
|
|
|
|
class Schedule;
|
2021-05-12 16:20:40 -05:00
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
/// The state of a set of wells, tailored for use by the fully
|
|
|
|
/// implicit blackoil simulator.
|
2021-05-20 06:32:18 -05:00
|
|
|
class WellState
|
2021-05-12 17:40:03 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const uint64_t event_mask = ScheduleEvents::WELL_STATUS_CHANGE + ScheduleEvents::PRODUCTION_UPDATE + ScheduleEvents::INJECTION_UPDATE;
|
|
|
|
|
2021-05-20 06:32:18 -05:00
|
|
|
virtual ~WellState() = default;
|
2021-05-12 17:40:03 -05:00
|
|
|
|
|
|
|
// TODO: same definition with WellInterface, eventually they should go to a common header file.
|
|
|
|
static const int Water = BlackoilPhases::Aqua;
|
|
|
|
static const int Oil = BlackoilPhases::Liquid;
|
|
|
|
static const int Gas = BlackoilPhases::Vapour;
|
|
|
|
|
2021-05-20 06:32:18 -05:00
|
|
|
explicit WellState(const PhaseUsage& pu)
|
2021-05-12 17:40:03 -05:00
|
|
|
{
|
2021-05-20 05:03:38 -05:00
|
|
|
this->phase_usage_ = pu;
|
2021-05-12 17:40:03 -05:00
|
|
|
}
|
|
|
|
|
2021-07-26 07:09:06 -05:00
|
|
|
std::size_t size() const {
|
2021-08-06 06:18:18 -05:00
|
|
|
return this->wells_.size();
|
2021-07-26 07:09:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-20 03:41:01 -05:00
|
|
|
int numWells() const
|
|
|
|
{
|
2021-07-26 07:09:06 -05:00
|
|
|
return this->size();
|
2021-05-20 03:41:01 -05:00
|
|
|
}
|
|
|
|
|
2021-05-20 04:02:00 -05:00
|
|
|
const ParallelWellInfo& parallelWellInfo(std::size_t well_index) const;
|
|
|
|
|
|
|
|
|
2021-05-20 03:41:01 -05:00
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
/// Allocate and initialize if wells is non-null. Also tries
|
|
|
|
/// to give useful initial values to the bhp(), wellRates()
|
2021-06-04 03:41:07 -05:00
|
|
|
/// and perfPhaseRatesORG() fields, depending on controls
|
2021-05-12 17:40:03 -05:00
|
|
|
void init(const std::vector<double>& cellPressures,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const std::vector<Well>& wells_ecl,
|
2021-09-27 05:00:39 -05:00
|
|
|
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
|
2021-05-12 17:40:03 -05:00
|
|
|
const int report_step,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState* prevState,
|
2021-05-12 17:40:03 -05:00
|
|
|
const std::vector<std::vector<PerforationData>>& well_perf_data,
|
|
|
|
const SummaryState& summary_state);
|
|
|
|
|
|
|
|
void resize(const std::vector<Well>& wells_ecl,
|
2021-09-27 05:00:39 -05:00
|
|
|
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
|
2021-05-12 17:40:03 -05:00
|
|
|
const Schedule& schedule,
|
|
|
|
const bool handle_ms_well,
|
|
|
|
const size_t numCells,
|
|
|
|
const std::vector<std::vector<PerforationData>>& well_perf_data,
|
|
|
|
const SummaryState& summary_state);
|
|
|
|
|
2021-05-27 08:02:45 -05:00
|
|
|
void setCurrentWellRates(const std::string& wellName, const std::vector<double>& new_rates ) {
|
|
|
|
auto& [owner, rates] = this->well_rates.at(wellName);
|
|
|
|
if (owner)
|
|
|
|
rates = new_rates;
|
2021-05-12 17:40:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<double>& currentWellRates(const std::string& wellName) const;
|
|
|
|
|
|
|
|
bool hasWellRates(const std::string& wellName) const {
|
|
|
|
return this->well_rates.find(wellName) != this->well_rates.end();
|
|
|
|
}
|
|
|
|
|
2021-05-20 03:26:30 -05:00
|
|
|
template<class Communication>
|
|
|
|
void gatherVectorsOnRoot(const std::vector< data::Connection >& from_connections,
|
|
|
|
std::vector< data::Connection >& to_connections,
|
|
|
|
const Communication& comm) const;
|
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
data::Wells
|
|
|
|
report(const int* globalCellIdxMap,
|
2021-05-20 03:26:30 -05:00
|
|
|
const std::function<bool(const int)>& wasDynamicallyClosed) const;
|
2021-05-12 17:40:03 -05:00
|
|
|
|
2021-06-11 07:36:10 -05:00
|
|
|
void reportConnections(std::vector<data::Connection>& connections, const PhaseUsage &pu,
|
|
|
|
std::size_t well_index,
|
2021-05-20 03:32:04 -05:00
|
|
|
const int* globalCellIdxMap) const;
|
2021-05-12 17:40:03 -05:00
|
|
|
|
|
|
|
/// init the MS well related.
|
|
|
|
void initWellStateMSWell(const std::vector<Well>& wells_ecl,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState* prev_well_state);
|
2021-05-12 17:40:03 -05:00
|
|
|
|
|
|
|
static void calculateSegmentRates(const std::vector<std::vector<int>>& segment_inlets, const std::vector<std::vector<int>>&segment_perforations,
|
|
|
|
const std::vector<double>& perforation_rates, const int np, const int segment, std::vector<double>& segment_rates);
|
|
|
|
|
2021-05-30 12:39:26 -05:00
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
template<class Comm>
|
|
|
|
void communicateGroupRates(const Comm& comm);
|
|
|
|
|
|
|
|
template<class Comm>
|
|
|
|
void updateGlobalIsGrup(const Comm& comm);
|
|
|
|
|
|
|
|
bool isInjectionGrup(const std::string& name) const {
|
|
|
|
return this->global_well_info.value().in_injecting_group(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isProductionGrup(const std::string& name) const {
|
|
|
|
return this->global_well_info.value().in_producing_group(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
double getALQ( const std::string& name) const
|
|
|
|
{
|
|
|
|
return this->alq_state.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setALQ( const std::string& name, double value)
|
|
|
|
{
|
|
|
|
this->alq_state.set(name, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gliftCheckAlqOscillation(const std::string &name) const {
|
|
|
|
return this->alq_state.oscillation(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gliftGetAlqDecreaseCount(const std::string &name) {
|
|
|
|
return this->alq_state.get_decrement_count(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gliftGetAlqIncreaseCount(const std::string &name) {
|
|
|
|
return this->alq_state.get_increment_count(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gliftUpdateAlqIncreaseCount(const std::string &name, bool increase) {
|
|
|
|
this->alq_state.update_count(name, increase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gliftTimeStepInit() {
|
|
|
|
this->alq_state.reset_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
int wellNameToGlobalIdx(const std::string &name) {
|
|
|
|
return this->global_well_info.value().well_index(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string globalIdxToWellName(const int index) {
|
|
|
|
return this->global_well_info.value().well_name(index);
|
|
|
|
}
|
|
|
|
|
2021-05-20 03:51:46 -05:00
|
|
|
bool wellIsOwned(std::size_t well_index,
|
|
|
|
const std::string& wellName) const;
|
|
|
|
|
|
|
|
bool wellIsOwned(const std::string& wellName) const;
|
|
|
|
|
2021-05-20 03:59:07 -05:00
|
|
|
/// Special purpose method to support dynamically rescaling a well's
|
|
|
|
/// CTFs through WELPI.
|
|
|
|
///
|
|
|
|
/// \param[in] well_index Process-local linear index of single well.
|
|
|
|
/// Must be in the range 0..numWells()-1.
|
|
|
|
///
|
|
|
|
/// \param[in] well_perf_data New perforation data. Only
|
|
|
|
/// PerforationData::connection_transmissibility_factor actually
|
|
|
|
/// used (overwrites existing internal values).
|
|
|
|
void resetConnectionTransFactors(const int well_index,
|
|
|
|
const std::vector<PerforationData>& well_perf_data);
|
|
|
|
|
2021-05-20 04:14:15 -05:00
|
|
|
void updateStatus(int well_index, Well::Status status);
|
|
|
|
|
2021-09-21 03:32:56 -05:00
|
|
|
void openWell(int well_index);
|
2021-05-20 04:14:15 -05:00
|
|
|
void shutWell(int well_index);
|
|
|
|
void stopWell(int well_index);
|
|
|
|
|
2021-05-20 04:19:14 -05:00
|
|
|
/// The number of phases present.
|
|
|
|
int numPhases() const
|
|
|
|
{
|
|
|
|
return this->phase_usage_.num_phases;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PhaseUsage& phaseUsage() const {
|
|
|
|
return this->phase_usage_;
|
|
|
|
}
|
2021-05-20 04:14:15 -05:00
|
|
|
|
2021-05-20 04:34:51 -05:00
|
|
|
/// One rate per well and phase.
|
2021-08-24 04:49:03 -05:00
|
|
|
std::vector<double>& wellRates(std::size_t well_index) { return this->wells_[well_index].surface_rates; }
|
|
|
|
const std::vector<double>& wellRates(std::size_t well_index) const { return this->wells_[well_index].surface_rates; }
|
2021-05-20 04:34:51 -05:00
|
|
|
|
2021-07-26 05:06:45 -05:00
|
|
|
const std::string& name(std::size_t well_index) const {
|
2021-08-03 14:29:47 -05:00
|
|
|
return this->wells_.well_name(well_index);
|
2021-07-26 05:06:45 -05:00
|
|
|
}
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
std::optional<std::size_t> index(const std::string& well_name) const {
|
|
|
|
return this->wells_.well_index(well_name);
|
|
|
|
}
|
|
|
|
|
2021-08-03 13:05:14 -05:00
|
|
|
const SingleWellState& well(std::size_t well_index) const {
|
|
|
|
return this->wells_[well_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
const SingleWellState& well(const std::string& well_name) const {
|
|
|
|
return this->wells_[well_name];
|
|
|
|
}
|
|
|
|
|
|
|
|
SingleWellState& well(std::size_t well_index) {
|
|
|
|
return this->wells_[well_index];
|
|
|
|
}
|
|
|
|
|
|
|
|
SingleWellState& well(const std::string& well_name) {
|
|
|
|
return this->wells_[well_name];
|
|
|
|
}
|
|
|
|
|
2021-08-05 05:55:18 -05:00
|
|
|
bool has(const std::string& well_name) const {
|
|
|
|
return this->wells_.has(well_name);
|
|
|
|
}
|
2021-07-26 07:09:06 -05:00
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
private:
|
2021-10-01 01:25:32 -05:00
|
|
|
PhaseUsage phase_usage_;
|
|
|
|
|
|
|
|
// The wells_ variable is essentially a map of all the wells on the current
|
|
|
|
// process. Observe that since a well can be split over several processes a
|
|
|
|
// well might appear in the WellContainer on different processes.
|
|
|
|
WellContainer<SingleWellState> wells_;
|
|
|
|
|
|
|
|
// The members alq_state, global_well_info and well_rates are map like
|
|
|
|
// structures which will have entries for *all* the wells in the system.
|
|
|
|
|
2021-05-25 00:47:31 -05:00
|
|
|
// Use of std::optional<> here is a technical crutch, the
|
|
|
|
// WellStateFullyImplicitBlackoil class should be default constructible,
|
|
|
|
// whereas the GlobalWellInfo is not.
|
|
|
|
std::optional<GlobalWellInfo> global_well_info;
|
|
|
|
ALQState alq_state;
|
|
|
|
|
2021-05-26 10:04:20 -05:00
|
|
|
// The well_rates variable is defined for all wells on all processors. The
|
|
|
|
// bool in the value pair is whether the current process owns the well or
|
|
|
|
// not.
|
2021-05-12 17:40:03 -05:00
|
|
|
std::map<std::string, std::pair<bool, std::vector<double>>> well_rates;
|
|
|
|
|
|
|
|
data::Segment
|
2021-10-01 01:34:58 -05:00
|
|
|
reportSegmentResults(const int well_id,
|
2021-05-12 17:40:03 -05:00
|
|
|
const int seg_ix,
|
|
|
|
const int seg_no) const;
|
|
|
|
|
|
|
|
// If the ALQ has changed since the previous report step,
|
|
|
|
// reset current_alq and update default_alq. ALQ is used for
|
|
|
|
// constant lift gas injection and for gas lift optimization
|
|
|
|
// (THP controlled wells).
|
2021-10-01 01:25:32 -05:00
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
void updateWellsDefaultALQ(const std::vector<Well>& wells_ecl);
|
2021-05-20 03:51:46 -05:00
|
|
|
|
2021-05-20 04:43:32 -05:00
|
|
|
/// Allocate and initialize if wells is non-null.
|
|
|
|
/// Also tries to give useful initial values to the bhp() and
|
|
|
|
/// wellRates() fields, depending on controls. The
|
|
|
|
/// perfRates() field is filled with zero, and perfPress()
|
|
|
|
/// with -1e100.
|
|
|
|
void base_init(const std::vector<double>& cellPressures,
|
|
|
|
const std::vector<Well>& wells_ecl,
|
2021-09-27 05:00:39 -05:00
|
|
|
const std::vector<std::reference_wrapper<ParallelWellInfo>>& parallel_well_info,
|
2021-05-20 04:43:32 -05:00
|
|
|
const std::vector<std::vector<PerforationData>>& well_perf_data,
|
|
|
|
const SummaryState& summary_state);
|
|
|
|
|
|
|
|
void initSingleWell(const std::vector<double>& cellPressures,
|
|
|
|
const Well& well,
|
|
|
|
const std::vector<PerforationData>& well_perf_data,
|
2021-09-27 05:00:39 -05:00
|
|
|
const ParallelWellInfo& well_info,
|
2021-05-20 04:43:32 -05:00
|
|
|
const SummaryState& summary_state);
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-12 17:40:03 -05:00
|
|
|
};
|
2014-03-18 05:23:05 -05:00
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
|
|
|
|
#endif // OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|