opm-grid
MetisPartition.hpp
1 /*
2  Copyright 2024 OPM-OP AS
3 
4  This file is part of The Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef DUNE_CPGRID_METISPARTITION_HEADER
20 #define DUNE_CPGRID_METISPARTITION_HEADER
21 
22 #include <opm/grid/CpGrid.hpp>
23 #include <opm/grid/common/ZoltanGraphFunctions.hpp>
24 #include <opm/grid/common/WellConnections.hpp>
25 #include <opm/grid/common/ZoltanPartition.hpp>
26 #include <opm/grid/common/GridPartitioning.hpp>
27 
28 // We want to use METIS, but if METIS is installed together with Scotch, then METIS uses some artifacts from Scotch.
29 // For this type, we need to include scotch.h.
30 #if IS_SCOTCH_METIS_HEADER
31 extern "C" {
32  #include <scotch.h>
33 }
34 // And also, we need to set the version number here manually to 5
35 #ifndef SCOTCH_METIS_VERSION
36 #define SCOTCH_METIS_VERSION 5
37 #endif /* SCOTCH_METIS_VERSION */
38 #endif
39 
40 #if defined(HAVE_METIS) && HAVE_MPI
41 extern "C" {
42  #include <metis.h>
43 }
44 #endif // defined(HAVE_METIS) && HAVE_MPI
45 
46 #if defined(HAVE_METIS) && HAVE_MPI
47 
48 #include <map>
49 #include <set>
50 #include <string>
51 #include <tuple>
52 #include <unordered_map>
53 #include <vector>
54 
55 namespace Dune
56 {
57 namespace cpgrid
58 {
59 #if defined(REALTYPEWIDTH)
60  using real_t = ::real_t;
61 #else
62  using real_t = double;
63 #endif
64 
65 #if defined(IDXTYPEWIDTH)
66  using idx_t = ::idx_t;
67 #elif IS_SCOTCH_METIS_HEADER
68  using idx_t = SCOTCH_Num;
69 #else
70  using idx_t = int;
71 #endif
72 
73 #if IS_SCOTCH_METIS_HEADER
74  // NOTE: scotchmetis does not define a return type for METIS functions
75  #define METIS_OK 1
76 #endif
77 
82 
108 
109 std::tuple<std::vector<int>,
110  std::vector<std::pair<std::string, bool>>,
111  std::vector<std::tuple<int, int, char>>,
112  std::vector<std::tuple<int, int, char, int>>,
113  WellConnections>
114 metisSerialGraphPartitionGridOnRoot(const CpGrid& grid,
115  const std::vector<OpmWellType> * wells,
116  const std::unordered_map<std::string, std::set<int>>& possibleFutureConnections,
117  const double* transmissibilities,
118  const Communication<MPI_Comm>& cc,
119  EdgeWeightMethod edgeWeightsMethod,
120  int root,
121  real_t imbalanceTol,
122  bool allowDistributedWells,
123  const std::map<std::string,std::string>& params);
124 }
125 }
126 
127 
128 #endif // defined(HAVE_METIS) && HAVE_MPI
129 #endif // header guard
The namespace Dune is the main namespace for all Dune code.
Definition: CartesianIndexMapper.hpp:9
EdgeWeightMethod
enum for choosing Methods for weighting graph-edges correspoding to cell interfaces in Zoltan&#39;s or Me...
Definition: GridEnums.hpp:34