InitStateEquil.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 3 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*/
29#ifndef OPM_INIT_STATE_EQUIL_HPP
30#define OPM_INIT_STATE_EQUIL_HPP
31
33
34#include <opm/material/common/Tabulated1DFunction.hpp>
35#include <opm/material/fluidstates/SimpleModularFluidState.hpp>
36
39
40#include <array>
41#include <cstddef>
42#include <memory>
43#include <utility>
44#include <vector>
45#include <string>
46
47namespace Opm {
48
49class EclipseState;
50class EquilRecord;
51class NumericalAquifers;
52
60namespace EQUIL {
61
62template<class Scalar> struct CellCornerData {
63 std::array<Scalar, 8> X;
64 std::array<Scalar, 8> Y;
65 std::array<Scalar, 8> Z;
66 CellCornerData() = default;
67
68 CellCornerData(const std::array<Scalar, 8>& x,
69 const std::array<Scalar, 8>& y,
70 const std::array<Scalar, 8>& z)
71 : X(x), Y(y), Z(z)
72 {}
73};
74
75template<class Scalar> class EquilReg;
76namespace Miscibility { template<class Scalar> class RsFunction; }
77
78namespace Details {
79
80namespace PhasePressODE {
81template <class FluidSystem>
82class Water
83{
84 using Scalar = typename FluidSystem::Scalar;
85 using TabulatedFunction = Tabulated1DFunction<Scalar>;
86
87public:
88 Water(const TabulatedFunction& tempVdTable,
89 const TabulatedFunction& saltVdTable,
90 const int pvtRegionIdx,
91 const Scalar normGrav);
92
93 Scalar operator()(const Scalar depth,
94 const Scalar press) const;
95
96private:
97 const TabulatedFunction& tempVdTable_;
98 const TabulatedFunction& saltVdTable_;
99 const int pvtRegionIdx_;
100 const Scalar g_;
101
102 Scalar density(const Scalar depth,
103 const Scalar press) const;
104};
105
106template <class FluidSystem, class RS>
107class Oil
108{
109 using Scalar = typename FluidSystem::Scalar;
110 using TabulatedFunction = Tabulated1DFunction<Scalar>;
111
112public:
113 Oil(const TabulatedFunction& tempVdTable,
114 const RS& rs,
115 const int pvtRegionIdx,
116 const Scalar normGrav);
117
118 Scalar operator()(const Scalar depth,
119 const Scalar press) const;
120
121private:
122 const TabulatedFunction& tempVdTable_;
123 const RS& rs_;
124 const int pvtRegionIdx_;
125 const Scalar g_;
126
127 Scalar density(const Scalar depth,
128 const Scalar press) const;
129};
130
131template <class FluidSystem, class RV, class RVW>
132class Gas
133{
134 using Scalar = typename FluidSystem::Scalar;
135 using TabulatedFunction = Tabulated1DFunction<Scalar>;
136
137public:
138 Gas(const TabulatedFunction& tempVdTable,
139 const RV& rv,
140 const RVW& rvw,
141 const int pvtRegionIdx,
142 const Scalar normGrav);
143
144 Scalar operator()(const Scalar depth,
145 const Scalar press) const;
146
147private:
148 const TabulatedFunction& tempVdTable_;
149 const RV& rv_;
150 const RVW& rvw_;
151 const int pvtRegionIdx_;
152 const Scalar g_;
153
154 Scalar density(const Scalar depth,
155 const Scalar press) const;
156};
157
158} // namespace PhasePressODE
159
160template <class FluidSystem, class Region>
162{
163public:
164 using Scalar = typename FluidSystem::Scalar;
165 using VSpan = std::array<Scalar, 2>;
166
175 explicit PressureTable(const Scalar gravity,
176 const int samplePoints = 2000);
177
181 PressureTable(const PressureTable& rhs);
182
189
196
205
206 void equilibrate(const Region& reg,
207 const VSpan& span);
208
210 bool oilActive() const;
211
213 bool gasActive() const;
214
216 bool waterActive() const;
217
225 Scalar oil(const Scalar depth) const;
226
234 Scalar gas(const Scalar depth) const;
235
243 Scalar water(const Scalar depth) const;
244
245private:
246 template <class ODE>
248
250 FluidSystem, typename Region::CalcDissolution
251 >;
252
254 FluidSystem, typename Region::CalcEvaporation, typename Region::CalcWaterEvaporation
255 >;
256
258
262
263 using Strategy = void (PressureTable::*)
264 (const Region&, const VSpan&);
265
266 Scalar gravity_;
267 int nsample_;
268
269 std::unique_ptr<OPress> oil_{};
270 std::unique_ptr<GPress> gas_{};
271 std::unique_ptr<WPress> wat_{};
272
273 template <typename PressFunc>
274 void checkPtr(const PressFunc* phasePress,
275 const std::string& phaseName) const;
276
277 Strategy selectEquilibrationStrategy(const Region& reg) const;
278
279 void copyInPointers(const PressureTable& rhs);
280
281 void equil_WOG(const Region& reg, const VSpan& span);
282 void equil_GOW(const Region& reg, const VSpan& span);
283 void equil_OWG(const Region& reg, const VSpan& span);
284
285 void makeOilPressure(const typename OPress::InitCond& ic,
286 const Region& reg,
287 const VSpan& span);
288
289 void makeGasPressure(const typename GPress::InitCond& ic,
290 const Region& reg,
291 const VSpan& span);
292
293 void makeWatPressure(const typename WPress::InitCond& ic,
294 const Region& reg,
295 const VSpan& span);
296};
297
298// ===========================================================================
299
301template<class Scalar>
303 Scalar oil{0.0};
304 Scalar gas{0.0};
305 Scalar water{0.0};
306
307 PhaseQuantityValue& axpy(const PhaseQuantityValue& rhs, const Scalar a)
308 {
309 this->oil += a * rhs.oil;
310 this->gas += a * rhs.gas;
311 this->water += a * rhs.water;
312
313 return *this;
314 }
315
317 {
318 this->oil /= x;
319 this->gas /= x;
320 this->water /= x;
321
322 return *this;
323 }
324
325 void reset()
326 {
327 this->oil = this->gas = this->water = 0.0;
328 }
329};
330
348template <class MaterialLawManager, class FluidSystem, class Region, typename CellID>
350{
351public:
352 using Scalar = typename FluidSystem::Scalar;
356 struct Position {
357 CellID cell;
359 };
360
363
371 explicit PhaseSaturations(MaterialLawManager& matLawMgr,
372 const std::vector<Scalar>& swatInit);
373
378
381
384
399 const Region& reg,
400 const PTable& ptable);
401
407 {
408 return this->press_;
409 }
410
411private:
414 struct EvaluationPoint {
415 const Position* position{nullptr};
416 const Region* region {nullptr};
417 const PTable* ptable {nullptr};
418 };
419
423 using FluidState = ::Opm::
424 SimpleModularFluidState<Scalar, /*numPhases=*/3, /*numComponents=*/3,
425 FluidSystem,
426 /*storePressure=*/false,
427 /*storeTemperature=*/false,
428 /*storeComposition=*/false,
429 /*storeFugacity=*/false,
430 /*storeSaturation=*/true,
431 /*storeDensity=*/false,
432 /*storeViscosity=*/false,
433 /*storeEnthalpy=*/false>;
434
436 using MaterialLaw = typename MaterialLawManager::MaterialLaw;
437
439 using PhaseIdx = std::remove_cv_t<
440 std::remove_reference_t<decltype(FluidSystem::oilPhaseIdx)>
441 >;
442
444 MaterialLawManager& matLawMgr_;
445
447 const std::vector<Scalar>& swatInit_;
448
450 PhaseQuantityValue<Scalar> sat_;
451
453 PhaseQuantityValue<Scalar> press_;
454
456 EvaluationPoint evalPt_;
457
459 FluidState fluidState_;
460
462 std::array<Scalar, FluidSystem::numPhases> matLawCapPress_;
463
473 void setEvaluationPoint(const Position& x,
474 const Region& reg,
475 const PTable& ptable);
476
480 void initializePhaseQuantities();
481
485 void deriveOilSat();
486
491 void deriveGasSat();
492
499 void deriveWaterSat();
500
503 void fixUnphysicalTransition();
504
507 void accountForScaledSaturations();
508
509 // --------------------------------------------------------------------
510 // Note: Function 'applySwatInit' is non-const because the overload set
511 // needs to mutate the 'matLawMgr_'.
512 // --------------------------------------------------------------------
513
523 std::pair<Scalar, bool> applySwatInit(const Scalar pcow);
524
537 std::pair<Scalar, bool> applySwatInit(const Scalar pc, const Scalar sw);
538
541 void computeMaterialLawCapPress();
542
545 Scalar materialLawCapPressGasOil() const;
546
549 Scalar materialLawCapPressOilWater() const;
550
553 Scalar materialLawCapPressGasWater() const;
554
562 bool isConstCapPress(const PhaseIdx phaseIdx) const;
563
569 bool isOverlappingTransition() const;
570
590 Scalar fromDepthTable(const Scalar contactdepth,
591 const PhaseIdx phasePos,
592 const bool isincr) const;
593
611 Scalar invertCapPress(const Scalar pc,
612 const PhaseIdx phasePos,
613 const bool isincr) const;
614
616 PhaseIdx oilPos() const
617 {
618 return FluidSystem::oilPhaseIdx;
619 }
620
622 PhaseIdx gasPos() const
623 {
624 return FluidSystem::gasPhaseIdx;
625 }
626
628 PhaseIdx waterPos() const
629 {
630 return FluidSystem::waterPhaseIdx;
631 }
632};
633
634// ===========================================================================
635
636template <typename CellRange, class Scalar>
637void verticalExtent(const CellRange& cells,
638 const std::vector<std::pair<Scalar, Scalar>>& cellZMinMax,
639 const Parallel::Communication& comm,
640 std::array<Scalar,2>& span);
641
642template <class Scalar, class Element>
643std::pair<Scalar,Scalar> cellZMinMax(const Element& element);
644
645} // namespace Details
646
647namespace DeckDependent {
648
649template<class FluidSystem,
650 class Grid,
651 class GridView,
652 class ElementMapper,
653 class CartesianIndexMapper>
655{
656 using Element = typename GridView::template Codim<0>::Entity;
657 using Scalar = typename FluidSystem::Scalar;
658public:
659 template<class MaterialLawManager>
660 InitialStateComputer(MaterialLawManager& materialLawManager,
661 const EclipseState& eclipseState,
662 const Grid& grid,
663 const GridView& gridView,
664 const CartesianIndexMapper& cartMapper,
665 const Scalar grav,
666 const int num_pressure_points = 2000,
667 const bool applySwatInit = true);
668
669 using Vec = std::vector<Scalar>;
670 using PVec = std::vector<Vec>; // One per phase.
671
672 const Vec& temperature() const { return temperature_; }
673 const Vec& saltConcentration() const { return saltConcentration_; }
674 const Vec& saltSaturation() const { return saltSaturation_; }
675 const PVec& press() const { return pp_; }
676 const PVec& saturation() const { return sat_; }
677 const Vec& rs() const { return rs_; }
678 const Vec& rv() const { return rv_; }
679 const Vec& rvw() const { return rvw_; }
680
681private:
682 template <class RMap>
683 void updateInitialTemperature_(const EclipseState& eclState, const RMap& reg);
684
685 template <class RMap>
686 void updateInitialSaltConcentration_(const EclipseState& eclState, const RMap& reg);
687
688 template <class RMap>
689 void updateInitialSaltSaturation_(const EclipseState& eclState, const RMap& reg);
690
691 void updateCellProps_(const GridView& gridView,
692 const NumericalAquifers& aquifer);
693
694 void applyNumericalAquifers_(const GridView& gridView,
695 const NumericalAquifers& aquifer,
696 const bool co2store_or_h2store);
697
698 template<class RMap>
699 void setRegionPvtIdx(const EclipseState& eclState, const GridView& gridView, const RMap& reg);
700
701 template <class RMap, class MaterialLawManager, class Comm>
702 void calcPressSatRsRv(const RMap& reg,
703 const std::vector<EquilRecord>& rec,
704 MaterialLawManager& materialLawManager,
705 const GridView& gridView,
706 const Comm& comm,
707 const Scalar grav);
708
709 template <class CellRange, class EquilibrationMethod>
710 void cellLoop(const CellRange& cells,
711 EquilibrationMethod&& eqmethod);
712
713 template <class CellRange, class PressTable, class PhaseSat>
714 void equilibrateCellCentres(const CellRange& cells,
715 const EquilReg<Scalar>& eqreg,
716 const PressTable& ptable,
717 PhaseSat& psat);
718
719 template <class CellRange, class PressTable, class PhaseSat>
720 void equilibrateHorizontal(const CellRange& cells,
721 const EquilReg<Scalar>& eqreg,
722 const int acc,
723 const PressTable& ptable,
724 PhaseSat& psat);
725
726 template<class CellRange, class PressTable, class PhaseSat>
727 void equilibrateTiltedFaultBlock(const CellRange& cells,
728 const EquilReg<Scalar>& eqreg,
729 const GridView& gridView, const int numLevels,
730 const PressTable& ptable, PhaseSat& psat);
731
732 template<class CellRange, class PressTable, class PhaseSat>
733 void equilibrateTiltedFaultBlockSimple(const CellRange& cells,
734 const EquilReg<Scalar>& eqreg,
735 const GridView& gridView, const int numLevels,
736 const PressTable& ptable, PhaseSat& psat);
737
738 std::vector< std::shared_ptr<Miscibility::RsFunction<Scalar>> > rsFunc_;
739 std::vector< std::shared_ptr<Miscibility::RsFunction<Scalar>> > rvFunc_;
740 std::vector< std::shared_ptr<Miscibility::RsFunction<Scalar>> > rvwFunc_;
741 using TabulatedFunction = Tabulated1DFunction<Scalar>;
742 std::vector<TabulatedFunction> tempVdTable_;
743 std::vector<TabulatedFunction> saltVdTable_;
744 std::vector<TabulatedFunction> saltpVdTable_;
745 std::vector<int> regionPvtIdx_;
746 Vec temperature_;
747 Vec saltConcentration_;
748 Vec saltSaturation_;
749 PVec pp_;
750 PVec sat_;
751 Vec rs_;
752 Vec rv_;
753 Vec rvw_;
754 const CartesianIndexMapper& cartesianIndexMapper_;
755 Vec swatInit_;
756 Vec cellCenterDepth_;
757 std::vector<std::pair<Scalar,Scalar>> cellCenterXY_;
758 std::vector<std::pair<Scalar,Scalar>> cellZSpan_;
759 std::vector<std::pair<Scalar,Scalar>> cellZMinMax_;
760 std::vector<CellCornerData<Scalar>> cellCorners_;
761 int num_pressure_points_;
762};
763
764} // namespace DeckDependent
765} // namespace EQUIL
766} // namespace Opm
767
768#endif // OPM_INIT_STATE_EQUIL_HPP
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:394
The ODE integrator and phase-pressure function used to solve the hydrostatic equilibrium problem,...
Definition: InitStateEquil.hpp:655
std::vector< Vec > PVec
Definition: InitStateEquil.hpp:670
const PVec & press() const
Definition: InitStateEquil.hpp:675
const Vec & rvw() const
Definition: InitStateEquil.hpp:679
InitialStateComputer(MaterialLawManager &materialLawManager, const EclipseState &eclipseState, const Grid &grid, const GridView &gridView, const CartesianIndexMapper &cartMapper, const Scalar grav, const int num_pressure_points=2000, const bool applySwatInit=true)
Definition: InitStateEquil_impl.hpp:1359
const Vec & rv() const
Definition: InitStateEquil.hpp:678
const Vec & saltSaturation() const
Definition: InitStateEquil.hpp:674
const Vec & saltConcentration() const
Definition: InitStateEquil.hpp:673
const Vec & temperature() const
Definition: InitStateEquil.hpp:672
std::vector< Scalar > Vec
Definition: InitStateEquil.hpp:669
const Vec & rs() const
Definition: InitStateEquil.hpp:677
const PVec & saturation() const
Definition: InitStateEquil.hpp:676
Definition: InitStateEquil.hpp:133
Gas(const TabulatedFunction &tempVdTable, const RV &rv, const RVW &rvw, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:411
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:427
Definition: InitStateEquil.hpp:108
Oil(const TabulatedFunction &tempVdTable, const RS &rs, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:363
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:377
Definition: InitStateEquil.hpp:83
Scalar operator()(const Scalar depth, const Scalar press) const
Definition: InitStateEquil_impl.hpp:337
Water(const TabulatedFunction &tempVdTable, const TabulatedFunction &saltVdTable, const int pvtRegionIdx, const Scalar normGrav)
Definition: InitStateEquil_impl.hpp:323
Definition: InitStateEquil.hpp:350
const PhaseQuantityValue< Scalar > & deriveSaturations(const Position &x, const Region &reg, const PTable &ptable)
Definition: InitStateEquil_impl.hpp:587
PhaseSaturations(MaterialLawManager &matLawMgr, const std::vector< Scalar > &swatInit)
Definition: InitStateEquil_impl.hpp:563
typename FluidSystem::Scalar Scalar
Definition: InitStateEquil.hpp:352
PressureTable< FluidSystem, Region > PTable
Convenience type alias.
Definition: InitStateEquil.hpp:362
PhaseSaturations & operator=(const PhaseSaturations &)=delete
Disabled assignment operator.
PhaseSaturations & operator=(PhaseSaturations &&)=delete
Disabled move-assignment operator.
const PhaseQuantityValue< Scalar > & correctedPhasePressures() const
Definition: InitStateEquil.hpp:406
Definition: PressureFunction.hpp:128
Definition: InitStateEquil.hpp:162
PressureTable & operator=(const PressureTable &rhs)
Definition: InitStateEquil_impl.hpp:1027
Scalar water(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1107
Scalar gas(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1096
bool waterActive() const
Predicate for whether or not water is an active phase.
Definition: InitStateEquil_impl.hpp:1078
bool gasActive() const
Predicate for whether or not gas is an active phase.
Definition: InitStateEquil_impl.hpp:1071
Scalar oil(const Scalar depth) const
Definition: InitStateEquil_impl.hpp:1086
std::array< Scalar, 2 > VSpan
Definition: InitStateEquil.hpp:165
bool oilActive() const
Predicate for whether or not oil is an active phase.
Definition: InitStateEquil_impl.hpp:1064
typename FluidSystem::Scalar Scalar
Definition: InitStateEquil.hpp:164
void equilibrate(const Region &reg, const VSpan &span)
Definition: InitStateEquil_impl.hpp:1053
PressureTable(const Scalar gravity, const int samplePoints=2000)
Definition: InitStateEquil_impl.hpp:997
Definition: EquilibrationHelpers.hpp:676
std::pair< Scalar, Scalar > cellZMinMax(const Element &element)
Definition: InitStateEquil_impl.hpp:187
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:70
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
The Opm property system, traits with inheritance.
Definition: InitStateEquil.hpp:62
std::array< Scalar, 8 > X
Definition: InitStateEquil.hpp:63
std::array< Scalar, 8 > Y
Definition: InitStateEquil.hpp:64
CellCornerData(const std::array< Scalar, 8 > &x, const std::array< Scalar, 8 > &y, const std::array< Scalar, 8 > &z)
Definition: InitStateEquil.hpp:68
std::array< Scalar, 8 > Z
Definition: InitStateEquil.hpp:65
Simple set of per-phase (named by primary component) quantities.
Definition: InitStateEquil.hpp:302
void reset()
Definition: InitStateEquil.hpp:325
Scalar gas
Definition: InitStateEquil.hpp:304
Scalar water
Definition: InitStateEquil.hpp:305
PhaseQuantityValue & operator/=(const Scalar x)
Definition: InitStateEquil.hpp:316
Scalar oil
Definition: InitStateEquil.hpp:303
PhaseQuantityValue & axpy(const PhaseQuantityValue &rhs, const Scalar a)
Definition: InitStateEquil.hpp:307
Definition: InitStateEquil.hpp:356
CellID cell
Definition: InitStateEquil.hpp:357
Scalar depth
Definition: InitStateEquil.hpp:358