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

Refactor: new gint module #5869

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
469cfb4
remove redundant parameters
dzzz2001 Nov 27, 2024
3a67b8f
version 0.0
dzzz2001 Dec 1, 2024
df73065
inline some simple functions
dzzz2001 Dec 1, 2024
c681070
change type alias
dzzz2001 Dec 2, 2024
1b9477e
version 0.1
dzzz2001 Dec 11, 2024
0b84ed3
version 0.2
dzzz2001 Dec 15, 2024
ad14583
for test
dzzz2001 Dec 18, 2024
a62c3dd
fix some bugs, the first correct version
dzzz2001 Dec 24, 2024
db36b26
improve efficiency ang rename some variables
dzzz2001 Dec 25, 2024
bfcc2fb
small change
dzzz2001 Dec 25, 2024
c1e5b4d
add openmp support to gint_vl
dzzz2001 Dec 25, 2024
4ecfb0c
remove some comments
dzzz2001 Dec 25, 2024
ef8f3f1
remove some comments
dzzz2001 Dec 25, 2024
e7d402a
remove some unused code related to spin in gint_k
dzzz2001 Dec 25, 2024
036cf85
enable rho calculation
dzzz2001 Dec 30, 2024
f223153
support fvl calculation
dzzz2001 Dec 30, 2024
747ade5
add nspin=4 support and change interface
dzzz2001 Jan 1, 2025
45a428c
change some raw pointer to shared_ptr
dzzz2001 Jan 1, 2025
b813dd3
rename hamilt::HContainer
dzzz2001 Jan 1, 2025
06f8ead
support tau calculation
dzzz2001 Jan 1, 2025
17a2f62
fix a bug
dzzz2001 Jan 2, 2025
10c2bb4
add vlocal metagga support
dzzz2001 Jan 2, 2025
4b0adb2
support force metagga calculation
dzzz2001 Jan 3, 2025
ad9157e
change shared_ptr to raw pointer of GintAtom
dzzz2001 Jan 9, 2025
0bf9da2
improve performance
dzzz2001 Jan 9, 2025
453206f
remove destructor
dzzz2001 Jan 10, 2025
d1fe00d
add timer
dzzz2001 Jan 10, 2025
db719d2
add timer
dzzz2001 Jan 10, 2025
a525613
improve performance
dzzz2001 Jan 13, 2025
d276af0
change 2D ptr to 1D ptr
dzzz2001 Jan 13, 2025
9de506c
modify zeros function
dzzz2001 Jan 13, 2025
d86de0f
replace array pool with vector
dzzz2001 Jan 13, 2025
e0fb551
Revert "Refactor:remove cal_tau from ElecStateLCAO (#5802)"
dzzz2001 Jan 13, 2025
12edd12
fix a bug
dzzz2001 Jan 13, 2025
5c39340
remove some rudundant functions
dzzz2001 Jan 16, 2025
4481063
simplify member function of biggrid_info
dzzz2001 Jan 16, 2025
b6c17ce
rename some variables
dzzz2001 Jan 16, 2025
56cb9bb
unify some variables name
dzzz2001 Jan 16, 2025
6c488db
change some variable to static
dzzz2001 Jan 14, 2025
d11d4c7
fix a bug and delete a redundant operation
dzzz2001 Jan 18, 2025
c9b37f2
add new gint interface
dzzz2001 Jan 18, 2025
f20de93
change new_grid_tech to new_gint
dzzz2001 Jan 18, 2025
7cfd5ef
revert some incorrect changes
dzzz2001 Jan 18, 2025
156ee88
Merge branch 'develop' into gint-new
dzzz2001 Jan 18, 2025
ea17559
add a unit test
dzzz2001 Jan 20, 2025
b267ee6
change some names
dzzz2001 Jan 20, 2025
af6f565
check nullptr
dzzz2001 Jan 20, 2025
78eef21
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 20, 2025
0c84005
Merge branch 'develop' into gint-new
dzzz2001 Jan 20, 2025
3b02824
Merge branch 'develop' into gint-new
dzzz2001 Jan 22, 2025
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
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
2 changes: 1 addition & 1 deletion source/module_base/array_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace ModuleBase
: nr(nr_in),
nc(nc_in)
{
this->ptr_1D = new T[nr * nc];
this->ptr_1D = new T[nr * nc]();
this->ptr_2D = new T*[nr];
for (int ir = 0; ir < nr; ++ir)
this->ptr_2D[ir] = &this->ptr_1D[ir * nc];
Expand Down
16 changes: 16 additions & 0 deletions source/module_base/vector3.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,22 @@ template <class T> inline Vector3<T> cross(const Vector3<T> &u, const Vector3<T>
// (u.z * (v.x * w.y - v.y * w.x)));
// }

// Overload the < operator for sorting
template <class T> bool operator<(const Vector3<T> &u, const Vector3<T> &v)
dzzz2001 marked this conversation as resolved.
Show resolved Hide resolved
{
if (u.x < v.x)
return true;
if (u.x > v.x)
return false;
if (u.y < v.y)
return true;
if (u.y > v.y)
return false;
if (u.z < v.z)
return true;
return false;
}

// whether m1 != m2
template <class T> inline bool operator!=(const Vector3<T> &u, const Vector3<T> &v)
{
Expand Down
25 changes: 20 additions & 5 deletions source/module_elecstate/elecstate_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "module_hamilt_lcao/module_gint/grid_technique.h"
#include "module_hamilt_pw/hamilt_pwdft/global.h"
#include "module_parameter/parameter.h"
#include "elecstate_lcao_cal_tau.h"

#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h"

#include <vector>

Expand Down Expand Up @@ -59,13 +60,17 @@ 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);
#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)
{
elecstate::lcao_cal_tau_k(gint_k, this->charge);
this->cal_tau(psi);
}

this->charge->renormalize_rho();
Expand All @@ -92,15 +97,17 @@ 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);
#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)
{
elecstate::lcao_cal_tau_gamma(gint_gamma, this->charge);
this->cal_tau(psi);
}

this->charge->renormalize_rho();
Expand Down Expand Up @@ -158,17 +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
1 change: 1 addition & 0 deletions source/module_elecstate/elecstate_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ElecStateLCAO : public ElecState
// virtual void psiToRho(const psi::Psi<double>& psi) override;
// return current electronic density rho, as a input for constructing Hamiltonian
// const double* getRho(int spin) const override;
virtual void cal_tau(const psi::Psi<TK>& psi) override;

// update charge density for next scf step
// void getNewRho() override;
Expand Down
49 changes: 21 additions & 28 deletions source/module_elecstate/elecstate_lcao_cal_tau.cpp
Original file line number Diff line number Diff line change
@@ -1,56 +1,49 @@
#include "elecstate_lcao.h"
#include "elecstate_lcao_cal_tau.h"
#include "module_hamilt_lcao/module_gint/new_gint/gint_interface.h"

#include "module_base/timer.h"

namespace elecstate
{

// calculate the kinetic energy density tau, multi-k case
void lcao_cal_tau_k(Gint_k* gint_k,
Charge* charge)
template <>
void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<double>>& psi)
{
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");

for (int is = 0; is < PARAM.inp.nspin; is++)
{
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
gint_k->cal_gint(&inout1);

#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;
}

// calculate the kinetic energy density tau, gamma-only case
void lcao_cal_tau_gamma(Gint_Gamma* gint_gamma,
Charge* charge)
template <>
void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
{
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");

for (int is = 0; is < PARAM.inp.nspin; is++)
{
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
}
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
gint_gamma->cal_gint(&inout1);
#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;
}
template <>
void lcao_cal_tau<double>(Gint_Gamma* gint_gamma,
Gint_k* gint_k,
Charge* charge)
{
lcao_cal_tau_gamma(gint_gamma, charge);
}
template <>
void lcao_cal_tau<complex<double>>(Gint_Gamma* gint_gamma,
Gint_k* gint_k,
Charge* charge)
{
lcao_cal_tau_k(gint_k, charge);
}

} // namespace elecstate
}
21 changes: 0 additions & 21 deletions source/module_elecstate/elecstate_lcao_cal_tau.h

