27#ifndef OPM_ECL_DEFAULT_MATERIAL_HPP
28#define OPM_ECL_DEFAULT_MATERIAL_HPP
54template <
class TraitsT,
55 class GasOilMaterialLawT,
56 class OilWaterMaterialLawT,
57 class ParamsT = EclDefaultMaterialParams<TraitsT,
58 typename GasOilMaterialLawT::Params,
59 typename OilWaterMaterialLawT::Params> >
63 using GasOilMaterialLaw = GasOilMaterialLawT;
64 using OilWaterMaterialLaw = OilWaterMaterialLawT;
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.");
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!");
88 using Traits = TraitsT;
89 using Params = ParamsT;
90 using Scalar =
typename Traits::Scalar;
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;
135 template <
class ContainerT,
class Flu
idState>
137 const Params& params,
138 const FluidState& state)
140 OPM_TIMEFUNCTION_LOCAL();
141 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
142 values[gasPhaseIdx] = pcgn<FluidState, Evaluation>(params, state);
143 values[oilPhaseIdx] = 0;
144 values[waterPhaseIdx] = - pcnw<FluidState, Evaluation>(params, state);
146 Valgrind::CheckDefined(values[gasPhaseIdx]);
147 Valgrind::CheckDefined(values[oilPhaseIdx]);
148 Valgrind::CheckDefined(values[waterPhaseIdx]);
157 static void oilWaterHysteresisParams(Scalar& pcSwMdc,
159 const Params& params)
161 pcSwMdc = params.oilWaterParams().pcSwMdc();
162 krnSwMdc = params.oilWaterParams().krnSwMdc();
164 Valgrind::CheckDefined(pcSwMdc);
165 Valgrind::CheckDefined(krnSwMdc);
174 static void setOilWaterHysteresisParams(
const Scalar& pcSwMdc,
175 const Scalar& krnSwMdc,
178 constexpr const double krwSw = 2.0;
179 params.oilWaterParams().update(pcSwMdc, krwSw, krnSwMdc);
188 static void gasOilHysteresisParams(Scalar& pcSwMdc,
190 const Params& params)
192 const auto Swco = params.Swl();
196 pcSwMdc = std::min(params.gasOilParams().pcSwMdc() + Swco, Scalar{2.0});
197 krnSwMdc = std::min(params.gasOilParams().krnSwMdc() + Swco, Scalar{2.0});
199 Valgrind::CheckDefined(pcSwMdc);
200 Valgrind::CheckDefined(krnSwMdc);
204 static Scalar trappedGasSaturation(
const Params& params)
207 return params.gasOilParams().SnTrapped();
215 static void setGasOilHysteresisParams(
const Scalar& pcSwMdc,
216 const Scalar& krnSwMdc,
220 const auto Swco = params.Swl();
221 constexpr const double krwSw = 2.0;
222 params.gasOilParams().update(pcSwMdc - Swco, krwSw, krnSwMdc - Swco);
234 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
235 static Evaluation
pcgn(
const Params& params,
236 const FluidState& fs)
238 OPM_TIMEFUNCTION_LOCAL();
240 const auto Sw = 1.0 - params.Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
241 return GasOilMaterialLaw::twoPhaseSatPcnw(params.gasOilParams(),
Sw);
253 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
254 static Evaluation
pcnw(
const Params& params,
255 const FluidState& fs)
257 OPM_TIMEFUNCTION_LOCAL();
258 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
259 return OilWaterMaterialLaw::twoPhaseSatPcnw(params.oilWaterParams(),
Sw);
265 template <
class ContainerT,
class Flu
idState>
270 throw std::logic_error(
"Not implemented: saturations()");
276 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
277 static Evaluation
Sg(
const Params& ,
280 throw std::logic_error(
"Not implemented: Sg()");
286 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
287 static Evaluation
Sn(
const Params& ,
290 throw std::logic_error(
"Not implemented: Sn()");
296 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
297 static Evaluation
Sw(
const Params& ,
300 throw std::logic_error(
"Not implemented: Sw()");
318 template <
class ContainerT,
class Flu
idState>
320 const Params& params,
321 const FluidState& fluidState)
323 OPM_TIMEFUNCTION_LOCAL();
324 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
326 values[waterPhaseIdx] = krw<FluidState, Evaluation>(params, fluidState);
327 values[oilPhaseIdx] = krn<FluidState, Evaluation>(params, fluidState);
328 values[gasPhaseIdx] = krg<FluidState, Evaluation>(params, fluidState);
334 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
335 static Evaluation
krg(
const Params& params,
336 const FluidState& fluidState)
338 OPM_TIMEFUNCTION_LOCAL();
340 const Evaluation
Sw = 1.0 - params.Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
341 return GasOilMaterialLaw::twoPhaseSatKrn(params.gasOilParams(),
Sw);
347 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
348 static Evaluation
krw(
const Params& params,
349 const FluidState& fluidState)
351 OPM_TIMEFUNCTION_LOCAL();
352 const Evaluation
Sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
353 return OilWaterMaterialLaw::twoPhaseSatKrw(params.oilWaterParams(),
Sw);
359 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
360 static Evaluation
krn(
const Params& params,
361 const FluidState& fluidState)
363 OPM_TIMEFUNCTION_LOCAL();
364 const Scalar Swco = params.Swl();
366 const Evaluation
Sw =
367 max(Evaluation(Swco),
368 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
370 const Evaluation
Sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
372 const Evaluation Sw_ow =
Sg +
Sw;
373 const Evaluation kro_ow = relpermOilInOilWaterSystem<Evaluation>(params, fluidState);
374 const Evaluation kro_go = relpermOilInOilGasSystem<Evaluation>(params, fluidState);
379 constexpr const Scalar epsilon = 1e-5;
380 if (scalarValue(Sw_ow) - Swco < epsilon) {
381 const Evaluation kro2 = (kro_ow + kro_go)/2;
382 if (scalarValue(Sw_ow) - Swco > epsilon/2) {
383 const Evaluation kro1 = (
Sg*kro_go + (
Sw - Swco)*kro_ow)/(Sw_ow - Swco);
384 const Evaluation alpha = (epsilon - (Sw_ow - Swco))/(epsilon/2);
386 return kro2*alpha + kro1*(1 - alpha);
392 return (
Sg*kro_go + (
Sw - Swco)*kro_ow) / (Sw_ow - Swco);
398 template <
class Evaluation,
class Flu
idState>
400 const FluidState& fluidState)
402 OPM_TIMEFUNCTION_LOCAL();
403 const Evaluation
Sw =
404 max(Evaluation{ params.Swl() },
405 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
407 const Evaluation
Sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
408 const Evaluation So_go = 1.0 - (
Sg +
Sw);
410 return GasOilMaterialLaw::twoPhaseSatKrw(params.gasOilParams(), So_go);
416 template <
class Evaluation,
class Flu
idState>
418 const FluidState& fluidState)
420 OPM_TIMEFUNCTION_LOCAL();
421 const Evaluation
Sw =
422 max(Evaluation{ params.Swl() },
423 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
425 const Evaluation
Sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
426 const Evaluation Sw_ow =
Sg +
Sw;
428 return OilWaterMaterialLaw::twoPhaseSatKrn(params.oilWaterParams(), Sw_ow);
438 template <
class Flu
idState>
441 OPM_TIMEFUNCTION_LOCAL();
442 bool changed =
false;
443 const Scalar Swco = params.Swl();
445 const Scalar
Sw = clampSaturation(fluidState, waterPhaseIdx);
446 const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
447 const Scalar
Sg = clampSaturation(fluidState, gasPhaseIdx);
449 if (params.inconsistentHysteresisUpdate()) {
459 bool oilchanged = params.oilWaterParams().update(
Sw,
463 changed = changed || oilchanged;
465 bool gaschanged = params.gasOilParams().update( 1.0 - Swco -
Sg,
466 1.0 - std::max(Swco,
Sw) -
Sg,
468 changed = changed || gaschanged;
471 const Scalar Sw_ow =
Sg + std::max(Swco,
Sw);
472 const Scalar So_go = 1.0 - Sw_ow;
473 bool oilchanged = params.oilWaterParams().update(
Sw,
476 changed = changed || oilchanged;
477 bool gaschanged = params.gasOilParams().update( 1.0 - Swco -
Sg,
481 changed = changed || gaschanged;
486 template <
class Flu
idState>
487 static Scalar clampSaturation(
const FluidState& fluidState,
const int phaseIndex)
489 OPM_TIMEFUNCTION_LOCAL();
490 const auto sat = scalarValue(fluidState.saturation(phaseIndex));
491 return std::clamp(sat, Scalar{0.0}, Scalar{1.0});
Default implementation for the parameters required by the default three-phase capillary pressure mode...
Some templates to wrap the valgrind client request macros.
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition EclDefaultMaterial.hpp:61
static Evaluation relpermOilInOilWaterSystem(const Params ¶ms, const FluidState &fluidState)
The relative permeability of oil in oil/water system.
Definition EclDefaultMaterial.hpp:417
static Evaluation krg(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the gas phase.
Definition EclDefaultMaterial.hpp:335
static Evaluation pcgn(const Params ¶ms, const FluidState &fs)
Capillary pressure between the gas and the non-wetting liquid (i.e., oil) phase.
Definition EclDefaultMaterial.hpp:235
static constexpr bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition.
Definition EclDefaultMaterial.hpp:119
static constexpr bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition EclDefaultMaterial.hpp:115
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition EclDefaultMaterial.hpp:277
static Evaluation relpermOilInOilGasSystem(const Params ¶ms, const FluidState &fluidState)
The relative permeability of oil in oil/gas system.
Definition EclDefaultMaterial.hpp:399
static constexpr bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition EclDefaultMaterial.hpp:99
static void capillaryPressures(ContainerT &values, const Params ¶ms, const FluidState &state)
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition EclDefaultMaterial.hpp:136
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition EclDefaultMaterial.hpp:266
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition EclDefaultMaterial.hpp:287
static Evaluation krn(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the non-wetting (i.e., oil) phase.
Definition EclDefaultMaterial.hpp:360
static Evaluation pcnw(const Params ¶ms, const FluidState &fs)
Capillary pressure between the non-wetting liquid (i.e., oil) and the wetting liquid (i....
Definition EclDefaultMaterial.hpp:254
static constexpr bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition EclDefaultMaterial.hpp:107
static bool updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclDefaultMaterial.hpp:439
static void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition EclDefaultMaterial.hpp:319
static Evaluation krw(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the wetting phase.
Definition EclDefaultMaterial.hpp:348
static Evaluation Sw(const Params &, const FluidState &)
The saturation of the wetting (i.e., water) phase.
Definition EclDefaultMaterial.hpp:297
static constexpr bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure.
Definition EclDefaultMaterial.hpp:111
static constexpr bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition EclDefaultMaterial.hpp:103
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30