Reference documentation for deal.II version 9.6.0
\(\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: LGPL-2.1-or-later
4// Copyright (C) 2006 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_tria_objects_h
16#define dealii_tria_objects_h
17
18#include <deal.II/base/config.h>
19
23
24#include <vector>
25
27
28// Forward declarations
29#ifndef DOXYGEN
30template <int dim, int spacedim>
32class Triangulation;
33template <class Accessor>
34class TriaRawIterator;
35template <int, int, int>
36class TriaAccessor;
37#endif
38
39namespace internal
40{
41 namespace TriangulationImplementation
42 {
53 {
54 public:
59
63 TriaObjects(const unsigned int structdim);
64
65 unsigned int structdim;
66
71 std::vector<int> cells;
72
76 unsigned int
77 n_objects() const;
78
87 get_bounding_object_indices(const unsigned int index);
88
100 std::vector<int> children;
101
107 std::vector<std::uint8_t> refinement_cases;
108
117 std::vector<bool> used;
118
128 std::vector<bool> user_flags;
129
130
136 {
137 union
138 {
141 };
142
143
148
152 static std::size_t
154
160 template <class Archive>
161 void
162 serialize(Archive &ar, const unsigned int version);
163 };
164
179 std::vector<BoundaryOrMaterialId> boundary_or_material_id;
180
185 std::vector<types::manifold_id> manifold_id;
186
198 template <int structdim, int dim, int spacedim>
201
213 template <int structdim, int dim, int spacedim>
216
221 template <int dim, int spacedim>
224 const unsigned int level);
225
229 void *&
230 user_pointer(const unsigned int i);
231
235 const void *
236 user_pointer(const unsigned int i) const;
237
241 unsigned int &
242 user_index(const unsigned int i);
243
247 unsigned int
248 user_index(const unsigned int i) const;
249
253 void
254 clear_user_data(const unsigned int i);
255
260 void
262
266 void
268
273 std::size_t
274 memory_consumption() const;
275
281 template <class Archive>
282 void
283 serialize(Archive &ar, const unsigned int version);
284
293
297 unsigned int next_free_single;
298
302 unsigned int next_free_pair;
303
308
312 struct UserData
313 {
314 union
315 {
318 void *p;
321 unsigned int i;
322 };
323
328 {
329 p = nullptr;
330 }
331
337 template <class Archive>
338 void
339 serialize(Archive &ar, const unsigned int version);
340 };
341
354
355
360 std::vector<UserData> user_data;
361
368 };
369
370
371 //----------------------------------------------------------------------//
372
373 inline unsigned int
375 {
376 // ensure that sizes are consistent, and then return one that
377 // corresponds to the number of objects
378 AssertDimension(cells.size(), manifold_id.size() * 2 * this->structdim);
379 return manifold_id.size();
380 }
381
382
383
384 inline ArrayView<int>
386 {
387 // assume that each cell has the same number of faces
388 const unsigned int faces_per_cell = 2 * this->structdim;
389 return ArrayView<int>(cells.data() + index * faces_per_cell,
390 faces_per_cell);
391 }
392
393
394
399
400
401
402 inline std::size_t
407
408
409
410 template <class Archive>
411 void
413 const unsigned int /*version*/)
414 {
415 // serialize this
416 // structure by
417 // writing and
418 // reading the larger
419 // of the two values,
420 // in order to make
421 // sure we get all
422 // bits
423 if (sizeof(material_id) > sizeof(boundary_id))
424 ar &material_id;
425 else
426 ar &boundary_id;
427 }
428
429
430 inline void *&
431 TriaObjects::user_pointer(const unsigned int i)
432 {
436
437 AssertIndexRange(i, user_data.size());
438 return user_data[i].p;
439 }
440
441
442 inline const void *
443 TriaObjects::user_pointer(const unsigned int i) const
444 {
448
449 AssertIndexRange(i, user_data.size());
450 return user_data[i].p;
451 }
452
453
454 inline unsigned int &
455 TriaObjects::user_index(const unsigned int i)
456 {
460
461 AssertIndexRange(i, user_data.size());
462 return user_data[i].i;
463 }
464
465
466 inline void
467 TriaObjects::clear_user_data(const unsigned int i)
468 {
469 AssertIndexRange(i, user_data.size());
470 user_data[i].i = 0;
471 }
472
473
475 : structdim(numbers::invalid_unsigned_int)
476 , next_free_single(numbers::invalid_unsigned_int)
477 , next_free_pair(numbers::invalid_unsigned_int)
480 {}
481
482
483 inline TriaObjects::TriaObjects(const unsigned int structdim)
484 : structdim(structdim)
485 , next_free_single(numbers::invalid_unsigned_int)
486 , next_free_pair(numbers::invalid_unsigned_int)
487 , reverse_order_next_free_single(false)
488 , user_data_type(data_unknown)
489 {}
490
491
492 inline unsigned int
493 TriaObjects::user_index(const unsigned int i) const
494 {
498
499 AssertIndexRange(i, user_data.size());
500 return user_data[i].i;
501 }
502
503
504 inline void
506 {
508 for (auto &data : user_data)
509 data.p = nullptr;
510 }
511
512
513 inline void
515 {
516 user_flags.assign(user_flags.size(), false);
517 }
518
519
520 template <class Archive>
521 void
522 TriaObjects::UserData::serialize(Archive &ar, const unsigned int)
523 {
524 // serialize this as an integer
525 ar &i;
526 }
527
528
529
530 template <class Archive>
531 void
532 TriaObjects::serialize(Archive &ar, const unsigned int)
533 {
534 ar &structdim;
535 ar &cells &children;
537 ar &used;
538 ar &user_flags;
540 ar &manifold_id;
543 }
544
545
546 //----------------------------------------------------------------------//
547
548 template <int structdim_, int dim, int spacedim>
552 {
553 // TODO: Think of a way to ensure that we are using the correct
554 // triangulation, i.e. the one containing *this.
555
556 AssertDimension(structdim_, this->structdim);
557
558 int pos = next_free_single, last = used.size() - 1;
560 {
561 // first sweep forward, only use really single slots, do not use
562 // pair slots
563 for (; pos < last; ++pos)
564 if (!used[pos])
565 if (used[++pos])
566 {
567 // this was a single slot
568 pos -= 1;
569 break;
570 }
571 if (pos >= last)
572 {
574 next_free_single = used.size() - 1;
575 pos = used.size() - 1;
576 }
577 else
578 next_free_single = pos + 1;
579 }
580
582 {
583 // second sweep, use all slots, even
584 // in pairs
585 for (; pos >= 0; --pos)
586 if (!used[pos])
587 break;
588 if (pos > 0)
589 next_free_single = pos - 1;
590 else
591 // no valid single object anymore
592 return ::TriaRawIterator<
594 }
595
596 return ::TriaRawIterator<
598 }
599
600
601
602 template <int structdim_, int dim, int spacedim>
605 {
606 // TODO: Think of a way to ensure that we are using the correct
607 // triangulation, i.e. the one containing *this.
608
609 AssertDimension(structdim_, this->structdim);
610
611 int pos = next_free_pair, last = used.size() - 1;
612 for (; pos < last; ++pos)
613 if (!used[pos])
614 if (!used[++pos])
615 {
616 // this was a pair slot
617 pos -= 1;
618 break;
619 }
620 if (pos >= last)
621 // no free slot
622 return ::TriaRawIterator<
624 else
625 next_free_pair = pos + 2;
626
627 return ::TriaRawIterator<
629 }
630 } // namespace TriangulationImplementation
631} // namespace internal
632
633
634
636
637#endif
typename IteratorSelector::raw_hex_iterator raw_hex_iterator
Definition tria.h:4098
std::vector< types::manifold_id > manifold_id
ArrayView< int > get_bounding_object_indices(const unsigned int index)
void serialize(Archive &ar, const unsigned int version)
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)
std::vector< BoundaryOrMaterialId > boundary_or_material_id
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:177
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
unsigned int level
Definition grid_out.cc:4626
#define DeclException0(Exception0)
Definition exceptions.h:471
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
const types::material_id invalid_material_id
Definition types.h:277
void serialize(Archive &ar, const unsigned int version)