FlowThresholdPressure.hpp
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18
19 Consult the COPYING file in the top-level source directory of this
20 module for the precise wording of the license and the list of
21 copyright holders.
22*/
28#ifndef OPM_FLOW_THRESHOLD_PRESSURE_HPP
29#define OPM_FLOW_THRESHOLD_PRESSURE_HPP
30
31#include <opm/material/densead/Evaluation.hpp>
32#include <opm/material/densead/Math.hpp>
33
34#include <opm/models/common/multiphasebaseproperties.hh>
35#include <opm/models/discretization/common/fvbaseproperties.hh>
36#include <opm/models/utils/propertysystem.hh>
37
39
40#include <algorithm>
41
42namespace Opm {
43
54template <class TypeTag>
55class FlowThresholdPressure : public GenericThresholdPressure<GetPropType<TypeTag, Properties::Grid>,
56 GetPropType<TypeTag, Properties::GridView>,
57 GetPropType<TypeTag, Properties::ElementMapper>,
58 GetPropType<TypeTag, Properties::Scalar>>
59{
61 GetPropType<TypeTag, Properties::GridView>,
62 GetPropType<TypeTag, Properties::ElementMapper>,
63 GetPropType<TypeTag, Properties::Scalar>>;
64 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
65 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
66 using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
67 using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
68 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
69
70 enum { numPhases = FluidSystem::numPhases };
71
72public:
73 FlowThresholdPressure(const Simulator& simulator)
74 : BaseType(simulator.vanguard().cartesianIndexMapper(),
75 simulator.vanguard().gridView(),
76 simulator.model().elementMapper(),
77 simulator.vanguard().eclState())
78 , simulator_(simulator)
79 {
80 }
81
86 {
88 if (this->enableThresholdPressure_ && !this->thpresDefault_.empty()) {
89 this->computeDefaultThresholdPressures_();
91 }
92 }
93
94private:
95 // compute the defaults of the threshold pressures using the initial condition
96 void computeDefaultThresholdPressures_()
97 {
98 const auto& vanguard = simulator_.vanguard();
99 const auto& gridView = vanguard.gridView();
100
101 using Toolbox = MathToolbox<Evaluation>;
102 // loop over the whole grid and compute the maximum gravity adjusted pressure
103 // difference between two EQUIL regions.
104 ElementContext elemCtx(simulator_);
105 for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
106 elemCtx.updateAll(elem);
107 const auto& stencil = elemCtx.stencil(/*timeIdx=*/0);
108
109 for (unsigned scvfIdx = 0; scvfIdx < stencil.numInteriorFaces(); ++ scvfIdx) {
110 const auto& face = stencil.interiorFace(scvfIdx);
111
112 unsigned i = face.interiorIndex();
113 unsigned j = face.exteriorIndex();
114
115 unsigned insideElemIdx = elemCtx.globalSpaceIndex(i, /*timeIdx=*/0);
116 unsigned outsideElemIdx = elemCtx.globalSpaceIndex(j, /*timeIdx=*/0);
117
118 unsigned equilRegionInside = this->elemEquilRegion_[insideElemIdx];
119 unsigned equilRegionOutside = this->elemEquilRegion_[outsideElemIdx];
120
121 if (equilRegionInside == equilRegionOutside)
122 // the current face is not at the boundary between EQUIL regions!
123 continue;
124
125 // don't include connections with negligible flow
126 const Evaluation& trans = simulator_.problem().transmissibility(elemCtx, i, j);
127 Scalar faceArea = face.area();
128 if (std::abs(faceArea*getValue(trans)) < 1e-18)
129 continue;
130
131 // determine the maximum difference of the pressure of any phase over the
132 // intersection
133 Scalar pth = 0.0;
134 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, /*timeIdx=*/0);
135 for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
136 unsigned upIdx = extQuants.upstreamIndex(phaseIdx);
137 const auto& up = elemCtx.intensiveQuantities(upIdx, /*timeIdx=*/0);
138
139 if (up.mobility(phaseIdx) > 0.0) {
140 Scalar phaseVal = Toolbox::value(extQuants.pressureDifference(phaseIdx));
141 pth = std::max(pth, std::abs(phaseVal));
142 }
143 }
144
145 int offset1 = equilRegionInside*this->numEquilRegions_ + equilRegionOutside;
146 int offset2 = equilRegionOutside*this->numEquilRegions_ + equilRegionInside;
147
148 this->thpresDefault_[offset1] = std::max(this->thpresDefault_[offset1], pth);
149 this->thpresDefault_[offset2] = std::max(this->thpresDefault_[offset2], pth);
150 }
151 }
152
153 // make sure that the threshold pressures is consistent for parallel
154 // runs. (i.e. take the maximum of all processes)
155 for (unsigned i = 0; i < this->thpresDefault_.size(); ++i)
156 this->thpresDefault_[i] = gridView.comm().max(this->thpresDefault_[i]);
157
158 this->logPressures();
159 }
160
161 const Simulator& simulator_;
162};
163
164} // namespace Opm
165
166#endif // OPM_FLOW_THRESHOLD_PRESSURE_HPP
This class calculates the threshold pressure for grid faces according to the Eclipse Reference Manual...
Definition: FlowThresholdPressure.hpp:59
FlowThresholdPressure(const Simulator &simulator)
Definition: FlowThresholdPressure.hpp:73
void finishInit()
Actually compute the threshold pressures over a face as a pre-compute step.
Definition: FlowThresholdPressure.hpp:85
Definition: GenericThresholdPressure.hpp:43
Definition: BlackoilPhases.hpp:27