2015-09-21 10:25:29 -05:00
|
|
|
/*
|
|
|
|
Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_BLACKOIMULTISEGMENTLMODEL_IMPL_HEADER_INCLUDED
|
|
|
|
#define OPM_BLACKOIMULTISEGMENTLMODEL_IMPL_HEADER_INCLUDED
|
|
|
|
|
|
|
|
#include <opm/autodiff/BlackoilMultiSegmentModel.hpp>
|
|
|
|
|
|
|
|
#include <opm/autodiff/AutoDiffBlock.hpp>
|
|
|
|
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
|
|
|
#include <opm/autodiff/GridHelpers.hpp>
|
|
|
|
#include <opm/autodiff/BlackoilPropsAdInterface.hpp>
|
|
|
|
#include <opm/autodiff/GeoProps.hpp>
|
|
|
|
#include <opm/autodiff/WellDensitySegmented.hpp>
|
|
|
|
#include <opm/autodiff/VFPProperties.hpp>
|
|
|
|
#include <opm/autodiff/VFPProdProperties.hpp>
|
|
|
|
#include <opm/autodiff/VFPInjProperties.hpp>
|
|
|
|
|
|
|
|
#include <opm/core/grid.h>
|
|
|
|
#include <opm/core/linalg/LinearSolverInterface.hpp>
|
|
|
|
#include <opm/core/linalg/ParallelIstlInformation.hpp>
|
|
|
|
#include <opm/core/props/rock/RockCompressibility.hpp>
|
2015-10-12 07:06:50 -05:00
|
|
|
#include <opm/common/ErrorMacros.hpp>
|
|
|
|
#include <opm/common/Exceptions.hpp>
|
2015-09-21 10:25:29 -05:00
|
|
|
#include <opm/core/utility/Units.hpp>
|
|
|
|
#include <opm/core/well_controls.h>
|
|
|
|
#include <opm/core/utility/parameters/ParameterGroup.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
//#include <fstream>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Opm {
|
|
|
|
|
|
|
|
|
|
|
|
template <class Grid>
|
|
|
|
BlackoilMultiSegmentModel<Grid>::
|
|
|
|
BlackoilMultiSegmentModel(const typename Base::ModelParameters& param,
|
|
|
|
const Grid& grid ,
|
|
|
|
const BlackoilPropsAdInterface& fluid,
|
|
|
|
const DerivedGeology& geo ,
|
|
|
|
const RockCompressibility* rock_comp_props,
|
2016-05-09 10:44:59 -05:00
|
|
|
const MultisegmentWells& well_model,
|
2015-09-21 10:25:29 -05:00
|
|
|
const NewtonIterationBlackoilInterface& linsolver,
|
|
|
|
Opm::EclipseStateConstPtr eclState,
|
|
|
|
const bool has_disgas,
|
|
|
|
const bool has_vapoil,
|
2016-05-09 10:44:59 -05:00
|
|
|
const bool terminal_output)
|
|
|
|
: Base(param, grid, fluid, geo, rock_comp_props, well_model, linsolver,
|
2015-09-22 08:42:36 -05:00
|
|
|
eclState, has_disgas, has_vapoil, terminal_output)
|
2015-11-17 08:21:12 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 04:41:28 -05:00
|
|
|
template <class Grid>
|
2015-09-21 10:25:29 -05:00
|
|
|
void
|
2015-09-23 04:41:28 -05:00
|
|
|
BlackoilMultiSegmentModel<Grid>::
|
2015-09-21 10:25:29 -05:00
|
|
|
prepareStep(const double dt,
|
|
|
|
ReservoirState& reservoir_state,
|
2015-10-12 05:49:30 -05:00
|
|
|
WellState& well_state)
|
2015-09-21 10:25:29 -05:00
|
|
|
{
|
|
|
|
pvdt_ = geo_.poreVolume() / dt;
|
|
|
|
if (active_[Gas]) {
|
|
|
|
updatePrimalVariableFromState(reservoir_state);
|
|
|
|
}
|
2015-09-23 04:41:28 -05:00
|
|
|
|
2015-10-14 10:24:05 -05:00
|
|
|
const int nw = wellsMultiSegment().size();
|
2016-03-08 08:44:53 -06:00
|
|
|
|
2016-04-22 10:15:47 -05:00
|
|
|
if ( !msWellOps().has_multisegment_wells ) {
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().segVDt() = V::Zero(nw);
|
2016-03-08 08:44:53 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-14 10:24:05 -05:00
|
|
|
const int nseg_total = well_state.numSegments();
|
|
|
|
std::vector<double> segment_volume;
|
|
|
|
segment_volume.reserve(nseg_total);
|
|
|
|
for (int w = 0; w < nw; ++w) {
|
|
|
|
WellMultiSegmentConstPtr well = wellsMultiSegment()[w];
|
|
|
|
const std::vector<double>& segment_volume_well = well->segmentVolume();
|
|
|
|
segment_volume.insert(segment_volume.end(), segment_volume_well.begin(), segment_volume_well.end());
|
|
|
|
}
|
|
|
|
assert(int(segment_volume.size()) == nseg_total);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().segVDt() = Eigen::Map<V>(segment_volume.data(), nseg_total) / dt;
|
2015-09-21 10:25:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-11-20 04:45:35 -06:00
|
|
|
template <class Grid>
|
|
|
|
int
|
|
|
|
BlackoilMultiSegmentModel<Grid>::numWellVars() const
|
|
|
|
{
|
|
|
|
// For each segment, we have a pressure variable, and one flux per phase.
|
2016-05-10 07:08:05 -05:00
|
|
|
const int nseg = wellModel().numSegment();
|
2015-11-20 04:45:35 -06:00
|
|
|
return (numPhases() + 1) * nseg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
|
2015-09-23 05:45:08 -05:00
|
|
|
template <class Grid>
|
2015-09-21 10:25:29 -05:00
|
|
|
void
|
2015-09-23 05:45:08 -05:00
|
|
|
BlackoilMultiSegmentModel<Grid>::makeConstantState(SolutionState& state) const
|
2015-09-21 10:25:29 -05:00
|
|
|
{
|
2015-09-23 05:45:08 -05:00
|
|
|
Base::makeConstantState(state);
|
|
|
|
state.segp = ADB::constant(state.segp.value());
|
|
|
|
state.segqs = ADB::constant(state.segqs.value());
|
2015-09-21 10:25:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 07:13:14 -05:00
|
|
|
template <class Grid>
|
2015-09-21 10:25:29 -05:00
|
|
|
void
|
2015-09-23 07:13:14 -05:00
|
|
|
BlackoilMultiSegmentModel<Grid>::variableStateExtractWellsVars(const std::vector<int>& indices,
|
2015-10-12 05:49:30 -05:00
|
|
|
std::vector<ADB>& vars,
|
|
|
|
SolutionState& state) const
|
2015-09-21 10:25:29 -05:00
|
|
|
{
|
2015-11-20 07:13:32 -06:00
|
|
|
// TODO: using the original Qs for the segment rates for now, to be fixed eventually.
|
|
|
|
// TODO: using the original Bhp for the segment pressures for now, to be fixed eventually.
|
2015-10-12 05:49:30 -05:00
|
|
|
|
2015-09-23 07:13:14 -05:00
|
|
|
// segment phase rates in surface volume
|
|
|
|
state.segqs = std::move(vars[indices[Qs]]);
|
2015-09-21 10:25:29 -05:00
|
|
|
|
2015-09-23 07:13:14 -05:00
|
|
|
// segment pressures
|
|
|
|
state.segp = std::move(vars[indices[Bhp]]);
|
2015-09-21 10:25:29 -05:00
|
|
|
|
2015-10-12 05:49:30 -05:00
|
|
|
// The qs and bhp are no longer primary variables, but could
|
|
|
|
// still be used in computations. They are identical to the
|
|
|
|
// pressures and flows of the top segments.
|
|
|
|
const int np = numPhases();
|
|
|
|
const int ns = state.segp.size();
|
2016-05-10 04:40:43 -05:00
|
|
|
const int nw = wellModel().topWellSegments().size();
|
2015-10-12 05:49:30 -05:00
|
|
|
state.qs = ADB::constant(ADB::V::Zero(np*nw));
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
// Extract segment fluxes for this phase (ns consecutive elements).
|
|
|
|
ADB segqs_phase = subset(state.segqs, Span(ns, 1, ns*phase));
|
|
|
|
// Extract top segment fluxes (= well fluxes)
|
2016-05-10 04:40:43 -05:00
|
|
|
ADB wellqs_phase = subset(segqs_phase, wellModel().topWellSegments());
|
2015-10-12 05:49:30 -05:00
|
|
|
// Expand to full size of qs (which contains all phases) and add.
|
|
|
|
state.qs += superset(wellqs_phase, Span(nw, 1, nw*phase), nw*np);
|
|
|
|
}
|
2016-05-10 04:40:43 -05:00
|
|
|
state.bhp = subset(state.segp, wellModel().topWellSegments());
|
2015-09-21 10:25:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-09-23 07:56:48 -05:00
|
|
|
|
|
|
|
template <class Grid>
|
2015-09-21 10:25:29 -05:00
|
|
|
void
|
2015-09-23 07:56:48 -05:00
|
|
|
BlackoilMultiSegmentModel<Grid>::
|
2015-09-21 10:25:29 -05:00
|
|
|
assemble(const ReservoirState& reservoir_state,
|
|
|
|
WellState& well_state,
|
|
|
|
const bool initial_assembly)
|
|
|
|
{
|
|
|
|
using namespace Opm::AutoDiffGrid;
|
|
|
|
|
2015-11-20 07:13:32 -06:00
|
|
|
// TODO: include VFP effect.
|
2015-09-21 10:25:29 -05:00
|
|
|
// If we have VFP tables, we need the well connection
|
|
|
|
// pressures for the "simple" hydrostatic correction
|
|
|
|
// between well depth and vfp table depth.
|
|
|
|
// if (isVFPActive()) {
|
|
|
|
// SolutionState state = asImpl().variableState(reservoir_state, well_state);
|
|
|
|
// SolutionState state0 = state;
|
|
|
|
// asImpl().makeConstantState(state0);
|
2015-10-12 09:27:13 -05:00
|
|
|
// asImpl().computeWellConnectionPressures(state0, well_state);
|
2015-09-21 10:25:29 -05:00
|
|
|
// }
|
|
|
|
|
|
|
|
// Possibly switch well controls and updating well state to
|
|
|
|
// get reasonable initial conditions for the wells
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().updateWellControls(terminal_output_, well_state);
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
// Create the primary variables.
|
2015-10-12 09:27:13 -05:00
|
|
|
SolutionState state = asImpl().variableState(reservoir_state, well_state);
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
if (initial_assembly) {
|
|
|
|
// Create the (constant, derivativeless) initial state.
|
|
|
|
SolutionState state0 = state;
|
2015-10-12 09:27:13 -05:00
|
|
|
asImpl().makeConstantState(state0);
|
2015-09-21 10:25:29 -05:00
|
|
|
// Compute initial accumulation contributions
|
|
|
|
// and well connection pressures.
|
2015-10-12 09:27:13 -05:00
|
|
|
asImpl().computeAccum(state0, 0);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeSegmentFluidProperties(state0);
|
2015-10-15 08:18:22 -05:00
|
|
|
const int np = numPhases();
|
2016-05-10 04:40:43 -05:00
|
|
|
assert(np == int(wellModel().segmentCompSurfVolumeInitial().size()));
|
2015-10-15 08:18:22 -05:00
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().segmentCompSurfVolumeInitial()[phase] = wellModel().segmentCompSurfVolumeCurrent()[phase].value();
|
2015-10-15 08:18:22 -05:00
|
|
|
}
|
2016-05-06 09:56:33 -05:00
|
|
|
|
|
|
|
const std::vector<ADB> kr_adb = Base::computeRelPerm(state0);
|
|
|
|
std::vector<ADB> fluid_density(numPhases(), ADB::null());
|
|
|
|
// TODO: make sure the order of the density and the order of the kr are the same.
|
|
|
|
for (int phaseIdx = 0; phaseIdx < fluid_.numPhases(); ++phaseIdx) {
|
|
|
|
const int canonicalPhaseIdx = canph_[phaseIdx];
|
|
|
|
fluid_density[phaseIdx] = fluidDensity(canonicalPhaseIdx, rq_[phaseIdx].b, state0.rs, state0.rv);
|
|
|
|
}
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeWellConnectionPressures(state0, well_state, kr_adb, fluid_density);
|
2016-05-06 09:56:33 -05:00
|
|
|
// asImpl().computeWellConnectionPressures(state0, well_state);
|
2015-09-21 10:25:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// OPM_AD_DISKVAL(state.pressure);
|
|
|
|
// OPM_AD_DISKVAL(state.saturation[0]);
|
|
|
|
// OPM_AD_DISKVAL(state.saturation[1]);
|
|
|
|
// OPM_AD_DISKVAL(state.saturation[2]);
|
|
|
|
// OPM_AD_DISKVAL(state.rs);
|
|
|
|
// OPM_AD_DISKVAL(state.rv);
|
|
|
|
// OPM_AD_DISKVAL(state.qs);
|
|
|
|
// OPM_AD_DISKVAL(state.bhp);
|
|
|
|
|
|
|
|
// -------- Mass balance equations --------
|
2015-10-12 09:27:13 -05:00
|
|
|
asImpl().assembleMassBalanceEq(state);
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
// -------- Well equations ----------
|
|
|
|
|
2016-04-06 05:52:54 -05:00
|
|
|
if ( ! wellsActive() ) {
|
2015-09-21 10:25:29 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeSegmentFluidProperties(state);
|
2016-04-27 06:11:36 -05:00
|
|
|
|
|
|
|
const double gravity = detail::getGravity(geo_.gravity(), UgGridHelpers::dimensions(grid_));
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeSegmentPressuresDelta(gravity);
|
2015-10-14 07:59:55 -05:00
|
|
|
|
2015-10-13 04:28:48 -05:00
|
|
|
std::vector<ADB> mob_perfcells;
|
|
|
|
std::vector<ADB> b_perfcells;
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().extractWellPerfProperties(state, rq_, mob_perfcells, b_perfcells);
|
2015-11-19 04:22:29 -06:00
|
|
|
if (param_.solve_welleq_initially_ && initial_assembly) {
|
2015-09-21 10:25:29 -05:00
|
|
|
// solve the well equations as a pre-processing step
|
2015-11-19 04:22:29 -06:00
|
|
|
asImpl().solveWellEq(mob_perfcells, b_perfcells, state, well_state);
|
|
|
|
}
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
// the perforation flux here are different
|
|
|
|
// it is related to the segment location
|
2015-10-13 04:28:48 -05:00
|
|
|
V aliveWells;
|
|
|
|
std::vector<ADB> cq_s;
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeWellFlux(state, mob_perfcells, b_perfcells, aliveWells, cq_s);
|
|
|
|
wellModel().updatePerfPhaseRatesAndPressures(cq_s, state, well_state);
|
|
|
|
wellModel().addWellFluxEq(cq_s, state, residual_);
|
2015-10-12 09:27:13 -05:00
|
|
|
asImpl().addWellContributionToMassBalanceEq(cq_s, state, well_state);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().addWellControlEq(state, well_state, aliveWells, residual_);
|
2015-09-21 10:25:29 -05:00
|
|
|
}
|
|
|
|
|
2015-09-23 07:56:48 -05:00
|
|
|
|
2015-09-21 10:25:29 -05:00
|
|
|
|
|
|
|
|
2015-09-25 10:16:23 -05:00
|
|
|
|
2015-11-19 04:22:29 -06:00
|
|
|
template <class Grid>
|
2015-11-19 06:49:42 -06:00
|
|
|
bool BlackoilMultiSegmentModel<Grid>::solveWellEq(const std::vector<ADB>& mob_perfcells,
|
2015-11-19 04:22:29 -06:00
|
|
|
const std::vector<ADB>& b_perfcells,
|
|
|
|
SolutionState& state,
|
|
|
|
WellState& well_state)
|
|
|
|
{
|
2016-04-12 07:00:22 -05:00
|
|
|
const bool converged = baseSolveWellEq(mob_perfcells, b_perfcells, state, well_state);
|
2015-11-19 04:22:29 -06:00
|
|
|
|
2015-11-19 06:49:42 -06:00
|
|
|
if (converged) {
|
|
|
|
// We must now update the state.segp and state.segqs members,
|
|
|
|
// that the base version does not know about.
|
|
|
|
const int np = numPhases();
|
|
|
|
const int nseg_total =well_state.numSegments();
|
|
|
|
{
|
|
|
|
// We will set the segp primary variable to the new ones,
|
|
|
|
// but we do not change the derivatives here.
|
|
|
|
ADB::V new_segp = Eigen::Map<ADB::V>(well_state.segPress().data(), nseg_total);
|
|
|
|
// Avoiding the copy below would require a value setter method
|
|
|
|
// in AutoDiffBlock.
|
|
|
|
std::vector<ADB::M> old_segp_derivs = state.segp.derivative();
|
|
|
|
state.segp = ADB::function(std::move(new_segp), std::move(old_segp_derivs));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Need to reshuffle well rates, from phase running fastest
|
|
|
|
// to wells running fastest.
|
|
|
|
// The transpose() below switches the ordering.
|
|
|
|
const DataBlock segrates = Eigen::Map<const DataBlock>(well_state.segPhaseRates().data(), nseg_total, np).transpose();
|
|
|
|
ADB::V new_segqs = Eigen::Map<const V>(segrates.data(), nseg_total * np);
|
|
|
|
std::vector<ADB::M> old_segqs_derivs = state.segqs.derivative();
|
|
|
|
state.segqs = ADB::function(std::move(new_segqs), std::move(old_segqs_derivs));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is also called by the base version, but since we have updated
|
|
|
|
// state.segp we must call it again.
|
2016-05-06 09:56:33 -05:00
|
|
|
const std::vector<ADB> kr_adb = Base::computeRelPerm(state);
|
|
|
|
std::vector<ADB> fluid_density(np, ADB::null());
|
|
|
|
// TODO: make sure the order of the density and the order of the kr are the same.
|
|
|
|
for (int phaseIdx = 0; phaseIdx < np; ++phaseIdx) {
|
|
|
|
const int canonicalPhaseIdx = canph_[phaseIdx];
|
|
|
|
fluid_density[phaseIdx] = fluidDensity(canonicalPhaseIdx, rq_[phaseIdx].b, state.rs, state.rv);
|
|
|
|
}
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeWellConnectionPressures(state, well_state, kr_adb, fluid_density);
|
2015-11-19 04:22:29 -06:00
|
|
|
}
|
|
|
|
|
2015-11-19 06:49:42 -06:00
|
|
|
return converged;
|
2015-11-19 04:22:29 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-10 07:08:05 -05:00
|
|
|
/// added to fixing the flow_multisegment running
|
2016-04-12 07:00:22 -05:00
|
|
|
template <class Grid>
|
|
|
|
bool
|
|
|
|
BlackoilMultiSegmentModel<Grid>::baseSolveWellEq(const std::vector<ADB>& mob_perfcells,
|
|
|
|
const std::vector<ADB>& b_perfcells,
|
|
|
|
SolutionState& state,
|
|
|
|
WellState& well_state) {
|
|
|
|
V aliveWells;
|
2016-05-10 04:40:43 -05:00
|
|
|
const int np = wellModel().numPhases();
|
2016-04-12 07:00:22 -05:00
|
|
|
std::vector<ADB> cq_s(np, ADB::null());
|
2016-05-10 04:40:43 -05:00
|
|
|
std::vector<int> indices = wellModel().variableWellStateIndices();
|
2016-04-12 07:00:22 -05:00
|
|
|
SolutionState state0 = state;
|
|
|
|
WellState well_state0 = well_state;
|
|
|
|
makeConstantState(state0);
|
|
|
|
|
|
|
|
std::vector<ADB> mob_perfcells_const(np, ADB::null());
|
|
|
|
std::vector<ADB> b_perfcells_const(np, ADB::null());
|
|
|
|
|
|
|
|
if ( Base::localWellsActive() ){
|
|
|
|
// If there are non well in the sudomain of the process
|
|
|
|
// thene mob_perfcells_const and b_perfcells_const would be empty
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
mob_perfcells_const[phase] = ADB::constant(mob_perfcells[phase].value());
|
|
|
|
b_perfcells_const[phase] = ADB::constant(b_perfcells[phase].value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int it = 0;
|
|
|
|
bool converged;
|
|
|
|
do {
|
|
|
|
// bhp and Q for the wells
|
|
|
|
std::vector<V> vars0;
|
|
|
|
vars0.reserve(2);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().variableWellStateInitials(well_state, vars0);
|
2016-04-12 07:00:22 -05:00
|
|
|
std::vector<ADB> vars = ADB::variables(vars0);
|
|
|
|
|
|
|
|
SolutionState wellSolutionState = state0;
|
|
|
|
variableStateExtractWellsVars(indices, vars, wellSolutionState);
|
2016-04-26 09:30:53 -05:00
|
|
|
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeWellFlux(wellSolutionState, mob_perfcells_const, b_perfcells_const, aliveWells, cq_s);
|
2016-04-26 09:30:53 -05:00
|
|
|
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().updatePerfPhaseRatesAndPressures(cq_s, wellSolutionState, well_state);
|
|
|
|
wellModel().addWellFluxEq(cq_s, wellSolutionState, residual_);
|
|
|
|
wellModel().addWellControlEq(wellSolutionState, well_state, aliveWells, residual_);
|
2016-04-12 07:00:22 -05:00
|
|
|
converged = Base::getWellConvergence(it);
|
|
|
|
|
|
|
|
if (converged) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++it;
|
|
|
|
if( Base::localWellsActive() )
|
|
|
|
{
|
|
|
|
std::vector<ADB> eqs;
|
|
|
|
eqs.reserve(2);
|
|
|
|
eqs.push_back(residual_.well_flux_eq);
|
|
|
|
eqs.push_back(residual_.well_eq);
|
|
|
|
ADB total_residual = vertcatCollapseJacs(eqs);
|
|
|
|
const std::vector<M>& Jn = total_residual.derivative();
|
|
|
|
typedef Eigen::SparseMatrix<double> Sp;
|
|
|
|
Sp Jn0;
|
|
|
|
Jn[0].toSparse(Jn0);
|
|
|
|
const Eigen::SparseLU< Sp > solver(Jn0);
|
|
|
|
ADB::V total_residual_v = total_residual.value();
|
|
|
|
const Eigen::VectorXd& dx = solver.solve(total_residual_v.matrix());
|
|
|
|
assert(dx.size() == total_residual_v.size());
|
2016-05-10 07:19:15 -05:00
|
|
|
wellModel().updateWellState(dx.array(), dpMaxRel(), well_state);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().updateWellControls(terminal_output_, well_state);
|
2016-04-12 07:00:22 -05:00
|
|
|
}
|
|
|
|
} while (it < 15);
|
|
|
|
|
|
|
|
if (converged) {
|
|
|
|
if ( terminal_output_ ) {
|
|
|
|
std::cout << "well converged iter: " << it << std::endl;
|
|
|
|
}
|
2016-05-10 04:40:43 -05:00
|
|
|
const int nw = wellModel().numWells();
|
2016-04-12 07:00:22 -05:00
|
|
|
{
|
|
|
|
// We will set the bhp primary variable to the new ones,
|
|
|
|
// but we do not change the derivatives here.
|
|
|
|
ADB::V new_bhp = Eigen::Map<ADB::V>(well_state.bhp().data(), nw);
|
|
|
|
// Avoiding the copy below would require a value setter method
|
|
|
|
// in AutoDiffBlock.
|
|
|
|
std::vector<ADB::M> old_derivs = state.bhp.derivative();
|
|
|
|
state.bhp = ADB::function(std::move(new_bhp), std::move(old_derivs));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Need to reshuffle well rates, from phase running fastest
|
|
|
|
// to wells running fastest.
|
|
|
|
// The transpose() below switches the ordering.
|
|
|
|
const DataBlock wrates = Eigen::Map<const DataBlock>(well_state.wellRates().data(), nw, np).transpose();
|
|
|
|
ADB::V new_qs = Eigen::Map<const V>(wrates.data(), nw*np);
|
|
|
|
std::vector<ADB::M> old_derivs = state.qs.derivative();
|
|
|
|
state.qs = ADB::function(std::move(new_qs), std::move(old_derivs));
|
|
|
|
}
|
2016-05-06 09:56:33 -05:00
|
|
|
|
|
|
|
const std::vector<ADB> kr_adb = Base::computeRelPerm(state);
|
|
|
|
std::vector<ADB> fluid_density(np, ADB::null());
|
|
|
|
// TODO: make sure the order of the density and the order of the kr are the same.
|
|
|
|
for (int phaseIdx = 0; phaseIdx < np; ++phaseIdx) {
|
|
|
|
const int canonicalPhaseIdx = canph_[phaseIdx];
|
|
|
|
fluid_density[phaseIdx] = fluidDensity(canonicalPhaseIdx, rq_[phaseIdx].b, state.rs, state.rv);
|
|
|
|
}
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().computeWellConnectionPressures(state, well_state, kr_adb, fluid_density);
|
2016-04-12 07:00:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!converged) {
|
|
|
|
well_state = well_state0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return converged;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 03:51:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Grid>
|
|
|
|
std::vector<V>
|
|
|
|
BlackoilMultiSegmentModel<Grid>::
|
|
|
|
variableStateInitials(const ReservoirState& x,
|
|
|
|
const WellState& xw) const
|
|
|
|
{
|
|
|
|
assert(active_[ Oil ]);
|
|
|
|
|
|
|
|
const int np = x.numPhases();
|
|
|
|
|
|
|
|
std::vector<V> vars0;
|
|
|
|
// p, Sw and Rs, Rv or Sg is used as primary depending on solution conditions
|
|
|
|
// and bhp and Q for the wells
|
|
|
|
vars0.reserve(np + 1);
|
|
|
|
variableReservoirStateInitials(x, vars0);
|
2016-05-10 04:40:43 -05:00
|
|
|
wellModel().variableWellStateInitials(xw, vars0);
|
2016-04-22 03:51:17 -05:00
|
|
|
return vars0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 10:25:29 -05:00
|
|
|
} // namespace Opm
|
|
|
|
|
|
|
|
#endif // OPM_BLACKOILMODELBASE_IMPL_HEADER_INCLUDED
|