BlackoilWellModel.hpp
Go to the documentation of this file.
1/*
2 Copyright 2016 SINTEF ICT, Applied Mathematics.
3 Copyright 2016 - 2017 Statoil ASA.
4 Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
5 Copyright 2016 - 2018 IRIS AS
6
7 This file is part of the Open Porous Media project (OPM).
8
9 OPM is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OPM is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OPM. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
24#define OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
25
26#include <dune/common/fmatrix.hh>
27
28#include <dune/istl/bcrsmatrix.hh>
29#include <dune/istl/matrixmatrix.hh>
30
31#include <opm/common/OpmLog/OpmLog.hpp>
32#include <opm/grid/utility/SparseTable.hpp>
33
34#include <opm/input/eclipse/Schedule/Group/Group.hpp>
35#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
36#include <opm/input/eclipse/Schedule/Schedule.hpp>
37#include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
38
39#include <opm/material/densead/Math.hpp>
40
43
46
49
51
78
79#include <cstddef>
80#include <map>
81#include <memory>
82#include <optional>
83#include <string>
84#include <tuple>
85#include <vector>
86
87namespace Opm {
88
89template<class Scalar> class BlackoilWellModelNldd;
90template<class T, template <typename, typename...> class Storage> class SparseTable;
91
92#if COMPILE_GPU_BRIDGE
93template<class Scalar> class WellContributions;
94#endif
95
97 template<typename TypeTag>
98 class BlackoilWellModel : public WellConnectionAuxiliaryModule<TypeTag, BlackoilWellModel<TypeTag>>
99 , public BlackoilWellModelGeneric<GetPropType<TypeTag, Properties::Scalar>,
100 typename GetPropType<TypeTag, Properties::FluidSystem>::IndexTraitsType>
101 {
102 public:
103 // --------- Types ---------
115
117 using IndexTraits = typename FluidSystem::IndexTraitsType;
119
121
122 static const int numEq = Indices::numEq;
123 static const int solventSaturationIdx = Indices::solventSaturationIdx;
124 static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
125 static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
126 static constexpr EnergyModules energyModuleType_ = getPropValue<TypeTag, Properties::EnergyModuleType>();
127 static constexpr bool has_energy_ = (energyModuleType_ == EnergyModules::FullyImplicitThermal);
128 static constexpr bool has_micp_ = Indices::enableMICP;
129 static constexpr bool has_geochem_ = getPropValue<TypeTag, Properties::EnableGeochemistry>();
130 static constexpr bool has_bioeffects_ = getPropValue<TypeTag, Properties::EnableBioeffects>();
131
132 // TODO: where we should put these types, WellInterface or Well Model?
133 // or there is some other strategy, like TypeTag
134 using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
135 using BVector = Dune::BlockVector<VectorBlockType>;
136
137 using PolymerModule = BlackOilPolymerModule<TypeTag, has_polymer_>;
138 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, has_bioeffects_>;
139
140 // For the conversion between the surface volume rate and reservoir voidage rate
141 using RateConverterType = RateConverter::
142 SurfaceToReservoirVoidage<FluidSystem, std::vector<int> >;
143
144 // For computing average pressured used by gpmaint
145 using AverageRegionalPressureType = RegionAverageCalculator::
146 AverageRegionalPressure<FluidSystem, std::vector<int> >;
147
149
150 void init();
151 void initWellContainer(const int reportStepIdx) override;
152
154 {
155 OPM_TIMEBLOCK(beginEpsiode);
156 beginReportStep(simulator_.episodeIndex());
157 }
158
159 void beginTimeStep();
160
161 void updateFailed();
162
163 void advanceTimeLevel();
164
166 {
167 OPM_TIMEBLOCK(beginIteration);
168 assemble(simulator_.timeStepSize());
169 }
170
172 { }
173
175 {
176 OPM_TIMEBLOCK(endTimeStep);
177 timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
178 }
179
181 {
183 }
184
186 unsigned globalIdx) const;
187
188 template <class Context>
190 const Context& context,
191 unsigned spaceIdx,
192 unsigned timeIdx) const;
193
194
195 using WellInterfacePtr = std::unique_ptr<WellInterface<TypeTag>>;
196
198 void initFromRestartFile(const RestartValue& restartValues)
199 {
200 initFromRestartFile(restartValues,
201 this->simulator_.vanguard().transferWTestState(),
202 grid().size(0),
203 this->simulator_.vanguard().enableDistributedWells());
204 }
205
207 void prepareDeserialize(const int report_step)
208 {
209 prepareDeserialize(report_step, grid().size(0),
210 this->simulator_.vanguard().enableDistributedWells());
211 }
212
213 data::Wells wellData() const
214 {
215 auto wsrpt = this->wellState()
216 .report(this->simulator_.vanguard().globalCell().data(),
217 [this](const std::size_t well_index)
218 { return this->wasDynamicallyShutThisTimeStep(well_index); },
219 this->rsConstInfo());
220
222 .assignWellGuideRates(wsrpt, this->reportStepIndex());
223
224 this->assignWellTracerRates_(wsrpt);
225
226 if constexpr (has_geochem_) {
227 this->assignWellSpeciesRates_(wsrpt);
228 }
229
230 if (const auto& rspec = eclState().runspec();
231 rspec.co2Storage() || rspec.h2Storage())
232 {
233 // The gas reference density (surface condition) is the
234 // same for all PVT regions in CO2STORE/H2STORE runs so,
235 // for simplicity, we use region zero (0) here.
236
237 this->assignMassGasRate(wsrpt, FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, 0));
238 }
239
240 this->assignWellTargets(wsrpt);
241
242 this->assignDynamicWellStatus(wsrpt);
243
244 // Assigning (a subset of the) property values in shut
245 // connections should be the last step of wellData().
246 this->assignShutConnections(wsrpt, this->reportStepIndex());
247
248 return wsrpt;
249 }
250
251 data::WellBlockAveragePressures wellBlockAveragePressures() const
252 {
253 return this->wbp_.computeWellBlockAveragePressures(this->gravity_);
254 }
255
256#if COMPILE_GPU_BRIDGE
257 // accumulate the contributions of all Wells in the WellContributions object
258 void getWellContributions(WellContributions<Scalar>& x) const;
259#endif
260
261 // Check if well equations is converged.
262 ConvergenceReport getWellConvergence(const std::vector<Scalar>& B_avg, const bool checkWellGroupControlsAndNetwork = false) const;
263
264 const SimulatorReportSingle& lastReport() const;
265
266 void addWellContributions(SparseMatrixAdapter& jacobian) const;
267
268 // add source from wells to the reservoir matrix
270 const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const;
271
272 // called at the beginning of a report step
273 void beginReportStep(const int time_step);
274
278 void calculateExplicitQuantities() const;
279
282 void prepareTimeStep(DeferredLogger& deferred_logger);
283
284 bool
285 updateWellControls(DeferredLogger& deferred_logger);
286
287 void updateAndCommunicate(const int reportStepIdx);
288
289 bool updateGroupControls(const Group& group,
290 DeferredLogger& deferred_logger,
291 const int reportStepIdx);
292
293 static constexpr int numResDofs = Indices::numEq;
294 static constexpr int numWellDofs = numResDofs + 1;//NB will fail for for thermal for now
295 using BMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numResDofs>>;
296 using CMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numResDofs, numWellDofs>>;
297 using DMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numWellDofs>>;
298 using WVector = Dune::BlockVector<Dune::FieldVector<Scalar, numWellDofs>>;
299
300 void addBCDMatrix(std::vector<BMatrix>& b_matrices,
301 std::vector<CMatrix>& c_matrices,
302 std::vector<DMatrix>& d_matrices,
303 Opm::SparseTable<int>& wcells) const;
304
305 const WellInterface<TypeTag>& getWell(const std::string& well_name) const;
306
307 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 1, 1>>;
308
310 const BVector& weights,
311 const bool use_well_weights) const;
314 const BVector& weights,
315 const bool use_well_weights,
316 const int domainIndex) const
317 {
318 if (!nldd_) {
319 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
320 }
321 return nldd_->addWellPressureEquations(jacobian,
322 weights,
323 use_well_weights,
324 domainIndex);
325 }
326
328 const std::vector<WellInterfacePtr>& localNonshutWells() const
329 {
330 return well_container_;
331 }
332
334 {
335 if (!nldd_) {
336 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
337 }
338 return nldd_->well_local_cells();
339 }
340
341 const std::map<std::string, int>& well_domain() const
342 {
343 if (!nldd_) {
344 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
345 }
346
347 return nldd_->well_domain();
348 }
349
350 auto begin() const { return well_container_.begin(); }
351 auto end() const { return well_container_.end(); }
352 bool empty() const { return well_container_.empty(); }
353
356
359
360 int compressedIndexForInterior(int cartesian_cell_idx) const override
361 {
362 return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
363 }
364
365 int compressedIndexForInteriorLGR(const std::string& lgr_tag, const Connection& conn) const override
366 {
367 return simulator_.vanguard().compressedIndexForInteriorLGR(lgr_tag, conn);
368 }
369
370 // using the solution x to recover the solution xw for wells and applying
371 // xw to update Well State
373
374 // using the solution x to recover the solution xw for wells and applying
375 // xw to update Well State
377 const int domainIdx);
378 // Update cellRates_ with contributions from all wells
379 void updateCellRates();
380
381 // Update cellRates_ with contributions from wells in a specific domain
382 void updateCellRatesForDomain(int domainIndex,
383 const std::map<std::string, int>& well_domain_map);
384
385 const Grid& grid() const
386 { return simulator_.vanguard().grid(); }
387
388 const Simulator& simulator() const
389 { return simulator_; }
391 { return simulator_; }
392
394 const BlackoilWellModelNetwork<TypeTag>& network() const { return network_; }
395
396 std::vector<WellInterfacePtr>& wellContainer() { return well_container_; }
397 const std::vector<WellInterfacePtr>& wellContainer() const { return well_container_; }
398
400 { nldd_ = mod; }
401
403 { return guide_rate_handler_; }
404
406 { return guide_rate_handler_; }
407
408 // === Reservoir Coupling ===
409
413
421 void updateGuideRates(const int report_step_idx,
422 const double sim_time)
423 {
424 this->guide_rate_handler_.updateGuideRates(
425 report_step_idx, sim_time, this->wellState(), this->groupState()
426 );
427 }
428
430 bool isReservoirCouplingMaster() const { return rescoup_.isMaster(); }
431
433 bool isReservoirCouplingSlave() const { return rescoup_.isSlave(); }
434
440 bool isReservoirCouplingMasterGroup(const std::string& group_name) const {
441 return rescoup_.isMasterGroup(group_name);
442 }
443
447 return rescoup_.master();
448 }
450 return rescoup_.master();
451 }
452
456 return rescoup_.slave();
457 }
459 return rescoup_.slave();
460 }
461
462#ifdef RESERVOIR_COUPLING_ENABLED
463 void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar>* master)
464 {
465 rescoup_.setMaster(master);
466 this->guide_rate_handler_.setReservoirCouplingMaster(master);
467 this->groupStateHelper().setReservoirCouplingMaster(master);
468 }
469 void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar>* slave)
470 {
471 rescoup_.setSlave(slave);
472 this->guide_rate_handler_.setReservoirCouplingSlave(slave);
473 this->groupStateHelper().setReservoirCouplingSlave(slave);
474 }
475#endif
476
477 bool updateWellControlsAndNetwork(const bool mandatory_network_balance,
478 const double dt,
479 DeferredLogger& local_deferredLogger);
480
481 // TODO: finding a better naming
482 void assembleWellEqWithoutIteration(const double dt);
483
515 void assembleWellEqAtRestoredState(const double dt)
516 {
517 // restore the well primary variables from the (converged) well
518 // state, then the well-local quantities, then assemble --
519 // without touching the group/control state.
520 auto logger_guard = this->groupStateHelper().pushLogger();
524 }
525
526 const std::vector<Scalar>& B_avg() const
527 { return B_avg_; }
528
529 const ModelParameters& param() const
530 { return param_; }
531
537
538#ifdef RESERVOIR_COUPLING_ENABLED
542 BlackoilWellModelRescoup<TypeTag>& rescoupHelper() { return rescoupHelper_; }
543#endif
544
545
546 template<class FluidState, class SingleWellState>
547 static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState& fs, const SingleWellState& ws)
548 {
549 const auto& perf_phase_rate = ws.perf_data.phase_rates;
550 // we only have one temperature pr cell any phaseIdx will do
551 Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
552 Scalar weight_factor = 0.0;
553 for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
554 if (!FluidSystem::phaseIsActive(phaseIdx)) {
555 continue;
556 }
557 Scalar cellInternalEnergy = fs.enthalpy(phaseIdx).value() -
558 fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
559 Scalar cellBinv = fs.invB(phaseIdx).value();
560 Scalar cellDensity = fs.density(phaseIdx).value();
561 Scalar perfPhaseRate = perf_phase_rate[perf_index*np + phaseIdx];
562 weight_factor += cellDensity * (perfPhaseRate / cellBinv) * (cellInternalEnergy / cellTemperatures);
563 }
564 return (std::abs(weight_factor) + 1e-13);
565 }
566
567 protected:
569
570 // a vector of all the wells.
571 std::vector<WellInterfacePtr> well_container_{};
572
573 std::vector<bool> is_cell_perforated_{};
574
575 void initializeWellState(const int timeStepIdx);
576
577 // create the well container
578 void createWellContainer(const int report_step) override;
579
581 createWellPointer(const int wellID,
582 const int report_step) const;
583
584 template <typename WellType>
585 std::unique_ptr<WellType>
586 createTypedWellPointer(const int wellID,
587 const int time_step) const;
588
589 WellInterfacePtr createWellForWellTest(const std::string& well_name,
590 const int report_step,
591 DeferredLogger& deferred_logger) const;
592
594 std::size_t global_num_cells_{};
595 // the number of the cells in the local grid
596 std::size_t local_num_cells_{};
598 std::vector<Scalar> depth_{};
600 std::unique_ptr<RateConverterType> rateConverter_{};
601 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
602
606
607 // A flag to tell the convergence report whether we need to take another newton step
609
610 std::vector<Scalar> B_avg_{};
611
612 const EquilGrid& equilGrid() const
613 { return simulator_.vanguard().equilGrid(); }
614
615 const EclipseState& eclState() const
616 { return simulator_.vanguard().eclState(); }
617
618 // compute the well fluxes and assemble them in to the reservoir equations as source terms
619 // and in the well equations.
620 void assemble(const double dt);
621
622 // collect the statistics for the standalone well solves gathered
623 // since the last call into last_report_ and reset them.
625
626 // well controls and network pressures affect each other and are solved in an iterative manner.
627 // the function handles one iteration of updating well controls and network pressures.
628 // it is possible to decouple the update of well controls and network pressures further.
629 // the returned two booleans are {continue_due_to_network, well_group_control_changed}, respectively
630 std::tuple<bool, bool, Scalar> updateWellControlsAndNetworkIteration(const bool mandatory_network_balance,
631 const bool relax_network_tolerance,
632 const bool optimize_gas_lift,
633 const double dt,
634 DeferredLogger& local_deferredLogger);
635
646 void initializeLocalWellStructure(const int reportStepIdx,
647 const bool enableWellPIScaling,
648 const bool initializeWellState);
649
653 void initializeGroupStructure(const int reportStepIdx);
654
655 // called at the end of a time step
656 void timeStepSucceeded(const double simulationTime, const double dt);
657
658 // called at the end of a report step
659 void endReportStep();
660
661 // setting the well_solutions_ based on well_state.
663
665
666 void computePotentials(const std::size_t widx,
667 const WellState<Scalar, IndexTraits>& well_state_copy,
668 std::string& exc_msg,
669 ExceptionType::ExcEnum& exc_type) override;
670
671 const std::vector<Scalar>& wellPerfEfficiencyFactors() const;
672
673 void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger) override;
674 void calculateProductivityIndexValues(DeferredLogger& deferred_logger) override;
676 DeferredLogger& deferred_logger);
677
678 // The number of conservation quantities.
679 int numConservationQuantities() const;
680
681 int reportStepIndex() const;
682
683 void assembleWellEq(const double dt);
684
685 void prepareWellsBeforeAssembling(const double dt);
686
688
689 void extractLegacyDepth_();
690
692 void updateWellTestState(const double simulationTime, WellTestState& wellTestState);
693
694 void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger& deferred_logger);
695
696 void calcResvCoeff(const int fipnum,
697 const int pvtreg,
698 const std::vector<Scalar>& production_rates,
699 std::vector<Scalar>& resv_coeff) const override;
700
701 void calcInjResvCoeff(const int fipnum,
702 const int pvtreg,
703 std::vector<Scalar>& resv_coeff) const override;
704
706
707 private:
708 // Private helper methods (alphabetical order)
709 // --------------------------------------------
710
711 void assignWellSpeciesRates_(data::Wells& wsrpt) const;
712 void assignWellTracerRates_(data::Wells& wsrpt) const;
713
722 bool isRescoupCoupledNetworkParticipant_() const;
723
731 bool isRescoupMasterCoupledNetworkIteration_() const;
732
740 bool isRescoupSlaveCoupledNetworkIteration_() const;
741
748 bool isRescoupSlaveOnSyncStepFirstSubstep_() const;
749
758 bool isRescoupSlaveConnectedToMasterNetwork_() const;
759
766 bool maybeSendSlaveGroupFlowToMaster_(const int reportStepIdx);
767
772 void sendSlaveNetworkLoopTerminationSignal_();
773
776 bool shouldDoPreStepNetworkRebalance_(const int episodeIdx) const;
777
779 void updateNetworkActiveState_();
780
783#ifdef RESERVOIR_COUPLING_ENABLED
784 BlackoilWellModelRescoup<TypeTag> rescoupHelper_;
785#endif
786 BlackoilWellModelNldd<TypeTag>* nldd_ = nullptr;
787
788 // These members are used to avoid reallocation in specific functions
789 // instead of using local variables.
790 // Their state is not relevant between function calls, so they can
791 // (and must) be mutable, as the functions using them are const.
792 mutable BVector x_local_;
793
794 // Store cell rates after assembling to avoid iterating all wells and connections for every element
795 std::map<int, RateVector> cellRates_;
796
797 // Cached well solution from the system solver, consumed by
798 // recoverWellSolutionAndUpdateWellState during postSolve.
799 std::optional<WellVector<Scalar>> cachedSystemWellSolution_;
800 std::vector<int> cachedWellDofOffsets_;
801
802 void assignWellTracerRates(data::Wells& wsrpt) const;
803 void assignWellSpeciesRates(data::Wells& wsrpt) const;
804
805 [[nodiscard]] auto rsConstInfo() const
806 -> typename WellState<Scalar,IndexTraits>::RsConstInfo;
807 };
808
809} // namespace Opm
810
811#include "BlackoilWellModel_impl.hpp"
812
813#endif // OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
Class for handling the gaslift in the blackoil well model.
Definition: BlackoilWellModelGasLift.hpp:96
Class for handling the blackoil well model.
Definition: BlackoilWellModelGeneric.hpp:99
const WellState< Scalar, IndexTraits > & wellState() const
Definition: BlackoilWellModelGeneric.hpp:158
Class for handling the guide rates in the blackoil well model.
Definition: BlackoilWellModelGuideRates.hpp:47
void assignWellGuideRates(data::Wells &wsrpt, const int reportStepIdx) const
Assign well guide rates.
Class for handling the blackoil well network model.
Definition: BlackoilWellModelNetwork.hpp:47
Class for handling the blackoil well model in a NLDD solver.
Definition: BlackoilWellModelNldd.hpp:80
Class for handling the blackoil well model.
Definition: BlackoilWellModel.hpp:101
ReservoirCoupling::Proxy< Scalar > & rescoup()
Get the reservoir coupling proxy.
Definition: BlackoilWellModel.hpp:411
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:307
bool network_needs_more_balancing_force_another_newton_iteration_
Definition: BlackoilWellModel.hpp:608
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numWellDofs > > DMatrix
Definition: BlackoilWellModel.hpp:297
void calcResvCoeff(const int fipnum, const int pvtreg, const std::vector< Scalar > &production_rates, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2288
ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster()
Get reference to reservoir coupling master.
Definition: BlackoilWellModel.hpp:446
void endTimeStep()
Definition: BlackoilWellModel.hpp:174
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2108
std::tuple< bool, bool, Scalar > updateWellControlsAndNetworkIteration(const bool mandatory_network_balance, const bool relax_network_tolerance, const bool optimize_gas_lift, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1351
static constexpr bool has_bioeffects_
Definition: BlackoilWellModel.hpp:130
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numResDofs > > BMatrix
Definition: BlackoilWellModel.hpp:295
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:1099
GuideRateHandler< Scalar, IndexTraits > guide_rate_handler_
Definition: BlackoilWellModel.hpp:604
const EclipseState & eclState() const
Definition: BlackoilWellModel.hpp:615
void prepareWellsBeforeAssembling(const double dt)
Definition: BlackoilWellModel_impl.hpp:1474
const std::vector< WellInterfacePtr > & localNonshutWells() const
Get list of local nonshut wells.
Definition: BlackoilWellModel.hpp:328
void prepareDeserialize(const int report_step)
Definition: BlackoilWellModel.hpp:207
void init()
Definition: BlackoilWellModel_impl.hpp:165
void setNlddAdapter(BlackoilWellModelNldd< TypeTag > *mod)
Definition: BlackoilWellModel.hpp:399
const Simulator & simulator() const
Definition: BlackoilWellModel.hpp:388
std::vector< Scalar > depth_
Definition: BlackoilWellModel.hpp:598
static constexpr bool has_geochem_
Definition: BlackoilWellModel.hpp:129
static constexpr EnergyModules energyModuleType_
Definition: BlackoilWellModel.hpp:126
std::size_t global_num_cells_
Definition: BlackoilWellModel.hpp:594
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:110
const std::vector< Scalar > & B_avg() const
Definition: BlackoilWellModel.hpp:526
SimulatorReportSingle last_report_
Definition: BlackoilWellModel.hpp:603
static const int solventSaturationIdx
Definition: BlackoilWellModel.hpp:123
Scalar gravity_
Definition: BlackoilWellModel.hpp:597
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:184
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:201
static constexpr int numResDofs
Definition: BlackoilWellModel.hpp:293
const WellInterface< TypeTag > & getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2260
bool useTightRcNetworkCoupling() const
True when tight (per-sub-iteration) reservoir-coupling network coupling is in effect....
Definition: BlackoilWellModel.hpp:535
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: BlackoilWellModel.hpp:106
void beginIteration()
Definition: BlackoilWellModel.hpp:165
bool isReservoirCouplingMaster() const
Check if this process is a reservoir coupling master.
Definition: BlackoilWellModel.hpp:430
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:134
const BlackoilWellModelNetwork< TypeTag > & network() const
Definition: BlackoilWellModel.hpp:394
void initFromRestartFile(const RestartValue &restartValues)
Definition: BlackoilWellModel.hpp:198
const ModelParameters param_
Definition: BlackoilWellModel.hpp:593
void beginEpisode()
Definition: BlackoilWellModel.hpp:153
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilWellModel.hpp:107
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilWellModel.hpp:104
GetPropType< TypeTag, Properties::EquilGrid > EquilGrid
Definition: BlackoilWellModel.hpp:105
static constexpr int numWellDofs
Definition: BlackoilWellModel.hpp:294
int numConservationQuantities() const
Definition: BlackoilWellModel_impl.hpp:2229
const std::map< std::string, int > & well_domain() const
Definition: BlackoilWellModel.hpp:341
const ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave() const
Definition: BlackoilWellModel.hpp:458
bool updateWellControls(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1771
void endIteration()
Definition: BlackoilWellModel.hpp:171
static constexpr bool has_polymer_
Definition: BlackoilWellModel.hpp:125
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2276
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2050
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2248
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2213
std::vector< WellInterfacePtr > & wellContainer()
Definition: BlackoilWellModel.hpp:396
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const int domainIdx)
Definition: BlackoilWellModel_impl.hpp:1692
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2156
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:109
BlackoilWellModel(Simulator &simulator, const NewtonIterationContext &iter_ctx)
Definition: BlackoilWellModel_impl.hpp:72
bool isReservoirCouplingSlave() const
Check if this process is a reservoir coupling slave.
Definition: BlackoilWellModel.hpp:433
const ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster() const
Definition: BlackoilWellModel.hpp:449
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:799
const Grid & grid() const
Definition: BlackoilWellModel.hpp:385
void updatePrimaryVariables()
Definition: BlackoilWellModel_impl.hpp:2204
const ReservoirCoupling::Proxy< Scalar > & rescoup() const
Definition: BlackoilWellModel.hpp:412
BlackOilPolymerModule< TypeTag, has_polymer_ > PolymerModule
Definition: BlackoilWellModel.hpp:137
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2310
static const int numEq
Definition: BlackoilWellModel.hpp:122
void addWellPressureEquations(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights) const
Definition: BlackoilWellModel_impl.hpp:1596
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:669
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1285
void endEpisode()
Definition: BlackoilWellModel.hpp:180
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: BlackoilWellModel.hpp:113
void assembleWellEqAtRestoredState(const double dt)
Assemble the well equations at an already-converged state that the caller has restored,...
Definition: BlackoilWellModel.hpp:515
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1573
const EquilGrid & equilGrid() const
Definition: BlackoilWellModel.hpp:612
void assembleWellEq(const double dt)
Definition: BlackoilWellModel_impl.hpp:1462
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1150
GetPropType< TypeTag, Properties::Indices > Indices
Definition: BlackoilWellModel.hpp:108
int compressedIndexForInteriorLGR(const std::string &lgr_tag, const Connection &conn) const override
Definition: BlackoilWellModel.hpp:365
void calculateExplicitQuantities() const
Definition: BlackoilWellModel_impl.hpp:1756
BlackoilWellModelNetwork< TypeTag > & network()
Definition: BlackoilWellModel.hpp:393
Dune::BlockVector< Dune::FieldVector< Scalar, numWellDofs > > WVector
Definition: BlackoilWellModel.hpp:298
std::vector< WellInterfacePtr > well_container_
Definition: BlackoilWellModel.hpp:571
void collectWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1265
static constexpr std::size_t pressureVarIndex
Definition: BlackoilWellModel.hpp:120
void updateAndCommunicate(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1869
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:307
void updateFailed()
Definition: BlackoilWellModel_impl.hpp:580
bool empty() const
Definition: BlackoilWellModel.hpp:352
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:762
bool addMatrixContributions() const
Definition: BlackoilWellModel.hpp:354
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:339
std::vector< Scalar > B_avg_
Definition: BlackoilWellModel.hpp:610
const std::vector< Scalar > & wellPerfEfficiencyFactors() const
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: BlackoilWellModel.hpp:111
bool updateGroupControls(const Group &group, DeferredLogger &deferred_logger, const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1896
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling, const bool initializeWellState)
Definition: BlackoilWellModel_impl.hpp:253
std::map< std::string, std::unique_ptr< AverageRegionalPressureType > > regionalAveragePressureCalculator_
Definition: BlackoilWellModel.hpp:601
void calcInjResvCoeff(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2299
static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState &fs, const SingleWellState &ws)
Definition: BlackoilWellModel.hpp:547
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: BlackoilWellModel.hpp:112
GuideRateHandler< Scalar, IndexTraits > & guideRateHandler()
Definition: BlackoilWellModel.hpp:402
static constexpr bool has_solvent_
Definition: BlackoilWellModel.hpp:124
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilWellModel.hpp:135
static constexpr bool has_micp_
Definition: BlackoilWellModel.hpp:128
std::unique_ptr< RateConverterType > rateConverter_
Definition: BlackoilWellModel.hpp:600
const SparseTable< int > & well_local_cells() const
Definition: BlackoilWellModel.hpp:333
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:595
std::vector< bool > is_cell_perforated_
Definition: BlackoilWellModel.hpp:573
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControlsAndNetwork=false) const
Definition: BlackoilWellModel_impl.hpp:1705
int numStrictIterations() const
Definition: BlackoilWellModel.hpp:357
typename FluidSystem::IndexTraitsType IndexTraits
Definition: BlackoilWellModel.hpp:117
void updateCellRatesForDomain(int domainIndex, const std::map< std::string, int > &well_domain_map)
Definition: BlackoilWellModel_impl.hpp:1520
data::WellBlockAveragePressures wellBlockAveragePressures() const
Definition: BlackoilWellModel.hpp:251
void assembleWellEqWithoutIteration(const double dt)
Definition: BlackoilWellModel_impl.hpp:1488
void updateCellRates()
Definition: BlackoilWellModel_impl.hpp:1508
void assemble(const double dt)
Definition: BlackoilWellModel_impl.hpp:1175
auto begin() const
Definition: BlackoilWellModel.hpp:350
std::size_t local_num_cells_
Definition: BlackoilWellModel.hpp:596
auto end() const
Definition: BlackoilWellModel.hpp:351
BlackOilBioeffectsModule< TypeTag, has_bioeffects_ > BioeffectsModule
Definition: BlackoilWellModel.hpp:138
bool alternative_well_rate_init_
Definition: BlackoilWellModel.hpp:599
Simulator & simulator()
Definition: BlackoilWellModel.hpp:390
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:679
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1119
void computePotentials(const std::size_t widx, const WellState< Scalar, IndexTraits > &well_state_copy, std::string &exc_msg, ExceptionType::ExcEnum &exc_type) override
Definition: BlackoilWellModel_impl.hpp:2015
Simulator & simulator_
Definition: BlackoilWellModel.hpp:568
void updateGuideRates(const int report_step_idx, const double sim_time)
Update guide rates for all wells and groups.
Definition: BlackoilWellModel.hpp:421
ReservoirCoupling::Proxy< Scalar > rescoup_
Definition: BlackoilWellModel.hpp:605
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:842
std::unique_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:195
ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave()
Get reference to reservoir coupling slave.
Definition: BlackoilWellModel.hpp:455
data::Wells wellData() const
Definition: BlackoilWellModel.hpp:213
const ModelParameters & param() const
Definition: BlackoilWellModel.hpp:529
void updateWellTestState(const double simulationTime, WellTestState &wellTestState)
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:1941
void addWellPressureEquationsDomain(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights, const int domainIndex) const
Definition: BlackoilWellModel.hpp:313
bool isReservoirCouplingMasterGroup(const std::string &group_name) const
Check if a group is a reservoir coupling master group.
Definition: BlackoilWellModel.hpp:440
void addBCDMatrix(std::vector< BMatrix > &b_matrices, std::vector< CMatrix > &c_matrices, std::vector< DMatrix > &d_matrices, Opm::SparseTable< int > &wcells) const
Definition: BlackoilWellModel_impl.hpp:1582
const GuideRateHandler< Scalar, IndexTraits > & guideRateHandler() const
Definition: BlackoilWellModel.hpp:405
void addReservoirSourceTerms(GlobalEqVector &residual, const std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1618
int compressedIndexForInterior(int cartesian_cell_idx) const override
get compressed index for interior cells (-1, otherwise
Definition: BlackoilWellModel.hpp:360
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numResDofs, numWellDofs > > CMatrix
Definition: BlackoilWellModel.hpp:296
static constexpr bool has_energy_
Definition: BlackoilWellModel.hpp:127
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1668
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1648
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2064
void advanceTimeLevel()
Definition: BlackoilWellModel_impl.hpp:588
const std::vector< WellInterfacePtr > & wellContainer() const
Definition: BlackoilWellModel.hpp:397
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:652
Definition: ConvergenceReport.hpp:38
Definition: DeferredLogger.hpp:57
Definition: GroupStateHelper.hpp:56
ScopedLoggerGuard pushLogger(bool do_mpi_gather=true) const
Push a new logger onto the stack with auto-cleanup on destruction.
Definition: GroupStateHelper.hpp:363
Handles computation and reporting of guide rates for wells and groups.
Definition: GuideRateHandler.hpp:46
Definition: RateConverter.hpp:70
Definition: RegionAverageCalculator.hpp:60
Thin proxy for reservoir coupling master/slave pointers.
Definition: RescoupProxy.hpp:54
Definition: ReservoirCouplingMaster.hpp:38
Definition: ReservoirCouplingSlave.hpp:40
Definition: SingleWellState.hpp:44
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:163
Definition: BlackoilWellModel.hpp:90
Definition: WellConnectionAuxiliaryModule.hpp:39
Definition: WellContributions.hpp:51
Definition: WellInterface.hpp:79
Definition: WellState.hpp:68
ExcEnum
Definition: DeferredLogger.hpp:45
Definition: blackoilbioeffectsmodules.hh:45
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
Solver parameters for the NonlinearSystemBlackOilReservoir.
Definition: BlackoilModelParameters.hpp:207
bool matrix_add_well_contributions_
Whether to add influences of wells between cells to the matrix and preconditioner matrix.
Definition: BlackoilModelParameters.hpp:321
int strict_outer_iter_wells_
Newton iteration where wells are stricly convergent.
Definition: BlackoilModelParameters.hpp:271
bool rc_network_loose_coupling_
Definition: BlackoilModelParameters.hpp:363
Context for iteration-dependent decisions in the Newton solver.
Definition: NewtonIterationContext.hpp:43
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34