My Project
ZoltanGraphFunctions.hpp
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 
24 #include <opm/grid/utility/OpmParserIncludes.hpp>
25 
26 #include <opm/grid/CpGrid.hpp>
27 #include <opm/grid/common/WellConnections.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 
40 namespace Dune
41 {
42 namespace cpgrid
43 {
48 inline 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 
56 void 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 
62 void getCpGridNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
63  int numCells,
64  ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
65  int *numEdges, int *err);
66 
68 void getCpGridEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
69  int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
70  int *num_edges,
71  ZOLTAN_ID_PTR nborGID, int *nborProc,
72  int wgt_dim, float *ewgts, int *err);
73 
75 void getNullVertexList(void* cpGridPointer, int numGlobalIds,
76  int numLocalIds, ZOLTAN_ID_PTR gids,
77  ZOLTAN_ID_PTR lids, int wgtDim,
78  float *objWgts, int *err);
79 
81 void getNullNumEdgesList(void *cpGridPointer, int sizeGID, int sizeLID,
82  int numCells,
83  ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
84  int *numEdges, int *err);
85 
87 void getNullEdgeList(void *cpGridPointer, int sizeGID, int sizeLID,
88  int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
89  int *num_edges,
90  ZOLTAN_ID_PTR nborGID, int *nborProc,
91  int wgt_dim, float *ewgts, int *err);
92 
96 inline int getNullNumCells(void* cpGridPointer, int* err)
97 {
98  (void) cpGridPointer;
99  *err = ZOLTAN_OK;
100  return 0;
101 }
102 
104 void getCpGridWellsNumEdgesList(void *cpGridWellsPointer, int sizeGID, int sizeLID,
105  int numCells,
106  ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
107  int *numEdges, int *err);
108 
110 void getCpGridWellsEdgeList(void *cpGridWellsPointer, int sizeGID, int sizeLID,
111  int numCells, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID,
112  int *num_edges,
113  ZOLTAN_ID_PTR nborGID, int *nborProc,
114  int wgt_dim, float *ewgts, int *err);
115 } // end namespace cpgrid
116 } // end namespace Dune
117 
118 #endif // HAVE_ZOLTAN
119 namespace Dune
120 {
121 namespace cpgrid
122 {
131 {
132 public:
133  typedef std::vector<std::set<int> > GraphType;
134 
142  const std::vector<OpmWellType> * wells,
143  const double* transmissibilities,
144  bool pretendEmptyGrid,
145  EdgeWeightMethod edgeWeightsMethod);
146 
148  const Dune::CpGrid& getGrid() const
149  {
150  return grid_;
151  }
152 
153  const GraphType& getWellsGraph() const
154  {
155  return wellsGraph_;
156  }
157 
158  double transmissibility(int face_index) const
159  {
160  return transmissibilities_ ? (1.0e18*transmissibilities_[face_index]) : 1;
161  }
162 
163  double logTransmissibilityWeights(int face_index) const
164  {
165  double trans = transmissibilities_ ? transmissibilities_[face_index] : 1;
166  return trans == 0.0 ? 0.0 : 1.0 + std::log(trans) - log_min_;
167  }
168 
169  const WellConnections& getWellConnections() const
170  {
171  return well_indices_;
172  }
173 
174  double edgeWeight(int face_index) const
175  {
176  if (edgeWeightsMethod_ == uniformEdgeWgt)
177  return 1.0;
178  else if (edgeWeightsMethod_ == defaultTransEdgeWgt)
179  return transmissibility(face_index);
180  else if (edgeWeightsMethod_ == logTransEdgeWgt)
181  return logTransmissibilityWeights(face_index);
182  else
183  return 1.0;
184  }
185 private:
186 
187  void addCompletionSetToGraph()
188  {
189  for(const auto& well_indices: well_indices_)
190  {
191  for( auto well_idx = well_indices.begin(); well_idx != well_indices.end();
192  ++well_idx)
193  {
194  auto well_idx2 = well_idx;
195  for( ++well_idx2; well_idx2 != well_indices.end();
196  ++well_idx2)
197  {
198  wellsGraph_[*well_idx].insert(*well_idx2);
199  wellsGraph_[*well_idx2].insert(*well_idx);
200  }
201  }
202  }
203  }
204 
205  void findMaxMinTrans()
206  {
207  double min_val = std::numeric_limits<float>::max();
208 
209  if (transmissibilities_) {
210  for (int face = 0; face < getGrid().numFaces(); ++face)
211  {
212  double trans = transmissibilities_[face];
213  if (trans > 0)
214  {
215  if (trans < min_val)
216  min_val = trans;
217  }
218  }
219  log_min_ = std::log(min_val);
220  }
221  else {
222  log_min_ = 0.0;
223  }
224  }
225 
226  const Dune::CpGrid& grid_;
227  GraphType wellsGraph_;
228  const double* transmissibilities_;
229  int edgeWeightsMethod_;
230  WellConnections well_indices_;
231  double log_min_;
232 };
233 
234 #ifdef HAVE_ZOLTAN
239 void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
240  bool pretendNull=false);
241 
242 void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
243  const CombinedGridWellGraph& graph,
244  bool pretendNull);
245 #endif // HAVE_ZOLTAN
246 } // end namespace cpgrid
247 } // end namespace Dune
248 
249 #endif // header guard
[ provides Dune::Grid ]
Definition: CpGrid.hpp:207
int numFaces() const
Get the number of faces.
Definition: CpGrid.hpp:960
A graph repesenting a grid together with the well completions.
Definition: ZoltanGraphFunctions.hpp:131
const Dune::CpGrid & getGrid() const
Access the grid.
Definition: ZoltanGraphFunctions.hpp:148
CombinedGridWellGraph(const Dune::CpGrid &grid, const std::vector< OpmWellType > *wells, const double *transmissibilities, bool pretendEmptyGrid, EdgeWeightMethod edgeWeightsMethod)
Create a graph representing a grid together with the wells.
Copyright 2019 Equinor AS.
Definition: CartesianIndexMapper.hpp:10
EdgeWeightMethod
enum for choosing Methods for weighting graph-edges correspoding to cell interfaces in Zoltan's graph...
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