Skip to content

Commit 985c069

Browse files
committed
fully support new gint module
1 parent 430d1e5 commit 985c069

File tree

8 files changed

+103
-54
lines changed

8 files changed

+103
-54
lines changed

source/module_esolver/lcao_before_scf.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
6969
Gint_Tools::init_orb(dr_uniform, rcuts, ucell, orb_, psi_u, dpsi_u, d2psi_u);
7070

7171
//! 5) set periodic boundary conditions
72+
#ifndef __NEW_GINT
7273
this->GridT.set_pbc_grid(this->pw_rho->nx,
7374
this->pw_rho->ny,
7475
this->pw_rho->nz,
@@ -92,9 +93,17 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
9293
dpsi_u,
9394
d2psi_u,
9495
PARAM.inp.nstream);
96+
97+
psi_u.clear();
98+
psi_u.shrink_to_fit();
99+
dpsi_u.clear();
100+
dpsi_u.shrink_to_fit();
101+
d2psi_u.clear();
102+
d2psi_u.shrink_to_fit();
103+
LCAO_domain::grid_prepare(this->GridT, this->GG, this->GK, ucell, orb_, *this->pw_rho, *this->pw_big);
95104

96105
//! 6) prepare grid integral
97-
#ifdef __NEW_GINT
106+
#else
98107
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
99108
this->pw_big->nbx,
100109
this->pw_big->nby,
@@ -114,22 +123,12 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
114123
ModuleGint::Gint::set_gint_info(gint_info);
115124
#endif
116125

117-
psi_u.clear();
118-
psi_u.shrink_to_fit();
119-
dpsi_u.clear();
120-
dpsi_u.shrink_to_fit();
121-
d2psi_u.clear();
122-
d2psi_u.shrink_to_fit();
123-
124126
// 7) For each atom, calculate the adjacent atoms in different cells
125127
// and allocate the space for H(R) and S(R).
126128
// If k point is used here, allocate HlocR after atom_arrange.
127129
this->RA.for_2d(ucell, this->gd, this->pv, PARAM.globalv.gamma_only_local, orb_.cutoffs());
128130

129-
// 8) after ions move, prepare grid in Gint
130-
LCAO_domain::grid_prepare(this->GridT, this->GG, this->GK, ucell, orb_, *this->pw_rho, *this->pw_big);
131-
132-
// 9) initialize the Hamiltonian operators
131+
// 8) initialize the Hamiltonian operators
133132
// if atom moves, then delete old pointer and add a new one
134133
if (this->p_hamilt != nullptr)
135134
{
@@ -169,7 +168,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
169168

170169

171170
#ifdef __MLALGO
172-
// 10) for each ionic step, the overlap <phi|alpha> must be rebuilt
171+
// 9) for each ionic step, the overlap <phi|alpha> must be rebuilt
173172
// since it depends on ionic positions
174173
if (PARAM.globalv.deepks_setorb)
175174
{
@@ -198,7 +197,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
198197
}
199198
#endif
200199

201-
// 11) prepare sc calculation
200+
// 10) prepare sc calculation
202201
if (PARAM.inp.sc_mag_switch)
203202
{
204203
spinconstrain::SpinConstrain<TK>& sc = spinconstrain::SpinConstrain<TK>::getScInstance();
@@ -217,7 +216,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
217216
this->pelec);
218217
}
219218

220-
// 12) set xc type before the first cal of xc in pelec->init_scf
219+
// 11) set xc type before the first cal of xc in pelec->init_scf
221220
// Peize Lin add 2016-12-03
222221
#ifdef __EXX
223222
if (PARAM.inp.calculation != "nscf")
@@ -233,10 +232,10 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
233232
}
234233
#endif
235234

236-
// 13) init_scf, should be before_scf? mohan add 2025-03-10
235+
// 12) init_scf, should be before_scf? mohan add 2025-03-10
237236
this->pelec->init_scf(istep, ucell, this->Pgrid, this->sf.strucFac, this->locpp.numeric, ucell.symm);
238237

