Skip to content

Commit a8e203a

Browse files
committed
Refactor: finish SDFT
Some bugs may exist. They will be checked and tests should be added in the next step.
1 parent 8094ec8 commit a8e203a

File tree

12 files changed

+67
-72
lines changed

12 files changed

+67
-72
lines changed

source/Makefile.vars

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ CPLUSPLUS_MPI = mpiicpc
44

55
LAPACK_DIR = $(MKLROOT)
66

7-
FFTW_DIR = /home/qianrui/intelcompile/fftw_3.3.8
7+
FFTW_DIR = /public/software/fftw_3.3.8
88

9-
ELPA_DIR = /home/qianrui/intelcompile/elpa_21.05.002
9+
ELPA_DIR = /public/software/elpa_21.05.002
1010
ELPA_INCLUDE_DIR = ${ELPA_DIR}/include/elpa-2021.05.002
1111

12-
CEREAL_DIR = /home/qianrui/headfile/cereal
12+
CEREAL_DIR = /public/software/cereal
1313

1414
# LIBXC_DIR = /public/software/libxc-5.0.0
1515

source/input.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ void Input::Default(void)
140140
pw_seed = 1;
141141
nche_sto = 0;
142142
seed_sto = 0;
143+
nstogroup = 1;
143144
kpar = 1;
144145
berry_phase = false;
145146
gdir = 3;
@@ -517,8 +518,8 @@ bool Input::Read(const std::string &fn)
517518
else if (strcmp("nbands", word) == 0) // number of atom bands
518519
{
519520
read_value(ifs, nbands);
520-
if (nbands <= 0)
521-
ModuleBase::WARNING_QUIT("Input", "NBANDS must > 0");
521+
if (nbands < 0)
522+
ModuleBase::WARNING_QUIT("Input", "NBANDS must >= 0");
522523
}
523524
else if (strcmp("nbands_sto", word) == 0) // number of stochastic bands
524525
{
@@ -2118,7 +2119,7 @@ void Input::Check(void)
21182119
ModuleBase::TITLE("Input", "Check");
21192120

21202121
if (nbands < 0)
2121-
ModuleBase::WARNING_QUIT("Input", "NBANDS must > 0");
2122+
ModuleBase::WARNING_QUIT("Input", "NBANDS must >= 0");
21222123
// if(nbands_istate < 0) ModuleBase::WARNING_QUIT("Input","NBANDS_ISTATE must > 0");
21232124
if (nb2d < 0)
21242125
ModuleBase::WARNING_QUIT("Input", "nb2d must > 0");

source/input.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ class Input
179179
//==========================================================
180180
// charge mixing
181181
//==========================================================
182-
std::string mixing_mode; // "plain","broden",...
182+
std::string mixing_mode; // "plain","broyden",...
183183
double mixing_beta; // 0 : no_mixing
184-
int mixing_ndim; // used in Broden method
184+
int mixing_ndim; // used in Broyden method
185185
double mixing_gg0; // used in kerker method. mohan add 2014-09-27
186186

187187
//==========================================================

source/module_cell/unitcell_pseudo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class UnitCell_pseudo : public UnitCell
3131
int lmax_ppwf;
3232
int lmaxmax; // liuyu 2021-07-04
3333
bool init_vel; // liuyu 2021-07-15
34-
double nelec;
34+
// double nelec;
3535

3636
public: // member functions
3737
UnitCell_pseudo();

source/module_esolver/esolver_ks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void ESolver_KS:: set_ethr(const int istep, const int iter)
165165
this->diag_ethr = std::min( this->diag_ethr, 0.1*this->drho/ std::max(1.0, GlobalC::CHR.nelec));
166166

167167
}
168-
if(GlobalV::BASIS_TYPE=="lcao" || GlobalV::BASIS_TYPE=="lcao_in_pw")
168+
if(GlobalV::BASIS_TYPE=="lcao" || GlobalV::BASIS_TYPE=="lcao_in_pw" || GlobalV::CALCULATION.substr(0,3)=="sto")
169169
{
170170
this->diag_ethr = 0.0;
171171
}

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ void ESolver_SDFT_PW::Init(Input &inp, UnitCell_pseudo &cell)
2929
stowf.init(GlobalC::kv.nks);
3030
if(INPUT.nbands_sto != 0) Init_Sto_Orbitals(this->stowf, INPUT.seed_sto);
3131
else Init_Com_Orbitals(this->stowf, GlobalC::kv);
32+
for (int ik =0 ; ik < GlobalC::kv.nks; ++ik)
33+
{
34+
this->stowf.shchi[ik].create(this->stowf.nchip[ik],GlobalC::wf.npwx,false);
35+
if(GlobalV::NBANDS > 0)
36+
{
37+
this->stowf.chiortho[ik].create(this->stowf.nchip[ik],GlobalC::wf.npwx,false);
38+
}
39+
}
3240
stoiter.init(GlobalC::wf.npwx, this->stowf.nchip);
3341
}
3442

