My Project
Loading...
Searching...
No Matches
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/OpmWellType.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
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
164 const GraphType& getWellsGraph() const
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
180 const WellConnections& getWellConnections() const
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 double min_val = std::numeric_limits<float>::max();
219
220 if (transmissibilities_) {
221 for (int face = 0; face < getGrid().numFaces(); ++face)
222 {
223 double trans = transmissibilities_[face];
224 if (trans > 0)
225 {
226 if (trans < min_val)
227 min_val = trans;
228 }
229 }
230 log_min_ = std::log(min_val);
231 }
232 else {
233 log_min_ = 0.0;
234 }
235 }
236
237 const Dune::CpGrid& grid_;
238 GraphType wellsGraph_;
239 const double* transmissibilities_;
240 int edgeWeightsMethod_;
241 WellConnections well_indices_;
242 double log_min_;
243};
244
246int getNumberOfEdgesForSpecificCellForGridWithWells(const CombinedGridWellGraph& graph, int localCellId);
247
249template<typename ID, typename weightType>
250void fillNBORGIDAndWeightsForSpecificCellAndIncrementNeighborCounterForGridWithWells(const CombinedGridWellGraph& graph, const int localCellId, ID globalID, int& neighborCounter, ID& nborGID, weightType *ewgts);
251
252#ifdef HAVE_ZOLTAN
257void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid,
258 bool pretendNull=false);
259
260void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz,
261 const CombinedGridWellGraph& graph,
262 bool pretendNull);
263#endif // HAVE_ZOLTAN
264} // end namespace cpgrid
265} // end namespace Dune
266
267#endif // header guard
[ provides Dune::Grid ]
Definition CpGrid.hpp:201
int numCells() const
Get the number of cells.
Definition CpGrid.cpp:1083
int numFaces() const
Get the number of faces.
Definition CpGrid.cpp:1088
A graph repesenting a grid together with the well completions.
Definition ZoltanGraphFunctions.hpp:138
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.
const Dune::CpGrid & getGrid() const
Access the grid.
Definition ZoltanGraphFunctions.hpp:159
Copyright 2019 Equinor AS.
Definition 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