deal.II version GIT relicensing-6842-g793a97d2aa 2026-10-02 14:00: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_objects.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) 2006 - 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_objects_h
14#define dealii_tria_objects_h
15
16#include <deal.II/base/config.h>
17
21
22#include <vector>
23
25
26// Forward declarations
27#ifndef DOXYGEN
28template <int dim, int spacedim>
30class Triangulation;
31template <class Accessor>
32class TriaRawIterator;
33template <int, int, int>
34class TriaAccessor;
35#endif
36
37namespace internal
38{
39 namespace TriangulationImplementation
40 {
51 {
52 public:
57
70 TriaObjects(const unsigned int structdim,
71 const unsigned int children_per_object,
72 const unsigned int faces_per_object);
73
80 void
81 allocate(const std::size_t n_objects);
82
95 void
96 allocate_end(const std::size_t new_objects_in_pairs,
97 const std::size_t new_objects_single);
98
102 unsigned int structdim;
103
110
116 unsigned int faces_per_object;
117
121 std::size_t
122 n_objects() const;
123
127 int
128 get_bounding_object(const int index, const unsigned int face_no) const;
129
134 void
135 set_bounding_object(const int index,
136 const unsigned int face_no,
137 const int neighbor_index);
138
147 get_bounding_object_indices(const unsigned int index);
148
160 std::vector<int> children;
161
167 std::vector<std::uint8_t> refinement_cases;
168
177 std::vector<bool> used;
178
188 std::vector<bool> user_flags;
189
190
196 {
197 union
198 {
201 };
202
203
208
212 static std::size_t
214
220 template <class Archive>
221 void
222 serialize(Archive &ar, const unsigned int version);
223 };
224
239 std::vector<BoundaryOrMaterialId> boundary_or_material_id;
240
245 std::vector<types::manifold_id> manifold_id;
246
258 template <int structdim, int dim, int spacedim>
261
273 template <int structdim, int dim, int spacedim>
276
281 template <int dim, int spacedim>
284 const unsigned int level);
285
289 void *&
290 user_pointer(const unsigned int i);
291
295 const void *
296 user_pointer(const unsigned int i) const;
297
301 unsigned int &
302 user_index(const unsigned int i);
303
307 unsigned int
308 user_index(const unsigned int i) const;
309
313 void
314 clear_user_data(const unsigned int i);
315
320 void
322
326 void
328
333 std::size_t
334 memory_consumption() const;
335
341 template <class Archive>
342 void
343 serialize(Archive &ar, const unsigned int version);
344
353
357 unsigned int next_free_single;
358
362 unsigned int next_free_pair;
363
368
372 struct UserData
373 {
374 union
375 {
378 void *p;
381 unsigned int i;
382 };
383
388 {
389 p = nullptr;
390 }
391
397 template <class Archive>
398 void
399 serialize(Archive &ar, const unsigned int version);
400 };
401
414
415
420 std::vector<UserData> user_data;
421
428
429 private:
438 std::vector<int> bounding_objects;
439 };
440
441
442 //----------------------------------------------------------------------//
443
444 inline std::size_t
446 {
447 // ensure that sizes are consistent, and then return one that
448 // corresponds to the number of objects
451 return manifold_id.size();
452 }
453
454
455
456 inline int
458 const unsigned int face_no) const
459 {
460 // Accessors with an index of -1 shouldn't get here
461 Assert(index != -1, ExcInternalError());
463 const auto i = index * faces_per_object + face_no;
465 return bounding_objects[i];
466 }
467
468
469
470 inline void
472 const unsigned int face_no,
473 const int neighbor_index)
474 {
475 // Accessors with an index of -1 shouldn't get here
476 Assert(index != -1, ExcInternalError());
477 Assert(neighbor_index >= -1, ExcInternalError());
479 const auto i = index * faces_per_object + face_no;
481 bounding_objects[i] = neighbor_index;
482 }
483
484
485
486 inline ArrayView<int>
488 {
489 // each cell has the same number of subcell objects
492 }
493
494
495
500
501
502
503 inline std::size_t
508
509
510
511 template <class Archive>
512 void
514 const unsigned int /*version*/)
515 {
516 // serialize this
517 // structure by
518 // writing and
519 // reading the larger
520 // of the two values,
521 // in order to make
522 // sure we get all
523 // bits
524 if (sizeof(material_id) > sizeof(boundary_id))
525 ar &material_id;
526 else
527 ar &boundary_id;
528 }
529
530
531 inline void *&
532 TriaObjects::user_pointer(const unsigned int i)
533 {
537
538 AssertIndexRange(i, user_data.size());
539 return user_data[i].p;
540 }
541
542
543 inline const void *
544 TriaObjects::user_pointer(const unsigned int i) const
545 {
549
550 AssertIndexRange(i, user_data.size());
551 return user_data[i].p;
552 }
553
554
555 inline unsigned int &
556 TriaObjects::user_index(const unsigned int i)
557 {
561
562 AssertIndexRange(i, user_data.size());
563 return user_data[i].i;
564 }
565
566
567 inline void
568 TriaObjects::clear_user_data(const unsigned int i)
569 {
570 AssertIndexRange(i, user_data.size());
571 user_data[i].i = 0;
572 }
573
574
576 : structdim(numbers::invalid_unsigned_int)
577 , children_per_object(numbers::invalid_unsigned_int)
578 , faces_per_object(numbers::invalid_unsigned_int)
579 , next_free_single(numbers::invalid_unsigned_int)
580 , next_free_pair(numbers::invalid_unsigned_int)
583 {}
584
585
586 inline TriaObjects::TriaObjects(const unsigned int structdim,
587 const unsigned int children_per_object,
588 const unsigned int faces_per_object)
589 : structdim(structdim)
590 , children_per_object(children_per_object)
591 , faces_per_object(faces_per_object)
592 , next_free_single(numbers::invalid_unsigned_int)
593 , next_free_pair(numbers::invalid_unsigned_int)
594 , reverse_order_next_free_single(false)
595 , user_data_type(data_unknown)
596 {}
597
598
599 inline unsigned int
600 TriaObjects::user_index(const unsigned int i) const
601 {
605
606 AssertIndexRange(i, user_data.size());
607 return user_data[i].i;
608 }
609
610
611 inline void
613 {
615 for (auto &data : user_data)
616 data.p = nullptr;
617 }
618
619
620 inline void
622 {
623 user_flags.assign(user_flags.size(), false);
624 }
625
626
627 template <class Archive>
628 void
629 TriaObjects::UserData::serialize(Archive &ar, const unsigned int)
630 {
631 // serialize this as an integer
632 ar &i;
633 }
634
635
636
637 template <class Archive>
638 void
639 TriaObjects::serialize(Archive &ar, const unsigned int)
640 {
641 ar &structdim;
646 ar &used;
647 ar &user_flags;
649 ar &manifold_id;
652 }
653
654
655 //----------------------------------------------------------------------//
656
657 template <int structdim_, int dim, int spacedim>
661 {
662 // TODO: Think of a way to ensure that we are using the correct
663 // triangulation, i.e. the one containing *this.
664
665 AssertDimension(structdim_, this->structdim);
666
667 int pos = next_free_single, last = used.size() - 1;
669 {
670 // first sweep forward, only use really single slots, do not use
671 // pair slots
672 for (; pos < last; ++pos)
673 if (!used[pos])
674 if (used[++pos])
675 {
676 // this was a single slot
677 pos -= 1;
678 break;
679 }
680 if (pos >= last)
681 {
683 next_free_single = used.size() - 1;
684 pos = used.size() - 1;
685 }
686 else
687 next_free_single = pos + 1;
688 }
689
691 {
692 // second sweep, use all slots, even
693 // in pairs
694 for (; pos >= 0; --pos)
695 if (!used[pos])
696 break;
697 if (pos > 0)
698 next_free_single = pos - 1;
699 else
700 // no valid single object anymore
701 return ::TriaRawIterator<
703 }
704
705 return ::TriaRawIterator<
707 }
708
709
710
711 template <int structdim_, int dim, int spacedim>
714 {
715 // TODO: Think of a way to ensure that we are using the correct
716 // triangulation, i.e. the one containing *this.
717
718 AssertDimension(structdim_, this->structdim);
719
720 int pos = next_free_pair, last = used.size() - 1;
721 for (; pos < last; ++pos)
722 if (!used[pos])
723 if (!used[++pos])
724 {
725 // this was a pair slot
726 pos -= 1;
727 break;
728 }
729 if (pos >= last)
730 // no free slot
731 return ::TriaRawIterator<
733 else
734 next_free_pair = pos + 2;
735
736 return ::TriaRawIterator<
738 }
739 } // namespace TriangulationImplementation
740} // namespace internal
741
742
743
745
746#endif
typename IteratorSelector::raw_hex_iterator raw_hex_iterator
Definition tria.h:4240
std::vector< types::manifold_id > manifold_id
void allocate_end(const std::size_t new_objects_in_pairs, const std::size_t new_objects_single)
ArrayView< int > get_bounding_object_indices(const unsigned int index)
void serialize(Archive &ar, const unsigned int version)
void set_bounding_object(const int index, const unsigned int face_no, const int neighbor_index)
int get_bounding_object(const int index, const unsigned int face_no) const
Triangulation< dim, spacedim >::raw_hex_iterator next_free_hex(const Triangulation< dim, spacedim > &tria, const unsigned int level)
unsigned int & user_index(const unsigned int i)
::TriaRawIterator<::TriaAccessor< structdim, dim, spacedim > > next_free_single_object(const Triangulation< dim, spacedim > &tria)
::TriaRawIterator<::TriaAccessor< structdim, dim, spacedim > > next_free_pair_object(const Triangulation< dim, spacedim > &tria)
void allocate(const std::size_t n_objects)
std::vector< BoundaryOrMaterialId > boundary_or_material_id
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
#define DeclException0(Exception0)
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
std::vector< index_type > data
Definition mpi.cc:734
constexpr types::material_id invalid_material_id
Definition types.h:284
void serialize(Archive &ar, const unsigned int version)