27#ifndef OPM_ECL_STONE2_MATERIAL_HPP
28#define OPM_ECL_STONE2_MATERIAL_HPP
54template <
class TraitsT,
55 class GasOilMaterialLawT,
56 class OilWaterMaterialLawT,
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 FluidState,
class ...Args>
137 const Params& params,
138 const FluidState& state)
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);
156 static void oilWaterHysteresisParams(Scalar& soMax,
159 const Params& params)
161 if constexpr (Traits::enableHysteresis) {
162 soMax = 1.0 - params.oilWaterParams().krnSwMdc();
163 swMax = params.oilWaterParams().krwSwMdc();
164 swMin = params.oilWaterParams().pcSwMdc();
178 static void setOilWaterHysteresisParams(
const Scalar& soMax,
183 if constexpr (Traits::enableHysteresis) {
184 params.oilWaterParams().update(swMin, swMax, 1.0 - soMax);
196 static void gasOilHysteresisParams(Scalar& sgMax,
199 const Params& params)
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);
219 static void setGasOilHysteresisParams(
const Scalar& sgMax,
224 if constexpr (Traits::enableHysteresis) {
225 const auto Swco = params.Swl();
226 params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
230 static Scalar trappedGasSaturation(
const Params& params,
bool maximumTrapping)
232 const auto Swco = params.Swl();
233 return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
236 static Scalar trappedOilSaturation(
const Params& params,
bool maximumTrapping)
238 return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
241 static Scalar trappedWaterSaturation(
const Params& params)
243 return params.oilWaterParams().SwTrapped();
245 static Scalar strandedGasSaturation(
const Params& params, Scalar
Sg, Scalar Kg)
247 const auto Swco = params.Swl();
248 return params.gasOilParams().SnStranded(
Sg, Kg) - Swco;
260 template <
class FluidState,
class Evaluation,
class ...Args>
261 static Evaluation
pcgn(
const Params& params,
262 const FluidState& fs)
265 const auto Sw = 1.0 - params.
Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
266 return GasOilMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.
gasOilParams(),
Sw);
278 template <
class FluidState,
class Evaluation,
class ...Args>
279 static Evaluation
pcnw(
const Params& params,
280 const FluidState& fs)
282 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
285 const auto result = OilWaterMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.
oilWaterParams(),
Sw);
294 template <
class ContainerT,
class Flu
idState>
299 throw std::logic_error(
"Not implemented: saturations()");
305 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
306 static Evaluation
Sg(
const Params& ,
309 throw std::logic_error(
"Not implemented: Sg()");
315 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
316 static Evaluation
Sn(
const Params& ,
319 throw std::logic_error(
"Not implemented: Sn()");
325 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
326 static Evaluation
Sw(
const Params& ,
329 throw std::logic_error(
"Not implemented: Sw()");
347 template <
class ContainerT,
class FluidState,
class ...Args>
349 const Params& params,
350 const FluidState& fluidState)
352 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
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);
362 template <
class FluidState,
class Evaluation,
class ...Args>
363 static Evaluation
krg(
const Params& params,
364 const FluidState& fluidState)
367 const Evaluation sw = 1 - params.
Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
368 return GasOilMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.
gasOilParams(), sw);
374 template <
class FluidState,
class Evaluation,
class ...Args>
375 static Evaluation
krw(
const Params& params,
376 const FluidState& fluidState)
378 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
379 return OilWaterMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.
oilWaterParams(), sw);
385 template <
class FluidState,
class Evaluation,
class ...Args>
386 static Evaluation
krn(
const Params& params,
387 const FluidState& fluidState)
389 const Scalar Swco = params.
Swl();
391 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
392 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
394 const Scalar krocw = OilWaterMaterialLaw::template twoPhaseSatKrn<Scalar, Args...>(params.
oilWaterParams(), Swco);
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);
400 return max(krocw * ((krow / krocw + Krw) * (krog / krocw + Krg) - Krw - Krg), Evaluation{0});
407 template <
class Evaluation,
class FluidState,
class ...Args>
409 const FluidState& fluidState)
411 const Scalar Swco = params.
Swl();
412 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
414 return GasOilMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.
gasOilParams(), 1 - Swco - sg);
421 template <
class Evaluation,
class FluidState,
class ...Args>
423 const FluidState& fluidState)
425 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
427 return OilWaterMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.
oilWaterParams(), sw);
437 template <
class Flu
idState>
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);
449 return owChanged || gochanged;
455 template <
class Flu
idState>
456 static Scalar clampSaturation(
const FluidState& fluidState,
const int phaseIndex)
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});
Default implementation for the parameters required by the three-phase capillary pressure/relperm Ston...
Some templates to wrap the valgrind client request macros.
OPM_HOST_DEVICE bool CheckDefined(const T &value)
Make valgrind complain if any of the memory occupied by an object is undefined.
Definition Valgrind.hpp:76
Default implementation for the parameters required by the three-phase capillary pressure/relperm Ston...
Definition EclStone2MaterialParams.hpp:46
Scalar Swl() const
Return the saturation of "connate" water.
Definition EclStone2MaterialParams.hpp:115
const GasOilParams & gasOilParams() const
The parameter object for the gas-oil twophase law.
Definition EclStone2MaterialParams.hpp:65
const OilWaterParams & oilWaterParams() const
The parameter object for the oil-water twophase law.
Definition EclStone2MaterialParams.hpp:83
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition EclStone2Material.hpp:61
static constexpr bool isPressureDependent
Definition EclStone2Material.hpp:111
static Evaluation Sw(const Params &, const FluidState &)
Definition EclStone2Material.hpp:326
static void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition EclStone2Material.hpp:348
static Evaluation krw(const Params ¶ms, const FluidState &fluidState)
Definition EclStone2Material.hpp:375
static bool updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclStone2Material.hpp:438
static Evaluation krg(const Params ¶ms, const FluidState &fluidState)
Definition EclStone2Material.hpp:363
static constexpr bool implementsTwoPhaseSatApi
Definition EclStone2Material.hpp:103
static constexpr bool isTemperatureDependent
Definition EclStone2Material.hpp:115
static constexpr bool isCompositionDependent
Definition EclStone2Material.hpp:119
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition EclStone2Material.hpp:306
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition EclStone2Material.hpp:295
static constexpr bool implementsTwoPhaseApi
Definition EclStone2Material.hpp:99
static Evaluation relpermOilInOilGasSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclStone2Material.hpp:408
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition EclStone2Material.hpp:316
static Evaluation pcgn(const Params ¶ms, const FluidState &fs)
Definition EclStone2Material.hpp:261
static Evaluation relpermOilInOilWaterSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclStone2Material.hpp:422
static constexpr bool isSaturationDependent
Definition EclStone2Material.hpp:107
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 EclStone2Material.hpp:136
static Evaluation pcnw(const Params ¶ms, const FluidState &fs)
Definition EclStone2Material.hpp:279
static Evaluation krn(const Params ¶ms, const FluidState &fluidState)
Definition EclStone2Material.hpp:386
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30