opm-common
ViscosityModels.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright 2022 NORCE.
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 2 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  Consult the COPYING file in the top-level source directory of this
22  module for the precise wording of the license and the list of
23  copyright holders.
24 */
30 #ifndef OPM_VISCOSITY_MODELS_HPP
31 #define OPM_VISCOSITY_MODELS_HPP
32 
34 
35 #include <array>
36 #include <cmath>
37 
38 namespace Opm
39 {
40 
41 template <class Scalar, class FluidSystem>
43 {
44 
45 public:
46 
47  // Standard coefficients of the Lorentz-Bray-Clark viscosity correlation.
48  // (Note the fourth coefficient: typo in 1964-paper has -0.40758.)
49  static constexpr std::array<Scalar, 5> defaultLBCCoefficients()
50  {
51  return {Scalar(0.10230),
52  Scalar(0.023364),
53  Scalar(0.058533),
54  Scalar(-0.040758),
55  Scalar(0.0093324)};
56  }
57 
58  // Standard LBC model. (Lohrenz, Bray & Clark: "Calculating Viscosities of Reservoir
59  // fluids from Their Compositions", JPT 16.10 (1964).
60  template <class FluidState, class Params, class LhsEval = typename FluidState::ValueType>
61  static LhsEval LBC(const FluidState& fluidState,
62  const Params& /*paramCache*/,
63  unsigned phaseIdx)
64  {
65  const Scalar MPa_atm = 0.101325;
66  const Scalar R = Opm::Constants<Scalar>::R;
67  const auto& T = Opm::decay<LhsEval>(fluidState.temperature(phaseIdx));
68  const auto& P = Opm::decay<LhsEval>(fluidState.pressure(phaseIdx));
69  const auto& Z = Opm::decay<LhsEval>(fluidState.compressFactor(phaseIdx));
70 
71  LhsEval sumVolume = 0.0;
72  for (unsigned compIdx = 0; compIdx < FluidSystem::numComponents; ++compIdx) {
73  const auto& x = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, compIdx));
74  const Scalar v_c = FluidSystem::criticalVolume(compIdx) / 1000; // converting to m3/mol from m3/kmol
75  sumVolume += x*v_c;
76  }
77 
78  LhsEval rho_pc = 1.0 / sumVolume;
79  LhsEval V = (R * T * Z)/P;
80  LhsEval rho = 1.0 / V;
81  LhsEval rho_r = rho / rho_pc;
82 
83  LhsEval xsum_T_c = 0.0; // mixture pseudocritical temperature
84  LhsEval xsum_Mm = 0.0; // mixture molar mass
85  LhsEval xsum_p_ca = 0.0; // mixture pseudocritical pressure
86  for (unsigned compIdx = 0; compIdx < FluidSystem::numComponents; ++compIdx) {
87  const Scalar& p_c = FluidSystem::criticalPressure(compIdx) / 1e6; // converting to Mpa from pascal
88  const Scalar& T_c = FluidSystem::criticalTemperature(compIdx);
89  const Scalar Mm = FluidSystem::molarMass(compIdx) * 1000; // converting to kg/kmol from kg/mol;
90  const auto& x = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, compIdx));
91  Scalar p_ca = p_c / MPa_atm;
92  xsum_T_c += x * T_c;
93  xsum_Mm += x * Mm;
94  xsum_p_ca += x * p_ca;
95  }
96  LhsEval zeta_tot = Opm::pow(xsum_T_c / (Opm::pow(xsum_Mm,3.0) * Opm::pow(xsum_p_ca,4.0)),1./6);
97 
98  LhsEval my0 = 0.0;
99  LhsEval sumxrM = 0.0;
100  for (unsigned compIdx = 0; compIdx < FluidSystem::numComponents; ++compIdx) {
101  const Scalar& p_c = FluidSystem::criticalPressure(compIdx) / 1e6; // converting to Mpa from pa;
102  const Scalar& T_c = FluidSystem::criticalTemperature(compIdx);
103  const Scalar Mm = FluidSystem::molarMass(compIdx) * 1000; // converting to kg/kmol from kg/mol;
104  const auto& x = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, compIdx));
105  Scalar p_ca = p_c / MPa_atm;
106  Scalar zeta = std::pow(T_c / (std::pow(Mm,3.0) * std::pow(p_ca,4.0)),1./6);
107  LhsEval T_r = T/T_c;
108  LhsEval xrM = x * std::pow(Mm,0.5);
109  LhsEval mys = 0.0;
110  if (T_r <= 1.5) {
111  mys = 34.0e-5*Opm::pow(T_r,0.94)/zeta;
112  } else {
113  mys = 17.78e-5*Opm::pow(4.58*T_r - 1.67, 0.625)/zeta;
114  }
115  my0 += xrM*mys;
116  sumxrM += xrM;
117  }
118  my0 /= sumxrM;
119 
120  // using reference to avoid copying the coefficients for every evaluation.
121  const auto& LBC = []() -> decltype(auto) {
122  if constexpr (requires { FluidSystem::lbcCoefficients(); }) {
123  return FluidSystem::lbcCoefficients();
124  } else {
125  static constexpr std::array<Scalar, 5> default_lbc = defaultLBCCoefficients();
126  return (default_lbc);
127  }
128  }();
129 
130  LhsEval sumLBC = 0.0;
131  for (int i = 0; i < 5; ++i) {
132  sumLBC += Opm::pow(rho_r,i)*LBC[i];
133  }
134 
135  const LhsEval mu = (my0 + (Opm::pow(sumLBC,4.0) - 1e-4)/zeta_tot)/1e3; // mPas-> Pas
136 
137  if (mu <= 0.) {
138  throw NumericalProblem("LBC correlation produced a non-positive viscosity; "
139  "check the LBC coefficients");
140  }
141 
142  return mu;
143  }
144 
145  // Improved LBC model for CO2 rich mixtures. (Lansangan, Taylor, Smith & Kovarik - 1993)
146  template <class FluidState, class Params, class LhsEval = typename FluidState::ValueType>
147  static LhsEval LBCco2rich(const FluidState& fluidState,
148  const Params& /*paramCache*/,
149  unsigned phaseIdx)
150  {
151  const Scalar MPa_atm = 0.101325;
152  const auto& T = Opm::decay<LhsEval>(fluidState.temperature(phaseIdx));
153  const auto& rho = Opm::decay<LhsEval>(fluidState.density(phaseIdx));
154 
155  LhsEval sumMm = 0.0;
156  LhsEval sumVolume = 0.0;
157  for (unsigned compIdx = 0; compIdx < FluidSystem::numComponents; ++compIdx) {
158  const Scalar Mm = FluidSystem::molarMass(compIdx) * 1000; // in kg/kmol;
159  const auto& x = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, compIdx));
160  const Scalar v_c = FluidSystem::criticalVolume(compIdx); // in m3/kmol
161  sumMm += x*Mm;
162  sumVolume += x*v_c;
163  }
164 
165  LhsEval rho_pc = sumMm/sumVolume; // mixture pseudocritical density
166  LhsEval rho_r = rho/rho_pc;
167 
168  LhsEval xxT_p = 0.0; // x*x*T_c/p_c
169  LhsEval xxT2_p = 0.0; // x*x*T^2_c/p_c
170  for (unsigned i_compIdx = 0; i_compIdx < FluidSystem::numComponents; ++i_compIdx) {
171  const Scalar& T_c_i = FluidSystem::criticalTemperature(i_compIdx);
172  const Scalar& p_c_i = FluidSystem::criticalPressure(i_compIdx)/1e6; // in Mpa;
173  const auto& x_i = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, i_compIdx));
174  for (unsigned j_compIdx = 0; j_compIdx < FluidSystem::numComponents; ++j_compIdx) {
175  const Scalar& T_c_j = FluidSystem::criticalTemperature(j_compIdx);
176  const Scalar& p_c_j = FluidSystem::criticalPressure(j_compIdx)/1e6; // in Mpa;
177  const auto& x_j = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, j_compIdx));
178 
179  const Scalar T_c_ij = std::sqrt(T_c_i*T_c_j);
180  const Scalar p_c_ij = 8.0*T_c_ij / Opm::pow(Opm::pow(T_c_i/p_c_i,1.0/3)+Opm::pow(T_c_j/p_c_j,1.0/3),3);
181 
182  xxT_p += x_i*x_j*T_c_ij/p_c_ij;
183  xxT2_p += x_i*x_j*T_c_ij*T_c_ij/p_c_ij;
184  }
185  }
186 
187  const LhsEval T_pc = xxT2_p/xxT_p; // mixture pseudocritical temperature
188  const LhsEval p_pc = T_pc/xxT_p; // mixture pseudocritical pressure
189 
190  LhsEval p_pca = p_pc / MPa_atm;
191  LhsEval zeta_tot = Opm::pow(T_pc / (Opm::pow(sumMm,3.0) * Opm::pow(p_pca,4.0)),1./6);
192 
193  LhsEval my0 = 0.0;
194  LhsEval sumxrM = 0.0;
195  for (unsigned compIdx = 0; compIdx < FluidSystem::numComponents; ++compIdx) {
196  const Scalar& p_c = FluidSystem::criticalPressure(compIdx)/1e6; // in Mpa;
197  const Scalar& T_c = FluidSystem::criticalTemperature(compIdx);
198  const Scalar Mm = FluidSystem::molarMass(compIdx) * 1000; // in kg/kmol;
199  const auto& x = Opm::decay<LhsEval>(fluidState.moleFraction(phaseIdx, compIdx));
200  Scalar p_ca = p_c / MPa_atm;
201  Scalar zeta = std::pow(T_c / (std::pow(Mm,3.0) * std::pow(p_ca,4.0)),1./6);
202  LhsEval T_r = T/T_c;
203  LhsEval xrM = x * std::pow(Mm,0.5);
204  LhsEval mys = 0.0;
205  if (T_r <= 1.5) {
206  mys = 34.0e-5*Opm::pow(T_r,0.94)/zeta;
207  } else {
208  mys = 17.78e-5*Opm::pow(4.58*T_r - 1.67, 0.625)/zeta;
209  }
210  my0 += xrM*mys;
211  sumxrM += xrM;
212  }
213  my0 /= sumxrM;
214 
215  // using reference to avoid copying the coefficients for every evaluation.
216  const auto& LBC = []() -> decltype(auto) {
217  if constexpr (requires { FluidSystem::lbcCoefficients(); }) {
218  return FluidSystem::lbcCoefficients();
219  } else {
220  static constexpr std::array<Scalar, 5> default_lbc = defaultLBCCoefficients();
221  return (default_lbc);
222  }
223  }();
224 
225  LhsEval sumLBC = 0.0;
226  for (int i = 0; i < 5; ++i) {
227  sumLBC += Opm::pow(rho_r,i)*LBC[i];
228  }
229 
230  return (my0 + (Opm::pow(sumLBC,4.0) - 1e-4)/zeta_tot - 1.8366e-8*Opm::pow(rho_r,13.992))/1e3; // mPas-> Pas
231  }
232 
233 };
234 
235 } // namespace Opm
236 
237 #endif // OPM_VISCOSITY_MODELS_HPP
Definition: Exceptions.hpp:39
Definition: ViscosityModels.hpp:42
Provides the OPM specific exception classes.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Constants.hpp:41