Skip to content

Commit 0aafb2c

Browse files
committed
Neglect wells and possibleFutureConnections when allow-distributed-wells=true
Before, they were still taken into account by setting the edge weights of connections made by wells to std::numeric_limits<weightType>::max()
1 parent 8b67f04 commit 0aafb2c

File tree

5 files changed

+66
-215
lines changed

5 files changed

+66
-215
lines changed

opm/grid/common/MetisPartition.cpp

+20-34
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,20 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
156156
#endif
157157

158158
std::shared_ptr<CombinedGridWellGraph> gridAndWells;
159-
if( wells )
160-
{
159+
if (allowDistributedWells) {
161160
gridAndWells.reset(new CombinedGridWellGraph(cpgrid,
162-
wells,
163-
possibleFutureConnections,
164-
transmissibilities,
165-
false,
166-
edgeWeightsMethod));
161+
nullptr, // if we allow distributed wells, we construct the CombinedGridWellGraph without the influence of the wells, just the transmissibilities
162+
{},
163+
transmissibilities,
164+
false,
165+
edgeWeightsMethod));
166+
} else {
167+
gridAndWells.reset(new CombinedGridWellGraph(cpgrid,
168+
wells, // if we allow distributed wells, we construct the CombinedGridWellGraph with the wells, possible future connections and the transmissibilities
169+
possibleFutureConnections,
170+
transmissibilities,
171+
false,
172+
edgeWeightsMethod));
167173
}
168174

169175
std::vector<int> partitionVector;
@@ -236,17 +242,8 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
236242

237243
//////// Now, we define all variables that *do depend* on whether there are wells or not
238244

