Skip to content

Commit c9b37f2

Browse files
committed
add new gint interface
1 parent d11d4c7 commit c9b37f2

File tree

7 files changed

+137
-31
lines changed

7 files changed

+137
-31
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_elecstate/elecstate_lcao.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
6060
//------------------------------------------------------------
6161

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

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

100+
#ifndef __NEW_GINT
97101
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
98-
99-
// Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
100-
101-
// this->gint_gamma->cal_gint(&inout);
102+
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
103+
this->gint_gamma->cal_gint(&inout);
104+
#else
102105
ModuleGint::cal_gint_rho(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->rho);
103-
106+
#endif
104107

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

164167
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
168+
#ifndef __NEW_GINT
165169
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
166170
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
167171
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
168175
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
169176
{
170177
for (int is = 0; is < PARAM.inp.nspin; is++)
171178
{
172179
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[0], this->charge->nrxx);
173180
}
181+
#ifndef __NEW_GINT
182+
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
183+
this->gint_gamma->cal_gint(&inout1);
184+
#else
174185
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
186+
#endif
175187
}
176188

177189
this->charge->renormalize_rho();

source/module_elecstate/elecstate_lcao_cal_tau.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<do
1616
{
1717
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
1818
}
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
1923
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
20-
24+
#endif
2125
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
2226
return;
2327
}
@@ -32,7 +36,12 @@ void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
3236
{
3337
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
3438
}
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
3543
ModuleGint::cal_gint_tau(this->DM->get_DMR_vector(), PARAM.inp.nspin, this->charge->kin_r);
44+
#endif
3645

3746
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
3847
return;

source/module_esolver/lcao_before_scf.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
116116
d2psi_u,
117117
PARAM.inp.nstream);
118118

119+
#ifdef __NEW_GINT
119120
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
120121
this->pw_big->nbx,
121122
this->pw_big->nby,
@@ -133,7 +134,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
133134
ucell,
134135
this->gd);
135136
ModuleGint::Gint::init_gint_info(gint_info);
136-
137+
#endif
137138
psi_u.clear();
138139
psi_u.shrink_to_fit();
139140
dpsi_u.clear();

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ void Veff<OperatorLCAO<double, double>>::contributeHR()
6868
double* vr_eff1 = this->pot->get_effective_v(this->current_spin);
6969
double* vofk_eff1 = this->pot->get_effective_vofk(this->current_spin);
7070

71+
#ifndef __NEW_GINT
72+
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
73+
{
74+
Gint_inout inout(vr_eff1, vofk_eff1, Gint_Tools::job_type::vlocal_meta);
75+
this->GG->cal_vlocal(&inout, this->new_e_iteration);
76+
}
77+
else
78+
{
79+
Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal);
80+
this->GG->cal_vlocal(&inout, this->new_e_iteration);
81+
}
82+
this->GG->transfer_pvpR(this->hR,this->ucell);
83+
this->new_e_iteration = false;
84+
#else
7185
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
7286
{
7387
ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR);
@@ -76,6 +90,7 @@ void Veff<OperatorLCAO<double, double>>::contributeHR()
7690
{
7791
ModuleGint::cal_gint_vl(vr_eff1, this->hR);
7892
}
93+
#endif
7994

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

116+
#ifndef __NEW_GINT
117+
// if you change the place of the following code,
118+
// rememeber to delete the #include
119+
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
120+
{
121+
Gint_inout inout(vr_eff1, vofk_eff1, 0, Gint_Tools::job_type::vlocal_meta);
122+
this->GK->cal_gint(&inout);
123+
}
124+
else
125+
{
126+
// vlocal = Vh[rho] + Vxc[rho] + Vl(pseudo)
127+
Gint_inout inout(vr_eff1, 0, Gint_Tools::job_type::vlocal);
128+
this->GK->cal_gint(&inout);
129+
}
130+
131+
this->GK->transfer_pvpR(this->hR,this->ucell,this->gd);
132+
#else
101133
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
102134
{
103135
ModuleGint::cal_gint_vl_metagga(vr_eff1, vofk_eff1, this->hR);
@@ -106,6 +138,7 @@ void Veff<OperatorLCAO<std::complex<double>, double>>::contributeHR()
106138
{
107139
ModuleGint::cal_gint_vl(vr_eff1, this->hR);
108140
}
141+
#endif
109142

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

158+
#ifndef __NEW_GINT
159+
double* vr_eff1 = nullptr;
160+
double* vofk_eff1 = nullptr;
161+
for (int is = 0; is < 4; is++)
162+
{
163+
vr_eff1 = this->pot->get_effective_v(is);
164+
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
165+
{
166+
vofk_eff1 = this->pot->get_effective_vofk(is);
167+
}
168+
169+
if(XC_Functional::get_func_type()==3 || XC_Functional::get_func_type()==5)
170+
{
171+
Gint_inout inout(vr_eff1, vofk_eff1, is, Gint_Tools::job_type::vlocal_meta);
172+
this->GK->cal_gint(&inout);
173+
}
174+
else
175+
{
176+
Gint_inout inout(vr_eff1, is, Gint_Tools::job_type::vlocal);
177+
this->GK->cal_gint(&inout);
178+
}
179+
}
180+
this->GK->transfer_pvpR(this->hR,this->ucell,this->gd);
181+
#else
125182
std::vector<const double*> vr_eff(4, nullptr);
126183
std::vector<const double*> vofk_eff(4, nullptr);
127184
for (int is = 0; is < 4; is++)
@@ -143,6 +200,7 @@ void Veff<OperatorLCAO<std::complex<double>, std::complex<double>>>::contributeH
143200
}
144201
}
145202
}
203+
#endif
146204

