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
26
29
30namespace Opm {
31
32 class DeferredLogger;
33
34 template<typename TypeTag>
35 class MultisegmentWell : public WellInterface<TypeTag>
36 , public MultisegmentWellEval<GetPropType<TypeTag, Properties::FluidSystem>,
37 GetPropType<TypeTag, Properties::Indices>>
38 {
39 public:
43
44 using typename Base::Simulator;
45 using typename Base::IntensiveQuantities;
46 using typename Base::FluidSystem;
47 using typename Base::IndexTraits;
48 using typename Base::ModelParameters;
49 using typename Base::MaterialLaw;
50 using typename Base::Indices;
51 using typename Base::RateConverterType;
52 using typename Base::SparseMatrixAdapter;
53 using typename Base::FluidState;
54 using typename Base::WellStateType;
55
58 using Base::Water;
59 using Base::Oil;
60 using Base::Gas;
61
62 using typename Base::Scalar;
63
65 using typename Base::BVector;
66 using typename Base::Eval;
67
68 using typename MSWEval::Equations;
69 using typename MSWEval::EvalWell;
70 using typename MSWEval::BVectorWell;
71 using MSWEval::SPres;
72 using typename Base::PressureMatrix;
73 using FSInfo = std::tuple<Scalar,typename std::decay<decltype(std::declval<decltype(std::declval<const Simulator&>().model().intensiveQuantities(0, 0).fluidState())>().saltConcentration())>::type,int>;
74
75 MultisegmentWell(const Well& well,
76 const ParallelWellInfo<Scalar>& pw_info,
77 const int time_step,
78 const ModelParameters& param,
79 const RateConverterType& rate_converter,
80 const int pvtRegionIdx,
81 const int num_conservation_quantities,
82 const int num_phases,
83 const int index_of_well,
84 const std::vector<PerforationData<Scalar>>& perf_data);
85
86 void init(const std::vector<Scalar>& depth_arg,
87 const Scalar gravity_arg,
88 const std::vector<Scalar>& B_avg,
89 const bool changed_to_open_this_step) override;
90
92 void updateWellStateWithTarget(const Simulator& simulator,
93 const GroupState<Scalar>& group_state,
94 WellStateType& well_state,
95 DeferredLogger& deferred_logger) const override;
96
98 void scaleSegmentRatesAndPressure(WellStateType& well_state) const override;
99
102 const WellStateType& well_state,
103 const std::vector<Scalar>& B_avg,
104 DeferredLogger& deferred_logger,
105 const bool relax_tolerance) const override;
106
108 void apply(const BVector& x, BVector& Ax) const override;
110 void apply(BVector& r) const override;
111
115 const BVector& x,
116 WellStateType& well_state,
117 DeferredLogger& deferred_logger) override;
118
120 void computeWellPotentials(const Simulator& simulator,
121 const WellStateType& well_state,
122 std::vector<Scalar>& well_potentials,
123 DeferredLogger& deferred_logger) override;
124
125 void updatePrimaryVariables(const Simulator& simulator,
126 const WellStateType& well_state,
127 DeferredLogger& deferred_logger) override;
128
129 void solveEqAndUpdateWellState(const Simulator& simulator,
130 WellStateType& well_state,
131 DeferredLogger& deferred_logger) override; // const?
132
133 void calculateExplicitQuantities(const Simulator& simulator,
134 const WellStateType& well_state,
135 DeferredLogger& deferred_logger) override; // should be const?
136
137 void updateIPRImplicit(const Simulator& simulator,
138 WellStateType& well_state,
139 DeferredLogger& deferred_logger) override;
140
141 void updateProductivityIndex(const Simulator& simulator,
142 const WellProdIndexCalculator<Scalar>& wellPICalc,
143 WellStateType& well_state,
144 DeferredLogger& deferred_logger) const override;
145
146 Scalar connectionDensity(const int globalConnIdx,
147 const int openConnIdx) const override;
148
149 void addWellContributions(SparseMatrixAdapter& jacobian) const override;
150
152 const BVector& x,
153 const int pressureVarIndex,
154 const bool use_well_weights,
155 const WellStateType& well_state) const override;
156
157 std::vector<Scalar>
158 computeCurrentWellRates(const Simulator& simulator,
159 DeferredLogger& deferred_logger) const override;
160
161 std::optional<Scalar>
163 const SummaryState& summary_state,
164 const Scalar alq_value,
165 DeferredLogger& deferred_logger,
166 bool iterate_if_no_solution) const override;
167
168 std::vector<Scalar> getPrimaryVars() const override;
169
170 int setPrimaryVars(typename std::vector<Scalar>::const_iterator it) override;
171
172 protected:
173 // regularize msw equation
175
176 // the intial amount of fluids in each segment under surface condition
177 std::vector<std::vector<Scalar> > segment_fluid_initial_;
178
179 mutable int debug_cost_counter_ = 0;
180
181 // updating the well_state based on well solution dwells
182 void updateWellState(const Simulator& simulator,
183 const BVectorWell& dwells,
184 WellStateType& well_state,
185 DeferredLogger& deferred_logger,
186 const Scalar relaxation_factor = 1.0);
187
188 // computing the accumulation term for later use in well mass equations
189 void computeInitialSegmentFluids(const Simulator& simulator);
190
191 // compute the pressure difference between the perforation and cell center
192 void computePerfCellPressDiffs(const Simulator& simulator);
193
194 template<class Value>
195 void computePerfRate(const IntensiveQuantities& int_quants,
196 const std::vector<Value>& mob_perfcells,
197 const std::vector<Scalar>& Tw,
198 const int seg,
199 const int perf,
200 const Value& segment_pressure,
201 const bool& allow_cf,
202 std::vector<Value>& cq_s,
203 Value& perf_press,
204 PerforationRates<Scalar>& perf_rates,
205 DeferredLogger& deferred_logger) const;
206
207 template<class Value>
208 void computePerfRate(const Value& pressure_cell,
209 const Value& rs,
210 const Value& rv,
211 const std::vector<Value>& b_perfcells,
212 const std::vector<Value>& mob_perfcells,
213 const std::vector<Scalar>& Tw,
214 const int perf,
215 const Value& segment_pressure,
216 const Value& segment_density,
217 const bool& allow_cf,
218 const std::vector<Value>& cmix_s,
219 std::vector<Value>& cq_s,
220 Value& perf_press,
221 PerforationRates<Scalar>& perf_rates,
222 DeferredLogger& deferred_logger) const;
223
224 // compute the fluid properties, such as densities, viscosities, and so on, in the segments
225 // They will be treated implicitly, so they need to be of Evaluation type
226 void computeSegmentFluidProperties(const Simulator& simulator,
227 DeferredLogger& deferred_logger);
228
229 // get the mobility for specific perforation
230 template<class Value>
231 void getMobility(const Simulator& simulator,
232 const int local_perf_index,
233 std::vector<Value>& mob,
234 DeferredLogger& deferred_logger) const;
235
236 void computeWellRatesAtBhpLimit(const Simulator& simulator,
237 std::vector<Scalar>& well_flux,
238 DeferredLogger& deferred_logger) const;
239
240 void computeWellRatesWithBhp(const Simulator& simulator,
241 const Scalar& bhp,
242 std::vector<Scalar>& well_flux,
243 DeferredLogger& deferred_logger) const override;
244
245 void computeWellRatesWithBhpIterations(const Simulator& simulator,
246 const Scalar& bhp,
247 std::vector<Scalar>& well_flux,
248 DeferredLogger& deferred_logger) const override;
249
250 std::vector<Scalar>
252 const Simulator& simulator,
253 DeferredLogger& deferred_logger) const;
254
255 bool computeWellPotentialsImplicit(const Simulator& simulator,
256 const WellStateType& well_state,
257 std::vector<Scalar>& well_potentials,
258 DeferredLogger& deferred_logger) const;
259
260 Scalar getRefDensity() const override;
261
262 bool iterateWellEqWithControl(const Simulator& simulator,
263 const double dt,
264 const Well::InjectionControls& inj_controls,
265 const Well::ProductionControls& prod_controls,
266 WellStateType& well_state,
267 const GroupState<Scalar>& group_state,
268 DeferredLogger& deferred_logger) override;
269
270 bool iterateWellEqWithSwitching(const Simulator& simulator,
271 const double dt,
272 const Well::InjectionControls& inj_controls,
273 const Well::ProductionControls& prod_controls,
274 WellStateType& well_state,
275 const GroupState<Scalar>& group_state,
276 DeferredLogger& deferred_logger,
277 const bool fixed_control = false,
278 const bool fixed_status = false) override;
279
280 void assembleWellEqWithoutIteration(const Simulator& simulator,
281 const double dt,
282 const Well::InjectionControls& inj_controls,
283 const Well::ProductionControls& prod_controls,
284 WellStateType& well_state,
285 const GroupState<Scalar>& group_state,
286 DeferredLogger& deferred_logger) override;
287
288 void updateWaterThroughput(const double dt, WellStateType& well_state) const override;
289
290 EvalWell getSegmentSurfaceVolume(const Simulator& simulator, const int seg_idx) const;
291
292 // turn on crossflow to avoid singular well equations
293 // when the well is banned from cross-flow and the BHP is not properly initialized,
294 // we turn on crossflow to avoid singular well equations. It can result in wrong-signed
295 // well rates, it can cause problem for THP calculation
296 // TODO: looking for better alternative to avoid wrong-signed well rates
297 bool openCrossFlowAvoidSingularity(const Simulator& simulator) const;
298
299 // for a well, when all drawdown are in the wrong direction, then this well will not
300 // be able to produce/inject .
301 bool allDrawDownWrongDirection(const Simulator& simulator) const;
302
303 std::optional<Scalar>
304 computeBhpAtThpLimitProd(const WellStateType& well_state,
305 const Simulator& ebos_simulator,
306 const SummaryState& summary_state,
307 DeferredLogger& deferred_logger) const;
308
309 std::optional<Scalar>
310 computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
311 const SummaryState& summary_state,
312 DeferredLogger& deferred_logger) const;
313
314 Scalar maxPerfPress(const Simulator& simulator) const;
315
316 // check whether the well is operable under BHP limit with current reservoir condition
317 void checkOperabilityUnderBHPLimit(const WellStateType& well_state,
318 const Simulator& ebos_simulator,
319 DeferredLogger& deferred_logger) override;
320
321 // check whether the well is operable under THP limit with current reservoir condition
322 void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator,
323 const WellStateType& well_state,
324 DeferredLogger& deferred_logger) override;
325
326 // updating the inflow based on the current reservoir condition
327 void updateIPR(const Simulator& ebos_simulator,
328 DeferredLogger& deferred_logger) const override;
329
330 FSInfo getFirstPerforationFluidStateInfo(const Simulator& simulator) const;
331 };
332
333}
334
336
337#endif // OPM_MULTISEGMENTWELL_HEADER_INCLUDED
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:41
Definition: MultisegmentWellEval.hpp:48
MultisegmentWellEquations< Scalar, IndexTraits, numWellEq, Indices::numEq > Equations
Definition: MultisegmentWellEval.hpp:57
Definition: MultisegmentWell.hpp:38
bool computeWellPotentialsImplicit(const Simulator &simulator, const WellStateType &well_state, std::vector< Scalar > &well_potentials, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:531
void updateWellState(const Simulator &simulator, const BVectorWell &dwells, WellStateType &well_state, DeferredLogger &deferred_logger, const Scalar relaxation_factor=1.0)
Definition: MultisegmentWell_impl.hpp:705
void updateWaterThroughput(const double dt, WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:2027
void addWellPressureEquations(PressureMatrix &mat, const BVector &x, const int pressureVarIndex, const bool use_well_weights, const WellStateType &well_state) const override
Definition: MultisegmentWell_impl.hpp:877
std::optional< Scalar > computeBhpAtThpLimitProdWithAlq(const Simulator &simulator, const SummaryState &summary_state, const Scalar alq_value, DeferredLogger &deferred_logger, bool iterate_if_no_solution) const override
Definition: MultisegmentWell_impl.hpp:2076
Scalar connectionDensity(const int globalConnIdx, const int openConnIdx) const override
Definition: MultisegmentWell_impl.hpp:842
void addWellContributions(SparseMatrixAdapter &jacobian) const override
Definition: MultisegmentWell_impl.hpp:864
bool iterateWellEqWithSwitching(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &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:1609
void solveEqAndUpdateWellState(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:601
Scalar getRefDensity() const override
Definition: MultisegmentWell_impl.hpp:1191
std::vector< Scalar > getPrimaryVars() const override
Definition: MultisegmentWell_impl.hpp:2258
void computeWellRatesWithBhpIterations(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:405
std::vector< Scalar > computeCurrentWellRates(const Simulator &simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:2214
void apply(const BVector &x, BVector &Ax) const override
Ax = Ax - C D^-1 B x.
Definition: MultisegmentWell_impl.hpp:230
MultisegmentWell(const Well &well, const ParallelWellInfo< Scalar > &pw_info, const int time_step, const ModelParameters &param, const RateConverterType &rate_converter, const int pvtRegionIdx, const int num_conservation_quantities, const int num_phases, const int index_of_well, const std::vector< PerforationData< Scalar > > &perf_data)
Definition: MultisegmentWell_impl.hpp:62
void checkOperabilityUnderBHPLimit(const WellStateType &well_state, const Simulator &ebos_simulator, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1199
void getMobility(const Simulator &simulator, const int local_perf_index, std::vector< Value > &mob, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1151
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< Scalar > &perf_rates, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:1046
void updateIPRImplicit(const Simulator &simulator, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1364
std::optional< Scalar > computeBhpAtThpLimitProd(const WellStateType &well_state, const Simulator &ebos_simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2058
bool openCrossFlowAvoidSingularity(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1965
void computeSegmentFluidProperties(const Simulator &simulator, DeferredLogger &deferred_logger)
Definition: MultisegmentWell_impl.hpp:1119
void checkOperabilityUnderTHPLimit(const Simulator &ebos_simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1433
bool iterateWellEqWithControl(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1485
int setPrimaryVars(typename std::vector< Scalar >::const_iterator it) override
Definition: MultisegmentWell_impl.hpp:2276
void computeWellRatesWithBhp(const Simulator &simulator, const Scalar &bhp, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:358
EvalWell getSegmentSurfaceVolume(const Simulator &simulator, const int seg_idx) const
Definition: MultisegmentWell_impl.hpp:2038
void scaleSegmentRatesAndPressure(WellStateType &well_state) const override
updating the segment pressure and rates based the current bhp and well rates
Definition: MultisegmentWell_impl.hpp:173
bool allDrawDownWrongDirection(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:1974
int debug_cost_counter_
Definition: MultisegmentWell.hpp:179
ConvergenceReport getWellConvergence(const Simulator &simulator, const WellStateType &well_state, const std::vector< Scalar > &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:204
void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellStateType &well_state, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:760
void computePerfCellPressDiffs(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:630
void computeWellPotentials(const Simulator &simulator, const WellStateType &well_state, std::vector< Scalar > &well_potentials, DeferredLogger &deferred_logger) override
computing the well potentials for group control
Definition: MultisegmentWell_impl.hpp:297
void recoverWellSolutionAndUpdateWellState(const Simulator &simulator, const BVector &x, WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:265
void updateWellStateWithTarget(const Simulator &simulator, const GroupState< Scalar > &group_state, WellStateType &well_state, DeferredLogger &deferred_logger) const override
updating the well state based the current control mode
Definition: MultisegmentWell_impl.hpp:184
void updateIPR(const Simulator &ebos_simulator, DeferredLogger &deferred_logger) const override
Definition: MultisegmentWell_impl.hpp:1265
std::tuple< Scalar, typename std::decay< decltype(std::declval< decltype(std::declval< const Simulator & >().model().intensiveQuantities(0, 0).fluidState())>().saltConcentration())>::type, int > FSInfo
Definition: MultisegmentWell.hpp:73
FSInfo getFirstPerforationFluidStateInfo(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2291
void computeWellRatesAtBhpLimit(const Simulator &simulator, std::vector< Scalar > &well_flux, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:342
void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: MultisegmentWell_impl.hpp:122
void assembleWellEqWithoutIteration(const Simulator &simulator, const double dt, const Well::InjectionControls &inj_controls, const Well::ProductionControls &prod_controls, WellStateType &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:1784
bool regularize_
Definition: MultisegmentWell.hpp:174
Scalar maxPerfPress(const Simulator &simulator) const
Definition: MultisegmentWell_impl.hpp:2186
std::vector< std::vector< Scalar > > segment_fluid_initial_
Definition: MultisegmentWell.hpp:177
void updatePrimaryVariables(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:157
std::optional< Scalar > computeBhpAtThpLimitInj(const Simulator &ebos_simulator, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:2132
void calculateExplicitQuantities(const Simulator &simulator, const WellStateType &well_state, DeferredLogger &deferred_logger) override
Definition: MultisegmentWell_impl.hpp:744
std::vector< Scalar > computeWellPotentialWithTHP(const WellStateType &well_state, const Simulator &simulator, DeferredLogger &deferred_logger) const
Definition: MultisegmentWell_impl.hpp:480
void computeInitialSegmentFluids(const Simulator &simulator)
Definition: MultisegmentWell_impl.hpp:687
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:198
static constexpr int Oil
Definition: WellInterfaceFluidSystem.hpp:62
static constexpr int Water
Definition: WellInterfaceFluidSystem.hpp:61
static constexpr int Gas
Definition: WellInterfaceFluidSystem.hpp:63
int pvtRegionIdx() const
Definition: WellInterfaceGeneric.hpp:128
Definition: WellInterface.hpp:76
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: WellInterface.hpp:81
typename WellInterfaceFluidSystem< FluidSystem >::RateConverterType RateConverterType
Definition: WellInterface.hpp:103
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:136
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: WellInterface.hpp:97
GetPropType< TypeTag, Properties::IntensiveQuantities > IntensiveQuantities
Definition: WellInterface.hpp:86
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: WellInterface.hpp:82
GetPropType< TypeTag, Properties::MaterialLaw > MaterialLaw
Definition: WellInterface.hpp:87
typename FluidSystem::IndexTraitsType IndexTraits
Definition: WellInterface.hpp:84
Dune::BlockVector< VectorBlockType > BVector
Definition: WellInterface.hpp:96
static constexpr bool has_polymer
Definition: WellInterface.hpp:113
typename Base::ModelParameters ModelParameters
Definition: WellInterface.hpp:109
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: WellInterface.hpp:83
static constexpr bool has_solvent
Definition: WellInterface.hpp:111
typename Base::Eval Eval
Definition: WellInterface.hpp:95
WellState< Scalar, IndexTraits > WellStateType
Definition: WellInterface.hpp:99
GetPropType< TypeTag, Properties::Indices > Indices
Definition: WellInterface.hpp:85
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: WellInterface.hpp:88
Definition: WellProdIndexCalculator.hpp:37
Definition: WellState.hpp:66
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilbioeffectsmodules.hh:43
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
Static data associated with a well perforation.
Definition: PerforationData.hpp:30
Definition: PerforationData.hpp:41