Skip to content

Commit

Permalink
add new gint interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dzzz2001 committed Jan 18, 2025
1 parent d11d4c7 commit c9b37f2
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ if(ENABLE_LCAO)
add_compile_definitions(__PEXSI)
set(CMAKE_CXX_STANDARD 14)
endif()
if(NEW_GINT)
add_compile_definitions(__NEW_GINT)
endif()
else()
set(ENABLE_DEEPKS OFF)
set(ENABLE_LIBRI OFF)
Expand Down
26 changes: 19 additions & 7 deletions source/module_elecstate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
//------------------------------------------------------------

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
#ifndef __NEW_GINT
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
// Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
// this->gint_k->cal_gint(&inout);
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_k->cal_gint(&inout);
#else
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
#endif

if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
Expand Down Expand Up @@ -94,13 +97,13 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
//------------------------------------------------------------
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");

#ifndef __NEW_GINT
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint

// Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);

// this->gint_gamma->cal_gint(&inout);
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout);
#else
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
#endif

if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
Expand Down Expand Up @@ -162,16 +165,25 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d
}

ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
#ifndef __NEW_GINT
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout);
#else
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
#endif
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
for (int is = 0; is < PARAM.inp.nspin; is++)
{
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx);
}
#ifndef __NEW_GINT
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
this->gint_gamma->cal_gint(&inout1);
#else
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
#endif
}

this->charge->renormalize_rho();
Expand Down
11 changes: 10 additions & 1 deletion source/module_elecstate/elecstate_lcao_cal_tau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<do
{
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
#ifndef __NEW_GINT
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
this->gint_k->cal_gint(&inout1);
#else
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);

#endif
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
return;
}
Expand All @@ -32,7 +36,12 @@ void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
{
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
#ifndef __NEW_GINT
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
this->gint_gamma->cal_gint(&inout1);
#else
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
#endif

ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
return;
Expand Down
3 changes: 2 additions & 1 deletion source/module_esolver/lcao_before_scf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
d2psi_u,
PARAM.inp.nstream);

#ifdef __NEW_GINT
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
this->pw_big->nbx,
this->pw_big->nby,
Expand All @@ -133,7 +134,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
ucell,
this->gd);
ModuleGint::Gint::init_gint_info(gint_info);
#endif
psi_u.clear();
psi_u.shrink_to_fit();
dpsi_u.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ void Veff<OperatorLCAO<double, double>>::contributeHR()
double* vr_eff1 = this->pot->get_effective_v(this->current_spin);
double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin);

#ifndef __NEW_GINT
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
Gint_inout inout(vr_eff1, vofk_eff1, Gint_Tools::job_type::vlocal_meta);
this->GG->cal_vlocal(&inout, this->new_e_iteration);
}
else
{
Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal);
this->GG->cal_vlocal(&inout, this->new_e_iteration);
}
this->GG->transfer_pvpR(this->hR,this->ucell);
this->new_e_iteration = false;
#else
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR);
Expand All @@ -76,6 +90,7 @@ void Veff<OperatorLCAO<double, double>>::contributeHR()
{
ModuleGint::cal_gint_vl(vr_eff1, this->hR);
}
#endif

if(this->nspin == 2)
{
Expand All @@ -98,6 +113,23 @@ void Veff<OperatorLCAO<std::complex<double>, double>>::contributeHR()
double* vr_eff1 = this->pot->get_effective_v(this->current_spin);
double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin);

#ifndef __NEW_GINT
// if you change the place of the following code,
// rememeber to delete the #include
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta);
this->GK->cal_gint(&inout);
}
else
{
// vlocal = Vh[rho] + Vxc[rho] + Vl(pseudo)
Gint_inout inout(vr_eff1, 0, Gint_Tools::job_type::vlocal);
this->GK->cal_gint(&inout);
}

this->GK->transfer_pvpR(this->hR,this->ucell,this->gd);
#else
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR);
Expand All @@ -106,6 +138,7 @@ void Veff<OperatorLCAO<std::complex<double>, double>>::contributeHR()
{
ModuleGint::cal_gint_vl(vr_eff1, this->hR);
}
#endif

