opm-simulators
SingleWellState.hpp
1 /*
2  Copyright 2021 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_SINGLE_WELL_STATE_HEADER_INCLUDED
21 #define OPM_SINGLE_WELL_STATE_HEADER_INCLUDED
22 
23 #include <functional>
24 #include <vector>
25 
26 #include <opm/input/eclipse/Schedule/Well/WellEnums.hpp>
27 #include <opm/input/eclipse/Schedule/Events.hpp>
28 #include <opm/input/eclipse/Schedule/Group/Group.hpp>
29 
30 #include <opm/material/fluidsystems/PhaseUsageInfo.hpp>
31 
32 #include <opm/simulators/wells/SegmentState.hpp>
33 #include <opm/simulators/wells/PerfData.hpp>
34 #include <opm/simulators/wells/ParallelWellInfo.hpp>
35 #include <opm/simulators/wells/ALQState.hpp>
36 
37 namespace Opm {
38 
39 template<class Scalar> struct PerforationData;
40 class SummaryState;
41 class Well;
42 
43 template<typename Scalar, typename IndexTraits>
44 class SingleWellState {
45 public:
46  static const int waterPhaseIdx = PhaseUsageInfo<IndexTraits>::waterPhaseIdx;
47  static const int oilPhaseIdx = PhaseUsageInfo<IndexTraits>::oilPhaseIdx;
48  static const int gasPhaseIdx = PhaseUsageInfo<IndexTraits>::gasPhaseIdx;
49 
50  SingleWellState(const std::string& name,
51  const ParallelWellInfo<Scalar>& pinfo,
52  const PhaseUsageInfo<IndexTraits>& pu,
53  bool is_producer,
54  Scalar pressure_first_connection,
55  const std::vector<PerforationData<Scalar>>& perf_input,
56  Scalar temp);
57 
58  static SingleWellState serializationTestObject(const ParallelWellInfo<Scalar>& pinfo);
59 
60  template<class Serializer>
61  void serializeOp(Serializer& serializer)
62  {
63  serializer(name);
64  serializer(status);
65  serializer(producer);
66  serializer(bhp);
67  serializer(thp);
68  serializer(pressure_first_connection);
69  serializer(temperature);
70  serializer(energy_rate);
71  serializer(efficiency_scaling_factor);
72  serializer(phase_mixing_rates);
73  serializer(well_potentials);
74  serializer(productivity_index);
75  serializer(implicit_ipr_a);
76  serializer(implicit_ipr_b);
77  serializer(surface_rates);
78  serializer(reservoir_rates);
79  serializer(prev_surface_rates);
80  serializer(trivial_group_target);
81  serializer(segments);
82  serializer(events);
83  serializer(injection_cmode);
84  serializer(production_cmode);
85  serializer(filtrate_conc);
86  serializer(perf_data);
87  serializer(primaryvar);
88  serializer(alq_state);
89  serializer(group_target);
90  serializer(group_target_fallback);
91  serializer(use_group_target_fallback);
92  serializer(was_shut_before_action_applied);
93  }
94 
95  bool operator==(const SingleWellState&) const;
96 
97  std::string name;
98  std::reference_wrapper<const ParallelWellInfo<Scalar>> parallel_info;
99 
100  WellStatus status{WellStatus::OPEN};
101  bool producer;
102  PhaseUsageInfo<IndexTraits> pu;
103  Scalar bhp{0};
104  Scalar thp{0};
105  Scalar pressure_first_connection{0};
106 
107  // thermal related
108  Scalar temperature{0};
109  Scalar energy_rate{0.};
110 
111  Scalar efficiency_scaling_factor{1.0};
112 
113  // filtration injection concentration
114  Scalar filtrate_conc{0};
115 
116  std::array<Scalar,4> phase_mixing_rates{};
117  enum RateIndices {
118  dissolved_gas = 0,
119  dissolved_gas_in_water = 1,
120  vaporized_oil = 2,
121  vaporized_water = 3
122  };
123 
124  struct GroupTarget {
125  std::string group_name;
126  Scalar target_value{0.0};
127  Group::ProductionCMode production_cmode {Group::ProductionCMode::NONE};
128  Group::InjectionCMode injection_cmode {Group::InjectionCMode::NONE};
129  Scalar guiderate_ratio{1.0}; // well to group guide rate ratio for diagnostics
130 
131  bool operator==(const GroupTarget& other) const {
132  return (group_name == other.group_name
133  && target_value == other.target_value
134  && production_cmode == other.production_cmode
135  && injection_cmode == other.injection_cmode
136  && guiderate_ratio == other.guiderate_ratio);
137  }
138 
139  template<class Serializer>
140  void serializeOp(Serializer& serializer) {
141  serializer(group_name);
142  serializer(target_value);
143  serializer(production_cmode);
144  serializer(injection_cmode);
145  serializer(guiderate_ratio);
146  }
147  };
148 
149  std::vector<Scalar> well_potentials;
150  std::vector<Scalar> productivity_index;
151  std::vector<Scalar> implicit_ipr_a;
152  std::vector<Scalar> implicit_ipr_b;
153  std::vector<Scalar> surface_rates;
154  std::vector<Scalar> reservoir_rates;
155  std::vector<Scalar> prev_surface_rates;
156  PerfData<Scalar> perf_data;
157  bool trivial_group_target;
158  std::optional<GroupTarget> group_target;
159  std::optional<GroupTarget> group_target_fallback;
160  bool use_group_target_fallback;
161  SegmentState<Scalar> segments;
162  Events events;
163  WellInjectorCMode injection_cmode{WellInjectorCMode::CMODE_UNDEFINED};
164  WellProducerCMode production_cmode{WellProducerCMode::CMODE_UNDEFINED};
165  std::vector<Scalar> primaryvar;
166  ALQState<Scalar> alq_state;
167  // This is used to indicate whether the well was shut before applying an action
168  // if it was SHUT, even the action set the well to OPEN, the data in the well state
169  // is not well-defined. We do not use it to overwrite the current well state.
170  bool was_shut_before_action_applied {false};
171 
178  void reset_connection_factors(const std::vector<PerforationData<Scalar>>& new_perf_data);
179  void update_producer_targets(const Well& ecl_well, const SummaryState& st);
180  void update_injector_targets(const Well& ecl_well, const SummaryState& st);
186  void update_type_and_targets(const Well& ecl_well, const SummaryState& st);
187  bool updateStatus(WellStatus status);
188  void init_timestep(const SingleWellState& other);
189  void shut();
190  void stop();
191  void open();
192 
193  // The sum_xxx_rates() functions sum over all connection rates of pertinent
194  // types. In the case of distributed wells this involves an MPI
195  // communication.
196  Scalar sum_solvent_rates() const;
197  Scalar sum_polymer_rates() const;
198  Scalar sum_brine_rates() const;
199  Scalar sum_microbial_rates() const;
200  Scalar sum_oxygen_rates() const;
201  Scalar sum_urea_rates() const;
202  Scalar sum_wat_mass_rates() const;
203 
204  Scalar sum_filtrate_rate() const;
205  Scalar sum_filtrate_total() const;
206 
207 private:
208  Scalar sum_connection_rates(const std::vector<Scalar>& connection_rates) const;
209 };
210 
211 }
212 
213 #endif
Definition: SingleWellState.hpp:124
void update_type_and_targets(const Well &ecl_well, const SummaryState &st)
update the type of the well and the targets.
Definition: SingleWellState.cpp:361
void reset_connection_factors(const std::vector< PerforationData< Scalar >> &new_perf_data)
Special purpose method to support dynamically rescaling a well&#39;s CTFs through WELPI.
Definition: SingleWellState.cpp:153
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: PerfData.hpp:33
Definition: MultisegmentWellSegments.hpp:34