Skip to content

Commit 7fdb1a3

Browse files
authored
remove nspin dependence form Gint (#5304)
1 parent f636d74 commit 7fdb1a3

File tree

17 files changed

+96
-79
lines changed

17 files changed

+96
-79
lines changed

source/module_elecstate/elecstate_lcao.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void ElecStateLCAO<std::complex<double>>::psiToRho(const psi::Psi<std::complex<d
6262

6363
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
6464
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
65-
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho);
65+
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
6666
this->gint_k->cal_gint(&inout);
6767

6868
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
@@ -113,7 +113,7 @@ void ElecStateLCAO<double>::psiToRho(const psi::Psi<double>& psi)
113113

114114
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
115115

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

118118
this->gint_gamma->cal_gint(&inout);
119119

@@ -178,7 +178,7 @@ void ElecStateLCAO<double>::dmToRho(std::vector<double*> pexsi_DM, std::vector<d
178178

179179
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
180180
this->gint_gamma->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
181-
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho);
181+
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
182182
this->gint_gamma->cal_gint(&inout);
183183
if (XC_Functional::get_func_type() == 3 || XC_Functional::get_func_type() == 5)
184184
{

source/module_elecstate/elecstate_lcao_cal_tau.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void ElecStateLCAO<std::complex<double>>::cal_tau(const psi::Psi<std::complex<do
1515
{
1616
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
1717
}
18-
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
18+
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
1919
this->gint_k->cal_gint(&inout1);
2020

2121
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");
@@ -32,7 +32,7 @@ void ElecStateLCAO<double>::cal_tau(const psi::Psi<double>& psi)
3232
{
3333
ModuleBase::GlobalFunc::ZEROS(this->charge->kin_r[is], this->charge->nrxx);
3434
}
35-
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau);
35+
Gint_inout inout1(this->charge->kin_r, Gint_Tools::job_type::tau, PARAM.inp.nspin);
3636
this->gint_gamma->cal_gint(&inout1);
3737

3838
ModuleBase::timer::tick("ElecStateLCAO", "cal_tau");

source/module_elecstate/elecstate_lcao_tddft.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void ElecStateLCAO_TDDFT::psiToRho_td(const psi::Psi<std::complex<double>>& psi)
3636

3737
ModuleBase::GlobalFunc::NOTE("Calculate the charge on real space grid!");
3838
this->gint_k->transfer_DM2DtoGrid(this->DM->get_DMR_vector()); // transfer DM2D to DM_grid in gint
39-
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho); // rho calculation
39+
Gint_inout inout(this->charge->rho, Gint_Tools::job_type::rho, PARAM.inp.nspin); // rho calculation
4040
this->gint_k->cal_gint(&inout);
4141

4242
this->charge->renormalize_rho();

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
174174
pot_in->pot_register(pot_register_in);
175175
// effective potential term
176176
Operator<TK>* veff = new Veff<OperatorLCAO<TK, TR>>(GG_in,
177-
this->hsk,
178-
this->kv->kvec_d,
179-
pot_in,
180-
this->hR, // no explicit call yet
181-
&GlobalC::ucell,
182-
orb.cutoffs(),
183-
&GlobalC::GridD
177+
this->hsk,
178+
this->kv->kvec_d,
179+
pot_in,
180+
this->hR, // no explicit call yet
181+
&GlobalC::ucell,
182+
orb.cutoffs(),
183+
&GlobalC::GridD,
184+
PARAM.inp.nspin
184185
);
185186
this->getOperator()->add(veff);
186187
}
@@ -242,13 +243,14 @@ HamiltLCAO<TK, TR>::HamiltLCAO(Gint_Gamma* GG_in,
242243
pot_in->pot_register(pot_register_in);
243244
// Veff term
244245
this->getOperator() = new Veff<OperatorLCAO<TK, TR>>(GK_in,
245-
this->hsk,
246-
kv->kvec_d,
247-
pot_in,
248-
this->hR,
249-
&GlobalC::ucell,
250-
orb.cutoffs(),
251-
&GlobalC::GridD);
246+
this->hsk,
247+
kv->kvec_d,
248+
pot_in,
249+
this->hR,
250+
&GlobalC::ucell,
251+
orb.cutoffs(),
252+
&GlobalC::GridD,
253+
PARAM.inp.nspin);
252254
// reset spin index and real space Hamiltonian matrix
253255
int start_spin = -1;
254256
GK_in->reset_spin(start_spin);

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,41 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
3636
* @param GK_in: the pointer of Gint_k object, used for grid integration
3737
*/
3838
Veff<OperatorLCAO<TK, TR>>(Gint_k* GK_in,
39-
HS_Matrix_K<TK>* hsk_in,
40-
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
41-
elecstate::Potential* pot_in,
42-
hamilt::HContainer<TR>* hR_in,
43-
const UnitCell* ucell_in,
44-
const std::vector<double>& orb_cutoff,
45-
Grid_Driver* GridD_in)
39+
HS_Matrix_K<TK>* hsk_in,
40+
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
41+
elecstate::Potential* pot_in,
42+
hamilt::HContainer<TR>* hR_in,
43+
const UnitCell* ucell_in,
44+
const std::vector<double>& orb_cutoff,
45+
Grid_Driver* GridD_in,
46+
const int& nspin)
4647
: GK(GK_in), orb_cutoff_(orb_cutoff), pot(pot_in), ucell(ucell_in),
4748
gd(GridD_in), OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in)
4849
{
4950
this->cal_type = calculation_type::lcao_gint;
5051

5152
this->initialize_HR(ucell_in, GridD_in);
52-
GK_in->initialize_pvpR(*ucell_in, GridD_in);
53+
GK_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
5354
}
5455
/**
5556
* @brief Construct a new Veff object for Gamma-only calculation
5657
* @param GG_in: the pointer of Gint_Gamma object, used for grid integration
5758
*/
5859
Veff<OperatorLCAO<TK, TR>>(Gint_Gamma* GG_in,
59-
HS_Matrix_K<TK>* hsk_in,
60-
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
61-
elecstate::Potential* pot_in,
62-
hamilt::HContainer<TR>* hR_in,
63-
const UnitCell* ucell_in,
64-
const std::vector<double>& orb_cutoff,
65-
Grid_Driver* GridD_in)
60+
HS_Matrix_K<TK>* hsk_in,
61+
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
62+
elecstate::Potential* pot_in,
63+
hamilt::HContainer<TR>* hR_in,
64+
const UnitCell* ucell_in,
65+
const std::vector<double>& orb_cutoff,
66+
Grid_Driver* GridD_in,
67+
const int& nspin)
6668
: GG(GG_in), orb_cutoff_(orb_cutoff), pot(pot_in), OperatorLCAO<TK, TR>(hsk_in, kvec_d_in, hR_in)
6769
{
6870
this->cal_type = calculation_type::lcao_gint;
6971
this->initialize_HR(ucell_in, GridD_in);
7072

71-
GG_in->initialize_pvpR(*ucell_in, GridD_in);
73+
GG_in->initialize_pvpR(*ucell_in, GridD_in, nspin);
7274
}
7375

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

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,15 @@ void Gint::prep_grid(const Grid_Technique& gt,
133133
return;
134134
}
135135

