Skip to content

Commit feece0c

Browse files
committed
change ucell in pwdft/stress_func_cc.cpp
1 parent 790aa51 commit feece0c

File tree

8 files changed

+35
-33
lines changed

8 files changed

+35
-33
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ void Force_Stress_LCAO<std::complex<double>>::integral_part(const bool isGammaOn
992992

993993
// vlocal, hartree, ewald, core correction, exchange-correlation terms in stress
994994
template <typename T>
995-
void Force_Stress_LCAO<T>::calStressPwPart(const UnitCell& ucell,
995+
void Force_Stress_LCAO<T>::calStressPwPart(UnitCell& ucell,
996996
ModuleBase::matrix& sigmadvl,
997997
ModuleBase::matrix& sigmahar,
998998
ModuleBase::matrix& sigmaewa,
@@ -1024,7 +1024,7 @@ void Force_Stress_LCAO<T>::calStressPwPart(const UnitCell& ucell,
10241024
//--------------------------------------------------------
10251025
// stress due to core correlation.
10261026
//--------------------------------------------------------
1027-
sc_pw.stress_cc(sigmacc, rhopw, &sf, 0, nlpp.numeric, chr);
1027+
sc_pw.stress_cc(ucell,sigmacc,rhopw, &sf, 0, nlpp.numeric, chr);
10281028

10291029
//--------------------------------------------------------
10301030
// stress due to self-consistent charge.

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Force_Stress_LCAO
102102
const Parallel_Orbitals& pv,
103103
const K_Vectors& kv);
104104

105-
void calStressPwPart(const UnitCell& ucell,
105+
void calStressPwPart(UnitCell& ucell,
106106
ModuleBase::matrix& sigmadvl,
107107
ModuleBase::matrix& sigmahar,
108108
ModuleBase::matrix& sigmaewa,

source/module_hamilt_pw/hamilt_ofdft/of_stress_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void OF_Stress_PW::cal_stress(ModuleBase::matrix& sigmatot,
7979
stress_loc(ucell,sigmaloc, this->rhopw, locpp.vloc, p_sf, true, pelec->charge);
8080

8181
// nlcc
82-
stress_cc(sigmaxcc, this->rhopw, p_sf, true, locpp.numeric, pelec->charge);
82+
stress_cc(ucell,sigmaxcc, this->rhopw, p_sf, true, locpp.numeric, pelec->charge);
8383

8484
// vdw term
8585
stress_vdw(sigmavdw, ucell);

source/module_hamilt_pw/hamilt_pwdft/stress_func.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ class Stress_Func
112112
ModulePW::PW_Basis* rho_basis); // used in local pseudopotential stress
113113

114114
// 5) the stress from the non-linear core correction (if any)
115-
void stress_cc(ModuleBase::matrix& sigma,
115+
void stress_cc(UnitCell& ucell,
116+
ModuleBase::matrix& sigma,
116117
ModulePW::PW_Basis* rho_basis,
117118
const Structure_Factor* p_sf,
118119
const bool is_pw,

source/module_hamilt_pw/hamilt_pwdft/stress_func_cc.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
//NLCC term, need to be tested
1515
template <typename FPTYPE, typename Device>
16-
void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
16+
void Stress_Func<FPTYPE, Device>::stress_cc(UnitCell& ucell,
17+
ModuleBase::matrix& sigma,
1718
ModulePW::PW_Basis* rho_basis,
1819
const Structure_Factor* p_sf,
1920
const bool is_pw,
@@ -34,9 +35,9 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
3435
FPTYPE* rhocg;
3536

3637
int judge=0;
37-
for(int nt=0;nt<GlobalC::ucell.ntype;nt++)
38+
for(int nt=0;nt<ucell.ntype;nt++)
3839
{
39-
if(GlobalC::ucell.atoms[nt].ncpp.nlcc)
40+
if(ucell.atoms[nt].ncpp.nlcc)
4041
{
4142
judge++;
4243
}
@@ -54,7 +55,7 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
5455
{
5556
#ifdef USE_LIBXC
5657
const auto etxc_vtxc_v
57-
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rho_basis->nrxx, GlobalC::ucell.omega, GlobalC::ucell.tpiba, chr);
58+
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rho_basis->nrxx, ucell.omega, ucell.tpiba, chr);
5859

5960
// etxc = std::get<0>(etxc_vtxc_v);
6061
// vtxc = std::get<1>(etxc_vtxc_v);
@@ -65,8 +66,8 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
6566
}
6667
else
6768
{
68-
elecstate::cal_ux(GlobalC::ucell);
69-
const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &GlobalC::ucell);
69+
elecstate::cal_ux(ucell);
70+
const auto etxc_vtxc_v = XC_Functional::v_xc(rho_basis->nrxx, chr, &ucell);
7071
// etxc = std::get<0>(etxc_vtxc_v); // may delete?
7172
// vtxc = std::get<1>(etxc_vtxc_v); // may delete?
7273
vxc = std::get<2>(etxc_vtxc_v);
@@ -103,17 +104,17 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
103104
rhocg= new FPTYPE [rho_basis->ngg];
104105

105106
sigmadiag=0.0;
106-
for(int nt=0;nt<GlobalC::ucell.ntype;nt++)
107+
for(int nt=0;nt<ucell.ntype;nt++)
107108
{
108-
if(GlobalC::ucell.atoms[nt].ncpp.nlcc)
109+
if(ucell.atoms[nt].ncpp.nlcc)
109110
{
110111
//drhoc();
111112
this->deriv_drhoc(
112113
numeric,
113-
GlobalC::ucell.atoms[nt].ncpp.msh,
114-
GlobalC::ucell.atoms[nt].ncpp.r.data(),
115-
GlobalC::ucell.atoms[nt].ncpp.rab.data(),
116-
GlobalC::ucell.atoms[nt].ncpp.rho_atc.data(),
114+
ucell.atoms[nt].ncpp.msh,
115+
ucell.atoms[nt].ncpp.r.data(),
116+
ucell.atoms[nt].ncpp.rab.data(),
117+
ucell.atoms[nt].ncpp.rho_atc.data(),
117118
rhocg,
118119
rho_basis,
119120
1);
@@ -130,15 +131,15 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
130131
local_sigmadiag = conj(psic[ig]) * p_sf->strucFac(nt, ig) * rhocg[rho_basis->ig2igg[ig]];
131132
} else {
132133
local_sigmadiag = conj(psic[ig]) * p_sf->strucFac(nt, ig) * rhocg[rho_basis->ig2igg[ig]] * fact;
133-
}
134+
}
134135
sigmadiag += local_sigmadiag.real();
135136
}
136137
this->deriv_drhoc (
137138
numeric,
138-
GlobalC::ucell.atoms[nt].ncpp.msh,
139-
GlobalC::ucell.atoms[nt].ncpp.r.data(),
140-
GlobalC::ucell.atoms[nt].ncpp.rab.data(),
141-
GlobalC::ucell.atoms[nt].ncpp.rho_atc.data(),
139+
ucell.atoms[nt].ncpp.msh,
140+
ucell.atoms[nt].ncpp.r.data(),
141+
ucell.atoms[nt].ncpp.rab.data(),
142+
ucell.atoms[nt].ncpp.rho_atc.data(),
142143
rhocg,
143144
rho_basis,
144145
0);
@@ -154,15 +155,15 @@ void Stress_Func<FPTYPE, Device>::stress_cc(ModuleBase::matrix& sigma,
154155
for(int ig = 0;ig< rho_basis->npw;ig++)
155156
{
156157
const FPTYPE norm_g = sqrt(rho_basis->gg[ig]);
157-
if(norm_g < 1e-4) { continue;
158-
}
158+
if(norm_g < 1e-4) {continue;
159+
}
159160
for (int l = 0; l < 3; l++)
160161
{
161162
for (int m = 0;m< 3;m++)
162163
{
163164
const std::complex<FPTYPE> t
164165
= conj(psic[ig]) * p_sf->strucFac(nt, ig) * rhocg[rho_basis->ig2igg[ig]]
165-
* GlobalC::ucell.tpiba * rho_basis->gcar[ig][l] * rho_basis->gcar[ig][m] / norm_g * fact;
166+
* ucell.tpiba * rho_basis->gcar[ig][l] * rho_basis->gcar[ig][m] / norm_g * fact;
166167
// sigmacc [l][ m] += t.real();
167168
local_sigma(l,m) += t.real();
168169
}//end m
@@ -254,7 +255,7 @@ void Stress_Func<FPTYPE, Device>::deriv_drhoc
254255
aux [ir] = r [ir] * r [ir] * rhoc [ir];
255256
}
256257
ModuleBase::Integral::Simpson_Integral(mesh, aux.data(), rab, rhocg1);
257-
drhocg [0] = ModuleBase::FOUR_PI * rhocg1 / GlobalC::ucell.omega;
258+
drhocg [0] = ModuleBase::FOUR_PI * rhocg1 / ucell->omega;
258259
igl0 = 1;
259260
}
260261
else
@@ -273,7 +274,7 @@ void Stress_Func<FPTYPE, Device>::deriv_drhoc
273274
#endif
274275
for(int igl = igl0;igl< rho_basis->ngg;igl++)
275276
{
276-
gx_arr[igl] = sqrt(rho_basis->gg_uniq[igl] * GlobalC::ucell.tpiba2);
277+
gx_arr[igl] = sqrt(rho_basis->gg_uniq[igl] * ucell->tpiba2);
277278
}
278279

279280
double *r_d = nullptr;
@@ -298,12 +299,12 @@ void Stress_Func<FPTYPE, Device>::deriv_drhoc
298299

299300
if(this->device == base_device::GpuDevice) {
300301
hamilt::cal_stress_drhoc_aux_op<FPTYPE, Device>()(
301-
r_d,rhoc_d,gx_arr_d+igl0,rab_d,drhocg_d+igl0,mesh,igl0,rho_basis->ngg-igl0,GlobalC::ucell.omega,type);
302+
r_d,rhoc_d,gx_arr_d+igl0,rab_d,drhocg_d+igl0,mesh,igl0,rho_basis->ngg-igl0,ucell->omega,type);
302303
syncmem_var_d2h_op()(this->cpu_ctx, this->ctx, drhocg+igl0, drhocg_d+igl0, rho_basis->ngg-igl0);
303304

304305
} else {
305306
hamilt::cal_stress_drhoc_aux_op<FPTYPE, Device>()(
306-
r,rhoc,gx_arr.data()+igl0,rab,drhocg+igl0,mesh,igl0,rho_basis->ngg-igl0,GlobalC::ucell.omega,type);
307+
r,rhoc,gx_arr.data()+igl0,rab,drhocg+igl0,mesh,igl0,rho_basis->ngg-igl0,ucell->omega,type);
307308

308309
}
309310
delmem_var_op()(this->ctx, r_d);

source/module_hamilt_pw/hamilt_pwdft/stress_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void Stress_PW<FPTYPE, Device>::cal_stress(ModuleBase::matrix& sigmatot,
9393
this->stress_loc(ucell,sigmaloc, rho_basis, nlpp.vloc, p_sf, 1, pelec->charge);
9494

9595
// nlcc
96-
this->stress_cc(sigmaxcc, rho_basis, p_sf, 1, nlpp.numeric, pelec->charge);
96+
this->stress_cc(ucell,sigmaxcc, rho_basis, p_sf, 1, nlpp.numeric, pelec->charge);
9797

9898
// nonlocal
9999
this->stress_nl(sigmanl, this->pelec->wg, this->pelec->ekb, p_sf, p_kv, p_symm, wfc_basis, d_psi_in, nlpp, ucell);

source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void Sto_Stress_PW<FPTYPE, Device>::cal_stress(ModuleBase::matrix& sigmatot,
2020
const Stochastic_WF<std::complex<FPTYPE>, Device>& stowf,
2121
const Charge* const chr,
2222
pseudopot_cell_vnl* nlpp,
23-
const UnitCell& ucell_in)
23+
UnitCell& ucell_in)
2424
{
2525
ModuleBase::TITLE("Sto_Stress_PW", "cal_stress");
2626
ModuleBase::timer::tick("Sto_Stress_PW", "cal_stress");
@@ -55,7 +55,7 @@ void Sto_Stress_PW<FPTYPE, Device>::cal_stress(ModuleBase::matrix& sigmatot,
5555
this->stress_loc(ucell_in,sigmaloc, rho_basis, nlpp->vloc, p_sf, true, chr);
5656

5757
// nlcc
58-
this->stress_cc(sigmaxcc, rho_basis, p_sf, true, nlpp->numeric, chr);
58+
this->stress_cc(ucell_in,sigmaxcc, rho_basis, p_sf, true, nlpp->numeric, chr);
5959

6060
// nonlocal
6161
this->sto_stress_nl(sigmanl, wg, p_sf, p_symm, p_kv, wfc_basis, *nlpp, ucell_in, psi_in, stowf);

source/module_hamilt_pw/hamilt_stodft/sto_stress_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Sto_Stress_PW : public Stress_Func<FPTYPE, Device>
2626
const Stochastic_WF<std::complex<FPTYPE>, Device>& stowf,
2727
const Charge* const chr,
2828
pseudopot_cell_vnl* nlpp_in,
29-
const UnitCell& ucell_in);
29+
UnitCell& ucell_in);
3030

3131
private:
3232
void sto_stress_kin(ModuleBase::matrix& sigma,

0 commit comments

Comments
 (0)