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/common/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;
90
91#if COMPILE_GPU_BRIDGE
92template<class Scalar> class WellContributions;
93#endif
94
96 template<typename TypeTag>
97 class BlackoilWellModel : public WellConnectionAuxiliaryModule<TypeTag, BlackoilWellModel<TypeTag>>
98 , public BlackoilWellModelGeneric<GetPropType<TypeTag, Properties::Scalar>,
99 typename GetPropType<TypeTag, Properties::FluidSystem>::IndexTraitsType>
100 {
101 public:
102 // --------- Types ---------
114
116 using IndexTraits = typename FluidSystem::IndexTraitsType;
118
120
121 static const int numEq = Indices::numEq;
122 static const int solventSaturationIdx = Indices::solventSaturationIdx;
123 static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
124 static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
125 static constexpr EnergyModules energyModuleType_ = getPropValue<TypeTag, Properties::EnergyModuleType>();
126 static constexpr bool has_energy_ = (energyModuleType_ == EnergyModules::FullyImplicitThermal);
127 static constexpr bool has_micp_ = Indices::enableMICP;
128 static constexpr bool has_geochem_ = getPropValue<TypeTag, Properties::EnableGeochemistry>();
129 static constexpr bool has_bioeffects_ = getPropValue<TypeTag, Properties::EnableBioeffects>();
130
131 // TODO: where we should put these types, WellInterface or Well Model?
132 // or there is some other strategy, like TypeTag
133 using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
134 using BVector = Dune::BlockVector<VectorBlockType>;
135
136 using PolymerModule = BlackOilPolymerModule<TypeTag, has_polymer_>;
137 using BioeffectsModule = BlackOilBioeffectsModule<TypeTag, has_bioeffects_>;
138
139 // For the conversion between the surface volume rate and reservoir voidage rate
140 using RateConverterType = RateConverter::
141 SurfaceToReservoirVoidage<FluidSystem, std::vector<int> >;
142
143 // For computing average pressured used by gpmaint
144 using AverageRegionalPressureType = RegionAverageCalculator::
145 AverageRegionalPressure<FluidSystem, std::vector<int> >;
146
148
149 void init();
150 void initWellContainer(const int reportStepIdx) override;
151
153 {
154 OPM_TIMEBLOCK(beginEpsiode);
155 beginReportStep(simulator_.episodeIndex());
156 }
157
158 void beginTimeStep();
159
160 void updateFailed();
161
162 void advanceTimeLevel();
163
165 {
166 OPM_TIMEBLOCK(beginIteration);
167 assemble(simulator_.timeStepSize());
168 }
169
171 { }
172
174 {
175 OPM_TIMEBLOCK(endTimeStep);
176 timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
177 }
178
180 {
182 }
183
185 unsigned globalIdx) const;
186
187 template <class Context>
189 const Context& context,
190 unsigned spaceIdx,
191 unsigned timeIdx) const;
192
193
194 using WellInterfacePtr = std::unique_ptr<WellInterface<TypeTag>>;
195
197 void initFromRestartFile(const RestartValue& restartValues)
198 {
199 initFromRestartFile(restartValues,
200 this->simulator_.vanguard().transferWTestState(),
201 grid().size(0),
202 this->simulator_.vanguard().enableDistributedWells());
203 }
204
206 void prepareDeserialize(const int report_step)
207 {
208 prepareDeserialize(report_step, grid().size(0),
209 this->simulator_.vanguard().enableDistributedWells());
210 }
211
212 data::Wells wellData() const
213 {
214 auto wsrpt = this->wellState()
215 .report(this->simulator_.vanguard().globalCell().data(),
216 [this](const std::size_t well_index)
217 { return this->wasDynamicallyShutThisTimeStep(well_index); },
218 this->rsConstInfo());
219
221 .assignWellGuideRates(wsrpt, this->reportStepIndex());
222
223 this->assignWellTracerRates_(wsrpt);
224
225 if constexpr (has_geochem_) {
226 this->assignWellSpeciesRates_(wsrpt);
227 }
228
229 if (const auto& rspec = eclState().runspec();
230 rspec.co2Storage() || rspec.h2Storage())
231 {
232 // The gas reference density (surface condition) is the
233 // same for all PVT regions in CO2STORE/H2STORE runs so,
234 // for simplicity, we use region zero (0) here.
235
236 this->assignMassGasRate(wsrpt, FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, 0));
237 }
238
239 this->assignWellTargets(wsrpt);
240
241 this->assignDynamicWellStatus(wsrpt);
242
244
245 // Assigning (a subset of the) property values in shut
246 // connections should be the last step of wellData().
247 this->assignShutConnections(wsrpt, this->reportStepIndex());
248
249 return wsrpt;
250 }
251
252 data::WellBlockAveragePressures wellBlockAveragePressures() const
253 {
254 return this->wbp_.computeWellBlockAveragePressures(this->gravity_);
255 }
256
257#if COMPILE_GPU_BRIDGE
258 // accumulate the contributions of all Wells in the WellContributions object
259 void getWellContributions(WellContributions<Scalar>& x) const;
260#endif
261
262 // Check if well equations is converged.
263 ConvergenceReport getWellConvergence(const std::vector<Scalar>& B_avg, const bool checkWellGroupControlsAndNetwork = false) const;
264
265 const SimulatorReportSingle& lastReport() const;
266
267 void addWellContributions(SparseMatrixAdapter& jacobian) const;
268
269 // add source from wells to the reservoir matrix
271 const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const;
272
273 // called at the beginning of a report step
274 void beginReportStep(const int time_step);
275
279 void calculateExplicitQuantities() const;
280
283 void prepareTimeStep(DeferredLogger& deferred_logger);
284
285 bool
286 updateWellControls(DeferredLogger& deferred_logger);
287
288 void updateAndCommunicate(const int reportStepIdx);
289
290 bool updateGroupControls(const Group& group,
291 DeferredLogger& deferred_logger,
292 const int reportStepIdx);
293
294 static constexpr int numResDofs = Indices::numEq;
295 static constexpr int numWellDofs = numResDofs + 1;//NB will fail for for thermal for now
296 using BMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numResDofs>>;
297 using CMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numResDofs, numWellDofs>>;
298 using DMatrix = Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numWellDofs, numWellDofs>>;
299 using WVector = Dune::BlockVector<Dune::FieldVector<Scalar, numWellDofs>>;
300
301 void addBCDMatrix(std::vector<BMatrix>& b_matrices,
302 std::vector<CMatrix>& c_matrices,
303 std::vector<DMatrix>& d_matrices,
304 Opm::SparseTable<int>& wcells) const;
305
306 const WellInterface<TypeTag>& getWell(const std::string& well_name) const;
307
308 using PressureMatrix = Dune::BCRSMatrix<Opm::MatrixBlock<Scalar, 1, 1>>;
309
311 const BVector& weights,
312 const bool use_well_weights,
313 const bool contract_d_diagonal) const;
316 const BVector& weights,
317 const bool use_well_weights,
318 const bool contract_d_diagonal,
319 const int domainIndex) const
320 {
321 if (!nldd_) {
322 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
323 }
324 return nldd_->addWellPressureEquations(jacobian,
325 weights,
326 use_well_weights,
327 contract_d_diagonal,
329 }
330
332 const std::vector<WellInterfacePtr>& localNonshutWells() const
333 {
334 return well_container_;
335 }
336
337 const SparseTable<int>& well_local_cells() const
338 {
339 if (!nldd_) {
340 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
341 }
342 return nldd_->well_local_cells();
343 }
344
345 const std::map<std::string, int>& well_domain() const
346 {
347 if (!nldd_) {
348 OPM_THROW(std::logic_error, "Attempt to access NLDD data without a NLDD solver");
349 }
350
351 return nldd_->well_domain();
352 }
353
354 auto begin() const { return well_container_.begin(); }
355 auto end() const { return well_container_.end(); }
356 bool empty() const { return well_container_.empty(); }
357
360
363
364 int compressedIndexForInterior(int cartesian_cell_idx) const override
365 {
366 return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
367 }
368
369 int compressedIndexForInteriorLGR(const std::string& lgr_tag, const Connection& conn) const override
370 {
371 return simulator_.vanguard().compressedIndexForInteriorLGR(lgr_tag, conn);
372 }
373
374 // using the solution x to recover the solution xw for wells and applying
375 // xw to update Well State
377
378 // using the solution x to recover the solution xw for wells and applying
379 // xw to update Well State
381 const int domainIdx);
382 // Update cellRates_ with contributions from all wells
383 void updateCellRates();
384
385 // Update cellRates_ with contributions from wells in a specific domain
387 const std::map<std::string, int>& well_domain_map);
388
389 // Add the rates of wells outside a domain that perforate its
390 // overlap cells, as constant sources, to cellRates_.
392 const std::map<std::string, int>& well_domain_map,
393 const std::vector<int>& domain_cells,
394 const std::vector<bool>& interior);
395
396 const Grid& grid() const
397 { return simulator_.vanguard().grid(); }
398
399 const Simulator& simulator() const
400 { return simulator_; }
402 { return simulator_; }
403
405 const BlackoilWellModelNetwork<TypeTag>& network() const { return network_; }
406
407 std::vector<WellInterfacePtr>& wellContainer() { return well_container_; }
408 const std::vector<WellInterfacePtr>& wellContainer() const { return well_container_; }
409
411 { nldd_ = mod; }
412
414 { return guide_rate_handler_; }
415
417 { return guide_rate_handler_; }
418
419 // === Reservoir Coupling ===
420
424
432 void updateGuideRates(const int report_step_idx,
433 const double sim_time)
434 {
435 this->guide_rate_handler_.updateGuideRates(
436 report_step_idx, sim_time, this->wellState(), this->groupState()
437 );
438 }
439
441 bool isReservoirCouplingMaster() const { return rescoup_.isMaster(); }
442
444 bool isReservoirCouplingSlave() const { return rescoup_.isSlave(); }
445
451 bool isReservoirCouplingMasterGroup(const std::string& group_name) const {
452 return rescoup_.isMasterGroup(group_name);
453 }
454
458 return rescoup_.master();
459 }
461 return rescoup_.master();
462 }
463
467 return rescoup_.slave();
468 }
470 return rescoup_.slave();
471 }
472
473#ifdef RESERVOIR_COUPLING_ENABLED
474 void setReservoirCouplingMaster(ReservoirCouplingMaster<Scalar>* master)
475 {
476 rescoup_.setMaster(master);
477 this->guide_rate_handler_.setReservoirCouplingMaster(master);
478 this->groupStateHelper().setReservoirCouplingMaster(master);
479 }
480 void setReservoirCouplingSlave(ReservoirCouplingSlave<Scalar>* slave)
481 {
482 rescoup_.setSlave(slave);
483 this->guide_rate_handler_.setReservoirCouplingSlave(slave);
484 this->groupStateHelper().setReservoirCouplingSlave(slave);
485 }
486#endif
487
488 bool updateWellControlsAndNetwork(const bool mandatory_network_balance,
489 const double dt,
490 DeferredLogger& local_deferredLogger);
491
492 // TODO: finding a better naming
493 void assembleWellEqWithoutIteration(const double dt);
494
526 void assembleWellEqAtRestoredState(const double dt)
527 {
528 // restore the well primary variables from the (converged) well
529 // state, then the well-local quantities, then assemble --
530 // without touching the group/control state.
531 auto logger_guard = this->groupStateHelper().pushLogger();
535 }
536
537 const std::vector<Scalar>& B_avg() const
538 { return B_avg_; }
539
540 const ModelParameters& param() const
541 { return param_; }
542
548
549#ifdef RESERVOIR_COUPLING_ENABLED
553 BlackoilWellModelRescoup<TypeTag>& rescoupHelper() { return rescoupHelper_; }
554#endif
555
556
557 template<class FluidState, class SingleWellState>
558 static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState& fs, const SingleWellState& ws)
559 {
560 const auto& perf_phase_rate = ws.perf_data.phase_rates;
561 // we only have one temperature pr cell any phaseIdx will do
562 Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
563 Scalar weight_factor = 0.0;
564 for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
565 if (!FluidSystem::phaseIsActive(phaseIdx)) {
566 continue;
567 }
568 Scalar cellInternalEnergy = fs.enthalpy(phaseIdx).value() -
569 fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
570 Scalar cellBinv = fs.invB(phaseIdx).value();
571 Scalar cellDensity = fs.density(phaseIdx).value();
572 Scalar perfPhaseRate = perf_phase_rate[perf_index*np + phaseIdx];
573 weight_factor += cellDensity * (perfPhaseRate / cellBinv) * (cellInternalEnergy / cellTemperatures);
574 }
575 return (std::abs(weight_factor) + 1e-13);
576 }
577
578 protected:
580
581 // a vector of all the wells.
582 std::vector<WellInterfacePtr> well_container_{};
583
584 std::vector<bool> is_cell_perforated_{};
585
586 void initializeWellState(const int timeStepIdx);
587
588 // create the well container
589 void createWellContainer(const int report_step) override;
590
592 createWellPointer(const int wellID,
593 const int report_step) const;
594
595 template <typename WellType>
596 std::unique_ptr<WellType>
597 createTypedWellPointer(const int wellID,
598 const int time_step) const;
599
600 WellInterfacePtr createWellForWellTest(const std::string& well_name,
601 const int report_step,
602 DeferredLogger& deferred_logger) const;
603
605 std::size_t global_num_cells_{};
606 // the number of the cells in the local grid
607 std::size_t local_num_cells_{};
609 std::vector<Scalar> depth_{};
611 std::unique_ptr<RateConverterType> rateConverter_{};
612 std::map<std::string, std::unique_ptr<AverageRegionalPressureType>> regionalAveragePressureCalculator_{};
613
618
619 // A flag to tell the convergence report whether we need to take another newton step
621
622 std::vector<Scalar> B_avg_{};
623
624 const EquilGrid& equilGrid() const
625 { return simulator_.vanguard().equilGrid(); }
626
627 const EclipseState& eclState() const
628 { return simulator_.vanguard().eclState(); }
629
630 // compute the well fluxes and assemble them in to the reservoir equations as source terms
631 // and in the well equations.
632 void assemble(const double dt);
633
634 // collect the statistics for the standalone well solves gathered
635 // since the last call into last_report_ and reset them.
637
638 // Move the wells' solve statistics into pending_solve_stats_; needed
639 // before the well container is rebuilt, which discards them.
640 void stashWellSolveStats();
641 void addSolveStats(const WellInterface<TypeTag>& well);
642
643 // well controls and network pressures affect each other and are solved in an iterative manner.
644 // the function handles one iteration of updating well controls and network pressures.
645 // it is possible to decouple the update of well controls and network pressures further.
646 // the returned two booleans are {continue_due_to_network, well_group_control_changed}, respectively
647 std::tuple<bool, bool, Scalar> updateWellControlsAndNetworkIteration(const bool mandatory_network_balance,
648 const bool relax_network_tolerance,
649 const bool optimize_gas_lift,
650 const double dt,
651 DeferredLogger& local_deferredLogger);
652
663 void initializeLocalWellStructure(const int reportStepIdx,
664 const bool enableWellPIScaling,
665 const bool initializeWellState);
666
670 void initializeGroupStructure(const int reportStepIdx);
671
672 // called at the end of a time step
673 void timeStepSucceeded(const double simulationTime, const double dt);
674
675 // called at the end of a report step
676 void endReportStep();
677
678 // setting the well_solutions_ based on well_state.
680
682
683 void computePotentials(const std::size_t widx,
684 const WellState<Scalar, IndexTraits>& well_state_copy,
685 std::string& exc_msg,
686 ExceptionType::ExcEnum& exc_type) override;
687
688 const std::vector<Scalar>& wellPerfEfficiencyFactors() const;
689
690 void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger) override;
691 void calculateProductivityIndexValues(DeferredLogger& deferred_logger) override;
693 DeferredLogger& deferred_logger);
694
695 // The number of conservation quantities.
696 int numConservationQuantities() const;
697
698 int reportStepIndex() const;
699
700 void assembleWellEq(const double dt);
701
702 void prepareWellsBeforeAssembling(const double dt);
703
705
706 void extractLegacyDepth_();
707
709 void updateWellTestState(const double simulationTime, WellTestState& wellTestState);
710
711 void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger& deferred_logger);
712
713 void calcResvCoeff(const int fipnum,
714 const int pvtreg,
715 const std::vector<Scalar>& production_rates,
716 std::vector<Scalar>& resv_coeff) const override;
717
718 void calcInjResvCoeff(const int fipnum,
719 const int pvtreg,
720 std::vector<Scalar>& resv_coeff) const override;
721
723
724 private:
725 // Private helper methods (alphabetical order)
726 // --------------------------------------------
727
728 void assignWellSpeciesRates_(data::Wells& wsrpt) const;
729 void assignWellTracerRates_(data::Wells& wsrpt) const;
730
739 bool isRescoupCoupledNetworkParticipant_() const;
740
748 bool isRescoupMasterCoupledNetworkIteration_() const;
749
757 bool isRescoupSlaveCoupledNetworkIteration_() const;
758
765 bool isRescoupSlaveOnSyncStepFirstSubstep_() const;
766
775 bool isRescoupSlaveConnectedToMasterNetwork_() const;
776
783 bool maybeSendSlaveGroupFlowToMaster_(const int reportStepIdx);
784
789 void sendSlaveNetworkLoopTerminationSignal_();
790
793 bool shouldDoPreStepNetworkRebalance_(const int episodeIdx) const;
794
796 void updateNetworkActiveState_();
797
800#ifdef RESERVOIR_COUPLING_ENABLED
801 BlackoilWellModelRescoup<TypeTag> rescoupHelper_;
802#endif
803 BlackoilWellModelNldd<TypeTag>* nldd_ = nullptr;
804
805 // These members are used to avoid reallocation in specific functions
806 // instead of using local variables.
807 // Their state is not relevant between function calls, so they can
808 // (and must) be mutable, as the functions using them are const.
809 mutable BVector x_local_;
810
811 // Store cell rates after assembling to avoid iterating all wells and connections for every element
812 std::map<int, RateVector> cellRates_;
813
814 // Cached well solution from the system solver, consumed by
815 // recoverWellSolutionAndUpdateWellState during postSolve.
816 std::optional<WellVector<Scalar>> cachedSystemWellSolution_;
817 std::vector<int> cachedWellDofOffsets_;
818
819 void assignWellTracerRates(data::Wells& wsrpt) const;
820 void assignWellSpeciesRates(data::Wells& wsrpt) const;
821
822 [[nodiscard]] auto rsConstInfo() const
823 -> typename WellState<Scalar,IndexTraits>::RsConstInfo;
824 };
825
826} // namespace Opm
827
828#include "BlackoilWellModel_impl.hpp"
829
830#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:101
const WellState< Scalar, IndexTraits > & wellState() const
Definition: BlackoilWellModelGeneric.hpp:160
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:100
ReservoirCoupling::Proxy< Scalar > & rescoup()
Get the reservoir coupling proxy.
Definition: BlackoilWellModel.hpp:422
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:309
bool network_needs_more_balancing_force_another_newton_iteration_
Definition: BlackoilWellModel.hpp:620
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numWellDofs > > DMatrix
Definition: BlackoilWellModel.hpp:298
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:2367
ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster()
Get reference to reservoir coupling master.
Definition: BlackoilWellModel.hpp:457
void endTimeStep()
Definition: BlackoilWellModel.hpp:173
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2187
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:1405
static constexpr bool has_bioeffects_
Definition: BlackoilWellModel.hpp:129
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numWellDofs, numResDofs > > BMatrix
Definition: BlackoilWellModel.hpp:296
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:1122
GuideRateHandler< Scalar, IndexTraits > guide_rate_handler_
Definition: BlackoilWellModel.hpp:616
const EclipseState & eclState() const
Definition: BlackoilWellModel.hpp:627
void prepareWellsBeforeAssembling(const double dt)
Definition: BlackoilWellModel_impl.hpp:1528
const std::vector< WellInterfacePtr > & localNonshutWells() const
Get list of local nonshut wells.
Definition: BlackoilWellModel.hpp:332
void prepareDeserialize(const int report_step)
Definition: BlackoilWellModel.hpp:206
void init()
Definition: BlackoilWellModel_impl.hpp:167
void setNlddAdapter(BlackoilWellModelNldd< TypeTag > *mod)
Definition: BlackoilWellModel.hpp:410
const Simulator & simulator() const
Definition: BlackoilWellModel.hpp:399
std::vector< Scalar > depth_
Definition: BlackoilWellModel.hpp:609
static constexpr bool has_geochem_
Definition: BlackoilWellModel.hpp:128
static constexpr EnergyModules energyModuleType_
Definition: BlackoilWellModel.hpp:125
std::size_t global_num_cells_
Definition: BlackoilWellModel.hpp:605
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:109
const std::vector< Scalar > & B_avg() const
Definition: BlackoilWellModel.hpp:537
SimulatorReportSingle last_report_
Definition: BlackoilWellModel.hpp:614
static const int solventSaturationIdx
Definition: BlackoilWellModel.hpp:122
void addConstantCellRatesForOverlap(int domainIndex, const std::map< std::string, int > &well_domain_map, const std::vector< int > &domain_cells, const std::vector< bool > &interior)
Definition: BlackoilWellModel_impl.hpp:1589
Scalar gravity_
Definition: BlackoilWellModel.hpp:608
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:186
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:203
static constexpr int numResDofs
Definition: BlackoilWellModel.hpp:294
const WellInterface< TypeTag > & getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2339
bool useTightRcNetworkCoupling() const
True when tight (per-sub-iteration) reservoir-coupling network coupling is in effect....
Definition: BlackoilWellModel.hpp:546
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: BlackoilWellModel.hpp:105
void beginIteration()
Definition: BlackoilWellModel.hpp:164
bool isReservoirCouplingMaster() const
Check if this process is a reservoir coupling master.
Definition: BlackoilWellModel.hpp:441
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:133
const BlackoilWellModelNetwork< TypeTag > & network() const
Definition: BlackoilWellModel.hpp:405
void initFromRestartFile(const RestartValue &restartValues)
Definition: BlackoilWellModel.hpp:197
const ModelParameters param_
Definition: BlackoilWellModel.hpp:604
void beginEpisode()
Definition: BlackoilWellModel.hpp:152
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilWellModel.hpp:106
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilWellModel.hpp:103
GetPropType< TypeTag, Properties::EquilGrid > EquilGrid
Definition: BlackoilWellModel.hpp:104
static constexpr int numWellDofs
Definition: BlackoilWellModel.hpp:295
int numConservationQuantities() const
Definition: BlackoilWellModel_impl.hpp:2308
const std::map< std::string, int > & well_domain() const
Definition: BlackoilWellModel.hpp:345
const ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave() const
Definition: BlackoilWellModel.hpp:469
bool updateWellControls(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1850
void endIteration()
Definition: BlackoilWellModel.hpp:170
static constexpr bool has_polymer_
Definition: BlackoilWellModel.hpp:124
WellInterface< TypeTag >::WellSolveStats pending_solve_stats_
Definition: BlackoilWellModel.hpp:615
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2355
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2129
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2327
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2292
std::vector< WellInterfacePtr > & wellContainer()
Definition: BlackoilWellModel.hpp:407
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const int domainIdx)
Definition: BlackoilWellModel_impl.hpp:1771
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2235
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:108
BlackoilWellModel(Simulator &simulator, const NewtonIterationContext &iter_ctx)
Definition: BlackoilWellModel_impl.hpp:74
bool isReservoirCouplingSlave() const
Check if this process is a reservoir coupling slave.
Definition: BlackoilWellModel.hpp:444
const ReservoirCouplingMaster< Scalar > & reservoirCouplingMaster() const
Definition: BlackoilWellModel.hpp:460
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:852
const Grid & grid() const
Definition: BlackoilWellModel.hpp:396
void updatePrimaryVariables()
Definition: BlackoilWellModel_impl.hpp:2283
const ReservoirCoupling::Proxy< Scalar > & rescoup() const
Definition: BlackoilWellModel.hpp:423
BlackOilPolymerModule< TypeTag, has_polymer_ > PolymerModule
Definition: BlackoilWellModel.hpp:136
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2389
static const int numEq
Definition: BlackoilWellModel.hpp:121
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:699
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1332
void endEpisode()
Definition: BlackoilWellModel.hpp:179
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: BlackoilWellModel.hpp:112
void assembleWellEqAtRestoredState(const double dt)
Assemble the well equations at an already-converged state that the caller has restored,...
Definition: BlackoilWellModel.hpp:526
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1650
const EquilGrid & equilGrid() const
Definition: BlackoilWellModel.hpp:624
void assembleWellEq(const double dt)
Definition: BlackoilWellModel_impl.hpp:1516
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1173
GetPropType< TypeTag, Properties::Indices > Indices
Definition: BlackoilWellModel.hpp:107
int compressedIndexForInteriorLGR(const std::string &lgr_tag, const Connection &conn) const override
Definition: BlackoilWellModel.hpp:369
void calculateExplicitQuantities() const
Definition: BlackoilWellModel_impl.hpp:1835
BlackoilWellModelNetwork< TypeTag > & network()
Definition: BlackoilWellModel.hpp:404
Dune::BlockVector< Dune::FieldVector< Scalar, numWellDofs > > WVector
Definition: BlackoilWellModel.hpp:299
std::vector< WellInterfacePtr > well_container_
Definition: BlackoilWellModel.hpp:582
void collectWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1287
static constexpr std::size_t pressureVarIndex
Definition: BlackoilWellModel.hpp:119
void updateAndCommunicate(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1948
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:308
void updateFailed()
Definition: BlackoilWellModel_impl.hpp:607
bool empty() const
Definition: BlackoilWellModel.hpp:356
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:815
void stashWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1303
bool addMatrixContributions() const
Definition: BlackoilWellModel.hpp:358
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:341
std::vector< Scalar > B_avg_
Definition: BlackoilWellModel.hpp:622
const std::vector< Scalar > & wellPerfEfficiencyFactors() const
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: BlackoilWellModel.hpp:110
bool updateGroupControls(const Group &group, DeferredLogger &deferred_logger, const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1975
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling, const bool initializeWellState)
Definition: BlackoilWellModel_impl.hpp:255
std::map< std::string, std::unique_ptr< AverageRegionalPressureType > > regionalAveragePressureCalculator_
Definition: BlackoilWellModel.hpp:612
void calcInjResvCoeff(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2378
static Scalar computeTemperatureWeightFactor(const int perf_index, const int np, const FluidState &fs, const SingleWellState &ws)
Definition: BlackoilWellModel.hpp:558
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: BlackoilWellModel.hpp:111
GuideRateHandler< Scalar, IndexTraits > & guideRateHandler()
Definition: BlackoilWellModel.hpp:413
static constexpr bool has_solvent_
Definition: BlackoilWellModel.hpp:123
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilWellModel.hpp:134
static constexpr bool has_micp_
Definition: BlackoilWellModel.hpp:127
std::unique_ptr< RateConverterType > rateConverter_
Definition: BlackoilWellModel.hpp:611
const SparseTable< int > & well_local_cells() const
Definition: BlackoilWellModel.hpp:337
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:622
std::vector< bool > is_cell_perforated_
Definition: BlackoilWellModel.hpp:584
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControlsAndNetwork=false) const
Definition: BlackoilWellModel_impl.hpp:1784
int numStrictIterations() const
Definition: BlackoilWellModel.hpp:361
typename FluidSystem::IndexTraitsType IndexTraits
Definition: BlackoilWellModel.hpp:116
void updateCellRatesForDomain(int domainIndex, const std::map< std::string, int > &well_domain_map)
Definition: BlackoilWellModel_impl.hpp:1574
data::WellBlockAveragePressures wellBlockAveragePressures() const
Definition: BlackoilWellModel.hpp:252
void assembleWellEqWithoutIteration(const double dt)
Definition: BlackoilWellModel_impl.hpp:1542
void updateCellRates()
Definition: BlackoilWellModel_impl.hpp:1562
void assemble(const double dt)
Definition: BlackoilWellModel_impl.hpp:1198
auto begin() const
Definition: BlackoilWellModel.hpp:354
std::size_t local_num_cells_
Definition: BlackoilWellModel.hpp:607
auto end() const
Definition: BlackoilWellModel.hpp:355
BlackOilBioeffectsModule< TypeTag, has_bioeffects_ > BioeffectsModule
Definition: BlackoilWellModel.hpp:137
bool alternative_well_rate_init_
Definition: BlackoilWellModel.hpp:610
Simulator & simulator()
Definition: BlackoilWellModel.hpp:401
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:709
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1142
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:2094
Simulator & simulator_
Definition: BlackoilWellModel.hpp:579
void updateGuideRates(const int report_step_idx, const double sim_time)
Update guide rates for all wells and groups.
Definition: BlackoilWellModel.hpp:432
ReservoirCoupling::Proxy< Scalar > rescoup_
Definition: BlackoilWellModel.hpp:617
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:895
std::unique_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:194
ReservoirCouplingSlave< Scalar > & reservoirCouplingSlave()
Get reference to reservoir coupling slave.
Definition: BlackoilWellModel.hpp:466
data::Wells wellData() const
Definition: BlackoilWellModel.hpp:212
const ModelParameters & param() const
Definition: BlackoilWellModel.hpp:540
void updateWellTestState(const double simulationTime, WellTestState &wellTestState)
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:2020
bool isReservoirCouplingMasterGroup(const std::string &group_name) const
Check if a group is a reservoir coupling master group.
Definition: BlackoilWellModel.hpp:451
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:1659
void addWellPressureEquationsDomain(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights, const bool contract_d_diagonal, const int domainIndex) const
Definition: BlackoilWellModel.hpp:315
const GuideRateHandler< Scalar, IndexTraits > & guideRateHandler() const
Definition: BlackoilWellModel.hpp:416
void addSolveStats(const WellInterface< TypeTag > &well)
Definition: BlackoilWellModel_impl.hpp:1313
void addReservoirSourceTerms(GlobalEqVector &residual, const std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1697
int compressedIndexForInterior(int cartesian_cell_idx) const override
get compressed index for interior cells (-1, otherwise
Definition: BlackoilWellModel.hpp:364
Dune::BCRSMatrix< Dune::FieldMatrix< Scalar, numResDofs, numWellDofs > > CMatrix
Definition: BlackoilWellModel.hpp:297
void addWellPressureEquations(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights, const bool contract_d_diagonal) const
Definition: BlackoilWellModel_impl.hpp:1673
static constexpr bool has_energy_
Definition: BlackoilWellModel.hpp:126
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1747
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1727
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2143
void advanceTimeLevel()
Definition: BlackoilWellModel_impl.hpp:615
const std::vector< WellInterfacePtr > & wellContainer() const
Definition: BlackoilWellModel.hpp:408
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:682
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:375
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:43
Definition: ReservoirCouplingSlave.hpp:40
Definition: SingleWellState.hpp:44
PerfData< Scalar > perf_data
Definition: SingleWellState.hpp:174
Definition: WellConnectionAuxiliaryModule.hpp:39
Definition: WellContributions.hpp:51
Definition: WellInterface.hpp:79
Definition: WellState.hpp:68
ExcEnum
Definition: DeferredLogger.hpp:45
constexpr std::size_t domainIndex(const NetworkDomain domain)
Definition: BlackoilWellModelNetworkGeneric.hpp:60
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:208
bool matrix_add_well_contributions_
Whether to add influences of wells between cells to the matrix and preconditioner matrix.
Definition: BlackoilModelParameters.hpp:322
int strict_outer_iter_wells_
Newton iteration where wells are stricly convergent.
Definition: BlackoilModelParameters.hpp:272
bool rc_network_loose_coupling_
Definition: BlackoilModelParameters.hpp:364
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