239-
// 14) initalize DMR
238+
// 13) initalize DMR
240239
// DMR should be same size with Hamiltonian(R)
241240
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)
242241
->get_DM()
@@ -247,26 +246,26 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
247246
this->ld.init_DMR(ucell, orb_, this->pv, this->gd);
248247
#endif
249248

250-
// 15) two cases are considered:
249+
// 14) two cases are considered:
251250
// 1. DMK in DensityMatrix is not empty (istep > 0), then DMR is initialized by DMK
252251
// 2. DMK in DensityMatrix is empty (istep == 0), then DMR is initialized by zeros
253252
if (istep > 0)
254253
{
255254
dynamic_cast<elecstate::ElecStateLCAO<TK>*>(this->pelec)->get_DM()->cal_DMR();
256255
}
257256

258-
// 16) the electron charge density should be symmetrized,
257+
// 15) the electron charge density should be symmetrized,
259258
// here is the initialization
260259
Symmetry_rho srho;
261260
for (int is = 0; is < PARAM.inp.nspin; is++)
262261
{
263262
srho.begin(is, this->chr, this->pw_rho, ucell.symm);
264263
}
265264

266-
// 17) why we need to set this sentence? mohan add 2025-03-10
265+
// 16) why we need to set this sentence? mohan add 2025-03-10
267266
this->p_hamilt->non_first_scf = istep;
268267

269-
// 18) update of RDMFT, added by jghan
268+
// 17) update of RDMFT, added by jghan
270269
if (PARAM.inp.rdmft == true)
271270
{
272271
// necessary operation of these parameters have be done with p_esolver->Init() in source/driver_run.cpp

source/module_esolver/lcao_others.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
9393
PARAM.inp.test_atom_input);
9494

9595
// (3) Periodic condition search for each grid.
96+
#ifndef __NEW_GINT
9697
double dr_uniform = 0.001;
9798
std::vector<double> rcuts;
9899
std::vector<std::vector<double>> psi_u;
99100
std::vector<std::vector<double>> dpsi_u;
100101
std::vector<std::vector<double>> d2psi_u;
101102

102103
Gint_Tools::init_orb(dr_uniform, rcuts, ucell, orb_, psi_u, dpsi_u, d2psi_u);
103-
104104
this->GridT.set_pbc_grid(this->pw_rho->nx,
105105
this->pw_rho->ny,
106106
this->pw_rho->nz,
@@ -124,7 +124,16 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
124124
dpsi_u,
125125
d2psi_u,
126126
PARAM.inp.nstream);
127-
#ifdef __NEW_GINT
127+
128+
psi_u.clear();
129+
psi_u.shrink_to_fit();
130+
dpsi_u.clear();
131+
dpsi_u.shrink_to_fit();
132+
d2psi_u.clear();
133+
d2psi_u.shrink_to_fit();
134+
// prepare grid in Gint
135+
LCAO_domain::grid_prepare(this->GridT, this->GG, this->GK, ucell, orb_, *this->pw_rho, *this->pw_big);
136+
#else
128137
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
129138
this->pw_big->nbx,
130139
this->pw_big->nby,
@@ -142,14 +151,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
142151
ucell,
143152
this->gd);
144153
ModuleGint::Gint::set_gint_info(gint_info);
145-
#endif
146-
147-
psi_u.clear();
148-
psi_u.shrink_to_fit();
149-
dpsi_u.clear();
150-
dpsi_u.shrink_to_fit();
151-
d2psi_u.clear();
152-
d2psi_u.shrink_to_fit();
154+
#endif
153155

154156
// (2)For each atom, calculate the adjacent atoms in different cells
155157
// and allocate the space for H(R) and S(R).
@@ -206,9 +208,6 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
206208
}
207209
}
208210

