ZoltanGraphFunctions.hpp
Go to the documentation of this file.
1/*
2 Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services.
3 Copyright 2015 NTNU
4 Copyright 2015 Statoil AS
5
6 This file is part of The Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21#ifndef DUNE_CPGRID_ZOLTAN_GRAPH_FUNCTIONS_HEADER
22#define DUNE_CPGRID_ZOLTAN_GRAPH_FUNCTIONS_HEADER
23
25
26#include <opm/grid/CpGrid.hpp>
28
29#if defined(HAVE_ZOLTAN) && defined(HAVE_MPI)
30
31#include <mpi.h>
32
33// Zoltan redefines HAVE_MPI. Therefore we need to back it up, undef, and
34// redifine it after the header is included
35#undef HAVE_MPI
36#include <zoltan.h>
37#undef HAVE_MPI
38#define HAVE_MPI 1
39
40namespace Dune
41{
42namespace cpgrid
43{
48inline int getCpGridNumCells(void* cpGridPointer, int* err)
49{
50 const Dune::CpGrid& grid = *static_cast<const Dune::CpGrid*>(cpGridPointer);
51 *err = ZOLTAN_OK;
52 return grid.numCells();
53}
54
56void getCpGridVertexList(void* cpGridPointer, int numGlobalIds,
57 int numLocalIds, ZOLTAN_ID_PTR gids,
58 ZOLTAN_ID_PTR lids, int wgtDim,
59 float *objWgts, int *err);
60
62int getNumberOfEdgesForSpecificCell(const Dune::CpGrid& grid, int localCellId);
63
65void 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
71template <typename ID>
72void fillNBORGIDForSpecificCellAndIncrementNeighborCounter(const Dune::CpGrid& grid, int localCellId, ID globalID, int& neighborCounter, ID& nborGID);
73
75void 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);
80
82void getNullVertexList(void* cpGridPointer, int numGlobalIds,
83 int numLocalIds, ZOLTAN_ID_PTR gids,
84 ZOLTAN_ID_PTR lids, int wgtDim,
85 float *objWgts, int *err);
86
88void getNullNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
89 int numCells,
90 ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
91 int *numEdges, int *err);
92
94void getNullEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
95 int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
96 int *num_edges,
97 ZOLTAN_ID_PTR nborGID, int *nborProc,
98 int wgt_dim, float *ewgts, int *err);
99
103inline int getNullNumCells(void* cpGridPointer, int* err)
104{
105 (void) cpGridPointer;
106 *err = ZOLTAN_OK;
107 return 0;
108}
109
111void getCpGridWellsNumEdgesList(void *cpGridWellsPointer, int sizeGID, int sizeLID,
112 int numCells,
113 ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
114 int *numEdges, int *err);
115
117void getCpGridWellsEdgeList(void *cpGridWellsPointer, int sizeGID, int sizeLID,
118 int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
119 int *num_edges,
120 ZOLTAN_ID_PTR nborGID, int *nborProc,
121 int wgt_dim, float *ewgts, int *err);
122} // end namespace cpgrid
123} // end namespace Dune
124
125#endif // HAVE_ZOLTAN
126namespace Dune
127{
128namespace cpgrid
129{
138{
139public:
140 typedef std::vector<std::set<int> > GraphType;
141
152 const std::vector<OpmWellType> * wells,
153 const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
154 const double* transmissibilities,
155 bool pretendEmptyGrid,
156 EdgeWeightMethod edgeWeightsMethod);
157
159 const Dune::CpGrid& getGrid() const
160 {
161 return grid_;
162 }
163
165 {
166 return wellsGraph_;
167 }
168
169 double transmissibility(int face_index) const
170 {
171 return transmissibilities_ ? (1.0e18*transmissibilities_[face_index]) : 1;
172 }
173
174 double logTransmissibilityWeights(int face_index) const
175 {
176 double trans = transmissibilities_ ? transmissibilities_[face_index] : 1;
177 return trans == 0.0 ? 0.0 : 1.0 + std::log(trans) - log_min_;
178 }
179
181 {
182 return well_indices_;
183 }
184
185 double edgeWeight(int face_index) const
186 {
187 if (edgeWeightsMethod_ == uniformEdgeWgt)
188 return 1.0;
189 else if (edgeWeightsMethod_ == defaultTransEdgeWgt)
190 return transmissibility(face_index);
191 else if (edgeWeightsMethod_ == logTransEdgeWgt)
192 return logTransmissibilityWeights(face_index);
193 else
194 return 1.0;
195 }
196private:
197
198 void addCompletionSetToGraph()
199 {
200 for(const auto& well_indices: well_indices_)
201 {
202 for( auto well_idx = well_indices.begin(); well_idx != well_indices.end();
203 ++well_idx)
204 {
205 auto well_idx2 = well_idx;
206 for( ++well_idx2; well_idx2 != well_indices.end();
207 ++well_idx2)
208 {
209 wellsGraph_[*well_idx].insert(*well_idx2);
210 wellsGraph_[*well_idx2].insert(*well_idx);
211 }
212 }
213 }
214 }
215
216 void findMaxMinTrans()
217 {
218 if (transmissibilities_) {
219 double min_val = std::numeric_limits<float>::max();
220 for (int face = 0; face < getGrid().numFaces(); ++face)
221 {
222 double trans = transmissibilities_[face];
223 if (trans > 0)
224 {
225 if (trans < min_val)
226 min_val = trans;
227 }
228 }
229 log_min_ = std::log(min_val);
230 }
231 else {
232 log_min_ = 0.0;
233 }
234 }
235
236 const Dune::CpGrid& grid_;
237 GraphType wellsGraph_;
238 const double* transmissibilities_;
239 int edgeWeightsMethod_;
240 WellConnections well_indices_;
241 double log_min_;
242};
243
246
248template<typename ID, typename weightType>
249void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts);
250
251#ifdef HAVE_ZOLTAN
256void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
257 bool pretendNull=false);
258
259void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
260 const CombinedGridWellGraph& graph,
261 bool pretendNull);
262#endif // HAVE_ZOLTAN
263} // end namespace cpgrid
264} // end namespace Dune
265
266#endif // header guard
[ provides Dune::Grid ]
Definition: CpGrid.hpp:198
int numFaces(int level=-1) const
Get the number of faces.
int numCells(int level=-1) const
Get the number of cells.
A graph repesenting a grid together with the well completions.
Definition: ZoltanGraphFunctions.hpp:138
const WellConnections & getWellConnections() const
Definition: ZoltanGraphFunctions.hpp:180
const GraphType & getWellsGraph() const
Definition: ZoltanGraphFunctions.hpp:164
double transmissibility(int face_index) const
Definition: ZoltanGraphFunctions.hpp:169
CombinedGridWellGraph(const Dune::CpGrid &grid, const std::vector< OpmWellType > *wells, const std::unordered_map< std::string, std::set< int > > &possibleFutureConnections, const double *transmissibilities, bool pretendEmptyGrid, EdgeWeightMethod edgeWeightsMethod)
Create a graph representing a grid together with the wells.
std::vector< std::set< int > > GraphType
Definition: ZoltanGraphFunctions.hpp:140
const Dune::CpGrid & getGrid() const
Access the grid.
Definition: ZoltanGraphFunctions.hpp:159
double logTransmissibilityWeights(int face_index) const
Definition: ZoltanGraphFunctions.hpp:174
double edgeWeight(int face_index) const
Definition: ZoltanGraphFunctions.hpp:185
A class calculating and representing all connections of wells.
Definition: WellConnections.hpp:51
void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph &graph, const int localCellId, ID globalID, int &neighborCounter, ID &nborGID, weightType *ewgts)
Get the list of edges and weights for one cell of a grid with wells.
int getNumberOfEdgesForSpecificCellForGridWithWells(const CombinedGridWellGraph &graph, int localCellId)
Get the number of edges of the graph of the grid and the wells for one cell.
The namespace Dune is the main namespace for all Dune code.
Definition: common/CartesianIndexMapper.hpp:10
EdgeWeightMethod
enum for choosing Methods for weighting graph-edges correspoding to cell interfaces in Zoltan's or Me...
Definition: GridEnums.hpp:34
@ defaultTransEdgeWgt
Use the transmissibilities as edge weights.
Definition: GridEnums.hpp:38
@ logTransEdgeWgt
Use the log of the transmissibilities as edge weights.
Definition: GridEnums.hpp:40
@ uniformEdgeWgt
All edge have a uniform weight of 1.
Definition: GridEnums.hpp:36
int numCells(const Dune::CpGrid &grid)
Get the number of cells of a grid.