All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
MiscibilityWater.hpp
1 //===========================================================================
2 //
3 // File: MiscibilityWater.hpp
4 //
5 // Created: Tue May 18 10:26:13 2010
6 //
7 // Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
8 // Bjørn Spjelkavik <bsp@sintef.no>
9 //
10 // $Date$
11 //
12 // $Revision$
13 //
14 //===========================================================================
15 /*
16  Copyright 2010 SINTEF ICT, Applied Mathematics.
17 
18  This file is part of the Open Porous Media project (OPM).
19 
20  OPM is free software: you can redistribute it and/or modify
21  it under the terms of the GNU General Public License as published by
22  the Free Software Foundation, either version 3 of the License, or
23  (at your option) any later version.
24 
25  OPM is distributed in the hope that it will be useful,
26  but WITHOUT ANY WARRANTY; without even the implied warranty of
27  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  GNU General Public License for more details.
29 
30  You should have received a copy of the GNU General Public License
31  along with OPM. If not, see <http://www.gnu.org/licenses/>.
32 */
33 
34 #ifndef OPENRS_MISCIBILITYWATER_HEADER
35 #define OPENRS_MISCIBILITYWATER_HEADER
36 
37 #include "MiscibilityProps.hpp"
38 #include <opm/common/ErrorMacros.hpp>
39 
40 #include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
41 #include <opm/parser/eclipse/Deck/DeckRecord.hpp>
42 #include <opm/parser/eclipse/Deck/DeckItem.hpp>
43 
44 // Forward declaration.
45 class PVTW;
46 
47 namespace Opm
48 {
50  {
51  public:
52  typedef std::vector<std::vector<double> > table_t;
53 
54  MiscibilityWater(const DeckKeyword& pvtwKeyword)
55  {
56  const auto& pvtwRecord = pvtwKeyword.getRecord(0);
57  ref_press_ = pvtwRecord.getItem("P_REF").getSIDouble(0);
58  ref_B_ = pvtwRecord.getItem("WATER_VOL_FACTOR").getSIDouble(0);
59  comp_ = pvtwRecord.getItem("WATER_COMPRESSIBILITY").getSIDouble(0);
60  viscosity_ = pvtwRecord.getItem("WATER_VISCOSITY").getSIDouble(0);
61 
62  if (pvtwRecord.getItem("WATER_VISCOSIBILITY").getSIDouble(0) != 0.0) {
63  OPM_THROW(std::runtime_error, "MiscibilityWater does not support 'viscosibility'.");
64  }
65  }
66 
67 
68  MiscibilityWater(double visc)
69  : ref_press_(0.0),
70  ref_B_(1.0),
71  comp_(0.0),
72  viscosity_(visc)
73  {
74  }
75 
76  // WTF?? we initialize a class for water from a keyword for oil?
77  void initFromPvcdo(const DeckKeyword& pvcdoKeyword)
78  {
79  const auto& pvcdoRecord = pvcdoKeyword.getRecord(0);
80  ref_press_ = pvcdoRecord.getItem("P_REF").getSIDouble(0);
81  ref_B_ = pvcdoRecord.getItem("OIL_VOL_FACTOR").getSIDouble(0);
82  comp_ = pvcdoRecord.getItem("OIL_COMPRESSIBILITY").getSIDouble(0);
83  viscosity_ = pvcdoRecord.getItem("OIL_VISCOSITY").getSIDouble(0);
84  if (pvcdoRecord.getItem("OIL_VISCOSIBILITY").getSIDouble(0) != 0.0) {
85  OPM_THROW(std::runtime_error, "MiscibilityWater does not support 'viscosibility'.");
86  }
87  }
88 
89  virtual ~MiscibilityWater()
90  {
91  }
92 
93  virtual double getViscosity(int /*region*/, double /*press*/, const surfvol_t& /*surfvol*/) const
94  {
95  return viscosity_;
96  }
97 
98  virtual void getViscosity(const std::vector<PhaseVec>& pressures,
99  const std::vector<CompVec>&,
100  int,
101  std::vector<double>& output) const
102  {
103  int num = pressures.size();
104  output.clear();
105  output.resize(num, viscosity_);
106  }
107 
108  virtual double B(int /*region*/, double press, const surfvol_t& /*surfvol*/) const
109  {
110  if (comp_) {
111  // Computing a polynomial approximation to the exponential.
112  double x = comp_*(press - ref_press_);
113  return ref_B_/(1.0 + x + 0.5*x*x);
114  } else {
115  return ref_B_;
116  }
117  }
118 
119  virtual void B(const std::vector<PhaseVec>& pressures,
120  const std::vector<CompVec>&,
121  int phase,
122  std::vector<double>& output) const
123  {
124  int num = pressures.size();
125  if (comp_) {
126  output.resize(num);
127 #pragma omp parallel for
128  for (int i = 0; i < num; ++i) {
129  // Computing a polynomial approximation to the exponential.
130  double x = comp_*(pressures[i][phase] - ref_press_);
131  output[i] = ref_B_/(1.0 + x + 0.5*x*x);
132  }
133  } else {
134  output.clear();
135  output.resize(num, ref_B_);
136  }
137  }
138 
139  virtual double dBdp(int region, double press, const surfvol_t& surfvol) const
140  {
141  if (comp_) {
142  return -comp_*B(region, press, surfvol);
143  } else {
144  return 0.0;
145  }
146  }
147 
148  virtual void dBdp(const std::vector<PhaseVec>& pressures,
149  const std::vector<CompVec>& surfvols,
150  int phase,
151  std::vector<double>& output_B,
152  std::vector<double>& output_dBdp) const
153  {
154  B(pressures, surfvols, phase, output_B);
155  int num = pressures.size();
156  if (comp_) {
157  output_dBdp.resize(num);
158 #pragma omp parallel for
159  for (int i = 0; i < num; ++i) {
160  output_dBdp[i] = -comp_*output_B[i];
161  }
162  } else {
163  output_dBdp.clear();
164  output_dBdp.resize(num, 0.0);
165  }
166  }
167 
168  virtual double R(int /*region*/, double /*press*/, const surfvol_t& /*surfvol*/) const
169  {
170  return 0.0;
171  }
172 
173  virtual void R(const std::vector<PhaseVec>& pressures,
174  const std::vector<CompVec>&,
175  int,
176  std::vector<double>& output) const
177  {
178  int num = pressures.size();
179  output.clear();
180  output.resize(num, 0.0);
181  }
182 
183  virtual double dRdp(int /*region*/, double /*press*/, const surfvol_t& /*surfvol*/) const
184  {
185  return 0.0;
186  }
187 
188  virtual void dRdp(const std::vector<PhaseVec>& pressures,
189  const std::vector<CompVec>&,
190  int,
191  std::vector<double>& output_R,
192  std::vector<double>& output_dRdp) const
193  {
194  int num = pressures.size();
195  output_R.clear();
196  output_R.resize(num, 0.0);
197  output_dRdp.clear();
198  output_dRdp.resize(num, 0.0);
199  }
200 
201  private:
202  double ref_press_;
203  double ref_B_;
204  double comp_;
205  double viscosity_;
206  };
207 
208 }
209 
210 #endif // OPENRS_MISCIBILITYWATER_HEADER
Definition: MiscibilityWater.hpp:49
Definition: MiscibilityProps.hpp:46