Xped
Loading...
Searching...
No Matches
FusionTree.hpp
Go to the documentation of this file.
1#ifndef FUSIONTREE_H_
2#define FUSIONTREE_H_
3
4#include <unordered_map>
5
6#include "yas/serialize.hpp"
7#include "yas/std_types.hpp"
8
9#include "Xped/Hash/hash.hpp"
10#include "Xped/Util/Mpi.hpp"
12
13namespace Xped {
14
15namespace util {
16constexpr std::size_t inter_dim(std::size_t Rank) { return (Rank == 1 or Rank == 0) ? 0 : Rank - 2; }
17constexpr std::size_t mult_dim(std::size_t Rank) { return (Rank == 0) ? 0 : Rank - 1; }
18constexpr std::size_t numberOfVertices(std::size_t Rank) { return (Rank == 0) ? 0 : Rank - 1; }
19constexpr std::size_t numberOfInnerlines(std::size_t Rank) { return (Rank == 1 or Rank == 0) ? 0 : Rank - 2; }
20} // namespace util
21
22template <std::size_t Rank, typename Symmetry>
24{
25 typedef typename Symmetry::qType qType;
26 typedef typename Symmetry::Scalar Scalar;
27
28 std::array<qType, Rank> q_uncoupled{};
30 std::size_t dim{};
31 std::array<size_t, Rank> dims{};
33 std::array<size_t, util::mult_dim(Rank)> multiplicities =
34 std::array<size_t, util::mult_dim(Rank)>(); // only for non-Abelian symmetries with outermultiplicity.
35 std::array<bool, Rank> IS_DUAL{};
36
37 template <typename Ar>
38 inline void serialize(Ar& ar)
39 {
40 ar& YAS_OBJECT_NVP("FusionTree",
41 ("q_uncoupled", q_uncoupled),
42 ("q_coupled", q_coupled),
43 ("dim", dim),
44 ("dims", dims),
45 ("q_intermediates", q_intermediates),
46 ("multiplicities", multiplicities),
47 ("IS_DUAL", IS_DUAL));
48 }
49
50 inline void computeDim() { dim = std::accumulate(dims.begin(), dims.end(), 1ul, std::multiplies<std::size_t>()); }
51
53
54 bool operator<(const FusionTree<Rank, Symmetry>& other) const;
55 bool operator>(const FusionTree<Rank, Symmetry>& other) const;
56
57 bool operator==(const FusionTree<Rank, Symmetry>& other) const;
58
59 inline bool operator!=(const FusionTree<Rank, Symmetry>& other) const { return !this->operator==(other); }
60
61 friend std::size_t hash_value(const FusionTree<Rank, Symmetry>& tree)
62 {
63 size_t seed = 0;
64 boost::hash_combine(seed, tree.q_uncoupled);
65 boost::hash_combine(seed, tree.q_coupled);
66 boost::hash_combine(seed, tree.q_intermediates);
67 boost::hash_combine(seed, tree.IS_DUAL);
68 boost::hash_combine(seed, tree.multiplicities);
69 boost::hash_combine(seed, tree.dims);
70 return seed;
71 }
72
73 std::string printTree(const std::array<std::string, Rank>& s_uncoupled,
74 const std::array<std::string, util::inter_dim(Rank)>& s_intermediates,
75 const std::string& s_coupled,
76 const std::array<std::string, util::mult_dim(Rank)>& s_multiplicities) const;
77
78 std::string draw() const;
79
80 std::string print() const;
81
82 template <typename PlainLib>
83 typename PlainLib::template TType<Scalar, Rank + 1> asTensor(const mpi::XpedWorld& world = mpi::getUniverse()) const;
84
86
87 std::unordered_map<FusionTree<Rank, Symmetry>, typename Symmetry::Scalar> permute(const util::Permutation& p) const;
88
89 std::unordered_map<FusionTree<Rank, Symmetry>, typename Symmetry::Scalar> swap(const std::size_t& pos) const; // swaps sites pos and pos+1
90};
91
92template <std::size_t depth, typename Symmetry>
93std::ostream& operator<<(std::ostream& os, const FusionTree<depth, Symmetry>& tree)
94{
95 os << tree.print();
96 return os;
97}
98
99} // namespace Xped
100
101#ifndef XPED_COMPILED_LIB
102# include "Core/FusionTree.cpp"
103#endif
104
105#endif
XpedWorld & getUniverse()
Definition: Mpi.hpp:49
constexpr std::size_t inter_dim(std::size_t Rank)
Definition: FusionTree.hpp:16
constexpr std::size_t mult_dim(std::size_t Rank)
Definition: FusionTree.hpp:17
constexpr std::size_t numberOfVertices(std::size_t Rank)
Definition: FusionTree.hpp:18
constexpr std::size_t numberOfInnerlines(std::size_t Rank)
Definition: FusionTree.hpp:19
Definition: bench.cpp:62
CTF::Tensor< Scalar > TType
Definition: PlainInterface_Cyclops_impl.cpp:13
std::ostream & operator<<(std::ostream &os, const FusionTree< depth, Symmetry > &tree)
Definition: FusionTree.hpp:93
Definition: FusionTree.hpp:24
FusionTree< Rank+1, Symmetry > enlarge(const FusionTree< 1, Symmetry > &other) const
Definition: FusionTree.cpp:305
void computeIntermediates()
Definition: FusionTree.cpp:132
Symmetry::Scalar Scalar
Definition: FusionTree.hpp:26
std::string printTree(const std::array< std::string, Rank > &s_uncoupled, const std::array< std::string, util::inter_dim(Rank)> &s_intermediates, const std::string &s_coupled, const std::array< std::string, util::mult_dim(Rank)> &s_multiplicities) const
Definition: FusionTree.cpp:410
std::unordered_map< FusionTree< Rank, Symmetry >, typename Symmetry::Scalar > swap(const std::size_t &pos) const
Definition: FusionTree.cpp:350
friend std::size_t hash_value(const FusionTree< Rank, Symmetry > &tree)
Definition: FusionTree.hpp:61
std::array< bool, Rank > IS_DUAL
Definition: FusionTree.hpp:35
std::string draw() const
Definition: FusionTree.cpp:83
bool operator==(const FusionTree< Rank, Symmetry > &other) const
Definition: FusionTree.cpp:62
std::array< qType, Rank > q_uncoupled
Definition: FusionTree.hpp:28
std::size_t dim
Definition: FusionTree.hpp:30
std::unordered_map< FusionTree< Rank, Symmetry >, typename Symmetry::Scalar > permute(const util::Permutation &p) const
Definition: FusionTree.cpp:322
void computeDim()
Definition: FusionTree.hpp:50
void serialize(Ar &ar)
Definition: FusionTree.hpp:38
std::array< size_t, Rank > dims
Definition: FusionTree.hpp:31
std::array< qType, util::inter_dim(Rank)> q_intermediates
Definition: FusionTree.hpp:32
std::array< size_t, util::mult_dim(Rank)> multiplicities
Definition: FusionTree.hpp:33
PlainLib::template TType< Scalar, Rank+1 > asTensor(const mpi::XpedWorld &world=mpi::getUniverse()) const
std::string print() const
Definition: FusionTree.cpp:117
bool operator>(const FusionTree< Rank, Symmetry > &other) const
Definition: FusionTree.cpp:22
qType q_coupled
Definition: FusionTree.hpp:29
Symmetry::qType qType
Definition: FusionTree.hpp:25
bool operator!=(const FusionTree< Rank, Symmetry > &other) const
Definition: FusionTree.hpp:59
bool operator<(const FusionTree< Rank, Symmetry > &other) const
Definition: FusionTree.cpp:28
Definition: Mpi.hpp:34
Definition: Permutations.hpp:40