opm-common
EclStone2Material.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 2 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_ECL_STONE2_MATERIAL_HPP
28 #define OPM_ECL_STONE2_MATERIAL_HPP
29 
31 
34 
35 #include <algorithm>
36 #include <stdexcept>
37 #include <type_traits>
38 
39 namespace Opm {
40 
54 template <class TraitsT,
55  class GasOilMaterialLawT,
56  class OilWaterMaterialLawT,
57  class ParamsT = EclStone2MaterialParams<TraitsT,
58  typename GasOilMaterialLawT::Params,
59  typename OilWaterMaterialLawT::Params> >
60 class EclStone2Material : public TraitsT
61 {
62 public:
63  using GasOilMaterialLaw = GasOilMaterialLawT;
64  using OilWaterMaterialLaw = OilWaterMaterialLawT;
65 
66  // some safety checks
67  static_assert(TraitsT::numPhases == 3,
68  "The number of phases considered by this capillary pressure "
69  "law is always three!");
70  static_assert(GasOilMaterialLaw::numPhases == 2,
71  "The number of phases considered by the gas-oil capillary "
72  "pressure law must be two!");
73  static_assert(OilWaterMaterialLaw::numPhases == 2,
74  "The number of phases considered by the oil-water capillary "
75  "pressure law must be two!");
76  static_assert(std::is_same<typename GasOilMaterialLaw::Scalar,
77  typename OilWaterMaterialLaw::Scalar>::value,
78  "The two two-phase capillary pressure laws must use the same "
79  "type of floating point values.");
80 
81  static_assert(GasOilMaterialLaw::implementsTwoPhaseSatApi,
82  "The gas-oil material law must implement the two-phase saturation "
83  "only API to for the default Ecl capillary pressure law!");
84  static_assert(OilWaterMaterialLaw::implementsTwoPhaseSatApi,
85  "The oil-water material law must implement the two-phase saturation "
86  "only API to for the default Ecl capillary pressure law!");
87 
88  using Traits = TraitsT;
89  using Params = ParamsT;
90  using Scalar = typename Traits::Scalar;
91 
92  static constexpr int numPhases = 3;
93  static constexpr int waterPhaseIdx = Traits::wettingPhaseIdx;
94  static constexpr int oilPhaseIdx = Traits::nonWettingPhaseIdx;
95  static constexpr int gasPhaseIdx = Traits::gasPhaseIdx;
96 
99  static constexpr bool implementsTwoPhaseApi = false;
100 
103  static constexpr bool implementsTwoPhaseSatApi = false;
104 
107  static constexpr bool isSaturationDependent = true;
108 
111  static constexpr bool isPressureDependent = false;
112 
115  static constexpr bool isTemperatureDependent = false;
116 
119  static constexpr bool isCompositionDependent = false;
120 
135  template <class ContainerT, class FluidState, class ...Args>
136  static void capillaryPressures(ContainerT& values,
137  const Params& params,
138  const FluidState& state)
139  {
140  using Evaluation = typename std::remove_reference<decltype(values[0])>::type;
141  values[gasPhaseIdx] = pcgn<FluidState, Evaluation, Args...>(params, state);
142  values[oilPhaseIdx] = 0;
143  values[waterPhaseIdx] = - pcnw<FluidState, Evaluation, Args...>(params, state);
144  Valgrind::CheckDefined(values[gasPhaseIdx]);
145  Valgrind::CheckDefined(values[oilPhaseIdx]);
146  Valgrind::CheckDefined(values[waterPhaseIdx]);
147  }
148 
149  /*
150  * Hysteresis parameters for oil-water
151  * @see EclHysteresisTwoPhaseLawParams::soMax(...)
152  * @see EclHysteresisTwoPhaseLawParams::swMax(...)
153  * @see EclHysteresisTwoPhaseLawParams::swMin(...)
154  * \param params Parameters
155  */
156  static void oilWaterHysteresisParams(Scalar& soMax,
157  Scalar& swMax,
158  Scalar& swMin,
159  const Params& params)
160  {
161  if constexpr (Traits::enableHysteresis) {
162  soMax = 1.0 - params.oilWaterParams().krnSwMdc();
163  swMax = params.oilWaterParams().krwSwMdc();
164  swMin = params.oilWaterParams().pcSwMdc();
165  Valgrind::CheckDefined(soMax);
166  Valgrind::CheckDefined(swMax);
167  Valgrind::CheckDefined(swMin);
168  }
169  }
170 
171  /*
172  * Hysteresis parameters for oil-water
173  * @see EclHysteresisTwoPhaseLawParams::soMax(...)
174  * @see EclHysteresisTwoPhaseLawParams::swMax(...)
175  * @see EclHysteresisTwoPhaseLawParams::swMin(...)
176  * \param params Parameters
177  */
178  static void setOilWaterHysteresisParams(const Scalar& soMax,
179  const Scalar& swMax,
180  const Scalar& swMin,
181  Params& params)
182  {
183  if constexpr (Traits::enableHysteresis) {
184  params.oilWaterParams().update(swMin, swMax, 1.0 - soMax);
185  }
186  }
187 
188 
189  /*
190  * Hysteresis parameters for gas-oil
191  * @see EclHysteresisTwoPhaseLawParams::sgMax(...)
192  * @see EclHysteresisTwoPhaseLawParams::shMax(...)
193  * @see EclHysteresisTwoPhaseLawParams::soMin(...)
194  * \param params Parameters
195  */
196  static void gasOilHysteresisParams(Scalar& sgMax,
197  Scalar& shMax,
198  Scalar& soMin,
199  const Params& params)
200  {
201  if constexpr (Traits::enableHysteresis) {
202  const auto Swco = params.Swl();
203  sgMax = 1.0 - params.gasOilParams().krnSwMdc() - Swco;
204  shMax = params.gasOilParams().krwSwMdc();
205  soMin = params.gasOilParams().pcSwMdc();
206  Valgrind::CheckDefined(sgMax);
207  Valgrind::CheckDefined(shMax);
208  Valgrind::CheckDefined(soMin);
209  }
210  }
211 
212  /*
213  * Hysteresis parameters for gas-oil
214  * @see EclHysteresisTwoPhaseLawParams::sgMax(...)
215  * @see EclHysteresisTwoPhaseLawParams::shMax(...)
216  * @see EclHysteresisTwoPhaseLawParams::soMin(...)
217  * \param params Parameters
218  */
219  static void setGasOilHysteresisParams(const Scalar& sgMax,
220  const Scalar& shMax,
221  const Scalar& soMin,
222  Params& params)
223  {
224  if constexpr (Traits::enableHysteresis) {
225  const auto Swco = params.Swl();
226  params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
227  }
228  }
229 
230  static Scalar trappedGasSaturation(const Params& params, bool maximumTrapping)
231  {
232  const auto Swco = params.Swl();
233  return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
234  }
235 
236  static Scalar trappedOilSaturation(const Params& params, bool maximumTrapping)
237  {
238  return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
239  }
240 
241  static Scalar trappedWaterSaturation(const Params& params)
242  {
243  return params.oilWaterParams().SwTrapped();
244  }
245  static Scalar strandedGasSaturation(const Params& params, Scalar Sg, Scalar Kg)
246  {
247  const auto Swco = params.Swl();
248  return params.gasOilParams().SnStranded(Sg, Kg) - Swco;
249  }
250 
260  template <class FluidState, class Evaluation, class ...Args>
261  static Evaluation pcgn(const Params& params,
262  const FluidState& fs)
263  {
264  // Maximum attainable oil saturation is 1-SWL.
265  const auto Sw = 1.0 - params.Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
266  return GasOilMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.gasOilParams(), Sw);
267  }
268 
278  template <class FluidState, class Evaluation, class ...Args>
279  static Evaluation pcnw(const Params& params,
280  const FluidState& fs)
281  {
282  const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
283  Valgrind::CheckDefined(Sw);
284 
285  const auto result = OilWaterMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.oilWaterParams(), Sw);
286  Valgrind::CheckDefined(result);
287 
288  return result;
289  }
290 
294  template <class ContainerT, class FluidState>
295  static void saturations(ContainerT& /*values */,
296  const Params& /* params */,
297  const FluidState& /* fluidState */)
298  {
299  throw std::logic_error("Not implemented: saturations()");
300  }
301 
305  template <class FluidState, class Evaluation = typename FluidState::ValueType>
306  static Evaluation Sg(const Params& /* params */,
307  const FluidState& /* fluidState */)
308  {
309  throw std::logic_error("Not implemented: Sg()");
310  }
311 
315  template <class FluidState, class Evaluation = typename FluidState::ValueType>
316  static Evaluation Sn(const Params& /* params */,
317  const FluidState& /* fluidState */)
318  {
319  throw std::logic_error("Not implemented: Sn()");
320  }
321 
325  template <class FluidState, class Evaluation = typename FluidState::ValueType>
326  static Evaluation Sw(const Params& /* params */,
327  const FluidState& /* fluidState */)
328  {
329  throw std::logic_error("Not implemented: Sw()");
330  }
331 
347  template <class ContainerT, class FluidState, class ...Args>
348  static void relativePermeabilities(ContainerT& values,
349  const Params& params,
350  const FluidState& fluidState)
351  {
352  using Evaluation = typename std::remove_reference<decltype(values[0])>::type;
353 
354  values[waterPhaseIdx] = krw<FluidState, Evaluation, Args...>(params, fluidState);
355  values[oilPhaseIdx] = krn<FluidState, Evaluation, Args...>(params, fluidState);
356  values[gasPhaseIdx] = krg<FluidState, Evaluation, Args...>(params, fluidState);
357  }
358 
362  template <class FluidState, class Evaluation, class ...Args>
363  static Evaluation krg(const Params& params,
364  const FluidState& fluidState)
365  {
366  // Maximum attainable oil saturation is 1-SWL.
367  const Evaluation sw = 1 - params.Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
368  return GasOilMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.gasOilParams(), sw);
369  }
370 
374  template <class FluidState, class Evaluation, class ...Args>
375  static Evaluation krw(const Params& params,
376  const FluidState& fluidState)
377  {
378  const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
379  return OilWaterMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.oilWaterParams(), sw);
380  }
381 
385  template <class FluidState, class Evaluation, class ...Args>
386  static Evaluation krn(const Params& params,
387  const FluidState& fluidState)
388  {
389  const Scalar Swco = params.Swl();
390 
391  const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
392  const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
393 
394  const Scalar krocw = OilWaterMaterialLaw::template twoPhaseSatKrn<Scalar, Args...>(params.oilWaterParams(), Swco);
395  const Evaluation krow = relpermOilInOilWaterSystem<Evaluation, FluidState, Args...>(params, fluidState);
396  const Evaluation Krw = OilWaterMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.oilWaterParams(), sw);
397  const Evaluation Krg = GasOilMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.gasOilParams(), 1 - Swco - sg);
398  const Evaluation krog = relpermOilInOilGasSystem<Evaluation, FluidState, Args...>(params, fluidState);
399 
400  return max(krocw * ((krow / krocw + Krw) * (krog / krocw + Krg) - Krw - Krg), Evaluation{0});
401  }
402 
403 
407  template <class Evaluation, class FluidState, class ...Args>
408  static Evaluation relpermOilInOilGasSystem(const Params& params,
409  const FluidState& fluidState)
410  {
411  const Scalar Swco = params.Swl();
412  const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
413 
414  return GasOilMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.gasOilParams(), 1 - Swco - sg);
415  }
416 
417 
421  template <class Evaluation, class FluidState, class ...Args>
422  static Evaluation relpermOilInOilWaterSystem(const Params& params,
423  const FluidState& fluidState)
424  {
425  const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
426 
427  return OilWaterMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.oilWaterParams(), sw);
428  }
429 
437  template <class FluidState>
438  static bool updateHysteresis(Params& params, const FluidState& fluidState)
439  {
440  if constexpr (Traits::enableHysteresis) {
441  const Scalar Swco = params.Swl();
442  const Scalar sw = clampSaturation(fluidState, waterPhaseIdx);
443  const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
444  const Scalar sg = clampSaturation(fluidState, gasPhaseIdx);
445  bool owChanged = params.oilWaterParams().update(/*pcSw=*/sw, /*krwSw=*/sw, /*krnSw=*/1 - So);
446  bool gochanged = params.gasOilParams().update(/*pcSw=*/So,
447  /*krwSw=*/So,
448  /*krnSw=*/1.0 - Swco - sg);
449  return owChanged || gochanged;
450  } else {
451  return false;
452  }
453  }
454 
455  template <class FluidState>
456  static Scalar clampSaturation(const FluidState& fluidState, const int phaseIndex)
457  {
458  OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
459  const auto sat = scalarValue(fluidState.saturation(phaseIndex));
460  return std::clamp(sat, Scalar{0.0}, Scalar{1.0});
461  }
462 };
463 
464 } // namespace Opm
465 
466 #endif
static Evaluation pcnw(const Params &params, const FluidState &fs)
Capillary pressure between the non-wetting liquid (i.e., oil) and the wetting liquid (i...
Definition: EclStone2Material.hpp:279
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
static Evaluation pcgn(const Params &params, const FluidState &fs)
Capillary pressure between the gas and the non-wetting liquid (i.e., oil) phase.
Definition: EclStone2Material.hpp:261
static Evaluation relpermOilInOilWaterSystem(const Params &params, const FluidState &fluidState)
The relative permeability of oil in oil/water system.
Definition: EclStone2Material.hpp:422
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition: EclStone2Material.hpp:295
Default implementation for the parameters required by the three-phase capillary pressure/relperm Ston...
static void relativePermeabilities(ContainerT &values, const Params &params, const FluidState &fluidState)
The relative permeability of all phases.
Definition: EclStone2Material.hpp:348
static Evaluation relpermOilInOilGasSystem(const Params &params, const FluidState &fluidState)
The relative permeability of oil in oil/gas system.
Definition: EclStone2Material.hpp:408
static Evaluation krw(const Params &params, const FluidState &fluidState)
The relative permeability of the wetting phase.
Definition: EclStone2Material.hpp:375
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition: EclStone2Material.hpp:60
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition: EclStone2Material.hpp:306
static Evaluation krg(const Params &params, const FluidState &fluidState)
The relative permeability of the gas phase.
Definition: EclStone2Material.hpp:363
static Evaluation krn(const Params &params, const FluidState &fluidState)
The relative permeability of the non-wetting (i.e., oil) phase.
Definition: EclStone2Material.hpp:386
static bool updateHysteresis(Params &params, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition: EclStone2Material.hpp:438
static constexpr bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition: EclStone2Material.hpp:103
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition: EclStone2Material.hpp:316
static constexpr bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition...
Definition: EclStone2Material.hpp:119
Some templates to wrap the valgrind client request macros.
static constexpr bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition: EclStone2Material.hpp:99
static constexpr bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition: EclStone2Material.hpp:115
static constexpr bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure...
Definition: EclStone2Material.hpp:111
static void capillaryPressures(ContainerT &values, const Params &params, const FluidState &state)
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition: EclStone2Material.hpp:136
static constexpr bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition: EclStone2Material.hpp:107
static Evaluation Sw(const Params &, const FluidState &)
The saturation of the wetting (i.e., water) phase.
Definition: EclStone2Material.hpp:326