27#ifndef OPM_ECL_DEFAULT_MATERIAL_HPP
28#define OPM_ECL_DEFAULT_MATERIAL_HPP
30#include <opm/common/TimingMacros.hpp>
55template <
class TraitsT,
56 class GasOilMaterialLawT,
57 class OilWaterMaterialLawT,
59 typename GasOilMaterialLawT::Params,
60 typename OilWaterMaterialLawT::Params> >
64 using GasOilMaterialLaw = GasOilMaterialLawT;
65 using OilWaterMaterialLaw = OilWaterMaterialLawT;
68 static_assert(TraitsT::numPhases == 3,
69 "The number of phases considered by this capillary pressure "
70 "law is always three!");
71 static_assert(GasOilMaterialLaw::numPhases == 2,
72 "The number of phases considered by the gas-oil capillary "
73 "pressure law must be two!");
74 static_assert(OilWaterMaterialLaw::numPhases == 2,
75 "The number of phases considered by the oil-water capillary "
76 "pressure law must be two!");
77 static_assert(std::is_same<
typename GasOilMaterialLaw::Scalar,
78 typename OilWaterMaterialLaw::Scalar>::value,
79 "The two two-phase capillary pressure laws must use the same "
80 "type of floating point values.");
82 static_assert(GasOilMaterialLaw::implementsTwoPhaseSatApi,
83 "The gas-oil material law must implement the two-phase saturation "
84 "only API to for the default Ecl capillary pressure law!");
85 static_assert(OilWaterMaterialLaw::implementsTwoPhaseSatApi,
86 "The oil-water material law must implement the two-phase saturation "
87 "only API to for the default Ecl capillary pressure law!");
89 using Traits = TraitsT;
90 using Params = ParamsT;
91 using Scalar =
typename Traits::Scalar;
93 static constexpr int numPhases = 3;
94 static constexpr int waterPhaseIdx = Traits::wettingPhaseIdx;
95 static constexpr int oilPhaseIdx = Traits::nonWettingPhaseIdx;
96 static constexpr int gasPhaseIdx = Traits::gasPhaseIdx;
136 template <
class ContainerT,
class FluidState,
class ...Args>
138 const Params& params,
139 const FluidState& state)
141 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
142 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
143 values[gasPhaseIdx] =
pcgn<FluidState, Evaluation, Args...>(params, state);
144 values[oilPhaseIdx] = 0;
145 values[waterPhaseIdx] = -
pcnw<FluidState, Evaluation, Args...>(params, state);
159 static void oilWaterHysteresisParams(Scalar& soMax,
162 const Params& params)
164 if constexpr (Traits::enableHysteresis) {
165 soMax = 1.0 - params.oilWaterParams().krnSwMdc();
166 swMax = params.oilWaterParams().krwSwMdc();
167 swMin = params.oilWaterParams().pcSwMdc();
181 static void setOilWaterHysteresisParams(
const Scalar& soMax,
186 if constexpr (Traits::enableHysteresis) {
187 params.oilWaterParams().update(swMin, swMax, 1.0 - soMax);
198 static void gasOilHysteresisParams(Scalar& sgMax,
201 const Params& params)
203 if constexpr (Traits::enableHysteresis) {
204 const auto Swco = params.Swl();
205 sgMax = 1.0 - params.gasOilParams().krnSwMdc() - Swco;
206 shMax = params.gasOilParams().krwSwMdc();
207 soMin = params.gasOilParams().pcSwMdc();
208 Valgrind::CheckDefined(sgMax);
209 Valgrind::CheckDefined(shMax);
210 Valgrind::CheckDefined(soMin);
221 static void setGasOilHysteresisParams(
const Scalar& sgMax,
226 if constexpr (Traits::enableHysteresis) {
227 const auto Swco = params.Swl();
228 params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
232 static Scalar trappedGasSaturation(
const Params& params,
bool maximumTrapping)
234 const auto Swco = params.Swl();
235 return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
238 static Scalar trappedOilSaturation(
const Params& params,
bool maximumTrapping)
240 return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
243 static Scalar trappedWaterSaturation(
const Params& params)
245 return params.oilWaterParams().SwTrapped();
248 static Scalar strandedGasSaturation(
const Params& params, Scalar
Sg, Scalar Kg)
250 const auto Swco = params.Swl();
251 return params.gasOilParams().SnStranded(
Sg, Kg) - Swco;
263 template <
class FluidState,
class Evaluation,
class ...Args>
264 static Evaluation
pcgn(
const Params& params,
265 const FluidState& fs)
267 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
269 const auto Sw = 1.0 - params.
Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
270 return GasOilMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.
gasOilParams(),
Sw);
282 template <
class FluidState,
class Evaluation,
class ...Args>
283 static Evaluation
pcnw(
const Params& params,
284 const FluidState& fs)
286 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
287 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
288 return 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 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
353 using Evaluation =
typename std::remove_reference<
decltype(values[0])>::type;
355 values[waterPhaseIdx] =
krw<FluidState, Evaluation, Args...>(params, fluidState);
356 values[oilPhaseIdx] =
krn<FluidState, Evaluation, Args...>(params, fluidState);
357 values[gasPhaseIdx] =
krg<FluidState, Evaluation, Args...>(params, fluidState);
363 template <
class FluidState,
class Evaluation,
class ...Args>
364 static Evaluation
krg(
const Params& params,
365 const FluidState& fluidState)
367 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
369 const Evaluation sw = 1.0 - params.
Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
370 return GasOilMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.
gasOilParams(), sw);
376 template <
class FluidState,
class Evaluation,
class ...Args>
377 static Evaluation
krw(
const Params& params,
378 const FluidState& fluidState)
380 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
381 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
382 return OilWaterMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.
oilWaterParams(), sw);
388 template <
class FluidState,
class Evaluation,
class ...Args>
389 static Evaluation
krn(
const Params& params,
390 const FluidState& fluidState)
392 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
393 const Scalar Swco = params.
Swl();
395 const Evaluation sw =
396 max(Evaluation(Swco),
397 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
399 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
401 const Evaluation Sw_ow = sg + sw;
408 constexpr const Scalar epsilon = 1e-5;
409 if (scalarValue(Sw_ow) - Swco < epsilon) {
410 const Evaluation kro2 = (kro_ow + kro_go)/2;
411 if (scalarValue(Sw_ow) - Swco > epsilon/2) {
412 const Evaluation kro1 = (sg * kro_go + (sw - Swco) * kro_ow) / (Sw_ow - Swco);
413 const Evaluation alpha = (epsilon - (Sw_ow - Swco)) / (epsilon / 2);
415 return kro2 * alpha + kro1 * (1 - alpha);
421 return (sg * kro_go + (sw - Swco) * kro_ow) / (Sw_ow - Swco);
427 template <
class Evaluation,
class FluidState,
class ...Args>
429 const FluidState& fluidState)
431 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
432 const Evaluation sw =
433 max(Evaluation{ params.
Swl() },
434 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
436 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
437 const Evaluation So_go = 1.0 - (sg + sw);
439 return GasOilMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.
gasOilParams(), So_go);
445 template <
class Evaluation,
class FluidState,
class ...Args>
447 const FluidState& fluidState)
449 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
450 const Evaluation sw =
451 max(Evaluation{ params.
Swl() },
452 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
454 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
455 const Evaluation Sw_ow = sg + sw;
457 return OilWaterMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.
oilWaterParams(), Sw_ow);
467 template <
class Flu
idState>
470 if constexpr (Traits::enableHysteresis) {
471 const Scalar Swco = params.
Swl();
472 const Scalar sw = clampSaturation(fluidState, waterPhaseIdx);
473 const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
474 const Scalar sg = clampSaturation(fluidState, gasPhaseIdx);
479 return owChanged || gochanged;
485 template <
class Flu
idState>
486 static Scalar clampSaturation(
const FluidState& fluidState,
const int phaseIndex)
488 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
489 const auto sat = scalarValue(fluidState.saturation(phaseIndex));
490 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.
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 default three-phase capillary pressure mode...
Definition EclDefaultMaterialParams.hpp:46
Scalar Swl() const
Return the saturation of "connate" water.
Definition EclDefaultMaterialParams.hpp:115
const OilWaterParams & oilWaterParams() const
The parameter object for the oil-water twophase law.
Definition EclDefaultMaterialParams.hpp:83
const GasOilParams & gasOilParams() const
The parameter object for the gas-oil twophase law.
Definition EclDefaultMaterialParams.hpp:65
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition EclDefaultMaterial.hpp:62
static Evaluation krn(const Params ¶ms, const FluidState &fluidState)
Definition EclDefaultMaterial.hpp:389
static Evaluation relpermOilInOilWaterSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclDefaultMaterial.hpp:446
static constexpr bool isCompositionDependent
Definition EclDefaultMaterial.hpp:120
static Evaluation pcnw(const Params ¶ms, const FluidState &fs)
Definition EclDefaultMaterial.hpp:283
static constexpr bool isTemperatureDependent
Definition EclDefaultMaterial.hpp:116
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition EclDefaultMaterial.hpp:306
static constexpr bool implementsTwoPhaseApi
Definition EclDefaultMaterial.hpp:100
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition EclDefaultMaterial.hpp:295
static Evaluation relpermOilInOilGasSystem(const Params ¶ms, const FluidState &fluidState)
Definition EclDefaultMaterial.hpp:428
static Evaluation krw(const Params ¶ms, const FluidState &fluidState)
Definition EclDefaultMaterial.hpp:377
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition EclDefaultMaterial.hpp:316
static constexpr bool isSaturationDependent
Definition EclDefaultMaterial.hpp:108
static bool updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclDefaultMaterial.hpp:468
static Evaluation krg(const Params ¶ms, const FluidState &fluidState)
Definition EclDefaultMaterial.hpp:364
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:137
static Evaluation pcgn(const Params ¶ms, const FluidState &fs)
Definition EclDefaultMaterial.hpp:264
static void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition EclDefaultMaterial.hpp:348
static Evaluation Sw(const Params &, const FluidState &)
Definition EclDefaultMaterial.hpp:326
static constexpr bool isPressureDependent
Definition EclDefaultMaterial.hpp:112
static constexpr bool implementsTwoPhaseSatApi
Definition EclDefaultMaterial.hpp:104
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30