ThermalGasPvtWrapper.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2015 Andreas Lauser
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 #ifndef OPM_THERMAL_GAS_PVT_WRAPPER_HPP
20 #define OPM_THERMAL_GAS_PVT_WRAPPER_HPP
21 
23 #include <opm/common/ErrorMacros.hpp>
24 
25 #include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
26 
27 #include <vector>
28 
29 namespace Opm
30 {
34  {
35  public:
37  {}
38 
39 
42  void initFromDeck(std::shared_ptr<const PvtInterface> isothermalPvt,
43  Opm::DeckConstPtr deck,
44  Opm::EclipseStateConstPtr eclipseState)
45  {
46  isothermalPvt_ = isothermalPvt;
47  auto tables = eclipseState->getTableManager();
48  int numRegions;
49  if (deck->hasKeyword("PVTG"))
50  numRegions = tables->getPvtgTables().size();
51  else if (deck->hasKeyword("PVDG"))
52  numRegions = tables->getPvdgTables().size();
53  else
54  OPM_THROW(std::runtime_error, "Gas phase was not initialized using a known way");
55 
56  // viscosity
57  if (deck->hasKeyword("GASVISCT")) {
58  gasvisctTables_ = &tables->getGasvisctTables();
59  assert(int(gasvisctTables_->size()) == numRegions);
60  static_cast<void>(numRegions); //Silence compiler warning
61 
62  gasCompIdx_ = deck->getKeyword("GCOMPIDX")->getRecord(0)->getItem("GAS_COMPONENT_INDEX")->getInt(0) - 1;
63  gasvisctColumnName_ = "Viscosity"+std::to_string(static_cast<long long>(gasCompIdx_));
64  }
65 
66  // density
67  if (deck->hasKeyword("TREF")) {
68  tref_ = deck->getKeyword("TREF")->getRecord(0)->getItem("TEMPERATURE")->getSIDouble(0);
69  }
70  }
71 
72  virtual void mu(const int n,
73  const int* pvtRegionIdx,
74  const double* p,
75  const double* T,
76  const double* z,
77  double* output_mu) const
78  {
79  if (gasvisctTables_)
80  // TODO: temperature dependence for viscosity depending on z
81  OPM_THROW(std::runtime_error,
82  "temperature dependent viscosity as a function of z "
83  "is not yet implemented!");
84 
85  // compute the isothermal viscosity
86  isothermalPvt_->mu(n, pvtRegionIdx, p, T, z, output_mu);
87  }
88 
89  virtual void mu(const int n,
90  const int* pvtRegionIdx,
91  const double* p,
92  const double* T,
93  const double* r,
94  double* output_mu,
95  double* output_dmudp,
96  double* output_dmudr) const
97  {
98  if (gasvisctTables_ != 0) {
99  for (int i = 0; i < n; ++i) {
100  // temperature dependence of the gas phase. this assumes that the gas
101  // component index has been set properly, and it also looses the
102  // pressure dependence of gas. (This does not make much sense, but it
103  // seems to be what the documentation for the GASVISCT keyword in the
104  // RM says.)
105 
106 
107  int regionIdx = getPvtRegionIndex_(pvtRegionIdx, i);
108  double muGasvisct;
109  {
110  const GasvisctTable& gasvisctTable = gasvisctTables_->getTable<GasvisctTable>(regionIdx);
111  muGasvisct = gasvisctTable.evaluate(gasvisctColumnName_, T[i]);
112  }
113 
114  output_mu[i] = muGasvisct;
115  output_dmudp[i] = 0.0;
116  output_dmudr[i] = 0.0;
117 
118  // TODO (?): derivative of gas viscosity w.r.t. temperature.
119  }
120  }
121  else {
122  // compute the isothermal viscosity and its derivatives
123  isothermalPvt_->mu(n, pvtRegionIdx, p, T, r, output_mu, output_dmudp, output_dmudr);
124  }
125  }
126 
127  virtual void mu(const int n,
128  const int* pvtRegionIdx,
129  const double* p,
130  const double* T,
131  const double* r,
132  const PhasePresence* cond,
133  double* output_mu,
134  double* output_dmudp,
135  double* output_dmudr) const
136  {
137  if (gasvisctTables_ != 0) {
138  for (int i = 0; i < n; ++i) {
139  // temperature dependence of the gas phase. this assumes that the gas
140  // component index has been set properly, and it also looses the
141  // pressure dependence of gas. (This does not make much sense, but it
142  // seems to be what the documentation for the GASVISCT keyword in the
143  // RM says.)
144  int regionIdx = getPvtRegionIndex_(pvtRegionIdx, i);
145  double muGasvisct;
146  {
147  const GasvisctTable& gasvisctTable = gasvisctTables_->getTable<GasvisctTable>(regionIdx);
148  muGasvisct = gasvisctTable.evaluate(gasvisctColumnName_, T[i]);
149  }
150 
151  output_mu[i] = muGasvisct;
152  output_dmudp[i] = 0.0;
153  output_dmudr[i] = 0.0;
154 
155  // TODO (?): derivative of gas viscosity w.r.t. temperature.
156  }
157  }
158  else {
159  // compute the isothermal viscosity and its derivatives
160  isothermalPvt_->mu(n, pvtRegionIdx, p, T, r, cond, output_mu, output_dmudp, output_dmudr);
161  }
162  }
163 
164  virtual void B(const int n,
165  const int* pvtRegionIdx,
166  const double* p,
167  const double* T,
168  const double* z,
169  double* output_B) const
170  {
171  // isothermal case
172  isothermalPvt_->B(n, pvtRegionIdx, p, T, z, output_B);
173 
174  if (tref_ > 0.0) {
175  // the Eclipse TD/RM do not explicitly specify the relation of the gas
176  // density and the temperature, but equation (69.49) (for Eclipse 2011.1)
177  // implies that the temperature dependence of the gas phase is rho(T, p) =
178  // rho(tref_, p)/tref_*T ...
179  for (int i = 0; i < n; ++i) {
180  double alpha = tref_/T[i];
181  output_B[i] *= alpha;
182  }
183  }
184  }
185 
186  virtual void dBdp(const int n,
187  const int* pvtRegionIdx,
188  const double* p,
189  const double* T,
190  const double* z,
191  double* output_B,
192  double* output_dBdp) const
193  {
194  isothermalPvt_->dBdp(n, pvtRegionIdx, p, T, z, output_B, output_dBdp);
195 
196  if (tref_ > 0.0) {
197  // the Eclipse TD/RM do not explicitly specify the relation of the gas
198  // density and the temperature, but equation (69.49) (for Eclipse 2011.1)
199  // implies that the temperature dependence of the gas phase is rho(T, p) =
200  // rho(tref_, p)/tref_*T ...
201  for (int i = 0; i < n; ++i) {
202  double alpha = tref_/T[i];
203  output_B[i] *= alpha;
204  output_dBdp[i] *= alpha;
205  }
206  }
207  }
208 
209  virtual void b(const int n,
210  const int* pvtRegionIdx,
211  const double* p,
212  const double* T,
213  const double* r,
214  double* output_b,
215  double* output_dbdp,
216  double* output_dbdr) const
217  {
218  isothermalPvt_->b(n, pvtRegionIdx, p, T, r, output_b, output_dbdp, output_dbdr);
219 
220  if (tref_ > 0.0) {
221  // the Eclipse TD/RM do not explicitly specify the relation of the gas
222  // density and the temperature, but equation (69.49) (for Eclipse 2011.1)
223  // implies that the temperature dependence of the gas phase is rho(T, p) =
224  // rho(tref_, p)/tref_*T ...
225  for (int i = 0; i < n; ++i) {
226  double alpha = T[i]/tref_;
227  output_b[i] *= alpha;
228  output_dbdp[i] *= alpha;
229  output_dbdr[i] *= alpha;
230  }
231  }
232  }
233 
234  virtual void b(const int n,
235  const int* pvtRegionIdx,
236  const double* p,
237  const double* T,
238  const double* r,
239  const PhasePresence* cond,
240  double* output_b,
241  double* output_dbdp,
242  double* output_dbdr) const
243  {
244  isothermalPvt_->b(n, pvtRegionIdx, p, T, r, cond, output_b, output_dbdp, output_dbdr);
245 
246  if (tref_ > 0.0) {
247  // the Eclipse TD/RM do not explicitly specify the relation of the gas
248  // density and the temperature, but equation (69.49) (for Eclipse 2011.1)
249  // implies that the temperature dependence of the gas phase is rho(T, p) =
250  // rho(tref_, p)/tref_*T ...
251  for (int i = 0; i < n; ++i) {
252  double alpha = T[i]/tref_;
253  output_b[i] *= alpha;
254  output_dbdp[i] *= alpha;
255  output_dbdr[i] *= alpha;
256  }
257  }
258  }
259 
260  virtual void rsSat(const int n,
261  const int* pvtRegionIdx,
262  const double* p,
263  double* output_rsSat,
264  double* output_drsSatdp) const
265  {
266  isothermalPvt_->rsSat(n, pvtRegionIdx, p, output_rsSat, output_drsSatdp);
267  }
268 
269  virtual void rvSat(const int n,
270  const int* pvtRegionIdx,
271  const double* p,
272  double* output_rvSat,
273  double* output_drvSatdp) const
274  {
275  isothermalPvt_->rvSat(n, pvtRegionIdx, p, output_rvSat, output_drvSatdp);
276  }
277 
278  virtual void R(const int n,
279  const int* pvtRegionIdx,
280  const double* p,
281  const double* z,
282  double* output_R) const
283  {
284  isothermalPvt_->R(n, pvtRegionIdx, p, z, output_R);
285  }
286 
287  virtual void dRdp(const int n,
288  const int* pvtRegionIdx,
289  const double* p,
290  const double* z,
291  double* output_R,
292  double* output_dRdp) const
293  {
294  isothermalPvt_->dRdp(n, pvtRegionIdx, p, z, output_R, output_dRdp);
295  }
296 
297  private:
298  int getPvtRegionIndex_(const int* pvtRegionIdx, int cellIdx) const
299  {
300  if (!pvtRegionIdx)
301  return 0;
302  return pvtRegionIdx[cellIdx];
303  }
304 
305  // the PVT propertied for the isothermal case
306  std::shared_ptr<const PvtInterface> isothermalPvt_;
307 
308  // The PVT properties needed for temperature dependence of the viscosity. We need
309  // to store one value per PVT region.
310  const TableContainer* gasvisctTables_;
311  std::string gasvisctColumnName_;
312  int gasCompIdx_;
313 
314  // The PVT properties needed for temperature dependence of the density.
315  double tref_;
316  };
317 
318 }
319 
320 #endif
321 
Definition: BlackoilPhases.hpp:48
virtual void b(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *r, const PhasePresence *cond, double *output_b, double *output_dbdp, double *output_dbdr) const
Definition: ThermalGasPvtWrapper.hpp:234
virtual void dBdp(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *z, double *output_B, double *output_dBdp) const
Formation volume factor and p-derivative as functions of p and z.
Definition: ThermalGasPvtWrapper.hpp:186
Definition: AnisotropicEikonal.hpp:43
virtual void mu(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *r, double *output_mu, double *output_dmudp, double *output_dmudr) const
Definition: ThermalGasPvtWrapper.hpp:89
virtual void b(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *r, double *output_b, double *output_dbdp, double *output_dbdr) const
Definition: ThermalGasPvtWrapper.hpp:209
virtual void dRdp(const int n, const int *pvtRegionIdx, const double *p, const double *z, double *output_R, double *output_dRdp) const
Solution factor and p-derivative as functions of p and z.
Definition: ThermalGasPvtWrapper.hpp:287
void initFromDeck(std::shared_ptr< const PvtInterface > isothermalPvt, Opm::DeckConstPtr deck, Opm::EclipseStateConstPtr eclipseState)
Definition: ThermalGasPvtWrapper.hpp:42
virtual void rvSat(const int n, const int *pvtRegionIdx, const double *p, double *output_rvSat, double *output_drvSatdp) const
Vapor oil/gas ratio and its derivatives at saturated conditions as a function of p.
Definition: ThermalGasPvtWrapper.hpp:269
virtual void mu(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *z, double *output_mu) const
Viscosity as a function of p, T and z.
Definition: ThermalGasPvtWrapper.hpp:72
virtual void R(const int n, const int *pvtRegionIdx, const double *p, const double *z, double *output_R) const
Solution factor as a function of p and z.
Definition: ThermalGasPvtWrapper.hpp:278
virtual void rsSat(const int n, const int *pvtRegionIdx, const double *p, double *output_rsSat, double *output_drsSatdp) const
Solution gas/oil ratio and its derivatives at saturated conditions as a function of p...
Definition: ThermalGasPvtWrapper.hpp:260
Definition: PvtInterface.hpp:30
ThermalGasPvtWrapper()
Definition: ThermalGasPvtWrapper.hpp:36
Definition: ThermalGasPvtWrapper.hpp:33
virtual void mu(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *r, const PhasePresence *cond, double *output_mu, double *output_dmudp, double *output_dmudr) const
Definition: ThermalGasPvtWrapper.hpp:127
virtual void B(const int n, const int *pvtRegionIdx, const double *p, const double *T, const double *z, double *output_B) const
Formation volume factor as a function of p, T and z.
Definition: ThermalGasPvtWrapper.hpp:164