opm-common
SatCurveMultiplexer.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  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  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
27 #ifndef OPM_SAT_CURVE_MULTIPLEXER_HPP
28 #define OPM_SAT_CURVE_MULTIPLEXER_HPP
29 
31 
32 #include <opm/common/ErrorMacros.hpp>
33 #include <opm/common/utility/gpuDecorators.hpp>
34 
35 #include <stdexcept>
36 
37 
38 // The static_assert does not compile with gcc 12 and earlier (or nvcc) when placed in the multiplexer calls below.
39 #if (defined(__GNUC__) && (__GNUC__ < 13)) || defined(__CUDACC__)
40  #define STATIC_ASSERT_SATCURVE_MULTIPLEXER_UNLESS_GCC_LT_13 throw std::logic_error("Unhandled SatCurveMultiplexerApproach")
41 #else
42  #define STATIC_ASSERT_SATCURVE_MULTIPLEXER_UNLESS_GCC_LT_13 static_assert(false, "Unhandled SatCurveMultiplexerApproach")
43 #endif
44 
45 namespace Opm {
53 template <class TraitsT, class ParamsT = SatCurveMultiplexerParams<TraitsT> >
54 class SatCurveMultiplexer : public TraitsT
55 {
56 public:
57  using Traits = TraitsT;
58  using Params = ParamsT;
59  using Scalar = typename Traits::Scalar;
60 
63 
65  using Traits::numPhases;
66  static_assert(numPhases == 2,
67  "The Brooks-Corey capillary pressure law only applies "
68  "to the case of two fluid phases");
69 
72  static constexpr bool implementsTwoPhaseApi = true;
73 
76  static constexpr bool implementsTwoPhaseSatApi = true;
77 
80  static constexpr bool isSaturationDependent = true;
81 
84  static constexpr bool isPressureDependent = false;
85 
88  static constexpr bool isTemperatureDependent = false;
89 
92  static constexpr bool isCompositionDependent = false;
93 
94  static_assert(Traits::numPhases == 2,
95  "The number of fluid phases must be two if you want to use "
96  "this material law!");
97 
101  template <class Container, class FluidState>
102  static void capillaryPressures(Container& values, const Params& params, const FluidState& fluidState)
103  {
104  switch (params.approach()) {
105  case SatCurveMultiplexerApproach::LET:
107  params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
108  fluidState);
109  break;
110 
111  case SatCurveMultiplexerApproach::PiecewiseLinear:
113  params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
114  fluidState);
115  break;
116  }
117  }
118 
123  template <class Container, class FluidState>
124  static void saturations(Container& values, const Params& params, const FluidState& fluidState)
125  {
126  switch (params.approach()) {
127  case SatCurveMultiplexerApproach::LET:
129  params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
130  fluidState);
131  break;
132 
133  case SatCurveMultiplexerApproach::PiecewiseLinear:
135  params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
136  fluidState);
137  break;
138  }
139  }
140 
151  template <class Container, class FluidState>
152  static void relativePermeabilities(Container& values, const Params& params, const FluidState& fluidState)
153  {
154  switch (params.approach()) {
155  case SatCurveMultiplexerApproach::LET:
157  params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
158  fluidState);
159  break;
160 
161  case SatCurveMultiplexerApproach::PiecewiseLinear:
163  params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
164  fluidState);
165  break;
166  }
167  }
168 
172  template <class FluidState, class Evaluation = typename FluidState::ValueType>
173  static Evaluation pcnw(const Params& params, const FluidState& fluidState)
174  {
175  switch (params.approach()) {
176  case SatCurveMultiplexerApproach::LET:
177  return LETTwoPhaseLaw::pcnw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
178  fluidState);
179  break;
180 
181  case SatCurveMultiplexerApproach::PiecewiseLinear:
182  return PLTwoPhaseLaw::pcnw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
183  fluidState);
184  break;
185  }
186 
187  return 0.0;
188  }
189 
190  template <class Evaluation, class ...Args>
191  OPM_HOST_DEVICE static Evaluation twoPhaseSatPcnw(const Params& params, const Evaluation& Sw)
192  {
193  if constexpr (FrontIsSatCurveMultiplexerDispatchV<Args...>) {
194  return twoPhaseSatPcnwT<Evaluation, Args...>(params, Sw);
195  }
196 
197 #if OPM_IS_INSIDE_DEVICE_FUNCTION
198  return PLTwoPhaseLaw::twoPhaseSatPcnw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
199  Sw);
200 #else
201  switch (params.approach()) {
202  case SatCurveMultiplexerApproach::LET:
203  return LETTwoPhaseLaw::twoPhaseSatPcnw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
204  Sw);
205  break;
206 
207  case SatCurveMultiplexerApproach::PiecewiseLinear:
208  return PLTwoPhaseLaw::twoPhaseSatPcnw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
209  Sw);
210  break;
211  }
212 
213  return 0.0;
214 #endif
215  }
216 
217  template <class Evaluation, class Head, class ...Args>
218  OPM_HOST_DEVICE static Evaluation twoPhaseSatPcnwT(const Params& params, const Evaluation& Sw)
219  {
220  if constexpr (Head::approach == SatCurveMultiplexerApproach::LET) {
221  return LETTwoPhaseLaw::twoPhaseSatPcnw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
222  Sw);
223  } else if constexpr (Head::approach == SatCurveMultiplexerApproach::PiecewiseLinear) {
224  return PLTwoPhaseLaw::twoPhaseSatPcnw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
225  Sw);
226  } else {
227  STATIC_ASSERT_SATCURVE_MULTIPLEXER_UNLESS_GCC_LT_13;
228  }
229  }
230 
231  template <class Evaluation>
232  static Evaluation twoPhaseSatPcnwInv(const Params&, const Evaluation&)
233  {
234  throw std::logic_error("SatCurveMultiplexer::twoPhaseSatPcnwInv"
235  " not implemented!");
236  }
237 
241  template <class FluidState, class Evaluation = typename FluidState::ValueType>
242  static Evaluation Sw(const Params& params, const FluidState& fluidstate)
243  {
244  switch (params.approach()) {
245  case SatCurveMultiplexerApproach::LET:
246  return LETTwoPhaseLaw::Sw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
247  fluidstate);
248  break;
249 
250  case SatCurveMultiplexerApproach::PiecewiseLinear:
251  return PLTwoPhaseLaw::Sw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
252  fluidstate);
253  break;
254  }
255 
256  return 0.0;
257  }
258 
259  template <class Evaluation>
260  static Evaluation twoPhaseSatSw(const Params&, const Evaluation&)
261  {
262  throw std::logic_error("SatCurveMultiplexer::twoPhaseSatSw"
263  " not implemented!");
264  }
265 
270  template <class FluidState, class Evaluation = typename FluidState::ValueType>
271  static Evaluation Sn(const Params& params, const FluidState& fluidstate)
272  {
273  switch (params.approach()) {
274  case SatCurveMultiplexerApproach::LET:
275  return LETTwoPhaseLaw::Sn(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
276  fluidstate);
277  break;
278 
279  case SatCurveMultiplexerApproach::PiecewiseLinear:
280  return PLTwoPhaseLaw::Sn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
281  fluidstate);
282  break;
283  }
284 
285  return 0.0;
286  }
287 
288  template <class Evaluation>
289  static Evaluation twoPhaseSatSn(const Params& params, const Evaluation& pc)
290  {
291  switch (params.approach()) {
292  case SatCurveMultiplexerApproach::LET:
293  return LETTwoPhaseLaw::twoPhaseSatSn(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
294  pc);
295  break;
296 
297  case SatCurveMultiplexerApproach::PiecewiseLinear:
298  return PLTwoPhaseLaw::twoPhaseSatSn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
299  pc);
300  break;
301  }
302 
303  return 0.0;
304  }
305 
310  template <class FluidState, class Evaluation = typename FluidState::ValueType>
311  static Evaluation krw(const Params& params, const FluidState& fluidstate)
312  {
313  switch (params.approach()) {
314  case SatCurveMultiplexerApproach::LET:
315  return LETTwoPhaseLaw::krw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
316  fluidstate);
317  break;
318 
319  case SatCurveMultiplexerApproach::PiecewiseLinear:
320  return PLTwoPhaseLaw::krw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
321  fluidstate);
322  break;
323  }
324 
325  return 0.0;
326  }
327 
328  template <class Evaluation, class ...Args>
329  OPM_HOST_DEVICE static Evaluation twoPhaseSatKrw(const Params& params, const Evaluation& Sw)
330  {
331  if constexpr (FrontIsSatCurveMultiplexerDispatchV<Args...>) {
332  return twoPhaseSatKrwT<Evaluation, Args...>(params, Sw);
333  }
334 
335 #if OPM_IS_INSIDE_DEVICE_FUNCTION
336  return PLTwoPhaseLaw::twoPhaseSatKrw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
337  Sw);
338 #else
339  switch (params.approach()) {
340  case SatCurveMultiplexerApproach::LET:
341  return LETTwoPhaseLaw::twoPhaseSatKrw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
342  Sw);
343  break;
344 
345  case SatCurveMultiplexerApproach::PiecewiseLinear:
346  return PLTwoPhaseLaw::twoPhaseSatKrw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
347  Sw);
348  break;
349  }
350 
351  return 0.0;
352 #endif
353  }
354 
355  template <class Evaluation, class Head, class ...Args>
356  OPM_HOST_DEVICE static Evaluation twoPhaseSatKrwT(const Params& params, const Evaluation& Sw)
357  {
358  if constexpr (Head::approach == SatCurveMultiplexerApproach::LET) {
359  return LETTwoPhaseLaw::twoPhaseSatKrw(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
360  Sw);
361  } else if constexpr (Head::approach == SatCurveMultiplexerApproach::PiecewiseLinear) {
362  return PLTwoPhaseLaw::twoPhaseSatKrw(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
363  Sw);
364  } else {
365  STATIC_ASSERT_SATCURVE_MULTIPLEXER_UNLESS_GCC_LT_13;
366  }
367  }
368 
369  template <class Evaluation>
370  static Evaluation twoPhaseSatKrwInv(const Params& params, const Evaluation& krw)
371  {
372  switch (params.approach()) {
373  case SatCurveMultiplexerApproach::LET:
374  return LETTwoPhaseLaw::twoPhaseSatKrwInv(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
375  krw);
376  break;
377 
378  case SatCurveMultiplexerApproach::PiecewiseLinear:
379  return PLTwoPhaseLaw::twoPhaseSatKrwInv(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
380  krw);
381  break;
382  }
383 
384  return 0.0;
385  }
386 
391  template <class FluidState, class Evaluation = typename FluidState::ValueType>
392  static Evaluation krn(const Params& params, const FluidState& fluidstate)
393  {
394  switch (params.approach()) {
395  case SatCurveMultiplexerApproach::LET:
396  return LETTwoPhaseLaw::krn(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
397  fluidstate);
398  break;
399 
400  case SatCurveMultiplexerApproach::PiecewiseLinear:
401  return PLTwoPhaseLaw::krn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
402  fluidstate);
403  break;
404  }
405 
406  return 0.0;
407  }
408 
409  template <class Evaluation, class ...Args>
410  OPM_HOST_DEVICE static Evaluation twoPhaseSatKrn(const Params& params, const Evaluation& Sw)
411  {
412  if constexpr (FrontIsSatCurveMultiplexerDispatchV<Args...>) {
413  return twoPhaseSatKrnT<Evaluation, Args...>(params, Sw);
414  }
415 
416 #if OPM_IS_INSIDE_DEVICE_FUNCTION
417  return PLTwoPhaseLaw::twoPhaseSatKrn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
418  Sw);
419 #else
420  switch (params.approach()) {
421  case SatCurveMultiplexerApproach::LET:
422  return LETTwoPhaseLaw::twoPhaseSatKrn(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
423  Sw);
424  break;
425 
426  case SatCurveMultiplexerApproach::PiecewiseLinear:
427  return PLTwoPhaseLaw::twoPhaseSatKrn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
428  Sw);
429  break;
430  }
431 
432  return 0.0;
433 #endif
434  }
435 
436  template <class Evaluation, class Head, class ...Args>
437  OPM_HOST_DEVICE static Evaluation twoPhaseSatKrnT(const Params& params, const Evaluation& Sw)
438  {
439  if constexpr (Head::approach == SatCurveMultiplexerApproach::LET) {
440  return LETTwoPhaseLaw::twoPhaseSatKrn(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
441  Sw);
442  } else if constexpr (Head::approach == SatCurveMultiplexerApproach::PiecewiseLinear) {
443  return PLTwoPhaseLaw::twoPhaseSatKrn(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
444  Sw);
445  } else {
446  STATIC_ASSERT_SATCURVE_MULTIPLEXER_UNLESS_GCC_LT_13;
447  }
448  }
449 
450  template <class Evaluation>
451  static Evaluation twoPhaseSatKrnInv(const Params& params, const Evaluation& krn)
452  {
453  switch (params.approach()) {
454  case SatCurveMultiplexerApproach::LET:
455  return LETTwoPhaseLaw::twoPhaseSatKrnInv(params.template getRealParams<SatCurveMultiplexerApproach::LET>(),
456  krn);
457  break;
458 
459  case SatCurveMultiplexerApproach::PiecewiseLinear:
460  return PLTwoPhaseLaw::twoPhaseSatKrnInv(params.template getRealParams<SatCurveMultiplexerApproach::PiecewiseLinear>(),
461  krn);
462  break;
463  }
464 
465  return 0.0;
466  }
467 };
468 
469 } // namespace Opm
470 
471 #endif // OPM_SAT_CURVE_MULTIPLEXER_HPP
static OPM_HOST_DEVICE void saturations(Container &, const Params &, const FluidState &)
The saturations of the fluid phases starting from their pressure differences.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:115
static constexpr bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition: SatCurveMultiplexer.hpp:72
static Evaluation krw(const Params &params, const FluidState &fluidstate)
The relative permeability for the wetting phase of the medium.
Definition: SatCurveMultiplexer.hpp:311
static constexpr bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition: SatCurveMultiplexer.hpp:80
Specification of the material parameters for the saturation function multiplexer. ...
static Evaluation pcnw(const Params &, const FluidState &)
The capillary pressure-saturation curve.
Definition: TwoPhaseLETCurves.hpp:130
static constexpr bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition...
Definition: SatCurveMultiplexer.hpp:92
static constexpr bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure...
Definition: SatCurveMultiplexer.hpp:84
static OPM_HOST_DEVICE void relativePermeabilities(Container &values, const Params &params, const FluidState &fs)
The relative permeabilities.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:122
static void capillaryPressures(Container &values, const Params &params, const FluidState &fluidState)
The capillary pressure-saturation curves.
Definition: SatCurveMultiplexer.hpp:102
static void saturations(Container &, const Params &, const FluidState &)
Calculate the saturations of the phases starting from their pressure differences. ...
Definition: TwoPhaseLETCurves.hpp:103
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static constexpr bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition: SatCurveMultiplexer.hpp:76
Implementation of a tabulated, piecewise linear capillary pressure law.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:53
static OPM_HOST_DEVICE void capillaryPressures(Container &values, const Params &params, const FluidState &fs)
The capillary pressure-saturation curve.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:101
static void relativePermeabilities(Container &, const Params &, const FluidState &)
The relative permeability-saturation curves.
Definition: TwoPhaseLETCurves.hpp:119
static Evaluation krn(const Params &params, const FluidState &fluidstate)
The relative permeability for the non-wetting phase of the medium.
Definition: SatCurveMultiplexer.hpp:392
static constexpr bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition: SatCurveMultiplexer.hpp:88
static OPM_HOST_DEVICE Evaluation krn(const Params &params, const FluidState &fs)
The relative permeability for the non-wetting phase of the porous medium.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:214
Implementation of the LET curve saturation functions.
Definition: TwoPhaseLETCurves.hpp:49
static OPM_HOST_DEVICE Evaluation krw(const Params &params, const FluidState &fs)
The relative permeability for the wetting phase of the porous medium.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:186
static OPM_HOST_DEVICE Evaluation Sw(const Params &, const FluidState &)
The saturation-capillary pressure curve.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:162
static Evaluation krw(const Params &, const FluidState &)
The relative permeability for the wetting phase of the medium implied by the LET parameterization.
Definition: TwoPhaseLETCurves.hpp:193
static Evaluation krn(const Params &, const FluidState &)
The relative permeability for the non-wetting phase of the medium as implied by the LET parameterizat...
Definition: TwoPhaseLETCurves.hpp:237
static OPM_HOST_DEVICE Evaluation twoPhaseSatPcnw(const Params &params, const Evaluation &Sw)
The saturation-capillary pressure curve.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:148
static Evaluation Sn(const Params &params, const FluidState &fluidstate)
Calculate the non-wetting phase saturations depending on the phase pressures.
Definition: SatCurveMultiplexer.hpp:271
static OPM_HOST_DEVICE Evaluation pcnw(const Params &params, const FluidState &fs)
The capillary pressure-saturation curve.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:135
static void saturations(Container &values, const Params &params, const FluidState &fluidState)
Calculate the saturations of the phases starting from their pressure differences. ...
Definition: SatCurveMultiplexer.hpp:124
static OPM_HOST_DEVICE Evaluation Sn(const Params &params, const FluidState &fs)
Calculate the non-wetting phase saturations depending on the phase pressures.
Definition: PiecewiseLinearTwoPhaseMaterial.hpp:174
static void capillaryPressures(Container &, const Params &, const FluidState &)
The capillary pressure-saturation curves.
Definition: TwoPhaseLETCurves.hpp:93
static Evaluation pcnw(const Params &params, const FluidState &fluidState)
The capillary pressure-saturation curve.
Definition: SatCurveMultiplexer.hpp:173
static void relativePermeabilities(Container &values, const Params &params, const FluidState &fluidState)
The relative permeability-saturation curves.
Definition: SatCurveMultiplexer.hpp:152
static Evaluation Sw(const Params &params, const FluidState &fluidstate)
The saturation-capillary pressure curve.
Definition: SatCurveMultiplexer.hpp:242
Implements a multiplexer class that provides LET curves and piecewise linear saturation functions...
Definition: SatCurveMultiplexer.hpp:54