TensorAsExpressionRank1TestHelpers.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <iterator>
8 #include <numeric>
9 
13 
14 namespace TestHelpers::TensorExpressions {
15 /// \ingroup TestingFrameworkGroup
16 /// \brief Test that the transformation between LHS and RHS multi-indices and
17 /// the subsequent computed RHS multi-index of a rank 1 tensor is correctly
18 /// computed by the functions of TensorAsExpression
19 ///
20 /// \details The functions tested are:
21 /// - `TensorAsExpression::compute_index_transformation`
22 /// - `TensorAsExpression::compute_rhs_multi_index`
23 ///
24 /// \param tensorindex the TensorIndex used in the the TensorExpression,
25 /// e.g. `ti_a`
26 template <typename TensorIndex>
27 void test_tensor_as_expression_rank_1(const TensorIndex& tensorindex) noexcept {
28  const size_t dim = 3;
29  const IndexType indextype =
30  TensorIndex::is_spacetime ? IndexType::Spacetime : IndexType::Spatial;
31 
32  Tensor<double, Symmetry<1>,
33  index_list<Tensor_detail::TensorIndexType<dim, TensorIndex::valence,
34  Frame::Grid, indextype>>>
35  rhs_tensor{};
36  std::iota(rhs_tensor.begin(), rhs_tensor.end(), 0.0);
37  // Get TensorExpression from RHS tensor
38  const auto R_a_expr = rhs_tensor(tensorindex);
39 
40  const std::array<size_t, 1> index_order = {TensorIndex::value};
41 
42  const std::array<size_t, 1> actual_transformation =
43  R_a_expr.compute_index_transformation(index_order);
44  const std::array<size_t, 1> expected_transformation = {0};
45  CHECK(actual_transformation == expected_transformation);
46 
47  // For L_a = R_a, check that L_i == R_i
48  for (size_t i = 0; i < dim; i++) {
49  const std::array<size_t, 1> tensor_multi_index = {i};
50  CHECK(R_a_expr.compute_rhs_multi_index(tensor_multi_index,
51  expected_transformation) ==
52  tensor_multi_index);
53  }
54 }
55 } // namespace TestHelpers::TensorExpressions
TensorExpression.hpp
IndexType.hpp
Frame::Grid
Definition: IndexType.hpp:43
TensorIndex
Represents the indices in a TensorExpression.
Definition: TensorExpression.hpp:65
iterator
IndexType::Spatial
@ Spatial
The TensorIndexType is purely spatial.
IndexType::Spacetime
@ Spacetime
The TensorIndexType is a spacetime index.
cstddef
std::array< size_t, 1 >
TestHelpers::TensorExpressions::test_tensor_as_expression_rank_1
void test_tensor_as_expression_rank_1(const TensorIndex &tensorindex) noexcept
Test that the transformation between LHS and RHS multi-indices and the subsequent computed RHS multi-...
Definition: TensorAsExpressionRank1TestHelpers.hpp:27
IndexType
IndexType
Definition: IndexType.hpp:134
Tensor.hpp
numeric
cpp2b::iota
constexpr void iota(ForwardIterator first, ForwardIterator last, T value)
Definition: Numeric.hpp:20