147205
ModuleBase::timer::tick("Veff", "contributeHR");
148206
return;

source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress_gint.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ namespace PulayForceStress
1919
const bool& set_dmr_gint)
2020
{
2121
const int nspin = PARAM.inp.nspin;
22+
23+
#ifndef __NEW_GINT
24+
if (set_dmr_gint) { gint.transfer_DM2DtoGrid(dm.get_DMR_vector()); } // 2d block to grid
25+
for (int is = 0; is < nspin; ++is)
26+
{
27+
const double* vr_eff1 = pot->get_effective_v(is);
28+
const double* vofk_eff1 = nullptr;
29+
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
30+
{
31+
vofk_eff1 = pot->get_effective_vofk(is);
32+
Gint_inout inout(is, vr_eff1, vofk_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force_meta);
33+
gint.cal_gint(&inout);
34+
}
35+
else
36+
{
37+
Gint_inout inout(is, vr_eff1, isforce, isstress, &f, &s, Gint_Tools::job_type::force);
38+
gint.cal_gint(&inout);
39+
}
40+
}
41+
#else
2242
std::vector<const double*> vr_eff(nspin, nullptr);
2343
std::vector<const double*> vofk_eff(nspin, nullptr);
2444
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
@@ -38,6 +58,7 @@ namespace PulayForceStress
3858
}
3959
ModuleGint::cal_gint_fvl(nspin, vr_eff, dm.get_DMR_vector(), isforce, isstress, &f, &s);
4060
}
61+
#endif
4162

4263
if (isstress) { StressTools::stress_fill(-1.0, ucell.omega, s); }
4364
}

source/module_hamilt_lcao/module_gint/CMakeLists.txt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ list(APPEND objects
2929
init_orb.cpp
3030
)
3131

32-
list(APPEND objects
33-
new_grid_tech/biggrid_info.cpp
34-
new_grid_tech/biggrid.cpp
35-
new_grid_tech/divide_info.cpp
36-
new_grid_tech/gint_atom.cpp
37-
new_grid_tech/gint_info.cpp
38-
new_grid_tech/gint.cpp
39-
new_grid_tech/gint_vl.cpp
40-
new_grid_tech/gint_vl_metagga.cpp
41-
new_grid_tech/gint_vl_nspin4.cpp
42-
new_grid_tech/gint_vl_metagga_nspin4.cpp
43-
new_grid_tech/gint_rho.cpp
44-
new_grid_tech/gint_tau.cpp
45-
new_grid_tech/gint_fvl.cpp
46-
new_grid_tech/gint_fvl_meta.cpp
47-
new_grid_tech/localcell_info.cpp
48-
new_grid_tech/phi_operator.cpp
49-
new_grid_tech/set_ddphi.cpp
50-
new_grid_tech/unitcell_info.cpp
51-
new_grid_tech/gint_common.cpp
52-
new_grid_tech/gint_interface.cpp
53-
)
32+
if(NEW_GINT)
33+
list(APPEND objects
34+
new_grid_tech/biggrid_info.cpp
35+
new_grid_tech/biggrid.cpp
36+
new_grid_tech/divide_info.cpp
37+
new_grid_tech/gint_atom.cpp
38+
new_grid_tech/gint_info.cpp
39+
new_grid_tech/gint.cpp
40+
new_grid_tech/gint_vl.cpp
41+
new_grid_tech/gint_vl_metagga.cpp
42+
new_grid_tech/gint_vl_nspin4.cpp
43+
new_grid_tech/gint_vl_metagga_nspin4.cpp
44+
new_grid_tech/gint_rho.cpp
45+
new_grid_tech/gint_tau.cpp
46+
new_grid_tech/gint_fvl.cpp
47+
new_grid_tech/gint_fvl_meta.cpp
48+
new_grid_tech/localcell_info.cpp
49+
new_grid_tech/phi_operator.cpp
50+
new_grid_tech/set_ddphi.cpp
51+
new_grid_tech/unitcell_info.cpp
52+
new_grid_tech/gint_common.cpp
53+
new_grid_tech/gint_interface.cpp
54+
)
55+
endif()
5456

5557
if(USE_CUDA)
5658
list(APPEND objects

0 commit comments

Comments
 (0)