MultisegmentWell.hpp
Go to the documentation of this file.
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4
5 This file is part of the Open Porous Media project (OPM).
6
7 OPM is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 OPM is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with OPM. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22#ifndef OPM_MULTISEGMENTWELL_HEADER_INCLUDED
23#define OPM_MULTISEGMENTWELL_HEADER_INCLUDED
24
27
28namespace Opm
29{
30 class DeferredLogger;
31
32 template<typename TypeTag>
33 class MultisegmentWell : public WellInterface<TypeTag>
34 , public MultisegmentWellEval<GetPropType<TypeTag, Properties::FluidSystem>,
35 GetPropType<TypeTag, Properties::Indices>>
36 {
37 public:
40 GetPropType<TypeTag, Properties::Indices>>;
41
42 using typename Base::Simulator;
43 using typename Base::IntensiveQuantities;
44 using typename Base::FluidSystem;
45 using typename Base::ModelParameters;
46 using typename Base::MaterialLaw;
47 using typename Base::Indices;
48 using typename Base::RateConverterType;
49 using typename Base::SparseMatrixAdapter;
50 using typename Base::FluidState;
51
54 using Base::Water;
55 using Base::Oil;
56 using Base::Gas;
57
58 using typename Base::Scalar;
59
61 using typename Base::BVector;
62 using typename Base::Eval;
63
64 using typename MSWEval::Equations;
65 using typename MSWEval::EvalWell;
66 using typename MSWEval::BVectorWell;
67 using MSWEval::SPres;
68 using typename Base::PressureMatrix;
69
70 MultisegmentWell(const Well& well,
71 const ParallelWellInfo& pw_info,
72 const int time_step,
73 const ModelParameters& param,
74 const RateConverterType& rate_converter,
75 const int pvtRegionIdx,
76 const int num_components,
77 const int num_phases,
78 const int index_of_well,
79 const std::vector<PerforationData>& perf_data);
80
81 void init(const PhaseUsage* phase_usage_arg,
82 const std::vector<double>& depth_arg,
83 const double gravity_arg,
84 const int num_cells,
85 const std::vector<Scalar>& B_avg,
86 const bool changed_to_open_this_step) override;
87
88 void initPrimaryVariablesEvaluation() override;
89
91 void updateWellStateWithTarget(const Simulator& simulator,
92 const GroupState<Scalar>& group_state,
93 WellState<Scalar>& well_state,
94 DeferredLogger& deferred_logger) const override;
95
97 ConvergenceReport getWellConvergence(const SummaryState& summary_state,
98 const WellState<Scalar>& well_state,
99 const std::vector<double>& B_avg,
100 DeferredLogger& deferred_logger,
101 const bool relax_tolerance) const override;
102
104 void apply(const BVector& x, BVector& Ax) const override;
106 void apply(BVector& r) const override;
107
110 void recoverWellSolutionAndUpdateWellState(const SummaryState& summary_state,
111 const BVector& x,
112 WellState<Scalar>& well_state,
113 DeferredLogger& deferred_logger) override;
114
116 void computeWellPotentials(const Simulator& simulator,
117 const WellState<Scalar>& well_state,
118 std::vector<double>& well_potentials,
119 DeferredLogger& deferred_logger) override;
120
121 void updatePrimaryVariables(const SummaryState& summary_state,
122 const WellState<Scalar>& well_state,
123 DeferredLogger& deferred_logger) override;
124
125 void solveEqAndUpdateWellState(const SummaryState& summary_state,
126 WellState<Scalar>& well_state,
127 DeferredLogger& deferred_logger) override; // const?
128
129 void calculateExplicitQuantities(const Simulator& simulator,
130 const WellState<Scalar>& well_state,
131 DeferredLogger& deferred_logger) override; // should be const?
132
133 void updateIPRImplicit(const Simulator& simulator,
134 WellState<Scalar>& well_state,
135 DeferredLogger& deferred_logger) override;
136
137 void updateProductivityIndex(const Simulator& simulator,
138 const WellProdIndexCalculator& wellPICalc,
139 WellState<Scalar>& well_state,
140 DeferredLogger& deferred_logger) const override;
141
142 double connectionDensity(const int globalConnIdx,
143 const int openConnIdx) const override;
144
145 void addWellContributions(SparseMatrixAdapter& jacobian) const override;
146
148 const BVector& x,
149 const int pressureVarIndex,
150 const bool use_well_weights,
151 const WellState<Scalar>& well_state) const override;
152
153 std::vector<double> computeCurrentWellRates(const Simulator& simulator,
154 DeferredLogger& deferred_logger) const override;
155
156 std::optional<double>
158 const SummaryState& summary_state,
159 const double alq_value,
160 DeferredLogger& deferred_logger) const override;
161
162 std::vector<double> getPrimaryVars() const override;
163
164 int setPrimaryVars(std::vector<double>::const_iterator it) override;
165
166 protected:
167
168 // regularize msw equation
170
171 // the intial amount of fluids in each segment under surface condition
172 std::vector<std::vector<double> > segment_fluid_initial_;
173
174 mutable int debug_cost_counter_ = 0;
175
176 // updating the well_state based on well solution dwells
177 void updateWellState(const SummaryState& summary_state,
178 const BVectorWell& dwells,
179 WellState<Scalar>& well_state,
180 DeferredLogger& deferred_logger,
181 const double relaxation_factor = 1.0);
182
183
184 // computing the accumulation term for later use in well mass equations
185 void computeInitialSegmentFluids(const Simulator& simulator);
186
187 // compute the pressure difference between the perforation and cell center
188 void computePerfCellPressDiffs(const Simulator& simulator);
189
190 template<class Value>
191 void computePerfRate(const IntensiveQuantities& int_quants,
192 const std::vector<Value>& mob_perfcells,
193 const std::vector<Scalar>& Tw,
194 const int seg,
195 const int perf,
196 const Value& segment_pressure,
197 const bool& allow_cf,
198 std::vector<Value>& cq_s,
199 Value& perf_press,
200 PerforationRates& perf_rates,
201 DeferredLogger& deferred_logger) const;
202
203 template<class Value>
204 void computePerfRate(const Value& pressure_cell,
205 const Value& rs,
206 const Value& rv,
207 const std::vector<Value>& b_perfcells,
208 const std::vector<Value>& mob_perfcells,
209 const std::vector<Scalar>& Tw,
210 const int perf,
211 const Value& segment_pressure,
212 const Value& segment_density,
213 const bool& allow_cf,
214 const std::vector<Value>& cmix_s,
215 std::vector<Value>& cq_s,
216 Value& perf_press,
217 PerforationRates& perf_rates,
218 DeferredLogger& deferred_logger) const;
219
220 // compute the fluid properties, such as densities, viscosities, and so on, in the segments
221 // They will be treated implicitly, so they need to be of Evaluation type
222 void computeSegmentFluidProperties(const Simulator& simulator,
223 DeferredLogger& deferred_logger);
224
225 // get the mobility for specific perforation
226 template<class Value>
227 void getMobility(const Simulator& simulator,
228 const int perf,
229 std::vector<Value>& mob,
230 DeferredLogger& deferred_logger) const;
231
232 void computeWellRatesAtBhpLimit(const Simulator& simulator,
233 std::vector<double>& well_flux,
234 DeferredLogger& deferred_logger) const;
235
236 void computeWellRatesWithBhp(const Simulator& simulator,
237 const double& bhp,
238 std::vector<double>& well_flux,
239 DeferredLogger& deferred_logger) const override;
240
241 void computeWellRatesWithBhpIterations(const Simulator& simulator,
242 const Scalar& bhp,
243 std::vector<double>& well_flux,
244 DeferredLogger& deferred_logger) const override;
245
246 std::vector<double>
248 const Simulator& simulator,
249 DeferredLogger& deferred_logger) const;
250
251 bool computeWellPotentialsImplicit(const Simulator& simulator,
252 std::vector<double>& well_potentials,
253 DeferredLogger& deferred_logger) const;
254
255 virtual double getRefDensity() const override;
256
257 virtual bool iterateWellEqWithControl(const Simulator& simulator,
258 const double dt,
259 const Well::InjectionControls& inj_controls,
260 const Well::ProductionControls& prod_controls,
261 WellState<Scalar>& well_state,
262 const GroupState<Scalar>& group_state,
263 DeferredLogger& deferred_logger) override;
264
265 virtual bool iterateWellEqWithSwitching(const Simulator& simulator,
266 const double dt,
267 const Well::InjectionControls& inj_controls,
268 const Well::ProductionControls& prod_controls,
269 WellState<Scalar>& well_state,
270 const GroupState<Scalar>& group_state,
271 DeferredLogger& deferred_logger,
272 const bool fixed_control = false,
273 const bool fixed_status = false) override;
274
275 virtual void assembleWellEqWithoutIteration(const Simulator& simulator,
276 const double dt,
277 const Well::InjectionControls& inj_controls,
278 const Well::ProductionControls& prod_controls,
279 WellState<Scalar>& well_state,
280 const GroupState<Scalar>& group_state,
281 DeferredLogger& deferred_logger) override;
282
283 virtual void updateWaterThroughput(const double dt, WellState<Scalar>& well_state) const override;
284
285 EvalWell getSegmentSurfaceVolume(const Simulator& simulator, const int seg_idx) const;
286
287 // turn on crossflow to avoid singular well equations
288 // when the well is banned from cross-flow and the BHP is not properly initialized,
289 // we turn on crossflow to avoid singular well equations. It can result in wrong-signed
290 // well rates, it can cause problem for THP calculation
291 // TODO: looking for better alternative to avoid wrong-signed well rates
292 bool openCrossFlowAvoidSingularity(const Simulator& simulator) const;
293
294 // for a well, when all drawdown are in the wrong direction, then this well will not
295 // be able to produce/inject .
296 bool allDrawDownWrongDirection(const Simulator& simulator) const;
297
298
299
300 std::optional<double>
302 const Simulator& simulator,
303 const SummaryState& summary_state,
304 DeferredLogger& deferred_logger) const;
305
306 std::optional<double>
307 computeBhpAtThpLimitInj(const Simulator& simulator,
308 const SummaryState& summary_state,
309 DeferredLogger& deferred_logger) const;
310
311 double maxPerfPress(const Simulator& simulator) const;
312
313 // check whether the well is operable under BHP limit with current reservoir condition
315 const Simulator& ebos_simulator,
316 DeferredLogger& deferred_logger) override;
317
318 // check whether the well is operable under THP limit with current reservoir condition
319 void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator,
320 const WellState<Scalar>& well_state,
321 DeferredLogger& deferred_logger) override;
322
323 // updating the inflow based on the current reservoir condition
324 void updateIPR(const Simulator& ebos_simulator,
325 DeferredLogger& deferred_logger) const override;
326 };
327
328}
329
330#ifndef OPM_MULTISEGMENTWELL_IMPL_HEADER_INCLUDED
332#endif
333
334#endif // OPM_MULTISEGMENTWELL_HEADER_INCLUDED
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:35
Definition: MultisegmentWellEval.hpp:47
MultisegmentWellEquations< Scalar, numWellEq, Indices::numEq > Equations
Definition: MultisegmentWellEval.hpp:55
Definition: MultisegmentWell.hpp:36
double connectionDensity(const int globalConnIdx, const int openConnIdx) const override
Definition: MultisegmentWell_impl.hpp:808
ConvergenceReport getWellConvergence(const SummaryState &summary_state, const WellState< Scalar > &well_state, const std::vector< double > &B_avg, DeferredLogger &deferred_logger, const bool relax_tolerance) const override
check whether the well equations get converged for this well
Definition: MultisegmentWell_impl.hpp:202
int setPrimaryVars(std::vector< double >::const_iterator it) override
Definition: MultisegmentWell_impl.hpp:2226
std::vector< std::vector< double > > segment_fluid_initial_
Definition: MultisegmentWell.hpp:172
void solveEqAndUpdateWellState(const SummaryState &summary_state, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:580
void calculateExplicitQuantities(const Simulator &simulator, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:718
void addWellContributions(SparseMatrixAdapter &jacobian) const override
Definition: MultisegmentWell_impl.hpp:830
virtual bool iterateWellEqWithSwitching(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger, const bool fixed_control=false, const bool fixed_status=false) override
Definition: MultisegmentWell_impl.hpp:1592
void computeWellRatesWithBhpIterations(const Simulator &simulator, const Scalar &bhp, std::vector< double > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:390
bool computeWellPotentialsImplicit(const Simulator &simulator, std::vector< double > &well_potentials, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:511
void computePerfRate(const IntensiveQuantities &int_quants, const std::vector< Value > &mob_perfcells, const std::vector< Scalar > &Tw, const int seg, const int perf, const Value &segment_pressure, const bool &allow_cf, std::vector< Value > &cq_s, Value &perf_press, PerforationRates &perf_rates, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1000
std::optional< double > computeBhpAtThpLimitProdWithAlq(const Simulator &simulator, const SummaryState &summary_state, const double alq_value, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2045
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:228
void updateWellState(const SummaryState &summary_state, const BVectorWell &dwells, WellState< Scalar > &well_state, DeferredLogger &deferred_logger, const double relaxation_factor=1.0)
Definition: MultisegmentWell_impl.hpp:683
void init(const PhaseUsage *phase_usage_arg, const std::vector< double > &depth_arg, const double gravity_arg, const int num_cells, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: MultisegmentWell_impl.hpp:118
void getMobility(const Simulator &simulator, const int perf, std::vector< Value > &mob, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1111
void computeWellRatesAtBhpLimit(const Simulator &simulator, std::vector< double > &well_flux, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:329
virtual bool iterateWellEqWithControl(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1440
std::optional< double > computeBhpAtThpLimitInj(const Simulator &simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2096
void checkOperabilityUnderBHPLimit(const WellState< Scalar > &well_state, const Simulator &ebos_simulator, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1159
bool openCrossFlowAvoidSingularity(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1937
void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator &wellPICalc, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:736
void computeSegmentFluidProperties(const Simulator &simulator, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:1073
EvalWell getSegmentSurfaceVolume(const Simulator &simulator, const int seg_idx) const
Definition: MultisegmentWell_impl.hpp:2001
bool allDrawDownWrongDirection(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1946
void computeWellPotentials(const Simulator &simulator, const WellState< Scalar > &well_state, std::vector< double > &well_potentials, DeferredLogger &deferred_logger) override
computing the well potentials for group control
Definition: MultisegmentWell_impl.hpp:284
void updateWellStateWithTarget(const Simulator &simulator, const GroupState< Scalar > &group_state, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const override
updating the well state based the current control mode
Definition: MultisegmentWell_impl.hpp:181
int debug_cost_counter_
Definition: MultisegmentWell.hpp:174
void addWellPressureEquations(PressureMatrix &mat, const BVector &x, const int pressureVarIndex, const bool use_well_weights, const WellState< Scalar > &well_state) const override
Definition: MultisegmentWell_impl.hpp:839
std::vector< double > computeWellPotentialWithTHP(const WellState< Scalar > &well_state, const Simulator &simulator, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:462
virtual void assembleWellEqWithoutIteration(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1783
void updatePrimaryVariables(const SummaryState &summary_state, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:165
void checkOperabilityUnderTHPLimit(const Simulator &ebos_simulator, const WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1388
void computePerfCellPressDiffs(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:610
virtual double getRefDensity() const override
Definition: MultisegmentWell_impl.hpp:1151
std::vector< double > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2173
std::vector< double > getPrimaryVars() const override
Definition: MultisegmentWell_impl.hpp:2208
void updateIPR(const Simulator &ebos_simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:1225
virtual void updateWaterThroughput(const double dt, WellState< Scalar > &well_state) const override
Definition: MultisegmentWell_impl.hpp:1990
std::optional< double > computeBhpAtThpLimitProd(const WellState< Scalar > &well_state, const Simulator &simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2028
void initPrimaryVariablesEvaluation() override
Definition: MultisegmentWell_impl.hpp:153
bool regularize_
Definition: MultisegmentWell.hpp:169
void recoverWellSolutionAndUpdateWellState(const SummaryState &summary_state, const BVector &x, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:263
void updateIPRImplicit(const Simulator &simulator, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1319
double maxPerfPress(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2150
MultisegmentWell(const Well &well, const ParallelWellInfo &pw_info, const int time_step, const ModelParameters &param, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_components, const int num_phases, const int index_of_well, const std::vector< PerforationData > &perf_data)
Definition: MultisegmentWell_impl.hpp:59
void computeWellRatesWithBhp(const Simulator &simulator, const double &bhp, std::vector< double > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:345
void computeInitialSegmentFluids(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:665
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:184
static constexpr int Oil
Definition: WellInterfaceFluidSystem.hpp:58
static constexpr int Water
Definition: WellInterfaceFluidSystem.hpp:57
static constexpr int Gas
Definition: WellInterfaceFluidSystem.hpp:59
int pvtRegionIdx() const
Definition: WellInterfaceGeneric.hpp:126
Definition: WellInterface.hpp:75
Dune::BCRSMatrix< Opm::MatrixBlock< double, 1, 1 > > PressureMatrix
Definition: WellInterface.hpp:102
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:82
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:105
BlackOilFluidState< Eval, FluidSystem, has_temperature, has_energy, Indices::compositionSwitchIdx >=0, has_watVapor, has_brine, has_saltPrecip, has_disgas_in_water, Indices::numPhases > FluidState
Definition: WellInterface.hpp:135
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:85
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:96
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: WellInterface.hpp:86
Dune::BlockVector< VectorBlockType > BVector
Definition: WellInterface.hpp:101
static constexpr bool has_polymer
Definition: WellInterface.hpp:113
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:83
static constexpr bool has_solvent
Definition: WellInterface.hpp:111
BlackoilModelParameters< TypeTag > ModelParameters
Definition: WellInterface.hpp:79
typename Base::Eval Eval
Definition: WellInterface.hpp:100
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:84
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: WellInterface.hpp:87
Definition: WellProdIndexCalculator.hpp:36
Definition: WellState.hpp:62
VFPEvaluation bhp(const VFPProdTable &table, const double aqua, const double liquid, const double vapour, const double thp, const double alq, const double explicit_wfr, const double explicit_gfr, const bool use_vfpexplicit)
Definition: BlackoilPhases.hpp:27
Solver parameters for the BlackoilModel.
Definition: BlackoilModelParameters.hpp:484
Definition: PerforationData.hpp:40
Definition: BlackoilPhases.hpp:46