1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
|
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
Copyright 2022 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
#include <opm/material/fluidmatrixinteractions/EclEpsGridProperties.hpp>
namespace Opm {
/* constructors*/
template <class Traits>
EclMaterialLawManager<Traits>::InitParams::
InitParams(EclMaterialLawManager<Traits>& parent, const EclipseState& eclState, size_t numCompressedElems) :
parent_{parent},
eclState_{eclState},
numCompressedElems_{numCompressedElems}
{
// read end point scaling grid properties
// TODO: these objects might require some memory, can this be simplified?
if (this->parent_.enableHysteresis()) {
this->epsImbGridProperties_
= std::make_unique<EclEpsGridProperties>(this->eclState_, /*useImbibition=*/true);
}
this->epsGridProperties_
= std::make_unique<EclEpsGridProperties>(this->eclState_, /*useImbibition=*/false);
}
/* public methods */
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
run(const std::function<std::vector<int>(const FieldPropsManager&, const std::string&, bool)>&
fieldPropIntOnLeafAssigner,
const std::function<unsigned(unsigned)>& lookupIdxOnLevelZeroAssigner) {
readUnscaledEpsPointsVectors_();
readEffectiveParameters_();
initSatnumRegionArray_(fieldPropIntOnLeafAssigner);
copySatnumArrays_(fieldPropIntOnLeafAssigner);
initOilWaterScaledEpsInfo_();
initMaterialLawParamVectors_();
std::vector<std::vector<int>*> satnumArray;
std::vector<std::vector<int>*> imbnumArray;
std::vector<std::vector<MaterialLawParams>*> mlpArray;
initArrays_(satnumArray, imbnumArray, mlpArray);
auto num_arrays = mlpArray.size();
for (unsigned i=0; i<num_arrays; i++) {
for (unsigned elemIdx = 0; elemIdx < this->numCompressedElems_; ++elemIdx) {
unsigned satRegionIdx = satRegion_(*satnumArray[i], elemIdx);
//unsigned satNumCell = this->parent_.satnumRegionArray_[elemIdx];
HystParams hystParams {*this};
hystParams.setConfig(satRegionIdx);
hystParams.setDrainageParamsOilGas(elemIdx, satRegionIdx, lookupIdxOnLevelZeroAssigner);
hystParams.setDrainageParamsOilWater(elemIdx, satRegionIdx, lookupIdxOnLevelZeroAssigner);
hystParams.setDrainageParamsGasWater(elemIdx, satRegionIdx, lookupIdxOnLevelZeroAssigner);
if (this->parent_.enableHysteresis()) {
unsigned imbRegionIdx = imbRegion_(*imbnumArray[i], elemIdx);
hystParams.setImbibitionParamsOilGas(elemIdx, imbRegionIdx, lookupIdxOnLevelZeroAssigner);
hystParams.setImbibitionParamsOilWater(elemIdx, imbRegionIdx, lookupIdxOnLevelZeroAssigner);
hystParams.setImbibitionParamsGasWater(elemIdx, imbRegionIdx, lookupIdxOnLevelZeroAssigner);
}
hystParams.finalize();
initThreePhaseParams_(hystParams, (*mlpArray[i])[elemIdx], satRegionIdx, elemIdx);
}
}
}
/* private methods alphabetically sorted*/
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
copySatnumArrays_(const std::function<std::vector<int>(const FieldPropsManager&, const std::string&, bool)>& fieldPropIntOnLeafAssigner)
{
copyIntArray_(this->parent_.krnumXArray_, "KRNUMX", fieldPropIntOnLeafAssigner);
copyIntArray_(this->parent_.krnumYArray_, "KRNUMY", fieldPropIntOnLeafAssigner);
copyIntArray_(this->parent_.krnumZArray_, "KRNUMZ", fieldPropIntOnLeafAssigner);
copyIntArray_(this->parent_.imbnumXArray_, "IMBNUMX", fieldPropIntOnLeafAssigner);
copyIntArray_(this->parent_.imbnumYArray_, "IMBNUMY", fieldPropIntOnLeafAssigner);
copyIntArray_(this->parent_.imbnumZArray_, "IMBNUMZ", fieldPropIntOnLeafAssigner);
// create the information for the imbibition region (IMBNUM). By default this is
// the same as the saturation region (SATNUM)
this->parent_.imbnumRegionArray_ = this->parent_.satnumRegionArray_;
copyIntArray_(this->parent_.imbnumRegionArray_, "IMBNUM", fieldPropIntOnLeafAssigner);
assert(this->numCompressedElems_ == this->parent_.satnumRegionArray_.size());
assert(!this->parent_.enableHysteresis() || this->numCompressedElems_ == this->parent_.imbnumRegionArray_.size());
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
copyIntArray_(std::vector<int>& dest, const std::string& keyword,
const std::function<std::vector<int>(const FieldPropsManager&, const std::string&, bool)>& fieldPropIntOnLeafAssigner)
{
if (this->eclState_.fieldProps().has_int(keyword)) {
dest = fieldPropIntOnLeafAssigner(this->eclState_.fieldProps(), keyword, /*needsTranslation*/true);
}
}
template <class Traits>
unsigned
EclMaterialLawManager<Traits>::InitParams::
imbRegion_(std::vector<int>& array, unsigned elemIdx)
{
std::vector<int>& default_vec = this->parent_.imbnumRegionArray_;
return satOrImbRegion_(array, default_vec, elemIdx);
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
initArrays_(
std::vector<std::vector<int>*>& satnumArray,
std::vector<std::vector<int>*>& imbnumArray,
std::vector<std::vector<MaterialLawParams>*>& mlpArray)
{
satnumArray.push_back(&this->parent_.satnumRegionArray_);
imbnumArray.push_back(&this->parent_.imbnumRegionArray_);
mlpArray.push_back(&this->parent_.materialLawParams_);
if (this->parent_.dirMaterialLawParams_) {
if (this->parent_.hasDirectionalRelperms()) {
satnumArray.push_back(&this->parent_.krnumXArray_);
satnumArray.push_back(&this->parent_.krnumYArray_);
satnumArray.push_back(&this->parent_.krnumZArray_);
}
if (this->parent_.hasDirectionalImbnum()) {
imbnumArray.push_back(&this->parent_.imbnumXArray_);
imbnumArray.push_back(&this->parent_.imbnumYArray_);
imbnumArray.push_back(&this->parent_.imbnumZArray_);
}
mlpArray.push_back(&(this->parent_.dirMaterialLawParams_->materialLawParamsX_));
mlpArray.push_back(&(this->parent_.dirMaterialLawParams_->materialLawParamsY_));
mlpArray.push_back(&(this->parent_.dirMaterialLawParams_->materialLawParamsZ_));
}
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
initMaterialLawParamVectors_()
{
this->parent_.materialLawParams_.resize(this->numCompressedElems_);
if (this->parent_.hasDirectionalImbnum() || this->parent_.hasDirectionalRelperms()) {
this->parent_.dirMaterialLawParams_
= std::make_unique<DirectionalMaterialLawParams<MaterialLawParams>>(this->numCompressedElems_);
}
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
initOilWaterScaledEpsInfo_()
{
// This vector will be updated in the hystParams.setDrainageOilWater() in the run() method
this->parent_.oilWaterScaledEpsInfoDrainage_.resize(this->numCompressedElems_);
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
initSatnumRegionArray_(const std::function<std::vector<int>(const FieldPropsManager&, const std::string&, bool)>& fieldPropIntOnLeafAssigner)
{
// copy the SATNUM grid property. in some cases this is not necessary, but it
// should not require much memory anyway...
auto &satnumArray = this->parent_.satnumRegionArray_;
satnumArray.resize(this->numCompressedElems_);
if (this->eclState_.fieldProps().has_int("SATNUM")) {
satnumArray = fieldPropIntOnLeafAssigner(this->eclState_.fieldProps(), "SATNUM", /*needsTranslation*/true);
}
else {
std::fill(satnumArray.begin(), satnumArray.end(), 0);
}
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
initThreePhaseParams_(HystParams &hystParams,
MaterialLawParams& materialParams,
unsigned satRegionIdx,
unsigned elemIdx)
{
const auto& epsInfo = this->parent_.oilWaterScaledEpsInfoDrainage_[elemIdx];
auto oilWaterParams = hystParams.getOilWaterParams();
auto gasOilParams = hystParams.getGasOilParams();
auto gasWaterParams = hystParams.getGasWaterParams();
materialParams.setApproach(this->parent_.threePhaseApproach_);
switch (materialParams.approach()) {
case EclMultiplexerApproach::Stone1: {
auto& realParams = materialParams.template getRealParams<EclMultiplexerApproach::Stone1>();
realParams.setGasOilParams(gasOilParams);
realParams.setOilWaterParams(oilWaterParams);
realParams.setSwl(epsInfo.Swl);
if (!this->parent_.stoneEtas_.empty()) {
realParams.setEta(this->parent_.stoneEtas_[satRegionIdx]);
}
else
realParams.setEta(1.0);
realParams.finalize();
break;
}
case EclMultiplexerApproach::Stone2: {
auto& realParams = materialParams.template getRealParams<EclMultiplexerApproach::Stone2>();
realParams.setGasOilParams(gasOilParams);
realParams.setOilWaterParams(oilWaterParams);
realParams.setSwl(epsInfo.Swl);
realParams.finalize();
break;
}
case EclMultiplexerApproach::Default: {
auto& realParams = materialParams.template getRealParams<EclMultiplexerApproach::Default>();
realParams.setGasOilParams(gasOilParams);
realParams.setOilWaterParams(oilWaterParams);
realParams.setSwl(epsInfo.Swl);
realParams.finalize();
break;
}
case EclMultiplexerApproach::TwoPhase: {
auto& realParams = materialParams.template getRealParams<EclMultiplexerApproach::TwoPhase>();
realParams.setGasOilParams(gasOilParams);
realParams.setOilWaterParams(oilWaterParams);
realParams.setGasWaterParams(gasWaterParams);
realParams.setApproach(this->parent_.twoPhaseApproach_);
realParams.finalize();
break;
}
case EclMultiplexerApproach::OnePhase: {
// Nothing to do, no parameters.
break;
}
} // end switch()
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
readEffectiveParameters_()
{
ReadEffectiveParams effectiveReader {*this};
// populates effective parameter vectors in the parent class (EclMaterialManager)
effectiveReader.read();
}
template <class Traits>
void
EclMaterialLawManager<Traits>::InitParams::
readUnscaledEpsPointsVectors_()
{
if (this->parent_.hasGas && this->parent_.hasOil) {
readUnscaledEpsPoints_(
this->parent_.gasOilUnscaledPointsVector_,
this->parent_.gasOilConfig_,
EclTwoPhaseSystemType::GasOil
);
}
if (this->parent_.hasOil && this->parent_.hasWater) {
readUnscaledEpsPoints_(
this->parent_.oilWaterUnscaledPointsVector_,
this->parent_.oilWaterConfig_,
EclTwoPhaseSystemType::OilWater
);
}
if (!this->parent_.hasOil) {
readUnscaledEpsPoints_(
this->parent_.gasWaterUnscaledPointsVector_,
this->parent_.gasWaterConfig_,
EclTwoPhaseSystemType::GasWater
);
}
}
template <class Traits>
template <class Container>
void
EclMaterialLawManager<Traits>::InitParams::
readUnscaledEpsPoints_(Container& dest, std::shared_ptr<EclEpsConfig> config, EclTwoPhaseSystemType system_type)
{
const size_t numSatRegions = this->eclState_.runspec().tabdims().getNumSatTables();
dest.resize(numSatRegions);
for (unsigned satRegionIdx = 0; satRegionIdx < numSatRegions; ++satRegionIdx) {
dest[satRegionIdx] = std::make_shared<EclEpsScalingPoints<Scalar> >();
dest[satRegionIdx]->init(this->parent_.unscaledEpsInfo_[satRegionIdx], *config, system_type);
}
}
template <class Traits>
unsigned
EclMaterialLawManager<Traits>::InitParams::
satRegion_(std::vector<int>& array, unsigned elemIdx)
{
std::vector<int>& default_vec = this->parent_.satnumRegionArray_;
return satOrImbRegion_(array, default_vec, elemIdx);
}
template <class Traits>
unsigned
EclMaterialLawManager<Traits>::InitParams::
satOrImbRegion_(std::vector<int>& array, std::vector<int>& default_vec, unsigned elemIdx)
{
int value;
if (array.size() > 0) {
value = array[elemIdx];
}
else { // use default value
value = default_vec[elemIdx];
}
return static_cast<unsigned>(value);
}
// Make some actual code, by realizing the previously defined templated class
template class EclMaterialLawManager<ThreePhaseMaterialTraits<double,0,1,2>>::InitParams;
template class EclMaterialLawManager<ThreePhaseMaterialTraits<float,0,1,2>>::InitParams;
} // namespace Opm
|