Skip to content

Commit

Permalink
Merge pull request #200 from YaphetS-jx/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
phanish-suryanarayana authored Sep 27, 2023
2 parents 1f286a4 + 7ee9fdf commit 8c5ee6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
-Name
-changes


--------------
Sep 27, 2023
Name: Xin Jing
Changes: (xc/exx/exactExchangeEnergyDensity.c)
1. Fix a bug in printing exact exchange energy densities

--------------
Sep 26, 2023
Name: Xin Jing
Expand Down
2 changes: 1 addition & 1 deletion src/initialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ void write_output_init(SPARC_OBJ *pSPARC) {
}

fprintf(output_fp,"***************************************************************************\n");
fprintf(output_fp,"* SPARC (version Sep 26, 2023) *\n");
fprintf(output_fp,"* SPARC (version Sep 27, 2023) *\n");
fprintf(output_fp,"* Copyright (c) 2020 Material Physics & Mechanics Group, Georgia Tech *\n");
fprintf(output_fp,"* Distributed under GNU General Public License 3 (GPL) *\n");
fprintf(output_fp,"* Start time: %s *\n",c_time_str);
Expand Down
27 changes: 14 additions & 13 deletions src/xc/exx/exactExchangeEnergyDensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
if (pSPARC->spincomm_index < 0 || pSPARC->bandcomm_index < 0 || pSPARC->dmcomm == MPI_COMM_NULL) return;

int i, Nband, DMnd, Ns, Nk, kpt, count;
int n, size_k, spinDMnd;
int n, size_k, ncol;
double *X, *Vexx, g_nk;
double _Complex *X_kpt, *Vexx_kpt;
MPI_Comm comm;
Expand All @@ -52,15 +52,16 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
size_k = DMndsp * Nband;
Ns = pSPARC->Nstates;
Nk = pSPARC->Nkpts_kptcomm;
spinDMnd = (pSPARC->spin_typ == 0) ? DMnd : 2*DMnd;
ncol = (pSPARC->spin_typ == 0) ? DMnd : 2*DMnd;
comm = pSPARC->dmcomm;
memset(Exxrho, 0, sizeof(double) * DMnd * (2*pSPARC->Nspin-1));
double *Exxrho_ = (pSPARC->spin_typ > 0) ? Exxrho+DMnd : Exxrho;

if (pSPARC->isGammaPoint == 1) {
Vexx = (double *) malloc(sizeof(double) * DMnd * Nband);
assert(Vexx != NULL);
for (int spinor = 0; spinor < pSPARC->Nspinor_spincomm; spinor++) {
int sg = pSPARC->spinor_start_indx + spinor;
int sg = pSPARC->spinor_start_indx + spinor;
X = pSPARC->Xorb + spinor*DMnd;
double *occ = (pSPARC->spin_typ == 1) ? (pSPARC->occ+spinor*Ns) : pSPARC->occ;

Expand All @@ -69,12 +70,12 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)

count = 0;
for (n = 0; n < Nband; n++) {
g_nk = occ[n+pSPARC->band_start_indx];
g_nk = occ[n+pSPARC->band_start_indx];
for (i = 0; i < DMnd; i++, count++) {
// first column spin up, second colum spin down, last column total in case of spin-polarized calculation
// only total in case of non-spin-polarized calculation
// different from electron density
Exxrho[sg*DMnd + i] += g_nk * X[i+n*DMndsp] * Vexx[count];
Exxrho_[sg*DMnd + i] += g_nk * X[i+n*DMndsp] * Vexx[count];
}
}
}
Expand All @@ -98,7 +99,7 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
// first column spin up, second colum spin down, last column total in case of spin-polarized calculation
// only total in case of non-spin-polarized calculation
// different from electron density
Exxrho[sg*DMnd + i] += g_nk * creal(conj(X_kpt[i+n*DMndsp]) * Vexx_kpt[count]);
Exxrho_[sg*DMnd + i] += g_nk * creal(conj(X_kpt[i+n*DMndsp]) * Vexx_kpt[count]);
}
}
}
Expand All @@ -111,7 +112,7 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
#ifdef DEBUG
t1 = MPI_Wtime();
#endif
MPI_Allreduce(MPI_IN_PLACE, Exxrho, spinDMnd, MPI_DOUBLE, MPI_SUM, pSPARC->spin_bridge_comm);
MPI_Allreduce(MPI_IN_PLACE, Exxrho_, ncol, MPI_DOUBLE, MPI_SUM, pSPARC->spin_bridge_comm);

#ifdef DEBUG
t2 = MPI_Wtime();
Expand All @@ -124,7 +125,7 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
#ifdef DEBUG
t1 = MPI_Wtime();
#endif
MPI_Allreduce(MPI_IN_PLACE, Exxrho, spinDMnd, MPI_DOUBLE, MPI_SUM, pSPARC->kpt_bridge_comm);
MPI_Allreduce(MPI_IN_PLACE, Exxrho_, ncol, MPI_DOUBLE, MPI_SUM, pSPARC->kpt_bridge_comm);

#ifdef DEBUG
t2 = MPI_Wtime();
Expand All @@ -137,7 +138,7 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
#ifdef DEBUG
t1 = MPI_Wtime();
#endif
MPI_Allreduce(MPI_IN_PLACE, Exxrho, spinDMnd, MPI_DOUBLE, MPI_SUM, pSPARC->blacscomm);
MPI_Allreduce(MPI_IN_PLACE, Exxrho_, ncol, MPI_DOUBLE, MPI_SUM, pSPARC->blacscomm);

#ifdef DEBUG
t2 = MPI_Wtime();
Expand All @@ -151,19 +152,19 @@ void computeExactExchangeEnergyDensity(SPARC_OBJ *pSPARC, double *Exxrho)
Exxrho[i] *= vscal;
}
} else {
vscal *= 0.5; // spin factor
vscal *= 0.5;
for (i = 0; i < 2*DMnd; i++) {
Exxrho[i] *= vscal;
Exxrho[i+DMnd] *= vscal;
}
// Total exx energy density
for (i = 0; i < DMnd; i++) {
Exxrho[i+2*DMnd] = Exxrho[i] + Exxrho[i+DMnd];
Exxrho[i] = Exxrho[i+DMnd] + Exxrho[i+2*DMnd];
}
}
#ifdef DEBUG
double Exx = 0.0;
for (i = 0; i < DMnd; i++) {
Exx += Exxrho[i + pSPARC->spin_typ*2*DMnd];
Exx += Exxrho[i];
}
if (pSPARC->spincomm_index == 0 && pSPARC->kptcomm_index == 0 && pSPARC->bandcomm_index == 0) {
MPI_Allreduce(MPI_IN_PLACE, &Exx, 1, MPI_DOUBLE, MPI_SUM, pSPARC->dmcomm);
Expand Down

0 comments on commit 8c5ee6a

Please sign in to comment.