deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
tria_levels.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1998 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_tria_levels_h
14#define dealii_tria_levels_h
15
16
17#include <deal.II/base/config.h>
18
19#include <deal.II/base/point.h>
20
24
25#include <cstdint>
26#include <vector>
27
29
30namespace internal
31{
32 namespace TriangulationImplementation
33 {
51 template <int dim, int spacedim = dim>
53 {
54 public:
70 TriaLevel(const unsigned int max_children_per_cell,
71 const unsigned int max_faces_per_cell,
72 const unsigned int max_vertices_per_cell)
73 : children_per_object(max_children_per_cell)
74 , faces_per_object(max_faces_per_cell)
75 , vertices_per_object(max_vertices_per_cell)
76 , cells(dim, max_children_per_cell, max_faces_per_cell)
77 , face_orientations(0, max_faces_per_cell)
78 {}
79
83 TriaLevel();
84
93 void
94 allocate(const std::size_t n_cells, const bool orientation_needed);
95
107 void
108 allocate_end(const std::size_t n_new_cells,
109 const bool orientation_needed,
110 const bool has_tetrahedra);
111
115 std::size_t
116 size() const;
117
122 int
123 neighbor_index(const int index, const unsigned int face_no) const;
124
129 int
130 neighbor_level(const int index, const unsigned int face_no) const;
131
136 void
138 const unsigned int face_no,
139 const int neighbor_level,
140 const int neighbor_index);
141
146 void
148 const unsigned int vertex_no,
149 const unsigned int vertex_index);
150
159 unsigned int
160 cached_vertex_index(const int index, const unsigned int vertex_no) const;
161
168
174 unsigned int faces_per_object;
175
182
191 std::vector<std::uint8_t> refine_flags;
192
198 std::vector<std::uint8_t> refine_choice;
199
204 std::vector<bool> coarsen_flags;
205
211 std::vector<unsigned int> active_cell_indices;
212
216 std::vector<types::global_cell_index> global_active_cell_indices;
217
221 std::vector<types::global_cell_index> global_level_cell_indices;
222
231 std::vector<types::subdomain_id> subdomain_ids;
232
240 std::vector<types::subdomain_id> level_subdomain_ids;
241
252 std::vector<int> parents;
253
261 std::vector<bool> direction_flags;
262
267
294
300 std::vector<ReferenceCell<dim>> reference_cell;
301
306 std::size_t
307 memory_consumption() const;
308
314 template <class Archive>
315 void
316 serialize(Archive &ar, const unsigned int version);
317
318 private:
342 std::vector<std::int8_t> neighbor_levels;
343
351 std::vector<int> neighbor_indices;
352
358 std::vector<unsigned int> cell_vertex_indices_cache;
359 };
360
361
362
363 template <int dim, int spacedim>
364 std::size_t
366 {
367 Assert(refine_flags.size() == coarsen_flags.size() &&
368 refine_flags.size() == active_cell_indices.size() &&
369 refine_flags.size() == global_active_cell_indices.size() &&
370 refine_flags.size() == global_level_cell_indices.size() &&
371 refine_flags.size() == subdomain_ids.size() &&
372 refine_flags.size() == level_subdomain_ids.size() &&
373 refine_flags.size() == cells.n_objects(),
375 if constexpr (dim > 1)
376 Assert(refine_flags.size() == reference_cell.size(),
378
379 return refine_flags.size();
380 }
381
382
383
384 template <int dim, int spacedim>
385 inline int
387 const unsigned int face_no) const
388 {
390 AssertIndexRange(face_no, faces_per_object);
391 const std::size_t i = index * faces_per_object + face_no;
392 AssertIndexRange(i, neighbor_indices.size());
393 return neighbor_indices[i];
394 }
395
396
397
398 template <int dim, int spacedim>
399 inline int
401 const unsigned int face_no) const
402 {
404 AssertIndexRange(face_no, faces_per_object);
405 const std::size_t i = index * faces_per_object + face_no;
406 AssertIndexRange(i, neighbor_levels.size());
407 return neighbor_levels[i];
408 }
409
410
411
412 template <int dim, int spacedim>
413 inline void
415 const unsigned int face_no,
416 const int neighbor_level,
417 const int neighbor_index)
418 {
420 AssertIndexRange(face_no, faces_per_object);
421 Assert(neighbor_level >= -1,
422 ExcMessage("The neighbor level must be -1 (for a cell at the "
423 "boundary) or a nonnegative number."));
424 Assert(neighbor_level < int(numbers::max_n_levels), ExcInternalError());
425 Assert(neighbor_index >= -1,
426 ExcMessage("The neighbor index must be -1 (for a cell at the "
427 "boundary) or a nonnegative number."));
428 const std::size_t i = index * faces_per_object + face_no;
429 AssertIndexRange(i, neighbor_levels.size());
430 AssertIndexRange(i, neighbor_indices.size());
431 neighbor_levels[i] = neighbor_level;
432 neighbor_indices[i] = neighbor_index;
433 }
434
435
436
437 template <int dim, int spacedim>
438 inline void
440 const int index,
441 const unsigned int vertex_no,
442 const unsigned int vertex_index)
443 {
445 AssertIndexRange(vertex_no, vertices_per_object);
446 const std::size_t i =
447 std::size_t(index) * vertices_per_object + vertex_no;
448 AssertIndexRange(i, cell_vertex_indices_cache.size());
449 cell_vertex_indices_cache[i] = vertex_index;
450 }
451
452
453
454 template <int dim, int spacedim>
455 inline unsigned int
457 const int index,
458 const unsigned int vertex_no) const
459 {
461 AssertIndexRange(vertex_no, vertices_per_object);
462 const std::size_t i =
463 std::size_t(index) * vertices_per_object + vertex_no;
464 AssertIndexRange(i, cell_vertex_indices_cache.size());
465 return cell_vertex_indices_cache[i];
466 }
467
468
469
470 template <int dim, int spacedim>
471 template <class Archive>
472 void
473 TriaLevel<dim, spacedim>::serialize(Archive &ar, const unsigned int)
474 {
475 ar &refine_flags &coarsen_flags;
476
477 ar &children_per_object;
478 ar &faces_per_object;
479 ar &vertices_per_object;
480
481 // do not serialize `active_cell_indices` and `vertex_indices_cache`
482 // here. instead of storing them to the stream and re-reading them again
483 // later, we just rebuild them in Triangulation::load()
484
485 ar &neighbor_levels;
486 ar &neighbor_indices;
487 ar &subdomain_ids;
488 ar &level_subdomain_ids;
489 ar &parents;
490 ar &direction_flags;
491 ar &cells;
492 ar &face_orientations;
493 ar &reference_cell;
494
495 // we do need to resize them so they can be populated in the other
496 // functions though.
497 if (cell_vertex_indices_cache.size() !=
498 refine_flags.size() * vertices_per_object)
499 {
500 cell_vertex_indices_cache.assign(refine_flags.size() *
501 vertices_per_object,
503 active_cell_indices.assign(refine_flags.size(),
505 global_active_cell_indices.assign(refine_flags.size(),
507 global_level_cell_indices.assign(refine_flags.size(),
509 }
510 }
511
512 } // namespace TriangulationImplementation
513} // namespace internal
514
516
517#endif
void set_neighbor(const int index, const unsigned int face_no, const int neighbor_level, const int neighbor_index)
unsigned int cached_vertex_index(const int index, const unsigned int vertex_no) const
void allocate(const std::size_t n_cells, const bool orientation_needed)
void set_cached_vertex_index(const int index, const unsigned int vertex_no, const unsigned int vertex_index)
std::vector< types::subdomain_id > level_subdomain_ids
void serialize(Archive &ar, const unsigned int version)
std::vector< ReferenceCell< dim > > reference_cell
void allocate_end(const std::size_t n_new_cells, const bool orientation_needed, const bool has_tetrahedra)
std::vector< unsigned int > cell_vertex_indices_cache
int neighbor_level(const int index, const unsigned int face_no) const
TriaLevel(const unsigned int max_children_per_cell, const unsigned int max_faces_per_cell, const unsigned int max_vertices_per_cell)
Definition tria_levels.h:70
std::vector< types::global_cell_index > global_active_cell_indices
int neighbor_index(const int index, const unsigned int face_no) const
std::vector< types::subdomain_id > subdomain_ids
std::vector< types::global_cell_index > global_level_cell_indices
std::vector< unsigned int > active_cell_indices
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:15808
constexpr std::uint8_t max_n_levels
Definition types.h:415
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
constexpr types::coarse_cell_id invalid_coarse_cell_id
Definition types.h:272