Faces.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <type_traits>
8 
9 #include "DataStructures/DataBox/PrefixHelpers.hpp"
10 #include "DataStructures/DataBox/Tag.hpp"
12 #include "Domain/Structure/DirectionMap.hpp"
13 #include "Utilities/Gsl.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 class DataVector;
18 /// \endcond
19 
20 namespace domain {
21 namespace Tags {
22 
23 /// The `Tag` on element faces
24 template <size_t Dim, typename Tag>
26  using tag = Tag;
28 };
29 
30 } // namespace Tags
31 
32 /// Wrap `Tag` in `domain::Tags::Faces`, unless `Tag` is in the `VolumeTags`
33 /// list
34 template <typename Dim, typename Tag, typename VolumeTags = tmpl::list<>>
36  using type = tmpl::conditional_t<tmpl::list_contains_v<VolumeTags, Tag>, Tag,
38 };
39 
40 /// Wrap all tags in `TagsList` in `domain::Tags::Faces`, except those in the
41 /// `VolumeTags` list
42 template <size_t Dim, typename TagsList, typename VolumeTags = tmpl::list<>>
43 using make_faces_tags =
44  tmpl::transform<TagsList, make_faces_tag<tmpl::pin<tmpl::size_t<Dim>>,
45  tmpl::_1, tmpl::pin<VolumeTags>>>;
46 
47 } // namespace domain
48 
49 namespace db {
50 template <size_t Dim, typename VariablesTag>
51 struct Subitems<domain::Tags::Faces<Dim, VariablesTag>,
52  Requires<tt::is_a_v<Variables, typename VariablesTag::type>>> {
53  template <typename LocalTag>
55 
57  using type =
59 
60  template <typename Subtag>
61  static void create_item(
62  const gsl::not_null<typename tag::type*> parent_value,
63  const gsl::not_null<typename Subtag::type*> sub_value) noexcept {
64  sub_value->clear();
65  for (auto& [direction, all_parent_vars] : *parent_value) {
66  auto& parent_var = get<typename Subtag::tag>(all_parent_vars);
67  auto& sub_var = (*sub_value)[direction];
68  for (auto vars_it = parent_var.begin(), sub_var_it = sub_var.begin();
69  vars_it != parent_var.end(); ++vars_it, ++sub_var_it) {
70  sub_var_it->set_data_ref(&*vars_it);
71  }
72  }
73  }
74 
75  // The `return_type` can be anything for Subitems because the DataBox figures
76  // out the correct return type, we just use the `return_type` type alias to
77  // signal to the DataBox we want mutating behavior.
78  using return_type = NoSuchType;
79 
80  template <typename Subtag>
81  static void create_compute_item(
83  const typename tag::type& parent_value) noexcept {
84  for (const auto& [direction, all_parent_vars] : parent_value) {
85  const auto& parent_var = get<typename Subtag::tag>(all_parent_vars);
86  auto& sub_var = (*sub_value)[direction];
87  auto sub_var_it = sub_var.begin();
88  for (auto vars_it = parent_var.begin(); vars_it != parent_var.end();
89  ++vars_it, ++sub_var_it) {
90  // clang-tidy: do not use const_cast
91  // The DataBox will only give out a const reference to the
92  // result of a compute item. Here, that is a reference to a
93  // const map to Tensors of DataVectors. There is no (publicly
94  // visible) indirection there, so having the map const will
95  // allow only allow const access to the contained DataVectors,
96  // so no modification through the pointer cast here is
97  // possible.
98  sub_var_it->set_data_ref(const_cast<DataVector*>(&*vars_it)); // NOLINT
99  }
100  }
101  }
102 };
103 } // namespace db
NoSuchType
Used to mark "no type" or "bad state" for metaprogramming.
Definition: NoSuchType.hpp:10
db::PrefixTag
Mark a struct as a prefix tag by inheriting from this.
Definition: Tag.hpp:103
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
domain::Tags::Faces
The Tag on element faces.
Definition: Faces.hpp:25
domain::make_faces_tag
Wrap Tag in domain::Tags::Faces, unless Tag is in the VolumeTags list.
Definition: Faces.hpp:35
cstddef
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
Variables.hpp
DirectionMap
Definition: DirectionMap.hpp:15
Gsl.hpp
db::wrap_tags_in
tmpl::transform< TagList, tmpl::bind< Wrapper, tmpl::_1, tmpl::pin< Args >... > > wrap_tags_in
Create a new tmpl::list of tags by wrapping each tag in TagList in Wrapper<_, Args....
Definition: PrefixHelpers.hpp:30
db::Subitems
Definition: Subitems.hpp:32
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
type_traits
TMPL.hpp
db
Namespace for DataBox related things.
Definition: DataBox.hpp:44
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13