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/core/props/BlackoilPhases.hpp>
28 
29 #include <dune/grid/common/gridview.hh>
30 
31 #include <any>
32 #include <vector>
33 
34 namespace Opm {
35 namespace detail {
36 
37 
38  std::vector<int> buildAllCells(const int nc);
39 
40 
41 
42  template <class PU>
43  std::vector<bool>
44  activePhases(const PU& pu)
45  {
46  const int maxnp = BlackoilPhases::MaxNumPhases;
47  std::vector<bool> active(maxnp, false);
48 
49  for (int p = 0; p < pu.MaxNumPhases; ++p) {
50  active[ p ] = pu.phase_used[ p ] != 0;
51  }
52 
53  return active;
54  }
55 
56 
57 
58  template <class PU>
59  std::vector<int>
60  active2Canonical(const PU& pu)
61  {
62  const int maxnp = BlackoilPhases::MaxNumPhases;
63  std::vector<int> act2can(maxnp, -1);
64 
65  for (int phase = 0; phase < maxnp; ++phase) {
66  if (pu.phase_used[ phase ]) {
67  act2can[ pu.phase_pos[ phase ] ] = phase;
68  }
69  }
70 
71  return act2can;
72  }
73 
74 
75 
76  double getGravity(const double* g, const int dim);
77 
83  template<class Grid>
84  std::size_t countLocalInteriorCells(const Grid& grid)
85  {
86  if ( grid.comm().size() == 1)
87  {
88  return grid.size(0);
89  }
90  std::size_t count = 0;
91  const auto& gridView = grid.leafGridView();
92  for(auto cell = gridView.template begin<0, Dune::Interior_Partition>(),
93  endCell = gridView.template end<0, Dune::Interior_Partition>();
94  cell != endCell; ++cell)
95  {
96  ++count;
97  }
98  return count;
99  }
100 
108  template<class Grid>
109  std::size_t countGlobalCells(const Grid& grid)
110  {
111  if ( grid.comm().size() == 1)
112  {
113  return grid.size(0);
114  }
115  std::size_t count = countLocalInteriorCells(grid);
116  return grid.comm().sum(count);
117  }
118 
119  } // namespace detail
120 } // namespace Opm
121 
122 #endif // OPM_BLACKOILDETAILS_HEADER_INCLUDED
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27