@@ -236,38 +236,42 @@ void ESolver_OF::before_opt(const int istep, UnitCell& ucell)
236236
237237 elecstate::init_scf (ucell, Pgrid, sf.strucFac , locpp.numeric , istep, PARAM .globalv .global_out_dir , PARAM .inp , this ->pelec );
238238
239- Symmetry_rho::symmetrize_rho (PARAM .inp .nspin , this ->chr , this ->pw_rho , ucell.symm );
240-
241- for (int is = 0 ; is < PARAM .inp .nspin ; ++is)
239+ const int nspin = PARAM .inp .nspin ;
240+ if (PARAM .inp .init_chg == " file" )
242241 {
243- if (PARAM .inp .init_chg != " file" )
242+ Symmetry_rho::symmetrize_rho (nspin, this ->chr , this ->pw_rho , ucell.symm );
243+ for (int is = 0 ; is < nspin; ++is)
244244 {
245245 for (int ibs = 0 ; ibs < this ->pw_rho ->nrxx ; ++ibs)
246246 {
247- // Here we initialize rho to be uniform,
248- // because the rho got by pot.init_pot -> Charge::atomic_rho may contain minus elements.
249- this ->chr .rho [is][ibs] = this ->nelec_ [is] / ucell.omega ;
250247 this ->pphi_ [is][ibs] = sqrt (this ->chr .rho [is][ibs]);
251248 }
252249 }
253- else
250+ }
251+ else
252+ {
253+ // Non-file densities are replaced with a uniform density, so
254+ // symmetrizing them would only add an unnecessary FFT round trip.
255+ for (int is = 0 ; is < nspin; ++is)
254256 {
255257 for (int ibs = 0 ; ibs < this ->pw_rho ->nrxx ; ++ibs)
256258 {
259+ // The density from pot.init_pot -> Charge::atomic_rho may contain negative elements.
260+ this ->chr .rho [is][ibs] = this ->nelec_ [is] / ucell.omega ;
257261 this ->pphi_ [is][ibs] = sqrt (this ->chr .rho [is][ibs]);
258262 }
259263 }
260264 }
261265
262- for (int is = 0 ; is < PARAM . inp . nspin ; ++is)
266+ for (int is = 0 ; is < nspin; ++is)
263267 {
264268 this ->pelec ->eferm .set_efval (is, 0 );
265269 this ->theta_ [is] = 0 .;
266270 ModuleBase::GlobalFunc::ZEROS (this ->pdLdphi_ [is], this ->pw_rho ->nrxx );
267271 ModuleBase::GlobalFunc::ZEROS (this ->pdEdphi_ [is], this ->pw_rho ->nrxx );
268272 ModuleBase::GlobalFunc::ZEROS (this ->pdirect_ [is], this ->pw_rho ->nrxx );
269273 }
270- if (PARAM . inp . nspin == 1 )
274+ if (nspin == 1 )
271275 {
272276 this ->theta_ [0 ] = 0.2 ;
273277 }
0 commit comments