Skip to content

Commit c6f8609

Browse files
A-006mohanchen
andauthored
Replace GlobalC in module_gint (#4164)
* replace ParaV in module gint * change PV to pv in module gint * change GlobalC in module gint * fix LCAO_Orbitals in module gint * fix error in compile without abacus * fix error in init_gpu_gint_variables * remove GlobalC in grid_technique and grid_bigcell * remove GlobalC in gint_tools and vbatch matrix --------- Co-authored-by: Mohan Chen <[email protected]>
1 parent edb2d1c commit c6f8609

30 files changed

+434
-353
lines changed

source/module_elecstate/elecstate_lcao_tddft.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "module_base/timer.h"
66
#include "module_hamilt_lcao/module_gint/grid_technique.h"
77
#include "module_hamilt_pw/hamilt_pwdft/global.h"
8-
98
namespace elecstate
109
{
1110

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ void ESolver_KS_LCAO<TK, TR>::set_matrix_grid(Record_adj& ra)
6464
this->pw_big->nbzp,
6565
this->pw_rho->ny,
6666
this->pw_rho->nplane,
67-
this->pw_rho->startz_current);
67+
this->pw_rho->startz_current,
68+
GlobalC::ucell,
69+
GlobalC::ORB);
6870

6971
// (2)For each atom, calculate the adjacent atoms in different cells
7072
// and allocate the space for H(R) and S(R).

source/module_hamilt_lcao/hamilt_lcaodft/grid_init.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void grid_prepare(
1717
{
1818
ModuleBase::TITLE("LCAO_domain","grid_prepare");
1919
ModuleBase::timer::tick("LCAO_domain","grid_prepare");
20-
20+
const UnitCell* ucell = &GlobalC::ucell;
21+
const LCAO_Orbitals* orb = &GlobalC::ORB;
2122
if(GlobalV::GAMMA_ONLY_LOCAL)
2223
{
2324
gint_gamma.prep_grid(
@@ -34,7 +35,9 @@ void grid_prepare(
3435
bigpw.nbxx,
3536
rhopw.ny,
3637
rhopw.nplane,
37-
rhopw.startz_current);
38+
rhopw.startz_current,
39+
ucell,
40+
orb);
3841
}
3942
else // multiple k-points
4043
{
@@ -53,7 +56,9 @@ void grid_prepare(
5356
bigpw.nbxx,
5457
rhopw.ny,
5558
rhopw.nplane,
56-
rhopw.startz_current);
59+
rhopw.startz_current,
60+
ucell,
61+
orb);
5762
}
5863

5964
ModuleBase::timer::tick("LCAO_domain","grid_prepare");

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "module_base/timer.h"
33
#include "module_base/tool_title.h"
44
#include "module_hamilt_general/module_xc/xc_functional.h"
5-
5+
#include "module_cell/unitcell.h"
66
namespace hamilt
77
{
88

@@ -112,8 +112,7 @@ void Veff<OperatorLCAO<TK, TR>>::contributeHR()
112112
}
113113
}
114114
}
115-
116-
this->GK->transfer_pvpR(this->hR);
115+
this->GK->transfer_pvpR(this->hR,this->ucell,GlobalC::ORB,this->gd);
117116

118117
ModuleBase::timer::tick("Veff", "contributeHR");
119118
return;
@@ -148,7 +147,7 @@ void Veff<OperatorLCAO<double, double>>::contributeHR(void)
148147
Gint_inout inout(vr_eff1, Gint_Tools::job_type::vlocal);
149148
this->GG->cal_vlocal(&inout, this->new_e_iteration);
150149
}
151-
this->GG->transfer_pvpR(this->hR);
150+
this->GG->transfer_pvpR(this->hR,this->ucell,GlobalC::ORB);
152151

