Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_tria_h
17 #define dealii_tria_h
18 
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/point.h>
22 #include <deal.II/base/subscriptor.h>
23 #include <deal.II/base/smartpointer.h>
24 #include <deal.II/base/geometry_info.h>
25 #include <deal.II/base/iterator_range.h>
26 #include <deal.II/grid/tria_iterator_selector.h>
27 
28 #include <boost/signals2.hpp>
29 #include <boost/serialization/vector.hpp>
30 #include <boost/serialization/map.hpp>
31 #include <boost/serialization/unique_ptr.hpp>
32 #include <boost/serialization/split_member.hpp>
33 
34 #include <vector>
35 #include <list>
36 #include <map>
37 #include <numeric>
38 #include <bitset>
39 #include <functional>
40 #include <memory>
41 
42 
43 DEAL_II_NAMESPACE_OPEN
44 
45 template <int dim, int spacedim> class Boundary;
46 template <int dim, int spacedim> class StraightBoundary;
47 template <int dim, int spacedim> class Manifold;
48 
49 namespace GridTools
50 {
51  template <typename CellIterator> struct PeriodicFacePair;
52 }
53 
54 template <int, int, int> class TriaAccessor;
55 template <int spacedim> class TriaAccessor<0,1,spacedim>;
56 template <int, int, int> class TriaAccessorBase;
57 
58 namespace internal
59 {
60  namespace TriangulationImplementation
61  {
62  template <int dim> class TriaLevel;
63  template <int dim> class TriaFaces;
64 
65  template <typename> class TriaObjects;
66 
72  struct Implementation;
73  }
74 
75  namespace TriaAccessorImplementation
76  {
77  struct Implementation;
78  }
79 }
80 
81 namespace hp
82 {
83  template <int dim, int spacedim> class DoFHandler;
84 }
85 
86 
87 /*------------------------------------------------------------------------*/
88 
124 template <int structdim>
125 struct CellData
126 {
133 
141  union
142  {
152 
163  };
164 
174 
182  CellData ();
183 };
184 
185 
186 
242 {
249  std::vector<CellData<1> > boundary_lines;
250 
257  std::vector<CellData<2> > boundary_quads;
258 
266  bool check_consistency (const unsigned int dim) const;
267 };
268 
269 
270 /*------------------------------------------------------------------------*/
271 
272 
273 namespace internal
274 {
279  namespace TriangulationImplementation
280  {
281 
295  template <int dim>
296  struct NumberCache
297  {
298  };
299 
313  template <>
314  struct NumberCache<1>
315  {
319  unsigned int n_levels;
320 
324  unsigned int n_lines;
325 
329  std::vector<unsigned int> n_lines_level;
330 
334  unsigned int n_active_lines;
335 
339  std::vector<unsigned int> n_active_lines_level;
340 
344  NumberCache ();
345 
350  std::size_t memory_consumption () const;
351 
356  template <class Archive>
357  void serialize (Archive &ar,
358  const unsigned int version);
359  };
360 
361 
376  template <>
377  struct NumberCache<2> : public NumberCache<1>
378  {
382  unsigned int n_quads;
383 
387  std::vector<unsigned int> n_quads_level;
388 
392  unsigned int n_active_quads;
393 
397  std::vector<unsigned int> n_active_quads_level;
398 
402  NumberCache ();
403 
408  std::size_t memory_consumption () const;
409 
414  template <class Archive>
415  void serialize (Archive &ar,
416  const unsigned int version);
417  };
418 
419 
435  template <>
436  struct NumberCache<3> : public NumberCache<2>
437  {
441  unsigned int n_hexes;
442 
446  std::vector<unsigned int> n_hexes_level;
447 
451  unsigned int n_active_hexes;
452 
456  std::vector<unsigned int> n_active_hexes_level;
457 
461  NumberCache ();
462 
467  std::size_t memory_consumption () const;
468 
473  template <class Archive>
474  void serialize (Archive &ar,
475  const unsigned int version);
476  };
477  }
478 }
479 
480 
481 /*------------------------------------------------------------------------*/
482 
483 
1268 template <int dim, int spacedim=dim>
1269 class Triangulation : public Subscriptor
1270 {
1271 private:
1272 
1277  typedef ::internal::TriangulationImplementation::Iterators<dim, spacedim> IteratorSelector;
1278 
1279 public:
1287  DEAL_II_DEPRECATED
1289 
1295  {
1300  none = 0x0,
1471 
1485 
1492  };
1493 
1510 
1528 
1542  typedef TriaIterator <TriaAccessor<dim-1, dim, spacedim> > face_iterator;
1543 
1555  typedef TriaActiveIterator<TriaAccessor<dim-1, dim, spacedim> > active_face_iterator;
1556 
1566 
1580 
1581  typedef typename IteratorSelector::line_iterator line_iterator;
1582  typedef typename IteratorSelector::active_line_iterator active_line_iterator;
1583 
1584  typedef typename IteratorSelector::quad_iterator quad_iterator;
1585  typedef typename IteratorSelector::active_quad_iterator active_quad_iterator;
1586 
1587  typedef typename IteratorSelector::hex_iterator hex_iterator;
1588  typedef typename IteratorSelector::active_hex_iterator active_hex_iterator;
1589 
1609  {
1616  virtual ~DistortedCellList () noexcept;
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 
1651  const bool check_for_distorted_cells = false);
1652 
1668  Triangulation (const Triangulation<dim, spacedim> &) = delete;
1669 
1676  Triangulation (Triangulation<dim, spacedim> &&tria) noexcept;
1677 
1682 
1686  virtual ~Triangulation ();
1687 
1694  virtual void clear ();
1695 
1701  virtual void set_mesh_smoothing (const MeshSmoothing mesh_smoothing);
1702 
1706  virtual const MeshSmoothing &get_mesh_smoothing() const;
1707 
1748  DEAL_II_DEPRECATED
1749  void set_boundary (const types::manifold_id number,
1750  const Boundary<dim,spacedim> &boundary_object);
1751 
1752 
1767  DEAL_II_DEPRECATED
1768  void set_boundary (const types::manifold_id number);
1769 
1793  void set_manifold (const types::manifold_id number,
1794  const Manifold<dim,spacedim> &manifold_object);
1795 
1796 
1811  DEAL_II_DEPRECATED
1812  void set_manifold (const types::manifold_id number);
1813 
1826  void reset_manifold (const types::manifold_id manifold_number);
1827 
1839  void reset_all_manifolds ();
1840 
1849  void set_all_manifold_ids (const types::manifold_id number);
1850 
1860 
1871  const types::manifold_id number);
1872 
1873 
1886  DEAL_II_DEPRECATED
1887  const Boundary<dim,spacedim> &get_boundary (const types::manifold_id number) const;
1888 
1898  const Manifold<dim,spacedim> &get_manifold (const types::manifold_id number) const;
1899 
1911  std::vector<types::boundary_id> get_boundary_ids() const;
1912 
1924  std::vector<types::manifold_id> get_manifold_ids() const;
1925 
1952  virtual void copy_triangulation (const Triangulation<dim, spacedim> &other_tria);
1953 
1997  virtual void create_triangulation (const std::vector<Point<spacedim> > &vertices,
1998  const std::vector<CellData<dim> > &cells,
1999  const SubCellData &subcelldata);
2000 
2009  virtual void create_triangulation_compatibility (
2010  const std::vector<Point<spacedim> > &vertices,
2011  const std::vector<CellData<dim> > &cells,
2012  const SubCellData &subcelldata);
2013 
2020  void flip_all_direction_flags();
2021 
2033  void set_all_refine_flags ();
2034 
2049  void refine_global (const unsigned int times = 1);
2050 
2082  virtual void execute_coarsening_and_refinement ();
2083 
2113  virtual bool prepare_coarsening_and_refinement ();
2114 
2115  /*
2116  * @}
2117  */
2118 
2133  {
2151  };
2152 
2158  template <typename T>
2160  {
2161  typedef T result_type;
2162 
2163  template <typename InputIterator>
2164  T operator()(InputIterator first, InputIterator last) const
2165  {
2166  return std::accumulate (first, last, T());
2167  }
2168  };
2169 
2179  struct Signals
2180  {
2188  boost::signals2::signal<void ()> create;
2189 
2197  boost::signals2::signal<void ()> pre_refinement;
2198 
2204  boost::signals2::signal<void ()> post_refinement;
2205 
2213  boost::signals2::signal<void ()> mesh_movement;
2214 
2222  boost::signals2::signal<void (const typename Triangulation<dim, spacedim>::cell_iterator &cell)> pre_coarsening_on_cell;
2223 
2230  boost::signals2::signal<void (const typename Triangulation<dim, spacedim>::cell_iterator &cell)> post_refinement_on_cell;
2231 
2238  boost::signals2::signal<void (const Triangulation<dim, spacedim> &destination_tria)> copy;
2239 
2253  boost::signals2::signal<void ()> clear;
2254 
2264  boost::signals2::signal<void ()> any_change;
2265 
2289  boost::signals2::signal<unsigned int (const cell_iterator &,
2290  const CellStatus),
2292 
2304  boost::signals2::signal<void ()> pre_distributed_refinement;
2305 
2314  boost::signals2::signal<void ()> post_distributed_refinement;
2315 
2322  boost::signals2::signal<void ()> pre_distributed_save;
2323 
2329  boost::signals2::signal<void ()> post_distributed_load;
2330  };
2331 
2335  mutable Signals signals;
2336 
2337  /*
2338  * @}
2339  */
2340 
2350  void save_refine_flags (std::ostream &out) const;
2351 
2355  void save_refine_flags (std::vector<bool> &v) const;
2356 
2360  void load_refine_flags (std::istream &in);
2361 
2365  void load_refine_flags (const std::vector<bool> &v);
2366 
2370  void save_coarsen_flags (std::ostream &out) const;
2371 
2375  void save_coarsen_flags (std::vector<bool> &v) const;
2376 
2380  void load_coarsen_flags (std::istream &out);
2381 
2385  void load_coarsen_flags (const std::vector<bool> &v);
2386 
2391  bool get_anisotropic_refinement_flag() const;
2392 
2393  /*
2394  * @}
2395  */
2396 
2406  void clear_user_flags ();
2407 
2413  void save_user_flags (std::ostream &out) const;
2414 
2420  void save_user_flags (std::vector<bool> &v) const;
2421 
2426  void load_user_flags (std::istream &in);
2427 
2432  void load_user_flags (const std::vector<bool> &v);
2433 
2438  void clear_user_flags_line ();
2439 
2444  void save_user_flags_line (std::ostream &out) const;
2445 
2451  void save_user_flags_line (std::vector<bool> &v) const;
2452 
2457  void load_user_flags_line (std::istream &in);
2458 
2463  void load_user_flags_line (const std::vector<bool> &v);
2464 
2469  void clear_user_flags_quad ();
2470 
2475  void save_user_flags_quad (std::ostream &out) const;
2476 
2482  void save_user_flags_quad (std::vector<bool> &v) const;
2483 
2488  void load_user_flags_quad (std::istream &in);
2489 
2494  void load_user_flags_quad (const std::vector<bool> &v);
2495 
2496 
2501  void clear_user_flags_hex ();
2502 
2507  void save_user_flags_hex (std::ostream &out) const;
2508 
2514  void save_user_flags_hex (std::vector<bool> &v) const;
2515 
2520  void load_user_flags_hex (std::istream &in);
2521 
2526  void load_user_flags_hex (const std::vector<bool> &v);
2527 
2533  void clear_user_data ();
2534 
2540  void save_user_indices (std::vector<unsigned int> &v) const;
2541 
2546  void load_user_indices (const std::vector<unsigned int> &v);
2547 
2553  void save_user_pointers (std::vector<void *> &v) const;
2554 
2559  void load_user_pointers (const std::vector<void *> &v);
2560 
2566  void save_user_indices_line (std::vector<unsigned int> &v) const;
2567 
2572  void load_user_indices_line (const std::vector<unsigned int> &v);
2573 
2579  void save_user_indices_quad (std::vector<unsigned int> &v) const;
2580 
2585  void load_user_indices_quad (const std::vector<unsigned int> &v);
2586 
2592  void save_user_indices_hex (std::vector<unsigned int> &v) const;
2593 
2598  void load_user_indices_hex (const std::vector<unsigned int> &v);
2604  void save_user_pointers_line (std::vector<void *> &v) const;
2605 
2610  void load_user_pointers_line (const std::vector<void *> &v);
2611 
2617  void save_user_pointers_quad (std::vector<void *> &v) const;
2618 
2623  void load_user_pointers_quad (const std::vector<void *> &v);
2624 
2630  void save_user_pointers_hex (std::vector<void *> &v) const;
2631 
2636  void load_user_pointers_hex (const std::vector<void *> &v);
2637 
2638  /*
2639  * @}
2640  */
2641 
2650  cell_iterator begin (const unsigned int level = 0) const;
2651 
2664  active_cell_iterator begin_active(const unsigned int level = 0) const;
2665 
2670  cell_iterator end () const;
2671 
2676  cell_iterator end (const unsigned int level) const;
2677 
2683  active_cell_iterator end_active (const unsigned int level) const;
2684 
2685 
2689  cell_iterator last () const;
2690 
2695 
2711 
2748 
2764  IteratorRange<cell_iterator> cell_iterators_on_level (const unsigned int level) const;
2765 
2782 
2783  /*
2784  * @}
2785  */
2786 
2787  /*---------------------------------------*/
2788  /*---------------------------------------*/
2789 
2798  face_iterator begin_face () const;
2799 
2804 
2809  face_iterator end_face () const;
2810 
2811  /*
2812  * @}
2813  */
2814 
2815  /*---------------------------------------*/
2816  /*---------------------------------------*/
2817 
2827  vertex_iterator begin_vertex() const;
2828 
2835 
2841  vertex_iterator end_vertex() const;
2842 
2843  /*
2844  * @}
2845  */
2846 
2864  unsigned int n_lines () const;
2865 
2869  unsigned int n_lines (const unsigned int level) const;
2870 
2874  unsigned int n_active_lines () const;
2875 
2879  unsigned int n_active_lines (const unsigned int level) const;
2880 
2884  unsigned int n_quads () const;
2885 
2889  unsigned int n_quads (const unsigned int level) const;
2890 
2894  unsigned int n_active_quads () const;
2895 
2899  unsigned int n_active_quads (const unsigned int level) const;
2900 
2904  unsigned int n_hexs() const;
2905 
2910  unsigned int n_hexs(const unsigned int level) const;
2911 
2915  unsigned int n_active_hexs() const;
2916 
2921  unsigned int n_active_hexs(const unsigned int level) const;
2922 
2927  unsigned int n_cells () const;
2928 
2933  unsigned int n_cells (const unsigned int level) const;
2934 
2939  unsigned int n_active_cells () const;
2940 
2949 
2950 
2955  unsigned int n_active_cells (const unsigned int level) const;
2956 
2962  unsigned int n_faces () const;
2963 
2969  unsigned int n_active_faces () const;
2970 
2988  unsigned int n_levels () const;
2989 
2996  virtual
2997  unsigned int n_global_levels () const;
2998 
3008  virtual
3009  bool has_hanging_nodes() const;
3010 
3018  unsigned int n_vertices () const;
3019 
3028  const std::vector<Point<spacedim> > &
3029  get_vertices () const;
3030 
3035  unsigned int n_used_vertices () const;
3036 
3040  bool vertex_used (const unsigned int index) const;
3041 
3046  const std::vector<bool> &
3047  get_used_vertices () const;
3048 
3060  unsigned int max_adjacent_cells () const;
3061 
3069 
3080  get_triangulation ();
3081 
3087  get_triangulation () const;
3088 
3089 
3090  /*
3091  * @}
3092  */
3093 
3108  unsigned int n_raw_lines () const;
3109 
3119  unsigned int n_raw_lines (const unsigned int level) const;
3120 
3130  unsigned int n_raw_quads () const;
3131 
3141  unsigned int n_raw_quads (const unsigned int level) const;
3142 
3152  unsigned int n_raw_hexs (const unsigned int level) const;
3153 
3163  unsigned int n_raw_cells (const unsigned int level) const;
3164 
3175  unsigned int n_raw_faces () const;
3176 
3177  /*
3178  * @}
3179  */
3180 
3189  virtual std::size_t memory_consumption () const;
3190 
3199  template <class Archive>
3200  void save (Archive &ar,
3201  const unsigned int version) const;
3202 
3218  template <class Archive>
3219  void load (Archive &ar,
3220  const unsigned int version);
3221 
3222 
3238  virtual void
3240  (const std::vector<GridTools::PeriodicFacePair<cell_iterator> > &);
3241 
3245  const std::map<std::pair<cell_iterator, unsigned int>,std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3> > > &
3246  get_periodic_face_map() const;
3247 
3248 
3249  BOOST_SERIALIZATION_SPLIT_MEMBER()
3250 
3251 
3262  int,
3263  << "The given level " << arg1
3264  << " is not in the valid range!");
3272  int, int,
3273  << "You are trying to perform an operation on a triangulation "
3274  << "that is only allowed if the triangulation is currently empty. "
3275  << "However, it currently stores " << arg1 << " vertices and has "
3276  << "cells on " << arg2 << " levels.");
3294  int,
3295  << "You tried to do something on level " << arg1
3296  << ", but this level is empty.");
3303 
3312  types::boundary_id,
3313  << "The given boundary_id " << arg1
3314  << " is not defined in this Triangulation!");
3315 
3316  /*
3317  * @}
3318  */
3319 
3320 protected:
3326 
3340  static void write_bool_vector (const unsigned int magic_number1,
3341  const std::vector<bool> &v,
3342  const unsigned int magic_number2,
3343  std::ostream &out);
3344 
3349  static void read_bool_vector (const unsigned int magic_number1,
3350  std::vector<bool> &v,
3351  const unsigned int magic_number2,
3352  std::istream &in);
3353 
3357  void update_periodic_face_map ();
3358 
3359 
3360 private:
3368 
3372  std::map<std::pair<cell_iterator, unsigned int>, std::pair<std::pair<cell_iterator, unsigned int>, std::bitset<3> > > periodic_face_map;
3373 
3388  typedef TriaRawIterator<TriaAccessor<dim-1, dim, spacedim> > raw_face_iterator;
3389  typedef TriaRawIterator<::TriaAccessor<0, dim, spacedim> > raw_vertex_iterator;
3390  typedef typename IteratorSelector::raw_line_iterator raw_line_iterator;
3391  typedef typename IteratorSelector::raw_quad_iterator raw_quad_iterator;
3392  typedef typename IteratorSelector::raw_hex_iterator raw_hex_iterator;
3393 
3398  raw_cell_iterator begin_raw (const unsigned int level = 0) const;
3399 
3404  raw_cell_iterator end_raw (const unsigned int level) const;
3405 
3406  /*
3407  * @}
3408  */
3409 
3421  raw_line_iterator
3422  begin_raw_line (const unsigned int level = 0) const;
3423 
3427  line_iterator
3428  begin_line (const unsigned int level = 0) const;
3429 
3433  active_line_iterator
3434  begin_active_line(const unsigned int level = 0) const;
3435 
3440  line_iterator end_line () const;
3441 
3442  /*
3443  * @}
3444  */
3445 
3456  raw_quad_iterator
3457  begin_raw_quad (const unsigned int level = 0) const;
3458 
3462  quad_iterator
3463  begin_quad (const unsigned int level = 0) const;
3464 
3468  active_quad_iterator
3469  begin_active_quad (const unsigned int level = 0) const;
3470 
3475  quad_iterator
3476  end_quad () const;
3477 
3478  /*
3479  * @}
3480  */
3481 
3491  raw_hex_iterator
3492  begin_raw_hex (const unsigned int level = 0) const;
3493 
3497  hex_iterator
3498  begin_hex (const unsigned int level = 0) const;
3499 
3503  active_hex_iterator
3504  begin_active_hex (const unsigned int level = 0) const;
3505 
3510  hex_iterator
3511  end_hex () const;
3512 
3513  /*
3514  * @}
3515  */
3516 
3517 
3532 
3539  void reset_active_cell_indices ();
3540 
3554  DistortedCellList execute_refinement ();
3555 
3562  void execute_coarsening ();
3563 
3568  void fix_coarsen_flags ();
3569 
3574  std::vector<std::unique_ptr<::internal::TriangulationImplementation::TriaLevel<dim> > > levels;
3575 
3581  std::unique_ptr<::internal::TriangulationImplementation::TriaFaces<dim> > faces;
3582 
3583 
3587  std::vector<Point<spacedim> > vertices;
3588 
3592  std::vector<bool> vertices_used;
3593 
3598  std::map<types::manifold_id, std::unique_ptr<const Manifold<dim,spacedim> > > manifold;
3599 
3604 
3605 
3611 
3621  ::internal::TriangulationImplementation::NumberCache<dim> number_cache;
3622 
3637  std::unique_ptr<std::map<unsigned int, types::boundary_id> > vertex_to_boundary_id_map_1d;
3638 
3639 
3659  std::unique_ptr<std::map<unsigned int, types::manifold_id> > vertex_to_manifold_id_map_1d;
3660 
3661  // make a couple of classes friends
3662  template <int,int,int> friend class TriaAccessorBase;
3663  template <int,int,int> friend class TriaAccessor;
3664  friend class TriaAccessor<0, 1, spacedim>;
3665 
3666  friend class CellAccessor<dim, spacedim>;
3667 
3668  friend struct ::internal::TriaAccessorImplementation::Implementation;
3669 
3670  friend class hp::DoFHandler<dim,spacedim>;
3671 
3672  friend struct ::internal::TriangulationImplementation::Implementation;
3673 
3674  template <typename>
3675  friend class ::internal::TriangulationImplementation::TriaObjects;
3676 
3677  // explicitly check for sensible template arguments, but not on windows
3678  // because MSVC creates bogus warnings during normal compilation
3679 #ifndef DEAL_II_MSVC
3680  static_assert (dim<=spacedim,
3681  "The dimension <dim> of a Triangulation must be less than or "
3682  "equal to the space dimension <spacedim> in which it lives.");
3683 #endif
3684 
3685 };
3686 
3687 
3688 #ifndef DOXYGEN
3689 
3690 
3691 template <int structdim>
3692 inline
3694 {
3695  for (unsigned int i=0; i<GeometryInfo<structdim>::vertices_per_cell; ++i)
3696  vertices[i] = numbers::invalid_unsigned_int;
3697 
3698  material_id = 0;
3699 
3700  // And the manifold to be invalid
3701  manifold_id = numbers::invalid_manifold_id;
3702 }
3703 
3704 
3705 
3706 namespace internal
3707 {
3708  namespace TriangulationImplementation
3709  {
3710  template <class Archive>
3711  void NumberCache<1>::serialize (Archive &ar,
3712  const unsigned int)
3713  {
3714  ar &n_levels;
3715  ar &n_lines &n_lines_level;
3716  ar &n_active_lines &n_active_lines_level;
3717  }
3718 
3719 
3720  template <class Archive>
3721  void NumberCache<2>::serialize (Archive &ar,
3722  const unsigned int version)
3723  {
3724  this->NumberCache<1>::serialize (ar, version);
3725 
3726  ar &n_quads &n_quads_level;
3727  ar &n_active_quads &n_active_quads_level;
3728  }
3729 
3730 
3731  template <class Archive>
3732  void NumberCache<3>::serialize (Archive &ar,
3733  const unsigned int version)
3734  {
3735  this->NumberCache<2>::serialize (ar, version);
3736 
3737  ar &n_hexes &n_hexes_level;
3738  ar &n_active_hexes &n_active_hexes_level;
3739  }
3740 
3741  }
3742 }
3743 
3744 
3745 template <int dim, int spacedim>
3746 inline
3747 bool
3748 Triangulation<dim,spacedim>::vertex_used(const unsigned int index) const
3749 {
3750  Assert (index < vertices_used.size(),
3751  ExcIndexRange(index, 0, vertices_used.size()));
3752  return vertices_used[index];
3753 }
3754 
3755 
3756 
3757 template <int dim, int spacedim>
3758 inline
3759 unsigned int Triangulation<dim, spacedim>::n_levels () const
3760 {
3761  return number_cache.n_levels;
3762 }
3763 
3764 template <int dim, int spacedim>
3765 inline
3767 {
3768  return number_cache.n_levels;
3769 }
3770 
3771 
3772 template <int dim, int spacedim>
3773 inline
3774 unsigned int
3776 {
3777  return vertices.size();
3778 }
3779 
3780 
3781 
3782 template <int dim, int spacedim>
3783 inline
3784 const std::vector<Point<spacedim> > &
3786 {
3787  return vertices;
3788 }
3789 
3790 
3791 template <int dim, int spacedim>
3792 template <class Archive>
3793 void
3795  const unsigned int) const
3796 {
3797  // as discussed in the documentation, do not store the signals as
3798  // well as boundary and manifold description but everything else
3799  ar &smooth_grid;
3800 
3801  unsigned int n_levels = levels.size();
3802  ar &n_levels;
3803  for (unsigned int i = 0; i < levels.size(); ++i)
3804  ar &levels[i];
3805 
3806  // boost dereferences a nullptr when serializing a nullptr
3807  // at least up to 1.65.1. This causes problems with clang-5.
3808  // Therefore, work around it.
3809  bool faces_is_nullptr = (faces.get()==nullptr);
3810  ar &faces_is_nullptr;
3811  if (!faces_is_nullptr)
3812  ar &faces;
3813 
3814  ar &vertices;
3815  ar &vertices_used;
3816 
3817  ar &anisotropic_refinement;
3818  ar &number_cache;
3819 
3820  ar &check_for_distorted_cells;
3821 
3822  if (dim == 1)
3823  {
3824  ar &vertex_to_boundary_id_map_1d;
3825  ar &vertex_to_manifold_id_map_1d;
3826  }
3827 }
3828 
3829 
3830 
3831 template <int dim, int spacedim>
3832 template <class Archive>
3833 void
3835  const unsigned int)
3836 {
3837  // clear previous content. this also calls the respective signal
3838  clear ();
3839 
3840  // as discussed in the documentation, do not store the signals as
3841  // well as boundary and manifold description but everything else
3842  ar &smooth_grid;
3843 
3844  unsigned int size;
3845  ar &size;
3846  levels.resize(size);
3847  for (unsigned int i = 0; i < levels.size(); ++i)
3848  {
3849  std::unique_ptr<internal::TriangulationImplementation::TriaLevel<dim>> level;
3850  ar &level;
3851  levels[i] = std::move(level);
3852  }
3853 
3854  //Workaround for nullptr, see in save().
3855  bool faces_is_nullptr = true;
3856  ar &faces_is_nullptr;
3857  if (!faces_is_nullptr)
3858  ar &faces;
3859 
3860  ar &vertices;
3861  ar &vertices_used;
3862 
3863  ar &anisotropic_refinement;
3864  ar &number_cache;
3865 
3866  // the levels do not serialize the active_cell_indices because
3867  // they are easy enough to rebuild upon re-loading data. do
3868  // this here. don't forget to first resize the fields appropriately
3869  {
3870  for (unsigned int l=0; l<levels.size(); ++l)
3871  levels[l]->active_cell_indices.resize (levels[l]->refine_flags.size());
3872  reset_active_cell_indices ();
3873  }
3874 
3875 
3876  bool my_check_for_distorted_cells;
3877  ar &my_check_for_distorted_cells;
3878 
3879  Assert (my_check_for_distorted_cells == check_for_distorted_cells,
3880  ExcMessage ("The triangulation loaded into here must have the "
3881  "same setting with regard to reporting distorted "
3882  "cell as the one previously stored."));
3883 
3884  if (dim == 1)
3885  {
3886  ar &vertex_to_boundary_id_map_1d;
3887  ar &vertex_to_manifold_id_map_1d;
3888  }
3889 
3890  // trigger the create signal to indicate
3891  // that new content has been imported into
3892  // the triangulation
3893  signals.create();
3894 }
3895 
3896 
3897 /* -------------- declaration of explicit specializations ------------- */
3898 
3899 template <> unsigned int Triangulation<1,1>::n_raw_lines (const unsigned int level) const;
3900 template <> unsigned int Triangulation<1,1>::n_quads () const;
3901 template <> unsigned int Triangulation<1,1>::n_quads (const unsigned int level) const;
3902 template <> unsigned int Triangulation<1,1>::n_raw_quads (const unsigned int level) const;
3903 template <> unsigned int Triangulation<2,2>::n_raw_quads (const unsigned int level) const;
3904 template <> unsigned int Triangulation<1,1>::n_raw_hexs (const unsigned int level) const;
3905 template <> unsigned int Triangulation<1,1>::n_active_quads (const unsigned int level) const;
3906 template <> unsigned int Triangulation<1,1>::n_active_quads () const;
3907 template <> unsigned int Triangulation<1,1>::max_adjacent_cells () const;
3908 
3909 
3910 // -------------------------------------------------------------------
3911 // -- Explicit specializations for codimension one grids
3912 
3913 
3914 template <> unsigned int Triangulation<1,2>::n_raw_lines (const unsigned int level) const;
3915 template <> unsigned int Triangulation<1,2>::n_quads () const;
3916 template <> unsigned int Triangulation<1,2>::n_quads (const unsigned int level) const;
3917 template <> unsigned int Triangulation<1,2>::n_raw_quads (const unsigned int level) const;
3918 template <> unsigned int Triangulation<2,3>::n_raw_quads (const unsigned int level) const;
3919 template <> unsigned int Triangulation<1,2>::n_raw_hexs (const unsigned int level) const;
3920 template <> unsigned int Triangulation<1,2>::n_active_quads (const unsigned int level) const;
3921 template <> unsigned int Triangulation<1,2>::n_active_quads () const;
3922 template <> unsigned int Triangulation<1,2>::max_adjacent_cells () const;
3923 
3924 // -------------------------------------------------------------------
3925 // -- Explicit specializations for codimension two grids
3926 
3927 
3928 template <> unsigned int Triangulation<1,3>::n_raw_lines (const unsigned int level) const;
3929 template <> unsigned int Triangulation<1,3>::n_quads () const;
3930 template <> unsigned int Triangulation<1,3>::n_quads (const unsigned int level) const;
3931 template <> unsigned int Triangulation<1,3>::n_raw_quads (const unsigned int level) const;
3932 template <> unsigned int Triangulation<2,3>::n_raw_quads (const unsigned int level) const;
3933 template <> unsigned int Triangulation<1,3>::n_raw_hexs (const unsigned int level) const;
3934 template <> unsigned int Triangulation<1,3>::n_active_quads (const unsigned int level) const;
3935 template <> unsigned int Triangulation<1,3>::n_active_quads () const;
3936 template <> unsigned int Triangulation<1,3>::max_adjacent_cells () const;
3937 
3938 
3939 #endif // DOXYGEN
3940 
3941 DEAL_II_NAMESPACE_CLOSE
3942 
3943 // Include tria_accessor.h here, so that it is possible for an end
3944 // user to use the iterators of Triangulation<dim> directly without
3945 // the need to include tria_accessor.h separately. (Otherwise the
3946 // iterators are an 'opaque' or 'incomplete' type.)
3947 #include <deal.II/grid/tria_accessor.h>
3948 
3949 #endif
std::vector< CellData< 1 > > boundary_lines
Definition: tria.h:249
TriaActiveIterator< CellAccessor< dim, spacedim > > active_cell_iterator
Definition: tria.h:1527
boost::signals2::signal< void()> any_change
Definition: tria.h:2264
::internal::TriangulationImplementation::NumberCache< dim > number_cache
Definition: tria.h:3621
unsigned int n_active_cells() const
Definition: tria.cc:11084
void set_boundary(const types::manifold_id number, const Boundary< dim, spacedim > &boundary_object)
Definition: tria.cc:8947
static const unsigned int space_dimension
Definition: tria.h:1634
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:9159
unsigned int n_vertices() const
unsigned int n_used_vertices() const
Definition: tria.cc:11612
static const unsigned int invalid_unsigned_int
Definition: types.h:173
static ::ExceptionBase & ExcInvalidLevel(int arg1)
void load_user_flags_line(std::istream &in)
Definition: tria.cc:9864
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:358
hex_iterator begin_hex(const unsigned int level=0) const
Definition: tria.cc:10976
virtual ~DistortedCellList() noexcept
Definition: tria.cc:13411
void clear_user_flags()
Definition: tria.cc:9729
active_face_iterator begin_active_face() const
Definition: tria.cc:10688
void save_user_flags_quad(std::ostream &out) const
Definition: tria.cc:9963
virtual bool has_hanging_nodes() const
Definition: tria.cc:11206
unsigned int n_raw_cells(const unsigned int level) const
Definition: tria.cc:11150
cell_iterator last() const
Definition: tria.cc:10528
void save_user_pointers_hex(std::vector< void *> &v) const
Definition: tria.cc:10430
vertex_iterator begin_vertex() const
Definition: tria.cc:10732
unsigned int n_cells() const
Definition: tria.cc:11077
std::vector< GridTools::PeriodicFacePair< cell_iterator > > periodic_face_pairs_level_0
Definition: tria.h:3367
std::list< typename Triangulation< dim, spacedim >::cell_iterator > distorted_cells
Definition: tria.h:1623
std::vector< Point< spacedim > > vertices
Definition: tria.h:3587
boost::signals2::signal< void()> clear
Definition: tria.h:2253
IteratorRange< active_cell_iterator > active_cell_iterators() const
Definition: tria.cc:10632
TriaActiveIterator< TriaAccessor< dim-1, dim, spacedim > > active_face_iterator
Definition: tria.h:1555
void set_all_refine_flags()
Definition: tria.cc:9432
void load_user_flags(std::istream &in)
Definition: tria.cc:9786
TriaActiveIterator<::TriaAccessor< 0, dim, spacedim > > active_vertex_iterator
Definition: tria.h:1579
unsigned int boundary_id
Definition: types.h:110
bool anisotropic_refinement
Definition: tria.h:3603
boost::signals2::signal< unsigned int(const cell_iterator &, const CellStatus), CellWeightSum< unsigned int > > cell_weight
Definition: tria.h:2291
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> pre_coarsening_on_cell
Definition: tria.h:2222
static void read_bool_vector(const unsigned int magic_number1, std::vector< bool > &v, const unsigned int magic_number2, std::istream &in)
Definition: tria.cc:13351
line_iterator begin_line(const unsigned int level=0) const
Definition: tria.cc:10816
line_iterator end_line() const
Definition: tria.cc:10848
boost::signals2::signal< void()> mesh_movement
Definition: tria.h:2213
::internal::TriangulationImplementation::Iterators< dim, spacedim > IteratorSelector
Definition: tria.h:1277
static ::ExceptionBase & ExcGridReadError()
void clear_user_flags_quad()
Definition: tria.cc:9689
unsigned int n_faces() const
Definition: tria.cc:11098
void serialize(Archive &ar, const unsigned int version)
void flip_all_direction_flags()
Definition: tria.cc:9421
active_cell_iterator begin_active(const unsigned int level=0) const
Definition: tria.cc:10508
STL namespace.
types::boundary_id boundary_id
Definition: tria.h:162
static void write_bool_vector(const unsigned int magic_number1, const std::vector< bool > &v, const unsigned int magic_number2, std::ostream &out)
Definition: tria.cc:13319
unsigned int n_active_hexs() const
Definition: tria.cc:11550
void save_user_pointers_quad(std::vector< void *> &v) const
Definition: tria.cc:10397
unsigned int material_id
Definition: types.h:133
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void execute_coarsening()
Definition: tria.cc:11900
cell_iterator begin(const unsigned int level=0) const
Definition: tria.cc:10488
const Boundary< dim, spacedim > & get_boundary(const types::manifold_id number) const
Definition: tria.cc:9070
void load_user_flags_quad(std::istream &in)
Definition: tria.cc:9974
unsigned int n_levels() const
void set_manifold(const types::manifold_id number, const Manifold< dim, spacedim > &manifold_object)
Definition: tria.cc:8955
raw_hex_iterator begin_raw_hex(const unsigned int level=0) const
Definition: tria.cc:10946
std::vector< std::unique_ptr<::internal::TriangulationImplementation::TriaLevel< dim > > > levels
Definition: tria.h:3574
static ::ExceptionBase & ExcFacesHaveNoLevel()
void load_user_pointers_line(const std::vector< void *> &v)
Definition: tria.cc:10383
unsigned int n_active_faces() const
Definition: tria.cc:11132
raw_quad_iterator begin_raw_quad(const unsigned int level=0) const
Definition: tria.cc:10862
std::unique_ptr<::internal::TriangulationImplementation::TriaFaces< dim > > faces
Definition: tria.h:3581
cell_iterator end() const
Definition: tria.cc:10576
TriaIterator< TriaAccessor< dim-1, dim, spacedim > > face_iterator
Definition: tria.h:1542
void load_coarsen_flags(std::istream &out)
Definition: tria.cc:9557
void load_user_flags_hex(std::istream &in)
Definition: tria.cc:10037
active_quad_iterator begin_active_quad(const unsigned int level=0) const
Definition: tria.cc:10917
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:11739
Definition: tria.h:76
unsigned int n_active_lines() const
Definition: tria.cc:11299
IteratorRange< cell_iterator > cell_iterators_on_level(const unsigned int level) const
Definition: tria.cc:10643
Definition: tria.h:45
virtual bool prepare_coarsening_and_refinement()
Definition: tria.cc:12426
static ::ExceptionBase & ExcMessage(std::string arg1)
bool check_consistency(const unsigned int dim) const
Definition: tria.cc:47
boost::signals2::signal< void()> pre_distributed_save
Definition: tria.h:2322
static ::ExceptionBase & ExcTriangulationNotEmpty(int arg1, int arg2)
void reset_active_cell_indices()
Definition: tria.cc:11783
DistortedCellList execute_refinement()
Definition: tria.cc:11866
const bool check_for_distorted_cells
Definition: tria.h:3610
boost::signals2::signal< void()> pre_refinement
Definition: tria.h:2197
static const unsigned int dimension
Definition: tria.h:1629
void save_user_flags_line(std::ostream &out) const
Definition: tria.cc:9853
static ::ExceptionBase & ExcNonOrientableTriangulation()
void save_user_pointers_line(std::vector< void *> &v) const
Definition: tria.cc:10370
Triangulation(const MeshSmoothing smooth_grid=none, const bool check_for_distorted_cells=false)
Definition: tria.cc:8808
#define DeclException1(Exception1, type1, outsequence)
Definition: exceptions.h:346
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
Definition: tria.h:1509
void clear_user_flags_hex()
Definition: tria.cc:9721
void load_user_indices_line(const std::vector< unsigned int > &v)
Definition: tria.cc:10185
Definition: types.h:30
unsigned int global_dof_index
Definition: types.h:88
vertex_iterator end_vertex() const
Definition: tria.cc:10769
unsigned int n_raw_quads() const
Definition: tria.cc:11492
#define Assert(cond, exc)
Definition: exceptions.h:1142
Signals signals
Definition: tria.h:2335
active_hex_iterator begin_active_hex(const unsigned int level=0) const
Definition: tria.cc:10992
void save_user_indices_line(std::vector< unsigned int > &v) const
Definition: tria.cc:10172
void set_all_manifold_ids(const types::manifold_id number)
Definition: tria.cc:9001
boost::signals2::signal< void()> create
Definition: tria.h:2188
static const StraightBoundary< dim, spacedim > straight_boundary
Definition: tria.h:1288
unsigned int n_raw_hexs(const unsigned int level) const
Definition: tria.cc:11543
unsigned int max_adjacent_cells() const
Definition: tria.cc:11653
bool get_anisotropic_refinement_flag() const
Definition: tria.cc:9586
void load(Archive &ar, const unsigned int version)
unsigned int n_quads() const
Definition: tria.cc:11446
std::unique_ptr< std::map< unsigned int, types::manifold_id > > vertex_to_manifold_id_map_1d
Definition: tria.h:3659
std::vector< bool > vertices_used
Definition: tria.h:3592
#define DeclException0(Exception0)
Definition: exceptions.h:323
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: tria.cc:9240
void save_coarsen_flags(std::ostream &out) const
Definition: tria.cc:9546
void reset_all_manifolds()
Definition: tria.cc:8993
void save_user_indices(std::vector< unsigned int > &v) const
Definition: tria.cc:10070
types::material_id material_id
Definition: tria.h:151
const std::vector< Point< spacedim > > & get_vertices() const
void load_user_indices(const std::vector< unsigned int > &v)
Definition: tria.cc:10100
void save_refine_flags(std::ostream &out) const
Definition: tria.cc:9481
unsigned int n_lines() const
Definition: tria.cc:11217
void clear_despite_subscriptions()
Definition: tria.cc:11850
raw_cell_iterator begin_raw(const unsigned int level=0) const
Definition: tria.cc:10468
unsigned int n_raw_lines() const
Definition: tria.cc:11282
virtual ~Triangulation()
Definition: tria.cc:8880
virtual std::size_t memory_consumption() const
Definition: tria.cc:13389
std::map< std::pair< cell_iterator, unsigned int >, std::pair< std::pair< cell_iterator, unsigned int >, std::bitset< 3 > > > periodic_face_map
Definition: tria.h:3372
boost::signals2::signal< void()> post_distributed_refinement
Definition: tria.h:2314
void save(Archive &ar, const unsigned int version) const
void serialize(Archive &ar, const unsigned int version)
virtual void set_mesh_smoothing(const MeshSmoothing mesh_smoothing)
Definition: tria.cc:8927
void load_user_pointers_hex(const std::vector< void *> &v)
Definition: tria.cc:10447
void save_user_flags_hex(std::ostream &out) const
Definition: tria.cc:10026
face_iterator begin_face() const
Definition: tria.cc:10667
unsigned int subdomain_id
Definition: types.h:42
boost::signals2::signal< void(const typename Triangulation< dim, spacedim >::cell_iterator &cell)> post_refinement_on_cell
Definition: tria.h:2230
boost::signals2::signal< void()> post_refinement
Definition: tria.h:2204
std::unique_ptr< std::map< unsigned int, types::boundary_id > > vertex_to_boundary_id_map_1d
Definition: tria.h:3637
virtual types::global_dof_index n_global_active_cells() const
Definition: tria.cc:11090
unsigned int n_hexs() const
Definition: tria.cc:11527
Definition: hp.h:102
unsigned int n_active_quads() const
Definition: tria.cc:11509
active_line_iterator begin_active_line(const unsigned int level=0) const
Definition: tria.cc:10832
types::manifold_id manifold_id
Definition: tria.h:173
raw_cell_iterator end_raw(const unsigned int level) const
Definition: tria.cc:10587
unsigned int n_raw_faces() const
Definition: tria.cc:11116
void load_user_indices_hex(const std::vector< unsigned int > &v)
Definition: tria.cc:10248
active_vertex_iterator begin_active_vertex() const
Definition: tria.cc:10760
void reset_manifold(const types::manifold_id manifold_number)
Definition: tria.cc:8982
std::vector< types::boundary_id > get_boundary_ids() const
Definition: tria.cc:9105
const types::manifold_id invalid_manifold_id
Definition: types.h:229
unsigned int manifold_id
Definition: types.h:122
void load_user_pointers_quad(const std::vector< void *> &v)
Definition: tria.cc:10414
void fix_coarsen_flags()
Definition: tria.cc:11972
active_cell_iterator end_active(const unsigned int level) const
Definition: tria.cc:10610
void update_periodic_face_map()
Definition: tria.cc:11801
std::vector< unsigned int > n_active_hexes_level
Definition: tria.h:456
void save_user_indices_quad(std::vector< unsigned int > &v) const
Definition: tria.cc:10198
virtual void add_periodicity(const std::vector< GridTools::PeriodicFacePair< cell_iterator > > &)
Definition: tria.cc:11714
const std::vector< bool > & get_used_vertices() const
Definition: tria.cc:11622
virtual unsigned int n_global_levels() const
hex_iterator end_hex() const
Definition: tria.cc:11008
std::vector< CellData< 2 > > boundary_quads
Definition: tria.h:257
MeshSmoothing smooth_grid
Definition: tria.h:3325
IteratorRange< active_cell_iterator > active_cell_iterators_on_level(const unsigned int level) const
Definition: tria.cc:10654
void load_user_pointers(const std::vector< void *> &v)
Definition: tria.cc:10335
std::vector< unsigned int > n_active_lines_level
Definition: tria.h:339
void refine_global(const unsigned int times=1)
Definition: tria.cc:9448
void save_user_pointers(std::vector< void *> &v) const
Definition: tria.cc:10305
void save_user_flags(std::ostream &out) const
Definition: tria.cc:9739
quad_iterator end_quad() const
Definition: tria.cc:10933
static ::ExceptionBase & ExcEmptyLevel(int arg1)
IteratorRange< cell_iterator > cell_iterators() const
Definition: tria.cc:10622
face_iterator end_face() const
Definition: tria.cc:10709
void set_all_manifold_ids_on_boundary(const types::manifold_id number)
Definition: tria.cc:9016
active_cell_iterator last_active() const
Definition: tria.cc:10555
std::map< types::manifold_id, std::unique_ptr< const Manifold< dim, spacedim > > > manifold
Definition: tria.h:3598
std::vector< unsigned int > n_active_quads_level
Definition: tria.h:397
void clear_user_flags_line()
Definition: tria.cc:9657
static ::ExceptionBase & ExcBoundaryIdNotFound(types::boundary_id arg1)
boost::signals2::signal< void()> post_distributed_load
Definition: tria.h:2329
void serialize(Archive &ar, const unsigned int version)
quad_iterator begin_quad(const unsigned int level=0) const
Definition: tria.cc:10901
void clear_user_data()
Definition: tria.cc:9629
Triangulation & operator=(Triangulation< dim, spacedim > &&tria) noexcept
Definition: tria.cc:8855
std::vector< types::manifold_id > get_manifold_ids() const
Definition: tria.cc:9137
bool vertex_used(const unsigned int index) const
const Manifold< dim, spacedim > & get_manifold(const types::manifold_id number) const
Definition: tria.cc:9083
virtual void create_triangulation_compatibility(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: tria.cc:9220
void load_user_indices_quad(const std::vector< unsigned int > &v)
Definition: tria.cc:10215
virtual types::subdomain_id locally_owned_subdomain() const
Definition: tria.cc:11686
raw_line_iterator begin_raw_line(const unsigned int level=0) const
Definition: tria.cc:10791
virtual void clear()
Definition: tria.cc:8912
virtual const MeshSmoothing & get_mesh_smoothing() const
Definition: tria.cc:8938
boost::signals2::signal< void(const Triangulation< dim, spacedim > &destination_tria)> copy
Definition: tria.h:2238
const std::map< std::pair< cell_iterator, unsigned int >, std::pair< std::pair< cell_iterator, unsigned int >, std::bitset< 3 > > > & get_periodic_face_map() const
Definition: tria.cc:11730
void load_refine_flags(std::istream &in)
Definition: tria.cc:9492
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
unsigned int vertices[GeometryInfo< structdim >::vertices_per_cell]
Definition: tria.h:132
Triangulation< dim, spacedim > & get_triangulation()
Definition: tria.cc:11695
boost::signals2::signal< void()> pre_distributed_refinement
Definition: tria.h:2304
void save_user_indices_hex(std::vector< unsigned int > &v) const
Definition: tria.cc:10231
TriaIterator<::TriaAccessor< 0, dim, spacedim > > vertex_iterator
Definition: tria.h:1565