Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add normalization procedure for partial charge in multi-k calculations when if_separate_k=1 #4724

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions source/module_io/istate_charge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void IState_Charge::begin(Gint_k& gk,
elecstate::DensityMatrix<std::complex<double>, double> DM(&kv, this->ParaV, nspin);

#ifdef __MPI
this->idmatrix(ib, nspin, nelec, nlocal, wg, DM, kv);
this->idmatrix(ib, nspin, nelec, nlocal, wg, DM, kv, if_separate_k);
#else
ModuleBase::WARNING_QUIT("IState_Charge::begin", "The `pchg` calculation is only available for MPI now!");
#endif
Expand Down Expand Up @@ -347,6 +347,8 @@ void IState_Charge::select_bands(const int nbands_istate,
const int mode,
const int fermi_band)
{
ModuleBase::TITLE("IState_Charge", "select_bands");

int bands_below = 0;
int bands_above = 0;

Expand All @@ -358,10 +360,10 @@ void IState_Charge::select_bands(const int nbands_istate,
bands_below = nbands_istate;
bands_above = nbands_istate;

std::cout << " Plot band-decomposed charge densities below Fermi surface with " << bands_below << " bands."
std::cout << " Plot band-decomposed charge densities below the Fermi surface with " << bands_below << " bands."
<< std::endl;

std::cout << " Plot band-decomposed charge densities above Fermi surface with " << bands_above << " bands."
std::cout << " Plot band-decomposed charge densities above the Fermi surface with " << bands_above << " bands."
<< std::endl;

for (int ib = 0; ib < nbands; ++ib)
Expand Down Expand Up @@ -505,13 +507,23 @@ void IState_Charge::idmatrix(const int& ib,
const int nlocal,
const ModuleBase::matrix& wg,
elecstate::DensityMatrix<std::complex<double>, double>& DM,
const K_Vectors& kv)
const K_Vectors& kv,
const bool if_separate_k)
{
ModuleBase::TITLE("IState_Charge", "idmatrix");
assert(wg.nr == kv.get_nks());

const int fermi_band = static_cast<int>((nelec + 1) / 2 + 1.0e-8);

// To ensure the normalization of charge density in multi-k calculation (if if_separate_k is true)
double wg_sum_k = 0;
double wg_sum_k_homo = 0;
for (int ik = 0; ik < kv.get_nks() / nspin; ++ik)
{
wg_sum_k += wg(ik, ib);
wg_sum_k_homo += wg(ik, fermi_band - 1);
}

for (int ik = 0; ik < kv.get_nks(); ++ik)
{
std::cout << " Calculating density matrix for band " << ib + 1 << ", k-point "
Expand All @@ -522,7 +534,16 @@ void IState_Charge::idmatrix(const int& ib,

if (ib_local >= 0)
{
wg_local[ib_local] = (ib < fermi_band) ? wg(ik, ib) : wg(ik, fermi_band - 1);
double wg_value;
if (if_separate_k)
{
wg_value = (ib < fermi_band) ? wg_sum_k : wg_sum_k_homo;
}
else
{
wg_value = (ib < fermi_band) ? wg(ik, ib) : wg(ik, fermi_band - 1);
}
wg_local[ib_local] = wg_value;
}

this->psi_k->fix_k(ik);
Expand Down
3 changes: 2 additions & 1 deletion source/module_io/istate_charge.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class IState_Charge
const int nlocal,
const ModuleBase::matrix& wg,
elecstate::DensityMatrix<std::complex<double>, double>& DM,
const K_Vectors& kv);
const K_Vectors& kv,
const bool if_separate_k);

#endif
std::vector<int> bands_picked_;
Expand Down
Loading