239-
if( wells )
240-
{
241-
for (int i = 0; i < n; i++) {
242-
xadj[i+1] = xadj[i] + Dune::cpgrid::getNumberOfEdgesForSpecificCellForGridWithWells(*gridAndWells, lids[i]);
243-
}
244-
}
245-
else
246-
{
247-
for (int i = 0; i < n; i++) {
248-
xadj[i+1] = xadj[i] + Dune::cpgrid::getNumberOfEdgesForSpecificCell(cpgrid, lids[i]);
249-
}
245+
for (int i = 0; i < n; i++) {
246+
xadj[i+1] = xadj[i] + Dune::cpgrid::getNumberOfEdgesForSpecificCell(*gridAndWells, lids[i]);
250247
}
251248

252249
// The number of edges depends on whether there are wells or not, twoM = 2*m, where m = number of edges.
@@ -263,21 +260,10 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
263260
// The weights of the edges (if any) are stored in an additional array called adjwgt. This array contains 2m elements, and the weight of edge adjncy[j] is stored at location adjwgt[j]
264261
idx_t* adjwgt = new idx_t[twoM];
265262

266-
if( wells )
263+
int neighborCounter = 0;
264+
for( int cell = 0; cell < n; cell++ )
267265
{
268-
int neighborCounter = 0;
269-
for( int cell = 0; cell < n; cell++ )
270-
{
271-
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(*gridAndWells, lids[cell], gids, neighborCounter, adjncy, adjwgt);
272-
}
273-
}
274-
else
275-
{
276-
int neighborCounter = 0;
277-
for( int cell = 0; cell < n; cell++ )
278-
{
279-
fillNBORGIDForSpecificCellAndIncrementNeighborCounter(cpgrid, lids[cell], gids, neighborCounter, adjncy);
280-
}
266+
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(*gridAndWells, lids[cell], gids, neighborCounter, adjncy, adjwgt);
281267
}
282268

283269
// Decide which partition method to use, both methods create k partitions, where
@@ -296,7 +282,7 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
296282
adjncy,
297283
nullptr, // vwgt
298284
nullptr, // vsize,
299-
wells ? adjwgt : nullptr,
285+
adjwgt,
300286
&nparts,
301287
nullptr, // tpwgts,
302288
&ubvec,
@@ -311,7 +297,7 @@ metisSerialGraphPartitionGridOnRoot(const CpGrid& cpgrid,
311297
adjncy,
312298
nullptr, // vwgt
313299
nullptr, // vsize,
314-
wells ? adjwgt : nullptr,
300+
adjwgt,
315301
&nparts,
316302
nullptr, // tpwgts,
317303
&ubvec,

opm/grid/common/ZoltanGraphFunctions.cpp

+18-138
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,8 @@ void getNullNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
8888
*err = ZOLTAN_OK;
8989
}
9090

91-
int getNumberOfEdgesForSpecificCell(const Dune::CpGrid& grid, int localCellId) {
92-
// For the graph there is an edge only if the face has two neighbors.
93-
// Therefore we need to check each face
94-
int edges = 0;
95-
for ( int local_face = 0; local_face < grid.numCellFaces(localCellId); ++local_face )
96-
{
97-
const int face = grid.cellFace(localCellId, local_face);
98-
if ( grid.faceCell(face, 0) != -1 && grid.faceCell(face, 1) != -1 )
99-
{
100-
++edges;
101-
}
102-
}
103-
return edges;
104-
}
10591

106-
void getCpGridNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
107-
int numCells,
108-
ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
109-
int *numEdges, int *err)
110-
{
111-
(void) globalID;
112-
const Dune::CpGrid& grid = *static_cast<const Dune::CpGrid*>(cpGridPointer);
113-
if ( sizeGID != 1 || sizeLID != 1 || numCells != grid.numCells() )
114-
{
115-
*err = ZOLTAN_FATAL;
116-
return;
117-
}
118-
for( int i = 0; i < numCells; i++ )
119-
{
120-
numEdges[i] = getNumberOfEdgesForSpecificCell(grid, localID[i]);
121-
}
122-
123-
*err = ZOLTAN_OK;
124-
}
125-
126-
int getNumberOfEdgesForSpecificCellForGridWithWells(const CombinedGridWellGraph& graph, int localCellId) {
92+
int getNumberOfEdgesForSpecificCell(const CombinedGridWellGraph& graph, int localCellId) {
12793
const Dune::CpGrid& grid = graph.getGrid();
12894
// Initial set of faces is the ones of the well completions
12995
auto edges = graph.getWellsGraph()[localCellId];
@@ -162,7 +128,7 @@ void getCpGridWellsNumEdgesList(void *graphPointer, int sizeGID, int sizeLID,
162128
}
163129
for( int i = 0; i < numCells; i++ )
164130
{
165-
numEdges[i] = getNumberOfEdgesForSpecificCellForGridWithWells(graph, localID[i]);
131+
numEdges[i] = getNumberOfEdgesForSpecificCell(graph, localID[i]);
166132
}
167133
*err = ZOLTAN_OK;
168134
}
@@ -179,73 +145,8 @@ void getNullEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
179145
*err = ZOLTAN_OK;
180146
}
181147