136-
void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
136+
void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd, const int& nspin) {
137137
ModuleBase::TITLE("Gint", "initialize_pvpR");
138138

139139
int npol = 1;
140140
// there is the only resize code of DMRGint
141141
if (this->DMRGint.size() == 0) {
142-
this->DMRGint.resize(PARAM.inp.nspin);
142+
this->DMRGint.resize(nspin);
143143
}
144-
if (PARAM.inp.nspin != 4) {
144+
if (nspin != 4) {
145145
if (this->hRGint != nullptr) {
146146
delete this->hRGint;
147147
}
@@ -153,7 +153,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
153153
}
154154
this->hRGintCd
155155
= new hamilt::HContainer<std::complex<double>>(ucell_in.nat);
156-
for (int is = 0; is < PARAM.inp.nspin; is++) {
156+
for (int is = 0; is < nspin; is++) {
157157
if (this->DMRGint[is] != nullptr) {
158158
delete this->DMRGint[is];
159159
}
@@ -186,7 +186,7 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
186186
}
187187
}
188188

189-
if (PARAM.globalv.gamma_only_local && PARAM.inp.nspin != 4) {
189+
if (PARAM.globalv.gamma_only_local && nspin != 4) {
190190
this->hRGint->fix_gamma();
191191
}
192192
for (int T1 = 0; T1 < ucell_in.ntype; ++T1) {
@@ -321,6 +321,26 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd) {
321321
}
322322
}
323323

324+
void Gint::reset_DMRGint(const int& nspin)
325+
{
326+
if (this->hRGint)
327+
{
328+
for (auto& d : this->DMRGint) { delete d; }
329+
this->DMRGint.resize(nspin);
330+
this->DMRGint.shrink_to_fit();
331+
for (auto& d : this->DMRGint) { d = new hamilt::HContainer<double>(*this->hRGint); }
332+
if (nspin == 4)
333+
{
334+
for (auto& d : this->DMRGint) { d->allocate(nullptr, false); }
335+
#ifdef __MPI
336+
delete this->DMRGint_full;
337+
this->DMRGint_full = new hamilt::HContainer<double>(*this->hRGint);
338+
this->DMRGint_full->allocate(nullptr, false);
339+
#endif
340+
}
341+
}
342+
}
343+
324344
void Gint::transfer_DM2DtoGrid(std::vector<hamilt::HContainer<double>*> DM2D) {
325345
ModuleBase::TITLE("Gint", "transfer_DMR");
326346

source/module_hamilt_lcao/module_gint/gint.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ class Gint {
4949
* @brief calculate the neighbor atoms of each atom in this processor
5050
* size of BaseMatrix with be the non-parallel version
5151
*/
52-
void initialize_pvpR(const UnitCell& unitcell, Grid_Driver* gd);
52+
void initialize_pvpR(const UnitCell& unitcell, Grid_Driver* gd, const int& nspin);
53+
54+
/**
55+
* @brief resize DMRGint to nspin and reallocate the memory
56+
*/
57+
void reset_DMRGint(const int& nspin);
5358

5459
/**
5560
* @brief transfer DMR (2D para) to DMR (Grid para) in elecstate_lcao.cpp

source/module_hamilt_lcao/module_gint/gint_rho_cpu_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void Gint::gint_kernel_rho(Gint_inout* inout) {
5454
cal_flag.get_ptr_2D(),
5555
psir_ylm.get_ptr_2D());
5656

57-
for (int is = 0; is < PARAM.inp.nspin; ++is)
57+
for (int is = 0; is < inout->nspin_rho; ++is)
5858
{
5959
ModuleBase::Array_Pool<double> psir_DM(this->bxyz, LD_pool);
6060
ModuleBase::GlobalFunc::ZEROS(psir_DM.get_ptr_1D(), this->bxyz * LD_pool);

source/module_hamilt_lcao/module_gint/gint_tools.h

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Gint_inout
3939
bool isforce;
4040
bool isstress;
4141
int ispin;
42+
int nspin_rho; // usually, but not always, equal to global nspin
4243
bool if_symm = false; // if true, use dsymv in gint_kernel_rho; if false, use dgemv.
4344

4445
// output
@@ -48,10 +49,11 @@ class Gint_inout
4849
Gint_Tools::job_type job;
4950

5051
// electron density and kin_r, multi-k
51-
Gint_inout(double** rho_in, Gint_Tools::job_type job_in, bool if_symm_in = true)
52+
Gint_inout(double** rho_in, Gint_Tools::job_type job_in, const int& nspin_rho_in, bool if_symm_in = true)
5253
{
5354
rho = rho_in;
5455
job = job_in;
56+
nspin_rho = nspin_rho_in;
5557
if_symm = if_symm_in;
5658
}
5759

@@ -110,15 +112,6 @@ class Gint_inout
110112
job = job_in;
111113
}
112114

113-
// electron density and kin_r, gamma point
114-
Gint_inout(double*** DM_in, double** rho_in, Gint_Tools::job_type job_in, bool if_symm_in = true)
115-
{
116-
DM = DM_in;
117-
rho = rho_in;
118-
job = job_in;
119-
if_symm = if_symm_in;
120-
}
121-
122115
// vlocal, gamma point
123116
Gint_inout(const double* vl_in, Gint_Tools::job_type job_in)
124117
{

source/module_io/get_pchg_lcao.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ void IState_Charge::begin(Gint_Gamma& gg,
104104

105105
DM.init_DMR(GridD_in, ucell_in);
106106
DM.cal_DMR();
107-
gg.initialize_pvpR(*ucell_in, GridD_in);
107+
gg.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
108108
gg.transfer_DM2DtoGrid(DM.get_DMR_vector());
109-
Gint_inout inout((double***)nullptr, rho, Gint_Tools::job_type::rho);
109+
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
110110
gg.cal_gint(&inout);
111111

112112
// A solution to replace the original implementation of the following code:
@@ -243,9 +243,9 @@ void IState_Charge::begin(Gint_k& gk,
243243

244244
DM.init_DMR(GridD_in, ucell_in);
245245
DM.cal_DMR(ik);
246-
gk.initialize_pvpR(*ucell_in, GridD_in);
246+
gk.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
247247
gk.transfer_DM2DtoGrid(DM.get_DMR_vector());
248-
Gint_inout inout(rho, Gint_Tools::job_type::rho);
248+
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
249249
gk.cal_gint(&inout);
250250

251251
// Using std::vector to replace the original double** rho_save
@@ -298,9 +298,9 @@ void IState_Charge::begin(Gint_k& gk,
298298

299299
DM.init_DMR(GridD_in, ucell_in);
300300
DM.cal_DMR();
301-
gk.initialize_pvpR(*ucell_in, GridD_in);
301+
gk.initialize_pvpR(*ucell_in, GridD_in, PARAM.inp.nspin);
302302
gk.transfer_DM2DtoGrid(DM.get_DMR_vector());
303-
Gint_inout inout(rho, Gint_Tools::job_type::rho);
303+
Gint_inout inout(rho, Gint_Tools::job_type::rho, PARAM.inp.nspin);
304304
gk.cal_gint(&inout);
305305

306306
// Using std::vector to replace the original double** rho_save

0 commit comments

Comments
 (0)