209-
// prepare grid in Gint
210-
LCAO_domain::grid_prepare(this->GridT, this->GG, this->GK, ucell, orb_, *this->pw_rho, *this->pw_big);
211-
212211
// init Hamiltonian
213212
if (this->p_hamilt != nullptr)
214213
{

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
5050
this->cal_type = calculation_type::lcao_gint;
5151

5252
this->initialize_HR(ucell_in, GridD_in);
53+
#ifndef __NEW_GINT
5354
GK_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
55+
#endif
5456
}
5557
/**
5658
* @brief Construct a new Veff object for Gamma-only calculation
@@ -69,8 +71,9 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
6971
{
7072
this->cal_type = calculation_type::lcao_gint;
7173
this->initialize_HR(ucell_in, GridD_in);
72-
74+
#ifndef __NEW_GINT
7375
GG_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
76+
#endif
7477
}
7578

7679
~Veff<OperatorLCAO<TK, TR>>(){};

source/module_lr/esolver_lrtd_lcao.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
397397
this->gint_->gridt = &this->gt_;
398398

399399
// (3) Periodic condition search for each grid.
400+
#ifndef __NEW_GINT
400401
double dr_uniform = 0.001;
401402
std::vector<double> rcuts;
402403
std::vector<std::vector<double>> psi_u;
@@ -451,7 +452,25 @@ LR::ESolver_LR<T, TR>::ESolver_LR(const Input_para& inp, UnitCell& ucell) : inpu
451452
&ucell,
452453
&orb);
453454
this->gint_->initialize_pvpR(ucell, &this->gd, 1); // always use nspin=1 for transition density
454-
455+
#else
456+
auto gint_info = std::make_shared<ModuleGint::GintInfo>(
457+
this->pw_big->nbx,
458+
this->pw_big->nby,
459+
this->pw_big->nbz,
460+
this->pw_rho->nx,
461+
this->pw_rho->ny,
462+
this->pw_rho->nz,
463+
0,
464+
0,
465+
this->pw_big->nbzp_start,
466+
this->pw_big->nbx,
467+
this->pw_big->nby,
468+
this->pw_big->nbzp,
469+
orb.Phi,
470+
ucell,
471+
this->gd);
472+
ModuleGint::Gint::set_gint_info(gint_info);
473+
#endif
455474
// if EXX from scratch, init 2-center integral and calculate Cs, Vs
456475
#ifdef __EXX
457476
if ((xc_kernel == "hf" || xc_kernel == "hse") && this->input.lr_solver != "spectrum")

source/module_lr/esolver_lrtd_lcao.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "module_elecstate/module_dm/density_matrix.h"
1818
#include "module_lr/potentials/pot_hxc_lrtd.h"
1919
#include "module_lr/hamilt_casida.h"
20+
#include "module_hamilt_lcao/module_gint/temp_gint/gint.h"
2021
#ifdef __EXX
2122
// #include <RI/physics/Exx.h>
2223
#include "module_ri/Exx_LRI.h"
@@ -34,6 +35,9 @@ namespace LR
3435
ESolver_LR(const Input_para& inp, UnitCell& ucell);
3536
~ESolver_LR() {
3637
delete this->psi_ks;
38+
#ifdef __NEW_GINT
39+
ModuleGint::Gint::set_gint_info(nullptr);
40+
#endif
3741
}
3842

3943
///input: input, call, basis(LCAO), psi(ground state), elecstate

source/module_lr/lr_spectrum.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "module_lr/utils/lr_util.h"
77
#include "module_lr/utils/lr_util_hcontainer.h"
88
#include "module_lr/utils/lr_util_print.h"
9+
#include "module_hamilt_lcao/module_gint/temp_gint/gint_interface.h"
910

1011
template <typename T>
1112
elecstate::DensityMatrix<T, T> LR::LR_Spectrum<T>::cal_transition_density_matrix(const int istate, const T* X_in, const bool need_R)
@@ -34,14 +35,6 @@ elecstate::DensityMatrix<T, T> LR::LR_Spectrum<T>::cal_transition_density_matrix
3435
return DM_trans;
3536
}
3637

37-
template<typename T>
38-
void LR::LR_Spectrum<T>::cal_gint_rho(double** rho, const int& nrxx)
39-
{
40-
ModuleBase::GlobalFunc::ZEROS(rho[0], nrxx);
41-
Gint_inout inout_rho(rho, Gint_Tools::job_type::rho, 1, false);
42-
this->gint->cal_gint(&inout_rho);
43-
}
44-
4538
inline void check_sum_rule(const double& osc_tot)
4639
{
4740
if (std::abs(osc_tot - 1.0) > 1e-3) {
@@ -59,12 +52,16 @@ ModuleBase::Vector3<double> LR::LR_Spectrum<double>::cal_transition_dipole_istat
5952
const elecstate::DensityMatrix<double, double>& DM_trans = this->cal_transition_density_matrix(istate);
6053
for (int is = 0;is < this->nspin_x;++is)
6154
{
62-
this->gint->transfer_DM2DtoGrid({ DM_trans.get_DMR_vector().at(is) });
63-
6455
// 2. transition density
6556
double** rho_trans;
6657
LR_Util::_allocate_2order_nested_ptr(rho_trans, 1, this->rho_basis.nrxx);
58+
#ifndef __NEW_GINT
59+
this->gint->transfer_DM2DtoGrid({ DM_trans.get_DMR_vector().at(is) });
6760
this->cal_gint_rho(rho_trans, this->rho_basis.nrxx);
61+
#else
62+
ModuleBase::GlobalFunc::ZEROS(rho_trans[0], this->rho_basis.nrxx);
63+
ModuleGint::cal_gint_rho({ DM_trans.get_DMR_vector().at(is) }, 1, rho_trans);
64+
#endif
6865

6966
// 3. transition dipole moment
7067
for (int ir = 0; ir < rho_basis.nrxx; ++ir)
@@ -108,14 +105,24 @@ ModuleBase::Vector3<std::complex<double>> LR::LR_Spectrum<std::complex<double>>:
108105

109106
// real part
110107
LR_Util::get_DMR_real_imag_part(DM_trans, DM_trans_real_imag, ucell.nat, 'R');
108+
#ifndef __NEW_GINT
111109
this->gint->transfer_DM2DtoGrid(DM_trans_real_imag.get_DMR_vector());
112110
this->cal_gint_rho(rho_trans_real, this->rho_basis.nrxx);
111+
#else
112+
ModuleBase::GlobalFunc::ZEROS(rho_trans_real[0], this->rho_basis.nrxx);
113+
ModuleGint::cal_gint_rho(DM_trans_real_imag.get_DMR_vector(), 1, rho_trans_real);
114+
#endif
113115
// LR_Util::print_grid_nonzero(rho_trans_real[0], this->rho_basis.nrxx, 10, "rho_trans");
114116

115117
// imag part
116118
LR_Util::get_DMR_real_imag_part(DM_trans, DM_trans_real_imag, ucell.nat, 'I');
119+
#ifndef __NEW_GINT
117120
this->gint->transfer_DM2DtoGrid(DM_trans_real_imag.get_DMR_vector());
118121
this->cal_gint_rho(rho_trans_imag, this->rho_basis.nrxx);
122+
#else
123+
ModuleBase::GlobalFunc::ZEROS(rho_trans_imag[0], this->rho_basis.nrxx);
124+
ModuleGint::cal_gint_rho(DM_trans_real_imag.get_DMR_vector(), 1, rho_trans_imag);
125+
#endif
119126
// LR_Util::print_grid_nonzero(rho_trans_imag[0], this->rho_basis.nrxx, 10, "rho_trans");
120127

121128
// 3. transition dipole moment

0 commit comments

Comments
 (0)