Skip to content

Commit bc7addf

Browse files
hnilbska
authored andcommitted
-- fixed out of bound nnc
-- still observer some race condition on strange files with temperature
1 parent 254487b commit bc7addf

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

opm/grid/MinpvProcessor.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ MinpvProcessor::process(const std::vector<double>& thickness,
123123
bool c_active = actnum.empty() || actnum[c];
124124
bool c_thin = (thickness[c] <= z_tolerance);
125125
bool c_thin_inactive = !c_active && c_thin;
126-
bool c_low_pv_active = pv[c] < minpvv[c] && c_active;
126+
bool c_low_pv_active = (pv[c] < minpvv[c] && c_active) || (c_thin && c_active);
127127

128128
if (c_low_pv_active || c_thin_inactive) {
129129
std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);
@@ -166,7 +166,7 @@ MinpvProcessor::process(const std::vector<double>& thickness,
166166
bool active = actnum.empty() || actnum[c_below];
167167
bool thin = (thickness[c_below] <= z_tolerance);
168168
bool thin_inactive = !active && thin;
169-
bool low_pv_active = pv[c_below] < minpvv[c_below] && active;
169+
bool low_pv_active = ((pv[c_below] < minpvv[c_below]) && active) || (thin && active);
170170

171171

172172
while ( (thin_inactive || low_pv_active) && kk_iter < dims_[2] )
@@ -223,13 +223,26 @@ MinpvProcessor::process(const std::vector<double>& thickness,
223223
active = actnum.empty() || actnum[c_below];
224224
thin = (thickness[c_below] <= z_tolerance);
225225
thin_inactive = (!actnum.empty() && !actnum[c_below]) && thin;
226-
low_pv_active = pv[c_below] < minpvv[c_below] && active;
226+
low_pv_active = ((pv[c_below] < minpvv[c_below]) && active) || (thin && active);
227227
}
228228

229229
// create nnc if false or merge the cells if true
230-
if (mergeMinPVCells && c_low_pv_active) {
230+
if (mergeMinPVCells){// && c_low_pv_active) {
231+
// try to make a topological connected grid
232+
// in Flow this is currently called only for edge_conformal grids
233+
// however zcorn inbetween is not modified to make zcorn sorted
231234
// Set lower k coordinates of cell below to upper cells's coordinates.
232235
// i.e fill the void using the cell below
236+
if (kk==0 || kk_iter == dims_[2]) {
237+
kk = kk_iter;
238+
continue;
239+
}
240+
//bottom cell not active, hence no nnc is created
241+
if (!actnum.empty() && !actnum[c_below]) {
242+
kk = kk_iter;
243+
continue;
244+
}
245+
233246
std::array<double, 8> cz_below = getCellZcorn(ii, jj, kk_iter, zcorn);
234247
for (int count = 0; count < 4; ++count) {
235248
cz_below[count] = cz[count];
@@ -258,15 +271,15 @@ MinpvProcessor::process(const std::vector<double>& thickness,
258271
auto above_active = actnum.empty() || actnum[c_above];
259272
auto above_inactive = !actnum.empty() && !actnum[c_above];
260273
auto above_thin = thickness[c_above] < z_tolerance;
261-
auto above_small_pv = pv[c_above] < minpvv[c_above];
274+
auto above_small_pv = (pv[c_above] < minpvv[c_above]) || above_thin;
262275

263276
if ((above_inactive && above_thin) || (above_active && above_small_pv
264277
&& (!pinchNOGAP || above_thin) ) ) {
265278
for (k_above = kk - 2; k_above > 0; --k_above) {
266279
c_above = ii + dims_[0] * (jj + dims_[1] * (k_above));
267280
above_active = actnum.empty() || actnum[c_above];
268281
above_inactive = !actnum.empty() && !actnum[c_above];
269-
auto above_significant_pv = pv[c_above] > minpvv[c_above];
282+
auto above_significant_pv = !((pv[c_above] < minpvv[c_above]) || (thickness[c_above] < z_tolerance));
270283
auto above_broad = thickness[c_above] > z_tolerance;
271284

272285
// \todo if condition seems wrong and should be the negation of above?
@@ -291,25 +304,30 @@ MinpvProcessor::process(const std::vector<double>& thickness,
291304
option4ALLZero = option4ALLZero || (!permz.empty() && permz[c_above] == 0.0) || multz(c_above) == 0.0;
292305
nnc_allowed = nnc_allowed && (computeGap(cz_above, cz_below) < max_gap) && (!pinchOption4ALL || !option4ALLZero) ;
293306

307+
//bool
308+
above_small_pv = (pv[c_above] < minpvv[c_above]) || (thickness[c_above] < z_tolerance);
309+
bool below_small_pv = (pv[c_below] < minpvv[c_below]) || (thickness[c_below] < z_tolerance);
294310
if ( nnc_allowed &&
295311
(actnum.empty() || (actnum[c_above] && actnum[c_below])) &&
296-
pv[c_above] > minpvv[c_above] && pv[c_below] > minpvv[c_below]) {
312+
!(above_small_pv) && !(below_small_pv) ){
297313
result.add_nnc(c_above, c_below);
298314
}
299315
kk = kk_iter;
300316
}
301317
}
302318
else
303319
{
304-
if (kk < dims_[2] - 1 && (actnum.empty() || actnum[c]) && pv[c] > minpvv[c] &&
320+
if (kk < dims_[2] - 1 && (actnum.empty() || actnum[c]) && !((pv[c] < minpvv[c]) || (thickness[c] < z_tolerance)) &&
305321
multz(c) != 0.0)
306322
{
307323
// Check whether there is a gap to the neighbor below whose thickness is less
308324
// than MAX_GAP. In that case we need to create an NNC if there is a gap between the two cells.
309325
int kk_below = kk + 1;
310326
int c_below = ii + dims_[0] * (jj + dims_[1] * kk_below);
311327

312-
if ((actnum.empty() || actnum[c_below]) && pv[c_below] > minpvv[c_below])
328+
if ( (actnum.empty() || actnum[c_below])
329+
&&
330+
!((pv[c_below] < minpvv[c_below]) || (thickness[c_below] < z_tolerance) ) )
313331
{
314332
// Check MAX_GAP threshold
315333
std::array<double, 8> cz = getCellZcorn(ii, jj, kk, zcorn);

opm/grid/common/GridPartitioning.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ int addOverlapLayer([[maybe_unused]] const CpGrid& grid,
576576
int index = ix.index(*it);
577577
auto owner = cell_part[index];
578578
exportProcs.insert(std::make_pair(owner, 0));
579-
if ( trans ) {
579+
if ( trans && false) {
580580
addOverlapLayerNoZeroTrans(grid, index, *it, owner, cell_part, exportList, addCornerCells, layers-1, trans, level);
581581
}
582582
else {

opm/grid/cpgrid/processEclipseFormat.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,10 @@ namespace cpgrid
204204
return transMult.getMultiplier(cartindex, ::Opm::FaceDir::ZPlus) *
205205
transMult.getMultiplier(cartindex, ::Opm::FaceDir::ZMinus);
206206
};
207+
bool mergeMinPVCells = edge_conformal;// try to make geometrically connected grids
208+
207209
minpv_result = mp.process(thickness, z_tolerance, ecl_grid.getPinchMaxEmptyGap(),
208-
poreVolume, ecl_grid.getMinpvVector(), actnumData, false,
210+
poreVolume, ecl_grid.getMinpvVector(), actnumData, edge_conformal,
209211
zcornData.data(), nogap, pinchOptionALL,
210212
permZ, multZ, tolerance_unique_points);
211213
if (!minpv_result.nnc.empty()) {
@@ -223,6 +225,9 @@ namespace cpgrid
223225

224226
// Add PINCH NNCs.
225227
std::vector<Opm::NNCdata> pinchedNNCs;
228+
if(edge_conformal){
229+
assert(minpv_result.nnc.size() == 0);
230+
}
226231

227232
for (const auto& [cell1, cell2] : minpv_result.nnc) {
228233
nnc_cells[PinchNNC].insert({cell1, cell2});
@@ -416,12 +421,19 @@ namespace cpgrid
416421
}
417422
else {
418423
// Make the grid.
424+
auto pinchActive_copy = pinchActive;
425+
if(edge_conformal){
426+
// In edge conformal grids we need to set the pinchActive flag to true
427+
pinchActive_copy = true;
428+
assert(nnc_cells[PinchNNC].empty());
429+
assert(nnc_cells[ExplicitNNC].empty());
430+
}
419431
this->processEclipseFormat(g,
420432
ecl_state,
421433
nnc_cells,
422434
false,
423435
turn_normals,
424-
pinchActive,
436+
pinchActive_copy,
425437
tolerance_unique_points,
426438
edge_conformal);
427439
}

0 commit comments

Comments
 (0)