My Project
Loading...
Searching...
No Matches
EclStone2Material.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
27#ifndef OPM_ECL_STONE2_MATERIAL_HPP
28#define OPM_ECL_STONE2_MATERIAL_HPP
29
31
34
35#include <algorithm>
36#include <stdexcept>
37#include <type_traits>
38
39namespace Opm {
40
54template <class TraitsT,
55 class GasOilMaterialLawT,
56 class OilWaterMaterialLawT,
57 class ParamsT = EclStone2MaterialParams<TraitsT,
58 typename GasOilMaterialLawT::Params,
59 typename OilWaterMaterialLawT::Params> >
60class EclStone2Material : public TraitsT
61{
62public:
63 using GasOilMaterialLaw = GasOilMaterialLawT;
64 using OilWaterMaterialLaw = OilWaterMaterialLawT;
65
66 // some safety checks
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.");
80
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!");
87
88 using Traits = TraitsT;
89 using Params = ParamsT;
90 using Scalar = typename Traits::Scalar;
91
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;
96
99 static constexpr bool implementsTwoPhaseApi = false;
100
103 static constexpr bool implementsTwoPhaseSatApi = false;
104
107 static constexpr bool isSaturationDependent = true;
108
111 static constexpr bool isPressureDependent = false;
112
115 static constexpr bool isTemperatureDependent = false;
116
119 static constexpr bool isCompositionDependent = false;
120
135 template <class ContainerT, class FluidState>
136 static void capillaryPressures(ContainerT& values,
137 const Params& params,
138 const FluidState& state)
139 {
140 using Evaluation = typename std::remove_reference<decltype(values[0])>::type;
141 values[gasPhaseIdx] = pcgn<FluidState, Evaluation>(params, state);
142 values[oilPhaseIdx] = 0;
143 values[waterPhaseIdx] = - pcnw<FluidState, Evaluation>(params, state);
144 Valgrind::CheckDefined(values[gasPhaseIdx]);
145 Valgrind::CheckDefined(values[oilPhaseIdx]);
146 Valgrind::CheckDefined(values[waterPhaseIdx]);
147 }
148
149 /*
150 * Hysteresis parameters for oil-water
151 * @see EclHysteresisTwoPhaseLawParams::soMax(...)
152 * @see EclHysteresisTwoPhaseLawParams::swMax(...)
153 * @see EclHysteresisTwoPhaseLawParams::swMin(...)
154 * \param params Parameters
155 */
156 static void oilWaterHysteresisParams(Scalar& soMax,
157 Scalar& swMax,
158 Scalar& swMin,
159 const Params& params)
160 {
161 soMax = 1.0 - params.oilWaterParams().krnSwMdc();
162 swMax = params.oilWaterParams().krwSwMdc();
163 swMin = params.oilWaterParams().pcSwMdc();
164 Valgrind::CheckDefined(soMax);
165 Valgrind::CheckDefined(swMax);
166 Valgrind::CheckDefined(swMin);
167 }
168
169 /*
170 * Hysteresis parameters for oil-water
171 * @see EclHysteresisTwoPhaseLawParams::soMax(...)
172 * @see EclHysteresisTwoPhaseLawParams::swMax(...)
173 * @see EclHysteresisTwoPhaseLawParams::swMin(...)
174 * \param params Parameters
175 */
176 static void setOilWaterHysteresisParams(const Scalar& soMax,
177 const Scalar& swMax,
178 const Scalar& swMin,
179 Params& params)
180 {
181 params.oilWaterParams().update(swMin, swMax, 1.0 - soMax);
182 }
183
184
185 /*
186 * Hysteresis parameters for gas-oil
187 * @see EclHysteresisTwoPhaseLawParams::sgMax(...)
188 * @see EclHysteresisTwoPhaseLawParams::shMax(...)
189 * @see EclHysteresisTwoPhaseLawParams::soMin(...)
190 * \param params Parameters
191 */
192 static void gasOilHysteresisParams(Scalar& sgMax,
193 Scalar& shMax,
194 Scalar& soMin,
195 const Params& params)
196 {
197 const auto Swco = params.Swl();
198 sgMax = 1.0 - params.gasOilParams().krnSwMdc() - Swco;
199 shMax = params.gasOilParams().krwSwMdc();
200 soMin = params.gasOilParams().pcSwMdc();
201
202 Valgrind::CheckDefined(sgMax);
203 Valgrind::CheckDefined(shMax);
204 Valgrind::CheckDefined(soMin);
205 }
206
207 /*
208 * Hysteresis parameters for gas-oil
209 * @see EclHysteresisTwoPhaseLawParams::sgMax(...)
210 * @see EclHysteresisTwoPhaseLawParams::shMax(...)
211 * @see EclHysteresisTwoPhaseLawParams::soMin(...)
212 * \param params Parameters
213 */
214 static void setGasOilHysteresisParams(const Scalar& sgMax,
215 const Scalar& shMax,
216 const Scalar& soMin,
217 Params& params)
218 {
219 const auto Swco = params.Swl();
220 params.gasOilParams().update(soMin, shMax, 1.0 - sgMax - Swco);
221 }
222
223 static Scalar trappedGasSaturation(const Params& params, bool maximumTrapping)
224 {
225 const auto Swco = params.Swl();
226 return params.gasOilParams().SnTrapped(maximumTrapping) - Swco;
227 }
228
229 static Scalar trappedOilSaturation(const Params& params, bool maximumTrapping)
230 {
231 return params.oilWaterParams().SnTrapped(maximumTrapping) + params.gasOilParams().SwTrapped();
232 }
233
234 static Scalar trappedWaterSaturation(const Params& params)
235 {
236 return params.oilWaterParams().SwTrapped();
237 }
238 static Scalar strandedGasSaturation(const Params& params, Scalar Sg, Scalar Kg)
239 {
240 const auto Swco = params.Swl();
241 return params.gasOilParams().SnStranded(Sg, Kg) - Swco;
242 }
243
253 template <class FluidState, class Evaluation = typename FluidState::Scalar>
254 static Evaluation pcgn(const Params& params,
255 const FluidState& fs)
256 {
257 // Maximum attainable oil saturation is 1-SWL.
258 const auto Sw = 1.0 - params.Swl() - decay<Evaluation>(fs.saturation(gasPhaseIdx));
259 return GasOilMaterialLaw::twoPhaseSatPcnw(params.gasOilParams(), Sw);
260 }
261
271 template <class FluidState, class Evaluation = typename FluidState::Scalar>
272 static Evaluation pcnw(const Params& params,
273 const FluidState& fs)
274 {
275 const auto Sw = decay<Evaluation>(fs.saturation(waterPhaseIdx));
276 Valgrind::CheckDefined(Sw);
277
278 const auto result = OilWaterMaterialLaw::twoPhaseSatPcnw(params.oilWaterParams(), Sw);
279 Valgrind::CheckDefined(result);
280
281 return result;
282 }
283
287 template <class ContainerT, class FluidState>
288 static void saturations(ContainerT& /*values */,
289 const Params& /* params */,
290 const FluidState& /* fluidState */)
291 {
292 throw std::logic_error("Not implemented: saturations()");
293 }
294
298 template <class FluidState, class Evaluation = typename FluidState::Scalar>
299 static Evaluation Sg(const Params& /* params */,
300 const FluidState& /* fluidState */)
301 {
302 throw std::logic_error("Not implemented: Sg()");
303 }
304
308 template <class FluidState, class Evaluation = typename FluidState::Scalar>
309 static Evaluation Sn(const Params& /* params */,
310 const FluidState& /* fluidState */)
311 {
312 throw std::logic_error("Not implemented: Sn()");
313 }
314
318 template <class FluidState, class Evaluation = typename FluidState::Scalar>
319 static Evaluation Sw(const Params& /* params */,
320 const FluidState& /* fluidState */)
321 {
322 throw std::logic_error("Not implemented: Sw()");
323 }
324
340 template <class ContainerT, class FluidState>
341 static void relativePermeabilities(ContainerT& values,
342 const Params& params,
343 const FluidState& fluidState)
344 {
345 using Evaluation = typename std::remove_reference<decltype(values[0])>::type;
346
347 values[waterPhaseIdx] = krw<FluidState, Evaluation>(params, fluidState);
348 values[oilPhaseIdx] = krn<FluidState, Evaluation>(params, fluidState);
349 values[gasPhaseIdx] = krg<FluidState, Evaluation>(params, fluidState);
350 }
351
355 template <class FluidState, class Evaluation = typename FluidState::Scalar>
356 static Evaluation krg(const Params& params,
357 const FluidState& fluidState)
358 {
359 // Maximum attainable oil saturation is 1-SWL.
360 const Evaluation Sw = 1 - params.Swl() - decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
361 return GasOilMaterialLaw::twoPhaseSatKrn(params.gasOilParams(), Sw);
362 }
363
367 template <class FluidState, class Evaluation = typename FluidState::Scalar>
368 static Evaluation krw(const Params& params,
369 const FluidState& fluidState)
370 {
371 const Evaluation Sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
372 return OilWaterMaterialLaw::twoPhaseSatKrw(params.oilWaterParams(), Sw);
373 }
374
378 template <class FluidState, class Evaluation = typename FluidState::Scalar>
379 static Evaluation krn(const Params& params,
380 const FluidState& fluidState)
381 {
382 const Scalar Swco = params.Swl();
383
384 const Evaluation Sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
385 const Evaluation Sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
386
387 const Scalar krocw = OilWaterMaterialLaw::twoPhaseSatKrn(params.oilWaterParams(), Swco);
388 const Evaluation krow = relpermOilInOilWaterSystem<Evaluation>(params, fluidState);
389 const Evaluation krw = OilWaterMaterialLaw::twoPhaseSatKrw(params.oilWaterParams(), Sw);
390 const Evaluation krg = GasOilMaterialLaw::twoPhaseSatKrn(params.gasOilParams(), 1 - Swco - Sg);
391 const Evaluation krog = relpermOilInOilGasSystem<Evaluation>(params, fluidState);
392
393 return max(krocw * ((krow/krocw + krw) * (krog/krocw + krg) - krw - krg), Evaluation{0});
394 }
395
396
400 template <class Evaluation, class FluidState>
401 static Evaluation relpermOilInOilGasSystem(const Params& params,
402 const FluidState& fluidState)
403 {
404 const Scalar Swco = params.Swl();
405 const Evaluation Sg = decay<Evaluation>(fluidState.saturation(gasPhaseIdx));
406
407 return GasOilMaterialLaw::twoPhaseSatKrw(params.gasOilParams(), 1 - Swco - Sg);
408 }
409
410
414 template <class Evaluation, class FluidState>
415 static Evaluation relpermOilInOilWaterSystem(const Params& params,
416 const FluidState& fluidState)
417 {
418 const Evaluation Sw = decay<Evaluation>(fluidState.saturation(waterPhaseIdx));
419
420 return OilWaterMaterialLaw::twoPhaseSatKrn(params.oilWaterParams(), Sw);
421 }
422
430 template <class FluidState>
431 static bool updateHysteresis(Params& params, const FluidState& fluidState)
432 {
433 const Scalar Swco = params.Swl();
434 const Scalar Sw = clampSaturation(fluidState, waterPhaseIdx);
435 const Scalar So = clampSaturation(fluidState, oilPhaseIdx);
436 const Scalar Sg = clampSaturation(fluidState, gasPhaseIdx);
437 bool owChanged = params.oilWaterParams().update(/*pcSw=*/Sw, /*krwSw=*/Sw, /*krnSw=*/1 - So);
438 bool gochanged = params.gasOilParams().update(/*pcSw=*/ So,
439 /*krwSw=*/ So,
440 /*krnSw=*/ 1.0 - Swco - Sg);
441 return owChanged || gochanged;
442 }
443
444 template <class FluidState>
445 static Scalar clampSaturation(const FluidState& fluidState, const int phaseIndex)
446 {
447 OPM_TIMEFUNCTION_LOCAL();
448 const auto sat = scalarValue(fluidState.saturation(phaseIndex));
449 return std::clamp(sat, Scalar{0.0}, Scalar{1.0});
450 }
451};
452
453} // namespace Opm
454
455#endif
Default implementation for the parameters required by the three-phase capillary pressure/relperm Ston...
A traits class which provides basic mathematical functions for arbitrary scalar floating point values...
Some templates to wrap the valgrind client request macros.
Implements the second phase capillary pressure/relperm law suggested by Stone as used by the ECLipse ...
Definition EclStone2Material.hpp:61
static constexpr bool isPressureDependent
Specify whether the quantities defined by this material law are dependent on the absolute pressure.
Definition EclStone2Material.hpp:111
static Evaluation Sw(const Params &, const FluidState &)
The saturation of the wetting (i.e., water) phase.
Definition EclStone2Material.hpp:319
static bool updateHysteresis(Params &params, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclStone2Material.hpp:431
static Evaluation pcgn(const Params &params, const FluidState &fs)
Capillary pressure between the gas and the non-wetting liquid (i.e., oil) phase.
Definition EclStone2Material.hpp:254
static Evaluation pcnw(const Params &params, const FluidState &fs)
Capillary pressure between the non-wetting liquid (i.e., oil) and the wetting liquid (i....
Definition EclStone2Material.hpp:272
static void capillaryPressures(ContainerT &values, const Params &params, const FluidState &state)
Implements the default three phase capillary pressure law used by the ECLipse simulator.
Definition EclStone2Material.hpp:136
static Evaluation relpermOilInOilWaterSystem(const Params &params, const FluidState &fluidState)
The relative permeability of oil in oil/water system.
Definition EclStone2Material.hpp:415
static constexpr bool implementsTwoPhaseSatApi
Specify whether this material law implements the two-phase convenience API which only depends on the ...
Definition EclStone2Material.hpp:103
static constexpr bool isTemperatureDependent
Specify whether the quantities defined by this material law are temperature dependent.
Definition EclStone2Material.hpp:115
static constexpr bool isCompositionDependent
Specify whether the quantities defined by this material law are dependent on the phase composition.
Definition EclStone2Material.hpp:119
static Evaluation Sg(const Params &, const FluidState &)
The saturation of the gas phase.
Definition EclStone2Material.hpp:299
static void saturations(ContainerT &, const Params &, const FluidState &)
The inverse of the capillary pressure.
Definition EclStone2Material.hpp:288
static constexpr bool implementsTwoPhaseApi
Specify whether this material law implements the two-phase convenience API.
Definition EclStone2Material.hpp:99
static Evaluation relpermOilInOilGasSystem(const Params &params, const FluidState &fluidState)
The relative permeability of oil in oil/gas system.
Definition EclStone2Material.hpp:401
static Evaluation Sn(const Params &, const FluidState &)
The saturation of the non-wetting (i.e., oil) phase.
Definition EclStone2Material.hpp:309
static Evaluation krn(const Params &params, const FluidState &fluidState)
The relative permeability of the non-wetting (i.e., oil) phase.
Definition EclStone2Material.hpp:379
static constexpr bool isSaturationDependent
Specify whether the quantities defined by this material law are saturation dependent.
Definition EclStone2Material.hpp:107
static Evaluation krw(const Params &params, const FluidState &fluidState)
The relative permeability of the wetting phase.
Definition EclStone2Material.hpp:368
static Evaluation krg(const Params &params, const FluidState &fluidState)
The relative permeability of the gas phase.
Definition EclStone2Material.hpp:356
static void relativePermeabilities(ContainerT &values, const Params &params, const FluidState &fluidState)
The relative permeability of all phases.
Definition EclStone2Material.hpp:341
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30