HΦ  3.1.0
PairExHubbard.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 /*-------------------------------------------------------------*/
17 #include "bitcalc.h"
18 #include "wrapperMPI.h"
19 #include "mltplyCommon.h"
20 #include "mltplyHubbard.h"
21 #include "mltplyHubbardCore.h"
22 #include "mltplyMPIHubbard.h"
23 #include "mltplyMPIHubbardCore.h"
24 #ifdef MPI
25 #include "mfmemory.h"
26 #endif
27 
38  struct BindStruct *X,
39  double complex *tmp_v0,
40  double complex *tmp_v1
42 ){
43 
44  long unsigned int i,j;
45  long unsigned int isite1;
46  long unsigned int org_isite1,org_isite2,org_sigma1,org_sigma2;
47 
48  double complex tmp_trans=0;
49  long int i_max;
50  long int ibit;
51  long unsigned int is;
52  i_max = X->Check.idim_maxOrg;
53  for(i=0;i<X->Def.NPairExcitationOperator;i++) {
54  org_isite1 = X->Def.PairExcitationOperator[i][0] + 1;
55  org_isite2 = X->Def.PairExcitationOperator[i][2] + 1;
56  org_sigma1 = X->Def.PairExcitationOperator[i][1];
57  org_sigma2 = X->Def.PairExcitationOperator[i][3];
58  tmp_trans = X->Def.ParaPairExcitationOperator[i];
59 
60  if (org_isite1 > X->Def.Nsite &&
61  org_isite2 > X->Def.Nsite) {
62  if (org_isite1 == org_isite2 && org_sigma1 == org_sigma2) {
63  if (X->Def.PairExcitationOperator[i][4] == 0) {
64  if (org_sigma1 == 0) {
65  is = X->Def.Tpow[2 * org_isite1 - 2];
66  }
67  else {
68  is = X->Def.Tpow[2 * org_isite1 - 1];
69  }
70  ibit = (unsigned long int) myrank & is;
71  if (ibit == is) {
72 #pragma omp parallel for default(none) shared(tmp_v0, tmp_v1) \
73  firstprivate(i_max, tmp_trans) private(j)
74  for (j = 1; j <= i_max; j++) tmp_v0[j] += tmp_trans * tmp_v1[j];
75  }
76  }
77  else {//X->Def.PairExcitationOperator[i][4]==1
78  if (org_sigma1 == 0) {
79  is = X->Def.Tpow[2 * org_isite1 - 2];
80  }
81  else {
82  is = X->Def.Tpow[2 * org_isite1 - 1];
83  }
84  ibit = (unsigned long int) myrank & is;
85  if (ibit != is) {
86  //minus sign comes from negative tmp_trans due to readdef
87 #pragma omp parallel for default(none) shared(tmp_v0, tmp_v1) \
88  firstprivate(i_max, tmp_trans) private(j)
89  for (j = 1; j <= i_max; j++) tmp_v0[j] += -tmp_trans * tmp_v1[j];
90  }
91  }
92  }
93  else {
94  X_GC_child_general_hopp_MPIdouble(org_isite1 - 1, org_sigma1, org_isite2 - 1, org_sigma2, -tmp_trans, X,
95  tmp_v0, tmp_v1);
96  }
97  }
98  else if (org_isite2 > X->Def.Nsite || org_isite1 > X->Def.Nsite) {
99  if (org_isite1 < org_isite2) {
100  X_GC_child_general_hopp_MPIsingle(org_isite1 - 1, org_sigma1, org_isite2 - 1, org_sigma2, -tmp_trans, X,
101  tmp_v0, tmp_v1);
102  }
103  else {
104  X_GC_child_general_hopp_MPIsingle(org_isite2 - 1, org_sigma2, org_isite1 - 1, org_sigma1,
105  -conj(tmp_trans), X, tmp_v0, tmp_v1);
106  }
107  }
108  else {
109 
110  if (org_isite1 == org_isite2 && org_sigma1 == org_sigma2 && X->Def.PairExcitationOperator[i][4] == 1) {
111  isite1=X->Def.Tpow[2 * org_isite1 - 2 + org_sigma1];
112 #pragma omp parallel for default(none) private(j) firstprivate(i_max,X,isite1, tmp_trans) shared(tmp_v0, tmp_v1)
113  for(j=1;j<=i_max;j++){
114  GC_AisCis(j, tmp_v0, tmp_v1, X, isite1, -tmp_trans);
115  }
116  }
117  else {
118  if (child_general_hopp_GetInfo(X, org_isite1, org_isite2, org_sigma1, org_sigma2) != 0) {
119  return -1;
120  }
121  GC_child_general_hopp(tmp_v0, tmp_v1, X, tmp_trans);
122  }
123  }
124  }
125  return TRUE;
126 }
127 
138  struct BindStruct *X,
139  double complex *tmp_v0,
140  double complex *tmp_v1
141 ){
142  long unsigned int i,j, idim_maxMPI;
143  long unsigned int irght,ilft,ihfbit;
144  long unsigned int org_isite1,org_isite2,org_sigma1,org_sigma2;
145  long unsigned int tmp_off=0;
146 
147  double complex tmp_trans=0;
148  long int i_max;
149  int tmp_sgn, num1;
150  long int ibit;
151  long unsigned int is, Asum, Adiff;
152  long unsigned int ibitsite1, ibitsite2;
153 
154  // i_max = X->Check.idim_max;
155  i_max = X->Check.idim_maxOrg;
156  if(GetSplitBitByModel(X->Def.Nsite, X->Def.iCalcModel, &irght, &ilft, &ihfbit)!=0){
157  return -1;
158  }
159  X->Large.i_max = i_max;
160  X->Large.irght = irght;
161  X->Large.ilft = ilft;
162  X->Large.ihfbit = ihfbit;
163  X->Large.mode=M_CALCSPEC;
164 // X->Large.mode = M_MLTPLY;
165 
166  double complex *tmp_v1bufOrg;
167  //set size
168 #ifdef MPI
169  idim_maxMPI = MaxMPI_li(X->Check.idim_maxOrg);
170  c_malloc1(tmp_v1bufOrg, idim_maxMPI + 1);
171 #endif // MPI
172 
173  for(i=0;i<X->Def.NPairExcitationOperator;i++){
174  org_isite1 = X->Def.PairExcitationOperator[i][0]+1;
175  org_isite2 = X->Def.PairExcitationOperator[i][2]+1;
176  org_sigma1 = X->Def.PairExcitationOperator[i][1];
177  org_sigma2 = X->Def.PairExcitationOperator[i][3];
178  tmp_trans = X->Def.ParaPairExcitationOperator[i];
179  ibitsite1 = X->Def.OrgTpow[2*org_isite1-2+org_sigma1] ;
180  ibitsite2 = X->Def.OrgTpow[2*org_isite2-2+org_sigma2] ;
181  child_general_hopp_GetInfo(X, org_isite1, org_isite2, org_sigma1, org_sigma2);
182  Asum = X->Large.isA_spin;
183  Adiff = X->Large.A_spin;
184 
185  if(X->Def.iFlagListModified == TRUE // Not to adopt HubbrdNConserved
186  && org_sigma1 != org_sigma2){
187  if (org_isite1 > X->Def.Nsite &&
188  org_isite2 > X->Def.Nsite)
189  {
190  X_child_CisAjt_MPIdouble(org_isite1-1, org_sigma1, org_isite2-1, org_sigma2, -tmp_trans, X, tmp_v0, tmp_v1, tmp_v1bufOrg, list_1_org, list_1buf_org, list_2_1, list_2_2);
191  }
192  else if (org_isite2 > X->Def.Nsite
193  || org_isite1 > X->Def.Nsite)
194  {
195  if(org_isite1 < org_isite2) {
196  X_child_CisAjt_MPIsingle(org_isite1 - 1, org_sigma1, org_isite2 - 1, org_sigma2, -tmp_trans, X, tmp_v0,
197  tmp_v1, tmp_v1bufOrg, list_1_org, list_1buf_org, list_2_1, list_2_2);
198  } else{
199  X_child_CisAjt_MPIsingle(org_isite2 - 1, org_sigma2, org_isite1 - 1, org_sigma1, -conj(tmp_trans), X, tmp_v0,
200  tmp_v1, tmp_v1bufOrg, list_1_org, list_1buf_org, list_2_1, list_2_2); }
201  }
202  else{
203 #pragma omp parallel for default(none) shared(tmp_v0, tmp_v1,stdoutMPI) \
204  firstprivate(i_max, tmp_trans, Asum, Adiff, ibitsite1, ibitsite2, X, list_1_org, list_1, myrank) \
205  private(j, tmp_sgn, tmp_off)
206  for (j = 1; j <= i_max; j++){
207  tmp_sgn=X_CisAjt(list_1_org[j], X, ibitsite1, ibitsite2, Asum, Adiff, &tmp_off);
208  tmp_v0[tmp_off] += tmp_trans * tmp_sgn*tmp_v1[j];
209  }
210  }
211  }
212  else{
213  if (org_isite1 > X->Def.Nsite &&
214  org_isite2 > X->Def.Nsite) {
215  if(org_isite1==org_isite2 && org_sigma1==org_sigma2){//diagonal
216  is = X->Def.Tpow[2 * org_isite1 - 2 + org_sigma1];
217  ibit = (unsigned long int) myrank & is;
218  if( X->Def.PairExcitationOperator[i][4]==0) {
219  if (ibit == is) {
220 #pragma omp parallel for default(none) shared(tmp_v0, tmp_v1) \
221  firstprivate(i_max, tmp_trans) private(j)
222  for (j = 1; j <= i_max; j++) tmp_v0[j] += tmp_trans * tmp_v1[j];
223  }
224  }
225  else{
226  if (ibit != is) {
227 #pragma omp parallel for default(none) shared(tmp_v0, tmp_v1) \
228  firstprivate(i_max, tmp_trans) private(j)
229  for (j = 1; j <= i_max; j++) tmp_v0[j] += -tmp_trans * tmp_v1[j];
230  }
231  }
232  }
233  else{
234  X_child_general_hopp_MPIdouble(org_isite1-1, org_sigma1, org_isite2-1, org_sigma2, -tmp_trans, X, tmp_v0, tmp_v1);
235  }
236  }
237  else if (org_isite2 > X->Def.Nsite || org_isite1 > X->Def.Nsite){
238  if(org_isite1 < org_isite2){
239  X_child_general_hopp_MPIsingle(org_isite1-1, org_sigma1,org_isite2-1, org_sigma2, -tmp_trans, X, tmp_v0, tmp_v1);
240  }
241  else{
242  X_child_general_hopp_MPIsingle(org_isite2-1, org_sigma2, org_isite1-1, org_sigma1, -conj(tmp_trans), X, tmp_v0, tmp_v1);
243  }
244  }
245  else{
246  if(child_general_hopp_GetInfo( X,org_isite1,org_isite2,org_sigma1,org_sigma2)!=0){
247  return -1;
248  }
249  if(org_isite1==org_isite2 && org_sigma1==org_sigma2){
250  is = X->Def.Tpow[2 * org_isite1 - 2 + org_sigma1];
251  if( X->Def.PairExcitationOperator[i][4]==0) {
252 #pragma omp parallel for default(none) shared(list_1, tmp_v0, tmp_v1) firstprivate(i_max, is, tmp_trans) private(num1, ibit)
253  for (j = 1; j <= i_max; j++) {
254  ibit = list_1[j] & is;
255  num1 = ibit / is;
256  tmp_v0[j] += tmp_trans * num1 * tmp_v1[j];
257  }
258  }
259  else{
260 #pragma omp parallel for default(none) shared(list_1, tmp_v0, tmp_v1) firstprivate(i_max, is, tmp_trans) private(num1, ibit)
261  for (j = 1; j <= i_max; j++) {
262  ibit = list_1[j] & is;
263  num1 = (1-ibit / is);
264  tmp_v0[j] += -tmp_trans * num1 * tmp_v1[j];
265  }
266  }
267  }
268  else{
269  child_general_hopp(tmp_v0, tmp_v1,X,tmp_trans);
270  }
271  }
272  }
273  }
274  return TRUE;
275 }
int GetPairExcitedStateHubbardGC(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Definition: PairExHubbard.c:37
double complex X_GC_child_general_hopp_MPIdouble(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Hopping term in Hubbard + GC When both site1 and site2 are in the inter process region.
int X_CisAjt(long unsigned int list_1_j, struct BindStruct *X, long unsigned int is1_spin, long unsigned int is2_spin, long unsigned int sum_spin, long unsigned int diff_spin, long unsigned int *tmp_off)
Compute index of wavefunction of final state.
#define TRUE
Definition: global.h:26
long unsigned int * list_1buf_org
Definition: global.h:54
double complex X_GC_child_general_hopp_MPIsingle(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Hopping term in Hubbard + GC When only site2 is in the inter process region.
double complex X_child_CisAjt_MPIsingle(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1, double complex *v1buf, long unsigned int *list_1_org, long unsigned int *list_1buf_org, long unsigned int *list_2_1_target, long unsigned int *list_2_2_target)
Hopping term in Hubbard (Kondo) + Canonical ensemble When only site2 is in the inter process region...
double complex child_general_hopp(double complex *tmp_v0, double complex *tmp_v1, struct BindStruct *X, double complex trans)
Compute hopping (canonical)
Bind.
Definition: struct.h:408
double complex GC_AisCis(long unsigned int j, double complex *tmp_v0, double complex *tmp_v1, struct BindStruct *X, long unsigned int is1_spin, double complex tmp_trans)
Operation of (Grandcanonical)
int GetSplitBitByModel(const int Nsite, const int iCalcModel, long unsigned int *irght, long unsigned int *ilft, long unsigned int *ihfbit)
function of splitting original bit into right and left spaces.
Definition: bitcalc.c:78
long unsigned int * list_1_org
Definition: global.h:53
unsigned long int MaxMPI_li(unsigned long int idim)
MPI wrapper function to obtain maximum unsigned long integer across processes.
Definition: wrapperMPI.c:171
long unsigned int * list_2_1
Definition: global.h:49
double complex X_child_general_hopp_MPIsingle(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Hopping term in Hubbard (Kondo) + Canonical ensemble When only site2 is in the inter process region...
long unsigned int * list_1
Definition: global.h:47
int child_general_hopp_GetInfo(struct BindStruct *X, unsigned long int isite1, unsigned long int isite2, unsigned long int sigma1, unsigned long int sigma2)
Compute mask for bit operation of hopping term.
long unsigned int * list_2_2
Definition: global.h:50
double complex X_child_CisAjt_MPIdouble(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1, double complex *v1buf, long unsigned int *list_1_org, long unsigned int *list_1buf_org, long unsigned int *list_2_1_target, long unsigned int *list_2_2_target)
Hopping term in Hubbard + MPI When both site1 and site2 are in the inter process region.
int GetPairExcitedStateHubbard(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
struct EDMainCalStruct X
Definition: struct.h:431
double complex GC_child_general_hopp(double complex *tmp_v0, double complex *tmp_v1, struct BindStruct *X, double complex trans)
Commpute hopping term (grandcanonical)
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:162
double complex X_child_general_hopp_MPIdouble(int org_isite1, int org_ispin1, int org_isite2, int org_ispin2, double complex tmp_trans, struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Hopping term in Hubbard (Kondo) + Canonical ensemble When both site1 and site2 are in the inter proce...