MeanValue.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3
4 /// \file
5 /// Defines function mean_value and mean_value_on_boundary.
6
7 #pragma once
8
9 #include <cstddef>
10 #include <utility>
11
12 #include "Domain/Side.hpp"
15 #include "Utilities/Gsl.hpp"
16
17 /// \cond
18 class DataVector;
19 template <size_t>
20 class Mesh;
21 /// \endcond
22
23 /*!
24  * \ingroup NumericalAlgorithmsGroup
25  * \brief Compute the mean value of a grid-function over a manifold.
26  * \f$mean value = \int f dV / \int dV\f$
27  *
28  * \remarks The mean value is computed on the reference element(s).
29  * \note The mean w.r.t. a different set of coordinates x can be computed
30  * by pre-multiplying the argument f by the Jacobian J = dx/dxi of the mapping
31  * from the reference coordinates xi to the coordinates x.
32  *
33  * \returns the mean value of f on the manifold
34  * \param f the grid function of which to find the mean.
35  * \param mesh the Mesh of the manifold on which f is located.
36  */
37 template <size_t Dim>
38 double mean_value(const DataVector& f, const Mesh<Dim>& mesh) noexcept {
39  return definite_integral(f, mesh) / two_to_the(Dim);
40 }
41
42 // @{
43 /*!
44  * \ingroup NumericalAlgorithmsGroup
45  * Compute the mean value of a grid-function on a boundary of a manifold.
46  * \f$mean value = \int f dV / \int dV\f$
47  *
48  * \remarks The mean value is computed on the reference element(s).
49  *
50  * \returns the mean value of f on the boundary of the manifold
51  *
52  * - f the grid function of which to find the mean.
53  * - mesh the Mesh of the manifold on which f is located.
54  * - d the dimension which is sliced away to get the boundary.
55  * - side whether it is the lower or upper boundary in the d-th dimension.
56  * - boundary_buffer is a pointer to a DataVector of size
57  * mesh.slice_away(d).number_of_grid_points() used as a temporary buffer
58  * when slicing the data to the boundary.
59  * - volume_and_slice_indices a pair of (volume_index_for_point,
60  * slice_index_for_point) computed using the SliceIterator. Because
61  * SliceIterator is somewhat expensive, if computing the mean value on the
62  * same boundary for many different tensor components, prefer computing the
63  * slice indices once.
64  */
65 template <size_t Dim>
66 double mean_value_on_boundary(const DataVector& f, const Mesh<Dim>& mesh,
67  size_t d, Side side) noexcept;
68
69 template <size_t Dim>
71  const DataVector& f, const Mesh<Dim>& mesh,
72  size_t d, Side side) noexcept;
73
74 double mean_value_on_boundary(gsl::not_null<DataVector*> /*boundary_buffer*/,
75  const DataVector& f, const Mesh<1>& mesh,
76  size_t d, Side side) noexcept;
77
78 template <size_t Dim>
80  gsl::not_null<DataVector*> boundary_buffer,
82  const DataVector& f, const Mesh<Dim>& mesh, size_t d,
83  Side /*side*/) noexcept;
84
86  gsl::not_null<DataVector*> /*boundary_buffer*/,
87  gsl::span<std::pair<size_t, size_t>> /*volume_and_slice_indices*/,
88  const DataVector& f, const Mesh<1>& mesh, size_t d, Side side) noexcept;
89 // @}
Defines function definite_integral.
std::pair< std::unique_ptr< std::pair< size_t, size_t >[], decltype(&free)>, std::array< std::pair< gsl::span< std::pair< size_t, size_t > >, gsl::span< std::pair< size_t, size_t > > >, VolumeDim > > volume_and_slice_indices(const Index< VolumeDim > &extents) noexcept
Get the mapping between volume and boundary slice indices.
Definition: SliceIterator.cpp:49
Holds the number of grid points, basis, and quadrature in each direction of the computational grid...
Definition: Mesh.hpp:49
Side
A label for the side of a manifold.
Definition: Side.hpp:17
Create a span/view on a range, which is cheap to copy (one pointer).
Definition: Gsl.hpp:291
double mean_value_on_boundary(const DataVector &f, const Mesh< Dim > &mesh, size_t d, Side side) noexcept
Definition: MeanValue.cpp:36
double mean_value(const DataVector &f, const Mesh< Dim > &mesh) noexcept
Compute the mean value of a grid-function over a manifold. .
Definition: MeanValue.hpp:38
constexpr T two_to_the(T n)
Compute 2 to the n for integral types.
Definition: ConstantExpressions.hpp:34
Define simple functions for constant expressions.
Stores a collection of function values.
Definition: DataVector.hpp:46
double definite_integral(const DataVector &integrand, const Mesh< Dim > &mesh) noexcept
Compute the definite integral of a grid-function over a manifold.
Defines functions and classes from the GSL.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12
Defines enum class Side.