23#ifndef OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED
24#define OPM_BLACKOILWELLMODEL_IMPL_HEADER_INCLUDED
27#ifndef OPM_BLACKOILWELLMODEL_HEADER_INCLUDED
32#include <opm/grid/utility/cartesianToCompressed.hpp>
34#include <opm/input/eclipse/Schedule/Network/Balance.hpp>
35#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
36#include <opm/input/eclipse/Schedule/Well/PAvgDynamicSourceData.hpp>
37#include <opm/input/eclipse/Schedule/Well/WellMatcher.hpp>
38#include <opm/input/eclipse/Schedule/Well/WellTestConfig.hpp>
39#include <opm/input/eclipse/Schedule/Well/WellEconProductionLimits.hpp>
41#include <opm/input/eclipse/Units/UnitSystem.hpp>
68#include <fmt/format.h>
71 template<
typename TypeTag>
78 simulator.vanguard().summaryState(),
79 simulator.vanguard().eclState(),
81 simulator.gridView().comm(),
83 , simulator_(simulator)
84 , guide_rate_handler_{
86 simulator.vanguard().schedule(),
87 simulator.vanguard().summaryState(),
88 simulator.vanguard().grid().comm()
90 , gaslift_(this->terminal_output_)
93 , rescoupHelper_(*this)
102 auto& parallel_wells =
simulator.vanguard().parallelWells();
105 for(
const auto& name_bool : parallel_wells) {
113 Parameters::Get<Parameters::AlternativeWellRateInit>();
115 using SourceDataSpan =
116 typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<Scalar>;
118 this->
wbp_.initializeSources(
119 [
this](
const std::size_t globalIndex)
121 [
this](
const int localCell, SourceDataSpan sourceTerms)
123 using Item =
typename SourceDataSpan::Item;
125 const auto* intQuants = this->
simulator_.model()
126 .cachedIntensiveQuantities(localCell, 0);
127 const auto& fs = intQuants->fluidState();
130 .set(Item::PoreVol, intQuants->porosity().value() *
131 this->
simulator_.model().dofTotalVolume(localCell))
132 .set(Item::Depth, this->
depth_[localCell]);
134 constexpr auto io = FluidSystem::oilPhaseIdx;
135 constexpr auto ig = FluidSystem::gasPhaseIdx;
136 constexpr auto iw = FluidSystem::waterPhaseIdx;
139 const auto haveOil = FluidSystem::phaseIsActive(io);
140 const auto haveGas = FluidSystem::phaseIsActive(ig);
141 const auto haveWat = FluidSystem::phaseIsActive(iw);
143 auto weightedPhaseDensity = [&fs](
const auto ip)
145 return fs.saturation(ip).value() * fs.density(ip).value();
148 if (haveOil) { sourceTerms.set(Item::Pressure, fs.pressure(io).value()); }
149 else if (haveGas) { sourceTerms.set(Item::Pressure, fs.pressure(ig).value()); }
150 else { sourceTerms.set(Item::Pressure, fs.pressure(iw).value()); }
154 if (haveOil) { rho += weightedPhaseDensity(io); }
155 if (haveGas) { rho += weightedPhaseDensity(ig); }
156 if (haveWat) { rho += weightedPhaseDensity(iw); }
158 sourceTerms.set(Item::MixtureDensity, rho);
163 template<
typename TypeTag>
168 extractLegacyCellPvtRegionIndex_();
169 extractLegacyDepth_();
171 gravity_ = simulator_.problem().gravity()[2];
173 this->initial_step_ =
true;
176 simulator_.model().addAuxiliaryModule(
this);
178 is_cell_perforated_.resize(local_num_cells_,
false);
182 template<
typename TypeTag>
187 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
188 + ScheduleEvents::NEW_WELL;
189 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
190 for (
auto& wellPtr : this->well_container_) {
191 const bool well_opened_this_step = this->report_step_starts_ &&
192 events.hasEvent(wellPtr->name(),
193 effective_events_mask);
194 wellPtr->init(this->depth_, this->gravity_,
195 this->B_avg_, well_opened_this_step);
199 template<
typename TypeTag>
204 this->groupStateHelper().setReportStep(timeStepIdx);
205 this->report_step_starts_ =
true;
206 this->report_step_start_events_ = this->schedule()[timeStepIdx].wellgroup_events();
208 this->rateConverter_ = std::make_unique<RateConverterType>
209 (std::vector<int>(this->local_num_cells_, 0));
212 const bool initializeWellState = !this->deserialized_state_pending_;
213 const auto enableWellPIScaling =
true;
214 this->initializeLocalWellStructure(timeStepIdx,
216 initializeWellState);
217 this->deserialized_state_pending_ =
false;
220 this->initializeGroupStructure(timeStepIdx);
222 const auto& comm = this->simulator_.vanguard().grid().comm();
228 this->rateConverter_->template defineState<ElementContext>(this->simulator_);
232 const auto& sched_state = this->schedule()[timeStepIdx];
234 this->vfp_properties_ = std::make_unique<VFPProperties<Scalar, IndexTraits>>
235 (sched_state.vfpinj(), sched_state.vfpprod(), this->wellState());
242 this->commitWGState();
244 this->wellStructureChangedDynamically_ =
false;
251 template <
typename TypeTag>
255 const bool enableWellPIScaling,
256 const bool initializeWellState)
258 auto logger_guard = this->groupStateHelper().pushLogger();
259 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
261 const auto& comm = this->simulator_.vanguard().grid().comm();
266 this->registerNewParallelWells(reportStepIdx);
269 this->wells_ecl_ = this->getLocalWells(reportStepIdx);
270 this->local_parallel_well_info_ =
271 this->createLocalParallelWellInfo(this->wells_ecl_);
278 if (initializeWellState) {
279 this->initializeWellPerfData();
280 this->initializeWellState(reportStepIdx);
282 this->wbp_.initializeWBPCalculationService();
284 if (initializeWellState && this->param_.use_multisegment_well_ && this->anyMSWellOpenLocal()) {
285 this->wellState().initWellStateMSWell(this->wells_ecl_, &this->prevWellState(), has_energy_);
288 this->initializeWellProdIndCalculators();
290 if (enableWellPIScaling && this->schedule()[reportStepIdx].events()
291 .hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX))
293 this->runWellPIScaling(reportStepIdx, local_deferredLogger);
297 "Failed to initialize local well structure: ",
298 this->terminal_output_, comm)
305 template <
typename TypeTag>
310 const auto& comm = this->simulator_.vanguard().grid().comm();
314 const auto& fieldGroup =
315 this->schedule().getGroup(
"FIELD", reportStepIdx);
317 this->groupStateHelper().setCmodeGroup(fieldGroup);
321 if (this->schedule()[reportStepIdx].has_gpmaint()) {
322 this->groupStateHelper().setRegionAveragePressureCalculator(
324 this->eclState_.fieldProps(),
325 this->regionalAveragePressureCalculator_
337 template<
typename TypeTag>
342 OPM_TIMEBLOCK(beginTimeStep);
344 this->updateAverageFormationFactor();
346 auto logger_guard = this->groupStateHelper().pushLogger();
347 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
349#ifdef RESERVOIR_COUPLING_ENABLED
350 auto rescoup_logger_guard = this->rescoupHelper_.setupScopedLogger(local_deferredLogger);
353 this->switched_prod_groups_.clear();
354 this->switched_inj_groups_.clear();
356 if (this->wellStructureChangedDynamically_) {
361 const auto reportStepIdx =
362 this->simulator_.episodeIndex();
366 const auto enableWellPIScaling =
false;
368 this->initializeLocalWellStructure(reportStepIdx, enableWellPIScaling,
true);
369 this->initializeGroupStructure(reportStepIdx);
371 this->commitWGState();
377 this->wellStructureChangedDynamically_ =
false;
380 this->resetWGState();
381 const int reportStepIdx = simulator_.episodeIndex();
383 this->wellState().updateWellsDefaultALQ(this->schedule(), reportStepIdx, this->summaryState());
384 this->wellState().gliftTimeStepInit();
386 const double simulationTime = simulator_.time();
388 this->well_performance_event_tracker_.beginTimeStep(this->schedule(), reportStepIdx,
389 this->wellStatusSnapshot());
394 wellTesting(reportStepIdx, simulationTime, local_deferredLogger);
397 stashWellSolveStats();
401 this->well_performance_event_tracker_.accumulate(this->wellStatusSnapshot());
404 createWellContainer(reportStepIdx);
408 this->well_performance_event_tracker_.applyDeckChanges(this->wellStatusSnapshot());
410#ifdef RESERVOIR_COUPLING_ENABLED
411 if (this->isReservoirCouplingMaster()) {
412 if (this->reservoirCouplingMaster().isFirstSubstepOfSyncTimestep()) {
413 this->rescoupHelper_.receiveSlaveGroupData();
420 this->updateAndCommunicateGroupData(reportStepIdx,
false);
423 const Grid& grid = simulator_.vanguard().grid();
424 this->wells_active_ = grid.comm().max(!this->well_container_.empty());
429 this->initWellContainer(reportStepIdx);
432 std::fill(is_cell_perforated_.begin(), is_cell_perforated_.end(),
false);
433 for (
auto& well : well_container_) {
434 well->updatePerforatedCell(is_cell_perforated_);
438 this->calculateEfficiencyFactors(reportStepIdx);
440 if constexpr (has_polymer_)
442 if (PolymerModule::hasPlyshlog() || getPropValue<TypeTag, Properties::EnablePolymerMW>() ) {
443 this->setRepRadiusPerfLength();
450 this->terminal_output_, simulator_.vanguard().grid().comm());
452 for (
auto& well : well_container_) {
453 well->setVFPProperties(this->vfp_properties_.get());
454 well->setGuideRate(&this->guideRate_);
457 this->updateFiltrationModelsPreStep(local_deferredLogger);
460 for (
auto& well : well_container_) {
461 well->closeCompletions(this->wellTestState());
467 if (alternative_well_rate_init_) {
472 for (
const auto& well : well_container_) {
473 if (well->isProducer() && !well->wellIsStopped()) {
474 well->initializeProducerWellState(simulator_, this->wellState(), local_deferredLogger);
479 for (
const auto& well : well_container_) {
480 if (well->isVFPActive(local_deferredLogger)){
481 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
485 this->updateWellPotentials(reportStepIdx,
487 simulator_.vanguard().summaryConfig(),
488 local_deferredLogger);
489 }
catch ( std::runtime_error& e ) {
490 const std::string msg =
"A zero well potential is returned for output purposes. ";
491 local_deferredLogger.warning(
"WELL_POTENTIAL_CALCULATION_FAILED", msg);
494 this->guide_rate_handler_.updateGuideRates(
495 reportStepIdx, simulationTime, this->wellState(), this->groupState()
497 bool slave_needs_well_solution =
false;
498#ifdef RESERVOIR_COUPLING_ENABLED
499 if (this->isReservoirCouplingSlave()) {
500 if (this->reservoirCouplingSlave().isFirstSubstepOfSyncTimestep()) {
504 this->reservoirCouplingSlave().setWellsSolvedThisSyncStep(
false);
505 this->rescoupHelper_.sendSlaveGroupDataToMaster();
506 this->rescoupHelper_.receiveGroupConstraintsFromMaster();
507 this->rescoupHelper_.receiveCoupledNetworkActiveStatus();
508 this->groupStateHelper().updateSlaveGroupCmodesFromMaster();
509 this->reservoirCouplingSlave().markSlaveGroupsInSchedule(
510 this->schedule_, reportStepIdx);
511 this->rescoupHelper_.refreshSlaveGroupInjectionTargets();
512 slave_needs_well_solution =
true;
519 if (this->schedule_[reportStepIdx].has_gpmaint()) {
520 for (
const auto& calculator : regionalAveragePressureCalculator_) {
521 calculator.second->template defineState<ElementContext>(simulator_);
523 const double dt = simulator_.timeStepSize();
524 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", reportStepIdx);
526 this->groupStateHelper().updateGpMaintTargetForGroups(fieldGroup,
527 regionalAveragePressureCalculator_,
533 this->updateAndCommunicateGroupData(reportStepIdx,
true);
536 for (
auto& well : well_container_) {
537 const uint64_t effective_events_mask = ScheduleEvents::WELL_STATUS_CHANGE
538 + ScheduleEvents::INJECTION_TYPE_CHANGED
539 + ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER
540 + ScheduleEvents::NEW_WELL;
542 const auto& events = this->schedule()[reportStepIdx].wellgroup_events();
543 const bool event = this->report_step_starts_ && events.hasEvent(well->name(), effective_events_mask);
544 const bool dyn_status_change = this->wellState().well(well->name()).status
545 != this->prevWellState().well(well->name()).status;
547 if (event || dyn_status_change || slave_needs_well_solution) {
549 well->scaleSegmentRatesAndPressure(this->wellState());
550 well->calculateExplicitQuantities(simulator_, this->groupStateHelper());
551 well->updateWellStateWithTarget(simulator_, this->groupStateHelper(), this->wellState());
552 well->updatePrimaryVariables(this->groupStateHelper());
553 well->solveWellEquation(
554 simulator_, this->groupStateHelper(), this->wellState()
556 }
catch (
const std::exception& e) {
557 const std::string msg =
"Compute initial well solution for new well " + well->name() +
" failed. Continue with zero initial rates";
558 local_deferredLogger.warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
566#ifdef RESERVOIR_COUPLING_ENABLED
567 if (slave_needs_well_solution) {
569 this->reservoirCouplingSlave().setWellsSolvedThisSyncStep(
true);
571 this->updateAndCommunicateGroupData(reportStepIdx,
false);
572 this->rescoupHelper_.sendSlaveGroupDataToMaster();
574 else if (this->isReservoirCouplingMaster()) {
575 if (this->reservoirCouplingMaster().isFirstSubstepOfSyncTimestep()) {
576 this->rescoupHelper_.sendMasterGroupConstraintsToSlaves();
577 this->rescoupHelper_.sendCoupledNetworkActiveStatus();
578 this->rescoupHelper_.receiveSlaveGroupData();
584 const std::string msg =
"Compute initial well solution for new wells failed. Continue with zero initial rates";
585 local_deferredLogger.warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
588 const auto& comm = simulator_.vanguard().grid().comm();
590 exc_type,
"beginTimeStep() failed: " + exc_msg, this->terminal_output_, comm);
594 template<
typename TypeTag>
602 template<
typename TypeTag>
610 template<
typename TypeTag>
613 const double simulationTime,
616 for (
const std::string& well_name : this->getWellsForTesting(timeStepIdx, simulationTime)) {
617 const Well& wellEcl = this->schedule().getWell(well_name, timeStepIdx);
618 if (wellEcl.getStatus() == Well::Status::SHUT)
621 WellInterfacePtr well = createWellForWellTest(well_name, timeStepIdx, deferred_logger);
623 well->init(depth_, gravity_, B_avg_,
true);
625 Scalar well_efficiency_factor = wellEcl.getEfficiencyFactor() *
626 this->wellState().getGlobalEfficiencyScalingFactor(well_name);
627 this->groupStateHelper().accumulateGroupEfficiencyFactor(
628 this->schedule().getGroup(wellEcl.groupName(), timeStepIdx),
629 well_efficiency_factor
632 well->setWellEfficiencyFactor(well_efficiency_factor);
633 well->setVFPProperties(this->vfp_properties_.get());
634 well->setGuideRate(&this->guideRate_);
637 if (well->isProducer() && alternative_well_rate_init_) {
638 well->initializeProducerWellState(simulator_, this->wellState(), deferred_logger);
640 if (well->isVFPActive(deferred_logger)) {
641 well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
644 this->network_.initializeWell(*well);
647 GLiftEclWells ecl_well_map;
648 gaslift_.initGliftEclWellMap(well_container_, ecl_well_map);
649 well->wellTesting(simulator_,
651 this->groupStateHelper(),
653 this->wellTestState(),
655 this->well_open_times_);
656 }
catch (
const std::exception& e) {
657 const std::string msg =
658 fmt::format(fmt::runtime(
"Exception during testing of well: {}. The well will not open.\n"
659 "Exception message: {}"), wellEcl.name(), e.what());
660 deferred_logger.
warning(
"WELL_TESTING_FAILED", msg);
663 addSolveStats(*well);
668 template<
typename TypeTag>
674 for (
auto&& pinfo : this->local_parallel_well_info_)
685 template<
typename TypeTag>
695 template<
typename TypeTag>
700 this->closed_this_step_.clear();
703 this->report_step_starts_ =
false;
704 const int reportStepIdx = simulator_.episodeIndex();
706 auto logger_guard = this->groupStateHelper().pushLogger();
707 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
708 for (
const auto& well : well_container_) {
709 if (getPropValue<TypeTag, Properties::EnablePolymerMW>() && well->isInjector()) {
710 well->updateWaterThroughput(dt, this->wellState());
714 for (
const auto& well : well_container_) {
715 well->updateConnectionTransmissibilityFactor(simulator_, this->wellState().well(well->indexOfWell()));
716 well->updateConnectionDFactor(simulator_, this->wellState().well(well->indexOfWell()));
719 if (Indices::waterEnabled) {
720 if constexpr (getPropValue<TypeTag, Properties::EnableMech>()) {
723 updateWellFractureFlowSplit<FluidSystem, Scalar>(
724 this->simulator_, this->well_container_,
725 this->wellState(), this->nupcolWellState());
727 this->updateFiltrationModelsPostStep(dt, FluidSystem::waterPhaseIdx, local_deferredLogger);
731 this->updateInjMult(local_deferredLogger);
734 for (
const auto& well : well_container_) {
735 well->reportWellSwitching(this->wellState().well(well->indexOfWell()), local_deferredLogger);
738 if (this->terminal_output_) {
739 this->reportGroupSwitching(local_deferredLogger);
743 rateConverter_->template defineState<ElementContext>(simulator_);
747 this->updateWellPotentials(reportStepIdx,
749 simulator_.vanguard().summaryConfig(),
750 local_deferredLogger);
751 }
catch ( std::runtime_error& e ) {
752 const std::string msg =
"A zero well potential is returned for output purposes. ";
753 local_deferredLogger.warning(
"WELL_POTENTIAL_CALCULATION_FAILED", msg);
760 const double closure_time = simulationTime + dt;
762 updateWellTestState(closure_time, this->wellTestState());
765 const Group& fieldGroup = this->schedule_.getGroup(
"FIELD", reportStepIdx);
766 this->checkGEconLimits(fieldGroup, closure_time,
767 simulator_.episodeIndex(), local_deferredLogger);
768 this->checkGconsaleLimits(fieldGroup, this->wellState(),
769 simulator_.episodeIndex(), local_deferredLogger);
771 this->well_performance_event_tracker_.accumulate(this->wellStatusSnapshot());
773 this->calculateProductivityIndexValues(local_deferredLogger);
775 this->groupStateHelper().updateNONEProductionGroups();
777#ifdef RESERVOIR_COUPLING_ENABLED
778 this->rescoupHelper_.rescoupSyncSummaryData();
780 this->well_performance_event_tracker_.commitTimeStep(this->schedule(), reportStepIdx);
781 this->commitWGState();
784 this->computeWellTemperature();
788 template<
typename TypeTag>
792 unsigned elemIdx)
const
796 if (!is_cell_perforated_[elemIdx] || cellRates_.count(elemIdx) == 0) {
800 rate = cellRates_.at(elemIdx);
804 template<
typename TypeTag>
805 template <
class Context>
809 const Context& context,
811 unsigned timeIdx)
const
814 int elemIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
816 if (!is_cell_perforated_[elemIdx] || cellRates_.count(elemIdx) == 0) {
820 rate = cellRates_.at(elemIdx);
825 template<
typename TypeTag>
830 const auto pressIx = []()
832 if (Indices::oilEnabled) {
return FluidSystem::oilPhaseIdx; }
833 if (Indices::waterEnabled) {
return FluidSystem::waterPhaseIdx; }
835 return FluidSystem::gasPhaseIdx;
838 auto cellPressures = std::vector<Scalar>(this->local_num_cells_,
Scalar{0});
839 auto cellTemperatures = std::vector<Scalar>(this->local_num_cells_,
Scalar{0});
842 const auto& gridView = this->simulator_.vanguard().gridView();
845 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
846 elemCtx.updatePrimaryStencil(elem);
847 elemCtx.updatePrimaryIntensiveQuantities(0);
849 const auto ix = elemCtx.globalSpaceIndex(0, 0);
850 const auto& fs = elemCtx.intensiveQuantities(0, 0).fluidState();
852 cellPressures[ix] = fs.pressure(pressIx).value();
853 cellTemperatures[ix] = fs.temperature(0).value();
856 this->simulator_.vanguard().grid().comm());
858 this->wellState().init(cellPressures, cellTemperatures, this->schedule(), this->wells_ecl_,
859 this->local_parallel_well_info_, timeStepIdx,
860 &this->prevWellState(), this->well_perf_data_,
861 this->summaryState(), simulator_.vanguard().enableDistributedWells());
868 template<
typename TypeTag>
873 auto logger_guard = this->groupStateHelper().pushLogger();
874 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
876 const int nw = this->numLocalWells();
878 well_container_.clear();
881 well_container_.reserve(nw);
883 const auto& wmatcher = this->schedule().wellMatcher(report_step);
884 const auto& wcycle = this->schedule()[report_step].wcycle.get();
888 std::ranges::for_each(this->wells_ecl_,
889 [
this, &wg_events = this->report_step_start_events_](
const auto& well_ecl)
891 if (!well_ecl.hasConnections()) {
896 constexpr auto events_mask = ScheduleEvents::WELL_STATUS_CHANGE |
897 ScheduleEvents::REQUEST_OPEN_WELL |
898 ScheduleEvents::REQUEST_SHUT_WELL;
899 const bool well_event =
900 this->report_step_starts_ &&
901 wg_events.hasEvent(well_ecl.name(), events_mask);
910 if (well_ecl.getStatus() == WellStatus::OPEN) {
911 this->well_open_times_.insert_or_assign(well_ecl.name(),
912 this->simulator_.time());
913 this->well_close_times_.erase(well_ecl.name());
914 }
else if (well_ecl.getStatus() == WellStatus::SHUT) {
915 this->well_close_times_.insert_or_assign(well_ecl.name(),
916 this->simulator_.time());
917 this->well_open_times_.erase(well_ecl.name());
923 const auto cycle_states = wcycle.wellStatus(this->simulator_.time(),
925 this->well_open_times_,
926 this->well_close_times_);
928 for (
int w = 0; w < nw; ++w) {
929 const Well& well_ecl = this->wells_ecl_[w];
931 if (!well_ecl.hasConnections()) {
936 const std::string& well_name = well_ecl.name();
937 const auto well_status = this->schedule()
938 .getWell(well_name, report_step).getStatus();
940 const bool shut_event = this->wellState().well(w).events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE)
941 && well_status == Well::Status::SHUT;
942 const bool open_event = this->wellState().well(w).events.hasEvent(ScheduleEvents::WELL_STATUS_CHANGE)
943 && well_status == Well::Status::OPEN;
944 const auto& ws = this->wellState().well(well_name);
946 if (shut_event && ws.status != Well::Status::SHUT) {
947 this->closed_this_step_.insert(well_name);
948 this->wellState().shutWell(w);
949 }
else if (open_event && ws.status != Well::Status::OPEN) {
950 this->wellState().openWell(w);
954 if (this->wellTestState().well_is_closed(well_name)) {
967 const bool closed_this_step =
968 (this->wellTestState().lastTestTime(well_name) == simulator_.time()) &&
969 !this->wasDynamicallyShutThisTimeStep(well_name);
972 auto& events = this->wellState().well(w).events;
973 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
974 if (!closed_this_step) {
975 this->wellTestState().open_well(well_name);
976 this->wellTestState().open_completions(well_name);
977 this->well_open_times_.insert_or_assign(well_name,
978 this->simulator_.time());
979 this->well_close_times_.erase(well_name);
981 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
991 auto& well_test_state = this->wellTestState();
992 const auto& sched_state = this->schedule()[report_step];
993 const bool may_reopen_completions =
994 ws.status == Well::Status::OPEN &&
995 sched_state.events().hasEvent(ScheduleEvents::COMPLETION_CHANGE) &&
996 well_test_state.num_closed_completions() > 0;
998 if (may_reopen_completions) {
999 const auto& completion_events = sched_state.wellcompletion_events();
1000 for (
const auto& connection : well_ecl.getConnections()) {
1001 const int complnum = connection.complnum();
1005 if (!well_test_state.completion_is_closed(well_name, complnum) ||
1006 !completion_events.hasEvent(well_name, complnum, ScheduleEvents::REQUEST_OPEN_COMPLETION)) {
1011 const bool closed_this_step =
1012 (well_test_state.lastCompletionCloseTime(well_name, complnum) == simulator_.time());
1013 if (closed_this_step) {
1017 well_test_state.open_completion(well_name, complnum);
1018 local_deferredLogger.info(
1019 fmt::format(
"Completion {} - block ({}, {}, {}) for well {} "
1020 "is reopened due to an explicit WELOPEN/COMPDAT "
1023 connection.getI() + 1,
1024 connection.getJ() + 1,
1025 connection.getK() + 1,
1032 if (this->wellTestState().well_is_closed(well_name))
1034 if (this->closedWellStatus(well_ecl) == WellStatus::SHUT)
1036 this->wellState().shutWell(w);
1037 this->well_close_times_.erase(well_name);
1038 this->well_open_times_.erase(well_name);
1042 this->wellState().stopWell(w);
1046 if (!well_ecl.getAllowCrossFlow()) {
1047 const bool any_zero_rate_constraint = well_ecl.isProducer()
1048 ? well_ecl.productionControls(this->summaryState_).anyZeroRateConstraint()
1049 : well_ecl.injectionControls(this->summaryState_).anyZeroRateConstraint();
1050 if (any_zero_rate_constraint) {
1052 local_deferredLogger.debug(fmt::format(fmt::runtime(
" Well {} gets shut due to having zero rate constraint and disallowing crossflow "), well_ecl.name()));
1053 this->wellState().shutWell(w);
1054 this->well_close_times_.erase(well_name);
1055 this->well_open_times_.erase(well_name);
1060 if (!wcycle.empty()) {
1061 const auto it = cycle_states.find(well_name);
1062 if (it != cycle_states.end()) {
1063 if (!it->second || well_status == Well::Status::SHUT) {
1065 if (well_status == Well::Status::SHUT) {
1066 this->well_open_times_.erase(well_name);
1067 this->well_close_times_.erase(well_name);
1069 this->wellState().shutWell(w);
1072 this->wellState().openWell(w);
1078 if (ws.status == Well::Status::SHUT) {
1082 well_container_.emplace_back(this->createWellPointer(w, report_step));
1084 if (ws.status == Well::Status::STOP) {
1085 well_container_.back()->stopWell();
1086 this->well_close_times_.erase(well_name);
1087 this->well_open_times_.erase(well_name);
1091 if (!wcycle.empty()) {
1092 const auto schedule_open =
1093 [&wg_events = this->report_step_start_events_](
const std::string& name)
1095 return wg_events.hasEvent(name, ScheduleEvents::REQUEST_OPEN_WELL);
1097 for (
const auto& [wname, wscale] : wcycle.efficiencyScale(this->simulator_.time(),
1098 this->simulator_.timeStepSize(),
1100 this->well_open_times_,
1103 this->wellState().updateEfficiencyScalingFactor(wname, wscale);
1104 this->schedule_.add_event(ScheduleEvents::WELLGROUP_EFFICIENCY_UPDATE, report_step);
1109 this->well_container_generic_.clear();
1110 for (
auto& w : well_container_) {
1111 this->well_container_generic_.push_back(w.get());
1114 this->network_.initialize(report_step);
1116 this->wbp_.registerOpenWellsForWBPCalculation();
1123 template <
typename TypeTag>
1128 const auto is_multiseg = this->wells_ecl_[wellID].isMultiSegment();
1130 if (! (this->param_.use_multisegment_well_ && is_multiseg)) {
1131 return this->
template createTypedWellPointer<StandardWell<TypeTag>>(wellID, report_step);
1134 return this->
template createTypedWellPointer<MultisegmentWell<TypeTag>>(wellID, report_step);
1142 template <
typename TypeTag>
1143 template <
typename WellType>
1144 std::unique_ptr<WellType>
1149 const auto& perf_data = this->well_perf_data_[wellID];
1152 const auto pvtreg = perf_data.empty()
1153 ? 0 : this->pvt_region_idx_[perf_data.front().cell_index];
1155 const auto& parallel_well_info = this->local_parallel_well_info_[wellID].get();
1156 const auto global_pvtreg = parallel_well_info.broadcastFirstPerforationValue(pvtreg);
1158 return std::make_unique<WellType>(this->wells_ecl_[wellID],
1162 *this->rateConverter_,
1164 this->numConservationQuantities(),
1174 template<
typename TypeTag>
1178 const int report_step,
1183 std::ranges::find_if(this->wells_ecl_,
1184 [&well_name](
const auto& w)
1185 {
return well_name == w.name(); });
1187 if (it == this->wells_ecl_.end()) {
1189 fmt::format(fmt::runtime(
"Could not find well {} in wells_ecl"), well_name),
1193 const int pos =
static_cast<int>(std::distance(this->wells_ecl_.begin(), it));
1194 return this->createWellPointer(pos, report_step);
1199 template<
typename TypeTag>
1205 auto logger_guard = this->groupStateHelper().pushLogger();
1206 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
1208 const auto& iterCtx = simulator_.problem().iterationContext();
1211 if (gaslift_.terminalOutput()) {
1212 const std::string msg =
1213 fmt::format(fmt::runtime(
"assemble() : iteration {}"), iterCtx.iteration());
1214 gaslift_.gliftDebug(msg, local_deferredLogger);
1218 Dune::Timer perfTimer;
1220 this->closed_offending_wells_.clear();
1223 if (iterCtx.needsTimestepInit()) {
1224 this->updateNetworkActiveState_();
1226 const int episodeIdx = simulator_.episodeIndex();
1227 const auto& network = this->schedule()[episodeIdx].network();
1228 if (!this->wellsActive() && !network.active()) {
1234 if (iterCtx.needsTimestepInit() && this->wellsActive()) {
1235 OPM_TIMEBLOCK(firstIterationAssemble);
1236 Dune::Timer prepareTimer;
1237 prepareTimer.start();
1244 calculateExplicitQuantities();
1245 prepareTimeStep(local_deferredLogger);
1248 "assemble() failed during well initialization: ",
1249 this->terminal_output_, grid().comm());
1250 last_report_.well_facility_time += prepareTimer.stop();
1253 Dune::Timer networkTimer;
1254 networkTimer.start();
1255 const bool well_group_control_changed = updateWellControlsAndNetwork(
1258 local_deferredLogger);
1261 const double network_time = networkTimer.stop();
1262 last_report_.well_control_network_time += network_time;
1263 last_report_.well_facility_time += network_time;
1267 if ( ! this->wellsActive() ) {
1271 assembleWellEqWithoutIteration(dt);
1278 collectWellSolveStats();
1282 last_report_.well_group_control_changed = well_group_control_changed;
1283 last_report_.assemble_time_well += perfTimer.stop();
1289 template<
typename TypeTag>
1294 stashWellSolveStats();
1295 const auto& stats = pending_solve_stats_;
1296 last_report_.well_solve_time += stats.solve_time;
1297 last_report_.well_potential_solve_time += stats.potential_solve_time;
1298 last_report_.well_solve_assemble_time += stats.assemble_time;
1299 last_report_.well_solve_linear_solve_time += stats.linear_solve_time;
1300 last_report_.total_well_iterations += stats.iterations;
1301 last_report_.total_well_potential_iterations += stats.potential_iterations;
1302 pending_solve_stats_ = {};
1305 template<
typename TypeTag>
1310 for (
const auto& well : well_container_) {
1311 addSolveStats(*well);
1315 template<
typename TypeTag>
1320 auto& pending = pending_solve_stats_;
1322 pending.solve_time += stats.solve_time;
1323 pending.potential_solve_time += stats.potential_solve_time;
1324 pending.assemble_time += stats.assemble_time;
1325 pending.linear_solve_time += stats.linear_solve_time;
1326 pending.iterations += stats.iterations;
1327 pending.potential_iterations += stats.potential_iterations;
1334 template<
typename TypeTag>
1343 bool do_network_update =
true;
1344 bool well_group_control_changed =
false;
1345 Scalar network_imbalance = 0.0;
1347 const std::size_t iteration_to_relax = param_.network_max_strict_outer_iterations_;
1349 const std::size_t max_iteration = param_.network_max_outer_iterations_;
1350 std::size_t network_update_iteration = 0;
1351 network_needs_more_balancing_force_another_newton_iteration_ =
false;
1352 while (do_network_update) {
1353 if (!this->isRescoupSlaveCoupledNetworkIteration_()
1354 && network_update_iteration >= max_iteration ) {
1356 const int episodeIdx = simulator_.episodeIndex();
1357 if (this->network_.willBalanceOnNextIteration(episodeIdx)) {
1358 if (this->terminal_output_) {
1359 const std::string msg = fmt::format(
"Maximum of {:d} network iterations has been used and we stop the update, \n"
1360 "and try again after the next Newton iteration (imbalance = {:.2e} bar)",
1361 max_iteration, network_imbalance*1.0e-5);
1362 local_deferredLogger.
debug(msg);
1366 network_needs_more_balancing_force_another_newton_iteration_ =
true;
1368 if (this->terminal_output_) {
1369 const std::string msg = fmt::format(
"Maximum of {:d} network iterations has been used and we stop the update. \n"
1370 "The simulator will continue with unconverged network results (imbalance = {:.2e} bar)",
1371 max_iteration, network_imbalance*1.0e-5);
1372 local_deferredLogger.
info(msg);
1377 if (this->terminal_output_ && (network_update_iteration == iteration_to_relax) ) {
1378 local_deferredLogger.
debug(
"We begin using relaxed tolerance for network update now after " +
std::to_string(iteration_to_relax) +
" iterations ");
1380 const bool relax_network_balance = network_update_iteration >= iteration_to_relax;
1382 const bool optimize_gas_lift = ( (network_update_iteration + 1) < std::max(max_iteration,
static_cast<std::size_t
>(2)) );
1383 std::tie(well_group_control_changed, do_network_update, network_imbalance) =
1384 updateWellControlsAndNetworkIteration(mandatory_network_balance, relax_network_balance, optimize_gas_lift, dt,local_deferredLogger);
1385 ++network_update_iteration;
1387 if (this->isRescoupMasterCoupledNetworkIteration_()) {
1388 this->sendSlaveNetworkLoopTerminationSignal_();
1391 if (this->schedule()[simulator_.episodeIndex()].network().active()) {
1392 last_report_.total_network_iterations += network_update_iteration;
1394 return well_group_control_changed;
1400 template<
typename TypeTag>
1401 std::tuple<bool, bool, typename BlackoilWellModel<TypeTag>::Scalar>
1404 const bool relax_network_tolerance,
1405 const bool optimize_gas_lift,
1410 const int reportStepIdx = simulator_.episodeIndex();
1412#ifdef RESERVOIR_COUPLING_ENABLED
1413 if (this->isRescoupSlaveCoupledNetworkIteration_()) {
1414 this->rescoupHelper_.receiveMasterGroupNodePressuresFromMaster();
1417 Dune::Timer groupTimer;
1419 this->updateAndCommunicateGroupData(reportStepIdx,
true);
1424 bool well_group_control_changed = updateWellControls(local_deferredLogger);
1425 last_report_.group_control_time += groupTimer.stop();
1427 Dune::Timer networkBalanceTimer;
1428 networkBalanceTimer.start();
1429 const auto [more_inner_network_update, network_imbalance] =
1430 this->network_.update(mandatory_network_balance,
1431 local_deferredLogger,
1432 relax_network_tolerance);
1434 if (this->schedule()[reportStepIdx].network().active()) {
1435 last_report_.network_balance_time += networkBalanceTimer.stop();
1437#ifdef RESERVOIR_COUPLING_ENABLED
1438 if (this->isReservoirCouplingMaster()) {
1439 this->rescoupHelper_.maybeExchangeNetworkOuterIterationWithSlaves(more_inner_network_update);
1443 bool alq_updated =
false;
1446 if (optimize_gas_lift) {
1449 const bool updatePotentials = (this->network_.shouldBalance(reportStepIdx) ||
1450 mandatory_network_balance);
1451 Dune::Timer gliftTimer;
1453 alq_updated = gaslift_.maybeDoGasLiftOptimize(simulator_,
1455 this->network_.nodePressures(),
1459 local_deferredLogger);
1461 if (this->schedule().glo(reportStepIdx).active()) {
1462 last_report_.gaslift_time += gliftTimer.stop();
1467 Dune::Timer prepareWellsTimer;
1468 prepareWellsTimer.start();
1469 prepareWellsBeforeAssembling(dt);
1470 last_report_.control_well_solve_time += prepareWellsTimer.stop();
1473 "updateWellControlsAndNetworkIteration() failed: ",
1474 this->terminal_output_, grid().comm());
1478 guideRateUpdateIsNeeded(reportStepIdx)) {
1479 const double simulationTime = simulator_.time();
1480 Dune::Timer guideRateTimer;
1481 guideRateTimer.start();
1485 this->guide_rate_handler_.updateGuideRates(
1486 reportStepIdx, simulationTime, this->wellState(), this->groupState()
1488 last_report_.group_control_time += guideRateTimer.stop();
1492 bool more_network_update = this->network_.shouldBalance(reportStepIdx) &&
1493 (more_inner_network_update || alq_updated);
1495 if (this->isRescoupSlaveOnSyncStepFirstSubstep_()
1496 && this->isRescoupSlaveConnectedToMasterNetwork_()) {
1503 const bool more_cross_rescoup_update =
1504 this->maybeSendSlaveGroupFlowToMaster_(reportStepIdx);
1505 more_network_update = more_network_update || more_cross_rescoup_update;
1508 return {well_group_control_changed, more_network_update, network_imbalance};
1511 template<
typename TypeTag>
1517 for (
auto& well : well_container_) {
1518 well->assembleWellEq(simulator_, dt, this->groupStateHelper(), this->wellState());
1523 template<
typename TypeTag>
1529 for (
auto& well : well_container_) {
1530 well->prepareWellBeforeAssembling(
1531 simulator_, dt, this->groupStateHelper(), this->wellState()
1537 template<
typename TypeTag>
1543 auto& deferred_logger = this->groupStateHelper().deferredLogger();
1548 for (
auto& well: well_container_) {
1549 well->assembleWellEqWithoutIteration(simulator_, this->groupStateHelper(), dt, this->wellState(),
1553 this->terminal_output_, grid().comm());
1557 template<
typename TypeTag>
1564 for (
const auto& well : well_container_) {
1565 well->addCellRates(cellRates_);
1569 template<
typename TypeTag>
1576 for (
const auto& well : well_container_) {
1577 const auto it = well_domain_map.find(well->name());
1578 if (it != well_domain_map.end() && it->second == domainIndex) {
1579 well->addCellRates(cellRates_);
1584#if COMPILE_GPU_BRIDGE
1585 template<
typename TypeTag>
1593 for(
unsigned int i = 0; i < well_container_.size(); i++){
1594 auto& well = well_container_[i];
1597 wellContribs.
addNumBlocks(derived->linSys().getNumBlocks());
1602 wellContribs.
alloc();
1604 for(
unsigned int i = 0; i < well_container_.size(); i++){
1605 auto& well = well_container_[i];
1607 auto derived_std =
dynamic_cast<StandardWell<TypeTag>*
>(well.get());
1609 derived_std->linSys().extract(derived_std->numStaticWellEq, wellContribs);
1611 auto derived_ms =
dynamic_cast<MultisegmentWell<TypeTag>*
>(well.get());
1613 derived_ms->linSys().extract(wellContribs);
1615 OpmLog::warning(
"Warning unknown type of well");
1622 template<
typename TypeTag>
1627 for (
const auto& well: well_container_ ) {
1628 well->addWellContributions(jacobian);
1632 template<
typename TypeTag>
1635 std::vector<CMatrix>& c_matrices,
1636 std::vector<DMatrix>& d_matrices,
1640 for (
const auto& well: well_container_ ) {
1641 well->addBCDMatrix(b_matrices, c_matrices, d_matrices, wcells);
1645 template<
typename TypeTag>
1650 const bool use_well_weights)
const
1652 int nw = this->numLocalWellsEnd();
1653 int rdofs = local_num_cells_;
1654 for (
int i = 0; i < nw; i++ ) {
1655 int wdof = rdofs + i;
1656 jacobian[wdof][wdof] = 1.0;
1659 for (
const auto& well : well_container_) {
1660 well->addWellPressureEquations(jacobian,
1668 template <
typename TypeTag>
1671 const std::vector<typename SparseMatrixAdapter::MatrixBlock*>& diagMatAddress)
const
1676 for (
const auto& well : well_container_) {
1677 if (!well->isOperableAndSolvable() && !well->wellIsStopped()) {
1680 const auto& cells = well->cells();
1681 const auto& rates = well->connectionRates();
1682 for (
unsigned perfIdx = 0; perfIdx < rates.size(); ++perfIdx) {
1683 unsigned cellIdx = cells[perfIdx];
1684 auto rate = rates[perfIdx];
1687 using MatrixBlockType =
typename SparseMatrixAdapter::MatrixBlock;
1688 MatrixBlockType bMat(0.0);
1689 simulator_.model().linearizer().setResAndJacobi(res, bMat, rate);
1690 residual[cellIdx] += res;
1691 *diagMatAddress[cellIdx] += bMat;
1697 template<
typename TypeTag>
1702 int nw = this->numLocalWellsEnd();
1703 int rdofs = local_num_cells_;
1704 const auto wellconnections = this->getMaxWellConnections();
1705 for (
int i = 0; i < nw; ++i) {
1706 int wdof = rdofs + i;
1707 jacobian.entry(wdof,wdof) = 0.0;
1708 const auto& perfcells = wellconnections[i];
1709 for (
int perfcell : perfcells) {
1710 jacobian.entry(wdof, perfcell) = 0.0;
1711 jacobian.entry(perfcell, wdof) = 0.0;
1717 template<
typename TypeTag>
1722 auto loggerGuard = this->groupStateHelper().pushLogger();
1725 for (
const auto& well : well_container_) {
1726 const auto& cells = well->cells();
1727 x_local_.resize(cells.size());
1729 for (
size_t i = 0; i < cells.size(); ++i) {
1730 x_local_[i] = x[cells[i]];
1732 well->recoverWellSolutionAndUpdateWellState(simulator_, x_local_,
1733 this->groupStateHelper(), this->wellState());
1737 simulator_.vanguard().grid().comm());
1741 template<
typename TypeTag>
1747 OPM_THROW(std::logic_error,
"Attempt to call NLDD method without a NLDD solver");
1750 return nldd_->recoverWellSolutionAndUpdateWellState(x, domainIdx);
1754 template<
typename TypeTag>
1757 getWellConvergence(
const std::vector<Scalar>& B_avg,
bool checkWellGroupControlsAndNetwork)
const
1761 const auto& iterCtx = simulator_.problem().iterationContext();
1762 const bool relaxTolerance = iterCtx.shouldRelax(param_.strict_outer_iter_wells_ + 1);
1764 auto logger_guard = this->groupStateHelper().pushLogger();
1765 for (
const auto& well : well_container_) {
1766 if (well->isOperableAndSolvable() || well->wellIsStopped()) {
1767 local_report += well->getWellConvergence(
1768 this->groupStateHelper(), B_avg,
1773 report.
setWellFailed({CR::WellFailure::Type::Unsolvable, CR::Severity::Normal, -1, well->name()});
1774 local_report += report;
1782 if (checkWellGroupControlsAndNetwork) {
1788 if (this->terminal_output_) {
1792 OpmLog::debug(
"NaN residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1794 OpmLog::debug(
"Too large residual found with phase " +
std::to_string(f.phase()) +
" for well " + f.wellName());
1805 template<
typename TypeTag>
1811 for (
auto& well : well_container_) {
1812 well->calculateExplicitQuantities(simulator_, this->groupStateHelper());
1820 template<
typename TypeTag>
1826 if (!this->wellsActive() && !this->isReservoirCouplingMaster()) {
1829 const int episodeIdx = simulator_.episodeIndex();
1830 const auto& comm = simulator_.vanguard().grid().comm();
1837 const auto nupcol = this->schedule()[episodeIdx].nupcol();
1838 const auto& iter_ctx = simulator_.problem().iterationContext();
1839 if (iter_ctx.withinNupcol(nupcol)) {
1841 for (
const auto& well : well_container_) {
1842 well->updateWeldrawMaxRate(simulator_, this->wellState(), deferred_logger);
1845 simulator_.gridView().comm());
1850 bool changed_well_group =
false;
1851 const Group& fieldGroup = this->schedule().getGroup(
"FIELD", episodeIdx);
1854 const std::size_t max_iter = param_.well_group_constraints_max_iterations_;
1855 while(!changed_well_group && iter < max_iter) {
1856 changed_well_group = updateGroupControls(fieldGroup, deferred_logger, episodeIdx);
1859 bool changed_well_to_group =
false;
1861 OPM_TIMEBLOCK(UpdateWellControls);
1865 for (
const auto& well : well_container_) {
1868 simulator_, mode, this->groupStateHelper(), this->wellState()
1871 changed_well_to_group = changed_well || changed_well_to_group;
1875 simulator_.gridView().comm());
1878 changed_well_to_group = comm.sum(
static_cast<int>(changed_well_to_group));
1879 if (changed_well_to_group) {
1880 updateAndCommunicate(episodeIdx);
1881 changed_well_group =
true;
1885 bool changed_well_individual =
false;
1890 for (
const auto& well : well_container_) {
1893 simulator_, mode, this->groupStateHelper(), this->wellState()
1896 changed_well_individual = changed_well || changed_well_individual;
1900 simulator_.gridView().comm());
1903 changed_well_individual = comm.sum(
static_cast<int>(changed_well_individual));
1904 if (changed_well_individual) {
1905 updateAndCommunicate(episodeIdx);
1906 changed_well_group =
true;
1912 this->updateWsolvent(fieldGroup, episodeIdx, this->nupcolWellState());
1914 return changed_well_group;
1918 template<
typename TypeTag>
1923 this->updateAndCommunicateGroupData(reportStepIdx,
true);
1929 for (
const auto& well : well_container_) {
1931 const auto& ws = this->wellState().well(well->indexOfWell());
1932 if (ws.production_cmode == Well::ProducerCMode::GRUP ||
1933 ws.injection_cmode == Well::InjectorCMode::GRUP)
1935 well->updateWellStateWithTarget(
1936 simulator_, this->groupStateHelper(), this->wellState()
1941 simulator_.gridView().comm())
1942 this->updateAndCommunicateGroupData(reportStepIdx,
true);
1945 template<
typename TypeTag>
1950 const int reportStepIdx)
1953 const auto& iterCtx = simulator_.problem().iterationContext();
1954 bool changed =
false;
1956 const int nupcol = this->schedule()[reportStepIdx].nupcol();
1957 const bool update_group_switching_log = !iterCtx.withinNupcol(nupcol);
1958 const bool changed_hc = this->checkGroupHigherConstraints(
1959 group, deferred_logger, reportStepIdx, update_group_switching_log);
1962 updateAndCommunicate(reportStepIdx);
1965 bool changed_individual =
1967 updateGroupIndividualControl(group,
1969 param_.max_number_of_group_switches_,
1970 update_group_switching_log,
1971 this->switched_inj_groups_,
1972 this->switched_prod_groups_,
1973 this->closed_offending_wells_,
1978 if (changed_individual) {
1980 updateAndCommunicate(reportStepIdx);
1983 for (
const std::string& groupName : group.groups()) {
1984 bool changed_this = updateGroupControls(this->schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx);
1985 changed = changed || changed_this;
1990 template<
typename TypeTag>
1996 auto logger_guard = this->groupStateHelper().pushLogger();
1997 auto& local_deferredLogger = this->groupStateHelper().deferredLogger();
1998 for (
const auto& well : well_container_) {
1999 const auto& wname = well->name();
2000 const auto wasClosed = wellTestState.well_is_closed(wname);
2001 well->checkWellOperability(simulator_,
2003 this->groupStateHelper());
2004 const bool under_zero_target =
2005 well->wellUnderZeroGroupRateTarget(this->groupStateHelper());
2006 well->updateWellTestState(this->wellState().well(wname),
2012 this->eclipseState().getUnits(),
2013 this->schedule().getStartTime(),
2014 local_deferredLogger);
2016 if (!wasClosed && wellTestState.well_is_closed(wname)) {
2017 this->closed_this_step_.insert(wname);
2020 const WellEconProductionLimits& econ_production_limits = well->wellEcl().getEconLimits();
2021 if (econ_production_limits.validFollowonWell()) {
2022 const auto episode_idx = simulator_.episodeIndex();
2023 const auto follow_on_well = econ_production_limits.followonWell();
2024 if (!this->schedule().hasWell(follow_on_well, episode_idx)) {
2025 const auto msg = fmt::format(
"Well {} was closed. But the given follow on well {} does not exist."
2026 "The simulator continues without opening a follow on well.",
2027 wname, follow_on_well);
2028 local_deferredLogger.warning(msg);
2030 auto& ws = this->wellState().well(follow_on_well);
2031 const bool success = ws.updateStatus(WellStatus::OPEN);
2033 const auto msg = fmt::format(
"Well {} was closed. The follow on well {} opens instead.", wname, follow_on_well);
2034 local_deferredLogger.info(msg);
2036 const auto msg = fmt::format(
"Well {} was closed. The follow on well {} is already open.", wname, follow_on_well);
2037 local_deferredLogger.warning(msg);
2044 for (
const auto& [group_name, to] : this->closed_offending_wells_) {
2045 if (this->hasOpenLocalWell(to.second) &&
2046 !this->wasDynamicallyShutThisTimeStep(to.second))
2048 wellTestState.close_well(to.second,
2049 WellTestConfig::Reason::GROUP,
2051 this->updateClosedWellsThisStep(to.second);
2052 const std::string msg =
2053 fmt::format(
"Procedure on exceeding {} limit is WELL for group {}. "
2059 local_deferredLogger.info(msg);
2065 template<
typename TypeTag>
2069 std::string& exc_msg,
2073 const int np = this->numPhases();
2074 std::vector<Scalar> potentials;
2075 const auto& well = well_container_[widx];
2076 std::string cur_exc_msg;
2079 well->computeWellPotentials(simulator_, well_state_copy, this->groupStateHelper(), potentials);
2084 exc_msg += fmt::format(
"\nFor well {}: {}", well->name(), cur_exc_msg);
2086 exc_type = std::max(exc_type, cur_exc_type);
2090 auto& ws = this->wellState().well(well->indexOfWell());
2091 for (
int p = 0; p < np; ++p) {
2093 ws.well_potentials[p] = std::max(
Scalar{0.0}, potentials[p]);
2099 template <
typename TypeTag>
2104 for (
const auto& wellPtr : this->well_container_) {
2105 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2113 template <
typename TypeTag>
2124 for (
const auto& shutWell : this->local_shut_wells_) {
2125 if (!this->wells_ecl_[shutWell].hasConnections()) {
2130 auto wellPtr = this->
template createTypedWellPointer
2133 wellPtr->
init(this->depth_, this->gravity_, this->B_avg_,
true);
2135 this->calculateProductivityIndexValues(wellPtr.get(), deferred_logger);
2143 template <
typename TypeTag>
2157 template<
typename TypeTag>
2162 const auto episodeIdx = simulator_.episodeIndex();
2165 const bool do_prestep_network_rebalance = this->shouldDoPreStepNetworkRebalance_(episodeIdx);
2167 for (
const auto& well : well_container_) {
2168 auto& events = this->wellState().well(well->indexOfWell()).events;
2170 well->updateWellStateWithTarget(
2171 simulator_, this->groupStateHelper(), this->wellState()
2173 well->updatePrimaryVariables(this->groupStateHelper());
2179 if (events.hasEvent(ScheduleEvents::REQUEST_OPEN_WELL)) {
2180 events.clearEvent(ScheduleEvents::REQUEST_OPEN_WELL);
2183 if (param_.solve_welleq_initially_ && well->isOperableAndSolvable()) {
2185 well->solveWellEquation(
2186 simulator_, this->groupStateHelper(), this->wellState()
2188 }
catch (
const std::exception& e) {
2189 const std::string msg =
"Compute initial well solution for " + well->name() +
" initially failed. Continue with the previous rates";
2190 deferred_logger.
warning(
"WELL_INITIAL_SOLVE_FAILED", msg);
2195 well->resetWellOperability();
2197 updatePrimaryVariables();
2200 if (do_prestep_network_rebalance) {
2201 network_.doPreStepRebalance(deferred_logger);
2205 template<
typename TypeTag>
2210 std::vector< Scalar > B_avg(numConservationQuantities(),
Scalar() );
2211 const auto& grid = simulator_.vanguard().grid();
2212 const auto& gridView = grid.leafGridView();
2216 for (
const auto& elem : elements(gridView, Dune::Partitions::interior)) {
2217 elemCtx.updatePrimaryStencil(elem);
2218 elemCtx.updatePrimaryIntensiveQuantities(0);
2220 const auto& intQuants = elemCtx.intensiveQuantities(0, 0);
2221 const auto& fs = intQuants.fluidState();
2223 for (
unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
2225 if (!FluidSystem::phaseIsActive(phaseIdx)) {
2229 const unsigned compIdx = FluidSystem::canonicalToActiveCompIdx(FluidSystem::solventComponentIndex(phaseIdx));
2230 auto& B = B_avg[ compIdx ];
2232 B += 1 / fs.invB(phaseIdx).value();
2234 if constexpr (has_solvent_) {
2235 auto& B = B_avg[solventSaturationIdx];
2236 B += 1 / intQuants.solventInverseFormationVolumeFactor().value();
2242 grid.comm().sum(B_avg.data(), B_avg.size());
2243 B_avg_.resize(B_avg.size());
2244 std::ranges::transform(B_avg, B_avg_.begin(),
2245 [gcells = global_num_cells_](
const auto bval)
2246 { return bval / gcells; });
2253 template<
typename TypeTag>
2258 for (
const auto& well : well_container_) {
2259 well->updatePrimaryVariables(this->groupStateHelper());
2263 template<
typename TypeTag>
2267 const auto& grid = simulator_.vanguard().grid();
2268 const auto& eclProblem = simulator_.problem();
2269 const unsigned numCells = grid.size(0);
2271 this->pvt_region_idx_.resize(numCells);
2272 for (
unsigned cellIdx = 0; cellIdx < numCells; ++cellIdx) {
2273 this->pvt_region_idx_[cellIdx] =
2274 eclProblem.pvtRegionIndex(cellIdx);
2279 template<
typename TypeTag>
2295 return this->numPhases() + has_solvent_;
2298 template<
typename TypeTag>
2302 const auto& eclProblem = simulator_.problem();
2303 depth_.resize(local_num_cells_);
2304 for (
unsigned cellIdx = 0; cellIdx < local_num_cells_; ++cellIdx) {
2305 depth_[cellIdx] = eclProblem.dofCenterDepth(cellIdx);
2309 template<
typename TypeTag>
2312 getWell(
const std::string& well_name)
const
2316 std::ranges::find_if(well_container_,
2318 {
return elem->name() == well_name; });
2320 assert(well != well_container_.end());
2325 template <
typename TypeTag>
2330 return std::max(this->simulator_.episodeIndex(), 0);
2337 template<
typename TypeTag>
2342 const std::vector<Scalar>& production_rates,
2343 std::vector<Scalar>& resv_coeff)
const
2345 rateConverter_->calcCoeff(fipnum, pvtreg, production_rates, resv_coeff);
2348 template<
typename TypeTag>
2353 std::vector<Scalar>& resv_coeff)
const
2355 rateConverter_->calcInjCoeff(fipnum, pvtreg, resv_coeff);
2359 template <
typename TypeTag>
2364 if constexpr (energyModuleType_ == EnergyModules::FullyImplicitThermal) {
2365 const int np = this->numPhases();
2366 const int nw = this->numLocalWells();
2367 for (
auto wellID = 0*nw; wellID < nw; ++wellID) {
2368 const Well& well = this->wells_ecl_[wellID];
2369 auto& ws = this->wellState().well(wellID);
2370 if (well.isInjector()) {
2371 if (ws.status != WellStatus::STOP) {
2372 this->wellState().well(wellID).temperature = well.inj_temperature();
2376 std::array<Scalar,2> weighted{0.0,0.0};
2377 auto& [weighted_temperature, total_weight] = weighted;
2378 const auto& well_info = this->local_parallel_well_info_[wellID].get();
2379 using int_type =
decltype(this->well_perf_data_[wellID].size());
2380 for (int_type perf = 0, end_perf = this->well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
2381 const int cell_idx = this->well_perf_data_[wellID][perf].cell_index;
2382 const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, 0);
2383 const auto& fs = intQuants.fluidState();
2384 Scalar weight_factor = computeTemperatureWeightFactor(perf, np, fs, ws);
2385 total_weight += weight_factor;
2386 weighted_temperature += weight_factor * fs.temperature(0).value();
2388 well_info.communication().sum(weighted.data(), 2);
2389 this->wellState().well(wellID).temperature = weighted_temperature / total_weight;
2395 template <
typename TypeTag>
2397 -> typename
WellState<Scalar,IndexTraits>::RsConstInfo
2399 if (! FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) ||
2400 ! FluidSystem::enableConstantRs())
2405 const auto& rsConstTables = this->eclState_
2406 .getTableManager().getRsconstTables();
2408 if (rsConstTables.empty() ||
2409 (rsConstTables[0].numRows() != std::size_t{1}))
2414 const auto rsConst = rsConstTables[0].getColumn(0).front();
2416 return {
true,
static_cast<Scalar
>(rsConst) };
2422 template <
typename TypeTag>
2423 void BlackoilWellModel<TypeTag>::
2424 assignWellTracerRates_(data::Wells& wsrpt)
const
2426 const auto reportStepIdx =
static_cast<unsigned int>(this->reportStepIndex());
2427 const auto& trMod = this->simulator_.problem().tracerModel();
2433 this->assignMswTracerRates(wsrpt, trMod.getMswTracerRates(), reportStepIdx);
2436 template <
typename TypeTag>
2437 void BlackoilWellModel<TypeTag>::
2438 assignWellSpeciesRates_(data::Wells& wsrpt)
const
2440 const auto reportStepIdx =
static_cast<unsigned int>(this->reportStepIndex());
2441 const auto& geochemMod = this->simulator_.problem().geochemistryModel();
2445 this->assignMswTracerRates(wsrpt, geochemMod.getMswSpeciesRates(), reportStepIdx);
2448 template <
typename TypeTag>
2449 bool BlackoilWellModel<TypeTag>::isRescoupMasterCoupledNetworkIteration_()
const
2451#ifdef RESERVOIR_COUPLING_ENABLED
2452 return this->rescoupHelper_.masterIsInCoupledNetworkIteration();
2458 template <
typename TypeTag>
2459 bool BlackoilWellModel<TypeTag>::isRescoupSlaveCoupledNetworkIteration_()
const
2470#ifdef RESERVOIR_COUPLING_ENABLED
2471 return this->isRescoupSlaveOnSyncStepFirstSubstep_()
2472 && this->reservoirCouplingSlave().connectedToMasterCoupledNetwork()
2473 && !this->reservoirCouplingSlave().lastReceivedMasterGroupNodePressuresIsFinal();
2479 template <
typename TypeTag>
2480 bool BlackoilWellModel<TypeTag>::isRescoupSlaveOnSyncStepFirstSubstep_()
const
2487#ifdef RESERVOIR_COUPLING_ENABLED
2488 return this->isReservoirCouplingSlave()
2489 && this->reservoirCouplingSlave().isFirstSubstepOfSyncTimestep();
2495 template <
typename TypeTag>
2496 bool BlackoilWellModel<TypeTag>::isRescoupSlaveConnectedToMasterNetwork_()
const
2498#ifdef RESERVOIR_COUPLING_ENABLED
2499 return this->isReservoirCouplingSlave()
2500 && this->reservoirCouplingSlave().connectedToMasterCoupledNetwork();
2506 template <
typename TypeTag>
2507 bool BlackoilWellModel<TypeTag>::
2508 maybeSendSlaveGroupFlowToMaster_([[maybe_unused]]
const int reportStepIdx)
2510#ifdef RESERVOIR_COUPLING_ENABLED
2517 assert(this->isReservoirCouplingSlave());
2518 const bool is_final =
2519 this->reservoirCouplingSlave().lastReceivedMasterGroupNodePressuresIsFinal();
2521 this->updateAndCommunicateGroupData(reportStepIdx,
false);
2522 this->rescoupHelper_.sendSlaveGroupDataToMaster();
2527 this->rescoupHelper_.receiveGroupConstraintsFromMaster();
2529 this->rescoupHelper_.refreshSlaveGroupInjectionTargets();
2538 template <
typename TypeTag>
2539 void BlackoilWellModel<TypeTag>::
2540 sendSlaveNetworkLoopTerminationSignal_()
2542#ifdef RESERVOIR_COUPLING_ENABLED
2547 assert(this->isReservoirCouplingMaster());
2548 this->rescoupHelper_.sendMasterGroupNodePressuresToSlaves(
true);
2552 template <
typename TypeTag>
2553 bool BlackoilWellModel<TypeTag>::
2554 shouldDoPreStepNetworkRebalance_(
const int episodeIdx)
const
2567 return param_.pre_solve_network_
2568 && this->network_.needPreStepRebalance(episodeIdx)
2569 && !this->isRescoupCoupledNetworkParticipant_();
2572 template <
typename TypeTag>
2573 bool BlackoilWellModel<TypeTag>::isRescoupCoupledNetworkParticipant_()
const
2575#ifdef RESERVOIR_COUPLING_ENABLED
2576 if (this->isReservoirCouplingMaster()) {
2577 return this->rescoupHelper_.masterNetworkHasMasterGroupLeaves();
2579 if (this->isReservoirCouplingSlave()) {
2580 return this->reservoirCouplingSlave().connectedToMasterCoupledNetwork();
2588 template <
typename TypeTag>
2589 void BlackoilWellModel<TypeTag>::
2590 updateNetworkActiveState_()
2601 const int episodeIdx = this->simulator_.episodeIndex();
2602 this->network_.updateActiveState(episodeIdx);
#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:207
#define OPM_DEFLOG_THROW(Exception, message, deferred_logger)
Definition: DeferredLoggingErrorHelpers.hpp:47
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:197
#define OPM_PARALLEL_CATCH_CLAUSE(obptc_exc_type, obptc_exc_msg)
Inserts catch classes for the parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:168
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:160
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:113
Class for handling constraints for the blackoil well model.
Definition: BlackoilWellModelConstraints.hpp:42
Class for handling the gaslift in the blackoil well model.
Definition: BlackoilWellModelGasLift.hpp:96
Class for handling the blackoil well model.
Definition: BlackoilWellModelGeneric.hpp:100
BlackoilWellModelWBP< Scalar, IndexTraits > wbp_
Definition: BlackoilWellModelGeneric.hpp:609
std::vector< std::unique_ptr< ParallelWellInfo< Scalar > > > parallel_well_info_
Definition: BlackoilWellModelGeneric.hpp:640
void updateFailed()
Restore the state captured at the start of the failing timestep.
Definition: BlackoilWellModelGeneric.hpp:241
void advanceTimeLevel()
Snapshot the mutable well-model state at the start of a timestep.
Definition: BlackoilWellModelGeneric.hpp:228
const Parallel::Communication & comm() const
Definition: BlackoilWellModelGeneric.hpp:266
void assignWellTracerRates(data::Wells &wsrpt, const WellTracerRates &wellTracerRates, const unsigned reportStep) const
Class for handling the guide rates in the blackoil well model.
Definition: BlackoilWellModelGuideRates.hpp:47
Class for handling the blackoil well model.
Definition: BlackoilWellModel.hpp:101
void initializeGroupStructure(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:308
void calcResvCoeff(const int fipnum, const int pvtreg, const std::vector< Scalar > &production_rates, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2340
void prepareTimeStep(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:2160
std::tuple< bool, bool, Scalar > updateWellControlsAndNetworkIteration(const bool mandatory_network_balance, const bool relax_network_tolerance, const bool optimize_gas_lift, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1403
WellInterfacePtr createWellPointer(const int wellID, const int report_step) const
Definition: BlackoilWellModel_impl.hpp:1126
void prepareWellsBeforeAssembling(const double dt)
Definition: BlackoilWellModel_impl.hpp:1526
void init()
Definition: BlackoilWellModel_impl.hpp:166
const Simulator & simulator() const
Definition: BlackoilWellModel.hpp:390
std::vector< Scalar > depth_
Definition: BlackoilWellModel.hpp:600
std::size_t global_num_cells_
Definition: BlackoilWellModel.hpp:596
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: BlackoilWellModel.hpp:110
void initWellContainer(const int reportStepIdx) override
Definition: BlackoilWellModel_impl.hpp:185
void beginReportStep(const int time_step)
Definition: BlackoilWellModel_impl.hpp:202
const WellInterface< TypeTag > & getWell(const std::string &well_name) const
Definition: BlackoilWellModel_impl.hpp:2312
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: BlackoilWellModel.hpp:106
Dune::FieldVector< Scalar, numEq > VectorBlockType
Definition: BlackoilWellModel.hpp:134
GetPropType< TypeTag, Properties::ElementContext > ElementContext
Definition: BlackoilWellModel.hpp:107
GetPropType< TypeTag, Properties::Grid > Grid
Definition: BlackoilWellModel.hpp:104
int numConservationQuantities() const
Definition: BlackoilWellModel_impl.hpp:2281
bool updateWellControls(DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:1823
int reportStepIndex() const
Definition: BlackoilWellModel_impl.hpp:2328
void calculateProductivityIndexValues(DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2102
void extractLegacyDepth_()
Definition: BlackoilWellModel_impl.hpp:2300
void extractLegacyCellPvtRegionIndex_()
Definition: BlackoilWellModel_impl.hpp:2265
void recoverWellSolutionAndUpdateWellStateDomain(const BVector &x, const int domainIdx)
Definition: BlackoilWellModel_impl.hpp:1744
void updateAverageFormationFactor()
Definition: BlackoilWellModel_impl.hpp:2208
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: BlackoilWellModel.hpp:109
BlackoilWellModel(Simulator &simulator, const NewtonIterationContext &iter_ctx)
Definition: BlackoilWellModel_impl.hpp:73
void initializeWellState(const int timeStepIdx)
Definition: BlackoilWellModel_impl.hpp:828
const Grid & grid() const
Definition: BlackoilWellModel.hpp:387
void updatePrimaryVariables()
Definition: BlackoilWellModel_impl.hpp:2256
void computeWellTemperature()
Definition: BlackoilWellModel_impl.hpp:2362
void addWellPressureEquations(PressureMatrix &jacobian, const BVector &weights, const bool use_well_weights) const
Definition: BlackoilWellModel_impl.hpp:1648
const SimulatorReportSingle & lastReport() const
Definition: BlackoilWellModel_impl.hpp:688
bool updateWellControlsAndNetwork(const bool mandatory_network_balance, const double dt, DeferredLogger &local_deferredLogger)
Definition: BlackoilWellModel_impl.hpp:1337
void addWellContributions(SparseMatrixAdapter &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1625
void assembleWellEq(const double dt)
Definition: BlackoilWellModel_impl.hpp:1514
WellInterfacePtr createWellForWellTest(const std::string &well_name, const int report_step, DeferredLogger &deferred_logger) const
Definition: BlackoilWellModel_impl.hpp:1177
void calculateExplicitQuantities() const
Definition: BlackoilWellModel_impl.hpp:1808
void collectWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1292
void updateAndCommunicate(const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1921
Dune::BCRSMatrix< Opm::MatrixBlock< Scalar, 1, 1 > > PressureMatrix
Definition: BlackoilWellModel.hpp:309
void updateFailed()
Definition: BlackoilWellModel_impl.hpp:597
void computeTotalRatesForDof(RateVector &rate, unsigned globalIdx) const
Definition: BlackoilWellModel_impl.hpp:791
void stashWellSolveStats()
Definition: BlackoilWellModel_impl.hpp:1308
void beginTimeStep()
Definition: BlackoilWellModel_impl.hpp:340
GetPropType< TypeTag, Properties::RateVector > RateVector
Definition: BlackoilWellModel.hpp:111
bool updateGroupControls(const Group &group, DeferredLogger &deferred_logger, const int reportStepIdx)
Definition: BlackoilWellModel_impl.hpp:1948
void initializeLocalWellStructure(const int reportStepIdx, const bool enableWellPIScaling, const bool initializeWellState)
Definition: BlackoilWellModel_impl.hpp:254
void calcInjResvCoeff(const int fipnum, const int pvtreg, std::vector< Scalar > &resv_coeff) const override
Definition: BlackoilWellModel_impl.hpp:2351
Dune::BlockVector< VectorBlockType > BVector
Definition: BlackoilWellModel.hpp:135
void wellTesting(const int timeStepIdx, const double simulationTime, DeferredLogger &deferred_logger)
Definition: BlackoilWellModel_impl.hpp:612
ConvergenceReport getWellConvergence(const std::vector< Scalar > &B_avg, const bool checkWellGroupControlsAndNetwork=false) const
Definition: BlackoilWellModel_impl.hpp:1757
typename FluidSystem::IndexTraitsType IndexTraits
Definition: BlackoilWellModel.hpp:117
void updateCellRatesForDomain(int domainIndex, const std::map< std::string, int > &well_domain_map)
Definition: BlackoilWellModel_impl.hpp:1572
void assembleWellEqWithoutIteration(const double dt)
Definition: BlackoilWellModel_impl.hpp:1540
void updateCellRates()
Definition: BlackoilWellModel_impl.hpp:1560
void assemble(const double dt)
Definition: BlackoilWellModel_impl.hpp:1202
std::size_t local_num_cells_
Definition: BlackoilWellModel.hpp:598
bool alternative_well_rate_init_
Definition: BlackoilWellModel.hpp:601
void timeStepSucceeded(const double simulationTime, const double dt)
Definition: BlackoilWellModel_impl.hpp:698
std::unique_ptr< WellType > createTypedWellPointer(const int wellID, const int time_step) const
Definition: BlackoilWellModel_impl.hpp:1146
void computePotentials(const std::size_t widx, const WellState< Scalar, IndexTraits > &well_state_copy, std::string &exc_msg, ExceptionType::ExcEnum &exc_type) override
Definition: BlackoilWellModel_impl.hpp:2067
Simulator & simulator_
Definition: BlackoilWellModel.hpp:570
void createWellContainer(const int report_step) override
Definition: BlackoilWellModel_impl.hpp:871
std::unique_ptr< WellInterface< TypeTag > > WellInterfacePtr
Definition: BlackoilWellModel.hpp:195
void updateWellTestState(const double simulationTime, WellTestState &wellTestState)
upate the wellTestState related to economic limits
Definition: BlackoilWellModel_impl.hpp:1993
void addBCDMatrix(std::vector< BMatrix > &b_matrices, std::vector< CMatrix > &c_matrices, std::vector< DMatrix > &d_matrices, Opm::SparseTable< int > &wcells) const
Definition: BlackoilWellModel_impl.hpp:1634
void addSolveStats(const WellInterface< TypeTag > &well)
Definition: BlackoilWellModel_impl.hpp:1318
void addReservoirSourceTerms(GlobalEqVector &residual, const std::vector< typename SparseMatrixAdapter::MatrixBlock * > &diagMatAddress) const
Definition: BlackoilWellModel_impl.hpp:1670
int compressedIndexForInterior(int cartesian_cell_idx) const override
get compressed index for interior cells (-1, otherwise
Definition: BlackoilWellModel.hpp:362
void recoverWellSolutionAndUpdateWellState(const BVector &x)
Definition: BlackoilWellModel_impl.hpp:1720
void addWellPressureEquationsStruct(PressureMatrix &jacobian) const
Definition: BlackoilWellModel_impl.hpp:1700
void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger &deferred_logger) override
Definition: BlackoilWellModel_impl.hpp:2116
void advanceTimeLevel()
Definition: BlackoilWellModel_impl.hpp:605
void endReportStep()
Definition: BlackoilWellModel_impl.hpp:671
Definition: ConvergenceReport.hpp:38
void setWellFailed(const WellFailure &wf)
Definition: ConvergenceReport.hpp:296
void setWellGroupTargetsViolated(const bool wellGroupTargetsViolated)
Definition: ConvergenceReport.hpp:314
const std::vector< WellFailure > & wellFailures() const
Definition: ConvergenceReport.hpp:459
void setNetworkNotYetBalancedForceAnotherNewtonIteration(const bool network_needs_more_balancing_force_another_newton_iteration)
Definition: ConvergenceReport.hpp:319
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)
std::map< std::string, std::pair< const Well *, int > > GLiftEclWells
Definition: GasLiftGroupInfo.hpp:65
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:217
Definition: StandardWell.hpp:55
virtual void init(const std::vector< Scalar > &depth_arg, const Scalar gravity_arg, const std::vector< Scalar > &B_avg, const bool changed_to_open_this_step) override
Definition: StandardWell_impl.hpp:77
Definition: WellContributions.hpp:51
void alloc()
Allocate memory for the StandardWells.
void setBlockSize(unsigned int dim, unsigned int dim_wells)
void addNumBlocks(unsigned int numBlocks)
const WellSolveStats & solveStats() const
Definition: WellInterfaceGeneric.hpp:293
void resetSolveStats() const
Definition: WellInterfaceGeneric.hpp:294
int indexOfWell() const
Index of well in the wells struct and wellState.
Definition: WellInterface.hpp:79
virtual void updateProductivityIndex(const Simulator &simulator, const WellProdIndexCalculator< Scalar > &wellPICalc, WellStateType &well_state, DeferredLogger &deferred_logger) const =0
bool updateWellControl(const Simulator &simulator, const IndividualOrGroup iog, const GroupStateHelperType &groupStateHelper, WellStateType &well_state)
Definition: WellInterface_impl.hpp:192
Definition: WellState.hpp:68
if(!linsolver_)
Definition: FlexibleSolver_impl.hpp:326
ExcEnum
Definition: DeferredLogger.hpp:45
@ NONE
Definition: DeferredLogger.hpp:46
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
ConvergenceReport gatherConvergenceReport(const ConvergenceReport &local_report, Parallel::Communication communicator)
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
#define RESERVOIR_COUPLING_ENABLED
Definition: simulator.hh:32
Context for iteration-dependent decisions in the Newton solver.
Definition: NewtonIterationContext.hpp:43
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34