Reference documentation for deal.II version Git 53084d8c6a 2020-10-21 00:34:33 -0400
\(\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\}}\)
mapping_q_cache.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 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 
18 
20 
21 #include <functional>
22 
24 
25 template <int dim, int spacedim>
27  const unsigned int polynomial_degree)
28  : MappingQGeneric<dim, spacedim>(polynomial_degree)
29 {}
30 
31 
32 
33 template <int dim, int spacedim>
35  const MappingQCache<dim, spacedim> &mapping)
36  : MappingQGeneric<dim, spacedim>(mapping)
38 {}
39 
40 
41 
42 template <int dim, int spacedim>
44 {
45  // When this object goes out of scope, we want the cache to get cleared and
46  // free its memory before the signal is disconnected in order to not work on
47  // invalid memory that has been left back by freeing an object of this
48  // class.
49  support_point_cache.reset();
50  clear_signal.disconnect();
51 }
52 
53 
54 
55 template <int dim, int spacedim>
56 std::unique_ptr<Mapping<dim, spacedim>>
58 {
59  return std::make_unique<MappingQCache<dim, spacedim>>(*this);
60 }
61 
62 
63 
64 template <int dim, int spacedim>
65 bool
67 {
68  return false;
69 }
70 
71 
72 
73 template <int dim, int spacedim>
74 void
77  const MappingQGeneric<dim, spacedim> &mapping)
78 {
79  AssertDimension(this->get_degree(), mapping.get_degree());
80  initialize(triangulation,
81  [&mapping](const typename Triangulation<dim>::cell_iterator &cell)
82  -> std::vector<Point<spacedim>> {
83  return mapping.compute_mapping_support_points(cell);
84  });
85 }
86 
87 
88 
89 template <int dim, int spacedim>
90 void
93  const std::function<std::vector<Point<spacedim>>(
95  &compute_points_on_cell)
96 {
97  clear_signal.disconnect();
98  clear_signal = triangulation.signals.any_change.connect(
99  [&]() -> void { this->support_point_cache.reset(); });
100 
102  std::make_shared<std::vector<std::vector<std::vector<Point<spacedim>>>>>(
103  triangulation.n_levels());
104  for (unsigned int l = 0; l < triangulation.n_levels(); ++l)
105  (*support_point_cache)[l].resize(triangulation.n_raw_cells(l));
106 
108  triangulation.begin(),
109  triangulation.end(),
110  [&](const typename Triangulation<dim, spacedim>::cell_iterator &cell,
111  void *,
112  void *) {
113  (*support_point_cache)[cell->level()][cell->index()] =
114  compute_points_on_cell(cell);
116  (*support_point_cache)[cell->level()][cell->index()].size(),
117  Utilities::pow(this->get_degree() + 1, dim));
118  },
119  /* copier */ std::function<void(void *)>(),
120  /* scratch_data */ nullptr,
121  /* copy_data */ nullptr,
123  /* chunk_size = */ 1);
124 }
125 
126 
127 
128 template <int dim, int spacedim>
129 std::size_t
131 {
132  if (support_point_cache.get() != nullptr)
133  return sizeof(*this) +
135  else
136  return sizeof(*this);
137 }
138 
139 
140 
141 template <int dim, int spacedim>
142 std::vector<Point<spacedim>>
144  const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
145 {
146  Assert(support_point_cache.get() != nullptr,
147  ExcMessage("Must call MappingQCache::initialize() before "
148  "using it or after mesh has changed!"));
149 
150  AssertIndexRange(cell->level(), support_point_cache->size());
151  AssertIndexRange(cell->index(), (*support_point_cache)[cell->level()].size());
152  return (*support_point_cache)[cell->level()][cell->index()];
153 }
154 
155 
156 
157 //--------------------------- Explicit instantiations -----------------------
158 #include "mapping_q_cache.inst"
159 
160 
virtual bool preserves_vertex_locations() const override
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1580
unsigned int n_raw_cells(const unsigned int level) const
Definition: tria.cc:11889
#define AssertIndexRange(index, range)
Definition: exceptions.h:1648
cell_iterator begin(const unsigned int level=0) const
Definition: tria.cc:11134
unsigned int n_levels() const
constexpr T pow(const T base, const int iexp)
Definition: utilities.h:461
std::size_t memory_consumption() const
cell_iterator end() const
Definition: tria.cc:11220
virtual std::unique_ptr< Mapping< dim, spacedim > > clone() const override
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1423
Signals signals
Definition: tria.h:2266
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:369
void initialize(const Triangulation< dim, spacedim > &triangulation, const MappingQGeneric< dim, spacedim > &mapping)
unsigned int get_degree() const
boost::signals2::connection clear_signal
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:368
MappingQCache(const unsigned int polynomial_degree)
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
void run(const std::vector< std::vector< Iterator >> &colored_iterators, Worker worker, Copier copier, const ScratchData &sample_scratch_data, const CopyData &sample_copy_data, const unsigned int queue_length=2 *MultithreadInfo::n_threads(), const unsigned int chunk_size=8)
Definition: work_stream.h:1337
static unsigned int n_threads()
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
std::shared_ptr< std::vector< std::vector< std::vector< Point< spacedim > > > > > support_point_cache
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)