Reference documentation for deal.II version GIT d9d8a449a2 2022-08-17 08:45:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
grid_tools_cache.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2017 - 2022 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 
17 #include <deal.II/base/mpi_stub.h>
18 
22 
24 
25 namespace GridTools
26 {
27  template <int dim, int spacedim>
29  const Mapping<dim, spacedim> & mapping)
30  : update_flags(update_all)
31  , tria(&tria)
32  , mapping(&mapping)
33  {
34  tria_signal =
35  tria.signals.any_change.connect([&]() { mark_for_update(update_all); });
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>
50  void
52  {
53  update_flags |= flags;
54  }
55 
56 
57 
58  template <int dim, int spacedim>
59  const std::vector<
60  std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>> &
62  {
63  if (update_flags & update_vertex_to_cell_map)
64  {
65  vertex_to_cells = GridTools::vertex_to_cell_map(*tria);
66  update_flags = update_flags & ~update_vertex_to_cell_map;
67  }
68  return vertex_to_cells;
69  }
70 
71 
72 
73  template <int dim, int spacedim>
74  const std::vector<std::vector<Tensor<1, spacedim>>> &
76  {
78  {
79  vertex_to_cell_centers = GridTools::vertex_to_cell_centers_directions(
80  *tria, get_vertex_to_cell_map());
81  update_flags = update_flags & ~update_vertex_to_cell_centers_directions;
82  }
83  return vertex_to_cell_centers;
84  }
85 
86 
87 
88  template <int dim, int spacedim>
89  const std::map<unsigned int, Point<spacedim>> &
91  {
92  if (update_flags & update_used_vertices)
93  {
94  used_vertices = GridTools::extract_used_vertices(*tria, *mapping);
95  update_flags = update_flags & ~update_used_vertices;
96  }
97  return used_vertices;
98  }
99 
100 
101 
102  template <int dim, int spacedim>
103  const RTree<std::pair<Point<spacedim>, unsigned int>> &
105  {
106  if (update_flags & update_used_vertices_rtree)
107  {
108  const auto &used_vertices = get_used_vertices();
109  std::vector<std::pair<Point<spacedim>, unsigned int>> vertices(
110  used_vertices.size());
111  unsigned int i = 0;
112  for (const auto &it : used_vertices)
113  vertices[i++] = std::make_pair(it.second, it.first);
114  used_vertices_rtree = pack_rtree(vertices);
115  update_flags = update_flags & ~update_used_vertices_rtree;
116  }
117  return used_vertices_rtree;
118  }
119 
120 
121 
122  template <int dim, int spacedim>
123  const RTree<
124  std::pair<BoundingBox<spacedim>,
127  {
128  if (update_flags & update_cell_bounding_boxes_rtree)
129  {
130  std::vector<std::pair<
133  boxes(tria->n_active_cells());
134  unsigned int i = 0;
135  for (const auto &cell : tria->active_cell_iterators())
136  boxes[i++] = std::make_pair(mapping->get_bounding_box(cell), cell);
137 
138  cell_bounding_boxes_rtree = pack_rtree(boxes);
139  update_flags = update_flags & ~update_cell_bounding_boxes_rtree;
140  }
141  return cell_bounding_boxes_rtree;
142  }
143 
144 
145 
146  template <int dim, int spacedim>
147  const RTree<
148  std::pair<BoundingBox<spacedim>,
151  {
153  {
154  std::vector<std::pair<
157  boxes;
158  boxes.reserve(tria->n_active_cells());
159  for (const auto &cell : tria->active_cell_iterators() |
161  boxes.emplace_back(mapping->get_bounding_box(cell), cell);
162 
163  locally_owned_cell_bounding_boxes_rtree = pack_rtree(boxes);
164  update_flags =
166  }
167  return locally_owned_cell_bounding_boxes_rtree;
168  }
169 
170 
171 
172  template <int dim, int spacedim>
173  const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &
175  {
176  if (update_flags & update_covering_rtree ||
177  covering_rtree.find(level) == covering_rtree.end())
178  {
179  const auto boxes =
180  extract_rtree_level(get_locally_owned_cell_bounding_boxes_rtree(),
181  level);
182 
183  if (const auto tria_mpi =
184  dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
185  &(*tria)))
186  {
188  boxes, tria_mpi->get_communicator());
189  }
190  else
191  {
192  covering_rtree[level] =
193  GridTools::build_global_description_tree(boxes, MPI_COMM_SELF);
194  }
195  update_flags = update_flags & ~update_covering_rtree;
196  }
197 
198  return covering_rtree[level];
199  }
200 
201  template <int dim, int spacedim>
202  const std::vector<std::set<unsigned int>> &
204  {
205  if (update_flags & update_vertex_to_neighbor_subdomain)
206  {
207  vertex_to_neighbor_subdomain.clear();
208  vertex_to_neighbor_subdomain.resize(tria->n_vertices());
209  for (const auto &cell : tria->active_cell_iterators())
210  {
211  if (cell->is_ghost())
212  for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
213  vertex_to_neighbor_subdomain[cell->vertex_index(v)].insert(
214  cell->subdomain_id());
215  }
216  update_flags = update_flags & ~update_vertex_to_neighbor_subdomain;
217  }
218  return vertex_to_neighbor_subdomain;
219  }
220 
221 #include "grid_tools_cache.inst"
222 
223 } // namespace GridTools
224 
SmartPointer< const Triangulation< dim, spacedim >, Cache< dim, spacedim > > tria
const std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > & get_vertex_to_cell_map() const
Cache(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< dim, spacedim >()))
const RTree< std::pair< BoundingBox< spacedim >, unsigned int > > & get_covering_rtree(const unsigned int level=0) const
const std::vector< std::vector< Tensor< 1, spacedim > > > & get_vertex_to_cell_centers_directions() const
const std::vector< std::set< unsigned int > > & get_vertex_to_neighbor_subdomain() const
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & get_locally_owned_cell_bounding_boxes_rtree() const
const RTree< std::pair< Point< spacedim >, unsigned int > > & get_used_vertices_rtree() const
const RTree< std::pair< BoundingBox< spacedim >, typename Triangulation< dim, spacedim >::active_cell_iterator > > & get_cell_bounding_boxes_rtree() const
const std::map< unsigned int, Point< spacedim > > & get_used_vertices() const
void mark_for_update(const CacheUpdateFlags &flags=update_all)
boost::signals2::connection tria_signal
unsigned int n_active_cells() const
unsigned int n_vertices() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
Point< 3 > vertices[4]
unsigned int level
Definition: grid_out.cc:4608
IteratorRange< active_cell_iterator > active_cell_iterators() const
std::map< unsigned int, Point< spacedim > > extract_used_vertices(const Triangulation< dim, spacedim > &container, const Mapping< dim, spacedim > &mapping=(ReferenceCells::get_hypercube< dim >() .template get_default_linear_mapping< dim, spacedim >()))
Definition: grid_tools.cc:6218
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:2741
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:3382
RTree< std::pair< BoundingBox< spacedim >, unsigned int > > build_global_description_tree(const std::vector< BoundingBox< spacedim >> &local_description, const MPI_Comm &mpi_communicator)
Definition: grid_tools.cc:6378
std::vector< BoundingBox< boost::geometry::dimension< typename Rtree::indexable_type >::value > > extract_rtree_level(const Rtree &tree, const unsigned int level)
boost::geometry::index::rtree< LeafType, IndexType, IndexableGetter > RTree
Definition: rtree.h:146
RTree< typename LeafTypeIterator::value_type, IndexType, IndexableGetter > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)
const ::Triangulation< dim, spacedim > & tria