16 #include "PowerLanczos.h" 18 #include "wrapperMPI.h" 24 double dnorm, dnorm_inv;
25 double complex dam_pr1,dam_pr2a,dam_pr2b,dam_pr3,dam_pr4;
26 double E1,E2a,E2b,E3,E4;
27 double alpha_p,alpha_m;
29 double Lz_Ene_p,Lz_Ene_m;
30 double Lz_Var_p,Lz_Var_m;
38 for(i_Lz=0;i_Lz<50;i_Lz++){
42 #pragma omp parallel for default(none) private(i) shared(v0) firstprivate(i_max) 43 for(i = 1; i <= i_max; i++){
50 #pragma omp parallel for default(none) reduction(+:dam_pr1,dam_pr2a) private(j) shared(v0, v1)firstprivate(i_max) 51 for(j=1;j<=i_max;j++){
52 dam_pr1 += conj(
v1[j])*
v0[j];
53 dam_pr2a += conj(
v0[j])*
v0[j];
59 E2a = creal(dam_pr2a);
61 #pragma omp parallel for default(none) private(i) shared(vg) firstprivate(i_max) 62 for(i = 1; i <= i_max; i++){
70 #pragma omp parallel for default(none) reduction(+:dam_pr2b,dam_pr3, dam_pr4) private(j) shared(v0,v1, vg)firstprivate(i_max) 71 for(j=1;j<=i_max;j++){
72 dam_pr2b += conj(
vg[j])*
v1[j];
73 dam_pr3 += conj(
vg[j])*
v0[j];
74 dam_pr4 += conj(
vg[j])*
vg[j];
81 E2b = creal(dam_pr2b) ;
86 fprintf(
stdoutMPI,
"Power Lanczos break \n");
91 Lz(X,alpha_p,&Lz_Ene_p,&Lz_Var_p,E1,E2a,E3,E4);
92 Lz(X,alpha_m,&Lz_Ene_m,&Lz_Var_m,E1,E2a,E3,E4);
94 if(Lz_Ene_p < Lz_Ene_m){
96 fprintf(
stdoutMPI,
"Power Lanczos (P): %.16lf %.16lf \n",Lz_Ene_p,Lz_Var_p);
97 #pragma omp parallel for default(none) private(j) shared(v0, v1) firstprivate(i_max,alpha_p) 98 for(j=1;j<=i_max;j++){
99 v1[j] =
v1[j]+alpha_p*
v0[j];
103 fprintf(
stdoutMPI,
"Power Lanczos (M): %.16lf %.16lf \n",Lz_Ene_m,Lz_Var_m);
104 #pragma omp parallel for default(none) private(j) shared(v0, v1)firstprivate(i_max,alpha_m) 105 for(j=1;j<=i_max;j++){
106 v1[j] =
v1[j]+alpha_m*
v0[j];
111 #pragma omp parallel for default(none) reduction(+:dnorm) private(j) shared(v1) firstprivate(i_max) 112 for(j=1;j<=i_max;j++){
113 dnorm += conj(
v1[j])*
v1[j];
118 #pragma omp parallel for default(none) private(j) shared(v1) firstprivate(i_max, dnorm_inv) 119 for(j=1;j<=i_max;j++){
120 v1[j] =
v1[j]*dnorm_inv;
123 fprintf(
stdoutMPI,
"Power Lanczos break \n");
133 double tmp_AA,tmp_BB,tmp_CC;
144 tmp_AA = b*(b+c)-2*a*d;
146 tmp_CC = b*((b+c)*(b+c))-(a*a)*b*(b+2*c)+4*(a*a*a)*d-2*a*(2*b+c)*d+d*d;
147 if(tmp_AA< pow(b, 2)*pow(10.0, -15)){
153 *alpha_p = (tmp_BB+sqrt((tmp_CC)))/tmp_AA;
154 *alpha_m = (tmp_BB-sqrt((tmp_CC)))/tmp_AA;
161 *alpha_p = cabs((tmp_BB+csqrt((tmp_CC))))/tmp_AA;
162 *alpha_m = cabs((tmp_BB-csqrt((tmp_CC))))/tmp_AA;
167 void Lz(
struct BindStruct *
X,
double alpha,
double *Lz_Ene,
double *Lz_Var,
double E1,
double E2,
double E3,
double E4){
169 double tmp_ene,tmp_var;
171 tmp_ene = (E1+2*alpha*E2+alpha*alpha*E3)/(1+2*alpha*E1+alpha*alpha*E2);
174 tmp_var = (E2+2*alpha*E3+alpha*alpha*E4)/(1+2*alpha*E1+alpha*alpha*E2);
176 *Lz_Var = fabs(tmp_var-tmp_ene*tmp_ene)/tmp_var;
int mltply(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Parent function of multiplying the wavefunction by the Hamiltonian. . First, the calculation of diago...
double complex SumMPI_dc(double complex norm)
MPI wrapper function to obtain sum of Double complex across processes.
unsigned long int idim_max
The dimension of the Hilbert space of this process.
double SumMPI_d(double norm)
MPI wrapper function to obtain sum of Double across processes.
struct PhysList Phys
Physical quantities.
void Lz(struct BindStruct *X, double alpha, double *Lz_Ene, double *Lz_Var, double E1, double E2, double E3, double E4)
int PowerLanczos(struct BindStruct *X)
double var
Expectation value of the Energy variance.
int solve_2ndPolinomial(struct BindStruct *X, double *alpha_p, double *alpha_m, double E1, double E2a, double E2b, double E3, double E4)
double energy
Expectation value of the total energy.
struct CheckList Check
Size of the Hilbert space.
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()