23#ifndef OPM_INIT_STATE_EQUIL_IMPL_HPP
24#define OPM_INIT_STATE_EQUIL_IMPL_HPP
26#include <dune/grid/common/mcmgmapper.hh>
28#include <opm/common/OpmLog/OpmLog.hpp>
30#include <opm/grid/utility/RegionMapping.hpp>
32#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
33#include <opm/input/eclipse/EclipseState/Tables/RsvdTable.hpp>
34#include <opm/input/eclipse/EclipseState/Tables/RvvdTable.hpp>
35#include <opm/input/eclipse/EclipseState/Tables/RvwvdTable.hpp>
36#include <opm/input/eclipse/EclipseState/Tables/PbvdTable.hpp>
37#include <opm/input/eclipse/EclipseState/Tables/PdvdTable.hpp>
38#include <opm/input/eclipse/EclipseState/Tables/SaltvdTable.hpp>
39#include <opm/input/eclipse/EclipseState/Tables/RtempvdTable.hpp>
41#include <opm/input/eclipse/EclipseState/Tables/SaltpvdTable.hpp>
43#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
44#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
50#include <fmt/format.h>
64template <
typename CellRange,
class Scalar>
66 const std::vector<std::pair<Scalar, Scalar>>&
cellZMinMax,
68 std::array<Scalar,2>& span)
70 span[0] = std::numeric_limits<Scalar>::max();
71 span[1] = std::numeric_limits<Scalar>::lowest();
81 for (
const auto& cell : cells) {
85 span[0] = comm.min(span[0]);
86 span[1] = comm.max(span[1]);
92 const int numIntervals,
93 std::vector<std::pair<Scalar, Scalar>>& subdiv)
95 const auto h = (right - left) / numIntervals;
98 for (
auto i = 0*numIntervals; i < numIntervals; ++i) {
99 const auto start = end;
100 end = left + (i + 1)*h;
102 subdiv.emplace_back((start + end) / 2, h);
106template <
typename CellID,
typename Scalar>
107std::vector<std::pair<Scalar, Scalar>>
109 const std::pair<Scalar, Scalar> topbot,
110 const int numIntervals)
112 auto subdiv = std::vector<std::pair<Scalar, Scalar>>{};
113 subdiv.reserve(2 * numIntervals);
115 if (topbot.first > topbot.second) {
116 throw std::out_of_range {
117 "Negative thickness (inverted top/bottom faces) in cell "
123 2*numIntervals, subdiv);
128template <
class Scalar,
class Element>
131 typedef typename Element::Geometry Geometry;
132 static constexpr int zCoord = Element::dimension - 1;
135 const Geometry& geometry = element.geometry();
136 const int corners = geometry.corners();
137 for (
int i=0; i < corners; ++i)
138 zz += geometry.corner(i)[zCoord];
143template <
class Scalar,
class Element>
146 typedef typename Element::Geometry Geometry;
147 static constexpr int xCoord = Element::dimension - 3;
148 static constexpr int yCoord = Element::dimension - 2;
153 const Geometry& geometry = element.geometry();
154 const int corners = geometry.corners();
155 for (
int i=0; i < corners; ++i) {
156 xx += geometry.corner(i)[xCoord];
157 yy += geometry.corner(i)[yCoord];
159 return std::make_pair(xx/corners, yy/corners);
162template <
class Scalar,
class Element>
163std::pair<Scalar,Scalar>
cellZSpan(
const Element& element)
165 typedef typename Element::Geometry Geometry;
166 static constexpr int zCoord = Element::dimension - 1;
170 const Geometry& geometry = element.geometry();
171 const int corners = geometry.corners();
172 assert(corners == 8);
173 for (
int i=0; i < 4; ++i)
174 bot += geometry.corner(i)[zCoord];
175 for (
int i=4; i < corners; ++i)
176 top += geometry.corner(i)[zCoord];
178 return std::make_pair(bot/4, top/4);
181template <
class Scalar,
class Element>
184 typedef typename Element::Geometry Geometry;
185 static constexpr int zCoord = Element::dimension - 1;
186 const Geometry& geometry = element.geometry();
187 const int corners = geometry.corners();
188 assert(corners == 8);
189 auto min = std::numeric_limits<Scalar>::max();
190 auto max = std::numeric_limits<Scalar>::lowest();
193 for (
int i=0; i < corners; ++i) {
194 min = std::min(min,
static_cast<Scalar
>(geometry.corner(i)[zCoord]));
195 max = std::max(max,
static_cast<Scalar
>(geometry.corner(i)[zCoord]));
197 return std::make_pair(min, max);
200template<
class Scalar>
202 Scalar& dipAngle, Scalar& dipAzimuth)
204 const auto& Xc = cellCorners.
X;
205 const auto& Yc = cellCorners.
Y;
206 const auto& Zc = cellCorners.
Z;
208 Scalar v1x = Xc[1] - Xc[0];
209 Scalar v1y = Yc[1] - Yc[0];
210 Scalar v1z = Zc[1] - Zc[0];
212 Scalar v2x = Xc[2] - Xc[0];
213 Scalar v2y = Yc[2] - Yc[0];
214 Scalar v2z = Zc[2] - Zc[0];
217 Scalar nx = v1y * v2z - v1z * v2y;
218 Scalar ny = v1z * v2x - v1x * v2z;
219 Scalar nz = v1x * v2y - v1y * v2x;
222 Scalar norm = std::hypot(nx, ny, nz);
230 dipAngle = std::acos(std::abs(nz));
233 if (std::abs(nx) > 1e-10 || std::abs(ny) > 1e-10) {
234 dipAzimuth = std::atan2(ny, nx);
236 dipAzimuth = std::fmod(dipAzimuth + 2*M_PI, 2*M_PI);
242 const Scalar maxDip = M_PI/2 - 1e-6;
243 dipAngle = std::min(dipAngle, maxDip);
251template <
class Scalar,
class Element>
254 typedef typename Element::Geometry Geometry;
255 const Geometry& geometry = element.geometry();
256 static constexpr int zCoord = Element::dimension - 1;
257 static constexpr int yCoord = Element::dimension - 2;
258 static constexpr int xCoord = Element::dimension - 3;
259 const int corners = geometry.corners();
260 assert(corners == 8);
261 std::array<Scalar, 8> X {};
262 std::array<Scalar, 8> Y {};
263 std::array<Scalar, 8> Z {};
265 for (
int i = 0; i < corners; ++i) {
266 auto corner = geometry.corner(i);
267 X[i] = corner[xCoord];
268 Y[i] = corner[yCoord];
269 Z[i] = corner[zCoord];
275template<
class Scalar>
277 Scalar dipAngle, Scalar dipAzimuth,
278 const std::array<Scalar, 3>& referencePoint)
285 Scalar dx = x - referencePoint[0];
286 Scalar dy = y - referencePoint[1];
287 Scalar dz = z - referencePoint[2];
290 if (std::abs(dipAngle) < 1e-10) {
291 return referencePoint[2] + dz;
295 Scalar pointAzimuth = std::atan2(dy, dx);
298 Scalar azimuthDiff = pointAzimuth - dipAzimuth;
301 Scalar lateralDist = std::hypot(dx, dy);
304 Scalar lateralInDipDir = lateralDist * std::cos(azimuthDiff);
309 Scalar tvd = referencePoint[2] + dz * std::cos(dipAngle) + lateralInDipDir * std::sin(dipAngle);
314template<
class Scalar,
class RHS>
316 const std::array<Scalar,2>& span,
322 const Scalar h = stepsize();
323 const Scalar h2 = h / 2;
324 const Scalar h6 = h / 6;
330 f_.push_back(f(span_[0], y0));
332 for (
int i = 0; i < N; ++i) {
333 const Scalar x = span_[0] + i*h;
334 const Scalar y = y_.back();
336 const Scalar k1 = f_[i];
337 const Scalar k2 = f(x + h2, y + h2*k1);
338 const Scalar k3 = f(x + h2, y + h2*k2);
339 const Scalar k4 = f(x + h, y + h*k3);
341 y_.push_back(y + h6*(k1 + 2*(k2 + k3) + k4));
342 f_.push_back(f(x + h, y_.back()));
345 assert (y_.size() ==
typename std::vector<Scalar>::size_type(N + 1));
348template<
class Scalar,
class RHS>
354 const Scalar h = stepsize();
355 int i = (x - span_[0]) / h;
356 const Scalar t = (x - (span_[0] + i*h)) / h;
359 if (i < 0) { i = 0; }
360 if (N_ <= i) { i = N_ - 1; }
362 const Scalar y0 = y_[i], y1 = y_[i + 1];
363 const Scalar f0 = f_[i], f1 = f_[i + 1];
365 Scalar u = (1 - 2*t) * (y1 - y0);
366 u += h * ((t - 1)*f0 + t*f1);
368 u += (1 - t)*y0 + t*y1;
373template<
class Scalar,
class RHS>
377 return (span_[1] - span_[0]) / N_;
380namespace PhasePressODE {
382template<
class Flu
idSystem>
384Water(
const TabulatedFunction& tempVdTable,
385 const TabulatedFunction& saltVdTable,
386 const int pvtRegionIdx,
387 const Scalar normGrav)
388 : tempVdTable_(tempVdTable)
389 , saltVdTable_(saltVdTable)
390 , pvtRegionIdx_(pvtRegionIdx)
395template<
class Flu
idSystem>
396typename Water<FluidSystem>::Scalar
399 const Scalar press)
const
401 return this->density(depth, press) * g_;
404template<
class Flu
idSystem>
405typename Water<FluidSystem>::Scalar
408 const Scalar press)
const
411 Scalar saltConcentration = saltVdTable_.eval(depth,
true);
412 Scalar temp = tempVdTable_.eval(depth,
true);
413 Scalar rho = FluidSystem::waterPvt().inverseFormationVolumeFactor(pvtRegionIdx_,
418 rho *= FluidSystem::referenceDensity(FluidSystem::waterPhaseIdx, pvtRegionIdx_);
422template<
class Flu
idSystem,
class RS>
424Oil(
const TabulatedFunction& tempVdTable,
426 const int pvtRegionIdx,
427 const Scalar normGrav)
428 : tempVdTable_(tempVdTable)
430 , pvtRegionIdx_(pvtRegionIdx)
435template<
class Flu
idSystem,
class RS>
436typename Oil<FluidSystem,RS>::Scalar
439 const Scalar press)
const
441 return this->density(depth, press) * g_;
444template<
class Flu
idSystem,
class RS>
445typename Oil<FluidSystem,RS>::Scalar
448 const Scalar press)
const
450 const Scalar temp = tempVdTable_.eval(depth,
true);
452 if (FluidSystem::enableDissolvedGas())
453 rs = rs_(depth, press, temp);
456 if (rs >= FluidSystem::oilPvt().saturatedGasDissolutionFactor(pvtRegionIdx_, temp, press)) {
457 bOil = FluidSystem::oilPvt().saturatedInverseFormationVolumeFactor(pvtRegionIdx_, temp, press);
460 bOil = FluidSystem::oilPvt().inverseFormationVolumeFactor(pvtRegionIdx_, temp, press, rs);
462 Scalar rho = bOil * FluidSystem::referenceDensity(FluidSystem::oilPhaseIdx, pvtRegionIdx_);
463 if (FluidSystem::enableDissolvedGas()) {
464 rho += rs * bOil * FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, pvtRegionIdx_);
470template<
class Flu
idSystem,
class RV,
class RVW>
472Gas(
const TabulatedFunction& tempVdTable,
475 const int pvtRegionIdx,
476 const Scalar normGrav)
477 : tempVdTable_(tempVdTable)
480 , pvtRegionIdx_(pvtRegionIdx)
485template<
class Flu
idSystem,
class RV,
class RVW>
486typename Gas<FluidSystem,RV,RVW>::Scalar
489 const Scalar press)
const
491 return this->density(depth, press) * g_;
494template<
class Flu
idSystem,
class RV,
class RVW>
495typename Gas<FluidSystem,RV,RVW>::Scalar
498 const Scalar press)
const
500 const Scalar temp = tempVdTable_.eval(depth,
true);
502 if (FluidSystem::enableVaporizedOil())
503 rv = rv_(depth, press, temp);
506 if (FluidSystem::enableVaporizedWater())
507 rvw = rvw_(depth, press, temp);
511 if (FluidSystem::enableVaporizedOil() && FluidSystem::enableVaporizedWater()) {
512 if (rv >= FluidSystem::gasPvt().saturatedOilVaporizationFactor(pvtRegionIdx_, temp, press)
513 && rvw >= FluidSystem::gasPvt().saturatedWaterVaporizationFactor(pvtRegionIdx_, temp, press))
515 bGas = FluidSystem::gasPvt().saturatedInverseFormationVolumeFactor(pvtRegionIdx_, temp, press);
517 bGas = FluidSystem::gasPvt().inverseFormationVolumeFactor(pvtRegionIdx_, temp, press, rv, rvw);
519 Scalar rho = bGas * FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, pvtRegionIdx_);
520 rho += rv * bGas * FluidSystem::referenceDensity(FluidSystem::oilPhaseIdx, pvtRegionIdx_)
521 + rvw * bGas * FluidSystem::referenceDensity(FluidSystem::waterPhaseIdx, pvtRegionIdx_);
525 if (FluidSystem::enableVaporizedOil()){
526 if (rv >= FluidSystem::gasPvt().saturatedOilVaporizationFactor(pvtRegionIdx_, temp, press)) {
527 bGas = FluidSystem::gasPvt().saturatedInverseFormationVolumeFactor(pvtRegionIdx_, temp, press);
529 bGas = FluidSystem::gasPvt().inverseFormationVolumeFactor(pvtRegionIdx_,
535 Scalar rho = bGas * FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, pvtRegionIdx_);
536 rho += rv * bGas * FluidSystem::referenceDensity(FluidSystem::oilPhaseIdx, pvtRegionIdx_);
540 if (FluidSystem::enableVaporizedWater()){
541 if (rvw >= FluidSystem::gasPvt().saturatedWaterVaporizationFactor(pvtRegionIdx_, temp, press)) {
542 bGas = FluidSystem::gasPvt().saturatedInverseFormationVolumeFactor(pvtRegionIdx_, temp, press);
545 bGas = FluidSystem::gasPvt().inverseFormationVolumeFactor(pvtRegionIdx_,
551 Scalar rho = bGas * FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, pvtRegionIdx_);
552 rho += rvw * bGas * FluidSystem::referenceDensity(FluidSystem::waterPhaseIdx, pvtRegionIdx_);
557 bGas = FluidSystem::gasPvt().inverseFormationVolumeFactor(pvtRegionIdx_, temp,
561 Scalar rho = bGas * FluidSystem::referenceDensity(FluidSystem::gasPhaseIdx, pvtRegionIdx_);
568template<
class Flu
idSystem,
class Region>
570PressureTable<FluidSystem,Region>::
571PressureFunction<ODE>::PressureFunction(
const ODE& ode,
577 this->value_[Direction::Up] = std::make_unique<Distribution>
578 (ode, VSpan {{ ic.depth, span[0] }}, ic.pressure, nsample);
580 this->value_[Direction::Down] = std::make_unique<Distribution>
581 (ode, VSpan {{ ic.depth, span[1] }}, ic.pressure, nsample);
584template<
class Flu
idSystem,
class Region>
586PressureTable<FluidSystem,Region>::
587PressureFunction<ODE>::PressureFunction(
const PressureFunction& rhs)
588 : initial_(rhs.initial_)
590 this->value_[Direction::Up] =
591 std::make_unique<Distribution>(*rhs.value_[Direction::Up]);
593 this->value_[Direction::Down] =
594 std::make_unique<Distribution>(*rhs.value_[Direction::Down]);
597template<
class Flu
idSystem,
class Region>
599typename PressureTable<FluidSystem,Region>::template PressureFunction<ODE>&
604 this->initial_ = rhs.initial_;
606 this->value_[Direction::Up] =
607 std::make_unique<Distribution>(*rhs.value_[Direction::Up]);
609 this->value_[Direction::Down] =
610 std::make_unique<Distribution>(*rhs.value_[Direction::Down]);
615template<
class Flu
idSystem,
class Region>
617typename PressureTable<FluidSystem,Region>::template PressureFunction<ODE>&
622 this->initial_ = rhs.initial_;
623 this->value_ = std::move(rhs.value_);
628template<
class Flu
idSystem,
class Region>
631PressureTable<FluidSystem,Region>::
632PressureFunction<ODE>::
633value(
const Scalar depth)
const
635 if (depth < this->initial_.depth) {
637 return (*this->value_[Direction::Up])(depth);
639 else if (depth > this->initial_.depth) {
641 return (*this->value_[Direction::Down])(depth);
645 return this->initial_.pressure;
650template<
class Flu
idSystem,
class Region>
651template<
typename PressFunc>
652void PressureTable<FluidSystem,Region>::
653checkPtr(
const PressFunc* phasePress,
654 const std::string& phaseName)
const
656 if (phasePress !=
nullptr) {
return; }
658 throw std::invalid_argument {
659 "Phase pressure function for \"" + phaseName
660 +
"\" most not be null"
664template<
class Flu
idSystem,
class Region>
665typename PressureTable<FluidSystem,Region>::Strategy
666PressureTable<FluidSystem,Region>::
667selectEquilibrationStrategy(
const Region& reg)
const
669 if (!this->oilActive()) {
670 if (reg.datum() > reg.zwoc()) {
671 return &PressureTable::equil_WOG;
673 return &PressureTable::equil_GOW;
676 if (reg.datum() > reg.zwoc()) {
677 return &PressureTable::equil_WOG;
679 else if (reg.datum() < reg.zgoc()) {
680 return &PressureTable::equil_GOW;
683 return &PressureTable::equil_OWG;
687template<
class Flu
idSystem,
class Region>
688void PressureTable<FluidSystem,Region>::
689copyInPointers(
const PressureTable& rhs)
691 if (rhs.oil_ !=
nullptr) {
692 this->oil_ = std::make_unique<OPress>(*rhs.oil_);
695 if (rhs.gas_ !=
nullptr) {
696 this->gas_ = std::make_unique<GPress>(*rhs.gas_);
699 if (rhs.wat_ !=
nullptr) {
700 this->wat_ = std::make_unique<WPress>(*rhs.wat_);
704template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
707 const std::vector<Scalar>& swatInit)
708 : matLawMgr_(matLawMgr)
709 , swatInit_ (swatInit)
713template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
716 : matLawMgr_(rhs.matLawMgr_)
717 , swatInit_ (rhs.swatInit_)
719 , press_ (rhs.press_)
722 this->setEvaluationPoint(*rhs.evalPt_.position,
724 *rhs.evalPt_.ptable);
727template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
734 this->setEvaluationPoint(x, reg, ptable);
735 this->initializePhaseQuantities();
737 if (ptable.
gasActive()) { this->deriveGasSat(); }
739 if (ptable.
waterActive()) { this->deriveWaterSat(); }
742 if (this->isOverlappingTransition()) {
743 this->fixUnphysicalTransition();
746 if (ptable.
oilActive()) { this->deriveOilSat(); }
748 this->accountForScaledSaturations();
753template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
757 const PTable& ptable)
759 this->evalPt_.position = &x;
760 this->evalPt_.region = ®
761 this->evalPt_.ptable = &ptable;
764template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
765void PhaseSaturations<MaterialLawManager,FluidSystem,Region,CellID>::
766initializePhaseQuantities()
769 this->press_.reset();
771 const auto depth = this->evalPt_.position->depth;
772 const auto& ptable = *this->evalPt_.ptable;
774 if (ptable.oilActive()) {
775 this->press_.oil = ptable.oil(depth);
778 if (ptable.gasActive()) {
779 this->press_.gas = ptable.gas(depth);
782 if (ptable.waterActive()) {
783 this->press_.water = ptable.water(depth);
787template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
788void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::deriveOilSat()
790 this->sat_.oil = 1.0 - this->sat_.water - this->sat_.gas;
793template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
794void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::deriveGasSat()
796 auto& sg = this->sat_.gas;
798 const auto isIncr =
true;
799 const auto oilActive = this->evalPt_.ptable->oilActive();
801 if (this->isConstCapPress(this->gasPos())) {
805 const auto gas_contact = oilActive? this->evalPt_.region->zgoc() : this->evalPt_.region->zwoc();
806 sg = this->fromDepthTable(gas_contact,
807 this->gasPos(), isIncr);
817 const auto pw = oilActive? this->press_.oil : this->press_.water;
818 const auto pcgo = this->press_.gas - pw;
819 sg = this->invertCapPress(pcgo, this->gasPos(), isIncr);
823template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
824void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::deriveWaterSat()
826 auto& sw = this->sat_.water;
828 const auto oilActive = this->evalPt_.ptable->oilActive();
831 sw = 1.0 - this->sat_.gas;
834 const auto isIncr =
false;
836 if (this->isConstCapPress(this->waterPos())) {
840 sw = this->fromDepthTable(this->evalPt_.region->zwoc(),
841 this->waterPos(), isIncr);
853 const auto pcow = this->press_.oil - this->press_.water;
855 if (this->swatInit_.empty()) {
856 sw = this->invertCapPress(pcow, this->waterPos(), isIncr);
859 auto [swout, newSwatInit] = this->applySwatInit(pcow);
861 sw = this->invertCapPress(pcow, this->waterPos(), isIncr);
870template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
871void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
872fixUnphysicalTransition()
874 auto& sg = this->sat_.gas;
875 auto& sw = this->sat_.water;
883 const auto pcgw = this->press_.gas - this->press_.water;
884 if (! this->swatInit_.empty()) {
888 auto [swout, newSwatInit] = this->applySwatInit(pcgw, sw);
890 const auto isIncr =
false;
891 sw = this->invertCapPress(pcgw, this->waterPos(), isIncr);
898 sw = satFromSumOfPcs<FluidSystem>
899 (this->matLawMgr_, this->waterPos(), this->gasPos(),
900 this->evalPt_.position->cell, pcgw);
903 this->fluidState_.setSaturation(this->oilPos(), 1.0 - sw - sg);
904 this->fluidState_.setSaturation(this->gasPos(), sg);
905 this->fluidState_.setSaturation(this->waterPos(), this->evalPt_
906 .ptable->waterActive() ? sw : 0.0);
909 this->computeMaterialLawCapPress();
910 this->press_.oil = this->press_.gas - this->materialLawCapPressGasOil();
913template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
914void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
915accountForScaledSaturations()
917 const auto gasActive = this->evalPt_.ptable->gasActive();
918 const auto watActive = this->evalPt_.ptable->waterActive();
919 const auto oilActive = this->evalPt_.ptable->oilActive();
921 auto sg = gasActive? this->sat_.gas : 0.0;
922 auto sw = watActive? this->sat_.water : 0.0;
923 auto so = oilActive? this->sat_.oil : 0.0;
925 this->fluidState_.setSaturation(this->waterPos(), sw);
926 this->fluidState_.setSaturation(this->oilPos(), so);
927 this->fluidState_.setSaturation(this->gasPos(), sg);
929 const auto& scaledDrainageInfo = this->matLawMgr_
930 .oilWaterScaledEpsInfoDrainage(this->evalPt_.position->cell);
932 const auto thresholdSat = 1.0e-6;
933 if (watActive && ((sw + thresholdSat) > scaledDrainageInfo.Swu)) {
937 this->fluidState_.setSaturation(this->waterPos(), scaledDrainageInfo.Swu);
939 this->fluidState_.setSaturation(this->oilPos(), so + sw - scaledDrainageInfo.Swu);
940 }
else if (gasActive) {
941 this->fluidState_.setSaturation(this->gasPos(), sg + sw - scaledDrainageInfo.Swu);
943 sw = scaledDrainageInfo.Swu;
944 this->computeMaterialLawCapPress();
948 this->press_.oil = this->press_.water + this->materialLawCapPressOilWater();
951 this->press_.gas = this->press_.water + this->materialLawCapPressGasWater();
955 if (gasActive && ((sg + thresholdSat) > scaledDrainageInfo.Sgu)) {
959 this->fluidState_.setSaturation(this->gasPos(), scaledDrainageInfo.Sgu);
961 this->fluidState_.setSaturation(this->oilPos(), so + sg - scaledDrainageInfo.Sgu);
962 }
else if (watActive) {
963 this->fluidState_.setSaturation(this->waterPos(), sw + sg - scaledDrainageInfo.Sgu);
965 sg = scaledDrainageInfo.Sgu;
966 this->computeMaterialLawCapPress();
970 this->press_.oil = this->press_.gas - this->materialLawCapPressGasOil();
973 this->press_.water = this->press_.gas - this->materialLawCapPressGasWater();
977 if (watActive && ((sw - thresholdSat) < scaledDrainageInfo.Swl)) {
981 this->fluidState_.setSaturation(this->waterPos(), scaledDrainageInfo.Swl);
983 this->fluidState_.setSaturation(this->oilPos(), so + sw - scaledDrainageInfo.Swl);
984 }
else if (gasActive) {
985 this->fluidState_.setSaturation(this->gasPos(), sg + sw - scaledDrainageInfo.Swl);
987 sw = scaledDrainageInfo.Swl;
988 this->computeMaterialLawCapPress();
992 this->press_.water = this->press_.oil - this->materialLawCapPressOilWater();
995 this->press_.water = this->press_.gas - this->materialLawCapPressGasWater();
999 if (gasActive && ((sg - thresholdSat) < scaledDrainageInfo.Sgl)) {
1003 this->fluidState_.setSaturation(this->gasPos(), scaledDrainageInfo.Sgl);
1005 this->fluidState_.setSaturation(this->oilPos(), so + sg - scaledDrainageInfo.Sgl);
1006 }
else if (watActive) {
1007 this->fluidState_.setSaturation(this->waterPos(), sw + sg - scaledDrainageInfo.Sgl);
1009 sg = scaledDrainageInfo.Sgl;
1010 this->computeMaterialLawCapPress();
1014 this->press_.gas = this->press_.oil + this->materialLawCapPressGasOil();
1017 this->press_.gas = this->press_.water + this->materialLawCapPressGasWater();
1022template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1023std::pair<typename FluidSystem::Scalar, bool>
1024PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1025applySwatInit(
const Scalar pcow)
1027 return this->applySwatInit(pcow, this->swatInit_[this->evalPt_.position->cell]);
1030template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1031std::pair<typename FluidSystem::Scalar, bool>
1032PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1033applySwatInit(
const Scalar pcow,
const Scalar sw)
1035 return this->matLawMgr_.applySwatinit(this->evalPt_.position->cell, pcow, sw);
1038template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1039void PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1040computeMaterialLawCapPress()
1042 const auto& matParams = this->matLawMgr_
1043 .materialLawParams(this->evalPt_.position->cell);
1045 this->matLawCapPress_.fill(0.0);
1046 MaterialLaw::capillaryPressures(this->matLawCapPress_,
1047 matParams, this->fluidState_);
1050template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1051typename FluidSystem::Scalar
1052PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1053materialLawCapPressGasOil()
const
1055 return this->matLawCapPress_[this->oilPos()]
1056 + this->matLawCapPress_[this->gasPos()];
1059template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1060typename FluidSystem::Scalar
1061PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1062materialLawCapPressOilWater()
const
1064 return this->matLawCapPress_[this->oilPos()]
1065 - this->matLawCapPress_[this->waterPos()];
1068template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1069typename FluidSystem::Scalar
1070PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1071materialLawCapPressGasWater()
const
1073 return this->matLawCapPress_[this->gasPos()]
1074 - this->matLawCapPress_[this->waterPos()];
1077template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1078bool PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1079isConstCapPress(
const PhaseIdx phaseIdx)
const
1081 return isConstPc<FluidSystem>
1082 (this->matLawMgr_, phaseIdx, this->evalPt_.position->cell);
1085template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1086bool PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1087isOverlappingTransition()
const
1089 return this->evalPt_.ptable->gasActive()
1090 && this->evalPt_.ptable->waterActive()
1091 && ((this->sat_.gas + this->sat_.water) > 1.0);
1094template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1095typename FluidSystem::Scalar
1096PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1097fromDepthTable(
const Scalar contactdepth,
1098 const PhaseIdx phasePos,
1099 const bool isincr)
const
1101 return satFromDepth<FluidSystem>
1102 (this->matLawMgr_, this->evalPt_.position->depth,
1103 contactdepth,
static_cast<int>(phasePos),
1104 this->evalPt_.position->cell, isincr);
1107template <
class MaterialLawManager,
class Flu
idSystem,
class Region,
typename CellID>
1108typename FluidSystem::Scalar
1109PhaseSaturations<MaterialLawManager, FluidSystem, Region, CellID>::
1110invertCapPress(
const Scalar pc,
1111 const PhaseIdx phasePos,
1112 const bool isincr)
const
1114 return satFromPc<FluidSystem>
1115 (this->matLawMgr_,
static_cast<int>(phasePos),
1116 this->evalPt_.position->cell, pc, isincr);
1119template<
class Flu
idSystem,
class Region>
1122 const int samplePoints)
1124 , nsample_(samplePoints)
1128template <
class Flu
idSystem,
class Region>
1131 : gravity_(rhs.gravity_)
1132 , nsample_(rhs.nsample_)
1134 this->copyInPointers(rhs);
1137template <
class Flu
idSystem,
class Region>
1140 : gravity_(rhs.gravity_)
1141 , nsample_(rhs.nsample_)
1142 , oil_ (std::move(rhs.oil_))
1143 , gas_ (std::move(rhs.gas_))
1144 , wat_ (std::move(rhs.wat_))
1148template <
class Flu
idSystem,
class Region>
1153 this->gravity_ = rhs.gravity_;
1154 this->nsample_ = rhs.nsample_;
1155 this->copyInPointers(rhs);
1160template <
class Flu
idSystem,
class Region>
1165 this->gravity_ = rhs.gravity_;
1166 this->nsample_ = rhs.nsample_;
1168 this->oil_ = std::move(rhs.oil_);
1169 this->gas_ = std::move(rhs.gas_);
1170 this->wat_ = std::move(rhs.wat_);
1175template <
class Flu
idSystem,
class Region>
1181 auto equil = this->selectEquilibrationStrategy(reg);
1183 (this->*equil)(reg, span);
1186template <
class Flu
idSystem,
class Region>
1190 return FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
1193template <
class Flu
idSystem,
class Region>
1197 return FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx);
1200template <
class Flu
idSystem,
class Region>
1204 return FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx);
1207template <
class Flu
idSystem,
class Region>
1208typename FluidSystem::Scalar
1212 this->checkPtr(this->oil_.get(),
"OIL");
1214 return this->oil_->value(depth);
1217template <
class Flu
idSystem,
class Region>
1218typename FluidSystem::Scalar
1222 this->checkPtr(this->gas_.get(),
"GAS");
1224 return this->gas_->value(depth);
1228template <
class Flu
idSystem,
class Region>
1229typename FluidSystem::Scalar
1233 this->checkPtr(this->wat_.get(),
"WATER");
1235 return this->wat_->value(depth);
1238template <
class Flu
idSystem,
class Region>
1240equil_WOG(
const Region& reg,
const VSpan& span)
1245 if (! this->waterActive()) {
1246 throw std::invalid_argument {
1247 "Don't know how to interpret EQUIL datum depth in "
1248 "WATER zone in model without active water phase"
1253 const auto ic =
typename WPress::InitCond {
1254 reg.datum(), reg.pressure()
1257 this->makeWatPressure(ic, reg, span);
1260 if (this->oilActive()) {
1262 const auto ic =
typename OPress::InitCond {
1264 this->water(reg.zwoc()) + reg.pcowWoc()
1267 this->makeOilPressure(ic, reg, span);
1270 if (this->gasActive() && this->oilActive()) {
1272 const auto ic =
typename GPress::InitCond {
1274 this->oil(reg.zgoc()) + reg.pcgoGoc()
1277 this->makeGasPressure(ic, reg, span);
1278 }
else if (this->gasActive() && !this->oilActive()) {
1280 const auto ic =
typename GPress::InitCond {
1282 this->water(reg.zwoc()) + reg.pcowWoc()
1284 this->makeGasPressure(ic, reg, span);
1288template <
class Flu
idSystem,
class Region>
1289void PressureTable<FluidSystem, Region>::
1290equil_GOW(
const Region& reg,
const VSpan& span)
1295 if (! this->gasActive()) {
1296 throw std::invalid_argument {
1297 "Don't know how to interpret EQUIL datum depth in "
1298 "GAS zone in model without active gas phase"
1303 const auto ic =
typename GPress::InitCond {
1304 reg.datum(), reg.pressure()
1307 this->makeGasPressure(ic, reg, span);
1310 if (this->oilActive()) {
1312 const auto ic =
typename OPress::InitCond {
1314 this->gas(reg.zgoc()) - reg.pcgoGoc()
1316 this->makeOilPressure(ic, reg, span);
1319 if (this->waterActive() && this->oilActive()) {
1321 const auto ic =
typename WPress::InitCond {
1323 this->oil(reg.zwoc()) - reg.pcowWoc()
1326 this->makeWatPressure(ic, reg, span);
1327 }
else if (this->waterActive() && !this->oilActive()) {
1329 const auto ic =
typename WPress::InitCond {
1331 this->gas(reg.zwoc()) - reg.pcowWoc()
1333 this->makeWatPressure(ic, reg, span);
1337template <
class Flu
idSystem,
class Region>
1338void PressureTable<FluidSystem, Region>::
1339equil_OWG(
const Region& reg,
const VSpan& span)
1344 if (! this->oilActive()) {
1345 throw std::invalid_argument {
1346 "Don't know how to interpret EQUIL datum depth in "
1347 "OIL zone in model without active oil phase"
1352 const auto ic =
typename OPress::InitCond {
1353 reg.datum(), reg.pressure()
1356 this->makeOilPressure(ic, reg, span);
1359 if (this->waterActive()) {
1361 const auto ic =
typename WPress::InitCond {
1363 this->oil(reg.zwoc()) - reg.pcowWoc()
1366 this->makeWatPressure(ic, reg, span);
1369 if (this->gasActive()) {
1371 const auto ic =
typename GPress::InitCond {
1373 this->oil(reg.zgoc()) + reg.pcgoGoc()
1375 this->makeGasPressure(ic, reg, span);
1379template <
class Flu
idSystem,
class Region>
1380void PressureTable<FluidSystem, Region>::
1381makeOilPressure(
const typename OPress::InitCond& ic,
1385 const auto drho = OilPressODE {
1386 reg.tempVdTable(), reg.dissolutionCalculator(),
1387 reg.pvtIdx(), this->gravity_
1390 this->oil_ = std::make_unique<OPress>(drho, ic, this->nsample_, span);
1393template <
class Flu
idSystem,
class Region>
1394void PressureTable<FluidSystem, Region>::
1395makeGasPressure(
const typename GPress::InitCond& ic,
1399 const auto drho = GasPressODE {
1400 reg.tempVdTable(), reg.evaporationCalculator(), reg.waterEvaporationCalculator(),
1401 reg.pvtIdx(), this->gravity_
1404 this->gas_ = std::make_unique<GPress>(drho, ic, this->nsample_, span);
1407template <
class Flu
idSystem,
class Region>
1408void PressureTable<FluidSystem, Region>::
1409makeWatPressure(
const typename WPress::InitCond& ic,
1413 const auto drho = WatPressODE {
1414 reg.tempVdTable(), reg.saltVdTable(), reg.pvtIdx(), this->gravity_
1417 this->wat_ = std::make_unique<WPress>(drho, ic, this->nsample_, span);
1422namespace DeckDependent {
1424std::vector<EquilRecord>
1427 const auto& init = state.getInitConfig();
1429 if(!init.hasEquil()) {
1430 throw std::domain_error(
"Deck does not provide equilibration data.");
1433 const auto& equil = init.getEquil();
1434 return { equil.begin(), equil.end() };
1437template<
class Gr
idView>
1440 const GridView& gridview)
1442 std::vector<int> eqlnum(gridview.size(0), 0);
1444 if (eclipseState.fieldProps().has_int(
"EQLNUM")) {
1445 const auto& e = eclipseState.fieldProps().get_int(
"EQLNUM");
1446 std::transform(e.begin(), e.end(), eqlnum.begin(), [](
int n){ return n - 1;});
1449 const int num_regions = eclipseState.getTableManager().getEqldims().getNumEquilRegions();
1450 if ( std::any_of(eqlnum.begin(), eqlnum.end(), [num_regions](
int n){return n >= num_regions;}) ) {
1451 throw std::runtime_error(
"Values larger than maximum Equil regions " +
std::to_string(num_regions) +
" provided in EQLNUM");
1453 if ( std::any_of(eqlnum.begin(), eqlnum.end(), [](
int n){return n < 0;}) ) {
1454 throw std::runtime_error(
"zero or negative values provided in EQLNUM");
1461template<
class FluidSystem,
1464 class ElementMapper,
1465 class CartesianIndexMapper>
1466template<
class MaterialLawManager>
1467InitialStateComputer<FluidSystem,
1471 CartesianIndexMapper>::
1472InitialStateComputer(MaterialLawManager& materialLawManager,
1473 const EclipseState& eclipseState,
1475 const GridView& gridView,
1476 const CartesianIndexMapper& cartMapper,
1478 const int num_pressure_points,
1479 const bool applySwatInit)
1480 : temperature_(grid.size(0), eclipseState.getTableManager().rtemp()),
1481 saltConcentration_(grid.size(0)),
1482 saltSaturation_(grid.size(0)),
1483 pp_(FluidSystem::numPhases,
1484 std::vector<Scalar>(grid.size(0))),
1485 sat_(FluidSystem::numPhases,
1486 std::vector<Scalar>(grid.size(0))),
1490 cartesianIndexMapper_(cartMapper),
1491 num_pressure_points_(num_pressure_points)
1494 if (applySwatInit) {
1495 if (eclipseState.fieldProps().has_double(
"SWATINIT")) {
1496 if constexpr (std::is_same_v<Scalar,double>) {
1497 swatInit_ = eclipseState.fieldProps().get_double(
"SWATINIT");
1499 const auto& input = eclipseState.fieldProps().get_double(
"SWATINIT");
1500 swatInit_.resize(input.size());
1501 std::copy(input.begin(), input.end(), swatInit_.begin());
1508 const auto& num_aquifers = eclipseState.aquifer().numericalAquifers();
1509 updateCellProps_(gridView, num_aquifers);
1512 const std::vector<EquilRecord> rec =
getEquil(eclipseState);
1513 const auto& tables = eclipseState.getTableManager();
1515 const RegionMapping<> eqlmap(
equilnum(eclipseState, grid));
1516 const int invalidRegion = -1;
1517 regionPvtIdx_.resize(rec.size(), invalidRegion);
1518 setRegionPvtIdx(eclipseState, eqlmap);
1521 rsFunc_.reserve(rec.size());
1523 auto getArray = [](
const std::vector<double>& input)
1525 if constexpr (std::is_same_v<Scalar,double>) {
1528 std::vector<Scalar> output;
1529 output.resize(input.size());
1530 std::copy(input.begin(), input.end(), output.begin());
1535 if (FluidSystem::enableDissolvedGas()) {
1536 for (std::size_t i = 0; i < rec.size(); ++i) {
1537 if (eqlmap.cells(i).empty()) {
1541 const int pvtIdx = regionPvtIdx_[i];
1542 if (!rec[i].liveOilInitConstantRs()) {
1543 const TableContainer& rsvdTables = tables.getRsvdTables();
1544 const TableContainer& pbvdTables = tables.getPbvdTables();
1545 if (rsvdTables.size() > 0) {
1546 const RsvdTable& rsvdTable = rsvdTables.getTable<RsvdTable>(i);
1547 auto depthColumn = getArray(rsvdTable.getColumn(
"DEPTH").vectorCopy());
1548 auto rsColumn = getArray(rsvdTable.getColumn(
"RS").vectorCopy());
1550 depthColumn, rsColumn));
1551 }
else if (pbvdTables.size() > 0) {
1552 const PbvdTable& pbvdTable = pbvdTables.getTable<PbvdTable>(i);
1553 auto depthColumn = getArray(pbvdTable.getColumn(
"DEPTH").vectorCopy());
1554 auto pbubColumn = getArray(pbvdTable.getColumn(
"PBUB").vectorCopy());
1556 depthColumn, pbubColumn));
1559 throw std::runtime_error(
"Cannot initialise: RSVD or PBVD table not available.");
1564 if (rec[i].gasOilContactDepth() != rec[i].datumDepth()) {
1565 throw std::runtime_error(
"Cannot initialise: when no explicit RSVD table is given, \n"
1566 "datum depth must be at the gas-oil-contact. "
1567 "In EQUIL region "+
std::to_string(i + 1)+
" (counting from 1), this does not hold.");
1569 const Scalar pContact = rec[i].datumDepthPressure();
1570 const Scalar TContact = 273.15 + 20;
1576 for (std::size_t i = 0; i < rec.size(); ++i) {
1581 rvFunc_.reserve(rec.size());
1582 if (FluidSystem::enableVaporizedOil()) {
1583 for (std::size_t i = 0; i < rec.size(); ++i) {
1584 if (eqlmap.cells(i).empty()) {
1588 const int pvtIdx = regionPvtIdx_[i];
1589 if (!rec[i].wetGasInitConstantRv()) {
1590 const TableContainer& rvvdTables = tables.getRvvdTables();
1591 const TableContainer& pdvdTables = tables.getPdvdTables();
1593 if (rvvdTables.size() > 0) {
1594 const RvvdTable& rvvdTable = rvvdTables.getTable<RvvdTable>(i);
1595 auto depthColumn = getArray(rvvdTable.getColumn(
"DEPTH").vectorCopy());
1596 auto rvColumn = getArray(rvvdTable.getColumn(
"RV").vectorCopy());
1598 depthColumn, rvColumn));
1599 }
else if (pdvdTables.size() > 0) {
1600 const PdvdTable& pdvdTable = pdvdTables.getTable<PdvdTable>(i);
1601 auto depthColumn = getArray(pdvdTable.getColumn(
"DEPTH").vectorCopy());
1602 auto pdewColumn = getArray(pdvdTable.getColumn(
"PDEW").vectorCopy());
1604 depthColumn, pdewColumn));
1606 throw std::runtime_error(
"Cannot initialise: RVVD or PDCD table not available.");
1610 if (rec[i].gasOilContactDepth() != rec[i].datumDepth()) {
1611 throw std::runtime_error(
1612 "Cannot initialise: when no explicit RVVD table is given, \n"
1613 "datum depth must be at the gas-oil-contact. "
1614 "In EQUIL region "+
std::to_string(i + 1)+
" (counting from 1), this does not hold.");
1616 const Scalar pContact = rec[i].datumDepthPressure() + rec[i].gasOilContactCapillaryPressure();
1617 const Scalar TContact = 273.15 + 20;
1623 for (std::size_t i = 0; i < rec.size(); ++i) {
1628 rvwFunc_.reserve(rec.size());
1629 if (FluidSystem::enableVaporizedWater()) {
1630 for (std::size_t i = 0; i < rec.size(); ++i) {
1631 if (eqlmap.cells(i).empty()) {
1635 const int pvtIdx = regionPvtIdx_[i];
1636 if (!rec[i].humidGasInitConstantRvw()) {
1637 const TableContainer& rvwvdTables = tables.getRvwvdTables();
1639 if (rvwvdTables.size() > 0) {
1640 const RvwvdTable& rvwvdTable = rvwvdTables.getTable<RvwvdTable>(i);
1641 auto depthColumn = getArray(rvwvdTable.getColumn(
"DEPTH").vectorCopy());
1642 auto rvwvdColumn = getArray(rvwvdTable.getColumn(
"RVWVD").vectorCopy());
1644 depthColumn, rvwvdColumn));
1646 throw std::runtime_error(
"Cannot initialise: RVWVD table not available.");
1650 const auto oilActive = FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
1652 if (rec[i].gasOilContactDepth() != rec[i].datumDepth()) {
1654 const auto msg =
"No explicit RVWVD table is given for EQUIL region " +
std::to_string(i + 1) +
". \n"
1655 "and datum depth is not at the gas-oil-contact. \n"
1656 "Rvw is set to 0.0 in all cells. \n";
1657 OpmLog::warning(msg);
1661 const Scalar pContact = rec[i].datumDepthPressure() + rec[i].gasOilContactCapillaryPressure();
1662 const Scalar TContact = 273.15 + 20;
1669 if (rec[i].waterOilContactDepth() != rec[i].datumDepth()) {
1671 const auto msg =
"No explicit RVWVD table is given for EQUIL region " +
std::to_string(i + 1) +
". \n"
1672 "and datum depth is not at the gas-water-contact. \n"
1673 "Rvw is set to 0.0 in all cells. \n";
1674 OpmLog::warning(msg);
1677 const Scalar pContact = rec[i].datumDepthPressure() + rec[i].waterOilContactCapillaryPressure();
1678 const Scalar TContact = 273.15 + 20;
1686 for (std::size_t i = 0; i < rec.size(); ++i) {
1693 updateInitialTemperature_(eclipseState, eqlmap);
1696 updateInitialSaltConcentration_(eclipseState, eqlmap);
1699 updateInitialSaltSaturation_(eclipseState, eqlmap);
1702 const auto& comm = grid.comm();
1703 calcPressSatRsRv(eqlmap, rec, materialLawManager, gridView, comm, grav);
1706 applyNumericalAquifers_(gridView, num_aquifers, eclipseState.runspec().co2Storage() || eclipseState.runspec().h2Storage());
1712template<
class FluidSystem,
1715 class ElementMapper,
1716 class CartesianIndexMapper>
1722 CartesianIndexMapper>::
1723updateInitialTemperature_(
const EclipseState& eclState,
const RMap& reg)
1725 const int numEquilReg = rsFunc_.size();
1726 tempVdTable_.resize(numEquilReg);
1727 const auto& tables = eclState.getTableManager();
1728 if (!tables.hasTables(
"RTEMPVD")) {
1729 std::vector<Scalar> x = {0.0,1.0};
1730 std::vector<Scalar> y = {
static_cast<Scalar
>(tables.rtemp()),
1731 static_cast<Scalar
>(tables.rtemp())};
1732 for (
auto& table : this->tempVdTable_) {
1733 table.setXYContainers(x, y);
1736 const TableContainer& tempvdTables = tables.getRtempvdTables();
1737 for (std::size_t i = 0; i < tempvdTables.size(); ++i) {
1738 const RtempvdTable& tempvdTable = tempvdTables.getTable<RtempvdTable>(i);
1739 tempVdTable_[i].setXYContainers(tempvdTable.getDepthColumn(), tempvdTable.getTemperatureColumn());
1740 const auto& cells = reg.cells(i);
1741 for (
const auto& cell : cells) {
1742 const Scalar depth = cellCenterDepth_[cell];
1743 this->temperature_[cell] = tempVdTable_[i].eval(depth,
true);
1749template<
class FluidSystem,
1752 class ElementMapper,
1753 class CartesianIndexMapper>
1755void InitialStateComputer<FluidSystem,
1759 CartesianIndexMapper>::
1760updateInitialSaltConcentration_(
const EclipseState& eclState,
const RMap& reg)
1762 const int numEquilReg = rsFunc_.size();
1763 saltVdTable_.resize(numEquilReg);
1764 const auto& tables = eclState.getTableManager();
1765 const TableContainer& saltvdTables = tables.getSaltvdTables();
1768 if (saltvdTables.empty()) {
1769 std::vector<Scalar> x = {0.0,1.0};
1770 std::vector<Scalar> y = {0.0,0.0};
1771 for (
auto& table : this->saltVdTable_) {
1772 table.setXYContainers(x, y);
1775 for (std::size_t i = 0; i < saltvdTables.size(); ++i) {
1776 const SaltvdTable& saltvdTable = saltvdTables.getTable<SaltvdTable>(i);
1777 saltVdTable_[i].setXYContainers(saltvdTable.getDepthColumn(), saltvdTable.getSaltColumn());
1779 const auto& cells = reg.cells(i);
1780 for (
const auto& cell : cells) {
1781 const Scalar depth = cellCenterDepth_[cell];
1782 this->saltConcentration_[cell] = saltVdTable_[i].eval(depth,
true);
1788template<
class FluidSystem,
1791 class ElementMapper,
1792 class CartesianIndexMapper>
1794void InitialStateComputer<FluidSystem,
1798 CartesianIndexMapper>::
1799updateInitialSaltSaturation_(
const EclipseState& eclState,
const RMap& reg)
1801 const int numEquilReg = rsFunc_.size();
1802 saltpVdTable_.resize(numEquilReg);
1803 const auto& tables = eclState.getTableManager();
1804 const TableContainer& saltpvdTables = tables.getSaltpvdTables();
1806 for (std::size_t i = 0; i < saltpvdTables.size(); ++i) {
1807 const SaltpvdTable& saltpvdTable = saltpvdTables.getTable<SaltpvdTable>(i);
1808 saltpVdTable_[i].setXYContainers(saltpvdTable.getDepthColumn(), saltpvdTable.getSaltpColumn());
1810 const auto& cells = reg.cells(i);
1811 for (
const auto& cell : cells) {
1812 const Scalar depth = cellCenterDepth_[cell];
1813 this->saltSaturation_[cell] = saltpVdTable_[i].eval(depth,
true);
1818template<
class FluidSystem,
1821 class ElementMapper,
1822 class CartesianIndexMapper>
1823void InitialStateComputer<FluidSystem,
1827 CartesianIndexMapper>::
1828updateCellProps_(
const GridView& gridView,
1829 const NumericalAquifers& aquifer)
1831 ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
1832 int numElements = gridView.size(0);
1833 cellCenterDepth_.resize(numElements);
1834 cellCenterXY_.resize(numElements);
1835 cellCorners_.resize(numElements);
1836 cellZSpan_.resize(numElements);
1837 cellZMinMax_.resize(numElements);
1839 auto elemIt = gridView.template begin<0>();
1840 const auto& elemEndIt = gridView.template end<0>();
1841 const auto num_aqu_cells = aquifer.allAquiferCells();
1842 for (; elemIt != elemEndIt; ++elemIt) {
1843 const Element& element = *elemIt;
1844 const unsigned int elemIdx = elemMapper.index(element);
1845 cellCenterDepth_[elemIdx] = Details::cellCenterDepth<Scalar>(element);
1846 cellCenterXY_[elemIdx] = Details::cellCenterXY<Scalar>(element);
1847 cellCorners_[elemIdx] = Details::getCellCornerXY<Scalar>(element);
1848 const auto cartIx = cartesianIndexMapper_.cartesianIndex(elemIdx);
1849 cellZSpan_[elemIdx] = Details::cellZSpan<Scalar>(element);
1850 cellZMinMax_[elemIdx] = Details::cellZMinMax<Scalar>(element);
1851 if (!num_aqu_cells.empty()) {
1852 const auto search = num_aqu_cells.find(cartIx);
1853 if (search != num_aqu_cells.end()) {
1854 const auto* aqu_cell = num_aqu_cells.at(cartIx);
1855 const Scalar depth_change_num_aqu = aqu_cell->depth - cellCenterDepth_[elemIdx];
1856 cellCenterDepth_[elemIdx] += depth_change_num_aqu;
1857 cellZSpan_[elemIdx].first += depth_change_num_aqu;
1858 cellZSpan_[elemIdx].second += depth_change_num_aqu;
1859 cellZMinMax_[elemIdx].first += depth_change_num_aqu;
1860 cellZMinMax_[elemIdx].second += depth_change_num_aqu;
1866template<
class FluidSystem,
1869 class ElementMapper,
1870 class CartesianIndexMapper>
1871void InitialStateComputer<FluidSystem,
1875 CartesianIndexMapper>::
1876applyNumericalAquifers_(
const GridView& gridView,
1877 const NumericalAquifers& aquifer,
1878 const bool co2store_or_h2store)
1880 const auto num_aqu_cells = aquifer.allAquiferCells();
1881 if (num_aqu_cells.empty())
return;
1884 bool oil_as_brine = co2store_or_h2store && FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx);
1885 const auto watPos = oil_as_brine? FluidSystem::oilPhaseIdx : FluidSystem::waterPhaseIdx;
1886 if (!FluidSystem::phaseIsActive(watPos)){
1887 throw std::logic_error {
"Water phase has to be active for numerical aquifer case" };
1890 ElementMapper elemMapper(gridView, Dune::mcmgElementLayout());
1891 auto elemIt = gridView.template begin<0>();
1892 const auto& elemEndIt = gridView.template end<0>();
1893 const auto oilPos = FluidSystem::oilPhaseIdx;
1894 const auto gasPos = FluidSystem::gasPhaseIdx;
1895 for (; elemIt != elemEndIt; ++elemIt) {
1896 const Element& element = *elemIt;
1897 const unsigned int elemIdx = elemMapper.index(element);
1898 const auto cartIx = cartesianIndexMapper_.cartesianIndex(elemIdx);
1899 const auto search = num_aqu_cells.find(cartIx);
1900 if (search != num_aqu_cells.end()) {
1902 this->sat_[watPos][elemIdx] = 1.;
1904 if (!co2store_or_h2store && FluidSystem::phaseIsActive(oilPos)) {
1905 this->sat_[oilPos][elemIdx] = 0.;
1908 if (FluidSystem::phaseIsActive(gasPos)) {
1909 this->sat_[gasPos][elemIdx] = 0.;
1911 const auto* aqu_cell = num_aqu_cells.at(cartIx);
1912 const auto msg = fmt::format(
"FOR AQUIFER CELL AT ({}, {}, {}) OF NUMERICAL "
1913 "AQUIFER {}, WATER SATURATION IS SET TO BE UNITY",
1914 aqu_cell->I+1, aqu_cell->J+1, aqu_cell->K+1, aqu_cell->aquifer_id);
1919 if (aqu_cell->init_pressure) {
1920 const Scalar pres = *(aqu_cell->init_pressure);
1921 this->pp_[watPos][elemIdx] = pres;
1922 if (FluidSystem::phaseIsActive(gasPos)) {
1923 this->pp_[gasPos][elemIdx] = pres;
1925 if (FluidSystem::phaseIsActive(oilPos)) {
1926 this->pp_[oilPos][elemIdx] = pres;
1933template<
class FluidSystem,
1936 class ElementMapper,
1937 class CartesianIndexMapper>
1939void InitialStateComputer<FluidSystem,
1943 CartesianIndexMapper>::
1944setRegionPvtIdx(
const EclipseState& eclState,
const RMap& reg)
1946 const auto& pvtnumData = eclState.fieldProps().get_int(
"PVTNUM");
1948 for (
const auto& r : reg.activeRegions()) {
1949 const auto& cells = reg.cells(r);
1950 regionPvtIdx_[r] = pvtnumData[*cells.begin()] - 1;
1954template<
class FluidSystem,
1957 class ElementMapper,
1958 class CartesianIndexMapper>
1959template<
class RMap,
class MaterialLawManager,
class Comm>
1960void InitialStateComputer<FluidSystem,
1964 CartesianIndexMapper>::
1965calcPressSatRsRv(
const RMap& reg,
1966 const std::vector<EquilRecord>& rec,
1967 MaterialLawManager& materialLawManager,
1968 const GridView& gridView,
1972 using PhaseSat = Details::PhaseSaturations<
1973 MaterialLawManager, FluidSystem, EquilReg<Scalar>,
typename RMap::CellId
1976 auto ptable = Details::PressureTable<FluidSystem, EquilReg<Scalar>>{ grav, this->num_pressure_points_ };
1977 auto psat = PhaseSat { materialLawManager, this->swatInit_ };
1978 auto vspan = std::array<Scalar, 2>{};
1980 std::vector<int> regionIsEmpty(rec.size(), 0);
1981 for (std::size_t r = 0; r < rec.size(); ++r) {
1982 const auto& cells = reg.cells(r);
1986 const auto acc = rec[r].initializationTargetAccuracy();
1990 if (cells.empty()) {
1991 regionIsEmpty[r] = 1;
1994 const auto eqreg = EquilReg {
1995 rec[r], this->rsFunc_[r], this->rvFunc_[r], this->rvwFunc_[r],
1996 this->tempVdTable_[r], this->saltVdTable_[r], this->regionPvtIdx_[r]
1999 vspan[0] = std::min(vspan[0], std::min(eqreg.zgoc(), eqreg.zwoc()));
2000 vspan[1] = std::max(vspan[1], std::max(eqreg.zgoc(), eqreg.zwoc()));
2001 ptable.equilibrate(eqreg, vspan);
2004 this->equilibrateTiltedFaultBlock(cells, eqreg, gridView, acc, ptable, psat);
2006 else if (acc == 0) {
2007 if (cells.empty()) {
2008 regionIsEmpty[r] = 1;
2011 const auto eqreg = EquilReg {
2012 rec[r], this->rsFunc_[r], this->rvFunc_[r], this->rvwFunc_[r],
2013 this->tempVdTable_[r], this->saltVdTable_[r], this->regionPvtIdx_[r]
2015 vspan[0] = std::min(vspan[0], std::min(eqreg.zgoc(), eqreg.zwoc()));
2016 vspan[1] = std::max(vspan[1], std::max(eqreg.zgoc(), eqreg.zwoc()));
2017 ptable.equilibrate(eqreg, vspan);
2019 this->equilibrateCellCentres(cells, eqreg, ptable, psat);
2022 if (cells.empty()) {
2023 regionIsEmpty[r] = 1;
2026 const auto eqreg = EquilReg {
2027 rec[r], this->rsFunc_[r], this->rvFunc_[r], this->rvwFunc_[r],
2028 this->tempVdTable_[r], this->saltVdTable_[r], this->regionPvtIdx_[r]
2030 vspan[0] = std::min(vspan[0], std::min(eqreg.zgoc(), eqreg.zwoc()));
2031 vspan[1] = std::max(vspan[1], std::max(eqreg.zgoc(), eqreg.zwoc()));
2032 ptable.equilibrate(eqreg, vspan);
2034 this->equilibrateHorizontal(cells, eqreg, -acc, ptable, psat);
2037 comm.min(regionIsEmpty.data(),regionIsEmpty.size());
2038 if (comm.rank() == 0) {
2039 for (std::size_t r = 0; r < rec.size(); ++r) {
2040 if (regionIsEmpty[r])
2042 +
" has no active cells");
2047template<
class FluidSystem,
2050 class ElementMapper,
2051 class CartesianIndexMapper>
2052template<
class CellRange,
class EquilibrationMethod>
2053void InitialStateComputer<FluidSystem,
2057 CartesianIndexMapper>::
2058cellLoop(
const CellRange& cells,
2059 EquilibrationMethod&& eqmethod)
2061 const auto oilPos = FluidSystem::oilPhaseIdx;
2062 const auto gasPos = FluidSystem::gasPhaseIdx;
2063 const auto watPos = FluidSystem::waterPhaseIdx;
2065 const auto oilActive = FluidSystem::phaseIsActive(oilPos);
2066 const auto gasActive = FluidSystem::phaseIsActive(gasPos);
2067 const auto watActive = FluidSystem::phaseIsActive(watPos);
2069 auto pressures = Details::PhaseQuantityValue<Scalar>{};
2070 auto saturations = Details::PhaseQuantityValue<Scalar>{};
2075 for (
const auto& cell : cells) {
2076 eqmethod(cell, pressures, saturations, Rs, Rv, Rvw);
2079 this->pp_ [oilPos][cell] = pressures.oil;
2080 this->sat_[oilPos][cell] = saturations.oil;
2084 this->pp_ [gasPos][cell] = pressures.gas;
2085 this->sat_[gasPos][cell] = saturations.gas;
2089 this->pp_ [watPos][cell] = pressures.water;
2090 this->sat_[watPos][cell] = saturations.water;
2093 if (oilActive && gasActive) {
2094 this->rs_[cell] =
Rs;
2095 this->rv_[cell] =
Rv;
2098 if (watActive && gasActive) {
2099 this->rvw_[cell] =
Rvw;
2104template<
class FluidSystem,
2107 class ElementMapper,
2108 class CartesianIndexMapper>
2109template<
class CellRange,
class PressTable,
class PhaseSat>
2110void InitialStateComputer<FluidSystem,
2114 CartesianIndexMapper>::
2115equilibrateCellCentres(
const CellRange& cells,
2116 const EquilReg<Scalar>& eqreg,
2117 const PressTable& ptable,
2120 using CellPos =
typename PhaseSat::Position;
2121 using CellID = std::remove_cv_t<std::remove_reference_t<
2122 decltype(std::declval<CellPos>().cell)>>;
2123 this->cellLoop(cells, [
this, &eqreg, &ptable, &psat]
2125 Details::PhaseQuantityValue<Scalar>& pressures,
2126 Details::PhaseQuantityValue<Scalar>& saturations,
2129 Scalar& Rvw) ->
void
2131 const auto pos = CellPos {
2132 cell, cellCenterDepth_[cell]
2135 saturations = psat.deriveSaturations(pos, eqreg, ptable);
2136 pressures = psat.correctedPhasePressures();
2138 const auto temp = this->temperature_[cell];
2140 Rs = eqreg.dissolutionCalculator()
2141 (pos.depth, pressures.oil, temp, saturations.gas);
2143 Rv = eqreg.evaporationCalculator()
2144 (pos.depth, pressures.gas, temp, saturations.oil);
2146 Rvw = eqreg.waterEvaporationCalculator()
2147 (pos.depth, pressures.gas, temp, saturations.water);
2151template<
class FluidSystem,
2154 class ElementMapper,
2155 class CartesianIndexMapper>
2156template<
class CellRange,
class PressTable,
class PhaseSat>
2157void InitialStateComputer<FluidSystem,
2161 CartesianIndexMapper>::
2162equilibrateHorizontal(
const CellRange& cells,
2163 const EquilReg<Scalar>& eqreg,
2165 const PressTable& ptable,
2168 using CellPos =
typename PhaseSat::Position;
2169 using CellID = std::remove_cv_t<std::remove_reference_t<
2170 decltype(std::declval<CellPos>().cell)>>;
2172 this->cellLoop(cells, [
this, acc, &eqreg, &ptable, &psat]
2174 Details::PhaseQuantityValue<Scalar>& pressures,
2175 Details::PhaseQuantityValue<Scalar>& saturations,
2178 Scalar& Rvw) ->
void
2181 saturations.reset();
2183 Scalar totfrac = 0.0;
2185 const auto pos = CellPos { cell, depth };
2187 saturations.axpy(psat.deriveSaturations(pos, eqreg, ptable), frac);
2188 pressures .axpy(psat.correctedPhasePressures(), frac);
2194 saturations /= totfrac;
2195 pressures /= totfrac;
2198 const auto pos = CellPos {
2199 cell, cellCenterDepth_[cell]
2202 saturations = psat.deriveSaturations(pos, eqreg, ptable);
2203 pressures = psat.correctedPhasePressures();
2206 const auto temp = this->temperature_[cell];
2207 const auto cz = cellCenterDepth_[cell];
2209 Rs = eqreg.dissolutionCalculator()
2210 (cz, pressures.oil, temp, saturations.gas);
2212 Rv = eqreg.evaporationCalculator()
2213 (cz, pressures.gas, temp, saturations.oil);
2215 Rvw = eqreg.waterEvaporationCalculator()
2216 (cz, pressures.gas, temp, saturations.water);
2220template<
class Flu
idSystem,
class Gr
id,
class Gr
idView,
class ElementMapper,
class CartesianIndexMapper>
2221template<
class CellRange,
class PressTable,
class PhaseSat>
2222void InitialStateComputer<FluidSystem, Grid, GridView, ElementMapper, CartesianIndexMapper>::
2223equilibrateTiltedFaultBlockSimple(
const CellRange& cells,
2224 const EquilReg<Scalar>& eqreg,
2225 const GridView& gridView,
2227 const PressTable& ptable,
2230 using CellPos =
typename PhaseSat::Position;
2231 using CellID = std::remove_cv_t<std::remove_reference_t<
2232 decltype(std::declval<CellPos>().cell)>>;
2234 this->cellLoop(cells, [
this, acc, &eqreg, &ptable, &psat, &gridView]
2236 Details::PhaseQuantityValue<Scalar>& pressures,
2237 Details::PhaseQuantityValue<Scalar>& saturations,
2240 Scalar& Rvw) ->
void
2243 saturations.reset();
2244 Scalar totalWeight = 0.0;
2247 const auto& [zmin, zmax] = cellZMinMax_[cell];
2248 const Scalar cellThickness = zmax - zmin;
2249 const Scalar halfThickness = cellThickness / 2.0;
2252 Scalar dipAngle, dipAzimuth;
2256 std::array<Scalar, 3> referencePoint = {
2257 cellCenterXY_[cell].first,
2258 cellCenterXY_[cell].second,
2259 cellCenterDepth_[cell]
2263 const int numLevelsPerHalf = std::min(20, acc);
2266 std::vector<std::pair<Scalar, Scalar>> levels;
2269 for (
int side = 0; side < 2; ++side) {
2270 Scalar halfStart = (side == 0) ? zmin : zmin + halfThickness;
2272 for (
int i = 0; i < numLevelsPerHalf; ++i) {
2274 Scalar depth = halfStart + (i + 0.5) * (halfThickness / numLevelsPerHalf);
2278 Scalar crossSectionWeight = (halfThickness / numLevelsPerHalf);
2281 if (std::abs(dipAngle) > 1e-10) {
2282 crossSectionWeight /= std::cos(dipAngle);
2285 levels.emplace_back(depth, crossSectionWeight);
2289 for (
const auto& [depth, weight] : levels) {
2291 const auto& [x, y] = cellCenterXY_[cell];
2293 depth, x, y, dipAngle, dipAzimuth, referencePoint);
2295 const auto pos = CellPos{cell, tvd};
2297 auto localSaturations = psat.deriveSaturations(pos, eqreg, ptable);
2298 auto localPressures = psat.correctedPhasePressures();
2301 saturations.axpy(localSaturations, weight);
2302 pressures.axpy(localPressures, weight);
2303 totalWeight += weight;
2307 if (totalWeight > 1e-10) {
2308 saturations /= totalWeight;
2309 pressures /= totalWeight;
2312 const auto& [x, y] = cellCenterXY_[cell];
2314 cellCenterDepth_[cell], x, y, dipAngle, dipAzimuth, referencePoint);
2315 const auto pos = CellPos{cell, tvdCenter};
2316 saturations = psat.deriveSaturations(pos, eqreg, ptable);
2317 pressures = psat.correctedPhasePressures();
2321 const auto temp = this->temperature_[cell];
2322 const auto& [x, y] = cellCenterXY_[cell];
2324 cellCenterDepth_[cell], x, y, dipAngle, dipAzimuth, referencePoint);
2326 Rs = eqreg.dissolutionCalculator()(tvdCenter, pressures.oil, temp, saturations.gas);
2327 Rv = eqreg.evaporationCalculator()(tvdCenter, pressures.gas, temp, saturations.oil);
2328 Rvw = eqreg.waterEvaporationCalculator()(tvdCenter, pressures.gas, temp, saturations.water);
2332template<
class Flu
idSystem,
class Gr
id,
class Gr
idView,
class ElementMapper,
class CartesianIndexMapper>
2333template<
class CellRange,
class PressTable,
class PhaseSat>
2334void InitialStateComputer<FluidSystem, Grid, GridView, ElementMapper, CartesianIndexMapper>::
2335equilibrateTiltedFaultBlock(
const CellRange& cells,
2336 const EquilReg<Scalar>& eqreg,
2337 const GridView& gridView,
2339 const PressTable& ptable,
2342 using CellPos =
typename PhaseSat::Position;
2343 using CellID = std::remove_cv_t<std::remove_reference_t<
2344 decltype(std::declval<CellPos>().cell)>>;
2346 std::vector<typename GridView::template Codim<0>::Entity> entityMap(gridView.size(0));
2347 for (
const auto& entity : entities(gridView, Dune::Codim<0>())) {
2348 CellID idx = gridView.indexSet().index(entity);
2349 entityMap[idx] = entity;
2353 auto polygonArea = [](
const std::vector<std::array<Scalar, 2>>& pts) {
2354 if (pts.size() < 3)
return Scalar(0);
2356 for (
size_t i = 0; i < pts.size(); ++i) {
2357 size_t j = (i + 1) % pts.size();
2358 area += pts[i][0] * pts[j][1] - pts[j][0] * pts[i][1];
2360 return std::abs(area) * Scalar(0.5);
2364 auto computeCrossSectionArea = [&](
const CellID cell, Scalar depth) -> Scalar {
2366 const auto& entity = entityMap[cell];
2367 const auto& geometry = entity.geometry();
2368 const int numCorners = geometry.corners();
2370 std::vector<std::array<Scalar, 3>> corners(numCorners);
2371 for (
int i = 0; i < numCorners; ++i) {
2372 const auto& corner = geometry.corner(i);
2373 corners[i] = {
static_cast<Scalar
>(corner[0]),
static_cast<Scalar
>(corner[1]),
static_cast<Scalar
>(corner[2])};
2377 std::vector<std::array<Scalar, 2>> intersectionPoints;
2378 const Scalar tol = 1e-10;
2381 for (
size_t i = 0; i < corners.size(); ++i) {
2382 for (
size_t j = i + 1; j < corners.size(); ++j) {
2383 Scalar za = corners[i][2];
2384 Scalar zb = corners[j][2];
2386 if ((za - depth) * (zb - depth) <= 0.0 && std::abs(za - zb) > tol) {
2388 Scalar t = (depth - za) / (zb - za);
2389 Scalar x = corners[i][0] + t * (corners[j][0] - corners[i][0]);
2390 Scalar y = corners[i][1] + t * (corners[j][1] - corners[i][1]);
2391 intersectionPoints.push_back({x, y});
2397 if (intersectionPoints.size() > 1) {
2398 auto pointsEqual = [tol](
const std::array<Scalar, 2>& a,
const std::array<Scalar, 2>& b) {
2399 return std::abs(a[0] - b[0]) < tol && std::abs(a[1] - b[1]) < tol;
2402 intersectionPoints.erase(
2403 std::unique(intersectionPoints.begin(), intersectionPoints.end(), pointsEqual),
2404 intersectionPoints.end()
2408 if (intersectionPoints.size() < 3) {
2414 Scalar cx = 0, cy = 0;
2415 for (
const auto& p : intersectionPoints) {
2416 cx += p[0]; cy += p[1];
2418 cx /= intersectionPoints.size();
2419 cy /= intersectionPoints.size();
2422 auto angleCompare = [cx, cy](
const std::array<Scalar, 2>& a,
const std::array<Scalar, 2>& b) {
2423 return std::atan2(a[1] - cy, a[0] - cx) < std::atan2(b[1] - cy, b[0] - cx);
2426 std::sort(intersectionPoints.begin(), intersectionPoints.end(), angleCompare);
2428 return polygonArea(intersectionPoints);
2430 }
catch (
const std::exception& e) {
2435 auto cellProcessor = [
this, acc, &eqreg, &ptable, &psat, &computeCrossSectionArea]
2437 Details::PhaseQuantityValue<Scalar>& pressures,
2438 Details::PhaseQuantityValue<Scalar>& saturations,
2441 Scalar&
Rvw) ->
void
2444 saturations.reset();
2445 Scalar totalWeight = 0.0;
2447 const auto& zmin = this->cellZMinMax_[cell].first;
2448 const auto& zmax = this->cellZMinMax_[cell].second;
2449 const Scalar cellThickness = zmax - zmin;
2450 const Scalar halfThickness = cellThickness / 2.0;
2453 Scalar dipAngle, dipAzimuth;
2457 std::array<Scalar, 3> referencePoint = {
2458 this->cellCenterXY_[cell].first,
2459 this->cellCenterXY_[cell].second,
2460 cellCenterDepth_[cell]
2464 const int numLevelsPerHalf = std::min(20, acc);
2467 std::vector<std::pair<Scalar, Scalar>> levels;
2470 for (
int side = 0; side < 2; ++side) {
2471 Scalar halfStart = (side == 0) ? zmin : zmin + halfThickness;
2473 for (
int i = 0; i < numLevelsPerHalf; ++i) {
2475 Scalar depth = halfStart + (i + 0.5) * (halfThickness / numLevelsPerHalf);
2478 Scalar crossSectionArea = computeCrossSectionArea(cell, depth);
2481 Scalar weight = crossSectionArea * (halfThickness / numLevelsPerHalf);
2483 levels.emplace_back(depth, weight);
2488 bool hasValidAreas =
false;
2489 for (
const auto& level : levels) {
2490 if (level.second > 1e-10) {
2491 hasValidAreas =
true;
2496 if (!hasValidAreas) {
2499 for (
int side = 0; side < 2; ++side) {
2500 Scalar halfStart = (side == 0) ? zmin : zmin + halfThickness;
2501 for (
int i = 0; i < numLevelsPerHalf; ++i) {
2502 Scalar depth = halfStart + (i + 0.5) * (halfThickness / numLevelsPerHalf);
2503 Scalar weight = (halfThickness / numLevelsPerHalf);
2504 if (std::abs(dipAngle) > 1e-10) {
2505 weight /= std::cos(dipAngle);
2507 levels.emplace_back(depth, weight);
2512 for (
const auto& level : levels) {
2513 Scalar depth = level.first;
2514 Scalar weight = level.second;
2517 const auto& xy = this->cellCenterXY_[cell];
2519 depth, xy.first, xy.second, dipAngle, dipAzimuth, referencePoint);
2521 const auto pos = CellPos{cell, tvd};
2523 auto localSaturations = psat.deriveSaturations(pos, eqreg, ptable);
2524 auto localPressures = psat.correctedPhasePressures();
2527 saturations.axpy(localSaturations, weight);
2528 pressures.axpy(localPressures, weight);
2529 totalWeight += weight;
2532 if (totalWeight > 1e-10) {
2533 saturations /= totalWeight;
2534 pressures /= totalWeight;
2537 const auto& xy = this->cellCenterXY_[cell];
2539 this->cellCenterDepth_[cell], xy.first, xy.second, dipAngle, dipAzimuth, referencePoint);
2540 const auto pos = CellPos{cell, tvdCenter};
2541 saturations = psat.deriveSaturations(pos, eqreg, ptable);
2542 pressures = psat.correctedPhasePressures();
2546 const auto temp = this->temperature_[cell];
2547 const auto& xy = this->cellCenterXY_[cell];
2549 this->cellCenterDepth_[cell], xy.first, xy.second, dipAngle, dipAzimuth, referencePoint);
2551 Rs = eqreg.dissolutionCalculator()(tvdCenter, pressures.oil, temp, saturations.gas);
2552 Rv = eqreg.evaporationCalculator()(tvdCenter, pressures.gas, temp, saturations.oil);
2553 Rvw = eqreg.waterEvaporationCalculator()(tvdCenter, pressures.gas, temp, saturations.water);
2556 this->cellLoop(cells, cellProcessor);
#define OPM_END_PARALLEL_TRY_CATCH(prefix, comm)
Catch exception and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:192
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:158
Auxiliary routines that to solve the ODEs that emerge from the hydrostatic equilibrium problem.
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:325
Routines that actually solve the ODEs that emerge from the hydrostatic equilibrium problem.
Definition: InitStateEquil.hpp:704
Definition: InitStateEquil.hpp:151
Gas(const TabulatedFunction &tempVdTable, const RV &rv, const RVW &rvw, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:472
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:488
Definition: InitStateEquil.hpp:126
Oil(const TabulatedFunction &tempVdTable, const RS &rs, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:424
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:438
Definition: InitStateEquil.hpp:101
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:398
Water(const TabulatedFunction &tempVdTable, const TabulatedFunction &saltVdTable, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:384
Definition: InitStateEquil.hpp:399
const PhaseQuantityValue< Scalar > & deriveSaturations(const Position &x, const Region ®, const PTable &ptable)
Definition: InitStateEquil_impl.hpp:730
PhaseSaturations(MaterialLawManager &matLawMgr, const std::vector< Scalar > &swatInit)
Definition: InitStateEquil_impl.hpp:706
Definition: InitStateEquil.hpp:180
PressureTable & operator=(const PressureTable &rhs)
Definition: InitStateEquil_impl.hpp:1151
Scalar water(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1231
Scalar gas(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1220
bool waterActive() const
Predicate for whether or not water is an active phase.
Definition: InitStateEquil_impl.hpp:1202
bool gasActive() const
Predicate for whether or not gas is an active phase.
Definition: InitStateEquil_impl.hpp:1195
Scalar oil(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1210
std::array< Scalar, 2 > VSpan
Definition: InitStateEquil.hpp:183
bool oilActive() const
Predicate for whether or not oil is an active phase.
Definition: InitStateEquil_impl.hpp:1188
typename FluidSystem::Scalar Scalar
Definition: InitStateEquil.hpp:182
void equilibrate(const Region ®, const VSpan &span)
Definition: InitStateEquil_impl.hpp:1177
PressureTable(const Scalar gravity, const int samplePoints=2000)
Definition: InitStateEquil_impl.hpp:1121
Definition: InitStateEquil.hpp:80
Scalar operator()(const Scalar x) const
Definition: InitStateEquil_impl.hpp:350
RK4IVP(const RHS &f, const std::array< Scalar, 2 > &span, const Scalar y0, const int N)
Definition: InitStateEquil_impl.hpp:315
Definition: EquilibrationHelpers.hpp:135
Definition: EquilibrationHelpers.hpp:216
Definition: EquilibrationHelpers.hpp:269
Definition: EquilibrationHelpers.hpp:162
Definition: EquilibrationHelpers.hpp:322
Definition: EquilibrationHelpers.hpp:376
std::vector< EquilRecord > getEquil(const EclipseState &state)
Definition: InitStateEquil_impl.hpp:1425
std::vector< int > equilnum(const EclipseState &eclipseState, const GridView &gridview)
Definition: InitStateEquil_impl.hpp:1439
std::pair< Scalar, Scalar > cellZMinMax(const Element &element)
Definition: InitStateEquil_impl.hpp:182
Scalar cellCenterDepth(const Element &element)
Definition: InitStateEquil_impl.hpp:129
std::pair< Scalar, Scalar > cellZSpan(const Element &element)
Definition: InitStateEquil_impl.hpp:163
CellCornerData< Scalar > getCellCornerXY(const Element &element)
Definition: InitStateEquil_impl.hpp:252
void verticalExtent(const CellRange &cells, const std::vector< std::pair< Scalar, Scalar > > &cellZMinMax, const Parallel::Communication &comm, std::array< Scalar, 2 > &span)
Definition: InitStateEquil_impl.hpp:65
std::pair< Scalar, Scalar > cellCenterXY(const Element &element)
Definition: InitStateEquil_impl.hpp:144
Scalar calculateTrueVerticalDepth(Scalar z, Scalar x, Scalar y, Scalar dipAngle, Scalar dipAzimuth, const std::array< Scalar, 3 > &referencePoint)
Definition: InitStateEquil_impl.hpp:276
void subdivisionCentrePoints(const Scalar left, const Scalar right, const int numIntervals, std::vector< std::pair< Scalar, Scalar > > &subdiv)
Definition: InitStateEquil_impl.hpp:90
std::vector< std::pair< Scalar, Scalar > > horizontalSubdivision(const CellID cell, const std::pair< Scalar, Scalar > topbot, const int numIntervals)
Definition: InitStateEquil_impl.hpp:108
void computeBlockDip(const CellCornerData< Scalar > &cellCorners, Scalar &dipAngle, Scalar &dipAzimuth)
Definition: InitStateEquil_impl.hpp:201
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:43
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
Definition: InitStateEquil.hpp:61
std::array< Scalar, 8 > X
Definition: InitStateEquil.hpp:62
std::array< Scalar, 8 > Y
Definition: InitStateEquil.hpp:63
std::array< Scalar, 8 > Z
Definition: InitStateEquil.hpp:64
Simple set of per-phase (named by primary component) quantities.
Definition: InitStateEquil.hpp:351
Definition: InitStateEquil.hpp:405