Reference documentation for deal.II version GIT relicensing-769-g16d39143b0 2024-05-28 17:50: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\}}\)
Loading...
Searching...
No Matches
grid_tools_cache.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2017 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
17
21
23
24namespace GridTools
25{
26 template <int dim, int spacedim>
29 : update_flags(update_all)
30 , tria(&tria)
32 {
34 tria.signals.any_change.connect([&]() { mark_for_update(update_all); });
35 }
36
37 template <int dim, int spacedim>
39 {
40 // Make sure that the signals that was attached to the triangulation
41 // is removed here.
42 if (tria_signal.connected())
43 tria_signal.disconnect();
44 }
45
46
47
48 template <int dim, int spacedim>
49 void
51 {
52 update_flags |= flags;
53 }
54
55
56
57 template <int dim, int spacedim>
58 const std::vector<
59 std::set<typename Triangulation<dim, spacedim>::active_cell_iterator>> &
61 {
62 if (update_flags & update_vertex_to_cell_map)
63 {
64 vertex_to_cells = GridTools::vertex_to_cell_map(*tria);
65 update_flags = update_flags & ~update_vertex_to_cell_map;
66 }
67 return vertex_to_cells;
68 }
69
70
71
72 template <int dim, int spacedim>
73 const std::vector<std::vector<Tensor<1, spacedim>>> &
75 {
77 {
78 vertex_to_cell_centers = GridTools::vertex_to_cell_centers_directions(
79 *tria, get_vertex_to_cell_map());
80 update_flags = update_flags & ~update_vertex_to_cell_centers_directions;
81 }
82 return vertex_to_cell_centers;
83 }
84
85
86
87 template <int dim, int spacedim>
88 const std::map<unsigned int, Point<spacedim>> &
90 {
91 if (update_flags & update_used_vertices)
92 {
94 update_flags = update_flags & ~update_used_vertices;
95 }
96 return used_vertices;
97 }
98
99
100
101 template <int dim, int spacedim>
102 const RTree<std::pair<Point<spacedim>, unsigned int>> &
104 {
105 if (update_flags & update_used_vertices_rtree)
106 {
107 const auto &used_vertices = get_used_vertices();
108 std::vector<std::pair<Point<spacedim>, unsigned int>> vertices(
109 used_vertices.size());
110 unsigned int i = 0;
111 for (const auto &it : used_vertices)
112 vertices[i++] = std::make_pair(it.second, it.first);
113 used_vertices_rtree = pack_rtree(vertices);
114 update_flags = update_flags & ~update_used_vertices_rtree;
115 }
116 return used_vertices_rtree;
117 }
119
120
121 template <int dim, int spacedim>
122 const RTree<
123 std::pair<BoundingBox<spacedim>,
126 {
127 if (update_flags & update_cell_bounding_boxes_rtree)
128 {
129 std::vector<std::pair<
132 boxes;
133 boxes.reserve(tria->n_active_cells());
134 for (const auto &cell : tria->active_cell_iterators())
135 boxes.emplace_back(mapping->get_bounding_box(cell), cell);
136
137 cell_bounding_boxes_rtree = pack_rtree(boxes);
138 update_flags = update_flags & ~update_cell_bounding_boxes_rtree;
139 }
140 return cell_bounding_boxes_rtree;
141 }
142
144
145 template <int dim, int spacedim>
146 const RTree<
147 std::pair<BoundingBox<spacedim>,
150 {
152 {
153 std::vector<std::pair<
156 boxes;
157 if (const parallel::TriangulationBase<dim, spacedim> *parallel_tria =
159 &*tria))
160 boxes.reserve(parallel_tria->n_locally_owned_active_cells());
161 else
162 boxes.reserve(tria->n_active_cells());
163 for (const auto &cell : tria->active_cell_iterators() |
164 IteratorFilters::LocallyOwnedCell())
165 boxes.emplace_back(mapping->get_bounding_box(cell), cell);
166
167 locally_owned_cell_bounding_boxes_rtree = pack_rtree(boxes);
168 update_flags =
169 update_flags & ~update_locally_owned_cell_bounding_boxes_rtree;
170 }
171 return locally_owned_cell_bounding_boxes_rtree;
172 }
173
174
176 template <int dim, int spacedim>
177 const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &
179 {
180 if (update_flags & update_covering_rtree ||
181 covering_rtree.find(level) == covering_rtree.end())
182 {
183 const auto boxes =
184 extract_rtree_level(get_locally_owned_cell_bounding_boxes_rtree(),
185 level);
186
187 if (const auto tria_mpi =
188 dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
189 &(*tria)))
190 {
192 boxes, tria_mpi->get_communicator());
193 }
194 else
195 {
196 covering_rtree[level] =
197 GridTools::build_global_description_tree(boxes, MPI_COMM_SELF);
198 }
199 update_flags = update_flags & ~update_covering_rtree;
200 }
201
202 return covering_rtree[level];
203 }
204
205 template <int dim, int spacedim>
206 const std::vector<std::set<unsigned int>> &
208 {
209 if (update_flags & update_vertex_to_neighbor_subdomain)
210 {
211 vertex_to_neighbor_subdomain.clear();
212 vertex_to_neighbor_subdomain.resize(tria->n_vertices());
213 for (const auto &cell : tria->active_cell_iterators())
214 {
215 if (cell->is_ghost())
216 for (const unsigned int v : cell->vertex_indices())
217 vertex_to_neighbor_subdomain[cell->vertex_index(v)].insert(
218 cell->subdomain_id());
220 update_flags = update_flags & ~update_vertex_to_neighbor_subdomain;
221 }
222 return vertex_to_neighbor_subdomain;
223 }
224
225 template <int dim, int spacedim>
226 const std::map<unsigned int, std::set<types::subdomain_id>> &
228 {
229 if (update_flags & update_vertex_with_ghost_neighbors)
230 {
233
234 update_flags = update_flags & ~update_vertex_with_ghost_neighbors;
235 }
236
238 }
239
240#include "grid_tools_cache.inst"
241
242} // namespace GridTools
243
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 std::map< unsigned int, std::set< types::subdomain_id > > & get_vertices_with_ghost_neighbors() 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
Abstract base class for mapping classes.
Definition mapping.h:318
unsigned int n_active_cells() const
Signals signals
Definition tria.h:2509
unsigned int n_vertices() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
Point< 2 > second
Definition grid_out.cc:4624
unsigned int level
Definition grid_out.cc:4626
IteratorRange< active_cell_iterator > active_cell_iterators() const
RTree< std::pair< BoundingBox< spacedim >, unsigned int > > build_global_description_tree(const std::vector< BoundingBox< spacedim > > &local_description, const MPI_Comm mpi_communicator)
spacedim & mapping
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 >()))
const Triangulation< dim, spacedim > & tria
const std::vector< Point< spacedim > > & vertices
std::map< unsigned int, std::set<::types::subdomain_id > > compute_vertices_with_ghost_neighbors(const Triangulation< dim, spacedim > &tria)
std::vector< bool >::const_iterator first
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
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)
STL namespace.
std::map< unsigned int, std::set<::types::subdomain_id > > * vertices_with_ghost_neighbors
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:145
RTree< typename LeafTypeIterator::value_type, IndexType, IndexableGetter > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)