27 #ifndef OPM_ECL_DEFAULT_MATERIAL_HPP 28 #define OPM_ECL_DEFAULT_MATERIAL_HPP 30 #include <opm/common/TimingMacros.hpp> 32 #include <opm/common/utility/gpuDecorators.hpp> 39 #include <type_traits> 56 template <
class TraitsT,
57 class GasOilMaterialLawT,
58 class OilWaterMaterialLawT,
59 class ParamsT = EclDefaultMaterialParams<TraitsT,
60 typename GasOilMaterialLawT::Params,
61 typename OilWaterMaterialLawT::Params> >
65 using GasOilMaterialLaw = GasOilMaterialLawT;
66 using OilWaterMaterialLaw = OilWaterMaterialLawT;
69 static_assert(TraitsT::numPhases == 3,
70 "The number of phases considered by this capillary pressure " 71 "law is always three!");
72 static_assert(GasOilMaterialLaw::numPhases == 2,
73 "The number of phases considered by the gas-oil capillary " 74 "pressure law must be two!");
75 static_assert(OilWaterMaterialLaw::numPhases == 2,
76 "The number of phases considered by the oil-water capillary " 77 "pressure law must be two!");
78 static_assert(std::is_same<
typename GasOilMaterialLaw::Scalar,
79 typename OilWaterMaterialLaw::Scalar>::
value,
80 "The two two-phase capillary pressure laws must use the same " 81 "type of floating point values.");
83 static_assert(GasOilMaterialLaw::implementsTwoPhaseSatApi,
84 "The gas-oil material law must implement the two-phase saturation " 85 "only API to for the default Ecl capillary pressure law!");
86 static_assert(OilWaterMaterialLaw::implementsTwoPhaseSatApi,
87 "The oil-water material law must implement the two-phase saturation " 88 "only API to for the default Ecl capillary pressure law!");
90 using Traits = TraitsT;
91 using Params = ParamsT;
92 using Scalar =
typename Traits::Scalar;
94 static constexpr
int numPhases = 3;
95 static constexpr
int waterPhaseIdx = Traits::wettingPhaseIdx;
96 static constexpr
int oilPhaseIdx = Traits::nonWettingPhaseIdx;
97 static constexpr
int gasPhaseIdx = Traits::gasPhaseIdx;
137 template <
class ContainerT,
class FluidState,
class ...Args>
139 const Params& params,
140 const FluidState& state)
142 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
143 using Evaluation =
typename std::remove_reference<decltype(values[0])>::type;
144 values[gasPhaseIdx] =
pcgn<FluidState, Evaluation, Args...>(params, state);
145 values[oilPhaseIdx] = 0;
146 values[waterPhaseIdx] = -
pcnw<FluidState, Evaluation, Args...>(params, state);
148 Valgrind::CheckDefined(values[gasPhaseIdx]);
149 Valgrind::CheckDefined(values[oilPhaseIdx]);
150 Valgrind::CheckDefined(values[waterPhaseIdx]);
160 static void oilWaterHysteresisParams(Scalar& soMax,
163 const Params& params)
165 if constexpr (Traits::enableHysteresis) {
166 soMax = 1.0 - params.oilWaterParams().krnSwMdc();
167 swMax = params.oilWaterParams().krwSwMdc();
168 swMin = params.oilWaterParams().pcSwMdc();
169 Valgrind::CheckDefined(soMax);
170 Valgrind::CheckDefined(swMax);
171 Valgrind::CheckDefined(swMin);
182 static void setOilWaterHysteresisParams(
const Scalar& soMax,
187 if constexpr (Traits::enableHysteresis) {
188 params.oilWaterParams().update(swMin, swMax, 1.0 - soMax);
199 static void gasOilHysteresisParams(Scalar& sgMax,
202 const Params& params)
204 if constexpr (Traits::enableHysteresis) {
205 const auto Swco = params.Swl();
206 sgMax = 1.0 - params.gasOilParams().krnSwMdc() - Swco;
207 shMax = params.gasOilParams().krwSwMdc();
208 soMin = params.gasOilParams().pcSwMdc();
209 Valgrind::CheckDefined(sgMax);
210 Valgrind::CheckDefined(shMax);
211 Valgrind::CheckDefined(soMin);
222 static void setGasOilHysteresisParams(
const Scalar& sgMax,
227 if constexpr (Traits::enableHysteresis) {
228 const auto Swco = params.Swl();
229 params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
233 static Scalar trappedGasSaturation(
const Params& params,
bool maximumTrapping)
235 const auto Swco = params.Swl();
236 return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
239 static Scalar trappedOilSaturation(
const Params& params,
bool maximumTrapping)
241 return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
244 static Scalar trappedWaterSaturation(
const Params& params)
246 return params.oilWaterParams().SwTrapped();
249 static Scalar strandedGasSaturation(
const Params& params, Scalar
Sg, Scalar Kg)
251 const auto Swco = params.Swl();
252 return params.gasOilParams().SnStranded(
Sg, Kg) - Swco;
264 template <
class FluidState,
class Evaluation,
class ...Args>
265 OPM_HOST_DEVICE
static Evaluation
pcgn(
const Params& params,
266 const FluidState& fs)
268 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
270 const auto Sw = 1.0 - params.Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
271 return GasOilMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.gasOilParams(),
Sw);
283 template <
class FluidState,
class Evaluation,
class ...Args>
284 OPM_HOST_DEVICE
static Evaluation
pcnw(
const Params& params,
285 const FluidState& fs)
287 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
288 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
289 return OilWaterMaterialLaw::template twoPhaseSatPcnw<Evaluation, Args...>(params.oilWaterParams(),
Sw);
295 template <
class ContainerT,
class Flu
idState>
300 throw std::logic_error(
"Not implemented: saturations()");
306 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
307 static Evaluation
Sg(
const Params& ,
310 throw std::logic_error(
"Not implemented: Sg()");
316 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
317 static Evaluation
Sn(
const Params& ,
320 throw std::logic_error(
"Not implemented: Sn()");
326 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::ValueType>
327 static Evaluation
Sw(
const Params& ,
330 throw std::logic_error(
"Not implemented: Sw()");
348 template <
class ContainerT,
class FluidState,
class ...Args>
350 const Params& params,
351 const FluidState& fluidState)
353 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
354 using Evaluation =
typename std::remove_reference<decltype(values[0])>::type;
356 values[waterPhaseIdx] =
krw<FluidState, Evaluation, Args...>(params, fluidState);
357 values[oilPhaseIdx] =
krn<FluidState, Evaluation, Args...>(params, fluidState);
358 values[gasPhaseIdx] =
krg<FluidState, Evaluation, Args...>(params, fluidState);
364 template <
class FluidState,
class Evaluation,
class ...Args>
365 OPM_HOST_DEVICE
static Evaluation
krg(
const Params& params,
366 const FluidState& fluidState)
368 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
370 const Evaluation sw = 1.0 - params.Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
371 return GasOilMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.gasOilParams(), sw);
377 template <
class FluidState,
class Evaluation,
class ...Args>
378 OPM_HOST_DEVICE
static Evaluation
krw(
const Params& params,
379 const FluidState& fluidState)
381 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
382 const Evaluation sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
383 return OilWaterMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.oilWaterParams(), sw);
389 template <
class FluidState,
class Evaluation,
class ...Args>
390 OPM_HOST_DEVICE
static Evaluation
krn(
const Params& params,
391 const FluidState& fluidState)
393 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
394 const Scalar Swco = params.Swl();
396 const Evaluation sw =
397 max(Evaluation(Swco),
398 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
400 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
402 const Evaluation Sw_ow = sg + sw;
409 constexpr
const Scalar epsilon = 1e-5;
410 if (scalarValue(Sw_ow) - Swco < epsilon) {
411 const Evaluation kro2 = (kro_ow + kro_go)/2;
412 if (scalarValue(Sw_ow) - Swco > epsilon/2) {
413 const Evaluation kro1 = (sg * kro_go + (sw - Swco) * kro_ow) / (Sw_ow - Swco);
414 const Evaluation alpha = (epsilon - (Sw_ow - Swco)) / (epsilon / 2);
416 return kro2 * alpha + kro1 * (1 - alpha);
422 return (sg * kro_go + (sw - Swco) * kro_ow) / (Sw_ow - Swco);
428 template <
class Evaluation,
class FluidState,
class ...Args>
430 const FluidState& fluidState)
432 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
433 const Evaluation sw =
434 max(Evaluation{ params.Swl() },
435 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
437 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
438 const Evaluation So_go = 1.0 - (sg + sw);
440 return GasOilMaterialLaw::template twoPhaseSatKrw<Evaluation, Args...>(params.gasOilParams(), So_go);
446 template <
class Evaluation,
class FluidState,
class ...Args>
448 const FluidState& fluidState)
450 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
451 const Evaluation sw =
452 max(Evaluation{ params.Swl() },
453 decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
455 const Evaluation sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
456 const Evaluation Sw_ow = sg + sw;
458 return OilWaterMaterialLaw::template twoPhaseSatKrn<Evaluation, Args...>(params.oilWaterParams(), Sw_ow);
468 template <
class Flu
idState>
471 if constexpr (Traits::enableHysteresis) {
472 const Scalar Swco = params.Swl();
473 const Scalar sw = clampSaturation(fluidState, waterPhaseIdx);
474 const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
475 const Scalar sg = clampSaturation(fluidState, gasPhaseIdx);
476 bool owChanged = params.oilWaterParams().update(sw, sw, 1 - So);
477 bool gochanged = params.gasOilParams().update(So,
480 return owChanged || gochanged;
486 template <
class Flu
idState>
487 static Scalar clampSaturation(
const FluidState& fluidState,
const int phaseIndex)
489 OPM_TIMEFUNCTION_LOCAL(Subsystem::SatProps);
490 const auto sat = scalarValue(fluidState.saturation(phaseIndex));
491 return std::clamp(sat, Scalar{0.0}, Scalar{1.0});
static constexpr bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition: EclDefaultMaterial.hpp:117
static OPM_HOST_DEVICE Evaluation relpermOilInOilGasSystem(const Params ¶ms, const FluidState &fluidState)
The relative permeability of oil in oil/gas system.
Definition: EclDefaultMaterial.hpp:429
static OPM_HOST_DEVICE Evaluation krg(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the gas phase.
Definition: EclDefaultMaterial.hpp:365
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition: EclDefaultMaterial.hpp:307
static constexpr bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition...
Definition: EclDefaultMaterial.hpp:121
static OPM_HOST_DEVICE Evaluation krn(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the non-wetting (i.e., oil) phase.
Definition: EclDefaultMaterial.hpp:390
Default implementation for the parameters required by the default three-phase capillary pressure mode...
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
static OPM_HOST_DEVICE void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition: EclDefaultMaterial.hpp:349
static constexpr bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure...
Definition: EclDefaultMaterial.hpp:113
static OPM_HOST_DEVICE Evaluation relpermOilInOilWaterSystem(const Params ¶ms, const FluidState &fluidState)
The relative permeability of oil in oil/water system.
Definition: EclDefaultMaterial.hpp:447
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition: EclDefaultMaterial.hpp:296
static constexpr bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition: EclDefaultMaterial.hpp:105
static OPM_HOST_DEVICE 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:138
static bool updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition: EclDefaultMaterial.hpp:469
static OPM_HOST_DEVICE Evaluation krw(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the wetting phase.
Definition: EclDefaultMaterial.hpp:378
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition: EclDefaultMaterial.hpp:317
static constexpr bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition: EclDefaultMaterial.hpp:101
static Evaluation Sw(const Params &, const FluidState &)
The saturation of the wetting (i.e., water) phase.
Definition: EclDefaultMaterial.hpp:327
static constexpr bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition: EclDefaultMaterial.hpp:109
static OPM_HOST_DEVICE 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:284
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:62
static OPM_HOST_DEVICE 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:265