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 
12 #include "Utilities/Algorithm.hpp"
13 #include "Utilities/TMPL.hpp"
14 
15 namespace TensorExpressions {
16 /*!
17  * \ingroup TensorExpressionsGroup
18  * \brief Determines and stores a LHS tensor's symmetry and index list from a
19  * RHS tensor expression and desired LHS index order
20  *
21  * \details Given the generic index order of a RHS TensorExpression and the
22  * generic index order of the desired LHS Tensor, this creates a mapping between
23  * the two that is used to determine the (potentially reordered) ordering of the
24  * elements of the desired LHS Tensor`s ::Symmetry and typelist of
25  * \ref SpacetimeIndex "TensorIndexType"s.
26  *
27  * @tparam RhsTensorIndexList the typelist of TensorIndex of the RHS
28  * TensorExpression
29  * @tparam LhsTensorIndexList the typelist of TensorIndexs of the desired LHS
30  * tensor
31  * @tparam RhsSymmetry the ::Symmetry of the RHS indices
32  * @tparam RhsTensorIndexTypeList the RHS TensorExpression's typelist of
33  * \ref SpacetimeIndex "TensorIndexType"s
34  */
35 template <typename RhsTensorIndexList, typename LhsTensorIndexList,
36  typename RhsSymmetry, typename RhsTensorIndexTypeList,
37  size_t NumIndices = tmpl::size<RhsSymmetry>::value,
38  typename IndexSequence = std::make_index_sequence<NumIndices>>
40 
41 template <typename RhsTensorIndexList, typename... LhsTensorIndices,
42  typename RhsSymmetry, typename RhsTensorIndexTypeList,
43  size_t NumIndices, size_t... Ints>
45  RhsTensorIndexList, tmpl::list<LhsTensorIndices...>, RhsSymmetry,
46  RhsTensorIndexTypeList, NumIndices, std::index_sequence<Ints...>> {
47  static constexpr std::array<size_t, NumIndices> lhs_tensorindex_values = {
48  {LhsTensorIndices::value...}};
49  static constexpr std::array<size_t, NumIndices> rhs_tensorindex_values = {
50  {tmpl::at_c<RhsTensorIndexList, Ints>::value...}};
51  static constexpr std::array<size_t, NumIndices> lhs_to_rhs_map = {
52  {std::distance(
53  rhs_tensorindex_values.begin(),
54  alg::find(rhs_tensorindex_values, lhs_tensorindex_values[Ints]))...}};
55 
56  // Desired LHS Tensor's Symmetry, typelist of TensorIndexTypes, and Structure
57  using symmetry =
59  using tensorindextype_list =
60  tmpl::list<tmpl::at_c<RhsTensorIndexTypeList, lhs_to_rhs_map[Ints]>...>;
61  using structure = Tensor_detail::Structure<
62  symmetry, tmpl::at_c<RhsTensorIndexTypeList, lhs_to_rhs_map[Ints]>...>;
63 };
64 } // namespace TensorExpressions
utility
Symmetry.hpp
std::make_index_sequence
TensorExpressions::LhsTensorSymmAndIndices
Determines and stores a LHS tensor's symmetry and index list from a RHS tensor expression and desired...
Definition: LhsTensorSymmAndIndices.hpp:39
Structure.hpp
TensorExpressions
Definition: AddSubtract.hpp:28
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:81
alg::find
constexpr decltype(auto) find(Container &&c, const T &value)
Convenience wrapper around constexpr reimplementation of std::find.
Definition: Algorithm.hpp:225
TMPL.hpp