Reconstruct.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <utility> // for std::pair
9 
11 #include "Utilities/Gsl.hpp"
12 
13 /// \cond
14 class DataVector;
15 template <size_t Dim>
16 class Direction;
17 template <size_t Dim, typename T>
18 class DirectionMap;
19 template <size_t Dim>
20 class Index;
21 /// \endcond
22 
23 namespace fd {
24 /*!
25  * \ingroup FiniteDifferenceGroup
26  * \brief Variable and flux vector splitting reconstruction schemes for finite
27  * difference methods.
28  *
29  * Implementations of reconstruction methods must call the function
30  * `fd::reconstruction::detail::reconstruct` to perform the reconstruction.
31  * This function performs the actual loops taking into account strides and ghost
32  * zones for the reconstruction method. The `reconstruct` function has the
33  * following signature:
34  *
35  * \code
36  * template <typename Reconstructor, typename... ArgsForReconstructor, size_t
37  * Dim>
38  * void reconstruct(
39  * const gsl::not_null<std::array<gsl::span<double>, Dim>*>
40  * reconstructed_upper_side_of_face_vars,
41  * const gsl::not_null<std::array<gsl::span<double>, Dim>*>
42  * reconstructed_lower_side_of_face_vars,
43  * const gsl::span<const double>& volume_vars,
44  * const DirectionMap<Dim, gsl::span<const double>>& ghost_cell_vars,
45  * const Index<Dim>& volume_extents, const size_t number_of_variables,
46  * const ArgsForReconstructor&... args_for_reconstructor) noexcept;
47  * \endcode
48  *
49  * The type of reconstruction done is specified with the `Reconstructor`
50  * explicit template parameter. Parameters for the reconstruction scheme, such
51  * as the linear weights and the epsilon tolerance in a CWENO reconstruction
52  * scheme, are forwarded along using the `args_for_reconstruction` parameter
53  * pack.
54  *
55  * `Reconstructor` classes must define:
56  * - a `static constexpr size_t stencil_width()` function that
57  * returns the size of the stencil, e.g. 3 for minmod, and 5 for 5-point
58  * reconstruction.
59  * - a
60  * \code
61  * SPECTRE_ALWAYS_INLINE static std::array<double, 2> pointwise(
62  * const double* const u, const int stride)
63  * \endcode
64  * function that optionally takes the additional arguments.
65  * The `u` are the cell-centered values to reconstruct. The value \f$u_i\f$ in
66  * the current FD cell is located at `u[0]`, the value at neighbor cell
67  * \f$u_{i+1}\f$ is at `u[stride]`, and the value at neighbor cell
68  * \f$u_{i-1}\f$ is at `u[-stride]`. The returned values are the
69  * reconstructed solution on the lower and upper side of the cell.
70  *
71  * \note Currently the stride is always one because we transpose the data before
72  * reconstruction. However, it may be faster to have a non-unit stride without
73  * the transpose. We have the `stride` parameter in the reconstruction schemes
74  * to make testing performance easier in the future.
75  *
76  * Here is an ASCII illustration of the names of various quantities and where in
77  * the cells they are:
78  *
79  * \code
80  * reconstructed_upper_side_of_face_vars v
81  * reconstructed_lower_side_of_face_vars v
82  * volume_vars (at the cell-center) v
83  * | x |
84  * ^ reconstructed_upper_side_of_face_vars
85  * ^ reconstructed_lower_side_of_face_vars
86  * \endcode
87  *
88  * Notice that the `reconstructed_upper_side_of_face_vars` are on the lower side
89  * of the cell, while the `reconstructed_lower_side_of_face_vars` are on the
90  * upper side of the cell.
91  */
92 namespace reconstruction {
93 namespace detail {
94 template <typename Reconstructor, size_t Dim, typename... ArgsForReconstructor>
95 void reconstruct(
97  reconstructed_upper_side_of_face_vars,
99  reconstructed_lower_side_of_face_vars,
100  const gsl::span<const double>& volume_vars,
101  const DirectionMap<Dim, gsl::span<const double>>& ghost_cell_vars,
102  const Index<Dim>& volume_extents, const size_t number_of_variables,
103  const ArgsForReconstructor&... args_for_reconstructor) noexcept;
104 } // namespace detail
105 
106 /*!
107  * \ingroup FiniteDifferenceGroup
108  * \brief In a given direction, reconstruct the cells in the neighboring Element
109  * (or cluster of cells) nearest to the shared boundary between the current and
110  * neighboring Element (or cluster of cells).
111  *
112  * This is needed if one is sending reconstruction and flux data separately, or
113  * if one is using DG-FD hybrid schemes. Below is an ASCII diagram of what is
114  * reconstructed.
115  *
116  * ```
117  * Self | Neighbor
118  * x x x x x | o o o
119  * ^+
120  * Reconstruct to right/+ side of the interface
121  * ```
122  */
123 template <Side LowerOrUpperSide, typename Reconstructor, size_t Dim,
124  typename... ArgsForReconstructor>
126  gsl::not_null<DataVector*> face_data, const DataVector& volume_data,
127  const DataVector& neighbor_data, const Index<Dim>& volume_extents,
128  const Index<Dim>& ghost_data_extents,
129  const Direction<Dim>& direction_to_reconstruct,
130  const ArgsForReconstructor&... args_for_reconstructor) noexcept;
131 } // namespace reconstruction
132 } // namespace fd
utility
Side.hpp
fd::reconstruction::reconstruct_neighbor
void reconstruct_neighbor(gsl::not_null< DataVector * > face_data, const DataVector &volume_data, const DataVector &neighbor_data, const Index< Dim > &volume_extents, const Index< Dim > &ghost_data_extents, const Direction< Dim > &direction_to_reconstruct, const ArgsForReconstructor &... args_for_reconstructor) noexcept
In a given direction, reconstruct the cells in the neighboring Element (or cluster of cells) nearest ...
Index
Definition: Index.hpp:31
Direction
Definition: Direction.hpp:23
cstddef
array
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
gsl::span
Create a span/view on a range, which is cheap to copy (one pointer).
Definition: Gsl.hpp:292
DirectionMap
Definition: DirectionMap.hpp:15
Side
Side
Definition: Side.hpp:17
Gsl.hpp
evolution::dg::subcell::fd::reconstruct
DataVector reconstruct(const DataVector &subcell_u_times_projected_det_jac, const Mesh< Dim > &dg_mesh, const Index< Dim > &subcell_extents) noexcept
reconstruct the variable subcell_u_times_projected_det_jac onto the DG grid dg_mesh.
fd
Functions and classes for finite difference methods.
Definition: AoWeno.hpp:25
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13