1111
1212// calcualte the Ewald stress term in PW and LCAO
1313template <typename FPTYPE, typename Device>
14- void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW::PW_Basis* rho_basis, const bool is_pw)
14+ void Stress_Func<FPTYPE, Device>::stress_ewa(const UnitCell& ucell,
15+ ModuleBase::matrix& sigma,
16+ ModulePW::PW_Basis* rho_basis,
17+ const bool is_pw)
1518{
1619 ModuleBase::TITLE (" Stress_Func" ," stress_ewa" );
1720 ModuleBase::timer::tick (" Stress_Func" ," stress_ewa" );
1821
1922 FPTYPE charge=0 ;
20- for (int it=0 ; it < GlobalC:: ucell.ntype ; it++)
23+ for (int it=0 ; it < ucell.ntype ; it++)
2124 {
22- charge = charge + GlobalC:: ucell.atoms [it].ncpp .zv * GlobalC:: ucell.atoms [it].na ;
25+ charge = charge + ucell.atoms [it].ncpp .zv * ucell.atoms [it].na ;
2326 }
2427 // choose alpha in order to have convergence in the sum over G
2528 // upperbound is a safe upper bound for the error ON THE ENERGY
@@ -30,7 +33,7 @@ void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW
3033 alpha-=0.1 ;
3134 if (alpha==0.0 )
3235 ModuleBase::WARNING_QUIT (" stres_ew" , " optimal alpha not found" );
33- upperbound =ModuleBase::e2 * pow (charge,2 ) * sqrt ( 2 * alpha / (ModuleBase::TWO_PI)) * erfc (sqrt (GlobalC:: ucell.tpiba2 * rho_basis->ggecut / 4.0 / alpha));
36+ upperbound =ModuleBase::e2 * pow (charge,2 ) * sqrt ( 2 * alpha / (ModuleBase::TWO_PI)) * erfc (sqrt (ucell.tpiba2 * rho_basis->ggecut / 4.0 / alpha));
3437 }
3538 while (upperbound>1e-7 );
3639
@@ -40,7 +43,7 @@ void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW
4043 const int ig0 = rho_basis->ig_gge0 ;
4144 if ( ig0 >= 0 )
4245 {
43- sdewald = (ModuleBase::TWO_PI) * ModuleBase::e2 / 4.0 / alpha * pow (charge/GlobalC:: ucell.omega ,2 );
46+ sdewald = (ModuleBase::TWO_PI) * ModuleBase::e2 / 4.0 / alpha * pow (charge/ucell.omega ,2 );
4447 }
4548 else
4649 {
@@ -79,27 +82,27 @@ void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW
7982 for (; ig < ig_end; ig++)
8083 {
8184 if (ig == ig0) continue ;
82- g2 = rho_basis->gg [ig]* GlobalC:: ucell.tpiba2 ;
85+ g2 = rho_basis->gg [ig]* ucell.tpiba2 ;
8386 g2a = g2 /4.0 /alpha;
8487 rhostar=std::complex <FPTYPE>(0.0 ,0.0 );
85- for (int it=0 ; it < GlobalC:: ucell.ntype ; it++)
88+ for (int it=0 ; it < ucell.ntype ; it++)
8689 {
87- for (int i=0 ; i<GlobalC:: ucell.atoms [it].na ; i++)
90+ for (int i=0 ; i<ucell.atoms [it].na ; i++)
8891 {
89- arg = (rho_basis->gcar [ig] * GlobalC:: ucell.atoms [it].tau [i]) * (ModuleBase::TWO_PI);
92+ arg = (rho_basis->gcar [ig] * ucell.atoms [it].tau [i]) * (ModuleBase::TWO_PI);
9093 FPTYPE sinp, cosp;
9194 ModuleBase::libm::sincos (arg, &sinp, &cosp);
92- rhostar = rhostar + std::complex <FPTYPE>(GlobalC:: ucell.atoms [it].ncpp .zv * cosp,GlobalC:: ucell.atoms [it].ncpp .zv * sinp);
95+ rhostar = rhostar + std::complex <FPTYPE>(ucell.atoms [it].ncpp .zv * cosp,ucell.atoms [it].ncpp .zv * sinp);
9396 }
9497 }
95- rhostar /= GlobalC:: ucell.omega ;
98+ rhostar /= ucell.omega ;
9699 sewald = fact* (ModuleBase::TWO_PI) * ModuleBase::e2 * ModuleBase::libm::exp (-g2a) / g2 * pow (std::abs (rhostar),2 );
97100 local_sdewald -= sewald;
98101 for (int l=0 ;l<3 ;l++)
99102 {
100103 for (int m=0 ;m<l+1 ;m++)
101104 {
102- local_sigma (l, m) += sewald * GlobalC:: ucell.tpiba2 * 2.0 * rho_basis->gcar [ig][l] * rho_basis->gcar [ig][m] / g2 * (g2a + 1 );
105+ local_sigma (l, m) += sewald * ucell.tpiba2 * 2.0 * rho_basis->gcar [ig][l] * rho_basis->gcar [ig][m] / g2 * (g2a + 1 );
103106 }
104107 }
105108 }
@@ -123,25 +126,25 @@ void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW
123126
124127 FPTYPE sqa = sqrt (alpha);
125128 FPTYPE sq8a_2pi = sqrt (8 * alpha / (ModuleBase::TWO_PI));
126- rmax = 4.0 /sqa/GlobalC:: ucell.lat0 ;
129+ rmax = 4.0 /sqa/ucell.lat0 ;
127130
128131 // collapse it, ia, jt, ja loop into a single loop
129132 long long ijat, ijat_end;
130133 int it, i, jt, j;
131- ModuleBase::TASK_DIST_1D (num_threads, thread_id, (long long )GlobalC:: ucell.nat * GlobalC:: ucell.nat , ijat, ijat_end);
134+ ModuleBase::TASK_DIST_1D (num_threads, thread_id, (long long )ucell.nat * ucell.nat , ijat, ijat_end);
132135 ijat_end = ijat + ijat_end;
133- GlobalC:: ucell.ijat2iaitjajt (ijat, &i, &it, &j, &jt);
136+ ucell.ijat2iaitjajt (ijat, &i, &it, &j, &jt);
134137
135138 while (ijat < ijat_end)
136139 {
137140 // calculate tau[na]-tau[nb]
138- d_tau = GlobalC:: ucell.atoms [it].tau [i] - GlobalC:: ucell.atoms [jt].tau [j];
141+ d_tau = ucell.atoms [it].tau [i] - ucell.atoms [jt].tau [j];
139142 // generates nearest-neighbors shells
140- H_Ewald_pw::rgen (d_tau, rmax, irr, GlobalC:: ucell.latvec , GlobalC:: ucell.G , r, r2, nrm);
143+ H_Ewald_pw::rgen (d_tau, rmax, irr, ucell.latvec , ucell.G , r, r2, nrm);
141144 for (int nr=0 ; nr<nrm ; nr++)
142145 {
143- rr=sqrt (r2[nr]) * GlobalC:: ucell.lat0 ;
144- fac = -ModuleBase::e2 /2.0 /GlobalC:: ucell.omega *pow (GlobalC:: ucell.lat0 ,2 )*GlobalC:: ucell.atoms [it].ncpp .zv * GlobalC:: ucell.atoms [jt].ncpp .zv / pow (rr,3 ) * (erfc (sqa*rr)+rr * sq8a_2pi * ModuleBase::libm::exp (-alpha * pow (rr,2 )));
146+ rr=sqrt (r2[nr]) * ucell.lat0 ;
147+ fac = -ModuleBase::e2 /2.0 /ucell.omega *pow (ucell.lat0 ,2 )*ucell.atoms [it].ncpp .zv * ucell.atoms [jt].ncpp .zv / pow (rr,3 ) * (erfc (sqa*rr)+rr * sq8a_2pi * ModuleBase::libm::exp (-alpha * pow (rr,2 )));
145148 for (int l=0 ; l<3 ; l++)
146149 {
147150 for (int m=0 ; m<l+1 ; m++)
@@ -155,7 +158,7 @@ void Stress_Func<FPTYPE, Device>::stress_ewa(ModuleBase::matrix& sigma, ModulePW
155158 }// end nr
156159
157160 ++ijat;
158- GlobalC:: ucell.step_jajtiait (&j, &jt, &i, &it);
161+ ucell.step_jajtiait (&j, &jt, &i, &it);
159162 }
160163
161164 delete[] r;
0 commit comments