24#ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
25#define OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED
32#include <opm/grid/utility/cartesianToCompressed.hpp>
34#include <opm/input/eclipse/Units/UnitSystem.hpp>
35#include <opm/input/eclipse/Schedule/Network/Balance.hpp>
36#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
37#include <opm/input/eclipse/Schedule/Well/PAvgDynamicSourceData.hpp>
38#include <opm/input/eclipse/Schedule/Well/WellTestConfig.hpp>
59#include <fmt/format.h>
62 template<
typename TypeTag>
65 : BlackoilWellModelGeneric<Scalar>(simulator.vanguard().schedule(),
66 simulator.vanguard().summaryState(),
67 simulator.vanguard().eclState(),
69 simulator.gridView().comm())
70 , simulator_(simulator)
72 this->terminal_output_ = ((simulator.gridView().comm().rank() == 0) &&
73 Parameters::get<TypeTag, Properties::EnableTerminalOutput>());
75 local_num_cells_ = simulator_.gridView().size(0);
78 global_num_cells_ = simulator_.vanguard().globalNumCells();
81 auto& parallel_wells = simulator.vanguard().parallelWells();
83 this->parallel_well_info_.reserve(parallel_wells.size());
84 for(
const auto& name_bool : parallel_wells) {
85 this->parallel_well_info_.emplace_back(name_bool, grid().comm());
89 this->alternative_well_rate_init_ =
90 Parameters::get<TypeTag, Properties::AlternativeWellRateInit>();
92 this->wbpCalculationService_
93 .localCellIndex([
this](
const std::size_t globalIndex)
94 {
return this->compressedIndexForInterior(globalIndex); })
95 .evalCellSource([
this](
const int localCell,
96 PAvgDynamicSourceData::SourceDataSpan<Scalar> sourceTerms)
98 using Item =
typename PAvgDynamicSourceData::SourceDataSpan<Scalar>::Item;
100 const auto* intQuants = this->simulator_.model()
101 .cachedIntensiveQuantities(localCell, 0);
102 const auto& fs = intQuants->fluidState();
104 sourceTerms.set(Item::PoreVol, intQuants->porosity().value() *
105 this->simulator_.model().dofTotalVolume(localCell));
107 constexpr auto io = FluidSystem::oilPhaseIdx;
108 constexpr auto ig = FluidSystem::gasPhaseIdx;
109 constexpr auto iw = FluidSystem::waterPhaseIdx;
112 const auto haveOil = FluidSystem::phaseIsActive(io);
113 const auto haveGas = FluidSystem::phaseIsActive(ig);
114 const auto haveWat = FluidSystem::phaseIsActive(iw);
116 auto weightedPhaseDensity = [&fs](
const auto ip)
118 return fs.saturation(ip).value() * fs.density(ip).value();
121 if (haveOil) { sourceTerms.set(Item::Pressure, fs.pressure(io).value()); }
122 else if (haveGas) { sourceTerms.set(Item::Pressure, fs.pressure(ig).value()); }
123 else { sourceTerms.set(Item::Pressure, fs.pressure(iw).value()); }
127 if (haveOil) { rho += weightedPhaseDensity(io); }
128 if (haveGas) { rho += weightedPhaseDensity(ig); }
129 if (haveWat) { rho += weightedPhaseDensity(iw); }
131 sourceTerms.set(Item::MixtureDensity, rho);
135 template<
typename TypeTag>
142 template<
typename TypeTag>
147 extractLegacyCellPvtRegionIndex_();
148 extractLegacyDepth_();
150 gravity_ = simulator_.problem().gravity()[2];
152 this->initial_step_ =
true;
155 simulator_.model().addAuxiliaryModule(
this);
157 is_cell_perforated_.resize(local_num_cells_,
false);
161 template<
typename TypeTag>
166 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
167 + ScheduleEvents::NEW_WELL;
168 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
169 for (
auto& wellPtr : this->well_container_) {
170 const bool well_opened_this_step = this->report_step_starts_ && events.hasEvent(wellPtr->name(), effective_events_mask);
171 wellPtr->init(&this->phase_usage_, this->depth_, this->gravity_,
172 this->local_num_cells_, this->B_avg_, well_opened_this_step);
177 template<
typename TypeTag>
182 if (!param_.matrix_add_well_contributions_) {
187 const auto& schedule_wells = this->schedule().getWellsatEnd();
190 for (
const auto& well : schedule_wells)
192 std::vector<int> wellCells = this->getCellsForConnections(well);
193 for (
int cellIdx : wellCells) {
194 neighbors[cellIdx].insert(wellCells.begin(),
201 template<
typename TypeTag>
207 for (
const auto& well: well_container_) {
210 if (param_.matrix_add_well_contributions_) {
211 well->addWellContributions(jacobian);
218 simulator_.gridView().comm());
222 template<
typename TypeTag>
230 for (
const auto& well: well_container_) {
231 if (well_domain_.at(well->name()) == domain.
index) {
234 if (param_.matrix_add_well_contributions_) {
235 well->addWellContributions(jacobian);
245 template<
typename TypeTag>
252 this->report_step_starts_ =
true;
255 this->rateConverter_ = std::make_unique<RateConverterType>
256 (this->phase_usage_, std::vector<int>(this->local_num_cells_, 0));
260 const auto enableWellPIScaling =
true;
261 this->initializeLocalWellStructure(timeStepIdx, enableWellPIScaling);
264 this->initializeGroupStructure(timeStepIdx);
266 const auto& comm = this->simulator_.vanguard().grid().comm();
272 this->rateConverter_->template defineState<ElementContext>(this->simulator_);
276 const auto& sched_state = this->schedule()[timeStepIdx];
278 this->vfp_properties_ = std::make_unique<VFPProperties>
279 (sched_state.vfpinj(), sched_state.vfpprod(), this->wellState());
283 "beginReportStep() failed: ",
284 this->terminal_output_, comm)
288 this->commitWGState();
290 this->wellStructureChangedDynamically_ =
false;
297 template <
typename TypeTag>
301 const bool enableWellPIScaling)
305 const auto& comm = this->simulator_.vanguard().grid().comm();
308 this->wells_ecl_ = this->getLocalWells(reportStepIdx);
309 this->local_parallel_well_info_ =
310 this->createLocalParallelWellInfo(this->wells_ecl_);
317 this->initializeWellPerfData();
318 this->initializeWellState(reportStepIdx);
319 this->initializeWBPCalculationService();
321 if (this->param_.use_multisegment_well_ && this->anyMSWellOpenLocal()) {
322 this->wellState().initWellStateMSWell(this->wells_ecl_, &this->prevWellState());
325 this->initializeWellProdIndCalculators();
327 if (enableWellPIScaling && this->schedule()[reportStepIdx].events()
328 .hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX))
330 this->runWellPIScaling(reportStepIdx, local_deferredLogger);
334 "Failed to initialize local well structure: ",
335 this->terminal_output_, comm)
342 template <
typename TypeTag>
349 const auto& comm = this->simulator_.vanguard().grid().comm();
353 const auto& fieldGroup =
354 this->schedule().getGroup(
"FIELD", reportStepIdx);
358 this->summaryState(),
364 if (this->schedule()[reportStepIdx].has_gpmaint()) {
369 this->eclState_.fieldProps(),
371 this->regionalAveragePressureCalculator_);
375 "Failed to initialize group structure: ",
376 this->terminal_output_, comm)
384 template<
typename TypeTag>
389 OPM_TIMEBLOCK(beginTimeStep);
391 this->updateAverageFormationFactor();
395 this->switched_prod_groups_.clear();
396 this->switched_inj_groups_.clear();
398 if (this->wellStructureChangedDynamically_) {
403 const auto reportStepIdx =
404 this->simulator_.episodeIndex();
408 const auto enableWellPIScaling =
false;
410 this->initializeLocalWellStructure(reportStepIdx, enableWellPIScaling);
411 this->initializeGroupStructure(reportStepIdx);
413 this->commitWGState();
419 this->wellStructureChangedDynamically_ =
false;
422 this->resetWGState();
424 const int reportStepIdx = simulator_.episodeIndex();
425 this->updateAndCommunicateGroupData(reportStepIdx,
426 simulator_.model().newtonMethod().numIterations());
428 this->wellState().updateWellsDefaultALQ(this->wells_ecl_, this->summaryState());
429 this->wellState().gliftTimeStepInit();
431 const double simulationTime = simulator_.time();
435 wellTesting(reportStepIdx, simulationTime, local_deferredLogger);
438 createWellContainer(reportStepIdx);
441 const Grid& grid = simulator_.vanguard().grid();
442 this->wells_active_ = grid.comm().max(!this->well_container_.empty());
447 this->initWellContainer(reportStepIdx);
450 std::fill(is_cell_perforated_.begin(), is_cell_perforated_.end(),
false);
451 for (
auto& well : well_container_) {
452 well->updatePerforatedCell(is_cell_perforated_);
456 this->calculateEfficiencyFactors(reportStepIdx);
458 if constexpr (has_polymer_)
460 if (PolymerModule::hasPlyshlog() || getPropValue<TypeTag, Properties::EnablePolymerMW>() ) {
461 this->setRepRadiusPerfLength();
467 this->terminal_output_, simulator_.vanguard().grid().comm());
469 for (
auto& well : well_container_) {
470 well->setVFPProperties(this->vfp_properties_.get());
471 well->setGuideRate(&this->guideRate_);
474 this->updateInjFCMult(local_deferredLogger);
477 for (
auto& well : well_container_) {
478 well->closeCompletions(this->wellTestState());
484 const auto& summaryState = simulator_.vanguard().summaryState();
485 if (alternative_well_rate_init_) {
490 for (
auto& well : well_container_) {
491 const bool zero_target = well->stopppedOrZeroRateTarget(summaryState, this->wellState());
492 if (well->isProducer() && !zero_target) {
493 well->updateWellStateRates(simulator_, this->wellState(), local_deferredLogger);
498 for (
auto& well : well_container_) {
499 if (well->isVFPActive(local_deferredLogger)){
500 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
506 this->updateWellPotentials(reportStepIdx,
508 simulator_.vanguard().summaryConfig(),
509 local_deferredLogger);
510 }
catch ( std::runtime_error& e ) {
511 const std::string msg =
"A zero well potential is returned for output purposes. ";
512 local_deferredLogger.
warning(
"WELL_POTENTIAL_CALCULATION_FAILED", msg);
516 const auto& comm = simulator_.vanguard().grid().comm();
517 std::vector<Scalar> pot(this->numPhases(), 0.0);
518 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", reportStepIdx);
530 local_deferredLogger);
534 if (this->schedule_[reportStepIdx].has_gpmaint()) {
535 for (
auto& calculator : regionalAveragePressureCalculator_) {
536 calculator.second->template defineState<ElementContext>(simulator_);
538 const double dt = simulator_.timeStepSize();
541 regionalAveragePressureCalculator_,
549 for (
auto& well : well_container_) {
550 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
551 + ScheduleEvents::INJECTION_TYPE_CHANGED
552 + ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER
553 + ScheduleEvents::NEW_WELL;
555 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
556 const bool event = this->report_step_starts_ && events.hasEvent(well->name(), effective_events_mask);
557 const bool dyn_status_change = this->wellState().well(well->name()).status
558 != this->prevWellState().well(well->name()).status;
560 if (event || dyn_status_change) {
562 well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), local_deferredLogger);
563 well->calculateExplicitQuantities(simulator_, this->wellState(), local_deferredLogger);
564 well->solveWellEquation(simulator_, this->wellState(), this->groupState(), local_deferredLogger);
565 }
catch (
const std::exception& e) {
566 const std::string msg =
"Compute initial well solution for new well " + well->name() +
" failed. Continue with zero initial rates";
567 local_deferredLogger.
warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
576 const std::string msg =
"Compute initial well solution for new wells failed. Continue with zero initial rates";
577 local_deferredLogger.
warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
581 exc_type,
"beginTimeStep() failed: " + exc_msg, this->terminal_output_, comm);
585 template<
typename TypeTag>
588 const double simulationTime,
591 for (
const std::string& well_name : this->getWellsForTesting(timeStepIdx, simulationTime)) {
592 const Well& wellEcl = this->schedule().getWell(well_name, timeStepIdx);
593 if (wellEcl.getStatus() == Well::Status::SHUT)
596 WellInterfacePtr well = createWellForWellTest(well_name, timeStepIdx, deferred_logger);
598 well->init(&this->phase_usage_, depth_, gravity_, local_num_cells_, B_avg_,
true);
600 Scalar well_efficiency_factor = wellEcl.getEfficiencyFactor();
605 well_efficiency_factor);
607 well->setWellEfficiencyFactor(well_efficiency_factor);
608 well->setVFPProperties(this->vfp_properties_.get());
609 well->setGuideRate(&this->guideRate_);
612 if (well->isProducer()) {
613 well->updateWellStateRates(simulator_, this->wellState(), deferred_logger);
615 if (well->isVFPActive(deferred_logger)) {
616 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
620 well->wellTesting(simulator_, simulationTime, this->wellState(),
621 this->groupState(), this->wellTestState(), deferred_logger);
622 }
catch (
const std::exception& e) {
623 const std::string msg = fmt::format(
"Exception during testing of well: {}. The well will not open.\n Exception message: {}", wellEcl.name(), e.what());
624 deferred_logger.
warning(
"WELL_TESTING_FAILED", msg);
634 template<
typename TypeTag>
640 for (
auto&& pinfo : this->local_parallel_well_info_)
651 template<
typename TypeTag>
661 template<
typename TypeTag>
666 this->closed_this_step_.clear();
669 this->report_step_starts_ =
false;
670 const int reportStepIdx = simulator_.episodeIndex();
673 for (
const auto& well : well_container_) {
674 if (getPropValue<TypeTag, Properties::EnablePolymerMW>() && well->isInjector()) {
675 well->updateWaterThroughput(dt, this->wellState());
679 for (
const auto& well : well_container_) {
680 well->updateConnectionTransmissibilityFactor(simulator_, this->wellState().well(well->indexOfWell()));
681 well->updateConnectionDFactor(simulator_, this->wellState().well(well->indexOfWell()));
684 if (Indices::waterEnabled) {
685 this->updateFiltrationParticleVolume(dt, FluidSystem::waterPhaseIdx);
689 this->updateInjMult(local_deferredLogger);
692 for (
const auto& well : well_container_) {
693 well->reportWellSwitching(this->wellState().well(well->indexOfWell()), local_deferredLogger);
696 if (this->terminal_output_) {
698 for (
const auto& [name, to] : this->switched_prod_groups_) {
699 const Group::ProductionCMode& oldControl = this->prevWGState().group_state.production_control(name);
700 std::string from = Group::ProductionCMode2String(oldControl);
702 std::string msg =
" Production Group " + name
703 +
" control mode changed from ";
706 local_deferredLogger.
info(msg);
709 for (
const auto& [key, to] : this->switched_inj_groups_) {
710 const std::string& name = key.first;
711 const Opm::Phase& phase = key.second;
713 const Group::InjectionCMode& oldControl = this->prevWGState().group_state.injection_control(name, phase);
714 std::string from = Group::InjectionCMode2String(oldControl);
716 std::string msg =
" Injection Group " + name
717 +
" control mode changed from ";
720 local_deferredLogger.
info(msg);
726 rateConverter_->template defineState<ElementContext>(simulator_);
730 this->updateWellPotentials(reportStepIdx,
732 simulator_.vanguard().summaryConfig(),
733 local_deferredLogger);
734 }
catch ( std::runtime_error& e ) {
735 const std::string msg =
"A zero well potential is returned for output purposes. ";
736 local_deferredLogger.
warning(
"WELL_POTENTIAL_CALCULATION_FAILED", msg);
739 updateWellTestState(simulationTime, this->wellTestState());
742 const Group& fieldGroup = this->schedule_.getGroup(
"FIELD", reportStepIdx);
743 this->checkGEconLimits(fieldGroup, simulationTime,
744 simulator_.episodeIndex(), local_deferredLogger);
745 this->checkGconsaleLimits(fieldGroup, this->wellState(),
746 simulator_.episodeIndex(), local_deferredLogger);
748 this->calculateProductivityIndexValues(local_deferredLogger);
750 this->commitWGState();
754 if (this->terminal_output_) {
759 this->computeWellTemperature();
763 template<
typename TypeTag>
767 unsigned elemIdx)
const
771 if (!is_cell_perforated_[elemIdx])
774 for (
const auto& well : well_container_)
775 well->addCellRates(rate, elemIdx);
779 template<
typename TypeTag>
780 template <
class Context>
784 const Context& context,
786 unsigned timeIdx)
const
789 int elemIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
791 if (!is_cell_perforated_[elemIdx])
794 for (
const auto& well : well_container_)
795 well->addCellRates(rate, elemIdx);
800 template<
typename TypeTag>
805 std::vector<Scalar> cellPressures(this->local_num_cells_, 0.0);
808 const auto& gridView = simulator_.vanguard().gridView();
811 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
812 elemCtx.updatePrimaryStencil(elem);
813 elemCtx.updatePrimaryIntensiveQuantities(0);
815 const auto& fs = elemCtx.intensiveQuantities(0, 0).fluidState();
817 Scalar& perf_pressure = cellPressures[elemCtx.globalSpaceIndex(0, 0)];
818 if (Indices::oilEnabled) {
819 perf_pressure = fs.pressure(FluidSystem::oilPhaseIdx).value();
820 }
else if (Indices::waterEnabled) {
821 perf_pressure = fs.pressure(FluidSystem::waterPhaseIdx).value();
823 perf_pressure = fs.pressure(FluidSystem::gasPhaseIdx).value();
828 this->wellState().init(cellPressures, this->schedule(), this->wells_ecl_,
829 this->local_parallel_well_info_, timeStepIdx,
830 &this->prevWellState(), this->well_perf_data_,
831 this->summaryState());
838 template<
typename TypeTag>
845 const int nw = this->numLocalWells();
847 well_container_.clear();
850 well_container_.reserve(nw);
852 for (
int w = 0; w < nw; ++w) {
853 const Well& well_ecl = this->wells_ecl_[w];
855 if (!well_ecl.hasConnections()) {
860 const std::string& well_name = well_ecl.name();
861 const auto well_status = this->schedule()
862 .getWell(well_name, report_step).getStatus();
864 if ((well_ecl.getStatus() == Well::Status::SHUT) ||
865 (well_status == Well::Status::SHUT))
868 if (well_ecl.getStatus() != Well::Status::SHUT) {
869 this->closed_this_step_.insert(well_name);
870 this->wellState().shutWell(w);
877 if (this->wellTestState().well_is_closed(well_name)) {
882 const bool closed_this_step = (this->wellTestState().lastTestTime(well_name) == simulator_.time());
885 auto& events = this->wellState().well(w).events;
886 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
887 if (!closed_this_step) {
888 this->wellTestState().open_well(well_name);
889 this->wellTestState().open_completions(well_name);
891 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
897 bool wellIsStopped =
false;
898 if (this->wellTestState().well_is_closed(well_name))
900 if (well_ecl.getAutomaticShutIn()) {
902 this->wellState().shutWell(w);
905 if (!well_ecl.getAllowCrossFlow()) {
908 this->wellState().shutWell(w);
912 this->wellState().stopWell(w);
913 wellIsStopped =
true;
918 if (!well_ecl.getAllowCrossFlow()) {
919 const bool any_zero_rate_constraint = well_ecl.isProducer()
920 ? well_ecl.productionControls(this->summaryState_).anyZeroRateConstraint()
921 : well_ecl.injectionControls(this->summaryState_).anyZeroRateConstraint();
922 if (any_zero_rate_constraint) {
924 local_deferredLogger.
debug(fmt::format(
" Well {} gets shut due to having zero rate constraint and disallowing crossflow ", well_ecl.name()) );
925 this->wellState().shutWell(w);
930 if (well_status == Well::Status::STOP) {
931 this->wellState().stopWell(w);
932 wellIsStopped =
true;
935 well_container_.emplace_back(this->createWellPointer(w, report_step));
938 well_container_.back()->stopWell();
946 if (this->terminal_output_) {
950 this->well_container_generic_.clear();
951 for (
auto& w : well_container_)
952 this->well_container_generic_.push_back(w.get());
954 const auto& network = this->schedule()[report_step].network();
955 if (network.active() && !this->node_pressures_.empty()) {
956 for (
auto& well: this->well_container_generic_) {
960 if (well->isProducer()) {
961 const auto it = this->node_pressures_.find(well->wellEcl().groupName());
962 if (it != this->node_pressures_.end()) {
965 const Scalar nodal_pressure = it->second;
966 well->setDynamicThpLimit(nodal_pressure);
972 this->registerOpenWellsForWBPCalculation();
979 template <
typename TypeTag>
984 const auto is_multiseg = this->wells_ecl_[wellID].isMultiSegment();
986 if (! (this->param_.use_multisegment_well_ && is_multiseg)) {
987 return this->
template createTypedWellPointer<StandardWell<TypeTag>>(wellID, report_step);
990 return this->
template createTypedWellPointer<MultisegmentWell<TypeTag>>(wellID, report_step);
998 template <
typename TypeTag>
999 template <
typename WellType>
1000 std::unique_ptr<WellType>
1005 const auto& perf_data = this->well_perf_data_[wellID];
1008 const auto pvtreg = perf_data.empty()
1009 ? 0 : this->pvt_region_idx_[perf_data.front().cell_index];
1011 const auto& parallel_well_info = this->local_parallel_well_info_[wellID].get();
1012 const auto global_pvtreg = parallel_well_info.broadcastFirstPerforationValue(pvtreg);
1014 return std::make_unique<WellType>(this->wells_ecl_[wellID],
1018 *this->rateConverter_,
1020 this->numComponents(),
1030 template<
typename TypeTag>
1034 const int report_step,
1038 const int nw_wells_ecl = this->wells_ecl_.size();
1039 int index_well_ecl = 0;
1040 for (; index_well_ecl < nw_wells_ecl; ++index_well_ecl) {
1041 if (well_name == this->wells_ecl_[index_well_ecl].name()) {
1046 if (index_well_ecl == nw_wells_ecl) {
1048 fmt::format(
"Could not find well {} in wells_ecl ", well_name),
1052 return this->createWellPointer(index_well_ecl, report_step);
1057 template<
typename TypeTag>
1061 const double dt = this->simulator_.timeStepSize();
1063 auto& well_state = this->wellState();
1064 const std::size_t max_iter = param_.network_max_iterations_;
1065 bool converged =
false;
1066 std::size_t iter = 0;
1067 bool changed_well_group =
false;
1069 changed_well_group = updateWellControlsAndNetwork(
true, dt, deferred_logger);
1070 assembleWellEqWithoutIteration(dt, deferred_logger);
1071 converged = this->getWellConvergence(this->B_avg_,
true).converged() && !changed_well_group;
1076 for (
auto& well : this->well_container_) {
1077 const auto& summary_state = this->simulator_.vanguard().summaryState();
1078 well->solveEqAndUpdateWellState(summary_state, well_state, deferred_logger);
1080 this->initPrimaryVariablesEvaluation();
1081 }
while (iter < max_iter);
1084 const std::string msg = fmt::format(
"Initial (pre-step) network balance did not get converged with {} iterations, "
1085 "unconverged network balance result will be used", max_iter);
1088 const std::string msg = fmt::format(
"Initial (pre-step) network balance converged with {} iterations", iter);
1089 deferred_logger.
debug(msg);
1096 template<
typename TypeTag>
1104 if (this->glift_debug) {
1105 const std::string msg = fmt::format(
1106 "assemble() : iteration {}" , iterationIdx);
1107 this->gliftDebug(msg, local_deferredLogger);
1110 Dune::Timer perfTimer;
1112 this->closed_offending_wells_.clear();
1115 const int episodeIdx = simulator_.episodeIndex();
1116 const auto& network = this->schedule()[episodeIdx].network();
1117 if (!this->wellsActive() && !network.active()) {
1122 if (iterationIdx == 0 && this->wellsActive()) {
1129 calculateExplicitQuantities(local_deferredLogger);
1130 prepareTimeStep(local_deferredLogger);
1133 "assemble() failed (It=0): ",
1134 this->terminal_output_, grid().comm());
1137 const bool well_group_control_changed = updateWellControlsAndNetwork(
false, dt, local_deferredLogger);
1141 if ( ! this->wellsActive() ) {
1145 assembleWellEqWithoutIteration(dt, local_deferredLogger);
1149 last_report_.well_group_control_changed = well_group_control_changed;
1150 last_report_.assemble_time_well += perfTimer.stop();
1156 template<
typename TypeTag>
1162 bool do_network_update =
true;
1163 bool well_group_control_changed =
false;
1165 const std::size_t iteration_to_relax = param_.network_max_strict_iterations_;
1167 const std::size_t max_iteration = param_.network_max_iterations_;
1168 std::size_t network_update_iteration = 0;
1169 while (do_network_update) {
1170 if (this->terminal_output_ && (network_update_iteration == iteration_to_relax) ) {
1171 local_deferredLogger.
info(
" we begin using relaxed tolerance for network update now after " +
std::to_string(iteration_to_relax) +
" iterations ");
1173 const bool relax_network_balance = network_update_iteration >= iteration_to_relax;
1174 std::tie(do_network_update, well_group_control_changed) =
1175 updateWellControlsAndNetworkIteration(mandatory_network_balance, relax_network_balance, dt,local_deferredLogger);
1176 ++network_update_iteration;
1178 if (network_update_iteration >= max_iteration ) {
1179 if (this->terminal_output_) {
1180 local_deferredLogger.
info(
"maximum of " +
std::to_string(max_iteration) +
" iterations has been used, we stop the network update now. "
1181 "The simulation will continue with unconverged network results");
1186 return well_group_control_changed;
1192 template<
typename TypeTag>
1193 std::pair<bool, bool>
1196 const bool relax_network_tolerance,
1200 auto [well_group_control_changed, more_network_update] =
1201 updateWellControls(mandatory_network_balance, local_deferredLogger, relax_network_tolerance);
1203 bool alq_updated =
false;
1207 initPrimaryVariablesEvaluation();
1209 alq_updated = maybeDoGasLiftOptimize(local_deferredLogger);
1211 prepareWellsBeforeAssembling(dt, local_deferredLogger);
1214 this->terminal_output_, grid().comm());
1217 const int reportStepIdx = simulator_.episodeIndex();
1219 guideRateUpdateIsNeeded(reportStepIdx)) {
1220 const double simulationTime = simulator_.time();
1221 const auto& comm = simulator_.vanguard().grid().comm();
1222 const auto& summaryState = simulator_.vanguard().summaryState();
1223 std::vector<Scalar> pot(this->numPhases(), 0.0);
1224 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", reportStepIdx);
1236 local_deferredLogger);
1239 return {more_network_update, well_group_control_changed};
1244 template<
typename TypeTag>
1252 Dune::Timer perfTimer;
1256 const int episodeIdx = simulator_.episodeIndex();
1257 const auto& network = this->schedule()[episodeIdx].network();
1258 if (!this->wellsActive() && !network.active()) {
1269 updateWellControlsDomain(local_deferredLogger, domain);
1270 initPrimaryVariablesEvaluationDomain(domain);
1271 assembleWellEqDomain(dt, domain, local_deferredLogger);
1275 if (this->terminal_output_) {
1279 last_report_.converged =
true;
1280 last_report_.assemble_time_well += perfTimer.stop();
1284 template<
typename TypeTag>
1289 bool do_glift_optimization =
false;
1290 int num_wells_changed = 0;
1291 const double simulation_time = simulator_.time();
1292 const Scalar min_wait = simulator_.vanguard().schedule().glo(simulator_.episodeIndex()).min_wait();
1297 if ( simulation_time == this->last_glift_opt_time_ || simulation_time >= (this->last_glift_opt_time_ + min_wait)) {
1298 do_glift_optimization =
true;
1299 this->last_glift_opt_time_ = simulation_time;
1302 if (do_glift_optimization) {
1314 initGliftEclWellMap(ecl_well_map);
1317 simulator_.vanguard().schedule(),
1318 simulator_.vanguard().summaryState(),
1319 simulator_.episodeIndex(),
1320 simulator_.model().newtonMethod().numIterations(),
1325 simulator_.vanguard().grid().comm(),
1328 group_info.initialize();
1329 gasLiftOptimizationStage1(deferred_logger, prod_wells, glift_wells,
1330 group_info, state_map);
1331 this->gasLiftOptimizationStage2(deferred_logger, prod_wells, glift_wells,
1332 group_info, state_map, simulator_.episodeIndex());
1333 if (this->glift_debug) {
1334 this->gliftDebugShowALQ(deferred_logger);
1336 num_wells_changed = glift_wells.size();
1338 num_wells_changed = this->comm_.sum(num_wells_changed);
1339 return num_wells_changed > 0;
1342 template<
typename TypeTag>
1349 auto comm = simulator_.vanguard().grid().comm();
1350 int num_procs = comm.size();
1376 for (
int i = 0; i< num_procs; i++) {
1377 int num_rates_to_sync = 0;
1379 if (comm.rank() == i) {
1381 for (
const auto& well : well_container_) {
1383 if (group_info.
hasWell(well->name())) {
1384 gasLiftOptimizationStage1SingleWell(
1385 well.get(), deferred_logger, prod_wells, glift_wells,
1386 group_info, state_map, groups_to_sync
1390 num_rates_to_sync = groups_to_sync.size();
1392 num_rates_to_sync = comm.sum(num_rates_to_sync);
1393 if (num_rates_to_sync > 0) {
1394 std::vector<int> group_indexes;
1395 group_indexes.reserve(num_rates_to_sync);
1396 std::vector<Scalar> group_alq_rates;
1397 group_alq_rates.reserve(num_rates_to_sync);
1398 std::vector<Scalar> group_oil_rates;
1399 group_oil_rates.reserve(num_rates_to_sync);
1400 std::vector<Scalar> group_gas_rates;
1401 group_gas_rates.reserve(num_rates_to_sync);
1402 std::vector<Scalar> group_water_rates;
1403 group_water_rates.reserve(num_rates_to_sync);
1404 if (comm.rank() == i) {
1405 for (
auto idx : groups_to_sync) {
1406 auto [oil_rate, gas_rate, water_rate, alq] = group_info.
getRates(idx);
1407 group_indexes.push_back(idx);
1408 group_oil_rates.push_back(oil_rate);
1409 group_gas_rates.push_back(gas_rate);
1410 group_water_rates.push_back(water_rate);
1411 group_alq_rates.push_back(alq);
1414 group_indexes.resize(num_rates_to_sync);
1415 group_oil_rates.resize(num_rates_to_sync);
1416 group_gas_rates.resize(num_rates_to_sync);
1417 group_water_rates.resize(num_rates_to_sync);
1418 group_alq_rates.resize(num_rates_to_sync);
1422 ser.
broadcast(i, group_indexes, group_oil_rates,
1423 group_gas_rates, group_water_rates, group_alq_rates);
1425 if (comm.rank() != i) {
1426 for (
int j=0; j<num_rates_to_sync; j++) {
1428 group_oil_rates[j], group_gas_rates[j], group_water_rates[j], group_alq_rates[j]);
1431 if (this->glift_debug) {
1433 if (comm.rank() == i) {
1434 counter = this->wellState().gliftGetDebugCounter();
1436 counter = comm.sum(counter);
1437 if (comm.rank() != i) {
1438 this->wellState().gliftSetDebugCounter(counter);
1448 template<
typename TypeTag>
1457 const auto& summary_state = simulator_.vanguard().summaryState();
1458 std::unique_ptr<GasLiftSingleWell> glift
1459 = std::make_unique<GasLiftSingleWell>(
1460 *well, simulator_, summary_state,
1461 deferred_logger, this->wellState(), this->groupState(),
1462 group_info, sync_groups, this->comm_, this->glift_debug);
1463 auto state = glift->runOptimize(
1464 simulator_.model().newtonMethod().numIterations());
1466 state_map.insert({well->
name(), std::move(state)});
1467 glift_wells.insert({well->
name(), std::move(glift)});
1470 prod_wells.insert({well->
name(), well});
1474 template<
typename TypeTag>
1479 for (
const auto& well: well_container_ ) {
1480 ecl_well_map.try_emplace(
1481 well->name(), &(well->wellEcl()), well->indexOfWell());
1486 template<
typename TypeTag>
1491 for (
auto& well : well_container_) {
1492 well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1497 template<
typename TypeTag>
1502 for (
auto& well : well_container_) {
1503 if (well_domain_.at(well->name()) == domain.
index) {
1504 well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1510 template<
typename TypeTag>
1515 for (
auto& well : well_container_) {
1516 well->prepareWellBeforeAssembling(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
1521 template<
typename TypeTag>
1530 for (
auto& well: well_container_) {
1531 well->assembleWellEqWithoutIteration(simulator_, dt, this->wellState(), this->groupState(),
1535 this->terminal_output_, grid().comm());
1540 template<
typename TypeTag>
1545 for (
auto& well : well_container_) {
1552 template<
typename TypeTag>
1557 for (
auto& well : well_container_) {
1562#if COMPILE_BDA_BRIDGE
1563 template<
typename TypeTag>
1571 for(
unsigned int i = 0; i < well_container_.size(); i++){
1572 auto& well = well_container_[i];
1573 std::shared_ptr<StandardWell<TypeTag> > derived = std::dynamic_pointer_cast<StandardWell<TypeTag> >(well);
1575 wellContribs.
addNumBlocks(derived->linSys().getNumBlocks());
1580 wellContribs.
alloc();
1582 for(
unsigned int i = 0; i < well_container_.size(); i++){
1583 auto& well = well_container_[i];
1585 auto derived_std = std::dynamic_pointer_cast<StandardWell<TypeTag>>(well);
1587 derived_std->linSys().extract(derived_std->numStaticWellEq, wellContribs);
1589 auto derived_ms = std::dynamic_pointer_cast<MultisegmentWell<TypeTag> >(well);
1591 derived_ms->linSys().extract(wellContribs);
1593 OpmLog::warning(
"Warning unknown type of well");
1601 template<
typename TypeTag>
1606 if (this->well_container_.empty()) {
1610 if( scaleAddRes_.size() != Ax.size() ) {
1611 scaleAddRes_.resize( Ax.size() );
1616 apply( x, scaleAddRes_ );
1618 Ax.axpy( alpha, scaleAddRes_ );
1621 template<
typename TypeTag>
1626 for (
const auto& well: well_container_ ) {
1627 well->addWellContributions(jacobian);
1631 template<
typename TypeTag>
1636 int nw = this->numLocalWellsEnd();
1637 int rdofs = local_num_cells_;
1638 for (
int i = 0; i < nw; i++ ){
1639 int wdof = rdofs + i;
1640 jacobian[wdof][wdof] = 1.0;
1643 for (
const auto& well : well_container_ ) {
1644 well->addWellPressureEquations(jacobian, weights, pressureVarIndex, use_well_weights, this->wellState());
1648 template <
typename TypeTag>
1651 std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress)
const
1656 for (
const auto& well : well_container_) {
1657 if (!well->isOperableAndSolvable() && !well->wellIsStopped()) {
1660 const auto& cells = well->cells();
1661 const auto& rates = well->connectionRates();
1662 for (
unsigned perfIdx = 0; perfIdx < rates.size(); ++perfIdx) {
1663 unsigned cellIdx = cells[perfIdx];
1664 auto rate = rates[perfIdx];
1667 using MatrixBlockType =
typename SparseMatrixAdapter::MatrixBlock;
1668 MatrixBlockType bMat(0.0);
1669 simulator_.model().linearizer().setResAndJacobi(res, bMat, rate);
1670 residual[cellIdx] += res;
1671 *diagMatAddress[cellIdx] += bMat;
1677 template<
typename TypeTag>
1682 int nw = this->numLocalWellsEnd();
1683 int rdofs = local_num_cells_;
1684 for(
int i=0; i < nw; i++){
1685 int wdof = rdofs + i;
1686 jacobian.entry(wdof,wdof) = 1.0;
1688 std::vector<std::vector<int>> wellconnections = this->getMaxWellConnections();
1689 for(
int i=0; i < nw; i++){
1690 const auto& perfcells = wellconnections[i];
1691 for(
int perfcell : perfcells){
1692 int wdof = rdofs + i;
1693 jacobian.entry(wdof,perfcell) = 0.0;
1694 jacobian.entry(perfcell, wdof) = 0.0;
1700 template<
typename TypeTag>
1708 const auto& summary_state = simulator_.vanguard().summaryState();
1709 for (
auto& well : well_container_) {
1710 well->recoverWellSolutionAndUpdateWellState(summary_state, x, this->wellState(), local_deferredLogger);
1714 "recoverWellSolutionAndUpdateWellState() failed: ",
1715 this->terminal_output_, simulator_.vanguard().grid().comm());
1719 template<
typename TypeTag>
1728 const auto& summary_state = this->simulator_.vanguard().summaryState();
1729 for (
auto& well : well_container_) {
1730 if (well_domain_.at(well->name()) == domain.
index) {
1731 well->recoverWellSolutionAndUpdateWellState(summary_state, x,
1733 local_deferredLogger);
1738 if (this->terminal_output_) {
1744 template<
typename TypeTag>
1749 for (
auto& well : well_container_) {
1750 well->initPrimaryVariablesEvaluation();
1755 template<
typename TypeTag>
1760 for (
auto& well : well_container_) {
1761 if (well_domain_.at(well->name()) == domain.
index) {
1762 well->initPrimaryVariablesEvaluation();
1772 template<
typename TypeTag>
1776 const std::vector<Scalar>& B_avg,
1779 const auto& summary_state = simulator_.vanguard().summaryState();
1780 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
1781 const bool relax_tolerance = iterationIdx > param_.strict_outer_iter_wells_;
1784 for (
const auto& well : well_container_) {
1785 if ((well_domain_.at(well->name()) == domain.
index)) {
1786 if (well->isOperableAndSolvable() || well->wellIsStopped()) {
1787 report += well->getWellConvergence(summary_state,
1790 local_deferredLogger,
1795 xreport.
setWellFailed({CR::WellFailure::Type::Unsolvable, CR::Severity::Normal, -1, well->name()});
1802 if (this->terminal_output_) {
1805 local_deferredLogger.
debug(
"NaN residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1807 local_deferredLogger.
debug(
"Too large residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1818 template<
typename TypeTag>
1821 getWellConvergence(
const std::vector<Scalar>& B_avg,
bool checkWellGroupControls)
const
1827 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
1828 for (
const auto& well : well_container_) {
1829 if (well->isOperableAndSolvable() || well->wellIsStopped()) {
1830 const auto& summary_state = simulator_.vanguard().summaryState();
1831 local_report += well->getWellConvergence(
1832 summary_state, this->wellState(), B_avg, local_deferredLogger,
1833 iterationIdx > param_.strict_outer_iter_wells_);
1837 report.
setWellFailed({CR::WellFailure::Type::Unsolvable, CR::Severity::Normal, -1, well->name()});
1838 local_report += report;
1847 if (checkWellGroupControls) {
1851 if (this->terminal_output_) {
1855 if (this->terminal_output_) {
1858 OpmLog::debug(
"NaN residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1860 OpmLog::debug(
"Too large residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1871 template<
typename TypeTag>
1877 for (
auto& well : well_container_) {
1878 well->calculateExplicitQuantities(simulator_, this->wellState(), deferred_logger);
1886 template<
typename TypeTag>
1887 std::pair<bool, bool>
1891 const int episodeIdx = simulator_.episodeIndex();
1892 const auto& network = this->schedule()[episodeIdx].network();
1893 if (!this->wellsActive() && !network.active()) {
1894 return {
false,
false};
1897 const int iterationIdx = simulator_.model().newtonMethod().numIterations();
1898 const auto& comm = simulator_.vanguard().grid().comm();
1899 this->updateAndCommunicateGroupData(episodeIdx, iterationIdx);
1902 bool more_network_update =
false;
1903 if (this->shouldBalanceNetwork(episodeIdx, iterationIdx) || mandatory_network_balance) {
1904 const auto local_network_imbalance = this->updateNetworkPressures(episodeIdx);
1905 const Scalar network_imbalance = comm.max(local_network_imbalance);
1906 const auto& balance = this->schedule()[episodeIdx].network_balance();
1907 constexpr Scalar relaxation_factor = 10.0;
1908 const Scalar tolerance = relax_network_tolerance ? relaxation_factor * balance.pressure_tolerance() : balance.pressure_tolerance();
1909 more_network_update = this->networkActive() && network_imbalance > tolerance;
1912 bool changed_well_group =
false;
1914 const int nupcol = this->schedule()[episodeIdx].nupcol();
1917 if (iterationIdx <= nupcol) {
1918 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", episodeIdx);
1919 changed_well_group = updateGroupControls(fieldGroup, deferred_logger, episodeIdx, iterationIdx);
1922 bool changed_well_to_group =
false;
1927 for (
const auto& well : well_container_) {
1929 const bool changed_well = well->
updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
1931 changed_well_to_group = changed_well || changed_well_to_group;
1935 simulator_.gridView().comm());
1938 changed_well_to_group = comm.sum(
static_cast<int>(changed_well_to_group));
1939 if (changed_well_to_group) {
1940 updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger);
1941 changed_well_group =
true;
1945 bool changed_well_individual =
false;
1950 for (
const auto& well : well_container_) {
1952 const bool changed_well = well->
updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
1954 changed_well_individual = changed_well || changed_well_individual;
1958 simulator_.gridView().comm());
1961 changed_well_individual = comm.sum(
static_cast<int>(changed_well_individual));
1962 if (changed_well_individual) {
1963 updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger);
1964 changed_well_group =
true;
1968 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", episodeIdx);
1969 this->updateWsolvent(fieldGroup, episodeIdx, this->nupcolWellState());
1971 return { changed_well_group, more_network_update };
1974 template<
typename TypeTag>
1979 if ( !this->wellsActive() ) return ;
1985 for (
const auto& well : well_container_) {
1986 if (well_domain_.at(well->name()) == domain.
index) {
1988 well->
updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
1997 template <
typename TypeTag>
2002 this->wbpCalcMap_.clear();
2003 this->wbpCalcMap_.resize(this->wells_ecl_.size());
2005 this->registerOpenWellsForWBPCalculation();
2007 auto wellID = std::size_t{0};
2008 for (
const auto& well : this->wells_ecl_) {
2009 this->wbpCalcMap_[wellID].wbpCalcIdx_ = this->wbpCalculationService_
2010 .createCalculator(well,
2011 this->local_parallel_well_info_[wellID],
2012 this->conn_idx_map_[wellID].local(),
2013 this->makeWellSourceEvaluatorFactory(wellID));
2018 this->wbpCalculationService_.defineCommunication();
2025 template <
typename TypeTag>
2026 data::WellBlockAveragePressures
2030 auto wbpResult = data::WellBlockAveragePressures{};
2032 using Calculated = PAvgCalculator::Result::WBPMode;
2033 using Output = data::WellBlockAvgPress::Quantity;
2035 this->wbpCalculationService_.collectDynamicValues();
2037 const auto numWells = this->wells_ecl_.size();
2038 for (
auto wellID = 0*numWells; wellID < numWells; ++wellID) {
2039 const auto calcIdx = this->wbpCalcMap_[wellID].wbpCalcIdx_;
2040 const auto& well = this->wells_ecl_[wellID];
2042 if (! well.hasRefDepth()) {
2048 this->wbpCalculationService_
2049 .inferBlockAveragePressures(calcIdx, well.pavg(),
2051 well.getWPaveRefDepth());
2053 const auto& result = this->wbpCalculationService_
2054 .averagePressures(calcIdx);
2056 auto& reported = wbpResult.values[well.name()];
2058 reported[Output::WBP] = result.value(Calculated::WBP);
2059 reported[Output::WBP4] = result.value(Calculated::WBP4);
2060 reported[Output::WBP5] = result.value(Calculated::WBP5);
2061 reported[Output::WBP9] = result.value(Calculated::WBP9);
2071 template <
typename TypeTag>
2076 using Span = PAvgDynamicSourceData::SourceDataSpan<Scalar>;
2077 using Item =
typename Span::Item;
2081 if (! this->wbpCalcMap_[wellIdx].openWellIdx_.has_value()) {
2083 return []([[maybe_unused]]
const int connIdx, Span sourceTerm)
2089 .set(Item::Pressure , 0.0)
2090 .set(Item::PoreVol , 0.0)
2091 .set(Item::MixtureDensity, 0.0);
2096 return [
this, wellPtr = this->well_container_[*this->wbpCalcMap_[wellIdx].openWellIdx_].get()]
2097 (
const int connIdx, Span sourceTerm)
2103 const auto& connIdxMap =
2104 this->conn_idx_map_[wellPtr->indexOfWell()];
2106 const auto rho = wellPtr->
2107 connectionDensity(connIdxMap.global(connIdx),
2108 connIdxMap.open(connIdx));
2111 .set(Item::Pressure , 0.0)
2112 .set(Item::PoreVol , 0.0)
2113 .set(Item::MixtureDensity, rho);
2122 template <
typename TypeTag>
2127 assert (this->wbpCalcMap_.size() == this->wells_ecl_.size());
2129 for (
auto& wbpCalc : this->wbpCalcMap_) {
2130 wbpCalc.openWellIdx_.reset();
2133 auto openWellIdx =
typename std::vector<WellInterfacePtr>::size_type{0};
2134 for (
const auto* openWell : this->well_container_generic_) {
2135 this->wbpCalcMap_[openWell->indexOfWell()].openWellIdx_ = openWellIdx++;
2143 template<
typename TypeTag>
2147 const int iterationIdx,
2150 this->updateAndCommunicateGroupData(reportStepIdx, iterationIdx);
2156 for (
const auto& well : well_container_) {
2157 well->updateWellStateWithTarget(simulator_, this->groupState(),
2158 this->wellState(), deferred_logger);
2161 simulator_.gridView().comm())
2162 this->updateAndCommunicateGroupData(reportStepIdx, iterationIdx);
2165 template<
typename TypeTag>
2170 const int reportStepIdx,
2171 const int iterationIdx)
2173 bool changed =
false;
2174 bool changed_hc = this->checkGroupHigherConstraints( group, deferred_logger, reportStepIdx);
2177 updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger);
2180 bool changed_individual =
2182 updateGroupIndividualControl(group,
2184 this->switched_inj_groups_,
2185 this->switched_prod_groups_,
2186 this->closed_offending_wells_,
2191 if (changed_individual) {
2193 updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger);
2196 for (
const std::string& groupName : group.groups()) {
2197 bool changed_this = updateGroupControls( this->schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx,iterationIdx);
2198 changed = changed || changed_this;
2203 template<
typename TypeTag>
2209 for (
const auto& well : well_container_) {
2210 const auto& wname = well->name();
2211 const auto wasClosed = wellTestState.well_is_closed(wname);
2212 well->checkWellOperability(simulator_, this->wellState(), local_deferredLogger);
2213 well->updateWellTestState(this->wellState().well(wname), simulationTime,
true, wellTestState, local_deferredLogger);
2215 if (!wasClosed && wellTestState.well_is_closed(wname)) {
2216 this->closed_this_step_.insert(wname);
2223 for (
const auto& [group_name, to] : this->closed_offending_wells_) {
2224 if (!this->wasDynamicallyShutThisTimeStep(to.second)) {
2225 wellTestState.close_well(to.second, WellTestConfig::Reason::GROUP, simulationTime);
2226 this->updateClosedWellsThisStep(to.second);
2227 const std::string msg =
2228 fmt::format(
"Procedure on exceeding {} limit is WELL for group {}. Well {} is {}.",
2233 global_deferredLogger.
info(msg);
2237 if (this->terminal_output_) {
2243 template<
typename TypeTag>
2247 std::string& exc_msg,
2251 const int np = this->numPhases();
2252 std::vector<Scalar> potentials;
2253 const auto& well = well_container_[widx];
2254 std::string cur_exc_msg;
2257 well->computeWellPotentials(simulator_, well_state_copy, potentials, deferred_logger);
2262 exc_msg += fmt::format(
"\nFor well {}: {}", well->name(), cur_exc_msg);
2264 exc_type = std::max(exc_type, cur_exc_type);
2268 auto& ws = this->wellState().well(well->indexOfWell());
2269 for (
int p = 0; p < np; ++p) {
2271 ws.well_potentials[p] = std::max(0.0, potentials[p]);
2277 template <
typename TypeTag>
2282 for (
const auto& wellPtr : this->well_container_) {
2283 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2291 template <
typename TypeTag>
2302 for (
const auto& shutWell : this->local_shut_wells_) {
2303 if (!this->wells_ecl_[shutWell].hasConnections()) {
2308 auto wellPtr = this->
template createTypedWellPointer
2311 wellPtr->
init(&this->phase_usage_, this->depth_, this->gravity_,
2312 this->local_num_cells_, this->B_avg_,
true);
2314 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2322 template <
typename TypeTag>
2336 template<
typename TypeTag>
2342 const auto episodeIdx = simulator_.episodeIndex();
2343 this->updateNetworkActiveState(episodeIdx);
2347 const bool do_prestep_network_rebalance = this->needPreStepNetworkRebalance(episodeIdx);
2349 for (
const auto& well : well_container_) {
2350 auto& events = this->wellState().well(well->indexOfWell()).events;
2352 well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger);
2353 const auto& summary_state = simulator_.vanguard().summaryState();
2354 well->updatePrimaryVariables(summary_state, this->wellState(), deferred_logger);
2355 well->initPrimaryVariablesEvaluation();
2361 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
2362 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
2365 if (param_.solve_welleq_initially_ && well->isOperableAndSolvable()) {
2367 well->solveWellEquation(simulator_, this->wellState(), this->groupState(), deferred_logger);
2368 }
catch (
const std::exception& e) {
2369 const std::string msg =
"Compute initial well solution for " + well->name() +
" initially failed. Continue with the previous rates";
2370 deferred_logger.
warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
2375 well->resetWellOperability();
2377 updatePrimaryVariables(deferred_logger);
2380 if (do_prestep_network_rebalance) doPreStepNetworkRebalance(deferred_logger);
2383 template<
typename TypeTag>
2388 std::vector< Scalar > B_avg(numComponents(),
Scalar() );
2389 const auto& grid = simulator_.vanguard().grid();
2390 const auto& gridView = grid.leafGridView();
2394 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
2395 elemCtx.updatePrimaryStencil(elem);
2396 elemCtx.updatePrimaryIntensiveQuantities(0);
2398 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
2399 const auto& fs = intQuants.fluidState();
2401 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
2403 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2407 const unsigned compIdx = Indices::canonicalToActiveComponentIndex(FluidSystem::solventComponentIndex(phaseIdx));
2408 auto& B = B_avg[ compIdx ];
2410 B += 1 / fs.invB(phaseIdx).value();
2412 if constexpr (has_solvent_) {
2413 auto& B = B_avg[solventSaturationIdx];
2414 B += 1 / intQuants.solventInverseFormationVolumeFactor().value();
2420 grid.comm().sum(B_avg.data(), B_avg.size());
2421 for (
auto& bval : B_avg)
2423 bval /= global_num_cells_;
2432 template<
typename TypeTag>
2437 for (
const auto& well : well_container_) {
2438 const auto& summary_state = simulator_.vanguard().summaryState();
2439 well->updatePrimaryVariables(summary_state, this->wellState(), deferred_logger);
2443 template<
typename TypeTag>
2447 const auto& grid = simulator_.vanguard().grid();
2448 const auto& eclProblem = simulator_.problem();
2449 const unsigned numCells = grid.size(0);
2451 this->pvt_region_idx_.resize(numCells);
2452 for (
unsigned cellIdx = 0; cellIdx < numCells; ++cellIdx) {
2453 this->pvt_region_idx_[cellIdx] =
2454 eclProblem.pvtRegionIndex(cellIdx);
2459 template<
typename TypeTag>
2469 int numComp = this->numPhases() < 3 ? this->numPhases() : FluidSystem::numComponents;
2470 if constexpr (has_solvent_) {
2476 template<
typename TypeTag>
2480 const auto& eclProblem = simulator_.problem();
2481 depth_.resize(local_num_cells_);
2482 for (
unsigned cellIdx = 0; cellIdx < local_num_cells_; ++cellIdx) {
2483 depth_[cellIdx] = eclProblem.dofCenterDepth(cellIdx);
2487 template<
typename TypeTag>
2490 getWell(
const std::string& well_name)
const
2493 auto well = std::find_if(well_container_.begin(),
2494 well_container_.end(),
2496 return elem->name() == well_name;
2499 assert(well != well_container_.end());
2504 template<
typename TypeTag>
2507 hasWell(
const std::string& well_name)
const
2509 return std::any_of(well_container_.begin(), well_container_.end(),
2512 return elem->name() == well_name;
2519 template <
typename TypeTag>
2524 return std::max(this->simulator_.episodeIndex(), 0);
2531 template<
typename TypeTag>
2536 const std::vector<Scalar>& production_rates,
2537 std::vector<Scalar>& resv_coeff)
2539 rateConverter_->calcCoeff(fipnum, pvtreg, production_rates, resv_coeff);
2542 template<
typename TypeTag>
2547 std::vector<Scalar>& resv_coeff)
2549 rateConverter_->calcInjCoeff(fipnum, pvtreg, resv_coeff);
2553 template <
typename TypeTag>
2561 int np = this->numPhases();
2562 Scalar cellInternalEnergy;
2566 const int nw = this->numLocalWells();
2567 for (
auto wellID = 0*nw; wellID < nw; ++wellID) {
2568 const Well& well = this->wells_ecl_[wellID];
2569 if (well.isInjector())
2572 std::array<Scalar,2> weighted{0.0,0.0};
2573 auto& [weighted_temperature, total_weight] = weighted;
2575 auto& well_info = this->local_parallel_well_info_[wellID].get();
2576 auto& ws = this->wellState().well(wellID);
2577 auto& perf_data = ws.perf_data;
2578 auto& perf_phase_rate = perf_data.phase_rates;
2580 using int_type =
decltype(this->well_perf_data_[wellID].size());
2581 for (int_type perf = 0, end_perf = this->well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
2582 const int cell_idx = this->well_perf_data_[wellID][perf].cell_index;
2583 const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, 0);
2584 const auto& fs = intQuants.fluidState();
2587 Scalar cellTemperatures = fs.temperature(0).value();
2589 Scalar weight_factor = 0.0;
2590 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
2592 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2595 cellInternalEnergy = fs.enthalpy(phaseIdx).value() - fs.pressure(phaseIdx).value() / fs.density(phaseIdx).value();
2596 cellBinv = fs.invB(phaseIdx).value();
2597 cellDensity = fs.density(phaseIdx).value();
2598 perfPhaseRate = perf_phase_rate[ perf*np + phaseIdx ];
2599 weight_factor += cellDensity * perfPhaseRate/cellBinv * cellInternalEnergy/cellTemperatures;
2601 total_weight += weight_factor;
2602 weighted_temperature += weight_factor * cellTemperatures;
2604 well_info.communication().sum(weighted.data(), 2);
2605 this->wellState().well(wellID).temperature = weighted_temperature/total_weight;
2610 template <
typename TypeTag>
2615 std::ostringstream os;
2616 for (
const auto& w : well_container_) {
2617 os << w->name() <<
":";
2618 auto pv = w->getPrimaryVars();
2619 for (
const Scalar v : pv) {
2624 OpmLog::debug(os.str());
2629 template <
typename TypeTag>
2630 std::vector<typename BlackoilWellModel<TypeTag>::Scalar>
2634 std::vector<Scalar> ret;
2635 for (
const auto& well : well_container_) {
2636 if (well_domain_.at(well->name()) == domain.
index) {
2637 const auto& pv = well->getPrimaryVars();
2638 ret.insert(ret.end(), pv.begin(), pv.end());
2646 template <
typename TypeTag>
2651 std::size_t offset = 0;
2652 for (
auto& well : well_container_) {
2653 if (well_domain_.at(well->name()) == domain.
index) {
2654 int num_pri_vars = well->setPrimaryVars(vars.begin() + offset);
2655 offset += num_pri_vars;
2658 assert(offset == vars.size());
2663 template <
typename TypeTag>
2673 for (
const auto& wellPtr : this->well_container_) {
2674 const int first_well_cell = wellPtr->cells().front();
2675 for (
const auto& domain : domains) {
2676 auto cell_present = [&domain](
const auto cell)
2678 return std::binary_search(domain.cells.begin(),
2679 domain.cells.end(), cell);
2682 if (cell_present(first_well_cell)) {
2685 well_domain_[wellPtr->name()] = domain.index;
2688 for (
int well_cell : wellPtr->cells()) {
2689 if (! cell_present(well_cell)) {
2690 OPM_THROW(std::runtime_error,
2691 fmt::format(
"Well '{}' found on multiple domains.",
2699 simulator_.gridView().comm());
2703 const int rank = comm.rank();
2705 if (!well_domain_.empty()) {
2706 std::ostringstream os;
2707 os <<
"Well name Rank Domain\n";
2708 for (
const auto& [wname, domain] : well_domain_) {
2709 os << wname << std::setw(19 - wname.size()) << rank << std::setw(12) << domain <<
'\n';
2711 local_log.
debug(os.str());
2714 if (this->terminal_output_) {
2715 global_log.logMessages();
#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:182
#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:172
#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg)
Inserts catch classes for the parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:146
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:138
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:101
ParallelWBPCalculation::EvaluatorFactory makeWellSourceEvaluatorFactory(const std::vector< Well >::size_type wellIdx) const
Definition: BlackoilWellModel_impl.hpp:2074
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:345
void apply(BVector &r) const
Definition: BlackoilWellModel_impl.hpp:1543
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2339
bool updateGroupControls(const Group &group, DeferredLogger &deferred_logger, const int reportStepIdx, const int iterationIdx)
Definition: BlackoilWellModel_impl.hpp:2168
void calcRates(const int fipnum, const int pvtreg, const std::vector< Scalar > &production_rates, std::vector< Scalar > &resv_coeff) override
Definition: BlackoilWellModel_impl.hpp:2534
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:982
WellInterfacePtr getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2490
void init()
Definition: BlackoilWellModel_impl.hpp:145
typename BlackoilWellModelGeneric< Scalar >::GLiftProdWells GLiftProdWells
Definition: BlackoilWellModel.hpp:118
void updateAndCommunicate(const int reportStepIdx, const int iterationIdx, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2146
typename GasLiftSingleWellGeneric::GLiftSyncGroups GLiftSyncGroups
Definition: BlackoilWellModel.hpp:122
void doPreStepNetworkRebalance(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1060
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:112
std::vector< Scalar > getPrimaryVarsDomain(const Domain &domain) const
Definition: BlackoilWellModel_impl.hpp:2632
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:164
void addReservoirSourceTerms(GlobalEqVector &residual, std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1650
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:248
void assembleWellEqDomain(const double dt, const Domain &domain, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1500
void applyScaleAdd(const Scalar alpha, const BVector &x, BVector &Ax) const
Definition: BlackoilWellModel_impl.hpp:1604
void gasLiftOptimizationStage1SingleWell(WellInterface< TypeTag > *well, DeferredLogger &deferred_logger, GLiftProdWells &prod_wells, GLiftOptWells &glift_wells, GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map, GLiftSyncGroups &groups_to_sync)
Definition: BlackoilWellModel_impl.hpp:1451
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilWellModel.hpp:109
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilWellModel.hpp:106
void updateWellControlsDomain(DeferredLogger &deferred_logger, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:1977
void assembleWellEq(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1489
void linearizeDomain(const Domain &domain, SparseMatrixAdapter &jacobian, GlobalEqVector &res)
Definition: BlackoilWellModel_impl.hpp:225
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2522
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2280
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2478
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2445
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2386
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:111
void calcInjRates(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) override
Definition: BlackoilWellModel_impl.hpp:2545
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:803
void assemble(const int iterationIdx, const double dt)
Definition: BlackoilWellModel_impl.hpp:1099
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2556
void addWellPressureEquations(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights) const
Definition: BlackoilWellModel_impl.hpp:1634
void logPrimaryVars() const
Definition: BlackoilWellModel_impl.hpp:2613
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:654
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1159
GetPropType< TypeTag, Properties::SparseMatrixAdapter > SparseMatrixAdapter
Definition: BlackoilWellModel.hpp:115
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1624
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1033
typename BlackoilWellModelGeneric< Scalar >::GLiftOptWells GLiftOptWells
Definition: BlackoilWellModel.hpp:117
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:2245
std::pair< bool, bool > updateWellControls(const bool mandatory_network_balance, DeferredLogger &deferred_logger, const bool relax_network_tolerance=false)
Definition: BlackoilWellModel_impl.hpp:1889
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:1722
void assembleDomain(const int iterationIdx, const double dt, const Domain &domain)
Definition: BlackoilWellModel_impl.hpp:1247
bool hasWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2507
void assembleWellEqWithoutIteration(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1524
data::WellBlockAveragePressures computeWellBlockAveragePressures() const
Definition: BlackoilWellModel_impl.hpp:2028
typename GasLiftGroupInfo::GLiftEclWells GLiftEclWells
Definition: BlackoilWellModel.hpp:121
void initPrimaryVariablesEvaluation() const
Definition: BlackoilWellModel_impl.hpp:1747
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:342
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:766
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:387
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: BlackoilWellModel.hpp:113
void calculateExplicitQuantities(DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1874
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:135
void updatePrimaryVariables(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2435
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: BlackoilWellModel.hpp:114
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling)
Definition: BlackoilWellModel_impl.hpp:300
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:1195
void addNeighbors(std::vector< NeighborSet > &neighbors) const override
Definition: BlackoilWellModel_impl.hpp:180
BlackoilWellModel(Simulator &simulator)
Definition: BlackoilWellModel_impl.hpp:137
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:587
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControls=false) const
Definition: BlackoilWellModel_impl.hpp:1821
void registerOpenWellsForWBPCalculation()
Definition: BlackoilWellModel_impl.hpp:2125
void linearize(SparseMatrixAdapter &jacobian, GlobalEqVector &res) override
Definition: BlackoilWellModel_impl.hpp:204
void initGliftEclWellMap(GLiftEclWells &ecl_well_map)
Definition: BlackoilWellModel_impl.hpp:1477
void gasLiftOptimizationStage1(DeferredLogger &deferred_logger, GLiftProdWells &prod_wells, GLiftOptWells &glift_wells, GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map)
Definition: BlackoilWellModel_impl.hpp:1345
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:664
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1002
void setPrimaryVarsDomain(const Domain &domain, const std::vector< Scalar > &vars)
Definition: BlackoilWellModel_impl.hpp:2649
std::shared_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:240
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:841
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilWellModel.hpp:136
bool maybeDoGasLiftOptimize(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1287
void updateWellTestState(const double &simulationTime, WellTestState &wellTestState) const
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:2206
ConvergenceReport getDomainWellConvergence(const Domain &domain, const std::vector< Scalar > &B_avg, DeferredLogger &local_deferredLogger) const
Definition: BlackoilWellModel_impl.hpp:1775
void initializeWBPCalculationService()
Definition: BlackoilWellModel_impl.hpp:2000
void initPrimaryVariablesEvaluationDomain(const Domain &domain) const
Definition: BlackoilWellModel_impl.hpp:1758
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1703
void setupDomains(const std::vector< Domain > &domains)
Definition: BlackoilWellModel_impl.hpp:2666
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1680
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2294
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:637
void prepareWellsBeforeAssembling(const double dt, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1513
typename BlackoilWellModelGeneric< Scalar >::GLiftWellStateMap GLiftWellStateMap
Definition: BlackoilWellModel.hpp:120
int numComponents() const
Definition: BlackoilWellModel_impl.hpp:2461
Definition: ConvergenceReport.hpp:38
void setWellFailed(const WellFailure &wf)
Definition: ConvergenceReport.hpp:130
void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
Definition: ConvergenceReport.hpp:142
const std::vector< WellFailure > & wellFailures() const
Definition: ConvergenceReport.hpp:192
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:45
void updateRate(int idx, double oil_rate, double gas_rate, double water_rate, double alq)
std::tuple< double, double, double, double > getRates(const int group_idx) const
bool hasWell(const std::string &well_name)
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
ParallelPAvgDynamicSourceData::Evaluator Evaluator
Callback for evaluating WBPn source terms on the current MPI rank.
Definition: ParallelWBPCalculation.hpp:57
std::function< Evaluator()> EvaluatorFactory
Definition: ParallelWBPCalculation.hpp:62
Definition: StandardWell.hpp:59
virtual void init(const PhaseUsage *phase_usage_arg, const std::vector< double > &depth_arg, const double 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: WellContributions.hpp:52
void setBlockSize(unsigned int dim, unsigned int dim_wells)
void alloc()
Allocate memory for the StandardWells.
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 > > ®ionalAveragePressureCalculator)
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 ®ional_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)
int indexOfWell() const
Index of well in the wells struct and wellState.
const std::string & name() const
Well name.
Definition: WellInterface.hpp:75
virtual void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator &wellPICalc, WellState< Scalar > &well_state, DeferredLogger &deferred_logger) const =0
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, WellState< Scalar > &well_state, const GroupState< Scalar > &group_state, DeferredLogger &deferred_logger)
Definition: WellInterface_impl.hpp:194
Definition: WellState.hpp:62
ExcEnum
Definition: DeferredLogger.hpp:45
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: BlackoilPhases.hpp:27
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