NormalVectors.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <cstddef>
7
8 #include "DataStructures/DataVector.hpp"
9
11 #include "Utilities/Gsl.hpp"
12 #include "Utilities/TMPL.hpp"
13 #include "Utilities/TypeTraits/CreateHasTypeAlias.hpp"
14
15 namespace TestHelpers::evolution::dg::detail {
16 CREATE_HAS_TYPE_ALIAS(inverse_spatial_metric_tag)
17 CREATE_HAS_TYPE_ALIAS_V(inverse_spatial_metric_tag)
18
19 template <bool HasInverseSpatialMetricTag = false>
20 struct inverse_spatial_metric_tag {
21  template <typename System>
22  using f = tmpl::list<>;
23 };
24
25 template <>
26 struct inverse_spatial_metric_tag<true> {
27  template <typename System>
28  using f = typename System::inverse_spatial_metric_tag;
29 };
30
31 // Takes in a spatial metric, or inverse spatial metric, with random components
32 // in the range [-1,1]. Adjusts the metric (or inverse) by scaling all
33 // components to lie in [0,0.01] and then adding 1 to the diagonal.
34 // This is to give an inverse spatial metric of the form:
35 // \delta^{ij} + small^{ij}
36 // This is done to give a physically reasonable spatial metric (or inverse)
37 template <typename Index>
39  const gsl::not_null<
40  Tensor<DataVector, Symmetry<1, 1>, index_list<Index, Index>>*>
41  spatial_metric_or_inverse) {
42  for (size_t i = 0; i < Index::dim; ++i) {
43  for (size_t j = i; j < Index::dim; ++j) {
44  spatial_metric_or_inverse->get(i, j) += 1.0;
45  spatial_metric_or_inverse->get(i, j) *= 0.005;
46  }
47  }
48  for (size_t i = 0; i < Index::dim; ++i) {
49  spatial_metric_or_inverse->get(i, i) += 1.0;
50  }
51 }
52
53 // On input the unit_normal_covector is the unnormalized normal covector. On
54 // output unit_normal_covector is the normalized (and hence actually unit)
55 // normal covector, and unit_normal_vector is the unit normal vector. The
56 // inverse spatial metric is used for computing the magnitude of the
57 // unnormalized normal vector.
58 template <size_t Dim>
59 void normalize_vector_and_covector(
60  const gsl::not_null<tnsr::i<DataVector, Dim>*> unit_normal_covector,
61  const gsl::not_null<tnsr::I<DataVector, Dim>*> unit_normal_vector,
62  const tnsr::II<DataVector, Dim>& inv_spatial_metric) {
63  for (size_t i = 0; i < Dim; ++i) {
64  unit_normal_vector->get(i) =
65  inv_spatial_metric.get(i, 0) * get<0>(*unit_normal_covector);
66  for (size_t j = 1; j < Dim; ++j) {
67  unit_normal_vector->get(i) +=
68  inv_spatial_metric.get(i, j) * unit_normal_covector->get(j);
69  }
70  }
71
72  const DataVector normal_magnitude =
73  sqrt(get(dot_product(*unit_normal_covector, *unit_normal_vector)));
74  for (auto& t : *unit_normal_covector) {
75  t /= normal_magnitude;
76  }
77  for (auto& t : *unit_normal_vector) {
78  t /= normal_magnitude;
79  }
80 }
81 } // namespace TestHelpers::evolution::dg::detail
sqrt
auto sqrt(const TensorExpression< T, typename T::type, tmpl::list<>, tmpl::list<>, tmpl::list<>> &t)
Returns the tensor expression representing the square root of a tensor expression that evaluates to a...
Definition: SquareRoot.hpp:83
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
dot_product
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:25
CREATE_HAS_TYPE_ALIAS
#define CREATE_HAS_TYPE_ALIAS(ALIAS_NAME)
Generate a type trait to check if a class has a type alias with a particular name,...
Definition: CreateHasTypeAlias.hpp:27
DotProduct.hpp
cstddef
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
Symmetry
typename detail::SymmetryImpl< std::make_index_sequence< sizeof...(T)>, tmpl::integral_list< std::int32_t, T... > >::type Symmetry
Computes the canonical symmetry from the integers T
Definition: Symmetry.hpp:80
Gsl.hpp
Tensor.hpp
CREATE_HAS_TYPE_ALIAS_V
#define CREATE_HAS_TYPE_ALIAS_V(ALIAS_NAME)
Generate a type trait to check if a class has a type alias with a particular name,...
Definition: CreateHasTypeAlias.hpp:39
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr