v2DM-DOCI  1.0
SPM.cpp
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Copyright (C) 2014-2015 Ward Poelmans
5  *
6  * This file is part of v2DM-DOCI.
7  *
8  * v2DM-DOCI is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Foobar is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @END LICENSE
22  */
23 
24 #include <algorithm>
25 #include "include.h"
26 #include "lapack.h"
27 
28 #include "OptIndex.h"
29 #include "Irreps.h"
30 
31 using namespace doci2DM;
32 
38 SPM::SPM(int L, int N): BlockVector(1)
39 {
40  this->L = L;
41  this->N = N;
42 
43  setDim(0,L,2);
44 }
45 
51 SPM::SPM(const TPM &tpm): BlockVector(1)
52 {
53  this->L = tpm.gL();
54  this->N = tpm.gN();
55 
56  setDim(0,L,2);
57 
58  bar3(1.0/(N-1.0), tpm);
59 }
60 
61 int SPM::gN() const
62 {
63  return N;
64 }
65 
66 int SPM::gL() const
67 {
68  return L;
69 }
70 
71 int SPM::gn() const
72 {
73  return 2*L;
74 }
75 
84 double SPM::GetElement(int a, int b) const
85 {
86  if(a!=b)
87  return 0;
88 
89  return (*this)(0,a%L);
90 }
91 
97 void SPM::bar(double scal, const TPM &tpm)
98 {
99  for(int i=0;i<L;i++)
100  (*this)(0,i) = scal * tpm(0,i,i);
101 
102 // int incx = L+1;
103 // int incy = 1;
104 // dcopy_(&L, tpm.getMatrix(0).gMatrix(), &incx, (*this)[0].gVector(), &incy);
105 }
106 
112 void SPM::bar2(double scal, const TPM &tpm)
113 {
114  for(int i=0;i<L;i++)
115  {
116  (*this)(0,i) = 0;
117 
118  for(int a=0;a<L;a++)
119  (*this)(0,i) += tpm.getDiag(i,a);
120 
121  (*this)(0,i) *= scal;
122  }
123 }
124 
131 void SPM::bar3(double scal, const TPM &tpm)
132 {
133  for(int i=0;i<L;i++)
134  {
135  (*this)(0,i) = tpm.getMatrix(0)(i,i);
136 
137  for(int a=0;a<L;a++)
138  (*this)(0,i) += 2 * tpm.getDiag(i,a);
139 
140  (*this)(0,i) *= scal;
141  }
142 }
143 
144 
145 namespace doci2DM {
146 std::ostream &operator<<(std::ostream &output,SPM &spm)
147 {
148  output << "SPM (2x): " << std::endl;
149 
150  for(int i=0;i<spm.gL();i++)
151  output << i << "\t|\t" << i << " " << i << "\t\t" << spm(0,i) << std::endl;
152 
153  return output;
154 }
155 }
156 
157 void SPM::bar(double scal, const PHM &phm)
158 {
159  for(int i=0;i<L;i++)
160  {
161  (*this)(0,i) = 0;
162 
163  for(int a=0;a<L;a++)
164  (*this)(0,i) += phm(i,a,i,a)+phm(i,a+L,i,a+L);
165 
166  (*this)(0,i) *= scal;
167  }
168 }
169 
173 void SPM::PrintSorted() const
174 {
175  std::vector<std::pair<int, double>> spm_elems;
176  spm_elems.reserve(L);
177 
178  for(int i=0;i<L;i++)
179  spm_elems.push_back(std::make_pair(i, (*this)(0,i)));
180 
181  std::sort(spm_elems.begin(), spm_elems.end(),
182  [](const std::pair<int,double> & a, const std::pair<int,double> & b) -> bool
183  {
184  return a.second < b.second;
185  });
186 
187  for(auto& elem: spm_elems)
188  std::cout << elem.first << "\t|\t" << elem.first << " " << elem.first << "\t\t" << elem.second << std::endl;
189 }
190 
196 std::vector<double> SPM::Particlesperirrep(const simanneal::OptIndex &index, bool print) const
197 {
198  CheMPS2::Irreps symgroup(index.getNgroup());
199  const auto orbtoirrep = index.get_irrep_each_orbital();
200 
201  std::vector<double> results(symgroup.getNumberOfIrreps(), 0);
202 
203  for(int a=0;a<L;a++)
204  results[orbtoirrep[a]] += 2*(*this)(0,a);
205 
206  if(print)
207  {
208  std::cout << "Group: " << symgroup.getGroupName() << std::endl;
209  for(int i=0;i<symgroup.getNumberOfIrreps();i++)
210  std::cout << symgroup.getIrrepName(i) << ":\t" << results[i] << std::endl;
211  }
212 
213  return results;
214 }
215 
216 /* vim: set ts=3 sw=3 expandtab :*/
int gN() const
Definition: TPM.cpp:110
SPM(int L, int N)
Definition: SPM.cpp:38
Matrix & getMatrix(int)
Definition: Container.cpp:174
void PrintSorted() const
Definition: SPM.cpp:173
void bar(double, const TPM &)
Definition: SPM.cpp:97
double GetElement(int, int) const
Definition: SPM.cpp:84
int L
the size of the sp DOCI space (there are 2*L sp states)
Definition: SPM.h:92
const int * get_irrep_each_orbital() const
Definition: OptIndex.cpp:77
void bar2(double, const TPM &)
Definition: SPM.cpp:112
int gn() const
Definition: SPM.cpp:71
std::ostream & operator<<(std::ostream &output, const doci2DM::BlockStructure< MyBlockType > &blocks_p)
int N
number of particles
Definition: SPM.h:89
int gN() const
Definition: SPM.cpp:61
int gL() const
Definition: SPM.cpp:66
int getNgroup() const
Definition: OptIndex.cpp:79
void setDim(int, int, int)
std::vector< double > Particlesperirrep(const simanneal::OptIndex &index, bool print=true) const
Definition: SPM.cpp:196
double getDiag(int, int) const
Definition: TPM.cpp:905
void bar3(double, const TPM &)
Definition: SPM.cpp:131
int gL() const
Definition: TPM.cpp:115