Reference documentation for deal.II version 9.5.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// Copyright (C) 2006 - 2023 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_tria_objects_h
17#define dealii_tria_objects_h
18
19#include <deal.II/base/config.h>
20
24
25#include <vector>
26
28
29// Forward declarations
30#ifndef DOXYGEN
31template <int dim, int spacedim>
33class Triangulation;
34template <class Accessor>
35class TriaRawIterator;
36template <int, int, int>
37class TriaAccessor;
38#endif
39
40namespace internal
41{
42 namespace TriangulationImplementation
43 {
54 {
55 public:
60
64 TriaObjects(const unsigned int structdim);
65
66 unsigned int structdim;
67
72 std::vector<int> cells;
73
77 unsigned int
78 n_objects() const;
79
88 get_bounding_object_indices(const unsigned int index);
89
101 std::vector<int> children;
102
108 std::vector<std::uint8_t> refinement_cases;
109
118 std::vector<bool> used;
119
129 std::vector<bool> user_flags;
130
131
137 {
138 union
139 {
142 };
143
144
149
153 static std::size_t
155
161 template <class Archive>
162 void
163 serialize(Archive &ar, const unsigned int version);
164 };
165
180 std::vector<BoundaryOrMaterialId> boundary_or_material_id;
181
186 std::vector<types::manifold_id> manifold_id;
187
199 template <int structdim, int dim, int spacedim>
202
214 template <int structdim, int dim, int spacedim>
217
222 template <int dim, int spacedim>
225 const unsigned int level);
226
230 void *&
231 user_pointer(const unsigned int i);
232
236 const void *
237 user_pointer(const unsigned int i) const;
238
242 unsigned int &
243 user_index(const unsigned int i);
244
248 unsigned int
249 user_index(const unsigned int i) const;
250
254 void
255 clear_user_data(const unsigned int i);
256
261 void
263
267 void
269
274 std::size_t
275 memory_consumption() const;
276
282 template <class Archive>
283 void
284 serialize(Archive &ar, const unsigned int version);
285
294
298 unsigned int next_free_single;
299
303 unsigned int next_free_pair;
304
309
313 struct UserData
314 {
315 union
316 {
319 void *p;
322 unsigned int i;
323 };
324
329 {
330 p = nullptr;
331 }
332
338 template <class Archive>
339 void
340 serialize(Archive &ar, const unsigned int version);
341 };
342
347 {
354 };
355
356
361 std::vector<UserData> user_data;
362
369 };
370
371
372 //----------------------------------------------------------------------//
373
374 inline unsigned int
376 {
377 // ensure that sizes are consistent, and then return one that
378 // corresponds to the number of objects
379 AssertDimension(cells.size(), manifold_id.size() * 2 * this->structdim);
380 return manifold_id.size();
381 }
382
383
384
385 inline ArrayView<int>
387 {
388 // assume that each cell has the same number of faces
389 const unsigned int faces_per_cell = 2 * this->structdim;
390 return ArrayView<int>(cells.data() + index * faces_per_cell,
391 faces_per_cell);
392 }
393
394
395
397 {
399 }
400
401
402
403 inline std::size_t
405 {
406 return sizeof(BoundaryOrMaterialId);
407 }
408
409
410
411 template <class Archive>
412 void
414 const unsigned int /*version*/)
415 {
416 // serialize this
417 // structure by
418 // writing and
419 // reading the larger
420 // of the two values,
421 // in order to make
422 // sure we get all
423 // bits
424 if (sizeof(material_id) > sizeof(boundary_id))
425 ar &material_id;
426 else
427 ar &boundary_id;
428 }
429
430
431 inline void *&
432 TriaObjects::user_pointer(const unsigned int i)
433 {
437
438 AssertIndexRange(i, user_data.size());
439 return user_data[i].p;
440 }
441
442
443 inline const void *
444 TriaObjects::user_pointer(const unsigned int i) const
445 {
449
450 AssertIndexRange(i, user_data.size());
451 return user_data[i].p;
452 }
453
454
455 inline unsigned int &
456 TriaObjects::user_index(const unsigned int i)
457 {
461
462 AssertIndexRange(i, user_data.size());
463 return user_data[i].i;
464 }
465
466
467 inline void
468 TriaObjects::clear_user_data(const unsigned int i)
469 {
470 AssertIndexRange(i, user_data.size());
471 user_data[i].i = 0;
472 }
473
474
476 : structdim(numbers::invalid_unsigned_int)
477 , next_free_single(numbers::invalid_unsigned_int)
478 , next_free_pair(numbers::invalid_unsigned_int)
481 {}
482
483
484 inline TriaObjects::TriaObjects(const unsigned int structdim)
485 : structdim(structdim)
486 , next_free_single(numbers::invalid_unsigned_int)
487 , next_free_pair(numbers::invalid_unsigned_int)
488 , reverse_order_next_free_single(false)
489 , user_data_type(data_unknown)
490 {}
491
492
493 inline unsigned int
494 TriaObjects::user_index(const unsigned int i) const
495 {
499
500 AssertIndexRange(i, user_data.size());
501 return user_data[i].i;
502 }
503
504
505 inline void
507 {
509 for (auto &data : user_data)
510 data.p = nullptr;
511 }
512
513
514 inline void
516 {
517 user_flags.assign(user_flags.size(), false);
518 }
519
520
521 template <class Archive>
522 void
523 TriaObjects::UserData::serialize(Archive &ar, const unsigned int)
524 {
525 // serialize this as an integer
526 ar &i;
527 }
528
529
530
531 template <class Archive>
532 void
533 TriaObjects::serialize(Archive &ar, const unsigned int)
534 {
535 ar &structdim;
536 ar &cells &children;
537 ar & refinement_cases;
538 ar & used;
539 ar & user_flags;
541 ar & manifold_id;
544 }
545
546
547 //----------------------------------------------------------------------//
548
549 template <int structdim_, int dim, int spacedim>
553 {
554 // TODO: Think of a way to ensure that we are using the correct
555 // triangulation, i.e. the one containing *this.
556
557 AssertDimension(structdim_, this->structdim);
558
559 int pos = next_free_single, last = used.size() - 1;
561 {
562 // first sweep forward, only use really single slots, do not use
563 // pair slots
564 for (; pos < last; ++pos)
565 if (!used[pos])
566 if (used[++pos])
567 {
568 // this was a single slot
569 pos -= 1;
570 break;
571 }
572 if (pos >= last)
573 {
575 next_free_single = used.size() - 1;
576 pos = used.size() - 1;
577 }
578 else
579 next_free_single = pos + 1;
580 }
581
583 {
584 // second sweep, use all slots, even
585 // in pairs
586 for (; pos >= 0; --pos)
587 if (!used[pos])
588 break;
589 if (pos > 0)
590 next_free_single = pos - 1;
591 else
592 // no valid single object anymore
593 return ::TriaRawIterator<
595 }
596
597 return ::TriaRawIterator<
599 }
600
601
602
603 template <int structdim_, int dim, int spacedim>
606 {
607 // TODO: Think of a way to ensure that we are using the correct
608 // triangulation, i.e. the one containing *this.
609
610 AssertDimension(structdim_, this->structdim);
611
612 int pos = next_free_pair, last = used.size() - 1;
613 for (; pos < last; ++pos)
614 if (!used[pos])
615 if (!used[++pos])
616 {
617 // this was a pair slot
618 pos -= 1;
619 break;
620 }
621 if (pos >= last)
622 // no free slot
623 return ::TriaRawIterator<
625 else
626 next_free_pair = pos + 2;
627
628 return ::TriaRawIterator<
630 }
631 } // namespace TriangulationImplementation
632} // namespace internal
633
634
635
637
638#endif
typename IteratorSelector::raw_hex_iterator raw_hex_iterator
Definition tria.h:3828
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:472
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:160
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
unsigned int level
Definition grid_out.cc:4618
#define DeclException0(Exception0)
Definition exceptions.h:465
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
const types::material_id invalid_material_id
Definition types.h:250
void serialize(Archive &ar, const unsigned int version)
const ::Triangulation< dim, spacedim > & tria