Xped
Loading...
Searching...
No Matches
Hubbard.hpp
Go to the documentation of this file.
1#ifndef XPED_HUBBARD_HPP_
2#define XPED_HUBBARD_HPP_
3
4#include <map>
5#include <string>
6
7#include <highfive/H5File.hpp>
8
10#include "Xped/Symmetry/U0.hpp"
11#include "Xped/Symmetry/U1.hpp"
12#include "Xped/Symmetry/ZN.hpp"
13
14#include "Xped/Core/Tensor.hpp"
19#include "Xped/Util/Param.hpp"
20
21namespace Xped {
22
23template <typename Symmetry>
24class Hubbard : public TwoSiteObservable<double, Symmetry>
25{
26public:
27 Hubbard(std::map<std::string, Param>& params_in, const Pattern& pat_in, Opts::Bond bond = Opts::Bond::H | Opts::Bond::V)
28 : TwoSiteObservable<double, Symmetry>(pat_in, bond)
29 , params(params_in)
30 , pat(pat_in)
31 {
33 used_params = {"U", /*"μ"*/ "mu", "tprime", "t"};
34 Tensor<double, 2, 2, Symmetry> gate, bond_gate, hopping, hubbard, occ;
35 if constexpr(Symmetry::Nq == 2 and Symmetry::ANY_NON_ABELIAN) {
36 if constexpr(Symmetry::IS_SPIN[0] and Symmetry::NON_ABELIAN[0] and Symmetry::ABELIAN[1]) {
37 hopping = (std::sqrt(2.) * tprod(F.cdag(), F.c()) + std::sqrt(2.) * tprod(F.c(), F.cdag())).eval();
38 hubbard = 0.25 * (tprod(F.d(), F.Id()) + tprod(F.Id(), F.d()));
39 occ = 0.25 * (tprod(F.n(), F.Id()) + tprod(F.Id(), F.n()));
41 for(auto& t : this->data_h) {
42 t = -params["t"].get<double>() * hopping + params["U"].get<double>() * hubbard - params["mu"].get<double>() * occ;
43 }
44 }
46 for(auto& t : this->data_v) {
47 t = -params["t"].get<double>() * hopping + params["U"].get<double>() * hubbard - params["mu"].get<double>() * occ;
48 }
49 }
51 // strange sign here but the code works fine
52 for(auto& t : this->data_d1) { t = +params["tprime"].get<double>() * hopping; }
53 }
55 // strange sign here but the code works fine
56 for(auto& t : this->data_d2) { t = +params["tprime"].get<double>() * hopping; }
57 }
58 }
59 } else if constexpr(std::is_same_v<Symmetry,
63 hopping = (tprod(F.cdag(), F.c()) - tprod(F.c(), F.cdag())).eval();
64 hubbard = 0.25 * (tprod(F.n() * (F.n() - F.Id()), F.Id()) + tprod(F.Id(), F.n() * (F.n() - F.Id())));
65 occ = 0.25 * (tprod(F.n(), F.Id()) + tprod(F.Id(), F.n()));
66 gate = -params["t"].get<double>() * (tprod(F.cdag(), F.c()) - tprod(F.c(), F.cdag())) +
67 0.25 * 0.5 * params["U"].get<double>() * (tprod(F.n() * (F.n() - F.Id()), F.Id()) + tprod(F.Id(), F.n() * (F.n() - F.Id()))) -
68 0.25 * (params["mu"].get<double>() + 1.5 * params["U"].get<double>()) * (tprod(F.n(), F.Id()) + tprod(F.Id(), F.n()));
69 bond_gate = -params["t"].get<double>() * (tprod(F.cdag(), F.c()) - tprod(F.c(), F.cdag()));
70
72 for(auto& t : this->data_h) {
73 t = -params["t"].get<double>() * hopping + 0.5 * params["U"].get<double>() * hubbard -
74 (params["mu"].get<double>() + 1.5 * params["U"].get<double>()) * occ;
75 }
76 }
78 for(auto& t : this->data_v) {
79 t = -params["t"].get<double>() * hopping + 0.5 * params["U"].get<double>() * hubbard -
80 (params["mu"].get<double>() + 1.5 * params["U"].get<double>()) * occ;
81 }
82 }
84 for(auto& t : this->data_d1) { t = -params["tprime"].get<double>() * hopping; }
85 }
87 for(auto& t : this->data_d2) { t = -params["tprime"].get<double>() * hopping; }
88 }
89 } else if constexpr(Symmetry::ALL_ABELIAN) {
90 hopping = (tprod(F.cdag(SPIN_INDEX::UP), F.c(SPIN_INDEX::UP)) + tprod(F.cdag(SPIN_INDEX::DN), F.c(SPIN_INDEX::DN)) -
91 tprod(F.c(SPIN_INDEX::UP), F.cdag(SPIN_INDEX::UP)) - tprod(F.c(SPIN_INDEX::DN), F.cdag(SPIN_INDEX::DN)))
92 .eval();
93
94 hubbard = 0.25 * (tprod(F.d(), F.Id()) + tprod(F.Id(), F.d())).eval();
95 occ = 0.25 * (tprod(F.n(), F.Id()) + tprod(F.Id(), F.n())).eval();
96 // std::cout << hopping << std::endl;
97 // std::exit(0);
98 // Es.print(std::cout, true);
99 // std::cout << std::endl;
100
101 if((bond & Opts::Bond::H) == Opts::Bond::H) {
102 for(auto& t : this->data_h) {
103 t = -params["t"].get<double>() * hopping + params["U"].get<double>() * hubbard - params["mu"].get<double>() * occ;
104 // t = params["t"].get<double>() * hopping;
105 }
106 }
107 if((bond & Opts::Bond::V) == Opts::Bond::V) {
108 for(auto& t : this->data_v) {
109 t = -params["t"].get<double>() * hopping + params["U"].get<double>() * hubbard - params["mu"].get<double>() * occ;
110 // t = params["t"].get<double>() * hopping;
111 }
112 }
114 for(auto& t : this->data_d1) {
115 // strange sign here but the code works fine
116 t = +params["tprime"].get<double>() * hopping;
117 }
118 }
120 for(auto& t : this->data_d2) {
121 // strange sign here but the code works fine
122 t = +params["tprime"].get<double>() * hopping;
123 }
124 }
125 } else {
126 assert(false and "Symmetry is not supported in Hubbard model.");
127 }
128 // this->loadFromMatlab(std::filesystem::path("/home/user/matlab-tmp/hubbard_D2.mat"), "cpp");
129 }
130
131 virtual void setDefaultObs() override
132 {
133 if constexpr(Symmetry::Nq == 2 and Symmetry::ANY_NON_ABELIAN) {
134 if constexpr(Symmetry::IS_SPIN[0] and Symmetry::NON_ABELIAN[0] and Symmetry::ABELIAN[1]) {
135 auto n = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "n");
136 for(auto& t : n->data) { t = F.n().data.template trim<2>(); }
137 obs.push_back(std::move(n));
138 auto d = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "d");
139 for(auto& t : d->data) { t = F.d().data.template trim<2>(); }
140 obs.push_back(std::move(d));
141 auto hopping = (std::sqrt(2.) * tprod(F.cdag(), F.c()) + std::sqrt(2.) * tprod(F.c(), F.cdag())).eval();
142 auto cdagc = std::make_unique<TwoSiteObservable<double, Symmetry>>(
144 for(auto& t : cdagc->data_h) { t = hopping; }
145 for(auto& t : cdagc->data_v) { t = hopping; }
146 for(auto& t : cdagc->data_d1) { t = -1. * hopping; }
147 for(auto& t : cdagc->data_d2) { t = -1. * hopping; }
148 obs.push_back(std::move(cdagc));
149 }
150 } else if constexpr(std::is_same_v<Symmetry,
154
155 auto n = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "n");
156 for(auto& t : n->data) { t = F.n().data.template trim<2>(); }
157 obs.push_back(std::move(n));
158 } else if constexpr(Symmetry::ALL_ABELIAN) {
159 auto nup = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "nup");
160 for(auto& t : nup->data) { t = F.n(Xped::SPIN_INDEX::UP).data.template trim<2>(); }
161 auto ndn = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "ndn");
162 for(auto& t : ndn->data) { t = F.n(Xped::SPIN_INDEX::DN).data.template trim<2>(); }
163 auto n = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "n");
164 for(auto& t : n->data) { t = F.n().data.template trim<2>(); }
165 auto d = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "d");
166 for(auto& t : d->data) { t = F.d().data.template trim<2>(); }
167 auto Sz = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Sz");
168 for(auto& t : Sz->data) { t = F.Sz().data.template trim<2>(); }
169 obs.push_back(std::move(nup));
170 obs.push_back(std::move(ndn));
171 obs.push_back(std::move(n));
172 obs.push_back(std::move(d));
173 obs.push_back(std::move(Sz));
174 auto hopping = (tprod(F.cdag(SPIN_INDEX::UP), F.c(SPIN_INDEX::UP)) + tprod(F.cdag(SPIN_INDEX::DN), F.c(SPIN_INDEX::DN)) -
175 tprod(F.c(SPIN_INDEX::UP), F.cdag(SPIN_INDEX::UP)) - tprod(F.c(SPIN_INDEX::DN), F.cdag(SPIN_INDEX::DN)))
176 .eval();
177 auto cdagc =
178 std::make_unique<TwoSiteObservable<double, Symmetry>>(pat, Opts::Bond::H | Opts::Bond::V | Opts::Bond::D1 | Opts::Bond::D2, "cdagc");
179 for(auto& t : cdagc->data_h) { t = hopping; }
180 for(auto& t : cdagc->data_v) { t = hopping; }
181 for(auto& t : cdagc->data_d1) { t = -1. * hopping; }
182 for(auto& t : cdagc->data_d2) { t = -1. * hopping; }
183
184 auto SzSz =
185 std::make_unique<TwoSiteObservable<double, Symmetry>>(pat, Opts::Bond::H | Opts::Bond::V | Opts::Bond::D1 | Opts::Bond::D2, "SzSz");
186 for(auto& t : SzSz->data_h) { t = tprod(F.Sz(), F.Sz()); }
187 for(auto& t : SzSz->data_v) { t = tprod(F.Sz(), F.Sz()); }
188 for(auto& t : SzSz->data_d1) { t = tprod(F.Sz(), F.Sz()); }
189 for(auto& t : SzSz->data_d2) { t = tprod(F.Sz(), F.Sz()); }
190
191 obs.push_back(std::move(cdagc));
192 obs.push_back(std::move(SzSz));
193 if constexpr(not Symmetry::ANY_IS_SPIN) {
194 auto Sx = std::make_unique<Xped::OneSiteObservable<double, Symmetry>>(pat, "Sx");
195 for(auto& t : Sx->data) { t = F.Sx().data.template trim<2>(); }
196 auto SxSx = std::make_unique<TwoSiteObservable<double, Symmetry>>(
198 for(auto& t : SxSx->data_h) { t = tprod(F.Sx(), F.Sx()); }
199 for(auto& t : SxSx->data_v) { t = tprod(F.Sx(), F.Sx()); }
200 for(auto& t : SxSx->data_d1) { t = tprod(F.Sx(), F.Sx()); }
201 for(auto& t : SxSx->data_d2) { t = tprod(F.Sx(), F.Sx()); }
202 obs.push_back(std::move(Sx));
203 obs.push_back(std::move(SxSx));
204 auto Sy = std::make_unique<Xped::OneSiteObservable<std::complex<double>, Symmetry>>(pat, "Sy");
205 for(auto& t : Sy->data) { t = F.Sy().data.template trim<2>(); }
206 obs.push_back(std::move(Sy));
207 }
208 }
209 }
210
211 virtual std::string file_name() const override
212 {
213 return internal::create_filename(fmt::format("Hubbard_Lx={}_Ly={}", pat.Lx, pat.Ly), params, used_params);
214 }
215
216 virtual std::string format() const override
217 {
218 return internal::format_params(fmt::format("Hubbard[sym={}]", Symmetry::name()), params, used_params);
219 }
220
221 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
222 {
223 for(auto& ob : obs) {
224 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
225 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
226 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
227 }
228 }
229
230 virtual void computeObs(XPED_CONST CTM<std::complex<double>, Symmetry, 2, false, Opts::CTMCheckpoint{}>& env) override
231 {
232 for(auto& ob : obs) {
233 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
234 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
235 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
236 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry, false>*>(ob.get()); one != nullptr) { avg(env, *one); }
237 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry, false>*>(ob.get()); one_c != nullptr) {
238 avg(env, *one_c);
239 }
240 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry, false>*>(ob.get()); two != nullptr) { avg(env, *two); }
241 }
242 }
243
244 virtual void computeObs(XPED_CONST CTM<double, Symmetry, 1, false, Opts::CTMCheckpoint{}>& env) override
245 {
246 for(auto& ob : obs) {
247 if(auto* one = dynamic_cast<OneSiteObservable<double, Symmetry>*>(ob.get()); one != nullptr) { avg(env, *one); }
248 if(auto* one_c = dynamic_cast<OneSiteObservable<std::complex<double>, Symmetry>*>(ob.get()); one_c != nullptr) { avg(env, *one_c); }
249 if(auto* two = dynamic_cast<TwoSiteObservable<double, Symmetry>*>(ob.get()); two != nullptr) { avg(env, *two); }
250 }
251 }
252
253 virtual std::string getObsString(const std::string& offset) const override
254 {
255 std::string out;
256 for(auto i = 0ul; const auto& ob : obs) {
257 out.append(ob->getResString(offset));
258 if(i++ < obs.size() - 1) { out.push_back('\n'); }
259 }
260 return out;
261 }
262
263 virtual void obsToFile(HighFive::File& file, const std::string& root = "/") const override
264 {
265 for(const auto& ob : obs) { ob->toFile(file, root); }
266 }
267
268 std::map<std::string, Param> params;
270 std::vector<std::string> used_params;
272 std::vector<std::unique_ptr<ObservableBase>> obs;
273};
274
275} // namespace Xped
276#endif
Definition: CTM.hpp:62
Definition: FermionBase.hpp:25
OperatorType Id(std::size_t orbital=0) const
Definition: FermionBase.hpp:733
std::enable_if<!Dummy::IS_SPIN_SU2(), OperatorType >::type Sz(std::size_t orbital=0) const
Definition: FermionBase.hpp:615
std::enable_if< Dummy::IS_SPIN_SU2() and!Dummy::IS_CHARGE_SU2(), OperatorType >::type cdag(std::size_t orbital=0) const
Definition: FermionBase.hpp:453
std::enable_if< true, OperatorType >::type n(std::size_t orbital=0) const
Definition: FermionBase.hpp:541
std::enable_if< Dummy::NO_SPIN_SYM(), OperatorTypeC >::type Sy(std::size_t orbital=0) const
Definition: FermionBase.hpp:645
std::enable_if< Dummy::IS_SPIN_SU2() and!Dummy::IS_CHARGE_SU2(), OperatorType >::type c(std::size_t orbital=0) const
Definition: FermionBase.hpp:445
std::enable_if<!Dummy::IS_CHARGE_SU2(), OperatorType >::type d(std::size_t orbital=0) const
Definition: FermionBase.hpp:570
std::enable_if< Dummy::NO_SPIN_SYM(), OperatorType >::type Sx(std::size_t orbital=0) const
Definition: FermionBase.hpp:636
Definition: Hubbard.hpp:25
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 1, false, Opts::CTMCheckpoint{}> &env) override
Definition: Hubbard.hpp:244
FermionBase< Symmetry > F
Definition: Hubbard.hpp:271
std::vector< std::unique_ptr< ObservableBase > > obs
Definition: Hubbard.hpp:272
std::vector< std::string > used_params
Definition: Hubbard.hpp:270
Pattern pat
Definition: Hubbard.hpp:269
Hubbard(std::map< std::string, Param > &params_in, const Pattern &pat_in, Opts::Bond bond=Opts::Bond::H|Opts::Bond::V)
Definition: Hubbard.hpp:27
virtual void computeObs(XPED_CONST CTM< std::complex< double >, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: Hubbard.hpp:230
virtual void setDefaultObs() override
Definition: Hubbard.hpp:131
virtual std::string file_name() const override
Definition: Hubbard.hpp:211
virtual void computeObs(XPED_CONST CTM< double, Symmetry, 2, false, Opts::CTMCheckpoint{}> &env) override
Definition: Hubbard.hpp:221
std::map< std::string, Param > params
Definition: Hubbard.hpp:268
virtual void obsToFile(HighFive::File &file, const std::string &root="/") const override
Definition: Hubbard.hpp:263
virtual std::string format() const override
Definition: Hubbard.hpp:216
virtual std::string getObsString(const std::string &offset) const override
Definition: Hubbard.hpp:253
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
std::size_t Ly
Definition: Pattern.hpp:72
std::size_t Lx
Definition: Pattern.hpp:72
Definition: CombSym.hpp:12
Definition: SU2.hpp:43
Definition: ZN.hpp:35
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