182-
template<typename ID>
183-
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid& grid, int localCellId, ID globalID, int& neighborCounter, ID& nborGID) {
184-
for ( int local_face = 0 ; local_face < grid.numCellFaces(localCellId); ++local_face )
185-
{
186-
const int face = grid.cellFace(localCellId, local_face);
187-
int otherCell = grid.faceCell(face, 0);
188-
if ( otherCell == localCellId || otherCell == -1 )
189-
{
190-
otherCell = grid.faceCell(face, 1);
191-
if ( otherCell == localCellId || otherCell == -1 )
192-
continue;
193-
}
194-
nborGID[neighborCounter++] = globalID[otherCell];
195-
}
196-
}
197-
198-
void getCpGridEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
199-
int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
200-
int *numEdges,
201-
ZOLTAN_ID_PTR nborGID, int *nborProc,
202-
int wgtDim, float *ewgts, int *err)
203-
{
204-
(void) wgtDim; (void) globalID; (void) numEdges; (void) ewgts;
205-
const Dune::CpGrid& grid = *static_cast<const Dune::CpGrid*>(cpGridPointer);
206-
if ( sizeGID != 1 || sizeLID != 1 || numCells != grid.numCells() )
207-
{
208-
*err = ZOLTAN_FATAL;
209-
return;
210-
}
211-
#ifndef NDEBUG
212-
int oldNeighborCounter = 0;
213-
#endif
214-
int neighborCounter = 0;
215-
216-
for( int cell = 0; cell < numCells; cell++ )
217-
{
218-
fillNBORGIDForSpecificCellAndIncrementNeighborCounter(grid, localID[cell], globalID, neighborCounter, nborGID);
219-
#ifndef NDEBUG
220-
assert(numEdges[cell] == neighborCounter - oldNeighborCounter);
221-
oldNeighborCounter = neighborCounter;
222-
#endif
223-
}
224-
225-
const int myrank = grid.comm().rank();
226-
227-
for ( int i = 0; i < neighborCounter; ++i )
228-
{
229-
nborProc[i] = myrank;
230-
}
231-
#if defined(DEBUG) && false // The index set will not be initialized here!
232-
// The above relies heavily on the grid not being distributed already.
233-
// Therefore we check here that all cells are owned by us.
234-
GlobalLookupIndexSet<Dune::CpGrid::ParallelIndexSet>
235-
globalIdxSet(grid.getCellIndexSet(),
236-
grid.numCells());
237-
for ( int cell = 0; cell < numCells; cell++ )
238-
{
239-
if ( globalIdxSet.pair(cell)->local().attribute() !=
240-
Dune::CpGrid::ParallelIndexSet::LocalIndex::Attribute::owner )
241-
{
242-
*err = ZOLTAN_FATAL;
243-
}
244-
}
245-
#endif
246-
}
247148
template<typename ID, typename weightType>
248-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts) {
149+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts) {
249150
const Dune::CpGrid& grid = graph.getGrid();
250151
// First the strong edges of the well completions.
251152
auto wellEdges = graph.getWellsGraph()[localCellId];
@@ -310,7 +211,7 @@ void getCpGridWellsEdgeList(void *graphPointer, int sizeGID, int sizeLID,
310211

311212
for( int cell = 0; cell < numCells; cell++ )
312213
{
313-
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(graph, localID[cell], globalID, neighborCounter, nborGID, ewgts);
214+
fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(graph, localID[cell], globalID, neighborCounter, nborGID, ewgts);
314215
#ifndef NDEBUG
315216
assert(neighborCounter-oldNeighborCounter==numEdges[cell]);
316217
oldNeighborCounter = neighborCounter;
@@ -354,41 +255,24 @@ CombinedGridWellGraph::CombinedGridWellGraph(const CpGrid& grid,
354255
return;
355256
}
356257
wellsGraph_.resize(grid.numCells());
357-
const auto& cpgdim = grid.logicalCartesianSize();
358-
// create compressed lookup from cartesian.
359-
std::vector<int> cartesian_to_compressed(cpgdim[0]*cpgdim[1]*cpgdim[2], -1);
258+
if (wells) {
259+
const auto& cpgdim = grid.logicalCartesianSize();
260+
// create compressed lookup from cartesian.
261+
std::vector<int> cartesian_to_compressed(cpgdim[0]*cpgdim[1]*cpgdim[2], -1);
360262

361-
for( int i=0; i < grid.numCells(); ++i )
362-
{
363-
cartesian_to_compressed[grid.globalCell()[i]] = i;
263+
for( int i=0; i < grid.numCells(); ++i )
264+
{
265+
cartesian_to_compressed[grid.globalCell()[i]] = i;
266+
}
267+
// If we're not taking the wells into account here we don't init the connections
268+
well_indices_.init(*wells, possibleFutureConnections, cpgdim, cartesian_to_compressed);
269+
std::vector<int>().swap(cartesian_to_compressed); // free memory.
270+
addCompletionSetToGraph();
364271
}
365-
well_indices_.init(*wells, possibleFutureConnections, cpgdim, cartesian_to_compressed);
366-
std::vector<int>().swap(cartesian_to_compressed); // free memory.
367-
addCompletionSetToGraph();
368-
369272
if (edgeWeightsMethod == logTransEdgeWgt)
370273
findMaxMinTrans();
371274
}
372275

373-
void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
374-
bool pretendNull)
375-
{
376-
Dune::CpGrid *gridPointer = const_cast<Dune::CpGrid*>(&grid);
377-
if ( pretendNull )
378-
{
379-
Zoltan_Set_Num_Obj_Fn(zz, getNullNumCells, gridPointer);
380-
Zoltan_Set_Obj_List_Fn(zz, getNullVertexList, gridPointer);
381-
Zoltan_Set_Num_Edges_Multi_Fn(zz, getNullNumEdgesList, gridPointer);
382-
Zoltan_Set_Edge_List_Multi_Fn(zz, getNullEdgeList, gridPointer);
383-
}
384-
else
385-
{
386-
Zoltan_Set_Num_Obj_Fn(zz, getCpGridNumCells, gridPointer);
387-
Zoltan_Set_Obj_List_Fn(zz, getCpGridVertexList, gridPointer);
388-
Zoltan_Set_Num_Edges_Multi_Fn(zz, getCpGridNumEdgesList, gridPointer);
389-
Zoltan_Set_Edge_List_Multi_Fn(zz, getCpGridEdgeList, gridPointer);
390-
}
391-
}
392276

393277
void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
394278
const CombinedGridWellGraph& graph,
@@ -414,14 +298,10 @@ void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
414298
// Explicit template instantiation for METIS
415299
#if HAVE_METIS
416300
template
417-
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid&, int, int*, int&, int*& nborGID);
418-
template
419-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph&, const int, int*, int&, int*&, int*);
301+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(const CombinedGridWellGraph&, const int, int*, int&, int*&, int*);
420302

