2017-06-15 04:41:03 -05:00
|
|
|
/*
|
|
|
|
Copyright 2017 SINTEF ICT, Applied Mathematics.
|
|
|
|
Copyright 2017 Statoil ASA.
|
|
|
|
|
|
|
|
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_STANDARDWELL_HEADER_INCLUDED
|
|
|
|
#define OPM_STANDARDWELL_HEADER_INCLUDED
|
|
|
|
|
|
|
|
|
|
|
|
#include <opm/autodiff/WellInterface.hpp>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
template<typename TypeTag>
|
|
|
|
class StandardWell: public WellInterface<TypeTag>
|
2017-06-15 04:41:03 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
2017-06-29 06:52:31 -05:00
|
|
|
// TODO: some functions working with AD variables handles only with values (double) without
|
|
|
|
// dealing with derivatives. It can be beneficial to make functions can work with either AD or scalar value.
|
|
|
|
// And also, it can also be beneficial to make these functions hanle different types of AD variables.
|
2017-06-27 09:04:04 -05:00
|
|
|
// TODO: several functions related to polymer and PLYSHLOG are not incorprated yet,
|
|
|
|
// like the function wpolymer, setupCompressedToCartesian, computeRepRadiusPerfLength,
|
|
|
|
// They are introduced though PR 1220 and will be included later.
|
2017-07-28 03:08:57 -05:00
|
|
|
using typename WellInterface<TypeTag>::Simulator;
|
|
|
|
using typename WellInterface<TypeTag>::WellState;
|
|
|
|
using typename WellInterface<TypeTag>::IntensiveQuantities;
|
|
|
|
using typename WellInterface<TypeTag>::FluidSystem;
|
|
|
|
using typename WellInterface<TypeTag>::MaterialLaw;
|
|
|
|
using typename WellInterface<TypeTag>::ModelParameters;
|
|
|
|
using typename WellInterface<TypeTag>::BlackoilIndices;
|
2017-06-19 09:46:06 -05:00
|
|
|
|
2017-06-15 04:41:03 -05:00
|
|
|
// the positions of the primary variables for StandardWell
|
|
|
|
// there are three primary variables, the second and the third ones are F_w and F_g
|
|
|
|
// the first one can be total rate (G_t) or bhp, based on the control
|
|
|
|
enum WellVariablePositions {
|
|
|
|
XvarWell = 0,
|
|
|
|
WFrac = 1,
|
2017-06-27 09:04:04 -05:00
|
|
|
GFrac = 2,
|
|
|
|
SFrac = 3
|
2017-06-15 04:41:03 -05:00
|
|
|
};
|
|
|
|
|
2017-07-31 10:11:44 -05:00
|
|
|
using typename WellInterface<TypeTag>::Scalar;
|
2017-07-21 07:21:17 -05:00
|
|
|
using typename WellInterface<TypeTag>::VectorBlockType;
|
|
|
|
using typename WellInterface<TypeTag>::MatrixBlockType;
|
|
|
|
using typename WellInterface<TypeTag>::Mat;
|
|
|
|
using typename WellInterface<TypeTag>::BVector;
|
|
|
|
using typename WellInterface<TypeTag>::Eval;
|
2017-07-31 08:04:25 -05:00
|
|
|
using typename WellInterface<TypeTag>::PolymerModule;
|
2017-06-15 10:19:49 -05:00
|
|
|
|
2017-07-28 03:08:57 -05:00
|
|
|
using WellInterface<TypeTag>::numEq;
|
2017-07-26 07:17:16 -05:00
|
|
|
static const int numWellEq = GET_PROP_VALUE(TypeTag, EnablePolymer)? numEq-1 : numEq; // //numEq; //number of wellEq is only numEq for polymer
|
2017-07-28 06:49:26 -05:00
|
|
|
// TODO: should these go to WellInterface?
|
2017-06-27 08:16:22 -05:00
|
|
|
static const int contiSolventEqIdx = BlackoilIndices::contiSolventEqIdx;
|
|
|
|
static const int contiPolymerEqIdx = BlackoilIndices::contiPolymerEqIdx;
|
2017-07-26 07:17:16 -05:00
|
|
|
static const int solventSaturationIdx = BlackoilIndices::solventSaturationIdx;
|
|
|
|
static const int polymerConcentrationIdx = BlackoilIndices::polymerConcentrationIdx;
|
2017-06-27 08:16:22 -05:00
|
|
|
|
2017-06-15 10:19:49 -05:00
|
|
|
typedef DenseAd::Evaluation<double, /*size=*/numEq + numWellEq> EvalWell;
|
|
|
|
|
|
|
|
StandardWell(const Well* well, const int time_step, const Wells* wells);
|
2017-06-15 04:41:03 -05:00
|
|
|
|
|
|
|
/// the densities of the fluid in each perforation
|
|
|
|
virtual const std::vector<double>& perfDensities() const;
|
|
|
|
virtual std::vector<double>& perfDensities();
|
|
|
|
|
|
|
|
/// the pressure difference between different perforations
|
|
|
|
virtual const std::vector<double>& perfPressureDiffs() const;
|
|
|
|
virtual std::vector<double>& perfPressureDiffs();
|
|
|
|
|
|
|
|
virtual void setWellVariables(const WellState& well_state);
|
|
|
|
|
|
|
|
EvalWell wellVolumeFractionScaled(const int phase) const;
|
|
|
|
|
|
|
|
EvalWell wellVolumeFraction(const int phase) const;
|
|
|
|
|
|
|
|
EvalWell wellSurfaceVolumeFraction(const int phase) const;
|
|
|
|
|
2017-06-19 08:24:49 -05:00
|
|
|
EvalWell extendEval(const Eval& in) const;
|
|
|
|
|
2017-06-19 09:46:06 -05:00
|
|
|
// TODO: to check whether all the paramters are required
|
|
|
|
void 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,
|
2017-06-19 09:46:06 -05:00
|
|
|
const bool& allow_cf, std::vector<EvalWell>& cq_s) const;
|
|
|
|
|
2017-06-27 05:17:36 -05:00
|
|
|
virtual void assembleWellEq(Simulator& ebosSimulator,
|
|
|
|
const double dt,
|
|
|
|
WellState& well_state,
|
|
|
|
bool only_wells);
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-06-28 07:22:16 -05:00
|
|
|
virtual bool crossFlowAllowed(const Simulator& ebosSimulator) const;
|
2017-06-21 07:07:11 -05:00
|
|
|
|
|
|
|
void getMobility(const Simulator& ebosSimulator,
|
|
|
|
const int perf,
|
|
|
|
std::vector<EvalWell>& mob) const;
|
|
|
|
|
|
|
|
// TODO: the parameters need to be optimized/adjusted
|
2017-06-28 08:20:25 -05:00
|
|
|
virtual void init(const PhaseUsage* phase_usage_arg,
|
|
|
|
const std::vector<bool>* active_arg,
|
|
|
|
const VFPProperties* vfp_properties_arg,
|
2017-08-01 09:11:55 -05:00
|
|
|
const std::vector<double>& depth_arg,
|
2017-06-28 08:20:25 -05:00
|
|
|
const double gravity_arg,
|
|
|
|
const int num_cells);
|
2017-06-21 07:07:11 -05:00
|
|
|
|
2017-06-22 08:37:54 -05:00
|
|
|
// Update the well_state based on solution
|
|
|
|
void updateWellState(const BVector& dwells,
|
|
|
|
const BlackoilModelParameters& param,
|
|
|
|
WellState& well_state) const;
|
|
|
|
|
2017-06-23 03:58:46 -05:00
|
|
|
// TODO: later will check wheter we need current
|
2017-06-28 04:15:04 -05:00
|
|
|
virtual void updateWellStateWithTarget(const int current,
|
|
|
|
WellState& xw) const;
|
2017-06-23 03:58:46 -05:00
|
|
|
|
2017-06-23 04:42:59 -05:00
|
|
|
// TODO: this should go to the WellInterface, while updateWellStateWithTarget
|
|
|
|
// will need touch different types of well_state, we will see.
|
2017-06-28 04:15:04 -05:00
|
|
|
virtual void updateWellControl(WellState& xw) const;
|
2017-06-23 04:42:59 -05:00
|
|
|
|
2017-06-26 07:35:43 -05:00
|
|
|
virtual bool getWellConvergence(Simulator& ebosSimulator,
|
2017-06-26 09:01:45 -05:00
|
|
|
const std::vector<double>& B_avg,
|
2017-06-26 07:35:43 -05:00
|
|
|
const ModelParameters& param) const;
|
|
|
|
|
2017-06-29 06:52:31 -05:00
|
|
|
virtual void computeAccumWell();
|
|
|
|
|
|
|
|
virtual void computeWellConnectionPressures(const Simulator& ebosSimulator,
|
|
|
|
const WellState& xw);
|
|
|
|
|
2017-07-21 07:21:17 -05:00
|
|
|
// Ax = Ax - C D^-1 B x
|
|
|
|
virtual void apply(const BVector& x, BVector& Ax) const;
|
|
|
|
// r = r - C D^-1 Rw
|
|
|
|
virtual void apply(BVector& r) const;
|
|
|
|
|
2017-07-21 08:30:34 -05:00
|
|
|
// using the solution x to recover the solution xw for wells and applying
|
|
|
|
// xw to update Well State
|
|
|
|
virtual void applySolutionWellState(const BVector& x, const ModelParameters& param,
|
|
|
|
WellState& well_state) const;
|
|
|
|
|
2017-07-24 08:09:44 -05:00
|
|
|
virtual void computeWellPotentials(const Simulator& ebosSimulator,
|
|
|
|
const WellState& well_state,
|
|
|
|
std::vector<double>& well_potentials) const;
|
|
|
|
|
2017-07-28 07:41:00 -05:00
|
|
|
using WellInterface<TypeTag>::has_solvent;
|
|
|
|
using WellInterface<TypeTag>::has_polymer;
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
using WellInterface<TypeTag>::phaseUsage;
|
|
|
|
using WellInterface<TypeTag>::active;
|
|
|
|
using WellInterface<TypeTag>::numberOfPerforations;
|
2017-06-21 07:07:11 -05:00
|
|
|
using WellInterface<TypeTag>::wellCells;
|
|
|
|
using WellInterface<TypeTag>::saturationTableNumber;
|
2017-06-19 07:49:49 -05:00
|
|
|
using WellInterface<TypeTag>::indexOfWell;
|
|
|
|
using WellInterface<TypeTag>::name;
|
|
|
|
using WellInterface<TypeTag>::wellType;
|
|
|
|
using WellInterface<TypeTag>::wellControls;
|
|
|
|
using WellInterface<TypeTag>::compFrac;
|
|
|
|
using WellInterface<TypeTag>::numberOfPhases;
|
|
|
|
using WellInterface<TypeTag>::perfDepth;
|
2017-06-19 08:24:49 -05:00
|
|
|
using WellInterface<TypeTag>::flowToEbosPvIdx;
|
2017-06-20 03:54:33 -05:00
|
|
|
using WellInterface<TypeTag>::flowPhaseToEbosPhaseIdx;
|
2017-06-21 07:07:11 -05:00
|
|
|
using WellInterface<TypeTag>::flowPhaseToEbosCompIdx;
|
2017-06-19 09:46:06 -05:00
|
|
|
using WellInterface<TypeTag>::numComponents;
|
2017-06-20 03:54:33 -05:00
|
|
|
using WellInterface<TypeTag>::numPhases;
|
2017-06-21 07:07:11 -05:00
|
|
|
using WellInterface<TypeTag>::wellIndex;
|
2017-06-23 03:58:46 -05:00
|
|
|
using WellInterface<TypeTag>::wsolvent;
|
2017-07-28 07:41:00 -05:00
|
|
|
using WellInterface<TypeTag>::wpolymer;
|
2017-06-19 07:49:49 -05:00
|
|
|
|
2017-06-15 04:41:03 -05:00
|
|
|
protected:
|
2017-06-19 07:49:49 -05:00
|
|
|
|
2017-06-22 08:37:54 -05:00
|
|
|
// TODO: maybe this function can go to some helper file.
|
2017-06-21 07:07:11 -05:00
|
|
|
void localInvert(Mat& istlA) const;
|
|
|
|
|
2017-07-21 08:30:34 -05:00
|
|
|
// xw = inv(D)*(rw - C*x)
|
|
|
|
void recoverSolutionWell(const BVector& x, BVector& xw) const;
|
|
|
|
|
2017-06-23 03:58:46 -05:00
|
|
|
// TODO: decide wether to use member function to refer to private member later
|
2017-06-19 07:49:49 -05:00
|
|
|
using WellInterface<TypeTag>::vfp_properties_;
|
|
|
|
using WellInterface<TypeTag>::gravity_;
|
2017-06-21 07:07:11 -05:00
|
|
|
using WellInterface<TypeTag>::well_efficiency_factor_;
|
2017-06-23 03:58:46 -05:00
|
|
|
using WellInterface<TypeTag>::phase_usage_;
|
2017-06-23 07:55:56 -05:00
|
|
|
using WellInterface<TypeTag>::first_perf_;
|
2017-06-23 09:32:43 -05:00
|
|
|
using WellInterface<TypeTag>::ref_depth_;
|
|
|
|
using WellInterface<TypeTag>::perf_depth_;
|
2017-06-28 07:22:16 -05:00
|
|
|
using WellInterface<TypeTag>::allow_cf_;
|
2017-06-19 07:49:49 -05:00
|
|
|
|
2017-07-31 10:11:44 -05:00
|
|
|
using WellInterface<TypeTag>::perf_rep_radius_;
|
|
|
|
using WellInterface<TypeTag>::perf_length_;
|
|
|
|
using WellInterface<TypeTag>::bore_diameters_;
|
|
|
|
|
2017-06-15 04:41:03 -05:00
|
|
|
// densities of the fluid in each perforation
|
|
|
|
std::vector<double> perf_densities_;
|
|
|
|
// pressure drop between different perforations
|
|
|
|
std::vector<double> perf_pressure_diffs_;
|
|
|
|
|
|
|
|
// TODO: probably, they should be moved to the WellInterface, when
|
|
|
|
// we decide the template paramters.
|
|
|
|
// two off-diagonal matrices
|
2017-06-21 07:07:11 -05:00
|
|
|
Mat duneB_;
|
|
|
|
Mat duneC_;
|
2017-06-15 04:41:03 -05:00
|
|
|
// diagonal matrix for the well
|
2017-06-21 07:07:11 -05:00
|
|
|
Mat invDuneD_;
|
|
|
|
|
|
|
|
// several vector used in the matrix calculation
|
2017-07-21 04:59:28 -05:00
|
|
|
mutable BVector Bx_;
|
2017-06-21 07:07:11 -05:00
|
|
|
mutable BVector invDrw_;
|
|
|
|
mutable BVector scaleAddRes_;
|
2017-06-15 04:41:03 -05:00
|
|
|
|
2017-06-21 07:07:11 -05:00
|
|
|
BVector resWell_;
|
2017-06-15 04:41:03 -05:00
|
|
|
|
|
|
|
std::vector<EvalWell> well_variables_;
|
2017-06-21 07:07:11 -05:00
|
|
|
std::vector<double> F0_;
|
2017-06-15 04:41:03 -05:00
|
|
|
|
|
|
|
// TODO: this function should be moved to the base class.
|
|
|
|
// while it faces chanllenges for MSWell later, since the calculation of bhp
|
|
|
|
// based on THP is never implemented for MSWell yet.
|
|
|
|
EvalWell getBhp() const;
|
|
|
|
|
|
|
|
// TODO: it is also possible to be moved to the base class.
|
2017-07-28 06:49:26 -05:00
|
|
|
EvalWell getQs(const int comp_idx) const;
|
2017-06-23 07:55:56 -05:00
|
|
|
|
|
|
|
// calculate the properties for the well connections
|
|
|
|
// to calulate the pressure difference between well connections.
|
|
|
|
void computePropertiesForWellConnectionPressures(const Simulator& ebosSimulator,
|
|
|
|
const WellState& xw,
|
|
|
|
std::vector<double>& b_perf,
|
|
|
|
std::vector<double>& rsmax_perf,
|
|
|
|
std::vector<double>& rvmax_perf,
|
|
|
|
std::vector<double>& surf_dens_perf) const;
|
2017-06-23 08:54:05 -05:00
|
|
|
|
|
|
|
// TODO: not total sure whether it is a good idea to put here
|
|
|
|
// the major reason to put here is to avoid the usage of Wells struct
|
|
|
|
void 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);
|
2017-06-23 09:32:43 -05:00
|
|
|
|
|
|
|
void computeConnectionPressureDelta();
|
2017-06-23 09:45:14 -05:00
|
|
|
|
|
|
|
void computeWellConnectionDensitesPressures(const WellState& xw,
|
|
|
|
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);
|
2017-06-26 09:01:45 -05:00
|
|
|
|
|
|
|
virtual void wellEqIteration(Simulator& ebosSimulator,
|
|
|
|
const ModelParameters& param,
|
|
|
|
WellState& well_state);
|
2017-07-24 04:31:57 -05:00
|
|
|
|
2017-07-24 07:48:57 -05:00
|
|
|
using WellInterface<TypeTag>::wellHasTHPConstraints;
|
|
|
|
using WellInterface<TypeTag>::mostStrictBhpFromBhpLimits;
|
|
|
|
|
2017-07-24 04:31:57 -05:00
|
|
|
// TODO: maybe we should provide a light version of computeWellFlux, which does not include the
|
|
|
|
// calculation of the derivatives
|
|
|
|
void computeWellRatesWithBhp(const Simulator& ebosSimulator,
|
|
|
|
const EvalWell& bhp,
|
|
|
|
std::vector<double>& well_flux) const;
|
2017-07-24 07:48:57 -05:00
|
|
|
|
|
|
|
std::vector<double> computeWellPotentialWithTHP(const Simulator& ebosSimulator,
|
|
|
|
const double initial_bhp, // bhp from BHP constraints
|
|
|
|
const std::vector<double>& initial_potential) const;
|
2017-06-15 04:41:03 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-06-19 07:49:49 -05:00
|
|
|
#include "StandardWell_impl.hpp"
|
|
|
|
|
2017-06-15 04:41:03 -05:00
|
|
|
#endif // OPM_STANDARDWELL_HEADER_INCLUDED
|