ElementChunks.hpp
Go to the documentation of this file.
1/*
2 Copyright 2025 SINTEF Digital
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 OPM_ELEMENT_CHUNKS_HEADER
20#define OPM_ELEMENT_CHUNKS_HEADER
21
23
24#include <cstddef>
25#include <iterator>
26#include <utility>
27#include <vector>
28
29namespace Opm
30{
31
75template <class GridView, class PartitionSet>
77{
78private:
79 using Iter = decltype(std::begin(elements(std::declval<const GridView&>(), PartitionSet())));
80 using Storage = std::vector<Iter>;
81 using StorageIter = decltype(Storage().cbegin());
82
83public:
84 ElementChunks(const GridView& gv,
85 const PartitionSet included_partition,
86 const std::size_t num_chunks)
87 {
88 grid_chunk_iterators_
89 = Opm::createChunkIterators(elements(gv, included_partition), gv.size(0), num_chunks);
90 }
91
92 struct Chunk
93 {
94 Chunk(const Iter& i1, const Iter& i2) : pi_(i1, i2) {}
95 auto begin() const { return pi_.first; }
96 auto end() const { return pi_.second; }
97 std::pair<Iter, Iter> pi_;
98 };
99
100 struct ChunkIterator : public StorageIter
101 {
102 explicit ChunkIterator(const StorageIter& itit) : StorageIter(itit) {}
104 {
105 const StorageIter it = *this;
106 return Chunk{*it, *(it+1)};
107 }
108 };
109
110 auto begin() const
111 {
112 return ChunkIterator(grid_chunk_iterators_.begin());
113 }
114 auto end() const
115 {
116 // Note the decrement, we want a StorageIterator pointing to
117 // the last element in grid_chunk_iterators_, not the
118 // one-beyond-last-element iterator.
119 return ChunkIterator(--grid_chunk_iterators_.end());
120 }
121 auto size() const
122 {
123 return grid_chunk_iterators_.size() - 1;
124 }
125private:
126 Storage grid_chunk_iterators_;
127};
128
129
130} // namespace Opm
131
132#endif // OPM_ELEMENT_CHUNKS_HEADER
Definition: ElementChunks.hpp:77
auto end() const
Definition: ElementChunks.hpp:114
auto size() const
Definition: ElementChunks.hpp:121
auto begin() const
Definition: ElementChunks.hpp:110
ElementChunks(const GridView &gv, const PartitionSet included_partition, const std::size_t num_chunks)
Definition: ElementChunks.hpp:84
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:26
auto createChunkIterators(const Range &r, const std::size_t num_elem, const std::size_t num_chunks)
Definition: createThreadIterators.hpp:48
Definition: ElementChunks.hpp:101
Chunk operator*() const
Definition: ElementChunks.hpp:103
ChunkIterator(const StorageIter &itit)
Definition: ElementChunks.hpp:102
Definition: ElementChunks.hpp:93
auto end() const
Definition: ElementChunks.hpp:96
std::pair< Iter, Iter > pi_
Definition: ElementChunks.hpp:97
auto begin() const
Definition: ElementChunks.hpp:95
Chunk(const Iter &i1, const Iter &i2)
Definition: ElementChunks.hpp:94