ComputeRhsTensorIndexRank1TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 
11 #include "Utilities/GenerateInstantiations.hpp"
12 #include "Utilities/TMPL.hpp"
13 
14 namespace TestHelpers::TensorExpressions {
15 
16 /// \ingroup TestingFrameworkGroup
17 /// \brief Test that the computed tensor multi-index of a rank 1 RHS Tensor is
18 /// equivalent to the given LHS tensor multi-index
19 ///
20 /// \tparam DataType the type of data being stored in the Tensors
21 /// \tparam TensorIndexTypeList the Tensors' typelist containing their
22 /// \ref SpacetimeIndex "TensorIndexType"
23 /// \param tensorindex the TensorIndex used in the the TensorExpression,
24 /// e.g. `ti_a`
25 template <typename DataType, typename TensorIndexTypeList, typename TensorIndex>
27  const TensorIndex& tensorindex) noexcept {
28  const Tensor<DataType, Symmetry<1>, TensorIndexTypeList> rhs_tensor(5_st);
29  // Get TensorExpression from RHS tensor
30  const auto R_a = rhs_tensor(tensorindex);
31 
32  const std::array<size_t, 1> index_order = {TensorIndex::value};
33 
34  const size_t dim = tmpl::at_c<TensorIndexTypeList, 0>::dim;
35 
36  // For L_a = R_a, check that L_i == R_i
37  for (size_t i = 0; i < dim; i++) {
38  const std::array<size_t, 1> tensor_multi_index = {i};
39  CHECK(R_a.compute_rhs_tensor_index(index_order, index_order,
40  tensor_multi_index) ==
41  tensor_multi_index);
42  }
43 }
44 
45 /// \ingroup TestingFrameworkGroup
46 /// \brief Iterate testing of computing the RHS tensor multi-index equivalent of
47 /// the LHS tensor multi-index with rank 1 Tensors on multiple Frame types and
48 /// dimensions
49 ///
50 /// \tparam DataType the type of data being stored in the Tensors
51 /// \tparam TensorIndexType the Tensors' \ref SpacetimeIndex "TensorIndexType"
52 /// \tparam Valence the valence of the Tensors' index
53 /// \param tensorindex the TensorIndex used in the the TensorExpression,
54 /// e.g. `ti_a`
55 template <typename DataType,
56  template <size_t, UpLo, typename> class TensorIndexType, UpLo Valence,
57  typename TensorIndex>
59  const TensorIndex& tensorindex) noexcept {
60 #define DIM(data) BOOST_PP_TUPLE_ELEM(0, data)
61 #define FRAME(data) BOOST_PP_TUPLE_ELEM(1, data)
62 
63 #define CALL_TEST_COMPUTE_RHS_TENSOR_INDEX_RANK_1_IMPL(_, data) \
64  test_compute_rhs_tensor_index_rank_1_impl< \
65  DataType, index_list<TensorIndexType<DIM(data), Valence, FRAME(data)>>>( \
66  tensorindex);
67 
68  GENERATE_INSTANTIATIONS(CALL_TEST_COMPUTE_RHS_TENSOR_INDEX_RANK_1_IMPL,
69  (1, 2, 3), (Frame::Grid, Frame::Inertial))
70 
71 #undef CALL_TEST_COMPUTE_RHS_TENSOR_INDEX_RANK_1_IMPL
72 #undef FRAME
73 #undef DIM
74 }
75 
76 } // namespace TestHelpers::TensorExpressions
Frame::Inertial
Definition: IndexType.hpp:44
TensorExpression.hpp
UpLo
UpLo
Definition: IndexType.hpp:20
Frame::Grid
Definition: IndexType.hpp:43
TestHelpers::TensorExpressions::test_compute_rhs_tensor_index_rank_1_impl
void test_compute_rhs_tensor_index_rank_1_impl(const TensorIndex &tensorindex) noexcept
Test that the computed tensor multi-index of a rank 1 RHS Tensor is equivalent to the given LHS tenso...
Definition: ComputeRhsTensorIndexRank1TestHelpers.hpp:26
TensorIndex
Represents the indices in a TensorExpression.
Definition: TensorExpression.hpp:66
cstddef
array
TestHelpers::TensorExpressions::test_compute_rhs_tensor_index_rank_1
void test_compute_rhs_tensor_index_rank_1(const TensorIndex &tensorindex) noexcept
Iterate testing of computing the RHS tensor multi-index equivalent of the LHS tensor multi-index with...
Definition: ComputeRhsTensorIndexRank1TestHelpers.hpp:58
Tensor.hpp
GENERATE_INSTANTIATIONS
#define GENERATE_INSTANTIATIONS(INSTANTIATION_MACRO,...)
Macro useful for generating many explicit instantiations of function or class templates.
Definition: GenerateInstantiations.hpp:160
TMPL.hpp