421303
template
422-
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(Dune::CpGrid const&, int, long*, int&, long*&);
423-
template
424-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(Dune::cpgrid::CombinedGridWellGraph const&, int, long*, int&, long*&, long*);
304+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(Dune::cpgrid::CombinedGridWellGraph const&, int, long*, int&, long*&, long*);
425305

426306
#endif
427307

opm/grid/common/ZoltanGraphFunctions.hpp

+2-21
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,8 @@ void getCpGridVertexList(void* cpGridPointer, int numGlobalIds,
5858
ZOLTAN_ID_PTR lids, int wgtDim,
5959
float *objWgts, int *err);
6060

61-
/// \brief Get the number of edges for one vertex of the graph of the grid.
62-
int getNumberOfEdgesForSpecificCell(const Dune::CpGrid& grid, int localCellId);
6361

6462
/// \brief Get the number of edges of the graph of the grid.
65-
void getCpGridNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
66-
int numCells,
67-
ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
68-
int *numEdges, int *err);
69-
70-
/// \brief Get the list of edges for one cell of a grid witout wells
71-
template <typename ID>
72-
void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid& grid, int localCellId, ID globalID, int& neighborCounter, ID& nborGID);
73-
74-
/// \brief Get the list of edges of the graph of the grid.
75-
void getCpGridEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
76-
int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
77-
int *num_edges,
78-
ZOLTAN_ID_PTR nborGID, int *nborProc,
79-
int wgt_dim, float *ewgts, int *err);
8063

8164
/// \brief Get a list of vertices with zero enties
8265
void getNullVertexList(void* cpGridPointer, int numGlobalIds,
@@ -242,19 +225,17 @@ class CombinedGridWellGraph
242225
};
243226

244227
/// \brief Get the number of edges of the graph of the grid and the wells for one cell
245-
int getNumberOfEdgesForSpecificCellForGridWithWells(const CombinedGridWellGraph& graph, int localCellId);
228+
int getNumberOfEdgesForSpecificCell(const CombinedGridWellGraph& graph, int localCellId);
246229

247230
/// \brief Get the list of edges and weights for one cell of a grid with wells
248231
template<typename ID, typename weightType>
249-
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts);
232+
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounter(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts);
250233

251234
#ifdef HAVE_ZOLTAN
252235
/// \brief Sets up the call-back functions for ZOLTAN's graph partitioning.
253236
/// \param zz The struct with the information for ZOLTAN.
254237
/// \param grid The grid to partition.
255238
/// \param pretendNull If true, we will pretend that the grid has zero cells.
256-
void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
257-
bool pretendNull=false);
258239

259240
void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
260241
const CombinedGridWellGraph& graph,

0 commit comments

Comments
 (0)