v0.16.0
Loading...
Searching...
No Matches
SymmLTensor.hpp
Go to the documentation of this file.
1/**
2 * @file SymmLTensor.hpp
3 *
4 */
5
6#pragma once
7
8namespace FTensor {
9
10/**
11 * @brief Mapping from symmetric tensor indices to packed storage index
12 *
13 * @tparam T
14 * @tparam Dim
15 */
16template <class T = int, int Dim = 3> class SymmLTensor {
17public:
19 static constexpr int size_symm = (Dim * (Dim + 1)) / 2;
20
21 constexpr value_type operator()(const int N0, const int N1,
22 const int N2) const {
23 const auto hi = N0 > N1 ? N0 : N1;
24 const auto lo = N0 > N1 ? N1 : N0;
25 const auto packed = hi + (lo * (2 * Dim - lo - 1)) / 2;
26 return N2 == packed ? value_type(1) : value_type(0);
27 }
28
29 template <char i, char j, char k, int Dim01, int Dim2>
30 typename std::enable_if<
31 (Dim01 == Dim && Dim2 == size_symm),
33 operator()(const Index<i, Dim01> &, const Index<j, Dim01> &,
34 const Index<k, Dim2> &) const {
35 return Dg_Expr<SymmLTensor<T, Dim>, value_type, Dim01, Dim2, i, j, k>(
36 *this);
37 };
38};
39
40template <class T = int, int Dim> constexpr auto symm_l_tensor() {
41 return SymmLTensor<T, Dim>();
42}
43
44template <class T = int, int Dim>
45constexpr auto symm_l_tensor(const Number<Dim> &) {
46 return SymmLTensor<T, Dim>();
47}
48
49template <class T = int, char i, char j, char k, int Dim01, int Dim2>
50typename std::enable_if<
51 (Dim2 == (Dim01 * (Dim01 + 1)) / 2),
52 Dg_Expr<SymmLTensor<T, Dim01>, typename SymmLTensor<T, Dim01>::value_type,
53 Dim01, Dim2, i, j, k>>::type
59
60} // namespace FTensor
std::string type
Mapping from symmetric tensor indices to packed storage index.
static constexpr int size_symm
typename promote< T, double >::V value_type
constexpr value_type operator()(const int N0, const int N1, const int N2) const
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
Tensors class implemented by Walter Landry.
Definition FTensor.hpp:51
constexpr auto symm_l_tensor()