Skip to content

Commit 0ff52dd

Browse files
authored
Merge pull request #1035 from michal-toth/partitioning/lower-bigM-constant
Make well edge weight equal to sum of grid edges instead of limits::max
2 parents 92a0d09 + 68d100e commit 0ff52dd

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

opm/grid/common/MetisPartition.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,13 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
275275

276276
if( wells )
277277
{
278+
// well edge weight for partitioning, big enough that wells should not get split
279+
idx_t weWeight = sumOfGridEdges<idx_t>(cpgrid, *gridAndWells);
280+
278281
int neighborCounter = 0;
279282
for( int cell = 0; cell < n; cell++ )
280283
{
281-
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(*gridAndWells, lids[cell], gids, neighborCounter, adjncy, adjwgt);
284+
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(*gridAndWells, lids[cell], gids, neighborCounter, adjncy, adjwgt, weWeight);
282285
}
283286
}
284287
else

opm/grid/common/ZoltanGraphFunctions.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,23 @@ void getNullEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
179179
*err = ZOLTAN_OK;
180180
}
181181

182+
template <typename EdgeWeightType>
183+
EdgeWeightType sumOfGridEdges(const Dune::CpGrid& grid,
184+
const CombinedGridWellGraph& graph)
185+
{
186+
EdgeWeightType weWeight = 0;
187+
for (int edge=0; edge<grid.numFaces(); ++edge) {
188+
// assumes that transmissibility is positive (too obvious to leave an assert)
189+
const auto& addend = graph.transmissibility(edge);
190+
if (weWeight >= std::numeric_limits<EdgeWeightType>::max()-addend) {
191+
weWeight = std::numeric_limits<EdgeWeightType>::max();
192+
break;
193+
}
194+
weWeight += graph.transmissibility(edge);
195+
}
196+
return weWeight;
197+
}
198+
182199
template<typename ID>
183200
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid& grid, int localCellId, ID globalID, int& neighborCounter, ID& nborGID) {
184201
for ( int local_face = 0 ; local_face < grid.numCellFaces(localCellId); ++local_face )
@@ -245,14 +262,14 @@ void getCpGridEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
245262
#endif
246263
}
247264
template<typename ID, typename weightType>
248-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts) {
265+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts, const weightType& weWeight) {
249266
const Dune::CpGrid& grid = graph.getGrid();
250267
// First the strong edges of the well completions.
251268
auto wellEdges = graph.getWellsGraph()[localCellId];
252269
for( auto edge : wellEdges)
253270
{
254271
nborGID[neighborCounter] = edge;
255-
ewgts[neighborCounter++] = std::numeric_limits<weightType>::max();
272+
ewgts[neighborCounter++] = weWeight;
256273
}
257274

258275
// Now the ones of the grid that are not handled by the well completions
@@ -308,9 +325,12 @@ void getCpGridWellsEdgeList(void *graphPointer, int sizeGID, int sizeLID,
308325
#endif
309326
int neighborCounter = 0;
310327

328+
// well edge weight for partitioning, big enough that wells should not get split
329+
float weWeight = sumOfGridEdges<float>(grid, graph);
330+
311331
for( int cell = 0; cell < numCells; cell++ )
312332
{
313-
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(graph, localID[cell], globalID, neighborCounter, nborGID, ewgts);
333+
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(graph, localID[cell], globalID, neighborCounter, nborGID, ewgts, weWeight);
314334
#ifndef NDEBUG
315335
assert(neighborCounter-oldNeighborCounter==numEdges[cell]);
316336
oldNeighborCounter = neighborCounter;
@@ -416,12 +436,16 @@ void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
416436
template
417437
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid&, int, int*, int&, int*& nborGID);
418438
template
419-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph&, const int, int*, int&, int*&, int*);
439+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph&, const int, int*, int&, int*&, int*, const int&);
440+
template
441+
int sumOfGridEdges(const Dune::CpGrid& grid, const CombinedGridWellGraph& graph);
420442

421443
template
422444
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(Dune::CpGrid const&, int, long*, int&, long*&);
423445
template
424-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(Dune::cpgrid::CombinedGridWellGraph const&, int, long*, int&, long*&, long*);
446+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(Dune::cpgrid::CombinedGridWellGraph const&, int, long*, int&, long*&, long*, const long&);
447+
template
448+
long sumOfGridEdges(const Dune::CpGrid& grid, const CombinedGridWellGraph& graph);
425449

426450
#endif
427451

opm/grid/common/ZoltanGraphFunctions.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,16 @@ class CombinedGridWellGraph
244244
/// \brief Get the number of edges of the graph of the grid and the wells for one cell
245245
int getNumberOfEdgesForSpecificCellForGridWithWells(const CombinedGridWellGraph& graph, int localCellId);
246246

247+
/// \brief Iterate over the grid and get the sum of all edge weights
248+
///
249+
/// Used as a weight for edges between cells of a well
250+
template <typename EdgeWeightType>
251+
EdgeWeightType sumOfGridEdges(const Dune::CpGrid& grid,
252+
const CombinedGridWellGraph& graph);
253+
247254
/// \brief Get the list of edges and weights for one cell of a grid with wells
248255
template<typename ID, typename weightType>
249-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts);
256+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts, const weightType& weWeight);
250257

251258
#ifdef HAVE_ZOLTAN
252259
/// \brief Sets up the call-back functions for ZOLTAN's graph partitioning.

0 commit comments

Comments
 (0)