Projection.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 #include "DataStructures/DataBox/PrefixHelpers.hpp"
10 #include "Utilities/Gsl.hpp"
11 #include "Utilities/TMPL.hpp"
12 
13 /// \cond
14 class DataVector;
15 template <size_t>
16 class Index;
17 template <size_t>
18 class Mesh;
19 /// \endcond
20 
22 namespace detail {
23 template <size_t Dim>
24 void project_impl(gsl::span<double> subcell_u, gsl::span<const double> dg_u,
25  const Mesh<Dim>& dg_mesh,
26  const Index<Dim>& subcell_extents) noexcept;
27 } // namespace detail
28 
29 // @{
30 /*!
31  * \ingroup DgSubcellGroup
32  * \brief Project the variable `dg_u` onto the subcell grid with extents
33  * `subcell_extents`.
34  *
35  * \note In the return-by-`gsl::not_null` with `Variables` interface, the
36  * `SubcellTagList` and the `DgtagList` must be the same when all tag prefixes
37  * are removed. Typically the `Tags::Inactive` prefix will be used.
38  */
39 template <size_t Dim>
40 DataVector project(const DataVector& dg_u, const Mesh<Dim>& dg_mesh,
41  const Index<Dim>& subcell_extents) noexcept;
42 
43 template <size_t Dim>
44 void project(gsl::not_null<DataVector*> subcell_u, const DataVector& dg_u,
45  const Mesh<Dim>& dg_mesh,
46  const Index<Dim>& subcell_extents) noexcept;
47 
48 template <typename SubcellTagList, typename DgTagList, size_t Dim>
49 void project(const gsl::not_null<Variables<SubcellTagList>*> subcell_u,
50  const Variables<DgTagList>& dg_u, const Mesh<Dim>& dg_mesh,
51  const Index<Dim>& subcell_extents) noexcept {
52  static_assert(
53  std::is_same_v<
54  tmpl::transform<SubcellTagList,
55  tmpl::bind<db::remove_all_prefixes, tmpl::_1>>,
56  tmpl::transform<DgTagList,
57  tmpl::bind<db::remove_all_prefixes, tmpl::_1>>>,
58  "DG and subcell tag lists must be the same once prefix tags "
59  "are removed.");
60  if (UNLIKELY(subcell_u->number_of_grid_points() !=
61  subcell_extents.product())) {
62  subcell_u->initialize(subcell_extents.product());
63  }
64  detail::project_impl(gsl::span<double>{subcell_u->data(), subcell_u->size()},
65  gsl::span<const double>{dg_u.data(), dg_u.size()},
66  dg_mesh, subcell_extents);
67 }
68 
69 template <typename TagList, size_t Dim>
70 Variables<TagList> project(const Variables<TagList>& dg_u,
71  const Mesh<Dim>& dg_mesh,
72  const Index<Dim>& subcell_extents) noexcept {
73  Variables<TagList> subcell_u(subcell_extents.product());
74  project(make_not_null(&subcell_u), dg_u, dg_mesh, subcell_extents);
75  return subcell_u;
76 }
77 // @}
78 } // namespace evolution::dg::subcell::fd
evolution::dg::subcell::fd::project
DataVector project(const DataVector &dg_u, const Mesh< Dim > &dg_mesh, const Index< Dim > &subcell_extents) noexcept
Project the variable dg_u onto the subcell grid with extents subcell_extents.
UNLIKELY
#define UNLIKELY(x)
Definition: Gsl.hpp:73
Index
Definition: Index.hpp:31
cstddef
evolution::dg::subcell::fd
Code specific to a conservative finite difference subcell limiter.
Definition: DgSubcell.hpp:29
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
Variables.hpp
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:48
gsl::span
Create a span/view on a range, which is cheap to copy (one pointer).
Definition: Gsl.hpp:292
Gsl.hpp
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13