countGlobalCells.hpp
Go to the documentation of this file.
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
28
29#include <dune/grid/common/gridview.hh>
30
31#include <algorithm>
32#include <vector>
33
34namespace Opm {
35namespace detail {
36
46 template <class GridView>
47 std::size_t countLocalInteriorCellsGridView(const GridView& gridView)
48 {
49 if (gridView.comm().size() == 1) {
50 return gridView.size(0);
51 }
52
53 return std::distance(gridView.template begin<0, Dune::Interior_Partition>(),
54 gridView.template end<0, Dune::Interior_Partition>());
55 }
56
65 template<class Grid>
66 std::size_t countLocalInteriorCells(const Grid& grid)
67 {
68 return countLocalInteriorCellsGridView(grid.leafGridView());
69 }
70
81 template<class Grid>
82 std::size_t countGlobalCells(const Grid& grid)
83 {
84 if ( grid.comm().size() == 1)
85 {
86 return grid.size(0);
87 }
88 const std::size_t count = countLocalInteriorCellsGridView(grid.leafGridView());
89 return grid.comm().sum(count);
90 }
91
92 } // namespace detail
93} // namespace Opm
94
95#endif // OPM_BLACKOILDETAILS_HEADER_INCLUDED
std::size_t countGlobalCells(const Grid &grid)
Get the number of cells of a global grid.
Definition: countGlobalCells.hpp:82
std::size_t countLocalInteriorCellsGridView(const GridView &gridView)
Get the number of local interior cells in a grid view.
Definition: countGlobalCells.hpp:47
std::size_t countLocalInteriorCells(const Grid &grid)
Get the number of local interior cells in a grid.
Definition: countGlobalCells.hpp:66
Definition: BlackoilPhases.hpp:27