My Project
Loading...
Searching...
No Matches
MultisegmentWell.hpp
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
25#include <opm/simulators/wells/WellInterface.hpp>
26#include <opm/simulators/wells/MultisegmentWellEval.hpp>
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 GetPropType<TypeTag, Properties::Scalar>>
37 {
38 public:
43
50 using typename Base::RateConverterType;
52 using typename Base::FluidState;
53
54 using Base::has_solvent;
55 using Base::has_polymer;
56 using Base::Water;
57 using Base::Oil;
58 using Base::Gas;
59
61
63 using typename Base::BVector;
64 using typename Base::Eval;
65
67 using typename MSWEval::EvalWell;
68 using typename MSWEval::BVectorWell;
69 using MSWEval::SPres;
70 using typename Base::PressureMatrix;
71
72 MultisegmentWell(const Well& well,
74 const int time_step,
75 const ModelParameters& param,
76 const RateConverterType& rate_converter,
77 const int pvtRegionIdx,
78 const int num_components,
79 const int num_phases,
80 const int index_of_well,
81 const std::vector<PerforationData>& perf_data);
82
83 virtual void init(const PhaseUsage* phase_usage_arg,
84 const std::vector<double>& depth_arg,
85 const double gravity_arg,
86 const int num_cells,
87 const std::vector< Scalar >& B_avg,
88 const bool changed_to_open_this_step) override;
89
90 void initPrimaryVariablesEvaluation() override;
91
93 virtual void updateWellStateWithTarget(const Simulator& ebos_simulator,
94 const GroupState& group_state,
95 WellState& well_state,
96 DeferredLogger& deferred_logger) const override;
97
100 const WellState& well_state,
101 const std::vector<double>& B_avg,
103 const bool relax_tolerance) const override;
104
106 virtual void apply(const BVector& x, BVector& Ax) const override;
108 virtual void apply(BVector& r) const override;
109
113 const BVector& x,
114 WellState& well_state,
116
118 virtual void computeWellPotentials(const Simulator& ebosSimulator,
119 const WellState& well_state,
120 std::vector<double>& well_potentials,
122
123 void updatePrimaryVariables(const SummaryState& summary_state,
124 const WellState& well_state,
126
127 virtual void solveEqAndUpdateWellState(const SummaryState& summary_state,
128 WellState& well_state,
129 DeferredLogger& deferred_logger) override; // const?
130
131 virtual void calculateExplicitQuantities(const Simulator& ebosSimulator,
132 const WellState& well_state,
133 DeferredLogger& deferred_logger) override; // should be const?
134
135 virtual void updateProductivityIndex(const Simulator& ebosSimulator,
137 WellState& well_state,
138 DeferredLogger& deferred_logger) const override;
139
140 double connectionDensity(const int globalConnIdx,
141 const int openConnIdx) const override;
142
143 void addWellContributions(SparseMatrixAdapter& jacobian) const override;
144
145 void addWellPressureEquations(PressureMatrix& mat,
146 const BVector& x,
147 const int pressureVarIndex,
148 const bool use_well_weights,
149 const WellState& well_state) const override;
150
151 virtual std::vector<double> computeCurrentWellRates(const Simulator& ebosSimulator,
152 DeferredLogger& deferred_logger) const override;
153
154 std::optional<double>
155 computeBhpAtThpLimitProdWithAlq(const Simulator& ebos_simulator,
157 const double alq_value,
158 DeferredLogger& deferred_logger) const override;
159
160 std::vector<double> getPrimaryVars() const override;
161
162 int setPrimaryVars(std::vector<double>::const_iterator it) override;
163
164 protected:
165
166 // regularize msw equation
167 bool regularize_;
168
169 // the intial amount of fluids in each segment under surface condition
170 std::vector<std::vector<double> > segment_fluid_initial_;
171
172 mutable int debug_cost_counter_ = 0;
173
174 // updating the well_state based on well solution dwells
175 void updateWellState(const SummaryState& summary_state,
176 const BVectorWell& dwells,
177 WellState& well_state,
179 const double relaxation_factor = 1.0);
180
181
182 // computing the accumulation term for later use in well mass equations
183 void computeInitialSegmentFluids(const Simulator& ebos_simulator);
184
185 // compute the pressure difference between the perforation and cell center
186 void computePerfCellPressDiffs(const Simulator& ebosSimulator);
187
188 template<class Value>
189 void computePerfRate(const IntensiveQuantities& int_quants,
190 const std::vector<Value>& mob_perfcells,
191 const double Tw,
192 const int seg,
193 const int perf,
194 const Value& segment_pressure,
195 const bool& allow_cf,
196 std::vector<Value>& cq_s,
197 Value& perf_press,
200
201 template<class Value>
202 void computePerfRate(const Value& pressure_cell,
203 const Value& rs,
204 const Value& rv,
205 const std::vector<Value>& b_perfcells,
206 const std::vector<Value>& mob_perfcells,
207 const double Tw,
208 const int perf,
209 const Value& segment_pressure,
210 const Value& segment_density,
211 const bool& allow_cf,
212 const std::vector<Value>& cmix_s,
213 std::vector<Value>& cq_s,
214 Value& perf_press,
217
218 // compute the fluid properties, such as densities, viscosities, and so on, in the segments
219 // They will be treated implicitly, so they need to be of Evaluation type
220 void computeSegmentFluidProperties(const Simulator& ebosSimulator,
222
223 // get the mobility for specific perforation
224 template<class Value>
225 void getMobility(const Simulator& ebosSimulator,
226 const int perf,
227 std::vector<Value>& mob,
229
230 void computeWellRatesAtBhpLimit(const Simulator& ebosSimulator,
231 std::vector<double>& well_flux,
233
234 void computeWellRatesWithBhp(const Simulator& ebosSimulator,
235 const double& bhp,
236 std::vector<double>& well_flux,
237 DeferredLogger& deferred_logger) const override;
238
239 void computeWellRatesWithBhpIterations(const Simulator& ebosSimulator,
240 const Scalar& bhp,
241 std::vector<double>& well_flux,
242 DeferredLogger& deferred_logger) const override;
243
244 std::vector<double> computeWellPotentialWithTHP(
245 const WellState& well_state,
246 const Simulator& ebos_simulator,
248
249 virtual double getRefDensity() const override;
250
251 virtual bool iterateWellEqWithControl(const Simulator& ebosSimulator,
252 const double dt,
253 const Well::InjectionControls& inj_controls,
254 const Well::ProductionControls& prod_controls,
255 WellState& well_state,
256 const GroupState& group_state,
258
259 virtual bool iterateWellEqWithSwitching(const Simulator& ebosSimulator,
260 const double dt,
261 const Well::InjectionControls& inj_controls,
262 const Well::ProductionControls& prod_controls,
263 WellState& well_state,
264 const GroupState& group_state,
266
267 virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
268 const double dt,
269 const Well::InjectionControls& inj_controls,
270 const Well::ProductionControls& prod_controls,
271 WellState& well_state,
272 const GroupState& group_state,
274
275 virtual void updateWaterThroughput(const double dt, WellState& well_state) const override;
276
277 EvalWell getSegmentSurfaceVolume(const Simulator& ebos_simulator, const int seg_idx) const;
278
279 // turn on crossflow to avoid singular well equations
280 // when the well is banned from cross-flow and the BHP is not properly initialized,
281 // we turn on crossflow to avoid singular well equations. It can result in wrong-signed
282 // well rates, it can cause problem for THP calculation
283 // TODO: looking for better alternative to avoid wrong-signed well rates
284 bool openCrossFlowAvoidSingularity(const Simulator& ebos_simulator) const;
285
286 // for a well, when all drawdown are in the wrong direction, then this well will not
287 // be able to produce/inject .
288 bool allDrawDownWrongDirection(const Simulator& ebos_simulator) const;
289
290
291
292 std::optional<double> computeBhpAtThpLimitProd(
293 const WellState& well_state,
294 const Simulator& ebos_simulator,
297
298 std::optional<double> computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
301
302 double maxPerfPress(const Simulator& ebos_simulator) const;
303
304 // check whether the well is operable under BHP limit with current reservoir condition
305 virtual void checkOperabilityUnderBHPLimit(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) override;
306
307 // check whether the well is operable under THP limit with current reservoir condition
308 virtual void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) override;
309
310 // updating the inflow based on the current reservoir condition
311 virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const override;
312 };
313
314}
315
316#include "MultisegmentWell_impl.hpp"
317
318#endif // OPM_MULTISEGMENTWELL_HEADER_INCLUDED
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
Definition MultisegmentWellEval.hpp:49
Definition MultisegmentWell.hpp:37
virtual void updateWellStateWithTarget(const Simulator &ebos_simulator, const GroupState &group_state, WellState &well_state, DeferredLogger &deferred_logger) const override
updating the well state based the current control mode
Definition MultisegmentWell_impl.hpp:174
virtual void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition MultisegmentWell_impl.hpp:220
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 MultisegmentWell_impl.hpp:1979
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 MultisegmentWell_impl.hpp:255
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 MultisegmentWell_impl.hpp:195
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 MultisegmentWell_impl.hpp:276
Class encapsulating some information about parallel wells.
Definition ParallelWellInfo.hpp:184
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