Reference documentation for deal.II version GIT 7bd1c95dbb 2022-06-29 20:50: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\}}\)
tria_objects.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 2021 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
31 template <int dim, int spacedim>
32 class Triangulation;
33 template <class Accessor>
34 class TriaRawIterator;
35 template <int, int, int>
36 class TriaAccessor;
37 #endif
38 
39 namespace internal
40 {
41  namespace TriangulationImplementation
42  {
53  {
54  public:
58  TriaObjects();
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
261  clear_user_data();
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 
346  {
352  data_index
353  };
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 
396  {
398  }
399 
400 
401 
402  inline std::size_t
404  {
405  return sizeof(BoundaryOrMaterialId);
406  }
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 
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;
536  ar & refinement_cases;
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
std::vector< types::manifold_id > manifold_id
Definition: tria_objects.h:185
::TriaRawIterator<::TriaAccessor< structdim, dim, spacedim > > next_free_pair_object(const Triangulation< dim, spacedim > &tria)
ArrayView< int > get_bounding_object_indices(const unsigned int index)
Definition: tria_objects.h:385
::TriaRawIterator<::TriaAccessor< structdim, dim, spacedim > > next_free_single_object(const Triangulation< dim, spacedim > &tria)
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:532
unsigned int & user_index(const unsigned int i)
Definition: tria_objects.h:455
std::vector< BoundaryOrMaterialId > boundary_or_material_id
Definition: tria_objects.h:179
Triangulation< dim, spacedim >::raw_hex_iterator next_free_hex(const Triangulation< dim, spacedim > &tria, const unsigned int level)
#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:4607
#define DeclException0(Exception0)
Definition: exceptions.h:464
#define Assert(cond, exc)
Definition: exceptions.h:1473
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1667
#define AssertIndexRange(index, range)
Definition: exceptions.h:1732
const types::material_id invalid_material_id
Definition: types.h:233
static const unsigned int invalid_unsigned_int
Definition: types.h:201
unsigned int material_id
Definition: types.h:152
unsigned int boundary_id
Definition: types.h:129
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:522
const ::Triangulation< dim, spacedim > & tria