VMPS++
Loading...
Searching...
No Matches
SpinlessFermionsObservables.h
Go to the documentation of this file.
1#ifndef SPINLESSFERMIONSOBSERVABLES
2#define SPINLESSFERMIONSOBSERVABLES
3
4#include "bases/SpinlessFermionBase.h"
5#include "Mpo.h"
6#include "ParamHandler.h" // from HELPERS
7
8template<typename Symmetry, typename Scalar=double>
10{
12
13public:
14
17 SpinlessFermionsObservables (const size_t &L); // for inheritance purposes
18 SpinlessFermionsObservables (const size_t &L, const vector<Param> &params, const std::map<string,std::any> &defaults);
20
22 Mpo<Symmetry,Scalar> c (size_t locx, size_t locy=0) const;
23 Mpo<Symmetry,Scalar> cdag (size_t locx, size_t locy=0) const;
25// Mpo<Symmetry,Scalar> c_plus_cdag (size_t locx, size_t locy=0) const;
27
29// Mpo<Symmetry,Scalar> cdagc (size_t locx1, size_t locx2, size_t locy1=0, size_t locy2=0) const;
31
33
34// Mpo<Symmetry,Scalar> d (size_t locx, size_t locy=0) const;
35 Mpo<Symmetry,Scalar> n (size_t locx, size_t locy=0) const;
36 Mpo<Symmetry,Scalar> nph (size_t locx, size_t locy=0) const;
37 Mpo<Symmetry,Scalar> nn (size_t locx1, size_t locx2, size_t locy1=0, size_t locy2=0) const;
39
40protected:
41
42 Mpo<Symmetry,Scalar> make_local (size_t locx, size_t locy, const OperatorType &Op, double factor, bool FERMIONIC=false, bool HERMITIAN=false) const;
43 Mpo<Symmetry,Scalar> make_corr (string name1, string name2,
44 size_t locx1, size_t locx2, size_t locy1, size_t locy2,
45 const OperatorType &Op1, const OperatorType &Op2,
46 bool BOTH_HERMITIAN=false) const;
47
48 vector<SpinlessFermionBase<Symmetry> > F;
49};
50
51template<typename Symmetry, typename Scalar>
53SpinlessFermionsObservables (const size_t &L)
54{
55 F.resize(L);
56}
57
58template<typename Symmetry, typename Scalar>
60SpinlessFermionsObservables (const size_t &L, const vector<Param> &params, const std::map<string,std::any> &defaults)
61{
62 ParamHandler P(params,defaults);
63 size_t Lcell = P.size();
64 F.resize(L);
65
66 for (size_t l=0; l<L; ++l)
67 {
68 F[l] = SpinlessFermionBase<Symmetry>(P.get<size_t>("Ly",l%Lcell));
69 }
70}
71
72//-------------
73
74template<typename Symmetry, typename Scalar>
76make_local (size_t locx, size_t locy, const OperatorType &Op, double factor, bool FERMIONIC, bool HERMITIAN) const
77{
78 assert(locx<F.size() and locy<F[locx].dim());
79 stringstream ss;
80 ss << Op.label() << "(" << locx << "," << locy;
81 if (factor != 1.) ss << ",factor=" << factor;
82 ss << ")";
83
84 Mpo<Symmetry,Scalar> Mout(F.size(), Op.Q(), ss.str(), HERMITIAN);
85 for (size_t l=0; l<F.size(); ++l) Mout.setLocBasis(F[l].get_basis().qloc(),l);
86
87 if (FERMIONIC)
88 {
89 vector<SiteOperator<Symmetry,Scalar> > Signs(locx);
90 for (size_t l=0; l<locx; ++l) {Signs[l] = F[l].sign().template plain<double>().template cast<Scalar>();}
91
92 Mout.setLocal(locx, (factor * Op).template plain<double>().template cast<Scalar>(), Signs);
93 }
94 else
95 {
96 Mout.setLocal(locx, (factor * Op).template plain<double>().template cast<Scalar>());
97 }
98
99 return Mout;
100}
101
102template<typename Symmetry, typename Scalar>
104make_corr (string name1, string name2,
105 size_t locx1, size_t locx2, size_t locy1, size_t locy2,
106 const OperatorType &Op1, const OperatorType &Op2,
107 bool BOTH_HERMITIAN) const
108{
109 assert(locx1<F.size() and locx2<F.size() and locy1<F[locx1].dim() and locy2<F[locx2].dim());
110 stringstream ss;
111 ss << name1 << "(" << locx1 << "," << locy1 << ")"
112 << name2 << "(" << locx2 << "," << locy2 << ")";
113
114 bool HERMITIAN = (BOTH_HERMITIAN and locx1==locx2 and locy1==locy2)? true:false;
115
116 Mpo<Symmetry,Scalar> Mout(F.size(), Op1.Q+Op2.Q, ss.str(), HERMITIAN);
117 for (size_t l=0; l<F.size(); ++l) {Mout.setLocBasis(F[l].get_basis(),l);}
118
119 Mout.setLocal({locx1,locx2}, {Op1,Op2});
120 return Mout;
121}
122
123//-------------
124
125template<typename Symmetry, typename Scalar>
127c (size_t locx, size_t locy) const
128{
129 return make_local(locx,locy, F[locx].c(locy), 1., true);
130}
131
132template<typename Symmetry, typename Scalar>
134cdag (size_t locx, size_t locy) const
135{
136 return make_local(locx,locy, F[locx].cdag(locy), 1., true);
137}
138
139//template<typename Symmetry, typename Scalar>
140//Mpo<Symmetry,Scalar> SpinlessFermionsObservables<Symmetry,Scalar>::
141//c_plus_cdag (size_t locx, size_t locy) const
142//{
143// assert(Symmetry::name() != "U(1)");
144// return make_local("c+c†", locx,locy, 1./sqrt(2.)*(F[locx].c(locy)+F[locx].cdag(locy)), true);
145//}
146
147template<typename Symmetry, typename Scalar>
149n (size_t locx, size_t locy) const
150{
151 return make_local(locx,locy, F[locx].n(locy), 1., false, true);
152}
153
154template<typename Symmetry, typename Scalar>
156nph (size_t locx, size_t locy) const
157{
158 return make_local(locx,locy, F[locx].nph(locy), 1., false, true);
159}
160
161//template<typename Symmetry, typename Scalar>
162//Mpo<Symmetry,Scalar> SpinlessFermionsObservables<Symmetry,Scalar>::
163//d (size_t locx, size_t locy) const
164//{
165// return make_local("d", locx,locy, F[locx].Zero(), false, true);
166//}
167
168//template<typename Symmetry, typename Scalar>
169//Mpo<Symmetry,Scalar> SpinlessFermionsObservables<Symmetry,Scalar>::
170//cdagc (size_t locx1, size_t locx2, size_t locy1, size_t locy2) const
171//{
172// assert(locx1<F.size() and locx2<F.size());
173// stringstream ss;
174// ss << "c†" << "(" << locx1 << "," << locy1 << "," << ")"
175// << "c " << "(" << locx2 << "," << locy2 << "," << ")";
176//
177// auto cdag = F[locx1].cdag(locy1);
178// auto c = F[locx2].c (locy2);
179//
180// Mpo<Symmetry,Scalar> Mout(F.size(), cdag.Q+c.Q, ss.str());
181// for (size_t l=0; l<F.size(); ++l) {Mout.setLocBasis(F[l].get_basis(),l);}
182//
183// if (locx1 == locx2)
184// {
185// Mout.setLocal(locx1, cdag*c);
186// }
187// else if (locx1<locx2)
188// {
189// Mout.setLocal({locx1, locx2}, {cdag*F[locx1].sign(), c}, F[0].sign());
190// }
191// else if (locx1>locx2)
192// {
193// Mout.setLocal({locx2, locx1}, {c*F[locx2].sign(), -1.*cdag}, F[0].sign());
194// }
195//
196// return Mout;
197//}
198
199//-------------
200
201template<typename Symmetry, typename Scalar>
203nn (size_t locx1, size_t locx2, size_t locy1, size_t locy2) const
204{
205 return make_corr ("n","n", locx1,locx2,locy1,locy2, F[locx1].n(locy1), F[locx2].n(locy2), true);
206}
207
208#endif
void setLocBasis(const std::vector< std::vector< qType > > &q)
Definition: MpoTerms.h:715
Definition: Mpo.h:40
void setLocal(std::size_t loc, const OperatorType &op)
std::string & label()
Mpo< Symmetry, Scalar > n(size_t locx, size_t locy=0) const
vector< SpinlessFermionBase< Symmetry > > F
Mpo< Symmetry, Scalar > c(size_t locx, size_t locy=0) const
Mpo< Symmetry, Scalar > nn(size_t locx1, size_t locx2, size_t locy1=0, size_t locy2=0) const
Mpo< Symmetry, Scalar > cdag(size_t locx, size_t locy=0) const
Mpo< Symmetry, Scalar > make_corr(string name1, string name2, size_t locx1, size_t locx2, size_t locy1, size_t locy2, const OperatorType &Op1, const OperatorType &Op2, bool BOTH_HERMITIAN=false) const
Mpo< Symmetry, Scalar > make_local(size_t locx, size_t locy, const OperatorType &Op, double factor, bool FERMIONIC=false, bool HERMITIAN=false) const
SpinlessFermionsObservables(const size_t &L, const vector< Param > &params, const std::map< string, std::any > &defaults)
SiteOperatorQ< Symmetry, Eigen::MatrixXd > OperatorType
Mpo< Symmetry, Scalar > nph(size_t locx, size_t locy=0) const