1#ifndef XPED_SITEOPERATOR_HPP_
2#define XPED_SITEOPERATOR_HPP_
8template <
typename Scalar_,
typename Symmetry_>
13 using qType =
typename Symmetry::qType;
22 const std::unordered_map<std::string, std::pair<qType, std::size_t>>& labels,
31 return data.subMatrix(b, k);
39 return data.subMatrix(b, k);
45 assert(it_bra !=
label_dict.end() and
"label_dict in SiteOperator does not contain bra label");
47 assert(it_ket !=
label_dict.end() and
"label_dict in SiteOperator does not contain ket label");
49 return this->
operator()(it_bra->second.first, it_ket->second.first)(it_bra->second.second, it_ket->second.second);
54 assert(it_bra !=
label_dict.end() and
"label_dict in SiteOperator does not contain bra label");
56 assert(it_ket !=
label_dict.end() and
"label_dict in SiteOperator does not contain ket label");
57 return this->
operator()(it_bra->second.first, it_ket->second.first)(it_bra->second.second, it_ket->second.second);
72 auto target = Symmetry::reduceSilent(O1.Q, O2.Q);
73 assert(target.size() == 1 and
"Use outerprod overload with specification of fuse quantum number!");
79 std::vector<MatrixType>
plain()
const;
81 std::string
print()
const;
88 std::unordered_map<std::string, std::pair<qType, std::size_t>>
label_dict;
92template <
typename Scalar,
typename Symmetry,
typename OtherScalar>
96 out.
data = s * op.data;
100template <
typename Scalar,
typename Symmetry,
typename OtherScalar>
107template <
typename Scalar,
typename Symmetry,
typename OtherScalar>
111 out.
data = s * op.data;
115template <
typename Scalar,
typename Symmetry>
118 auto Qtots = Symmetry::reduceSilent(O1.Q, O2.Q);
119 assert(Qtots.size() == 1 and
120 "The operator * for SiteOperator can only be used if the target quantumnumber is unique. Use SiteOperator::prod() instead.");
125template <
typename Scalar,
typename Symmetry>
128 assert(O1.Q == O2.Q and
"For addition of SiteOperator the operator quantum number needs to be the same.");
130 out.
data = O1.data + O2.data;
134template <
typename Scalar,
typename Symmetry>
137 assert(O1.Q == O2.Q and
"For subtraction of SiteOperator the operator quantum number needs to be the same.");
139 out.
data = O1.data - O2.data;
143template <
typename Scalar,
typename Symmetry>
149template <
typename Scalar,
typename Symmetry>
152 bool ADD_TWIST =
false,
153 bool REVERSE_ORDER =
false)
155 if(not REVERSE_ORDER) {
157 Otarget_op.
push_back(Symmetry::qvacuum(), 1);
159 {{O2.data.uncoupledCodomain()[1], O1.data.uncoupledCodomain()[1]}}, {{Otarget_op}}, O1.data.world());
160 couple.setConstant(1.);
161 auto tmp1 = ADD_TWIST ? O1.data.twist(2).template contract<std::array{-1, -2, 1}, std::array{-3, 1, -4}, 2>(couple)
162 : O1.data.template contract<std::array{-1, -2, 1}, std::array{-3, 1, -4}, 2>(couple);
163 return tmp1.template contract<std::array{-1, -3, 1, -5}, std::array{-2, -4, 1}, 2>(O2.data).
template trim<4>();
165 Qbasis<Symmetry, 1> Otarget_op;
166 Otarget_op.push_back(Symmetry::qvacuum(), 1);
167 Tensor<double, 2, 1, Symmetry, false> couple(
168 {{O1.data.uncoupledCodomain()[1], O2.data.uncoupledCodomain()[1]}}, {{Otarget_op}}, O1.data.world());
169 couple.setConstant(1.);
170 auto tmp1 = ADD_TWIST ? O1.data.twist(2).template contract<std::array{-1, -2, 1}, std::array{1, -3, -4}, 2>(couple)
171 : O1.data.template contract<std::array{-1, -2, 1}, std::array{1, -3, -4}, 2>(couple);
172 return tmp1.template contract<std::array{-1, -3, 1, -5}, std::array{-2, -4, 1}, 2>(O2.data).
template trim<4>();
176template <
typename Scalar,
typename Symmetry>
181 return tprod(tmp_O1, tmp_O2);
184template <
typename Scalar,
typename Symmetry>
193#ifndef XPED_COMPILED_LIB
Definition: Qbasis.hpp:39
void push_back(const qType &q, const size_t &inner_dim)
Definition: Qbasis.cpp:32
Definition: Tensor.hpp:40
XpedWorld & getUniverse()
Definition: Mpi.hpp:49
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator-(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:428
Tensor< Scalar, 2, 2, Symmetry, false > tprod(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2, bool ADD_TWIST=false, bool REVERSE_ORDER=false)
Definition: SiteOperator.hpp:150
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator+(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:440
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator*(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:452
SiteOperator< Scalar, Symmetry > kroneckerProduct(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2)
Definition: SiteOperator.hpp:144
std::ostream & operator<<(std::ostream &os, const FusionTree< depth, Symmetry > &tree)
Definition: FusionTree.hpp:93
Definition: FusionTree.hpp:24
std::array< qType, Rank > q_uncoupled
Definition: FusionTree.hpp:28
Definition: SiteOperator.hpp:10
Tensor< Scalar, 1, 2, Symmetry, false > data
Definition: SiteOperator.hpp:86
std::string print() const
Definition: SiteOperator.cpp:110
Symmetry_ Symmetry
Definition: SiteOperator.hpp:12
const auto operator()(const qType &bra, const qType &ket) const
Definition: SiteOperator.hpp:25
static SiteOperator< Scalar, Symmetry > prod(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2, const qType &target)
Definition: SiteOperator.cpp:36
void setZero()
Definition: SiteOperator.hpp:62
static SiteOperator< Scalar, Symmetry > outerprod(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2, const qType &target)
Definition: SiteOperator.cpp:51
typename Symmetry::qType qType
Definition: SiteOperator.hpp:13
std::string & label()
Definition: SiteOperator.hpp:85
void setIdentity()
Definition: SiteOperator.hpp:63
std::string label_
Definition: SiteOperator.hpp:89
static SiteOperator< Scalar, Symmetry > outerprod(XPED_CONST SiteOperator< Scalar, Symmetry > &O1, XPED_CONST SiteOperator< Scalar, Symmetry > &O2)
Definition: SiteOperator.hpp:70
auto operator()(const qType &bra, const qType &ket)
Definition: SiteOperator.hpp:33
void setRandom()
Definition: SiteOperator.hpp:64
Scalar & operator()(const std::string &bra, const std::string &ket)
Definition: SiteOperator.hpp:51
Scalar norm() const
Definition: SiteOperator.cpp:86
typename Tensor< Scalar, 1, 2, Symmetry, false >::MatrixType MatrixType
Definition: SiteOperator.hpp:14
Scalar_ Scalar
Definition: SiteOperator.hpp:11
std::unordered_map< std::string, std::pair< qType, std::size_t > > label_dict
Definition: SiteOperator.hpp:88
const Scalar & operator()(const std::string &bra, const std::string &ket) const
Definition: SiteOperator.hpp:42
SiteOperator< Scalar, Symmetry > adjoint() XPED_CONST
Definition: SiteOperator.cpp:28
std::vector< MatrixType > plain() const
Definition: SiteOperator.cpp:92
qType Q
Definition: SiteOperator.hpp:87