Skip to content

Commit 71e2dea

Browse files
committed
Fix: get_pchg_lcao with nspin=4
1 parent c53f445 commit 71e2dea

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

source/module_io/get_pchg_lcao.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,9 @@ void IState_Charge::begin(Gint_k& gk,
200200
mode = 3;
201201
}
202202

203-
const int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);
203+
int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);
204+
// for nspin = 4 case, fermi_band is the number of electrons because of each band has 1 electron
205+
if(PARAM.inp.nspin == 4) fermi_band = nelec;
204206
std::cout << " number of electrons = " << nelec << std::endl;
205207
std::cout << " number of occupied bands = " << fermi_band << std::endl;
206208

@@ -216,15 +218,15 @@ void IState_Charge::begin(Gint_k& gk,
216218
elecstate::DensityMatrix<std::complex<double>, double> DM(this->ParaV, nspin_dm, kv.kvec_d, kv.get_nks() / nspin_dm);
217219

218220
#ifdef __MPI
219-
this->idmatrix(ib, nspin, nelec, nlocal, wg, DM, kv, if_separate_k);
221+
this->idmatrix(ib, nspin_dm, nelec, nlocal, wg, DM, kv, if_separate_k);
220222
#else
221223
ModuleBase::WARNING_QUIT("IState_Charge::begin", "The `pchg` calculation is only available for MPI now!");
222224
#endif
223225
// If contribution from different k-points need to be output separately
224226
if (if_separate_k)
225227
{
226228
// For multi-k, loop over all real k-points
227-
for (int ik = 0; ik < kv.get_nks() / nspin; ++ik)
229+
for (int ik = 0; ik < kv.get_nks() / nspin_dm; ++ik)
228230
{
229231
for (int is = 0; is < nspin; ++is)
230232
{
@@ -506,16 +508,8 @@ void IState_Charge::idmatrix(const int& ib,
506508
ModuleBase::TITLE("IState_Charge", "idmatrix");
507509
assert(wg.nr == kv.get_nks());
508510

509-
const int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);
510-
511511
// To ensure the normalization of charge density in multi-k calculation (if if_separate_k is true)
512-
double wg_sum_k = 0;
513-
double wg_sum_k_homo = 0;
514-
for (int ik = 0; ik < kv.get_nks() / nspin; ++ik)
515-
{
516-
wg_sum_k += wg(ik, ib);
517-
wg_sum_k_homo += wg(ik, fermi_band - 1);
518-
}
512+
double wg_sum_k = 1.0;
519513

520514
for (int ik = 0; ik < kv.get_nks(); ++ik)
521515
{
@@ -530,11 +524,11 @@ void IState_Charge::idmatrix(const int& ib,
530524
double wg_value;
531525
if (if_separate_k)
532526
{
533-
wg_value = (ib < fermi_band) ? wg_sum_k : wg_sum_k_homo;
527+
wg_value = wg_sum_k;
534528
}
535529
else
536530
{
537-
wg_value = (ib < fermi_band) ? wg(ik, ib) : wg(ik, fermi_band - 1);
531+
wg_value = wg(ik, 0);
538532
}
539533
wg_local[ib_local] = wg_value;
540534
}

0 commit comments

Comments
 (0)