2017-06-15 04:41:03 -05:00
|
|
|
/*
|
2017-08-03 09:45:59 -05:00
|
|
|
Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
|
2017-06-15 04:41:03 -05:00
|
|
|
Copyright 2017 Statoil ASA.
|
2017-08-03 09:45:59 -05:00
|
|
|
Copyright 2016 - 2017 IRIS AS.
|
2017-06-15 04:41:03 -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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
2017-05-15 07:46:43 -05:00
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
StandardWell<TypeTag>::
|
2017-11-22 07:39:42 -06:00
|
|
|
StandardWell(const Well* well, const int time_step, const Wells* wells,
|
|
|
|
const ModelParameters& param,
|
|
|
|
const RateConverterType& rate_converter,
|
2017-11-30 09:31:48 -06:00
|
|
|
const int pvtRegionIdx,
|
|
|
|
const int num_components)
|
|
|
|
: Base(well, time_step, wells, param, rate_converter, pvtRegionIdx, num_components)
|
2017-08-04 06:07:16 -05:00
|
|
|
, perf_densities_(number_of_perforations_)
|
|
|
|
, perf_pressure_diffs_(number_of_perforations_)
|
2017-08-21 08:41:25 -05:00
|
|
|
, primary_variables_(numWellEq, 0.0)
|
|
|
|
, primary_variables_evaluation_(numWellEq) // the number of the primary variables
|
2018-05-18 03:57:08 -05:00
|
|
|
, F0_(numWellConservationEq)
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
2018-05-18 03:57:08 -05:00
|
|
|
assert(num_components_ == numWellConservationEq);
|
|
|
|
|
2017-08-03 08:14:36 -05:00
|
|
|
duneB_.setBuildMode( OffDiagMatWell::row_wise );
|
|
|
|
duneC_.setBuildMode( OffDiagMatWell::row_wise );
|
|
|
|
invDuneD_.setBuildMode( DiagMatWell::row_wise );
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
init(const PhaseUsage* phase_usage_arg,
|
2017-08-01 09:11:55 -05:00
|
|
|
const std::vector<double>& depth_arg,
|
2017-06-21 07:07:11 -05:00
|
|
|
const double gravity_arg,
|
|
|
|
const int num_cells)
|
|
|
|
{
|
2017-12-04 02:14:08 -06:00
|
|
|
Base::init(phase_usage_arg, depth_arg, gravity_arg, num_cells);
|
2017-06-28 08:20:25 -05:00
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
perf_depth_.resize(number_of_perforations_, 0.);
|
|
|
|
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-08-01 09:11:55 -05:00
|
|
|
perf_depth_[perf] = depth_arg[cell_idx];
|
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
// setup sparsity pattern for the matrices
|
2017-07-21 04:59:28 -05:00
|
|
|
//[A C^T [x = [ res
|
|
|
|
// B D] x_well] res_well]
|
2017-06-21 07:07:11 -05:00
|
|
|
// set the size of the matrices
|
|
|
|
invDuneD_.setSize(1, 1, 1);
|
2017-08-04 06:07:16 -05:00
|
|
|
duneB_.setSize(1, num_cells, number_of_perforations_);
|
|
|
|
duneC_.setSize(1, num_cells, number_of_perforations_);
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
for (auto row=invDuneD_.createbegin(), end = invDuneD_.createend(); row!=end; ++row) {
|
|
|
|
// Add nonzeros for diagonal
|
|
|
|
row.insert(row.index());
|
|
|
|
}
|
|
|
|
|
2017-07-21 04:59:28 -05:00
|
|
|
for (auto row = duneB_.createbegin(), end = duneB_.createend(); row!=end; ++row) {
|
2017-08-04 06:07:16 -05:00
|
|
|
for (int perf = 0 ; perf < number_of_perforations_; ++perf) {
|
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-06-21 07:07:11 -05:00
|
|
|
row.insert(cell_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 04:59:28 -05:00
|
|
|
// make the C^T matrix
|
|
|
|
for (auto row = duneC_.createbegin(), end = duneC_.createend(); row!=end; ++row) {
|
2017-08-04 06:07:16 -05:00
|
|
|
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-06-21 07:07:11 -05:00
|
|
|
row.insert(cell_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resWell_.resize(1);
|
|
|
|
|
|
|
|
// resize temporary class variables
|
2017-07-21 04:59:28 -05:00
|
|
|
Bx_.resize( duneB_.N() );
|
2017-06-21 07:07:11 -05:00
|
|
|
invDrw_.resize( invDuneD_.N() );
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void StandardWell<TypeTag>::
|
2017-08-21 08:41:25 -05:00
|
|
|
initPrimaryVariablesEvaluation() const
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
2018-05-09 08:07:43 -05:00
|
|
|
for (int eqIdx = 0; eqIdx < numWellEq; ++eqIdx) {
|
2017-10-09 07:44:50 -05:00
|
|
|
assert( (size_t)eqIdx < primary_variables_.size() );
|
2017-06-19 09:46:06 -05:00
|
|
|
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_evaluation_[eqIdx] = 0.0;
|
|
|
|
primary_variables_evaluation_[eqIdx].setValue(primary_variables_[eqIdx]);
|
|
|
|
primary_variables_evaluation_[eqIdx].setDerivative(numEq + eqIdx, 1.0);
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
2018-05-09 08:07:43 -05:00
|
|
|
const typename StandardWell<TypeTag>::EvalWell&
|
2017-06-19 07:49:49 -05:00
|
|
|
StandardWell<TypeTag>::
|
2017-06-15 04:41:03 -05:00
|
|
|
getBhp() const
|
|
|
|
{
|
2018-05-08 03:54:57 -05:00
|
|
|
return primary_variables_evaluation_[Bhp];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-09 05:16:33 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
const typename StandardWell<TypeTag>::EvalWell&
|
|
|
|
StandardWell<TypeTag>::
|
2018-05-30 08:44:05 -05:00
|
|
|
getWQTotal() const
|
2018-05-09 05:16:33 -05:00
|
|
|
{
|
2018-05-30 08:44:05 -05:00
|
|
|
return primary_variables_evaluation_[WQTotal];
|
2018-05-09 05:16:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
typename StandardWell<TypeTag>::EvalWell
|
|
|
|
StandardWell<TypeTag>::
|
2018-05-09 08:07:43 -05:00
|
|
|
getQs(const int comp_idx) const
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
2018-05-30 08:44:05 -05:00
|
|
|
// Note: currently, the WQTotal definition is still depends on Injector/Producer.
|
2017-11-30 09:31:48 -06:00
|
|
|
assert(comp_idx < num_components_);
|
2017-06-15 04:41:03 -05:00
|
|
|
|
2018-05-08 03:54:57 -05:00
|
|
|
if (well_type_ == INJECTOR) { // only single phase injection
|
2018-05-09 05:16:33 -05:00
|
|
|
// TODO: using comp_frac here is dangerous, it should be changed later
|
|
|
|
// Most likely, it should be changed to use distr, or at least, we need to update comp_frac_ based on distr
|
|
|
|
// while solvent might complicate the situation
|
2018-05-08 03:54:57 -05:00
|
|
|
const auto pu = phaseUsage();
|
|
|
|
const int legacyCompIdx = ebosCompIdxToFlowCompIdx(comp_idx);
|
2018-05-09 05:16:33 -05:00
|
|
|
double comp_frac = 0.0;
|
|
|
|
if (has_solvent && comp_idx == contiSolventEqIdx) { // solvent
|
|
|
|
comp_frac = comp_frac_[pu.phase_pos[ Gas ]] * wsolvent();
|
|
|
|
} else if (legacyCompIdx == pu.phase_pos[ Gas ]) {
|
|
|
|
comp_frac = comp_frac_[legacyCompIdx];
|
|
|
|
if (has_solvent) {
|
|
|
|
comp_frac *= (1.0 - wsolvent());
|
2017-06-19 05:43:08 -05:00
|
|
|
}
|
2018-05-09 05:16:33 -05:00
|
|
|
} else {
|
|
|
|
comp_frac = comp_frac_[legacyCompIdx];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
2018-05-11 07:21:53 -05:00
|
|
|
|
2018-05-30 08:44:05 -05:00
|
|
|
return comp_frac * primary_variables_evaluation_[WQTotal];
|
2018-05-11 07:21:53 -05:00
|
|
|
} else { // producers
|
2018-05-30 08:44:05 -05:00
|
|
|
return primary_variables_evaluation_[WQTotal] * wellVolumeFractionScaled(comp_idx);
|
2017-06-19 05:43:08 -05:00
|
|
|
}
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
typename StandardWell<TypeTag>::EvalWell
|
|
|
|
StandardWell<TypeTag>::
|
2017-06-20 03:54:33 -05:00
|
|
|
wellVolumeFractionScaled(const int compIdx) const
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
2017-06-20 03:54:33 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
const int legacyCompIdx = ebosCompIdxToFlowCompIdx(compIdx);
|
|
|
|
const double scal = scalingFactor(legacyCompIdx);
|
2017-09-05 02:25:34 -05:00
|
|
|
if (scal > 0)
|
|
|
|
return wellVolumeFraction(compIdx) / scal;
|
2017-06-20 03:54:33 -05:00
|
|
|
|
2017-09-05 02:25:34 -05:00
|
|
|
// the scaling factor may be zero for RESV controlled wells.
|
|
|
|
return wellVolumeFraction(compIdx);
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
typename StandardWell<TypeTag>::EvalWell
|
|
|
|
StandardWell<TypeTag>::
|
2017-12-04 02:14:08 -06:00
|
|
|
wellVolumeFraction(const unsigned compIdx) const
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) && compIdx == Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
return primary_variables_evaluation_[WFrac];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) && compIdx == Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
return primary_variables_evaluation_[GFrac];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
2018-04-13 04:23:29 -05:00
|
|
|
if (has_solvent && compIdx == (unsigned)contiSolventEqIdx) {
|
2017-08-21 08:41:25 -05:00
|
|
|
return primary_variables_evaluation_[SFrac];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
|
2017-06-15 04:41:03 -05:00
|
|
|
// Oil fraction
|
|
|
|
EvalWell well_fraction = 1.0;
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
well_fraction -= primary_variables_evaluation_[WFrac];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
well_fraction -= primary_variables_evaluation_[GFrac];
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
2017-06-20 03:54:33 -05:00
|
|
|
if (has_solvent) {
|
2017-08-21 08:41:25 -05:00
|
|
|
well_fraction -= primary_variables_evaluation_[SFrac];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
2017-06-15 04:41:03 -05:00
|
|
|
return well_fraction;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
typename StandardWell<TypeTag>::EvalWell
|
|
|
|
StandardWell<TypeTag>::
|
2017-06-20 03:54:33 -05:00
|
|
|
wellSurfaceVolumeFraction(const int compIdx) const
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
|
|
|
EvalWell sum_volume_fraction_scaled = 0.;
|
2017-11-30 09:31:48 -06:00
|
|
|
for (int idx = 0; idx < num_components_; ++idx) {
|
2017-06-20 03:54:33 -05:00
|
|
|
sum_volume_fraction_scaled += wellVolumeFractionScaled(idx);
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(sum_volume_fraction_scaled.value() != 0.);
|
|
|
|
|
2017-06-20 03:54:33 -05:00
|
|
|
return wellVolumeFractionScaled(compIdx) / sum_volume_fraction_scaled;
|
2017-06-15 10:19:49 -05:00
|
|
|
}
|
2017-06-15 04:41:03 -05:00
|
|
|
|
2017-06-19 08:24:49 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
typename StandardWell<TypeTag>::EvalWell
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
extendEval(const Eval& in) const
|
|
|
|
{
|
|
|
|
EvalWell out = 0.0;
|
|
|
|
out.setValue(in.value());
|
|
|
|
for(int eqIdx = 0; eqIdx < numEq;++eqIdx) {
|
2017-08-31 00:50:28 -05:00
|
|
|
out.setDerivative(eqIdx, in.derivative(eqIdx));
|
2017-06-19 08:24:49 -05:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2017-06-19 09:46:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computePerfRate(const IntensiveQuantities& intQuants,
|
|
|
|
const std::vector<EvalWell>& mob_perfcells_dense,
|
2017-06-20 03:54:33 -05:00
|
|
|
const double Tw, const EvalWell& bhp, const double& cdp,
|
2018-02-12 09:32:46 -06:00
|
|
|
const bool& allow_cf, std::vector<EvalWell>& cq_s,
|
|
|
|
double& perf_dis_gas_rate, double& perf_vap_oil_rate) const
|
2017-06-19 09:46:06 -05:00
|
|
|
{
|
2017-11-30 09:31:48 -06:00
|
|
|
std::vector<EvalWell> cmix_s(num_components_,0.0);
|
|
|
|
for (int componentIdx = 0; componentIdx < num_components_; ++componentIdx) {
|
2017-06-20 03:54:33 -05:00
|
|
|
cmix_s[componentIdx] = wellSurfaceVolumeFraction(componentIdx);
|
|
|
|
}
|
2017-09-08 04:06:34 -05:00
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
const EvalWell pressure = extendEval(fs.pressure(FluidSystem::oilPhaseIdx));
|
|
|
|
const EvalWell rs = extendEval(fs.Rs());
|
|
|
|
const EvalWell rv = extendEval(fs.Rv());
|
2017-11-30 09:31:48 -06:00
|
|
|
std::vector<EvalWell> b_perfcells_dense(num_components_, 0.0);
|
2017-12-04 02:14:08 -06:00
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
b_perfcells_dense[compIdx] = extendEval(fs.invB(phaseIdx));
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2017-06-27 08:16:22 -05:00
|
|
|
b_perfcells_dense[contiSolventEqIdx] = extendEval(intQuants.solventInverseFormationVolumeFactor());
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pressure drawdown (also used to determine direction of flow)
|
2017-09-08 04:06:34 -05:00
|
|
|
const EvalWell well_pressure = bhp + cdp;
|
|
|
|
const EvalWell drawdown = pressure - well_pressure;
|
2017-06-20 03:54:33 -05:00
|
|
|
|
|
|
|
// producing perforations
|
|
|
|
if ( drawdown.value() > 0 ) {
|
|
|
|
//Do nothing if crossflow is not allowed
|
2017-08-04 06:07:16 -05:00
|
|
|
if (!allow_cf && well_type_ == INJECTOR) {
|
2017-06-20 03:54:33 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute component volumetric rates at standard conditions
|
2017-11-30 09:31:48 -06:00
|
|
|
for (int componentIdx = 0; componentIdx < num_components_; ++componentIdx) {
|
2017-06-20 03:54:33 -05:00
|
|
|
const EvalWell cq_p = - Tw * (mob_perfcells_dense[componentIdx] * drawdown);
|
|
|
|
cq_s[componentIdx] = b_perfcells_dense[componentIdx] * cq_p;
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
|
|
|
const EvalWell cq_sOil = cq_s[oilCompIdx];
|
|
|
|
const EvalWell cq_sGas = cq_s[gasCompIdx];
|
2018-02-12 09:32:46 -06:00
|
|
|
const EvalWell dis_gas = rs * cq_sOil;
|
|
|
|
const EvalWell vap_oil = rv * cq_sGas;
|
|
|
|
|
|
|
|
cq_s[gasCompIdx] += dis_gas;
|
|
|
|
cq_s[oilCompIdx] += vap_oil;
|
|
|
|
|
|
|
|
// recording the perforation solution gas rate and solution oil rates
|
|
|
|
if (well_type_ == PRODUCER) {
|
|
|
|
perf_dis_gas_rate = dis_gas.value();
|
|
|
|
perf_vap_oil_rate = vap_oil.value();
|
|
|
|
}
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
2017-06-19 09:46:06 -05:00
|
|
|
|
2017-06-20 03:54:33 -05:00
|
|
|
} else {
|
|
|
|
//Do nothing if crossflow is not allowed
|
2017-08-04 06:07:16 -05:00
|
|
|
if (!allow_cf && well_type_ == PRODUCER) {
|
2017-06-20 03:54:33 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using total mobilities
|
|
|
|
EvalWell total_mob_dense = mob_perfcells_dense[0];
|
2017-11-30 09:31:48 -06:00
|
|
|
for (int componentIdx = 1; componentIdx < num_components_; ++componentIdx) {
|
2017-06-20 03:54:33 -05:00
|
|
|
total_mob_dense += mob_perfcells_dense[componentIdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
// injection perforations total volume rates
|
|
|
|
const EvalWell cqt_i = - Tw * (total_mob_dense * drawdown);
|
2017-06-19 09:46:06 -05:00
|
|
|
|
2017-06-20 03:54:33 -05:00
|
|
|
// compute volume ratio between connection at standard conditions
|
|
|
|
EvalWell volumeRatio = 0.0;
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
|
|
|
const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
|
|
|
volumeRatio += cmix_s[waterCompIdx] / b_perfcells_dense[waterCompIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_solvent) {
|
2017-06-27 08:16:22 -05:00
|
|
|
volumeRatio += cmix_s[contiSolventEqIdx] / b_perfcells_dense[contiSolventEqIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
2017-06-19 09:46:06 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
2017-06-20 03:54:33 -05:00
|
|
|
// Incorporate RS/RV factors if both oil and gas active
|
|
|
|
const EvalWell d = 1.0 - rv * rs;
|
|
|
|
|
|
|
|
if (d.value() == 0.0) {
|
2018-02-08 05:02:25 -06:00
|
|
|
OPM_THROW(Opm::NumericalIssue, "Zero d value obtained for well " << name() << " during flux calcuation"
|
2017-06-20 03:54:33 -05:00
|
|
|
<< " with rs " << rs << " and rv " << rv);
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
const EvalWell tmp_oil = (cmix_s[oilCompIdx] - rv * cmix_s[gasCompIdx]) / d;
|
2017-06-20 03:54:33 -05:00
|
|
|
//std::cout << "tmp_oil " <<tmp_oil << std::endl;
|
2017-12-04 02:14:08 -06:00
|
|
|
volumeRatio += tmp_oil / b_perfcells_dense[oilCompIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
const EvalWell tmp_gas = (cmix_s[gasCompIdx] - rs * cmix_s[oilCompIdx]) / d;
|
2017-06-20 03:54:33 -05:00
|
|
|
//std::cout << "tmp_gas " <<tmp_gas << std::endl;
|
2017-12-04 02:14:08 -06:00
|
|
|
volumeRatio += tmp_gas / b_perfcells_dense[gasCompIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
else {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
volumeRatio += cmix_s[oilCompIdx] / b_perfcells_dense[oilCompIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
|
|
|
volumeRatio += cmix_s[gasCompIdx] / b_perfcells_dense[gasCompIdx];
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// injecting connections total volumerates at standard conditions
|
|
|
|
EvalWell cqt_is = cqt_i/volumeRatio;
|
|
|
|
//std::cout << "volrat " << volumeRatio << " " << volrat_perf_[perf] << std::endl;
|
2017-11-30 09:31:48 -06:00
|
|
|
for (int componentIdx = 0; componentIdx < num_components_; ++componentIdx) {
|
2017-06-20 03:54:33 -05:00
|
|
|
cq_s[componentIdx] = cmix_s[componentIdx] * cqt_is; // * b_perfcells_dense[phase];
|
|
|
|
}
|
2018-02-12 09:32:46 -06:00
|
|
|
|
|
|
|
// calculating the perforation solution gas rate and solution oil rates
|
|
|
|
if (well_type_ == PRODUCER) {
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
2018-02-21 06:12:48 -06:00
|
|
|
// TODO: the formulations here remain to be tested with cases with strong crossflow through production wells
|
|
|
|
// s means standard condition, r means reservoir condition
|
|
|
|
// q_os = q_or * b_o + rv * q_gr * b_g
|
|
|
|
// q_gs = q_gr * g_g + rs * q_or * b_o
|
|
|
|
// d = 1.0 - rs * rv
|
|
|
|
// q_or = 1 / (b_o * d) * (q_os - rv * q_gs)
|
|
|
|
// q_gr = 1 / (b_g * d) * (q_gs - rs * q_os)
|
|
|
|
|
2018-02-12 09:32:46 -06:00
|
|
|
const double d = 1.0 - rv.value() * rs.value();
|
2018-02-21 06:12:48 -06:00
|
|
|
// vaporized oil into gas
|
|
|
|
// rv * q_gr * b_g = rv * (q_gs - rs * q_os) / d
|
|
|
|
perf_vap_oil_rate = rv.value() * (cq_s[gasCompIdx].value() - rs.value() * cq_s[oilCompIdx].value()) / d;
|
|
|
|
// dissolved of gas in oil
|
|
|
|
// rs * q_or * b_o = rs * (q_os - rv * q_gs) / d
|
|
|
|
perf_dis_gas_rate = rs.value() * (cq_s[oilCompIdx].value() - rv.value() * cq_s[gasCompIdx].value()) / d;
|
2018-02-12 09:32:46 -06:00
|
|
|
}
|
|
|
|
}
|
2017-06-20 03:54:33 -05:00
|
|
|
}
|
2017-06-19 09:46:06 -05:00
|
|
|
}
|
|
|
|
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
assembleWellEq(Simulator& ebosSimulator,
|
|
|
|
const double dt,
|
|
|
|
WellState& well_state,
|
|
|
|
bool only_wells)
|
|
|
|
{
|
2017-08-04 06:07:16 -05:00
|
|
|
const int np = number_of_phases_;
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
// clear all entries
|
2017-09-22 08:47:24 -05:00
|
|
|
if (!only_wells) {
|
|
|
|
duneB_ = 0.0;
|
|
|
|
duneC_ = 0.0;
|
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
invDuneD_ = 0.0;
|
|
|
|
resWell_ = 0.0;
|
|
|
|
|
|
|
|
auto& ebosJac = ebosSimulator.model().linearizer().matrix();
|
|
|
|
auto& ebosResid = ebosSimulator.model().linearizer().residual();
|
|
|
|
|
|
|
|
// TODO: it probably can be static member for StandardWell
|
|
|
|
const double volume = 0.002831684659200; // 0.1 cu ft;
|
|
|
|
|
2017-06-27 09:59:52 -05:00
|
|
|
const bool allow_cf = crossFlowAllowed(ebosSimulator);
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
const EvalWell& bhp = getBhp();
|
|
|
|
|
2018-02-14 06:34:35 -06:00
|
|
|
// the solution gas rate and solution oil rate needs to be reset to be zero for well_state.
|
|
|
|
well_state.wellVaporizedOilRates()[index_of_well_] = 0.;
|
|
|
|
well_state.wellDissolvedGasRates()[index_of_well_] = 0.;
|
2018-02-12 09:32:46 -06:00
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-06-21 07:07:11 -05:00
|
|
|
const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/ 0));
|
2017-11-30 09:31:48 -06:00
|
|
|
std::vector<EvalWell> cq_s(num_components_,0.0);
|
|
|
|
std::vector<EvalWell> mob(num_components_, 0.0);
|
2017-06-21 07:07:11 -05:00
|
|
|
getMobility(ebosSimulator, perf, mob);
|
2018-02-12 09:32:46 -06:00
|
|
|
double perf_dis_gas_rate = 0.;
|
|
|
|
double perf_vap_oil_rate = 0.;
|
|
|
|
computePerfRate(intQuants, mob, well_index_[perf], bhp, perf_pressure_diffs_[perf], allow_cf,
|
|
|
|
cq_s, perf_dis_gas_rate, perf_vap_oil_rate);
|
|
|
|
|
|
|
|
// updating the solution gas rate and solution oil rate
|
|
|
|
if (well_type_ == PRODUCER) {
|
|
|
|
well_state.wellDissolvedGasRates()[index_of_well_] += perf_dis_gas_rate;
|
|
|
|
well_state.wellVaporizedOilRates()[index_of_well_] += perf_vap_oil_rate;
|
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-11-30 09:31:48 -06:00
|
|
|
for (int componentIdx = 0; componentIdx < num_components_; ++componentIdx) {
|
2017-08-01 04:53:56 -05:00
|
|
|
// the cq_s entering mass balance equations need to consider the efficiency factors.
|
|
|
|
const EvalWell cq_s_effective = cq_s[componentIdx] * well_efficiency_factor_;
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
if (!only_wells) {
|
|
|
|
// subtract sum of component fluxes in the reservoir equation.
|
|
|
|
// need to consider the efficiency factor
|
2017-12-04 02:14:08 -06:00
|
|
|
ebosResid[cell_idx][componentIdx] -= cq_s_effective.value();
|
2017-08-01 04:53:56 -05:00
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
// subtract sum of phase fluxes in the well equations.
|
2017-09-11 05:55:12 -05:00
|
|
|
resWell_[0][componentIdx] -= cq_s_effective.value();
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
// assemble the jacobians
|
|
|
|
for (int pvIdx = 0; pvIdx < numWellEq; ++pvIdx) {
|
|
|
|
if (!only_wells) {
|
|
|
|
// also need to consider the efficiency factor when manipulating the jacobians.
|
2017-12-04 02:14:08 -06:00
|
|
|
duneC_[0][cell_idx][pvIdx][componentIdx] -= cq_s_effective.derivative(pvIdx+numEq); // intput in transformed matrix
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
2017-09-11 05:55:12 -05:00
|
|
|
invDuneD_[0][0][componentIdx][pvIdx] -= cq_s_effective.derivative(pvIdx+numEq);
|
2017-08-01 04:53:56 -05:00
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
for (int pvIdx = 0; pvIdx < numEq; ++pvIdx) {
|
|
|
|
if (!only_wells) {
|
|
|
|
// also need to consider the efficiency factor when manipulating the jacobians.
|
2017-12-04 02:14:08 -06:00
|
|
|
ebosJac[cell_idx][cell_idx][componentIdx][pvIdx] -= cq_s_effective.derivative(pvIdx);
|
2017-08-31 00:50:28 -05:00
|
|
|
duneB_[0][cell_idx][componentIdx][pvIdx] -= cq_s_effective.derivative(pvIdx);
|
2017-06-27 09:04:04 -05:00
|
|
|
}
|
2017-08-01 04:53:56 -05:00
|
|
|
}
|
2017-06-27 09:04:04 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
// Store the perforation phase flux for later usage.
|
2017-12-04 02:14:08 -06:00
|
|
|
if (has_solvent && componentIdx == contiSolventEqIdx) {
|
2017-08-01 04:53:56 -05:00
|
|
|
well_state.perfRateSolvent()[first_perf_ + perf] = cq_s[componentIdx].value();
|
|
|
|
} else {
|
2017-12-04 02:14:08 -06:00
|
|
|
well_state.perfPhaseRates()[(first_perf_ + perf) * np + ebosCompIdxToFlowCompIdx(componentIdx)] = cq_s[componentIdx].value();
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
2017-08-01 04:53:56 -05:00
|
|
|
}
|
2018-05-08 02:56:15 -05:00
|
|
|
if (has_energy) {
|
2018-03-26 03:50:33 -05:00
|
|
|
|
|
|
|
auto fs = intQuants.fluidState();
|
2018-05-08 02:56:15 -05:00
|
|
|
const int reportStepIdx = ebosSimulator.episodeIndex();
|
2018-03-26 03:50:33 -05:00
|
|
|
|
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
// convert to reservoar conditions
|
|
|
|
EvalWell cq_r_thermal = 0.0;
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
|
|
|
|
if(FluidSystem::waterPhaseIdx == phaseIdx)
|
|
|
|
cq_r_thermal = cq_s[activeCompIdx] / extendEval(fs.invB(phaseIdx));
|
|
|
|
|
|
|
|
// remove dissolved gas and vapporized oil
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
|
|
|
// q_os = q_or * b_o + rv * q_gr * b_g
|
|
|
|
// q_gs = q_gr * g_g + rs * q_or * b_o
|
|
|
|
// d = 1.0 - rs * rv
|
2018-05-08 02:56:15 -05:00
|
|
|
const EvalWell d = extendEval(1.0 - fs.Rv() * fs.Rs());
|
2018-03-26 03:50:33 -05:00
|
|
|
// q_gr = 1 / (b_g * d) * (q_gs - rs * q_os)
|
|
|
|
if(FluidSystem::gasPhaseIdx == phaseIdx)
|
|
|
|
cq_r_thermal = (cq_s[gasCompIdx] - extendEval(fs.Rs()) * cq_s[oilCompIdx]) / (d * extendEval(fs.invB(phaseIdx)) );
|
|
|
|
// q_or = 1 / (b_o * d) * (q_os - rv * q_gs)
|
|
|
|
if(FluidSystem::oilPhaseIdx == phaseIdx)
|
|
|
|
cq_r_thermal = (cq_s[oilCompIdx] - extendEval(fs.Rv()) * cq_s[gasCompIdx]) / (d * extendEval(fs.invB(phaseIdx)) );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
cq_r_thermal = cq_s[activeCompIdx] / extendEval(fs.invB(phaseIdx));
|
|
|
|
}
|
|
|
|
|
|
|
|
// change temperature for injecting fluids
|
|
|
|
if (well_type_ == INJECTOR && cq_s[activeCompIdx] > 0.0){
|
|
|
|
const auto& injProps = this->well_ecl_->getInjectionProperties(reportStepIdx);
|
|
|
|
fs.setTemperature(injProps.temperature);
|
|
|
|
typedef typename std::decay<decltype(fs)>::type::Scalar FsScalar;
|
|
|
|
typename FluidSystem::template ParameterCache<FsScalar> paramCache;
|
2018-05-08 02:56:15 -05:00
|
|
|
const unsigned pvtRegionIdx = intQuants.pvtRegionIndex();
|
2018-03-26 03:50:33 -05:00
|
|
|
paramCache.setRegionIndex(pvtRegionIdx);
|
|
|
|
paramCache.setMaxOilSat(ebosSimulator.problem().maxOilSaturation(cell_idx));
|
|
|
|
paramCache.updatePhase(fs, phaseIdx);
|
|
|
|
|
|
|
|
const auto& rho = FluidSystem::density(fs, paramCache, phaseIdx);
|
|
|
|
fs.setDensity(phaseIdx, rho);
|
|
|
|
const auto& h = FluidSystem::enthalpy(fs, paramCache, phaseIdx);
|
|
|
|
fs.setEnthalpy(phaseIdx, h);
|
|
|
|
}
|
|
|
|
// compute the thermal flux
|
|
|
|
cq_r_thermal *= extendEval(fs.enthalpy(phaseIdx)) * extendEval(fs.density(phaseIdx));
|
|
|
|
// scale the flux by the scaling factor for the energy equation
|
|
|
|
cq_r_thermal *= GET_PROP_VALUE(TypeTag, BlackOilEnergyScalingFactor);
|
|
|
|
|
|
|
|
if (!only_wells) {
|
|
|
|
for (int pvIdx = 0; pvIdx < numEq; ++pvIdx) {
|
|
|
|
ebosJac[cell_idx][cell_idx][contiEnergyEqIdx][pvIdx] -= cq_r_thermal.derivative(pvIdx);
|
|
|
|
}
|
|
|
|
ebosResid[cell_idx][contiEnergyEqIdx] -= cq_r_thermal.value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
if (has_polymer) {
|
2017-11-30 10:14:29 -06:00
|
|
|
// TODO: the application of well efficiency factor has not been tested with an example yet
|
2017-12-04 02:14:08 -06:00
|
|
|
const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
|
|
|
EvalWell cq_s_poly = cq_s[waterCompIdx] * well_efficiency_factor_;
|
2017-08-04 06:07:16 -05:00
|
|
|
if (well_type_ == INJECTOR) {
|
2017-08-01 04:53:56 -05:00
|
|
|
cq_s_poly *= wpolymer();
|
|
|
|
} else {
|
|
|
|
cq_s_poly *= extendEval(intQuants.polymerConcentration() * intQuants.polymerViscosityCorrection());
|
|
|
|
}
|
|
|
|
if (!only_wells) {
|
|
|
|
for (int pvIdx = 0; pvIdx < numEq; ++pvIdx) {
|
2017-08-31 00:50:28 -05:00
|
|
|
ebosJac[cell_idx][cell_idx][contiPolymerEqIdx][pvIdx] -= cq_s_poly.derivative(pvIdx);
|
2017-06-27 09:04:04 -05:00
|
|
|
}
|
2017-08-01 04:53:56 -05:00
|
|
|
ebosResid[cell_idx][contiPolymerEqIdx] -= cq_s_poly.value();
|
2017-07-28 07:41:00 -05:00
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
// Store the perforation pressure for later usage.
|
2017-08-04 06:07:16 -05:00
|
|
|
well_state.perfPress()[first_perf_ + perf] = well_state.bhp()[index_of_well_] + perf_pressure_diffs_[perf];
|
2017-08-01 04:53:56 -05:00
|
|
|
}
|
2017-06-27 09:04:04 -05:00
|
|
|
|
2017-08-01 04:53:56 -05:00
|
|
|
// add vol * dF/dt + Q to the well equations;
|
2018-05-18 03:57:08 -05:00
|
|
|
for (int componentIdx = 0; componentIdx < numWellConservationEq; ++componentIdx) {
|
2017-08-01 04:53:56 -05:00
|
|
|
EvalWell resWell_loc = (wellSurfaceVolumeFraction(componentIdx) - F0_[componentIdx]) * volume / dt;
|
2017-09-11 05:55:12 -05:00
|
|
|
resWell_loc += getQs(componentIdx) * well_efficiency_factor_;
|
2017-08-01 04:53:56 -05:00
|
|
|
for (int pvIdx = 0; pvIdx < numWellEq; ++pvIdx) {
|
|
|
|
invDuneD_[0][0][componentIdx][pvIdx] += resWell_loc.derivative(pvIdx+numEq);
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
2017-08-01 04:53:56 -05:00
|
|
|
resWell_[0][componentIdx] += resWell_loc.value();
|
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2018-05-09 05:16:33 -05:00
|
|
|
assembleControlEq();
|
|
|
|
|
2017-06-21 07:07:11 -05:00
|
|
|
// do the local inversion of D.
|
2018-02-26 05:16:04 -06:00
|
|
|
// we do this manually with invertMatrix to always get our
|
|
|
|
// specializations in for 3x3 and 4x4 matrices.
|
2018-05-08 03:54:57 -05:00
|
|
|
Dune::ISTLUtility::invertMatrix(invDuneD_[0][0]);
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-09 05:16:33 -05:00
|
|
|
template <typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
assembleControlEq()
|
|
|
|
{
|
|
|
|
EvalWell control_eq(0.0);
|
|
|
|
switch (well_controls_get_current_type(well_controls_)) {
|
|
|
|
case THP:
|
|
|
|
{
|
2018-05-15 09:17:01 -05:00
|
|
|
std::vector<EvalWell> rates(3, 0.);
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
|
|
|
rates[ Water ] = getQs(flowPhaseToEbosCompIdx(Water));
|
|
|
|
}
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
|
|
|
rates[ Oil ] = getQs(flowPhaseToEbosCompIdx(Oil));
|
|
|
|
}
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
rates[ Gas ] = getQs(flowPhaseToEbosCompIdx(Gas));
|
|
|
|
}
|
|
|
|
const int current = well_controls_get_current(well_controls_);
|
|
|
|
control_eq = getBhp() - calculateBhpFromThp(rates, current);
|
2018-05-09 05:16:33 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BHP:
|
|
|
|
{
|
|
|
|
const double target_bhp = well_controls_get_current_target(well_controls_);
|
|
|
|
control_eq = getBhp() - target_bhp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SURFACE_RATE:
|
|
|
|
{
|
2018-05-15 09:34:31 -05:00
|
|
|
const double target_rate = well_controls_get_current_target(well_controls_); // surface rate target
|
2018-05-09 05:16:33 -05:00
|
|
|
if (well_type_ == INJECTOR) {
|
2018-05-18 03:57:08 -05:00
|
|
|
// only handles single phase injection now
|
2018-06-06 03:59:41 -05:00
|
|
|
assert(well_ecl_->getInjectionProperties(current_step_).injectorType != WellInjector::MULTI);
|
2018-05-30 08:44:05 -05:00
|
|
|
control_eq = getWQTotal() - target_rate;
|
2018-05-09 05:16:33 -05:00
|
|
|
} else if (well_type_ == PRODUCER) {
|
2018-05-16 08:35:58 -05:00
|
|
|
if (target_rate != 0.) {
|
|
|
|
EvalWell rate_for_control(0.);
|
2018-05-30 08:44:05 -05:00
|
|
|
const EvalWell& g_total = getWQTotal();
|
2018-05-18 03:57:08 -05:00
|
|
|
// a variable to check if we are producing any targeting fluids
|
|
|
|
double sum_fraction = 0.;
|
|
|
|
const double* distr = well_controls_get_current_distr(well_controls_);
|
2018-05-16 08:35:58 -05:00
|
|
|
for (int phase = 0; phase < number_of_phases_; ++phase) {
|
|
|
|
if (distr[phase] > 0.) {
|
2018-05-18 03:57:08 -05:00
|
|
|
const EvalWell fraction_scaled = wellVolumeFractionScaled(flowPhaseToEbosCompIdx(phase));
|
|
|
|
rate_for_control += g_total * fraction_scaled;
|
|
|
|
sum_fraction += fraction_scaled.value();
|
2018-05-16 08:35:58 -05:00
|
|
|
}
|
2018-05-18 03:57:08 -05:00
|
|
|
}
|
|
|
|
if (sum_fraction > 0.) {
|
|
|
|
control_eq = rate_for_control - target_rate;
|
|
|
|
} else {
|
|
|
|
// we are not producing any fluids that specfied for a non-zero target
|
|
|
|
// which makes it a mission impossible, we will set all the rates to be zero for this case
|
|
|
|
const std::string msg = " Setting all rates to be zero for well " + name()
|
|
|
|
+ " due to un-solvable situation. There is non-zero target for the phase "
|
|
|
|
+ " that does not exist in the wellbore for the situation";
|
|
|
|
OpmLog::warning("NON_SOLVABLE_WELL_SOLUTION", msg);
|
|
|
|
|
2018-05-30 08:44:05 -05:00
|
|
|
control_eq = getWQTotal() - target_rate;
|
2018-05-18 03:57:08 -05:00
|
|
|
}
|
2018-05-16 08:35:58 -05:00
|
|
|
} else {
|
|
|
|
// there is some special treatment for the zero rate control well
|
2018-05-18 03:57:08 -05:00
|
|
|
// 1. if the well can produce the specified phase, it means the well should not produce any fluid, this
|
|
|
|
// is a fine situation.
|
2018-05-16 08:35:58 -05:00
|
|
|
// 2. if the well can not produce the specified phase, it cause a under-determined problem, we
|
|
|
|
// basically assume the well not producing any fluid as a solution
|
2018-05-18 03:57:08 -05:00
|
|
|
// With both the situation, we can use the following well equation
|
2018-05-30 08:44:05 -05:00
|
|
|
control_eq = getWQTotal() - target_rate;
|
2018-05-09 05:16:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RESERVOIR_RATE:
|
|
|
|
{
|
|
|
|
const double target_rate = well_controls_get_current_target(well_controls_); // reservoir rate target
|
|
|
|
if (well_type_ == INJECTOR) {
|
2018-05-18 03:57:08 -05:00
|
|
|
// only handles single phase injection now
|
2018-06-06 03:59:41 -05:00
|
|
|
assert(well_ecl_->getInjectionProperties(current_step_).injectorType != WellInjector::MULTI);
|
2018-05-18 03:57:08 -05:00
|
|
|
const double* distr = well_controls_get_current_distr(well_controls_);
|
2018-05-09 05:16:33 -05:00
|
|
|
for (int phase = 0; phase < number_of_phases_; ++phase) {
|
|
|
|
if (distr[phase] > 0.0) {
|
2018-05-30 08:44:05 -05:00
|
|
|
control_eq = getWQTotal() * scalingFactor(phase) - target_rate;
|
2018-05-09 05:16:33 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2018-05-30 08:44:05 -05:00
|
|
|
const EvalWell& g_total = getWQTotal();
|
2018-05-09 05:16:33 -05:00
|
|
|
EvalWell rate_for_control(0.0); // reservoir rate
|
|
|
|
for (int phase = 0; phase < number_of_phases_; ++phase) {
|
|
|
|
rate_for_control += g_total * wellVolumeFraction( flowPhaseToEbosCompIdx(phase) );
|
|
|
|
}
|
|
|
|
control_eq = rate_for_control - target_rate;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
OPM_THROW(std::runtime_error, "Unknown well control control types for well " << name());
|
|
|
|
}
|
|
|
|
|
|
|
|
// using control_eq to update the matrix and residuals
|
|
|
|
// TODO: we should use a different index system for the well equations
|
|
|
|
resWell_[0][Bhp] = control_eq.value();
|
|
|
|
for (int pv_idx = 0; pv_idx < numWellEq; ++pv_idx) {
|
|
|
|
invDuneD_[0][0][Bhp][pv_idx] = control_eq.derivative(pv_idx + numEq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-21 07:07:11 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
bool
|
|
|
|
StandardWell<TypeTag>::
|
2017-06-27 09:59:52 -05:00
|
|
|
crossFlowAllowed(const Simulator& ebosSimulator) const
|
2017-06-21 07:07:11 -05:00
|
|
|
{
|
2017-08-21 04:26:21 -05:00
|
|
|
if (getAllowCrossFlow()) {
|
2017-06-21 07:07:11 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: investigate the justification of the following situation
|
|
|
|
|
|
|
|
// check for special case where all perforations have cross flow
|
|
|
|
// then the wells must allow for cross flow
|
2017-08-04 06:07:16 -05:00
|
|
|
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-06-21 07:07:11 -05:00
|
|
|
const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/0));
|
|
|
|
const auto& fs = intQuants.fluidState();
|
2017-11-30 10:14:29 -06:00
|
|
|
const EvalWell pressure = extendEval(fs.pressure(FluidSystem::oilPhaseIdx));
|
2018-05-09 08:07:43 -05:00
|
|
|
const EvalWell& bhp = getBhp();
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
// Pressure drawdown (also used to determine direction of flow)
|
2017-11-30 10:14:29 -06:00
|
|
|
const EvalWell well_pressure = bhp + perf_pressure_diffs_[perf];
|
|
|
|
const EvalWell drawdown = pressure - well_pressure;
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
if (drawdown.value() < 0 && well_type_ == INJECTOR) {
|
2017-06-21 07:07:11 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
if (drawdown.value() > 0 && well_type_ == PRODUCER) {
|
2017-06-21 07:07:11 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
getMobility(const Simulator& ebosSimulator,
|
|
|
|
const int perf,
|
|
|
|
std::vector<EvalWell>& mob) const
|
|
|
|
{
|
2017-08-04 06:07:16 -05:00
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-11-30 09:31:48 -06:00
|
|
|
assert (int(mob.size()) == num_components_);
|
2017-06-21 07:07:11 -05:00
|
|
|
const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/0));
|
|
|
|
const auto& materialLawManager = ebosSimulator.problem().materialLawManager();
|
|
|
|
|
|
|
|
// either use mobility of the perforation cell or calcualte its own
|
|
|
|
// based on passing the saturation table index
|
2017-08-04 06:07:16 -05:00
|
|
|
const int satid = saturation_table_number_[perf] - 1;
|
2017-06-21 07:07:11 -05:00
|
|
|
const int satid_elem = materialLawManager->satnumRegionIdx(cell_idx);
|
|
|
|
if( satid == satid_elem ) { // the same saturation number is used. i.e. just use the mobilty from the cell
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
mob[activeCompIdx] = extendEval(intQuants.mobility(phaseIdx));
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2017-06-27 08:16:22 -05:00
|
|
|
mob[contiSolventEqIdx] = extendEval(intQuants.solventMobility());
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const auto& paramsCell = materialLawManager->connectionMaterialLawParams(satid, cell_idx);
|
|
|
|
Eval relativePerms[3] = { 0.0, 0.0, 0.0 };
|
|
|
|
MaterialLaw::relativePermeabilities(relativePerms, paramsCell, intQuants.fluidState());
|
|
|
|
|
|
|
|
// reset the satnumvalue back to original
|
|
|
|
materialLawManager->connectionMaterialLawParams(satid_elem, cell_idx);
|
|
|
|
|
|
|
|
// compute the mobility
|
2017-12-04 02:14:08 -06:00
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned activeCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
mob[activeCompIdx] = extendEval(relativePerms[phaseIdx] / intQuants.fluidState().viscosity(phaseIdx));
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// this may not work if viscosity and relperms has been modified?
|
|
|
|
if (has_solvent) {
|
|
|
|
OPM_THROW(std::runtime_error, "individual mobility for wells does not work in combination with solvent");
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 08:04:25 -05:00
|
|
|
|
|
|
|
// modify the water mobility if polymer is present
|
|
|
|
if (has_polymer) {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (!FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-11-23 09:10:37 -06:00
|
|
|
OPM_THROW(std::runtime_error, "Water is required when polymer is active");
|
2017-07-31 10:11:44 -05:00
|
|
|
}
|
2017-11-23 09:10:37 -06:00
|
|
|
|
|
|
|
updateWaterMobilityWithPolymer(ebosSimulator, perf, mob);
|
2017-07-31 08:04:25 -05:00
|
|
|
}
|
2017-06-21 07:07:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-22 08:37:54 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-08-03 08:14:36 -05:00
|
|
|
updateWellState(const BVectorWell& dwells,
|
2017-06-22 08:37:54 -05:00
|
|
|
WellState& well_state) const
|
|
|
|
{
|
2018-05-04 09:25:33 -05:00
|
|
|
updatePrimaryVariablesNewton(dwells, well_state);
|
|
|
|
|
|
|
|
updateWellStateFromPrimaryVariables(well_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
updatePrimaryVariablesNewton(const BVectorWell& dwells,
|
|
|
|
const WellState& well_state) const
|
|
|
|
{
|
2017-10-16 09:46:28 -05:00
|
|
|
const double dFLimit = param_.dwell_fraction_max_;
|
2017-06-22 08:37:54 -05:00
|
|
|
|
2018-05-08 05:17:18 -05:00
|
|
|
const std::vector<double> old_primary_variables = primary_variables_;
|
2017-06-22 08:37:54 -05:00
|
|
|
|
|
|
|
// update the second and third well variable (The flux fractions)
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-06-22 08:37:54 -05:00
|
|
|
const int sign2 = dwells[0][WFrac] > 0 ? 1: -1;
|
|
|
|
const double dx2_limited = sign2 * std::min(std::abs(dwells[0][WFrac]),dFLimit);
|
2018-05-08 05:17:18 -05:00
|
|
|
primary_variables_[WFrac] = old_primary_variables[WFrac] - dx2_limited;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-06-22 08:37:54 -05:00
|
|
|
const int sign3 = dwells[0][GFrac] > 0 ? 1: -1;
|
|
|
|
const double dx3_limited = sign3 * std::min(std::abs(dwells[0][GFrac]),dFLimit);
|
2018-05-08 05:17:18 -05:00
|
|
|
primary_variables_[GFrac] = old_primary_variables[GFrac] - dx3_limited;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (has_solvent) {
|
|
|
|
const int sign4 = dwells[0][SFrac] > 0 ? 1: -1;
|
|
|
|
const double dx4_limited = sign4 * std::min(std::abs(dwells[0][SFrac]),dFLimit);
|
2018-05-08 05:17:18 -05:00
|
|
|
primary_variables_[SFrac] = old_primary_variables[SFrac] - dx4_limited;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2018-05-11 07:58:44 -05:00
|
|
|
processFractions();
|
|
|
|
|
|
|
|
// updating the total rates G_t
|
2018-05-30 08:44:05 -05:00
|
|
|
primary_variables_[WQTotal] = old_primary_variables[WQTotal] - dwells[0][WQTotal];
|
2018-05-11 07:58:44 -05:00
|
|
|
|
|
|
|
// updating the bottom hole pressure
|
|
|
|
{
|
|
|
|
const double dBHPLimit = param_.dbhp_max_rel_;
|
|
|
|
const int sign1 = dwells[0][Bhp] > 0 ? 1: -1;
|
|
|
|
const double dx1_limited = sign1 * std::min(std::abs(dwells[0][Bhp]), std::abs(old_primary_variables[Bhp]) * dBHPLimit);
|
|
|
|
// 1e5 to make sure bhp will not be below 1bar
|
|
|
|
primary_variables_[Bhp] = std::max(old_primary_variables[Bhp] - dx1_limited, 1e5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-04 09:25:33 -05:00
|
|
|
|
2018-05-11 07:58:44 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
processFractions() const
|
|
|
|
{
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx));
|
2018-05-08 05:17:18 -05:00
|
|
|
const auto pu = phaseUsage();
|
2018-05-04 09:25:33 -05:00
|
|
|
std::vector<double> F(number_of_phases_, 0.0);
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Oil]] = 1.0;
|
2017-06-22 08:37:54 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Water]] = primary_variables_[WFrac];
|
|
|
|
F[pu.phase_pos[Oil]] -= F[pu.phase_pos[Water]];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Gas]] = primary_variables_[GFrac];
|
|
|
|
F[pu.phase_pos[Oil]] -= F[pu.phase_pos[Gas]];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double F_solvent = 0.0;
|
|
|
|
if (has_solvent) {
|
2017-08-21 08:41:25 -05:00
|
|
|
F_solvent = primary_variables_[SFrac];
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Oil]] -= F_solvent;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-06-22 08:37:54 -05:00
|
|
|
if (F[Water] < 0.0) {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Gas]] /= (1.0 - F[pu.phase_pos[Water]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F_solvent /= (1.0 - F[pu.phase_pos[Water]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Oil]] /= (1.0 - F[pu.phase_pos[Water]]);
|
|
|
|
F[pu.phase_pos[Water]] = 0.0;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
if (F[pu.phase_pos[Gas]] < 0.0) {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Water]] /= (1.0 - F[pu.phase_pos[Gas]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F_solvent /= (1.0 - F[pu.phase_pos[Gas]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Oil]] /= (1.0 - F[pu.phase_pos[Gas]]);
|
|
|
|
F[pu.phase_pos[Gas]] = 0.0;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-31 00:50:28 -05:00
|
|
|
if (F[pu.phase_pos[Oil]] < 0.0) {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Water]] /= (1.0 - F[pu.phase_pos[Oil]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Gas]] /= (1.0 - F[pu.phase_pos[Oil]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2017-08-31 00:50:28 -05:00
|
|
|
F_solvent /= (1.0 - F[pu.phase_pos[Oil]]);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-08-31 00:50:28 -05:00
|
|
|
F[pu.phase_pos[Oil]] = 0.0;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
primary_variables_[WFrac] = F[pu.phase_pos[Water]];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
primary_variables_[GFrac] = F[pu.phase_pos[Gas]];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
if(has_solvent) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[SFrac] = F_solvent;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2018-05-04 09:25:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
updateWellStateFromPrimaryVariables(WellState& well_state) const
|
|
|
|
{
|
|
|
|
const PhaseUsage& pu = phaseUsage();
|
|
|
|
assert( FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) );
|
|
|
|
const int oil_pos = pu.phase_pos[Oil];
|
|
|
|
|
|
|
|
std::vector<double> F(number_of_phases_, 0.0);
|
|
|
|
F[oil_pos] = 1.0;
|
|
|
|
|
|
|
|
if ( FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) ) {
|
|
|
|
const int water_pos = pu.phase_pos[Water];
|
|
|
|
F[water_pos] = primary_variables_[WFrac];
|
|
|
|
F[oil_pos] -= F[water_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) ) {
|
|
|
|
const int gas_pos = pu.phase_pos[Gas];
|
|
|
|
F[gas_pos] = primary_variables_[GFrac];
|
|
|
|
F[oil_pos] -= F[gas_pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
double F_solvent = 0.0;
|
|
|
|
if (has_solvent) {
|
|
|
|
F_solvent = primary_variables_[SFrac];
|
|
|
|
F[oil_pos] -= F_solvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert the fractions to be Q_p / G_total to calculate the phase rates
|
|
|
|
for (int p = 0; p < number_of_phases_; ++p) {
|
2017-09-05 02:25:34 -05:00
|
|
|
const double scal = scalingFactor(p);
|
2018-05-04 09:25:33 -05:00
|
|
|
// for injection wells, there should only one non-zero scaling factor
|
2017-09-05 02:25:34 -05:00
|
|
|
if (scal > 0) {
|
|
|
|
F[p] /= scal ;
|
|
|
|
} else {
|
2018-05-04 09:25:33 -05:00
|
|
|
// this should only happens to injection wells
|
2017-09-05 02:25:34 -05:00
|
|
|
F[p] = 0.;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 07:39:42 -06:00
|
|
|
// F_solvent is added to F_gas. This means that well_rate[Gas] also contains solvent.
|
|
|
|
// More testing is needed to make sure this is correct for well groups and THP.
|
|
|
|
if (has_solvent){
|
2017-11-23 04:15:50 -06:00
|
|
|
F_solvent /= scalingFactor(contiSolventEqIdx);
|
2017-11-22 07:39:42 -06:00
|
|
|
F[pu.phase_pos[Gas]] += F_solvent;
|
|
|
|
}
|
|
|
|
|
2018-05-08 05:17:18 -05:00
|
|
|
well_state.bhp()[index_of_well_] = primary_variables_[Bhp];
|
2018-05-04 09:25:33 -05:00
|
|
|
|
2018-05-08 05:17:18 -05:00
|
|
|
// calculate the phase rates based on the primary variables
|
|
|
|
// for producers, this is not a problem, while not sure for injectors here
|
|
|
|
if (well_type_ == PRODUCER) {
|
2018-05-30 08:44:05 -05:00
|
|
|
const double g_total = primary_variables_[WQTotal];
|
2018-05-08 05:17:18 -05:00
|
|
|
for (int p = 0; p < number_of_phases_; ++p) {
|
|
|
|
well_state.wellRates()[index_of_well_ * number_of_phases_ + p] = g_total * F[p];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2018-05-11 07:21:53 -05:00
|
|
|
} else { // injectors
|
2018-05-08 05:17:18 -05:00
|
|
|
// TODO: using comp_frac_ here is very dangerous, since we do not update it based on the injection phase
|
|
|
|
// Either we use distr (might conflict with RESV related) or we update comp_frac_ based on the injection phase
|
|
|
|
for (int p = 0; p < number_of_phases_; ++p) {
|
|
|
|
const double comp_frac = comp_frac_[p];
|
2018-05-30 08:44:05 -05:00
|
|
|
well_state.wellRates()[index_of_well_ * number_of_phases_ + p] = comp_frac * primary_variables_[WQTotal];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2018-05-08 05:17:18 -05:00
|
|
|
}
|
2017-06-22 08:37:54 -05:00
|
|
|
|
2018-05-16 05:44:38 -05:00
|
|
|
updateThp(well_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
updateThp(WellState& well_state) const
|
|
|
|
{
|
2017-06-22 08:37:54 -05:00
|
|
|
// for the wells having a THP constaint, we should update their thp value
|
2018-05-08 05:17:18 -05:00
|
|
|
// If it is under THP control, it will be set to be the target value.
|
|
|
|
// TODO: a better standard is probably whether we have the table to calculate the THP value
|
|
|
|
// TODO: it is something we need to check the output to decide.
|
|
|
|
const WellControls* wc = well_controls_;
|
|
|
|
// TODO: we should only maintain one current control either from the well_state or from well_controls struct.
|
|
|
|
// Either one can be more favored depending on the final strategy for the initilzation of the well control
|
2017-06-22 08:37:54 -05:00
|
|
|
const int nwc = well_controls_get_num(wc);
|
|
|
|
// Looping over all controls until we find a THP constraint
|
2018-05-08 05:17:18 -05:00
|
|
|
for (int ctrl_index = 0; ctrl_index < nwc; ++ctrl_index) {
|
2017-06-22 08:37:54 -05:00
|
|
|
if (well_controls_iget_type(wc, ctrl_index) == THP) {
|
|
|
|
// the current control
|
2017-08-04 06:07:16 -05:00
|
|
|
const int current = well_state.currentControls()[index_of_well_];
|
2018-05-15 09:17:01 -05:00
|
|
|
// if well under THP control at the moment
|
2017-06-22 08:37:54 -05:00
|
|
|
if (current == ctrl_index) {
|
|
|
|
const double thp_target = well_controls_iget_target(wc, current);
|
2017-08-04 06:07:16 -05:00
|
|
|
well_state.thp()[index_of_well_] = thp_target;
|
2017-06-22 08:37:54 -05:00
|
|
|
} else { // otherwise we calculate the thp from the bhp value
|
|
|
|
const Opm::PhaseUsage& pu = phaseUsage();
|
2017-08-11 04:10:59 -05:00
|
|
|
std::vector<double> rates(3, 0.0);
|
2017-06-22 08:37:54 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2018-05-04 09:25:33 -05:00
|
|
|
rates[ Water ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Water ] ];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
2018-05-04 09:25:33 -05:00
|
|
|
rates[ Oil ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Oil ] ];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2018-05-04 09:25:33 -05:00
|
|
|
rates[ Gas ] = well_state.wellRates()[index_of_well_ * number_of_phases_ + pu.phase_pos[ Gas ] ];
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
const double bhp = well_state.bhp()[index_of_well_];
|
2017-06-22 08:37:54 -05:00
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
well_state.thp()[index_of_well_] = calculateThpFromBhp(rates, ctrl_index, bhp);
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
2018-05-15 09:17:01 -05:00
|
|
|
break;
|
2017-06-22 08:37:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-23 03:58:46 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-11-30 10:14:29 -06:00
|
|
|
updateWellStateWithTarget(WellState& well_state) const
|
2017-06-23 03:58:46 -05:00
|
|
|
{
|
|
|
|
// number of phases
|
2017-08-04 06:07:16 -05:00
|
|
|
const int np = number_of_phases_;
|
|
|
|
const int well_index = index_of_well_;
|
|
|
|
const WellControls* wc = well_controls_;
|
2017-11-30 10:14:29 -06:00
|
|
|
const int current = well_state.currentControls()[well_index];
|
2017-06-23 03:58:46 -05:00
|
|
|
// Updating well state and primary variables.
|
|
|
|
// Target values are used as initial conditions for BHP, THP, and SURFACE_RATE
|
|
|
|
const double target = well_controls_iget_target(wc, current);
|
|
|
|
const double* distr = well_controls_iget_distr(wc, current);
|
|
|
|
switch (well_controls_iget_type(wc, current)) {
|
|
|
|
case BHP:
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.bhp()[well_index] = target;
|
2017-06-23 03:58:46 -05:00
|
|
|
// TODO: similar to the way below to handle THP
|
|
|
|
// we should not something related to thp here when there is thp constraint
|
2018-05-09 05:16:33 -05:00
|
|
|
// or when can calculate the THP (table avaiable or requested for output?)
|
2017-06-23 03:58:46 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case THP: {
|
2018-05-09 05:16:33 -05:00
|
|
|
// TODO: this will be the big task here.
|
|
|
|
// p_bhp = BHP(THP, rates(p_bhp))
|
|
|
|
// more sophiscated techniques is required to obtain the bhp and rates here
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.thp()[well_index] = target;
|
2017-06-23 03:58:46 -05:00
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
const Opm::PhaseUsage& pu = phaseUsage();
|
|
|
|
std::vector<double> rates(3, 0.0);
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-11-30 10:14:29 -06:00
|
|
|
rates[ Water ] = well_state.wellRates()[well_index*np + pu.phase_pos[ Water ] ];
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
2017-11-30 10:14:29 -06:00
|
|
|
rates[ Oil ] = well_state.wellRates()[well_index*np + pu.phase_pos[ Oil ] ];
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-11-30 10:14:29 -06:00
|
|
|
rates[ Gas ] = well_state.wellRates()[well_index*np + pu.phase_pos[ Gas ] ];
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
|
|
|
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.bhp()[well_index] = calculateBhpFromThp(rates, current);
|
2017-06-23 03:58:46 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case RESERVOIR_RATE: // intentional fall-through
|
|
|
|
case SURFACE_RATE:
|
|
|
|
// checking the number of the phases under control
|
|
|
|
int numPhasesWithTargetsUnderThisControl = 0;
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
if (distr[phase] > 0.0) {
|
|
|
|
numPhasesWithTargetsUnderThisControl += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(numPhasesWithTargetsUnderThisControl > 0);
|
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
if (well_type_ == INJECTOR) {
|
2017-06-23 03:58:46 -05:00
|
|
|
// assign target value as initial guess for injectors
|
|
|
|
// only handles single phase control at the moment
|
|
|
|
assert(numPhasesWithTargetsUnderThisControl == 1);
|
|
|
|
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
if (distr[phase] > 0.) {
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.wellRates()[np*well_index + phase] = target / distr[phase];
|
2017-06-23 03:58:46 -05:00
|
|
|
} else {
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.wellRates()[np * well_index + phase] = 0.;
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 06:07:16 -05:00
|
|
|
} else if (well_type_ == PRODUCER) {
|
2017-06-23 03:58:46 -05:00
|
|
|
// update the rates of phases under control based on the target,
|
|
|
|
// and also update rates of phases not under control to keep the rate ratio,
|
|
|
|
// assuming the mobility ratio does not change for the production wells
|
|
|
|
double original_rates_under_phase_control = 0.0;
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
if (distr[phase] > 0.0) {
|
2017-11-30 10:14:29 -06:00
|
|
|
original_rates_under_phase_control += well_state.wellRates()[np * well_index + phase] * distr[phase];
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (original_rates_under_phase_control != 0.0 ) {
|
2018-05-11 07:21:53 -05:00
|
|
|
const double scaling_factor = target / original_rates_under_phase_control;
|
2017-06-23 03:58:46 -05:00
|
|
|
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.wellRates()[np * well_index + phase] *= scaling_factor;
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
2018-05-11 07:21:53 -05:00
|
|
|
} else { // scaling factor is not well defined when original_rates_under_phase_control is zero
|
2017-06-23 03:58:46 -05:00
|
|
|
// separating targets equally between phases under control
|
|
|
|
const double target_rate_divided = target / numPhasesWithTargetsUnderThisControl;
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
if (distr[phase] > 0.0) {
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.wellRates()[np * well_index + phase] = target_rate_divided / distr[phase];
|
2017-06-23 03:58:46 -05:00
|
|
|
} else {
|
|
|
|
// this only happens for SURFACE_RATE control
|
2017-11-30 10:14:29 -06:00
|
|
|
well_state.wellRates()[np * well_index + phase] = target_rate_divided;
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OPM_THROW(std::logic_error, "Expected PRODUCER or INJECTOR type of well");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
} // end of switch
|
|
|
|
|
2017-11-30 10:14:29 -06:00
|
|
|
updatePrimaryVariables(well_state);
|
2017-06-23 03:58:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-23 04:42:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-23 07:55:56 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computePropertiesForWellConnectionPressures(const Simulator& ebosSimulator,
|
2017-11-30 10:14:29 -06:00
|
|
|
const WellState& well_state,
|
2017-06-23 07:55:56 -05:00
|
|
|
std::vector<double>& b_perf,
|
|
|
|
std::vector<double>& rsmax_perf,
|
|
|
|
std::vector<double>& rvmax_perf,
|
|
|
|
std::vector<double>& surf_dens_perf) const
|
|
|
|
{
|
2017-08-04 06:07:16 -05:00
|
|
|
const int nperf = number_of_perforations_;
|
2017-09-08 04:06:34 -05:00
|
|
|
const PhaseUsage& pu = phaseUsage();
|
2017-11-30 09:31:48 -06:00
|
|
|
b_perf.resize(nperf * num_components_);
|
|
|
|
surf_dens_perf.resize(nperf * num_components_);
|
2017-08-04 06:07:16 -05:00
|
|
|
const int w = index_of_well_;
|
2017-06-23 07:55:56 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
const bool waterPresent = FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
|
|
|
|
const bool oilPresent = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
|
|
|
|
const bool gasPresent = FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
|
|
|
|
|
2017-06-23 07:55:56 -05:00
|
|
|
//rs and rv are only used if both oil and gas is present
|
2017-12-04 02:14:08 -06:00
|
|
|
if (oilPresent && gasPresent) {
|
2017-06-23 07:55:56 -05:00
|
|
|
rsmax_perf.resize(nperf);
|
|
|
|
rvmax_perf.resize(nperf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the average pressure in each well block
|
|
|
|
for (int perf = 0; perf < nperf; ++perf) {
|
2017-08-04 06:07:16 -05:00
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-06-23 07:55:56 -05:00
|
|
|
const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/0));
|
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
|
|
|
|
// TODO: this is another place to show why WellState need to be a vector of WellState.
|
|
|
|
// TODO: to check why should be perf - 1
|
2017-11-30 10:14:29 -06:00
|
|
|
const double p_above = perf == 0 ? well_state.bhp()[w] : well_state.perfPress()[first_perf_ + perf - 1];
|
|
|
|
const double p_avg = (well_state.perfPress()[first_perf_ + perf] + p_above)/2;
|
2017-06-23 07:55:56 -05:00
|
|
|
const double temperature = fs.temperature(FluidSystem::oilPhaseIdx).value();
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (waterPresent) {
|
|
|
|
const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
|
|
|
b_perf[ waterCompIdx + perf * num_components_] =
|
2017-06-23 07:55:56 -05:00
|
|
|
FluidSystem::waterPvt().inverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (gasPresent) {
|
|
|
|
const unsigned gasCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
|
|
|
const int gaspos = gasCompIdx + perf * num_components_;
|
2017-11-16 04:42:34 -06:00
|
|
|
const int gaspos_well = pu.phase_pos[Gas] + w * pu.num_phases;
|
2017-06-23 07:55:56 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (oilPresent) {
|
2017-11-16 04:42:34 -06:00
|
|
|
const int oilpos_well = pu.phase_pos[Oil] + w * pu.num_phases;
|
2017-11-30 10:14:29 -06:00
|
|
|
const double oilrate = std::abs(well_state.wellRates()[oilpos_well]); //in order to handle negative rates in producers
|
2017-06-23 07:55:56 -05:00
|
|
|
rvmax_perf[perf] = FluidSystem::gasPvt().saturatedOilVaporizationFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
if (oilrate > 0) {
|
2017-11-30 10:14:29 -06:00
|
|
|
const double gasrate = std::abs(well_state.wellRates()[gaspos_well]) - well_state.solventWellRate(w);
|
2017-06-23 07:55:56 -05:00
|
|
|
double rv = 0.0;
|
|
|
|
if (gasrate > 0) {
|
|
|
|
rv = oilrate / gasrate;
|
|
|
|
}
|
|
|
|
rv = std::min(rv, rvmax_perf[perf]);
|
|
|
|
|
|
|
|
b_perf[gaspos] = FluidSystem::gasPvt().inverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b_perf[gaspos] = FluidSystem::gasPvt().saturatedInverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
b_perf[gaspos] = FluidSystem::gasPvt().saturatedInverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (oilPresent) {
|
|
|
|
const unsigned oilCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
const int oilpos = oilCompIdx + perf * num_components_;
|
2017-11-16 04:42:34 -06:00
|
|
|
const int oilpos_well = pu.phase_pos[Oil] + w * pu.num_phases;
|
2017-12-04 02:14:08 -06:00
|
|
|
if (gasPresent) {
|
2017-06-23 07:55:56 -05:00
|
|
|
rsmax_perf[perf] = FluidSystem::oilPvt().saturatedGasDissolutionFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
2017-11-16 04:42:34 -06:00
|
|
|
const int gaspos_well = pu.phase_pos[Gas] + w * pu.num_phases;
|
2017-11-30 10:14:29 -06:00
|
|
|
const double gasrate = std::abs(well_state.wellRates()[gaspos_well]) - well_state.solventWellRate(w);
|
2017-06-23 07:55:56 -05:00
|
|
|
if (gasrate > 0) {
|
2017-11-30 10:14:29 -06:00
|
|
|
const double oilrate = std::abs(well_state.wellRates()[oilpos_well]);
|
2017-06-23 07:55:56 -05:00
|
|
|
double rs = 0.0;
|
|
|
|
if (oilrate > 0) {
|
|
|
|
rs = gasrate / oilrate;
|
|
|
|
}
|
|
|
|
rs = std::min(rs, rsmax_perf[perf]);
|
|
|
|
b_perf[oilpos] = FluidSystem::oilPvt().inverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg, rs);
|
|
|
|
} else {
|
|
|
|
b_perf[oilpos] = FluidSystem::oilPvt().saturatedInverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
b_perf[oilpos] = FluidSystem::oilPvt().saturatedInverseFormationVolumeFactor(fs.pvtRegionIndex(), temperature, p_avg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Surface density.
|
2017-12-04 02:14:08 -06:00
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
|
|
|
|
surf_dens_perf[num_components_ * perf + compIdx] = FluidSystem::referenceDensity( phaseIdx, fs.pvtRegionIndex() );
|
2017-06-23 07:55:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// We use cell values for solvent injector
|
|
|
|
if (has_solvent) {
|
2017-11-30 09:31:48 -06:00
|
|
|
b_perf[num_components_ * perf + contiSolventEqIdx] = intQuants.solventInverseFormationVolumeFactor().value();
|
|
|
|
surf_dens_perf[num_components_ * perf + contiSolventEqIdx] = intQuants.solventRefDensity();
|
2017-06-23 07:55:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 08:54:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeConnectionDensities(const std::vector<double>& perfComponentRates,
|
|
|
|
const std::vector<double>& b_perf,
|
|
|
|
const std::vector<double>& rsmax_perf,
|
|
|
|
const std::vector<double>& rvmax_perf,
|
|
|
|
const std::vector<double>& surf_dens_perf)
|
|
|
|
{
|
|
|
|
// Verify that we have consistent input.
|
2017-08-04 06:07:16 -05:00
|
|
|
const int np = number_of_phases_;
|
|
|
|
const int nperf = number_of_perforations_;
|
2017-11-30 09:31:48 -06:00
|
|
|
const int num_comp = num_components_;
|
2017-06-23 08:54:05 -05:00
|
|
|
|
|
|
|
// 1. Compute the flow (in surface volume units for each
|
|
|
|
// component) exiting up the wellbore from each perforation,
|
|
|
|
// taking into account flow from lower in the well, and
|
|
|
|
// in/out-flow at each perforation.
|
|
|
|
std::vector<double> q_out_perf(nperf*num_comp);
|
|
|
|
|
|
|
|
// TODO: investigate whether we should use the following techniques to calcuate the composition of flows in the wellbore
|
|
|
|
// Iterate over well perforations from bottom to top.
|
|
|
|
for (int perf = nperf - 1; perf >= 0; --perf) {
|
|
|
|
for (int component = 0; component < num_comp; ++component) {
|
|
|
|
if (perf == nperf - 1) {
|
|
|
|
// This is the bottom perforation. No flow from below.
|
|
|
|
q_out_perf[perf*num_comp+ component] = 0.0;
|
|
|
|
} else {
|
|
|
|
// Set equal to flow from below.
|
|
|
|
q_out_perf[perf*num_comp + component] = q_out_perf[(perf+1)*num_comp + component];
|
|
|
|
}
|
|
|
|
// Subtract outflow through perforation.
|
|
|
|
q_out_perf[perf*num_comp + component] -= perfComponentRates[perf*num_comp + component];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Compute the component mix at each perforation as the
|
|
|
|
// absolute values of the surface rates divided by their sum.
|
|
|
|
// Then compute volume ratios (formation factors) for each perforation.
|
|
|
|
// Finally compute densities for the segments associated with each perforation.
|
|
|
|
std::vector<double> mix(num_comp,0.0);
|
|
|
|
std::vector<double> x(num_comp);
|
|
|
|
std::vector<double> surf_dens(num_comp);
|
|
|
|
|
|
|
|
for (int perf = 0; perf < nperf; ++perf) {
|
|
|
|
// Find component mix.
|
|
|
|
const double tot_surf_rate = std::accumulate(q_out_perf.begin() + num_comp*perf,
|
|
|
|
q_out_perf.begin() + num_comp*(perf+1), 0.0);
|
|
|
|
if (tot_surf_rate != 0.0) {
|
|
|
|
for (int component = 0; component < num_comp; ++component) {
|
|
|
|
mix[component] = std::fabs(q_out_perf[perf*num_comp + component]/tot_surf_rate);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No flow => use well specified fractions for mix.
|
2017-12-04 02:14:08 -06:00
|
|
|
for (int component = 0; component < num_comp; ++component) {
|
|
|
|
if (component < np) {
|
|
|
|
mix[component] = comp_frac_[ ebosCompIdxToFlowCompIdx(component)];
|
|
|
|
}
|
2017-06-23 08:54:05 -05:00
|
|
|
}
|
|
|
|
// intialize 0.0 for comIdx >= np;
|
|
|
|
}
|
|
|
|
// Compute volume ratio.
|
|
|
|
x = mix;
|
2017-12-04 02:14:08 -06:00
|
|
|
|
|
|
|
// Subtract dissolved gas from oil phase and vapporized oil from gas phase
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasCompIdx) && FluidSystem::phaseIsActive(FluidSystem::oilCompIdx)) {
|
|
|
|
const unsigned gaspos = Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx);
|
|
|
|
const unsigned oilpos = Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx);
|
|
|
|
double rs = 0.0;
|
|
|
|
double rv = 0.0;
|
|
|
|
if (!rsmax_perf.empty() && mix[oilpos] > 0.0) {
|
|
|
|
rs = std::min(mix[gaspos]/mix[oilpos], rsmax_perf[perf]);
|
|
|
|
}
|
|
|
|
if (!rvmax_perf.empty() && mix[gaspos] > 0.0) {
|
|
|
|
rv = std::min(mix[oilpos]/mix[gaspos], rvmax_perf[perf]);
|
|
|
|
}
|
|
|
|
if (rs != 0.0) {
|
|
|
|
// Subtract gas in oil from gas mixture
|
|
|
|
x[gaspos] = (mix[gaspos] - mix[oilpos]*rs)/(1.0 - rs*rv);
|
|
|
|
}
|
|
|
|
if (rv != 0.0) {
|
|
|
|
// Subtract oil in gas from oil mixture
|
|
|
|
x[oilpos] = (mix[oilpos] - mix[gaspos]*rv)/(1.0 - rs*rv);;
|
|
|
|
}
|
2017-06-23 08:54:05 -05:00
|
|
|
}
|
|
|
|
double volrat = 0.0;
|
|
|
|
for (int component = 0; component < num_comp; ++component) {
|
|
|
|
volrat += x[component] / b_perf[perf*num_comp+ component];
|
|
|
|
}
|
|
|
|
for (int component = 0; component < num_comp; ++component) {
|
|
|
|
surf_dens[component] = surf_dens_perf[perf*num_comp+ component];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute segment density.
|
|
|
|
perf_densities_[perf] = std::inner_product(surf_dens.begin(), surf_dens.end(), mix.begin(), 0.0) / volrat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:32:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeConnectionPressureDelta()
|
|
|
|
{
|
|
|
|
// Algorithm:
|
|
|
|
|
|
|
|
// We'll assume the perforations are given in order from top to
|
|
|
|
// bottom for each well. By top and bottom we do not necessarily
|
|
|
|
// mean in a geometric sense (depth), but in a topological sense:
|
|
|
|
// the 'top' perforation is nearest to the surface topologically.
|
|
|
|
// Our goal is to compute a pressure delta for each perforation.
|
|
|
|
|
|
|
|
// 1. Compute pressure differences between perforations.
|
|
|
|
// dp_perf will contain the pressure difference between a
|
|
|
|
// perforation and the one above it, except for the first
|
|
|
|
// perforation for each well, for which it will be the
|
|
|
|
// difference to the reference (bhp) depth.
|
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
const int nperf = number_of_perforations_;
|
2017-06-23 09:32:43 -05:00
|
|
|
perf_pressure_diffs_.resize(nperf, 0.0);
|
|
|
|
|
|
|
|
for (int perf = 0; perf < nperf; ++perf) {
|
|
|
|
const double z_above = perf == 0 ? ref_depth_ : perf_depth_[perf - 1];
|
|
|
|
const double dz = perf_depth_[perf] - z_above;
|
|
|
|
perf_pressure_diffs_[perf] = dz * perf_densities_[perf] * gravity_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Compute pressure differences to the reference point (bhp) by
|
|
|
|
// accumulating the already computed adjacent pressure
|
|
|
|
// differences, storing the result in dp_perf.
|
|
|
|
// This accumulation must be done per well.
|
|
|
|
const auto beg = perf_pressure_diffs_.begin();
|
|
|
|
const auto end = perf_pressure_diffs_.end();
|
|
|
|
std::partial_sum(beg, end, beg);
|
|
|
|
}
|
|
|
|
|
2017-06-23 09:45:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-26 07:35:43 -05:00
|
|
|
template<typename TypeTag>
|
2018-10-25 04:57:47 -05:00
|
|
|
ConvergenceReport
|
2017-06-26 07:35:43 -05:00
|
|
|
StandardWell<TypeTag>::
|
2017-10-16 09:46:28 -05:00
|
|
|
getWellConvergence(const std::vector<double>& B_avg) const
|
2017-06-26 07:35:43 -05:00
|
|
|
{
|
2017-07-31 07:20:02 -05:00
|
|
|
// the following implementation assume that the polymer is always after the w-o-g phases
|
2018-05-02 02:15:52 -05:00
|
|
|
// For the polymer case and the energy case, there is one more mass balance equations of reservoir than wells
|
2018-05-08 02:56:15 -05:00
|
|
|
assert((int(B_avg.size()) == num_components_) || has_polymer || has_energy);
|
2017-06-26 07:35:43 -05:00
|
|
|
|
2017-10-16 09:46:28 -05:00
|
|
|
const double tol_wells = param_.tolerance_wells_;
|
|
|
|
const double maxResidualAllowed = param_.max_residual_allowed_;
|
2017-06-26 07:35:43 -05:00
|
|
|
|
2018-05-11 07:46:19 -05:00
|
|
|
std::vector<double> res(numWellEq);
|
2018-05-15 09:17:01 -05:00
|
|
|
for (int eq_idx = 0; eq_idx < numWellEq; ++eq_idx) {
|
2017-07-19 09:10:50 -05:00
|
|
|
// magnitude of the residual matters
|
2018-05-15 09:17:01 -05:00
|
|
|
res[eq_idx] = std::abs(resWell_[0][eq_idx]);
|
2017-06-26 07:35:43 -05:00
|
|
|
}
|
|
|
|
|
2017-11-30 10:14:29 -06:00
|
|
|
std::vector<double> well_flux_residual(num_components_);
|
2017-06-26 07:35:43 -05:00
|
|
|
|
|
|
|
// Finish computation
|
2017-11-30 09:31:48 -06:00
|
|
|
for ( int compIdx = 0; compIdx < num_components_; ++compIdx )
|
2017-06-26 07:35:43 -05:00
|
|
|
{
|
|
|
|
well_flux_residual[compIdx] = B_avg[compIdx] * res[compIdx];
|
|
|
|
}
|
|
|
|
|
2018-10-25 04:57:47 -05:00
|
|
|
ConvergenceReport report;
|
|
|
|
using CR = ConvergenceReport;
|
|
|
|
CR::WellFailure::Type type = CR::WellFailure::Type::Mb;
|
2017-08-22 07:49:30 -05:00
|
|
|
// checking if any NaN or too large residuals found
|
2017-12-04 02:14:08 -06:00
|
|
|
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
|
|
|
|
if (!FluidSystem::phaseIsActive(phaseIdx)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const unsigned canonicalCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
|
|
|
|
const std::string& compName = FluidSystem::componentName(canonicalCompIdx);
|
2018-10-23 07:05:19 -05:00
|
|
|
const int compIdx = Indices::canonicalToActiveComponentIndex(canonicalCompIdx);
|
2017-06-26 07:35:43 -05:00
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (std::isnan(well_flux_residual[compIdx])) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::NotANumber, compIdx, name()});
|
2018-10-23 07:05:19 -05:00
|
|
|
} else if (well_flux_residual[compIdx] > maxResidualAllowed) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::TooLarge, compIdx, name()});
|
2018-10-23 07:05:19 -05:00
|
|
|
} else if (well_flux_residual[compIdx] > tol_wells) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::Normal, compIdx, name()});
|
2017-06-26 07:35:43 -05:00
|
|
|
}
|
2017-08-22 07:49:30 -05:00
|
|
|
}
|
2017-06-26 07:35:43 -05:00
|
|
|
|
2018-05-11 07:46:19 -05:00
|
|
|
// processing the residual of the well control equation
|
|
|
|
const double well_control_residual = res[numWellEq - 1];
|
|
|
|
// TODO: we should have better way to specify the control equation tolerance
|
|
|
|
double control_tolerance = 0.;
|
|
|
|
switch(well_controls_get_current_type(well_controls_)) {
|
|
|
|
case THP:
|
2018-10-25 04:57:47 -05:00
|
|
|
type = CR::WellFailure::Type::CtrlTHP;
|
2018-10-23 07:05:19 -05:00
|
|
|
control_tolerance = 1.e3; // 0.01 bar
|
|
|
|
break;
|
2018-05-11 07:46:19 -05:00
|
|
|
case BHP: // pressure type of control
|
2018-10-25 04:57:47 -05:00
|
|
|
type = CR::WellFailure::Type::CtrlBHP;
|
2018-05-15 09:17:01 -05:00
|
|
|
control_tolerance = 1.e3; // 0.01 bar
|
2018-05-11 07:46:19 -05:00
|
|
|
break;
|
|
|
|
case RESERVOIR_RATE:
|
|
|
|
case SURFACE_RATE:
|
2018-10-25 04:57:47 -05:00
|
|
|
type = CR::WellFailure::Type::CtrlRate;
|
2018-05-11 07:46:19 -05:00
|
|
|
control_tolerance = 1.e-4; // smaller tolerance for rate control
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OPM_THROW(std::runtime_error, "Unknown well control control types for well " << name());
|
|
|
|
}
|
|
|
|
|
2018-10-23 07:05:19 -05:00
|
|
|
const int dummy_component = -1;
|
2018-05-11 07:46:19 -05:00
|
|
|
if (std::isnan(well_control_residual)) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::NotANumber, dummy_component, name()});
|
2018-10-23 07:05:19 -05:00
|
|
|
} else if (well_control_residual > maxResidualAllowed * 10.) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::TooLarge, dummy_component, name()});
|
2018-10-23 07:05:19 -05:00
|
|
|
} else if ( well_control_residual > control_tolerance) {
|
2018-10-25 04:57:47 -05:00
|
|
|
report.setWellFailed({type, CR::Severity::Normal, dummy_component, name()});
|
2017-06-26 07:35:43 -05:00
|
|
|
}
|
|
|
|
|
2017-08-22 07:49:30 -05:00
|
|
|
return report;
|
2017-06-26 07:35:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-23 09:45:14 -05:00
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-11-30 10:14:29 -06:00
|
|
|
computeWellConnectionDensitesPressures(const WellState& well_state,
|
2017-06-23 09:45:14 -05:00
|
|
|
const std::vector<double>& b_perf,
|
|
|
|
const std::vector<double>& rsmax_perf,
|
|
|
|
const std::vector<double>& rvmax_perf,
|
|
|
|
const std::vector<double>& surf_dens_perf)
|
|
|
|
{
|
|
|
|
// Compute densities
|
2017-08-04 06:07:16 -05:00
|
|
|
const int nperf = number_of_perforations_;
|
|
|
|
const int np = number_of_phases_;
|
2017-06-23 09:45:14 -05:00
|
|
|
std::vector<double> perfRates(b_perf.size(),0.0);
|
|
|
|
|
|
|
|
for (int perf = 0; perf < nperf; ++perf) {
|
2017-12-04 02:14:08 -06:00
|
|
|
for (int comp = 0; comp < np; ++comp) {
|
|
|
|
perfRates[perf * num_components_ + comp] = well_state.perfPhaseRates()[(first_perf_ + perf) * np + ebosCompIdxToFlowCompIdx(comp)];
|
2017-06-23 09:45:14 -05:00
|
|
|
}
|
|
|
|
if(has_solvent) {
|
2017-11-30 10:14:29 -06:00
|
|
|
perfRates[perf * num_components_ + contiSolventEqIdx] = well_state.perfRateSolvent()[first_perf_ + perf];
|
2017-06-23 09:45:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
computeConnectionDensities(perfRates, b_perf, rsmax_perf, rvmax_perf, surf_dens_perf);
|
|
|
|
|
|
|
|
computeConnectionPressureDelta();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-26 09:01:45 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-29 06:52:31 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeWellConnectionPressures(const Simulator& ebosSimulator,
|
|
|
|
const WellState& well_state)
|
|
|
|
{
|
|
|
|
// 1. Compute properties required by computeConnectionPressureDelta().
|
|
|
|
// Note that some of the complexity of this part is due to the function
|
|
|
|
// taking std::vector<double> arguments, and not Eigen objects.
|
|
|
|
std::vector<double> b_perf;
|
|
|
|
std::vector<double> rsmax_perf;
|
|
|
|
std::vector<double> rvmax_perf;
|
|
|
|
std::vector<double> surf_dens_perf;
|
|
|
|
computePropertiesForWellConnectionPressures(ebosSimulator, well_state, b_perf, rsmax_perf, rvmax_perf, surf_dens_perf);
|
|
|
|
computeWellConnectionDensitesPressures(well_state, b_perf, rsmax_perf, rvmax_perf, surf_dens_perf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-26 09:01:45 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-10-16 09:46:28 -05:00
|
|
|
solveEqAndUpdateWellState(WellState& well_state)
|
2017-06-26 09:01:45 -05:00
|
|
|
{
|
|
|
|
// We assemble the well equations, then we check the convergence,
|
|
|
|
// which is why we do not put the assembleWellEq here.
|
2017-08-03 08:14:36 -05:00
|
|
|
BVectorWell dx_well(1);
|
2017-06-26 09:01:45 -05:00
|
|
|
invDuneD_.mv(resWell_, dx_well);
|
|
|
|
|
2017-10-16 09:46:28 -05:00
|
|
|
updateWellState(dx_well, well_state);
|
2017-06-26 09:01:45 -05:00
|
|
|
}
|
|
|
|
|
2017-06-29 06:52:31 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-05 04:09:58 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-09-05 04:20:43 -05:00
|
|
|
calculateExplicitQuantities(const Simulator& ebosSimulator,
|
|
|
|
const WellState& well_state)
|
2017-09-05 04:09:58 -05:00
|
|
|
{
|
|
|
|
computeWellConnectionPressures(ebosSimulator, well_state);
|
|
|
|
computeAccumWell();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-29 06:52:31 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeAccumWell()
|
|
|
|
{
|
2018-05-18 03:57:08 -05:00
|
|
|
for (int eq_idx = 0; eq_idx < numWellConservationEq; ++eq_idx) {
|
2017-06-29 06:52:31 -05:00
|
|
|
F0_[eq_idx] = wellSurfaceVolumeFraction(eq_idx).value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
apply(const BVector& x, BVector& Ax) const
|
|
|
|
{
|
2018-03-05 09:40:17 -06:00
|
|
|
if ( param_.matrix_add_well_contributions_ )
|
|
|
|
{
|
|
|
|
// Contributions are already in the matrix itself
|
|
|
|
return;
|
|
|
|
}
|
2017-07-21 07:21:17 -05:00
|
|
|
assert( Bx_.size() == duneB_.N() );
|
|
|
|
assert( invDrw_.size() == invDuneD_.N() );
|
|
|
|
|
|
|
|
// Bx_ = duneB_ * x
|
|
|
|
duneB_.mv(x, Bx_);
|
|
|
|
// invDBx = invDuneD_ * Bx_
|
|
|
|
// TODO: with this, we modified the content of the invDrw_.
|
|
|
|
// Is it necessary to do this to save some memory?
|
2017-08-03 08:14:36 -05:00
|
|
|
BVectorWell& invDBx = invDrw_;
|
2017-07-21 07:21:17 -05:00
|
|
|
invDuneD_.mv(Bx_, invDBx);
|
|
|
|
|
|
|
|
// Ax = Ax - duneC_^T * invDBx
|
|
|
|
duneC_.mmtv(invDBx,Ax);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
apply(BVector& r) const
|
|
|
|
{
|
|
|
|
assert( invDrw_.size() == invDuneD_.N() );
|
|
|
|
|
|
|
|
// invDrw_ = invDuneD_ * resWell_
|
|
|
|
invDuneD_.mv(resWell_, invDrw_);
|
|
|
|
// r = r - duneC_^T * invDrw_
|
|
|
|
duneC_.mmtv(invDrw_, r);
|
|
|
|
}
|
|
|
|
|
2017-07-21 08:30:34 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-08-03 08:14:36 -05:00
|
|
|
recoverSolutionWell(const BVector& x, BVectorWell& xw) const
|
2017-07-21 08:30:34 -05:00
|
|
|
{
|
2017-08-03 08:14:36 -05:00
|
|
|
BVectorWell resWell = resWell_;
|
2017-07-21 08:30:34 -05:00
|
|
|
// resWell = resWell - B * x
|
|
|
|
duneB_.mmv(x, resWell);
|
|
|
|
// xw = D^-1 * resWell
|
|
|
|
invDuneD_.mv(resWell, xw);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-08-21 07:16:24 -05:00
|
|
|
recoverWellSolutionAndUpdateWellState(const BVector& x,
|
|
|
|
WellState& well_state) const
|
2017-07-21 08:30:34 -05:00
|
|
|
{
|
2017-08-03 08:14:36 -05:00
|
|
|
BVectorWell xw(1);
|
2017-07-21 08:30:34 -05:00
|
|
|
recoverSolutionWell(x, xw);
|
2017-10-16 09:46:28 -05:00
|
|
|
updateWellState(xw, well_state);
|
2017-07-21 08:30:34 -05:00
|
|
|
}
|
|
|
|
|
2017-07-24 04:31:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeWellRatesWithBhp(const Simulator& ebosSimulator,
|
|
|
|
const EvalWell& bhp,
|
|
|
|
std::vector<double>& well_flux) const
|
|
|
|
{
|
2017-08-04 06:07:16 -05:00
|
|
|
const int np = number_of_phases_;
|
2017-07-24 04:31:57 -05:00
|
|
|
well_flux.resize(np, 0.0);
|
|
|
|
|
|
|
|
const bool allow_cf = crossFlowAllowed(ebosSimulator);
|
|
|
|
|
2017-08-04 06:07:16 -05:00
|
|
|
for (int perf = 0; perf < number_of_perforations_; ++perf) {
|
|
|
|
const int cell_idx = well_cells_[perf];
|
2017-07-24 04:31:57 -05:00
|
|
|
const auto& intQuants = *(ebosSimulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/ 0));
|
|
|
|
// flux for each perforation
|
2017-11-30 09:31:48 -06:00
|
|
|
std::vector<EvalWell> cq_s(num_components_, 0.0);
|
|
|
|
std::vector<EvalWell> mob(num_components_, 0.0);
|
2017-07-24 04:31:57 -05:00
|
|
|
getMobility(ebosSimulator, perf, mob);
|
2018-02-12 09:32:46 -06:00
|
|
|
double perf_dis_gas_rate = 0.;
|
|
|
|
double perf_vap_oil_rate = 0.;
|
|
|
|
computePerfRate(intQuants, mob, well_index_[perf], bhp, perf_pressure_diffs_[perf], allow_cf,
|
|
|
|
cq_s, perf_dis_gas_rate, perf_vap_oil_rate);
|
2017-07-24 04:31:57 -05:00
|
|
|
|
|
|
|
for(int p = 0; p < np; ++p) {
|
2017-12-04 02:14:08 -06:00
|
|
|
well_flux[ebosCompIdxToFlowCompIdx(p)] += cq_s[p].value();
|
2017-07-24 04:31:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-24 07:48:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
std::vector<double>
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeWellPotentialWithTHP(const Simulator& ebosSimulator,
|
|
|
|
const double initial_bhp, // bhp from BHP constraints
|
|
|
|
const std::vector<double>& initial_potential) const
|
|
|
|
{
|
|
|
|
// TODO: pay attention to the situation that finally the potential is calculated based on the bhp control
|
|
|
|
// TODO: should we consider the bhp constraints during the iterative process?
|
2017-08-04 06:07:16 -05:00
|
|
|
const int np = number_of_phases_;
|
2017-07-24 07:48:57 -05:00
|
|
|
|
|
|
|
assert( np == int(initial_potential.size()) );
|
|
|
|
|
|
|
|
std::vector<double> potentials = initial_potential;
|
|
|
|
std::vector<double> old_potentials = potentials; // keeping track of the old potentials
|
|
|
|
|
|
|
|
double bhp = initial_bhp;
|
|
|
|
double old_bhp = bhp;
|
|
|
|
|
|
|
|
bool converged = false;
|
|
|
|
const int max_iteration = 1000;
|
|
|
|
const double bhp_tolerance = 1000.; // 1000 pascal
|
|
|
|
|
|
|
|
int iteration = 0;
|
|
|
|
|
|
|
|
while ( !converged && iteration < max_iteration ) {
|
|
|
|
// for each iteration, we calculate the bhp based on the rates/potentials with thp constraints
|
|
|
|
// with considering the bhp value from the bhp limits. At the beginning of each iteration,
|
|
|
|
// we initialize the bhp to be the bhp value from the bhp limits. Then based on the bhp values calculated
|
|
|
|
// from the thp constraints, we decide the effective bhp value for well potential calculation.
|
|
|
|
bhp = initial_bhp;
|
|
|
|
|
|
|
|
// The number of the well controls/constraints
|
2017-08-04 06:07:16 -05:00
|
|
|
const int nwc = well_controls_get_num(well_controls_);
|
2017-07-24 07:48:57 -05:00
|
|
|
|
|
|
|
for (int ctrl_index = 0; ctrl_index < nwc; ++ctrl_index) {
|
2017-08-04 06:07:16 -05:00
|
|
|
if (well_controls_iget_type(well_controls_, ctrl_index) == THP) {
|
2017-09-08 04:06:34 -05:00
|
|
|
const Opm::PhaseUsage& pu = phaseUsage();
|
2017-07-24 07:48:57 -05:00
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
std::vector<double> rates(3, 0.0);
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-11 04:10:59 -05:00
|
|
|
rates[ Water ] = potentials[pu.phase_pos[ Water ] ];
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
2017-08-11 04:10:59 -05:00
|
|
|
rates[ Oil ] = potentials[pu.phase_pos[ Oil ] ];
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-11 04:10:59 -05:00
|
|
|
rates[ Gas ] = potentials[pu.phase_pos[ Gas ] ];
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
const double bhp_calculated = calculateBhpFromThp(rates, ctrl_index);
|
|
|
|
|
|
|
|
if (well_type_ == INJECTOR && bhp_calculated < bhp ) {
|
|
|
|
bhp = bhp_calculated;
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
2017-08-11 04:10:59 -05:00
|
|
|
|
|
|
|
if (well_type_ == PRODUCER && bhp_calculated > bhp) {
|
|
|
|
bhp = bhp_calculated;
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// there should be always some available bhp/thp constraints there
|
|
|
|
if (std::isinf(bhp) || std::isnan(bhp)) {
|
2017-08-21 04:26:21 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Unvalid bhp value obtained during the potential calculation for well " << name());
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
converged = std::abs(old_bhp - bhp) < bhp_tolerance;
|
|
|
|
|
|
|
|
computeWellRatesWithBhp(ebosSimulator, bhp, potentials);
|
|
|
|
|
|
|
|
// checking whether the potentials have valid values
|
|
|
|
for (const double value : potentials) {
|
|
|
|
if (std::isinf(value) || std::isnan(value)) {
|
2017-08-21 04:26:21 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Unvalid potential value obtained during the potential calculation for well " << name());
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!converged) {
|
|
|
|
old_bhp = bhp;
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
// TODO: improve the interpolation, will it always be valid with the way below?
|
|
|
|
// TODO: finding better paramters, better iteration strategy for better convergence rate.
|
|
|
|
const double potential_update_damping_factor = 0.001;
|
|
|
|
potentials[p] = potential_update_damping_factor * potentials[p] + (1.0 - potential_update_damping_factor) * old_potentials[p];
|
|
|
|
old_potentials[p] = potentials[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
++iteration;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!converged) {
|
2017-08-21 04:26:21 -05:00
|
|
|
OPM_THROW(std::runtime_error, "Failed in getting converged for the potential calculation for well " << name());
|
2017-07-24 07:48:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return potentials;
|
|
|
|
}
|
|
|
|
|
2017-07-24 08:09:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
computeWellPotentials(const Simulator& ebosSimulator,
|
|
|
|
const WellState& well_state,
|
2017-09-05 04:09:58 -05:00
|
|
|
std::vector<double>& well_potentials) // const
|
2017-07-24 08:09:44 -05:00
|
|
|
{
|
2017-09-05 04:09:58 -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-07-24 08:09:44 -05:00
|
|
|
|
2017-09-05 04:09:58 -05:00
|
|
|
const int np = number_of_phases_;
|
2017-07-24 08:09:44 -05:00
|
|
|
well_potentials.resize(np, 0.0);
|
|
|
|
|
|
|
|
// get the bhp value based on the bhp constraints
|
|
|
|
const double bhp = mostStrictBhpFromBhpLimits();
|
|
|
|
|
|
|
|
// does the well have a THP related constraint?
|
|
|
|
if ( !wellHasTHPConstraints() ) {
|
|
|
|
assert(std::abs(bhp) != std::numeric_limits<double>::max());
|
|
|
|
|
|
|
|
computeWellRatesWithBhp(ebosSimulator, bhp, well_potentials);
|
|
|
|
} else {
|
|
|
|
// the well has a THP related constraint
|
|
|
|
// checking whether a well is newly added, it only happens at the beginning of the report step
|
2017-08-04 06:07:16 -05:00
|
|
|
if ( !well_state.isNewWell(index_of_well_) ) {
|
2017-07-24 08:09:44 -05:00
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
// This is dangerous for new added well
|
|
|
|
// since we are not handling the initialization correctly for now
|
2017-08-04 06:07:16 -05:00
|
|
|
well_potentials[p] = well_state.wellRates()[index_of_well_ * np + p];
|
2017-07-24 08:09:44 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We need to generate a reasonable rates to start the iteration process
|
|
|
|
computeWellRatesWithBhp(ebosSimulator, bhp, well_potentials);
|
|
|
|
for (double& value : well_potentials) {
|
|
|
|
// make the value a little safer in case the BHP limits are default ones
|
|
|
|
// TODO: a better way should be a better rescaling based on the investigation of the VFP table.
|
|
|
|
const double rate_safety_scaling_factor = 0.00001;
|
|
|
|
value *= rate_safety_scaling_factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
well_potentials = computeWellPotentialWithTHP(ebosSimulator, bhp, well_potentials);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:49:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
2017-08-21 08:41:25 -05:00
|
|
|
updatePrimaryVariables(const WellState& well_state) const
|
2017-08-07 10:49:35 -05:00
|
|
|
{
|
|
|
|
const int well_index = index_of_well_;
|
2018-05-08 03:54:57 -05:00
|
|
|
const int np = number_of_phases_;
|
2017-08-07 10:49:35 -05:00
|
|
|
|
2018-05-08 03:54:57 -05:00
|
|
|
// the weighted total well rate
|
|
|
|
double total_well_rate = 0.0;
|
|
|
|
for (int p = 0; p < np; ++p) {
|
|
|
|
total_well_rate += scalingFactor(p) * well_state.wellRates()[np * well_index + p];
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
|
2018-05-11 07:21:53 -05:00
|
|
|
// Not: for the moment, the first primary variable for the injectors is not G_total. The injection rate
|
|
|
|
// under surface condition is used here
|
2018-05-08 03:54:57 -05:00
|
|
|
if (well_type_ == INJECTOR) {
|
2018-05-30 08:44:05 -05:00
|
|
|
primary_variables_[WQTotal] = 0.;
|
2018-05-08 03:54:57 -05:00
|
|
|
for (int p = 0; p < np; ++p) {
|
2018-05-11 07:21:53 -05:00
|
|
|
// TODO: the use of comp_frac_ here is dangerous, since the injection phase can be different from
|
|
|
|
// prefered phasse in WELSPECS, while comp_frac_ only reflect the one specified in WELSPECS
|
2018-05-30 08:44:05 -05:00
|
|
|
primary_variables_[WQTotal] += well_state.wellRates()[np * well_index + p] * comp_frac_[p];
|
2018-05-08 03:54:57 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int p = 0; p < np; ++p) {
|
2018-05-30 08:44:05 -05:00
|
|
|
primary_variables_[WQTotal] = total_well_rate;
|
2018-05-08 03:54:57 -05:00
|
|
|
}
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
2018-05-08 03:54:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
const WellControls* wc = well_controls_;
|
|
|
|
const double* distr = well_controls_get_current_distr(wc);
|
|
|
|
const auto pu = phaseUsage();
|
|
|
|
|
|
|
|
if(std::abs(total_well_rate) > 0.) {
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2018-05-08 03:54:57 -05:00
|
|
|
primary_variables_[WFrac] = scalingFactor(pu.phase_pos[Water]) * well_state.wellRates()[np*well_index + pu.phase_pos[Water]] / total_well_rate;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2018-05-08 03:54:57 -05:00
|
|
|
primary_variables_[GFrac] = scalingFactor(pu.phase_pos[Gas]) * (well_state.wellRates()[np*well_index + pu.phase_pos[Gas]] - well_state.solventWellRate(well_index)) / total_well_rate ;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
if (has_solvent) {
|
2018-05-08 03:54:57 -05:00
|
|
|
primary_variables_[SFrac] = scalingFactor(pu.phase_pos[Gas]) * well_state.solventWellRate(well_index) / total_well_rate ;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
2018-05-08 03:54:57 -05:00
|
|
|
} else { // total_well_rate == 0
|
2017-08-07 10:49:35 -05:00
|
|
|
if (well_type_ == INJECTOR) {
|
|
|
|
// only single phase injection handled
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-07 10:49:35 -05:00
|
|
|
if (distr[Water] > 0.0) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[WFrac] = 1.0;
|
2017-08-07 10:49:35 -05:00
|
|
|
} else {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[WFrac] = 0.0;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-31 00:50:28 -05:00
|
|
|
if (distr[pu.phase_pos[Gas]] > 0.0) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[GFrac] = 1.0 - wsolvent();
|
2017-08-07 10:49:35 -05:00
|
|
|
if (has_solvent) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[SFrac] = wsolvent();
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
} else {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[GFrac] = 0.0;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: it is possible to leave injector as a oil well,
|
|
|
|
// when F_w and F_g both equals to zero, not sure under what kind of circumstance
|
|
|
|
// this will happen.
|
|
|
|
} else if (well_type_ == PRODUCER) { // producers
|
|
|
|
// TODO: the following are not addressed for the solvent case yet
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[WFrac] = 1.0 / np;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
2017-12-04 02:14:08 -06:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
2017-08-21 08:41:25 -05:00
|
|
|
primary_variables_[GFrac] = 1.0 / np;
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OPM_THROW(std::logic_error, "Expected PRODUCER or INJECTOR type of well");
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 03:54:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
// BHP
|
|
|
|
primary_variables_[Bhp] = well_state.bhp()[index_of_well_];
|
2017-08-07 10:49:35 -05:00
|
|
|
}
|
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
template<class ValueType>
|
|
|
|
ValueType
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
calculateBhpFromThp(const std::vector<ValueType>& rates,
|
|
|
|
const int control_index) const
|
|
|
|
{
|
2017-08-14 07:11:58 -05:00
|
|
|
// TODO: when well is under THP control, the BHP is dependent on the rates,
|
|
|
|
// the well rates is also dependent on the BHP, so it might need to do some iteration.
|
|
|
|
// However, when group control is involved, change of the rates might impacts other wells
|
|
|
|
// so iterations on a higher level will be required. Some investigation might be needed when
|
|
|
|
// we face problems under THP control.
|
|
|
|
|
2017-08-11 04:10:59 -05:00
|
|
|
assert(int(rates.size()) == 3); // the vfp related only supports three phases now.
|
|
|
|
|
|
|
|
const ValueType aqua = rates[Water];
|
|
|
|
const ValueType liquid = rates[Oil];
|
|
|
|
const ValueType vapour = rates[Gas];
|
|
|
|
|
|
|
|
const int vfp = well_controls_iget_vfp(well_controls_, control_index);
|
|
|
|
const double& thp = well_controls_iget_target(well_controls_, control_index);
|
|
|
|
const double& alq = well_controls_iget_alq(well_controls_, control_index);
|
|
|
|
|
|
|
|
// pick the density in the top layer
|
2018-05-15 09:17:01 -05:00
|
|
|
// TODO: it is possible it should be a Evaluation
|
2017-08-11 04:10:59 -05:00
|
|
|
const double rho = perf_densities_[0];
|
|
|
|
|
|
|
|
ValueType bhp = 0.;
|
|
|
|
if (well_type_ == INJECTOR) {
|
|
|
|
const double vfp_ref_depth = vfp_properties_->getInj()->getTable(vfp)->getDatumDepth();
|
|
|
|
|
|
|
|
const double dp = wellhelpers::computeHydrostaticCorrection(ref_depth_, vfp_ref_depth, rho, gravity_);
|
|
|
|
|
|
|
|
bhp = vfp_properties_->getInj()->bhp(vfp, aqua, liquid, vapour, thp) - dp;
|
|
|
|
}
|
|
|
|
else if (well_type_ == PRODUCER) {
|
|
|
|
const double vfp_ref_depth = vfp_properties_->getProd()->getTable(vfp)->getDatumDepth();
|
|
|
|
|
|
|
|
const double dp = wellhelpers::computeHydrostaticCorrection(ref_depth_, vfp_ref_depth, rho, gravity_);
|
|
|
|
|
|
|
|
bhp = vfp_properties_->getProd()->bhp(vfp, aqua, liquid, vapour, thp, alq) - dp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
OPM_THROW(std::logic_error, "Expected INJECTOR or PRODUCER well");
|
|
|
|
}
|
|
|
|
|
|
|
|
return bhp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
double
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
calculateThpFromBhp(const std::vector<double>& rates,
|
|
|
|
const int control_index,
|
|
|
|
const double bhp) const
|
|
|
|
{
|
|
|
|
assert(int(rates.size()) == 3); // the vfp related only supports three phases now.
|
|
|
|
|
|
|
|
const double aqua = rates[Water];
|
|
|
|
const double liquid = rates[Oil];
|
|
|
|
const double vapour = rates[Gas];
|
|
|
|
|
|
|
|
const int vfp = well_controls_iget_vfp(well_controls_, control_index);
|
|
|
|
const double& alq = well_controls_iget_alq(well_controls_, control_index);
|
|
|
|
|
|
|
|
// pick the density in the top layer
|
|
|
|
const double rho = perf_densities_[0];
|
|
|
|
|
|
|
|
double thp = 0.0;
|
|
|
|
if (well_type_ == INJECTOR) {
|
|
|
|
const double vfp_ref_depth = vfp_properties_->getInj()->getTable(vfp)->getDatumDepth();
|
|
|
|
|
|
|
|
const double dp = wellhelpers::computeHydrostaticCorrection(ref_depth_, vfp_ref_depth, rho, gravity_);
|
|
|
|
|
|
|
|
thp = vfp_properties_->getInj()->thp(vfp, aqua, liquid, vapour, bhp + dp);
|
|
|
|
}
|
|
|
|
else if (well_type_ == PRODUCER) {
|
|
|
|
const double vfp_ref_depth = vfp_properties_->getProd()->getTable(vfp)->getDatumDepth();
|
|
|
|
|
|
|
|
const double dp = wellhelpers::computeHydrostaticCorrection(ref_depth_, vfp_ref_depth, rho, gravity_);
|
|
|
|
|
|
|
|
thp = vfp_properties_->getProd()->thp(vfp, aqua, liquid, vapour, bhp + dp, alq);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
OPM_THROW(std::logic_error, "Expected INJECTOR or PRODUCER well");
|
|
|
|
}
|
|
|
|
|
|
|
|
return thp;
|
|
|
|
}
|
|
|
|
|
2017-09-05 02:25:34 -05:00
|
|
|
|
2017-08-31 00:50:28 -05:00
|
|
|
|
|
|
|
|
2017-11-23 09:10:37 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::
|
|
|
|
updateWaterMobilityWithPolymer(const Simulator& ebos_simulator,
|
|
|
|
const int perf,
|
|
|
|
std::vector<EvalWell>& mob) const
|
|
|
|
{
|
|
|
|
const int cell_idx = well_cells_[perf];
|
|
|
|
const auto& int_quant = *(ebos_simulator.model().cachedIntensiveQuantities(cell_idx, /*timeIdx=*/ 0));
|
|
|
|
const EvalWell polymer_concentration = extendEval(int_quant.polymerConcentration());
|
|
|
|
|
|
|
|
// TODO: not sure should based on the well type or injecting/producing peforations
|
|
|
|
// it can be different for crossflow
|
|
|
|
if (well_type_ == INJECTOR) {
|
|
|
|
// assume fully mixing within injecting wellbore
|
|
|
|
const auto& visc_mult_table = PolymerModule::plyviscViscosityMultiplierTable(int_quant.pvtRegionIndex());
|
2017-12-04 02:14:08 -06:00
|
|
|
const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
|
|
|
mob[waterCompIdx] /= (extendEval(int_quant.waterViscosityCorrection()) * visc_mult_table.eval(polymer_concentration, /*extrapolate=*/true) );
|
2017-11-23 09:10:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PolymerModule::hasPlyshlog()) {
|
|
|
|
// we do not calculate the shear effects for injection wells when they do not
|
|
|
|
// inject polymer.
|
|
|
|
if (well_type_ == INJECTOR && wpolymer() == 0.) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// compute the well water velocity with out shear effects.
|
|
|
|
const bool allow_cf = crossFlowAllowed(ebos_simulator);
|
|
|
|
const EvalWell& bhp = getBhp();
|
2017-11-30 09:31:48 -06:00
|
|
|
std::vector<EvalWell> cq_s(num_components_,0.0);
|
2018-02-12 09:32:46 -06:00
|
|
|
double perf_dis_gas_rate = 0.;
|
|
|
|
double perf_vap_oil_rate = 0.;
|
|
|
|
computePerfRate(int_quant, mob, well_index_[perf], bhp, perf_pressure_diffs_[perf], allow_cf,
|
|
|
|
cq_s, perf_dis_gas_rate, perf_vap_oil_rate);
|
2017-11-23 09:10:37 -06:00
|
|
|
// TODO: make area a member
|
|
|
|
const double area = 2 * M_PI * perf_rep_radius_[perf] * perf_length_[perf];
|
|
|
|
const auto& material_law_manager = ebos_simulator.problem().materialLawManager();
|
|
|
|
const auto& scaled_drainage_info =
|
|
|
|
material_law_manager->oilWaterScaledEpsInfoDrainage(cell_idx);
|
|
|
|
const double swcr = scaled_drainage_info.Swcr;
|
|
|
|
const EvalWell poro = extendEval(int_quant.porosity());
|
2017-12-04 02:14:08 -06:00
|
|
|
const EvalWell sw = extendEval(int_quant.fluidState().saturation(FluidSystem::waterPhaseIdx));
|
2017-11-23 09:10:37 -06:00
|
|
|
// guard against zero porosity and no water
|
|
|
|
const EvalWell denom = Opm::max( (area * poro * (sw - swcr)), 1e-12);
|
2017-12-04 02:14:08 -06:00
|
|
|
const unsigned waterCompIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx);
|
|
|
|
EvalWell water_velocity = cq_s[waterCompIdx] / denom * extendEval(int_quant.fluidState().invB(FluidSystem::waterPhaseIdx));
|
2017-11-23 09:10:37 -06:00
|
|
|
|
|
|
|
if (PolymerModule::hasShrate()) {
|
|
|
|
// the equation for the water velocity conversion for the wells and reservoir are from different version
|
|
|
|
// of implementation. It can be changed to be more consistent when possible.
|
|
|
|
water_velocity *= PolymerModule::shrate( int_quant.pvtRegionIndex() ) / bore_diameters_[perf];
|
|
|
|
}
|
|
|
|
const EvalWell shear_factor = PolymerModule::computeShearFactor(polymer_concentration,
|
|
|
|
int_quant.pvtRegionIndex(),
|
|
|
|
water_velocity);
|
|
|
|
// modify the mobility with the shear factor.
|
2017-12-04 02:14:08 -06:00
|
|
|
mob[waterCompIdx] /= shear_factor;
|
2017-11-23 09:10:37 -06:00
|
|
|
}
|
|
|
|
}
|
2017-05-15 07:46:43 -05:00
|
|
|
|
|
|
|
template<typename TypeTag>
|
|
|
|
void
|
|
|
|
StandardWell<TypeTag>::addWellContributions(Mat& mat) const
|
|
|
|
{
|
2017-05-17 08:54:07 -05:00
|
|
|
// We need to change matrx A as follows
|
|
|
|
// A -= C^T D^-1 B
|
|
|
|
// D is diagonal
|
|
|
|
// B and C have 1 row, nc colums and nonzero
|
2018-02-26 06:57:41 -06:00
|
|
|
// at (0,j) only if this well has a perforation at cell j.
|
2017-05-17 08:54:07 -05:00
|
|
|
|
2018-02-26 02:09:12 -06:00
|
|
|
for ( auto colC = duneC_[0].begin(), endC = duneC_[0].end(); colC != endC; ++colC )
|
|
|
|
{
|
2017-05-17 08:54:07 -05:00
|
|
|
const auto row_index = colC.index();
|
2017-05-15 07:46:43 -05:00
|
|
|
auto& row = mat[row_index];
|
2017-05-17 08:54:07 -05:00
|
|
|
auto col = row.begin();
|
2018-04-07 14:41:34 -05:00
|
|
|
|
2018-02-26 02:09:12 -06:00
|
|
|
for ( auto colB = duneB_[0].begin(), endB = duneB_[0].end(); colB != endB; ++colB )
|
|
|
|
{
|
2017-05-17 08:54:07 -05:00
|
|
|
const auto col_index = colB.index();
|
2018-02-26 06:57:41 -06:00
|
|
|
// Move col to index col_index
|
2018-02-26 02:09:12 -06:00
|
|
|
while ( col != row.end() && col.index() < col_index ) ++col;
|
2017-05-17 08:54:07 -05:00
|
|
|
assert(col != row.end() && col.index() == col_index);
|
2017-05-15 07:46:43 -05:00
|
|
|
|
|
|
|
Dune::FieldMatrix<Scalar, numWellEq, numEq> tmp;
|
|
|
|
typename Mat::block_type tmp1;
|
|
|
|
Dune::FMatrixHelp::multMatrix(invDuneD_[0][0], (*colB), tmp);
|
|
|
|
Detail::multMatrixTransposed((*colC), tmp, tmp1);
|
|
|
|
(*col) -= tmp1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-15 04:41:03 -05:00
|
|
|
}
|