opm-simulators
CompWellState_impl.hpp
1 /*
2  Copyright 2024, SINTEF Digital
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 namespace Opm {
21 
22 template <typename FluidSystem>
23 CompWellState<FluidSystem>::
24 CompWellState(const CompositionalConfig& comp_config)
25  : comp_config_(comp_config)
26 {
27 }
28 
29 
30 template <typename FluidSystem>
31 void CompWellState<FluidSystem>::
32 init(const std::vector<Well>& wells_ecl,
33  const std::vector<Scalar>& cell_pressures,
34  const Scalar temperature,
35  const std::vector<std::vector<Scalar>>& cell_mole_fractions,
36  const std::vector<std::vector<CompConnectionData> >& well_connection_data,
37  const SummaryState& summary_state,
38  const CompWellState* prev_well_state)
39 {
40  this->base_init(wells_ecl, cell_pressures, temperature, cell_mole_fractions, well_connection_data, summary_state);
41 
42  if (!prev_well_state) {
43  return;
44  }
45 
46  for (const auto& well_name : this->wells_.wells()) {
47  if (prev_well_state->wells_.has(well_name)) {
48  this->wells_[well_name].copyRuntimeStateFrom(prev_well_state->wells_[well_name]);
49  }
50  }
51 }
52 
53 template <typename FluidSystem>
54 void CompWellState<FluidSystem>::
55 base_init(const std::vector<Well>& wells_ecl,
56  const std::vector<Scalar>& cell_pressures,
57  const Scalar temperature,
58  const std::vector<std::vector<Scalar>>& cell_mole_fractions,
59  const std::vector<std::vector<CompConnectionData>>& well_connection_data,
60  const SummaryState& summary_state)
61 {
62  this->wells_.clear();
63 
64  const auto num_wells = wells_ecl.size();
65 
66  for (auto w = 0*num_wells; w < num_wells; ++w) {
67  const Well& well = wells_ecl[w];
68  const auto& conn_data = well_connection_data[w];
69  initSingleWell(well, cell_pressures, temperature, cell_mole_fractions, conn_data, summary_state);
70  }
71 
72 }
73 
74 template <typename FluidSystem>
75 void CompWellState<FluidSystem>::
76 initSingleWell(const Well& well,
77  const std::vector<Scalar>& cell_pressures,
78  const Scalar tempearture,
79  const std::vector<std::vector<Scalar>>& cell_mole_fractions,
80  const std::vector<CompConnectionData>& conn_data,
81  const SummaryState& summary_state)
82 {
83  if (well.isInjector()) {
84  initSingleInjector(well, cell_pressures, tempearture, conn_data, summary_state);
85  } else {
86  initSingleProducer(well, cell_pressures, tempearture, cell_mole_fractions, conn_data, summary_state);
87  }
88 
89 }
90 
91 template <typename FluidSystem>
92 void CompWellState<FluidSystem>::
93 initSingleInjector(const Well& well,
94  const std::vector<Scalar>& /* cell_pressures */,
95  const Scalar temperature,
96  const std::vector<CompConnectionData>& conn_data,
97  const SummaryState& summary_state)
98 {
99  auto& ws = this->wells_.add(well.name(),
100  SingleWellState(well.name(),
101  this->comp_config_,
102  temperature,
103  conn_data,
104  false) );
105  ws.update_injector_targets(well, summary_state);
106 }
107 
108 template <typename FluidSystem>
109 void CompWellState<FluidSystem>::
110 initSingleProducer(const Well& well,
111  const std::vector<Scalar>& /* cell_pressures */,
112  const Scalar temperature,
113  const std::vector<std::vector<Scalar>>& cell_mole_fractions,
114  const std::vector<CompConnectionData>& conn_data,
115  const SummaryState& summary_state)
116 {
117  auto& ws = this->wells_.add(well.name(),
118  SingleWellState(well.name(),
119  this->comp_config_,
120  temperature,
121  conn_data,
122  true) );
123  ws.update_producer_targets(well, cell_mole_fractions, summary_state);
124 }
125 
126 template <typename FluidSystem>
127 const typename CompWellState<FluidSystem>::SingleWellState&
128 CompWellState<FluidSystem>::
129 operator[](const std::string& well_name) const
130 {
131  return this->wells_[well_name];
132 }
133 
134 template <typename FluidSystem>
135 typename CompWellState<FluidSystem>::SingleWellState&
136 CompWellState<FluidSystem>::
137 operator[](const std::string& well_name)
138 {
139  return this->wells_[well_name];
140 }
141 
142 template <typename FluidSystem>
143 data::Wells
144 CompWellState<FluidSystem>::
145 report() const
146 {
147  if (this->wells_.empty()) {
148  return {};
149  }
150  using rt = data::Rates::opt;
151 
152  data::Wells res;
153  for (std::size_t w = 0; w < this->wells_.size(); ++w) {
154  const auto& ws = this->wells_[w];
155  if (ws.status == Well::Status::SHUT) {
156  continue;
157  }
158  auto& well = res[ws.name];
159  well.bhp = ws.bhp;
160  well.temperature = ws.temperature;
161  const auto& surface_rates = ws.surface_phase_rates;
162  if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
163  well.rates.set(rt::wat, surface_rates[FluidSystem::waterPhaseIdx]);
164  }
165  if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
166  well.rates.set(rt::oil, surface_rates[FluidSystem::oilPhaseIdx]);
167  }
168  if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
169  well.rates.set(rt::gas, surface_rates[FluidSystem::gasPhaseIdx]);
170  }
171  }
172  return res;
173 }
174 
175 } // end of namespace Opm
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45