Skip to content

Commit 9ec397f

Browse files
committed
change ucell in pwdft/VL_in_pw.cpp
1 parent adb8a2f commit 9ec397f

File tree

6 files changed

+45
-29
lines changed

6 files changed

+45
-29
lines changed

source/module_esolver/esolver_fp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void ESolver_FP::before_scf(UnitCell& ucell, const int istep)
281281
this->pw_rhod->collect_uniqgg();
282282
}
283283

284-
this->p_locpp->init_vloc(this->pw_rhod);
284+
this->p_locpp->init_vloc(ucell,this->pw_rhod);
285285
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
286286

287287
this->pelec->omega = ucell.omega;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
197197
}
198198

199199
// 8) initialize ppcell
200-
this->ppcell.init_vloc(this->pw_rho);
200+
this->ppcell.init_vloc(ucell,this->pw_rho);
201201
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
202202

203203
// 9) inititlize the charge density

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void ESolver_KS_PW<T, Device>::before_all_runners(UnitCell& ucell, const Input_p
205205
this->ppcell.init(ucell.ntype, &this->sf, this->pw_wfc);
206206

207207
//! initalize local pseudopotential
208-
this->ppcell.init_vloc(this->pw_rhod);
208+
this->ppcell.init_vloc(ucell,this->pw_rhod);
209209
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
210210

211211
//! Initalize non-local pseudopotential

source/module_esolver/esolver_of.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void ESolver_OF::before_all_runners(UnitCell& ucell, const Input_para& inp)
112112
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "INIT BASIS");
113113

114114
// initialize local pseudopotential
115-
this->locpp.init_vloc(pw_rho);
115+
this->locpp.init_vloc(ucell,pw_rho);
116116
ModuleBase::GlobalFunc::DONE(GlobalV::ofs_running, "LOCAL POTENTIAL");
117117

118118

source/module_hamilt_pw/hamilt_pwdft/VL_in_pw.cpp

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pseudopot_cell_vl::~pseudopot_cell_vl()
1717
delete[] zp;
1818
}
1919

20-
void pseudopot_cell_vl::init_vloc(const ModulePW::PW_Basis* rho_basis)
20+
void pseudopot_cell_vl::init_vloc(const UnitCell& ucell,
21+
const ModulePW::PW_Basis* rho_basis)
2122
{
2223
if(PARAM.inp.use_paw) { return;
2324
}
@@ -30,19 +31,19 @@ void pseudopot_cell_vl::init_vloc(const ModulePW::PW_Basis* rho_basis)
3031
double *vloc1d = new double[rho_basis->ngg];
3132
ModuleBase::GlobalFunc::ZEROS(vloc1d, rho_basis->ngg);
3233

33-
this->allocate(rho_basis->ngg);
34+
this->allocate(ucell,rho_basis->ngg);
3435

35-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
36+
for (int it = 0; it < ucell.ntype; it++)
3637
{
37-
const Atom* atom = &GlobalC::ucell.atoms[it];
38+
const Atom* atom = &ucell.atoms[it];
3839

3940
ModuleBase::GlobalFunc::ZEROS(vloc1d, rho_basis->ngg);
4041

4142
this->zp[it] = atom->ncpp.zv;
4243
// compute V_loc(G) for a given type of atom
4344
if(atom->coulomb_potential)
4445
{
45-
this->vloc_coulomb(this->zp[it], vloc1d, rho_basis);
46+
this->vloc_coulomb(ucell,this->zp[it], vloc1d, rho_basis);
4647
}
4748
else if(numeric[it]==true)
4849
{
@@ -53,6 +54,7 @@ void pseudopot_cell_vl::init_vloc(const ModulePW::PW_Basis* rho_basis)
5354
atom->ncpp.vloc_at.data(), // local potential in real space radial form.
5455
this->zp[it],
5556
vloc1d,
57+
ucell,
5658
rho_basis);
5759
}
5860
else
@@ -69,26 +71,27 @@ void pseudopot_cell_vl::init_vloc(const ModulePW::PW_Basis* rho_basis)
6971

7072
delete[] vloc1d;
7173

72-
this->print_vloc(rho_basis);
74+
this->print_vloc(ucell,rho_basis);
7375

7476
ModuleBase::timer::tick("ppcell_vl","init_vloc");
7577
return;
7678
}
7779

