deal.II version GIT relicensing-6839-g338455934c 2026-10-02 12:10:01+00:00
\(\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: Apache-2.0 WITH LLVM-exception OR 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// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_adaptation_strategies_h
14#define dealii_adaptation_strategies_h
15
16
17#include <deal.II/base/config.h>
18
20
22
23#include <algorithm>
24#include <numeric>
25#include <typeinfo>
26#include <vector>
27
29
41{
50 namespace Refinement
51 {
62 template <int dim, int spacedim, typename value_type>
63 std::vector<value_type>
64 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
65 &parent,
66 const value_type parent_value);
67
81 template <int dim, int spacedim, typename value_type>
82 std::vector<value_type>
83 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
84 &parent,
85 const value_type parent_value);
86
100 template <int dim, int spacedim, typename value_type>
101 std::vector<value_type>
102 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
103 &parent,
104 const value_type parent_value);
105 } // namespace Refinement
106
115 namespace Coarsening
116 {
126 template <int dim, int spacedim, typename value_type>
129 const typename ::Triangulation<dim, spacedim>::cell_iterator
130 &parent,
131 const std::vector<value_type> &children_values);
132
145 template <int dim, int spacedim, typename value_type>
147 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator
148 &parent,
149 const std::vector<value_type> &children_values);
150
163 template <int dim, int spacedim, typename value_type>
165 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
166 &parent,
167 const std::vector<value_type> &children_values);
168
178 template <int dim, int spacedim, typename value_type>
180 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
181 &parent,
182 const std::vector<value_type> &children_values);
183
193 template <int dim, int spacedim, typename value_type>
195 max(const typename ::Triangulation<dim, spacedim>::cell_iterator
196 &parent,
197 const std::vector<value_type> &children_values);
198 } // namespace Coarsening
199} // namespace AdaptationStrategies
200
201
202
203/* ---------------- template functions ---------------- */
204
205#ifndef DOXYGEN
206
207namespace AdaptationStrategies
208{
209 namespace Refinement
210 {
211 template <int dim, int spacedim, typename value_type>
212 std::vector<value_type>
213 preserve(const typename ::Triangulation<dim, spacedim>::cell_iterator
214 &parent,
215 const value_type parent_value)
216 {
217 Assert(parent->n_children() > 0, ExcInternalError());
218 return std::vector<value_type>(parent->n_children(), parent_value);
219 }
220
221
222
223 template <int dim, int spacedim, typename value_type>
224 std::vector<value_type>
225 split(const typename ::Triangulation<dim, spacedim>::cell_iterator
226 &parent,
227 const value_type parent_value)
228 {
229 static_assert(std::is_arithmetic_v<value_type> &&
230 !std::is_same_v<value_type, bool>,
231 "The provided value_type may not meet the requirements "
232 "of this function.");
233
234 Assert(parent->n_children() > 0, ExcInternalError());
235 return std::vector<value_type>(parent->n_children(),
236 parent_value / parent->n_children());
237 }
238
239
240
241 template <int dim, int spacedim, typename value_type>
242 std::vector<value_type>
243 l2_norm(const typename ::Triangulation<dim, spacedim>::cell_iterator
244 &parent,
245 const value_type parent_value)
246 {
247 static_assert(std::is_arithmetic_v<value_type> &&
248 !std::is_same_v<value_type, bool>,
249 "The provided value_type may not meet the requirements "
250 "of this function.");
251
252 Assert(parent->n_children() > 0, ExcInternalError());
253 return std::vector<value_type>(parent->n_children(),
254 parent_value /
255 std::sqrt(parent->n_children()));
256 }
257 } // namespace Refinement
258
259
260
261 namespace Coarsening
262 {
263 template <int dim, int spacedim, typename value_type>
266 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
267 const std::vector<value_type> &children_values)
268 {
269 Assert(!children_values.empty(), ExcInternalError());
270
271 const auto first_child = children_values.cbegin();
272 for (auto other_child = first_child + 1;
273 other_child != children_values.cend();
274 ++other_child)
275 Assert(*first_child == *other_child,
277 "Values on cells that will be coarsened are not equal!"));
278
279 return *first_child;
280 }
281
282
283
284 template <int dim, int spacedim, typename value_type>
286 sum(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
287 const std::vector<value_type> &children_values)
288 {
289 static_assert(std::is_arithmetic_v<value_type> &&
290 !std::is_same_v<value_type, bool>,
291 "The provided value_type may not meet the requirements "
292 "of this function.");
293
294 Assert(!children_values.empty(), ExcInternalError());
295 return std::accumulate(children_values.cbegin(),
296 children_values.cend(),
297 static_cast<value_type>(0));
298 }
299
300
301
302 template <int dim, int spacedim, typename value_type>
304 l2_norm(
305 const typename ::Triangulation<dim, spacedim>::cell_iterator &,
306 const std::vector<value_type> &children_values)
307 {
308 static_assert(std::is_arithmetic_v<value_type> &&
309 !std::is_same_v<value_type, bool>,
310 "The provided value_type may not meet the requirements "
311 "of this function.");
312
313 Assert(!children_values.empty(), ExcInternalError());
314 return std::sqrt(std::inner_product(children_values.cbegin(),
315 children_values.cend(),
316 children_values.cbegin(),
317 static_cast<value_type>(0)));
318 }
319
320
321
322 template <int dim, int spacedim, typename value_type>
324 mean(const typename ::Triangulation<dim, spacedim>::cell_iterator
325 &parent,
326 const std::vector<value_type> &children_values)
327 {
328 return sum<dim, spacedim, value_type>(parent, children_values) /
329 children_values.size();
330 }
331
332
333
334 template <int dim, int spacedim, typename value_type>
336 max(const typename ::Triangulation<dim, spacedim>::cell_iterator &,
337 const std::vector<value_type> &children_values)
338 {
339 Assert(!children_values.empty(), ExcInternalError());
340 return *std::max_element(children_values.cbegin(),
341 children_values.cend());
342 }
343 } // namespace Coarsening
344} // namespace AdaptationStrategies
345
346#endif
347
349
350#endif /* dealii_adaptation_strategies_h */
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#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 > &)