if(this->nspin == 2)
{
Expand All @@ -122,6 +155,30 @@ void Veff<OperatorLCAO<std::complex<double>, std::complex<double>>>::contributeH
ModuleBase::TITLE("Veff", "contributeHR");
ModuleBase::timer::tick("Veff", "contributeHR");

#ifndef __NEW_GINT
double* vr_eff1 = nullptr;
double* vofk_eff1 = nullptr;
for (int is = 0; is < 4; is++)
{
vr_eff1 = this->pot->get_effective_v(is);
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
vofk_eff1 = this->pot->get_effective_vofk(is);
}

if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
{
Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta);
this->GK->cal_gint(&inout);
}
else
{
Gint_inout inout(vr_eff1, is, Gint_Tools::job_type::vlocal);
this->GK->cal_gint(&inout);
}
}
this->GK->transfer_pvpR(this->hR,this->ucell,this->gd);
#else
std::vector<const double*> vr_eff(4, nullptr);
std::vector<const double*> vofk_eff(4, nullptr);
for (int is = 0; is < 4; is++)
Expand All @@ -143,6 +200,7 @@ void Veff<OperatorLCAO<std::complex<double>, std::complex<double>>>::contributeH
}
}
}
#endif

ModuleBase::timer::tick("Veff", "contributeHR");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ namespace PulayForceStress
const bool& set_dmr_gint)
{
const int nspin = PARAM.inp.nspin;

#ifndef __NEW_GINT
if (set_dmr_gint) { gint.transfer_DM2DtoGrid(dm.get_DMR_vector()); } // 2d block to grid
for (int is = 0; is < nspin; ++is)
{
const double* vr_eff1 = pot->get_effective_v(is);
const double* vofk_eff1 = nullptr;
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
{
vofk_eff1 = pot->get_effective_vofk(is);
Gint_inout inout(is, vr_eff1, vofk_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force_meta);
gint.cal_gint(&inout);
}
else
{
Gint_inout inout(is, vr_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force);
gint.cal_gint(&inout);
}
}
#else
std::vector<const double*> vr_eff(nspin, nullptr);
std::vector<const double*> vofk_eff(nspin, nullptr);
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
Expand All @@ -38,6 +58,7 @@ namespace PulayForceStress
}
ModuleGint::cal_gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s);
}
#endif

if (isstress) { StressTools::stress_fill(-1.0, ucell.omega, s); }
}
Expand Down
46 changes: 24 additions & 22 deletions source/module_hamilt_lcao/module_gint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,30 @@ list(APPEND objects
init_orb.cpp
)

list(APPEND objects
new_grid_tech/biggrid_info.cpp
new_grid_tech/biggrid.cpp
new_grid_tech/divide_info.cpp
new_grid_tech/gint_atom.cpp
new_grid_tech/gint_info.cpp
new_grid_tech/gint.cpp
new_grid_tech/gint_vl.cpp
new_grid_tech/gint_vl_metagga.cpp
new_grid_tech/gint_vl_nspin4.cpp
new_grid_tech/gint_vl_metagga_nspin4.cpp
new_grid_tech/gint_rho.cpp
new_grid_tech/gint_tau.cpp
new_grid_tech/gint_fvl.cpp
new_grid_tech/gint_fvl_meta.cpp
new_grid_tech/localcell_info.cpp
new_grid_tech/phi_operator.cpp
new_grid_tech/set_ddphi.cpp
new_grid_tech/unitcell_info.cpp
new_grid_tech/gint_common.cpp
new_grid_tech/gint_interface.cpp
)
if(NEW_GINT)
list(APPEND objects
new_grid_tech/biggrid_info.cpp
new_grid_tech/biggrid.cpp
new_grid_tech/divide_info.cpp
new_grid_tech/gint_atom.cpp
new_grid_tech/gint_info.cpp
new_grid_tech/gint.cpp
new_grid_tech/gint_vl.cpp
new_grid_tech/gint_vl_metagga.cpp
new_grid_tech/gint_vl_nspin4.cpp
new_grid_tech/gint_vl_metagga_nspin4.cpp
new_grid_tech/gint_rho.cpp
new_grid_tech/gint_tau.cpp
new_grid_tech/gint_fvl.cpp
new_grid_tech/gint_fvl_meta.cpp
new_grid_tech/localcell_info.cpp
new_grid_tech/phi_operator.cpp
new_grid_tech/set_ddphi.cpp
new_grid_tech/unitcell_info.cpp
new_grid_tech/gint_common.cpp
new_grid_tech/gint_interface.cpp
)
endif()

if(USE_CUDA)
list(APPEND objects
Expand Down

0 comments on commit c9b37f2

Please sign in to comment.