27#ifndef OPM_ECL_STONE1_MATERIAL_HPP
28#define OPM_ECL_STONE1_MATERIAL_HPP
32#include <opm/common/TimingMacros.hpp>
56template <
class TraitsT,
57 class GasOilMaterialLawT,
58 class OilWaterMaterialLawT,
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);
195 static void gasOilHysteresisParams(Scalar& sgMax,
198 const Params& params)
200 if constexpr (Traits::enableHysteresis) {
201 const auto Swco = params.Swl();
202 sgMax = 1.0 - params.gasOilParams().krnSwMdc() - Swco;
203 shMax = params.gasOilParams().krwSwMdc();
204 soMin = params.gasOilParams().pcSwMdc();
205 Valgrind::CheckDefined(sgMax);
206 Valgrind::CheckDefined(shMax);
207 Valgrind::CheckDefined(soMin);
218 static void setGasOilHysteresisParams(
const Scalar& sgMax,
223 if constexpr (Traits::enableHysteresis) {
224 const auto Swco = params.Swl();
225 params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
229 static Scalar trappedGasSaturation(
const Params& params,
bool maximumTrapping)
231 const auto Swco = params.Swl();
232 return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
235 static Scalar trappedOilSaturation(
const Params& params,
bool maximumTrapping)
237 return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
240 static Scalar trappedWaterSaturation(
const Params& params)
242 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;
259 template <
class FluidState,
class Evaluation,
class ...Args>
260 static Evaluation
pcgn(
const Params& params,
261 const FluidState& fs)
264 const auto Sw = 1.0 - params.
Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
265 return GasOilMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.
gasOilParams(),
Sw);
277 template <
class FluidState,
class Evaluation,
class ...Args>
278 static Evaluation
pcnw(
const Params& params,
279 const FluidState& fs)
281 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
284 const auto result = OilWaterMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.
oilWaterParams(),
Sw);
293 template <
class ContainerT,
class Flu
idState>
298 throw std::logic_error(
"Not implemented: saturations()");
304 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
305 static Evaluation
Sg(
const Params& ,
308 throw std::logic_error(
"Not implemented: Sg()");
314 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
315 static Evaluation
Sn(
const Params& ,
318 throw std::logic_error(
"Not implemented: Sn()");
324 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
325 static Evaluation
Sw(
const Params& ,
328 throw std::logic_error(
"Not implemented: Sw()");
346 template <
class ContainerT,
class FluidState,
class ...Args>
348 const Params& params,
349 const FluidState& fluidState)
351 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
353 values[waterPhaseIdx] =
krw<FluidState, Evaluation, Args...>(params, fluidState);
354 values[oilPhaseIdx] =
krn<FluidState, Evaluation, Args...>(params, fluidState);
355 values[gasPhaseIdx] =
krg<FluidState, Evaluation, Args...>(params, fluidState);
361 template <
class FluidState,
class Evaluation,
class ...Args>
362 static Evaluation
krg(
const Params& params,
363 const FluidState& fluidState)
366 const Evaluation sw = 1 - params.
Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
367 return GasOilMaterialLaw::twoPhaseSatKrn(params.
gasOilParams(), sw);
373 template <
class FluidState,
class Evaluation,
class ...Args>
374 static Evaluation
krw(
const Params& params,
375 const FluidState& fluidState)
377 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
378 return OilWaterMaterialLaw::twoPhaseSatKrw(params.
oilWaterParams(), sw);
384 template <
class FluidState,
class Evaluation,
class ...Args>
385 static Evaluation
krn(
const Params& params,
386 const FluidState& fluidState)
391 const Scalar Swco = params.
Swl();
394 const Scalar krocw = params.
krocw();
396 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
397 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
409 const Evaluation SSw = (sw - Swco) / (1.0 - Swco);
410 const Evaluation SSg = sg / (1.0 - Swco);
411 const Evaluation SSo = 1.0 - SSw - SSg;
413 if (SSw >= 1.0 || SSg >= 1.0)
416 beta = pow( SSo/((1 - SSw)*(1 - SSg)), params.
eta());
419 return max(0.0, min(1.0, beta*kro_ow*kro_go/krocw));
425 template <
class Evaluation,
class FluidState,
class ...Args>
427 const FluidState& fluidState)
429 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
430 return GasOilMaterialLaw::twoPhaseSatKrw(params.
gasOilParams(), 1 - sg - params.
Swl());
436 template <
class Evaluation,
class FluidState,
class ...Args>
438 const FluidState& fluidState)
440 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
441 return OilWaterMaterialLaw::twoPhaseSatKrn(params.
oilWaterParams(), sw);
451 template <
class Flu
idState>
454 if constexpr (Traits::enableHysteresis) {
455 const Scalar Swco = params.
Swl();
456 const Scalar sw = clampSaturation(fluidState, waterPhaseIdx);
457 const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
458 const Scalar sg = clampSaturation(fluidState, gasPhaseIdx);
463 return owChanged || gochanged;
469 template <
class Flu
idState>
470 static Scalar clampSaturation(
const FluidState& fluidState,
const int phaseIndex)
472 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
473 const auto sat = scalarValue(fluidState.saturation(phaseIndex));
474 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 EclStone1MaterialParams.hpp:46
const GasOilParams & gasOilParams() const
The parameter object for the gas-oil twophase law.
Definition EclStone1MaterialParams.hpp:74
Scalar Swl() const
Return the saturation of "connate" water.
Definition EclStone1MaterialParams.hpp:124
Scalar eta() const
Return the exponent of the extended Stone 1 model.
Definition EclStone1MaterialParams.hpp:143
Scalar krocw() const
Return the oil relperm for the oil-water system at the connate water saturation.
Definition EclStone1MaterialParams.hpp:131
const OilWaterParams & oilWaterParams() const
The parameter object for the oil-water twophase law.
Definition EclStone1MaterialParams.hpp:92
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition EclStone1Material.hpp:61
static constexpr bool isSaturationDependent
Definition EclStone1Material.hpp:107
static constexpr bool implementsTwoPhaseSatApi
Definition EclStone1Material.hpp:103
static constexpr bool isCompositionDependent
Definition EclStone1Material.hpp:119
static Evaluation pcgn(const Params ¶ms, const FluidState &fs)
Definition EclStone1Material.hpp:260
static void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition EclStone1Material.hpp:347
static Evaluation relpermOilInOilGasSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclStone1Material.hpp:426
static Evaluation relpermOilInOilWaterSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclStone1Material.hpp:437
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition EclStone1Material.hpp:294
static constexpr bool isTemperatureDependent
Definition EclStone1Material.hpp:115
static Evaluation krw(const Params ¶ms, const FluidState &fluidState)
Definition EclStone1Material.hpp:374
static Evaluation krg(const Params ¶ms, const FluidState &fluidState)
Definition EclStone1Material.hpp:362
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition EclStone1Material.hpp:305
static constexpr bool implementsTwoPhaseApi
Definition EclStone1Material.hpp:99
static Evaluation Sw(const Params &, const FluidState &)
Definition EclStone1Material.hpp:325
static constexpr bool isPressureDependent
Definition EclStone1Material.hpp:111
static bool updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclStone1Material.hpp:452
static Evaluation krn(const Params ¶ms, const FluidState &fluidState)
Definition EclStone1Material.hpp:385
static Evaluation pcnw(const Params ¶ms, const FluidState &fs)
Definition EclStone1Material.hpp:278
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition EclStone1Material.hpp:315
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 EclStone1Material.hpp:136
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30