Reference documentation for deal.II version 9.0.0
grid_tools_cache.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 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 #include <deal.II/grid/grid_tools_cache.h>
17 #include <deal.II/grid/grid_tools.h>
18 
19 DEAL_II_NAMESPACE_OPEN
20 
21 namespace GridTools
22 {
23 
24  template<int dim, int spacedim>
26  const Triangulation<dim, spacedim> &tria,
27  const Mapping<dim, spacedim> &mapping) :
28  update_flags(update_all),
29  tria(&tria),
30  mapping(&mapping)
31  {
32  tria_signal = tria.signals.any_change.connect([&]()
33  {
34  mark_for_update(update_all);
35  });
36  }
37 
38  template<int dim, int spacedim>
40  {
41  // Make sure that the signals that was attached to the triangulation
42  // is removed here.
43  if (tria_signal.connected())
44  tria_signal.disconnect();
45  }
46 
47 
48 
49  template<int dim, int spacedim>
51  {
52  update_flags |= flags;
53  }
54 
55 
56 
57  template<int dim, int spacedim>
58  const std::vector<std::set<typename Triangulation<dim,spacedim>::active_cell_iterator> > &
60  {
61  if (update_flags & update_vertex_to_cell_map)
62  {
63  vertex_to_cells = GridTools::vertex_to_cell_map(*tria);
64  update_flags = update_flags & ~update_vertex_to_cell_map;
65  }
66  return vertex_to_cells;
67  }
68 
69 
70 
71  template<int dim, int spacedim>
72  const std::vector<std::vector<Tensor<1,spacedim>>> &
74  {
76  {
77  vertex_to_cell_centers =
78  GridTools::vertex_to_cell_centers_directions(*tria, get_vertex_to_cell_map());
79  update_flags = update_flags & ~update_vertex_to_cell_centers_directions;
80  }
81  return vertex_to_cell_centers;
82  }
83 
84 
85 
86  template<int dim, int spacedim>
87  const std::map<unsigned int, Point<spacedim> > &
89  {
90  if (update_flags & update_used_vertices)
91  {
92  used_vertices = GridTools::extract_used_vertices(*tria, *mapping);
93  update_flags = update_flags & ~update_used_vertices;
94  }
95  return used_vertices;
96  }
97 
98 
99 
100 #ifdef DEAL_II_WITH_NANOFLANN
101  template<int dim, int spacedim>
103  {
104  if (update_flags & update_vertex_kdtree)
105  {
106  vertex_kdtree.set_points(tria->get_vertices());
107  update_flags = update_flags & ~update_vertex_kdtree;
108  }
109  return vertex_kdtree;
110  }
111 #endif
112 
113 #include "grid_tools_cache.inst"
114 
115 } // GridTools
116 
117 DEAL_II_NAMESPACE_CLOSE
118 
std::map< unsigned int, Point< spacedim > > extract_used_vertices(const Triangulation< dim, spacedim > &container, const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
Definition: grid_tools.cc:4543
Cache(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:1978
Definition: tria.h:76
Signals signals
Definition: tria.h:2335
Abstract base class for mapping classes.
Definition: dof_tools.h:46
std::vector< std::vector< Tensor< 1, spacedim > > > vertex_to_cell_centers_directions(const Triangulation< dim, spacedim > &mesh, const std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > &vertex_to_cells)
Definition: grid_tools.cc:1557