Reference documentation for deal.II version 9.5.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\}}\)
Loading...
Searching...
No Matches
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
44{
53 namespace Refinement
54 {
65 template <int dim, int spacedim, typename value_type>
66 std::vector<value_type>
67 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
68 & parent,
69 const value_type parent_value);
70
84 template <int dim, int spacedim, typename value_type>
85 std::vector<value_type>
86 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
87 & parent,
88 const value_type parent_value);
89
103 template <int dim, int spacedim, typename value_type>
104 std::vector<value_type>
105 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
106 & parent,
107 const value_type parent_value);
108 } // namespace Refinement
109
118 namespace Coarsening
119 {
129 template <int dim, int spacedim, typename value_type>
130 value_type
132 const typename ::Triangulation<dim, spacedim>::cell_iterator
133 & parent,
134 const std::vector<value_type> &children_values);
135
148 template <int dim, int spacedim, typename value_type>
149 value_type
150 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator
151 & parent,
152 const std::vector<value_type> &children_values);
153
166 template <int dim, int spacedim, typename value_type>
167 value_type
168 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
169 & parent,
170 const std::vector<value_type> &children_values);
171
181 template <int dim, int spacedim, typename value_type>
182 value_type
183 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
184 & parent,
185 const std::vector<value_type> &children_values);
186
196 template <int dim, int spacedim, typename value_type>
197 value_type
198 max(const typename ::Triangulation<dim, spacedim>::cell_iterator
199 & parent,
200 const std::vector<value_type> &children_values);
201 } // namespace Coarsening
202} // namespace AdaptationStrategies
203
204
205
206/* ---------------- template functions ---------------- */
207
208#ifndef DOXYGEN
209
210namespace AdaptationStrategies
211{
212 namespace Refinement
213 {
214 template <int dim, int spacedim, typename value_type>
215 std::vector<value_type>
216 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
217 & parent,
218 const value_type parent_value)
219 {
220 Assert(parent->n_children() > 0, ExcInternalError());
221 return std::vector<value_type>(parent->n_children(), parent_value);
222 }
223
224
225
226 template <int dim, int spacedim, typename value_type>
227 std::vector<value_type>
228 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
229 & parent,
230 const value_type parent_value)
231 {
232 static_assert(std::is_arithmetic<value_type>::value &&
233 !std::is_same<value_type, bool>::value,
234 "The provided value_type may not meet the requirements "
235 "of this function.");
236
237 Assert(parent->n_children() > 0, ExcInternalError());
238 return std::vector<value_type>(parent->n_children(),
239 parent_value / parent->n_children());
240 }
241
242
243
244 template <int dim, int spacedim, typename value_type>
245 std::vector<value_type>
246 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
247 & parent,
248 const value_type parent_value)
249 {
250 static_assert(std::is_arithmetic<value_type>::value &&
251 !std::is_same<value_type, bool>::value,
252 "The provided value_type may not meet the requirements "
253 "of this function.");
254
255 Assert(parent->n_children() > 0, ExcInternalError());
256 return std::vector<value_type>(parent->n_children(),
257 parent_value /
258 std::sqrt(parent->n_children()));
259 }
260 } // namespace Refinement
261
262
263
264 namespace Coarsening
265 {
266 template <int dim, int spacedim, typename value_type>
267 value_type
269 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
270 const std::vector<value_type> &children_values)
271 {
272 Assert(!children_values.empty(), ExcInternalError());
273
274 const auto first_child = children_values.cbegin();
275 for (auto other_child = first_child + 1;
276 other_child != children_values.cend();
277 ++other_child)
278 Assert(*first_child == *other_child,
280 "Values on cells that will be coarsened are not equal!"));
281
282 return *first_child;
283 }
284
285
286
287 template <int dim, int spacedim, typename value_type>
288 value_type
289 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
290 const std::vector<value_type> &children_values)
291 {
292 static_assert(std::is_arithmetic<value_type>::value &&
293 !std::is_same<value_type, bool>::value,
294 "The provided value_type may not meet the requirements "
295 "of this function.");
296
297 Assert(!children_values.empty(), ExcInternalError());
298 return std::accumulate(children_values.cbegin(),
299 children_values.cend(),
300 static_cast<value_type>(0));
301 }
302
303
304
305 template <int dim, int spacedim, typename value_type>
306 value_type
307 l2_norm(
308 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
309 const std::vector<value_type> &children_values)
310 {
311 static_assert(std::is_arithmetic<value_type>::value &&
312 !std::is_same<value_type, bool>::value,
313 "The provided value_type may not meet the requirements "
314 "of this function.");
315
316 Assert(!children_values.empty(), ExcInternalError());
317 return std::sqrt(std::inner_product(children_values.cbegin(),
318 children_values.cend(),
319 children_values.cbegin(),
320 static_cast<value_type>(0)));
321 }
322
323
324
325 template <int dim, int spacedim, typename value_type>
326 value_type
327 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
328 & parent,
329 const std::vector<value_type> &children_values)
330 {
331 return sum<dim, spacedim, value_type>(parent, children_values) /
332 children_values.size();
333 }
334
335
336
337 template <int dim, int spacedim, typename value_type>
338 value_type
339 max(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
340 const std::vector<value_type> &children_values)
341 {
342 Assert(!children_values.empty(), ExcInternalError());
343 return *std::max_element(children_values.cbegin(),
344 children_values.cend());
345 }
346 } // namespace Coarsening
347} // namespace AdaptationStrategies
348
349#endif
350
352
353#endif /* dealii_adaptation_strategies_h */
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
value_type check_equality(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
value_type sum(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
value_type l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
value_type mean(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const std::vector< value_type > &children_values)
std::vector< value_type > l2_norm(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
std::vector< value_type > preserve(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
std::vector< value_type > split(const typename ::Triangulation< dim, spacedim >::cell_iterator &parent, const value_type parent_value)
::VectorizedArray< Number, width > sqrt(const ::VectorizedArray< Number, width > &)