Reference documentation for deal.II version 9.6.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// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2020 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_adaptation_strategies_h
16#define dealii_adaptation_strategies_h
17
18
19#include <deal.II/base/config.h>
20
22
24
25#include <algorithm>
26#include <numeric>
27#include <typeinfo>
28#include <vector>
29
31
43{
52 namespace Refinement
53 {
64 template <int dim, int spacedim, typename value_type>
65 std::vector<value_type>
66 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
67 &parent,
68 const value_type parent_value);
69
83 template <int dim, int spacedim, typename value_type>
84 std::vector<value_type>
85 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
86 &parent,
87 const value_type parent_value);
88
102 template <int dim, int spacedim, typename value_type>
103 std::vector<value_type>
104 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
105 &parent,
106 const value_type parent_value);
107 } // namespace Refinement
108
117 namespace Coarsening
118 {
128 template <int dim, int spacedim, typename value_type>
129 value_type
131 const typename ::Triangulation<dim, spacedim>::cell_iterator
132 &parent,
133 const std::vector<value_type> &children_values);
134
147 template <int dim, int spacedim, typename value_type>
148 value_type
149 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator
150 &parent,
151 const std::vector<value_type> &children_values);
152
165 template <int dim, int spacedim, typename value_type>
166 value_type
167 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
168 &parent,
169 const std::vector<value_type> &children_values);
170
180 template <int dim, int spacedim, typename value_type>
181 value_type
182 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
183 &parent,
184 const std::vector<value_type> &children_values);
185
195 template <int dim, int spacedim, typename value_type>
196 value_type
197 max(const typename ::Triangulation<dim, spacedim>::cell_iterator
198 &parent,
199 const std::vector<value_type> &children_values);
200 } // namespace Coarsening
201} // namespace AdaptationStrategies
202
203
204
205/* ---------------- template functions ---------------- */
206
207#ifndef DOXYGEN
208
209namespace AdaptationStrategies
210{
211 namespace Refinement
212 {
213 template <int dim, int spacedim, typename value_type>
214 std::vector<value_type>
215 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
216 &parent,
217 const value_type parent_value)
218 {
219 Assert(parent->n_children() > 0, ExcInternalError());
220 return std::vector<value_type>(parent->n_children(), parent_value);
221 }
222
223
224
225 template <int dim, int spacedim, typename value_type>
226 std::vector<value_type>
227 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
228 &parent,
229 const value_type parent_value)
230 {
231 static_assert(std::is_arithmetic_v<value_type> &&
232 !std::is_same_v<value_type, bool>,
233 "The provided value_type may not meet the requirements "
234 "of this function.");
235
236 Assert(parent->n_children() > 0, ExcInternalError());
237 return std::vector<value_type>(parent->n_children(),
238 parent_value / parent->n_children());
239 }
240
241
242
243 template <int dim, int spacedim, typename value_type>
244 std::vector<value_type>
245 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
246 &parent,
247 const value_type parent_value)
248 {
249 static_assert(std::is_arithmetic_v<value_type> &&
250 !std::is_same_v<value_type, bool>,
251 "The provided value_type may not meet the requirements "
252 "of this function.");
253
254 Assert(parent->n_children() > 0, ExcInternalError());
255 return std::vector<value_type>(parent->n_children(),
256 parent_value /
257 std::sqrt(parent->n_children()));
258 }
259 } // namespace Refinement
260
261
262
263 namespace Coarsening
264 {
265 template <int dim, int spacedim, typename value_type>
266 value_type
268 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
269 const std::vector<value_type> &children_values)
270 {
271 Assert(!children_values.empty(), ExcInternalError());
272
273 const auto first_child = children_values.cbegin();
274 for (auto other_child = first_child + 1;
275 other_child != children_values.cend();
276 ++other_child)
277 Assert(*first_child == *other_child,
279 "Values on cells that will be coarsened are not equal!"));
280
281 return *first_child;
282 }
283
284
285
286 template <int dim, int spacedim, typename value_type>
287 value_type
288 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
289 const std::vector<value_type> &children_values)
290 {
291 static_assert(std::is_arithmetic_v<value_type> &&
292 !std::is_same_v<value_type, bool>,
293 "The provided value_type may not meet the requirements "
294 "of this function.");
295
296 Assert(!children_values.empty(), ExcInternalError());
297 return std::accumulate(children_values.cbegin(),
298 children_values.cend(),
299 static_cast<value_type>(0));
300 }
301
302
303
304 template <int dim, int spacedim, typename value_type>
305 value_type
306 l2_norm(
307 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
308 const std::vector<value_type> &children_values)
309 {
310 static_assert(std::is_arithmetic_v<value_type> &&
311 !std::is_same_v<value_type, bool>,
312 "The provided value_type may not meet the requirements "
313 "of this function.");
314
315 Assert(!children_values.empty(), ExcInternalError());
316 return std::sqrt(std::inner_product(children_values.cbegin(),
317 children_values.cend(),
318 children_values.cbegin(),
319 static_cast<value_type>(0)));
320 }
321
322
323
324 template <int dim, int spacedim, typename value_type>
325 value_type
326 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
327 &parent,
328 const std::vector<value_type> &children_values)
329 {
330 return sum<dim, spacedim, value_type>(parent, children_values) /
331 children_values.size();
332 }
333
334
335
336 template <int dim, int spacedim, typename value_type>
337 value_type
338 max(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
339 const std::vector<value_type> &children_values)
340 {
341 Assert(!children_values.empty(), ExcInternalError());
342 return *std::max_element(children_values.cbegin(),
343 children_values.cend());
344 }
345 } // namespace Coarsening
346} // namespace AdaptationStrategies
347
348#endif
349
351
352#endif /* dealii_adaptation_strategies_h */
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
#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 max(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 > &)