@@ -38,7 +46,7 @@ void ESolver_SDFT_PW::beforescf()
3846
// if(NITER==0)
3947
// {
4048
// int iter = 1;
41-
// ETHR = 0.1*DRHO2/ std::max(1.0, ucell.nelec);
49+
// ETHR = 0.1*DRHO2/ std::max(1.0, CHR.nelec);
4250
// double *h_diag = new double[wf.npwx * NPOL];
4351
// for (int ik = 0;ik < kv.nks;ik++)
4452
// {

source/src_ions/ions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void Ions::opt_ions_pw(ModuleESolver::ESolver *p_esolver)
7979

8080
// mohan added eiter to count for the electron iteration number, 2021-01-28
8181
int eiter=0;
82-
if (GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="md" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax") // pengfei 2014-10-13
82+
if (GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="md" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax" || GlobalV::CALCULATION.substr(0,3)=="sto") // pengfei 2014-10-13
8383
{
8484
#ifdef __LCAO
8585
#ifdef __MPI

source/src_parallel/parallel_kpoints.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void Parallel_Kpoints::init_pools(void)
6363
#ifdef __MPI
6464
void Parallel_Kpoints::divide_pools(void)
6565
{
66+
ModuleBase::TITLE("Parallel_Kpoints", "divide_pools");
6667
if (GlobalV::NPROC < GlobalV::KPAR)
6768
{
6869
std::cout<<"\n NPROC=" << GlobalV::NPROC << " KPAR=" << GlobalV::KPAR;

source/src_pw/energy.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,21 @@ void energy::calculate_etot(void)
9393
+ evdw; // Peize Lin add evdw 2021.03.09
9494

9595
//Quxin adds for DFT+U energy correction on 20201029
96-
/*
97-
std::cout << std::resetiosflags(ios::scientific) << std::endl;
98-
std::cout << std::setprecision(16) << std::endl;
99-
std::cout << " eband=" << eband << std::endl;
100-
std::cout << " deband=" << deband << std::endl;
101-
std::cout << " etxc-etxcc=" << H_XC_pw::etxc-etxcc << std::endl;
102-
std::cout << " ewld=" << H_Ewald_pw::ewald_energy << std::endl;
103-
std::cout << " ehart=" << H_Hartree_pw::hartree_energy << std::endl;
104-
std::cout << " demet=" << demet << std::endl;
105-
std::cout << " descf=" << descf << std::endl;
106-
std::cout << " exx=" << exx << std::endl;
107-
std::cout << " efiled=" << Efield::etotefield << std::endl;
108-
std::cout << " total= "<<etot<<std::endl;
109-
std::cout << " fermienergy= "<<ef<<std::endl;*/
96+
97+
// std::cout << std::resetiosflags(ios::scientific) << std::endl;
98+
// std::cout << std::setprecision(16) << std::endl;
99+
// std::cout << " eband=" << eband << std::endl;
100+
// std::cout << " deband=" << deband << std::endl;
101+
// std::cout << " etxc-etxcc=" <<etxc-etxcc << std::endl;
102+
// std::cout << " ewld=" << H_Ewald_pw::ewald_energy << std::endl;
103+
// std::cout << " ehart=" << H_Hartree_pw::hartree_energy << std::endl;
104+
// std::cout << " demet=" << demet << std::endl;
105+
// std::cout << " descf=" << descf << std::endl;
106+
// std::cout << " exx=" << exx << std::endl;
107+
// std::cout << " efiled=" << Efield::etotefield << std::endl;
108+
// std::cout << " total= "<<etot<<std::endl;
109+
// std::cout << " fermienergy= "<<ef<<std::endl;
110+
110111
#ifdef __LCAO
111112
if(INPUT.dft_plus_u)
112113
{

source/src_pw/sto_iter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Stochastic_Iter::~Stochastic_Iter()
2828
void Stochastic_Iter::init(const int dim, int* nchip_in)
2929
{
3030
nchip = nchip_in;
31-
targetne = GlobalC::ucell.nelec;
31+
targetne = GlobalC::CHR.nelec;
3232
stoche.init( dim, INPUT.nche_sto );
3333
stohchi.init();
3434
delete [] spolyv;
@@ -145,13 +145,13 @@ void Stochastic_Iter::itermu(int &iter)
145145
if(iter == 1)
146146
{
147147
dmu = 2;
148-
th_ne = 0.1 * GlobalV::SCF_THR * GlobalC::ucell.nelec;
149-
std::cout<<"th_ne "<<th_ne<<std::endl;
148+
th_ne = 0.1 * GlobalV::SCF_THR * GlobalC::CHR.nelec;
149+
// std::cout<<"th_ne "<<th_ne<<std::endl;
150150
}
151151
else
152152
{
153153
dmu = 0.1;
154-
th_ne = GlobalV::SCF_THR * 1e-2 * GlobalC::ucell.nelec;
154+
th_ne = GlobalV::SCF_THR * 1e-2 * GlobalC::CHR.nelec;
155155
}
156156
mu = mu0 - dmu;
157157
double ne1 = calne();
@@ -188,7 +188,7 @@ void Stochastic_Iter::itermu(int &iter)
188188
mu2 += dmu;
189189
mu = mu2;
190190
ne2 = calne();
191-
cout<<"Reset mu2 form "<<mu2-dmu<<" to "<<mu2<<endl;
191+
// cout<<"Reset mu2 from "<<mu2-dmu<<" to "<<mu2<<endl;
192192
dmu *= 2;
193193
}
194194
int count = 0;
@@ -219,12 +219,12 @@ void Stochastic_Iter::itermu(int &iter)
219219
"Cannot converge feimi energy. Please retry with different random number");
220220
}
221221
}
222-
std::cout<<"Converge fermi energy = "<<mu<<" Ry in "<<count<<" steps."<<std::endl;
222+
GlobalV::ofs_running<<"Converge fermi energy = "<<mu<<" Ry in "<<count<<" steps."<<std::endl;
223223
//precision check
224224
double tmpre;
225225
tmpre = stoche.coef[stoche.norder-1] * spolyv[stoche.norder-1];
226226
MPI_Allreduce(MPI_IN_PLACE, &tmpre, 1, MPI_DOUBLE, MPI_SUM , MPI_COMM_WORLD);
227-
std::cout<<"Chebyshev Precision: "<<abs(tmpre/targetne)<<std::endl;
227+
GlobalV::ofs_running<<"Chebyshev Precision: "<<abs(tmpre/targetne)<<std::endl;
228228
if(tmpre/targetne > GlobalV::SCF_THR )
229229
{
230230
stringstream ss;
@@ -458,7 +458,7 @@ void Stochastic_Iter::sum_stoband(Stochastic_WF& stowf)
458458
GlobalC::en.demet *= Occupy::gaussian_parameter;
459459

460460
cout.precision(12);
461-
cout<<"Renormalize rho from ne = "<<sto_ne+KS_ne<<" to targetne = "<<targetne<<endl;
461+
GlobalV::ofs_running<<"Renormalize rho from ne = "<<sto_ne+KS_ne<<" to targetne = "<<targetne<<endl;
462462

463463
double factor;
464464
if(abs(sto_ne) > 1e-20)

0 commit comments

Comments
 (0)