20 #ifndef OPM_MINPVPROCESSOR_HEADER_INCLUDED
21 #define OPM_MINPVPROCESSOR_HEADER_INCLUDED
24 #include <opm/grid/utility/ErrorMacros.hpp>
25 #include <opm/grid/utility/OpmParserIncludes.hpp>
41 std::vector<std::size_t> removed_cells;
42 std::map<int,int> nnc;
45 void add_nnc(
int cell1,
int cell2) {
46 auto key = std::min(cell1, cell2);
47 auto value = std::max(cell1,cell2);
49 this->nnc.insert({key, value});
73 const double z_tolerance,
74 const std::vector<double>& pv,
75 const std::vector<double>& minpvv,
76 const std::vector<int>& actnum,
77 const bool mergeMinPVCells,
79 bool pinchNOGAP =
false)
const;
81 std::array<int,8> cornerIndices(
const int i,
const int j,
const int k)
const;
82 std::array<double, 8> getCellZcorn(
const int i,
const int j,
const int k,
const double* z)
const;
83 void setCellZcorn(
const int i,
const int j,
const int k,
const std::array<double, 8>& cellz,
double* z)
const;
84 std::array<int, 3> dims_;
85 std::array<int, 3> delta_;
89 dims_( {{nx,ny,nz}} ),
90 delta_( {{1 , 2*nx , 4*nx*ny}} )
96 const double z_tolerance,
97 const std::vector<double>& pv,
98 const std::vector<double>& minpvv,
99 const std::vector<int>& actnum,
100 const bool mergeMinPVCells,
102 bool pinchNOGAP)
const
130 const size_t log_size = dims_[0] * dims_[1] * dims_[2];
131 if (pv.size() != log_size) {
132 OPM_THROW(std::runtime_error,
"Wrong size of PORV input, must have one element per logical cartesian cell.");
134 if (!actnum.empty() && actnum.size() != log_size) {
135 OPM_THROW(std::runtime_error,
"Wrong size of ACTNUM input, must have one element per logical cartesian cell.");
139 for (
int kk = 0; kk < dims_[2]; ++kk) {
140 for (
int jj = 0; jj < dims_[1]; ++jj) {
141 for (
int ii = 0; ii < dims_[0]; ++ii) {
142 const int c = ii + dims_[0] * (jj + dims_[1] * kk);
143 if (pv[c] < minpvv[c] && (actnum.empty() || actnum[c])) {
146 std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);
147 for (
int count = 0; count < 4; ++count) {
148 cz[count + 4] = cz[count];
150 setCellZcorn(ii, jj, kk, cz, zcorn);
153 int kk_iter = kk + 1;
154 if (kk_iter == dims_[2]) {
155 result.removed_cells.push_back(c);
159 int c_below = ii + dims_[0] * (jj + dims_[1] * (kk_iter));
161 while ( ((actnum.empty() || !actnum[c_below]) && (thickness[c_below] <= z_tolerance)) ){
164 setCellZcorn(ii, jj, kk_iter, cz, zcorn);
166 if (kk_iter == dims_[2])
169 c_below = ii + dims_[0] * (jj + dims_[1] * (kk_iter));
172 if (kk_iter == dims_[2]) {
173 result.removed_cells.push_back(c);
178 if (!mergeMinPVCells) {
182 result.removed_cells.push_back(c);
186 int c_above = ii + dims_[0] * (jj + dims_[1] * (kk - 1));
189 auto above_active = actnum.empty() || actnum[c_above];
190 auto above_inactive = actnum.empty() || !actnum[c_above];
191 auto above_thin = thickness[c_above] < z_tolerance;
192 auto above_small_pv = pv[c_above] < minpvv[c_above];
193 if ((above_inactive && above_thin) || (above_active && above_small_pv
194 && (!pinchNOGAP || above_thin) ) ) {
195 for (
int topk = kk - 2; topk > 0; --topk) {
196 c_above = ii + dims_[0] * (jj + dims_[1] * (topk));
197 above_active = actnum.empty() || actnum[c_above];
198 above_inactive = actnum.empty() || !actnum[c_above];
199 auto above_significant_pv = pv[c_above] > minpvv[c_above];
200 auto above_broad = thickness[c_above] > z_tolerance;
202 if ( (above_active && (above_significant_pv || (pinchNOGAP && above_broad) ) ) || (above_inactive && above_broad)) {
209 auto below_active = actnum.empty() || actnum[c_below];
210 auto below_inactive = actnum.empty() || !actnum[c_below];
211 auto below_thin = thickness[c_below] < z_tolerance;
212 auto below_small_pv = pv[c_below] < minpvv[c];
213 if ((below_inactive && below_thin) || (below_active && below_small_pv
214 && (!pinchNOGAP || below_thin ) ) ) {
215 for (
int botk = kk_iter + 1; botk < dims_[2]; ++botk) {
216 c_below = ii + dims_[0] * (jj + dims_[1] * (botk));
217 below_active = actnum.empty() || actnum[c_below];
218 below_inactive = actnum.empty() || !actnum[c_below];
219 auto below_significant_pv = pv[c_below] > minpvv[c_below];
220 auto below_broad = thickness[c_above] > z_tolerance;
222 if ( (below_active && (below_significant_pv || (pinchNOGAP && below_broad) ) ) || (below_inactive && below_broad)) {
229 if ((actnum.empty() || (actnum[c_above] && actnum[c_below])) && pv[c_above] > minpvv[c_above] && pv[c_below] > minpvv[c_below]) {
230 result.add_nnc(c_above, c_below);
236 std::array<double, 8> cz_below = getCellZcorn(ii, jj, kk_iter, zcorn);
237 for (
int count = 0; count < 4; ++count) {
238 cz_below[count] = cz[count];
241 setCellZcorn(ii, jj, kk_iter, cz_below, zcorn);
244 result.removed_cells.push_back(c);
255 inline std::array<int,8> MinpvProcessor::cornerIndices(
const int i,
const int j,
const int k)
const
257 const int ix = 2*(i*delta_[0] + j*delta_[1] + k*delta_[2]);
258 std::array<int, 8> ixs = {{ ix, ix + delta_[0],
259 ix + delta_[1], ix + delta_[1] + delta_[0],
260 ix + delta_[2], ix + delta_[2] + delta_[0],
261 ix + delta_[2] + delta_[1], ix + delta_[2] + delta_[1] + delta_[0] }};
272 inline std::array<double, 8> MinpvProcessor::getCellZcorn(
const int i,
const int j,
const int k,
const double* z)
const
274 const std::array<int, 8> ixs = cornerIndices(i, j, k);
275 std::array<double, 8> cellz;
276 for (
int count = 0; count < 8; ++count) {
277 cellz[count] = z[ixs[count]];
284 inline void MinpvProcessor::setCellZcorn(
const int i,
const int j,
const int k,
const std::array<double, 8>& cellz,
double* z)
const
286 const std::array<int, 8> ixs = cornerIndices(i, j, k);
287 for (
int count = 0; count < 8; ++count) {
288 z[ixs[count]] = cellz[count];
Transform a corner-point grid ZCORN field to account for MINPV processing.
Definition: MinpvProcessor.hpp:37
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:95
MinpvProcessor(const int nx, const int ny, const int nz)
Create a processor.
Definition: MinpvProcessor.hpp:88
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:29
Definition: MinpvProcessor.hpp:40