2012-03-06 13:59:51 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
2016-04-04 08:10:24 +02:00
|
|
|
Copyright 2016 IRIS AS
|
2012-03-06 13:59:51 +01: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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-04-10 12:56:14 +02:00
|
|
|
#include "config.h"
|
2014-01-07 16:10:45 +01:00
|
|
|
|
|
|
|
|
|
2012-06-05 15:42:49 +02:00
|
|
|
#include <opm/core/wells/WellsManager.hpp>
|
2018-02-09 13:42:16 +01:00
|
|
|
#include <opm/grid/UnstructuredGrid.h>
|
2013-03-18 10:33:34 +01:00
|
|
|
#include <opm/core/wells.h>
|
2014-01-05 15:03:30 +01:00
|
|
|
#include <opm/core/well_controls.h>
|
2015-10-08 11:42:15 +02:00
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
2012-06-05 15:42:49 +02:00
|
|
|
#include <opm/core/wells/WellCollection.hpp>
|
2016-04-08 15:47:49 +02:00
|
|
|
#include <opm/core/wells/WellsGroup.hpp>
|
2013-03-14 10:29:42 +01:00
|
|
|
#include <opm/core/props/phaseUsageFromDeck.hpp>
|
2012-03-06 13:59:51 +01:00
|
|
|
|
2012-06-18 15:21:27 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cassert>
|
2012-06-19 00:01:30 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstddef>
|
2012-06-19 00:30:32 +02:00
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
2013-08-28 14:19:12 +02:00
|
|
|
#include <iostream>
|
2012-03-06 13:59:51 +01:00
|
|
|
|
2015-08-17 08:47:33 +02:00
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
static double invalid_alq = -1e100;
|
|
|
|
|
static double invalid_vfp = -2147483647;
|
|
|
|
|
} //Namespace
|
2012-03-06 13:59:51 +01:00
|
|
|
|
|
|
|
|
// Helper structs and functions for the implementation.
|
2014-02-25 17:52:51 +01:00
|
|
|
namespace WellsManagerDetail
|
2012-03-06 13:59:51 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
namespace ProductionControl
|
2012-03-06 13:59:51 +01:00
|
|
|
{
|
2012-06-19 00:30:32 +02:00
|
|
|
namespace Details {
|
|
|
|
|
std::map<std::string, Mode>
|
|
|
|
|
init_mode_map() {
|
|
|
|
|
std::map<std::string, Mode> m;
|
|
|
|
|
|
|
|
|
|
m.insert(std::make_pair("ORAT", ORAT));
|
|
|
|
|
m.insert(std::make_pair("WRAT", WRAT));
|
|
|
|
|
m.insert(std::make_pair("GRAT", GRAT));
|
|
|
|
|
m.insert(std::make_pair("LRAT", LRAT));
|
|
|
|
|
m.insert(std::make_pair("CRAT", CRAT));
|
|
|
|
|
m.insert(std::make_pair("RESV", RESV));
|
|
|
|
|
m.insert(std::make_pair("BHP" , BHP ));
|
|
|
|
|
m.insert(std::make_pair("THP" , THP ));
|
|
|
|
|
m.insert(std::make_pair("GRUP", GRUP));
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
} // namespace Details
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
Mode mode(const std::string& control)
|
|
|
|
|
{
|
2012-06-19 00:30:32 +02:00
|
|
|
static std::map<std::string, Mode>
|
|
|
|
|
mode_map = Details::init_mode_map();
|
2012-06-18 15:21:27 +02:00
|
|
|
|
2012-06-19 00:30:32 +02:00
|
|
|
std::map<std::string, Mode>::iterator
|
|
|
|
|
p = mode_map.find(control);
|
|
|
|
|
|
|
|
|
|
if (p != mode_map.end()) {
|
|
|
|
|
return p->second;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-08-28 13:59:03 +02:00
|
|
|
OPM_THROW(std::runtime_error, "Unknown well control mode = "
|
2012-06-19 00:30:32 +02:00
|
|
|
<< control << " in input file");
|
2012-05-02 09:38:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-01-30 15:55:17 +01:00
|
|
|
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
Mode mode(Opm::Well::ProducerCMode controlMode)
|
2014-01-30 15:55:17 +01:00
|
|
|
{
|
|
|
|
|
switch( controlMode ) {
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::ORAT:
|
2014-01-30 15:55:17 +01:00
|
|
|
return ORAT;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::WRAT:
|
2014-01-30 15:55:17 +01:00
|
|
|
return WRAT;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::GRAT:
|
2014-01-30 15:55:17 +01:00
|
|
|
return GRAT;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::LRAT:
|
2014-01-30 15:55:17 +01:00
|
|
|
return LRAT;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::CRAT:
|
2014-01-30 15:55:17 +01:00
|
|
|
return CRAT;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::RESV:
|
2014-01-30 15:55:17 +01:00
|
|
|
return RESV;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::BHP:
|
2014-01-30 15:55:17 +01:00
|
|
|
return BHP;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::THP:
|
2014-01-30 15:55:17 +01:00
|
|
|
return THP;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::ProducerCMode::GRUP:
|
2014-01-30 15:55:17 +01:00
|
|
|
return GRUP;
|
|
|
|
|
default:
|
|
|
|
|
throw std::invalid_argument("unhandled enum value");
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-05-02 09:38:18 +02:00
|
|
|
} // namespace ProductionControl
|
2012-03-06 13:59:51 +01:00
|
|
|
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
namespace InjectionControl
|
2012-03-06 13:59:51 +01:00
|
|
|
{
|
2012-06-18 15:21:27 +02:00
|
|
|
|
2012-06-19 00:30:32 +02:00
|
|
|
namespace Details {
|
|
|
|
|
std::map<std::string, Mode>
|
|
|
|
|
init_mode_map() {
|
|
|
|
|
std::map<std::string, Mode> m;
|
|
|
|
|
|
|
|
|
|
m.insert(std::make_pair("RATE", RATE));
|
|
|
|
|
m.insert(std::make_pair("RESV", RESV));
|
|
|
|
|
m.insert(std::make_pair("BHP" , BHP ));
|
|
|
|
|
m.insert(std::make_pair("THP" , THP ));
|
|
|
|
|
m.insert(std::make_pair("GRUP", GRUP));
|
|
|
|
|
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
} // namespace Details
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
Mode mode(const std::string& control)
|
|
|
|
|
{
|
2012-06-19 00:30:32 +02:00
|
|
|
static std::map<std::string, Mode>
|
|
|
|
|
mode_map = Details::init_mode_map();
|
|
|
|
|
|
|
|
|
|
std::map<std::string, Mode>::iterator
|
|
|
|
|
p = mode_map.find(control);
|
2012-05-02 09:38:18 +02:00
|
|
|
|
2012-06-19 00:30:32 +02:00
|
|
|
if (p != mode_map.end()) {
|
|
|
|
|
return p->second;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2013-08-28 13:59:03 +02:00
|
|
|
OPM_THROW(std::runtime_error, "Unknown well control mode = "
|
2012-06-19 00:30:32 +02:00
|
|
|
<< control << " in input file");
|
2012-05-02 09:38:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-01-30 08:02:13 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
Mode mode(Opm::Well::InjectorCMode controlMode)
|
2019-08-28 00:30:12 +02:00
|
|
|
{
|
2014-01-30 08:02:13 +01:00
|
|
|
switch ( controlMode ) {
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::InjectorCMode::GRUP:
|
2014-01-30 08:02:13 +01:00
|
|
|
return GRUP;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::InjectorCMode::RESV:
|
2014-01-30 08:02:13 +01:00
|
|
|
return RESV;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::InjectorCMode::RATE:
|
2014-01-30 08:02:13 +01:00
|
|
|
return RATE;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::InjectorCMode::THP:
|
2014-01-30 08:02:13 +01:00
|
|
|
return THP;
|
2019-11-13 23:16:11 +01:00
|
|
|
case Opm::Well::InjectorCMode::BHP:
|
2014-01-30 08:02:13 +01:00
|
|
|
return BHP;
|
|
|
|
|
default:
|
|
|
|
|
throw std::invalid_argument("unhandled enum value");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
} // namespace InjectionControl
|
2012-03-06 13:59:51 +01:00
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
2012-03-09 14:25:52 +01:00
|
|
|
/// Default constructor.
|
|
|
|
|
WellsManager::WellsManager()
|
2018-02-13 15:32:24 +01:00
|
|
|
: w_(create_wells(0,0,0)), is_parallel_run_(false)
|
2012-03-09 14:25:52 +01:00
|
|
|
{
|
|
|
|
|
}
|
2013-07-28 08:34:13 -03:00
|
|
|
|
2014-03-29 10:12:40 +01:00
|
|
|
/// Construct from existing wells object.
|
|
|
|
|
WellsManager::WellsManager(struct Wells* W)
|
2015-05-08 19:44:50 +02:00
|
|
|
: w_(clone_wells(W)), is_parallel_run_(false)
|
2014-03-29 10:12:40 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-07 16:10:45 +01:00
|
|
|
/// Construct wells from deck.
|
2016-10-13 16:03:35 +02:00
|
|
|
WellsManager::WellsManager(const Opm::EclipseState& eclipseState,
|
2017-10-24 20:38:15 +02:00
|
|
|
const Opm::Schedule& schedule,
|
2019-05-29 07:44:23 +02:00
|
|
|
const SummaryState& summaryState,
|
2014-01-07 16:10:45 +01:00
|
|
|
const size_t timeStep,
|
2017-01-26 17:36:00 +01:00
|
|
|
const UnstructuredGrid& grid)
|
2018-02-13 15:32:24 +01:00
|
|
|
: w_(create_wells(0,0,0)), is_parallel_run_(false)
|
2012-03-06 13:59:51 +01:00
|
|
|
{
|
2019-06-16 10:21:17 +02:00
|
|
|
init(eclipseState, schedule, summaryState, timeStep, UgGridHelpers::numCells(grid),
|
2019-01-08 11:28:11 +01:00
|
|
|
UgGridHelpers::globalCell(grid), UgGridHelpers::cartDims(grid),
|
2015-02-17 10:28:11 +01:00
|
|
|
UgGridHelpers::dimensions(grid),
|
2014-03-27 15:27:11 +01:00
|
|
|
UgGridHelpers::cell2Faces(grid), UgGridHelpers::beginFaceCentroids(grid),
|
2016-09-12 12:03:39 +02:00
|
|
|
std::unordered_set<std::string>());
|
2012-03-06 13:59:51 +01:00
|
|
|
|
2014-01-07 16:10:45 +01:00
|
|
|
}
|
2012-03-06 13:59:51 +01:00
|
|
|
|
|
|
|
|
/// Destructor.
|
|
|
|
|
WellsManager::~WellsManager()
|
|
|
|
|
{
|
2012-05-02 09:38:18 +02:00
|
|
|
destroy_wells(w_);
|
2012-03-06 13:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-05-09 16:09:13 +02:00
|
|
|
/// Does the "deck" define any wells?
|
|
|
|
|
bool WellsManager::empty() const
|
|
|
|
|
{
|
|
|
|
|
return (w_ == 0) || (w_->number_of_wells == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 13:59:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Access the managed Wells.
|
|
|
|
|
/// The method is named similarly to c_str() in std::string,
|
|
|
|
|
/// to make it clear that we are returning a C-compatible struct.
|
|
|
|
|
const Wells* WellsManager::c_wells() const
|
|
|
|
|
{
|
2012-05-02 09:38:18 +02:00
|
|
|
return w_;
|
2012-03-06 13:59:51 +01:00
|
|
|
}
|
|
|
|
|
|
2012-04-12 14:25:39 +02:00
|
|
|
const WellCollection& WellsManager::wellCollection() const
|
|
|
|
|
{
|
|
|
|
|
return well_collection_;
|
|
|
|
|
}
|
2012-03-06 13:59:51 +01:00
|
|
|
|
2016-09-30 12:59:10 +02:00
|
|
|
WellCollection& WellsManager::wellCollection() {
|
|
|
|
|
return well_collection_;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-05-02 09:38:18 +02:00
|
|
|
bool WellsManager::conditionsMet(const std::vector<double>& well_bhp,
|
2012-05-02 13:02:59 +02:00
|
|
|
const std::vector<double>& well_reservoirrates_phase,
|
|
|
|
|
const std::vector<double>& well_surfacerates_phase)
|
2012-04-23 13:24:47 +02:00
|
|
|
{
|
2012-05-02 13:02:59 +02:00
|
|
|
return well_collection_.conditionsMet(well_bhp,
|
|
|
|
|
well_reservoirrates_phase,
|
|
|
|
|
well_surfacerates_phase);
|
2012-04-23 13:24:47 +02:00
|
|
|
}
|
2012-03-06 13:59:51 +01:00
|
|
|
|
2012-05-09 13:03:37 +02:00
|
|
|
/// Applies explicit reinjection controls. This must be called at each timestep to be correct.
|
|
|
|
|
/// \param[in] well_reservoirrates_phase
|
|
|
|
|
/// A vector containing reservoir rates by phase for each well.
|
|
|
|
|
/// Is assumed to be ordered the same way as the related Wells-struct,
|
|
|
|
|
/// with all phase rates of a single well adjacent in the array.
|
|
|
|
|
/// \param[in] well_surfacerates_phase
|
|
|
|
|
/// A vector containing surface rates by phase for each well.
|
|
|
|
|
/// Is assumed to be ordered the same way as the related Wells-struct,
|
|
|
|
|
/// with all phase rates of a single well adjacent in the array.
|
|
|
|
|
|
|
|
|
|
void WellsManager::applyExplicitReinjectionControls(const std::vector<double>& well_reservoirrates_phase,
|
|
|
|
|
const std::vector<double>& well_surfacerates_phase)
|
|
|
|
|
{
|
|
|
|
|
well_collection_.applyExplicitReinjectionControls(well_reservoirrates_phase, well_surfacerates_phase);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 13:23:01 +01:00
|
|
|
void WellsManager::setupCompressedToCartesian(const int* global_cell, int number_of_cells,
|
|
|
|
|
std::map<int,int>& cartesian_to_compressed ) {
|
2014-02-03 08:58:54 +01:00
|
|
|
// global_cell is a map from compressed cells to Cartesian grid cells.
|
|
|
|
|
// We must make the inverse lookup.
|
|
|
|
|
|
|
|
|
|
if (global_cell) {
|
2014-02-17 13:23:01 +01:00
|
|
|
for (int i = 0; i < number_of_cells; ++i) {
|
2014-02-03 08:58:54 +01:00
|
|
|
cartesian_to_compressed.insert(std::make_pair(global_cell[i], i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2014-02-17 13:23:01 +01:00
|
|
|
for (int i = 0; i < number_of_cells; ++i) {
|
2014-02-03 08:58:54 +01:00
|
|
|
cartesian_to_compressed.insert(std::make_pair(i, i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-03 09:07:58 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
void WellsManager::setupWellControls(const std::vector<Well>& wells,
|
2019-06-16 10:21:17 +02:00
|
|
|
const SummaryState& summaryState,
|
|
|
|
|
std::vector<std::string>& well_names,
|
|
|
|
|
const PhaseUsage& phaseUsage,
|
2019-01-08 11:28:11 +01:00
|
|
|
const std::vector<int>& wells_on_proc) {
|
2014-02-03 09:07:58 +01:00
|
|
|
int well_index = 0;
|
2015-05-26 20:45:08 +02:00
|
|
|
auto well_on_proc = wells_on_proc.begin();
|
|
|
|
|
|
2019-05-02 12:51:25 +02:00
|
|
|
for (auto wellIter = wells.begin(); wellIter != wells.end(); ++wellIter, ++well_on_proc) {
|
2015-05-26 20:45:08 +02:00
|
|
|
if( ! *well_on_proc )
|
|
|
|
|
{
|
|
|
|
|
// Wells not stored on the process are not in the list
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 12:51:25 +02:00
|
|
|
const auto& well = (*wellIter);
|
2014-02-06 16:31:35 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getStatus() == Well::Status::SHUT) {
|
2014-10-27 07:20:03 +01:00
|
|
|
//SHUT wells are not added to the well list
|
2014-10-03 13:12:31 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getStatus() == Well::Status::STOP) {
|
2016-06-29 14:46:24 +02:00
|
|
|
// Stopped wells are kept in the well list but marked as stopped.
|
|
|
|
|
well_controls_stop_well(w_->ctrls[well_index]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-05-02 12:51:25 +02:00
|
|
|
if (well.isInjector()) {
|
2019-05-21 07:31:54 +02:00
|
|
|
const auto controls = well.injectionControls(summaryState);
|
2014-02-03 09:07:58 +01:00
|
|
|
int ok = 1;
|
|
|
|
|
int control_pos[5] = { -1, -1, -1, -1, -1 };
|
2019-05-21 07:31:54 +02:00
|
|
|
|
2014-03-21 00:35:15 +01:00
|
|
|
clear_well_controls(well_index, w_);
|
2019-11-13 23:16:11 +01:00
|
|
|
if (controls.hasControl(Well::InjectorCMode::RATE)) {
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::InjectionControl::RATE] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
2019-08-28 00:30:12 +02:00
|
|
|
auto injectorType = controls.injector_type;
|
2014-02-03 09:07:58 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (injectorType == Well::InjectorType::WATER) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::OIL) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::GAS) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = append_well_controls(SURFACE_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
controls.surface_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::InjectorCMode::RESV)) {
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::InjectionControl::RESV] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
2019-08-28 00:30:12 +02:00
|
|
|
auto injectorType = controls.injector_type;
|
2014-02-03 09:07:58 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (injectorType == Well::InjectorType::WATER) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::OIL) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::GAS) {
|
2014-02-03 09:07:58 +01:00
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = append_well_controls(RESERVOIR_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
controls.reservoir_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::InjectorCMode::BHP)) {
|
2014-03-27 15:27:11 +01:00
|
|
|
control_pos[WellsManagerDetail::InjectionControl::BHP] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
ok = append_well_controls(BHP,
|
2019-05-21 07:31:54 +02:00
|
|
|
controls.bhp_limit,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
NULL,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::InjectorCMode::THP)) {
|
2015-08-11 16:26:56 +02:00
|
|
|
control_pos[WellsManagerDetail::InjectionControl::THP] = well_controls_get_num(w_->ctrls[well_index]);
|
2019-05-21 07:31:54 +02:00
|
|
|
const double thp_limit = controls.thp_limit;
|
|
|
|
|
const int vfp_number = controls.vfp_table_number;
|
2015-08-11 12:51:18 +02:00
|
|
|
ok = append_well_controls(THP,
|
|
|
|
|
thp_limit,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
2015-08-11 12:51:18 +02:00
|
|
|
vfp_number,
|
|
|
|
|
NULL,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
2014-02-03 09:07:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[well_index]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (controls.cmode != Well::InjectorCMode::CMODE_UNDEFINED) {
|
2019-05-21 07:31:54 +02:00
|
|
|
WellsManagerDetail::InjectionControl::Mode mode = WellsManagerDetail::InjectionControl::mode(controls.cmode);
|
2014-02-03 09:07:58 +01:00
|
|
|
int cpos = control_pos[mode];
|
2014-02-25 17:52:51 +01:00
|
|
|
if (cpos == -1 && mode != WellsManagerDetail::InjectionControl::GRUP) {
|
2014-02-03 09:07:58 +01:00
|
|
|
OPM_THROW(std::runtime_error, "Control not specified in well " << well_names[well_index]);
|
|
|
|
|
}
|
2014-10-17 08:05:13 +02:00
|
|
|
|
2014-02-03 09:07:58 +01:00
|
|
|
set_current_control(well_index, cpos, w_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set well component fraction.
|
|
|
|
|
double cf[3] = { 0.0, 0.0, 0.0 };
|
2014-03-21 00:35:15 +01:00
|
|
|
{
|
2019-08-28 00:30:12 +02:00
|
|
|
auto injectorType = controls.injector_type;
|
2014-03-21 00:35:15 +01:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (injectorType == Well::InjectorType::WATER) {
|
2014-03-21 00:35:15 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Aqua]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Water phase not used, yet found water-injecting well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::OIL) {
|
2014-03-21 00:35:15 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Liquid]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Oil phase not used, yet found oil-injecting well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
2019-11-13 23:16:11 +01:00
|
|
|
} else if (injectorType == Well::InjectorType::GAS) {
|
2014-03-21 00:35:15 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Vapour]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Gas phase not used, yet found gas-injecting well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
2014-02-03 09:07:58 +01:00
|
|
|
}
|
2014-03-21 00:35:15 +01:00
|
|
|
std::copy(cf, cf + phaseUsage.num_phases, w_->comp_frac + well_index*phaseUsage.num_phases);
|
2014-02-03 09:07:58 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 12:51:25 +02:00
|
|
|
if (well.isProducer( )) {
|
2014-02-03 09:07:58 +01:00
|
|
|
// Add all controls that are present in well.
|
|
|
|
|
// First we must clear existing controls, in case the
|
|
|
|
|
// current WCONPROD line is modifying earlier controls.
|
2019-05-21 07:31:54 +02:00
|
|
|
const auto controls = well.productionControls(summaryState);
|
2014-02-03 09:07:58 +01:00
|
|
|
int control_pos[9] = { -1, -1, -1, -1, -1, -1, -1, -1, -1 };
|
|
|
|
|
int ok = 1;
|
2019-05-21 07:31:54 +02:00
|
|
|
|
2014-03-21 00:35:15 +01:00
|
|
|
clear_well_controls(well_index, w_);
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::ORAT)) {
|
2014-02-03 09:07:58 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Liquid]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Oil phase not active and ORAT control specified.");
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::ORAT] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
|
|
|
|
ok = append_well_controls(SURFACE_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
-controls.oil_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
2015-08-17 08:47:33 +02:00
|
|
|
well_index,
|
2014-02-03 09:07:58 +01:00
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::WRAT)) {
|
2014-02-03 09:07:58 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Aqua]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Water phase not active and WRAT control specified.");
|
|
|
|
|
}
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::WRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
|
|
|
|
ok = append_well_controls(SURFACE_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
-controls.water_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::GRAT)) {
|
2014-02-03 09:07:58 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Vapour]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Gas phase not active and GRAT control specified.");
|
|
|
|
|
}
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::GRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
|
|
|
|
ok = append_well_controls(SURFACE_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
-controls.gas_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::LRAT)) {
|
2014-02-03 09:07:58 +01:00
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Aqua]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Water phase not active and LRAT control specified.");
|
|
|
|
|
}
|
|
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Liquid]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Oil phase not active and LRAT control specified.");
|
|
|
|
|
}
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::LRAT] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
|
|
|
|
distr[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
|
|
|
|
ok = append_well_controls(SURFACE_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
-controls.liquid_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::RESV)) {
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::RESV] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
double distr[3] = { 1.0, 1.0, 1.0 };
|
|
|
|
|
ok = append_well_controls(RESERVOIR_RATE,
|
2019-05-21 07:31:54 +02:00
|
|
|
-controls.resv_rate,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
distr,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (ok && controls.hasControl(Well::ProducerCMode::THP)) {
|
2019-05-21 07:31:54 +02:00
|
|
|
const double thp_limit = controls.thp_limit;
|
|
|
|
|
const double alq_value = controls.alq_value;
|
|
|
|
|
const int vfp_number = controls.vfp_table_number;
|
2015-07-08 17:40:10 +02:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::THP] = well_controls_get_num(w_->ctrls[well_index]);
|
|
|
|
|
ok = append_well_controls(THP,
|
|
|
|
|
thp_limit,
|
|
|
|
|
alq_value,
|
|
|
|
|
vfp_number,
|
|
|
|
|
NULL,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-04 10:30:15 +01:00
|
|
|
if (ok) {
|
2019-05-21 07:31:54 +02:00
|
|
|
const double bhp_limit = controls.bhp_limit;
|
2014-02-25 17:52:51 +01:00
|
|
|
control_pos[WellsManagerDetail::ProductionControl::BHP] = well_controls_get_num(w_->ctrls[well_index]);
|
2014-02-03 09:07:58 +01:00
|
|
|
ok = append_well_controls(BHP,
|
2015-02-04 10:30:15 +01:00
|
|
|
bhp_limit,
|
2015-08-17 08:47:33 +02:00
|
|
|
invalid_alq,
|
|
|
|
|
invalid_vfp,
|
2014-02-03 09:07:58 +01:00
|
|
|
NULL,
|
|
|
|
|
well_index,
|
|
|
|
|
w_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Failure occured appending controls for well " << well_names[well_index]);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (controls.cmode != Well::ProducerCMode::CMODE_UNDEFINED) {
|
2019-05-21 07:31:54 +02:00
|
|
|
WellsManagerDetail::ProductionControl::Mode mode = WellsManagerDetail::ProductionControl::mode(controls.cmode);
|
2014-10-14 12:42:55 +02:00
|
|
|
int cpos = control_pos[mode];
|
|
|
|
|
if (cpos == -1 && mode != WellsManagerDetail::ProductionControl::GRUP) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Control mode type " << mode << " not present in well " << well_names[well_index]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
set_current_control(well_index, cpos, w_);
|
|
|
|
|
}
|
2014-10-03 13:12:31 +02:00
|
|
|
}
|
2014-04-04 12:15:49 +02:00
|
|
|
|
2014-04-06 23:33:43 +02:00
|
|
|
// Set well component fraction to match preferred phase for the well.
|
|
|
|
|
double cf[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
|
{
|
2019-05-02 12:51:25 +02:00
|
|
|
switch (well.getPreferredPhase()) {
|
2014-04-06 23:33:43 +02:00
|
|
|
case Phase::WATER:
|
|
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Aqua]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Water phase not used, yet found water-preferring well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Aqua]] = 1.0;
|
|
|
|
|
break;
|
|
|
|
|
case Phase::OIL:
|
|
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Liquid]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Oil phase not used, yet found oil-preferring well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Liquid]] = 1.0;
|
2014-04-24 15:43:54 +02:00
|
|
|
break;
|
2014-04-06 23:33:43 +02:00
|
|
|
case Phase::GAS:
|
|
|
|
|
if (!phaseUsage.phase_used[BlackoilPhases::Vapour]) {
|
|
|
|
|
OPM_THROW(std::runtime_error, "Gas phase not used, yet found gas-preferring well.");
|
|
|
|
|
}
|
|
|
|
|
cf[phaseUsage.phase_pos[BlackoilPhases::Vapour]] = 1.0;
|
2014-04-24 15:43:54 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2019-05-02 12:51:25 +02:00
|
|
|
OPM_THROW(std::logic_error, "Unknown preferred phase: " << well.getPreferredPhase());
|
2014-04-06 23:33:43 +02:00
|
|
|
}
|
|
|
|
|
std::copy(cf, cf + phaseUsage.num_phases, w_->comp_frac + well_index*phaseUsage.num_phases);
|
|
|
|
|
}
|
2014-02-03 09:07:58 +01:00
|
|
|
}
|
|
|
|
|
well_index++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2014-02-14 13:43:25 +01:00
|
|
|
|
2017-03-23 14:40:54 +01:00
|
|
|
// only handle the guide rates from the keyword WGRUPCON
|
2019-11-13 23:16:11 +01:00
|
|
|
void WellsManager::setupGuideRates(const std::vector<Well>& wells, std::vector<WellData>& well_data, std::map<std::string, int>& well_names_to_index)
|
2014-02-24 15:24:33 +01:00
|
|
|
{
|
|
|
|
|
for (auto wellIter = wells.begin(); wellIter != wells.end(); ++wellIter ) {
|
2019-05-02 12:51:25 +02:00
|
|
|
const auto& well = *wellIter;
|
2016-04-08 15:47:49 +02:00
|
|
|
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getStatus() == Well::Status::SHUT) {
|
2016-04-08 15:47:49 +02:00
|
|
|
//SHUT wells does not need guide rates
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-02 12:51:25 +02:00
|
|
|
const int wix = well_names_to_index[well.name()];
|
2014-02-24 15:24:33 +01:00
|
|
|
WellNode& wellnode = *well_collection_.getLeafNodes()[wix];
|
|
|
|
|
|
2017-03-23 14:40:54 +01:00
|
|
|
// TODO: looks like only handling OIL phase guide rate for producers
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getGuideRatePhase() != Well::GuideRateTarget::UNDEFINED && well.getGuideRate() >= 0.) {
|
2014-02-24 15:24:33 +01:00
|
|
|
if (well_data[wix].type == PRODUCER) {
|
2019-05-02 12:51:25 +02:00
|
|
|
wellnode.prodSpec().guide_rate_ = well.getGuideRate();
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getGuideRatePhase() == Well::GuideRateTarget::OIL) {
|
2014-02-24 15:24:33 +01:00
|
|
|
wellnode.prodSpec().guide_rate_type_ = ProductionSpecification::OIL;
|
|
|
|
|
} else {
|
2019-11-13 23:16:11 +01:00
|
|
|
OPM_THROW(std::runtime_error, "Guide rate type " << Well::GuideRateTarget2String(well.getGuideRatePhase()) << " specified for producer "
|
2019-05-02 12:51:25 +02:00
|
|
|
<< well.name() << " in WGRUPCON, cannot handle.");
|
2014-02-24 15:24:33 +01:00
|
|
|
}
|
|
|
|
|
} else if (well_data[wix].type == INJECTOR) {
|
2019-05-02 12:51:25 +02:00
|
|
|
wellnode.injSpec().guide_rate_ = well.getGuideRate();
|
2019-11-13 23:16:11 +01:00
|
|
|
if (well.getGuideRatePhase() == Well::GuideRateTarget::RAT) {
|
2014-02-24 15:24:33 +01:00
|
|
|
wellnode.injSpec().guide_rate_type_ = InjectionSpecification::RAT;
|
|
|
|
|
} else {
|
2019-11-13 23:16:11 +01:00
|
|
|
OPM_THROW(std::runtime_error, "Guide rate type " << Well::GuideRateTarget2String(well.getGuideRatePhase()) << " specified for injector "
|
2019-05-02 12:51:25 +02:00
|
|
|
<< well.name() << " in WGRUPCON, cannot handle.");
|
2014-02-24 15:24:33 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-05-02 12:51:25 +02:00
|
|
|
OPM_THROW(std::runtime_error, "Unknown well type " << well_data[wix].type << " for well " << well.name());
|
2014-02-24 15:24:33 +01:00
|
|
|
}
|
2017-04-07 10:59:46 +02:00
|
|
|
} else {
|
|
|
|
|
wellnode.setIsGuideRateWellPotential(true);
|
2017-03-23 14:40:54 +01:00
|
|
|
}
|
2014-02-24 15:24:33 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-06 13:59:51 +01:00
|
|
|
} // namespace Opm
|