opm-simulators
GroupEconomicLimitsChecker.hpp
1 /*
2  Copyright 2023 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_GROUP_ECONOMIC_LIMITS_CHECKER_HEADER_INCLUDED
21 #define OPM_GROUP_ECONOMIC_LIMITS_CHECKER_HEADER_INCLUDED
22 
23 #include <opm/input/eclipse/Schedule/Group/GroupEconProductionLimits.hpp>
24 #include <opm/input/eclipse/Units/UnitSystem.hpp>
25 
26 #include <array>
27 #include <map>
28 #include <optional>
29 #include <string>
30 #include <vector>
31 
32 namespace Opm
33 {
34 
35 template<typename Scalar, typename IndexTraits> class BlackoilWellModelGeneric;
36 class DeferredLogger;
37 class Group;
38 template<typename Scalar, typename IndexTraits> class WellState;
39 class WellTestState;
40 
41 template<typename Scalar, typename IndexTraits>
43 {
44 public:
45  enum class RatioViolation {
46  NONE,
47  WATER_CUT,
48  GOR,
49  WGR
50  };
51 
52  struct RatioDetails
53  {
54  RatioViolation violation;
55  std::string ratio_type;
56  Scalar ratio;
57  Scalar limit;
58  UnitSystem::measure measure;
59  };
60 
62  WellTestState& well_test_state,
63  const Group& group,
64  const double simulation_time,
65  const int report_step_idx,
66  DeferredLogger& deferred_logger);
67  void closeWells();
68  bool minGasRate();
69  bool minOilRate();
70  std::optional<RatioDetails> waterCut();
71  std::optional<RatioDetails> GOR();
72  std::optional<RatioDetails> WGR();
73  std::optional<RatioDetails> ratioViolation();
74  void doWorkOver(const RatioDetails& ratio_details);
75  bool endRun();
76  int numProducersOpenInitially();
77  int numProducersOpen();
78  void activateEndRun();
79  std::string message_separator(const char sep_char = '*',
80  const size_t sep_length = 110) const
81  { return std::string(sep_length, sep_char); }
82 
83  static constexpr int NUM_PHASES = 3;
84 
85 private:
86  void displayDebugMessage(const std::string& msg) const;
87  void addPrintMessage(const std::string& msg,
88  const Scalar value,
89  const Scalar limit,
90  const UnitSystem::measure measure);
91  bool closeWellsRecursive(const Group& group, int level = 0);
92  void throwNotImplementedError(const std::string& error) const;
93 
95  void collectProducerWells(const Group& group,
96  std::vector<std::string>& well_names) const;
97 
101  std::optional<Scalar> computeWellRatio(const std::string& well_name,
102  const RatioViolation ratio_violation) const;
103 
107  void closeWorstOffendingRatioWell(const RatioDetails& ratio_details);
108 
109  std::optional<RatioDetails> groupRatioDetails(const RatioViolation ratio_violation) const;
110 
112  const Group& group_;
113  const double simulation_time_;
114  const int report_step_idx_;
115  DeferredLogger& deferred_logger_;
116  const std::string date_string_;
117  const UnitSystem& unit_system_;
118  const WellState<Scalar, IndexTraits>& well_state_;
119  WellTestState& well_test_state_;
120  const Schedule& schedule_;
121  GroupEconProductionLimits::GEconGroupProp gecon_props_;
122  bool debug_ = true;
123  std::array<Scalar,NUM_PHASES> production_rates_;
124  std::map<int, unsigned> phase_idx_map_ = {
125  {0, IndexTraits::oilPhaseIdx},
126  {1, IndexTraits::gasPhaseIdx},
127  {2, IndexTraits::waterPhaseIdx}
128  };
129  std::map<unsigned, int> phase_idx_reverse_map_;
130  std::string message_;
131 };
132 
133 } // namespace Opm
134 
135 #endif // OPM_GROUP_ECONOMIC_LIMITS_CHECKER_HEADER_INCLUDED
Definition: GroupEconomicLimitsChecker.hpp:52
Definition: GroupEconomicLimitsChecker.hpp:42
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: DeferredLogger.hpp:56
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: TemperatureModel.hpp:65