diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index f1954cb56d..92b3d8c308 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -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); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp index 7b929bfb62..a540d7f2e6 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp @@ -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, diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp index 223de7ceb9..dbd0862f1d 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp @@ -23,7 +23,7 @@ void DeePKS>::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); diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h b/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h index 60eaf95611..31e4445fad 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks.h @@ -271,7 +271,7 @@ class LCAO_Deepks ///calculate projected density matrix: ///pdm = sum_i,occ - void cal_projected_DM(const ModuleBase::matrix& dm/**< [in] density matrix*/, + void cal_projected_DM(const std::vector& dm/**< [in] density matrix*/, const UnitCell &ucell, const LCAO_Orbitals &orb, Grid_Driver& GridD); @@ -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& dm/**< [in] density matrix*/, const UnitCell &ucell, const LCAO_Orbitals &orb, Grid_Driver& GridD, diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fdelta.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fdelta.cpp index 1069812616..f1e9ea1c49 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fdelta.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_fdelta.cpp @@ -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& dm, const UnitCell &ucell, const LCAO_Orbitals &orb, Grid_Driver& GridD, @@ -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) { @@ -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]); + } } } } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp index 666326525d..26abdc15a3 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp @@ -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 { diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp index 2c2908e9d8..89004d8d2a 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp @@ -25,7 +25,7 @@ //this subroutine performs the calculation of projected density matrices //pdm_m,m'=\sum_{mu,nu} rho_{mu,nu} -void LCAO_Deepks::cal_projected_DM(const ModuleBase::matrix &dm, +void LCAO_Deepks::cal_projected_DM(const std::vector &dm, const UnitCell &ucell, const LCAO_Orbitals &orb, Grid_Driver& GridD) @@ -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; } @@ -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; diff --git a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp index 941a5cb463..08ae88dac1 100644 --- a/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp +++ b/source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test.cpp @@ -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); @@ -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,