20#ifndef OPM_MINPVPROCESSOR_HEADER_INCLUDED
21#define OPM_MINPVPROCESSOR_HEADER_INCLUDED
23#include <opm/common/ErrorMacros.hpp>
39 std::vector<std::size_t> removed_cells;
40 std::map<int,int> nnc;
43 void add_nnc(
int cell1,
int cell2) {
44 auto key = std::min(cell1, cell2);
45 auto value = std::max(cell1,cell2);
47 this->nnc.insert({key, value});
71 const double z_tolerance,
72 const std::vector<double>& pv,
73 const std::vector<double>& minpvv,
74 const std::vector<int>& actnum,
75 const bool mergeMinPVCells,
77 bool pinchNOGAP =
false)
const;
79 std::array<int,8> cornerIndices(
const int i,
const int j,
const int k)
const;
80 std::array<double, 8> getCellZcorn(
const int i,
const int j,
const int k,
const double* z)
const;
81 void setCellZcorn(
const int i,
const int j,
const int k,
const std::array<double, 8>& cellz,
double* z)
const;
82 std::array<int, 3> dims_;
83 std::array<int, 3> delta_;
87 dims_( {{nx,ny,nz}} ),
88 delta_( {{1 , 2*nx , 4*nx*ny}} )
94 const double z_tolerance,
95 const std::vector<double>& pv,
96 const std::vector<double>& minpvv,
97 const std::vector<int>& actnum,
98 const bool mergeMinPVCells,
100 bool pinchNOGAP)
const
128 const size_t log_size = dims_[0] * dims_[1] * dims_[2];
129 if (pv.size() != log_size) {
130 OPM_THROW(std::runtime_error,
"Wrong size of PORV input, must have one element per logical cartesian cell.");
132 if (!actnum.empty() && actnum.size() != log_size) {
133 OPM_THROW(std::runtime_error,
"Wrong size of ACTNUM input, must have one element per logical cartesian cell.");
137 for (
int jj = 0; jj < dims_[1]; ++jj) {
138 for (
int ii = 0; ii < dims_[0]; ++ii) {
139 for (
int kk = 0; kk < dims_[2]; ++kk) {
140 const int c = ii + dims_[0] * (jj + dims_[1] * kk);
141 if (pv[c] < minpvv[c] && (actnum.empty() || actnum[c])) {
145 std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);
146 for (
int count = 0; count < 4; ++count) {
147 cz[count + 4] = cz[count];
149 setCellZcorn(ii, jj, kk, cz, zcorn);
150 result.removed_cells.push_back(c);
152 if (kk == dims_[2] - 1) {
159 int kk_iter = kk + 1;
161 int c_below = ii + dims_[0] * (jj + dims_[1] * (kk_iter));
162 bool active = actnum.empty() || actnum[c_below];
163 bool thin = (thickness[c_below] <= z_tolerance);
164 bool thin_inactive = !active && thin;
165 bool low_pv_active = pv[c_below] < minpvv[c_below] && active;
167 bool nnc_allowed = !pinchNOGAP || thickness[c] <= z_tolerance;
169 while ( (thin_inactive || low_pv_active) && kk_iter < dims_[2] )
176 setCellZcorn(ii, jj, kk_iter, cz, zcorn);
181 nnc_allowed = nnc_allowed && (!pinchNOGAP || thin);
190 setCellZcorn(ii, jj, kk_iter, cz, zcorn);
195 cz = getCellZcorn(ii, jj, kk_iter, zcorn);
196 for (
int count = 0; count < 4; ++count) {
197 cz[count + 4] = cz[count];
199 setCellZcorn(ii, jj, kk_iter, cz, zcorn);
201 result.removed_cells.push_back(c_below);
204 kk_iter = kk_iter + 1;
205 if (kk_iter == dims_[2])
210 c_below = ii + dims_[0] * (jj + dims_[1] * (kk_iter));
211 active = actnum.empty() || actnum[c_below];
212 thin = (thickness[c_below] <= z_tolerance);
213 thin_inactive = (!actnum.empty() && !actnum[c_below]) && thin;
214 low_pv_active = pv[c_below] < minpvv[c_below] && active;
218 if (mergeMinPVCells) {
221 std::array<double, 8> cz_below = getCellZcorn(ii, jj, kk_iter, zcorn);
222 for (
int count = 0; count < 4; ++count) {
223 cz_below[count] = cz[count];
226 setCellZcorn(ii, jj, kk_iter, cz_below, zcorn);
232 if (kk == 0 || kk_iter == dims_[2]) {
237 if (!actnum.empty() && (!actnum[c] || !actnum[c_below])) {
243 int c_above = ii + dims_[0] * (jj + dims_[1] * (kk-1));
244 auto above_active = actnum.empty() || actnum[c_above];
245 auto above_inactive = !actnum.empty() && !actnum[c_above];
246 auto above_thin = thickness[c_above] < z_tolerance;
247 auto above_small_pv = pv[c_above] < minpvv[c_above];
248 if ((above_inactive && above_thin) || (above_active && above_small_pv
249 && (!pinchNOGAP || above_thin) ) ) {
250 for (
int topk = kk - 2; topk > 0; --topk) {
251 c_above = ii + dims_[0] * (jj + dims_[1] * (topk));
252 above_active = actnum.empty() || actnum[c_above];
253 above_inactive = !actnum.empty() && !actnum[c_above];
254 auto above_significant_pv = pv[c_above] > minpvv[c_above];
255 auto above_broad = thickness[c_above] > z_tolerance;
257 if ( (above_active && (above_significant_pv || (pinchNOGAP && above_broad) ) ) || (above_inactive && above_broad)) {
266 (actnum.empty() || (actnum[c_above] && actnum[c_below])) &&
267 pv[c_above] > minpvv[c_above] && pv[c_below] > minpvv[c_below]) {
268 result.add_nnc(c_above, c_below);
282 inline std::array<int,8> MinpvProcessor::cornerIndices(
const int i,
const int j,
const int k)
const
284 const int ix = 2*(i*delta_[0] + j*delta_[1] + k*delta_[2]);
285 std::array<int, 8> ixs = {{ ix, ix + delta_[0],
286 ix + delta_[1], ix + delta_[1] + delta_[0],
287 ix + delta_[2], ix + delta_[2] + delta_[0],
288 ix + delta_[2] + delta_[1], ix + delta_[2] + delta_[1] + delta_[0] }};
299 inline std::array<double, 8> MinpvProcessor::getCellZcorn(
const int i,
const int j,
const int k,
const double* z)
const
301 const std::array<int, 8> ixs = cornerIndices(i, j, k);
302 std::array<double, 8> cellz;
303 for (
int count = 0; count < 8; ++count) {
304 cellz[count] = z[ixs[count]];
311 inline void MinpvProcessor::setCellZcorn(
const int i,
const int j,
const int k,
const std::array<double, 8>& cellz,
double* z)
const
313 const std::array<int, 8> ixs = cornerIndices(i, j, k);
314 for (
int count = 0; count < 8; ++count) {
315 z[ixs[count]] = cellz[count];
Transform a corner-point grid ZCORN field to account for MINPV processing.
Definition: MinpvProcessor.hpp:35
Result process(const std::vector< double > &thickness, const double z_tolerance, const std::vector< double > &pv, const std::vector< double > &minpvv, const std::vector< int > &actnum, const bool mergeMinPVCells, double *zcorn, bool pinchNOGAP=false) const
Change zcorn so that it respects the minpv property.
Definition: MinpvProcessor.hpp:93
MinpvProcessor(const int nx, const int ny, const int nz)
Create a processor.
Definition: MinpvProcessor.hpp:86
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:29
Definition: MinpvProcessor.hpp:38