27 #ifndef OPM_ECL_DEFAULT_MATERIAL_HPP
28 #define OPM_ECL_DEFAULT_MATERIAL_HPP
32 #include <opm/common/Valgrind.hpp>
35 #include <opm/common/Exceptions.hpp>
36 #include <opm/common/ErrorMacros.hpp>
55 template <
class TraitsT,
56 class GasOilMaterialLawT,
57 class OilWaterMaterialLawT,
58 class ParamsT = EclDefaultMaterialParams<TraitsT,
59 typename GasOilMaterialLawT::Params,
60 typename OilWaterMaterialLawT::Params> >
64 typedef GasOilMaterialLawT GasOilMaterialLaw;
65 typedef OilWaterMaterialLawT OilWaterMaterialLaw;
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 typedef TraitsT Traits;
90 typedef ParamsT Params;
91 typedef typename Traits::Scalar Scalar;
93 static const int numPhases = 3;
94 static const int waterPhaseIdx = Traits::wettingPhaseIdx;
95 static const int oilPhaseIdx = Traits::nonWettingPhaseIdx;
96 static const int gasPhaseIdx = Traits::gasPhaseIdx;
136 template <
class ContainerT,
class Flu
idState>
138 const Params& params,
139 const FluidState& state)
141 typedef typename std::remove_reference<decltype(values[0])>::type Evaluation;
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 const double krwSw = 2.0;
179 params.oilWaterParams().update(pcSwMdc, krwSw, krnSwMdc);
188 static void gasOilHysteresisParams(Scalar& pcSwMdc,
190 const Params& params)
192 pcSwMdc = params.gasOilParams().pcSwMdc();
193 krnSwMdc = params.gasOilParams().krnSwMdc();
195 Valgrind::CheckDefined(pcSwMdc);
196 Valgrind::CheckDefined(krnSwMdc);
205 static void setGasOilHysteresisParams(
const Scalar& pcSwMdc,
206 const Scalar& krnSwMdc,
209 const double krwSw = 2.0;
210 params.gasOilParams().update(pcSwMdc, krwSw, krnSwMdc);
222 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
223 static Evaluation
pcgn(
const Params& params,
224 const FluidState& fs)
226 const auto&
Sw = 1.0 - Opm::decay<Evaluation>(fs.saturation(gasPhaseIdx));
227 return GasOilMaterialLaw::twoPhaseSatPcnw(params.gasOilParams(),
Sw);
239 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
240 static Evaluation
pcnw(
const Params& params,
241 const FluidState& fs)
243 const auto&
Sw = Opm::decay<Evaluation>(fs.saturation(waterPhaseIdx));
244 return OilWaterMaterialLaw::twoPhaseSatPcnw(params.oilWaterParams(),
Sw);
250 template <
class ContainerT,
class Flu
idState>
255 OPM_THROW(std::logic_error,
"Not implemented: saturations()");
261 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
262 static Evaluation
Sg(
const Params& ,
265 OPM_THROW(std::logic_error,
"Not implemented: Sg()");
271 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
272 static Evaluation
Sn(
const Params& ,
275 OPM_THROW(std::logic_error,
"Not implemented: Sn()");
281 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
282 static Evaluation
Sw(
const Params& ,
285 OPM_THROW(std::logic_error,
"Not implemented: Sw()");
303 template <
class ContainerT,
class Flu
idState>
305 const Params& params,
306 const FluidState& fluidState)
308 typedef typename std::remove_reference<decltype(values[0])>::type Evaluation;
310 values[waterPhaseIdx] = krw<FluidState, Evaluation>(params, fluidState);
311 values[oilPhaseIdx] = krn<FluidState, Evaluation>(params, fluidState);
312 values[gasPhaseIdx] = krg<FluidState, Evaluation>(params, fluidState);
318 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
319 static Evaluation
krg(
const Params& params,
320 const FluidState& fluidState)
322 const Evaluation&
Sw = 1 - Opm::decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
323 return GasOilMaterialLaw::twoPhaseSatKrn(params.gasOilParams(),
Sw);
329 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
330 static Evaluation
krw(
const Params& params,
331 const FluidState& fluidState)
333 const Evaluation&
Sw = Opm::decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
334 return OilWaterMaterialLaw::twoPhaseSatKrw(params.oilWaterParams(),
Sw);
340 template <
class Flu
idState,
class Evaluation =
typename Flu
idState::Scalar>
341 static Evaluation
krn(
const Params& params,
342 const FluidState& fluidState)
344 Scalar Swco = params.Swl();
347 Opm::max(Evaluation(Swco),
348 Opm::decay<Evaluation>(fluidState.saturation(waterPhaseIdx)));
349 Evaluation
Sg = Opm::decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
351 Evaluation Sw_ow = Sg +
Sw;
352 Evaluation So_go = 1.0 - Sw_ow;
353 const Evaluation& kro_ow = OilWaterMaterialLaw::twoPhaseSatKrn(params.oilWaterParams(), Sw_ow);
354 const Evaluation& kro_go = GasOilMaterialLaw::twoPhaseSatKrw(params.gasOilParams(), So_go);
359 const Scalar epsilon = 1e-5;
360 if (Opm::scalarValue(Sw_ow) - Swco < epsilon) {
361 Evaluation kro2 = (kro_ow + kro_go)/2;;
362 if (Opm::scalarValue(Sw_ow) - Swco > epsilon/2) {
363 Evaluation kro1 = (Sg*kro_go + (Sw - Swco)*kro_ow)/(Sw_ow - Swco);
364 Evaluation alpha = (epsilon - (Sw_ow - Swco))/(epsilon/2);
365 return kro2*alpha + kro1*(1 - alpha);
371 return (Sg*kro_go + (Sw - Swco)*kro_ow)/(Sw_ow - Swco);
381 template <
class Flu
idState>
384 Scalar
Sw = Opm::scalarValue(fluidState.saturation(waterPhaseIdx));
385 Scalar So = Opm::scalarValue(fluidState.saturation(oilPhaseIdx));
386 Scalar
Sg = Opm::scalarValue(fluidState.saturation(gasPhaseIdx));
388 if (params.inconsistentHysteresisUpdate()) {
389 Sg = std::min(Scalar(1.0), std::max(Scalar(0.0), Sg));
399 params.oilWaterParams().update(1 - So, 1 - So, 1 - So);
400 params.gasOilParams().update(1 - Sg, 1 - Sg, 1 - Sg);
403 Scalar Swco = params.Swl();
404 Sw = std::min(Scalar(1.0), std::max(Scalar(0.0), Sw));
405 Sg = std::min(Scalar(1.0), std::max(Scalar(0.0), Sg));
407 Scalar Sw_ow = Sg + std::max(Swco, Sw);
408 Scalar So_go = 1 + Sw_ow;
410 params.oilWaterParams().update(Sw, 1 - Sg, Sw_ow);
411 params.gasOilParams().update(1 - Sg, So_go, 1 - Sg);
static const bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition...
Definition: EclDefaultMaterial.hpp:120
static const bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition: EclDefaultMaterial.hpp:100
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 krg(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the gas phase.
Definition: EclDefaultMaterial.hpp:319
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:240
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition: EclDefaultMaterial.hpp:262
Default implementation for the parameters required by the default three-phase capillary pressure mode...
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition: EclDefaultMaterial.hpp:251
static Evaluation krw(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the wetting phase.
Definition: EclDefaultMaterial.hpp:330
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:223
static const bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition: EclDefaultMaterial.hpp:116
static Evaluation krn(const Params ¶ms, const FluidState &fluidState)
The relative permeability of the non-wetting (i.e., oil) phase.
Definition: EclDefaultMaterial.hpp:341
static const bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure...
Definition: EclDefaultMaterial.hpp:112
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition: EclDefaultMaterial.hpp:272
static const bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition: EclDefaultMaterial.hpp:108
static void relativePermeabilities(ContainerT &values, const Params ¶ms, const FluidState &fluidState)
The relative permeability of all phases.
Definition: EclDefaultMaterial.hpp:304
static Evaluation Sw(const Params &, const FluidState &)
The saturation of the wetting (i.e., water) phase.
Definition: EclDefaultMaterial.hpp:282
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition: EclDefaultMaterial.hpp:61
static const bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition: EclDefaultMaterial.hpp:104
static void updateHysteresis(Params ¶ms, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition: EclDefaultMaterial.hpp:382