My Project
countGlobalCells.hpp
1 /*
2  Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
3  Copyright 2014, 2015 Dr. Blatt - HPC-Simulation-Software & Services
4  Copyright 2014, 2015 Statoil ASA.
5  Copyright 2015 NTNU
6  Copyright 2015 IRIS AS
7 
8  This file is part of the Open Porous Media project (OPM).
9 
10  OPM is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  OPM is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with OPM. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #ifndef OPM_COUNTGLOBALCELLS_HEADER_INCLUDED
25 #define OPM_COUNTGLOBALCELLS_HEADER_INCLUDED
26 
27 #include <opm/simulators/linalg/ParallelIstlInformation.hpp>
28 #include <opm/core/props/BlackoilPhases.hpp>
29 
30 #include <dune/grid/common/gridview.hh>
31 
32 #include <any>
33 #include <vector>
34 
35 namespace Opm {
36 namespace detail {
37 
38 
39  std::vector<int> buildAllCells(const int nc);
40 
41 
42 
43  template <class PU>
44  std::vector<bool>
45  activePhases(const PU& pu)
46  {
47  const int maxnp = BlackoilPhases::MaxNumPhases;
48  std::vector<bool> active(maxnp, false);
49 
50  for (int p = 0; p < pu.MaxNumPhases; ++p) {
51  active[ p ] = pu.phase_used[ p ] != 0;
52  }
53 
54  return active;
55  }
56 
57 
58 
59  template <class PU>
60  std::vector<int>
61  active2Canonical(const PU& pu)
62  {
63  const int maxnp = BlackoilPhases::MaxNumPhases;
64  std::vector<int> act2can(maxnp, -1);
65 
66  for (int phase = 0; phase < maxnp; ++phase) {
67  if (pu.phase_used[ phase ]) {
68  act2can[ pu.phase_pos[ phase ] ] = phase;
69  }
70  }
71 
72  return act2can;
73  }
74 
75 
76 
77  double getGravity(const double* g, const int dim);
78 
84  template<class Grid>
85  std::size_t countLocalInteriorCells(const Grid& grid)
86  {
87  if ( grid.comm().size() == 1)
88  {
89  return grid.size(0);
90  }
91  std::size_t count = 0;
92  const auto& gridView = grid.leafGridView();
93  for(auto cell = gridView.template begin<0, Dune::Interior_Partition>(),
94  endCell = gridView.template end<0, Dune::Interior_Partition>();
95  cell != endCell; ++cell)
96  {
97  ++count;
98  }
99  return count;
100  }
101 
109  template<class Grid>
110  std::size_t countGlobalCells(const Grid& grid)
111  {
112  if ( grid.comm().size() == 1)
113  {
114  return grid.size(0);
115  }
116  std::size_t count = countLocalInteriorCells(grid);
117  return grid.comm().sum(count);
118  }
119 
120  } // namespace detail
121 } // namespace Opm
122 
123 #endif // OPM_BLACKOILDETAILS_HEADER_INCLUDED
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27