Loading [MathJax]/extensions/TeX/newcommand.js
 Reference documentation for deal.II version 9.4.1
\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}} \newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=} \newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]} \newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cell_id_translator.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2021 - 2022 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_cell_id_translator_h
17#define dealii_cell_id_translator_h
18
21
24
25#include <cstdint>
26
28
29namespace internal
30{
53 template <int dim>
55 {
56 public:
63
69 size() const;
70
75 template <typename Accessor>
77 translate(const TriaIterator<Accessor> &cell) const;
78
82 template <typename Accessor>
85 const types::global_cell_index i) const;
86
90 CellId
92
93 private:
99 const typename CellId::binary_type &binary_representation);
100
105
110
114 std::vector<types::global_cell_index> tree_sizes;
115 };
116
117
118
119 template <int dim>
121 const types::global_cell_index n_coarse_cells,
122 const types::global_cell_index n_global_levels)
123 : n_coarse_cells(n_coarse_cells)
124 , n_global_levels(n_global_levels)
125 {
126 std::uint64_t max_cell_index = 0;
127
128 for (unsigned int i = 0; i < n_global_levels; ++i)
129 max_cell_index +=
130 Utilities::pow<std::uint64_t>(GeometryInfo<dim>::max_children_per_cell,
131 i) *
133
134 max_cell_index -= 1;
135
136 Assert(
137 max_cell_index <= std::numeric_limits<types::global_cell_index>::max(),
139 "You have exceeded the maximal number of possible indices this function "
140 "can handle. The current setup (n_coarse_cells=" +
141 std::to_string(n_coarse_cells) +
142 ", n_global_levels=" + std::to_string(n_global_levels) + ") requires " +
143 std::to_string(max_cell_index + 1) +
144 " indices but the current deal.II configuration only supports " +
145 std::to_string(std::numeric_limits<types::global_cell_index>::max()) +
146 " indices. You may want to consider to build deal.II with 64bit "
147 "indices (-D DEAL_II_WITH_64BIT_INDICES=\"ON\") to increase the limit "
148 "of indices."));
149
150 tree_sizes.push_back(0);
151 for (unsigned int i = 0; i < n_global_levels; ++i)
152 tree_sizes.push_back(tree_sizes.back() +
153 Utilities::pow<types::global_cell_index>(
156 }
157
158
159
160 template <int dim>
163 {
164 return n_coarse_cells *
165 (Utilities::pow<types::global_cell_index>(
167 1);
168 }
169
170
171
172 template <int dim>
173 template <typename Accessor>
176 {
177 static_assert(dim == Accessor::dimension &&
178 dim == Accessor::structure_dimension,
179 "The information can only be queried for cells.");
180
182
183 id += convert_cell_id_binary_type_to_level_coarse_cell_id(
185 .id()
186 .template to_binary<dim>());
187
188 id += tree_sizes[cell->level()];
189
190 return id;
191 }
192
193
194
195 template <int dim>
196 template <typename Accessor>
199 const types::global_cell_index i) const
200 {
201 static_assert(dim == Accessor::dimension &&
202 dim == Accessor::structure_dimension,
203 "The information can only be queried for cells.");
204
205 return (translate(cell) - tree_sizes[cell->level()]) *
207 i + tree_sizes[cell->level() + 1];
208 }
209
210
211
212 template <int dim>
213 CellId
215 {
216 std::vector<std::uint8_t> child_indices;
217
218 types::global_cell_index id_temp = id;
219
221
222 for (; level < n_global_levels; ++level)
223 if (id < tree_sizes[level])
224 break;
225 level -= 1;
226
227 id_temp -= tree_sizes[level];
228
229 for (types::global_cell_index l = 0; l < level; ++l)
230 {
231 child_indices.push_back(id_temp %
234 }
235
236 std::reverse(child_indices.begin(), child_indices.end());
237
238 return {id_temp, child_indices}; // TODO
239 }
240
241
242
243 template <int dim>
246 const typename CellId::binary_type &binary_representation)
247 {
248 // exploiting the structure of CellId::binary_type
249 // see also the documentation of CellId
250
251 // actual coarse-grid id
252 const unsigned int coarse_cell_id = binary_representation[0];
253 const unsigned int n_child_indices = binary_representation[1] >> 2;
254
255 const unsigned int children_per_value =
256 sizeof(CellId::binary_type::value_type) * 8 / dim;
257 unsigned int child_level = 0;
258 unsigned int binary_entry = 2;
259
260 // path to the get to the cell
261 std::vector<unsigned int> cell_indices;
262 while (child_level < n_child_indices)
263 {
264 Assert(binary_entry < binary_representation.size(), ExcInternalError());
265
266 for (unsigned int j = 0; j < children_per_value; ++j)
267 {
268 unsigned int cell_index =
269 (((binary_representation[binary_entry] >> (j * dim))) &
271 cell_indices.push_back(cell_index);
272 ++child_level;
273 if (child_level == n_child_indices)
274 break;
275 }
276 ++binary_entry;
277 }
278
279 // compute new coarse-grid id: c_{i+1} = c_{i}*2^dim + q;
280 types::global_cell_index level_coarse_cell_id = coarse_cell_id;
281 for (auto i : cell_indices)
282 level_coarse_cell_id =
283 level_coarse_cell_id * GeometryInfo<dim>::max_children_per_cell + i;
284
285 return level_coarse_cell_id;
286 }
287
288} // namespace internal
289
291
292#endif
Definition: cell_id.h:71
std::array< unsigned int, 4 > binary_type
Definition: cell_id.h:80
const types::global_cell_index n_global_levels
types::global_cell_index translate(const TriaIterator< Accessor > &cell) const
static types::global_cell_index convert_cell_id_binary_type_to_level_coarse_cell_id(const typename CellId::binary_type &binary_representation)
CellIDTranslator(const types::global_cell_index n_coarse_cells, const types::global_cell_index n_global_levels)
std::vector< types::global_cell_index > tree_sizes
CellId to_cell_id(const types::global_cell_index id) const
const types::global_cell_index n_coarse_cells
types::global_cell_index size() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
unsigned int level
Definition: grid_out.cc:4606
unsigned int cell_index
Definition: grid_tools.cc:1129
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)