RegularizedVanGenuchten.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 (C) 2008-2013 by Andreas Lauser
5  Copyright (C) 2010 by Philipp Nuske
6  Copyright (C) 2010 by Bernd Flemisch
7 
8  This file is part of the Open Porous Media project (OPM).
9 
10  OPM is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  OPM is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with OPM. If not, see <http://www.gnu.org/licenses/>.
22 */
27 #ifndef OPM_REGULARIZED_VAN_GENUCHTEN_HPP
28 #define OPM_REGULARIZED_VAN_GENUCHTEN_HPP
29 
30 #include "VanGenuchten.hpp"
32 
34 
35 #include <algorithm>
36 
37 namespace Opm {
38 
70 template <class TraitsT, class ParamsT = RegularizedVanGenuchtenParams<TraitsT> >
71 class RegularizedVanGenuchten : public TraitsT
72 {
74 
75 public:
76  typedef TraitsT Traits;
77  typedef ParamsT Params;
78 
79  typedef typename Traits::Scalar Scalar;
80 
82  static const int numPhases = Traits::numPhases;
83  static_assert(numPhases == 2,
84  "The regularized van Genuchten capillary pressure law only "
85  "applies to the case of two fluid phases");
86 
89  static const bool implementsTwoPhaseApi = true;
90 
93  static const bool implementsTwoPhaseSatApi = true;
94 
97  static const bool isSaturationDependent = true;
98 
101  static const bool isPressureDependent = false;
102 
105  static const bool isTemperatureDependent = false;
106 
109  static const bool isCompositionDependent = false;
110 
115  template <class Container, class FluidState>
116  static void capillaryPressures(Container &values, const Params &params, const FluidState &fs)
117  {
118  typedef typename std::remove_reference<decltype(values[0])>::type Evaluation;
119 
120  values[Traits::wettingPhaseIdx] = 0.0; // reference phase
121  values[Traits::nonWettingPhaseIdx] = pcnw<FluidState, Evaluation>(params, fs);
122  }
123 
128  template <class Container, class FluidState>
129  static void saturations(Container &values, const Params &params, const FluidState &fs)
130  {
131  typedef typename std::remove_reference<decltype(values[0])>::type Evaluation;
132 
133  values[Traits::wettingPhaseIdx] = Sw<FluidState, Evaluation>(params, fs);
134  values[Traits::nonWettingPhaseIdx] = 1 - values[Traits::wettingPhaseIdx];
135  }
136 
141  template <class Container, class FluidState>
142  static void relativePermeabilities(Container &values, const Params &params, const FluidState &fs)
143  {
144  typedef typename std::remove_reference<decltype(values[0])>::type Evaluation;
145 
146  values[Traits::wettingPhaseIdx] = krw<FluidState, Evaluation>(params, fs);
147  values[Traits::nonWettingPhaseIdx] = krn<FluidState, Evaluation>(params, fs);
148  }
149 
162  template <class FluidState, class Evaluation = typename FluidState::Scalar>
163  static Evaluation pcnw(const Params &params, const FluidState &fs)
164  {
165  typedef MathToolbox<typename FluidState::Scalar> FsToolbox;
166 
167  const auto& Sw = FsToolbox::template toLhs<Evaluation>(fs.saturation(Traits::wettingPhaseIdx));
168  return twoPhaseSatPcnw(params, Sw);
169  }
170 
171  template <class Evaluation>
172  static Evaluation twoPhaseSatPcnw(const Params &params, const Evaluation& Sw)
173  {
174  // retrieve the low and the high threshold saturations for the
175  // unregularized capillary pressure curve from the parameters
176  const Scalar SwThLow = params.pcnwLowSw();
177  const Scalar SwThHigh = params.pcnwHighSw();
178 
179  // make sure that the capillary pressure observes a derivative
180  // != 0 for 'illegal' saturations. This is favourable for the
181  // newton solver (if the derivative is calculated numerically)
182  // in order to get the saturation moving to the right
183  // direction if it temporarily is in an 'illegal' range.
184  if (Sw < SwThLow) {
185  return params.pcnwLow() + params.pcnwSlopeLow()*(Sw - SwThLow);
186  }
187  else if (Sw > SwThHigh)
188  {
189  Scalar yTh = params.pcnwHigh();
190  Scalar m1 = (0.0 - yTh)/(1.0 - SwThHigh)*2;
191 
192  if (Sw < 1.0) {
193  // use spline between threshold Sw and 1.0
194  const Spline<Scalar> &sp = params.pcnwHighSpline();
195 
196  return sp.eval(Sw);
197  }
198  else {
199  // straight line for Sw > 1.0
200  return m1*(Sw - 1.0) + 0.0;
201  }
202  }
203 
204  // if the effective saturation is in an 'reasonable'
205  // range, we use the real van genuchten law...
206  return VanGenuchten::twoPhaseSatPcnw(params, Sw);
207  }
208 
223  template <class FluidState, class Evaluation = typename FluidState::Scalar>
224  static Evaluation Sw(const Params &params, const FluidState &fs)
225  {
226  typedef MathToolbox<typename FluidState::Scalar> FsToolbox;
227 
228  const Evaluation& pC =
229  FsToolbox::template toLhs<Evaluation>(fs.pressure(Traits::nonWettingPhaseIdx))
230  - FsToolbox::template toLhs<Evaluation>(fs.pressure(Traits::wettingPhaseIdx));
231  return twoPhaseSatSw(params, pC);
232  }
233 
234  template <class Evaluation>
235  static Evaluation twoPhaseSatSw(const Params &params, const Evaluation& pC)
236  {
237  // retrieve the low and the high threshold saturations for the
238  // unregularized capillary pressure curve from the parameters
239  const Scalar SwThLow = params.pcnwLowSw();
240  const Scalar SwThHigh = params.pcnwHighSw();
241 
242  // calculate the saturation which corrosponds to the
243  // saturation in the non-regularized verision of van
244  // Genuchten's law
245  if (pC <= 0) {
246  // invert straight line for Sw > 1.0
247  Scalar m1 = params.pcnwSlopeHigh();
248  return pC/m1 + 1.0;
249  }
250 
251  Evaluation Sw = VanGenuchten::twoPhaseSatSw(params, pC);
252 
253  // invert the regularization if necessary
254  if (Sw <= SwThLow) {
255  // invert the low saturation regularization of pC()
256  Scalar pC_SwLow = VanGenuchten::twoPhaseSatPcnw(params, SwThLow);
257  return (pC - pC_SwLow)/params.pcnwSlopeLow() + SwThLow;
258  }
259  else if (SwThHigh < Sw /* && Sw < 1.0*/)
260  {
261  // invert spline between threshold saturation and 1.0
262  const Spline<Scalar>& spline = params.pcnwHighSpline();
263 
264  return spline.template intersectInterval<Evaluation>(/*x0=*/SwThHigh, /*x1=*/1.0,
265  /*a=*/0, /*b=*/0, /*c=*/0, /*d=*/pC);
266  }
267 
268  return Sw;
269  }
270 
275  template <class FluidState, class Evaluation = typename FluidState::Scalar>
276  static Evaluation Sn(const Params &params, const FluidState &fs)
277  { return 1 - Sw<FluidState, Evaluation>(params, fs); }
278 
279  template <class Evaluation>
280  static Evaluation twoPhaseSatSn(const Params &params, const Evaluation& pc)
281  { return 1 - twoPhaseSatSw(params, pc); }
282 
297  template <class FluidState, class Evaluation = typename FluidState::Scalar>
298  static Evaluation krw(const Params &params, const FluidState &fs)
299  {
300  typedef MathToolbox<typename FluidState::Scalar> FsToolbox;
301 
302  const auto& Sw = FsToolbox::template toLhs<Evaluation>(fs.saturation(Traits::wettingPhaseIdx));
303  return twoPhaseSatKrw(params, Sw);
304  }
305 
306  template <class Evaluation>
307  static Evaluation twoPhaseSatKrw(const Params &params, const Evaluation& Sw)
308  {
309  typedef MathToolbox<Evaluation> Toolbox;
310 
311  // regularize
312  if (Sw <= 0)
313  return Toolbox::createConstant(0);
314  else if (Sw >= 1)
315  return Toolbox::createConstant(1);
316 
317  return VanGenuchten::twoPhaseSatKrw(params, Sw);
318  }
319 
334  template <class FluidState, class Evaluation = typename FluidState::Scalar>
335  static Evaluation krn(const Params &params, const FluidState &fs)
336  {
337  typedef MathToolbox<typename FluidState::Scalar> FsToolbox;
338 
339  const Evaluation& Sw =
340  1.0 - FsToolbox::template toLhs<Evaluation>(fs.saturation(Traits::nonWettingPhaseIdx));
341  return twoPhaseSatKrn(params, Sw);
342  }
343 
344  template <class Evaluation>
345  static Evaluation twoPhaseSatKrn(const Params &params, const Evaluation& Sw)
346  {
347  typedef MathToolbox<Evaluation> Toolbox;
348 
349  // regularize
350  if (Sw <= 0)
351  return Toolbox::createConstant(1);
352  else if (Sw >= 1)
353  return Toolbox::createConstant(0);
354 
355  return VanGenuchten::twoPhaseSatKrn(params, Sw);
356  }
357 };
358 
359 } // namespace Opm
360 
361 #endif
Definition: Air_Mesitylene.hpp:31
Implementation of the van Genuchten capillary pressure - saturation relation.
Definition: VanGenuchten.hpp:54
Implementation of the van Genuchten capillary pressure - saturation relation.
Class implementing cubic splines.
Traits::Scalar Scalar
Definition: RegularizedVanGenuchten.hpp:79
ParamsT Params
Definition: RegularizedVanGenuchten.hpp:77
TraitsT Traits
Definition: RegularizedVanGenuchten.hpp:76
static const int numPhases
The number of fluid phases.
Definition: RegularizedVanGenuchten.hpp:82
Parameters that are necessary for the regularization of VanGenuchten "material law".
Implementation of the regularized van Genuchten's capillary pressure / relative permeability <-> satu...
Definition: RegularizedVanGenuchten.hpp:71