Reference documentation for deal.II version Git e849c0d71e 2019-06-17 10:40:29 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
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_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,
1342  limit_level_difference_at_vertices = 0x1,
1363  eliminate_unrefined_islands = 0x2,
1379  patch_level_1 = 0x4,
1403  coarsest_level_1 = 0x8,
1428  allow_anisotropic_smoothing = 0x10,
1461  eliminate_refined_inner_islands = 0x100,
1466  eliminate_refined_boundary_islands = 0x200,
1472  do_not_produce_unrefined_islands = 0x400,
1473 
1478  smoothing_on_refinement =
1479  (limit_level_difference_at_vertices | eliminate_unrefined_islands),
1484  smoothing_on_coarsening =
1485  (eliminate_refined_inner_islands | eliminate_refined_boundary_islands |
1486  do_not_produce_unrefined_islands),
1487 
1493  maximum_smoothing = 0xffff ^ allow_anisotropic_smoothing
1494  };
1495 
1512 
1530 
1544  using face_iterator = TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1545 
1557  using active_face_iterator =
1558  TriaActiveIterator<TriaAccessor<dim - 1, dim, spacedim>>;
1559 
1569 
1582  using active_vertex_iterator =
1584 
1592  using line_iterator = typename IteratorSelector::line_iterator;
1593 
1607  using active_line_iterator = typename IteratorSelector::active_line_iterator;
1608 
1616  using quad_iterator = typename IteratorSelector::quad_iterator;
1617 
1631  using active_quad_iterator = typename IteratorSelector::active_quad_iterator;
1632 
1640  using hex_iterator = typename IteratorSelector::hex_iterator;
1641 
1651  using active_hex_iterator = typename IteratorSelector::active_hex_iterator;
1652 
1672  {
1679  virtual ~DistortedCellList() noexcept override = default;
1680 
1685  std::list<typename Triangulation<dim, spacedim>::cell_iterator>
1687  };
1688 
1692  static const unsigned int dimension = dim;
1693 
1697  static const unsigned int space_dimension = spacedim;
1698 
1713  Triangulation(const MeshSmoothing smooth_grid = none,
1714  const bool check_for_distorted_cells = false);
1715 
1731  Triangulation(const Triangulation<dim, spacedim> &) = delete;
1732 
1740 
1744  Triangulation &
1745  operator=(Triangulation<dim, spacedim> &&tria) noexcept;
1746 
1750  virtual ~Triangulation() override;
1751 
1758  virtual void
1759  clear();
1760 
1766  virtual void
1767  set_mesh_smoothing(const MeshSmoothing mesh_smoothing);
1768 
1772  virtual const MeshSmoothing &
1773  get_mesh_smoothing() const;
1774 
1798  void
1799  set_manifold(const types::manifold_id number,
1800  const Manifold<dim, spacedim> &manifold_object);
1801 
1802 
1817  DEAL_II_DEPRECATED
1818  void
1819  set_manifold(const types::manifold_id number);
1820 
1833  void
1834  reset_manifold(const types::manifold_id manifold_number);
1835 
1847  void
1848  reset_all_manifolds();
1849 
1858  void
1859  set_all_manifold_ids(const types::manifold_id number);
1860 
1869  void
1870  set_all_manifold_ids_on_boundary(const types::manifold_id number);
1871 
1881  void
1882  set_all_manifold_ids_on_boundary(const types::boundary_id b_id,
1883  const types::manifold_id number);
1884 
1894  const Manifold<dim, spacedim> &
1895  get_manifold(const types::manifold_id number) const;
1896 
1908  std::vector<types::boundary_id>
1909  get_boundary_ids() const;
1910 
1922  std::vector<types::manifold_id>
1923  get_manifold_ids() const;
1924 
1951  virtual void
1952  copy_triangulation(const Triangulation<dim, spacedim> &other_tria);
1953 
1999  virtual void
2000  create_triangulation(const std::vector<Point<spacedim>> &vertices,
2001  const std::vector<CellData<dim>> & cells,
2002  const SubCellData & subcelldata);
2003 
2012  virtual void
2013  create_triangulation_compatibility(
2014  const std::vector<Point<spacedim>> &vertices,
2015  const std::vector<CellData<dim>> & cells,
2016  const SubCellData & subcelldata);
2017 
2024  void
2025  flip_all_direction_flags();
2026 
2038  void
2039  set_all_refine_flags();
2040 
2055  void
2056  refine_global(const unsigned int times = 1);
2057 
2089  virtual void
2090  execute_coarsening_and_refinement();
2091 
2121  virtual bool
2122  prepare_coarsening_and_refinement();
2123 
2124  /*
2125  * @}
2126  */
2127 
2142  {
2159  CELL_INVALID
2160  };
2161 
2167  template <typename T>
2169  {
2170  using result_type = T;
2171 
2172  template <typename InputIterator>
2173  T
2174  operator()(InputIterator first, InputIterator last) const
2175  {
2176  return std::accumulate(first, last, T());
2177  }
2178  };
2179 
2189  struct Signals
2190  {
2198  boost::signals2::signal<void()> create;
2199 
2207  boost::signals2::signal<void()> pre_refinement;
2208 
2214  boost::signals2::signal<void()> post_refinement;
2215 
2222  boost::signals2::signal<void()> pre_partition;
2223 
2231  boost::signals2::signal<void()> mesh_movement;
2232 
2240  boost::signals2::signal<void(
2241  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2243 
2250  boost::signals2::signal<void(
2251  const typename Triangulation<dim, spacedim>::cell_iterator &cell)>
2253 
2260  boost::signals2::signal<void(
2261  const Triangulation<dim, spacedim> &destination_tria)>
2263 
2277  boost::signals2::signal<void()> clear;
2278 
2288  boost::signals2::signal<void()> any_change;
2289 
2313  boost::signals2::signal<unsigned int(const cell_iterator &,
2314  const CellStatus),
2317 
2329  boost::signals2::signal<void()> pre_distributed_refinement;
2330 
2339  boost::signals2::signal<void()> post_distributed_refinement;
2340 
2351  boost::signals2::signal<void()> pre_distributed_repartition;
2352 
2358  boost::signals2::signal<void()> post_distributed_repartition;
2359 
2366  boost::signals2::signal<void()> pre_distributed_save;
2367 
2373  boost::signals2::signal<void()> post_distributed_save;
2374 
2381  boost::signals2::signal<void()> pre_distributed_load;
2382 
2388  boost::signals2::signal<void()> post_distributed_load;
2389  };
2390 
2394  mutable Signals signals;
2395 
2396  /*
2397  * @}
2398  */
2399 
2409  void
2410  save_refine_flags(std::ostream &out) const;
2411 
2415  void
2416  save_refine_flags(std::vector<bool> &v) const;
2417 
2421  void
2422  load_refine_flags(std::istream &in);
2423 
2427  void
2428  load_refine_flags(const std::vector<bool> &v);
2429 
2433  void
2434  save_coarsen_flags(std::ostream &out) const;
2435 
2439  void
2440  save_coarsen_flags(std::vector<bool> &v) const;
2441 
2445  void
2446  load_coarsen_flags(std::istream &out);
2447 
2451  void
2452  load_coarsen_flags(const std::vector<bool> &v);
2453 
2458  bool
2459  get_anisotropic_refinement_flag() const;
2460 
2461  /*
2462  * @}
2463  */
2464 
2474  void
2475  clear_user_flags();
2476 
2482  void
2483  save_user_flags(std::ostream &out) const;
2484 
2490  void
2491  save_user_flags(std::vector<bool> &v) const;
2492 
2497  void
2498  load_user_flags(std::istream &in);
2499 
2504  void
2505  load_user_flags(const std::vector<bool> &v);
2506 
2511  void
2512  clear_user_flags_line();
2513 
2518  void
2519  save_user_flags_line(std::ostream &out) const;
2520 
2526  void
2527  save_user_flags_line(std::vector<bool> &v) const;
2528 
2533  void
2534  load_user_flags_line(std::istream &in);
2535 
2540  void
2541  load_user_flags_line(const std::vector<bool> &v);
2542 
2547  void
2548  clear_user_flags_quad();
2549 
2554  void
2555  save_user_flags_quad(std::ostream &out) const;
2556 
2562  void
2563  save_user_flags_quad(std::vector<bool> &v) const;
2564 
2569  void
2570  load_user_flags_quad(std::istream &in);
2571 
2576  void
2577  load_user_flags_quad(const std::vector<bool> &v);
2578 
2579 
2584  void
2585  clear_user_flags_hex();
2586 
2591  void
2592  save_user_flags_hex(std::ostream &out) const;
2593 
2599  void
2600  save_user_flags_hex(std::vector<bool> &v) const;
2601 
2606  void
2607  load_user_flags_hex(std::istream &in);
2608 
2613  void
2614  load_user_flags_hex(const std::vector<bool> &v);
2615 
2621  void
2622  clear_user_data();
2623 
2629  void
2630  save_user_indices(std::vector<unsigned int> &v) const;
2631 
2636  void
2637  load_user_indices(const std::vector<unsigned int> &v);
2638 
2644  void
2645  save_user_pointers(std::vector<void *> &v) const;
2646 
2651  void
2652  load_user_pointers(const std::vector<void *> &v);
2653 
2659  void
2660  save_user_indices_line(std::vector<unsigned int> &v) const;
2661 
2666  void
2667  load_user_indices_line(const std::vector<unsigned int> &v);
2668 
2674  void
2675  save_user_indices_quad(std::vector<unsigned int> &v) const;
2676 
2681  void
2682  load_user_indices_quad(const std::vector<unsigned int> &v);
2683 
2689  void
2690  save_user_indices_hex(std::vector<unsigned int> &v) const;
2691 
2696  void
2697  load_user_indices_hex(const std::vector<unsigned int> &v);
2703  void
2704  save_user_pointers_line(std::vector<void *> &v) const;
2705 
2710  void
2711  load_user_pointers_line(const std::vector<void *> &v);
2712 
2718  void
2719  save_user_pointers_quad(std::vector<void *> &v) const;
2720 
2725  void
2726  load_user_pointers_quad(const std::vector<void *> &v);
2727 
2733  void
2734  save_user_pointers_hex(std::vector<void *> &v) const;
2735 
2740  void
2741  load_user_pointers_hex(const std::vector<void *> &v);
2742 
2743  /*
2744  * @}
2745  */
2746 
2770  begin(const unsigned int level = 0) const;
2771 
2803  begin_active(const unsigned int level = 0) const;
2804 
2810  end() const;
2811 
2831  end(const unsigned int level) const;
2832 
2853  end_active(const unsigned int level) const;
2854 
2855 
2860  last() const;
2861 
2866  last_active() const;
2867 
2883  cell_iterators() const;
2884 
2921  active_cell_iterators() const;
2922 
2939  cell_iterators_on_level(const unsigned int level) const;
2940 
2957  active_cell_iterators_on_level(const unsigned int level) const;
2958 
2959  /*
2960  * @}
2961  */
2962 
2963  /*-------------------------------------------------------------------------*/
2964 
2974  begin_face() const;
2975 
2980  begin_active_face() const;
2981 
2987  end_face() const;
2988 
3008  active_face_iterators() const;
3009 
3010  /*
3011  * @}
3012  */
3013 
3014  /*-------------------------------------------------------------------------*/
3015 
3026  begin_vertex() const;
3027 
3034  begin_active_vertex() const;
3035 
3042  end_vertex() const;
3043 
3044  /*
3045  * @}
3046  */
3047 
3065  unsigned int
3066  n_lines() const;
3067 
3071  unsigned int
3072  n_lines(const unsigned int level) const;
3073 
3077  unsigned int
3078  n_active_lines() const;
3079 
3083  unsigned int
3084  n_active_lines(const unsigned int level) const;
3085 
3089  unsigned int
3090  n_quads() const;
3091 
3095  unsigned int
3096  n_quads(const unsigned int level) const;
3097 
3101  unsigned int
3102  n_active_quads() const;
3103 
3107  unsigned int
3108  n_active_quads(const unsigned int level) const;
3109 
3113  unsigned int
3114  n_hexs() const;
3115 
3120  unsigned int
3121  n_hexs(const unsigned int level) const;
3122 
3126  unsigned int
3127  n_active_hexs() const;
3128 
3133  unsigned int
3134  n_active_hexs(const unsigned int level) const;
3135 
3140  unsigned int
3141  n_cells() const;
3142 
3147  unsigned int
3148  n_cells(const unsigned int level) const;
3149 
3154  unsigned int
3155  n_active_cells() const;
3156 
3164  virtual types::global_dof_index
3165  n_global_active_cells() const;
3166 
3167 
3172  unsigned int
3173  n_active_cells(const unsigned int level) const;
3174 
3180  unsigned int
3181  n_faces() const;
3182 
3188  unsigned int
3189  n_active_faces() const;
3190 
3208  unsigned int
3209  n_levels() const;
3210 
3217  virtual unsigned int
3218  n_global_levels() const;
3219 
3229  virtual bool
3230  has_hanging_nodes() const;
3231 
3239  unsigned int
3240  n_vertices() const;
3241 
3250  const std::vector<Point<spacedim>> &
3251  get_vertices() const;
3252 
3257  unsigned int
3258  n_used_vertices() const;
3259 
3263  bool
3264  vertex_used(const unsigned int index) const;
3265 
3270  const std::vector<bool> &
3271  get_used_vertices() const;
3272 
3284  unsigned int
3285  max_adjacent_cells() const;
3286 
3293  virtual types::subdomain_id
3294  locally_owned_subdomain() const;
3295 
3306  get_triangulation();
3307 
3313  get_triangulation() const;
3314 
3315 
3316  /*
3317  * @}
3318  */
3319 
3334  unsigned int
3335  n_raw_lines() const;
3336 
3346  unsigned int
3347  n_raw_lines(const unsigned int level) const;
3348 
3358  unsigned int
3359  n_raw_quads() const;
3360 
3370  unsigned int
3371  n_raw_quads(const unsigned int level) const;
3372 
3382  unsigned int
3383  n_raw_hexs(const unsigned int level) const;
3384 
3394  unsigned int
3395  n_raw_cells(const unsigned int level) const;
3396 
3408  unsigned int
3409  n_raw_faces() const;
3410 
3411  /*
3412  * @}
3413  */
3414 
3423  virtual std::size_t
3424  memory_consumption() const;
3425 
3434  template <class Archive>
3435  void
3436  save(Archive &ar, const unsigned int version) const;
3437 
3453  template <class Archive>
3454  void
3455  load(Archive &ar, const unsigned int version);
3456 
3457 
3473  virtual void
3474  add_periodicity(
3475  const std::vector<GridTools::PeriodicFacePair<cell_iterator>> &);
3476 
3480  const std::map<
3481  std::pair<cell_iterator, unsigned int>,
3482  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>> &
3483  get_periodic_face_map() const;
3484 
3485 
3486  BOOST_SERIALIZATION_SPLIT_MEMBER()
3487 
3488 
3498  DeclException2(ExcInvalidLevel,
3499  int,
3500  int,
3501  << "You are requesting information from refinement level "
3502  << arg1
3503  << " of a triangulation, but this triangulation only has "
3504  << arg2 << " refinement levels. The given level " << arg1
3505  << " must be *less* than " << arg2 << ".");
3513  ExcTriangulationNotEmpty,
3514  int,
3515  int,
3516  << "You are trying to perform an operation on a triangulation "
3517  << "that is only allowed if the triangulation is currently empty. "
3518  << "However, it currently stores " << arg1 << " vertices and has "
3519  << "cells on " << arg2 << " levels.");
3525  DeclException0(ExcGridReadError);
3536  DeclException1(ExcEmptyLevel,
3537  int,
3538  << "You tried to do something on level " << arg1
3539  << ", but this level is empty.");
3545  DeclException0(ExcNonOrientableTriangulation);
3546 
3554  DeclException1(ExcBoundaryIdNotFound,
3555  types::boundary_id,
3556  << "The given boundary_id " << arg1
3557  << " is not defined in this Triangulation!");
3558 
3559  /*
3560  * @}
3561  */
3562 
3563 protected:
3568  MeshSmoothing smooth_grid;
3569 
3583  static void
3584  write_bool_vector(const unsigned int magic_number1,
3585  const std::vector<bool> &v,
3586  const unsigned int magic_number2,
3587  std::ostream & out);
3588 
3593  static void
3594  read_bool_vector(const unsigned int magic_number1,
3595  std::vector<bool> &v,
3596  const unsigned int magic_number2,
3597  std::istream & in);
3598 
3603  void
3604  update_periodic_face_map();
3605 
3606 
3607 private:
3614  std::vector<GridTools::PeriodicFacePair<cell_iterator>>
3615  periodic_face_pairs_level_0;
3616 
3621  std::map<std::pair<cell_iterator, unsigned int>,
3622  std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3>>>
3623  periodic_face_map;
3624 
3639  using raw_face_iterator =
3640  TriaRawIterator<TriaAccessor<dim - 1, dim, spacedim>>;
3641  using raw_vertex_iterator =
3642  TriaRawIterator<::TriaAccessor<0, dim, spacedim>>;
3643  using raw_line_iterator = typename IteratorSelector::raw_line_iterator;
3644  using raw_quad_iterator = typename IteratorSelector::raw_quad_iterator;
3645  using raw_hex_iterator = typename IteratorSelector::raw_hex_iterator;
3646 
3652  begin_raw(const unsigned int level = 0) const;
3653 
3659  end_raw(const unsigned int level) const;
3660 
3661  /*
3662  * @}
3663  */
3664 
3676  raw_line_iterator
3677  begin_raw_line(const unsigned int level = 0) const;
3678 
3697  begin_line(const unsigned int level = 0) const;
3698 
3717  begin_active_line(const unsigned int level = 0) const;
3718 
3724  end_line() const;
3725 
3726  /*
3727  * @}
3728  */
3729 
3754  raw_quad_iterator
3755  begin_raw_quad(const unsigned int level = 0) const;
3756 
3775  begin_quad(const unsigned int level = 0) const;
3776 
3795  begin_active_quad(const unsigned int level = 0) const;
3796 
3802  end_quad() const;
3803 
3804  /*
3805  * @}
3806  */
3807 
3831  raw_hex_iterator
3832  begin_raw_hex(const unsigned int level = 0) const;
3833 
3851  hex_iterator
3852  begin_hex(const unsigned int level = 0) const;
3853 
3872  begin_active_hex(const unsigned int level = 0) const;
3873 
3878  hex_iterator
3879  end_hex() const;
3880 
3881  /*
3882  * @}
3883  */
3884 
3885 
3899  void
3900  clear_despite_subscriptions();
3901 
3908  void
3909  reset_active_cell_indices();
3910 
3924  DistortedCellList
3925  execute_refinement();
3926 
3933  void
3934  execute_coarsening();
3935 
3940  void
3941  fix_coarsen_flags();
3942 
3947  std::vector<std::unique_ptr<
3948  ::internal::TriangulationImplementation::TriaLevel<dim>>>
3949  levels;
3950 
3956  std::unique_ptr<::internal::TriangulationImplementation::TriaFaces<dim>>
3957  faces;
3958 
3959 
3963  std::vector<Point<spacedim>> vertices;
3964 
3968  std::vector<bool> vertices_used;
3969 
3974  std::map<types::manifold_id, std::unique_ptr<const Manifold<dim, spacedim>>>
3975  manifold;
3976 
3980  bool anisotropic_refinement;
3981 
3982 
3987  const bool check_for_distorted_cells;
3988 
3998  ::internal::TriangulationImplementation::NumberCache<dim> number_cache;
3999 
4014  std::unique_ptr<std::map<unsigned int, types::boundary_id>>
4015  vertex_to_boundary_id_map_1d;
4016 
4017 
4037  std::unique_ptr<std::map<unsigned int, types::manifold_id>>
4038  vertex_to_manifold_id_map_1d;
4039 
4040  // make a couple of classes friends
4041  template <int, int, int>
4042  friend class TriaAccessorBase;
4043  template <int, int, int>
4044  friend class TriaAccessor;
4045  friend class TriaAccessor<0, 1, spacedim>;
4046 
4047  friend class CellAccessor<dim, spacedim>;
4048 
4049  friend struct ::internal::TriaAccessorImplementation::Implementation;
4050 
4051  friend class hp::DoFHandler<dim, spacedim>;
4052 
4053  friend struct ::internal::TriangulationImplementation::Implementation;
4054 
4055  template <typename>
4056  friend class ::internal::TriangulationImplementation::TriaObjects;
4057 
4058  // explicitly check for sensible template arguments, but not on windows
4059  // because MSVC creates bogus warnings during normal compilation
4060 #ifndef DEAL_II_MSVC
4061  static_assert(dim <= spacedim,
4062  "The dimension <dim> of a Triangulation must be less than or "
4063  "equal to the space dimension <spacedim> in which it lives.");
4064 #endif
4065 };
4066 
4067 
4068 #ifndef DOXYGEN
4069 
4070 
4071 template <int structdim>
4073 {
4074  for (unsigned int i = 0; i < GeometryInfo<structdim>::vertices_per_cell; ++i)
4075  vertices[i] = numbers::invalid_unsigned_int;
4076 
4077  material_id = 0;
4078 
4079  // And the manifold to be invalid
4080  manifold_id = numbers::flat_manifold_id;
4081 }
4082 
4083 
4084 
4085 namespace internal
4086 {
4087  namespace TriangulationImplementation
4088  {
4089  template <class Archive>
4090  void
4091  NumberCache<1>::serialize(Archive &ar, const unsigned int)
4092  {
4093  ar &n_levels;
4094  ar &n_lines &n_lines_level;
4095  ar &n_active_lines &n_active_lines_level;
4096  }
4097 
4098 
4099  template <class Archive>
4100  void
4101  NumberCache<2>::serialize(Archive &ar, const unsigned int version)
4102  {
4103  this->NumberCache<1>::serialize(ar, version);
4104 
4105  ar &n_quads &n_quads_level;
4106  ar &n_active_quads &n_active_quads_level;
4107  }
4108 
4109 
4110  template <class Archive>
4111  void
4112  NumberCache<3>::serialize(Archive &ar, const unsigned int version)
4113  {
4114  this->NumberCache<2>::serialize(ar, version);
4115 
4116  ar &n_hexes &n_hexes_level;
4117  ar &n_active_hexes &n_active_hexes_level;
4118  }
4119 
4120  } // namespace TriangulationImplementation
4121 } // namespace internal
4122 
4123 
4124 template <int dim, int spacedim>
4125 inline bool
4126 Triangulation<dim, spacedim>::vertex_used(const unsigned int index) const
4127 {
4128  Assert(index < vertices_used.size(),
4129  ExcIndexRange(index, 0, vertices_used.size()));
4130  return vertices_used[index];
4131 }
4132 
4133 
4134 
4135 template <int dim, int spacedim>
4136 inline unsigned int
4138 {
4139  return number_cache.n_levels;
4140 }
4141 
4142 template <int dim, int spacedim>
4143 inline unsigned int
4145 {
4146  return number_cache.n_levels;
4147 }
4148 
4149 
4150 template <int dim, int spacedim>
4151 inline unsigned int
4153 {
4154  return vertices.size();
4155 }
4156 
4157 
4158 
4159 template <int dim, int spacedim>
4160 inline const std::vector<Point<spacedim>> &
4162 {
4163  return vertices;
4164 }
4165 
4166 
4167 template <int dim, int spacedim>
4168 template <class Archive>
4169 void
4170 Triangulation<dim, spacedim>::save(Archive &ar, const unsigned int) const
4171 {
4172  // as discussed in the documentation, do not store the signals as
4173  // well as boundary and manifold description but everything else
4174  ar &smooth_grid;
4175 
4176  unsigned int n_levels = levels.size();
4177  ar & n_levels;
4178  for (unsigned int i = 0; i < levels.size(); ++i)
4179  ar &levels[i];
4180 
4181  // boost dereferences a nullptr when serializing a nullptr
4182  // at least up to 1.65.1. This causes problems with clang-5.
4183  // Therefore, work around it.
4184  bool faces_is_nullptr = (faces.get() == nullptr);
4185  ar & faces_is_nullptr;
4186  if (!faces_is_nullptr)
4187  ar &faces;
4188 
4189  ar &vertices;
4190  ar &vertices_used;
4191 
4192  ar &anisotropic_refinement;
4193  ar &number_cache;
4194 
4195  ar &check_for_distorted_cells;
4196 
4197  if (dim == 1)
4198  {
4199  ar &vertex_to_boundary_id_map_1d;
4200  ar &vertex_to_manifold_id_map_1d;
4201  }
4202 }
4203 
4204 
4205 
4206 template <int dim, int spacedim>
4207 template <class Archive>
4208 void
4209 Triangulation<dim, spacedim>::load(Archive &ar, const unsigned int)
4210 {
4211  // clear previous content. this also calls the respective signal
4212  clear();
4213 
4214  // as discussed in the documentation, do not store the signals as
4215  // well as boundary and manifold description but everything else
4216  ar &smooth_grid;
4217 
4218  unsigned int size;
4219  ar & size;
4220  levels.resize(size);
4221  for (unsigned int i = 0; i < levels.size(); ++i)
4222  {
4223  std::unique_ptr<internal::TriangulationImplementation::TriaLevel<dim>>
4224  level;
4225  ar &level;
4226  levels[i] = std::move(level);
4227  }
4228 
4229  // Workaround for nullptr, see in save().
4230  bool faces_is_nullptr = true;
4231  ar & faces_is_nullptr;
4232  if (!faces_is_nullptr)
4233  ar &faces;
4234 
4235  ar &vertices;
4236  ar &vertices_used;
4237 
4238  ar &anisotropic_refinement;
4239  ar &number_cache;
4240 
4241  // the levels do not serialize the active_cell_indices because
4242  // they are easy enough to rebuild upon re-loading data. do
4243  // this here. don't forget to first resize the fields appropriately
4244  {
4245  for (unsigned int l = 0; l < levels.size(); ++l)
4246  levels[l]->active_cell_indices.resize(levels[l]->refine_flags.size());
4247  reset_active_cell_indices();
4248  }
4249 
4250 
4251  bool my_check_for_distorted_cells;
4252  ar & my_check_for_distorted_cells;
4253 
4254  Assert(my_check_for_distorted_cells == check_for_distorted_cells,
4255  ExcMessage("The triangulation loaded into here must have the "
4256  "same setting with regard to reporting distorted "
4257  "cell as the one previously stored."));
4258 
4259  if (dim == 1)
4260  {
4261  ar &vertex_to_boundary_id_map_1d;
4262  ar &vertex_to_manifold_id_map_1d;
4263  }
4264 
4265  // trigger the create signal to indicate
4266  // that new content has been imported into
4267  // the triangulation
4268  signals.create();
4269 }
4270 
4271 
4272 /* -------------- declaration of explicit specializations ------------- */
4273 
4274 template <>
4275 unsigned int
4276 Triangulation<1, 1>::n_raw_lines(const unsigned int level) const;
4277 template <>
4278 unsigned int
4280 template <>
4281 unsigned int
4282 Triangulation<1, 1>::n_quads(const unsigned int level) const;
4283 template <>
4284 unsigned int
4285 Triangulation<1, 1>::n_raw_quads(const unsigned int level) const;
4286 template <>
4287 unsigned int
4288 Triangulation<2, 2>::n_raw_quads(const unsigned int level) const;
4289 template <>
4290 unsigned int
4291 Triangulation<1, 1>::n_raw_hexs(const unsigned int level) const;
4292 template <>
4293 unsigned int
4294 Triangulation<1, 1>::n_active_quads(const unsigned int level) const;
4295 template <>
4296 unsigned int
4298 template <>
4299 unsigned int
4301 
4302 
4303 // -------------------------------------------------------------------
4304 // -- Explicit specializations for codimension one grids
4305 
4306 
4307 template <>
4308 unsigned int
4309 Triangulation<1, 2>::n_raw_lines(const unsigned int level) const;
4310 template <>
4311 unsigned int
4313 template <>
4314 unsigned int
4315 Triangulation<1, 2>::n_quads(const unsigned int level) const;
4316 template <>
4317 unsigned int
4318 Triangulation<1, 2>::n_raw_quads(const unsigned int level) const;
4319 template <>
4320 unsigned int
4321 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4322 template <>
4323 unsigned int
4324 Triangulation<1, 2>::n_raw_hexs(const unsigned int level) const;
4325 template <>
4326 unsigned int
4327 Triangulation<1, 2>::n_active_quads(const unsigned int level) const;
4328 template <>
4329 unsigned int
4331 template <>
4332 unsigned int
4334 
4335 // -------------------------------------------------------------------
4336 // -- Explicit specializations for codimension two grids
4337 
4338 
4339 template <>
4340 unsigned int
4341 Triangulation<1, 3>::n_raw_lines(const unsigned int level) const;
4342 template <>
4343 unsigned int
4345 template <>
4346 unsigned int
4347 Triangulation<1, 3>::n_quads(const unsigned int level) const;
4348 template <>
4349 unsigned int
4350 Triangulation<1, 3>::n_raw_quads(const unsigned int level) const;
4351 template <>
4352 unsigned int
4353 Triangulation<2, 3>::n_raw_quads(const unsigned int level) const;
4354 template <>
4355 unsigned int
4356 Triangulation<1, 3>::n_raw_hexs(const unsigned int level) const;
4357 template <>
4358 unsigned int
4359 Triangulation<1, 3>::n_active_quads(const unsigned int level) const;
4360 template <>
4361 unsigned int
4363 template <>
4364 unsigned int
4366 
4367 
4368 #endif // DOXYGEN
4369 
4370 DEAL_II_NAMESPACE_CLOSE
4371 
4372 // Include tria_accessor.h here, so that it is possible for an end
4373 // user to use the iterators of Triangulation<dim> directly without
4374 // the need to include tria_accessor.h separately. (Otherwise the
4375 // iterators are an 'opaque' or 'incomplete' type.)
4376 #include <deal.II/grid/tria_accessor.h>
4377 
4378 #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:2262
boost::signals2::signal< void()> post_refinement
Definition: tria.h:2214
unsigned int n_vertices() const
const types::manifold_id flat_manifold_id
Definition: types.h:246
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:2242
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
boost::signals2::signal< void()> post_distributed_repartition
Definition: tria.h:2358
typename IteratorSelector::line_iterator line_iterator
Definition: tria.h:1592
typename IteratorSelector::hex_iterator hex_iterator
Definition: tria.h:1640
typename IteratorSelector::active_line_iterator active_line_iterator
Definition: tria.h:1607
boost::signals2::signal< void()> pre_distributed_refinement
Definition: tria.h:2329
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()
unsigned int n_levels() const
Definition: tria.h:81
static ::ExceptionBase & ExcMessage(std::string arg1)
boost::signals2::signal< void()> pre_refinement
Definition: tria.h:2207
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:12996
#define Assert(cond, exc)
Definition: exceptions.h:1407
Signals signals
Definition: tria.h:2394
boost::signals2::signal< void()> clear
Definition: tria.h:2277
::internal::TriangulationImplementation::Iterators< dim, dim > IteratorSelector
Definition: tria.h:1285
unsigned int n_raw_hexs(const unsigned int level) const
Definition: tria.cc:13053
unsigned int max_adjacent_cells() const
Definition: tria.cc:13176
void load(Archive &ar, const unsigned int version)
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
Definition: tria.h:1686
unsigned int n_quads() const
Definition: tria.cc:12947
#define DeclException0(Exception0)
Definition: exceptions.h:473
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> post_refinement_on_cell
Definition: tria.h:2252
typename IteratorSelector::active_quad_iterator active_quad_iterator
Definition: tria.h:1631
types::material_id material_id
Definition: tria.h:160
const std::vector< Point< spacedim > > & get_vertices() const
boost::signals2::signal< void()> mesh_movement
Definition: tria.h:2231
unsigned int n_raw_lines() const
Definition: tria.cc:12762
boost::signals2::signal< void()> pre_distributed_save
Definition: tria.h:2366
void save(Archive &ar, const unsigned int version) const
typename IteratorSelector::quad_iterator quad_iterator
Definition: tria.h:1616
boost::signals2::signal< void()> create
Definition: tria.h:2198
Definition: hp.h:117
unsigned int n_active_quads() const
Definition: tria.cc:13015
types::manifold_id manifold_id
Definition: tria.h:182
boost::signals2::signal< void()> pre_partition
Definition: tria.h:2222
typename IteratorSelector::active_hex_iterator active_hex_iterator
Definition: tria.h:1651
unsigned int global_dof_index
Definition: types.h:89
boost::signals2::signal< void()> post_distributed_save
Definition: tria.h:2373
std::vector< unsigned int > n_active_hexes_level
Definition: tria.h:467
virtual unsigned int n_global_levels() 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:2316
boost::signals2::signal< void()> pre_distributed_load
Definition: tria.h:2381
std::vector< unsigned int > n_active_lines_level
Definition: tria.h:348
std::vector< unsigned int > n_active_quads_level
Definition: tria.h:407
boost::signals2::signal< void()> post_distributed_load
Definition: tria.h:2388
unsigned int boundary_id
Definition: types.h:111
boost::signals2::signal< void()> pre_distributed_repartition
Definition: tria.h:2351
bool vertex_used(const unsigned int index) const
boost::signals2::signal< void()> any_change
Definition: tria.h:2288
boost::signals2::signal< void()> post_distributed_refinement
Definition: tria.h:2339