My Project
Loading...
Searching...
No Matches
StandardWell.hpp
1/*
2 Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2017 Statoil ASA.
4 Copyright 2016 - 2017 IRIS AS.
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22
23#ifndef OPM_STANDARDWELL_HEADER_INCLUDED
24#define OPM_STANDARDWELL_HEADER_INCLUDED
25
26#include <opm/simulators/timestepping/ConvergenceReport.hpp>
28#include <opm/simulators/wells/VFPInjProperties.hpp>
29#include <opm/simulators/wells/VFPProdProperties.hpp>
30#include <opm/simulators/wells/WellInterface.hpp>
31#include <opm/simulators/wells/WellProdIndexCalculator.hpp>
32#include <opm/simulators/wells/ParallelWellInfo.hpp>
33
34#include <opm/models/blackoil/blackoilpolymermodules.hh>
35#include <opm/models/blackoil/blackoilsolventmodules.hh>
36#include <opm/models/blackoil/blackoilextbomodules.hh>
37#include <opm/models/blackoil/blackoilfoammodules.hh>
38#include <opm/models/blackoil/blackoilbrinemodules.hh>
39#include <opm/models/blackoil/blackoilmicpmodules.hh>
40
41#include <opm/material/densead/Evaluation.hpp>
42#include <opm/input/eclipse/Schedule/ScheduleTypes.hpp>
43
44#include <opm/simulators/wells/StandardWellEval.hpp>
45
46#include <dune/common/dynvector.hh>
47#include <dune/common/dynmatrix.hh>
48
49#include <memory>
50#include <optional>
51
52namespace Opm
53{
54
55 template<typename TypeTag>
56 class StandardWell : public WellInterface<TypeTag>
57 , public StandardWellEval<GetPropType<TypeTag, Properties::FluidSystem>,
58 GetPropType<TypeTag, Properties::Indices>,
59 GetPropType<TypeTag, Properties::Scalar>>
60 {
61
62 public:
67
68 // TODO: some functions working with AD variables handles only with values (double) without
69 // dealing with derivatives. It can be beneficial to make functions can work with either AD or scalar value.
70 // And also, it can also be beneficial to make these functions hanle different types of AD variables.
77 using typename Base::RateConverterType;
79 using typename Base::FluidState;
81
82 using Base::has_solvent;
83 using Base::has_zFraction;
84 using Base::has_polymer;
85 using Base::has_polymermw;
86 using Base::has_foam;
87 using Base::has_brine;
88 using Base::has_energy;
89 using Base::has_micp;
90
94 using typename Base::PressureMatrix;
95
96 // number of the conservation equations
97 static constexpr int numWellConservationEq = Indices::numPhases + Indices::numSolvents;
98 // number of the well control equations
99 static constexpr int numWellControlEq = 1;
100 // number of the well equations that will always be used
101 // based on the solution strategy, there might be other well equations be introduced
102 static constexpr int numStaticWellEq = numWellConservationEq + numWellControlEq;
103
104 // the index for Bhp in primary variables and also the index of well control equation
105 // they both will be the last one in their respective system.
106 // TODO: we should have indices for the well equations and well primary variables separately
107 static constexpr int Bhp = numStaticWellEq - numWellControlEq;
108
109 using StdWellEval::WQTotal;
110
112
113
114 using Base::name;
115 using Base::Water;
116 using Base::Oil;
117 using Base::Gas;
118
119 using typename Base::BVector;
120
121 using Eval = typename StdWellEval::Eval;
122 using EvalWell = typename StdWellEval::EvalWell;
123 using BVectorWell = typename StdWellEval::BVectorWell;
124
125 StandardWell(const Well& well,
127 const int time_step,
128 const ModelParameters& param,
129 const RateConverterType& rate_converter,
130 const int pvtRegionIdx,
131 const int num_components,
132 const int num_phases,
133 const int index_of_well,
134 const std::vector<PerforationData>& perf_data);
135
136 virtual void init(const PhaseUsage* phase_usage_arg,
137 const std::vector<double>& depth_arg,
138 const double gravity_arg,
139 const int num_cells,
140 const std::vector< Scalar >& B_avg,
141 const bool changed_to_open_this_step) override;
142
143
144 void initPrimaryVariablesEvaluation() override;
145
148 const WellState& well_state,
149 const std::vector<double>& B_avg,
151 const bool relax_tolerance) const override;
152
154 virtual void apply(const BVector& x, BVector& Ax) const override;
156 virtual void apply(BVector& r) const override;
157
161 const BVector& x,
162 WellState& well_state,
164
166 virtual void computeWellPotentials(const Simulator& ebosSimulator,
167 const WellState& well_state,
168 std::vector<double>& well_potentials,
169 DeferredLogger& deferred_logger) /* const */ override;
170
171 void updatePrimaryVariables(const SummaryState& summary_state,
172 const WellState& well_state,
174
175 virtual void solveEqAndUpdateWellState(const SummaryState& summary_state,
176 WellState& well_state,
178
179 virtual void calculateExplicitQuantities(const Simulator& ebosSimulator,
180 const WellState& well_state,
181 DeferredLogger& deferred_logger) override; // should be const?
182
183 virtual void updateProductivityIndex(const Simulator& ebosSimulator,
185 WellState& well_state,
186 DeferredLogger& deferred_logger) const override;
187
188 virtual double connectionDensity(const int globalConnIdx,
189 const int openConnIdx) const override;
190
191 virtual void addWellContributions(SparseMatrixAdapter& mat) const override;
192
193 virtual void addWellPressureEquations(PressureMatrix& mat,
194 const BVector& x,
195 const int pressureVarIndex,
196 const bool use_well_weights,
197 const WellState& well_state) const override;
198
199 // iterate well equations with the specified control until converged
200 bool iterateWellEqWithControl(const Simulator& ebosSimulator,
201 const double dt,
202 const Well::InjectionControls& inj_controls,
203 const Well::ProductionControls& prod_controls,
204 WellState& well_state,
205 const GroupState& group_state,
207
208 // iterate well equations including control switching
209 bool iterateWellEqWithSwitching(const Simulator& ebosSimulator,
210 const double dt,
211 const Well::InjectionControls& inj_controls,
212 const Well::ProductionControls& prod_controls,
213 WellState& well_state,
214 const GroupState& group_state,
216
218 virtual bool jacobianContainsWellContributions() const override
219 {
220 return this->param_.matrix_add_well_contributions_;
221 }
222
223 /* returns BHP */
224 double computeWellRatesAndBhpWithThpAlqProd(const Simulator &ebos_simulator,
227 std::vector<double> &potentials,
228 double alq) const;
229
230 void computeWellRatesWithThpAlqProd(
231 const Simulator &ebos_simulator,
234 std::vector<double> &potentials,
235 double alq) const;
236
237 std::optional<double> computeBhpAtThpLimitProdWithAlq(
238 const Simulator& ebos_simulator,
240 const double alq_value,
241 DeferredLogger& deferred_logger) const override;
242
243 virtual void computeWellRatesWithBhp(
244 const Simulator& ebosSimulator,
245 const double& bhp,
246 std::vector<double>& well_flux,
247 DeferredLogger& deferred_logger) const override;
248
249 // NOTE: These cannot be protected since they are used by GasLiftRuntime
250 using Base::phaseUsage;
251 using Base::vfp_properties_;
252
253 virtual std::vector<double> computeCurrentWellRates(const Simulator& ebosSimulator,
254 DeferredLogger& deferred_logger) const override;
255
256 std::vector<double> getPrimaryVars() const override;
257
258 int setPrimaryVars(std::vector<double>::const_iterator it) override;
259
260 protected:
261 bool regularize_;
262
263 // updating the well_state based on well solution dwells
264 void updateWellState(const SummaryState& summary_state,
265 const BVectorWell& dwells,
266 WellState& well_state,
268
269 // calculate the properties for the well connections
270 // to calulate the pressure difference between well connections.
271 using WellConnectionProps = typename StdWellEval::StdWellConnections::Properties;
272 void computePropertiesForWellConnectionPressures(const Simulator& ebosSimulator,
273 const WellState& well_state,
274 WellConnectionProps& props) const;
275
276 void computeWellConnectionDensitesPressures(const Simulator& ebosSimulator,
277 const WellState& well_state,
278 const WellConnectionProps& props,
280
281 void computeWellConnectionPressures(const Simulator& ebosSimulator,
282 const WellState& well_state,
284
285 template<class Value>
286 void computePerfRate(const IntensiveQuantities& intQuants,
287 const std::vector<Value>& mob,
288 const Value& bhp,
289 const double Tw,
290 const int perf,
291 const bool allow_cf,
292 std::vector<Value>& cq_s,
295
296 template<class Value>
297 void computePerfRate(const std::vector<Value>& mob,
298 const Value& pressure,
299 const Value& bhp,
300 const Value& rs,
301 const Value& rv,
302 const Value& rvw,
303 const Value& rsw,
304 std::vector<Value>& b_perfcells_dense,
305 const double Tw,
306 const int perf,
307 const bool allow_cf,
308 const Value& skin_pressure,
309 const std::vector<Value>& cmix_s,
310 std::vector<Value>& cq_s,
313
314 void computeWellRatesWithBhpIterations(const Simulator& ebosSimulator,
315 const double& bhp,
316 std::vector<double>& well_flux,
317 DeferredLogger& deferred_logger) const override;
318
319 std::vector<double> computeWellPotentialWithTHP(
320 const Simulator& ebosSimulator,
322 const WellState &well_state) const;
323
324 virtual double getRefDensity() const override;
325
326 // get the mobility for specific perforation
327 template<class Value>
328 void getMobility(const Simulator& ebosSimulator,
329 const int perf,
330 std::vector<Value>& mob,
332
333 void updateWaterMobilityWithPolymer(const Simulator& ebos_simulator,
334 const int perf,
335 std::vector<EvalWell>& mob_water,
337
338 void updatePrimaryVariablesNewton(const BVectorWell& dwells,
339 const bool stop_or_zero_rate_target,
341
342 void updateWellStateFromPrimaryVariables(const bool stop_or_zero_rate_target,
343 WellState& well_state,
346
347 virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
348 const double dt,
349 const Well::InjectionControls& inj_controls,
350 const Well::ProductionControls& prod_controls,
351 WellState& well_state,
352 const GroupState& group_state,
354
355 void assembleWellEqWithoutIterationImpl(const Simulator& ebosSimulator,
356 const double dt,
357 const Well::InjectionControls& inj_controls,
358 const Well::ProductionControls& prod_controls,
359 WellState& well_state,
360 const GroupState& group_state,
362
363 void calculateSinglePerf(const Simulator& ebosSimulator,
364 const int perf,
365 WellState& well_state,
366 std::vector<RateVector>& connectionRates,
367 std::vector<EvalWell>& cq_s,
368 EvalWell& water_flux_s,
369 EvalWell& cq_s_zfrac_effective,
371
372 // check whether the well is operable under BHP limit with current reservoir condition
373 virtual void checkOperabilityUnderBHPLimit(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) override;
374
375 // check whether the well is operable under THP limit with current reservoir condition
376 virtual void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) override;
377
378 // updating the inflow based on the current reservoir condition
379 virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const override;
380
381 // for a well, when all drawdown are in the wrong direction, then this well will not
382 // be able to produce/inject .
383 bool allDrawDownWrongDirection(const Simulator& ebos_simulator) const;
384
385 // whether the well can produce / inject based on the current well state (bhp)
386 bool canProduceInjectWithCurrentBhp(const Simulator& ebos_simulator,
387 const WellState& well_state,
389
390 // turn on crossflow to avoid singular well equations
391 // when the well is banned from cross-flow and the BHP is not properly initialized,
392 // we turn on crossflow to avoid singular well equations. It can result in wrong-signed
393 // well rates, it can cause problem for THP calculation
394 // TODO: looking for better alternative to avoid wrong-signed well rates
395 bool openCrossFlowAvoidSingularity(const Simulator& ebos_simulator) const;
396
397 // calculate the skin pressure based on water velocity, throughput and polymer concentration.
398 // throughput is used to describe the formation damage during water/polymer injection.
399 // calculated skin pressure will be applied to the drawdown during perforation rate calculation
400 // to handle the effect from formation damage.
401 EvalWell pskin(const double throuhgput,
402 const EvalWell& water_velocity,
403 const EvalWell& poly_inj_conc,
405
406 // calculate the skin pressure based on water velocity, throughput during water injection.
407 EvalWell pskinwater(const double throughput,
408 const EvalWell& water_velocity,
410
411 // calculate the injecting polymer molecular weight based on the througput and water velocity
412 EvalWell wpolymermw(const double throughput,
413 const EvalWell& water_velocity,
415
416 // modify the water rate for polymer injectivity study
417 void handleInjectivityRate(const Simulator& ebosSimulator,
418 const int perf,
419 std::vector<EvalWell>& cq_s) const;
420
421 // handle the extra equations for polymer injectivity study
422 void handleInjectivityEquations(const Simulator& ebosSimulator,
423 const WellState& well_state,
424 const int perf,
425 const EvalWell& water_flux_s,
427
428 virtual void updateWaterThroughput(const double dt, WellState& well_state) const override;
429
430 // checking convergence of extra equations, if there are any
431 void checkConvergenceExtraEqs(const std::vector<double>& res,
432 ConvergenceReport& report) const;
433
434 // updating the connectionRates_ related polymer molecular weight
435 void updateConnectionRatePolyMW(const EvalWell& cq_s_poly,
436 const IntensiveQuantities& int_quants,
437 const WellState& well_state,
438 const int perf,
439 std::vector<RateVector>& connectionRates,
441
442
443 std::optional<double> computeBhpAtThpLimitProd(const WellState& well_state,
444 const Simulator& ebos_simulator,
447
448 std::optional<double> computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
451
452 private:
453 Eval connectionRateEnergy(const double maxOilSaturation,
454 const std::vector<EvalWell>& cq_s,
455 const IntensiveQuantities& intQuants,
457
458 template<class Value>
459 void gasOilPerfRateInj(const std::vector<Value>& cq_s,
461 const Value& rv,
462 const Value& rs,
463 const Value& pressure,
464 const Value& rvw,
466
467 template<class Value>
468 void gasOilPerfRateProd(std::vector<Value>& cq_s,
470 const Value& rv,
471 const Value& rs,
472 const Value& rvw) const;
473
474 template<class Value>
475 void gasWaterPerfRateProd(std::vector<Value>& cq_s,
477 const Value& rvw,
478 const Value& rsw) const;
479
480 template<class Value>
481 void gasWaterPerfRateInj(const std::vector<Value>& cq_s,
483 const Value& rvw,
484 const Value& rsw,
485 const Value& pressure,
487
488 template<class Value>
489 void disOilVapWatVolumeRatio(Value& volumeRatio,
490 const Value& rvw,
491 const Value& rsw,
492 const Value& pressure,
493 const std::vector<Value>& cmix_s,
494 const std::vector<Value>& b_perfcells_dense,
496
497 template<class Value>
498 void gasOilVolumeRatio(Value& volumeRatio,
499 const Value& rv,
500 const Value& rs,
501 const Value& pressure,
502 const std::vector<Value>& cmix_s,
503 const std::vector<Value>& b_perfcells_dense,
505 };
506
507}
508
509#include "StandardWell_impl.hpp"
510
511#endif // OPM_STANDARDWELL_HEADER_INCLUDED
Facility for converting component rates at surface conditions to phase (voidage) rates at reservoir c...
Definition AquiferInterface.hpp:35
Represents the convergence status of the whole simulator, to make it possible to query and store the ...
Definition ConvergenceReport.hpp:38
Definition DeferredLogger.hpp:57
Definition GroupState.hpp:34
Class encapsulating some information about parallel wells.
Definition ParallelWellInfo.hpp:184
Definition StandardWellEval.hpp:49
Definition StandardWell.hpp:60
virtual bool jacobianContainsWellContributions() const override
Wether the Jacobian will also have well contributions in it.
Definition StandardWell.hpp:218
void recoverWellSolutionAndUpdateWellState(const SummaryState &summary_state, const BVector &x, WellState &well_state, DeferredLogger &deferred_logger) override
using the solution x to recover the solution xw for wells and applying xw to update Well State
Definition StandardWell_impl.hpp:1327
virtual std::vector< double > computeCurrentWellRates(const Simulator &ebosSimulator, DeferredLogger &deferred_logger) const override
Compute well rates based on current reservoir conditions and well variables.
Definition StandardWell_impl.hpp:2258
virtual ConvergenceReport getWellConvergence(const SummaryState &summary_state, const WellState &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 StandardWell_impl.hpp:1082
virtual void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition StandardWell_impl.hpp:1295
virtual void computeWellPotentials(const Simulator &ebosSimulator, const WellState &well_state, std::vector< double > &well_potentials, DeferredLogger &deferred_logger) override
computing the well potentials for group control
Definition StandardWell_impl.hpp:1536
const std::string & name() const
Well name.
Definition WellInterfaceGeneric.cpp:147
Definition WellInterface.hpp:74
Collect per-connection static information to enable calculating connection-level or well-level produc...
Definition WellProdIndexCalculator.hpp:36
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:60
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27
Solver parameters for the BlackoilModel.
Definition BlackoilModelParametersEbos.hpp:451
Definition PerforationData.hpp:39
Definition BlackoilPhases.hpp:46