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"
11 #include "Utilities/Gsl.hpp"
12 #include "Utilities/TMPL.hpp"
13 
14 /// \cond
15 class DataVector;
16 template <size_t>
17 class Index;
18 template <size_t>
19 class Mesh;
20 /// \endcond
21 
23 namespace detail {
24 template <size_t Dim>
25 void project_impl(gsl::span<double> subcell_u, gsl::span<const double> dg_u,
26  const Mesh<Dim>& dg_mesh,
27  const Index<Dim>& subcell_extents) noexcept;
28 } // namespace detail
29 
30 /// @{
31 /*!
32  * \ingroup DgSubcellGroup
33  * \brief Project the variable `dg_u` onto the subcell grid with extents
34  * `subcell_extents`.
35  *
36  * \note In the return-by-`gsl::not_null` with `Variables` interface, the
37  * `SubcellTagList` and the `DgtagList` must be the same when all tag prefixes
38  * are removed. Typically the `Tags::Inactive` prefix will be used.
39  */
40 template <size_t Dim>
41 DataVector project(const DataVector& dg_u, const Mesh<Dim>& dg_mesh,
42  const Index<Dim>& subcell_extents) noexcept;
43 
44 template <size_t Dim>
45 void project(gsl::not_null<DataVector*> subcell_u, const DataVector& dg_u,
46  const Mesh<Dim>& dg_mesh,
47  const Index<Dim>& subcell_extents) noexcept;
48 
49 template <typename SubcellTagList, typename DgTagList, size_t Dim>
50 void project(const gsl::not_null<Variables<SubcellTagList>*> subcell_u,
51  const Variables<DgTagList>& dg_u, const Mesh<Dim>& dg_mesh,
52  const Index<Dim>& subcell_extents) noexcept {
53  static_assert(
54  std::is_same_v<
55  tmpl::transform<SubcellTagList,
56  tmpl::bind<db::remove_all_prefixes, tmpl::_1>>,
57  tmpl::transform<DgTagList,
58  tmpl::bind<db::remove_all_prefixes, tmpl::_1>>>,
59  "DG and subcell tag lists must be the same once prefix tags "
60  "are removed.");
61  ASSERT(dg_u.number_of_grid_points() == dg_mesh.number_of_grid_points(),
62  "dg_u has incorrect size " << dg_u.number_of_grid_points()
63  << " since the mesh is size "
64  << dg_mesh.number_of_grid_points());
65  if (UNLIKELY(subcell_u->number_of_grid_points() !=
66  subcell_extents.product())) {
67  subcell_u->initialize(subcell_extents.product());
68  }
69  detail::project_impl(gsl::span<double>{subcell_u->data(), subcell_u->size()},
70  gsl::span<const double>{dg_u.data(), dg_u.size()},
71  dg_mesh, subcell_extents);
72 }
73 
74 template <typename TagList, size_t Dim>
75 Variables<TagList> project(const Variables<TagList>& dg_u,
76  const Mesh<Dim>& dg_mesh,
77  const Index<Dim>& subcell_extents) noexcept {
78  Variables<TagList> subcell_u(subcell_extents.product());
79  project(make_not_null(&subcell_u), dg_u, dg_mesh, subcell_extents);
80  return subcell_u;
81 }
82 /// @}
83 } // 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
Assert.hpp
evolution::dg::subcell::fd
Code specific to a conservative finite difference subcell limiter.
Definition: Actions.hpp:10
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
ASSERT
#define ASSERT(a, m)
Assert that an expression should be true.
Definition: Assert.hpp:49
Variables.hpp
Mesh
Holds the number of grid points, basis, and quadrature in each direction of the computational grid.
Definition: Mesh.hpp:49
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: ReadSpecPiecewisePolynomial.hpp:13