Reference documentation for deal.II version 9.1.0-pre
tria.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2018 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_iterator_selector.h>
29 
30 #include <boost/serialization/map.hpp>
31 #include <boost/serialization/split_member.hpp>
32 #include <boost/serialization/unique_ptr.hpp>
33 #include <boost/serialization/vector.hpp>
34 #include <boost/signals2.hpp>
35 
36 #include <bitset>
37 #include <functional>
38 #include <list>
39 #include <map>
40 #include <memory>
41 #include <numeric>
42 #include <vector>
43 
44 
45 DEAL_II_NAMESPACE_OPEN
46 
47 template <int dim, int spacedim>
48 class Manifold;
49 
50 namespace GridTools
51 {
52  template <typename CellIterator>
53  struct PeriodicFacePair;
54 }
55 
56 template <int, int, int>
58 template <int spacedim>
59 class TriaAccessor<0, 1, spacedim>;
60 template <int, int, int>
62 
63 namespace internal
64 {
65  namespace TriangulationImplementation
66  {
67  template <int dim>
68  class TriaLevel;
69  template <int dim>
70  class TriaFaces;
71 
72  template <typename>
73  class TriaObjects;
74 
80  struct Implementation;
81  } // namespace TriangulationImplementation
82 
83  namespace TriaAccessorImplementation
84  {
85  struct Implementation;
86  }
87 } // namespace internal
88 
89 namespace hp
90 {
91  template <int dim, int spacedim>
92  class DoFHandler;
93 }
94 
95 
96 /*------------------------------------------------------------------------*/
97 
133 template <int structdim>
134 struct CellData
135 {
142 
150  union
151  {
161 
172  };
173 
183 
191  CellData();
192 };
193 
194 
195 
251 {
258  std::vector<CellData<1>> boundary_lines;
259 
266  std::vector<CellData<2>> boundary_quads;
267 
276  bool
277  check_consistency(const unsigned int dim) const;
278 };
279 
280 
281 /*------------------------------------------------------------------------*/
282 
283 
284 namespace internal
285 {
290  namespace TriangulationImplementation
291  {
305  template <int dim>
306  struct NumberCache
307  {};
308 
322  template <>
323  struct NumberCache<1>
324  {
328  unsigned int n_levels;
329 
333  unsigned int n_lines;
334 
338  std::vector<unsigned int> n_lines_level;
339 
343  unsigned int n_active_lines;
344 
348  std::vector<unsigned int> n_active_lines_level;
349 
353  NumberCache();
354 
359  std::size_t
360  memory_consumption() const;
361 
366  template <class Archive>
367  void
368  serialize(Archive &ar, const unsigned int version);
369  };
370 
371 
386  template <>
387  struct NumberCache<2> : public NumberCache<1>
388  {
392  unsigned int n_quads;
393 
397  std::vector<unsigned int> n_quads_level;
398 
402  unsigned int n_active_quads;
403 
407  std::vector<unsigned int> n_active_quads_level;
408 
412  NumberCache();
413 
418  std::size_t
419  memory_consumption() const;
420 
425  template <class Archive>
426  void
427  serialize(Archive &ar, const unsigned int version);
428  };
429 
430 
446  template <>
447  struct NumberCache<3> : public NumberCache<2>
448  {
452  unsigned int n_hexes;
453 
457  std::vector<unsigned int> n_hexes_level;
458 
462  unsigned int n_active_hexes;
463 
467  std::vector<unsigned int> n_active_hexes_level;
468 
472  NumberCache();
473 
478  std::size_t
479  memory_consumption() const;
480 
485  template <class Archive>
486  void
487  serialize(Archive &ar, const unsigned int version);
488  };
489  } // namespace TriangulationImplementation
490 } // namespace internal
491 
492 
493 /*------------------------------------------------------------------------*/
494 
495 
1276 template <int dim, int spacedim = dim>
1277 class Triangulation : public Subscriptor
1278 {
1279 private:
1284  using IteratorSelector =
1285  ::internal::TriangulationImplementation::Iterators<dim, spacedim>;
1286 
1287 public:
1293  {
1298  none = 0x0,
1341  limit_level_difference_at_vertices = 0x1,
1362  eliminate_unrefined_islands = 0x2,
1378  patch_level_1 = 0x4,
1399  coarsest_level_1 = 0x8,
1424  allow_anisotropic_smoothing = 0x10,
1457  eliminate_refined_inner_islands = 0x100,
1462  eliminate_refined_boundary_islands = 0x200,
1468  do_not_produce_unrefined_islands = 0x400,
1469 
1474  smoothing_on_refinement =
1475  (limit_level_difference_at_vertices | eliminate_unrefined_islands),
1480  smoothing_on_coarsening =
1481  (eliminate_refined_inner_islands | eliminate_refined_boundary_islands |
1482  do_not_produce_unrefined_islands),
1483 
1489  maximum_smoothing = 0xffff ^ allow_anisotropic_smoothing
1490  };
1491 
1508 
1526 
1540  using face_iterator = TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1541 
1553  using active_face_iterator =
1554  TriaActiveIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1555 
1565 
1578  using active_vertex_iterator =
1580 
1581  using line_iterator = typename IteratorSelector::line_iterator;
1582  using active_line_iterator = typename IteratorSelector::active_line_iterator;
1583 
1584  using quad_iterator = typename IteratorSelector::quad_iterator;
1585  using active_quad_iterator = typename IteratorSelector::active_quad_iterator;
1586 
1587  using hex_iterator = typename IteratorSelector::hex_iterator;
1588  using active_hex_iterator = typename IteratorSelector::active_hex_iterator;
1589 
1609  {
1616  virtual ~DistortedCellList() noexcept override;
1617 
1622  std::list<typename Triangulation<dim, spacedim>::cell_iterator>
1624  };
1625 
1629  static const unsigned int dimension = dim;
1630 
1634  static const unsigned int space_dimension = spacedim;
1635 
1650  Triangulation(const MeshSmoothing smooth_grid = none,
1651  const bool check_for_distorted_cells = false);
1652 
1668  Triangulation(const Triangulation<dim, spacedim> &) = delete;
1669 
1677 
1681  Triangulation &
1682  operator=(Triangulation<dim, spacedim> &&tria) noexcept;
1683 
1687  virtual ~Triangulation() override;
1688 
1695  virtual void
1696  clear();
1697 
1703  virtual void
1704  set_mesh_smoothing(const MeshSmoothing mesh_smoothing);
1705 
1709  virtual const MeshSmoothing &
1710  get_mesh_smoothing() const;
1711 
1735  void
1736  set_manifold(const types::manifold_id number,
1737  const Manifold<dim, spacedim> &manifold_object);
1738 
1739 
1754  DEAL_II_DEPRECATED
1755  void
1756  set_manifold(const types::manifold_id number);
1757 
1770  void
1771  reset_manifold(const types::manifold_id manifold_number);
1772 
1784  void
1785  reset_all_manifolds();
1786 
1795  void
1796  set_all_manifold_ids(const types::manifold_id number);
1797 
1806  void
1807  set_all_manifold_ids_on_boundary(const types::manifold_id number);
1808 
1818  void
1819  set_all_manifold_ids_on_boundary(const types::boundary_id b_id,
1820  const types::manifold_id number);
1821 
1831  const Manifold<dim, spacedim> &
1832  get_manifold(const types::manifold_id number) const;
1833 
1845  std::vector<types::boundary_id>
1846  get_boundary_ids() const;
1847 
1859  std::vector<types::manifold_id>
1860  get_manifold_ids() const;
1861 
1888  virtual void
1889  copy_triangulation(const Triangulation<dim, spacedim> &other_tria);
1890 
1934  virtual void
1935  create_triangulation(const std::vector<Point<spacedim>> &vertices,
1936  const std::vector<CellData<dim>> & cells,
1937  const SubCellData & subcelldata);
1938 
1947  virtual void
1948  create_triangulation_compatibility(
1949  const std::vector<Point<spacedim>> &vertices,
1950  const std::vector<CellData<dim>> & cells,
1951  const SubCellData & subcelldata);
1952 
1959  void
1960  flip_all_direction_flags();
1961 
1973  void
1974  set_all_refine_flags();
1975 
1990  void
1991  refine_global(const unsigned int times = 1);
1992 
2024  virtual void
2025  execute_coarsening_and_refinement();
2026 
2056  virtual bool
2057  prepare_coarsening_and_refinement();
2058 
2059  /*
2060  * @}
2061  */
2062 
2077  {
2094  CELL_INVALID
2095  };
2096 
2102  template <typename T>
2104  {
2105  using result_type = T;
2106 
2107  template <typename InputIterator>
2108  T
2109  operator()(InputIterator first, InputIterator last) const
2110  {
2111  return std::accumulate(first, last, T());
2112  }
2113  };
2114 
2124  struct Signals
2125  {
2133  boost::signals2::signal<void()> create;
2134 
2142  boost::signals2::signal<void()> pre_refinement;
2143 
2149  boost::signals2::signal<void()> post_refinement;
2150 
2158  boost::signals2::signal<void()> mesh_movement;
2159 
2167  boost::signals2::signal<void(
2168  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2170 
2177  boost::signals2::signal<void(
2178  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2180 
2187  boost::signals2::signal<void(
2188  const Triangulation<dim, spacedim> &destination_tria)>
2190 
2204  boost::signals2::signal<void()> clear;
2205 
2215  boost::signals2::signal<void()> any_change;
2216 
2240  boost::signals2::signal<unsigned int(const cell_iterator &,
2241  const CellStatus),
2244 
2256  boost::signals2::signal<void()> pre_distributed_refinement;
2257 
2266  boost::signals2::signal<void()> post_distributed_refinement;
2267 
2274  boost::signals2::signal<void()> pre_distributed_save;
2275 
2281  boost::signals2::signal<void()> post_distributed_load;
2282  };
2283 
2287  mutable Signals signals;
2288 
2289  /*
2290  * @}
2291  */
2292 
2302  void
2303  save_refine_flags(std::ostream &out) const;
2304 
2308  void
2309  save_refine_flags(std::vector<bool> &v) const;
2310 
2314  void
2315  load_refine_flags(std::istream &in);
2316 
2320  void
2321  load_refine_flags(const std::vector<bool> &v);
2322 
2326  void
2327  save_coarsen_flags(std::ostream &out) const;
2328 
2332  void
2333  save_coarsen_flags(std::vector<bool> &v) const;
2334 
2338  void
2339  load_coarsen_flags(std::istream &out);
2340 
2344  void
2345  load_coarsen_flags(const std::vector<bool> &v);
2346 
2351  bool
2352  get_anisotropic_refinement_flag() const;
2353 
2354  /*
2355  * @}
2356  */
2357 
2367  void
2368  clear_user_flags();
2369 
2375  void
2376  save_user_flags(std::ostream &out) const;
2377 
2383  void
2384  save_user_flags(std::vector<bool> &v) const;
2385 
2390  void
2391  load_user_flags(std::istream &in);
2392 
2397  void
2398  load_user_flags(const std::vector<bool> &v);
2399 
2404  void
2405  clear_user_flags_line();
2406 
2411  void
2412  save_user_flags_line(std::ostream &out) const;
2413 
2419  void
2420  save_user_flags_line(std::vector<bool> &v) const;
2421 
2426  void
2427  load_user_flags_line(std::istream &in);
2428 
2433  void
2434  load_user_flags_line(const std::vector<bool> &v);
2435 
2440  void
2441  clear_user_flags_quad();
2442 
2447  void
2448  save_user_flags_quad(std::ostream &out) const;
2449 
2455  void
2456  save_user_flags_quad(std::vector<bool> &v) const;
2457 
2462  void
2463  load_user_flags_quad(std::istream &in);
2464 
2469  void
2470  load_user_flags_quad(const std::vector<bool> &v);
2471 
2472 
2477  void
2478  clear_user_flags_hex();
2479 
2484  void
2485  save_user_flags_hex(std::ostream &out) const;
2486 
2492  void
2493  save_user_flags_hex(std::vector<bool> &v) const;
2494 
2499  void
2500  load_user_flags_hex(std::istream &in);
2501 
2506  void
2507  load_user_flags_hex(const std::vector<bool> &v);
2508 
2514  void
2515  clear_user_data();
2516 
2522  void
2523  save_user_indices(std::vector<unsigned int> &v) const;
2524 
2529  void
2530  load_user_indices(const std::vector<unsigned int> &v);
2531 
2537  void
2538  save_user_pointers(std::vector<void *> &v) const;
2539 
2544  void
2545  load_user_pointers(const std::vector<void *> &v);
2546 
2552  void
2553  save_user_indices_line(std::vector<unsigned int> &v) const;
2554 
2559  void
2560  load_user_indices_line(const std::vector<unsigned int> &v);
2561 
2567  void
2568  save_user_indices_quad(std::vector<unsigned int> &v) const;
2569 
2574  void
2575  load_user_indices_quad(const std::vector<unsigned int> &v);
2576 
2582  void
2583  save_user_indices_hex(std::vector<unsigned int> &v) const;
2584 
2589  void
2590  load_user_indices_hex(const std::vector<unsigned int> &v);
2596  void
2597  save_user_pointers_line(std::vector<void *> &v) const;
2598 
2603  void
2604  load_user_pointers_line(const std::vector<void *> &v);
2605 
2611  void
2612  save_user_pointers_quad(std::vector<void *> &v) const;
2613 
2618  void
2619  load_user_pointers_quad(const std::vector<void *> &v);
2620 
2626  void
2627  save_user_pointers_hex(std::vector<void *> &v) const;
2628 
2633  void
2634  load_user_pointers_hex(const std::vector<void *> &v);
2635 
2636  /*
2637  * @}
2638  */
2639 
2649  begin(const unsigned int level = 0) const;
2650 
2668  begin_active(const unsigned int level = 0) const;
2669 
2675  end() const;
2676 
2682  end(const unsigned int level) const;
2683 
2690  end_active(const unsigned int level) const;
2691 
2692 
2697  last() const;
2698 
2703  last_active() const;
2704 
2720  cell_iterators() const;
2721 
2758  active_cell_iterators() const;
2759 
2776  cell_iterators_on_level(const unsigned int level) const;
2777 
2794  active_cell_iterators_on_level(const unsigned int level) const;
2795 
2796  /*
2797  * @}
2798  */
2799 
2800  /*-------------------------------------------------------------------------*/
2801 
2811  begin_face() const;
2812 
2817  begin_active_face() const;
2818 
2824  end_face() const;
2825 
2826  /*
2827  * @}
2828  */
2829 
2830  /*-------------------------------------------------------------------------*/
2831 
2842  begin_vertex() const;
2843 
2850  begin_active_vertex() const;
2851 
2858  end_vertex() const;
2859 
2860  /*
2861  * @}
2862  */
2863 
2881  unsigned int
2882  n_lines() const;
2883 
2887  unsigned int
2888  n_lines(const unsigned int level) const;
2889 
2893  unsigned int
2894  n_active_lines() const;
2895 
2899  unsigned int
2900  n_active_lines(const unsigned int level) const;
2901 
2905  unsigned int
2906  n_quads() const;
2907 
2911  unsigned int
2912  n_quads(const unsigned int level) const;
2913 
2917  unsigned int
2918  n_active_quads() const;
2919 
2923  unsigned int
2924  n_active_quads(const unsigned int level) const;
2925 
2929  unsigned int
2930  n_hexs() const;
2931 
2936  unsigned int
2937  n_hexs(const unsigned int level) const;
2938 
2942  unsigned int
2943  n_active_hexs() const;
2944 
2949  unsigned int
2950  n_active_hexs(const unsigned int level) const;
2951 
2956  unsigned int
2957  n_cells() const;
2958 
2963  unsigned int
2964  n_cells(const unsigned int level) const;
2965 
2970  unsigned int
2971  n_active_cells() const;
2972 
2980  virtual types::global_dof_index
2981  n_global_active_cells() const;
2982 
2983 
2988  unsigned int
2989  n_active_cells(const unsigned int level) const;
2990 
2996  unsigned int
2997  n_faces() const;
2998 
3004  unsigned int
3005  n_active_faces() const;
3006 
3024  unsigned int
3025  n_levels() const;
3026 
3033  virtual unsigned int
3034  n_global_levels() const;
3035 
3045  virtual bool
3046  has_hanging_nodes() const;
3047 
3055  unsigned int
3056  n_vertices() const;
3057 
3066  const std::vector<Point<spacedim>> &
3067  get_vertices() const;
3068 
3073  unsigned int
3074  n_used_vertices() const;
3075 
3079  bool
3080  vertex_used(const unsigned int index) const;
3081 
3086  const std::vector<bool> &
3087  get_used_vertices() const;
3088 
3100  unsigned int
3101  max_adjacent_cells() const;
3102 
3109  virtual types::subdomain_id
3110  locally_owned_subdomain() const;
3111 
3122  get_triangulation();
3123 
3129  get_triangulation() const;
3130 
3131 
3132  /*
3133  * @}
3134  */
3135 
3150  unsigned int
3151  n_raw_lines() const;
3152 
3162  unsigned int
3163  n_raw_lines(const unsigned int level) const;
3164 
3174  unsigned int
3175  n_raw_quads() const;
3176 
3186  unsigned int
3187  n_raw_quads(const unsigned int level) const;
3188 
3198  unsigned int
3199  n_raw_hexs(const unsigned int level) const;
3200 
3210  unsigned int
3211  n_raw_cells(const unsigned int level) const;
3212 
3223  unsigned int
3224  n_raw_faces() const;
3225 
3226  /*
3227  * @}
3228  */
3229 
3238  virtual std::size_t
3239  memory_consumption() const;
3240 
3249  template <class Archive>
3250  void
3251  save(Archive &ar, const unsigned int version) const;
3252 
3268  template <class Archive>
3269  void
3270  load(Archive &ar, const unsigned int version);
3271 
3272 
3288  virtual void
3289  add_periodicity(
3290  const std::vector<GridTools::PeriodicFacePair<cell_iterator>> &);
3291 
3295  const std::map<
3296  std::pair<cell_iterator, unsigned int>,
3297  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>> &
3298  get_periodic_face_map() const;
3299 
3300 
3301  BOOST_SERIALIZATION_SPLIT_MEMBER()
3302 
3303 
3313  DeclException1(ExcInvalidLevel,
3314  int,
3315  << "The given level " << arg1
3316  << " is not in the valid range!");
3324  ExcTriangulationNotEmpty,
3325  int,
3326  int,
3327  << "You are trying to perform an operation on a triangulation "
3328  << "that is only allowed if the triangulation is currently empty. "
3329  << "However, it currently stores " << arg1 << " vertices and has "
3330  << "cells on " << arg2 << " levels.");
3336  DeclException0(ExcGridReadError);
3347  DeclException1(ExcEmptyLevel,
3348  int,
3349  << "You tried to do something on level " << arg1
3350  << ", but this level is empty.");
3356  DeclException0(ExcNonOrientableTriangulation);
3357 
3365  DeclException1(ExcBoundaryIdNotFound,
3366  types::boundary_id,
3367  << "The given boundary_id " << arg1
3368  << " is not defined in this Triangulation!");
3369 
3370  /*
3371  * @}
3372  */
3373 
3374 protected:
3379  MeshSmoothing smooth_grid;
3380 
3394  static void
3395  write_bool_vector(const unsigned int magic_number1,
3396  const std::vector<bool> &v,
3397  const unsigned int magic_number2,
3398  std::ostream & out);
3399 
3404  static void
3405  read_bool_vector(const unsigned int magic_number1,
3406  std::vector<bool> &v,
3407  const unsigned int magic_number2,
3408  std::istream & in);
3409 
3414  void
3415  update_periodic_face_map();
3416 
3417 
3418 private:
3425  std::vector<GridTools::PeriodicFacePair<cell_iterator>>
3426  periodic_face_pairs_level_0;
3427 
3432  std::map<std::pair<cell_iterator, unsigned int>,
3433  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>>
3434  periodic_face_map;
3435 
3450  using raw_face_iterator =
3451  TriaRawIterator<TriaAccessor<dim - 1, dim, spacedim>>;
3452  using raw_vertex_iterator =
3453  TriaRawIterator<::TriaAccessor<0, dim, spacedim>>;
3454  using raw_line_iterator = typename IteratorSelector::raw_line_iterator;
3455  using raw_quad_iterator = typename IteratorSelector::raw_quad_iterator;
3456  using raw_hex_iterator = typename IteratorSelector::raw_hex_iterator;
3457 
3463  begin_raw(const unsigned int level = 0) const;
3464 
3470  end_raw(const unsigned int level) const;
3471 
3472  /*
3473  * @}
3474  */
3475 
3487  raw_line_iterator
3488  begin_raw_line(const unsigned int level = 0) const;
3489 
3493  line_iterator
3494  begin_line(const unsigned int level = 0) const;
3495 
3499  active_line_iterator
3500  begin_active_line(const unsigned int level = 0) const;
3501 
3506  line_iterator
3507  end_line() const;
3508 
3509  /*
3510  * @}
3511  */
3512 
3523  raw_quad_iterator
3524  begin_raw_quad(const unsigned int level = 0) const;
3525 
3529  quad_iterator
3530  begin_quad(const unsigned int level = 0) const;
3531 
3535  active_quad_iterator
3536  begin_active_quad(const unsigned int level = 0) const;
3537 
3542  quad_iterator
3543  end_quad() const;
3544 
3545  /*
3546  * @}
3547  */
3548 
3558  raw_hex_iterator
3559  begin_raw_hex(const unsigned int level = 0) const;
3560 
3564  hex_iterator
3565  begin_hex(const unsigned int level = 0) const;
3566 
3570  active_hex_iterator
3571  begin_active_hex(const unsigned int level = 0) const;
3572 
3577  hex_iterator
3578  end_hex() const;
3579 
3580  /*
3581  * @}
3582  */
3583 
3584 
3598  void
3599  clear_despite_subscriptions();
3600 
3607  void
3608  reset_active_cell_indices();
3609 
3623  DistortedCellList
3624  execute_refinement();
3625 
3632  void
3633  execute_coarsening();
3634 
3639  void
3640  fix_coarsen_flags();
3641 
3646  std::vector<std::unique_ptr<
3647  ::internal::TriangulationImplementation::TriaLevel<dim>>>
3648  levels;
3649 
3655  std::unique_ptr<::internal::TriangulationImplementation::TriaFaces<dim>>
3656  faces;
3657 
3658 
3662  std::vector<Point<spacedim>> vertices;
3663 
3667  std::vector<bool> vertices_used;
3668 
3673  std::map<types::manifold_id, std::unique_ptr<const Manifold<dim, spacedim>>>
3674  manifold;
3675 
3679  bool anisotropic_refinement;
3680 
3681 
3686  const bool check_for_distorted_cells;
3687 
3697  ::internal::TriangulationImplementation::NumberCache<dim> number_cache;
3698 
3713  std::unique_ptr<std::map<unsigned int, types::boundary_id>>
3714  vertex_to_boundary_id_map_1d;
3715 
3716 
3736  std::unique_ptr<std::map<unsigned int, types::manifold_id>>
3737  vertex_to_manifold_id_map_1d;
3738 
3739  // make a couple of classes friends
3740  template <int, int, int>
3741  friend class TriaAccessorBase;
3742  template <int, int, int>
3743  friend class TriaAccessor;
3744  friend class TriaAccessor<0, 1, spacedim>;
3745 
3746  friend class CellAccessor<dim, spacedim>;
3747 
3748  friend struct ::internal::TriaAccessorImplementation::Implementation;
3749 
3750  friend class hp::DoFHandler<dim, spacedim>;
3751 
3752  friend struct ::internal::TriangulationImplementation::Implementation;
3753 
3754  template <typename>
3755  friend class ::internal::TriangulationImplementation::TriaObjects;
3756 
3757  // explicitly check for sensible template arguments, but not on windows
3758  // because MSVC creates bogus warnings during normal compilation
3759 #ifndef DEAL_II_MSVC
3760  static_assert(dim <= spacedim,
3761  "The dimension <dim> of a Triangulation must be less than or "
3762  "equal to the space dimension <spacedim> in which it lives.");
3763 #endif
3764 };
3765 
3766 
3767 #ifndef DOXYGEN
3768 
3769 
3770 template <int structdim>
3772 {
3773  for (unsigned int i = 0; i < GeometryInfo<structdim>::vertices_per_cell; ++i)
3774  vertices[i] = numbers::invalid_unsigned_int;
3775 
3776  material_id = 0;
3777 
3778  // And the manifold to be invalid
3779  manifold_id = numbers::invalid_manifold_id;
3780 }
3781 
3782 
3783 
3784 namespace internal
3785 {
3786  namespace TriangulationImplementation
3787  {
3788  template <class Archive>
3789  void
3790  NumberCache<1>::serialize(Archive &ar, const unsigned int)
3791  {
3792  ar &n_levels;
3793  ar &n_lines &n_lines_level;
3794  ar &n_active_lines &n_active_lines_level;
3795  }
3796 
3797 
3798  template <class Archive>
3799  void
3800  NumberCache<2>::serialize(Archive &ar, const unsigned int version)
3801  {
3802  this->NumberCache<1>::serialize(ar, version);
3803 
3804  ar &n_quads &n_quads_level;
3805  ar &n_active_quads &n_active_quads_level;
3806  }
3807 
3808 
3809  template <class Archive>
3810  void
3811  NumberCache<3>::serialize(Archive &ar, const unsigned int version)
3812  {
3813  this->NumberCache<2>::serialize(ar, version);
3814 
3815  ar &n_hexes &n_hexes_level;
3816  ar &n_active_hexes &n_active_hexes_level;
3817  }
3818 
3819  } // namespace TriangulationImplementation
3820 } // namespace internal
3821 
3822 
3823 template <int dim, int spacedim>
3824 inline bool
3825 Triangulation<dim, spacedim>::vertex_used(const unsigned int index) const
3826 {
3827  Assert(index < vertices_used.size(),
3828  ExcIndexRange(index, 0, vertices_used.size()));
3829  return vertices_used[index];
3830 }
3831 
3832 
3833 
3834 template <int dim, int spacedim>
3835 inline unsigned int
3837 {
3838  return number_cache.n_levels;
3839 }
3840 
3841 template <int dim, int spacedim>
3842 inline unsigned int
3844 {
3845  return number_cache.n_levels;
3846 }
3847 
3848 
3849 template <int dim, int spacedim>
3850 inline unsigned int
3852 {
3853  return vertices.size();
3854 }
3855 
3856 
3857 
3858 template <int dim, int spacedim>
3859 inline const std::vector<Point<spacedim>> &
3861 {
3862  return vertices;
3863 }
3864 
3865 
3866 template <int dim, int spacedim>
3867 template <class Archive>
3868 void
3869 Triangulation<dim, spacedim>::save(Archive &ar, const unsigned int) const
3870 {
3871  // as discussed in the documentation, do not store the signals as
3872  // well as boundary and manifold description but everything else
3873  ar &smooth_grid;
3874 
3875  unsigned int n_levels = levels.size();
3876  ar & n_levels;
3877  for (unsigned int i = 0; i < levels.size(); ++i)
3878  ar &levels[i];
3879 
3880  // boost dereferences a nullptr when serializing a nullptr
3881  // at least up to 1.65.1. This causes problems with clang-5.
3882  // Therefore, work around it.
3883  bool faces_is_nullptr = (faces.get() == nullptr);
3884  ar & faces_is_nullptr;
3885  if (!faces_is_nullptr)
3886  ar &faces;
3887 
3888  ar &vertices;
3889  ar &vertices_used;
3890 
3891  ar &anisotropic_refinement;
3892  ar &number_cache;
3893 
3894  ar &check_for_distorted_cells;
3895 
3896  if (dim == 1)
3897  {
3898  ar &vertex_to_boundary_id_map_1d;
3899  ar &vertex_to_manifold_id_map_1d;
3900  }
3901 }
3902 
3903 
3904 
3905 template <int dim, int spacedim>
3906 template <class Archive>
3907 void
3908 Triangulation<dim, spacedim>::load(Archive &ar, const unsigned int)
3909 {
3910  // clear previous content. this also calls the respective signal
3911  clear();
3912 
3913  // as discussed in the documentation, do not store the signals as
3914  // well as boundary and manifold description but everything else
3915  ar &smooth_grid;
3916 
3917  unsigned int size;
3918  ar & size;
3919  levels.resize(size);
3920  for (unsigned int i = 0; i < levels.size(); ++i)
3921  {
3922  std::unique_ptr<internal::TriangulationImplementation::TriaLevel<dim>>
3923  level;
3924  ar &level;
3925  levels[i] = std::move(level);
3926  }
3927 
3928  // Workaround for nullptr, see in save().
3929  bool faces_is_nullptr = true;
3930  ar & faces_is_nullptr;
3931  if (!faces_is_nullptr)
3932  ar &faces;
3933 
3934  ar &vertices;
3935  ar &vertices_used;
3936 
3937  ar &anisotropic_refinement;
3938  ar &number_cache;
3939 
3940  // the levels do not serialize the active_cell_indices because
3941  // they are easy enough to rebuild upon re-loading data. do
3942  // this here. don't forget to first resize the fields appropriately
3943  {
3944  for (unsigned int l = 0; l < levels.size(); ++l)
3945  levels[l]->active_cell_indices.resize(levels[l]->refine_flags.size());
3946  reset_active_cell_indices();
3947  }
3948 
3949 
3950  bool my_check_for_distorted_cells;
3951  ar & my_check_for_distorted_cells;
3952 
3953  Assert(my_check_for_distorted_cells == check_for_distorted_cells,
3954  ExcMessage("The triangulation loaded into here must have the "
3955  "same setting with regard to reporting distorted "
3956  "cell as the one previously stored."));
3957 
3958  if (dim == 1)
3959  {
3960  ar &vertex_to_boundary_id_map_1d;
3961  ar &vertex_to_manifold_id_map_1d;
3962  }
3963 
3964  // trigger the create signal to indicate
3965  // that new content has been imported into
3966  // the triangulation
3967  signals.create();
3968 }
3969 
3970 
3971 /* -------------- declaration of explicit specializations ------------- */
3972 
3973 template <>
3974 unsigned int
3975 Triangulation<1, 1>::n_raw_lines(const unsigned int level) const;
3976 template <>
3977 unsigned int
3979 template <>
3980 unsigned int
3981 Triangulation<1, 1>::n_quads(const unsigned int level) const;
3982 template <>
3983 unsigned int
3984 Triangulation<1, 1>::n_raw_quads(const unsigned int level) const;
3985 template <>
3986 unsigned int
3987 Triangulation<2, 2>::n_raw_quads(const unsigned int level) const;
3988 template <>
3989 unsigned int
3990 Triangulation<1, 1>::n_raw_hexs(const unsigned int level) const;
3991 template <>
3992 unsigned int
3993 Triangulation<1, 1>::n_active_quads(const unsigned int level) const;
3994 template <>
3995 unsigned int
3997 template <>
3998 unsigned int
4000 
4001 
4002 // -------------------------------------------------------------------
4003 // -- Explicit specializations for codimension one grids
4004 
4005 
4006 template <>
4007 unsigned int
4008 Triangulation<1, 2>::n_raw_lines(const unsigned int level) const;
4009 template <>
4010 unsigned int
4012 template <>
4013 unsigned int
4014 Triangulation<1, 2>::n_quads(const unsigned int level) const;
4015 template <>
4016 unsigned int
4017 Triangulation<1, 2>::n_raw_quads(const unsigned int level) const;
4018 template <>
4019 unsigned int
4020 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4021 template <>
4022 unsigned int
4023 Triangulation<1, 2>::n_raw_hexs(const unsigned int level) const;
4024 template <>
4025 unsigned int
4026 Triangulation<1, 2>::n_active_quads(const unsigned int level) const;
4027 template <>
4028 unsigned int
4030 template <>
4031 unsigned int
4033 
4034 // -------------------------------------------------------------------
4035 // -- Explicit specializations for codimension two grids
4036 
4037 
4038 template <>
4039 unsigned int
4040 Triangulation<1, 3>::n_raw_lines(const unsigned int level) const;
4041 template <>
4042 unsigned int
4044 template <>
4045 unsigned int
4046 Triangulation<1, 3>::n_quads(const unsigned int level) const;
4047 template <>
4048 unsigned int
4049 Triangulation<1, 3>::n_raw_quads(const unsigned int level) const;
4050 template <>
4051 unsigned int
4052 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4053 template <>
4054 unsigned int
4055 Triangulation<1, 3>::n_raw_hexs(const unsigned int level) const;
4056 template <>
4057 unsigned int
4058 Triangulation<1, 3>::n_active_quads(const unsigned int level) const;
4059 template <>
4060 unsigned int
4062 template <>
4063 unsigned int
4065 
4066 
4067 #endif // DOXYGEN
4068 
4069 DEAL_II_NAMESPACE_CLOSE
4070 
4071 // Include tria_accessor.h here, so that it is possible for an end
4072 // user to use the iterators of Triangulation<dim> directly without
4073 // the need to include tria_accessor.h separately. (Otherwise the
4074 // iterators are an 'opaque' or 'incomplete' type.)
4075 #include <deal.II/grid/tria_accessor.h>
4076 
4077 #endif
std::vector< CellData< 1 > > boundary_lines
Definition: tria.h:258
boost::signals2::signal< void(const Triangulation< dim, spacedim > &destination_tria)> copy
Definition: tria.h:2189
boost::signals2::signal< void()> post_refinement
Definition: tria.h:2149
static const unsigned int invalid_unsigned_int
Definition: types.h:173
unsigned int manifold_id
Definition: types.h:123
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> pre_coarsening_on_cell
Definition: tria.h:2169
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:420
const std::vector< Point< spacedim > > & get_vertices() const
virtual unsigned int n_global_levels() const
boost::signals2::signal< void()> pre_distributed_refinement
Definition: tria.h:2256
unsigned int material_id
Definition: types.h:134
STL namespace.
types::boundary_id boundary_id
Definition: tria.h:171
static::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
static::ExceptionBase & ExcFacesHaveNoLevel()
Definition: point.h:106
unsigned long long int global_dof_index
Definition: types.h:72
unsigned int n_levels() const
Definition: tria.h:81
unsigned int n_active_quads() const
Definition: tria.cc:12977
static::ExceptionBase & ExcMessage(std::string arg1)
unsigned int n_raw_hexs(const unsigned int level) const
Definition: tria.cc:13015
boost::signals2::signal< void()> pre_refinement
Definition: tria.h:2142
unsigned int n_raw_lines() const
Definition: tria.cc:12724
unsigned int subdomain_id
Definition: types.h:43
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:408
Definition: types.h:31
#define Assert(cond, exc)
Definition: exceptions.h:1227
Signals signals
Definition: tria.h:2287
unsigned int n_raw_quads() const
Definition: tria.cc:12958
boost::signals2::signal< void()> clear
Definition: tria.h:2204
::internal::TriangulationImplementation::Iterators< dim, spacedim > IteratorSelector
Definition: tria.h:1285
void load(Archive &ar, const unsigned int version)
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
Definition: tria.h:1623
#define DeclException0(Exception0)
Definition: exceptions.h:385
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> post_refinement_on_cell
Definition: tria.h:2179
types::material_id material_id
Definition: tria.h:160
boost::signals2::signal< void()> mesh_movement
Definition: tria.h:2158
boost::signals2::signal< void()> pre_distributed_save
Definition: tria.h:2274
boost::signals2::signal< void()> create
Definition: tria.h:2133
bool vertex_used(const unsigned int index) const
Definition: hp.h:102
types::manifold_id manifold_id
Definition: tria.h:182
const types::manifold_id invalid_manifold_id
Definition: types.h:234
std::vector< unsigned int > n_active_hexes_level
Definition: tria.h:467
void save(Archive &ar, const unsigned int version) const
std::vector< CellData< 2 > > boundary_quads
Definition: tria.h:266
boost::signals2::signal< unsigned int(const cell_iterator &, const CellStatus), CellWeightSum< unsigned int > > cell_weight
Definition: tria.h:2243
unsigned int n_quads() const
Definition: tria.cc:12909
std::vector< unsigned int > n_active_lines_level
Definition: tria.h:348
std::vector< unsigned int > n_active_quads_level
Definition: tria.h:407
unsigned int max_adjacent_cells() const
Definition: tria.cc:13138
boost::signals2::signal< void()> post_distributed_load
Definition: tria.h:2281
unsigned int n_vertices() const
unsigned int boundary_id
Definition: types.h:111
boost::signals2::signal< void()> any_change
Definition: tria.h:2215
boost::signals2::signal< void()> post_distributed_refinement
Definition: tria.h:2266