2014-03-18 05:23:05 -05:00
|
|
|
/*
|
|
|
|
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-02-09 06:54:42 -06:00
|
|
|
#include <opm/autodiff/BlackoilModelEnums.hpp>
|
2014-03-18 05:23:05 -05:00
|
|
|
#include <opm/core/wells.h>
|
|
|
|
#include <opm/core/well_controls.h>
|
|
|
|
#include <opm/core/simulator/WellState.hpp>
|
2016-09-20 02:43:58 -05:00
|
|
|
#include <opm/core/props/BlackoilPhases.hpp>
|
2015-10-08 04:43:36 -05:00
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
2014-03-18 05:23:05 -05:00
|
|
|
#include <vector>
|
|
|
|
#include <cassert>
|
2014-11-10 01:46:07 -06:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
|
|
|
#include <algorithm>
|
2014-11-11 00:33:15 -06:00
|
|
|
#include <array>
|
2014-03-18 05:23:05 -05:00
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
/// The state of a set of wells, tailored for use by the fully
|
|
|
|
/// implicit blackoil simulator.
|
|
|
|
class WellStateFullyImplicitBlackoil
|
2015-01-06 03:45:15 -06:00
|
|
|
: public WellState
|
2014-03-18 05:23:05 -05:00
|
|
|
{
|
2015-01-06 03:45:15 -06:00
|
|
|
typedef WellState BaseType;
|
2014-03-18 05:23:05 -05:00
|
|
|
public:
|
2015-09-14 09:51:27 -05:00
|
|
|
typedef BaseType :: WellMapType WellMapType;
|
2014-11-10 01:46:07 -06:00
|
|
|
|
2015-01-06 03:45:15 -06:00
|
|
|
using BaseType :: wellRates;
|
|
|
|
using BaseType :: bhp;
|
2015-02-19 02:50:41 -06:00
|
|
|
using BaseType :: perfPress;
|
2015-09-14 09:51:27 -05:00
|
|
|
using BaseType :: wellMap;
|
|
|
|
using BaseType :: numWells;
|
|
|
|
using BaseType :: numPhases;
|
2014-11-11 00:33:15 -06:00
|
|
|
|
2014-03-18 05:23:05 -05:00
|
|
|
/// Allocate and initialize if wells is non-null. Also tries
|
|
|
|
/// to give useful initial values to the bhp(), wellRates()
|
|
|
|
/// and perfPhaseRates() fields, depending on controls
|
2014-11-10 01:46:07 -06:00
|
|
|
template <class State, class PrevState>
|
|
|
|
void init(const Wells* wells, const State& state, const PrevState& prevState)
|
2014-03-18 05:23:05 -05:00
|
|
|
{
|
2015-09-16 05:40:14 -05:00
|
|
|
// call init on base class
|
|
|
|
BaseType :: init(wells, state);
|
2014-11-10 01:46:07 -06:00
|
|
|
|
2015-09-16 05:40:14 -05:00
|
|
|
// if there are no well, do nothing in init
|
2014-03-18 05:23:05 -05:00
|
|
|
if (wells == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-19 07:14:18 -06:00
|
|
|
const int nw = wells->number_of_wells;
|
|
|
|
if( nw == 0 ) return ;
|
|
|
|
|
2014-03-18 05:23:05 -05:00
|
|
|
// Initialize perfphaserates_, which must be done here.
|
|
|
|
const int np = wells->number_of_phases;
|
|
|
|
const int nperf = wells->well_connpos[nw];
|
2015-01-26 09:46:51 -06:00
|
|
|
// Ensure that we start out with zero rates by default.
|
|
|
|
perfphaserates_.clear();
|
2014-03-18 05:23:05 -05:00
|
|
|
perfphaserates_.resize(nperf * np, 0.0);
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
assert((wells->type[w] == INJECTOR) || (wells->type[w] == PRODUCER));
|
|
|
|
const WellControls* ctrl = wells->ctrls[w];
|
2015-01-16 00:52:07 -06:00
|
|
|
|
2014-12-19 00:18:36 -06:00
|
|
|
if (well_controls_well_is_stopped(ctrl)) {
|
2014-03-18 05:23:05 -05:00
|
|
|
// Shut well: perfphaserates_ are all zero.
|
|
|
|
} else {
|
2015-09-14 09:51:27 -05:00
|
|
|
const int num_perf_this_well = wells->well_connpos[w + 1] - wells->well_connpos[w];
|
2014-03-18 05:23:05 -05:00
|
|
|
// Open well: Initialize perfphaserates_ to well
|
|
|
|
// rates divided by the number of perforations.
|
|
|
|
for (int perf = wells->well_connpos[w]; perf < wells->well_connpos[w + 1]; ++perf) {
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
perfphaserates_[np*perf + p] = wellRates()[np*w + p] / double(num_perf_this_well);
|
|
|
|
}
|
2015-02-19 02:50:41 -06:00
|
|
|
perfPress()[perf] = state.pressure()[wells->well_cells[perf]];
|
2014-03-18 05:23:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 05:11:19 -05:00
|
|
|
|
|
|
|
// Initialize current_controls_.
|
|
|
|
// The controls set in the Wells object are treated as defaults,
|
|
|
|
// and also used for initial values.
|
|
|
|
current_controls_.resize(nw);
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
current_controls_[w] = well_controls_get_current(wells->ctrls[w]);
|
|
|
|
}
|
2014-11-10 01:46:07 -06:00
|
|
|
|
2016-04-12 01:50:34 -05:00
|
|
|
well_potentials_.clear();
|
|
|
|
well_potentials_.resize(nperf * np, 0.0);
|
|
|
|
|
2014-11-10 01:46:07 -06:00
|
|
|
// intialize wells that have been there before
|
|
|
|
// order may change so the mapping is based on the well name
|
2014-11-11 00:33:15 -06:00
|
|
|
if( ! prevState.wellMap().empty() )
|
2014-11-10 01:46:07 -06:00
|
|
|
{
|
2014-11-11 00:33:15 -06:00
|
|
|
typedef typename WellMapType :: const_iterator const_iterator;
|
|
|
|
const_iterator end = prevState.wellMap().end();
|
2014-11-10 01:46:07 -06:00
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
std::string name( wells->name[ w ] );
|
2014-11-11 00:33:15 -06:00
|
|
|
const_iterator it = prevState.wellMap().find( name );
|
2014-11-10 01:46:07 -06:00
|
|
|
if( it != end )
|
|
|
|
{
|
2014-11-11 00:33:15 -06:00
|
|
|
const int oldIndex = (*it).second[ 0 ];
|
2014-11-10 01:46:07 -06:00
|
|
|
const int newIndex = w;
|
|
|
|
|
|
|
|
// bhp
|
|
|
|
bhp()[ newIndex ] = prevState.bhp()[ oldIndex ];
|
|
|
|
|
|
|
|
// wellrates
|
|
|
|
for( int i=0, idx=newIndex*np, oldidx=oldIndex*np; i<np; ++i, ++idx, ++oldidx )
|
|
|
|
{
|
|
|
|
wellRates()[ idx ] = prevState.wellRates()[ oldidx ];
|
|
|
|
}
|
|
|
|
|
|
|
|
// perfPhaseRates
|
2015-02-19 02:50:41 -06:00
|
|
|
int oldPerf_idx = (*it).second[ 1 ];
|
2015-01-16 00:52:07 -06:00
|
|
|
const int num_perf_old_well = (*it).second[ 2 ];
|
|
|
|
const int num_perf_this_well = wells->well_connpos[newIndex + 1] - wells->well_connpos[newIndex];
|
|
|
|
// copy perforation rates when the number of perforations is equal,
|
|
|
|
// otherwise initialize perfphaserates to well rates divided by the number of perforations.
|
|
|
|
if( num_perf_old_well == num_perf_this_well )
|
2014-11-10 01:46:07 -06:00
|
|
|
{
|
2015-02-19 02:50:41 -06:00
|
|
|
int oldPerf = oldPerf_idx *np;
|
2015-01-16 00:52:07 -06:00
|
|
|
for (int perf = wells->well_connpos[ newIndex ]*np;
|
|
|
|
perf < wells->well_connpos[ newIndex + 1]*np; ++perf, ++oldPerf )
|
|
|
|
{
|
|
|
|
perfPhaseRates()[ perf ] = prevState.perfPhaseRates()[ oldPerf ];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int perf = wells->well_connpos[newIndex]; perf < wells->well_connpos[newIndex + 1]; ++perf) {
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
perfPhaseRates()[np*perf + p] = wellRates()[np*newIndex + p] / double(num_perf_this_well);
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 01:46:07 -06:00
|
|
|
}
|
2015-02-19 02:50:41 -06:00
|
|
|
// perfPressures
|
|
|
|
if( num_perf_old_well == num_perf_this_well )
|
|
|
|
{
|
|
|
|
for (int perf = wells->well_connpos[ newIndex ];
|
|
|
|
perf < wells->well_connpos[ newIndex + 1]; ++perf, ++oldPerf_idx )
|
|
|
|
{
|
|
|
|
perfPress()[ perf ] = prevState.perfPress()[ oldPerf_idx ];
|
|
|
|
}
|
|
|
|
}
|
2014-11-10 01:46:07 -06:00
|
|
|
|
|
|
|
// currentControls
|
2017-03-23 10:08:39 -05:00
|
|
|
// TODO: copying the control index from the previous state can provide better guess of the inital control
|
|
|
|
// while it can cause problem when the combination of the controls/constraints change. In that situation, coying
|
|
|
|
// the control index means specifying a rather random control. The VFP table provides some damaging values for
|
|
|
|
// situatioin not desirable, entering with a random control will possibly crash the whole simulation. Restarting with smaller
|
|
|
|
// time step might not help.
|
|
|
|
/* const int old_control_index = prevState.currentControls()[ oldIndex ];
|
2015-01-26 09:46:51 -06:00
|
|
|
if (old_control_index < well_controls_get_num(wells->ctrls[w])) {
|
|
|
|
// If the set of controls have changed, this may not be identical
|
|
|
|
// to the last control, but it must be a valid control.
|
|
|
|
currentControls()[ newIndex ] = old_control_index;
|
2016-10-31 09:35:32 -05:00
|
|
|
} else {
|
|
|
|
assert(well_controls_get_num(wells->ctrls[w]) > 0);
|
|
|
|
currentControls()[ newIndex ] = 0;
|
2017-03-23 10:08:39 -05:00
|
|
|
} */
|
2014-11-10 01:46:07 -06:00
|
|
|
}
|
2017-02-17 10:12:52 -06:00
|
|
|
|
|
|
|
|
|
|
|
// If in the new step, there is no THP related target/limit anymore, its thp value should be
|
|
|
|
// set to zero.
|
|
|
|
const WellControls* ctrl = wells->ctrls[w];
|
|
|
|
const int nwc = well_controls_get_num(ctrl);
|
|
|
|
int ctrl_index = 0;
|
|
|
|
for (; ctrl_index < nwc; ++ctrl_index) {
|
|
|
|
if (well_controls_iget_type(ctrl, ctrl_index) == THP) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// not finding any thp related control/limits
|
|
|
|
if (ctrl_index == nwc) {
|
|
|
|
thp()[w] = 0.;
|
|
|
|
}
|
2014-11-10 01:46:07 -06:00
|
|
|
}
|
|
|
|
}
|
2014-03-18 05:23:05 -05:00
|
|
|
}
|
|
|
|
|
2016-01-05 05:39:02 -06:00
|
|
|
template <class State>
|
2017-02-09 06:54:42 -06:00
|
|
|
void resize(const Wells* wells, const State& state ) {
|
2016-02-11 09:17:17 -06:00
|
|
|
const WellStateFullyImplicitBlackoil dummy_state{}; // Init with an empty previous state only resizes
|
2016-01-05 05:39:02 -06:00
|
|
|
init(wells, state, dummy_state) ;
|
|
|
|
}
|
|
|
|
|
2017-02-09 06:54:42 -06:00
|
|
|
template <class State>
|
|
|
|
void resize(const Wells* wells, const State& state, const PhaseUsage& ) {
|
|
|
|
resize( wells, state );
|
|
|
|
}
|
2016-01-05 05:39:02 -06:00
|
|
|
|
2014-03-18 05:23:05 -05:00
|
|
|
/// One rate per phase and well connection.
|
|
|
|
std::vector<double>& perfPhaseRates() { return perfphaserates_; }
|
|
|
|
const std::vector<double>& perfPhaseRates() const { return perfphaserates_; }
|
|
|
|
|
2014-03-25 05:11:19 -05:00
|
|
|
/// One current control per well.
|
|
|
|
std::vector<int>& currentControls() { return current_controls_; }
|
|
|
|
const std::vector<int>& currentControls() const { return current_controls_; }
|
|
|
|
|
2016-04-12 01:50:34 -05:00
|
|
|
/// One rate per phase and well connection.
|
|
|
|
std::vector<double>& wellPotentials() { return well_potentials_; }
|
|
|
|
const std::vector<double>& wellPotentials() const { return well_potentials_; }
|
|
|
|
|
2016-09-20 02:43:58 -05:00
|
|
|
data::Wells report(const PhaseUsage &pu) const override {
|
|
|
|
data::Wells res = WellState::report(pu);
|
2016-05-20 09:15:23 -05:00
|
|
|
|
|
|
|
const int nw = this->numWells();
|
2016-09-28 03:22:03 -05:00
|
|
|
if( nw == 0 ) return res;
|
2016-09-28 07:27:30 -05:00
|
|
|
const int np = pu.num_phases;
|
2016-09-28 03:22:03 -05:00
|
|
|
|
2016-05-20 09:15:23 -05:00
|
|
|
|
2016-09-26 09:22:51 -05:00
|
|
|
using rt = data::Rates::opt;
|
|
|
|
std::vector< rt > phs( np );
|
|
|
|
if( pu.phase_used[BlackoilPhases::Aqua] ) {
|
|
|
|
phs.at( pu.phase_pos[BlackoilPhases::Aqua] ) = rt::wat;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pu.phase_used[BlackoilPhases::Liquid] ) {
|
|
|
|
phs.at( pu.phase_pos[BlackoilPhases::Liquid] ) = rt::oil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pu.phase_used[BlackoilPhases::Vapour] ) {
|
|
|
|
phs.at( pu.phase_pos[BlackoilPhases::Vapour] ) = rt::gas;
|
|
|
|
}
|
|
|
|
|
2016-05-20 09:15:23 -05:00
|
|
|
/* this is a reference or example on **how** to convert from
|
|
|
|
* WellState to something understood by opm-output. it is intended
|
|
|
|
* to be properly implemented and maintained as a part of
|
|
|
|
* simulators, as it relies on simulator internals, details and
|
|
|
|
* representations.
|
|
|
|
*/
|
|
|
|
|
2016-09-26 09:22:51 -05:00
|
|
|
for( const auto& wt : this->wellMap() ) {
|
|
|
|
const auto w = wt.second[ 0 ];
|
|
|
|
auto& well = res.at( wt.first );
|
2016-09-29 05:06:51 -05:00
|
|
|
well.control = this->currentControls()[ w ];
|
2016-05-20 09:15:23 -05:00
|
|
|
|
2016-09-26 09:22:51 -05:00
|
|
|
int local_comp_index = 0;
|
2016-10-25 03:31:02 -05:00
|
|
|
for( auto& comp : well.completions ) {
|
2016-09-26 09:22:51 -05:00
|
|
|
const auto rates = this->perfPhaseRates().begin()
|
|
|
|
+ (np * wt.second[ 1 ])
|
|
|
|
+ (np * local_comp_index);
|
|
|
|
++local_comp_index;
|
2016-05-20 09:15:23 -05:00
|
|
|
|
2016-09-26 09:22:51 -05:00
|
|
|
for( int i = 0; i < np; ++i ) {
|
2016-10-25 03:31:02 -05:00
|
|
|
comp.rates.set( phs[ i ], *(rates + i) );
|
2016-09-26 09:22:51 -05:00
|
|
|
}
|
2016-05-20 09:15:23 -05:00
|
|
|
}
|
2016-10-25 03:31:02 -05:00
|
|
|
assert(local_comp_index == this->wells_->well_connpos[ w + 1 ] - this->wells_->well_connpos[ w ]);
|
2016-05-20 09:15:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-03-18 05:23:05 -05:00
|
|
|
private:
|
|
|
|
std::vector<double> perfphaserates_;
|
2014-03-25 05:11:19 -05:00
|
|
|
std::vector<int> current_controls_;
|
2016-04-12 01:50:34 -05:00
|
|
|
std::vector<double> well_potentials_;
|
2014-03-18 05:23:05 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
|
|
|
|
#endif // OPM_WELLSTATEFULLYIMPLICITBLACKOIL_HEADER_INCLUDED
|