7880

79-
void pseudopot_cell_vl::allocate(const int ngg)
81+
void pseudopot_cell_vl::allocate(const UnitCell& ucell,
82+
const int ngg)
8083
{
8184
if(PARAM.inp.test_pp>0) { ModuleBase::TITLE("pseudopot_cell_vl","allocate");
8285
}
8386
if(PARAM.inp.use_paw) { return;
8487
}
85-
this->vloc.create(GlobalC::ucell.ntype, ngg);
88+
this->vloc.create(ucell.ntype, ngg);
8689

8790
delete[] numeric;
88-
this->numeric = new bool[GlobalC::ucell.ntype];
89-
ModuleBase::GlobalFunc::ZEROS(numeric, GlobalC::ucell.ntype);
91+
this->numeric = new bool[ucell.ntype];
92+
ModuleBase::GlobalFunc::ZEROS(numeric, ucell.ntype);
9093

91-
for (int it = 0; it < GlobalC::ucell.ntype; it++)
94+
for (int it = 0; it < ucell.ntype; it++)
9295
{
9396
this->numeric[it] = true;
9497
}
@@ -104,7 +107,10 @@ void pseudopot_cell_vl::allocate(const int ngg)
104107
return;
105108
}
106109

107-
void pseudopot_cell_vl::vloc_coulomb(const double& zp_in, double* vloc_1d, const ModulePW::PW_Basis* rho_basis) const
110+
void pseudopot_cell_vl::vloc_coulomb(const UnitCell& ucell,
111+
const double& zp_in,
112+
double* vloc_1d,
113+
const ModulePW::PW_Basis* rho_basis) const
108114
{
109115
int igl0 = 0;
110116
// start from |G|=0 or not.
@@ -117,14 +123,14 @@ void pseudopot_cell_vl::vloc_coulomb(const double& zp_in, double* vloc_1d, const
117123
{
118124
igl0 = 0;
119125
}
120-
const double d_fpi_omega = ModuleBase::FOUR_PI / GlobalC::ucell.omega; // mohan add 2008-06-04
126+
const double d_fpi_omega = ModuleBase::FOUR_PI / ucell.omega; // mohan add 2008-06-04
121127
double fac = -zp_in * ModuleBase::e2 * d_fpi_omega;
122128
#ifdef _OPENMP
123129
#pragma omp for
124130
#endif
125131
for (int ig = igl0; ig < rho_basis->ngg; ig++)
126132
{
127-
double gx2 = rho_basis->gg_uniq[ig] * GlobalC::ucell.tpiba2;
133+
double gx2 = rho_basis->gg_uniq[ig] * ucell.tpiba2;
128134
vloc_1d[ig] = fac / gx2;
129135
}
130136
return;
@@ -145,6 +151,7 @@ void pseudopot_cell_vl::vloc_of_g(const int& msh,
145151
const double* vloc_at,
146152
const double& zp_in,
147153
double* vloc_1d,
154+
const UnitCell& ucell,
148155
const ModulePW::PW_Basis* rho_basis) const
149156
{
150157
//----------------------------------------------------------------
@@ -173,7 +180,7 @@ void pseudopot_cell_vl::vloc_of_g(const int& msh,
173180
/*
174181
for(ir=0; ir<msh; ir++)
175182
{
176-
aux[ir] = r[ir] * zp_in * e2 / GlobalC::ucell.omega;
183+
aux[ir] = r[ir] * zp_in * e2 / ucell.omega;
177184
}
178185
ModuleBase::Integral::Simpson_Integral(msh, aux, rab, vloc_1d[0] );
179186
vloc_1d[0] *= 4*3.1415926;
@@ -224,7 +231,7 @@ void pseudopot_cell_vl::vloc_of_g(const int& msh,
224231
#endif
225232
for (int ig = igl0;ig < rho_basis->ngg;ig++)
226233
{
227-
double gx2= rho_basis->gg_uniq[ig] * GlobalC::ucell.tpiba2;
234+
double gx2= rho_basis->gg_uniq[ig] * ucell.tpiba2;
228235
double gx = std::sqrt(gx2);
229236
for (int ir = 0;ir < msh;ir++)
230237
{
@@ -235,7 +242,7 @@ void pseudopot_cell_vl::vloc_of_g(const int& msh,
235242
vloc_1d[ig] -= fac * ModuleBase::libm::exp(- gx2 * 0.25)/ gx2;
236243
} // enddo
237244

238-
const double d_fpi_omega = ModuleBase::FOUR_PI/GlobalC::ucell.omega;//mohan add 2008-06-04
245+
const double d_fpi_omega = ModuleBase::FOUR_PI/ucell.omega;//mohan add 2008-06-04
239246
#ifdef _OPENMP
240247
#pragma omp for
241248
#endif
@@ -253,21 +260,22 @@ void pseudopot_cell_vl::vloc_of_g(const int& msh,
253260
return;
254261
} // end subroutine vloc_of_g
255262

256-
void pseudopot_cell_vl::print_vloc(const ModulePW::PW_Basis* rho_basis) const
263+
void pseudopot_cell_vl::print_vloc(const UnitCell& ucell,
264+
const ModulePW::PW_Basis* rho_basis) const
257265
{
258266
if(GlobalV::MY_RANK!=0) { return; //mohan fix bug 2011-10-13
259267
}
260268
bool check_vl = PARAM.inp.out_element_info;
261269
if(check_vl)
262270
{
263-
for(int it=0; it<GlobalC::ucell.ntype; it++)
271+
for(int it=0; it<ucell.ntype; it++)
264272
{
265273
std::stringstream ss ;
266-
ss << PARAM.globalv.global_out_dir << GlobalC::ucell.atoms[it].label << "/v_loc_g.dat" ;
274+
ss << PARAM.globalv.global_out_dir << ucell.atoms[it].label << "/v_loc_g.dat" ;
267275
std::ofstream ofs_vg( ss.str().c_str() );
268276
for(int ig=0;ig<rho_basis->ngg;ig++)
269277
{
270-
ofs_vg << std::setw(15) << rho_basis->gg_uniq [ig] * GlobalC::ucell.tpiba2
278+
ofs_vg << std::setw(15) << rho_basis->gg_uniq [ig] * ucell.tpiba2
271279
<< std::setw(15) << this->vloc(it, ig) << std::endl;
272280
}
273281
ofs_vg.close();

source/module_hamilt_pw/hamilt_pwdft/VL_in_pw.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "module_base/global_variable.h"
66
#include "module_base/matrix.h"
77
#include "module_basis/module_pw/pw_basis.h"
8+
#include "module_cell/unitcell.h"
89

910
class pseudopot_cell_vl
1011
{
@@ -19,7 +20,8 @@ class pseudopot_cell_vl
1920
* @param rho_basis pw basis
2021
* @return this->vloc
2122
*/
22-
void init_vloc(const ModulePW::PW_Basis* rho_basis);
23+
void init_vloc(const UnitCell& ucell,
24+
const ModulePW::PW_Basis* rho_basis);
2325

2426
ModuleBase::matrix vloc; //(ntype,ngl),the local potential for each atom type(ntype,ngl)
2527
bool *numeric; //[ntype], =true
@@ -28,22 +30,28 @@ class pseudopot_cell_vl
2830

2931
double *zp; // (npsx),the charge of the pseudopotential
3032

31-
void allocate(const int ngg);
33+
void allocate(const UnitCell& ucell,
34+
const int ngg);
3235
/**
3336
* @brief compute the coulomb potential in reciprocal space
3437
* v(g) = -\frac{4pi}{V} * zp*e^2 / G^2
3538
*/
36-
void vloc_coulomb(const double& zp, double* vloc_1d, const ModulePW::PW_Basis* rho_basis) const;
39+
void vloc_coulomb(const UnitCell& ucell,
40+
const double& zp,
41+
double* vloc_1d,
42+
const ModulePW::PW_Basis* rho_basis) const;
3743
// generate vloc for a particular atom type.
3844
void vloc_of_g(const int& msh,
3945
const double* rab,
4046
const double* r,
4147
const double* vloc_at,
4248
const double& zp,
4349
double* vloc,
50+
const UnitCell& ucell,
4451
const ModulePW::PW_Basis* rho_basis) const;
4552

46-
void print_vloc(const ModulePW::PW_Basis* rho_basis) const;
53+
void print_vloc(const UnitCell& ucell,
54+
const ModulePW::PW_Basis* rho_basis) const;
4755
};
4856

4957
#endif // VL_IN_PW

0 commit comments

Comments
 (0)