From d8baf5fb0e80c5dc7f5d652ebeb4c3f68e7f5eb4 Mon Sep 17 00:00:00 2001 From: tmisawa Date: Thu, 2 May 2024 16:25:48 +0900 Subject: [PATCH 1/7] add three body G for general spin --- src/expec_cisajscktaltdc.c | 142 +++++++++++++++++++++++++++++ src/include/expec_cisajscktaltdc.h | 1 + src/include/mltplySpin.h | 10 ++ src/mltplySpin.c | 87 ++++++++++++++++++ 4 files changed, 240 insertions(+) diff --git a/src/expec_cisajscktaltdc.c b/src/expec_cisajscktaltdc.c index 2b7603494..4cf310eb8 100644 --- a/src/expec_cisajscktaltdc.c +++ b/src/expec_cisajscktaltdc.c @@ -771,6 +771,148 @@ int expec_cisajscktalt_SpinHalf(struct BindStruct *X,double complex *vec, FILE * return 0; } +/** + * @brief Child function to calculate three-body green functions for general Spin GC model + * + * @param X [in] data list for calculation + * @param vec [in] eigenvectors + * @param _fp [in] output file name + * @retval 0 normally finished + * @retval -1 abnormally finished + * + */ + +int expec_ThreeBody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE **_fp){ + long unsigned int i,j; + long unsigned int org_isite1,org_isite2,org_isite3,org_isite4,org_isite5,org_isite6; + long unsigned int org_sigma1,org_sigma2,org_sigma3,org_sigma4,org_sigma5,org_sigma6; + long unsigned int tmp_org_isite1,tmp_org_isite2,tmp_org_isite3,tmp_org_isite4,tmp_org_isite5,tmp_org_isite6; + long unsigned int tmp_org_sigma1,tmp_org_sigma2,tmp_org_sigma3,tmp_org_sigma4,tmp_org_sigma5,tmp_org_sigma6; + long unsigned int tmp_off=0; + long unsigned int tmp_off_2=0; + long unsigned int list1_off=0; + int num1; + double complex tmp_V; + double complex dam_pr; + long int i_max; + int tmp_Sz; + long unsigned int tmp_org=0; + double complex *vec_pr; + vec[0]=0; + i_max=X->Check.idim_max; + X->Large.mode=M_CORR; + + for(i=0;iDef.NTBody;i++){ + vec_pr = cd_1d_allocate(i_max + 1); + tmp_org_isite1 = X->Def.CisAjtCkuAlvDC[i][0]+1; + tmp_org_sigma1 = X->Def.CisAjtCkuAlvDC[i][1]; + tmp_org_isite2 = X->Def.CisAjtCkuAlvDC[i][2]+1; + tmp_org_sigma2 = X->Def.CisAjtCkuAlvDC[i][3]; + tmp_org_isite3 = X->Def.CisAjtCkuAlvDC[i][4]+1; + tmp_org_sigma3 = X->Def.CisAjtCkuAlvDC[i][5]; + tmp_org_isite4 = X->Def.CisAjtCkuAlvDC[i][6]+1; + tmp_org_sigma4 = X->Def.CisAjtCkuAlvDC[i][7]; + + /*[s]For three body*/ + org_isite5 = X->Def.TBody[i][8]+1; + org_sigma5 = X->Def.TBody[i][9]; + org_isite6 = X->Def.TBody[i][10]+1; + org_sigma6 = X->Def.TBody[i][11]; + + X->Large.mode = M_MLTPLY; + /* |vec_pr>= c5a6|phi>*/ + mltplyGeneralSpinGC_mini(X,tmp_org_isite5-1,tmp_org_sigma5,tmp_org_isite6-1,tmp_org_sigma6,vec_pr,vec); + X->Large.mode = M_CORR; + /*[e]For three body*/ + + if(Rearray_Interactions(i, &org_isite1, &org_isite2, &org_isite3, &org_isite4, &org_sigma1, &org_sigma2, &org_sigma3, &org_sigma4, &tmp_V, X,2)!=0){ + fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); + continue; + } + tmp_Sz=0; + + for(j=0;j<2; j++) { + tmp_org = X->Def.CisAjtCkuAlvDC[i][4*j+1]*X->Def.Tpow[X->Def.CisAjtCkuAlvDC[i][4 * j]]; + tmp_Sz += GetLocal2Sz(X->Def.CisAjtCkuAlvDC[i][4 * j] + 1, tmp_org, X->Def.SiteToBit, X->Def.Tpow); + tmp_org = X->Def.CisAjtCkuAlvDC[i][4*j+3]*X->Def.Tpow[X->Def.CisAjtCkuAlvDC[i][4 * j+2]]; + tmp_Sz -= GetLocal2Sz(X->Def.CisAjtCkuAlvDC[i][4 * j+2] + 1, tmp_org, X->Def.SiteToBit, X->Def.Tpow); + } + if(tmp_Sz !=0){ // not Sz conserved + fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); + continue; + } + + dam_pr = 0.0; + if(org_isite1 >X->Def.Nsite && org_isite3>X->Def.Nsite){ + if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal + dam_pr=child_CisAisCjuAju_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec); + } + else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_CisAitCjuAjv_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec); + } + else{ + dam_pr=0.0; + } + } + else if(org_isite3 > X->Def.Nsite || org_isite1 > X->Def.Nsite){ + if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal + dam_pr=child_CisAisCjuAju_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec); + } + else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_CisAitCjuAjv_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec); + } + else{ + dam_pr=0.0; + } + } + else{ + if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal +#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X,org_isite1, org_sigma1,org_isite3, org_sigma3, tmp_V) shared(vec,list_1) + for(j=1;j<=i_max;j++){ + num1=BitCheckGeneral(list_1[j], org_isite1, org_sigma1, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + num1=BitCheckGeneral(list_1[j], org_isite3, org_sigma3, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + dam_pr += tmp_V*conj(vec[j])*vec[j]; + } + } + } + } + else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ +#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1, org_sigma2, org_sigma3, org_sigma4, tmp_off, tmp_off_2, list1_off, myrank, tmp_V) shared(vec, list_1) + for(j=1;j<=i_max;j++){ + num1 = GetOffCompGeneralSpin(list_1[j], org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE) { + num1 = GetOffCompGeneralSpin(tmp_off, org_isite1, org_sigma2, org_sigma1, &tmp_off_2, + X->Def.SiteToBit, X->Def.Tpow); + if (num1 != FALSE) { + ConvertToList1GeneralSpin(tmp_off_2, X->Check.sdim, &list1_off); + dam_pr += tmp_V * conj(vec[list1_off]) * vec[j]; + } + } + } + //printf("DEBUG: rank=%d, dam_pr=%lf\n", myrank, creal(dam_pr)); + } + else{ + dam_pr=0.0; + } + } + dam_pr = SumMPI_dc(dam_pr); + //fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1, tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4, creal(dam_pr),cimag(dam_pr)); + fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n", + tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, + tmp_org_isite3-1, tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4, + tmp_org_isite5-1, tmp_org_sigma5, tmp_org_isite6-1, tmp_org_sigma6, + creal(dam_pr),cimag(dam_pr)); + free_cd_1d_allocate(vec_pr); + } + return 0; +} + + + + + /** * @brief Child function to calculate two-body green's functions for General Spin model * diff --git a/src/include/expec_cisajscktaltdc.h b/src/include/expec_cisajscktaltdc.h index 96f939d8b..e80c7718b 100644 --- a/src/include/expec_cisajscktaltdc.h +++ b/src/include/expec_cisajscktaltdc.h @@ -69,5 +69,6 @@ void expec_cisajscktaltdc_alldiag_spin( double complex *vec ); +int expec_Threebody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE **_fp); int expec_Threebody_SpinGCHalf(struct BindStruct *X,double complex *vec, FILE **_fp); int expec_Fourbody_SpinGCHalf(struct BindStruct *X,double complex *vec, FILE **_fp); diff --git a/src/include/mltplySpin.h b/src/include/mltplySpin.h index 3937fbd68..ef3ef69eb 100644 --- a/src/include/mltplySpin.h +++ b/src/include/mltplySpin.h @@ -35,6 +35,16 @@ void mltplyHalfSpinGC_mini( double complex *tmp_v1//!<[in] Input producted vector ); +void mltplyGeneralSpinGC_mini( + struct BindStruct *X,//!<[inout] + int site_i, + int spin_i, + int site_j, + int spin_j, + double complex *tmp_v0,//!<[inout] Result vector + double complex *tmp_v1//!<[in] Input producted vector +); + int mltplySpinGC(struct BindStruct *X, double complex *tmp_v0,double complex *tmp_v1); int mltplyHalfSpinGC(struct BindStruct *X, double complex *tmp_v0,double complex *tmp_v1); diff --git a/src/mltplySpin.c b/src/mltplySpin.c index e8b52e106..d5442c164 100644 --- a/src/mltplySpin.c +++ b/src/mltplySpin.c @@ -408,6 +408,93 @@ int mltplySpinGC( return iret; }/*int mltplySpinGC*/ + +/** +@brief Driver function for General Spin Hamiltonian (grandcanonical) +@return error code +@author Takahiro Misawa (The University of Tokyo) +*/ +void mltplyGeneralSpinGC_mini( + struct BindStruct *X,//!<[inout] + int site_i, + int spin_i, + int site_j, + int spin_j, + double complex *tmp_v0,//!<[inout] Result vector + double complex *tmp_v1//!<[in] Input producted vector +) { + long unsigned int j; + long unsigned int i; + long unsigned int off = 0; + long unsigned int tmp_off = 0; + long unsigned int isite1, isite2, sigma1, sigma2; + long unsigned int sigma3, sigma4; + double complex dam_pr; + double complex tmp_trans; + long int tmp_sgn; + double num1 = 0; + /*[s] For InterAll */ + double complex tmp_V; + double complex dmv=0; + /*[e] For InterAll */ + + long unsigned int i_max; + i_max = X->Check.idim_max; + + int ihermite=0; + int idx=0; + + StartTimer(510); + //for (i = 0; i < X->Def.EDNTransfer; i += 2) { + isite1 = site_i + 1; + isite2 = site_j + 1; + sigma1 = spin_i; + sigma2 = spin_j; + tmp_trans = 1.0; + dam_pr = 0.0; + if (isite1 == isite2) { + if (sigma1 != sigma2) { + if (isite1 > X->Def.Nsite) { + dam_pr = child_GC_CisAit_GeneralSpin_MPIdouble(isite1 - 1, sigma1, sigma2, tmp_trans, X, tmp_v0, tmp_v1); + //X->Large.prdct += dam_pr; + }/*if (isite1 > X->Def.Nsite)*/ + else { + //for (ihermite = 0; ihermite<2; ihermite++) { + idx = i + ihermite; + + isite1 = site_i + 1; + isite2 = site_j + 1; + sigma1 = spin_i; + sigma2 = spin_j; + tmp_trans = 1.0; + // transverse magnetic field + //dam_pr = 0.0; + #pragma omp parallel for default(none) reduction(+:dam_pr) \ + private(j, tmp_sgn, num1) firstprivate(i_max, isite1, sigma1, sigma2, X, off, tmp_trans) \ + shared(tmp_v0, tmp_v1) + for (j = 1; j <= i_max; j++) { + num1 = GetOffCompGeneralSpin(j - 1, isite1, sigma2, sigma1, &off, X->Def.SiteToBit, X->Def.Tpow); + if (num1 != 0) { // for multply + tmp_v0[off + 1] += tmp_v1[j] * tmp_trans; + //dam_pr += conj(tmp_v1[off + 1]) * tmp_v1[j] * tmp_trans; + }/*if (num1 != 0)*/ + }/*for (j = 1; j <= i_max; j++)*/ + //X->Large.prdct += dam_pr; + //}/*for (ihermite = 0; ihermite<2; ihermite++)*/ + } + }// sigma1 != sigma2 + else{ // sigma1 = sigma2 + fprintf(stderr, "Error: Transverse_Diagonal component must be absorbed !"); + } + }//isite1 = isite2 + //else { // isite1 != isite2 + // hopping is not allowed in localized spin system + // return -1; + //} + //}/*for (i = 0; i < X->Def.EDNTransfer; i += 2)*/ + StopTimer(510); +} + /** @brief Driver function for Spin 1/2 Hamiltonian (grandcanonical) @return error code From ee290919c5c77f88c122f8639b3a55707ca3cfb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E6=BE=A4=E8=B2=B4=E5=AE=8F?= Date: Mon, 13 May 2024 12:19:52 +0900 Subject: [PATCH 2/7] fixed bugs --- src/expec_cisajscktaltdc.c | 167 ++++++++++++++++++++----------------- src/mltplySpin.c | 13 ++- 2 files changed, 103 insertions(+), 77 deletions(-) diff --git a/src/expec_cisajscktaltdc.c b/src/expec_cisajscktaltdc.c index 4cf310eb8..5cfee0924 100644 --- a/src/expec_cisajscktaltdc.c +++ b/src/expec_cisajscktaltdc.c @@ -782,7 +782,7 @@ int expec_cisajscktalt_SpinHalf(struct BindStruct *X,double complex *vec, FILE * * */ -int expec_ThreeBody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE **_fp){ +int expec_Threebody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE **_fp){ long unsigned int i,j; long unsigned int org_isite1,org_isite2,org_isite3,org_isite4,org_isite5,org_isite6; long unsigned int org_sigma1,org_sigma2,org_sigma3,org_sigma4,org_sigma5,org_sigma6; @@ -804,20 +804,26 @@ int expec_ThreeBody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE * for(i=0;iDef.NTBody;i++){ vec_pr = cd_1d_allocate(i_max + 1); - tmp_org_isite1 = X->Def.CisAjtCkuAlvDC[i][0]+1; - tmp_org_sigma1 = X->Def.CisAjtCkuAlvDC[i][1]; - tmp_org_isite2 = X->Def.CisAjtCkuAlvDC[i][2]+1; - tmp_org_sigma2 = X->Def.CisAjtCkuAlvDC[i][3]; - tmp_org_isite3 = X->Def.CisAjtCkuAlvDC[i][4]+1; - tmp_org_sigma3 = X->Def.CisAjtCkuAlvDC[i][5]; - tmp_org_isite4 = X->Def.CisAjtCkuAlvDC[i][6]+1; - tmp_org_sigma4 = X->Def.CisAjtCkuAlvDC[i][7]; + tmp_org_isite1 = X->Def.TBody[i][0]+1; + tmp_org_sigma1 = X->Def.TBody[i][1]; + tmp_org_isite2 = X->Def.TBody[i][2]+1; + tmp_org_sigma2 = X->Def.TBody[i][3]; + tmp_org_isite3 = X->Def.TBody[i][4]+1; + tmp_org_sigma3 = X->Def.TBody[i][5]; + tmp_org_isite4 = X->Def.TBody[i][6]+1; + tmp_org_sigma4 = X->Def.TBody[i][7]; /*[s]For three body*/ - org_isite5 = X->Def.TBody[i][8]+1; - org_sigma5 = X->Def.TBody[i][9]; - org_isite6 = X->Def.TBody[i][10]+1; - org_sigma6 = X->Def.TBody[i][11]; + tmp_org_isite5 = X->Def.TBody[i][8]+1; + tmp_org_sigma5 = X->Def.TBody[i][9]; + tmp_org_isite6 = X->Def.TBody[i][10]+1; + tmp_org_sigma6 = X->Def.TBody[i][11]; + /**/ + org_isite5 = X->Def.TBody[i][8]+1; + org_sigma5 = X->Def.TBody[i][9]; + org_isite6 = X->Def.TBody[i][10]+1; + org_sigma6 = X->Def.TBody[i][11]; + dam_pr = 0.0; X->Large.mode = M_MLTPLY; /* |vec_pr>= c5a6|phi>*/ @@ -825,86 +831,95 @@ int expec_ThreeBody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE * X->Large.mode = M_CORR; /*[e]For three body*/ - if(Rearray_Interactions(i, &org_isite1, &org_isite2, &org_isite3, &org_isite4, &org_sigma1, &org_sigma2, &org_sigma3, &org_sigma4, &tmp_V, X,2)!=0){ + if(Rearray_Interactions(i, &org_isite1, &org_isite2, &org_isite3, &org_isite4, &org_sigma1, &org_sigma2, &org_sigma3, &org_sigma4, &tmp_V, X,3)!=0){ fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); continue; } - tmp_Sz=0; - - for(j=0;j<2; j++) { - tmp_org = X->Def.CisAjtCkuAlvDC[i][4*j+1]*X->Def.Tpow[X->Def.CisAjtCkuAlvDC[i][4 * j]]; - tmp_Sz += GetLocal2Sz(X->Def.CisAjtCkuAlvDC[i][4 * j] + 1, tmp_org, X->Def.SiteToBit, X->Def.Tpow); - tmp_org = X->Def.CisAjtCkuAlvDC[i][4*j+3]*X->Def.Tpow[X->Def.CisAjtCkuAlvDC[i][4 * j+2]]; - tmp_Sz -= GetLocal2Sz(X->Def.CisAjtCkuAlvDC[i][4 * j+2] + 1, tmp_org, X->Def.SiteToBit, X->Def.Tpow); - } - if(tmp_Sz !=0){ // not Sz conserved - fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); - continue; - } - - dam_pr = 0.0; - if(org_isite1 >X->Def.Nsite && org_isite3>X->Def.Nsite){ + if(org_isite1 > X->Def.Nsite && org_isite3 > X->Def.Nsite){ if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal - dam_pr=child_CisAisCjuAju_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec); + dam_pr=child_GC_CisAisCjuAju_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec_pr); } - else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ - dam_pr=child_CisAitCjuAjv_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec); + else if(org_sigma1 == org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_GC_CisAisCjuAjv_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, org_sigma4, tmp_V, X, vec, vec_pr); } - else{ - dam_pr=0.0; + else if(org_sigma1 != org_sigma2 && org_sigma3 == org_sigma4){ + dam_pr=child_GC_CisAitCjuAju_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, tmp_V, X, vec, vec_pr); + } + else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_GC_CisAitCjuAjv_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec_pr); } } else if(org_isite3 > X->Def.Nsite || org_isite1 > X->Def.Nsite){ if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal - dam_pr=child_CisAisCjuAju_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec); + dam_pr=child_GC_CisAisCjuAju_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec_pr); } - else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ - dam_pr=child_CisAitCjuAjv_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec); + else if(org_sigma1 == org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_GC_CisAisCjuAjv_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, org_sigma4, tmp_V, X, vec, vec_pr); } - else{ - dam_pr=0.0; + else if(org_sigma1 != org_sigma2 && org_sigma3 == org_sigma4){ + dam_pr=child_GC_CisAitCjuAju_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, tmp_V, X, vec, vec_pr); + } + else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ + dam_pr=child_GC_CisAitCjuAjv_GeneralSpin_MPIsingle(org_isite1-1, org_sigma1, org_sigma2, org_isite3-1, org_sigma3, org_sigma4,tmp_V, X, vec, vec_pr); } } else{ if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X,org_isite1, org_sigma1,org_isite3, org_sigma3, tmp_V) shared(vec,list_1) + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X,org_isite1, org_sigma1,org_isite3, org_sigma3, tmp_V) shared(vec,vec_pr) for(j=1;j<=i_max;j++){ - num1=BitCheckGeneral(list_1[j], org_isite1, org_sigma1, X->Def.SiteToBit, X->Def.Tpow); + num1=BitCheckGeneral(j-1, org_isite1, org_sigma1, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ - num1=BitCheckGeneral(list_1[j], org_isite3, org_sigma3, X->Def.SiteToBit, X->Def.Tpow); + num1=BitCheckGeneral(j-1, org_isite3, org_sigma3, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ - dam_pr += tmp_V*conj(vec[j])*vec[j]; + dam_pr += tmp_V*conj(vec[j])*vec_pr[j]; } } } - } - else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1, org_sigma2, org_sigma3, org_sigma4, tmp_off, tmp_off_2, list1_off, myrank, tmp_V) shared(vec, list_1) + }else if(org_sigma1 == org_sigma2 && org_sigma3 != org_sigma4){ + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma3,org_sigma4, tmp_off, tmp_V) shared(vec,vec_pr) for(j=1;j<=i_max;j++){ - num1 = GetOffCompGeneralSpin(list_1[j], org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); - if(num1 != FALSE) { - num1 = GetOffCompGeneralSpin(tmp_off, org_isite1, org_sigma2, org_sigma1, &tmp_off_2, - X->Def.SiteToBit, X->Def.Tpow); - if (num1 != FALSE) { - ConvertToList1GeneralSpin(tmp_off_2, X->Check.sdim, &list1_off); - dam_pr += tmp_V * conj(vec[list1_off]) * vec[j]; + num1 = GetOffCompGeneralSpin(j-1, org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + num1=BitCheckGeneral(tmp_off, org_isite1, org_sigma1, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + dam_pr += tmp_V*conj(vec[tmp_off+1])*vec_pr[j]; + } } - } } - //printf("DEBUG: rank=%d, dam_pr=%lf\n", myrank, creal(dam_pr)); - } - else{ - dam_pr=0.0; + }else if(org_sigma1 != org_sigma2 && org_sigma3 == org_sigma4){ + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma2, org_sigma3, tmp_off, tmp_V) shared(vec,vec_pr) + for(j=1;j<=i_max;j++){ + num1 = BitCheckGeneral(j-1, org_isite3, org_sigma3, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + num1 = GetOffCompGeneralSpin(j-1, org_isite1, org_sigma2, org_sigma1, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + dam_pr += tmp_V*conj(vec[tmp_off+1])*vec_pr[j]; + } + } + } + }else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1, org_sigma2, org_sigma3, org_sigma4, tmp_off, tmp_off_2, tmp_V) shared(vec,vec_pr) + for(j=1;j<=i_max;j++){ + num1 = GetOffCompGeneralSpin(j-1, org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + num1 = GetOffCompGeneralSpin(tmp_off, org_isite1, org_sigma2, org_sigma1, &tmp_off_2, X->Def.SiteToBit, X->Def.Tpow); + if(num1 != FALSE){ + dam_pr += tmp_V*conj(vec[tmp_off_2+1])*vec_pr[j]; + } + } + + } } } dam_pr = SumMPI_dc(dam_pr); - //fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1, tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4, creal(dam_pr),cimag(dam_pr)); - fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n", + fprintf(*_fp, " %4ld %4ld %4ld %4ld " + " %4ld %4ld %4ld %4ld " + " %4ld %4ld %4ld %4ld " + " %.10lf %.10lf \n", tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, - tmp_org_isite3-1, tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4, - tmp_org_isite5-1, tmp_org_sigma5, tmp_org_isite6-1, tmp_org_sigma6, + tmp_org_isite3-1, tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4, + tmp_org_isite5-1, tmp_org_sigma5, tmp_org_isite6-1, tmp_org_sigma6, creal(dam_pr),cimag(dam_pr)); - free_cd_1d_allocate(vec_pr); } return 0; } @@ -1246,6 +1261,9 @@ int expec_cisajscktalt_SpinGC(struct BindStruct *X,double complex *vec, FILE **_ } } else { info=expec_cisajscktalt_SpinGCGeneral(X,vec, _fp); + if(X->Def.NTBody>0){ + info = expec_Threebody_SpinGeneral(X,vec,_fp_2); + } } return info; } @@ -1688,8 +1706,7 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F i_max=X->Check.idim_max; X->Large.mode=M_CORR; - - for(i=0;iDef.NCisAjtCkuAlvDC;i++){ + for(i=0;iDef.NCisAjtCkuAlvDC;i++){ tmp_org_isite1 = X->Def.CisAjtCkuAlvDC[i][0]+1; tmp_org_sigma1 = X->Def.CisAjtCkuAlvDC[i][1]; tmp_org_isite2 = X->Def.CisAjtCkuAlvDC[i][2]+1; @@ -1700,13 +1717,13 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F tmp_org_sigma4 = X->Def.CisAjtCkuAlvDC[i][7]; dam_pr = 0.0; - if(Rearray_Interactions(i, &org_isite1, &org_isite2, &org_isite3, &org_isite4, &org_sigma1, &org_sigma2, &org_sigma3, &org_sigma4, &tmp_V, X,2)!=0){ - //error message will be added - fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); - continue; - } + if(Rearray_Interactions(i, &org_isite1, &org_isite2, &org_isite3, &org_isite4, &org_sigma1, &org_sigma2, &org_sigma3, &org_sigma4, &tmp_V, X,2)!=0){ + //error message will be added + fprintf(*_fp," %4ld %4ld %4ld %4ld %4ld %4ld %4ld %4ld %.10lf %.10lf \n",tmp_org_isite1-1, tmp_org_sigma1, tmp_org_isite2-1, tmp_org_sigma2, tmp_org_isite3-1,tmp_org_sigma3, tmp_org_isite4-1, tmp_org_sigma4,0.0,0.0); + continue; + } - if(org_isite1 > X->Def.Nsite && org_isite3 > X->Def.Nsite){ + if(org_isite1 > X->Def.Nsite && org_isite3 > X->Def.Nsite){ if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal dam_pr=child_GC_CisAisCjuAju_GeneralSpin_MPIdouble(org_isite1-1, org_sigma1, org_isite3-1, org_sigma3, tmp_V, X, vec, vec); } @@ -1736,7 +1753,7 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F } else{ if(org_sigma1==org_sigma2 && org_sigma3==org_sigma4 ){ //diagonal -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X,org_isite1, org_sigma1,org_isite3, org_sigma3, tmp_V) shared(vec) + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X,org_isite1, org_sigma1,org_isite3, org_sigma3, tmp_V) shared(vec) for(j=1;j<=i_max;j++){ num1=BitCheckGeneral(j-1, org_isite1, org_sigma1, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ @@ -1747,7 +1764,7 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F } } }else if(org_sigma1 == org_sigma2 && org_sigma3 != org_sigma4){ -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma3,org_sigma4, tmp_off, tmp_V) shared(vec) + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma3,org_sigma4, tmp_off, tmp_V) shared(vec) for(j=1;j<=i_max;j++){ num1 = GetOffCompGeneralSpin(j-1, org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ @@ -1758,7 +1775,7 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F } } }else if(org_sigma1 != org_sigma2 && org_sigma3 == org_sigma4){ -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma2, org_sigma3, tmp_off, tmp_V) shared(vec) + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1,org_sigma2, org_sigma3, tmp_off, tmp_V) shared(vec) for(j=1;j<=i_max;j++){ num1 = BitCheckGeneral(j-1, org_isite3, org_sigma3, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ @@ -1769,7 +1786,7 @@ int expec_cisajscktalt_SpinGCGeneral(struct BindStruct *X,double complex *vec, F } } }else if(org_sigma1 != org_sigma2 && org_sigma3 != org_sigma4){ -#pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1, org_sigma2, org_sigma3, org_sigma4, tmp_off, tmp_off_2, tmp_V) shared(vec) + #pragma omp parallel for default(none) reduction(+:dam_pr) private(j, num1) firstprivate(i_max,X, org_isite1, org_isite3, org_sigma1, org_sigma2, org_sigma3, org_sigma4, tmp_off, tmp_off_2, tmp_V) shared(vec) for(j=1;j<=i_max;j++){ num1 = GetOffCompGeneralSpin(j-1, org_isite3, org_sigma4, org_sigma3, &tmp_off, X->Def.SiteToBit, X->Def.Tpow); if(num1 != FALSE){ diff --git a/src/mltplySpin.c b/src/mltplySpin.c index d5442c164..65f018f86 100644 --- a/src/mltplySpin.c +++ b/src/mltplySpin.c @@ -466,7 +466,6 @@ void mltplyGeneralSpinGC_mini( isite2 = site_j + 1; sigma1 = spin_i; sigma2 = spin_j; - tmp_trans = 1.0; // transverse magnetic field //dam_pr = 0.0; #pragma omp parallel for default(none) reduction(+:dam_pr) \ @@ -484,7 +483,17 @@ void mltplyGeneralSpinGC_mini( } }// sigma1 != sigma2 else{ // sigma1 = sigma2 - fprintf(stderr, "Error: Transverse_Diagonal component must be absorbed !"); + if (isite1 > X->Def.Nsite) { + dam_pr = child_GC_CisAis_GeneralSpin_MPIdouble(isite1 - 1, sigma1, tmp_trans, X, tmp_v0, tmp_v1); + }else{ + // longitudinal magnetic field + #pragma omp parallel for default(none) private(j, num1) firstprivate(i_max, isite1, sigma1, X, tmp_trans) shared(tmp_v0, tmp_v1) + for (j = 1; j <= i_max; j++) { + num1 = BitCheckGeneral(j - 1, isite1, sigma1, X->Def.SiteToBit, X->Def.Tpow); + tmp_v0[j] += tmp_trans * tmp_v1[j] * num1; + } + } + //fprintf(stderr, "Error: Transverse_Diagonal component must be absorbed !"); } }//isite1 = isite2 //else { // isite1 != isite2 From efa6fcef9382eb905423a68bece434e9e567be73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E6=BE=A4=E8=B2=B4=E5=AE=8F?= Date: Wed, 15 May 2024 13:50:28 +0900 Subject: [PATCH 3/7] add test for three-body Green func. --- test/CMakeLists.txt | 10 ++ test/GenSpinThreeBody.py | 204 ++++++++++++++++++++++++++ test/lobcg_genspin_chain_threebody.sh | 22 +++ 3 files changed, 236 insertions(+) create mode 100644 test/GenSpinThreeBody.py create mode 100755 test/lobcg_genspin_chain_threebody.sh diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ccf5bcaed..940afe5af 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -258,4 +258,14 @@ add_test( COMMAND ${CMAKE_SOURCE_DIR}/test/ctpq_spin_kagome_randomsphere.sh ${CMAKE_SOURCE_DIR} ) +# +#three body for spin 1 Heisenberg chain +# +add_test( + NAME lobcg_genspin_chain_threebody + COMMAND ${CMAKE_SOURCE_DIR}/test/lobcg_genspin_chain_threebody.sh ${CMAKE_SOURCE_DIR} +) + + + diff --git a/test/GenSpinThreeBody.py b/test/GenSpinThreeBody.py new file mode 100644 index 000000000..7329f0b6f --- /dev/null +++ b/test/GenSpinThreeBody.py @@ -0,0 +1,204 @@ +import math +import sys +import numpy as np + +def main(): + #[s] set param. + mag_J = 1.0 + mag_h = 1.0 + size = 6 + + if sys.argv[1] == "generate": + func_generate(size, mag_J, mag_h) + elif sys.argv[1] == "aft": + func_aft(size, mag_J, mag_h) + +def func_aft(size,mag_J,mag_h): + #[s] ene + file_path = 'output/zvo_energy.dat' + with open(file_path, 'r') as file: + for line in file: + if 'Energy' in line: + parts = line.split() + ene = float(parts[-1]) # last component + #[e] ene + #[s] green1.def + file_name = "output/zvo_cisajs_eigen0.dat" + data = np.loadtxt(file_name) + m_x = (data[0][4]+data[1][4]+data[2][4]+data[3][4])/math.sqrt(2.0) + m_y = (data[4][5]-data[5][5]+data[6][5]-data[7][5])/math.sqrt(2.0) + m_z = (data[8][4]-data[9][4]) + print(m_x,m_y,m_z) + #[e] green1.def + #[s] green3.def + file_name = "output/zvo_ThreeBody_eigen0.dat" + data = np.loadtxt(file_name) + def calculate_sum(data): + total_1 = 0.0 + total_2 = 0.0 + for row in data: + sign = 1 + if tuple(row[4:8]) in [(1, 0, 1, 1), (1, 1, 1, 2)]: + sign *= -1 + if tuple(row[8:12]) == (2, 2, 2, 2): + sign *= -1 + + total_1 += sign * (row[12]) + total_2 += sign * (row[13]) + + return total_1,total_2 + + r1,r2 = calculate_sum(data) + result = (1j/2.0)*(r1+1j*r2) + #print("SxSySz:", result.real,result.imag) + #[e] green3.def + with open("result_hphi_size%d.dat"%(size), 'w') as file: + file.write(" %.12f\n" %(mag_h) ) + file.write(" %.12f\n" %(ene) ) + file.write(" %.12f\n" %(m_x) ) + file.write(" %.12f\n" %(m_y) ) + file.write(" %.12f\n" %(m_z) ) + file.write(" %.12f\n" %(result.real) ) + +def func_generate(size, mag_J, mag_h): + file_mag = "mag.def" + file_green1 = "green1.def" + file_green3 = "green3.def" + file_interall = "open_interall.def" + file_name = "open_namelist.def" + #[s] green1.def + num_green1 = 4+4+2 + with open(file_green1, 'w') as file: + # ヘッダーの書き込み + file.write("=====\n") + file.write(f"NumGreen {num_green1}\n") + file.write("=====\n") + file.write("=====\n") + file.write("=====\n") + for site in range(size): + if site == 0: # Sx + file.write(f"{site} 0 {site} 1 \n") + file.write(f"{site} 1 {site} 0 \n") + file.write(f"{site} 1 {site} 2 \n") + file.write(f"{site} 2 {site} 1 \n") + elif site == 1: #Sy + file.write(f"{site} 0 {site} 1 \n") + file.write(f"{site} 1 {site} 0 \n") + file.write(f"{site} 1 {site} 2 \n") + file.write(f"{site} 2 {site} 1 \n") + elif site == 2: #Sz + file.write(f"{site} 0 {site} 0 \n") + file.write(f"{site} 2 {site} 2 \n") + #[e] green1.def + + #[s] green3.def + indices = { + 'i': 0, + 'j': 1, + 'k': 2 + } + s_values = [(0, 1), (1, 2), (1, 0), (2, 1)] + t_values = [(0, 1), (1, 2), (1, 0), (2, 1)] + u_values = [(0, 0), (2, 2)] + combinations = generate_combinations(s_values, t_values, u_values, indices) + with open(file_green3, 'w') as file: + file.write("=====\n") + file.write(f"NumGreen {len(combinations)}\n") + file.write("=====\n") + file.write("=====\n") + file.write("=====\n") + for comb in combinations: + file.write(comb + '\n') + #[e] green3.def + #[s] mag.def + num_mag = 2*int(size/3)+4*2*int(size/3) + with open(file_mag, 'w') as file: + # ヘッダーの書き込み + file.write("=====\n") + file.write(f"NumMag {num_mag} \n") + file.write("=====\n") + file.write("=====\n") + file.write("=====\n") + + for site in range(size): + if site%3 == 0: # Sx + file.write(f"{site} 0 {site} 1 {-mag_h/math.sqrt(2.0)} 0.0\n") + file.write(f"{site} 1 {site} 0 {-mag_h/math.sqrt(2.0)} 0.0\n") + file.write(f"{site} 1 {site} 2 {-mag_h/math.sqrt(2.0)} 0.0\n") + file.write(f"{site} 2 {site} 1 {-mag_h/math.sqrt(2.0)} 0.0\n") + elif site%3 == 1: + file.write(f"{site} 0 {site} 1 0.0 {mag_h/math.sqrt(2.0)}\n") + file.write(f"{site} 1 {site} 0 0.0 {-mag_h/math.sqrt(2.0)}\n") + file.write(f"{site} 1 {site} 2 0.0 {mag_h/math.sqrt(2.0)}\n") + file.write(f"{site} 2 {site} 1 0.0 {-mag_h/math.sqrt(2.0)}\n") + elif site%3 == 2: + file.write(f"{site} 0 {site} 0 {-mag_h} 0.0\n") + file.write(f"{site} 2 {site} 2 {mag_h} 0.0\n") + #[e] mag.def + #[s] open_interall.def + num_J = (4+4+4)*(size-1) # size-1 = open boundary condition + with open(file_interall, 'w') as file: + file.write("=====\n") + file.write(f"NumJ {num_J} \n") + file.write("=====\n") + file.write("=====\n") + file.write("=====\n") + for site in range(size-1): + #[s] S+*S- & S-*S+ + file.write(f"{site} 0 {site} 1 {site+1} 1 {site+1} 0 {mag_J} 0.0\n") + file.write(f"{site+1} 0 {site+1} 1 {site} 1 {site} 0 {mag_J} 0.0\n") + file.write(f"{site} 0 {site} 1 {site+1} 2 {site+1} 1 {mag_J} 0.0\n") + file.write(f"{site+1} 1 {site+1} 2 {site} 1 {site} 0 {mag_J} 0.0\n") + file.write(f"{site} 1 {site} 2 {site+1} 1 {site+1} 0 {mag_J} 0.0\n") + file.write(f"{site+1} 0 {site+1} 1 {site} 2 {site} 1 {mag_J} 0.0\n") + file.write(f"{site} 1 {site} 2 {site+1} 2 {site+1} 1 {mag_J} 0.0\n") + file.write(f"{site+1} 1 {site+1} 2 {site} 2 {site} 1 {mag_J} 0.0\n") + #[e] S+*S- & S-*S+ + #[s] Sz*Sz + file.write(f"{site} 0 {site} 0 {site+1} 0 {site+1} 0 {mag_J} 0.0\n") + file.write(f"{site} 2 {site} 2 {site+1} 0 {site+1} 0 {-mag_J} 0.0\n") + file.write(f"{site} 0 {site} 0 {site+1} 2 {site+1} 2 {-mag_J} 0.0\n") + file.write(f"{site} 2 {site} 2 {site+1} 2 {site+1} 2 {mag_J} 0.0\n") + #[e] Sz*Sz + #[e] open_interall.def + content = f"""\ + ModPara modpara.def + LocSpin locspn.def + Trans {file_mag} + InterAll {file_interall} + OneBodyG {file_green1} + TwoBodyG greentwo.def + ThreeBodyG {file_green3} + CalcMod calcmod.def + PairExcitation pair.def + SpectrumVec zvo_eigenvec_0 +""" + with open(file_name, 'w') as file: + file.write(content) + + stan = f"""\ + L={size} + model = "SpinGC" + method = "CG" + lattice = "chain" + J = {mag_J} + 2S = 2 + H = {mag_h} +""" + with open("stan.in", 'w') as file: + file.write(stan) + + +def generate_combinations(s_values, t_values, u_values, indices): + combinations = [] + for s in s_values: + for t in t_values: + for u in u_values: + # 文字列フォーマットで組み合わせを生成 + combination = f"{indices['i']} {s[0]} {indices['i']} {s[1]} {indices['j']} {t[0]} {indices['j']} {t[1]} {indices['k']} {u[0]} {indices['k']} {u[1]}" + combinations.append(combination) + return combinations + + +if __name__ == "__main__": + main() diff --git a/test/lobcg_genspin_chain_threebody.sh b/test/lobcg_genspin_chain_threebody.sh new file mode 100755 index 000000000..690305771 --- /dev/null +++ b/test/lobcg_genspin_chain_threebody.sh @@ -0,0 +1,22 @@ +#!/bin/sh -e + +mkdir -p lobcg_genspin_chain_threebody/ +cp $1/test/GenSpinThreeBody.py ./lobcg_genspin_chain_threebody +cd ./lobcg_genspin_chain_threebody + python3 GenSpinThreeBody.py generate + ../../src/HPhi -sdry stan.in + ${MPIRUN} ../../src/HPhi -e open_namelist.def + python3 GenSpinThreeBody.py aft + +cat > reference.dat < paste.dat +diff=`awk 'BEGIN{diff=0.0} {diff+=sqrt(($1-$2)*($1-$2))} END{printf "%8.6f", diff}' paste.dat` +test "${diff}" = "0.000000" +exit $? From a78384081e65ab7c182d80a0ae30d6c07c71e3e1 Mon Sep 17 00:00:00 2001 From: Yuichi Motoyama Date: Wed, 15 May 2024 14:09:02 +0900 Subject: [PATCH 4/7] disable mpitest for threebody (because only this is S=1 while others are S=3/2) --- test/lobcg_genspin_chain_threebody.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lobcg_genspin_chain_threebody.sh b/test/lobcg_genspin_chain_threebody.sh index 690305771..ec0c2d93f 100755 --- a/test/lobcg_genspin_chain_threebody.sh +++ b/test/lobcg_genspin_chain_threebody.sh @@ -5,7 +5,8 @@ cp $1/test/GenSpinThreeBody.py ./lobcg_genspin_chain_threebody cd ./lobcg_genspin_chain_threebody python3 GenSpinThreeBody.py generate ../../src/HPhi -sdry stan.in - ${MPIRUN} ../../src/HPhi -e open_namelist.def + # ${MPIRUN} ../../src/HPhi -e open_namelist.def + ../../src/HPhi -e open_namelist.def python3 GenSpinThreeBody.py aft cat > reference.dat < Date: Wed, 15 May 2024 14:56:34 +0900 Subject: [PATCH 5/7] made ctest_spinone --- .github/workflows/main.yml | 77 ++++++++++++++++++- test/CMakeLists.txt | 4 +- ...enSpinThreeBody.py => SpinOneThreeBody.py} | 0 ...dy.sh => lobcg_spinone_chain_threebody.sh} | 14 ++-- 4 files changed, 85 insertions(+), 10 deletions(-) rename test/{GenSpinThreeBody.py => SpinOneThreeBody.py} (100%) rename test/{lobcg_genspin_chain_threebody.sh => lobcg_spinone_chain_threebody.sh} (56%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 27edaeccb..b4df90165 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,4 +75,79 @@ jobs: - name: ctest working-directory: ${{runner.workspace}}/build shell: bash - run: ctest -V + run: ctest -V -E spinone + + ctest_spinone: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-22.04] + mpisize: [1, 3, 9] + ompsize: [1, 3] + include: + - os: macos-13 + mpisize: 1 + ompsize: 1 + - os: macos-latest + mpisize: 1 + ompsize: 1 + - os: ubuntu-20.04 + mpisize: 1 + ompsize: 1 + exclude: + - mpisize: 9 + ompsize: 3 + - mpisize: 3 + ompsize: 3 + fail-fast: false + + env: + MPIRUN: "mpiexec --oversubscribe -np ${{ matrix.mpisize }}" + OMP_NUM_THREADS: ${{ matrix.ompsize }} + + steps: + - uses: actions/checkout@v4 + + - name: apt + if: ${{ runner.os == 'Linux' }} + run: | + sudo apt update + sudo apt install liblapack-dev openmpi-bin libopenmpi-dev libscalapack-openmpi-dev + + - name: brew + if: ${{ runner.os == 'macOS' }} + run: | + brew install openmpi scalapack + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: pip + run: | + python3 -m pip install numpy + + - name: make workspace + run: cmake -E make_directory ${{runner.workspace}}/build + + - name: cmake + working-directory: ${{runner.workspace}}/build + shell: bash + run: | + if [ ${{ runner.os }} = "macOS" ] ; then + export FC=gfortran-12 + fi + cmake -DCMAKE_VERBOSE_MAKEFILE=ON $GITHUB_WORKSPACE + + - name: build + working-directory: ${{runner.workspace}}/build + shell: bash + run: cmake --build ./ -j4 + + - name: ctest + working-directory: ${{runner.workspace}}/build + shell: bash + run: ctest -V -R spinone + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 940afe5af..31996ddff 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -262,8 +262,8 @@ add_test( #three body for spin 1 Heisenberg chain # add_test( - NAME lobcg_genspin_chain_threebody - COMMAND ${CMAKE_SOURCE_DIR}/test/lobcg_genspin_chain_threebody.sh ${CMAKE_SOURCE_DIR} + NAME lobcg_spinone_chain_threebody + COMMAND ${CMAKE_SOURCE_DIR}/test/lobcg_spinone_chain_threebody.sh ${CMAKE_SOURCE_DIR} ) diff --git a/test/GenSpinThreeBody.py b/test/SpinOneThreeBody.py similarity index 100% rename from test/GenSpinThreeBody.py rename to test/SpinOneThreeBody.py diff --git a/test/lobcg_genspin_chain_threebody.sh b/test/lobcg_spinone_chain_threebody.sh similarity index 56% rename from test/lobcg_genspin_chain_threebody.sh rename to test/lobcg_spinone_chain_threebody.sh index ec0c2d93f..1feca1afd 100755 --- a/test/lobcg_genspin_chain_threebody.sh +++ b/test/lobcg_spinone_chain_threebody.sh @@ -1,13 +1,13 @@ #!/bin/sh -e -mkdir -p lobcg_genspin_chain_threebody/ -cp $1/test/GenSpinThreeBody.py ./lobcg_genspin_chain_threebody -cd ./lobcg_genspin_chain_threebody - python3 GenSpinThreeBody.py generate +mkdir -p lobcg_spinone_chain_threebody/ +cp $1/test/SpinOneThreeBody.py ./lobcg_spinone_chain_threebody +cd ./lobcg_spinone_chain_threebody + python3 SpinOneThreeBody.py generate ../../src/HPhi -sdry stan.in - # ${MPIRUN} ../../src/HPhi -e open_namelist.def - ../../src/HPhi -e open_namelist.def - python3 GenSpinThreeBody.py aft + ${MPIRUN} ../../src/HPhi -e open_namelist.def + #../../src/HPhi -e open_namelist.def + python3 SpinOneThreeBody.py aft cat > reference.dat < Date: Wed, 15 May 2024 16:57:30 +0900 Subject: [PATCH 6/7] fixed bug in magneticfield in general spin --- src/mltplySpin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mltplySpin.c b/src/mltplySpin.c index 65f018f86..c796df2a5 100644 --- a/src/mltplySpin.c +++ b/src/mltplySpin.c @@ -836,7 +836,7 @@ int mltplyGeneralSpinGC( isite2 = X->Def.EDGeneralTransfer[i][2] + 1; sigma1 = X->Def.EDGeneralTransfer[i][1]; sigma2 = X->Def.EDGeneralTransfer[i][3]; - tmp_trans = -X->Def.EDParaGeneralTransfer[idx]; + tmp_trans = -X->Def.EDParaGeneralTransfer[i]; dam_pr = 0.0; if (isite1 == isite2) { if (sigma1 != sigma2) { From 007849b04fc5d3192ad4ce263145b3d5a4442c99 Mon Sep 17 00:00:00 2001 From: tmisawa Date: Thu, 23 May 2024 16:56:00 +0900 Subject: [PATCH 7/7] mod free --- src/expec_cisajscktaltdc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/expec_cisajscktaltdc.c b/src/expec_cisajscktaltdc.c index 5cfee0924..78b76c692 100644 --- a/src/expec_cisajscktaltdc.c +++ b/src/expec_cisajscktaltdc.c @@ -802,8 +802,8 @@ int expec_Threebody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE * i_max=X->Check.idim_max; X->Large.mode=M_CORR; + vec_pr = cd_1d_allocate(i_max + 1); for(i=0;iDef.NTBody;i++){ - vec_pr = cd_1d_allocate(i_max + 1); tmp_org_isite1 = X->Def.TBody[i][0]+1; tmp_org_sigma1 = X->Def.TBody[i][1]; tmp_org_isite2 = X->Def.TBody[i][2]+1; @@ -825,6 +825,12 @@ int expec_Threebody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE * org_sigma6 = X->Def.TBody[i][11]; dam_pr = 0.0; + /*[s]initialized vec_pr*/ + #pragma omp parallel for default(none) private(j) firstprivate(i_max) shared(vec_pr) + for(j=1;j<=i_max;j++){ + vec_pr[j] = 0.0+0.0*I; + } + /*[e]initialized vec_pr*/ X->Large.mode = M_MLTPLY; /* |vec_pr>= c5a6|phi>*/ mltplyGeneralSpinGC_mini(X,tmp_org_isite5-1,tmp_org_sigma5,tmp_org_isite6-1,tmp_org_sigma6,vec_pr,vec); @@ -921,6 +927,7 @@ int expec_Threebody_SpinGeneral(struct BindStruct *X,double complex *vec, FILE * tmp_org_isite5-1, tmp_org_sigma5, tmp_org_isite6-1, tmp_org_sigma6, creal(dam_pr),cimag(dam_pr)); } + free_cd_1d_allocate(vec_pr); return 0; }