2017-02-13 09:45:06 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 09:45:06 -06:00
|
|
|
StandardWellsDense(const Wells* wells_arg,
|
|
|
|
WellCollection* well_collection,
|
2017-05-09 01:21:51 -05:00
|
|
|
const std::vector< const Well* >& wells_ecl,
|
2017-02-13 09:45:06 -06:00
|
|
|
const ModelParameters& param,
|
2017-08-10 04:20:09 -05:00
|
|
|
const RateConverterType& rate_converter,
|
2017-05-09 01:21:51 -05:00
|
|
|
const bool terminal_output,
|
|
|
|
const int current_timeIdx)
|
2017-02-13 09:45:06 -06:00
|
|
|
: wells_active_(wells_arg!=nullptr)
|
|
|
|
, wells_(wells_arg)
|
2017-05-09 01:21:51 -05:00
|
|
|
, wells_ecl_(wells_ecl)
|
2017-06-27 05:17:36 -05:00
|
|
|
, number_of_wells_(wells_arg ? (wells_arg->number_of_wells) : 0)
|
2017-07-25 03:15:27 -05:00
|
|
|
, number_of_phases_(wells_arg ? (wells_arg->number_of_phases) : 0) // TODO: not sure if it is proper for this way
|
2017-08-21 03:23:42 -05:00
|
|
|
, well_container_(createWellContainer(wells_arg, wells_ecl, current_timeIdx) )
|
2017-02-13 09:45:06 -06:00
|
|
|
, well_collection_(well_collection)
|
|
|
|
, param_(param)
|
|
|
|
, terminal_output_(terminal_output)
|
2017-05-09 01:21:51 -05:00
|
|
|
, has_solvent_(GET_PROP_VALUE(TypeTag, EnableSolvent))
|
2017-06-07 02:29:31 -05:00
|
|
|
, has_polymer_(GET_PROP_VALUE(TypeTag, EnablePolymer))
|
2017-05-09 01:21:51 -05:00
|
|
|
, current_timeIdx_(current_timeIdx)
|
2017-08-10 04:20:09 -05:00
|
|
|
, rate_converter_(rate_converter)
|
2017-02-13 09:45:06 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 09:45:06 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 09:45:06 -06:00
|
|
|
init(const PhaseUsage phase_usage_arg,
|
|
|
|
const std::vector<bool>& active_arg,
|
|
|
|
const double gravity_arg,
|
|
|
|
const std::vector<double>& depth_arg,
|
2017-06-07 02:29:31 -05:00
|
|
|
long int global_nc,
|
2017-06-27 09:51:11 -05:00
|
|
|
const Grid& grid)
|
2017-02-13 09:45:06 -06:00
|
|
|
{
|
2017-03-24 09:12:42 -05:00
|
|
|
// has to be set always for the convergence check!
|
|
|
|
global_nc_ = global_nc;
|
|
|
|
|
2017-02-13 09:45:06 -06:00
|
|
|
if ( ! localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
phase_usage_ = phase_usage_arg;
|
|
|
|
active_ = active_arg;
|
|
|
|
|
|
|
|
calculateEfficiencyFactors();
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
2017-07-26 08:27:39 -05:00
|
|
|
const auto& pu = phase_usage_;
|
2017-02-13 09:45:06 -06:00
|
|
|
const int np = pu.num_phases;
|
|
|
|
|
|
|
|
// assumes the gas fractions are stored after water fractions
|
|
|
|
// WellVariablePositions needs to be changed for 2p runs
|
|
|
|
assert (np == 3 || (np == 2 && !pu.phase_used[Gas]) );
|
|
|
|
#endif
|
|
|
|
|
2017-06-07 02:29:31 -05:00
|
|
|
if (has_polymer_)
|
|
|
|
{
|
|
|
|
if (PolymerModule::hasPlyshlog()) {
|
|
|
|
computeRepRadiusPerfLength(grid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 07:51:29 -05:00
|
|
|
number_of_cells_ = Opm::UgGridHelpers::numCells(grid);
|
2017-06-21 07:07:11 -05:00
|
|
|
// do the initialization for all the wells
|
|
|
|
// TODO: to see whether we can postpone of the intialization of the well containers to
|
|
|
|
// optimize the usage of the following several member variables
|
|
|
|
for (auto& well : well_container_) {
|
2017-08-11 07:51:29 -05:00
|
|
|
well->init(&phase_usage_, &active_, depth_arg, gravity_arg, number_of_cells_);
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
2017-02-13 09:45:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-07 04:35:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
|
|
|
setVFPProperties(const VFPProperties* vfp_properties_arg)
|
|
|
|
{
|
2017-08-07 07:50:03 -05:00
|
|
|
for (auto& well : well_container_) {
|
|
|
|
well->setVFPProperties(vfp_properties_arg);
|
|
|
|
}
|
2017-08-07 04:35:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-09 05:32:45 -05:00
|
|
|
|
2017-06-15 10:19:49 -05:00
|
|
|
|
2017-08-10 08:27:05 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
int
|
|
|
|
StandardWellsDense<TypeTag>::
|
|
|
|
numWells() const
|
|
|
|
{
|
|
|
|
return number_of_wells_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-15 10:19:49 -05:00
|
|
|
template<typename TypeTag>
|
2017-08-21 03:23:42 -05:00
|
|
|
std::vector<typename StandardWellsDense<TypeTag>::WellInterfacePtr >
|
2017-06-15 10:19:49 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-08-21 03:23:42 -05:00
|
|
|
createWellContainer(const Wells* wells,
|
|
|
|
const std::vector< const Well* >& wells_ecl,
|
|
|
|
const int time_step)
|
2017-06-15 10:19:49 -05:00
|
|
|
{
|
2017-08-21 03:23:42 -05:00
|
|
|
std::vector<WellInterfacePtr> well_container;
|
|
|
|
|
|
|
|
const int nw = wells ? (wells->number_of_wells) : 0;
|
2017-06-15 10:19:49 -05:00
|
|
|
|
2017-08-21 03:23:42 -05:00
|
|
|
if (nw > 0) {
|
|
|
|
well_container.reserve(nw);
|
2017-06-15 10:19:49 -05:00
|
|
|
|
|
|
|
// With the following way, it will have the same order with wells struct
|
|
|
|
// Hopefully, it can generate the same residual history with master branch
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-08-21 03:23:42 -05:00
|
|
|
const std::string well_name = std::string(wells->name[w]);
|
2017-06-15 10:19:49 -05:00
|
|
|
|
|
|
|
// finding the location of the well in wells_ecl
|
2017-08-21 03:23:42 -05:00
|
|
|
const int nw_wells_ecl = wells_ecl.size();
|
2017-06-15 10:19:49 -05:00
|
|
|
int index_well = 0;
|
|
|
|
for (; index_well < nw_wells_ecl; ++index_well) {
|
2017-08-21 03:23:42 -05:00
|
|
|
if (well_name == wells_ecl[index_well]->name()) {
|
2017-06-15 10:19:49 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It should be able to find in wells_ecl.
|
|
|
|
if (index_well == nw_wells_ecl) {
|
|
|
|
OPM_THROW(std::logic_error, "Could not find well " << well_name << " in wells_ecl ");
|
|
|
|
}
|
|
|
|
|
2017-08-21 03:23:42 -05:00
|
|
|
const Well* well_ecl = wells_ecl[index_well];
|
2017-08-29 03:01:31 -05:00
|
|
|
// TODO: stopping throwing when encoutnering MS wells for now.
|
|
|
|
/* if (well_ecl->isMultiSegment(time_step)) {
|
2017-06-15 10:19:49 -05:00
|
|
|
OPM_THROW(Opm::NumericalProblem, "Not handling Multisegment Wells for now");
|
2017-08-29 03:01:31 -05:00
|
|
|
} */
|
2017-06-15 10:19:49 -05:00
|
|
|
|
|
|
|
// Basically, we are handling all the wells as StandardWell for the moment
|
2017-08-21 03:23:42 -05:00
|
|
|
well_container.emplace_back(new StandardWell<TypeTag>(well_ecl, time_step, wells) );
|
2017-06-15 10:19:49 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-21 03:23:42 -05:00
|
|
|
return well_container;
|
2017-06-15 10:19:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 09:45:06 -06:00
|
|
|
SimulatorReport
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 09:45:06 -06:00
|
|
|
assemble(Simulator& ebosSimulator,
|
|
|
|
const int iterationIdx,
|
|
|
|
const double dt,
|
|
|
|
WellState& well_state)
|
|
|
|
{
|
2017-03-09 08:43:13 -06:00
|
|
|
|
2017-03-24 09:11:49 -05:00
|
|
|
if (iterationIdx == 0) {
|
|
|
|
prepareTimeStep(ebosSimulator, well_state);
|
|
|
|
}
|
|
|
|
|
2017-02-13 09:45:06 -06:00
|
|
|
SimulatorReport report;
|
2017-04-12 10:37:34 -05:00
|
|
|
if ( ! wellsActive() ) {
|
2017-02-13 09:45:06 -06:00
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateWellControls(well_state);
|
2017-08-21 08:41:25 -05:00
|
|
|
// Set the well primary variables based on the value of well solutions
|
|
|
|
initPrimaryVariablesEvaluation();
|
2017-02-13 09:45:06 -06:00
|
|
|
|
|
|
|
if (iterationIdx == 0) {
|
|
|
|
computeWellConnectionPressures(ebosSimulator, well_state);
|
|
|
|
computeAccumWells();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param_.solve_welleq_initially_ && iterationIdx == 0) {
|
|
|
|
// solve the well equations as a pre-processing step
|
|
|
|
report = solveWellEq(ebosSimulator, dt, well_state);
|
|
|
|
}
|
|
|
|
assembleWellEq(ebosSimulator, dt, well_state, false);
|
|
|
|
|
|
|
|
report.converged = true;
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 09:45:06 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 09:45:06 -06:00
|
|
|
assembleWellEq(Simulator& ebosSimulator,
|
|
|
|
const double dt,
|
|
|
|
WellState& well_state,
|
2017-08-10 08:27:05 -05:00
|
|
|
bool only_wells) const
|
2017-02-13 09:45:06 -06:00
|
|
|
{
|
2017-06-27 05:17:36 -05:00
|
|
|
for (int w = 0; w < number_of_wells_; ++w) {
|
|
|
|
well_container_[w]->assembleWellEq(ebosSimulator, dt, well_state, only_wells);
|
2017-02-13 09:45:06 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-27 09:59:52 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
// applying the well residual to reservoir residuals
|
|
|
|
// r = r - duneC_^T * invDuneD_ * resWell_
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 10:07:34 -06:00
|
|
|
apply( BVector& r) const
|
|
|
|
{
|
|
|
|
if ( ! localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
for (auto& well : well_container_) {
|
|
|
|
well->apply(r);
|
|
|
|
}
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
// Ax = A x - C D^-1 B x
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-06-07 07:23:43 -05:00
|
|
|
apply(const BVector& x, BVector& Ax) const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
2017-07-21 08:30:34 -05:00
|
|
|
// TODO: do we still need localWellsActive()?
|
2017-02-13 10:07:34 -06:00
|
|
|
if ( ! localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
for (auto& well : well_container_) {
|
|
|
|
well->apply(x, Ax);
|
|
|
|
}
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
// Ax = Ax - alpha * C D^-1 B x
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-06-07 07:23:43 -05:00
|
|
|
applyScaleAdd(const Scalar alpha, const BVector& x, BVector& Ax) const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
|
|
|
if ( ! localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( scaleAddRes_.size() != Ax.size() ) {
|
|
|
|
scaleAddRes_.resize( Ax.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
scaleAddRes_ = 0.0;
|
2017-07-21 07:21:17 -05:00
|
|
|
// scaleAddRes_ = - C D^-1 B x
|
2017-02-13 10:07:34 -06:00
|
|
|
apply( x, scaleAddRes_ );
|
2017-07-21 07:21:17 -05:00
|
|
|
// Ax = Ax + alpha * scaleAddRes_
|
2017-02-13 10:07:34 -06:00
|
|
|
Ax.axpy( alpha, scaleAddRes_ );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-08-21 07:16:24 -05:00
|
|
|
recoverWellSolutionAndUpdateWellState(const BVector& x, WellState& well_state) const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
2017-07-21 08:30:34 -05:00
|
|
|
for (auto& well : well_container_) {
|
2017-08-21 07:16:24 -05:00
|
|
|
well->recoverWellSolutionAndUpdateWellState(x, param_, well_state);
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-21 08:30:34 -05:00
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 06:39:53 -06:00
|
|
|
int
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 06:39:53 -06:00
|
|
|
flowPhaseToEbosPhaseIdx( const int phaseIdx ) const
|
|
|
|
{
|
2017-05-03 06:34:15 -05:00
|
|
|
assert(phaseIdx < 3);
|
2017-02-14 06:39:53 -06:00
|
|
|
const int flowToEbos[ 3 ] = { FluidSystem::waterPhaseIdx, FluidSystem::oilPhaseIdx, FluidSystem::gasPhaseIdx };
|
|
|
|
return flowToEbos[ phaseIdx ];
|
|
|
|
}
|
|
|
|
|
2017-02-13 10:07:34 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
int
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 10:07:34 -06:00
|
|
|
numPhases() const
|
|
|
|
{
|
2017-07-26 08:27:39 -05:00
|
|
|
return number_of_phases_;
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-03-08 04:29:06 -06:00
|
|
|
resetWellControlFromState(const WellState& xw) const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
|
|
|
const int nw = wells_->number_of_wells;
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
WellControls* wc = wells_->ctrls[w];
|
|
|
|
well_controls_set_current( wc, xw.currentControls()[w]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
bool
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 10:07:34 -06:00
|
|
|
wellsActive() const
|
|
|
|
{
|
|
|
|
return wells_active_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 10:07:34 -06:00
|
|
|
setWellsActive(const bool wells_active)
|
|
|
|
{
|
|
|
|
wells_active_ = wells_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
bool
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-13 10:07:34 -06:00
|
|
|
localWellsActive() const
|
|
|
|
{
|
2017-07-26 08:27:39 -05:00
|
|
|
return number_of_wells_ > 0;
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-08-21 08:41:25 -05:00
|
|
|
initPrimaryVariablesEvaluation() const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
2017-07-25 03:15:27 -05:00
|
|
|
for (auto& well : well_container_) {
|
2017-08-21 08:41:25 -05:00
|
|
|
well->initPrimaryVariablesEvaluation();
|
2017-06-19 05:43:08 -05:00
|
|
|
}
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
|
2017-02-14 08:06:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-13 10:07:34 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-08-10 08:27:05 -05:00
|
|
|
computeAccumWells() const
|
2017-02-13 10:07:34 -06:00
|
|
|
{
|
2017-06-29 06:52:31 -05:00
|
|
|
for (auto& well : well_container_) {
|
|
|
|
well->computeAccumWell();
|
2017-02-13 10:07:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-14 04:34:03 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 04:34:03 -06:00
|
|
|
SimulatorReport
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 04:34:03 -06:00
|
|
|
solveWellEq(Simulator& ebosSimulator,
|
|
|
|
const double dt,
|
2017-08-10 08:27:05 -05:00
|
|
|
WellState& well_state) const
|
2017-02-14 04:34:03 -06:00
|
|
|
{
|
2017-07-26 08:27:39 -05:00
|
|
|
const int nw = number_of_wells_;
|
2017-02-14 04:34:03 -06:00
|
|
|
WellState well_state0 = well_state;
|
|
|
|
|
2017-07-21 09:01:32 -05:00
|
|
|
const int numComp = numComponents();
|
|
|
|
std::vector< Scalar > B_avg( numComp, Scalar() );
|
|
|
|
computeAverageFormationFactor(ebosSimulator, B_avg);
|
|
|
|
|
2017-02-14 04:34:03 -06:00
|
|
|
int it = 0;
|
|
|
|
bool converged;
|
|
|
|
do {
|
|
|
|
assembleWellEq(ebosSimulator, dt, well_state, true);
|
2017-07-21 09:01:32 -05:00
|
|
|
|
|
|
|
converged = getWellConvergence(ebosSimulator, B_avg);
|
2017-02-14 04:34:03 -06:00
|
|
|
|
|
|
|
// checking whether the group targets are converged
|
|
|
|
if (wellCollection()->groupControlActive()) {
|
|
|
|
converged = converged && wellCollection()->groupTargetConverged(well_state.wellRates());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (converged) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
if( localWellsActive() )
|
|
|
|
{
|
2017-06-28 06:46:01 -05:00
|
|
|
for (auto& well : well_container_) {
|
2017-08-21 07:16:24 -05:00
|
|
|
well->solveEqAndUpdateWellState(param_, well_state);
|
2017-06-28 06:46:01 -05:00
|
|
|
}
|
2017-04-12 10:37:34 -05:00
|
|
|
}
|
|
|
|
// updateWellControls uses communication
|
|
|
|
// Therefore the following is executed if there
|
|
|
|
// are active wells anywhere in the global domain.
|
|
|
|
if( wellsActive() )
|
|
|
|
{
|
2017-02-14 04:34:03 -06:00
|
|
|
updateWellControls(well_state);
|
2017-08-21 08:41:25 -05:00
|
|
|
initPrimaryVariablesEvaluation();
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
|
|
|
} while (it < 15);
|
|
|
|
|
2017-08-15 02:51:49 -05:00
|
|
|
if (converged) {
|
|
|
|
OpmLog::debug("Well equation solution gets converged with " + std::to_string(it) + " iterations");
|
|
|
|
} else {
|
|
|
|
OpmLog::debug("Well equation solution failed in getting converged with " + std::to_string(it) + " iterations");
|
|
|
|
|
2017-02-14 04:34:03 -06:00
|
|
|
well_state = well_state0;
|
2017-08-21 08:41:25 -05:00
|
|
|
updatePrimaryVariables(well_state);
|
2017-03-08 07:02:00 -06:00
|
|
|
// also recover the old well controls
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-07-26 08:27:39 -05:00
|
|
|
WellControls* wc = well_container_[w]->wellControls();
|
2017-03-08 07:02:00 -06:00
|
|
|
well_controls_set_current(wc, well_state.currentControls()[w]);
|
|
|
|
}
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
SimulatorReport report;
|
|
|
|
report.converged = converged;
|
|
|
|
report.total_well_iterations = it;
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 04:34:03 -06:00
|
|
|
bool
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 04:34:03 -06:00
|
|
|
getWellConvergence(Simulator& ebosSimulator,
|
2017-07-21 09:01:32 -05:00
|
|
|
const std::vector<Scalar>& B_avg) const
|
2017-02-14 04:34:03 -06:00
|
|
|
{
|
2017-08-22 07:49:30 -05:00
|
|
|
ConvergenceReport report;
|
2017-02-14 04:34:03 -06:00
|
|
|
|
2017-06-28 04:15:04 -05:00
|
|
|
for (const auto& well : well_container_) {
|
2017-08-22 07:49:30 -05:00
|
|
|
report += well->getWellConvergence(ebosSimulator, B_avg, param_);
|
|
|
|
}
|
|
|
|
|
|
|
|
// checking NaN residuals
|
|
|
|
{
|
|
|
|
bool nan_residual_found = report.nan_residual_found;
|
|
|
|
const auto& grid = ebosSimulator.gridManager().grid();
|
|
|
|
int value = nan_residual_found ? 1 : 0;
|
|
|
|
|
|
|
|
nan_residual_found = grid.comm().max(value);
|
|
|
|
|
|
|
|
if (nan_residual_found) {
|
|
|
|
for (const auto& well : report.nan_residual_wells) {
|
|
|
|
OpmLog::debug("NaN residual found with phase " + well.phase_name + " for well " + well.well_name);
|
|
|
|
}
|
|
|
|
OPM_THROW(Opm::NumericalProblem, "NaN residual found!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// checking too large residuals
|
|
|
|
{
|
|
|
|
bool too_large_residual_found = report.too_large_residual_found;
|
|
|
|
const auto& grid = ebosSimulator.gridManager().grid();
|
|
|
|
int value = too_large_residual_found ? 1 : 0;
|
|
|
|
|
|
|
|
too_large_residual_found = grid.comm().max(value);
|
|
|
|
if (too_large_residual_found) {
|
|
|
|
for (const auto& well : report.too_large_residual_wells) {
|
|
|
|
OpmLog::debug("Too large residual found with phase " + well.phase_name + " fow well " + well.well_name);
|
|
|
|
}
|
|
|
|
OPM_THROW(Opm::NumericalProblem, "Too large residual found!");
|
2017-03-24 06:12:06 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-22 07:49:30 -05:00
|
|
|
// checking convergence
|
|
|
|
bool converged_well = report.converged;
|
2017-08-02 08:14:54 -05:00
|
|
|
{
|
|
|
|
const auto& grid = ebosSimulator.gridManager().grid();
|
2017-08-10 09:56:03 -05:00
|
|
|
int value = converged_well ? 1 : 0;
|
2017-08-02 08:14:54 -05:00
|
|
|
|
2017-08-10 09:56:03 -05:00
|
|
|
converged_well = grid.comm().min(value);
|
|
|
|
}
|
2017-02-14 04:34:03 -06:00
|
|
|
|
2017-06-28 04:15:04 -05:00
|
|
|
return converged_well;
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 04:34:03 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 04:34:03 -06:00
|
|
|
computeWellConnectionPressures(const Simulator& ebosSimulator,
|
2017-08-10 08:27:05 -05:00
|
|
|
const WellState& xw) const
|
2017-02-14 04:34:03 -06:00
|
|
|
{
|
|
|
|
if( ! localWellsActive() ) return ;
|
|
|
|
|
2017-06-29 06:52:31 -05:00
|
|
|
for (auto& well : well_container_) {
|
|
|
|
well->computeWellConnectionPressures(ebosSimulator, xw);
|
|
|
|
}
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 04:34:03 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 04:34:03 -06:00
|
|
|
updateWellControls(WellState& xw) const
|
|
|
|
{
|
2017-04-12 10:37:34 -05:00
|
|
|
// Even if there no wells active locally, we cannot
|
|
|
|
// return as the Destructor of the WellSwitchingLogger
|
|
|
|
// uses global communication. For no well active globally
|
|
|
|
// we simply return.
|
|
|
|
if( !wellsActive() ) return ;
|
2017-02-14 04:34:03 -06:00
|
|
|
|
2017-08-08 05:30:24 -05:00
|
|
|
wellhelpers::WellSwitchingLogger logger;
|
|
|
|
|
2017-06-28 04:15:04 -05:00
|
|
|
for (const auto& well : well_container_) {
|
2017-08-08 05:30:24 -05:00
|
|
|
well->updateWellControl(xw, logger);
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
2017-08-10 08:27:05 -05:00
|
|
|
|
|
|
|
updateGroupControls(xw);
|
2017-02-14 04:34:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-14 06:39:53 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 06:39:53 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 06:39:53 -06:00
|
|
|
updateListEconLimited(const Schedule& schedule,
|
|
|
|
const int current_step,
|
|
|
|
const Wells* wells_struct,
|
|
|
|
const WellState& well_state,
|
|
|
|
DynamicListEconLimited& list_econ_limited) const
|
|
|
|
{
|
2017-07-26 04:01:26 -05:00
|
|
|
for (const auto& well : well_container_) {
|
|
|
|
well->updateListEconLimited(well_state, list_econ_limited);
|
|
|
|
}
|
2017-02-14 06:39:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 06:39:53 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 06:39:53 -06:00
|
|
|
computeWellPotentials(const Simulator& ebosSimulator,
|
2017-03-23 05:36:49 -05:00
|
|
|
const WellState& well_state,
|
2017-04-03 08:07:56 -05:00
|
|
|
std::vector<double>& well_potentials) const
|
2017-02-14 06:39:53 -06:00
|
|
|
{
|
2017-08-21 08:41:25 -05:00
|
|
|
updatePrimaryVariables(well_state);
|
|
|
|
computeWellConnectionPressures(ebosSimulator, well_state);
|
|
|
|
|
|
|
|
// initialize the primary variables in Evaluation, which is used in computePerfRate for computeWellPotentials
|
|
|
|
// TODO: for computeWellPotentials, no derivative is required actually
|
|
|
|
initPrimaryVariablesEvaluation();
|
2017-02-14 06:39:53 -06:00
|
|
|
|
|
|
|
// number of wells and phases
|
2017-07-25 03:15:27 -05:00
|
|
|
const int nw = number_of_wells_;
|
|
|
|
const int np = number_of_phases_;
|
2017-03-23 05:36:49 -05:00
|
|
|
well_potentials.resize(nw * np, 0.0);
|
|
|
|
|
2017-02-14 06:39:53 -06:00
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-07-25 03:15:27 -05:00
|
|
|
std::vector<double> potentials;
|
|
|
|
well_container_[w]->computeWellPotentials(ebosSimulator, well_state, potentials);
|
2017-02-14 06:39:53 -06:00
|
|
|
|
2017-03-31 09:33:20 -05:00
|
|
|
// putting the sucessfully calculated potentials to the well_potentials
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
well_potentials[w * np + p] = std::abs(potentials[p]);
|
2017-02-14 06:39:53 -06:00
|
|
|
}
|
2017-02-14 08:06:57 -06:00
|
|
|
} // end of for (int w = 0; w < nw; ++w)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-03-16 10:39:05 -05:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-03-16 10:39:05 -05:00
|
|
|
prepareTimeStep(const Simulator& ebos_simulator,
|
|
|
|
WellState& well_state)
|
|
|
|
{
|
2017-07-26 08:27:39 -05:00
|
|
|
const int nw = number_of_wells_;
|
2017-03-31 05:50:50 -05:00
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-04-07 07:17:54 -05:00
|
|
|
// after restarting, the well_controls can be modified while
|
|
|
|
// the well_state still uses the old control index
|
|
|
|
// we need to synchronize these two.
|
2017-04-11 08:02:36 -05:00
|
|
|
resetWellControlFromState(well_state);
|
2017-03-31 05:50:50 -05:00
|
|
|
|
|
|
|
if (wellCollection()->groupControlActive()) {
|
2017-07-26 08:27:39 -05:00
|
|
|
WellControls* wc = well_container_[w]->wellControls();
|
|
|
|
WellNode& well_node = well_collection_->findWellNode(well_container_[w]->name());
|
2017-03-31 05:50:50 -05:00
|
|
|
|
2017-04-07 07:17:54 -05:00
|
|
|
// handling the situation that wells do not have a valid control
|
|
|
|
// it happens the well specified with GRUP and restarting due to non-convergencing
|
|
|
|
// putting the well under group control for this situation
|
|
|
|
int ctrl_index = well_controls_get_current(wc);
|
|
|
|
|
|
|
|
const int group_control_index = well_node.groupControlIndex();
|
|
|
|
if (group_control_index >= 0 && ctrl_index < 0) {
|
|
|
|
// put well under group control
|
|
|
|
well_controls_set_current(wc, group_control_index);
|
|
|
|
well_state.currentControls()[w] = group_control_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Final step, update whehter the well is under group control or individual control
|
|
|
|
// updated ctrl_index from the well control
|
|
|
|
ctrl_index = well_controls_get_current(wc);
|
2017-03-31 05:50:50 -05:00
|
|
|
if (well_node.groupControlIndex() >= 0 && ctrl_index == well_node.groupControlIndex()) {
|
|
|
|
// under group control
|
|
|
|
well_node.setIndividualControl(false);
|
|
|
|
} else {
|
|
|
|
// individual control
|
|
|
|
well_node.setIndividualControl(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 10:39:05 -05:00
|
|
|
if (well_collection_->groupControlActive()) {
|
2017-04-07 04:00:51 -05:00
|
|
|
if (well_collection_->requireWellPotentials()) {
|
2017-03-23 10:41:13 -05:00
|
|
|
|
2017-04-07 07:17:54 -05:00
|
|
|
// calculate the well potentials
|
2017-03-16 10:39:05 -05:00
|
|
|
std::vector<double> well_potentials;
|
2017-03-23 05:36:49 -05:00
|
|
|
computeWellPotentials(ebos_simulator, well_state, well_potentials);
|
2017-03-16 10:39:05 -05:00
|
|
|
|
|
|
|
// update/setup guide rates for each well based on the well_potentials
|
2017-08-11 07:51:29 -05:00
|
|
|
// TODO: this is one of two places that still need Wells struct. In this function, only the well names
|
|
|
|
// well types are used, probably the order of the wells to locate the correct values in well_potentials.
|
2017-08-18 09:25:05 -05:00
|
|
|
well_collection_->setGuideRatesWithPotentials(wells_, phase_usage_, well_potentials);
|
2017-04-06 07:53:44 -05:00
|
|
|
}
|
2017-03-31 05:50:50 -05:00
|
|
|
|
2017-03-16 10:39:05 -05:00
|
|
|
applyVREPGroupControl(well_state);
|
2017-03-23 10:41:13 -05:00
|
|
|
|
|
|
|
if (!wellCollection()->groupControlApplied()) {
|
|
|
|
wellCollection()->applyGroupControls();
|
|
|
|
} else {
|
|
|
|
wellCollection()->updateWellTargets(well_state.wellRates());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// since the controls are all updated, we should update well_state accordingly
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-07-26 08:27:39 -05:00
|
|
|
WellControls* wc = well_container_[w]->wellControls();
|
2017-03-23 10:41:13 -05:00
|
|
|
const int control = well_controls_get_current(wc);
|
|
|
|
well_state.currentControls()[w] = control;
|
2017-08-07 07:50:03 -05:00
|
|
|
// TODO: for VFP control, the perf_densities are still zero here, investigate better
|
|
|
|
// way to handle it later.
|
2017-07-25 04:22:08 -05:00
|
|
|
well_container_[w]->updateWellStateWithTarget(control, well_state);
|
2017-04-03 08:07:56 -05:00
|
|
|
|
|
|
|
// The wells are not considered to be newly added
|
|
|
|
// for next time step
|
|
|
|
if (well_state.isNewWell(w) ) {
|
|
|
|
well_state.setNewWell(w, false);
|
|
|
|
}
|
2017-04-04 07:27:41 -05:00
|
|
|
} // end of for (int w = 0; w < nw; ++w)
|
2017-03-16 10:39:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 08:06:57 -06:00
|
|
|
WellCollection*
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 08:06:57 -06:00
|
|
|
wellCollection() const
|
|
|
|
{
|
|
|
|
return well_collection_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 08:06:57 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 08:06:57 -06:00
|
|
|
calculateEfficiencyFactors()
|
|
|
|
{
|
|
|
|
if ( !localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-26 08:27:39 -05:00
|
|
|
const int nw = number_of_wells_;
|
2017-02-14 08:06:57 -06:00
|
|
|
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-07-25 07:48:37 -05:00
|
|
|
const std::string well_name = well_container_[w]->name();
|
2017-02-14 08:06:57 -06:00
|
|
|
const WellNode& well_node = wellCollection()->findWellNode(well_name);
|
|
|
|
|
|
|
|
const double well_efficiency_factor = well_node.getAccumulativeEfficiencyFactor();
|
|
|
|
|
2017-07-25 07:48:37 -05:00
|
|
|
well_container_[w]->setWellEfficiencyFactor(well_efficiency_factor);
|
2017-02-14 08:06:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 08:06:57 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 08:06:57 -06:00
|
|
|
computeWellVoidageRates(const WellState& well_state,
|
|
|
|
std::vector<double>& well_voidage_rates,
|
|
|
|
std::vector<double>& voidage_conversion_coeffs) const
|
|
|
|
{
|
|
|
|
if ( !localWellsActive() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// TODO: for now, we store the voidage rates for all the production wells.
|
|
|
|
// For injection wells, the rates are stored as zero.
|
|
|
|
// We only store the conversion coefficients for all the injection wells.
|
|
|
|
// Later, more delicate model will be implemented here.
|
|
|
|
// And for the moment, group control can only work for serial running.
|
2017-08-10 09:00:27 -05:00
|
|
|
const int nw = numWells();
|
|
|
|
const int np = numPhases();
|
2017-02-14 08:06:57 -06:00
|
|
|
|
|
|
|
// we calculate the voidage rate for each well, that means the sum of all the phases.
|
|
|
|
well_voidage_rates.resize(nw, 0);
|
|
|
|
// store the conversion coefficients, while only for the use of injection wells.
|
|
|
|
voidage_conversion_coeffs.resize(nw * np, 1.0);
|
|
|
|
|
|
|
|
std::vector<double> well_rates(np, 0.0);
|
|
|
|
std::vector<double> convert_coeff(np, 1.0);
|
|
|
|
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
2017-07-26 08:27:39 -05:00
|
|
|
const bool is_producer = well_container_[w]->wellType() == PRODUCER;
|
2017-02-14 08:06:57 -06:00
|
|
|
|
|
|
|
// not sure necessary to change all the value to be positive
|
|
|
|
if (is_producer) {
|
|
|
|
std::transform(well_state.wellRates().begin() + np * w,
|
|
|
|
well_state.wellRates().begin() + np * (w + 1),
|
|
|
|
well_rates.begin(), std::negate<double>());
|
|
|
|
|
|
|
|
// the average hydrocarbon conditions of the whole field will be used
|
|
|
|
const int fipreg = 0; // Not considering FIP for the moment.
|
|
|
|
|
2017-08-10 04:20:09 -05:00
|
|
|
rate_converter_.calcCoeff(well_rates, fipreg, convert_coeff);
|
2017-02-14 08:06:57 -06:00
|
|
|
well_voidage_rates[w] = std::inner_product(well_rates.begin(), well_rates.end(),
|
|
|
|
convert_coeff.begin(), 0.0);
|
|
|
|
} else {
|
|
|
|
// TODO: Not sure whether will encounter situation with all zero rates
|
|
|
|
// and whether it will cause problem here.
|
|
|
|
std::copy(well_state.wellRates().begin() + np * w,
|
|
|
|
well_state.wellRates().begin() + np * (w + 1),
|
|
|
|
well_rates.begin());
|
|
|
|
// the average hydrocarbon conditions of the whole field will be used
|
|
|
|
const int fipreg = 0; // Not considering FIP for the moment.
|
2017-08-10 04:20:09 -05:00
|
|
|
rate_converter_.calcCoeff(well_rates, fipreg, convert_coeff);
|
2017-02-14 08:06:57 -06:00
|
|
|
std::copy(convert_coeff.begin(), convert_coeff.end(),
|
|
|
|
voidage_conversion_coeffs.begin() + np * w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-05-03 06:34:15 -05:00
|
|
|
template<typename TypeTag>
|
2017-02-14 08:06:57 -06:00
|
|
|
void
|
2017-05-03 06:34:15 -05:00
|
|
|
StandardWellsDense<TypeTag>::
|
2017-02-14 08:06:57 -06:00
|
|
|
applyVREPGroupControl(WellState& well_state) const
|
|
|
|
{
|
|
|
|
if ( wellCollection()->havingVREPGroups() ) {
|
|
|
|
std::vector<double> well_voidage_rates;
|
|
|
|
std::vector<double> voidage_conversion_coeffs;
|
|
|
|
computeWellVoidageRates(well_state, well_voidage_rates, voidage_conversion_coeffs);
|
|
|
|
wellCollection()->applyVREPGroupControls(well_voidage_rates, voidage_conversion_coeffs);
|
|
|
|
|
2017-03-09 08:54:23 -06:00
|
|
|
// for the wells under group control, update the control index for the well_state and well_controls
|
2017-02-14 08:06:57 -06:00
|
|
|
for (const WellNode* well_node : wellCollection()->getLeafNodes()) {
|
|
|
|
if (well_node->isInjector() && !well_node->individualControl()) {
|
|
|
|
const int well_index = well_node->selfIndex();
|
|
|
|
well_state.currentControls()[well_index] = well_node->groupControlIndex();
|
2017-03-09 08:54:23 -06:00
|
|
|
|
2017-07-26 08:27:39 -05:00
|
|
|
WellControls* wc = well_container_[well_index]->wellControls();
|
2017-03-09 08:54:23 -06:00
|
|
|
well_controls_set_current(wc, well_node->groupControlIndex());
|
2017-02-14 08:06:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-28 06:46:01 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
|
|
|
updateGroupControls(WellState& well_state) const
|
|
|
|
{
|
2017-08-09 09:36:16 -05:00
|
|
|
|
2017-06-28 06:46:01 -05:00
|
|
|
if (wellCollection()->groupControlActive()) {
|
2017-08-09 09:36:16 -05:00
|
|
|
for (int w = 0; w < number_of_wells_; ++w) {
|
|
|
|
// update whether well is under group control
|
|
|
|
// get well node in the well collection
|
|
|
|
WellNode& well_node = well_collection_->findWellNode(well_container_[w]->name());
|
2017-06-28 06:46:01 -05:00
|
|
|
|
2017-08-09 09:36:16 -05:00
|
|
|
// update whehter the well is under group control or individual control
|
|
|
|
const int current = well_state.currentControls()[w];
|
|
|
|
if (well_node.groupControlIndex() >= 0 && current == well_node.groupControlIndex()) {
|
|
|
|
// under group control
|
|
|
|
well_node.setIndividualControl(false);
|
|
|
|
} else {
|
|
|
|
// individual control
|
|
|
|
well_node.setIndividualControl(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applyVREPGroupControl(well_state);
|
2017-06-28 06:46:01 -05:00
|
|
|
// upate the well targets following group controls
|
|
|
|
// it will not change the control mode, only update the targets
|
2017-08-09 09:36:16 -05:00
|
|
|
wellCollection()->updateWellTargets(well_state.wellRates());
|
|
|
|
|
2017-06-28 06:46:01 -05:00
|
|
|
for (int w = 0; w < number_of_wells_; ++w) {
|
|
|
|
// TODO: check whether we need current argument in updateWellStateWithTarget
|
|
|
|
// maybe there is some circumstances that the current is different from the one
|
|
|
|
// in the WellState.
|
|
|
|
// while probalby, the current argument can be removed
|
|
|
|
const int current = well_state.currentControls()[w];
|
|
|
|
well_container_[w]->updateWellStateWithTarget(current, well_state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-14 08:06:57 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-07 02:29:31 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
|
|
|
setupCompressedToCartesian(const int* global_cell, int number_of_cells, std::map<int,int>& cartesian_to_compressed ) const
|
|
|
|
{
|
|
|
|
if (global_cell) {
|
|
|
|
for (int i = 0; i < number_of_cells; ++i) {
|
|
|
|
cartesian_to_compressed.insert(std::make_pair(global_cell[i], i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < number_of_cells; ++i) {
|
|
|
|
cartesian_to_compressed.insert(std::make_pair(i, i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
2017-06-27 13:06:44 -05:00
|
|
|
computeRepRadiusPerfLength(const Grid& grid)
|
2017-06-07 02:29:31 -05:00
|
|
|
{
|
|
|
|
// TODO, the function does not work for parallel running
|
|
|
|
// to be fixed later.
|
|
|
|
const int* global_cell = Opm::UgGridHelpers::globalCell(grid);
|
|
|
|
|
|
|
|
std::map<int,int> cartesian_to_compressed;
|
2017-08-11 07:51:29 -05:00
|
|
|
setupCompressedToCartesian(global_cell, number_of_cells_,
|
2017-06-07 02:29:31 -05:00
|
|
|
cartesian_to_compressed);
|
|
|
|
|
2017-07-31 09:42:26 -05:00
|
|
|
for (const auto& well : well_container_) {
|
|
|
|
well->computeRepRadiusPerfLength(grid, cartesian_to_compressed);
|
2017-06-07 02:29:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-09 01:21:51 -05:00
|
|
|
|
|
|
|
|
2017-06-23 05:24:50 -05:00
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
|
|
|
computeAverageFormationFactor(Simulator& ebosSimulator,
|
|
|
|
std::vector<double>& B_avg) const
|
|
|
|
{
|
|
|
|
const int np = numPhases();
|
|
|
|
|
|
|
|
const auto& grid = ebosSimulator.gridManager().grid();
|
|
|
|
const auto& gridView = grid.leafGridView();
|
|
|
|
ElementContext elemCtx(ebosSimulator);
|
|
|
|
const auto& elemEndIt = gridView.template end</*codim=*/0, Dune::Interior_Partition>();
|
|
|
|
|
|
|
|
for (auto elemIt = gridView.template begin</*codim=*/0, Dune::Interior_Partition>();
|
|
|
|
elemIt != elemEndIt; ++elemIt)
|
|
|
|
{
|
|
|
|
elemCtx.updatePrimaryStencil(*elemIt);
|
|
|
|
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
|
|
|
|
|
|
|
const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
|
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
|
|
|
|
for ( int phaseIdx = 0; phaseIdx < np; ++phaseIdx )
|
|
|
|
{
|
|
|
|
auto& B = B_avg[ phaseIdx ];
|
|
|
|
const int ebosPhaseIdx = flowPhaseToEbosPhaseIdx(phaseIdx);
|
|
|
|
|
|
|
|
B += 1 / fs.invB(ebosPhaseIdx).value();
|
|
|
|
}
|
|
|
|
if (has_solvent_) {
|
2017-06-27 08:16:22 -05:00
|
|
|
auto& B = B_avg[solventSaturationIdx];
|
2017-06-23 05:24:50 -05:00
|
|
|
B += 1 / intQuants.solventInverseFormationVolumeFactor().value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute global average
|
|
|
|
grid.comm().sum(B_avg.data(), B_avg.size());
|
|
|
|
for(auto& bval: B_avg)
|
|
|
|
{
|
|
|
|
bval/=global_nc_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-08 03:44:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWellsDense<TypeTag>::
|
2017-08-21 08:41:25 -05:00
|
|
|
updatePrimaryVariables(const WellState& well_state) const
|
2017-08-08 03:44:10 -05:00
|
|
|
{
|
|
|
|
for (const auto& well : well_container_) {
|
2017-08-21 08:41:25 -05:00
|
|
|
well->updatePrimaryVariables(well_state);
|
2017-08-08 03:44:10 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 09:45:06 -06:00
|
|
|
} // namespace Opm
|