All Classes Namespaces Files Functions Variables Typedefs Enumerator Pages
SimFIBODetails.hpp
1 /*
2  Copyright 2013 SINTEF ICT, Applied Mathematics.
3  Copyright 2014-2016 IRIS AS
4  Copyright 2015 Andreas Lauser
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 */
21 #ifndef OPM_SIM_FIBO_DETAILS_HPP
22 #define OPM_SIM_FIBO_DETAILS_HPP
23 
24 #include <utility>
25 #include <algorithm>
26 #include <locale>
27 #include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
28 #include <opm/core/utility/initHydroCarbonState.hpp>
29 #include <opm/core/well_controls.h>
30 #include <opm/core/wells/DynamicListEconLimited.hpp>
31 
32 namespace Opm
33 {
34  namespace SimFIBODetails {
35  typedef std::unordered_map<std::string, const Well* > WellMap;
36 
37  inline WellMap
38  mapWells(const std::vector< const Well* >& wells)
39  {
40  WellMap wmap;
41 
42  for (std::vector< const Well* >::const_iterator
43  w = wells.begin(), e = wells.end();
44  w != e; ++w)
45  {
46  wmap.insert(std::make_pair((*w)->name(), *w));
47  }
48 
49  return wmap;
50  }
51 
52  inline int
53  resv_control(const WellControls* ctrl)
54  {
55  int i, n = well_controls_get_num(ctrl);
56 
57  bool match = false;
58  for (i = 0; (! match) && (i < n); ++i) {
59  match = well_controls_iget_type(ctrl, i) == RESERVOIR_RATE;
60  }
61 
62  if (! match) { i = 0; }
63 
64  return i - 1; // -1 if no match, undo final "++" otherwise
65  }
66 
67  inline bool
68  is_resv(const Wells& wells,
69  const int w)
70  {
71  return (0 <= resv_control(wells.ctrls[w]));
72  }
73 
74  inline bool
75  is_resv(const WellMap& wmap,
76  const std::string& name,
77  const std::size_t step)
78  {
79  bool match = false;
80 
81  WellMap::const_iterator i = wmap.find(name);
82 
83  if (i != wmap.end()) {
84  const Well* wp = i->second;
85 
86  match = (wp->isProducer(step) &&
87  wp->getProductionProperties(step)
88  .hasProductionControl(WellProducer::RESV))
89  || (wp->isInjector(step) &&
90  wp->getInjectionProperties(step)
91  .hasInjectionControl(WellInjector::RESV));
92  }
93 
94  return match;
95  }
96 
97  inline std::vector<int>
98  resvWells(const Wells* wells,
99  const std::size_t step,
100  const WellMap& wmap)
101  {
102  std::vector<int> resv_wells;
103  if( wells )
104  {
105  for (int w = 0, nw = wells->number_of_wells; w < nw; ++w) {
106  if (is_resv(*wells, w) ||
107  ((wells->name[w] != 0) &&
108  is_resv(wmap, wells->name[w], step)))
109  {
110  resv_wells.push_back(w);
111  }
112  }
113  }
114 
115  return resv_wells;
116  }
117 
118  inline void
119  historyRates(const PhaseUsage& pu,
120  const WellProductionProperties& p,
121  std::vector<double>& rates)
122  {
123  assert (! p.predictionMode);
124  assert (rates.size() ==
125  std::vector<double>::size_type(pu.num_phases));
126 
127  if (pu.phase_used[ BlackoilPhases::Aqua ]) {
128  const std::vector<double>::size_type
129  i = pu.phase_pos[ BlackoilPhases::Aqua ];
130 
131  rates[i] = p.WaterRate;
132  }
133 
134  if (pu.phase_used[ BlackoilPhases::Liquid ]) {
135  const std::vector<double>::size_type
136  i = pu.phase_pos[ BlackoilPhases::Liquid ];
137 
138  rates[i] = p.OilRate;
139  }
140 
141  if (pu.phase_used[ BlackoilPhases::Vapour ]) {
142  const std::vector<double>::size_type
143  i = pu.phase_pos[ BlackoilPhases::Vapour ];
144 
145  rates[i] = p.GasRate;
146  }
147  }
148  } // namespace SimFIBODetails
149 } // namespace Opm
150 
151 #endif // OPM_SIM_FIBO_DETAILS_HPP