LhsTensorSymmAndIndices.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 #include <utility>
9 
14 #include "Utilities/Algorithm.hpp"
15 #include "Utilities/TMPL.hpp"
16 
17 namespace TensorExpressions {
18 /*!
19  * \ingroup TensorExpressionsGroup
20  * \brief Determines and stores a LHS tensor's symmetry and index list from a
21  * RHS tensor expression and desired LHS index order
22  *
23  * \details Given the generic index order of a RHS TensorExpression and the
24  * generic index order of the desired LHS Tensor, this creates a mapping between
25  * the two that is used to determine the (potentially reordered) ordering of the
26  * elements of the desired LHS Tensor`s ::Symmetry and typelist of
27  * \ref SpacetimeIndex "TensorIndexType"s.
28  *
29  * Note: If a generic spatial index is used for a spacetime index in the RHS
30  * tensor, its corresponding index in the LHS tensor type will be a spatial
31  * index with the same valence, frame, and number of spatial dimensions.
32  *
33  * @tparam RhsTensorIndexList the typelist of TensorIndex of the RHS
34  * TensorExpression
35  * @tparam LhsTensorIndexList the typelist of TensorIndexs of the desired LHS
36  * tensor
37  * @tparam RhsSymmetry the ::Symmetry of the RHS indices
38  * @tparam RhsTensorIndexTypeList the RHS TensorExpression's typelist of
39  * \ref SpacetimeIndex "TensorIndexType"s
40  */
41 template <typename RhsTensorIndexList, typename LhsTensorIndexList,
42  typename RhsSymmetry, typename RhsTensorIndexTypeList,
43  size_t NumIndices = tmpl::size<RhsSymmetry>::value,
44  typename IndexSequence = std::make_index_sequence<NumIndices>>
46 
47 template <typename RhsTensorIndexList, typename... LhsTensorIndices,
48  typename RhsSymmetry, typename RhsTensorIndexTypeList,
49  size_t NumIndices, size_t... Ints>
51  RhsTensorIndexList, tmpl::list<LhsTensorIndices...>, RhsSymmetry,
52  RhsTensorIndexTypeList, NumIndices, std::index_sequence<Ints...>> {
53  // LHS generic indices, RHS generic indices, and the mapping between them
54  static constexpr std::array<size_t, NumIndices> lhs_tensorindex_values = {
55  {LhsTensorIndices::value...}};
56  static constexpr std::array<size_t, NumIndices> rhs_tensorindex_values = {
57  {tmpl::at_c<RhsTensorIndexList, Ints>::value...}};
58  static constexpr std::array<size_t, NumIndices> rhs_to_lhs_map =
59  compute_tensorindex_transformation(rhs_tensorindex_values,
60  lhs_tensorindex_values);
61 
62  // Compute symmetry of RHS after spacetime indices using generic spatial
63  // indices are swapped for spatial indices
64  static constexpr std::array<std::int32_t, NumIndices> rhs_symmetry = {
65  {tmpl::at_c<RhsSymmetry, Ints>::value...}};
66  using rhs_spatial_spacetime_index_positions_ =
67  detail::spatial_spacetime_index_positions<RhsTensorIndexTypeList,
68  RhsTensorIndexList>;
69  using make_list_type = std::conditional_t<
70  tmpl::size<rhs_spatial_spacetime_index_positions_>::value == 0, size_t,
71  rhs_spatial_spacetime_index_positions_>;
72  static constexpr auto rhs_spatial_spacetime_index_positions =
73  make_array_from_list<make_list_type>();
75  rhs_spatial_spacetime_index_symmetry =
76  detail::get_spatial_spacetime_index_symmetry(
77  rhs_symmetry, rhs_spatial_spacetime_index_positions);
78 
79  // Compute index list of RHS after spacetime indices using generic spatial
80  // indices are made nonsymmetric to other indices
81  using rhs_spatial_spacetime_tensorindextype_list =
82  detail::replace_spatial_spacetime_indices<
83  RhsTensorIndexTypeList, rhs_spatial_spacetime_index_positions_>;
84 
85  // Desired LHS Tensor's Symmetry, typelist of TensorIndexTypes, and Structure
86  using symmetry =
87  Symmetry<rhs_spatial_spacetime_index_symmetry[rhs_to_lhs_map[Ints]]...>;
88  using tensorindextype_list =
89  tmpl::list<tmpl::at_c<rhs_spatial_spacetime_tensorindextype_list,
90  rhs_to_lhs_map[Ints]>...>;
91  using structure =
92  Tensor_detail::Structure<symmetry,
93  tmpl::at_c<tensorindextype_list, Ints>...>;
94 };
95 } // namespace TensorExpressions
utility
Symmetry.hpp
std::make_index_sequence
SpatialSpacetimeIndex.hpp
TensorExpressions::LhsTensorSymmAndIndices
Determines and stores a LHS tensor's symmetry and index list from a RHS tensor expression and desired...
Definition: LhsTensorSymmAndIndices.hpp:45
Structure.hpp
TensorExpressions
Definition: AddSubtract.hpp:36
cstddef
array
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
TensorExpressions::compute_tensorindex_transformation
constexpr std::array< size_t, NumIndices > compute_tensorindex_transformation(const std::array< size_t, NumIndices > &tensorindices1, const std::array< size_t, NumIndices > &tensorindices2) noexcept
Computes a transformation from one generic tensor index order to another.
Definition: TensorIndexTransformation.hpp:51
std::conditional_t
TMPL.hpp
TensorIndexTransformation.hpp