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\}}\)
adaptation_strategies.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2019 - 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 
16 #ifndef dealii_adaptation_strategies_h
17 #define dealii_adaptation_strategies_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 
25 
26 #include <algorithm>
27 #include <numeric>
28 #include <typeinfo>
29 #include <vector>
30 
32 
46 {
55  namespace Refinement
56  {
67  template <int dim, int spacedim, typename value_type>
68  std::vector<value_type>
69  preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
70  & parent,
71  const value_type parent_value);
72 
86  template <int dim, int spacedim, typename value_type>
87  std::vector<value_type>
88  split(const typename ::Triangulation<dim, spacedim>::cell_iterator
89  & parent,
90  const value_type parent_value);
91 
105  template <int dim, int spacedim, typename value_type>
106  std::vector<value_type>
107  l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
108  & parent,
109  const value_type parent_value);
110  } // namespace Refinement
111 
120  namespace Coarsening
121  {
131  template <int dim, int spacedim, typename value_type>
132  value_type
134  const typename ::Triangulation<dim, spacedim>::cell_iterator
135  & parent,
136  const std::vector<value_type> &children_values);
137 
150  template <int dim, int spacedim, typename value_type>
151  value_type
152  sum(const typename ::Triangulation<dim, spacedim>::cell_iterator
153  & parent,
154  const std::vector<value_type> &children_values);
155 
168  template <int dim, int spacedim, typename value_type>
169  value_type
170  l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
171  & parent,
172  const std::vector<value_type> &children_values);
173 
183  template <int dim, int spacedim, typename value_type>
184  value_type
185  mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
186  & parent,
187  const std::vector<value_type> &children_values);
188 
198  template <int dim, int spacedim, typename value_type>
199  value_type
200  max(const typename ::Triangulation<dim, spacedim>::cell_iterator
201  & parent,
202  const std::vector<value_type> &children_values);
203  } // namespace Coarsening
204 } // namespace AdaptationStrategies
205 
206 
207 
208 /* ---------------- template functions ---------------- */
209 
210 #ifndef DOXYGEN
211 
212 namespace AdaptationStrategies
213 {
214  namespace Refinement
215  {
216  template <int dim, int spacedim, typename value_type>
217  std::vector<value_type>
218  preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
219  & parent,
220  const value_type parent_value)
221  {
222  Assert(parent->n_children() > 0, ExcInternalError());
223  return std::vector<value_type>(parent->n_children(), parent_value);
224  }
225 
226 
227 
228  template <int dim, int spacedim, typename value_type>
229  std::vector<value_type>
230  split(const typename ::Triangulation<dim, spacedim>::cell_iterator
231  & parent,
232  const value_type parent_value)
233  {
236  "The provided value_type may not meet the requirements "
237  "of this function.");
238 
239  Assert(parent->n_children() > 0, ExcInternalError());
240  return std::vector<value_type>(parent->n_children(),
241  parent_value / parent->n_children());
242  }
243 
244 
245 
246  template <int dim, int spacedim, typename value_type>
247  std::vector<value_type>
248  l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
249  & parent,
250  const value_type parent_value)
251  {
254  "The provided value_type may not meet the requirements "
255  "of this function.");
256 
257  Assert(parent->n_children() > 0, ExcInternalError());
258  return std::vector<value_type>(parent->n_children(),
259  parent_value /
260  std::sqrt(parent->n_children()));
261  }
262  } // namespace Refinement
263 
264 
265 
266  namespace Coarsening
267  {
268  template <int dim, int spacedim, typename value_type>
269  value_type
271  const typename ::Triangulation<dim, spacedim>::cell_iterator &,
272  const std::vector<value_type> &children_values)
273  {
274  Assert(!children_values.empty(), ExcInternalError());
275 
276  const auto first_child = children_values.cbegin();
277  for (auto other_child = first_child + 1;
278  other_child != children_values.cend();
279  ++other_child)
280  Assert(*first_child == *other_child,
281  ExcMessage(
282  "Values on cells that will be coarsened are not equal!"));
283 
284  return *first_child;
285  }
286 
287 
288 
289  template <int dim, int spacedim, typename value_type>
290  value_type
291  sum(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
292  const std::vector<value_type> &children_values)
293  {
296  "The provided value_type may not meet the requirements "
297  "of this function.");
298 
299  Assert(!children_values.empty(), ExcInternalError());
300  return std::accumulate(children_values.cbegin(),
301  children_values.cend(),
302  static_cast<value_type>(0));
303  }
304 
305 
306 
307  template <int dim, int spacedim, typename value_type>
308  value_type
309  l2_norm(
310  const typename ::Triangulation<dim, spacedim>::cell_iterator &,
311  const std::vector<value_type> &children_values)
312  {
315  "The provided value_type may not meet the requirements "
316  "of this function.");
317 
318  Assert(!children_values.empty(), ExcInternalError());
319  return std::sqrt(std::inner_product(children_values.cbegin(),
320  children_values.cend(),
321  children_values.cbegin(),
322  static_cast<value_type>(0)));
323  }
324 
325 
326 
327  template <int dim, int spacedim, typename value_type>
328  value_type
329  mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
330  & parent,
331  const std::vector<value_type> &children_values)
332  {
333  return sum<dim, spacedim, value_type>(parent, children_values) /
334  children_values.size();
335  }
336 
337 
338 
339  template <int dim, int spacedim, typename value_type>
340  value_type
341  max(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
342  const std::vector<value_type> &children_values)
343  {
344  Assert(!children_values.empty(), ExcInternalError());
345  return *std::max_element(children_values.cbegin(),
346  children_values.cend());
347  }
348  } // namespace Coarsening
349 } // namespace AdaptationStrategies
350 
351 #endif
352 
354 
355 #endif /* dealii_adaptation_strategies_h */
AdaptationStrategies::Refinement::preserve
std::vector< value_type > preserve(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
tria_accessor.h
AdaptationStrategies::Coarsening::sum
value_type sum(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
AdaptationStrategies::Coarsening::check_equality
value_type check_equality(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
StandardExceptions::ExcMessage
static ::ExceptionBase & ExcMessage(std::string arg1)
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
exceptions.h
value
static const bool value
Definition: dof_tools_constraints.cc:433
AdaptationStrategies::Refinement::l2_norm
std::vector< value_type > l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
AdaptationStrategies::Refinement::split
std::vector< value_type > split(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
std::sqrt
inline ::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &x)
Definition: vectorization.h:5412
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
AdaptationStrategies::Coarsening::mean
value_type mean(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
config.h
AdaptationStrategies
Definition: adaptation_strategies.h:45
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
value_type
AdaptationStrategies::Coarsening::l2_norm
value_type l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
AdaptationStrategies::Coarsening::max
value_type max(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)