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

Fix : DeePKS for nspin = 2 and gamma point #2755

Merged
merged 6 commits into from
Jul 28, 2023
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
2 changes: 1 addition & 1 deletion source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ namespace ModuleESolver
{
if (GlobalV::GAMMA_ONLY_LOCAL)
{
GlobalC::ld.cal_projected_DM(this->LOC.dm_gamma[0],
GlobalC::ld.cal_projected_DM(this->LOC.dm_gamma,
GlobalC::ucell,
GlobalC::ORB,
GlobalC::GridD);
Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ void Force_LCAO_gamma::ftable_gamma(const bool isforce,
#ifdef __DEEPKS
if (GlobalV::deepks_scf)
{
GlobalC::ld.cal_projected_DM(loc.dm_gamma[0],
GlobalC::ld.cal_projected_DM(loc.dm_gamma,
GlobalC::ucell,
GlobalC::ORB,
GlobalC::GridD);
GlobalC::ld.cal_descriptor();
GlobalC::ld.cal_gedm(GlobalC::ucell.nat);
GlobalC::ld.cal_f_delta_gamma(loc.dm_gamma[0],
GlobalC::ld.cal_f_delta_gamma(loc.dm_gamma,
GlobalC::ucell,
GlobalC::ORB,
GlobalC::GridD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void DeePKS<OperatorLCAO<double>>::contributeHR()
{
ModuleBase::timer::tick("DeePKS", "contributeHR");
const Parallel_Orbitals* pv = this->LM->ParaV;
GlobalC::ld.cal_projected_DM(this->loc->dm_gamma[0],
GlobalC::ld.cal_projected_DM(this->loc->dm_gamma,
GlobalC::ucell,
GlobalC::ORB,
GlobalC::GridD);
Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_lcao/module_deepks/LCAO_deepks.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class LCAO_Deepks

///calculate projected density matrix:
///pdm = sum_i,occ <phi_i|alpha1><alpha2|phi_k>
void cal_projected_DM(const ModuleBase::matrix& dm/**< [in] density matrix*/,
void cal_projected_DM(const std::vector<ModuleBase::matrix>& dm/**< [in] density matrix*/,
const UnitCell &ucell,
const LCAO_Orbitals &orb,
Grid_Driver& GridD);
Expand Down Expand Up @@ -351,7 +351,7 @@ class LCAO_Deepks
public:

//for gamma only, pulay and HF terms of force are calculated together
void cal_f_delta_gamma(const ModuleBase::matrix& dm/**< [in] density matrix*/,
void cal_f_delta_gamma(const std::vector<ModuleBase::matrix>& dm/**< [in] density matrix*/,
const UnitCell &ucell,
const LCAO_Orbitals &orb,
Grid_Driver& GridD,
Expand Down
28 changes: 17 additions & 11 deletions source/module_hamilt_lcao/module_deepks/LCAO_deepks_fdelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void stress_fill(

//force for gamma only calculations
//Pulay and HF terms are calculated together
void LCAO_Deepks::cal_f_delta_gamma(const ModuleBase::matrix& dm,
void LCAO_Deepks::cal_f_delta_gamma(const std::vector<ModuleBase::matrix>& dm,
const UnitCell &ucell,
const LCAO_Orbitals &orb,
Grid_Driver& GridD,
Expand Down Expand Up @@ -142,15 +142,18 @@ void LCAO_Deepks::cal_f_delta_gamma(const ModuleBase::matrix& dm,
}
assert(ib==nlm1.size());

// HF term is minus, only one projector for each atom force.
this->F_delta(iat, 0) -= 2 * dm(iw1_local, iw2_local) * nlm[0];
this->F_delta(iat, 1) -= 2 * dm(iw1_local, iw2_local) * nlm[1];
this->F_delta(iat, 2) -= 2 * dm(iw1_local, iw2_local) * nlm[2];

// Pulay term is plus, only one projector for each atom force.
this->F_delta(ibt, 0) += 2 * dm(iw1_local, iw2_local) * nlm[0];
this->F_delta(ibt, 1) += 2 * dm(iw1_local, iw2_local) * nlm[1];
this->F_delta(ibt, 2) += 2 * dm(iw1_local, iw2_local) * nlm[2];
for(int is = 0; is < GlobalV::NSPIN; is ++)
{
// HF term is minus, only one projector for each atom force.
this->F_delta(iat, 0) -= 2 * dm[is](iw1_local, iw2_local) * nlm[0];
this->F_delta(iat, 1) -= 2 * dm[is](iw1_local, iw2_local) * nlm[1];
this->F_delta(iat, 2) -= 2 * dm[is](iw1_local, iw2_local) * nlm[2];

// Pulay term is plus, only one projector for each atom force.
this->F_delta(ibt, 0) += 2 * dm[is](iw1_local, iw2_local) * nlm[0];
this->F_delta(ibt, 1) += 2 * dm[is](iw1_local, iw2_local) * nlm[1];
this->F_delta(ibt, 2) += 2 * dm[is](iw1_local, iw2_local) * nlm[2];
}

if(isstress)
{
Expand Down Expand Up @@ -188,7 +191,10 @@ void LCAO_Deepks::cal_f_delta_gamma(const ModuleBase::matrix& dm,
{
for(int jpol=ipol;jpol<3;jpol++)
{
svnl_dalpha(ipol, jpol) += dm(iw1_local, iw2_local) * (nlm[jpol] * r0[ipol] + nlm_t[jpol] * r1[ipol]);
for(int is = 0; is < GlobalV::NSPIN; is ++)
{
svnl_dalpha(ipol, jpol) += dm[is](iw1_local, iw2_local) * (nlm[jpol] * r0[ipol] + nlm_t[jpol] * r1[ipol]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(double etot,
// so it is printed no matter even if deepks_out_labels is not used
if (GlobalV::GAMMA_ONLY_LOCAL)
{
ld->cal_projected_DM(dm_gamma[0], ucell, orb, GridD);
ld->cal_projected_DM(dm_gamma, ucell, orb, GridD);
}
else
{
Expand Down
9 changes: 6 additions & 3 deletions source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

//this subroutine performs the calculation of projected density matrices
//pdm_m,m'=\sum_{mu,nu} rho_{mu,nu} <chi_mu|alpha_m><alpha_m'|chi_nu>
void LCAO_Deepks::cal_projected_DM(const ModuleBase::matrix &dm,
void LCAO_Deepks::cal_projected_DM(const std::vector<ModuleBase::matrix> &dm,
const UnitCell &ucell,
const LCAO_Orbitals &orb,
Grid_Driver& GridD)
Expand Down Expand Up @@ -54,7 +54,7 @@ void LCAO_Deepks::cal_projected_DM(const ModuleBase::matrix &dm,
return;
}

if(dm.nr == 0 && dm.nc ==0)
if(dm[0].nr == 0 && dm[0].nc ==0)
{
return;
}
Expand Down Expand Up @@ -134,7 +134,10 @@ void LCAO_Deepks::cal_projected_DM(const ModuleBase::matrix &dm,
for (int m2 = 0; m2 < 2 * L0 + 1; ++m2)
{
int ind = m1*nm + m2;
pdm[inl][ind] += dm(iw1_local, iw2_local)*nlm1[ib+m1]*nlm2[ib+m2];
for(int is = 0; is < dm.size(); ++is)
{
pdm[inl][ind] += dm[is](iw1_local, iw2_local)*nlm1[ib+m1]*nlm2[ib+m2];
}
}
}
ib+=nm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void test_deepks::check_pdm(void)
if(GlobalV::GAMMA_ONLY_LOCAL)
{
this->read_dm();
this->ld.cal_projected_DM(dm[0],
this->ld.cal_projected_DM(dm,
ucell,
ORB,
Test_Deepks::GridD);
Expand Down Expand Up @@ -266,7 +266,7 @@ void test_deepks::check_f_delta()
svnl_dalpha.create(3,3);
if(GlobalV::GAMMA_ONLY_LOCAL)
{
ld.cal_f_delta_gamma(dm[0],
ld.cal_f_delta_gamma(dm,
ucell,
ORB,
Test_Deepks::GridD,
Expand Down