Skip to content

Commit 7d7723f

Browse files
authored
Merge pull request #920 from Qianruipku/SDFT
refactor: finish forces and stress for SDFT
2 parents 8617aea + 9766c3e commit 7d7723f

File tree

84 files changed

+1828
-339
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1828
-339
lines changed

source/Makefile.Objects

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ sto_iter.o\
6161
sto_wf.o\
6262
sto_hchi.o\
6363
sto_che.o\
64+
sto_forces.o\
65+
sto_stress_pw.o
6466

6567
OBJS_TOOLS=complexarray.o\
6668
complexmatrix.o \

source/input.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,6 +1804,7 @@ void Input::Default_2(void) // jiyy add 2019-08-04
18041804
}
18051805
}
18061806
if(calculation.substr(0,3) != "sto") bndpar = 1;
1807+
if(bndpar > GlobalV::NPROC) bndpar = GlobalV::NPROC;
18071808
}
18081809
#ifdef __MPI
18091810
void Input::Bcast()
@@ -2270,9 +2271,9 @@ void Input::Check(void)
22702271
ModuleBase::WARNING_QUIT("Input::Check", "calculate = istate is only availble for LCAO.");
22712272
}
22722273
}
2273-
else if (calculation == "md") // mohan add 2011-11-04
2274+
else if (calculation == "md" || calculation == "sto-md") // mohan add 2011-11-04
22742275
{
2275-
GlobalV::CALCULATION = "md";
2276+
GlobalV::CALCULATION = calculation;
22762277
symmetry = false;
22772278
cal_force = 1;
22782279
if (mdp.md_nstep == 0)

source/module_esolver/esolver_sdft_pw.cpp

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#include "../src_pw/global.h"
1010
#include "../src_pw/symmetry_rho.h"
1111
//----------------------------------------------
12+
//-----force-------------------
13+
#include "../src_pw/sto_forces.h"
14+
//-----stress------------------
15+
#include "../src_pw/sto_stress_pw.h"
16+
//---------------------------------------------------
1217

1318
namespace ModuleESolver
1419
{
@@ -43,57 +48,7 @@ void ESolver_SDFT_PW::Init(Input &inp, UnitCell_pseudo &cell)
4348
void ESolver_SDFT_PW::beforescf(const int istep)
4449
{
4550
ESolver_KS_PW::beforescf(istep);
46-
// if(NITER==0)
47-
// {
48-
// int iter = 1;
49-
// ETHR = 0.1*DRHO2/ std::max(1.0, CHR.nelec);
50-
// double *h_diag = new double[wf.npwx * NPOL];
51-
// for (int ik = 0;ik < kv.nks;ik++)
52-
// {
53-
// if(NBANDS > 0 && MY_STOGROUP == 0)
54-
// {
55-
// this->c_bands_k(ik,h_diag,istep+1);
56-
// }
57-
// else
58-
// {
59-
// hm.hpw.init_k(ik);
60-
// }
61-
// if(NBANDS > 0)
62-
// {
63-
// MPI_Bcast(wf.evc[ik].c, wf.npwx*NBANDS*2, MPI_DOUBLE , 0, PARAPW_WORLD);
64-
// MPI_Bcast(wf.ekb[ik], NBANDS, MPI_DOUBLE, 0, PARAPW_WORLD);
65-
// }
66-
// stoiter.stoche.ndmin = wf.npw;
67-
// stoiter.orthog(ik);
68-
// stoiter.checkemm(ik,iter);
69-
// }
70-
// for (int ik = 0;ik < kv.nks;ik++)
71-
// {
72-
// //init k
73-
// if(kv.nks > 1) hm.hpw.init_k(ik);
74-
// stoiter.stoche.ndmin = wf.npw;
75-
76-
// stoiter.sumpolyval_k(ik);
77-
// }
78-
// delete [] h_diag;
79-
// stoiter.itermu(iter);
80-
// stoiter.stoche.calcoef(Stochastic_Iter::nroot_fd);
81-
// for(int ik = 0; ik < kv.nks; ++ik)
82-
// {
83-
// //init k
84-
// if(kv.nks > 1) hm.hpw.init_k(ik);
85-
// stoiter.stoche.ndmin = wf.npw;
86-
// complex<double> * out, *pchi;
87-
// out = stowf.shchi[ik].c;
88-
// if(NBANDS > 0)
89-
// pchi = stowf.chiortho[ik].c;
90-
// else
91-
// pchi = stowf.chi0[ik].c;
92-
93-
// stoiter.stoche.calfinalvec(stoiter.stohchi.hchi_reciprocal, pchi, out, stoiter.nchip[ik]);
94-
// }
95-
96-
// }
51+
if(istep > 0 && INPUT.nbands_sto != 0) Update_Sto_Orbitals(this->stowf, INPUT.seed_sto);
9752
}
9853

9954
void ESolver_SDFT_PW::eachiterfinish(int iter)
@@ -292,11 +247,13 @@ void ESolver_SDFT_PW::cal_Energy(energy &en)
292247

293248
void ESolver_SDFT_PW::cal_Force(ModuleBase::matrix &force)
294249
{
295-
250+
Sto_Forces ff;
251+
ff.init(force, this->stowf);
296252
}
297253
void ESolver_SDFT_PW::cal_Stress(ModuleBase::matrix &stress)
298254
{
299-
255+
Sto_Stress_PW ss;
256+
ss.cal_stress(stress, this->stowf);
300257
}
301258

302259

source/run_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void Run_pw::plane_wave_line(ModuleESolver::ESolver *p_esolver)
4141

4242

4343

44-
if(GlobalV::CALCULATION == "md")
44+
if(GlobalV::CALCULATION == "md" || GlobalV::CALCULATION == "sto-md")
4545
{
4646
Run_MD_PW run_md_pw;
4747
run_md_pw.md_cells_pw(p_esolver);

source/src_ions/ions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void Ions::opt_ions_pw(ModuleESolver::ESolver *p_esolver)
141141
time_t fstart = time(NULL);
142142

143143

144-
if (GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax")
144+
if (GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax" || GlobalV::CALCULATION.substr(0,3)=="sto")
145145
{
146146
stop = this->after_scf(p_esolver, istep, force_step, stress_step); // pengfei Li 2018-05-14
147147
}
@@ -171,7 +171,7 @@ void Ions::opt_ions_pw(ModuleESolver::ESolver *p_esolver)
171171

172172
}
173173

174-
if(GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax")
174+
if(GlobalV::CALCULATION=="scf" || GlobalV::CALCULATION=="relax" || GlobalV::CALCULATION=="cell-relax" || GlobalV::CALCULATION.substr(0,3)=="sto")
175175
{
176176
GlobalV::ofs_running << "\n\n --------------------------------------------" << std::endl;
177177
GlobalV::ofs_running << std::setprecision(16);

source/src_pw/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ list(APPEND objects
2626
sto_iter.cpp
2727
sto_hchi.cpp
2828
sto_wf.cpp
29+
sto_forces.cpp
30+
sto_stress_pw.cpp
2931
stress_func_cc.cpp
3032
stress_func_ewa.cpp
3133
stress_func_gga.cpp

source/src_pw/forces.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Forces
2323

2424
void init(ModuleBase::matrix& force);
2525

26-
private:
26+
protected:
2727

2828
int nat;
2929
static double output_acc;

source/src_pw/run_md_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ void Run_MD_PW::md_force_virial(
206206

207207
// mohan added eiter to count for the electron iteration number, 2021-01-28
208208
int eiter = 0;
209-
if (GlobalV::CALCULATION == "md")
209+
if (GlobalV::CALCULATION == "md" || GlobalV::CALCULATION == "sto-md")
210210
{
211211
Electrons elec;
212212
#ifdef __LCAO

0 commit comments

Comments
 (0)