@@ -211,7 +211,7 @@ void Stochastic_Iter::check_precision(const double ref, const double thr, const
211211 ss.clear ();
212212 ss<<thr;
213213 ss>>tartxt;
214- string warningtxt = " ( " +info+" Chebyshev error = " +fractxt+" > threshold = " +tartxt+" ) Please add more expansion terms for Chebychev expansion ." ;
214+ string warningtxt = " ( " +info+" Chebyshev error = " +fractxt+" > threshold = " +tartxt+" ) Maybe you should increase the parameter \" nche_sto \" for more accuracy ." ;
215215 ModuleBase::WARNING (" Stochastic_Chebychev" , warningtxt);
216216 }
217217 // ===============================
@@ -232,6 +232,7 @@ void Stochastic_Iter::itermu(const int iter, elecstate::ElecState* pes)
232232 {
233233 dmu = 0.1 ;
234234 th_ne = 1e-2 * GlobalV::SCF_THR * GlobalC::CHR.nelec ;
235+ th_ne = std::min (th_ne, 1e-5 );
235236 }
236237 this ->stofunc .mu = mu0 - dmu;
237238 double ne1 = calne (pes);
@@ -484,7 +485,6 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, elecstate::ElecState* pe
484485 pes->eband += sto_eband;
485486 // ---------------------cal rho-------------------------
486487 double *sto_rho = new double [nrxx];
487- // int npwall = npwx * nchip;
488488
489489 double dr3 = GlobalC::ucell.omega / GlobalC::wfcpw->nxyz ;
490490 double tmprho, tmpne;
@@ -519,6 +519,7 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, elecstate::ElecState* pe
519519 }
520520 delete[] porter;
521521#ifdef __MPI
522+ // temporary, rho_mpi should be rewrite as a tool function! Now it only treats pes->charge->rho
522523 pes->charge ->rho_mpi ();
523524#endif
524525 for (int ir = 0 ; ir < nrxx; ++ir)
@@ -534,33 +535,34 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf, elecstate::ElecState* pe
534535 MPI_Allreduce (MPI_IN_PLACE,&sto_ne,1 ,MPI_DOUBLE,MPI_SUM,PARAPW_WORLD);
535536 MPI_Allreduce (MPI_IN_PLACE,sto_rho,nrxx,MPI_DOUBLE,MPI_SUM,PARAPW_WORLD);
536537#endif
537-
538- double factor;
539- if (abs (sto_ne) > 1e-15 )
538+ double factor = targetne/(KS_ne+sto_ne);
539+ if (abs (factor-1 ) > 1e-10 )
540540 {
541- factor = (targetne - KS_ne) / sto_ne;
542541 GlobalV::ofs_running<<" Renormalize rho from ne = " <<sto_ne+KS_ne<<" to targetne = " <<targetne<<endl;
543542 }
544543 else
545544 factor = 1 ;
546545
547- if (GlobalV::MY_STOGROUP == 0 )
546+ if (GlobalV::MY_STOGROUP == 0 )
548547 {
549548 if (GlobalV::NBANDS > 0 )
550549 ModuleBase::GlobalFunc::DCOPY (ksrho, pes->charge ->rho [0 ], nrxx);
551550 else
552551 ModuleBase::GlobalFunc::ZEROS (pes->charge ->rho [0 ], nrxx);
553552 }
554553
555- if (GlobalV::MY_STOGROUP == 0 )
554+
555+ if (GlobalV::MY_STOGROUP == 0 )
556+ {
556557 for (int is = 0 ; is < 1 ; ++is)
557558 {
558559 for (int ir = 0 ; ir < nrxx; ++ir)
559560 {
560- pes->charge ->rho [is][ir] += sto_rho[ir] * factor;
561+ pes->charge ->rho [is][ir] += sto_rho[ir];
562+ pes->charge ->rho [is][ir] *= factor;
561563 }
562564 }
563-
565+ }
564566 delete[] sto_rho;
565567 delete[] ksrho;
566568 ModuleBase::timer::tick (" Stochastic_Iter" , " sum_stoband" );
0 commit comments