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\}}\)
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)
37  , support_point_cache(mapping.support_point_cache)
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_cxx14::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 = triangulation.signals.any_change.connect(
98  [&]() -> void { this->support_point_cache.reset(); });
99 
100  support_point_cache =
101  std::make_shared<std::vector<std::vector<std::vector<Point<spacedim>>>>>(
102  triangulation.n_levels());
103  for (unsigned int l = 0; l < triangulation.n_levels(); ++l)
104  (*support_point_cache)[l].resize(triangulation.n_raw_cells(l));
105 
107  triangulation.begin(),
108  triangulation.end(),
109  [&](const typename Triangulation<dim, spacedim>::cell_iterator &cell,
110  void *,
111  void *) {
112  (*support_point_cache)[cell->level()][cell->index()] =
113  compute_points_on_cell(cell);
114  AssertDimension(
115  (*support_point_cache)[cell->level()][cell->index()].size(),
116  Utilities::pow(this->get_degree() + 1, dim));
117  },
118  /* copier */ std::function<void(void *)>(),
119  /* scratch_data */ nullptr,
120  /* copy_data */ nullptr,
122  /* chunk_size = */ 1);
123 }
124 
125 
126 
127 template <int dim, int spacedim>
128 std::size_t
130 {
131  if (support_point_cache.get() != nullptr)
132  return sizeof(*this) +
133  MemoryConsumption::memory_consumption(*support_point_cache);
134  else
135  return sizeof(*this);
136 }
137 
138 
139 
140 template <int dim, int spacedim>
141 std::vector<Point<spacedim>>
143  const typename Triangulation<dim, spacedim>::cell_iterator &cell) const
144 {
145  Assert(support_point_cache.get() != nullptr,
146  ExcMessage("Must call MappingQCache::initialize() before "
147  "using it or after mesh has changed!"));
148 
149  AssertIndexRange(cell->level(), support_point_cache->size());
150  AssertIndexRange(cell->index(), (*support_point_cache)[cell->level()].size());
151  return (*support_point_cache)[cell->level()][cell->index()];
152 }
153 
154 
155 
156 //--------------------------- Explicit instantiations -----------------------
157 #include "mapping_q_cache.inst"
158 
159 
MappingQGeneric< dim, dim >::MappingQCache
friend class MappingQCache
Definition: mapping_q_generic.h:735
MultithreadInfo::n_threads
static unsigned int n_threads()
Definition: multithread_info.cc:169
MappingQCache::initialize
void initialize(const Triangulation< dim, spacedim > &triangulation, const MappingQGeneric< dim, spacedim > &mapping)
Definition: mapping_q_cache.cc:75
Triangulation
Definition: tria.h:1109
MappingQGeneric
Definition: mapping_q_generic.h:135
memory_consumption.h
MappingQCache
Definition: mapping_q_cache.h:46
AssertIndexRange
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
MappingQCache::memory_consumption
std::size_t memory_consumption() const
Definition: mapping_q_cache.cc:129
WorkStream::run
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:1185
work_stream.h
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
MemoryConsumption::memory_consumption
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Definition: memory_consumption.h:268
Physics::Elasticity::Kinematics::l
Tensor< 2, dim, Number > l(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
AssertDimension
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1579
mapping_q_cache.h
MappingQCache::compute_mapping_support_points
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const override
Definition: mapping_q_cache.cc:142
MappingQGeneric::compute_mapping_support_points
virtual std::vector< Point< spacedim > > compute_mapping_support_points(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
Definition: mapping_q_generic.cc:4005
MappingQCache::clone
virtual std::unique_ptr< Mapping< dim, spacedim > > clone() const override
Definition: mapping_q_cache.cc:57
MappingQGeneric::get_degree
unsigned int get_degree() const
Definition: mapping_q_generic.cc:2258
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
MappingQCache::preserves_vertex_locations
virtual bool preserves_vertex_locations() const override
Definition: mapping_q_cache.cc:66
MappingQCache::~MappingQCache
~MappingQCache()
Definition: mapping_q_cache.cc:43
Point< spacedim >
triangulation
const typename ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
Definition: p4est_wrappers.cc:69
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
TriaIterator
Definition: tria_iterator.h:578