153152
this->new_e_iteration = false;
154153
ModuleBase::timer::tick("Veff", "contributeHR");

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/veff_lcao.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
4848
: GK(GK_in),
4949
loc(loc_in),
5050
pot(pot_in),
51+
ucell(ucell_in),
52+
gd(GridD_in),
5153
OperatorLCAO<TK, TR>(LM_in, kvec_d_in, hR_in, hK_in)
5254
{
5355
this->cal_type = lcao_gint;
@@ -74,7 +76,6 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
7476
OperatorLCAO<TK, TR>(LM_in, kvec_d_in, hR_in, hK_in)
7577
{
7678
this->cal_type = lcao_gint;
77-
7879
this->initialize_HR(ucell_in, GridD_in, paraV);
7980

8081
GG_in->initialize_pvpR(*ucell_in, GridD_in);
@@ -89,7 +90,9 @@ class Veff<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
8990
* grid integration is used to calculate the contribution Hamiltonian of effective potential
9091
*/
9192
virtual void contributeHR() override;
92-
93+
94+
const UnitCell* ucell;
95+
Grid_Driver* gd;
9396
private:
9497
// used for k-dependent grid integration.
9598
Gint_k* GK = nullptr;

source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void sparse_format::cal_dH(
4242
delete[] lm.DHloc_fixedR_y;
4343
delete[] lm.DHloc_fixedR_z;
4444

45-
gint_k.cal_dvlocal_R_sparseMatrix(current_spin, sparse_thr, &lm, lm.ParaV);
45+
gint_k.cal_dvlocal_R_sparseMatrix(current_spin, sparse_thr, &lm, lm.ParaV,GlobalC::ORB,GlobalC::ucell,GlobalC::GridD);
4646

4747
return;
4848
}

source/module_hamilt_lcao/module_gint/gint.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ void Gint::cal_gint(Gint_inout* inout)
6767
ModuleBase::TITLE("Gint_interface","cal_gint_force_meta");
6868
ModuleBase::timer::tick("Gint_interface","cal_gint_force_meta");
6969
}
70-
70+
const UnitCell& ucell = *this->ucell;
71+
const LCAO_Orbitals& orb = *this->orb;
7172
const int max_size = this->gridt->max_atom;
72-
const int LD_pool = max_size * GlobalC::ucell.nwmax;
73+
const int LD_pool = max_size * ucell.nwmax;
7374
const int lgd = this->gridt->lgd;
7475
const int nnrg = this->gridt->nnrg;
7576

@@ -86,21 +87,21 @@ void Gint::cal_gint(Gint_inout* inout)
8687
ylmcoef[i] = ModuleBase::Ylm::ylmcoef[i];
8788
}
8889

89-
const int ntype = GlobalC::ORB.get_ntype();
90+
const int ntype = orb.get_ntype();
9091
double* rcut = new double[ntype];
9192
for (int it = 0; it < ntype; it++)
9293
{
93-
rcut[it] = GlobalC::ORB.Phi[it].getRcut();
94+
rcut[it] = orb.Phi[it].getRcut();
9495
}
9596

96-
const double dr = GlobalC::ORB.dr_uniform;
97+
const double dr = orb.dr_uniform;
9798

