My Project
WellInterfaceFluidSystem.hpp
1 /*
2  Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
3  Copyright 2017 Statoil ASA.
4  Copyright 2017 IRIS
5  Copyright 2019 Norce
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #ifndef OPM_WELLINTERFACE_FLUID_SYSTEM_HEADER_INCLUDED
25 #define OPM_WELLINTERFACE_FLUID_SYSTEM_HEADER_INCLUDED
26 
27 #include <opm/simulators/wells/WellInterfaceGeneric.hpp>
28 #include <opm/core/props/BlackoilPhases.hpp>
29 
30 #include <limits>
31 
32 namespace Opm
33 {
34 namespace RateConverter
35 {
36  template <class FluidSystem, class Region> class SurfaceToReservoirVoidage;
37 }
38 
39 class Group;
40 class GroupState;
41 class Schedule;
42 class WellState;
43 class SingleWellState;
44 
45 template<class FluidSystem>
47 protected:
48  using RateConverterType = RateConverter::
49  SurfaceToReservoirVoidage<FluidSystem, std::vector<int>>;
50  // to indicate a invalid completion
51  static constexpr int INVALIDCOMPLETION = std::numeric_limits<int>::max();
52 
53 public:
54  void updateWellTestState(const SingleWellState& ws,
55  const double& simulationTime,
56  const bool& writeMessageToOPMLog,
57  WellTestState& wellTestState,
58  DeferredLogger& deferred_logger) const;
59 
60  int flowPhaseToEbosPhaseIdx(const int phaseIdx) const;
61 
62  static constexpr int Water = BlackoilPhases::Aqua;
63  static constexpr int Oil = BlackoilPhases::Liquid;
64  static constexpr int Gas = BlackoilPhases::Vapour;
65 
66  const RateConverterType& rateConverter() const
67  {
68  return rateConverter_;
69  }
70 
71 protected:
72  WellInterfaceFluidSystem(const Well& well,
73  const ParallelWellInfo& parallel_well_info,
74  const int time_step,
75  const RateConverterType& rate_converter,
76  const int pvtRegionIdx,
77  const int num_components,
78  const int num_phases,
79  const int index_of_well,
80  const std::vector<PerforationData>& perf_data);
81 
82  // updating the voidage rates in well_state when requested
83  void calculateReservoirRates(SingleWellState& ws) const;
84 
85  bool checkIndividualConstraints(SingleWellState& ws,
86  const SummaryState& summaryState) const;
87 
88  Well::InjectorCMode activeInjectionConstraint(const SingleWellState& ws,
89  const SummaryState& summaryState) const;
90 
91  Well::ProducerCMode activeProductionConstraint(const SingleWellState& ws,
92  const SummaryState& summaryState) const;
93 
94  std::pair<bool, double> checkGroupConstraintsInj(const Group& group,
95  const WellState& well_state,
96  const GroupState& group_state,
97  const double efficiencyFactor,
98  const Schedule& schedule,
99  const SummaryState& summaryState,
100  DeferredLogger& deferred_logger) const;
101 
102  std::pair<bool, double> checkGroupConstraintsProd(const Group& group,
103  const WellState& well_state,
104  const GroupState& group_state,
105  const double efficiencyFactor,
106  const Schedule& schedule,
107  const SummaryState& summaryState,
108  DeferredLogger& deferred_logger) const;
109 
110  bool checkGroupConstraints(WellState& well_state,
111  const GroupState& group_state,
112  const Schedule& schedule,
113  const SummaryState& summaryState,
114  DeferredLogger& deferred_logger) const;
115 
116  bool checkConstraints(WellState& well_state,
117  const GroupState& group_state,
118  const Schedule& schedule,
119  const SummaryState& summaryState,
120  DeferredLogger& deferred_logger) const;
121 
122  bool checkRateEconLimits(const WellEconProductionLimits& econ_production_limits,
123  const double* rates_or_potentials,
124  Opm::DeferredLogger& deferred_logger) const;
125 
127  bool ratio_limit_violated = false;
128  int worst_offending_completion = INVALIDCOMPLETION;
129  double violation_extent = 0.0;
130  };
131 
132  void checkMaxWaterCutLimit(const WellEconProductionLimits& econ_production_limits,
133  const SingleWellState& ws,
134  RatioLimitCheckReport& report) const;
135 
136  void checkMaxGORLimit(const WellEconProductionLimits& econ_production_limits,
137  const SingleWellState& ws,
138  RatioLimitCheckReport& report) const;
139 
140  void checkMaxWGRLimit(const WellEconProductionLimits& econ_production_limits,
141  const SingleWellState& ws,
142  RatioLimitCheckReport& report) const;
143 
144  void checkRatioEconLimits(const WellEconProductionLimits& econ_production_limits,
145  const SingleWellState& ws,
146  RatioLimitCheckReport& report,
147  DeferredLogger& deferred_logger) const;
148 
149  void updateWellTestStateEconomic(const SingleWellState& ws,
150  const double simulation_time,
151  const bool write_message_to_opmlog,
152  WellTestState& well_test_state,
153  DeferredLogger& deferred_logger) const;
154 
155  std::optional<double>
156  getGroupInjectionTargetRate(const Group& group,
157  const WellState& well_state,
158  const GroupState& group_state,
159  const Schedule& schedule,
160  const SummaryState& summaryState,
161  const InjectorType& injectorType,
162  double efficiencyFactor,
163  DeferredLogger& deferred_logger) const;
164 
165  double
166  getGroupProductionTargetRate(const Group& group,
167  const WellState& well_state,
168  const GroupState& group_state,
169  const Schedule& schedule,
170  const SummaryState& summaryState,
171  double efficiencyFactor) const;
172 
173  // For the conversion between the surface volume rate and reservoir voidage rate
174  const RateConverterType& rateConverter_;
175 
176 private:
177  template <typename RatioFunc>
178  void checkMaxRatioLimitCompletions(const SingleWellState& ws,
179  const double max_ratio_limit,
180  const RatioFunc& ratioFunc,
181  RatioLimitCheckReport& report) const;
182 
183  template<typename RatioFunc>
184  bool checkMaxRatioLimitWell(const SingleWellState& well_state,
185  const double max_ratio_limit,
186  const RatioFunc& ratioFunc) const;
187 };
188 
189 }
190 
191 #endif // OPM_WELLINTERFACE_FLUID_SYSTEM_HEADER_INCLUDED
Definition: DeferredLogger.hpp:57
Definition: GroupState.hpp:34
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:252
Convert component rates at surface conditions to phase (voidage) rates at reservoir conditions.
Definition: RateConverter.hpp:68
Definition: SingleWellState.hpp:34
Definition: WellInterfaceFluidSystem.hpp:46
Definition: WellInterfaceGeneric.hpp:51
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:56
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
Definition: WellInterfaceFluidSystem.hpp:126