Skip to content

Commit 105fd19

Browse files
Refactor: new gint module (#5869)
* remove redundant parameters * version 0.0 * inline some simple functions * change type alias * version 0.1 * version 0.2 * for test * fix some bugs, the first correct version * improve efficiency ang rename some variables * small change * add openmp support to gint_vl * remove some comments * remove some comments * remove some unused code related to spin in gint_k * enable rho calculation * support fvl calculation * add nspin=4 support and change interface * change some raw pointer to shared_ptr * rename hamilt::HContainer * support tau calculation * fix a bug * add vlocal metagga support * support force metagga calculation * change shared_ptr to raw pointer of GintAtom * improve performance * remove destructor * add timer * add timer * improve performance * change 2D ptr to 1D ptr * modify zeros function * replace array pool with vector * Revert "Refactor:remove cal_tau from ElecStateLCAO (#5802)" This reverts commit 414446a. * fix a bug * remove some rudundant functions * simplify member function of biggrid_info * rename some variables * unify some variables name * change some variable to static * fix a bug and delete a redundant operation * add new gint interface * change new_grid_tech to new_gint * revert some incorrect changes * add a unit test * change some names * check nullptr * [pre-commit.ci lite] apply automatic fixes * change DM to dm * change HRGint to hr_gint * modify variable name * fix a bug --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 3c8ac0a commit 105fd19

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4084
-134
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ if(ENABLE_LCAO)
236236
add_compile_definitions(__PEXSI)
237237
set(CMAKE_CXX_STANDARD 14)
238238
endif()
239+
if(NEW_GINT)
240+
add_compile_definitions(__NEW_GINT)
241+
endif()
239242
else()
240243
set(ENABLE_DEEPKS OFF)
241244
set(ENABLE_LIBRI OFF)

source/module_base/array_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace ModuleBase
4040
: nr(nr_in),
4141
nc(nc_in)
4242
{
43-
this->ptr_1D = new T[nr * nc];
43+
this->ptr_1D = new T[nr * nc]();
4444
this->ptr_2D = new T*[nr];
4545
for (int ir = 0; ir < nr; ++ir)
4646
this->ptr_2D[ir] = &this->ptr_1D[ir * nc];

source/module_base/test/vector3_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@
6464
* - VneV
6565
* - overload operator "!=" to assert
6666
* - the inequality between two 3d vectors
67+
* - VltV
68+
* - overload operator "<" to sort
69+
* - the "less than" relationship between two 3d vectors
6770
* - StdOutV
6871
* - overload operator "<<" to print out
6972
* - a 3d vectors on standard output
@@ -703,6 +706,22 @@ TEST_F(Vector3Test,VneV)
703706
EXPECT_TRUE(wp != w);
704707
}
705708

709+
TEST_F(Vector3Test, VltV)
710+
{
711+
ModuleBase::Vector3<double> u, up;
712+
u.set(da, db, dc);
713+
up.set(dc, db, da);
714+
EXPECT_TRUE(u < up);
715+
ModuleBase::Vector3<float> v, vp;
716+
v.set(fa, fb, fc);
717+
vp.set(fa, fb, fc);
718+
EXPECT_FALSE(v < vp);
719+
ModuleBase::Vector3<int> w, wp;
720+
w.set(ia, ib, ic);
721+
wp.set(ib, ib, ic);
722+
EXPECT_TRUE(w < wp);
723+
}
724+
706725
TEST_F(Vector3Test,StdOutV)
707726
{
708727
// double Vector3

source/module_base/vector3.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ template <class T> inline Vector3<T> cross(const Vector3<T> &u, const Vector3<T>
365365
// (u.z * (v.x * w.y - v.y * w.x)));
366366
// }
367367

368+
// Overload the < operator for sorting
369+
template <class T> bool operator<(const Vector3<T> &u, const Vector3<T> &v)
370+
{
371+
if (u.x < v.x)
372+
return true;
373+
if (u.x > v.x)
374+
return false;
375+
if (u.y < v.y)
376+
return true;
377+
if (u.y > v.y)
378+
return false;
379+
if (u.z < v.z)
380+
return true;
381+
return false;
382+
}
383+
368384
// whether m1 != m2
369385
template <class T> inline bool operator!=(const Vector3<T> &u, const Vector3<T> &v)
370386
{

source/module_basis/module_ao/ORB_atomic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Numerical_Orbital
6666

6767
const inline Numerical_Orbital_Lm& PhiLN( const int &L, const int &N)const
6868
{
69+
assert(this->phiLN != nullptr);
6970
return this->phiLN[ this->find_chi(L, N) ];
7071
}
7172

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include "module_hamilt_lcao/module_gint/grid_technique.h"
99
#include "module_hamilt_pw/hamilt_pwdft/global.h"
1010
#include "module_parameter/parameter.h"
11-
#include "elecstate_lcao_cal_tau.h"
11+
12+
#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h"
1213

1314
#include <vector>
1415

@@ -59,13 +60,17 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
5960
//------------------------------------------------------------
6061

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

6671
if (XC_Functional::get_ked_flag())
6772
{
68-
elecstate::lcao_cal_tau_k(gint_k, this->charge);
73+
this->cal_tau(psi);
6974
}
7075

7176
this->charge->renormalize_rho();
@@ -92,15 +97,17 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
9297
//------------------------------------------------------------
9398
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
9499

100+
#ifndef __NEW_GINT
95101
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
96-
97102
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
98-
99103
this->gint_gamma->cal_gint(&inout);
104+
#else
105+
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
106+
#endif
100107

101108
if (XC_Functional::get_ked_flag())
102109
{
103-
elecstate::lcao_cal_tau_gamma(gint_gamma, this->charge);
110+
this->cal_tau(psi);
104111
}
105112

106113
this->charge->renormalize_rho();
@@ -158,17 +165,25 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d
158165
}
159166

160167
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
168+
#ifndef __NEW_GINT
161169
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
162170
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
163171
this->gint_gamma->cal_gint(&inout);
172+
#else
173+
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
174+
#endif
164175
if (XC_Functional::get_ked_flag())
165176
{
166177
for (int is = 0; is < PARAM.inp.nspin; is++)
167178
{
168179
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx);
169180
}
181+
#ifndef __NEW_GINT
170182
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
171183
this->gint_gamma->cal_gint(&inout1);
184+
#else
185+
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
186+
#endif
172187
}
173188

174189
this->charge->renormalize_rho();

source/module_elecstate/elecstate_lcao.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ElecStateLCAO : public ElecState
4646
// virtual void psiToRho(const psi::Psi<double>& psi) override;
4747
// return current electronic density rho, as a input for constructing Hamiltonian
4848
// const double* getRho(int spin) const override;
49+
virtual void cal_tau(const psi::Psi<TK>& psi) override;
4950

5051
// update charge density for next scf step
5152
// void getNewRho() override;
Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,49 @@
11
#include "elecstate_lcao.h"
2-
#include "elecstate_lcao_cal_tau.h"
2+
#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h"
3+
34
#include "module_base/timer.h"
45

56
namespace elecstate
67
{
78

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

1415
for (int is = 0; is < PARAM.inp.nspin; is++)
1516
{
16-
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
17+
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
1718
}
18-
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
19-
gint_k->cal_gint(&inout1);
20-
19+
#ifndef __NEW_GINT
20+
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
21+
this->gint_k->cal_gint(&inout1);
22+
#else
23+
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
24+
#endif
2125
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
2226
return;
2327
}
2428

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

3135
for (int is = 0; is < PARAM.inp.nspin; is++)
3236
{
33-
ModuleBase::GlobalFunc::ZEROS(charge->kin_r[is], charge->nrxx);
37+
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
3438
}
35-
Gint_inout inout1(charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
36-
gint_gamma->cal_gint(&inout1);
39+
#ifndef __NEW_GINT
40+
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
41+
this->gint_gamma->cal_gint(&inout1);
42+
#else
43+
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
44+
#endif
3745

3846
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
3947
return;
4048
}
41-
template <>
42-
void lcao_cal_tau<double>(Gint_Gamma* gint_gamma,
43-
Gint_k* gint_k,
44-
Charge* charge)
45-
{
46-
lcao_cal_tau_gamma(gint_gamma, charge);
47-
}
48-
template <>
49-
void lcao_cal_tau<complex<double>>(Gint_Gamma* gint_gamma,
50-
Gint_k* gint_k,
51-
Charge* charge)
52-
{
53-
lcao_cal_tau_k(gint_k, charge);
54-
}
55-
56-
} // namespace elecstate
49+
}

source/module_elecstate/elecstate_lcao_cal_tau.h

Lines changed: 0 additions & 21 deletions
This file was deleted.

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "module_base/global_function.h"
3535
#include "module_cell/module_neighbor/sltk_grid_driver.h"
3636
#include "module_elecstate/cal_ux.h"
37-
#include "module_elecstate/elecstate_lcao_cal_tau.h"
3837
#include "module_elecstate/module_charge/symmetry_rho.h"
3938
#include "module_elecstate/occupy.h"
4039
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h" // need DeePKS_init
@@ -933,7 +932,8 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep)
933932
// 1) calculate the kinetic energy density tau, sunliang 2024-09-18
934933
if (PARAM.inp.out_elf[0] > 0)
935934
{
936-
elecstate::lcao_cal_tau<TK>(&(this->GG), &(this->GK), this->pelec->charge);
935+
assert(this->psi != nullptr);
936+
this->pelec->cal_tau(*(this->psi));
937937
}
938938

939939
//! 2) call after_scf() of ESolver_KS

0 commit comments

Comments
 (0)