RegionPhasePVAverage.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 Copyright 2024 Equinor AS
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
23#define OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
24
26
27#include <cstddef>
28#include <functional>
29#include <string>
30#include <string_view>
31#include <vector>
32
33namespace Opm {
34
42 {
43 public:
45 struct CellValue
46 {
48 double value { 0.0 };
49
51 double sat { 0.0 };
52
54 double porv { 0.0 };
55 };
56
58 struct Phase
59 {
61 unsigned int ix;
62 };
63
65 struct Region
66 {
68 unsigned int ix;
69 };
70
72 using RegionArrayAccessor = std::function<const std::vector<int>&(const std::string&)>;
73
88 std::size_t numPhases,
89 const std::vector<std::string>& regionNames,
90 RegionArrayAccessor getRegionArray);
91
98 double fieldValue(const Phase& p) const;
99
112 double value(std::string_view rset, const Phase& p, const Region& r) const;
113
117
126 void addCell(std::size_t activeCell, const Phase& p, const CellValue& cv);
127
134
135 private:
137 using Ix = std::vector<double>::size_type;
138
140 enum AvgType {
141 SatPV, //< Weighted by phase-filled pore-volume.
142 PV, //< Weighted by total pore-volume (s=1).
143
144 // ---- Must be last enumerator ----
145 NumTypes, //< Number of averge types.
146 };
147
149 enum Element {
150 Value, //< Running sum of weighted function values.
151 Weight, //< Running sum of weights.
152
153 // ---- Must be last enumerator ----
154 NumElem, //< Number of items/elements per average type.
155 };
156
158 std::reference_wrapper<const Parallel::Communication> comm_;
159
161 std::size_t np_{};
162
164 std::vector<std::string> rsetNames_{};
165
167 RegionArrayAccessor getRegionArray_;
168
173 std::vector<Ix> rsStart_{};
174
190 std::vector<double> x_{};
191
204 double averageValueWithFallback(Ix start) const;
205
216 double averageValue(Ix start, AvgType type) const;
217
224 Ix fieldStartIx(unsigned int phase) const;
225
236 Ix rsetStartIx(std::size_t rset, int region, unsigned int phase) const;
237
246 Ix startIx(std::size_t offset, unsigned int phase) const;
247
257 int regionIndex(std::size_t rset, std::size_t activeCell) const;
258
267 void add(Ix start, const CellValue& cv);
268
281 void add(Ix start, AvgType type, double x, double w);
282
294 double& value(Ix start, AvgType type);
295
307 double& weight(Ix start, AvgType type);
308
319 double value(Ix start, AvgType type) const;
320
331 double weight(Ix start, AvgType type) const;
332
349 Ix valueArrayIndex(Ix start, AvgType type, Element element) const;
350 };
351} // namespace Opm
352
353#endif // OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
Definition: RegionPhasePVAverage.hpp:42
void addCell(std::size_t activeCell, const Phase &p, const CellValue &cv)
double fieldValue(const Phase &p) const
std::function< const std::vector< int > &(const std::string &)> RegionArrayAccessor
Call-back function type for accessing region arrays–typically the FIP* arrays.
Definition: RegionPhasePVAverage.hpp:72
RegionPhasePoreVolAverage(const Parallel::Communication &comm, std::size_t numPhases, const std::vector< std::string > &regionNames, RegionArrayAccessor getRegionArray)
double value(std::string_view rset, const Phase &p, const Region &r) const
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: BlackoilPhases.hpp:27
Minimal characteristics of a cell from a simulation grid.
Definition: RegionPhasePVAverage.hpp:46
double value
Function value.
Definition: RegionPhasePVAverage.hpp:48
double porv
Reservoir condition pore-volume.
Definition: RegionPhasePVAverage.hpp:54
double sat
Phase saturation.
Definition: RegionPhasePVAverage.hpp:51
Compile-time disambiguation type for phases.
Definition: RegionPhasePVAverage.hpp:59
unsigned int ix
Phase index.
Definition: RegionPhasePVAverage.hpp:61
Compile-time disambiguation type for regions.
Definition: RegionPhasePVAverage.hpp:66
unsigned int ix
Region index.
Definition: RegionPhasePVAverage.hpp:68