This file was deleted.

4 changes: 2 additions & 2 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "module_base/global_function.h"
#include "module_cell/module_neighbor/sltk_grid_driver.h"
#include "module_elecstate/cal_ux.h"
#include "module_elecstate/elecstate_lcao_cal_tau.h"
#include "module_elecstate/module_charge/symmetry_rho.h"
#include "module_elecstate/occupy.h"
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need DeePKS_init
Expand Down Expand Up @@ -933,7 +932,8 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
// 1) calculate the kinetic energy density tau, sunliang 2024-09-18
if (PARAM.inp.out_elf[0] > 0)
{
elecstate::lcao_cal_tau<TK>(&(this->GG), &(this->GK), this->pelec->charge);
assert(this->psi != nullptr);
this->pelec->cal_tau(*(this->psi));
mohanchen marked this conversation as resolved.
Show resolved Hide resolved
}

//! 2) call after_scf() of ESolver_KS
Expand Down
2 changes: 2 additions & 0 deletions source/module_esolver/esolver_ks_lcao.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// for grid integration
#include "module_hamilt_lcao/module_gint/gint_gamma.h"
#include "module_hamilt_lcao/module_gint/gint_k.h"
#include "module_hamilt_lcao/module_gint/new_gint/gint_info.h"
mohanchen marked this conversation as resolved.
Show resolved Hide resolved
#include "module_hamilt_lcao/module_gint/new_gint/gint.h"
#ifdef __DEEPKS
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
#endif
Expand Down
20 changes: 20 additions & 0 deletions source/module_esolver/lcao_before_scf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
dpsi_u,
d2psi_u,
PARAM.inp.nstream);

#ifdef __NEW_GINT
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
this->pw_big->nbx,
this->pw_big->nby,
this->pw_big->nbz,
this->pw_rho->nx,
this->pw_rho->ny,
this->pw_rho->nz,
0,
0,
this->pw_big->nbzp_start,
this->pw_big->nbx,
this->pw_big->nby,
this->pw_big->nbzp,
orb_.Phi,
ucell,
this->gd);
ModuleGint::Gint::init_gint_info(gint_info);
#endif
psi_u.clear();
psi_u.shrink_to_fit();
dpsi_u.clear();
Expand Down
Loading
Loading