SpECTRE Documentation Coverage Report
Current view: top level - Evolution/DgSubcell - Projection.hpp Hit Total Coverage
Commit: 9a905b0737f373631c1b8e8389b8f26e67fa5313 Lines: 8 9 88.9 %
Date: 2024-03-28 09:03:18
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // 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"
       9             : #include "DataStructures/Variables.hpp"
      10             : #include "Utilities/ErrorHandling/Assert.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             : 
      22             : namespace evolution::dg::subcell::fd {
      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, const Index<Dim>& subcell_extents);
      27             : template <size_t Dim>
      28             : void project_to_faces_impl(gsl::span<double> subcell_u,
      29             :                            gsl::span<const double> dg_u,
      30             :                            const Mesh<Dim>& dg_mesh,
      31             :                            const Index<Dim>& subcell_extents,
      32             :                            const size_t& face_direction);
      33             : }  // namespace detail
      34             : 
      35             : /// @{
      36             : /*!
      37             :  * \ingroup DgSubcellGroup
      38             :  * \brief Project the variable `dg_u` onto the subcell grid with extents
      39             :  * `subcell_extents`.
      40             :  *
      41             :  * \note In the return-by-`gsl::not_null` with `Variables` interface, the
      42             :  * `SubcellTagList` and the `DgtagList` must be the same when all tag prefixes
      43             :  * are removed.
      44             :  */
      45             : template <size_t Dim>
      46           1 : DataVector project(const DataVector& dg_u, const Mesh<Dim>& dg_mesh,
      47             :                    const Index<Dim>& subcell_extents);
      48             : 
      49             : template <size_t Dim>
      50           1 : void project(gsl::not_null<DataVector*> subcell_u, const DataVector& dg_u,
      51             :              const Mesh<Dim>& dg_mesh, const Index<Dim>& subcell_extents);
      52             : 
      53             : template <typename SubcellTagList, typename DgTagList, size_t Dim>
      54           1 : void project(const gsl::not_null<Variables<SubcellTagList>*> subcell_u,
      55             :              const Variables<DgTagList>& dg_u, const Mesh<Dim>& dg_mesh,
      56             :              const Index<Dim>& subcell_extents) {
      57             :   static_assert(
      58             :       std::is_same_v<
      59             :           tmpl::transform<SubcellTagList,
      60             :                           tmpl::bind<db::remove_all_prefixes, tmpl::_1>>,
      61             :           tmpl::transform<DgTagList,
      62             :                           tmpl::bind<db::remove_all_prefixes, tmpl::_1>>>,
      63             :       "DG and subcell tag lists must be the same once prefix tags "
      64             :       "are removed.");
      65             :   ASSERT(dg_u.number_of_grid_points() == dg_mesh.number_of_grid_points(),
      66             :          "dg_u has incorrect size " << dg_u.number_of_grid_points()
      67             :                                     << " since the mesh is size "
      68             :                                     << dg_mesh.number_of_grid_points());
      69             :   if (UNLIKELY(subcell_u->number_of_grid_points() !=
      70             :                subcell_extents.product())) {
      71             :     subcell_u->initialize(subcell_extents.product());
      72             :   }
      73             :   detail::project_impl(gsl::span<double>{subcell_u->data(), subcell_u->size()},
      74             :                        gsl::span<const double>{dg_u.data(), dg_u.size()},
      75             :                        dg_mesh, subcell_extents);
      76             : }
      77             : 
      78             : template <typename TagList, size_t Dim>
      79           1 : Variables<TagList> project(const Variables<TagList>& dg_u,
      80             :                            const Mesh<Dim>& dg_mesh,
      81             :                            const Index<Dim>& subcell_extents) {
      82             :   Variables<TagList> subcell_u(subcell_extents.product());
      83             :   project(make_not_null(&subcell_u), dg_u, dg_mesh, subcell_extents);
      84             :   return subcell_u;
      85             : }
      86             : 
      87             : template <size_t Dim>
      88           1 : DataVector project_to_faces(const DataVector& dg_u, const Mesh<Dim>& dg_mesh,
      89             :                             const Index<Dim>& subcell_extents,
      90             :                             const size_t& face_direction);
      91             : 
      92             : template <size_t Dim>
      93           1 : void project_to_faces(gsl::not_null<DataVector*> subcell_u,
      94             :                       const DataVector& dg_u, const Mesh<Dim>& dg_mesh,
      95             :                       const Index<Dim>& subcell_extents,
      96             :                       const size_t& face_direction);
      97             : 
      98             : template <typename SubcellTagList, typename DgTagList, size_t Dim>
      99           1 : void project_to_faces(const gsl::not_null<Variables<SubcellTagList>*> subcell_u,
     100             :                       const Variables<DgTagList>& dg_u,
     101             :                       const Mesh<Dim>& dg_mesh,
     102             :                       const Index<Dim>& subcell_extents,
     103             :                       const size_t& face_direction) {
     104             :   static_assert(
     105             :       std::is_same_v<
     106             :           tmpl::transform<SubcellTagList,
     107             :                           tmpl::bind<db::remove_all_prefixes, tmpl::_1>>,
     108             :           tmpl::transform<DgTagList,
     109             :                           tmpl::bind<db::remove_all_prefixes, tmpl::_1>>>,
     110             :       "DG and subcell tag lists must be the same once prefix tags "
     111             :       "are removed.");
     112             :   ASSERT(dg_u.number_of_grid_points() == dg_mesh.number_of_grid_points(),
     113             :          "dg_u has incorrect size " << dg_u.number_of_grid_points()
     114             :                                     << " since the mesh is size "
     115             :                                     << dg_mesh.number_of_grid_points());
     116             :   if (UNLIKELY(subcell_u->number_of_grid_points() !=
     117             :                subcell_extents.product())) {
     118             :     subcell_u->initialize(subcell_extents.product());
     119             :   }
     120             :   detail::project_to_faces_impl(
     121             :       gsl::span<double>{subcell_u->data(), subcell_u->size()},
     122             :       gsl::span<const double>{dg_u.data(), dg_u.size()}, dg_mesh,
     123             :       subcell_extents, face_direction);
     124             : }
     125             : 
     126             : template <typename TagList, size_t Dim>
     127           1 : Variables<TagList> project_to_faces(const Variables<TagList>& dg_u,
     128             :                                     const Mesh<Dim>& dg_mesh,
     129             :                                     const Index<Dim>& subcell_extents,
     130             :                                     const size_t& face_direction) {
     131             :   Variables<TagList> subcell_u(subcell_extents.product());
     132             :   project_to_faces(make_not_null(&subcell_u), dg_u, dg_mesh, subcell_extents,
     133             :                    face_direction);
     134             :   return subcell_u;
     135             : }
     136             : /// @}
     137             : }  // namespace evolution::dg::subcell::fd

Generated by: LCOV version 1.14