Skip to content

Commit e92f03f

Browse files
committed
change renormalization of density in SDFT
1 parent 673d008 commit e92f03f

File tree

7 files changed

+53
-36
lines changed

7 files changed

+53
-36
lines changed

source/module_esolver/esolver_sdft_pw_tool.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,9 @@ void ESolver_SDFT_PW::sKG(const int nche_KG, const double fwhmin, const double w
456456

457457
void ESolver_SDFT_PW:: caldos( const int nche_dos, const double sigmain, const double emin, const double emax, const double de)
458458
{
459-
cout<<"Calculating Dos...."<<endl;
459+
cout<<"========================="<<endl;
460+
cout<<"###Calculating Dos....###"<<endl;
461+
cout<<"========================="<<endl;
460462
ModuleBase::Chebyshev<double> che(nche_dos);
461463
const int nk = GlobalC::kv.nks;
462464
Stochastic_Iter& stoiter = ((hsolver::HSolverPW_SDFT*)phsol)->stoiter;
@@ -465,8 +467,10 @@ void ESolver_SDFT_PW:: caldos( const int nche_dos, const double sigmain, const d
465467

466468
double * spolyv = new double [nche_dos];
467469
ModuleBase::GlobalFunc::ZEROS(spolyv, nche_dos);
470+
cout<<"1. TracepolyA:"<<endl;
468471
for (int ik = 0;ik < nk;ik++)
469472
{
473+
cout<<"ik: "<<ik+1<<endl;
470474
if(nk > 1)
471475
{
472476
this->phami->updateHk(ik);
@@ -486,6 +490,7 @@ void ESolver_SDFT_PW:: caldos( const int nche_dos, const double sigmain, const d
486490
spolyv[i] += che.polytrace[i] * GlobalC::kv.wk[ik] / 2 ;
487491
}
488492
}
493+
489494
string dosfile = GlobalV::global_out_dir+"DOS1_smearing.dat";
490495
ofstream ofsdos(dosfile.c_str());
491496
int ndos = int((emax-emin) / de)+1;
@@ -495,6 +500,9 @@ void ESolver_SDFT_PW:: caldos( const int nche_dos, const double sigmain, const d
495500
double sum = 0;
496501
double error = 0;
497502
ofsdos<<setw(8)<<"## E(eV) "<<setw(20)<<"dos(eV^-1)"<<setw(20)<<"sum"<<setw(20)<<"Error(eV^-1)"<<endl;
503+
cout<<"2. Dos:"<<endl;
504+
int n10 = ndos/10;
505+
int percent = 10;
498506
for(int ie = 0; ie < ndos; ++ie)
499507
{
500508
stoiter.stofunc.targ_e = (emin + ie * de) / ModuleBase::Ry_to_eV;
@@ -525,7 +533,14 @@ void ESolver_SDFT_PW:: caldos( const int nche_dos, const double sigmain, const d
525533
dos[ie] = (KS_dos + sto_dos) / ModuleBase::Ry_to_eV;
526534
sum += dos[ie];
527535
ofsdos <<setw(8)<< emin + ie * de <<setw(20)<<dos[ie]<<setw(20)<<sum * de <<setw(20) <<error <<endl;
536+
if(ie%n10 == n10 -1)
537+
{
538+
cout<<percent<<"%"<<" ";
539+
percent+=10;
540+
}
528541
}
542+
cout<<endl;
543+
cout<<"Finish DOS"<<endl;
529544
cout<<scientific<<"DOS max Chebyshev Error: "<<error<<endl;
530545
delete[] dos;
531546
delete[] spolyv;

source/src_pw/sto_iter.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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");
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -321.3205422051483993
2-
etotperatomref -160.6602711026
3-
totalforceref 4.120026
4-
totalstressref 2048.414311
5-
totaltimeref +0.57339
1+
etotref -321.3205436122449896
2+
etotperatomref -160.6602718061
3+
totalforceref 4.120030
4+
totalstressref 2048.414648
5+
totaltimeref +0.88273
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -321.3172254412079
2-
etotperatomref -160.6586127206
3-
totalforceref 4.252396
4-
totalstressref 2050.525310
5-
totaltimeref +0.97192
1+
etotref -321.3172326953681
2+
etotperatomref -160.6586163477
3+
totalforceref 4.252426
4+
totalstressref 2050.529180
5+
totaltimeref +1.5481
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -103.9856590797226943
2-
etotperatomref -51.9928295399
3-
totalforceref 197.979934
4-
totalstressref 257668.767204
5-
totaltimeref +4.74845
1+
etotref -103.9856591181504513
2+
etotperatomref -51.9928295591
3+
totalforceref 197.979930
4+
totalstressref 257668.766684
5+
totaltimeref +5.34573
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -323.3085526932184166
2-
etotperatomref -161.6542763466
3-
totalforceref 5.008278
4-
totalstressref 1832.775736
5-
totaltimeref +0.40613
1+
etotref -323.3085579669327672
2+
etotperatomref -161.6542789835
3+
totalforceref 5.008270
4+
totalstressref 1832.776628
5+
totaltimeref +0.76110
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
etotref -324.2147557509094895
2-
etotperatomref -162.1073778755
3-
totalforceref 4.067434
4-
totalstressref 1839.372263
5-
totaltimeref +2.42942
1+
etotref -324.2147671023046769
2+
etotperatomref -162.1073835512
3+
totalforceref 4.067650
4+
totalstressref 1839.374349
5+
totaltimeref +2.48875

0 commit comments

Comments
 (0)