| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: 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 |
// 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_function_tools_h |
| 16 |
#define dealii_function_tools_h |
| 17 |
|
| 18 |
|
| 19 |
#include <deal.II/base/config.h> |
| 20 |
|
| 21 |
#include <deal.II/base/bounding_box.h> |
| 22 |
#include <deal.II/base/function.h> |
| 23 |
|
| 24 |
#include <array> |
| 25 |
|
| 26 |
|
| 27 |
DEAL_II_NAMESPACE_OPEN |
| 28 |
|
| 29 |
namespace FunctionTools |
| 30 |
{ |
| 31 |
/** |
| 32 |
* Estimate bounds on the value and bounds on each gradient component of a |
| 33 |
* Function, $f$, over a BoundingBox, by approximating it by a 2nd order |
| 34 |
* Taylor polynomial starting from the box center. |
| 35 |
* |
| 36 |
* Each lower and upper bound is returned as a |
| 37 |
* <code>std::pair<double, double></code>, such that the first entry is the |
| 38 |
* lower bound, $L$, and the second is the upper bound, $U$, i.e. |
| 39 |
* $f(x) \in [L, U]$. |
| 40 |
* |
| 41 |
* The function value, gradient, and Hessian are computed at the box center. |
| 42 |
* The bounds on the value of the function are then estimated as |
| 43 |
* |
| 44 |
* $f(x) \in [f(x_c) - F, f(x_c) + F]$, |
| 45 |
* where |
| 46 |
* $F = \sum_i |\partial_i f(x_c)| h_i |
| 47 |
* + 1/2 \sum_i \sum_j |\partial_i \partial_j f(x_c)| h_i h_j$. |
| 48 |
* |
| 49 |
* Here, $h_i$ is half the side length of the box in the $i$th coordinate |
| 50 |
* direction, which is the distance we extrapolate. The bounds on the gradient |
| 51 |
* components are estimated similarly as |
| 52 |
* |
| 53 |
* $\partial_i f \in [\partial_i f(x_c) - G_i, \partial_i f(x_c) + G_i]$, |
| 54 |
* where |
| 55 |
* $G_i = \sum_j |\partial_i \partial_j f(x_c)| h_j$. |
| 56 |
* |
| 57 |
* If the function has more than 1 component the @p component parameter can |
| 58 |
* be used to specify which function component the bounds should be computed |
| 59 |
* for. |
| 60 |
*/ |
| 61 |
template <int dim> |
| 62 |
void |
| 63 |
taylor_estimate_function_bounds( |
| 64 |
const Function<dim> &function, |
| 65 |
const BoundingBox<dim> &box, |
| 66 |
std::pair<double, double> &value_bounds, |
| 67 |
std::array<std::pair<double, double>, dim> &gradient_bounds, |
| 68 |
const unsigned int component = 0); |
| 69 |
|
| 70 |
} // namespace FunctionTools |
| 71 |
DEAL_II_NAMESPACE_CLOSE |
| 72 |
|
| 73 |
#endif /* dealii_function_tools_h */ |