9899
if (inout->job == Gint_Tools::job_type::vlocal)
99100
{
100101
GintKernel::gint_gamma_vl_gpu(this->hRGint,
101102
lgd,
102103
max_size,
103-
GlobalC::ucell.omega
104+
ucell.omega
104105
/ this->ncxyz,
105106
inout->vl,
106107
ylmcoef,
@@ -109,7 +110,7 @@ void Gint::cal_gint(Gint_inout* inout)
109110
dr,
110111
rcut,
111112
*this->gridt,
112-
GlobalC::ucell);
113+
ucell);
113114
}
114115
else if (inout->job == Gint_Tools::job_type::rho)
115116
{
@@ -123,17 +124,17 @@ void Gint::cal_gint(Gint_inout* inout)
123124
dr,
124125
rcut,
125126
*this->gridt,
126-
GlobalC::ucell,
127+
ucell,
127128
inout->rho[is]);
128129
}
129130
}
130131
else if (inout->job == Gint_Tools::job_type::force)
131132
{
132133
const int ncyz = this->ny * this->nplane;
133-
int nat = GlobalC::ucell.nat;
134+
int nat = ucell.nat;
134135
// for (int is = 0; is < GlobalV::NSPIN; ++is)
135136
// {
136-
double *force = new double[GlobalC::ucell.nat * 3];
137+
double *force = new double[ucell.nat * 3];
137138
for (int i = 0; i < nat * 3; i++)
138139
{
139140
force[i] = 0.0;
@@ -144,7 +145,7 @@ void Gint::cal_gint(Gint_inout* inout)
144145
stress[i] = 0.0;
145146
}
146147
GintKernel::gint_gamma_force_gpu(this->DMRGint[inout->ispin],
147-
GlobalC::ucell.omega
148+
ucell.omega
148149
/ this->ncxyz,
149150
inout->vl,
150151
force,
@@ -153,7 +154,7 @@ void Gint::cal_gint(Gint_inout* inout)
153154
dr,
154155
rcut,
155156
*this->gridt,
156-
GlobalC::ucell);
157+
ucell);
157158
for (int iat = 0; iat < nat; iat++)
158159
{
159160
inout->fvl_dphi[0](iat, 0) += force[iat * 3];
@@ -187,11 +188,11 @@ void Gint::cal_gint(Gint_inout* inout)
187188
// prepare some constants
188189
const int ncyz
189190
= this->ny * this->nplane; // mohan add 2012-03-25
190-
const double dv = GlobalC::ucell.omega / this->ncxyz;
191+
const double dv = ucell.omega / this->ncxyz;
191192

192193
// it's a uniform grid to save orbital values, so the delta_r is
193194
// a constant.
194-
const double delta_r = GlobalC::ORB.dr_uniform;
195+
const double delta_r = orb.dr_uniform;
195196

196197
if((inout->job==Gint_Tools::job_type::vlocal
197198
|| inout->job==Gint_Tools::job_type::vlocal_meta)
@@ -293,14 +294,14 @@ void Gint::cal_gint(Gint_inout* inout)
293294
//int* vindex = Gint_Tools::get_vindex(ncyz, ibx, jby, kbz);
294295
int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
295296
this->nplane, this->gridt->start_ind[grid_index], ncyz);
296-
this->gint_kernel_rho(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
297+
this->gint_kernel_rho(na_grid, grid_index, delta_r, vindex, LD_pool, ucell,inout);
297298
delete[] vindex;
298299
}
299300
else if(inout->job == Gint_Tools::job_type::tau)
300301
{
301302
int* vindex = Gint_Tools::get_vindex(this->bxyz, this->bx, this->by, this->bz,
302303
this->nplane, this->gridt->start_ind[grid_index], ncyz);
303-
this->gint_kernel_tau(na_grid, grid_index, delta_r, vindex, LD_pool, inout);
304+
this->gint_kernel_tau(na_grid, grid_index, delta_r, vindex, LD_pool, inout,ucell);
304305
delete[] vindex;
305306
}
306307
else if(inout->job == Gint_Tools::job_type::force)
@@ -322,11 +323,11 @@ void Gint::cal_gint(Gint_inout* inout)
322323
#ifdef _OPENMP
323324
this->gint_kernel_force(na_grid, grid_index, delta_r, vldr3, LD_pool,
324325
DM_in, inout->ispin, inout->isforce, inout->isstress,
325-
&fvl_dphi_thread, &svl_dphi_thread);
326+
&fvl_dphi_thread, &svl_dphi_thread,ucell);
326327
#else
327328
this->gint_kernel_force(na_grid, grid_index, delta_r, vldr3, LD_pool,
328329
DM_in, inout->ispin, inout->isforce, inout->isstress,
329-
inout->fvl_dphi, inout->svl_dphi);
330+
inout->fvl_dphi, inout->svl_dphi,ucell);
330331
#endif
331332
delete[] vldr3;
332333
}
@@ -338,17 +339,17 @@ void Gint::cal_gint(Gint_inout* inout)
338339
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
339340
{
340341
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
341-
pvpR_thread, hRGint_thread);
342+
pvpR_thread,ucell,hRGint_thread);
342343
}
343344
#else
344345
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
345346
{
346-
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool, nullptr);
347+
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,ucell,nullptr);
347348
}
348349
if(!GlobalV::GAMMA_ONLY_LOCAL)
349350
{
350351
this->gint_kernel_vlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
351-
this->pvpR_reduced[inout->ispin]);
352+
ucell,this->pvpR_reduced[inout->ispin]);
352353
}
353354
#endif
354355
delete[] vldr3;
@@ -359,12 +360,13 @@ void Gint::cal_gint(Gint_inout* inout)
359360
this->nplane, this->gridt->start_ind[grid_index], ncyz, dv);
360361
#ifdef _OPENMP
361362
this->gint_kernel_dvlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
362-
pvdpRx_thread, pvdpRy_thread, pvdpRz_thread);
363+
pvdpRx_thread, pvdpRy_thread, pvdpRz_thread,ucell);
363364
#else
364365
this->gint_kernel_dvlocal(na_grid, grid_index, delta_r, vldr3, LD_pool,
365366
this->pvdpRx_reduced[inout->ispin],
366367
this->pvdpRy_reduced[inout->ispin],
367-
this->pvdpRz_reduced[inout->ispin]);
368+
this->pvdpRz_reduced[inout->ispin],
369+
ucell);
368370
#endif
369371
delete[] vldr3;
370372
}
@@ -378,16 +380,16 @@ void Gint::cal_gint(Gint_inout* inout)
378380
if((GlobalV::GAMMA_ONLY_LOCAL && lgd>0) || !GlobalV::GAMMA_ONLY_LOCAL)
379381
{
380382
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
381-
pvpR_thread, hRGint_thread);
383+
pvpR_thread, ucell,hRGint_thread);
382384
}
383385
#else
384386
if(GlobalV::GAMMA_ONLY_LOCAL && lgd>0)
385387
{
386-
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool, nullptr);
388+
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool, ucell,nullptr);
387389
}
388390
if(!GlobalV::GAMMA_ONLY_LOCAL)
389391
{
390-
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
392+
this->gint_kernel_vlocal_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,ucell,
391393
this->pvpR_reduced[inout->ispin]);
392394
}
393395
#endif
@@ -415,11 +417,11 @@ void Gint::cal_gint(Gint_inout* inout)
415417
#ifdef _OPENMP
416418
this->gint_kernel_force_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
417419
DM_in, inout->ispin, inout->isforce, inout->isstress,
418-
&fvl_dphi_thread, &svl_dphi_thread);
420+
&fvl_dphi_thread, &svl_dphi_thread,ucell);
419421
#else
420422
this->gint_kernel_force_meta(na_grid, grid_index, delta_r, vldr3, vkdr3, LD_pool,
421423
DM_in, inout->ispin, inout->isforce, inout->isstress,
422-
inout->fvl_dphi, inout->svl_dphi);
424+
inout->fvl_dphi, inout->svl_dphi,ucell);
423425
#endif
424426
delete[] vldr3;
425427
delete[] vkdr3;
@@ -504,7 +506,9 @@ void Gint::prep_grid(const Grid_Technique& gt,
504506
const int& nbxx_in,
505507
const int& ny_in,
506508
const int& nplane_in,
507-
const int& startz_current_in)
509+
const int& startz_current_in,
510+
const UnitCell* ucell_in,
511+
const LCAO_Orbitals* orb_in)
508512
{
509513
ModuleBase::TITLE(GlobalV::ofs_running, "Gint_k", "prep_grid");
510514

@@ -522,6 +526,9 @@ void Gint::prep_grid(const Grid_Technique& gt,
522526
this->ny = ny_in;
523527
this->nplane = nplane_in;
524528
this->startz_current = startz_current_in;
529+
this->ucell= ucell_in;
530+
this->orb = orb_in;
531+
525532
assert(nbx > 0);
526533
assert(nby > 0);
527534
assert(nbz >= 0);
@@ -534,8 +541,7 @@ void Gint::prep_grid(const Grid_Technique& gt,
534541
assert(ny > 0);
535542
assert(nplane >= 0);
536543
assert(startz_current >= 0);
537-
538-
assert(GlobalC::ucell.omega > 0.0);
544+
assert(this->ucell->omega > 0.0);
539545

540546
return;
541547
}
@@ -640,15 +646,15 @@ void Gint::initialize_pvpR(const UnitCell& ucell_in, Grid_Driver* gd)
640646
{
641647
ModuleBase::Vector3<double> dtau = gd->getAdjacentTau(ad) - tau1;
642648
double distance = dtau.norm() * ucell_in.lat0;
643-
double rcut = GlobalC::ORB.Phi[T1].getRcut() + GlobalC::ORB.Phi[T2].getRcut();
649+
double rcut = this->orb->Phi[T1].getRcut() + this->orb->Phi[T2].getRcut();
644650

645651
//if(distance < rcut)
646652
// mohan reset this 2013-07-02 in Princeton
647-
// we should make absolutely sure that the distance is smaller than GlobalC::ORB.Phi[it].getRcut
653+
// we should make absolutely sure that the distance is smaller than orb.Phi[it].getRcut
648654
// this should be consistant with LCAO_nnr::cal_nnrg function
649655
// typical example : 7 Bohr cutoff Si orbital in 14 Bohr length of cell.
650656
// distance = 7.0000000000000000
651-
// GlobalC::ORB.Phi[it].getRcut = 7.0000000000000008
657+
// orb.Phi[it].getRcut = 7.0000000000000008
652658
if(distance < rcut - 1.0e-15)
653659
{
654660
// calculate R index

0 commit comments

Comments
 (0)