My Project
Loading...
Searching...
No Matches
EclMaterialLawManager.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#if ! HAVE_ECL_INPUT
28#error "Eclipse input support in opm-common is required to use the ECL material manager!"
29#endif
30
31#ifndef OPM_ECL_MATERIAL_LAW_MANAGER_HPP
32#define OPM_ECL_MATERIAL_LAW_MANAGER_HPP
33
34#include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
35
38#include <opm/input/eclipse/EclipseState/WagHysteresisConfig.hpp>
43#include <opm/input/eclipse/EclipseState/Tables/TableColumn.hpp>
44#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
45
46#include <cassert>
47#include <memory>
48#include <tuple>
49#include <vector>
50
51namespace Opm {
52
53class EclipseState;
54class EclEpsConfig;
55class EclEpsGridProperties;
56template<class Scalar> class EclEpsScalingPoints;
57template<class Scalar> struct EclEpsScalingPointsInfo;
58class EclHysteresisConfig;
59enum class EclTwoPhaseSystemType;
60class Runspec;
61class SgfnTable;
62class SgofTable;
63class SlgofTable;
64
71template <class TraitsT>
73{
74private:
75 using Traits = TraitsT;
76 using Scalar = typename Traits::Scalar;
77 enum { waterPhaseIdx = Traits::wettingPhaseIdx };
78 enum { oilPhaseIdx = Traits::nonWettingPhaseIdx };
79 enum { gasPhaseIdx = Traits::gasPhaseIdx };
80 enum { numPhases = Traits::numPhases };
81
85
86 // the two-phase material law which is defined on effective (unscaled) saturations
90
91 using GasOilEffectiveTwoPhaseParams = typename GasOilEffectiveTwoPhaseLaw::Params;
92 using OilWaterEffectiveTwoPhaseParams = typename OilWaterEffectiveTwoPhaseLaw::Params;
93 using GasWaterEffectiveTwoPhaseParams = typename GasWaterEffectiveTwoPhaseLaw::Params;
94
95 // the two-phase material law which is defined on absolute (scaled) saturations
99 using GasOilEpsTwoPhaseParams = typename GasOilEpsTwoPhaseLaw::Params;
100 using OilWaterEpsTwoPhaseParams = typename OilWaterEpsTwoPhaseLaw::Params;
101 using GasWaterEpsTwoPhaseParams = typename GasWaterEpsTwoPhaseLaw::Params;
102
103 // the scaled two-phase material laws with hystersis
107 using GasOilTwoPhaseHystParams = typename GasOilTwoPhaseLaw::Params;
108 using OilWaterTwoPhaseHystParams = typename OilWaterTwoPhaseLaw::Params;
109 using GasWaterTwoPhaseHystParams = typename GasWaterTwoPhaseLaw::Params;
110
111public:
112 // the three-phase material law used by the simulation
114 using MaterialLawParams = typename MaterialLaw::Params;
115 using DirectionalMaterialLawParamsPtr = std::unique_ptr<DirectionalMaterialLawParams<MaterialLawParams>>;
116
119
120private:
121 // internal typedefs
122 using GasOilEffectiveParamVector = std::vector<std::shared_ptr<GasOilEffectiveTwoPhaseParams>>;
123 using OilWaterEffectiveParamVector = std::vector<std::shared_ptr<OilWaterEffectiveTwoPhaseParams>>;
124 using GasWaterEffectiveParamVector = std::vector<std::shared_ptr<GasWaterEffectiveTwoPhaseParams>>;
125
126 using GasOilScalingPointsVector = std::vector<std::shared_ptr<EclEpsScalingPoints<Scalar>>>;
127 using OilWaterScalingPointsVector = std::vector<std::shared_ptr<EclEpsScalingPoints<Scalar>>>;
128 using GasWaterScalingPointsVector = std::vector<std::shared_ptr<EclEpsScalingPoints<Scalar>>>;
129 using OilWaterScalingInfoVector = std::vector<EclEpsScalingPointsInfo<Scalar>>;
130 using GasOilParamVector = std::vector<std::shared_ptr<GasOilTwoPhaseHystParams>>;
131 using OilWaterParamVector = std::vector<std::shared_ptr<OilWaterTwoPhaseHystParams>>;
132 using GasWaterParamVector = std::vector<std::shared_ptr<GasWaterTwoPhaseHystParams>>;
133 using MaterialLawParamsVector = std::vector<std::shared_ptr<MaterialLawParams>>;
134
135 // helper classes
136
137 // This class' implementation is defined in "EclMaterialLawManagerInitParams.cpp"
138 class InitParams {
139 public:
140 InitParams(EclMaterialLawManager<TraitsT>& parent, const EclipseState& eclState, size_t numCompressedElems);
141 void run();
142 private:
143 class HystParams;
144 void copySatnumArrays_();
145 void copyIntArray_(std::vector<int>& dest, const std::string keyword);
146 unsigned imbRegion_(std::vector<int>& array, unsigned elemIdx);
147 void initArrays_(
148 std::vector<std::vector<int>*>& satnumArray,
149 std::vector<std::vector<int>*>& imbnumArray,
150 std::vector<std::vector<MaterialLawParams>*>& mlpArray);
151 void initMaterialLawParamVectors_();
152 void initOilWaterScaledEpsInfo_();
153 void initSatnumRegionArray_();
154 void initThreePhaseParams_(
155 HystParams &hystParams,
156 MaterialLawParams& materialParams,
157 unsigned satRegionIdx,
158 unsigned elemIdx);
159 void readEffectiveParameters_();
160 void readUnscaledEpsPointsVectors_();
161 template <class Container>
162 void readUnscaledEpsPoints_(Container& dest, std::shared_ptr<EclEpsConfig> config, EclTwoPhaseSystemType system_type);
163 unsigned satRegion_(std::vector<int>& array, unsigned elemIdx);
164 unsigned satOrImbRegion_(std::vector<int>& array, std::vector<int>& default_vec, unsigned elemIdx);
165
166 // This class' implementation is defined in "EclMaterialLawManagerHystParams.cpp"
167 class HystParams {
168 public:
169 HystParams(EclMaterialLawManager<TraitsT>::InitParams& init_params);
170 void finalize();
171 std::shared_ptr<GasOilTwoPhaseHystParams> getGasOilParams();
172 std::shared_ptr<OilWaterTwoPhaseHystParams> getOilWaterParams();
173 std::shared_ptr<GasWaterTwoPhaseHystParams> getGasWaterParams();
174 void setConfig(unsigned satRegionIdx);
175 void setDrainageParamsOilGas(unsigned elemIdx, unsigned satRegionIdx);
176 void setDrainageParamsOilWater(unsigned elemIdx, unsigned satRegionIdx);
177 void setDrainageParamsGasWater(unsigned elemIdx, unsigned satRegionIdx);
178 void setImbibitionParamsOilGas(unsigned elemIdx, unsigned satRegionIdx);
179 void setImbibitionParamsOilWater(unsigned elemIdx, unsigned satRegionIdx);
180 void setImbibitionParamsGasWater(unsigned elemIdx, unsigned satRegionIdx);
181 private:
182 bool hasGasWater_();
183 bool hasGasOil_();
184 bool hasOilWater_();
185
186 std::tuple<EclEpsScalingPointsInfo<Scalar>, EclEpsScalingPoints<Scalar>> readScaledEpsPoints_(
187 const EclEpsGridProperties& epsGridProperties, unsigned elemIdx, EclTwoPhaseSystemType type);
188 std::tuple<EclEpsScalingPointsInfo<Scalar>, EclEpsScalingPoints<Scalar>>
189 readScaledEpsPointsDrainage_(unsigned elemIdx, EclTwoPhaseSystemType type);
190 std::tuple<EclEpsScalingPointsInfo<Scalar>, EclEpsScalingPoints<Scalar>>
191 readScaledEpsPointsImbibition_(unsigned elemIdx, EclTwoPhaseSystemType type);
194 const EclipseState& eclState_;
195 std::shared_ptr<GasOilTwoPhaseHystParams> gasOilParams_;
196 std::shared_ptr<OilWaterTwoPhaseHystParams> oilWaterParams_;
197 std::shared_ptr<GasWaterTwoPhaseHystParams> gasWaterParams_;
198 };
199
200 // This class' implementation is defined in "EclMaterialLawManagerReadEffectiveParams.cpp"
201 class ReadEffectiveParams {
202 public:
203 ReadEffectiveParams(EclMaterialLawManager<TraitsT>::InitParams& init_params);
204 void read();
205 private:
206 std::vector<double> normalizeKrValues_(const double tolcrit, const TableColumn& krValues) const;
207 void readGasOilParameters_(GasOilEffectiveParamVector& dest, unsigned satRegionIdx);
208 template <class TableType>
209 void readGasOilFamily2_(
210 GasOilEffectiveTwoPhaseParams& effParams,
211 const Scalar Swco,
212 const double tolcrit,
213 const TableType& sofTable,
214 const SgfnTable& sgfnTable,
215 const std::string& columnName);
216 void readGasOilSgof_(GasOilEffectiveTwoPhaseParams& effParams,
217 const Scalar Swco,
218 const double tolcrit,
219 const SgofTable& sgofTable);
220
221 void readGasOilSlgof_(GasOilEffectiveTwoPhaseParams& effParams,
222 const Scalar Swco,
223 const double tolcrit,
224 const SlgofTable& slgofTable);
225 void readGasWaterParameters_(GasWaterEffectiveParamVector& dest, unsigned satRegionIdx);
226 void readOilWaterParameters_(OilWaterEffectiveParamVector& dest, unsigned satRegionIdx);
227
230 const EclipseState& eclState_;
231 }; // end of "class ReadEffectiveParams"
232
234 const EclipseState& eclState_;
235 size_t numCompressedElems_;
236
237 std::unique_ptr<EclEpsGridProperties> epsImbGridProperties_; //imbibition
238 std::unique_ptr<EclEpsGridProperties> epsGridProperties_; // drainage
239
240 }; // end of "class InitParams"
241
242public:
243 void initFromState(const EclipseState& eclState);
244
245 void initParamsForElements(const EclipseState& eclState, size_t numCompressedElems);
246
255 std::pair<Scalar, bool>
256 applySwatinit(unsigned elemIdx,
257 Scalar pcow,
258 Scalar Sw);
259
260 bool enableEndPointScaling() const
261 { return enableEndPointScaling_; }
262
263 bool enablePpcwmax() const
264 { return enablePpcwmax_; }
265
266 bool enableHysteresis() const
267 { return hysteresisConfig_->enableHysteresis(); }
268
269 MaterialLawParams& materialLawParams(unsigned elemIdx)
270 {
271 assert(elemIdx < materialLawParams_.size());
272 return materialLawParams_[elemIdx];
273 }
274
275 const MaterialLawParams& materialLawParams(unsigned elemIdx) const
276 {
277 assert(elemIdx < materialLawParams_.size());
278 return materialLawParams_[elemIdx];
279 }
280
281 const MaterialLawParams& materialLawParams(unsigned elemIdx, FaceDir::DirEnum facedir) const
282 {
283 return materialLawParamsFunc_(elemIdx, facedir);
284 }
285
286 MaterialLawParams& materialLawParams(unsigned elemIdx, FaceDir::DirEnum facedir)
287 {
288 return const_cast<MaterialLawParams&>(materialLawParamsFunc_(elemIdx, facedir));
289 }
290
299 const MaterialLawParams& connectionMaterialLawParams(unsigned satRegionIdx, unsigned elemIdx) const;
300
301 int satnumRegionIdx(unsigned elemIdx) const
302 { return satnumRegionArray_[elemIdx]; }
303
304 int getKrnumSatIdx(unsigned elemIdx, FaceDir::DirEnum facedir) const;
305
306 bool hasDirectionalRelperms() const
307 {
308 return !krnumXArray_.empty() || !krnumYArray_.empty() || !krnumZArray_.empty();
309 }
310
311 bool hasDirectionalImbnum() const {
312 if (imbnumXArray_.size() > 0 || imbnumYArray_.size() > 0 || imbnumZArray_.size() > 0) {
313 return true;
314 }
315 return false;
316 }
317
318 int imbnumRegionIdx(unsigned elemIdx) const
319 { return imbnumRegionArray_[elemIdx]; }
320
321 template <class FluidState>
322 bool updateHysteresis(const FluidState& fluidState, unsigned elemIdx)
323 {
324 OPM_TIMEFUNCTION_LOCAL();
325 if (!enableHysteresis())
326 return false;
327 bool changed = MaterialLaw::updateHysteresis(materialLawParams(elemIdx), fluidState);
328 if (hasDirectionalRelperms() || hasDirectionalImbnum()) {
329 using Dir = FaceDir::DirEnum;
330 constexpr int ndim = 3;
331 Dir facedirs[ndim] = {Dir::XPlus, Dir::YPlus, Dir::ZPlus};
332 for (int i = 0; i<ndim; i++) {
333 bool ischanged = MaterialLaw::updateHysteresis(materialLawParams(elemIdx, facedirs[i]), fluidState);
334 changed = changed || ischanged;
335 }
336 }
337 return changed;
338 }
339
340 void oilWaterHysteresisParams(Scalar& pcSwMdc,
341 Scalar& krnSwMdc,
342 unsigned elemIdx) const;
343
344 void setOilWaterHysteresisParams(const Scalar& pcSwMdc,
345 const Scalar& krnSwMdc,
346 unsigned elemIdx);
347
348 void gasOilHysteresisParams(Scalar& pcSwMdc,
349 Scalar& krnSwMdc,
350 unsigned elemIdx) const;
351
352 void setGasOilHysteresisParams(const Scalar& pcSwMdc,
353 const Scalar& krnSwMdc,
354 unsigned elemIdx);
355
356 EclEpsScalingPoints<Scalar>& oilWaterScaledEpsPointsDrainage(unsigned elemIdx);
357
358 const EclEpsScalingPointsInfo<Scalar>& oilWaterScaledEpsInfoDrainage(size_t elemIdx) const
359 { return oilWaterScaledEpsInfoDrainage_[elemIdx]; }
360
361 template<class Serializer>
362 void serializeOp(Serializer& serializer)
363 {
364 // This is for restart serialization.
365 // Only dynamic state in the parameters need to be stored.
366 // For that reason we do not serialize the vector
367 // as that would recreate the objects inside.
368 for (auto& mat : materialLawParams_) {
369 serializer(mat);
370 }
371 }
372
373private:
374 const MaterialLawParams& materialLawParamsFunc_(unsigned elemIdx, FaceDir::DirEnum facedir) const;
375
376 void readGlobalEpsOptions_(const EclipseState& eclState);
377
378 void readGlobalHysteresisOptions_(const EclipseState& state);
379
380 void readGlobalThreePhaseOptions_(const Runspec& runspec);
381
382 bool enableEndPointScaling_;
383 std::shared_ptr<EclHysteresisConfig> hysteresisConfig_;
384 std::vector<std::shared_ptr<WagHysteresisConfig::WagHysteresisConfigRecord>> wagHystersisConfig_;
385
386
387 std::shared_ptr<EclEpsConfig> oilWaterEclEpsConfig_;
388 std::vector<EclEpsScalingPointsInfo<Scalar>> unscaledEpsInfo_;
389 OilWaterScalingInfoVector oilWaterScaledEpsInfoDrainage_;
390
391 std::shared_ptr<EclEpsConfig> gasWaterEclEpsConfig_;
392
393 GasOilScalingPointsVector gasOilUnscaledPointsVector_;
394 OilWaterScalingPointsVector oilWaterUnscaledPointsVector_;
395 GasWaterScalingPointsVector gasWaterUnscaledPointsVector_;
396
397 GasOilEffectiveParamVector gasOilEffectiveParamVector_;
398 OilWaterEffectiveParamVector oilWaterEffectiveParamVector_;
399 GasWaterEffectiveParamVector gasWaterEffectiveParamVector_;
400
401 EclMultiplexerApproach threePhaseApproach_ = EclMultiplexerApproach::Default;
402 // this attribute only makes sense for twophase simulations!
403 enum EclTwoPhaseApproach twoPhaseApproach_ = EclTwoPhaseApproach::GasOil;
404
405 std::vector<MaterialLawParams> materialLawParams_;
406 DirectionalMaterialLawParamsPtr dirMaterialLawParams_;
407
408 std::vector<int> satnumRegionArray_;
409 std::vector<int> krnumXArray_;
410 std::vector<int> krnumYArray_;
411 std::vector<int> krnumZArray_;
412 std::vector<int> imbnumXArray_;
413 std::vector<int> imbnumYArray_;
414 std::vector<int> imbnumZArray_;
415 std::vector<int> imbnumRegionArray_;
416 std::vector<Scalar> stoneEtas_;
417
418 bool enablePpcwmax_;
419 std::vector<Scalar> maxAllowPc_;
420 std::vector<bool> modifySwl_;
421
422 bool hasGas;
423 bool hasOil;
424 bool hasWater;
425
426 std::shared_ptr<EclEpsConfig> gasOilConfig_;
427 std::shared_ptr<EclEpsConfig> oilWaterConfig_;
428 std::shared_ptr<EclEpsConfig> gasWaterConfig_;
429};
430} // namespace Opm
431
432#endif
This file contains definitions related to directional material law parameters.
This material law takes a material law defined for unscaled saturation and converts it to a material ...
This material law implements the hysteresis model of the ECL file format.
Implements a multiplexer class that provides all three phase capillary pressure laws used by the ECLi...
This file contains helper classes for the material laws.
Implements a multiplexer class that provides LET curves and piecewise linear saturation functions.
Collects all grid properties which are relevant for end point scaling.
Definition EclEpsGridProperties.hpp:47
Represents the points on the X and Y axis to be scaled if endpoint scaling is used.
Definition EclEpsScalingPoints.hpp:166
This material law takes a material law defined for unscaled saturation and converts it to a material ...
Definition EclEpsTwoPhaseLaw.hpp:51
This material law implements the hysteresis model of the ECL file format.
Definition EclHysteresisTwoPhaseLaw.hpp:44
Provides an simple way to create and manage the material law objects for a complete ECL deck.
Definition EclMaterialLawManager.hpp:73
const MaterialLawParams & connectionMaterialLawParams(unsigned satRegionIdx, unsigned elemIdx) const
Returns a material parameter object for a given element and saturation region.
std::pair< Scalar, bool > applySwatinit(unsigned elemIdx, Scalar pcow, Scalar Sw)
Modify the initial condition according to the SWATINIT keyword.
Implements a multiplexer class that provides all three phase capillary pressure laws used by the ECLi...
Definition EclMultiplexerMaterial.hpp:58
static bool updateHysteresis(Params &params, const FluidState &fluidState)
Update the hysteresis parameters after a time step.
Definition EclMultiplexerMaterial.hpp:575
Definition EclipseState.hpp:57
Implements a multiplexer class that provides LET curves and piecewise linear saturation functions.
Definition SatCurveMultiplexer.hpp:44
Definition SgfnTable.hpp:28
Definition SgofTable.hpp:27
Definition SlgofTable.hpp:28
Definition TableColumn.hpp:32
A generic traits class for two-phase material laws.
Definition MaterialTraits.hpp:61
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
EclTwoPhaseSystemType
Specified which fluids are involved in a given twophase material law for endpoint scaling.
Definition EclEpsConfig.hpp:42