Xped
Loading...
Searching...
No Matches
KondoNecklace.hpp
Go to the documentation of this file.
1#ifndef XPED_KONDO_NECKLACE_HPP_
2#define XPED_KONDO_NECKLACE_HPP_
3
4#include <map>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include <highfive/H5File.hpp>
10
11#include "Xped/Core/Tensor.hpp"
16#include "Xped/Util/Param.hpp"
17
18namespace Xped {
19
20template <typename Symmetry>
21class KondoNecklace : public TwoSiteObservable<double, Symmetry>
22{
23public:
24 KondoNecklace(std::map<std::string, Param>& params_in, const Pattern& pat_in, Opts::Bond bond = Opts::Bond::H | Opts::Bond::V)
25 : TwoSiteObservable<double, Symmetry>(pat_in, bond)
26 , params(params_in)
27 , pat(pat_in)
28 {
29 B = SpinBase<Symmetry>(2, 2);
30 Tensor<double, 2, 2, Symmetry> gate, local_gate;
31 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
32 used_params = {"J", "Jk", "I"};
33 } else {
34 used_params = {"Jxy", "Jz", "Jkxy", "Jkz", "Ixy", "Iz"};
35 }
36
37 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
38 auto SS = (std::sqrt(3.) * tprod(B.Sdag(0), B.S(0))).eval();
39
40 auto ss = (std::sqrt(3.) * tprod(B.Sdag(1), B.S(1))).eval();
41
42 auto IdxSs = tprod(B.Id(), std::sqrt(3.) * SiteOperator<double, Symmetry>::prod(B.Sdag(0), B.S(1), Symmetry::qvacuum()));
43
44 auto SsxId = tprod(std::sqrt(3.) * SiteOperator<double, Symmetry>::prod(B.Sdag(0), B.S(1), Symmetry::qvacuum()), B.Id());
45
46 gate = params["J"].get<double>() * ss + params["I"].get<double>() * SS;
47 local_gate = gate + 0.25 * params["Jk"].get<double>() * (SsxId + IdxSs);
48 } else if constexpr(Symmetry::ALL_ABELIAN) {
49 auto SzSz = tprod(B.Sz(0), B.Sz(0));
50 auto SpSm = tprod(B.Sp(0), B.Sm(0));
51 auto SmSp = tprod(B.Sm(0), B.Sp(0));
52
53 auto szsz = tprod(B.Sz(1), B.Sz(1));
54 auto spsm = tprod(B.Sp(1), B.Sm(1));
55 auto smsp = tprod(B.Sm(1), B.Sp(1));
56
57 auto IdxSzsz = tprod(B.Id(), B.Sz(0) * B.Sz(1));
58 auto IdxSpsm = tprod(B.Id(), B.Sp(0) * B.Sm(1));
59 auto IdxSmsp = tprod(B.Id(), B.Sm(0) * B.Sp(1));
60
61 auto SzszxId = tprod(B.Sz(0) * B.Sz(1), B.Id());
62 auto SpsmxId = tprod(B.Sp(0) * B.Sm(1), B.Id());
63 auto SmspxId = tprod(B.Sm(0) * B.Sp(1), B.Id());
64 gate = params["Jz"].get<double>() * szsz + 0.5 * params["Jxy"].get<double>() * (spsm + smsp);
65 gate = gate + params["Iz"].get<double>() * SzSz + 0.5 * params["Ixy"].get<double>() * (SpSm + SmSp);
66 local_gate = gate + 0.25 * (params["Jkz"].get<double>() * (SzszxId + IdxSzsz) +
67 0.5 * params["Jkxy"].get<double>() * ((SpsmxId + IdxSpsm) + (SmspxId + IdxSmsp)));
68 } else {
69 assert(false and "Symmetry is not supported in KondoNecklace model.");
70 }
71
73 for(auto& t : this->data_h) { t = local_gate; }
74 }
76 for(auto& t : this->data_v) { t = local_gate; }
77 }
79 for(auto& t : this->data_d1) { t = gate; }
80 }
82 for(auto& t : this->data_d2) { t = gate; }
83 }
84 }
85
86 virtual void setDefaultObs() override
87 {
88 if constexpr(std::is_same_v<Symmetry, Sym::SU2<Sym::SpinSU2>>) {
89 } else if constexpr(Symmetry::ALL_ABELIAN) {
90 auto Sz = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Sz");
91 for(auto& t : Sz->data) { t = B.Sz(0).data.template trim<2>(); }
92 auto sz = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "sz");
93 for(auto& t : sz->data) { t = B.Sz(1).data.template trim<2>(); }
94 auto Szsz = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Szsz");
95 for(auto& t : Szsz->data) { t = (B.Sz(0) * B.Sz(1)).data.template trim<2>(); }
96 auto Spsm = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Spsm");
97 for(auto& t : Spsm->data) { t = (B.Sp(0) * B.Sm(1)).data.template trim<2>(); }
98 auto Smsp = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Smsp");
99 for(auto& t : Smsp->data) { t = (B.Sm(0) * B.Sp(1)).data.template trim<2>(); }
100 obs.push_back(std::move(Sz));
101 obs.push_back(std::move(sz));
102 obs.push_back(std::move(Szsz));
103 obs.push_back(std::move(Spsm));
104 obs.push_back(std::move(Smsp));
105
106 auto szsz = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
108 for(auto& t : szsz->data_h) { t = Xped::tprod(B.Sz(1), B.Sz(1)); }
109 for(auto& t : szsz->data_v) { t = Xped::tprod(B.Sz(1), B.Sz(1)); }
110 for(auto& t : szsz->data_d1) { t = Xped::tprod(B.Sz(1), B.Sz(1)); }
111 for(auto& t : szsz->data_d2) { t = Xped::tprod(B.Sz(1), B.Sz(1)); }
112 auto spsm = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
114 for(auto& t : spsm->data_h) { t = Xped::tprod(B.Sp(1), B.Sm(1)); }
115 for(auto& t : spsm->data_v) { t = Xped::tprod(B.Sp(1), B.Sm(1)); }
116 for(auto& t : spsm->data_d1) { t = Xped::tprod(B.Sp(1), B.Sm(1)); }
117 for(auto& t : spsm->data_d2) { t = Xped::tprod(B.Sp(1), B.Sm(1)); }
118 auto smsp = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
120 for(auto& t : smsp->data_h) { t = Xped::tprod(B.Sm(1), B.Sp(1)); }
121 for(auto& t : smsp->data_v) { t = Xped::tprod(B.Sm(1), B.Sp(1)); }
122 for(auto& t : smsp->data_d1) { t = Xped::tprod(B.Sm(1), B.Sp(1)); }
123 for(auto& t : smsp->data_d2) { t = Xped::tprod(B.Sm(1), B.Sp(1)); }
124 auto SzSz = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
126 for(auto& t : SzSz->data_h) { t = Xped::tprod(B.Sz(0), B.Sz(0)); }
127 for(auto& t : SzSz->data_v) { t = Xped::tprod(B.Sz(0), B.Sz(0)); }
128 for(auto& t : SzSz->data_d1) { t = Xped::tprod(B.Sz(0), B.Sz(0)); }
129 for(auto& t : SzSz->data_d2) { t = Xped::tprod(B.Sz(0), B.Sz(0)); }
130 auto SpSm = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
132 for(auto& t : SpSm->data_h) { t = Xped::tprod(B.Sp(0), B.Sm(0)); }
133 for(auto& t : SpSm->data_v) { t = Xped::tprod(B.Sp(0), B.Sm(0)); }
134 for(auto& t : SpSm->data_d1) { t = Xped::tprod(B.Sp(0), B.Sm(0)); }
135 for(auto& t : SpSm->data_d2) { t = Xped::tprod(B.Sp(0), B.Sm(0)); }
136 auto SmSp = std::make_unique<Xped::TwoSiteObservable<double, Symmetry>>(
138 for(auto& t : SmSp->data_h) { t = Xped::tprod(B.Sm(0), B.Sp(0)); }
139 for(auto& t : SmSp->data_v) { t = Xped::tprod(B.Sm(0), B.Sp(0)); }
140 for(auto& t : SmSp->data_d1) { t = Xped::tprod(B.Sm(0), B.Sp(0)); }
141 for(auto& t : SmSp->data_d2) { t = Xped::tprod(B.Sm(0), B.Sp(0)); }
142 obs.push_back(std::move(szsz));
143 obs.push_back(std::move(spsm));
144 obs.push_back(std::move(smsp));
145 obs.push_back(std::move(SzSz));
146 obs.push_back(std::move(SpSm));
147 obs.push_back(std::move(SmSp));
148 }
149 }
150
151 virtual std::string file_name() const override { return internal::create_filename("KondoNecklace", params, used_params); }
152
153 virtual std::string format() const override
154 {
155 return internal::format_params(fmt::format("KondoNecklace[sym={}]", Symmetry::name()), params, used_params);
156 }
157
158 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
159 {
160 for(auto& ob : obs) {
161 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
162 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
163 }
164 }
165
166 virtual void computeObs(XPED_CONST CTM<std::complex<double>, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
167 {
168 for(auto& ob : obs) {
169 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
170 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
171 }
172 }
173
174 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 1, false, Opts::CTMCheckpoint{}>& env) override
175 {
176 for(auto& ob : obs) {
177 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
178 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
179 }
180 }
181
182 virtual std::string getObsString(const std::string& offset) const override
183 {
184 std::string out;
185 for(const auto& ob : obs) {
186 out.append(ob->getResString(offset));
187 if(&ob != &obs.back()) { out.push_back('\n'); }
188 }
189 return out;
190 }
191
192 virtual void obsToFile(HighFive::File& file, const std::string& root = "/") const override
193 {
194 for(const auto& ob : obs) { ob->toFile(file, root); }
195 }
196
197 std::map<std::string, Param> params;
199 std::vector<std::string> used_params;
201 std::vector<std::unique_ptr<ObservableBase>> obs;
202};
203
204} // namespace Xped
205#endif
Definition: CTM.hpp:62
Definition: KondoNecklace.hpp:22
std::vector< std::unique_ptr< ObservableBase > > obs
Definition: KondoNecklace.hpp:201
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 1, false, Opts::CTMCheckpoint{}> &env) override
Definition: KondoNecklace.hpp:174
virtual std::string file_name() const override
Definition: KondoNecklace.hpp:151
virtual void obsToFile(HighFive::File &file, const std::string &root="/") const override
Definition: KondoNecklace.hpp:192
Pattern pat
Definition: KondoNecklace.hpp:198
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: KondoNecklace.hpp:158
virtual std::string format() const override
Definition: KondoNecklace.hpp:153
std::vector< std::string > used_params
Definition: KondoNecklace.hpp:199
virtual void setDefaultObs() override
Definition: KondoNecklace.hpp:86
KondoNecklace(std::map< std::string, Param > &params_in, const Pattern &pat_in, Opts::Bond bond=Opts::Bond::H|Opts::Bond::V)
Definition: KondoNecklace.hpp:24
virtual std::string getObsString(const std::string &offset) const override
Definition: KondoNecklace.hpp:182
virtual void computeObs(XPED_CONST CTM< std::complex< double >, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: KondoNecklace.hpp:166
std::map< std::string, Param > params
Definition: KondoNecklace.hpp:197
SpinBase< Symmetry > B
Definition: KondoNecklace.hpp:200
Definition: SpinBase.hpp:23
std::enable_if< Dummy::IS_SPIN_SU2(), OperatorType >::type S(std::size_t orbital=0) const
Definition: SpinBase.hpp:387
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sz(std::size_t orbital=0) const
Definition: SpinBase.hpp:450
OperatorType Id(std::size_t orbital=0) const
Definition: SpinBase.hpp:499
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sp(std::size_t orbital=0) const
Definition: SpinBase.hpp:457
std::enable_if< Dummy::IS_SPIN_SU2(), OperatorType >::type Sdag(std::size_t orbital=0) const
Definition: SpinBase.hpp:394
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sm(std::size_t orbital=0) const
Definition: SpinBase.hpp:464
Definition: Tensor.hpp:40
Bond
Definition: Bonds.hpp:10
std::string format_params(const std::string &name, const std::map< std::string, Param > &params, const std::vector< std::string > &used_params)
Definition: Helpers.hpp:12
std::string create_filename(const std::string &name, const std::map< std::string, Param > &params, const std::vector< std::string > &used_params)
Definition: Helpers.hpp:26
Definition: bench.cpp:62
TMatrix< std::conditional_t< ENABLE_AD, stan::math::var, typename OneSiteObservable< OpScalar, Symmetry, HERMITIAN >::ObsScalar > > avg(XPED_CONST CTM< Scalar, Symmetry, TRank, ENABLE_AD, CPOpts > &env, OneSiteObservable< OpScalar, Symmetry, HERMITIAN > &op)
Definition: LinearAlgebra.cpp:11
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
Definition: OneSiteObservable.hpp:21
Definition: CTMOpts.hpp:96
Definition: Pattern.hpp:18
Definition: SiteOperator.hpp:10
Definition: TwoSiteObservable.hpp:22
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_h
Definition: TwoSiteObservable.hpp:287
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_v
Definition: TwoSiteObservable.hpp:288
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_d1
Definition: TwoSiteObservable.hpp:289
Opts::Bond bond
Definition: TwoSiteObservable.hpp:295
TMatrix< Tensor< double, 2, 2, Symmetry, false > > data_d2
Definition: TwoSiteObservable.hpp:290