deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20: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
function_tools.cc
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) 2021 - 2025 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
14
15#include <cmath>
16
17
19namespace FunctionTools
20{
21 template <int dim>
22 void
24 const Function<dim> &function,
25 const BoundingBox<dim> &box,
26 std::pair<double, double> &value_bounds,
27 std::array<std::pair<double, double>, dim> &gradient_bounds,
28 const unsigned int component)
29 {
30 const Point<dim> center = box.center();
31 const double value = function.value(center, component);
32 const Tensor<1, dim> gradient = function.gradient(center, component);
33 const SymmetricTensor<2, dim> hessian = function.hessian(center, component);
34
35 // Deviation from function value at the center, based on the
36 // Taylor-expansion: |f'| * dx + 1/2 * |f''| * dx^2, (in 1d). dx is half
37 // the side-length of the box.
38 double taylor_bound_f = 0;
39
40 for (unsigned int i = 0; i < dim; ++i)
41 {
42 const double dx_i = .5 * box.side_length(i);
43
44 taylor_bound_f += std::abs(gradient[i]) * dx_i;
45
46 // Deviation from value of df/dx_i at the center,
47 // |f''| * dx, (in 1d).
48 double taylor_bound_dfdxi = 0;
49
50 for (unsigned int j = 0; j < dim; ++j)
51 {
52 const double dx_j = .5 * box.side_length(j);
53
54 taylor_bound_dfdxi += std::abs(hessian[i][j]) * dx_j;
55 taylor_bound_f += .5 * std::abs(hessian[i][j]) * dx_i * dx_j;
56 }
57
58 gradient_bounds[i].first = gradient[i] - taylor_bound_dfdxi;
59 gradient_bounds[i].second = gradient[i] + taylor_bound_dfdxi;
60 }
61
62 value_bounds.first = value - taylor_bound_f;
63 value_bounds.second = value + taylor_bound_f;
64 }
65
66} // namespace FunctionTools
67
68#include "base/function_tools.inst"
69
Point< spacedim, Number > center() const
Number side_length(const unsigned int direction) const
virtual SymmetricTensor< 2, dim, RangeNumberType > hessian(const Point< dim > &p, const unsigned int component=0) const
virtual Tensor< 1, dim, RangeNumberType > gradient(const Point< dim > &p, const unsigned int component=0) const
virtual RangeNumberType value(const Point< dim > &p, const unsigned int component=0) const
Definition point.h:111
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
void taylor_estimate_function_bounds(const Function< dim > &function, const BoundingBox< dim > &box, std::pair< double, double > &value_bounds, std::array< std::pair< double, double >, dim > &gradient_bounds, const unsigned int component=0)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)