VMPS++
Loading...
Searching...
No Matches
VumpsLinearAlgebra.h
Go to the documentation of this file.
1#ifndef VUMPSLINEARALGEBRA
2#define VUMPSLINEARALGEBRA
3
4#include "tensors/Multipede.h"
6
7template<typename Symmetry, typename MpoScalar>
8complex<double> calc_formfactor_L (const Biped<Symmetry,Matrix<complex<double>,Dynamic,Dynamic> > &Teigen,
10 const Umps<Symmetry,double> &V)
11{
14
15 auto Obs = O;
16 Obs.transform_base(V.Qtarget(),false);
17
18 B.setIdentity(Obs.inBasis(0).inner_dim(Symmetry::qvacuum()), 1, V.inBasis(0));
19 for (size_t l=0; l<Obs.length(); ++l)
20 {
21 contract_L(B, V.A_at(GAUGE::L,l), Obs.W_at(l), V.A_at(GAUGE::L,l), Obs.locBasis(l), Obs.opBasis(l), Bnext);
22 B.clear();
23 B = Bnext;
24 Bnext.clear();
25 }
26
27 return contract_LR(std::make_pair(Symmetry::qvacuum(),0ul), B.template cast<Matrix<complex<double>,Dynamic,Dynamic> >(), Teigen);
28}
29
30template<typename Symmetry, typename MpoScalar>
31complex<double> calc_formfactor_R (const Biped<Symmetry,Matrix<complex<double>,Dynamic,Dynamic> > &Teigen,
33 const Umps<Symmetry,double> &V)
34{
37
38 auto Obs = O;
39 Obs.transform_base(V.Qtarget(),false);
40
41 B.setIdentity(Obs.outBasis(Obs.length()-1).inner_dim(Symmetry::qvacuum()), 1, V.outBasis((Obs.length()-1)%V.length()));
42 for (size_t l=0; l<Obs.length(); ++l)
43 {
44 GAUGE::OPTION g = (l==Obs.length()-1)? GAUGE::C : GAUGE::L;
45 contract_R(B, V.A_at(g,l), Obs.W_at(l), V.A_at(g,l), Obs.locBasis(l), Obs.opBasis(l), Bnext);
46 B.clear();
47 B = Bnext;
48 Bnext.clear();
49 }
50
51 return contract_LR(std::make_pair(Symmetry::qvacuum(),0ul), Teigen, B.template cast<Matrix<complex<double>,Dynamic,Dynamic> >());
52}
53
55template<typename Symmetry, typename MpoScalar, typename Scalar>
56Scalar avg (const Umps<Symmetry,Scalar> &Vbra,
58 const Umps<Symmetry,Scalar> &Vket)
59{
63 size_t Ncells = 1;
64 auto Obs = O;
65
66 if (Obs.length() != Vket.length() and Vket.Qtarget() != Symmetry::qvacuum())
67 {
68 assert(Obs.length()%Vket.length() == 0); //?
69 Ncells = static_cast<size_t>(Obs.length()/Vket.length());
70 qarray<Symmetry::Nq> transformed_Qtot = ::adjustQN<Symmetry>(Vket.Qtarget(),Ncells);
71 Obs.transform_base(transformed_Qtot,false);
72 }
73 else
74 {
75 Obs.transform_base(Vket.Qtarget(),false);
76 }
77
78 if (Obs.length() != Vket.length() and Vket.Qtarget() != Symmetry::qvacuum())
79 {
80 auto Vbra_copy = Vbra;
81 auto Vket_copy = Vket;
82
83 Vbra_copy.adjustQN(Ncells);
84 Vket_copy.adjustQN(Ncells);
85
86 B.setIdentity(Obs.inBasis(0).inner_dim(Symmetry::qvacuum()), 1, Vket_copy.inBasis(0));
87 for (size_t l=0; l<Obs.length(); ++l)
88 {
89 GAUGE::OPTION g = (l==0)? GAUGE::C : GAUGE::R;
91 Vbra_copy.A_at(g,l%Vket.length()), Obs.W_at(l),
92 Vket_copy.A_at(g,l%Vket.length()), Obs.locBasis(l), Obs.opBasis(l), Bnext);
93
94 B.clear();
95 B = Bnext;
96 Bnext.clear();
97 }
98 IdR.setIdentity(Obs.outBasis(Obs.length()-1).inner_dim(Symmetry::qvacuum()), 1, Vket_copy.outBasis((Obs.length()-1)%Vket.length()));
99 }
100 else // do not copy, optimize for memory
101 {
102 B.setIdentity(Obs.inBasis(0).inner_dim(Symmetry::qvacuum()), 1, Vket.inBasis(0));
103 for (size_t l=0; l<Obs.length(); ++l)
104 {
105 GAUGE::OPTION g = (l==0)? GAUGE::C : GAUGE::R;
107 Vbra.A_at(g,l%Vket.length()), Obs.W_at(l),
108 Vket.A_at(g,l%Vket.length()), Obs.locBasis(l), Obs.opBasis(l), Bnext);
109
110 B.clear();
111 B = Bnext;
112 Bnext.clear();
113 }
114 IdR.setIdentity(Obs.outBasis(Obs.length()-1).inner_dim(Symmetry::qvacuum()), 1, Vket.outBasis((Obs.length()-1)%Vket.length()));
115 }
116
117 return contract_LR(B,IdR);
118}
119
120//template<typename Symmetry, typename MpoScalar, typename Scalar>
121//complex<Scalar> avg (const vector<vector<Biped<Symmetry,Matrix<complex<Scalar>,Dynamic,Dynamic>>>> &Abra,
122// const Biped<Symmetry,Matrix<complex<double>,Dynamic,Dynamic>> &L,
123// const Mpo<Symmetry,MpoScalar> &O,
124// const vector<vector<Biped<Symmetry,Matrix<complex<Scalar>,Dynamic,Dynamic>>>> &Aket,
125// const Biped<Symmetry,Matrix<complex<double>,Dynamic,Dynamic>> &R)
126//{
127// Tripod<Symmetry,Matrix<complex<Scalar>,Dynamic,Dynamic> > Bnext;
128// Tripod<Symmetry,Matrix<complex<Scalar>,Dynamic,Dynamic> > B(L);
129// Tripod<Symmetry,Matrix<complex<Scalar>,Dynamic,Dynamic> > Blast(R);
130// size_t Ncells = 1;
131// auto Obs = O;
132//
144//
145// for (size_t l=0; l<Obs.length(); ++l)
146// {
147// contract_L(B,
148// Abra[l%Aket.size()], Obs.W_at(l),
149// Aket[l%Aket.size()], Obs.locBasis(l), Obs.opBasis(l), Bnext);
150//
151// B.clear();
152// B = Bnext;
153// Bnext.clear();
154// }
155//
156// return contract_LR(B,Blast);
157//}
158
159template<typename Symmetry, typename MpoScalar, typename Scalar>
160Scalar avg (const Umps<Symmetry,Scalar> &Vbra,
161 const Mpo<Symmetry,MpoScalar> &O1,
162 const Mpo<Symmetry,MpoScalar> &O2,
163 const Umps<Symmetry,Scalar> &Vket)
164{
168 size_t Ncells = 1;
169 auto Obs1 = O1;
170 auto Obs2 = O2;
171
172 if (Obs1.length() != Vket.length() and Vket.Qtarget() != Symmetry::qvacuum())
173 {
174 assert(Obs1.length()%Vket.length() == 0); //?
175 Ncells = static_cast<size_t>(Obs1.length()/Vket.length());
176 qarray<Symmetry::Nq> transformed_Qtot = ::adjustQN<Symmetry>(Vket.Qtarget(),Ncells);
177 Obs1.transform_base(transformed_Qtot,false);
178 Obs2.transform_base(transformed_Qtot,false);
179 }
180 else
181 {
182 Obs1.transform_base(Vket.Qtarget(),false);
183 Obs2.transform_base(Vket.Qtarget(),false);
184 }
185
186 if (Obs1.length() != Vket.length() and Vket.Qtarget() != Symmetry::qvacuum())
187 {
188 auto Vbra_copy = Vbra;
189 auto Vket_copy = Vket;
190
191 Vbra_copy.adjustQN(Ncells);
192 Vket_copy.adjustQN(Ncells);
193
194 B.setIdentity(Obs1.outBasis(Obs1.length()-1).inner_dim(Symmetry::qvacuum()), 1, Vket_copy.outBasis((Obs1.length()-1)%Vket.length()));
195 for (size_t l=O1.length()-1; l!=-1; --l)
196 {
197 GAUGE::OPTION g = (l==0)? GAUGE::C : GAUGE::R;
198
200 Vbra_copy.A_at(g,l%Vket.length()), Obs1.W_at(l), Obs2.W_at(l), Vket_copy.A_at(g,l%Vket.length()),
201 Obs1.locBasis(l), Obs1.opBasis(l), Obs2.opBasis(l),
202 Bnext);
203 B.clear();
204 B = Bnext;
205 Bnext.clear();
206 }
207 IdL.setIdentity(Obs1.inBasis(0).inner_dim(Symmetry::qvacuum()), 1, Vket_copy.inBasis(0));
208 }
209 else // do not copy, optimize for memory
210 {
211 B.setIdentity(Obs1.outBasis(Obs1.length()-1).inner_dim(Symmetry::qvacuum()), 1, Vket.outBasis((Obs1.length()-1)%Vket.length()));
212 for (size_t l=O1.length()-1; l!=-1; --l)
213 {
214 GAUGE::OPTION g = (l==0)? GAUGE::C : GAUGE::R;
215
217 Vbra.A_at(g,l%Vket.length()), Obs1.W_at(l), Obs2.W_at(l), Vket.A_at(g,l%Vket.length()),
218 Obs1.locBasis(l), Obs1.opBasis(l), Obs2.opBasis(l),
219 Bnext);
220 B.clear();
221 B = Bnext;
222 Bnext.clear();
223 }
224 IdL.setIdentity(Obs1.inBasis(0).inner_dim(Symmetry::qvacuum()), 1, Vket.inBasis(0));
225 }
226
227 return contract_LR(IdL,B);
228}
229
231template<typename Symmetry, typename MpoScalar, typename Scalar>
232Scalar avg (const Umps<Symmetry,Scalar> &Vbra,
233 const vector<Mpo<Symmetry,MpoScalar> > &O,
234 const Umps<Symmetry,Scalar> &Vket)
235{
236 Scalar out = 0;
237
238 for (int t=0; t<O.size(); ++t)
239 {
240// cout << "partial val=" << avg(Vbra,O[t],Vket) << endl;
241 out += avg(Vbra,O[t],Vket);
242 }
243 return out;
244}
245
246template<typename Symmetry, typename MpoScalar, typename Scalar>
247Scalar avg (const Umps<Symmetry,Scalar> &Vbra,
248 const vector<Mpo<Symmetry,MpoScalar> > &O1,
249 const vector<Mpo<Symmetry,MpoScalar> > &O2,
250 const Umps<Symmetry,Scalar> &Vket)
251{
252 Scalar out = 0;
253
254 for (int i=0; i<O1.size(); ++i)
255 for (int j=0; j<O2.size(); ++j)
256 {
257 cout << "partial val=" << avg(Vbra, O1[i], O2[j], Vket) << endl;
258 out += avg(Vbra, O1[i], O2[j], Vket);
259 }
260 return out;
261}
262
263#endif
@ B
Definition: DmrgTypedefs.h:130
complex< double > calc_formfactor_R(const Biped< Symmetry, Matrix< complex< double >, Dynamic, Dynamic > > &Teigen, const Mpo< Symmetry, MpoScalar > &O, const Umps< Symmetry, double > &V)
Scalar avg(const Umps< Symmetry, Scalar > &Vbra, const Mpo< Symmetry, MpoScalar > &O, const Umps< Symmetry, Scalar > &Vket)
complex< double > calc_formfactor_L(const Biped< Symmetry, Matrix< complex< double >, Dynamic, Dynamic > > &Teigen, const Mpo< Symmetry, MpoScalar > &O, const Umps< Symmetry, double > &V)
void transform_base(const qType &qShift, const bool PRINT=false, const int factor=-1, const std::size_t powre=0ul)
Definition: MpoTerms.h:3113
Definition: Mpo.h:40
std::size_t length() const
Definition: Mpo.h:112
Definition: Umps.h:42
const vector< Biped< Symmetry, MatrixType > > & A_at(GAUGE::OPTION g, size_t loc) const
Definition: Umps.h:201
size_t length() const
Definition: Umps.h:147
Qbasis< Symmetry > inBasis(size_t loc) const
Definition: Umps.h:133
qarray< Nq > Qtarget() const
Definition: Umps.h:211
Qbasis< Symmetry > outBasis(size_t loc) const
Definition: Umps.h:137
void adjustQN(const size_t number_cells)
Definition: Umps.h:2025
void contract_R(const Tripod< Symmetry, MatrixType2 > &Rold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Rnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
void contract_L(const Tripod< Symmetry, MatrixType2 > &Lold, const vector< Biped< Symmetry, MatrixType > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, MatrixType > > &Aket, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp, Tripod< Symmetry, MatrixType2 > &Lnew, bool RANDOMIZE=false, tuple< CONTRACT_LR_MODE, size_t > MODE_input=make_pair(FULL, 0), const std::unordered_map< pair< qarray< Symmetry::Nq >, size_t >, size_t > &basis_order_map={})
Scalar contract_LR(const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &L, const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &Abra, const vector< vector< vector< Biped< Symmetry, MpoMatrixType > > > > &W, const vector< Biped< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > > &Aket, const Tripod< Symmetry, Matrix< Scalar, Dynamic, Dynamic > > &R, const vector< qarray< Symmetry::Nq > > &qloc, const vector< qarray< Symmetry::Nq > > &qOp)
Definition: Biped.h:64
void clear()
Definition: Multipede.h:409
void setIdentity(size_t Drows, size_t Dcols, size_t amax=1, size_t bmax=1)
Definition: Multipede.h:509
Definition: qarray.h:26