BlackoilWellModel_impl.hpp
Go to the documentation of this file.
1/*
2 Copyright 2016 - 2019 SINTEF Digital, Mathematics & Cybernetics.
3 Copyright 2016 - 2018 Equinor ASA.
4 Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
5 Copyright 2016 - 2018 Norce 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// Improve IDE experience
24#ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
25#define OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED
26#include <config.h>
28#endif
29
30#include <opm/grid/utility/cartesianToCompressed.hpp>
31#include <opm/common/utility/numeric/RootFinders.hpp>
32
33#include <opm/input/eclipse/Schedule/Network/Balance.hpp>
34#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
35#include <opm/input/eclipse/Schedule/Well/PAvgDynamicSourceData.hpp>
36#include <opm/input/eclipse/Schedule/Well/WellTestConfig.hpp>
37
38#include <opm/input/eclipse/Units/UnitSystem.hpp>
39
47
51
52#if COMPILE_BDA_BRIDGE
54#endif
55
56#if HAVE_MPI
58#endif
59
60#include <algorithm>
61#include <cassert>
62#include <iomanip>
63#include <utility>
64#include <optional>
65
66#include <fmt/format.h>
67
68namespace Opm {
69 template<typename TypeTag>
71 BlackoilWellModel(Simulator& simulator, const PhaseUsage& phase_usage)
72 : BlackoilWellModelGeneric<Scalar>(simulator.vanguard().schedule(),
73 simulator.vanguard().summaryState(),
74 simulator.vanguard().eclState(),
75 phase_usage,
76 simulator.gridView().comm())
77 , simulator_(simulator)
78 {
79 this->terminal_output_ = (simulator.gridView().comm().rank() == 0)
80 && Parameters::Get<Parameters::EnableTerminalOutput>();
81
82 local_num_cells_ = simulator_.gridView().size(0);
83
84 // Number of cells the global grid view
85 global_num_cells_ = simulator_.vanguard().globalNumCells();
86
87 {
88 auto& parallel_wells = simulator.vanguard().parallelWells();
89
90 this->parallel_well_info_.reserve(parallel_wells.size());
91 for( const auto& name_bool : parallel_wells) {
92 this->parallel_well_info_.emplace_back(name_bool, grid().comm());
93 }
94 }
95
96 this->alternative_well_rate_init_ =
97 Parameters::Get<Parameters::AlternativeWellRateInit>();
98
99 using SourceDataSpan =
100 typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
101
102 this->wbpCalculationService_
103 .localCellIndex([this](const std::size_t globalIndex)
104 { return this->compressedIndexForInterior(globalIndex); })
105 .evalCellSource([this](const int localCell, SourceDataSpan sourceTerms)
106 {
107 using Item = typename SourceDataSpan::Item;
108
109 const auto* intQuants = this->simulator_.model()
110 .cachedIntensiveQuantities(localCell, /*timeIndex = */0);
111 const auto& fs = intQuants->fluidState();
112
113 sourceTerms.set(Item::PoreVol, intQuants->porosity().value() *
114 this->simulator_.model().dofTotalVolume(localCell));
115
116 constexpr auto io = FluidSystem::oilPhaseIdx;
117 constexpr auto ig = FluidSystem::gasPhaseIdx;
118 constexpr auto iw = FluidSystem::waterPhaseIdx;
119
120 // Ideally, these would be 'constexpr'.
121 const auto haveOil = FluidSystem::phaseIsActive(io);
122 const auto haveGas = FluidSystem::phaseIsActive(ig);
123 const auto haveWat = FluidSystem::phaseIsActive(iw);
124
125 auto weightedPhaseDensity = [&fs](const auto ip)
126 {
127 return fs.saturation(ip).value() * fs.density(ip).value();
128 };
129
130 if (haveOil) { sourceTerms.set(Item::Pressure, fs.pressure(io).value()); }
131 else if (haveGas) { sourceTerms.set(Item::Pressure, fs.pressure(ig).value()); }
132 else { sourceTerms.set(Item::Pressure, fs.pressure(iw).value()); }
133
134 // Strictly speaking, assumes SUM(s[p]) == 1.
135 auto rho = 0.0;
136 if (haveOil) { rho += weightedPhaseDensity(io); }
137 if (haveGas) { rho += weightedPhaseDensity(ig); }
138 if (haveWat) { rho += weightedPhaseDensity(iw); }
139
140 sourceTerms.set(Item::MixtureDensity, rho);
141 });
142 }
143
144 template<typename TypeTag>
146 BlackoilWellModel(Simulator& simulator) :
147 BlackoilWellModel(simulator, phaseUsageFromDeck(simulator.vanguard().eclState()))
148 {}
149
150
151 template<typename TypeTag>
152 void
154 init()
155 {
156 extractLegacyCellPvtRegionIndex_();
157 extractLegacyDepth_();
158
159 gravity_ = simulator_.problem().gravity()[2];
160
161 this->initial_step_ = true;
162
163 // add the eWoms auxiliary module for the wells to the list
164 simulator_.model().addAuxiliaryModule(this);
165
166 is_cell_perforated_.resize(local_num_cells_, false);
167 }
168
169
170 template<typename TypeTag>
171 void
173 initWellContainer(const int reportStepIdx)
174 {
175 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
176 + ScheduleEvents::NEW_WELL;
177 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
178 for (auto& wellPtr : this->well_container_) {
179 const bool well_opened_this_step = this->report_step_starts_ && events.hasEvent(wellPtr->name(), effective_events_mask);
180 wellPtr->init(&this->phase_usage_, this->depth_, this->gravity_,
181 this->local_num_cells_, this->B_avg_, well_opened_this_step);
182 }
183 }
184
185
186 template<typename TypeTag>
187 void
189 addNeighbors(std::vector<NeighborSet>& neighbors) const
190 {
191 if (!param_.matrix_add_well_contributions_) {
192 return;
193 }
194
195 // Create cartesian to compressed mapping
196 const auto& schedule_wells = this->schedule().getWellsatEnd();
197 auto possibleFutureConnections = this->schedule().getPossibleFutureConnections();
198
199#if HAVE_MPI
200 // Communicate Map to other processes, since it is only available on rank 0
201 const auto& comm = this->simulator_.vanguard().grid().comm();
202 Parallel::MpiSerializer ser(comm);
203 ser.broadcast(possibleFutureConnections);
204#endif
205 // initialize the additional cell connections introduced by wells.
206 for (const auto& well : schedule_wells)
207 {
208 std::vector<int> wellCells = this->getCellsForConnections(well);
209 // Now add the cells of the possible future connections
210 const auto possibleFutureConnectionSetIt = possibleFutureConnections.find(well.name());
211 if (possibleFutureConnectionSetIt != possibleFutureConnections.end()) {
212 for (auto& global_index : possibleFutureConnectionSetIt->second) {
213 int compressed_idx = compressedIndexForInterior(global_index);
214 if (compressed_idx >= 0) { // Ignore connections in inactive/remote cells.
215 wellCells.push_back(compressed_idx);
216 }
217 }
218 }
219 for (int cellIdx : wellCells) {
220 neighbors[cellIdx].insert(wellCells.begin(),
221 wellCells.end());
222 }
223 }
224 }
225
226
227 template<typename TypeTag>
228 void
230 linearize(SparseMatrixAdapter& jacobian, GlobalEqVector& res)
231 {
233 for (const auto& well: well_container_) {
234 // Modifiy the Jacobian with explicit Schur complement
235 // contributions if requested.
236 if (param_.matrix_add_well_contributions_) {
237 well->addWellContributions(jacobian);
238 }
239 // Apply as Schur complement the well residual to reservoir residuals:
240 // r = r - duneC_^T * invDuneD_ * resWell_
241 well->apply(res);
242 }
243 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::linearize failed: ",
244 simulator_.gridView().comm());
245 }
246
247
248 template<typename TypeTag>
249 void
251 linearizeDomain(const Domain& domain, SparseMatrixAdapter& jacobian, GlobalEqVector& res)
252 {
253 // Note: no point in trying to do a parallel gathering
254 // try/catch here, as this function is not called in
255 // parallel but for each individual domain of each rank.
256 for (const auto& well: well_container_) {
257 if (well_domain_.at(well->name()) == domain.index) {
258 // Modifiy the Jacobian with explicit Schur complement
259 // contributions if requested.
260 if (param_.matrix_add_well_contributions_) {
261 well->addWellContributions(jacobian);
262 }
263 // Apply as Schur complement the well residual to reservoir residuals:
264 // r = r - duneC_^T * invDuneD_ * resWell_
265 well->apply(res);
266 }
267 }
268 }
269
270
271 template<typename TypeTag>
272 void
274 beginReportStep(const int timeStepIdx)
275 {
276 DeferredLogger local_deferredLogger{};
277
278 this->report_step_starts_ = true;
279
280
281 this->rateConverter_ = std::make_unique<RateConverterType>
282 (this->phase_usage_, std::vector<int>(this->local_num_cells_, 0));
283
284 {
285 // WELPI scaling runs at start of report step.
286 const auto enableWellPIScaling = true;
287 this->initializeLocalWellStructure(timeStepIdx, enableWellPIScaling);
288 }
289
290 this->initializeGroupStructure(timeStepIdx);
291
292 const auto& comm = this->simulator_.vanguard().grid().comm();
293
295 {
296 // Create facility for calculating reservoir voidage volumes for
297 // purpose of RESV controls.
298 this->rateConverter_->template defineState<ElementContext>(this->simulator_);
299
300 // Update VFP properties.
301 {
302 const auto& sched_state = this->schedule()[timeStepIdx];
303
304 this->vfp_properties_ = std::make_unique<VFPProperties<Scalar>>
305 (sched_state.vfpinj(), sched_state.vfpprod(), this->wellState());
306 }
307 }
308 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
309 "beginReportStep() failed: ",
310 this->terminal_output_, comm)
311
312 // Store the current well and group states in order to recover in
313 // the case of failed iterations
314 this->commitWGState();
315
316 this->wellStructureChangedDynamically_ = false;
317 }
318
319
320
321
322
323 template <typename TypeTag>
324 void
326 initializeLocalWellStructure(const int reportStepIdx,
327 const bool enableWellPIScaling)
328 {
329 DeferredLogger local_deferredLogger{};
330
331 const auto& comm = this->simulator_.vanguard().grid().comm();
332
333 // Wells_ecl_ holds this rank's wells, both open and stopped/shut.
334 this->wells_ecl_ = this->getLocalWells(reportStepIdx);
335 this->local_parallel_well_info_ =
336 this->createLocalParallelWellInfo(this->wells_ecl_);
337
338 // At least initializeWellState() might be throw an exception in
339 // UniformTabulated2DFunction. Playing it safe by extending the
340 // scope a bit.
342 {
343 this->initializeWellPerfData();
344 this->initializeWellState(reportStepIdx);
345 this->initializeWBPCalculationService();
346
347 if (this->param_.use_multisegment_well_ && this->anyMSWellOpenLocal()) {
348 this->wellState().initWellStateMSWell(this->wells_ecl_, &this->prevWellState());
349 }
350
351 this->initializeWellProdIndCalculators();
352
353 if (enableWellPIScaling && this->schedule()[reportStepIdx].events()
354 .hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX))
355 {
356 this->runWellPIScaling(reportStepIdx, local_deferredLogger);
357 }
358 }
359 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
360 "Failed to initialize local well structure: ",
361 this->terminal_output_, comm)
362 }
363
364
365
366
367
368 template <typename TypeTag>
369 void
371 initializeGroupStructure(const int reportStepIdx)
372 {
373 DeferredLogger local_deferredLogger{};
374
375 const auto& comm = this->simulator_.vanguard().grid().comm();
376
378 {
379 const auto& fieldGroup =
380 this->schedule().getGroup("FIELD", reportStepIdx);
381
383 this->schedule(),
384 this->summaryState(),
385 reportStepIdx,
386 this->groupState());
387
388 // Define per region average pressure calculators for use by
389 // pressure maintenance groups (GPMAINT keyword).
390 if (this->schedule()[reportStepIdx].has_gpmaint()) {
392 (fieldGroup,
393 this->schedule(),
394 reportStepIdx,
395 this->eclState_.fieldProps(),
396 this->phase_usage_,
397 this->regionalAveragePressureCalculator_);
398 }
399 }
400 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
401 "Failed to initialize group structure: ",
402 this->terminal_output_, comm)
403 }
404
405
406
407
408
409 // called at the beginning of a time step
410 template<typename TypeTag>
411 void
414 {
415 OPM_TIMEBLOCK(beginTimeStep);
416
417 this->updateAverageFormationFactor();
418
419 DeferredLogger local_deferredLogger;
420
421 this->switched_prod_groups_.clear();
422 this->switched_inj_groups_.clear();
423
424 if (this->wellStructureChangedDynamically_) {
425 // Something altered the well structure/topology. Possibly
426 // WELSPECS/COMPDAT and/or WELOPEN run from an ACTIONX block.
427 // Reconstruct the local wells to account for the new well
428 // structure.
429 const auto reportStepIdx =
430 this->simulator_.episodeIndex();
431
432 // Disable WELPI scaling when well structure is updated in the
433 // middle of a report step.
434 const auto enableWellPIScaling = false;
435
436 this->initializeLocalWellStructure(reportStepIdx, enableWellPIScaling);
437 this->initializeGroupStructure(reportStepIdx);
438
439 this->commitWGState();
440
441 // Reset topology flag to signal that we've handled this
442 // structure change. That way we don't end up here in
443 // subsequent calls to beginTimeStep() unless there's a new
444 // dynamic change to the well structure during a report step.
445 this->wellStructureChangedDynamically_ = false;
446 }
447
448 this->resetWGState();
449
450 const int reportStepIdx = simulator_.episodeIndex();
451 this->updateAndCommunicateGroupData(reportStepIdx,
452 simulator_.model().newtonMethod().numIterations());
453
454 this->wellState().updateWellsDefaultALQ(this->schedule(), reportStepIdx, this->summaryState());
455 this->wellState().gliftTimeStepInit();
456
457 const double simulationTime = simulator_.time();
459 {
460 // test wells
461 wellTesting(reportStepIdx, simulationTime, local_deferredLogger);
462
463 // create the well container
464 createWellContainer(reportStepIdx);
465
466 // Wells are active if they are active wells on at least one process.
467 const Grid& grid = simulator_.vanguard().grid();
468 this->wells_active_ = grid.comm().max(!this->well_container_.empty());
469
470 // do the initialization for all the wells
471 // TODO: to see whether we can postpone of the intialization of the well containers to
472 // optimize the usage of the following several member variables
473 this->initWellContainer(reportStepIdx);
474
475 // update the updated cell flag
476 std::fill(is_cell_perforated_.begin(), is_cell_perforated_.end(), false);
477 for (auto& well : well_container_) {
478 well->updatePerforatedCell(is_cell_perforated_);
479 }
480
481 // calculate the efficiency factors for each well
482 this->calculateEfficiencyFactors(reportStepIdx);
483
484 if constexpr (has_polymer_)
485 {
486 if (PolymerModule::hasPlyshlog() || getPropValue<TypeTag, Properties::EnablePolymerMW>() ) {
487 this->setRepRadiusPerfLength();
488 }
489 }
490
491 }
492 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger, "beginTimeStep() failed: ",
493 this->terminal_output_, simulator_.vanguard().grid().comm());
494
495 for (auto& well : well_container_) {
496 well->setVFPProperties(this->vfp_properties_.get());
497 well->setGuideRate(&this->guideRate_);
498 }
499
500 this->updateInjFCMult(local_deferredLogger);
501
502 // Close completions due to economic reasons
503 for (auto& well : well_container_) {
504 well->closeCompletions(this->wellTestState());
505 }
506
507 // we need the inj_multiplier from the previous time step
508 this->initInjMult();
509
510 const auto& summaryState = simulator_.vanguard().summaryState();
511 if (alternative_well_rate_init_) {
512 // Update the well rates of well_state_, if only single-phase rates, to
513 // have proper multi-phase rates proportional to rates at bhp zero.
514 // This is done only for producers, as injectors will only have a single
515 // nonzero phase anyway.
516 for (auto& well : well_container_) {
517 const bool zero_target = well->stoppedOrZeroRateTarget(simulator_, this->wellState(), local_deferredLogger);
518 if (well->isProducer() && !zero_target) {
519 well->updateWellStateRates(simulator_, this->wellState(), local_deferredLogger);
520 }
521 }
522 }
523
524 for (auto& well : well_container_) {
525 if (well->isVFPActive(local_deferredLogger)){
526 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
527 }
528 }
529
530 // calculate the well potentials
531 try {
532 this->updateWellPotentials(reportStepIdx,
533 /*onlyAfterEvent*/true,
534 simulator_.vanguard().summaryConfig(),
535 local_deferredLogger);
536 } catch ( std::runtime_error& e ) {
537 const std::string msg = "A zero well potential is returned for output purposes. ";
538 local_deferredLogger.warning("WELL_POTENTIAL_CALCULATION_FAILED", msg);
539 }
540
541 //update guide rates
542 const auto& comm = simulator_.vanguard().grid().comm();
543 std::vector<Scalar> pot(this->numPhases(), 0.0);
544 const Group& fieldGroup = this->schedule().getGroup("FIELD", reportStepIdx);
546 this->schedule(),
547 summaryState,
548 this->phase_usage_,
549 reportStepIdx,
550 simulationTime,
551 this->wellState(),
552 this->groupState(),
553 comm,
554 &this->guideRate_,
555 pot,
556 local_deferredLogger);
557 std::string exc_msg;
558 auto exc_type = ExceptionType::NONE;
559 // update gpmaint targets
560 if (this->schedule_[reportStepIdx].has_gpmaint()) {
561 for (auto& calculator : regionalAveragePressureCalculator_) {
562 calculator.second->template defineState<ElementContext>(simulator_);
563 }
564 const double dt = simulator_.timeStepSize();
566 this->schedule_,
567 regionalAveragePressureCalculator_,
568 reportStepIdx,
569 dt,
570 this->wellState(),
571 this->groupState());
572 }
573 try {
574 // Compute initial well solution for new wells and injectors that change injection type i.e. WAG.
575 for (auto& well : well_container_) {
576 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
577 + ScheduleEvents::INJECTION_TYPE_CHANGED
578 + ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER
579 + ScheduleEvents::NEW_WELL;
580
581 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
582 const bool event = this->report_step_starts_ && events.hasEvent(well->name(), effective_events_mask);
583 const bool dyn_status_change = this->wellState().well(well->name()).status
584 != this->prevWellState().well(well->name()).status;
585
586 if (event || dyn_status_change) {
587 try {
588 well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), local_deferredLogger);
589 well->calculateExplicitQuantities(simulator_, this->wellState(), local_deferredLogger);
590 well->solveWellEquation(simulator_, this->wellState(), this->groupState(), local_deferredLogger);
591 } catch (const std::exception& e) {
592 const std::string msg = "Compute initial well solution for new well " + well->name() + " failed. Continue with zero initial rates";
593 local_deferredLogger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
594 }
595 }
596 }
597 }
598 // Catch clauses for all errors setting exc_type and exc_msg
599 OPM_PARALLEL_CATCH_CLAUSE(exc_type, exc_msg);
600
601 if (exc_type != ExceptionType::NONE) {
602 const std::string msg = "Compute initial well solution for new wells failed. Continue with zero initial rates";
603 local_deferredLogger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
604 }
605
606 logAndCheckForExceptionsAndThrow(local_deferredLogger,
607 exc_type, "beginTimeStep() failed: " + exc_msg, this->terminal_output_, comm);
608
609 }
610
611 template<typename TypeTag>
612 void
614 const double simulationTime,
615 DeferredLogger& deferred_logger)
616 {
617 for (const std::string& well_name : this->getWellsForTesting(timeStepIdx, simulationTime)) {
618 const Well& wellEcl = this->schedule().getWell(well_name, timeStepIdx);
619 if (wellEcl.getStatus() == Well::Status::SHUT)
620 continue;
621
622 WellInterfacePtr well = createWellForWellTest(well_name, timeStepIdx, deferred_logger);
623 // some preparation before the well can be used
624 well->init(&this->phase_usage_, depth_, gravity_, local_num_cells_, B_avg_, true);
625
626 Scalar well_efficiency_factor = wellEcl.getEfficiencyFactor();
627 WellGroupHelpers<Scalar>::accumulateGroupEfficiencyFactor(this->schedule().getGroup(wellEcl.groupName(),
628 timeStepIdx),
629 this->schedule(),
630 timeStepIdx,
631 well_efficiency_factor);
632
633 well->setWellEfficiencyFactor(well_efficiency_factor);
634 well->setVFPProperties(this->vfp_properties_.get());
635 well->setGuideRate(&this->guideRate_);
636
637 // initialize rates/previous rates to prevent zero fractions in vfp-interpolation
638 if (well->isProducer()) {
639 well->updateWellStateRates(simulator_, this->wellState(), deferred_logger);
640 }
641 if (well->isVFPActive(deferred_logger)) {
642 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
643 }
644
645 try {
646 well->wellTesting(simulator_, simulationTime, this->wellState(),
647 this->groupState(), this->wellTestState(), deferred_logger);
648 } catch (const std::exception& e) {
649 const std::string msg = fmt::format("Exception during testing of well: {}. The well will not open.\n Exception message: {}", wellEcl.name(), e.what());
650 deferred_logger.warning("WELL_TESTING_FAILED", msg);
651 }
652 }
653 }
654
655
656
657
658
659 // called at the end of a report step
660 template<typename TypeTag>
661 void
664 {
665 // Clear the communication data structures for above values.
666 for (auto&& pinfo : this->local_parallel_well_info_)
667 {
668 pinfo.get().clear();
669 }
670 }
671
672
673
674
675
676 // called at the end of a report step
677 template<typename TypeTag>
680 lastReport() const {return last_report_; }
681
682
683
684
685
686 // called at the end of a time step
687 template<typename TypeTag>
688 void
690 timeStepSucceeded(const double simulationTime, const double dt)
691 {
692 this->closed_this_step_.clear();
693
694 // time step is finished and we are not any more at the beginning of an report step
695 this->report_step_starts_ = false;
696 const int reportStepIdx = simulator_.episodeIndex();
697
698 DeferredLogger local_deferredLogger;
699 for (const auto& well : well_container_) {
700 if (getPropValue<TypeTag, Properties::EnablePolymerMW>() && well->isInjector()) {
701 well->updateWaterThroughput(dt, this->wellState());
702 }
703 }
704 // update connection transmissibility factor and d factor (if applicable) in the wellstate
705 for (const auto& well : well_container_) {
706 well->updateConnectionTransmissibilityFactor(simulator_, this->wellState().well(well->indexOfWell()));
707 well->updateConnectionDFactor(simulator_, this->wellState().well(well->indexOfWell()));
708 }
709
710 if (Indices::waterEnabled) {
711 this->updateFiltrationParticleVolume(dt, FluidSystem::waterPhaseIdx);
712 }
713
714 // at the end of the time step, updating the inj_multiplier saved in WellState for later use
715 this->updateInjMult(local_deferredLogger);
716
717 // report well switching
718 for (const auto& well : well_container_) {
719 well->reportWellSwitching(this->wellState().well(well->indexOfWell()), local_deferredLogger);
720 }
721 // report group switching
722 if (this->terminal_output_) {
723
724 for (const auto& [name, to] : this->switched_prod_groups_) {
725 const Group::ProductionCMode& oldControl = this->prevWGState().group_state.production_control(name);
726 std::string from = Group::ProductionCMode2String(oldControl);
727 if (to != from) {
728 std::string msg = " Production Group " + name
729 + " control mode changed from ";
730 msg += from;
731 msg += " to " + to;
732 local_deferredLogger.info(msg);
733 }
734 }
735 for (const auto& [key, to] : this->switched_inj_groups_) {
736 const std::string& name = key.first;
737 const Opm::Phase& phase = key.second;
738
739 const Group::InjectionCMode& oldControl = this->prevWGState().group_state.injection_control(name, phase);
740 std::string from = Group::InjectionCMode2String(oldControl);
741 if (to != from) {
742 std::string msg = " Injection Group " + name
743 + " control mode changed from ";
744 msg += from;
745 msg += " to " + to;
746 local_deferredLogger.info(msg);
747 }
748 }
749 }
750
751 // update the rate converter with current averages pressures etc in
752 rateConverter_->template defineState<ElementContext>(simulator_);
753
754 // calculate the well potentials
755 try {
756 this->updateWellPotentials(reportStepIdx,
757 /*onlyAfterEvent*/false,
758 simulator_.vanguard().summaryConfig(),
759 local_deferredLogger);
760 } catch ( std::runtime_error& e ) {
761 const std::string msg = "A zero well potential is returned for output purposes. ";
762 local_deferredLogger.warning("WELL_POTENTIAL_CALCULATION_FAILED", msg);
763 }
764
765 updateWellTestState(simulationTime, this->wellTestState());
766
767 // check group sales limits at the end of the timestep
768 const Group& fieldGroup = this->schedule_.getGroup("FIELD", reportStepIdx);
769 this->checkGEconLimits(fieldGroup, simulationTime,
770 simulator_.episodeIndex(), local_deferredLogger);
771 this->checkGconsaleLimits(fieldGroup, this->wellState(),
772 simulator_.episodeIndex(), local_deferredLogger);
773
774 this->calculateProductivityIndexValues(local_deferredLogger);
775
776 this->commitWGState();
777
778 const Opm::Parallel::Communication& comm = grid().comm();
779 DeferredLogger global_deferredLogger = gatherDeferredLogger(local_deferredLogger, comm);
780 if (this->terminal_output_) {
781 global_deferredLogger.logMessages();
782 }
783
784 //reporting output temperatures
785 this->computeWellTemperature();
786 }
787
788
789 template<typename TypeTag>
790 void
793 unsigned elemIdx) const
794 {
795 rate = 0;
796
797 if (!is_cell_perforated_[elemIdx])
798 return;
799
800 for (const auto& well : well_container_)
801 well->addCellRates(rate, elemIdx);
802 }
803
804
805 template<typename TypeTag>
806 template <class Context>
807 void
810 const Context& context,
811 unsigned spaceIdx,
812 unsigned timeIdx) const
813 {
814 rate = 0;
815 int elemIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
816
817 if (!is_cell_perforated_[elemIdx])
818 return;
819
820 for (const auto& well : well_container_)
821 well->addCellRates(rate, elemIdx);
822 }
823
824
825
826 template<typename TypeTag>
827 void
829 initializeWellState(const int timeStepIdx)
830 {
831 const auto pressIx = []()
832 {
833 if (Indices::oilEnabled) { return FluidSystem::oilPhaseIdx; }
834 if (Indices::waterEnabled) { return FluidSystem::waterPhaseIdx; }
835
836 return FluidSystem::gasPhaseIdx;
837 }();
838
839 auto cellPressures = std::vector<Scalar>(this->local_num_cells_, Scalar{0});
840 auto cellTemperatures = std::vector<Scalar>(this->local_num_cells_, Scalar{0});
841
842 auto elemCtx = ElementContext { this->simulator_ };
843 const auto& gridView = this->simulator_.vanguard().gridView();
844
846 for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
847 elemCtx.updatePrimaryStencil(elem);
848 elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
849
850 const auto ix = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
851 const auto& fs = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0).fluidState();
852
853 cellPressures[ix] = fs.pressure(pressIx).value();
854 cellTemperatures[ix] = fs.temperature(0).value();
855 }
856 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::initializeWellState() failed: ",
857 this->simulator_.vanguard().grid().comm());
858
859 this->wellState().init(cellPressures, cellTemperatures, this->schedule(), this->wells_ecl_,
860 this->local_parallel_well_info_, timeStepIdx,
861 &this->prevWellState(), this->well_perf_data_,
862 this->summaryState());
863 }
864
865
866
867
868
869 template<typename TypeTag>
870 void
872 createWellContainer(const int report_step)
873 {
874 DeferredLogger local_deferredLogger;
875
876 const int nw = this->numLocalWells();
877
878 well_container_.clear();
879
880 if (nw > 0) {
881 well_container_.reserve(nw);
882
883 for (int w = 0; w < nw; ++w) {
884 const Well& well_ecl = this->wells_ecl_[w];
885
886 if (!well_ecl.hasConnections()) {
887 // No connections in this well. Nothing to do.
888 continue;
889 }
890
891 const std::string& well_name = well_ecl.name();
892 const auto well_status = this->schedule()
893 .getWell(well_name, report_step).getStatus();
894
895 if ((well_ecl.getStatus() == Well::Status::SHUT) ||
896 (well_status == Well::Status::SHUT))
897 {
898 // Due to ACTIONX the well might have been closed behind our back.
899 if (well_ecl.getStatus() != Well::Status::SHUT) {
900 this->closed_this_step_.insert(well_name);
901 this->wellState().shutWell(w);
902 }
903
904 continue;
905 }
906
907 // A new WCON keywords can re-open a well that was closed/shut due to Physical limit
908 if (this->wellTestState().well_is_closed(well_name)) {
909 // The well was shut this timestep, we are most likely retrying
910 // a timestep without the well in question, after it caused
911 // repeated timestep cuts. It should therefore not be opened,
912 // even if it was new or received new targets this report step.
913 const bool closed_this_step = (this->wellTestState().lastTestTime(well_name) == simulator_.time());
914 // TODO: more checking here, to make sure this standard more specific and complete
915 // maybe there is some WCON keywords will not open the well
916 auto& events = this->wellState().well(w).events;
917 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
918 if (!closed_this_step) {
919 this->wellTestState().open_well(well_name);
920 this->wellTestState().open_completions(well_name);
921 }
922 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
923 }
924 }
925
926 // TODO: should we do this for all kinds of closing reasons?
927 // something like wellTestState().hasWell(well_name)?
928 bool wellIsStopped = false;
929 if (this->wellTestState().well_is_closed(well_name))
930 {
931 if (well_ecl.getAutomaticShutIn()) {
932 // shut wells are not added to the well container
933 this->wellState().shutWell(w);
934 continue;
935 } else {
936 if (!well_ecl.getAllowCrossFlow()) {
937 // stopped wells where cross flow is not allowed
938 // are not added to the well container
939 this->wellState().shutWell(w);
940 continue;
941 }
942 // stopped wells are added to the container but marked as stopped
943 this->wellState().stopWell(w);
944 wellIsStopped = true;
945 }
946 }
947
948 // shut wells with zero rante constraints and disallowing
949 if (!well_ecl.getAllowCrossFlow()) {
950 const bool any_zero_rate_constraint = well_ecl.isProducer()
951 ? well_ecl.productionControls(this->summaryState_).anyZeroRateConstraint()
952 : well_ecl.injectionControls(this->summaryState_).anyZeroRateConstraint();
953 if (any_zero_rate_constraint) {
954 // Treat as shut, do not add to container.
955 local_deferredLogger.debug(fmt::format(" Well {} gets shut due to having zero rate constraint and disallowing crossflow ", well_ecl.name()) );
956 this->wellState().shutWell(w);
957 continue;
958 }
959 }
960
961 if (well_status == Well::Status::STOP) {
962 this->wellState().stopWell(w);
963 wellIsStopped = true;
964 }
965
966 well_container_.emplace_back(this->createWellPointer(w, report_step));
967
968 if (wellIsStopped)
969 well_container_.back()->stopWell();
970 }
971 }
972
973 // Collect log messages and print.
974
975 const Opm::Parallel::Communication& comm = grid().comm();
976 DeferredLogger global_deferredLogger = gatherDeferredLogger(local_deferredLogger, comm);
977 if (this->terminal_output_) {
978 global_deferredLogger.logMessages();
979 }
980
981 this->well_container_generic_.clear();
982 for (auto& w : well_container_)
983 this->well_container_generic_.push_back(w.get());
984
985 const auto& network = this->schedule()[report_step].network();
986 if (network.active() && !this->node_pressures_.empty()) {
987 for (auto& well: this->well_container_generic_) {
988 // Producers only, since we so far only support the
989 // "extended" network model (properties defined by
990 // BRANPROP and NODEPROP) which only applies to producers.
991 if (well->isProducer()) {
992 const auto it = this->node_pressures_.find(well->wellEcl().groupName());
993 if (it != this->node_pressures_.end()) {
994 // The well belongs to a group which has a network nodal pressure,
995 // set the dynamic THP constraint based on the network nodal pressure
996 const Scalar nodal_pressure = it->second;
997 well->setDynamicThpLimit(nodal_pressure);
998 }
999 }
1000 }
1001 }
1002
1003 this->registerOpenWellsForWBPCalculation();
1004 }
1005
1006
1007
1008
1009
1010 template <typename TypeTag>
1013 createWellPointer(const int wellID, const int report_step) const
1014 {
1015 const auto is_multiseg = this->wells_ecl_[wellID].isMultiSegment();
1016
1017 if (! (this->param_.use_multisegment_well_ && is_multiseg)) {
1018 return this->template createTypedWellPointer<StandardWell<TypeTag>>(wellID, report_step);
1019 }
1020 else {
1021 return this->template createTypedWellPointer<MultisegmentWell<TypeTag>>(wellID, report_step);
1022 }
1023 }
1024
1025
1026
1027
1028
1029 template <typename TypeTag>
1030 template <typename WellType>
1031 std::unique_ptr<WellType>
1033 createTypedWellPointer(const int wellID, const int time_step) const
1034 {
1035 // Use the pvtRegionIdx from the top cell
1036 const auto& perf_data = this->well_perf_data_[wellID];
1037
1038 // Cater for case where local part might have no perforations.
1039 const auto pvtreg = perf_data.empty()
1040 ? 0 : this->pvt_region_idx_[perf_data.front().cell_index];
1041
1042 const auto& parallel_well_info = this->local_parallel_well_info_[wellID].get();
1043 const auto global_pvtreg = parallel_well_info.broadcastFirstPerforationValue(pvtreg);
1044
1045 return std::make_unique<WellType>(this->wells_ecl_[wellID],
1046 parallel_well_info,
1047 time_step,
1048 this->param_,
1049 *this->rateConverter_,
1050 global_pvtreg,
1051 this->numComponents(),
1052 this->numPhases(),
1053 wellID,
1054 perf_data);
1055 }
1056
1057
1058
1059
1060
1061 template<typename TypeTag>
1064 createWellForWellTest(const std::string& well_name,
1065 const int report_step,
1066 DeferredLogger& deferred_logger) const
1067 {
1068 // Finding the location of the well in wells_ecl
1069 const int nw_wells_ecl = this->wells_ecl_.size();
1070 int index_well_ecl = 0;
1071 for (; index_well_ecl < nw_wells_ecl; ++index_well_ecl) {
1072 if (well_name == this->wells_ecl_[index_well_ecl].name()) {
1073 break;
1074 }
1075 }
1076 // It should be able to find in wells_ecl.
1077 if (index_well_ecl == nw_wells_ecl) {
1078 OPM_DEFLOG_THROW(std::logic_error,
1079 fmt::format("Could not find well {} in wells_ecl ", well_name),
1080 deferred_logger);
1081 }
1082
1083 return this->createWellPointer(index_well_ecl, report_step);
1084 }
1085
1086
1087
1088 template<typename TypeTag>
1089 void
1092 const double dt = this->simulator_.timeStepSize();
1093 // TODO: should we also have the group and network backed-up here in case the solution did not get converged?
1094 auto& well_state = this->wellState();
1095 const std::size_t max_iter = param_.network_max_iterations_;
1096 bool converged = false;
1097 std::size_t iter = 0;
1098 bool changed_well_group = false;
1099 do {
1100 changed_well_group = updateWellControlsAndNetwork(true, dt, deferred_logger);
1101 assembleWellEqWithoutIteration(dt, deferred_logger);
1102 converged = this->getWellConvergence(this->B_avg_, true).converged() && !changed_well_group;
1103 if (converged) {
1104 break;
1105 }
1106 ++iter;
1107 for (auto& well : this->well_container_) {
1108 well->solveEqAndUpdateWellState(simulator_, well_state, deferred_logger);
1109 }
1110 this->initPrimaryVariablesEvaluation();
1111 } while (iter < max_iter);
1112
1113 if (!converged) {
1114 const std::string msg = fmt::format("Initial (pre-step) network balance did not get converged with {} iterations, "
1115 "unconverged network balance result will be used", max_iter);
1116 deferred_logger.warning(msg);
1117 } else {
1118 const std::string msg = fmt::format("Initial (pre-step) network balance converged with {} iterations", iter);
1119 deferred_logger.debug(msg);
1120 }
1121 }
1122
1123
1124
1125
1126 template<typename TypeTag>
1127 void
1129 assemble(const int iterationIdx,
1130 const double dt)
1131 {
1132
1133 DeferredLogger local_deferredLogger;
1134 if (this->glift_debug) {
1135 const std::string msg = fmt::format(
1136 "assemble() : iteration {}" , iterationIdx);
1137 this->gliftDebug(msg, local_deferredLogger);
1138 }
1139 last_report_ = SimulatorReportSingle();
1140 Dune::Timer perfTimer;
1141 perfTimer.start();
1142 this->closed_offending_wells_.clear();
1143
1144 {
1145 const int episodeIdx = simulator_.episodeIndex();
1146 const auto& network = this->schedule()[episodeIdx].network();
1147 if (!this->wellsActive() && !network.active()) {
1148 return;
1149 }
1150 }
1151
1152 if (iterationIdx == 0 && this->wellsActive()) {
1153 // try-catch is needed here as updateWellControls
1154 // contains global communication and has either to
1155 // be reached by all processes or all need to abort
1156 // before.
1158 {
1159 calculateExplicitQuantities(local_deferredLogger);
1160 prepareTimeStep(local_deferredLogger);
1161 }
1162 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
1163 "assemble() failed (It=0): ",
1164 this->terminal_output_, grid().comm());
1165 }
1166
1167 const bool well_group_control_changed = updateWellControlsAndNetwork(false, dt, local_deferredLogger);
1168
1169 // even when there is no wells active, the network nodal pressure still need to be updated through updateWellControlsAndNetwork()
1170 // but there is no need to assemble the well equations
1171 if ( ! this->wellsActive() ) {
1172 return;
1173 }
1174
1175 assembleWellEqWithoutIteration(dt, local_deferredLogger);
1176
1177 // if group or well control changes we don't consider the
1178 // case converged
1179 last_report_.well_group_control_changed = well_group_control_changed;
1180 last_report_.assemble_time_well += perfTimer.stop();
1181 }
1182
1183
1184
1185
1186 template<typename TypeTag>
1187 bool
1189 updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger& local_deferredLogger)
1190 {
1191 // not necessarily that we always need to update once of the network solutions
1192 bool do_network_update = true;
1193 bool well_group_control_changed = false;
1194 // after certain number of the iterations, we use relaxed tolerance for the network update
1195 const std::size_t iteration_to_relax = param_.network_max_strict_iterations_;
1196 // after certain number of the iterations, we terminate
1197 const std::size_t max_iteration = param_.network_max_iterations_;
1198 std::size_t network_update_iteration = 0;
1199 while (do_network_update) {
1200 if (this->terminal_output_ && (network_update_iteration == iteration_to_relax) ) {
1201 local_deferredLogger.info(" we begin using relaxed tolerance for network update now after " + std::to_string(iteration_to_relax) + " iterations ");
1202 }
1203 const bool relax_network_balance = network_update_iteration >= iteration_to_relax;
1204 std::tie(do_network_update, well_group_control_changed) =
1205 updateWellControlsAndNetworkIteration(mandatory_network_balance, relax_network_balance, dt,local_deferredLogger);
1206 ++network_update_iteration;
1207
1208 if (network_update_iteration >= max_iteration ) {
1209 if (this->terminal_output_) {
1210 local_deferredLogger.info("maximum of " + std::to_string(max_iteration) + " iterations has been used, we stop the network update now. "
1211 "The simulation will continue with unconverged network results");
1212 }
1213 break;
1214 }
1215 }
1216 return well_group_control_changed;
1217 }
1218
1219
1220
1221
1222 template<typename TypeTag>
1223 std::pair<bool, bool>
1225 updateWellControlsAndNetworkIteration(const bool mandatory_network_balance,
1226 const bool relax_network_tolerance,
1227 const double dt,
1228 DeferredLogger& local_deferredLogger)
1229 {
1230 auto [well_group_control_changed, more_network_update] =
1231 updateWellControls(mandatory_network_balance, local_deferredLogger, relax_network_tolerance);
1232
1233 bool alq_updated = false;
1235 {
1236 // Set the well primary variables based on the value of well solutions
1237 initPrimaryVariablesEvaluation();
1238
1239 alq_updated = maybeDoGasLiftOptimize(local_deferredLogger);
1240
1241 prepareWellsBeforeAssembling(dt, local_deferredLogger);
1242 }
1243 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger, "updateWellControlsAndNetworkIteration() failed: ",
1244 this->terminal_output_, grid().comm());
1245
1246 //update guide rates
1247 const int reportStepIdx = simulator_.episodeIndex();
1248 if (alq_updated || BlackoilWellModelGuideRates(*this).
1249 guideRateUpdateIsNeeded(reportStepIdx)) {
1250 const double simulationTime = simulator_.time();
1251 const auto& comm = simulator_.vanguard().grid().comm();
1252 const auto& summaryState = simulator_.vanguard().summaryState();
1253 std::vector<Scalar> pot(this->numPhases(), 0.0);
1254 const Group& fieldGroup = this->schedule().getGroup("FIELD", reportStepIdx);
1256 this->schedule(),
1257 summaryState,
1258 this->phase_usage_,
1259 reportStepIdx,
1260 simulationTime,
1261 this->wellState(),
1262 this->groupState(),
1263 comm,
1264 &this->guideRate_,
1265 pot,
1266 local_deferredLogger);
1267 }
1268
1269 return {more_network_update, well_group_control_changed};
1270 }
1271
1272 // This function is to be used for well groups in an extended network that act as a subsea manifold
1273 // The wells of such group should have a common THP and total phase rate(s) obeying (if possible)
1274 // the well group constraint set by GCONPROD
1275 template <typename TypeTag>
1276 void
1278 computeWellGroupThp(const double dt, DeferredLogger& local_deferredLogger)
1279 {
1280 const int reportStepIdx = this->simulator_.episodeIndex();
1281 const auto& network = this->schedule()[reportStepIdx].network();
1282 const auto& balance = this->schedule()[reportStepIdx].network_balance();
1283 const Scalar thp_tolerance = balance.thp_tolerance();
1284
1285 if (!network.active()) {
1286 return;
1287 }
1288
1289 auto& well_state = this->wellState();
1290 auto& group_state = this->groupState();
1291
1292 for (const std::string& nodeName : network.node_names()) {
1293 const bool has_choke = network.node(nodeName).as_choke();
1294 if (has_choke) {
1295 const auto& summary_state = this->simulator_.vanguard().summaryState();
1296 const Group& group = this->schedule().getGroup(nodeName, reportStepIdx);
1297 const auto ctrl = group.productionControls(summary_state);
1298 const auto cmode = ctrl.cmode;
1299 const auto pu = this->phase_usage_;
1300 //TODO: Auto choke combined with RESV control is not supported
1301 std::vector<Scalar> resv_coeff(pu.num_phases, 1.0);
1302 Scalar gratTargetFromSales = 0.0;
1303 if (group_state.has_grat_sales_target(group.name()))
1304 gratTargetFromSales = group_state.grat_sales_target(group.name());
1305
1306 WGHelpers::TargetCalculator tcalc(cmode, pu, resv_coeff,
1307 gratTargetFromSales, nodeName, group_state,
1308 group.has_gpmaint_control(cmode));
1309 const Scalar orig_target = tcalc.groupTarget(ctrl, local_deferredLogger);
1310
1311 auto mismatch = [&] (auto group_thp) {
1312 Scalar group_rate(0.0);
1313 Scalar rate(0.0);
1314 for (auto& well : this->well_container_) {
1315 std::string well_name = well->name();
1316 auto& ws = well_state.well(well_name);
1317 if (group.hasWell(well_name)) {
1318 well->setDynamicThpLimit(group_thp);
1319 const Well& well_ecl = this->wells_ecl_[well->indexOfWell()];
1320 const auto inj_controls = Well::InjectionControls(0);
1321 const auto prod_controls = well_ecl.productionControls(summary_state);
1322 well->iterateWellEqWithSwitching(this->simulator_, dt, inj_controls, prod_controls, well_state, group_state, local_deferredLogger, false, false);
1323 rate = -tcalc.calcModeRateFromRates(ws.surface_rates);
1324 group_rate += rate;
1325 }
1326 }
1327 return (group_rate - orig_target)/orig_target;
1328 };
1329
1330 const auto upbranch = network.uptree_branch(nodeName);
1331 const auto it = this->node_pressures_.find((*upbranch).uptree_node());
1332 const Scalar nodal_pressure = it->second;
1333 Scalar well_group_thp = nodal_pressure;
1334
1335 std::optional<Scalar> autochoke_thp;
1336 if (auto iter = this->well_group_thp_calc_.find(nodeName); iter != this->well_group_thp_calc_.end()) {
1337 autochoke_thp = this->well_group_thp_calc_.at(nodeName);
1338 }
1339
1340 //Find an initial bracket
1341 std::array<Scalar, 2> range_initial;
1342 if (!autochoke_thp.has_value()){
1343 Scalar min_thp, max_thp;
1344 // Retrieve the terminal pressure of the associated root of the manifold group
1345 std::string node_name = nodeName;
1346 while (!network.node(node_name).terminal_pressure().has_value()) {
1347 auto branch = network.uptree_branch(node_name).value();
1348 node_name = branch.uptree_node();
1349 }
1350 min_thp = network.node(node_name).terminal_pressure().value();
1352 // Narrow down the bracket
1353 Scalar low1, high1;
1354 std::array<Scalar, 2> range = {Scalar{0.9}*min_thp, Scalar{1.1}*max_thp};
1355 std::optional<Scalar> appr_sol;
1356 WellBhpThpCalculator<Scalar>::bruteForceBracketCommonTHP(mismatch, range, low1, high1, appr_sol, 0.0, local_deferredLogger);
1357 min_thp = low1;
1358 max_thp = high1;
1359 range_initial = {min_thp, max_thp};
1360 }
1361
1362 if (!autochoke_thp.has_value() || autochoke_thp.value() > nodal_pressure) {
1363 // The bracket is based on the initial bracket or on a range based on a previous calculated group thp
1364 std::array<Scalar, 2> range = autochoke_thp.has_value() ?
1365 std::array<Scalar, 2>{Scalar{0.9} * autochoke_thp.value(),
1366 Scalar{1.1} * autochoke_thp.value()} : range_initial;
1367 Scalar low, high;
1368 std::optional<Scalar> approximate_solution;
1369 const Scalar tolerance1 = thp_tolerance;
1370 local_deferredLogger.debug("Using brute force search to bracket the group THP");
1371 const bool finding_bracket = WellBhpThpCalculator<Scalar>::bruteForceBracketCommonTHP(mismatch, range, low, high, approximate_solution, tolerance1, local_deferredLogger);
1372
1373 if (approximate_solution.has_value()) {
1374 autochoke_thp = *approximate_solution;
1375 local_deferredLogger.debug("Approximate group THP value found: " + std::to_string(autochoke_thp.value()));
1376 } else if (finding_bracket) {
1377 const Scalar tolerance2 = thp_tolerance;
1378 const int max_iteration_solve = 100;
1379 int iteration = 0;
1380 autochoke_thp = RegulaFalsiBisection<ThrowOnError>::
1381 solve(mismatch, low, high, max_iteration_solve, tolerance2, iteration);
1382 local_deferredLogger.debug(" bracket = [" + std::to_string(low) + ", " + std::to_string(high) + "], " +
1383 "iteration = " + std::to_string(iteration));
1384 local_deferredLogger.debug("Group THP value = " + std::to_string(autochoke_thp.value()));
1385 } else {
1386 autochoke_thp.reset();
1387 local_deferredLogger.debug("Group THP solve failed due to bracketing failure");
1388 }
1389 }
1390 if (autochoke_thp.has_value()) {
1391 well_group_thp_calc_[nodeName] = autochoke_thp.value();
1392 // Note: The node pressure of the auto-choke node is set to well_group_thp in computeNetworkPressures()
1393 // and must be larger or equal to the pressure of the uptree node of its branch.
1394 well_group_thp = std::max(autochoke_thp.value(), nodal_pressure);
1395 }
1396
1397 for (auto& well : this->well_container_) {
1398 std::string well_name = well->name();
1399 if (group.hasWell(well_name)) {
1400 well->setDynamicThpLimit(well_group_thp);
1401 }
1402 }
1403
1404 // Use the group THP in computeNetworkPressures().
1405 group_state.update_well_group_thp(nodeName, well_group_thp);
1406 }
1407 }
1408 }
1409
1410 template<typename TypeTag>
1411 void
1413 assembleDomain([[maybe_unused]] const int iterationIdx,
1414 const double dt,
1415 const Domain& domain)
1416 {
1417 last_report_ = SimulatorReportSingle();
1418 Dune::Timer perfTimer;
1419 perfTimer.start();
1420
1421 {
1422 const int episodeIdx = simulator_.episodeIndex();
1423 const auto& network = this->schedule()[episodeIdx].network();
1424 if (!this->wellsActive() && !network.active()) {
1425 return;
1426 }
1427 }
1428
1429 // We assume that calculateExplicitQuantities() and
1430 // prepareTimeStep() have been called already for the entire
1431 // well model, so we do not need to do it here (when
1432 // iterationIdx is 0).
1433
1434 DeferredLogger local_deferredLogger;
1435 updateWellControlsDomain(local_deferredLogger, domain);
1436 initPrimaryVariablesEvaluationDomain(domain);
1437 assembleWellEqDomain(dt, domain, local_deferredLogger);
1438
1439 // TODO: errors here must be caught higher up, as this method is not called in parallel.
1440 // We will log errors on rank 0, but not other ranks for now.
1441 if (this->terminal_output_) {
1442 local_deferredLogger.logMessages();
1443 }
1444
1445 last_report_.converged = true;
1446 last_report_.assemble_time_well += perfTimer.stop();
1447 }
1448
1449
1450 template<typename TypeTag>
1451 bool
1454 {
1455 bool do_glift_optimization = false;
1456 int num_wells_changed = 0;
1457 const double simulation_time = simulator_.time();
1458 const Scalar min_wait = simulator_.vanguard().schedule().glo(simulator_.episodeIndex()).min_wait();
1459 // We only optimize if a min_wait time has past.
1460 // If all_newton is true we still want to optimize several times pr timestep
1461 // i.e. we also optimize if check simulation_time == last_glift_opt_time_
1462 // that is when the last_glift_opt_time is already updated with the current time step
1463 if ( simulation_time == this->last_glift_opt_time_ || simulation_time >= (this->last_glift_opt_time_ + min_wait)) {
1464 do_glift_optimization = true;
1465 this->last_glift_opt_time_ = simulation_time;
1466 }
1467
1468 if (do_glift_optimization) {
1469 GLiftOptWells glift_wells;
1470 GLiftProdWells prod_wells;
1471 GLiftWellStateMap state_map;
1472 // NOTE: To make GasLiftGroupInfo (see below) independent of the TypeTag
1473 // associated with *this (i.e. BlackoilWellModel<TypeTag>) we observe
1474 // that GasLiftGroupInfo's only dependence on *this is that it needs to
1475 // access the eclipse Wells in the well container (the eclipse Wells
1476 // themselves are independent of the TypeTag).
1477 // Hence, we extract them from the well container such that we can pass
1478 // them to the GasLiftGroupInfo constructor.
1479 GLiftEclWells ecl_well_map;
1480 initGliftEclWellMap(ecl_well_map);
1481 GasLiftGroupInfo group_info {
1482 ecl_well_map,
1483 simulator_.vanguard().schedule(),
1484 simulator_.vanguard().summaryState(),
1485 simulator_.episodeIndex(),
1486 simulator_.model().newtonMethod().numIterations(),
1487 this->phase_usage_,
1488 deferred_logger,
1489 this->wellState(),
1490 this->groupState(),
1491 simulator_.vanguard().grid().comm(),
1492 this->glift_debug
1493 };
1494 group_info.initialize();
1495 gasLiftOptimizationStage1(deferred_logger, prod_wells, glift_wells,
1496 group_info, state_map);
1497 this->gasLiftOptimizationStage2(deferred_logger, prod_wells, glift_wells,
1498 group_info, state_map, simulator_.episodeIndex());
1499 if (this->glift_debug) {
1500 this->gliftDebugShowALQ(deferred_logger);
1501 }
1502 num_wells_changed = glift_wells.size();
1503 }
1504 num_wells_changed = this->comm_.sum(num_wells_changed);
1505 return num_wells_changed > 0;
1506 }
1507
1508 template<typename TypeTag>
1509 void
1512 GLiftProdWells& prod_wells,
1513 GLiftOptWells &glift_wells,
1514 GasLiftGroupInfo<Scalar>& group_info,
1515 GLiftWellStateMap& state_map)
1516 {
1517 auto comm = simulator_.vanguard().grid().comm();
1518 int num_procs = comm.size();
1519 // NOTE: Gas lift optimization stage 1 seems to be difficult
1520 // to do in parallel since the wells are optimized on different
1521 // processes and each process needs to know the current ALQ allocated
1522 // to each group it is a memeber of in order to check group limits and avoid
1523 // allocating more ALQ than necessary. (Surplus ALQ is removed in
1524 // stage 2). In stage1, as each well is adding ALQ, the current group ALQ needs
1525 // to be communicated to the other processes. But there is no common
1526 // synchronization point that all process will reach in the
1527 // runOptimizeLoop_() in GasLiftSingleWell.cpp.
1528 //
1529 // TODO: Maybe a better solution could be invented by distributing
1530 // wells according to certain parent groups. Then updated group rates
1531 // might not have to be communicated to the other processors.
1532
1533 // Currently, the best option seems to be to run this part sequentially
1534 // (not in parallel).
1535 //
1536 // TODO: The simplest approach seems to be if a) one process could take
1537 // ownership of all the wells (the union of all the wells in the
1538 // well_container_ of each process) then this process could do the
1539 // optimization, while the other processes could wait for it to
1540 // finish (e.g. comm.barrier()), or alternatively, b) if all
1541 // processes could take ownership of all the wells. Then there
1542 // would be no need for synchronization here..
1543 //
1544 for (int i = 0; i< num_procs; i++) {
1545 int num_rates_to_sync = 0; // communication variable
1546 GLiftSyncGroups groups_to_sync;
1547 if (comm.rank() == i) {
1548 // Run stage1: Optimize single wells while also checking group limits
1549 for (const auto& well : well_container_) {
1550 // NOTE: Only the wells in "group_info" needs to be optimized
1551 if (group_info.hasWell(well->name())) {
1552 gasLiftOptimizationStage1SingleWell(
1553 well.get(), deferred_logger, prod_wells, glift_wells,
1554 group_info, state_map, groups_to_sync
1555 );
1556 }
1557 }
1558 num_rates_to_sync = groups_to_sync.size();
1559 }
1560 num_rates_to_sync = comm.sum(num_rates_to_sync);
1561 if (num_rates_to_sync > 0) {
1562 std::vector<int> group_indexes;
1563 group_indexes.reserve(num_rates_to_sync);
1564 std::vector<Scalar> group_alq_rates;
1565 group_alq_rates.reserve(num_rates_to_sync);
1566 std::vector<Scalar> group_oil_rates;
1567 group_oil_rates.reserve(num_rates_to_sync);
1568 std::vector<Scalar> group_gas_rates;
1569 group_gas_rates.reserve(num_rates_to_sync);
1570 std::vector<Scalar> group_water_rates;
1571 group_water_rates.reserve(num_rates_to_sync);
1572 if (comm.rank() == i) {
1573 for (auto idx : groups_to_sync) {
1574 auto [oil_rate, gas_rate, water_rate, alq] = group_info.getRates(idx);
1575 group_indexes.push_back(idx);
1576 group_oil_rates.push_back(oil_rate);
1577 group_gas_rates.push_back(gas_rate);
1578 group_water_rates.push_back(water_rate);
1579 group_alq_rates.push_back(alq);
1580 }
1581 } else {
1582 group_indexes.resize(num_rates_to_sync);
1583 group_oil_rates.resize(num_rates_to_sync);
1584 group_gas_rates.resize(num_rates_to_sync);
1585 group_water_rates.resize(num_rates_to_sync);
1586 group_alq_rates.resize(num_rates_to_sync);
1587 }
1588#if HAVE_MPI
1589 Parallel::MpiSerializer ser(comm);
1590 ser.broadcast(i, group_indexes, group_oil_rates,
1591 group_gas_rates, group_water_rates, group_alq_rates);
1592#endif
1593 if (comm.rank() != i) {
1594 for (int j=0; j<num_rates_to_sync; j++) {
1595 group_info.updateRate(group_indexes[j],
1596 group_oil_rates[j], group_gas_rates[j], group_water_rates[j], group_alq_rates[j]);
1597 }
1598 }
1599 if (this->glift_debug) {
1600 int counter = 0;
1601 if (comm.rank() == i) {
1602 counter = this->wellState().gliftGetDebugCounter();
1603 }
1604 counter = comm.sum(counter);
1605 if (comm.rank() != i) {
1606 this->wellState().gliftSetDebugCounter(counter);
1607 }
1608 }
1609 }
1610 }
1611 }
1612
1613 // NOTE: this method cannot be const since it passes this->wellState()
1614 // (see below) to the GasLiftSingleWell constructor which accepts WellState
1615 // as a non-const reference..
1616 template<typename TypeTag>
1617 void
1620 DeferredLogger& deferred_logger,
1621 GLiftProdWells& prod_wells,
1622 GLiftOptWells& glift_wells,
1623 GasLiftGroupInfo<Scalar>& group_info,
1624 GLiftWellStateMap& state_map,
1625 GLiftSyncGroups& sync_groups)
1626 {
1627 const auto& summary_state = simulator_.vanguard().summaryState();
1628 std::unique_ptr<GasLiftSingleWell> glift
1629 = std::make_unique<GasLiftSingleWell>(
1630 *well, simulator_, summary_state,
1631 deferred_logger, this->wellState(), this->groupState(),
1632 group_info, sync_groups, this->comm_, this->glift_debug);
1633 auto state = glift->runOptimize(
1634 simulator_.model().newtonMethod().numIterations());
1635 if (state) {
1636 state_map.insert({well->name(), std::move(state)});
1637 glift_wells.insert({well->name(), std::move(glift)});
1638 return;
1639 }
1640 prod_wells.insert({well->name(), well});
1641 }
1642
1643
1644 template<typename TypeTag>
1645 void
1648 {
1649 for ( const auto& well: well_container_ ) {
1650 ecl_well_map.try_emplace(
1651 well->name(), &(well->wellEcl()), well->indexOfWell());
1652 }
1653 }
1654
1655
1656 template<typename TypeTag>
1657 void
1659 assembleWellEq(const double dt, DeferredLogger& deferred_logger)
1660 {
1661 for (auto& well : well_container_) {
1662 well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1663 }
1664 }
1665
1666
1667 template<typename TypeTag>
1668 void
1670 assembleWellEqDomain(const double dt, const Domain& domain, DeferredLogger& deferred_logger)
1671 {
1672 for (auto& well : well_container_) {
1673 if (well_domain_.at(well->name()) == domain.index) {
1674 well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1675 }
1676 }
1677 }
1678
1679
1680 template<typename TypeTag>
1681 void
1683 prepareWellsBeforeAssembling(const double dt, DeferredLogger& deferred_logger)
1684 {
1685 for (auto& well : well_container_) {
1686 well->prepareWellBeforeAssembling(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1687 }
1688 }
1689
1690
1691 template<typename TypeTag>
1692 void
1694 assembleWellEqWithoutIteration(const double dt, DeferredLogger& deferred_logger)
1695 {
1696 // We make sure that all processes throw in case there is an exception
1697 // on one of them (WetGasPvt::saturationPressure might throw if not converged)
1699
1700 for (auto& well: well_container_) {
1701 well->assembleWellEqWithoutIteration(simulator_, dt, this->wellState(), this->groupState(),
1702 deferred_logger);
1703 }
1704 OPM_END_PARALLEL_TRY_CATCH_LOG(deferred_logger, "BlackoilWellModel::assembleWellEqWithoutIteration failed: ",
1705 this->terminal_output_, grid().comm());
1706
1707 }
1708
1709
1710 template<typename TypeTag>
1711 void
1713 apply(BVector& r) const
1714 {
1715 for (auto& well : well_container_) {
1716 well->apply(r);
1717 }
1718 }
1719
1720
1721 // Ax = A x - C D^-1 B x
1722 template<typename TypeTag>
1723 void
1725 apply(const BVector& x, BVector& Ax) const
1726 {
1727 for (auto& well : well_container_) {
1728 well->apply(x, Ax);
1729 }
1730 }
1731
1732#if COMPILE_BDA_BRIDGE
1733 template<typename TypeTag>
1734 void
1737 {
1738 // prepare for StandardWells
1740
1741 for(unsigned int i = 0; i < well_container_.size(); i++){
1742 auto& well = well_container_[i];
1743 std::shared_ptr<StandardWell<TypeTag> > derived = std::dynamic_pointer_cast<StandardWell<TypeTag> >(well);
1744 if (derived) {
1745 wellContribs.addNumBlocks(derived->linSys().getNumBlocks());
1746 }
1747 }
1748
1749 // allocate memory for data from StandardWells
1750 wellContribs.alloc();
1751
1752 for(unsigned int i = 0; i < well_container_.size(); i++){
1753 auto& well = well_container_[i];
1754 // maybe WellInterface could implement addWellContribution()
1755 auto derived_std = std::dynamic_pointer_cast<StandardWell<TypeTag>>(well);
1756 if (derived_std) {
1757 derived_std->linSys().extract(derived_std->numStaticWellEq, wellContribs);
1758 } else {
1759 auto derived_ms = std::dynamic_pointer_cast<MultisegmentWell<TypeTag> >(well);
1760 if (derived_ms) {
1761 derived_ms->linSys().extract(wellContribs);
1762 } else {
1763 OpmLog::warning("Warning unknown type of well");
1764 }
1765 }
1766 }
1767 }
1768#endif
1769
1770 // Ax = Ax - alpha * C D^-1 B x
1771 template<typename TypeTag>
1772 void
1774 applyScaleAdd(const Scalar alpha, const BVector& x, BVector& Ax) const
1775 {
1776 if (this->well_container_.empty()) {
1777 return;
1778 }
1779
1780 if( scaleAddRes_.size() != Ax.size() ) {
1781 scaleAddRes_.resize( Ax.size() );
1782 }
1783
1784 scaleAddRes_ = 0.0;
1785 // scaleAddRes_ = - C D^-1 B x
1786 apply( x, scaleAddRes_ );
1787 // Ax = Ax + alpha * scaleAddRes_
1788 Ax.axpy( alpha, scaleAddRes_ );
1789 }
1790
1791 template<typename TypeTag>
1792 void
1794 addWellContributions(SparseMatrixAdapter& jacobian) const
1795 {
1796 for ( const auto& well: well_container_ ) {
1797 well->addWellContributions(jacobian);
1798 }
1799 }
1800
1801 template<typename TypeTag>
1802 void
1804 addWellPressureEquations(PressureMatrix& jacobian, const BVector& weights,const bool use_well_weights) const
1805 {
1806 int nw = this->numLocalWellsEnd();
1807 int rdofs = local_num_cells_;
1808 for ( int i = 0; i < nw; i++ ){
1809 int wdof = rdofs + i;
1810 jacobian[wdof][wdof] = 1.0;// better scaling ?
1811 }
1812
1813 for ( const auto& well : well_container_ ) {
1814 well->addWellPressureEquations(jacobian, weights, pressureVarIndex, use_well_weights, this->wellState());
1815 }
1816 }
1817
1818 template <typename TypeTag>
1820 addReservoirSourceTerms(GlobalEqVector& residual,
1821 std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress) const
1822 {
1823 // NB this loop may write multiple times to the same element
1824 // if a cell is perforated by more than one well, so it should
1825 // not be OpenMP-parallelized.
1826 for (const auto& well : well_container_) {
1827 if (!well->isOperableAndSolvable() && !well->wellIsStopped()) {
1828 continue;
1829 }
1830 const auto& cells = well->cells();
1831 const auto& rates = well->connectionRates();
1832 for (unsigned perfIdx = 0; perfIdx < rates.size(); ++perfIdx) {
1833 unsigned cellIdx = cells[perfIdx];
1834 auto rate = rates[perfIdx];
1835 rate *= -1.0;
1836 VectorBlockType res(0.0);
1837 using MatrixBlockType = typename SparseMatrixAdapter::MatrixBlock;
1838 MatrixBlockType bMat(0.0);
1839 simulator_.model().linearizer().setResAndJacobi(res, bMat, rate);
1840 residual[cellIdx] += res;
1841 *diagMatAddress[cellIdx] += bMat;
1842 }
1843 }
1844 }
1845
1846
1847 template<typename TypeTag>
1848 void
1851 {
1852 int nw = this->numLocalWellsEnd();
1853 int rdofs = local_num_cells_;
1854 for(int i=0; i < nw; i++){
1855 int wdof = rdofs + i;
1856 jacobian.entry(wdof,wdof) = 1.0;// better scaling ?
1857 }
1858 std::vector<std::vector<int>> wellconnections = this->getMaxWellConnections();
1859 for(int i=0; i < nw; i++){
1860 const auto& perfcells = wellconnections[i];
1861 for(int perfcell : perfcells){
1862 int wdof = rdofs + i;
1863 jacobian.entry(wdof,perfcell) = 0.0;
1864 jacobian.entry(perfcell, wdof) = 0.0;
1865 }
1866 }
1867 }
1868
1869
1870 template<typename TypeTag>
1871 void
1874 {
1875 DeferredLogger local_deferredLogger;
1877 {
1878 for (auto& well : well_container_) {
1879 well->recoverWellSolutionAndUpdateWellState(simulator_, x, this->wellState(), local_deferredLogger);
1880 }
1881 }
1882 OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
1883 "recoverWellSolutionAndUpdateWellState() failed: ",
1884 this->terminal_output_, simulator_.vanguard().grid().comm());
1885 }
1886
1887
1888 template<typename TypeTag>
1889 void
1892 {
1893 // Note: no point in trying to do a parallel gathering
1894 // try/catch here, as this function is not called in
1895 // parallel but for each individual domain of each rank.
1896 DeferredLogger local_deferredLogger;
1897 for (auto& well : well_container_) {
1898 if (well_domain_.at(well->name()) == domain.index) {
1899 well->recoverWellSolutionAndUpdateWellState(simulator_, x,
1900 this->wellState(),
1901 local_deferredLogger);
1902 }
1903 }
1904 // TODO: avoid losing the logging information that could
1905 // be stored in the local_deferredlogger in a parallel case.
1906 if (this->terminal_output_) {
1907 local_deferredLogger.logMessages();
1908 }
1909 }
1910
1911
1912 template<typename TypeTag>
1913 void
1916 {
1917 for (auto& well : well_container_) {
1918 well->initPrimaryVariablesEvaluation();
1919 }
1920 }
1921
1922
1923 template<typename TypeTag>
1924 void
1927 {
1928 for (auto& well : well_container_) {
1929 if (well_domain_.at(well->name()) == domain.index) {
1930 well->initPrimaryVariablesEvaluation();
1931 }
1932 }
1933 }
1934
1935
1936
1937
1938
1939
1940 template<typename TypeTag>
1943 getDomainWellConvergence(const Domain& domain,
1944 const std::vector<Scalar>& B_avg,
1945 DeferredLogger& local_deferredLogger) const
1946 {
1947 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
1948 const bool relax_tolerance = iterationIdx > param_.strict_outer_iter_wells_;
1949
1950 ConvergenceReport report;
1951 for (const auto& well : well_container_) {
1952 if ((well_domain_.at(well->name()) == domain.index)) {
1953 if (well->isOperableAndSolvable() || well->wellIsStopped()) {
1954 report += well->getWellConvergence(simulator_,
1955 this->wellState(),
1956 B_avg,
1957 local_deferredLogger,
1958 relax_tolerance);
1959 } else {
1960 ConvergenceReport xreport;
1961 using CR = ConvergenceReport;
1962 xreport.setWellFailed({CR::WellFailure::Type::Unsolvable, CR::Severity::Normal, -1, well->name()});
1963 report += xreport;
1964 }
1965 }
1966 }
1967
1968 // Log debug messages for NaN or too large residuals.
1969 if (this->terminal_output_) {
1970 for (const auto& f : report.wellFailures()) {
1971 if (f.severity() == ConvergenceReport::Severity::NotANumber) {
1972 local_deferredLogger.debug("NaN residual found with phase " + std::to_string(f.phase()) + " for well " + f.wellName());
1973 } else if (f.severity() == ConvergenceReport::Severity::TooLarge) {
1974 local_deferredLogger.debug("Too large residual found with phase " + std::to_string(f.phase()) + " for well " + f.wellName());
1975 }
1976 }
1977 }
1978 return report;
1979 }
1980
1981
1982
1983
1984
1985 template<typename TypeTag>
1988 getWellConvergence(const std::vector<Scalar>& B_avg, bool checkWellGroupControls) const
1989 {
1990
1991 DeferredLogger local_deferredLogger;
1992 // Get global (from all processes) convergence report.
1993 ConvergenceReport local_report;
1994 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
1995 for (const auto& well : well_container_) {
1996 if (well->isOperableAndSolvable() || well->wellIsStopped()) {
1997 local_report += well->getWellConvergence(
1998 simulator_, this->wellState(), B_avg, local_deferredLogger,
1999 iterationIdx > param_.strict_outer_iter_wells_);
2000 } else {
2001 ConvergenceReport report;
2002 using CR = ConvergenceReport;
2003 report.setWellFailed({CR::WellFailure::Type::Unsolvable, CR::Severity::Normal, -1, well->name()});
2004 local_report += report;
2005 }
2006 }
2007
2008 const Opm::Parallel::Communication comm = grid().comm();
2009 DeferredLogger global_deferredLogger = gatherDeferredLogger(local_deferredLogger, comm);
2010 ConvergenceReport report = gatherConvergenceReport(local_report, comm);
2011
2012 // the well_group_control_changed info is already communicated
2013 if (checkWellGroupControls) {
2014 report.setWellGroupTargetsViolated(this->lastReport().well_group_control_changed);
2015 }
2016
2017 if (this->terminal_output_) {
2018 global_deferredLogger.logMessages();
2019 }
2020 // Log debug messages for NaN or too large residuals.
2021 if (this->terminal_output_) {
2022 for (const auto& f : report.wellFailures()) {
2023 if (f.severity() == ConvergenceReport::Severity::NotANumber) {
2024 OpmLog::debug("NaN residual found with phase " + std::to_string(f.phase()) + " for well " + f.wellName());
2025 } else if (f.severity() == ConvergenceReport::Severity::TooLarge) {
2026 OpmLog::debug("Too large residual found with phase " + std::to_string(f.phase()) + " for well " + f.wellName());
2027 }
2028 }
2029 }
2030 return report;
2031 }
2032
2033
2034
2035
2036
2037 template<typename TypeTag>
2038 void
2040 calculateExplicitQuantities(DeferredLogger& deferred_logger) const
2041 {
2042 // TODO: checking isOperableAndSolvable() ?
2043 for (auto& well : well_container_) {
2044 well->calculateExplicitQuantities(simulator_, this->wellState(), deferred_logger);
2045 }
2046 }
2047
2048
2049
2050
2051
2052 template<typename TypeTag>
2053 std::pair<bool, bool>
2055 updateWellControls(const bool mandatory_network_balance, DeferredLogger& deferred_logger, const bool relax_network_tolerance)
2056 {
2057 const int episodeIdx = simulator_.episodeIndex();
2058 const auto& network = this->schedule()[episodeIdx].network();
2059 if (!this->wellsActive() && !network.active()) {
2060 return {false, false};
2061 }
2062
2063 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
2064 const auto& comm = simulator_.vanguard().grid().comm();
2065 this->updateAndCommunicateGroupData(episodeIdx, iterationIdx);
2066
2067 // network related
2068 bool more_network_update = false;
2069 if (this->shouldBalanceNetwork(episodeIdx, iterationIdx) || mandatory_network_balance) {
2070 const double dt = this->simulator_.timeStepSize();
2071 // Calculate common THP for subsea manifold well group (item 3 of NODEPROP set to YES)
2072 computeWellGroupThp(dt, deferred_logger);
2073 const auto local_network_imbalance = this->updateNetworkPressures(episodeIdx);
2074 const Scalar network_imbalance = comm.max(local_network_imbalance);
2075 const auto& balance = this->schedule()[episodeIdx].network_balance();
2076 constexpr Scalar relaxation_factor = 10.0;
2077 const Scalar tolerance = relax_network_tolerance ? relaxation_factor * balance.pressure_tolerance() : balance.pressure_tolerance();
2078 more_network_update = this->networkActive() && network_imbalance > tolerance;
2079 }
2080
2081 bool changed_well_group = false;
2082 // Check group individual constraints.
2083 const int nupcol = this->schedule()[episodeIdx].nupcol();
2084 // don't switch group control when iterationIdx > nupcol
2085 // to avoid oscilations between group controls
2086 if (iterationIdx <= nupcol) {
2087 const Group& fieldGroup = this->schedule().getGroup("FIELD", episodeIdx);
2088 changed_well_group = updateGroupControls(fieldGroup, deferred_logger, episodeIdx, iterationIdx);
2089 }
2090 // Check wells' group constraints and communicate.
2091 bool changed_well_to_group = false;
2092 {
2093 // For MS Wells a linear solve is performed below and the matrix might be singular.
2094 // We need to communicate the exception thrown to the others and rethrow.
2096 for (const auto& well : well_container_) {
2098 const bool changed_well = well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
2099 if (changed_well) {
2100 changed_well_to_group = changed_well || changed_well_to_group;
2101 }
2102 }
2103 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel: updating well controls failed: ",
2104 simulator_.gridView().comm());
2105 }
2106
2107 changed_well_to_group = comm.sum(static_cast<int>(changed_well_to_group));
2108 if (changed_well_to_group) {
2109 updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger);
2110 changed_well_group = true;
2111 }
2112
2113 // Check individual well constraints and communicate.
2114 bool changed_well_individual = false;
2115 {
2116 // For MS Wells a linear solve is performed below and the matrix might be singular.
2117 // We need to communicate the exception thrown to the others and rethrow.
2119 for (const auto& well : well_container_) {
2121 const bool changed_well = well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
2122 if (changed_well) {
2123 changed_well_individual = changed_well || changed_well_individual;
2124 }
2125 }
2126 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel: updating well controls failed: ",
2127 simulator_.gridView().comm());
2128 }
2129
2130 changed_well_individual = comm.sum(static_cast<int>(changed_well_individual));
2131 if (changed_well_individual) {
2132 updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger);
2133 changed_well_group = true;
2134 }
2135
2136 // update wsolvent fraction for REIN wells
2137 const Group& fieldGroup = this->schedule().getGroup("FIELD", episodeIdx);
2138 this->updateWsolvent(fieldGroup, episodeIdx, this->nupcolWellState());
2139
2140 return { changed_well_group, more_network_update };
2141 }
2142
2143 template<typename TypeTag>
2144 void
2146 updateWellControlsDomain(DeferredLogger& deferred_logger, const Domain& domain)
2147 {
2148 if ( !this->wellsActive() ) return ;
2149
2150 // TODO: decide on and implement an approach to handling of
2151 // group controls, network and similar for domain solves.
2152
2153 // Check only individual well constraints and communicate.
2154 for (const auto& well : well_container_) {
2155 if (well_domain_.at(well->name()) == domain.index) {
2157 well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
2158 }
2159 }
2160 }
2161
2162
2163
2164
2165
2166 template <typename TypeTag>
2167 void
2170 {
2171 this->wbpCalcMap_.clear();
2172 this->wbpCalcMap_.resize(this->wells_ecl_.size());
2173
2174 this->registerOpenWellsForWBPCalculation();
2175
2176 auto wellID = std::size_t{0};
2177 for (const auto& well : this->wells_ecl_) {
2178 this->wbpCalcMap_[wellID].wbpCalcIdx_ = this->wbpCalculationService_
2179 .createCalculator(well,
2180 this->local_parallel_well_info_[wellID],
2181 this->conn_idx_map_[wellID].local(),
2182 this->makeWellSourceEvaluatorFactory(wellID));
2183
2184 ++wellID;
2185 }
2186
2187 this->wbpCalculationService_.defineCommunication();
2188 }
2189
2190
2191
2192
2193
2194 template <typename TypeTag>
2195 data::WellBlockAveragePressures
2198 {
2199 auto wbpResult = data::WellBlockAveragePressures{};
2200
2201 using Calculated = typename PAvgCalculator<Scalar>::Result::WBPMode;
2202 using Output = data::WellBlockAvgPress::Quantity;
2203
2204 this->wbpCalculationService_.collectDynamicValues();
2205
2206 const auto numWells = this->wells_ecl_.size();
2207 for (auto wellID = 0*numWells; wellID < numWells; ++wellID) {
2208 const auto calcIdx = this->wbpCalcMap_[wellID].wbpCalcIdx_;
2209 const auto& well = this->wells_ecl_[wellID];
2210
2211 if (! well.hasRefDepth()) {
2212 // Can't perform depth correction without at least a
2213 // fall-back datum depth.
2214 continue;
2215 }
2216
2217 this->wbpCalculationService_
2218 .inferBlockAveragePressures(calcIdx, well.pavg(),
2219 this->gravity_,
2220 well.getWPaveRefDepth());
2221
2222 const auto& result = this->wbpCalculationService_
2223 .averagePressures(calcIdx);
2224
2225 auto& reported = wbpResult.values[well.name()];
2226
2227 reported[Output::WBP] = result.value(Calculated::WBP);
2228 reported[Output::WBP4] = result.value(Calculated::WBP4);
2229 reported[Output::WBP5] = result.value(Calculated::WBP5);
2230 reported[Output::WBP9] = result.value(Calculated::WBP9);
2231 }
2232
2233 return wbpResult;
2234 }
2235
2236
2237
2238
2239
2240 template <typename TypeTag>
2243 makeWellSourceEvaluatorFactory(const std::vector<Well>::size_type wellIdx) const
2244 {
2245 using Span = typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
2246 using Item = typename Span::Item;
2247
2248 return [wellIdx, this]() -> typename ParallelWBPCalculation<Scalar>::Evaluator
2249 {
2250 if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
2251 // Well is stopped/shut. Return evaluator for stopped wells.
2252 return []([[maybe_unused]] const int connIdx, Span sourceTerm)
2253 {
2254 // Well/connection is stopped/shut. Set all items to
2255 // zero.
2256
2257 sourceTerm
2258 .set(Item::Pressure , 0.0)
2259 .set(Item::PoreVol , 0.0)
2260 .set(Item::MixtureDensity, 0.0);
2261 };
2262 }
2263
2264 // Well is open. Return an evaluator for open wells/open connections.
2265 return [this, wellPtr = this->well_container_[*this->wbpCalcMap_[wellIdx].openWellIdx_].get()]
2266 (const int connIdx, Span sourceTerm)
2267 {
2268 // Note: The only item which actually matters for the WBP
2269 // calculation at the well reservoir connection level is the
2270 // mixture density. Set other items to zero.
2271
2272 const auto& connIdxMap =
2273 this->conn_idx_map_[wellPtr->indexOfWell()];
2274
2275 const auto rho = wellPtr->
2276 connectionDensity(connIdxMap.global(connIdx),
2277 connIdxMap.open(connIdx));
2278
2279 sourceTerm
2280 .set(Item::Pressure , 0.0)
2281 .set(Item::PoreVol , 0.0)
2282 .set(Item::MixtureDensity, rho);
2283 };
2284 };
2285 }
2286
2287
2288
2289
2290
2291 template <typename TypeTag>
2292 void
2295 {
2296 assert (this->wbpCalcMap_.size() == this->wells_ecl_.size());
2297
2298 for (auto& wbpCalc : this->wbpCalcMap_) {
2299 wbpCalc.openWellIdx_.reset();
2300 }
2301
2302 auto openWellIdx = typename std::vector<WellInterfacePtr>::size_type{0};
2303 for (const auto* openWell : this->well_container_generic_) {
2304 this->wbpCalcMap_[openWell->indexOfWell()].openWellIdx_ = openWellIdx++;
2305 }
2306 }
2307
2308
2309
2310
2311
2312 template<typename TypeTag>
2313 void
2315 updateAndCommunicate(const int reportStepIdx,
2316 const int iterationIdx,
2317 DeferredLogger& deferred_logger)
2318 {
2319 this->updateAndCommunicateGroupData(reportStepIdx, iterationIdx);
2320
2321 // updateWellStateWithTarget might throw for multisegment wells hence we
2322 // have a parallel try catch here to thrown on all processes.
2324 // if a well or group change control it affects all wells that are under the same group
2325 for (const auto& well : well_container_) {
2326 well->updateWellStateWithTarget(simulator_, this->groupState(),
2327 this->wellState(), deferred_logger);
2328 }
2329 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::updateAndCommunicate failed: ",
2330 simulator_.gridView().comm())
2331 this->updateAndCommunicateGroupData(reportStepIdx, iterationIdx);
2332 }
2333
2334 template<typename TypeTag>
2335 bool
2337 updateGroupControls(const Group& group,
2338 DeferredLogger& deferred_logger,
2339 const int reportStepIdx,
2340 const int iterationIdx)
2341 {
2342 bool changed = false;
2343 bool changed_hc = this->checkGroupHigherConstraints( group, deferred_logger, reportStepIdx);
2344 if (changed_hc) {
2345 changed = true;
2346 updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger);
2347 }
2348
2349 bool changed_individual =
2351 updateGroupIndividualControl(group,
2352 reportStepIdx,
2353 this->switched_inj_groups_,
2354 this->switched_prod_groups_,
2355 this->closed_offending_wells_,
2356 this->groupState(),
2357 this->wellState(),
2358 deferred_logger);
2359
2360 if (changed_individual) {
2361 changed = true;
2362 updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger);
2363 }
2364 // call recursively down the group hierarchy
2365 for (const std::string& groupName : group.groups()) {
2366 bool changed_this = updateGroupControls( this->schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx,iterationIdx);
2367 changed = changed || changed_this;
2368 }
2369 return changed;
2370 }
2371
2372 template<typename TypeTag>
2373 void
2375 updateWellTestState(const double& simulationTime, WellTestState& wellTestState) const
2376 {
2377 DeferredLogger local_deferredLogger;
2378 for (const auto& well : well_container_) {
2379 const auto& wname = well->name();
2380 const auto wasClosed = wellTestState.well_is_closed(wname);
2381 well->checkWellOperability(simulator_, this->wellState(), local_deferredLogger);
2382 const bool under_zero_target = well->wellUnderZeroGroupRateTarget(this->simulator_, this->wellState(), local_deferredLogger);
2383 well->updateWellTestState(this->wellState().well(wname), simulationTime, /*writeMessageToOPMLog=*/ true, under_zero_target, wellTestState, local_deferredLogger);
2384
2385 if (!wasClosed && wellTestState.well_is_closed(wname)) {
2386 this->closed_this_step_.insert(wname);
2387 }
2388 }
2389
2390 const Opm::Parallel::Communication comm = grid().comm();
2391 DeferredLogger global_deferredLogger = gatherDeferredLogger(local_deferredLogger, comm);
2392
2393 for (const auto& [group_name, to] : this->closed_offending_wells_) {
2394 if (this->hasWell(to.second) && !this->wasDynamicallyShutThisTimeStep(to.second)) {
2395 wellTestState.close_well(to.second, WellTestConfig::Reason::GROUP, simulationTime);
2396 this->updateClosedWellsThisStep(to.second);
2397 const std::string msg =
2398 fmt::format("Procedure on exceeding {} limit is WELL for group {}. Well {} is {}.",
2399 to.first,
2400 group_name,
2401 to.second,
2402 "shut");
2403 global_deferredLogger.info(msg);
2404 }
2405 }
2406
2407 if (this->terminal_output_) {
2408 global_deferredLogger.logMessages();
2409 }
2410 }
2411
2412
2413 template<typename TypeTag>
2414 void
2416 const WellState<Scalar>& well_state_copy,
2417 std::string& exc_msg,
2418 ExceptionType::ExcEnum& exc_type,
2419 DeferredLogger& deferred_logger)
2420 {
2421 const int np = this->numPhases();
2422 std::vector<Scalar> potentials;
2423 const auto& well = well_container_[widx];
2424 std::string cur_exc_msg;
2425 auto cur_exc_type = ExceptionType::NONE;
2426 try {
2427 well->computeWellPotentials(simulator_, well_state_copy, potentials, deferred_logger);
2428 }
2429 // catch all possible exception and store type and message.
2430 OPM_PARALLEL_CATCH_CLAUSE(cur_exc_type, cur_exc_msg);
2431 if (cur_exc_type != ExceptionType::NONE) {
2432 exc_msg += fmt::format("\nFor well {}: {}", well->name(), cur_exc_msg);
2433 }
2434 exc_type = std::max(exc_type, cur_exc_type);
2435 // Store it in the well state
2436 // potentials is resized and set to zero in the beginning of well->ComputeWellPotentials
2437 // and updated only if sucessfull. i.e. the potentials are zero for exceptions
2438 auto& ws = this->wellState().well(well->indexOfWell());
2439 for (int p = 0; p < np; ++p) {
2440 // make sure the potentials are positive
2441 ws.well_potentials[p] = std::max(Scalar{0.0}, potentials[p]);
2442 }
2443 }
2444
2445
2446
2447 template <typename TypeTag>
2448 void
2451 {
2452 for (const auto& wellPtr : this->well_container_) {
2453 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2454 }
2455 }
2456
2457
2458
2459
2460
2461 template <typename TypeTag>
2462 void
2464 calculateProductivityIndexValuesShutWells(const int reportStepIdx,
2465 DeferredLogger& deferred_logger)
2466 {
2467 // For the purpose of computing PI/II values, it is sufficient to
2468 // construct StandardWell instances only. We don't need to form
2469 // well objects that honour the 'isMultisegment()' flag of the
2470 // corresponding "this->wells_ecl_[shutWell]".
2471
2472 for (const auto& shutWell : this->local_shut_wells_) {
2473 if (!this->wells_ecl_[shutWell].hasConnections()) {
2474 // No connections in this well. Nothing to do.
2475 continue;
2476 }
2477
2478 auto wellPtr = this->template createTypedWellPointer
2479 <StandardWell<TypeTag>>(shutWell, reportStepIdx);
2480
2481 wellPtr->init(&this->phase_usage_, this->depth_, this->gravity_,
2482 this->local_num_cells_, this->B_avg_, true);
2483
2484 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2485 }
2486 }
2487
2488
2489
2490
2491
2492 template <typename TypeTag>
2493 void
2496 DeferredLogger& deferred_logger)
2497 {
2498 wellPtr->updateProductivityIndex(this->simulator_,
2499 this->prod_index_calc_[wellPtr->indexOfWell()],
2500 this->wellState(),
2501 deferred_logger);
2502 }
2503
2504
2505
2506 template<typename TypeTag>
2507 void
2509 prepareTimeStep(DeferredLogger& deferred_logger)
2510 {
2511 // Check if there is a network with active prediction wells at this time step.
2512 const auto episodeIdx = simulator_.episodeIndex();
2513 this->updateNetworkActiveState(episodeIdx);
2514
2515 // Rebalance the network initially if any wells in the network have status changes
2516 // (Need to check this before clearing events)
2517 const bool do_prestep_network_rebalance = this->needPreStepNetworkRebalance(episodeIdx);
2518
2519 for (const auto& well : well_container_) {
2520 auto& events = this->wellState().well(well->indexOfWell()).events;
2521 if (events.hasEvent(WellState<Scalar>::event_mask)) {
2522 well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger);
2523 well->updatePrimaryVariables(simulator_, this->wellState(), deferred_logger);
2524 well->initPrimaryVariablesEvaluation();
2525 // There is no new well control change input within a report step,
2526 // so next time step, the well does not consider to have effective events anymore.
2527 events.clearEvent(WellState<Scalar>::event_mask);
2528 }
2529 // these events only work for the first time step within the report step
2530 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
2531 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
2532 }
2533 // solve the well equation initially to improve the initial solution of the well model
2534 if (param_.solve_welleq_initially_ && well->isOperableAndSolvable()) {
2535 try {
2536 well->solveWellEquation(simulator_, this->wellState(), this->groupState(), deferred_logger);
2537 } catch (const std::exception& e) {
2538 const std::string msg = "Compute initial well solution for " + well->name() + " initially failed. Continue with the previous rates";
2539 deferred_logger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
2540 }
2541 }
2542 // If we're using local well solves that include control switches, they also update
2543 // operability, so reset before main iterations begin
2544 well->resetWellOperability();
2545 }
2546 updatePrimaryVariables(deferred_logger);
2547
2548 // Actually do the pre-step network rebalance, using the updated well states and initial solutions
2549 if (do_prestep_network_rebalance) doPreStepNetworkRebalance(deferred_logger);
2550 }
2551
2552 template<typename TypeTag>
2553 void
2556 {
2557 std::vector< Scalar > B_avg(numComponents(), Scalar() );
2558 const auto& grid = simulator_.vanguard().grid();
2559 const auto& gridView = grid.leafGridView();
2560 ElementContext elemCtx(simulator_);
2561
2563 for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
2564 elemCtx.updatePrimaryStencil(elem);
2565 elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
2566
2567 const auto& intQuants = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
2568 const auto& fs = intQuants.fluidState();
2569
2570 for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
2571 {
2572 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2573 continue;
2574 }
2575
2576 const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
2577 auto& B = B_avg[ compIdx ];
2578
2579 B += 1 / fs.invB(phaseIdx).value();
2580 }
2581 if constexpr (has_solvent_) {
2582 auto& B = B_avg[solventSaturationIdx];
2583 B += 1 / intQuants.solventInverseFormationVolumeFactor().value();
2584 }
2585 }
2586 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::updateAverageFormationFactor() failed: ", grid.comm())
2587
2588 // compute global average
2589 grid.comm().sum(B_avg.data(), B_avg.size());
2590 for (auto& bval : B_avg)
2591 {
2592 bval /= global_num_cells_;
2593 }
2594 B_avg_ = B_avg;
2595 }
2596
2597
2598
2599
2600
2601 template<typename TypeTag>
2602 void
2605 {
2606 for (const auto& well : well_container_) {
2607 well->updatePrimaryVariables(simulator_, this->wellState(), deferred_logger);
2608 }
2609 }
2610
2611 template<typename TypeTag>
2612 void
2614 {
2615 const auto& grid = simulator_.vanguard().grid();
2616 const auto& eclProblem = simulator_.problem();
2617 const unsigned numCells = grid.size(/*codim=*/0);
2618
2619 this->pvt_region_idx_.resize(numCells);
2620 for (unsigned cellIdx = 0; cellIdx < numCells; ++cellIdx) {
2621 this->pvt_region_idx_[cellIdx] =
2622 eclProblem.pvtRegionIndex(cellIdx);
2623 }
2624 }
2625
2626 // The number of components in the model.
2627 template<typename TypeTag>
2628 int
2630 {
2631 // The numComponents here does not reflect the actual number of the components in the system.
2632 // It more or less reflects the number of mass conservation equations for the well equations.
2633 // For example, in the current formulation, we do not have the polymer conservation equation
2634 // in the well equations. As a result, for an oil-water-polymer system, this function will return 2.
2635 // In some way, it makes this function appear to be confusing from its name, and we need
2636 // to revisit/revise this function again when extending the variants of system that flow can simulate.
2637 int numComp = this->numPhases() < 3 ? this->numPhases() : FluidSystem::numComponents;
2638 if constexpr (has_solvent_) {
2639 numComp++;
2640 }
2641 return numComp;
2642 }
2643
2644 template<typename TypeTag>
2645 void
2647 {
2648 const auto& eclProblem = simulator_.problem();
2649 depth_.resize(local_num_cells_);
2650 for (unsigned cellIdx = 0; cellIdx < local_num_cells_; ++cellIdx) {
2651 depth_[cellIdx] = eclProblem.dofCenterDepth(cellIdx);
2652 }
2653 }
2654
2655 template<typename TypeTag>
2658 getWell(const std::string& well_name) const
2659 {
2660 // finding the iterator of the well in wells_ecl
2661 auto well = std::find_if(well_container_.begin(),
2662 well_container_.end(),
2663 [&well_name](const WellInterfacePtr& elem)->bool {
2664 return elem->name() == well_name;
2665 });
2666
2667 assert(well != well_container_.end());
2668
2669 return *well;
2670 }
2671
2672 template<typename TypeTag>
2673 bool
2675 hasWell(const std::string& well_name) const
2676 {
2677 return std::any_of(well_container_.begin(), well_container_.end(),
2678 [&well_name](const WellInterfacePtr& elem) -> bool
2679 {
2680 return elem->name() == well_name;
2681 });
2682 }
2683
2684
2685
2686
2687 template <typename TypeTag>
2688 int
2690 reportStepIndex() const
2691 {
2692 return std::max(this->simulator_.episodeIndex(), 0);
2693 }
2694
2695
2696
2697
2698
2699 template<typename TypeTag>
2700 void
2702 calcResvCoeff(const int fipnum,
2703 const int pvtreg,
2704 const std::vector<Scalar>& production_rates,
2705 std::vector<Scalar>& resv_coeff)
2706 {
2707 rateConverter_->calcCoeff(fipnum, pvtreg, production_rates, resv_coeff);
2708 }
2709
2710 template<typename TypeTag>
2711 void
2713 calcInjResvCoeff(const int fipnum,
2714 const int pvtreg,
2715 std::vector<Scalar>& resv_coeff)
2716 {
2717 rateConverter_->calcInjCoeff(fipnum, pvtreg, resv_coeff);
2718 }
2719
2720
2721 template <typename TypeTag>
2722 void
2725 {
2726 if (!has_energy_)
2727 return;
2728
2729 int np = this->numPhases();
2730 Scalar cellInternalEnergy;
2731 Scalar cellBinv;
2732 Scalar cellDensity;
2733 Scalar perfPhaseRate;
2734 const int nw = this->numLocalWells();
2735 for (auto wellID = 0*nw; wellID < nw; ++wellID) {
2736 const Well& well = this->wells_ecl_[wellID];
2737 auto& ws = this->wellState().well(wellID);
2738 if (well.isInjector()){
2739 if( !(ws.status == WellStatus::STOP)){
2740 this->wellState().well(wellID).temperature = well.inj_temperature();
2741 continue;
2742 }
2743 }
2744
2745 std::array<Scalar,2> weighted{0.0,0.0};
2746 auto& [weighted_temperature, total_weight] = weighted;
2747
2748 auto& well_info = this->local_parallel_well_info_[wellID].get();
2749 auto& perf_data = ws.perf_data;
2750 auto& perf_phase_rate = perf_data.phase_rates;
2751
2752 using int_type = decltype(this->well_perf_data_[wellID].size());
2753 for (int_type perf = 0, end_perf = this->well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
2754 const int cell_idx = this->well_perf_data_[wellID][perf].cell_index;
2755 const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
2756 const auto& fs = intQuants.fluidState();
2757
2758 // we on only have one temperature pr cell any phaseIdx will do
2759 Scalar cellTemperatures = fs.temperature(/*phaseIdx*/0).value();
2760
2761 Scalar weight_factor = 0.0;
2762 for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
2763 {
2764 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2765 continue;
2766 }
2767 cellInternalEnergy = fs.enthalpy(phaseIdx).value() - fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
2768 cellBinv = fs.invB(phaseIdx).value();
2769 cellDensity = fs.density(phaseIdx).value();
2770 perfPhaseRate = perf_phase_rate[ perf*np + phaseIdx ];
2771 weight_factor += cellDensity * perfPhaseRate/cellBinv * cellInternalEnergy/cellTemperatures;
2772 }
2773 weight_factor = std::abs(weight_factor)+1e-13;
2774 total_weight += weight_factor;
2775 weighted_temperature += weight_factor * cellTemperatures;
2776 }
2777 well_info.communication().sum(weighted.data(), 2);
2778 this->wellState().well(wellID).temperature = weighted_temperature/total_weight;
2779 }
2780 }
2781
2782
2783 template <typename TypeTag>
2784 void
2786 logPrimaryVars() const
2787 {
2788 std::ostringstream os;
2789 for (const auto& w : well_container_) {
2790 os << w->name() << ":";
2791 auto pv = w->getPrimaryVars();
2792 for (const Scalar v : pv) {
2793 os << ' ' << v;
2794 }
2795 os << '\n';
2796 }
2797 OpmLog::debug(os.str());
2798 }
2799
2800
2801
2802 template <typename TypeTag>
2803 std::vector<typename BlackoilWellModel<TypeTag>::Scalar>
2805 getPrimaryVarsDomain(const Domain& domain) const
2806 {
2807 std::vector<Scalar> ret;
2808 for (const auto& well : well_container_) {
2809 if (well_domain_.at(well->name()) == domain.index) {
2810 const auto& pv = well->getPrimaryVars();
2811 ret.insert(ret.end(), pv.begin(), pv.end());
2812 }
2813 }
2814 return ret;
2815 }
2816
2817
2818
2819 template <typename TypeTag>
2820 void
2822 setPrimaryVarsDomain(const Domain& domain, const std::vector<Scalar>& vars)
2823 {
2824 std::size_t offset = 0;
2825 for (auto& well : well_container_) {
2826 if (well_domain_.at(well->name()) == domain.index) {
2827 int num_pri_vars = well->setPrimaryVars(vars.begin() + offset);
2828 offset += num_pri_vars;
2829 }
2830 }
2831 assert(offset == vars.size());
2832 }
2833
2834
2835
2836 template <typename TypeTag>
2837 void
2839 setupDomains(const std::vector<Domain>& domains)
2840 {
2842 // TODO: This loop nest may be slow for very large numbers of
2843 // domains and wells, but that has not been observed on tests so
2844 // far. Using the partition vector instead would be faster if we
2845 // need to change.
2846 for (const auto& wellPtr : this->well_container_) {
2847 const int first_well_cell = wellPtr->cells().front();
2848 for (const auto& domain : domains) {
2849 auto cell_present = [&domain](const auto cell)
2850 {
2851 return std::binary_search(domain.cells.begin(),
2852 domain.cells.end(), cell);
2853 };
2854
2855 if (cell_present(first_well_cell)) {
2856 // Assuming that if the first well cell is found in a domain,
2857 // then all of that well's cells are in that same domain.
2858 well_domain_[wellPtr->name()] = domain.index;
2859
2860 // Verify that all of that well's cells are in that same domain.
2861 for (int well_cell : wellPtr->cells()) {
2862 if (! cell_present(well_cell)) {
2863 OPM_THROW(std::runtime_error,
2864 fmt::format("Well '{}' found on multiple domains.",
2865 wellPtr->name()));
2866 }
2867 }
2868 }
2869 }
2870 }
2871 OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::setupDomains(): well found on multiple domains.",
2872 simulator_.gridView().comm());
2873
2874 // Write well/domain info to the DBG file.
2875 const Opm::Parallel::Communication& comm = grid().comm();
2876 const int rank = comm.rank();
2877 DeferredLogger local_log;
2878 if (!well_domain_.empty()) {
2879 std::ostringstream os;
2880 os << "Well name Rank Domain\n";
2881 for (const auto& [wname, domain] : well_domain_) {
2882 os << wname << std::setw(19 - wname.size()) << rank << std::setw(12) << domain << '\n';
2883 }
2884 local_log.debug(os.str());
2885 }
2886 auto global_log = gatherDeferredLogger(local_log, comm);
2887 if (this->terminal_output_) {
2888 global_log.logMessages();
2889 }
2890 }
2891
2892} // namespace Opm
#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)
Catch exception, log, and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:202
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:45
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:192
#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg)
Inserts catch classes for the parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:166
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:158
void logAndCheckForExceptionsAndThrow(Opm::DeferredLogger &deferred_logger, Opm::ExceptionType::ExcEnum exc_type, const std::string &message, const bool terminal_output, Opm::Parallel::Communication comm)
Definition: DeferredLoggingErrorHelpers.hpp:111
Class for handling constraints for the blackoil well model.
Definition: BlackoilWellModelConstraints.hpp:41
Class for handling the guide rates in the blackoil well model.
Definition: BlackoilWellModelGuideRates.hpp:46
Class for handling the blackoil well model.
Definition: BlackoilWellModel.hpp:98
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:371
void apply(BVector &r) const
Definition: BlackoilWellModel_impl.hpp:1713
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2509
bool updateGroupControls(const Group &group, DeferredLogger &deferred_logger, const int reportStepIdx, const int iterationIdx)
Definition: BlackoilWellModel_impl.hpp:2337
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:1013
WellInterfacePtr getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2658
void calcInjResvCoeff(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) override
Definition: BlackoilWellModel_impl.hpp:2713
void init()
Definition: BlackoilWellModel_impl.hpp:154
typename BlackoilWellModelGeneric< Scalar >::GLiftProdWells GLiftProdWells
Definition: BlackoilWellModel.hpp:113
void calcResvCoeff(const int fipnum, const int pvtreg, const std::vector< Scalar > &production_rates, std::vector< Scalar > &resv_coeff) override
Definition: BlackoilWellModel_impl.hpp:2702
void updateAndCommunicate(const int reportStepIdx, const int iterationIdx, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2315
void doPreStepNetworkRebalance(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1091
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:107
std::vector< Scalar > getPrimaryVarsDomain(const Domain &domain) const
Definition: BlackoilWellModel_impl.hpp:2805
typename GasLiftGroupInfo< Scalar >::GLiftEclWells GLiftEclWells
Definition: BlackoilWellModel.hpp:116
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:173
void addReservoirSourceTerms(GlobalEqVector &residual, std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1820
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:274
void assembleWellEqDomain(const double dt, const Domain &domain, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1670
void applyScaleAdd(const Scalar alpha, const BVector &x, BVector &Ax) const
Definition: BlackoilWellModel_impl.hpp:1774
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilWellModel.hpp:104
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilWellModel.hpp:101
void updateWellControlsDomain(DeferredLogger &deferred_logger, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:2146
void assembleWellEq(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1659
void gasLiftOptimizationStage1SingleWell(WellInterface< TypeTag > *well, DeferredLogger &deferred_logger, GLiftProdWells &prod_wells, GLiftOptWells &glift_wells, GasLiftGroupInfo< Scalar > &group_info, GLiftWellStateMap &state_map, GLiftSyncGroups &groups_to_sync)
Definition: BlackoilWellModel_impl.hpp:1619
void linearizeDomain(const Domain &domain, SparseMatrixAdapter &jacobian, GlobalEqVector &res)
Definition: BlackoilWellModel_impl.hpp:251
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2690
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2450
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2646
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2613
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2555
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:106
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:829
void assemble(const int iterationIdx, const double dt)
Definition: BlackoilWellModel_impl.hpp:1129
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2724
void addWellPressureEquations(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights) const
Definition: BlackoilWellModel_impl.hpp:1804
void logPrimaryVars() const
Definition: BlackoilWellModel_impl.hpp:2786
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:680
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1189
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1794
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1064
typename BlackoilWellModelGeneric< Scalar >::GLiftOptWells GLiftOptWells
Definition: BlackoilWellModel.hpp:112
void computePotentials(const std::size_t widx, const WellState< Scalar > &well_state_copy, std::string &exc_msg, ExceptionType::ExcEnum &exc_type, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2415
std::pair< bool, bool > updateWellControls(const bool mandatory_network_balance, DeferredLogger &deferred_logger, const bool relax_network_tolerance=false)
Definition: BlackoilWellModel_impl.hpp:2055
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:1891
typename GasLiftSingleWellGeneric< Scalar >::GLiftSyncGroups GLiftSyncGroups
Definition: BlackoilWellModel.hpp:117
void assembleDomain(const int iterationIdx, const double dt, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:1413
bool hasWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2675
ParallelWBPCalculation< Scalar >::EvaluatorFactory makeWellSourceEvaluatorFactory(const std::vector< Well >::size_type wellIdx) const
Definition: BlackoilWellModel_impl.hpp:2243
void assembleWellEqWithoutIteration(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1694
data::WellBlockAveragePressures computeWellBlockAveragePressures() const
Definition: BlackoilWellModel_impl.hpp:2197
void initPrimaryVariablesEvaluation() const
Definition: BlackoilWellModel_impl.hpp:1915
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:360
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:792
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:413
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: BlackoilWellModel.hpp:108
void calculateExplicitQuantities(DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:2040
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:133
void updatePrimaryVariables(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2604
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling)
Definition: BlackoilWellModel_impl.hpp:326
std::pair< bool, bool > updateWellControlsAndNetworkIteration(const bool mandatory_network_balance, const bool relax_network_tolerance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1225
void addNeighbors(std::vector< NeighborSet > &neighbors) const override
Specify the additional neighboring correlations caused by the auxiliary module.
Definition: BlackoilWellModel_impl.hpp:189
BlackoilWellModel(Simulator &simulator)
Definition: BlackoilWellModel_impl.hpp:146
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:613
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControls=false) const
Definition: BlackoilWellModel_impl.hpp:1988
void registerOpenWellsForWBPCalculation()
Definition: BlackoilWellModel_impl.hpp:2294
void linearize(SparseMatrixAdapter &jacobian, GlobalEqVector &res) override
Linearize the auxiliary equation.
Definition: BlackoilWellModel_impl.hpp:230
void initGliftEclWellMap(GLiftEclWells &ecl_well_map)
Definition: BlackoilWellModel_impl.hpp:1647
void gasLiftOptimizationStage1(DeferredLogger &deferred_logger, GLiftProdWells &prod_wells, GLiftOptWells &glift_wells, GasLiftGroupInfo< Scalar > &group_info, GLiftWellStateMap &state_map)
Definition: BlackoilWellModel_impl.hpp:1511
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:690
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1033
void setPrimaryVarsDomain(const Domain &domain, const std::vector< Scalar > &vars)
Definition: BlackoilWellModel_impl.hpp:2822
std::shared_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:238
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:872
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilWellModel.hpp:134
bool maybeDoGasLiftOptimize(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1453
void computeWellGroupThp(const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1278
void updateWellTestState(const double &simulationTime, WellTestState &wellTestState) const
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:2375
ConvergenceReport getDomainWellConvergence(const Domain &domain, const std::vector< Scalar > &B_avg, DeferredLogger &local_deferredLogger) const
Definition: BlackoilWellModel_impl.hpp:1943
void initializeWBPCalculationService()
Definition: BlackoilWellModel_impl.hpp:2169
void initPrimaryVariablesEvaluationDomain(const Domain &domain) const
Definition: BlackoilWellModel_impl.hpp:1926
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1873
void setupDomains(const std::vector< Domain > &domains)
Definition: BlackoilWellModel_impl.hpp:2839
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1850
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2464
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:663
void prepareWellsBeforeAssembling(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1683
typename BlackoilWellModelGeneric< Scalar >::GLiftWellStateMap GLiftWellStateMap
Definition: BlackoilWellModel.hpp:115
int numComponents() const
Definition: BlackoilWellModel_impl.hpp:2629
Definition: ConvergenceReport.hpp:38
void setWellFailed(const WellFailure &wf)
Definition: ConvergenceReport.hpp:197
void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
Definition: ConvergenceReport.hpp:209
const std::vector< WellFailure > & wellFailures() const
Definition: ConvergenceReport.hpp:289
Definition: DeferredLogger.hpp:57
void info(const std::string &tag, const std::string &message)
void warning(const std::string &tag, const std::string &message)
void debug(const std::string &tag, const std::string &message)
Definition: GasLiftGroupInfo.hpp:46
std::tuple< Scalar, Scalar, Scalar, Scalar > getRates(const int group_idx) const
bool hasWell(const std::string &well_name)
void updateRate(int idx, Scalar oil_rate, Scalar gas_rate, Scalar water_rate, Scalar alq)
Class for serializing and broadcasting data using MPI.
Definition: MPISerializer.hpp:31
void broadcast(T &data, int root=0)
Serialize and broadcast on root process, de-serialize on others.
Definition: MPISerializer.hpp:46
Definition: ParallelWBPCalculation.hpp:51
typename ParallelPAvgDynamicSourceData< Scalar >::Evaluator Evaluator
Callback for evaluating WBPn source terms on the current MPI rank.
Definition: ParallelWBPCalculation.hpp:58
Definition: StandardWell.hpp:59
virtual void init(const PhaseUsage *phase_usage_arg, const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const int num_cells, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: StandardWell_impl.hpp:96
Definition: TargetCalculator.hpp:43
RateType calcModeRateFromRates(const std::vector< RateType > &rates) const
Definition: TargetCalculator.hpp:54
Scalar groupTarget(const std::optional< Group::ProductionControls > &ctrl, DeferredLogger &deferred_logger) const
static bool bruteForceBracketCommonTHP(const std::function< Scalar(const Scalar)> &eq, const std::array< Scalar, 2 > &range, Scalar &low, Scalar &high, std::optional< Scalar > &approximate_solution, const Scalar &limit, DeferredLogger &deferred_logger)
Find limits using brute-force solver.
Definition: WellContributions.hpp:53
void alloc()
Allocate memory for the StandardWells.
void setBlockSize(unsigned int dim, unsigned int dim_wells)
void addNumBlocks(unsigned int numBlocks)
static void setCmodeGroup(const Group &group, const Schedule &schedule, const SummaryState &summaryState, const int reportStepIdx, GroupState< Scalar > &group_state)
static void setRegionAveragePressureCalculator(const Group &group, const Schedule &schedule, const int reportStepIdx, const FieldPropsManager &fp, const PhaseUsage &pu, std::map< std::string, std::unique_ptr< AverageRegionalPressureType > > &regionalAveragePressureCalculator)
static void updateGuideRates(const Group &group, const Schedule &schedule, const SummaryState &summary_state, const PhaseUsage &pu, int report_step, double sim_time, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, const Parallel::Communication &comm, GuideRate *guide_rate, std::vector< Scalar > &pot, DeferredLogger &deferred_logger)
static void updateGpMaintTargetForGroups(const Group &group, const Schedule &schedule, const RegionalValues &regional_values, const int reportStepIdx, const double dt, const WellState< Scalar > &well_state, GroupState< Scalar > &group_state)
static void accumulateGroupEfficiencyFactor(const Group &group, const Schedule &schedule, const int reportStepIdx, Scalar &factor)
const std::string & name() const
Well name.
int indexOfWell() const
Index of well in the wells struct and wellState.
Definition: WellInterface.hpp:73
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:195
virtual void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const =0
Definition: WellState.hpp:62
ExcEnum
Definition: DeferredLogger.hpp:45
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:37
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Parallel::Communication communicator)
Create a global log combining local logs.
ConvergenceReport gatherConvergenceReport(const ConvergenceReport &local_report, Parallel::Communication communicator)
PhaseUsage phaseUsageFromDeck(const EclipseState &eclipseState)
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34
Definition: SubDomain.hpp:62
int index
Definition: SubDomain.hpp:65