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
245
246 // Assigning (a subset of the) property values in shut
247 // connections should be the last step of wellData().
248 this->assignShutConnections(wsrpt, this->reportStepIndex());
249
250 return wsrpt;
251 }
252
253 data::WellBlockAveragePressures wellBlockAveragePressures() const
254 {
255 return this->wbp_.computeWellBlockAveragePressures(this->gravity_);
256 }
257
258#if COMPILE_GPU_BRIDGE
259 // accumulate the contributions of all Wells in the WellContributions object
260 void getWellContributions(WellContributions<Scalar>& x) const;
261#endif
262
263 // Check if well equations is converged.
264 ConvergenceReport getWellConvergence(const std::vector<Scalar>& B_avg, const bool checkWellGroupControlsAndNetwork = false) const;
265
266 const SimulatorReportSingle& lastReport() const;
267
268 void addWellContributions(SparseMatrixAdapter& jacobian) const;
269
270 // add source from wells to the reservoir matrix
272 const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const;
273
274 // called at the beginning of a report step
275 void beginReportStep(const int time_step);
276
280 void calculateExplicitQuantities() const;
281
284 void prepareTimeStep(DeferredLogger& deferred_logger);
285
286 bool
287 updateWellControls(DeferredLogger& deferred_logger);
288
289 void updateAndCommunicate(const int reportStepIdx);
290
291 bool updateGroupControls(const Group& group,
292 DeferredLogger& deferred_logger,
293 const int reportStepIdx);
294
295 static constexpr int numResDofs = Indices::numEq;
296 static constexpr int numWellDofs = numResDofs + 1;//NB will fail for for thermal for now
297 using BMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numResDofs>>;
298 using CMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numResDofs, numWellDofs>>;
299 using DMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numWellDofs>>;
300 using WVector = Dune::BlockVector<Dune::FieldVector<Scalar, numWellDofs>>;
301
302 void addBCDMatrix(std::vector<BMatrix>& b_matrices,
303 std::vector<CMatrix>& c_matrices,
304 std::vector<DMatrix>& d_matrices,
305 Opm::SparseTable<int>& wcells) const;
306
307 const WellInterface<TypeTag>& getWell(const std::string& well_name) const;
308
309 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 1, 1>>;
310
312 const BVector& weights,
313 const bool use_well_weights) const;
316 const BVector& weights,
317 const bool use_well_weights,
318 const int domainIndex) const
319 {
320 if (!nldd_) {
321 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
322 }
323 return nldd_->addWellPressureEquations(jacobian,
324 weights,
325 use_well_weights,
326 domainIndex);
327 }
328
330 const std::vector<WellInterfacePtr>& localNonshutWells() const
331 {
332 return well_container_;
333 }
334
336 {
337 if (!nldd_) {
338 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
339 }
340 return nldd_->well_local_cells();
341 }
342
343 const std::map<std::string, int>& well_domain() const
344 {
345 if (!nldd_) {
346 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
347 }
348
349 return nldd_->well_domain();
350 }
351
352 auto begin() const { return well_container_.begin(); }
353 auto end() const { return well_container_.end(); }
354 bool empty() const { return well_container_.empty(); }
355
358
361
362 int compressedIndexForInterior(int cartesian_cell_idx) const override
363 {
364 return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
365 }
366
367 int compressedIndexForInteriorLGR(const std::string& lgr_tag, const Connection& conn) const override
368 {
369 return simulator_.vanguard().compressedIndexForInteriorLGR(lgr_tag, conn);
370 }
371
372 // using the solution x to recover the solution xw for wells and applying
373 // xw to update Well State
375
376 // using the solution x to recover the solution xw for wells and applying
377 // xw to update Well State
379 const int domainIdx);
380 // Update cellRates_ with contributions from all wells
381 void updateCellRates();
382
383 // Update cellRates_ with contributions from wells in a specific domain
384 void updateCellRatesForDomain(int domainIndex,
385 const std::map<std::string, int>& well_domain_map);
386
387 const Grid& grid() const
388 { return simulator_.vanguard().grid(); }
389
390 const Simulator& simulator() const
391 { return simulator_; }
393 { return simulator_; }
394
396 const BlackoilWellModelNetwork<TypeTag>& network() const { return network_; }
397
398 std::vector<WellInterfacePtr>& wellContainer() { return well_container_; }
399 const std::vector<WellInterfacePtr>& wellContainer() const { return well_container_; }
400
402 { nldd_ = mod; }
403
405 { return guide_rate_handler_; }
406
408 { return guide_rate_handler_; }
409
410 // === Reservoir Coupling ===
411
415
423 void updateGuideRates(const int report_step_idx,
424 const double sim_time)
425 {
426 this->guide_rate_handler_.updateGuideRates(
427 report_step_idx, sim_time, this->wellState(), this->groupState()
428 );
429 }
430
432 bool isReservoirCouplingMaster() const { return rescoup_.isMaster(); }
433
435 bool isReservoirCouplingSlave() const { return rescoup_.isSlave(); }
436
442 bool isReservoirCouplingMasterGroup(const std::string& group_name) const {
443 return rescoup_.isMasterGroup(group_name);
444 }
445
449 return rescoup_.master();
450 }
452 return rescoup_.master();
453 }
454
458 return rescoup_.slave();
459 }
461 return rescoup_.slave();
462 }
463
464#ifdef RESERVOIR_COUPLING_ENABLED
465 void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar>* master)
466 {
467 rescoup_.setMaster(master);
468 this->guide_rate_handler_.setReservoirCouplingMaster(master);
469 this->groupStateHelper().setReservoirCouplingMaster(master);
470 }
471 void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar>* slave)
472 {
473 rescoup_.setSlave(slave);
474 this->guide_rate_handler_.setReservoirCouplingSlave(slave);
475 this->groupStateHelper().setReservoirCouplingSlave(slave);
476 }
477#endif
478
479 bool updateWellControlsAndNetwork(const bool mandatory_network_balance,
480 const double dt,
481 DeferredLogger& local_deferredLogger);
482
483 // TODO: finding a better naming
484 void assembleWellEqWithoutIteration(const double dt);
485
517 void assembleWellEqAtRestoredState(const double dt)
518 {
519 // restore the well primary variables from the (converged) well
520 // state, then the well-local quantities, then assemble --
521 // without touching the group/control state.
522 auto logger_guard = this->groupStateHelper().pushLogger();
526 }
527
528 const std::vector<Scalar>& B_avg() const
529 { return B_avg_; }
530
531 const ModelParameters& param() const
532 { return param_; }
533
539
540#ifdef RESERVOIR_COUPLING_ENABLED
544 BlackoilWellModelRescoup<TypeTag>& rescoupHelper() { return rescoupHelper_; }
545#endif
546
547
548 template<class FluidState, class SingleWellState>
549 static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState& fs, const SingleWellState& ws)
550 {
551 const auto& perf_phase_rate = ws.perf_data.phase_rates;
552 // we only have one temperature pr cell any phaseIdx will do
553 Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
554 Scalar weight_factor = 0.0;
555 for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
556 if (!FluidSystem::phaseIsActive(phaseIdx)) {
557 continue;
558 }
559 Scalar cellInternalEnergy = fs.enthalpy(phaseIdx).value() -
560 fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
561 Scalar cellBinv = fs.invB(phaseIdx).value();
562 Scalar cellDensity = fs.density(phaseIdx).value();
563 Scalar perfPhaseRate = perf_phase_rate[perf_index*np + phaseIdx];
564 weight_factor += cellDensity * (perfPhaseRate / cellBinv) * (cellInternalEnergy / cellTemperatures);
565 }
566 return (std::abs(weight_factor) + 1e-13);
567 }
568
569 protected:
571
572 // a vector of all the wells.
573 std::vector<WellInterfacePtr> well_container_{};
574
575 std::vector<bool> is_cell_perforated_{};
576
577 void initializeWellState(const int timeStepIdx);
578
579 // create the well container
580 void createWellContainer(const int report_step) override;
581
583 createWellPointer(const int wellID,
584 const int report_step) const;
585
586 template <typename WellType>
587 std::unique_ptr<WellType>
588 createTypedWellPointer(const int wellID,
589 const int time_step) const;
590
591 WellInterfacePtr createWellForWellTest(const std::string& well_name,
592 const int report_step,
593 DeferredLogger& deferred_logger) const;
594
596 std::size_t global_num_cells_{};
597 // the number of the cells in the local grid
598 std::size_t local_num_cells_{};
600 std::vector<Scalar> depth_{};
602 std::unique_ptr<RateConverterType> rateConverter_{};
603 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
604
609
610 // A flag to tell the convergence report whether we need to take another newton step
612
613 std::vector<Scalar> B_avg_{};
614
615 const EquilGrid& equilGrid() const
616 { return simulator_.vanguard().equilGrid(); }
617
618 const EclipseState& eclState() const
619 { return simulator_.vanguard().eclState(); }
620
621 // compute the well fluxes and assemble them in to the reservoir equations as source terms
622 // and in the well equations.
623 void assemble(const double dt);
624
625 // collect the statistics for the standalone well solves gathered
626 // since the last call into last_report_ and reset them.
628
629 // Move the wells' solve statistics into pending_solve_stats_; needed
630 // before the well container is rebuilt, which discards them.
631 void stashWellSolveStats();
632 void addSolveStats(const WellInterface<TypeTag>& well);
633
634 // well controls and network pressures affect each other and are solved in an iterative manner.
635 // the function handles one iteration of updating well controls and network pressures.
636 // it is possible to decouple the update of well controls and network pressures further.
637 // the returned two booleans are {continue_due_to_network, well_group_control_changed}, respectively
638 std::tuple<bool, bool, Scalar> updateWellControlsAndNetworkIteration(const bool mandatory_network_balance,
639 const bool relax_network_tolerance,
640 const bool optimize_gas_lift,
641 const double dt,
642 DeferredLogger& local_deferredLogger);
643
654 void initializeLocalWellStructure(const int reportStepIdx,
655 const bool enableWellPIScaling,
656 const bool initializeWellState);
657
661 void initializeGroupStructure(const int reportStepIdx);
662
663 // called at the end of a time step
664 void timeStepSucceeded(const double simulationTime, const double dt);
665
666 // called at the end of a report step
667 void endReportStep();
668
669 // setting the well_solutions_ based on well_state.
671
673
674 void computePotentials(const std::size_t widx,
675 const WellState<Scalar, IndexTraits>& well_state_copy,
676 std::string& exc_msg,
677 ExceptionType::ExcEnum& exc_type) override;
678
679 const std::vector<Scalar>& wellPerfEfficiencyFactors() const;
680
681 void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger) override;
682 void calculateProductivityIndexValues(DeferredLogger& deferred_logger) override;
684 DeferredLogger& deferred_logger);
685
686 // The number of conservation quantities.
687 int numConservationQuantities() const;
688
689 int reportStepIndex() const;
690
691 void assembleWellEq(const double dt);
692
693 void prepareWellsBeforeAssembling(const double dt);
694
696
697 void extractLegacyDepth_();
698
700 void updateWellTestState(const double simulationTime, WellTestState& wellTestState);
701
702 void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger& deferred_logger);
703
704 void calcResvCoeff(const int fipnum,
705 const int pvtreg,
706 const std::vector<Scalar>& production_rates,
707 std::vector<Scalar>& resv_coeff) const override;
708
709 void calcInjResvCoeff(const int fipnum,
710 const int pvtreg,
711 std::vector<Scalar>& resv_coeff) const override;
712
714
715 private:
716 // Private helper methods (alphabetical order)
717 // --------------------------------------------
718
719 void assignWellSpeciesRates_(data::Wells& wsrpt) const;
720 void assignWellTracerRates_(data::Wells& wsrpt) const;
721
730 bool isRescoupCoupledNetworkParticipant_() const;
731
739 bool isRescoupMasterCoupledNetworkIteration_() const;
740
748 bool isRescoupSlaveCoupledNetworkIteration_() const;
749
756 bool isRescoupSlaveOnSyncStepFirstSubstep_() const;
757
766 bool isRescoupSlaveConnectedToMasterNetwork_() const;
767
774 bool maybeSendSlaveGroupFlowToMaster_(const int reportStepIdx);
775
780 void sendSlaveNetworkLoopTerminationSignal_();
781
784 bool shouldDoPreStepNetworkRebalance_(const int episodeIdx) const;
785
787 void updateNetworkActiveState_();
788
791#ifdef RESERVOIR_COUPLING_ENABLED
792 BlackoilWellModelRescoup<TypeTag> rescoupHelper_;
793#endif
794 BlackoilWellModelNldd<TypeTag>* nldd_ = nullptr;
795
796 // These members are used to avoid reallocation in specific functions
797 // instead of using local variables.
798 // Their state is not relevant between function calls, so they can
799 // (and must) be mutable, as the functions using them are const.
800 mutable BVector x_local_;
801
802 // Store cell rates after assembling to avoid iterating all wells and connections for every element
803 std::map<int, RateVector> cellRates_;
804
805 // Cached well solution from the system solver, consumed by
806 // recoverWellSolutionAndUpdateWellState during postSolve.
807 std::optional<WellVector<Scalar>> cachedSystemWellSolution_;
808 std::vector<int> cachedWellDofOffsets_;
809
810 void assignWellTracerRates(data::Wells& wsrpt) const;
811 void assignWellSpeciesRates(data::Wells& wsrpt) const;
812
813 [[nodiscard]] auto rsConstInfo() const
814 -> typename WellState<Scalar,IndexTraits>::RsConstInfo;
815 };
816
817} // namespace Opm
818
819#include "BlackoilWellModel_impl.hpp"
820
821#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:100
const WellState< Scalar, IndexTraits > & wellState() const
Definition: BlackoilWellModelGeneric.hpp:159
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:413
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:308
bool network_needs_more_balancing_force_another_newton_iteration_
Definition: BlackoilWellModel.hpp:611
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numWellDofs > > DMatrix
Definition: BlackoilWellModel.hpp:299
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:2340
ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster()
Get reference to reservoir coupling master.
Definition: BlackoilWellModel.hpp:448
void endTimeStep()
Definition: BlackoilWellModel.hpp:174
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2160
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:1403
static constexpr bool has_bioeffects_
Definition: BlackoilWellModel.hpp:130
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numResDofs > > BMatrix
Definition: BlackoilWellModel.hpp:297
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:1126
GuideRateHandler< Scalar, IndexTraits > guide_rate_handler_
Definition: BlackoilWellModel.hpp:607
const EclipseState & eclState() const
Definition: BlackoilWellModel.hpp:618
void prepareWellsBeforeAssembling(const double dt)
Definition: BlackoilWellModel_impl.hpp:1526
const std::vector< WellInterfacePtr > & localNonshutWells() const
Get list of local nonshut wells.
Definition: BlackoilWellModel.hpp:330
void prepareDeserialize(const int report_step)
Definition: BlackoilWellModel.hpp:207
void init()
Definition: BlackoilWellModel_impl.hpp:166
void setNlddAdapter(BlackoilWellModelNldd< TypeTag > *mod)
Definition: BlackoilWellModel.hpp:401
const Simulator & simulator() const
Definition: BlackoilWellModel.hpp:390
std::vector< Scalar > depth_
Definition: BlackoilWellModel.hpp:600
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:596
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:110
const std::vector< Scalar > & B_avg() const
Definition: BlackoilWellModel.hpp:528
SimulatorReportSingle last_report_
Definition: BlackoilWellModel.hpp:605
static const int solventSaturationIdx
Definition: BlackoilWellModel.hpp:123
Scalar gravity_
Definition: BlackoilWellModel.hpp:599
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:185
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:202
static constexpr int numResDofs
Definition: BlackoilWellModel.hpp:295
const WellInterface< TypeTag > & getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2312
bool useTightRcNetworkCoupling() const
True when tight (per-sub-iteration) reservoir-coupling network coupling is in effect....
Definition: BlackoilWellModel.hpp:537
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:432
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:134
const BlackoilWellModelNetwork< TypeTag > & network() const
Definition: BlackoilWellModel.hpp:396
void initFromRestartFile(const RestartValue &restartValues)
Definition: BlackoilWellModel.hpp:198
const ModelParameters param_
Definition: BlackoilWellModel.hpp:595
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:296
int numConservationQuantities() const
Definition: BlackoilWellModel_impl.hpp:2281
const std::map< std::string, int > & well_domain() const
Definition: BlackoilWellModel.hpp:343
const ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave() const
Definition: BlackoilWellModel.hpp:460
bool updateWellControls(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1823
void endIteration()
Definition: BlackoilWellModel.hpp:171
static constexpr bool has_polymer_
Definition: BlackoilWellModel.hpp:125
WellInterface< TypeTag >::WellSolveStats pending_solve_stats_
Definition: BlackoilWellModel.hpp:606
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2328
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2102
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2300
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2265
std::vector< WellInterfacePtr > & wellContainer()
Definition: BlackoilWellModel.hpp:398
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const int domainIdx)
Definition: BlackoilWellModel_impl.hpp:1744
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2208
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:109
BlackoilWellModel(Simulator &simulator, const NewtonIterationContext &iter_ctx)
Definition: BlackoilWellModel_impl.hpp:73
bool isReservoirCouplingSlave() const
Check if this process is a reservoir coupling slave.
Definition: BlackoilWellModel.hpp:435
const ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster() const
Definition: BlackoilWellModel.hpp:451
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:828
const Grid & grid() const
Definition: BlackoilWellModel.hpp:387
void updatePrimaryVariables()
Definition: BlackoilWellModel_impl.hpp:2256
const ReservoirCoupling::Proxy< Scalar > & rescoup() const
Definition: BlackoilWellModel.hpp:414
BlackOilPolymerModule< TypeTag, has_polymer_ > PolymerModule
Definition: BlackoilWellModel.hpp:137
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2362
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:1648
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:688
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1337
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:517
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1625
const EquilGrid & equilGrid() const
Definition: BlackoilWellModel.hpp:615
void assembleWellEq(const double dt)
Definition: BlackoilWellModel_impl.hpp:1514
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1177
GetPropType< TypeTag, Properties::Indices > Indices
Definition: BlackoilWellModel.hpp:108
int compressedIndexForInteriorLGR(const std::string &lgr_tag, const Connection &conn) const override
Definition: BlackoilWellModel.hpp:367
void calculateExplicitQuantities() const
Definition: BlackoilWellModel_impl.hpp:1808
BlackoilWellModelNetwork< TypeTag > & network()
Definition: BlackoilWellModel.hpp:395
Dune::BlockVector< Dune::FieldVector< Scalar, numWellDofs > > WVector
Definition: BlackoilWellModel.hpp:300
std::vector< WellInterfacePtr > well_container_
Definition: BlackoilWellModel.hpp:573
void collectWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1292
static constexpr std::size_t pressureVarIndex
Definition: BlackoilWellModel.hpp:120
void updateAndCommunicate(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1921
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:309
void updateFailed()
Definition: BlackoilWellModel_impl.hpp:597
bool empty() const
Definition: BlackoilWellModel.hpp:354
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:791
void stashWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1308
bool addMatrixContributions() const
Definition: BlackoilWellModel.hpp:356
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:340
std::vector< Scalar > B_avg_
Definition: BlackoilWellModel.hpp:613
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:1948
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling, const bool initializeWellState)
Definition: BlackoilWellModel_impl.hpp:254
std::map< std::string, std::unique_ptr< AverageRegionalPressureType > > regionalAveragePressureCalculator_
Definition: BlackoilWellModel.hpp:603
void calcInjResvCoeff(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2351
static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState &fs, const SingleWellState &ws)
Definition: BlackoilWellModel.hpp:549
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: BlackoilWellModel.hpp:112
GuideRateHandler< Scalar, IndexTraits > & guideRateHandler()
Definition: BlackoilWellModel.hpp:404
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:602
const SparseTable< int > & well_local_cells() const
Definition: BlackoilWellModel.hpp:335
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:612
std::vector< bool > is_cell_perforated_
Definition: BlackoilWellModel.hpp:575
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControlsAndNetwork=false) const
Definition: BlackoilWellModel_impl.hpp:1757
int numStrictIterations() const
Definition: BlackoilWellModel.hpp:359
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:1572
data::WellBlockAveragePressures wellBlockAveragePressures() const
Definition: BlackoilWellModel.hpp:253
void assembleWellEqWithoutIteration(const double dt)
Definition: BlackoilWellModel_impl.hpp:1540
void updateCellRates()
Definition: BlackoilWellModel_impl.hpp:1560
void assemble(const double dt)
Definition: BlackoilWellModel_impl.hpp:1202
auto begin() const
Definition: BlackoilWellModel.hpp:352
std::size_t local_num_cells_
Definition: BlackoilWellModel.hpp:598
auto end() const
Definition: BlackoilWellModel.hpp:353
BlackOilBioeffectsModule< TypeTag, has_bioeffects_ > BioeffectsModule
Definition: BlackoilWellModel.hpp:138
bool alternative_well_rate_init_
Definition: BlackoilWellModel.hpp:601
Simulator & simulator()
Definition: BlackoilWellModel.hpp:392
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:698
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1146
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:2067
Simulator & simulator_
Definition: BlackoilWellModel.hpp:570
void updateGuideRates(const int report_step_idx, const double sim_time)
Update guide rates for all wells and groups.
Definition: BlackoilWellModel.hpp:423
ReservoirCoupling::Proxy< Scalar > rescoup_
Definition: BlackoilWellModel.hpp:608
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:871
std::unique_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:195
ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave()
Get reference to reservoir coupling slave.
Definition: BlackoilWellModel.hpp:457
data::Wells wellData() const
Definition: BlackoilWellModel.hpp:213
const ModelParameters & param() const
Definition: BlackoilWellModel.hpp:531
void updateWellTestState(const double simulationTime, WellTestState &wellTestState)
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:1993
void addWellPressureEquationsDomain(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights, const int domainIndex) const
Definition: BlackoilWellModel.hpp:315
bool isReservoirCouplingMasterGroup(const std::string &group_name) const
Check if a group is a reservoir coupling master group.
Definition: BlackoilWellModel.hpp:442
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:1634
const GuideRateHandler< Scalar, IndexTraits > & guideRateHandler() const
Definition: BlackoilWellModel.hpp:407
void addSolveStats(const WellInterface< TypeTag > &well)
Definition: BlackoilWellModel_impl.hpp:1318
void addReservoirSourceTerms(GlobalEqVector &residual, const std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1670
int compressedIndexForInterior(int cartesian_cell_idx) const override
get compressed index for interior cells (-1, otherwise
Definition: BlackoilWellModel.hpp:362
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numResDofs, numWellDofs > > CMatrix
Definition: BlackoilWellModel.hpp:298
static constexpr bool has_energy_
Definition: BlackoilWellModel.hpp:127
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1720
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1700
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2116
void advanceTimeLevel()
Definition: BlackoilWellModel_impl.hpp:605
const std::vector< WellInterfacePtr > & wellContainer() const
Definition: BlackoilWellModel.hpp:399
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:671
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