66
77void Charge_Mixing::Kerker_screen_recip (std::complex <double >* drhog)
88{
9- if (this ->mixing_gg0 <= 0.0 || this ->mixing_beta <= 0.1 ) {
10- return ;
11- }
9+ ModuleBase::TITLE (" Charge_Mixing" , " Kerker_screen_recip" );
10+
11+ if (this ->mixing_gg0 <= 0.0 || this ->mixing_beta <= 0.1 )
12+ {
13+ return ;
14+ }
15+
16+ ModuleBase::timer::tick (" Charge_Mixing" , " Kerker_screen_recip" );
17+
18+ const int nspin = PARAM.inp .nspin ;
19+
1220 double fac = 0.0 ;
1321 double gg0 = 0.0 ;
1422 double amin = 0.0 ;
1523
1624 // / consider a resize for mixing_angle
17- int resize_tmp = 1 ;
18- if (PARAM.inp .nspin == 4 && this ->mixing_angle > 0 ) { resize_tmp = 2 ;
19- }
25+ int resize_tmp = 1 ;
26+ if (nspin == 4 && this ->mixing_angle > 0 )
27+ {
28+ resize_tmp = 2 ;
29+ }
2030
2131 // / implement Kerker for density and magnetization separately
22- for (int is = 0 ; is < PARAM. inp . nspin / resize_tmp; ++is)
32+ for (int is = 0 ; is < nspin / resize_tmp; ++is)
2333 {
34+ const int is_idx = is * this ->rhopw ->npw ;
2435 // / new mixing method only support nspin=2 not nspin=4
2536 if (is >= 1 )
2637 {
@@ -29,10 +40,10 @@ void Charge_Mixing::Kerker_screen_recip(std::complex<double>* drhog)
2940#ifdef __DEBUG
3041 assert (is == 1 ); // make sure break works
3142#endif
32- double is_mag = PARAM. inp . nspin - 1 ;
43+ double is_mag = nspin - 1 ;
3344 // for (int ig = 0; ig < this->rhopw->npw * is_mag; ig++)
3445 // {
35- // drhog[is * this->rhopw->npw + ig] *= 1;
46+ // drhog[is_idx + ig] *= 1;
3647 // }
3748 break ;
3849 }
@@ -46,32 +57,49 @@ void Charge_Mixing::Kerker_screen_recip(std::complex<double>* drhog)
4657 }
4758
4859 gg0 = std::pow (fac * 0.529177 / *this ->tpiba , 2 );
60+
61+ const double gg0_amin = this ->mixing_gg0_min / amin;
62+
4963#ifdef _OPENMP
5064#pragma omp parallel for schedule(static, 512)
5165#endif
5266 for (int ig = 0 ; ig < this ->rhopw ->npw ; ++ig)
5367 {
5468 double gg = this ->rhopw ->gg [ig];
55- double filter_g = std::max (gg / (gg + gg0), this -> mixing_gg0_min / amin );
56- drhog[is * this -> rhopw -> npw + ig] *= filter_g;
69+ double filter_g = std::max (gg / (gg + gg0), gg0_amin );
70+ drhog[is_idx + ig] *= filter_g;
5771 }
5872 }
73+
74+ ModuleBase::timer::tick (" Charge_Mixing" , " Kerker_screen_recip" );
5975 return ;
6076}
6177
6278void Charge_Mixing::Kerker_screen_real (double * drhor)
6379{
64- if (this ->mixing_gg0 <= 0.0001 || this ->mixing_beta <= 0.1 ) {
65- return ;
66- }
67- // / consider a resize for mixing_angle
80+ ModuleBase::TITLE (" Charge_Mixing" , " Kerker_screen_real" );
81+
82+ if (this ->mixing_gg0 <= 0.0001 || this ->mixing_beta <= 0.1 )
83+ {
84+ return ;
85+ }
86+
87+ ModuleBase::timer::tick (" Charge_Mixing" , " Kerker_screen_real" );
88+
89+ const int nspin = PARAM.inp .nspin ;
90+ assert (nspin==1 || nspin==2 || nspin==4 );
91+
92+ // / consider a resize for mixing_angle
6893 int resize_tmp = 1 ;
69- if (PARAM.inp .nspin == 4 && this ->mixing_angle > 0 ) { resize_tmp = 2 ;
70- }
94+ if (nspin == 4 && this ->mixing_angle > 0 )
95+ {
96+ resize_tmp = 2 ;
97+ }
7198
72- std::vector<std::complex <double >> drhog (this ->rhopw ->npw * PARAM.inp .nspin / resize_tmp);
73- std::vector<double > drhor_filter (this ->rhopw ->nrxx * PARAM.inp .nspin / resize_tmp);
74- for (int is = 0 ; is < PARAM.inp .nspin / resize_tmp; ++is)
99+ std::vector<std::complex <double >> drhog (this ->rhopw ->npw * nspin / resize_tmp);
100+ std::vector<double > drhor_filter (this ->rhopw ->nrxx * nspin / resize_tmp);
101+
102+ for (int is = 0 ; is < nspin / resize_tmp; ++is)
75103 {
76104 // Note after this process some G which is higher than Gmax will be filtered.
77105 // Thus we cannot use Kerker_screen_recip(drhog.data()) directly after it.
@@ -82,7 +110,7 @@ void Charge_Mixing::Kerker_screen_real(double* drhor)
82110 double gg0 = 0.0 ;
83111 double amin = 0.0 ;
84112
85- for (int is = 0 ; is < PARAM. inp . nspin / resize_tmp; is++)
113+ for (int is = 0 ; is < nspin / resize_tmp; is++)
86114 {
87115
88116 if (is >= 1 )
@@ -92,8 +120,8 @@ void Charge_Mixing::Kerker_screen_real(double* drhor)
92120#ifdef __DEBUG
93121 assert (is == 1 ); // / make sure break works
94122#endif
95- double is_mag = PARAM. inp . nspin - 1 ;
96- if (PARAM. inp . nspin == 4 && this ->mixing_angle > 0 ) { is_mag = 1 ;
123+ double is_mag = nspin - 1 ;
124+ if (nspin == 4 && this ->mixing_angle > 0 ) { is_mag = 1 ;
97125}
98126 for (int ig = 0 ; ig < this ->rhopw ->npw * is_mag; ig++)
99127 {
@@ -111,6 +139,9 @@ void Charge_Mixing::Kerker_screen_real(double* drhor)
111139 }
112140
113141 gg0 = std::pow (fac * 0.529177 / *this ->tpiba , 2 );
142+
143+ const int is_idx = is * this ->rhopw ->npw ;
144+ const double gg0_amin = this ->mixing_gg0_min / amin;
114145#ifdef _OPENMP
115146#pragma omp parallel for schedule(static, 512)
116147#endif
@@ -120,24 +151,27 @@ void Charge_Mixing::Kerker_screen_real(double* drhor)
120151 // I have not decided how to handle gg=0 part, will be changed in future
121152 // if (gg == 0)
122153 // {
123- // drhog[is * this->rhopw->npw + ig] *= 0;
154+ // drhog[is_idx + ig] *= 0;
124155 // continue;
125156 // }
126- double filter_g = std::max (gg / (gg + gg0), this -> mixing_gg0_min / amin );
127- drhog[is * this -> rhopw -> npw + ig] *= (1 - filter_g);
157+ double filter_g = std::max (gg / (gg + gg0), gg0_amin );
158+ drhog[is_idx + ig] *= (1 - filter_g);
128159 }
129160 }
130161 // / inverse FT
131- for (int is = 0 ; is < PARAM. inp . nspin / resize_tmp; ++is)
162+ for (int is = 0 ; is < nspin / resize_tmp; ++is)
132163 {
133164 this ->rhopw ->recip2real (drhog.data () + is * this ->rhopw ->npw , drhor_filter.data () + is * this ->rhopw ->nrxx );
134165 }
135166
136167#ifdef _OPENMP
137168#pragma omp parallel for schedule(static, 512)
138169#endif
139- for (int ir = 0 ; ir < this ->rhopw ->nrxx * PARAM. inp . nspin / resize_tmp; ir++)
170+ for (int ir = 0 ; ir < this ->rhopw ->nrxx * nspin / resize_tmp; ir++)
140171 {
141172 drhor[ir] -= drhor_filter[ir];
142173 }
174+
175+ ModuleBase::timer::tick (" Charge_Mixing" , " Kerker_screen_real" );
176+ return ;
143177}
0 commit comments