Reference documentation for deal.II version 9.2.0
\(\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 
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 #ifdef DEAL_II_WITH_NANOFLANN
146  template <int dim, int spacedim>
147  const KDTree<spacedim> &
149  {
150  if (update_flags & update_vertex_kdtree)
151  {
152  vertex_kdtree.set_points(tria->get_vertices());
153  update_flags = update_flags & ~update_vertex_kdtree;
154  }
155  return vertex_kdtree;
156  }
157 #endif
158 
159 
160 
161  template <int dim, int spacedim>
162  const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &
164  {
165  if (update_flags & update_covering_rtree)
166  {
167  // TO DO: the locally owned portion of the domain
168  // might consists of more separate pieces: a single
169  // bounding box might not always be the best choice.
170 
171  // Note: we create the local variable ptr here, because gcc 4.8.5
172  // fails to compile if we pass the variable directly.
173  IteratorFilters::LocallyOwnedCell locally_owned_cell_predicate;
174  std::function<bool(
176  ptr(locally_owned_cell_predicate);
177 
178  const BoundingBox<spacedim> bbox =
179  GridTools::compute_bounding_box(get_triangulation(), ptr);
180 
181 
182  std::vector<BoundingBox<spacedim>> bbox_v(1, bbox);
183  if (const auto tria_mpi =
184  dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
185  &(*tria)))
186  {
188  bbox_v, tria_mpi->get_communicator());
189  }
190  else
191  {
192  covering_rtree =
193  GridTools::build_global_description_tree(bbox_v, MPI_COMM_SELF);
194  }
195  update_flags = update_flags & ~update_covering_rtree;
196  }
197 
198  return covering_rtree;
199  }
200 
201 #include "grid_tools_cache.inst"
202 
203 } // namespace GridTools
204 
GridTools::update_vertex_to_cell_centers_directions
@ update_vertex_to_cell_centers_directions
Definition: grid_tools_cache_update_flags.h:52
GridTools
Definition: grid_tools.h:125
bounding_box.h
Triangulation::signals
Signals signals
Definition: tria.h:2222
GridTools::update_all
@ update_all
Definition: grid_tools_cache_update_flags.h:89
KDTree< spacedim >
GridTools::extract_used_vertices
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:5174
Triangulation
Definition: tria.h:1109
GridTools::update_used_vertices_rtree
@ update_used_vertices_rtree
Definition: grid_tools_cache_update_flags.h:69
GridTools::build_global_description_tree
RTree< std::pair< BoundingBox< spacedim >, unsigned int > > build_global_description_tree(const std::vector< BoundingBox< spacedim >> &local_description, MPI_Comm mpi_communicator)
Definition: grid_tools.cc:5332
GridTools::CacheUpdateFlags
CacheUpdateFlags
Definition: grid_tools_cache_update_flags.h:35
GridTools::vertex_to_cell_centers_directions
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:1510
GridTools::compute_bounding_box
BoundingBox< spacedim > compute_bounding_box(const Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:274
IteratorFilters::LocallyOwnedCell
Definition: filtered_iterator.h:191
GridTools::Cache::Cache
Cache(const Triangulation< dim, spacedim > &tria, const Mapping< dim, spacedim > &mapping=StaticMappingQ1< dim, spacedim >::mapping)
Definition: grid_tools_cache.cc:28
BoundingBox
Definition: bounding_box.h:128
bool
RTree
boost::geometry::index::rtree< LeafType, IndexType > RTree
Definition: rtree.h:134
Mapping
Abstract base class for mapping classes.
Definition: mapping.h:302
GridTools::update_used_vertices
@ update_used_vertices
Definition: grid_tools_cache_update_flags.h:64
GridTools::update_covering_rtree
@ update_covering_rtree
Definition: grid_tools_cache_update_flags.h:84
mpi.h
grid_tools.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
GridTools::Cache
Definition: grid_tools.h:128
TriaActiveIterator
Definition: tria_iterator.h:759
vertices
Point< 3 > vertices[4]
Definition: data_out_base.cc:174
GridTools::update_vertex_kdtree
@ update_vertex_kdtree
Definition: grid_tools_cache_update_flags.h:59
pack_rtree
RTree< typename LeafTypeIterator::value_type, IndexType > pack_rtree(const LeafTypeIterator &begin, const LeafTypeIterator &end)
GridTools::update_vertex_to_cell_map
@ update_vertex_to_cell_map
Definition: grid_tools_cache_update_flags.h:46
grid_tools_cache.h
parallel::TriangulationBase
Definition: tria_base.h:78
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
filtered_iterator.h
GridTools::update_cell_bounding_boxes_rtree
@ update_cell_bounding_boxes_rtree
Definition: grid_tools_cache_update_flags.h:74
GridTools::vertex_to_cell_map
std::vector< std::set< typename Triangulation< dim, spacedim >::active_cell_iterator > > vertex_to_cell_map(const Triangulation< dim, spacedim > &triangulation)
Definition: grid_tools.cc:2072