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 <dune/grid/CpGrid.hpp>
27 #include <dune/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 
123 class CombinedGridWellGraph
124 {
125 public:
126  typedef std::vector<std::set<int> > GraphType;
127 
132  CombinedGridWellGraph(const Dune::CpGrid& grid,
133  const Opm::EclipseState*,
134  const double* transmissibilities,
135  bool pretendEmptyGrid);
136 
138  const Dune::CpGrid& getGrid() const
139  {
140  return grid_;
141  }
142 
143  const GraphType& getWellsGraph() const
144  {
145  return wellsGraph_;
146  }
147 
148  double transmissibility(int face_index) const
149  {
150  return transmissibilities_ ? (1.0e18*transmissibilities_[face_index]) : 1;
151  }
152 
153  const WellConnections& getWellConnections() const
154  {
155  return well_indices_;
156  }
157 private:
158 
159  void addCompletionSetToGraph()
160  {
161  for(const auto& well_indices: well_indices_)
162  {
163  for( auto well_idx = well_indices.begin(); well_idx != well_indices.end();
164  ++well_idx)
165  {
166  auto well_idx2 = well_idx;
167  for( ++well_idx2; well_idx2 != well_indices.end();
168  ++well_idx2)
169  {
170  wellsGraph_[*well_idx].insert(*well_idx2);
171  wellsGraph_[*well_idx2].insert(*well_idx);
172  }
173  }
174  }
175  }
176 
177 
178  const Dune::CpGrid& grid_;
179  GraphType wellsGraph_;
180  const double* transmissibilities_;
181  WellConnections well_indices_;
182 };
183 
184 
189 void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
190  bool pretendNull=false);
191 
192 void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
193  const CombinedGridWellGraph& graph,
194  bool pretendNull);
195 } // end namespace cpgrid
196 } // end namespace Dune
197 
198 #endif // HAVE_ZOLTAN
199 #endif // header guard
Holds the implementation of the CpGrid as a pimple.
Definition: OpmParserIncludes.hpp:42
[ provides Dune::Grid ]
Definition: CpGrid.hpp:213