Reference documentation for deal.II version Git 1f3f4df3cd 2020-02-17 16:54:31 -0500
\(\newcommand{\vcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\vcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
tria.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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_h
17 #define dealii_tria_h
18 
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/geometry_info.h>
23 #include <deal.II/base/iterator_range.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/smartpointer.h>
26 #include <deal.II/base/subscriptor.h>
27 
28 #include <deal.II/grid/tria_description.h>
29 #include <deal.II/grid/tria_iterator_selector.h>
30 
31 #include <boost/serialization/map.hpp>
32 #include <boost/serialization/split_member.hpp>
33 #include <boost/serialization/unique_ptr.hpp>
34 #include <boost/serialization/vector.hpp>
35 #include <boost/signals2.hpp>
36 
37 #include <bitset>
38 #include <functional>
39 #include <list>
40 #include <map>
41 #include <memory>
42 #include <numeric>
43 #include <vector>
44 
45 
46 DEAL_II_NAMESPACE_OPEN
47 
48 // Forward declarations
49 #ifndef DOXYGEN
50 template <int dim, int spacedim>
51 class Manifold;
52 
53 template <int dim>
54 struct CellData;
55 
56 struct SubCellData;
57 
59 {
60  template <int, int>
61  struct Description;
62 }
63 
64 namespace GridTools
65 {
66  template <typename CellIterator>
67  struct PeriodicFacePair;
68 }
69 
70 template <int, int, int>
71 class TriaAccessor;
72 template <int spacedim>
73 class TriaAccessor<0, 1, spacedim>;
74 template <int, int, int>
75 class TriaAccessorBase;
76 
77 namespace internal
78 {
79  namespace TriangulationImplementation
80  {
81  template <int dim>
82  class TriaLevel;
83  template <int dim>
84  class TriaFaces;
85 
86  template <typename>
87  class TriaObjects;
88 
94  struct Implementation;
95  } // namespace TriangulationImplementation
96 
97  namespace TriaAccessorImplementation
98  {
99  struct Implementation;
100  }
101 } // namespace internal
102 
103 namespace hp
104 {
105  template <int dim, int spacedim>
106  class DoFHandler;
107 }
108 #endif
109 
110 
111 /*------------------------------------------------------------------------*/
112 
113 
114 namespace internal
115 {
120  namespace TriangulationImplementation
121  {
135  template <int dim>
136  struct NumberCache
137  {};
138 
152  template <>
153  struct NumberCache<1>
154  {
158  unsigned int n_levels;
159 
163  unsigned int n_lines;
164 
168  std::vector<unsigned int> n_lines_level;
169 
173  unsigned int n_active_lines;
174 
178  std::vector<unsigned int> n_active_lines_level;
179 
183  NumberCache();
184 
189  std::size_t
190  memory_consumption() const;
191 
196  template <class Archive>
197  void
198  serialize(Archive &ar, const unsigned int version);
199  };
200 
201 
216  template <>
217  struct NumberCache<2> : public NumberCache<1>
218  {
222  unsigned int n_quads;
223 
227  std::vector<unsigned int> n_quads_level;
228 
232  unsigned int n_active_quads;
233 
237  std::vector<unsigned int> n_active_quads_level;
238 
242  NumberCache();
243 
248  std::size_t
249  memory_consumption() const;
250 
255  template <class Archive>
256  void
257  serialize(Archive &ar, const unsigned int version);
258  };
259 
260 
276  template <>
277  struct NumberCache<3> : public NumberCache<2>
278  {
282  unsigned int n_hexes;
283 
287  std::vector<unsigned int> n_hexes_level;
288 
292  unsigned int n_active_hexes;
293 
297  std::vector<unsigned int> n_active_hexes_level;
298 
302  NumberCache();
303 
308  std::size_t
309  memory_consumption() const;
310 
315  template <class Archive>
316  void
317  serialize(Archive &ar, const unsigned int version);
318  };
319  } // namespace TriangulationImplementation
320 } // namespace internal
321 
322 
323 /*------------------------------------------------------------------------*/
324 
325 
1108 template <int dim, int spacedim = dim>
1110 {
1111 private:
1116  using IteratorSelector =
1117  ::internal::TriangulationImplementation::Iterators<dim, spacedim>;
1118 
1119 public:
1125  {
1130  none = 0x0,
1174  limit_level_difference_at_vertices = 0x1,
1195  eliminate_unrefined_islands = 0x2,
1211  patch_level_1 = 0x4,
1235  coarsest_level_1 = 0x8,
1260  allow_anisotropic_smoothing = 0x10,
1293  eliminate_refined_inner_islands = 0x100,
1298  eliminate_refined_boundary_islands = 0x200,
1304  do_not_produce_unrefined_islands = 0x400,
1305 
1310  smoothing_on_refinement =
1311  (limit_level_difference_at_vertices | eliminate_unrefined_islands),
1316  smoothing_on_coarsening =
1317  (eliminate_refined_inner_islands | eliminate_refined_boundary_islands |
1318  do_not_produce_unrefined_islands),
1319 
1325  maximum_smoothing = 0xffff ^ allow_anisotropic_smoothing
1326  };
1327 
1344 
1362 
1376  using face_iterator = TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1377 
1389  using active_face_iterator =
1390  TriaActiveIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1391 
1401 
1414  using active_vertex_iterator =
1416 
1424  using line_iterator = typename IteratorSelector::line_iterator;
1425 
1439  using active_line_iterator = typename IteratorSelector::active_line_iterator;
1440 
1448  using quad_iterator = typename IteratorSelector::quad_iterator;
1449 
1463  using active_quad_iterator = typename IteratorSelector::active_quad_iterator;
1464 
1472  using hex_iterator = typename IteratorSelector::hex_iterator;
1473 
1483  using active_hex_iterator = typename IteratorSelector::active_hex_iterator;
1484 
1504  {
1511  virtual ~DistortedCellList() noexcept override = default;
1512 
1517  std::list<typename Triangulation<dim, spacedim>::cell_iterator>
1519  };
1520 
1524  static const unsigned int dimension = dim;
1525 
1529  static const unsigned int space_dimension = spacedim;
1530 
1545  Triangulation(const MeshSmoothing smooth_grid = none,
1546  const bool check_for_distorted_cells = false);
1547 
1563  Triangulation(const Triangulation<dim, spacedim> &) = delete;
1564 
1572 
1576  Triangulation &
1577  operator=(Triangulation<dim, spacedim> &&tria) noexcept;
1578 
1582  virtual ~Triangulation() override;
1583 
1590  virtual void
1591  clear();
1592 
1598  virtual void
1599  set_mesh_smoothing(const MeshSmoothing mesh_smoothing);
1600 
1604  virtual const MeshSmoothing &
1605  get_mesh_smoothing() const;
1606 
1629  void
1630  set_manifold(const types::manifold_id number,
1631  const Manifold<dim, spacedim> &manifold_object);
1632 
1633 
1648  DEAL_II_DEPRECATED
1649  void
1650  set_manifold(const types::manifold_id number);
1651 
1664  void
1665  reset_manifold(const types::manifold_id manifold_number);
1666 
1678  void
1679  reset_all_manifolds();
1680 
1689  void
1690  set_all_manifold_ids(const types::manifold_id number);
1691 
1700  void
1701  set_all_manifold_ids_on_boundary(const types::manifold_id number);
1702 
1712  void
1713  set_all_manifold_ids_on_boundary(const types::boundary_id b_id,
1714  const types::manifold_id number);
1715 
1725  const Manifold<dim, spacedim> &
1726  get_manifold(const types::manifold_id number) const;
1727 
1739  std::vector<types::boundary_id>
1740  get_boundary_ids() const;
1741 
1753  std::vector<types::manifold_id>
1754  get_manifold_ids() const;
1755 
1782  virtual void
1783  copy_triangulation(const Triangulation<dim, spacedim> &other_tria);
1784 
1830  virtual void
1831  create_triangulation(const std::vector<Point<spacedim>> &vertices,
1832  const std::vector<CellData<dim>> & cells,
1833  const SubCellData & subcelldata);
1834 
1844  virtual void
1845  create_triangulation(
1847  &construction_data);
1848 
1857  virtual void
1858  create_triangulation_compatibility(
1859  const std::vector<Point<spacedim>> &vertices,
1860  const std::vector<CellData<dim>> & cells,
1861  const SubCellData & subcelldata);
1862 
1869  void
1870  flip_all_direction_flags();
1871 
1883  void
1884  set_all_refine_flags();
1885 
1900  void
1901  refine_global(const unsigned int times = 1);
1902 
1934  virtual void
1935  execute_coarsening_and_refinement();
1936 
1966  virtual bool
1967  prepare_coarsening_and_refinement();
1968 
1969  /*
1970  * @}
1971  */
1972 
1987  {
2004  CELL_INVALID
2005  };
2006 
2012  template <typename T>
2014  {
2015  using result_type = T;
2016 
2017  template <typename InputIterator>
2018  T
2019  operator()(InputIterator first, InputIterator last) const
2020  {
2021  return std::accumulate(first, last, T());
2022  }
2023  };
2024 
2034  struct Signals
2035  {
2043  boost::signals2::signal<void()> create;
2044 
2052  boost::signals2::signal<void()> pre_refinement;
2053 
2059  boost::signals2::signal<void()> post_refinement;
2060 
2067  boost::signals2::signal<void()> pre_partition;
2068 
2076  boost::signals2::signal<void()> mesh_movement;
2077 
2085  boost::signals2::signal<void(
2086  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2088 
2095  boost::signals2::signal<void(
2096  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2098 
2105  boost::signals2::signal<void(
2106  const Triangulation<dim, spacedim> &destination_tria)>
2108 
2122  boost::signals2::signal<void()> clear;
2123 
2133  boost::signals2::signal<void()> any_change;
2134 
2158  boost::signals2::signal<unsigned int(const cell_iterator &,
2159  const CellStatus),
2162 
2174  boost::signals2::signal<void()> pre_distributed_refinement;
2175 
2184  boost::signals2::signal<void()> post_distributed_refinement;
2185 
2196  boost::signals2::signal<void()> pre_distributed_repartition;
2197 
2203  boost::signals2::signal<void()> post_distributed_repartition;
2204 
2211  boost::signals2::signal<void()> pre_distributed_save;
2212 
2218  boost::signals2::signal<void()> post_distributed_save;
2219 
2226  boost::signals2::signal<void()> pre_distributed_load;
2227 
2233  boost::signals2::signal<void()> post_distributed_load;
2234  };
2235 
2239  mutable Signals signals;
2240 
2241  /*
2242  * @}
2243  */
2244 
2254  void
2255  save_refine_flags(std::ostream &out) const;
2256 
2260  void
2261  save_refine_flags(std::vector<bool> &v) const;
2262 
2266  void
2267  load_refine_flags(std::istream &in);
2268 
2272  void
2273  load_refine_flags(const std::vector<bool> &v);
2274 
2278  void
2279  save_coarsen_flags(std::ostream &out) const;
2280 
2284  void
2285  save_coarsen_flags(std::vector<bool> &v) const;
2286 
2290  void
2291  load_coarsen_flags(std::istream &out);
2292 
2296  void
2297  load_coarsen_flags(const std::vector<bool> &v);
2298 
2303  bool
2304  get_anisotropic_refinement_flag() const;
2305 
2306  /*
2307  * @}
2308  */
2309 
2319  void
2320  clear_user_flags();
2321 
2327  void
2328  save_user_flags(std::ostream &out) const;
2329 
2335  void
2336  save_user_flags(std::vector<bool> &v) const;
2337 
2342  void
2343  load_user_flags(std::istream &in);
2344 
2349  void
2350  load_user_flags(const std::vector<bool> &v);
2351 
2356  void
2357  clear_user_flags_line();
2358 
2363  void
2364  save_user_flags_line(std::ostream &out) const;
2365 
2371  void
2372  save_user_flags_line(std::vector<bool> &v) const;
2373 
2378  void
2379  load_user_flags_line(std::istream &in);
2380 
2385  void
2386  load_user_flags_line(const std::vector<bool> &v);
2387 
2392  void
2393  clear_user_flags_quad();
2394 
2399  void
2400  save_user_flags_quad(std::ostream &out) const;
2401 
2407  void
2408  save_user_flags_quad(std::vector<bool> &v) const;
2409 
2414  void
2415  load_user_flags_quad(std::istream &in);
2416 
2421  void
2422  load_user_flags_quad(const std::vector<bool> &v);
2423 
2424 
2429  void
2430  clear_user_flags_hex();
2431 
2436  void
2437  save_user_flags_hex(std::ostream &out) const;
2438 
2444  void
2445  save_user_flags_hex(std::vector<bool> &v) const;
2446 
2451  void
2452  load_user_flags_hex(std::istream &in);
2453 
2458  void
2459  load_user_flags_hex(const std::vector<bool> &v);
2460 
2466  void
2467  clear_user_data();
2468 
2474  void
2475  save_user_indices(std::vector<unsigned int> &v) const;
2476 
2481  void
2482  load_user_indices(const std::vector<unsigned int> &v);
2483 
2489  void
2490  save_user_pointers(std::vector<void *> &v) const;
2491 
2496  void
2497  load_user_pointers(const std::vector<void *> &v);
2498 
2504  void
2505  save_user_indices_line(std::vector<unsigned int> &v) const;
2506 
2511  void
2512  load_user_indices_line(const std::vector<unsigned int> &v);
2513 
2519  void
2520  save_user_indices_quad(std::vector<unsigned int> &v) const;
2521 
2526  void
2527  load_user_indices_quad(const std::vector<unsigned int> &v);
2528 
2534  void
2535  save_user_indices_hex(std::vector<unsigned int> &v) const;
2536 
2541  void
2542  load_user_indices_hex(const std::vector<unsigned int> &v);
2548  void
2549  save_user_pointers_line(std::vector<void *> &v) const;
2550 
2555  void
2556  load_user_pointers_line(const std::vector<void *> &v);
2557 
2563  void
2564  save_user_pointers_quad(std::vector<void *> &v) const;
2565 
2570  void
2571  load_user_pointers_quad(const std::vector<void *> &v);
2572 
2578  void
2579  save_user_pointers_hex(std::vector<void *> &v) const;
2580 
2585  void
2586  load_user_pointers_hex(const std::vector<void *> &v);
2587 
2588  /*
2589  * @}
2590  */
2591 
2615  begin(const unsigned int level = 0) const;
2616 
2648  begin_active(const unsigned int level = 0) const;
2649 
2655  end() const;
2656 
2676  end(const unsigned int level) const;
2677 
2698  end_active(const unsigned int level) const;
2699 
2700 
2705  last() const;
2706 
2711  last_active() const;
2712 
2728  cell_iterators() const;
2729 
2766  active_cell_iterators() const;
2767 
2784  cell_iterators_on_level(const unsigned int level) const;
2785 
2802  active_cell_iterators_on_level(const unsigned int level) const;
2803 
2804  /*
2805  * @}
2806  */
2807 
2808  /*-------------------------------------------------------------------------*/
2809 
2819  begin_face() const;
2820 
2825  begin_active_face() const;
2826 
2832  end_face() const;
2833 
2853  active_face_iterators() const;
2854 
2855  /*
2856  * @}
2857  */
2858 
2859  /*-------------------------------------------------------------------------*/
2860 
2871  begin_vertex() const;
2872 
2879  begin_active_vertex() const;
2880 
2887  end_vertex() const;
2888 
2889  /*
2890  * @}
2891  */
2892 
2910  unsigned int
2911  n_lines() const;
2912 
2916  unsigned int
2917  n_lines(const unsigned int level) const;
2918 
2922  unsigned int
2923  n_active_lines() const;
2924 
2928  unsigned int
2929  n_active_lines(const unsigned int level) const;
2930 
2934  unsigned int
2935  n_quads() const;
2936 
2940  unsigned int
2941  n_quads(const unsigned int level) const;
2942 
2946  unsigned int
2947  n_active_quads() const;
2948 
2952  unsigned int
2953  n_active_quads(const unsigned int level) const;
2954 
2958  unsigned int
2959  n_hexs() const;
2960 
2965  unsigned int
2966  n_hexs(const unsigned int level) const;
2967 
2971  unsigned int
2972  n_active_hexs() const;
2973 
2978  unsigned int
2979  n_active_hexs(const unsigned int level) const;
2980 
2985  unsigned int
2986  n_cells() const;
2987 
2992  unsigned int
2993  n_cells(const unsigned int level) const;
2994 
2999  unsigned int
3000  n_active_cells() const;
3001 
3009  virtual types::global_dof_index
3010  n_global_active_cells() const;
3011 
3012 
3017  unsigned int
3018  n_active_cells(const unsigned int level) const;
3019 
3025  unsigned int
3026  n_faces() const;
3027 
3033  unsigned int
3034  n_active_faces() const;
3035 
3053  unsigned int
3054  n_levels() const;
3055 
3062  virtual unsigned int
3063  n_global_levels() const;
3064 
3074  virtual bool
3075  has_hanging_nodes() const;
3076 
3084  unsigned int
3085  n_vertices() const;
3086 
3095  const std::vector<Point<spacedim>> &
3096  get_vertices() const;
3097 
3102  unsigned int
3103  n_used_vertices() const;
3104 
3108  bool
3109  vertex_used(const unsigned int index) const;
3110 
3115  const std::vector<bool> &
3116  get_used_vertices() const;
3117 
3129  unsigned int
3130  max_adjacent_cells() const;
3131 
3138  virtual types::subdomain_id
3139  locally_owned_subdomain() const;
3140 
3151  get_triangulation();
3152 
3158  get_triangulation() const;
3159 
3160 
3161  /*
3162  * @}
3163  */
3164 
3179  unsigned int
3180  n_raw_lines() const;
3181 
3191  unsigned int
3192  n_raw_lines(const unsigned int level) const;
3193 
3203  unsigned int
3204  n_raw_quads() const;
3205 
3215  unsigned int
3216  n_raw_quads(const unsigned int level) const;
3217 
3227  unsigned int
3228  n_raw_hexs(const unsigned int level) const;
3229 
3239  unsigned int
3240  n_raw_cells(const unsigned int level) const;
3241 
3253  unsigned int
3254  n_raw_faces() const;
3255 
3256  /*
3257  * @}
3258  */
3259 
3268  virtual std::size_t
3269  memory_consumption() const;
3270 
3279  template <class Archive>
3280  void
3281  save(Archive &ar, const unsigned int version) const;
3282 
3298  template <class Archive>
3299  void
3300  load(Archive &ar, const unsigned int version);
3301 
3302 
3318  virtual void
3319  add_periodicity(
3320  const std::vector<GridTools::PeriodicFacePair<cell_iterator>> &);
3321 
3325  const std::map<
3326  std::pair<cell_iterator, unsigned int>,
3327  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>> &
3328  get_periodic_face_map() const;
3329 
3341  virtual unsigned int
3342  coarse_cell_id_to_coarse_cell_index(
3343  const types::coarse_cell_id coarse_cell_id) const;
3344 
3345 
3356  virtual types::coarse_cell_id
3357  coarse_cell_index_to_coarse_cell_id(
3358  const unsigned int coarse_cell_index) const;
3359 
3360 
3361  BOOST_SERIALIZATION_SPLIT_MEMBER()
3362 
3363 
3373  DeclException2(ExcInvalidLevel,
3374  int,
3375  int,
3376  << "You are requesting information from refinement level "
3377  << arg1
3378  << " of a triangulation, but this triangulation only has "
3379  << arg2 << " refinement levels. The given level " << arg1
3380  << " must be *less* than " << arg2 << ".");
3388  ExcTriangulationNotEmpty,
3389  int,
3390  int,
3391  << "You are trying to perform an operation on a triangulation "
3392  << "that is only allowed if the triangulation is currently empty. "
3393  << "However, it currently stores " << arg1 << " vertices and has "
3394  << "cells on " << arg2 << " levels.");
3400  DeclException0(ExcGridReadError);
3411  DeclException1(ExcEmptyLevel,
3412  int,
3413  << "You tried to do something on level " << arg1
3414  << ", but this level is empty.");
3420  DeclException0(ExcNonOrientableTriangulation);
3421 
3429  DeclException1(ExcBoundaryIdNotFound,
3430  types::boundary_id,
3431  << "The given boundary_id " << arg1
3432  << " is not defined in this Triangulation!");
3433 
3440  ExcInconsistentCoarseningFlags,
3441  "A cell is flagged for coarsening, but either not all of its siblings "
3442  "are active or flagged for coarsening as well. Please clean up all "
3443  "coarsen flags on your triangulation via "
3444  "Triangulation::prepare_coarsening_and_refinement() beforehand!");
3445 
3446  /*
3447  * @}
3448  */
3449 
3450 protected:
3455  MeshSmoothing smooth_grid;
3456 
3470  static void
3471  write_bool_vector(const unsigned int magic_number1,
3472  const std::vector<bool> &v,
3473  const unsigned int magic_number2,
3474  std::ostream & out);
3475 
3480  static void
3481  read_bool_vector(const unsigned int magic_number1,
3482  std::vector<bool> &v,
3483  const unsigned int magic_number2,
3484  std::istream & in);
3485 
3490  void
3491  update_periodic_face_map();
3492 
3493 
3494 private:
3501  std::vector<GridTools::PeriodicFacePair<cell_iterator>>
3502  periodic_face_pairs_level_0;
3503 
3508  std::map<std::pair<cell_iterator, unsigned int>,
3509  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>>
3510  periodic_face_map;
3511 
3526  using raw_face_iterator =
3527  TriaRawIterator<TriaAccessor<dim - 1, dim, spacedim>>;
3528  using raw_vertex_iterator =
3529  TriaRawIterator<::TriaAccessor<0, dim, spacedim>>;
3530  using raw_line_iterator = typename IteratorSelector::raw_line_iterator;
3531  using raw_quad_iterator = typename IteratorSelector::raw_quad_iterator;
3532  using raw_hex_iterator = typename IteratorSelector::raw_hex_iterator;
3533 
3539  begin_raw(const unsigned int level = 0) const;
3540 
3546  end_raw(const unsigned int level) const;
3547 
3548  /*
3549  * @}
3550  */
3551 
3563  raw_line_iterator
3564  begin_raw_line(const unsigned int level = 0) const;
3565 
3584  begin_line(const unsigned int level = 0) const;
3585 
3604  begin_active_line(const unsigned int level = 0) const;
3605 
3611  end_line() const;
3612 
3613  /*
3614  * @}
3615  */
3616 
3641  raw_quad_iterator
3642  begin_raw_quad(const unsigned int level = 0) const;
3643 
3662  begin_quad(const unsigned int level = 0) const;
3663 
3682  begin_active_quad(const unsigned int level = 0) const;
3683 
3689  end_quad() const;
3690 
3691  /*
3692  * @}
3693  */
3694 
3718  raw_hex_iterator
3719  begin_raw_hex(const unsigned int level = 0) const;
3720 
3738  hex_iterator
3739  begin_hex(const unsigned int level = 0) const;
3740 
3759  begin_active_hex(const unsigned int level = 0) const;
3760 
3765  hex_iterator
3766  end_hex() const;
3767 
3768  /*
3769  * @}
3770  */
3771 
3772 
3786  void
3787  clear_despite_subscriptions();
3788 
3795  void
3796  reset_active_cell_indices();
3797 
3811  DistortedCellList
3812  execute_refinement();
3813 
3820  void
3821  execute_coarsening();
3822 
3827  void
3828  fix_coarsen_flags();
3829 
3834  std::vector<std::unique_ptr<
3835  ::internal::TriangulationImplementation::TriaLevel<dim>>>
3836  levels;
3837 
3843  std::unique_ptr<::internal::TriangulationImplementation::TriaFaces<dim>>
3844  faces;
3845 
3846 
3850  std::vector<Point<spacedim>> vertices;
3851 
3855  std::vector<bool> vertices_used;
3856 
3861  std::map<types::manifold_id, std::unique_ptr<const Manifold<dim, spacedim>>>
3862  manifold;
3863 
3867  bool anisotropic_refinement;
3868 
3869 
3874  const bool check_for_distorted_cells;
3875 
3885  ::internal::TriangulationImplementation::NumberCache<dim> number_cache;
3886 
3901  std::unique_ptr<std::map<unsigned int, types::boundary_id>>
3902  vertex_to_boundary_id_map_1d;
3903 
3904 
3924  std::unique_ptr<std::map<unsigned int, types::manifold_id>>
3925  vertex_to_manifold_id_map_1d;
3926 
3927  // make a couple of classes friends
3928  template <int, int, int>
3929  friend class TriaAccessorBase;
3930  template <int, int, int>
3931  friend class TriaAccessor;
3932  friend class TriaAccessor<0, 1, spacedim>;
3933 
3934  friend class CellAccessor<dim, spacedim>;
3935 
3936  friend struct ::internal::TriaAccessorImplementation::Implementation;
3937 
3938  friend class hp::DoFHandler<dim, spacedim>;
3939 
3940  friend struct ::internal::TriangulationImplementation::Implementation;
3941 
3942  template <typename>
3943  friend class ::internal::TriangulationImplementation::TriaObjects;
3944 
3945  // explicitly check for sensible template arguments, but not on windows
3946  // because MSVC creates bogus warnings during normal compilation
3947 #ifndef DEAL_II_MSVC
3948  static_assert(dim <= spacedim,
3949  "The dimension <dim> of a Triangulation must be less than or "
3950  "equal to the space dimension <spacedim> in which it lives.");
3951 #endif
3952 };
3953 
3954 
3955 #ifndef DOXYGEN
3956 
3957 
3958 
3959 namespace internal
3960 {
3961  namespace TriangulationImplementation
3962  {
3963  template <class Archive>
3964  void
3965  NumberCache<1>::serialize(Archive &ar, const unsigned int)
3966  {
3967  ar &n_levels;
3968  ar &n_lines &n_lines_level;
3969  ar &n_active_lines &n_active_lines_level;
3970  }
3971 
3972 
3973  template <class Archive>
3974  void
3975  NumberCache<2>::serialize(Archive &ar, const unsigned int version)
3976  {
3977  this->NumberCache<1>::serialize(ar, version);
3978 
3979  ar &n_quads &n_quads_level;
3980  ar &n_active_quads &n_active_quads_level;
3981  }
3982 
3983 
3984  template <class Archive>
3985  void
3986  NumberCache<3>::serialize(Archive &ar, const unsigned int version)
3987  {
3988  this->NumberCache<2>::serialize(ar, version);
3989 
3990  ar &n_hexes &n_hexes_level;
3991  ar &n_active_hexes &n_active_hexes_level;
3992  }
3993 
3994  } // namespace TriangulationImplementation
3995 } // namespace internal
3996 
3997 
3998 template <int dim, int spacedim>
3999 inline bool
4000 Triangulation<dim, spacedim>::vertex_used(const unsigned int index) const
4001 {
4002  AssertIndexRange(index, vertices_used.size());
4003  return vertices_used[index];
4004 }
4005 
4006 
4007 
4008 template <int dim, int spacedim>
4009 inline unsigned int
4011 {
4012  return number_cache.n_levels;
4013 }
4014 
4015 template <int dim, int spacedim>
4016 inline unsigned int
4018 {
4019  return number_cache.n_levels;
4020 }
4021 
4022 
4023 template <int dim, int spacedim>
4024 inline unsigned int
4026 {
4027  return vertices.size();
4028 }
4029 
4030 
4031 
4032 template <int dim, int spacedim>
4033 inline const std::vector<Point<spacedim>> &
4035 {
4036  return vertices;
4037 }
4038 
4039 
4040 template <int dim, int spacedim>
4041 template <class Archive>
4042 void
4043 Triangulation<dim, spacedim>::save(Archive &ar, const unsigned int) const
4044 {
4045  // as discussed in the documentation, do not store the signals as
4046  // well as boundary and manifold description but everything else
4047  ar &smooth_grid;
4048 
4049  unsigned int n_levels = levels.size();
4050  ar & n_levels;
4051  for (unsigned int i = 0; i < levels.size(); ++i)
4052  ar &levels[i];
4053 
4054  // boost dereferences a nullptr when serializing a nullptr
4055  // at least up to 1.65.1. This causes problems with clang-5.
4056  // Therefore, work around it.
4057  bool faces_is_nullptr = (faces.get() == nullptr);
4058  ar & faces_is_nullptr;
4059  if (!faces_is_nullptr)
4060  ar &faces;
4061 
4062  ar &vertices;
4063  ar &vertices_used;
4064 
4065  ar &anisotropic_refinement;
4066  ar &number_cache;
4067 
4068  ar &check_for_distorted_cells;
4069 
4070  if (dim == 1)
4071  {
4072  ar &vertex_to_boundary_id_map_1d;
4073  ar &vertex_to_manifold_id_map_1d;
4074  }
4075 }
4076 
4077 
4078 
4079 template <int dim, int spacedim>
4080 template <class Archive>
4081 void
4082 Triangulation<dim, spacedim>::load(Archive &ar, const unsigned int)
4083 {
4084  // clear previous content. this also calls the respective signal
4085  clear();
4086 
4087  // as discussed in the documentation, do not store the signals as
4088  // well as boundary and manifold description but everything else
4089  ar &smooth_grid;
4090 
4091  unsigned int size;
4092  ar & size;
4093  levels.resize(size);
4094  for (unsigned int i = 0; i < levels.size(); ++i)
4095  {
4096  std::unique_ptr<internal::TriangulationImplementation::TriaLevel<dim>>
4097  level;
4098  ar &level;
4099  levels[i] = std::move(level);
4100  }
4101 
4102  // Workaround for nullptr, see in save().
4103  bool faces_is_nullptr = true;
4104  ar & faces_is_nullptr;
4105  if (!faces_is_nullptr)
4106  ar &faces;
4107 
4108  ar &vertices;
4109  ar &vertices_used;
4110 
4111  ar &anisotropic_refinement;
4112  ar &number_cache;
4113 
4114  // the levels do not serialize the active_cell_indices because
4115  // they are easy enough to rebuild upon re-loading data. do
4116  // this here. don't forget to first resize the fields appropriately
4117  {
4118  for (unsigned int l = 0; l < levels.size(); ++l)
4119  levels[l]->active_cell_indices.resize(levels[l]->refine_flags.size());
4120  reset_active_cell_indices();
4121  }
4122 
4123 
4124  bool my_check_for_distorted_cells;
4125  ar & my_check_for_distorted_cells;
4126 
4127  Assert(my_check_for_distorted_cells == check_for_distorted_cells,
4128  ExcMessage("The triangulation loaded into here must have the "
4129  "same setting with regard to reporting distorted "
4130  "cell as the one previously stored."));
4131 
4132  if (dim == 1)
4133  {
4134  ar &vertex_to_boundary_id_map_1d;
4135  ar &vertex_to_manifold_id_map_1d;
4136  }
4137 
4138  // trigger the create signal to indicate
4139  // that new content has been imported into
4140  // the triangulation
4141  signals.create();
4142 }
4143 
4144 
4145 
4146 template <int dim, int spacedim>
4147 inline unsigned int
4149  const types::coarse_cell_id coarse_cell_id) const
4150 {
4151  return coarse_cell_id;
4152 }
4153 
4154 
4155 
4156 template <int dim, int spacedim>
4157 inline types::coarse_cell_id
4159  const unsigned int coarse_cell_index) const
4160 {
4161  return coarse_cell_index;
4162 }
4163 
4164 
4165 
4166 /* -------------- declaration of explicit specializations ------------- */
4167 
4168 template <>
4169 unsigned int
4170 Triangulation<1, 1>::n_raw_lines(const unsigned int level) const;
4171 template <>
4172 unsigned int
4174 template <>
4175 unsigned int
4176 Triangulation<1, 1>::n_quads(const unsigned int level) const;
4177 template <>
4178 unsigned int
4179 Triangulation<1, 1>::n_raw_quads(const unsigned int level) const;
4180 template <>
4181 unsigned int
4182 Triangulation<2, 2>::n_raw_quads(const unsigned int level) const;
4183 template <>
4184 unsigned int
4185 Triangulation<1, 1>::n_raw_hexs(const unsigned int level) const;
4186 template <>
4187 unsigned int
4188 Triangulation<1, 1>::n_active_quads(const unsigned int level) const;
4189 template <>
4190 unsigned int
4192 template <>
4193 unsigned int
4195 
4196 
4197 // -------------------------------------------------------------------
4198 // -- Explicit specializations for codimension one grids
4199 
4200 
4201 template <>
4202 unsigned int
4203 Triangulation<1, 2>::n_raw_lines(const unsigned int level) const;
4204 template <>
4205 unsigned int
4207 template <>
4208 unsigned int
4209 Triangulation<1, 2>::n_quads(const unsigned int level) const;
4210 template <>
4211 unsigned int
4212 Triangulation<1, 2>::n_raw_quads(const unsigned int level) const;
4213 template <>
4214 unsigned int
4215 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4216 template <>
4217 unsigned int
4218 Triangulation<1, 2>::n_raw_hexs(const unsigned int level) const;
4219 template <>
4220 unsigned int
4221 Triangulation<1, 2>::n_active_quads(const unsigned int level) const;
4222 template <>
4223 unsigned int
4225 template <>
4226 unsigned int
4228 
4229 // -------------------------------------------------------------------
4230 // -- Explicit specializations for codimension two grids
4231 
4232 
4233 template <>
4234 unsigned int
4235 Triangulation<1, 3>::n_raw_lines(const unsigned int level) const;
4236 template <>
4237 unsigned int
4239 template <>
4240 unsigned int
4241 Triangulation<1, 3>::n_quads(const unsigned int level) const;
4242 template <>
4243 unsigned int
4244 Triangulation<1, 3>::n_raw_quads(const unsigned int level) const;
4245 template <>
4246 unsigned int
4247 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4248 template <>
4249 unsigned int
4250 Triangulation<1, 3>::n_raw_hexs(const unsigned int level) const;
4251 template <>
4252 unsigned int
4253 Triangulation<1, 3>::n_active_quads(const unsigned int level) const;
4254 template <>
4255 unsigned int
4257 template <>
4258 unsigned int
4260 
4261 
4262 #endif // DOXYGEN
4263 
4264 DEAL_II_NAMESPACE_CLOSE
4265 
4266 // Include tria_accessor.h here, so that it is possible for an end
4267 // user to use the iterators of Triangulation<dim> directly without
4268 // the need to include tria_accessor.h separately. (Otherwise the
4269 // iterators are an 'opaque' or 'incomplete' type.)
4270 #include <deal.II/grid/tria_accessor.h>
4271 
4272 #endif
boost::signals2::signal< void(const Triangulation< dim, spacedim > &destination_tria)> copy
Definition: tria.h:2107
virtual unsigned int coarse_cell_id_to_coarse_cell_index(const types::coarse_cell_id coarse_cell_id) const
boost::signals2::signal< void()> post_refinement
Definition: tria.h:2059
unsigned int n_vertices() const
unsigned int manifold_id
Definition: types.h:137
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> pre_coarsening_on_cell
Definition: tria.h:2087
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
boost::signals2::signal< void()> post_distributed_repartition
Definition: tria.h:2203
typename IteratorSelector::line_iterator line_iterator
Definition: tria.h:1424
typename IteratorSelector::hex_iterator hex_iterator
Definition: tria.h:1472
typename IteratorSelector::active_line_iterator active_line_iterator
Definition: tria.h:1439
boost::signals2::signal< void()> pre_distributed_refinement
Definition: tria.h:2174
#define AssertIndexRange(index, range)
Definition: exceptions.h:1641
STL namespace.
unsigned int coarse_cell_id
Definition: types.h:109
static ::ExceptionBase & ExcFacesHaveNoLevel()
unsigned int n_levels() const
static ::ExceptionBase & ExcMessage(std::string arg1)
boost::signals2::signal< void()> pre_refinement
Definition: tria.h:2052
unsigned int subdomain_id
Definition: types.h:43
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:518
Definition: types.h:31
unsigned int n_raw_quads() const
Definition: tria.cc:13162
#define Assert(cond, exc)
Definition: exceptions.h:1411
Signals signals
Definition: tria.h:2239
boost::signals2::signal< void()> clear
Definition: tria.h:2122
::internal::TriangulationImplementation::Iterators< dim, spacedim > IteratorSelector
Definition: tria.h:1117
unsigned int n_raw_hexs(const unsigned int level) const
Definition: tria.cc:13218
unsigned int max_adjacent_cells() const
Definition: tria.cc:13335
void load(Archive &ar, const unsigned int version)
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
Definition: tria.h:1518
unsigned int n_quads() const
Definition: tria.cc:13114
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:496
#define DeclException0(Exception0)
Definition: exceptions.h:473
virtual types::coarse_cell_id coarse_cell_index_to_coarse_cell_id(const unsigned int coarse_cell_index) const
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> post_refinement_on_cell
Definition: tria.h:2097
typename IteratorSelector::active_quad_iterator active_quad_iterator
Definition: tria.h:1463
const std::vector< Point< spacedim > > & get_vertices() const
boost::signals2::signal< void()> mesh_movement
Definition: tria.h:2076
unsigned int n_raw_lines() const
Definition: tria.cc:12931
boost::signals2::signal< void()> pre_distributed_save
Definition: tria.h:2211
void save(Archive &ar, const unsigned int version) const
typename IteratorSelector::quad_iterator quad_iterator
Definition: tria.h:1448
boost::signals2::signal< void()> create
Definition: tria.h:2043
Definition: hp.h:117
unsigned int n_active_quads() const
Definition: tria.cc:13181
boost::signals2::signal< void()> pre_partition
Definition: tria.h:2067
typename IteratorSelector::active_hex_iterator active_hex_iterator
Definition: tria.h:1483
unsigned int global_dof_index
Definition: types.h:89
boost::signals2::signal< void()> post_distributed_save
Definition: tria.h:2218
std::vector< unsigned int > n_active_hexes_level
Definition: tria.h:297
virtual unsigned int n_global_levels() const
boost::signals2::signal< unsigned int(const cell_iterator &, const CellStatus), CellWeightSum< unsigned int > > cell_weight
Definition: tria.h:2161
boost::signals2::signal< void()> pre_distributed_load
Definition: tria.h:2226
std::vector< unsigned int > n_active_lines_level
Definition: tria.h:178
std::vector< unsigned int > n_active_quads_level
Definition: tria.h:237
boost::signals2::signal< void()> post_distributed_load
Definition: tria.h:2233
unsigned int boundary_id
Definition: types.h:125
boost::signals2::signal< void()> pre_distributed_repartition
Definition: tria.h:2196
bool vertex_used(const unsigned int index) const
boost::signals2::signal< void()> any_change
Definition: tria.h:2133
boost::signals2::signal< void()> post_distributed_refinement
Definition: tria.h:2184