TagsCharacteresticSpeeds.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <boost/optional.hpp>
8 #include <cstddef>
9 
10 #include "DataStructures/DataVector.hpp"
12 #include "DataStructures/Tensor/EagerMath/Magnitude.hpp" // For Tags::Normalized
14 #include "Domain/Tags.hpp"
15 #include "Domain/TagsTimeDependent.hpp"
16 #include "Utilities/Gsl.hpp"
17 #include "Utilities/TMPL.hpp"
18 
19 namespace domain {
20 namespace Tags {
21 /// Compute the characteristic speeds on the moving mesh given the
22 /// characteristic speeds if the mesh were stationary.
23 ///
24 /// \note Assumes that `typename CharSpeedsComputeTag::return_type` is a
25 /// `std::array<DataVector, NumberOfCharSpeeds>`
26 template <typename CharSpeedsComputeTag, size_t Dim>
27 struct CharSpeedCompute : CharSpeedsComputeTag {
28  using base = CharSpeedsComputeTag;
29  using return_type = typename CharSpeedsComputeTag::return_type;
30 
31  template <typename... Ts, typename T, size_t NumberOfCharSpeeds>
32  static void function(
34  const boost::optional<tnsr::I<DataVector, Dim, Frame::Inertial>>&
35  grid_velocity,
36  const tnsr::i<DataVector, Dim, Frame::Inertial>& unit_normal_covector,
37  const Ts&... ts) noexcept {
38  // Note that while the CharSpeedsComputeTag almost certainly also needs the
39  // unit normal covector for computing the original characteristic speeds, we
40  // don't know which of the `ts` it is, and thus we need the unit normal
41  // covector to be passed explicitly.
42  CharSpeedsComputeTag::function(result, ts...);
43  if (static_cast<bool>(grid_velocity)) {
44  const Scalar<DataVector> normal_dot_velocity =
45  dot_product(*grid_velocity, unit_normal_covector);
46  for (size_t i = 0; i < result->size(); ++i) {
47  gsl::at(*result, i) -= get(normal_dot_velocity);
48  }
49  }
50  }
51 
52  using argument_tags =
53  tmpl::push_front<typename CharSpeedsComputeTag::argument_tags,
56 };
57 } // namespace Tags
58 } // namespace domain
The normalized (co)vector represented by Tag.
Definition: Magnitude.hpp:121
Definition: BlockId.hpp:16
Defines functions euclidean dot_product and dot_product with a metric.
CoordinateMap< SourceFrame, TargetFrame, NewMap, Maps... > push_front(CoordinateMap< SourceFrame, TargetFrame, Maps... > old_map, NewMap new_map) noexcept
Creates a CoordinateMap by prepending the new map to the beginning of the old maps.
Definition: DataBoxTag.hpp:27
Defines classes for Tensor.
Compute the characteristic speeds on the moving mesh given the characteristic speeds if the mesh were...
Definition: TagsCharacteresticSpeeds.hpp:27
Wraps the template metaprogramming library used (brigand)
Defines functions and classes from the GSL.
Defines tags related to domain quantities.
void dot_product(const gsl::not_null< Scalar< DataType > *> dot_product, const Tensor< DataType, Symmetry< 1 >, index_list< Index >> &vector_a, const Tensor< DataType, Symmetry< 1 >, index_list< Index >> &vector_b) noexcept
Compute the Euclidean dot product of two vectors or one forms.
Definition: DotProduct.hpp:24
Tensor< T, Symmetry<>, index_list<> > Scalar
Scalar type.
Definition: TypeAliases.hpp:21
Require a pointer to not be a nullptr
Definition: Gsl.hpp:182
constexpr T & at(std::array< T, N > &arr, Size index)
Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid...
Definition: Gsl.hpp:124