NormalDotFlux.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <string>
8 
11 #include "DataStructures/Tensor/EagerMath/Magnitude.hpp"
12 #include "DataStructures/Variables.hpp" // IWYU pragma: keep
13 #include "Domain/FaceNormal.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 /// \cond
19 // IWYU pragma: no_forward_declare Variables
20 // IWYU pragma: no_forward_declare Tags::Flux
21 /// \endcond
22 
23 /*!
24  * \brief Contract a surface normal covector with the first index of a flux
25  * tensor
26  *
27  * \details
28  * Returns \f$n_i F^i_{j\ldots}\f$, where the flux tensor \f$F\f$ must have an
29  * upper spatial first index and may have arbitray extra indices.
30  */
31 template <size_t VolumeDim, typename Fr, typename Symm,
32  typename... RemainingIndices,
33  typename ResultTensor = Tensor<DataVector, tmpl::pop_front<Symm>,
34  index_list<RemainingIndices...>>>
35 void normal_dot_flux(
36  const gsl::not_null<ResultTensor*> normal_dot_flux,
37  const tnsr::i<DataVector, VolumeDim, Fr>& normal,
38  const Tensor<DataVector, Symm,
40  RemainingIndices...>>& flux_tensor) noexcept {
41  for (auto it = normal_dot_flux->begin(); it != normal_dot_flux->end(); it++) {
42  const auto result_indices = normal_dot_flux->get_tensor_index(it);
43  *it = get<0>(normal) * flux_tensor.get(prepend(result_indices, size_t{0}));
44  for (size_t d = 1; d < VolumeDim; d++) {
45  *it += normal.get(d) * flux_tensor.get(prepend(result_indices, d));
46  }
47  }
48 }
49 
50 namespace Tags {
51 
52 /// \ingroup ConservativeGroup
53 /// \ingroup DataBoxTagsGroup
54 /// \brief Prefix computing a boundary unit normal vector dotted into
55 /// the flux from a flux on the boundary.
56 template <typename Tag, size_t VolumeDim, typename Fr>
57 struct NormalDotFluxCompute : db::add_tag_prefix<NormalDotFlux, Tag>,
60 
61  private:
63  using normal_tag =
65 
66  public:
67  static auto function(const db::const_item_type<flux_tag>& flux,
68  const db::const_item_type<normal_tag>& normal) noexcept {
69  using tags_list = typename db::const_item_type<Tag>::tags_list;
70  auto result = make_with_value<
72 
73  tmpl::for_each<tags_list>([&result, &flux,
74  &normal ](auto local_tag) noexcept {
75  using tensor_tag = tmpl::type_from<decltype(local_tag)>;
76  normal_dot_flux(make_not_null(&get<NormalDotFlux<tensor_tag>>(result)),
77  normal,
78  get<Flux<tensor_tag, tmpl::size_t<VolumeDim>, Fr>>(flux));
79  });
80  return result;
81  }
82  using argument_tags = tmpl::list<flux_tag, normal_tag>;
83 };
84 } // namespace Tags
Prefix< DataBox_detail::dispatch_add_tag_prefix_impl< Prefix, Tag, Args... >, Args... > add_tag_prefix
Wrap Tag in Prefix<_, Args...>, also wrapping variables tags if Tag is a Tags::Variables.
Definition: DataBoxTag.hpp:616
Prefix indicating a boundary unit normal vector dotted into the flux.
Definition: Prefixes.hpp:122
Definition: Variables.hpp:46
The normalized (co)vector represented by Tag.
Definition: Magnitude.hpp:104
Marks a DataBoxTag as being a compute item that executes a function.
Definition: DataBoxTag.hpp:154
Define prefixes for DataBox tags.
constexpr std::array< T, Dim+1 > prepend(const std::array< T, Dim > &a, T value) noexcept
Construct an array from an existing array prepending a value.
Definition: StdArrayHelpers.hpp:132
Prefix computing a boundary unit normal vector dotted into the flux from a flux on the boundary...
Definition: NormalDotFlux.hpp:57
Tensor_detail::TensorIndexType< SpatialDim, Ul, Fr, IndexType::Spatial > SpatialIndex
A SpatialIndex holds information about the number of spatial dimensions, whether the index is covaria...
Definition: IndexType.hpp:187
std::remove_const_t< R > make_with_value(const T &input, const ValueType &value) noexcept
Given an object of type T, create an object of type R whose elements are initialized to value...
Definition: MakeWithValue.hpp:42
Prefix indicating a flux.
Definition: Prefixes.hpp:54
Defines class Variables.
Definition: DataBoxTag.hpp:29
Declares function unnormalized_face_normal.
Stores a collection of function values.
Definition: DataVector.hpp:42
Wraps the template metaprogramming library used (brigand)
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:879
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines arithmetic operators for std::array and other helpful functions.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12
Defines make_with_value.