Reference documentation for deal.II version 9.3.3
\(\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 - 2020 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.h>
18
22
24
25namespace 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 {
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 }
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)
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
122 template <int dim, int spacedim>
123 const RTree<
124 std::pair<BoundingBox<spacedim>,
127 {
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())
160 if (cell->is_locally_owned())
161 boxes.emplace_back(
162 std::make_pair(mapping->get_bounding_box(cell), cell));
163
164 locally_owned_cell_bounding_boxes_rtree = pack_rtree(boxes);
165 update_flags =
166 update_flags & ~update_locally_owned_cell_bounding_boxes_rtree;
167 }
168 return locally_owned_cell_bounding_boxes_rtree;
169 }
170
171
172
173 template <int dim, int spacedim>
174 const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &
176 {
177 if (update_flags & update_covering_rtree ||
178 covering_rtree.find(level) == covering_rtree.end())
179 {
180 const auto boxes =
181 extract_rtree_level(get_locally_owned_cell_bounding_boxes_rtree(),
182 level);
183
184 if (const auto tria_mpi =
185 dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
186 &(*tria)))
187 {
189 boxes, tria_mpi->get_communicator());
190 }
191 else
192 {
193 covering_rtree[level] =
194 GridTools::build_global_description_tree(boxes, MPI_COMM_SELF);
195 }
196 update_flags = update_flags & ~update_covering_rtree;
197 }
198
199 return covering_rtree[level];
200 }
201
202 template <int dim, int spacedim>
203 const std::vector<std::set<unsigned int>> &
205 {
206 if (update_flags & update_vertex_to_neighbor_subdomain)
207 {
208 vertex_to_neighbor_subdomain.clear();
209 vertex_to_neighbor_subdomain.resize(tria->n_vertices());
210 for (const auto &cell : tria->active_cell_iterators())
211 {
212 if (cell->is_ghost())
213 for (const unsigned int v : GeometryInfo<dim>::vertex_indices())
214 vertex_to_neighbor_subdomain[cell->vertex_index(v)].insert(
215 cell->subdomain_id());
216 }
217 update_flags = update_flags & ~update_vertex_to_neighbor_subdomain;
218 }
219 return vertex_to_neighbor_subdomain;
220 }
221
222#include "grid_tools_cache.inst"
223
224} // namespace GridTools
225
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
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
Point< 3 > vertices[4]
unsigned int level
Definition: grid_out.cc:4590
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:6325
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:6165
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:3261
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:2696
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:153
RTree< typename LeafTypeIterator::value_type, IndexType, IndexableGetter > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)