opm-simulators
Loading...
Searching...
No Matches
GuideRateHandler.hpp
1/*
2 Copyright 2025 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_GUIDERATE_HANDLER_HPP
21#define OPM_GUIDERATE_HANDLER_HPP
22
23#if HAVE_MPI
24#define RESERVOIR_COUPLING_ENABLED
25#endif
26#ifdef RESERVOIR_COUPLING_ENABLED
27#include <opm/simulators/flow/ReservoirCoupling.hpp>
28#include <opm/simulators/flow/ReservoirCouplingMaster.hpp>
29#include <opm/simulators/flow/ReservoirCouplingSlave.hpp>
30#endif
31#include <opm/input/eclipse/Schedule/Group/GuideRate.hpp>
32#include <opm/output/data/Groups.hpp>
33#include <opm/output/data/GuideRateValue.hpp>
34#include <opm/simulators/utils/DeferredLogger.hpp>
35#include <opm/simulators/wells/BlackoilWellModelGeneric.hpp>
36#include <opm/simulators/wells/BlackoilWellModelGuideRates.hpp>
37#include <opm/simulators/wells/GroupState.hpp>
38#include <opm/simulators/wells/WellState.hpp>
39namespace Opm {
40
52template<typename Scalar, typename IndexTraits>
53class GuideRateHandler {
54public:
55
56#ifdef RESERVOIR_COUPLING_ENABLED
57 using Potentials = ReservoirCoupling::Potentials;
58#endif
59
66 class GuideRateDumper {
67 public:
68 GuideRateDumper(
69 GuideRateHandler<Scalar, IndexTraits> &parent, const int report_step_idx, const double sim_time
70 );
71
72 DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
76 void dumpGuideRates();
77 private:
78 void dumpGuideRatesRecursive_(const Group& group, int level);
79 void getGroupGuideRatesInjection_(
80 const Group& group,
81 const data::GroupGuideRates& group_guide_rate,
82 std::vector<std::string>& msg_items
83 ) const;
84 void getGroupGuideRatesProduction_(
85 const Group& group,
86 const data::GroupGuideRates& group_guide_rate,
87 std::vector<std::string>& msg_items
88 ) const;
95 void printGroupGuideRates_(const Group& group, int level);
96 void printHeader_();
97 void printFooter_();
98 void printWellGuideRates_(const Well& well, int level);
99
100 GuideRateHandler<Scalar, IndexTraits> &parent_;
101 const int report_step_idx_;
102 const double sim_time_;
104 const Schedule& schedule_;
105 const Parallel::Communication& comm_;
106 std::unordered_map<std::string, data::GuideRateValue> well_guide_rates_;
107 std::unordered_map<std::string, data::GroupGuideRates> group_guide_rates_;
108 };
109
117 class UpdateGuideRates {
118 public:
119 UpdateGuideRates(
120 GuideRateHandler<Scalar, IndexTraits> &parent,
121 const int report_step_idx,
122 const double sim_time,
123 const WellState<Scalar, IndexTraits> &well_state,
124 GroupState<Scalar> &group_state,
125 const int num_phases
126 );
127
128#ifdef RESERVOIR_COUPLING_ENABLED
129 bool isReservoirCouplingMaster() const { return this->parent_.isReservoirCouplingMaster(); }
130 ReservoirCouplingMaster& reservoirCouplingMaster() {
131 return this->parent_.reservoirCouplingMaster();
132 }
133#endif
134 const Parallel::Communication &comm() const { return this->parent_.comm_; }
135 DeferredLogger &deferredLogger() { return this->parent_.deferredLogger(); }
136 GuideRate &guideRate() { return this->parent_.guide_rate_; }
137 const PhaseUsageInfo<IndexTraits>& phaseUsage() const { return this->parent_.wellModel().phaseUsage(); }
138 const SummaryState &summaryState() const { return this->parent_.summary_state_; }
139 const Schedule &schedule() const { return this->parent_.schedule_; }
143 void update();
144
145 private:
146#ifdef RESERVOIR_COUPLING_ENABLED
147 bool isMasterGroup_(const Group& group);
148#endif
149 void updateGuideRatesForInjectionGroups_(const Group& group);
156 void updateGuideRatesForProductionGroups_(const Group& group, std::vector<Scalar>& pot);
157 void updateGuideRatesForWells_();
158#ifdef RESERVOIR_COUPLING_ENABLED
159 void updateProductionGroupPotentialFromSlaveGroup_(
160 const Group& group, std::vector<Scalar>& pot);
161#endif
162 void updateProductionGroupPotentialFromSubGroups(
163 const Group& group, std::vector<Scalar>& pot);
164
165 GuideRateHandler<Scalar, IndexTraits> &parent_;
166 const int report_step_idx_;
167 const double sim_time_;
168 const WellState<Scalar, IndexTraits> &well_state_;
169 GroupState<Scalar> &group_state_;
170 const int num_phases_;
171 const UnitSystem& unit_system_;
172 };
173
174 GuideRateHandler(
176 const Schedule& schedule,
177 const SummaryState& summary_state,
178 const Parallel::Communication& comm
179 );
180
181#ifdef RESERVOIR_COUPLING_ENABLED
182 bool isReservoirCouplingMaster() const {
183 return this->reservoir_coupling_master_ != nullptr;
184 }
185 bool isReservoirCouplingSlave() const {
186 return this->reservoir_coupling_slave_ != nullptr;
187 }
188 void receiveMasterGroupPotentialsFromSlaves();
189 ReservoirCouplingMaster& reservoirCouplingMaster() { return *(this->reservoir_coupling_master_); }
190 ReservoirCouplingSlave& reservoirCouplingSlave() { return *(this->reservoir_coupling_slave_); }
191 void sendSlaveGroupPotentialsToMaster(const GroupState<Scalar>& group_state);
192 void setReservoirCouplingMaster(ReservoirCouplingMaster *reservoir_coupling_master) {
193 this->reservoir_coupling_master_ = reservoir_coupling_master;
194 }
195 void setReservoirCouplingSlave(ReservoirCouplingSlave *reservoir_coupling_slave) {
196 this->reservoir_coupling_slave_ = reservoir_coupling_slave;
197 }
198#endif
199 DeferredLogger& deferredLogger();
208 void debugDumpGuideRates(const int report_step_idx, const double sim_time);
209 const Parallel::Communication& getComm() const { return comm_; }
210 void setLogger(DeferredLogger *deferred_logger);
211 const Schedule& schedule() const { return schedule_; }
220 void updateGuideRates(const int report_step_idx,
221 const double sim_time,
222 const WellState<Scalar, IndexTraits>& well_state,
223 GroupState<Scalar>& group_state);
224
225 const BlackoilWellModelGeneric<Scalar, IndexTraits>& wellModel() const { return well_model_; }
226private:
227 void debugDumpGuideRatesRecursive_(const Group& group) const;
228 BlackoilWellModelGeneric<Scalar, IndexTraits>& well_model_;
229 const Schedule& schedule_;
230 const SummaryState& summary_state_;
231 const Parallel::Communication& comm_;
232 GuideRate& guide_rate_;
233 DeferredLogger *deferred_logger_ = nullptr;
234#ifdef RESERVOIR_COUPLING_ENABLED
235 ReservoirCouplingMaster *reservoir_coupling_master_ = nullptr;
236 ReservoirCouplingSlave *reservoir_coupling_slave_ = nullptr;
237#endif
238};
239
240} // namespace Opm
241
242#endif // OPM_GUIDERATE_HANDLER_HPP
Class for handling the blackoil well model.
Definition BlackoilWellModelGeneric.hpp:95
Definition DeferredLogger.hpp:57
Definition GroupState.hpp:41
void dumpGuideRates()
Dumps guide rates for all wells and groups in a hierarchical structure.
Definition GuideRateHandler.cpp:213
void update()
Triggers the guide rate update process for the current simulation step.
Definition GuideRateHandler.cpp:482
void debugDumpGuideRates(const int report_step_idx, const double sim_time)
Dumps guide rate information to the logger in a readable format.
Definition GuideRateHandler.cpp:101
void updateGuideRates(const int report_step_idx, const double sim_time, const WellState< Scalar, IndexTraits > &well_state, GroupState< Scalar > &group_state)
Updates guide rates for the current simulation step.
Definition GuideRateHandler.cpp:172
Definition GasLiftGroupInfo.hpp:37
Definition ReservoirCouplingMaster.hpp:35
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:66
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Definition ReservoirCoupling.hpp:63