MinpvProcessor.hpp
Go to the documentation of this file.
1 /*
2  Copyright 2014 SINTEF ICT, Applied Mathematics.
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 
20 #ifndef OPM_MINPVPROCESSOR_HEADER_INCLUDED
21 #define OPM_MINPVPROCESSOR_HEADER_INCLUDED
22 
23 
24 #include <opm/common/ErrorMacros.hpp>
25 #include <array>
26 
27 
28 namespace Opm
29 {
30 
33  {
34  public:
39  MinpvProcessor(const int nx, const int ny, const int nz);
48  void process(const std::vector<double>& pv,
49  const double minpv,
50  const std::vector<int>& actnum,
51  double* zcorn) const;
52  private:
53  std::array<int,8> cornerIndices(const int i, const int j, const int k) const;
54  std::array<double, 8> getCellZcorn(const int i, const int j, const int k, const double* z) const;
55  void setCellZcorn(const int i, const int j, const int k, const std::array<double, 8>& cellz, double* z) const;
56  std::array<int, 3> dims_;
57  std::array<int, 3> delta_;
58  };
59 
60  inline MinpvProcessor::MinpvProcessor(const int nx, const int ny, const int nz)
61  {
62  // Not doing init-list init since bracket-init not available
63  // for all compilers we support (gcc 4.4).
64  dims_[0] = nx;
65  dims_[1] = ny;
66  dims_[2] = nz;
67  delta_[0] = 1;
68  delta_[1] = 2*nx;
69  delta_[2] = 4*nx*ny;
70  }
71 
72 
73 
74  inline void MinpvProcessor::process(const std::vector<double>& pv,
75  const double minpv,
76  const std::vector<int>& actnum,
77  double* zcorn) const
78  {
79  // Algorithm:
80  // 1. Process each column of cells (with same i and j
81  // coordinates) from top (low k) to bottom (high k).
82  // 2. For each cell 'c' visited, check if its pore volume
83  // pv[c] is less than minpv.
84  // 3. If below the minpv threshold, move the lower four
85  // zcorn associated with the cell c to coincide with
86  // the upper four (so it becomes degenerate). Also move
87  // the higher four zcorn associated with the cell below
88  // to these values (so it gains the deleted volume).
89 
90  // Check for sane input sizes.
91  const size_t log_size = dims_[0] * dims_[1] * dims_[2];
92  if (pv.size() != log_size) {
93  OPM_THROW(std::runtime_error, "Wrong size of PORV input, must have one element per logical cartesian cell.");
94  }
95  if (!actnum.empty() && actnum.size() != log_size) {
96  OPM_THROW(std::runtime_error, "Wrong size of ACTNUM input, must have one element per logical cartesian cell.");
97  }
98 
99  // Main loop.
100  for (int kk = 0; kk < dims_[2]; ++kk) {
101  for (int jj = 0; jj < dims_[1]; ++jj) {
102  for (int ii = 0; ii < dims_[0]; ++ii) {
103  const int c = ii + dims_[0] * (jj + dims_[1] * kk);
104  if (pv[c] < minpv && (actnum.empty() || actnum[c])) {
105  // Move deeper (higher k) coordinates to lower k coordinates.
106  std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);
107  for (int count = 0; count < 4; ++count) {
108  cz[count + 4] = cz[count];
109  }
110  setCellZcorn(ii, jj, kk, cz, zcorn);
111  // Check if there is a cell below.
112  if (pv[c] > 0.0 && kk < dims_[2] - 1) {
113  // Set lower k coordinates of cell below to upper cells's coordinates.
114  std::array<double, 8> cz_below = getCellZcorn(ii, jj, kk + 1, zcorn);
115  for (int count = 0; count < 4; ++count) {
116  cz_below[count] = cz[count];
117  }
118  setCellZcorn(ii, jj, kk + 1, cz_below, zcorn);
119  }
120  }
121  }
122  }
123  }
124  }
125 
126 
127 
128  inline std::array<int,8> MinpvProcessor::cornerIndices(const int i, const int j, const int k) const
129  {
130  const int ix = 2*(i*delta_[0] + j*delta_[1] + k*delta_[2]);
131  std::array<int, 8> ixs = {{ ix, ix + delta_[0],
132  ix + delta_[1], ix + delta_[1] + delta_[0],
133  ix + delta_[2], ix + delta_[2] + delta_[0],
134  ix + delta_[2] + delta_[1], ix + delta_[2] + delta_[1] + delta_[0] }};
135 
136  return ixs;
137  }
138 
139 
140 
141  // Returns the eight z-values associated with a given cell.
142  // The ordering is such that i runs fastest. That is, with
143  // L = low and H = high:
144  // {LLL, HLL, LHL, HHL, LLH, HLH, LHH, HHH }.
145  inline std::array<double, 8> MinpvProcessor::getCellZcorn(const int i, const int j, const int k, const double* z) const
146  {
147  const std::array<int, 8> ixs = cornerIndices(i, j, k);
148  std::array<double, 8> cellz;
149  for (int count = 0; count < 8; ++count) {
150  cellz[count] = z[ixs[count]];
151  }
152  return cellz;
153  }
154 
155 
156 
157  inline void MinpvProcessor::setCellZcorn(const int i, const int j, const int k, const std::array<double, 8>& cellz, double* z) const
158  {
159  const std::array<int, 8> ixs = cornerIndices(i, j, k);
160  for (int count = 0; count < 8; ++count) {
161  z[ixs[count]] = cellz[count];
162  }
163  }
164 
165 
166 
167 } // namespace Opm
168 
169 #endif // OPM_MINPVPROCESSOR_HEADER_INCLUDED
Definition: AnisotropicEikonal.hpp:43
void process(const std::vector< double > &pv, const double minpv, const std::vector< int > &actnum, double *zcorn) const
Definition: MinpvProcessor.hpp:74
Transform a corner-point grid ZCORN field to account for MINPV processing.
Definition: MinpvProcessor.hpp:32
MinpvProcessor(const int nx, const int ny, const int nz)
Create a processor.
Definition: MinpvProcessor.hpp:60