Skip to content

Commit 54091f2

Browse files
authored
Merge pull request #917 from deepmodeling/SDFT
Merge SDFT to develop
2 parents 7e9a8b7 + 8617aea commit 54091f2

Some content is hidden

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

46 files changed

+1594
-1948
lines changed

docs/input-main.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
- [System variables](#system-variables)
1010

11-
[suffix](#suffix) | [ntype](#ntype) | [calculation](#calculation) | [symmetry](#symmetry) | [kpar](#kpar) | [latname](#latname) | [init_wfc](#init_wfc) | [init_chg](#init_chg) | [init_vel](#init_vel) | [nelec](#nelec) | [tot_magnetization](#tot-magnetization) | [dft_functional](#dft-functional) | [pseudo_type](#pseudo-type) | [pseudo_rcut](#pseudo-rcut) | [pseudo_mesh](#pseudo_mesh) | [mem_saver](#mem-saver) | [diago_proc](#diago_proc) | [nbspline](#nbspline)
11+
[suffix](#suffix) | [ntype](#ntype) | [calculation](#calculation) | [symmetry](#symmetry) | [kpar](#kpar) | [bndpar](#bndpar) | [latname](#latname) | [init_wfc](#init_wfc) | [init_chg](#init_chg) | [init_vel](#init_vel) | [nelec](#nelec) | [tot_magnetization](#tot-magnetization) | [dft_functional](#dft-functional) | [pseudo_type](#pseudo-type) | [pseudo_rcut](#pseudo-rcut) | [pseudo_mesh](#pseudo_mesh) | [mem_saver](#mem-saver) | [diago_proc](#diago_proc) | [nbspline](#nbspline)
1212

1313
- [Variables related to input files](#variables-related-to-input-files)
1414

@@ -24,7 +24,7 @@
2424

2525
- [Electronic structure](#electronic-structure)
2626

27-
[basis_type](#basis-type) | [ks_solver](#ks-solver) | [nbands](#nbands) | [nbands_istate](#nbands-istate) | [nspin](#nspin) | [occupations](#occupations) | [smearing_method](#smearing_method) | [smearing_sigma](#smearing_sigma) | [mixing_type](#mixing-type) | [mixing_beta](#mixing-beta) | [mixing_ndim](#mixing-ndim) | [mixing_gg0](#mixing-gg0) | [gamma_only](#gamma-only) | [printe](#printe) | [scf_nmax](#scf_nmax) | [scf_thr](#scf_thr) | [chg_extrap](#chg_extrap)
27+
[basis_type](#basis-type) | [ks_solver](#ks-solver) | [nbands](#nbands) | [nbands_sto](#nbands_sto) | [nbands_istate](#nbands-istate) | [nspin](#nspin) | [occupations](#occupations) | [smearing_method](#smearing_method) | [smearing_sigma](#smearing_sigma) | [mixing_type](#mixing-type) | [mixing_beta](#mixing-beta) | [mixing_ndim](#mixing-ndim) | [mixing_gg0](#mixing-gg0) | [gamma_only](#gamma-only) | [printe](#printe) | [scf_nmax](#scf_nmax) | [scf_thr](#scf_thr) | [chg_extrap](#chg_extrap) | [nche_sto](#nche_sto) | [emin_sto](#emin_sto) | [emax_sto](#emax_sto) | [seed_sto](#seed_sto)
2828

2929
- [Geometry relaxation](#geometry-relaxation)
3030

@@ -150,6 +150,12 @@ This part of variables are used to control general system parameters.
150150
- **Description**: devide all processors into kpar groups, and k points will be distributed among each group. The value taken should be less than or equal to the number of k points as well as the number of MPI threads.
151151
- **Default**: 1
152152

153+
#### bndpar
154+
155+
- **Type**: Integer
156+
- **Description**: devide all processors into bndpar groups, and bands (only stochastic orbitals now) will be distributed among each group. It should be larger than 0.
157+
- **Default**: 1
158+
153159
#### latname
154160

155161
- **Type**: String
@@ -453,6 +459,14 @@ calculations.
453459
- nspin=1: 1.2\*occupied_bands, occupied_bands+10)
454460
- nspin=2: max(1.2\*nelec, nelec+20)
455461
462+
#### nbands_sto
463+
464+
- **Type**: Integer
465+
- **Description**:
466+
- nbands_sto>0: Number of stochastic orbitals to calculate in stochastic DFT (SDFT) or mix stochastic-deterministic (MDFT). More bands obtain more precise results or smaller stochastic errors ($ \propto 1/\sqrt{N_{\chi}}$);
467+
- nbands_sto=0: Complete basis will be used to replace stochastic orbitals with the Chebyshev method (CT) and it will get the results the same as KSDFT without stochastic errors.
468+
- **Default**: 0
469+
456470
#### nbands_istate
457471
458472
- **Type**: Integer
@@ -551,6 +565,32 @@ calculations.
551565
- second-order: second-order extrapolation
552566
- **Default**:atomic
553567
568+
#### nche_sto
569+
570+
- **Type**: Integer
571+
- **Description**: Chebyshev expansion orders for SDFT, MDFT, CT methods.
572+
- **Default**:5
573+
574+
#### emin_sto
575+
576+
- **Type**: Real
577+
- **Description**: Trial energy to guess the lower bound of eigen energies of the Hamitonian Operator $\hat{H}$. The unit is Ry.
578+
- **Default**:0.0
579+
580+
#### emax_sto
581+
582+
- **Type**: Real
583+
- **Description**: Trial energy to guess the upper bound of eigen energies of the Hamitonian Operator $\hat{H}$. The unit is Ry.
584+
- **Default**:0.0
585+
586+
#### seed_sto
587+
588+
- **Type**: Integer
589+
- **Description**: The random seed to generate stochastic orbitals.
590+
- seed_sto>=0: Stochastic orbitals have the form of $\exp(i2\pi\theta(G))$, where $\theta$ is a uniform distribution in $(0,1)$. If seed_sto=0, the seed is decided by time(NULL).
591+
- seed_sto<=-1: Stochastic orbitals have the form of $\pm1$ with the equal probability. If seed_sto=-1, the seed is decided by time(NULL).
592+
- **Default**:0
593+
554594
### Geometry relaxation
555595
556596
This part of variables are used to control the geometry relaxation.

source/Makefile.Objects

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ soc.o\
5757
to_wannier90.o \
5858
unk_overlap_pw.o \
5959
berryphase.o \
60-
sto_elec.o\
61-
sto_wf.o\
6260
sto_iter.o\
61+
sto_wf.o\
6362
sto_hchi.o\
6463
sto_che.o\
6564

source/driver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ void Driver::atomic_world(void)
9696
ModuleESolver::ESolver *p_esolver;
9797
if(GlobalV::BASIS_TYPE=="pw" || GlobalV::BASIS_TYPE=="lcao_in_pw")
9898
{
99-
use_ensol = "ksdft_pw";
99+
if(GlobalV::CALCULATION.substr(0,3) == "sto") use_ensol = "sdft_pw";
100+
else use_ensol = "ksdft_pw";
100101
//We set it temporarily
101102
//Finally, we have ksdft_pw, ksdft_lcao, sdft_pw, ofdft, lj, eam, etc.
102103
ModuleESolver::init_esolver(p_esolver, use_ensol);

source/input.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ void Input::Default(void)
138138
nbands_sto = 0;
139139
nbands_istate = 5;
140140
pw_seed = 1;
141-
nche_sto = 0;
141+
nche_sto = 5;
142142
seed_sto = 0;
143-
stotype = "pw";
143+
bndpar = 1;
144144
kpar = 1;
145145
berry_phase = false;
146146
gdir = 3;
@@ -519,8 +519,8 @@ bool Input::Read(const std::string &fn)
519519
else if (strcmp("nbands", word) == 0) // number of atom bands
520520
{
521521
read_value(ifs, nbands);
522-
if (nbands <= 0)
523-
ModuleBase::WARNING_QUIT("Input", "NBANDS must > 0");
522+
if (nbands < 0)
523+
ModuleBase::WARNING_QUIT("Input", "NBANDS must >= 0");
524524
}
525525
else if (strcmp("nbands_sto", word) == 0) // number of stochastic bands
526526
{
@@ -553,9 +553,9 @@ bool Input::Read(const std::string &fn)
553553
{
554554
read_value(ifs, emin_sto);
555555
}
556-
else if (strcmp("stotype", word) == 0)
556+
else if (strcmp("bndpar", word) == 0)
557557
{
558-
read_value(ifs, stotype);
558+
read_value(ifs, bndpar);
559559
}
560560
else if (strcmp("kpar", word) == 0) // number of pools
561561
{
@@ -1803,6 +1803,7 @@ void Input::Default_2(void) // jiyy add 2019-08-04
18031803
vdw_radius = "95";
18041804
}
18051805
}
1806+
if(calculation.substr(0,3) != "sto") bndpar = 1;
18061807
}
18071808
#ifdef __MPI
18081809
void Input::Bcast()
@@ -1833,7 +1834,7 @@ void Input::Bcast()
18331834
Parallel_Common::bcast_int(pw_seed);
18341835
Parallel_Common::bcast_double(emax_sto);
18351836
Parallel_Common::bcast_double(emin_sto);
1836-
Parallel_Common::bcast_string(stotype);
1837+
Parallel_Common::bcast_int(bndpar);
18371838
Parallel_Common::bcast_int(kpar);
18381839
Parallel_Common::bcast_bool(berry_phase);
18391840
Parallel_Common::bcast_int(gdir);
@@ -2124,7 +2125,7 @@ void Input::Check(void)
21242125
ModuleBase::TITLE("Input", "Check");
21252126

21262127
if (nbands < 0)
2127-
ModuleBase::WARNING_QUIT("Input", "NBANDS must > 0");
2128+
ModuleBase::WARNING_QUIT("Input", "NBANDS must >= 0");
21282129
// if(nbands_istate < 0) ModuleBase::WARNING_QUIT("Input","NBANDS_ISTATE must > 0");
21292130
if (nb2d < 0)
21302131
ModuleBase::WARNING_QUIT("Input", "nb2d must > 0");
@@ -2180,7 +2181,7 @@ void Input::Check(void)
21802181
*/
21812182
this->relax_nmax = 1;
21822183
}
2183-
else if (calculation == "scf-sto") // qianrui 2021-2-20
2184+
else if (calculation == "sto-scf") // qianrui 2021-2-20
21842185
{
21852186
if (mem_saver == 1)
21862187
{

source/input.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ class Input
6464
// Stochastic DFT
6565
//==========================================================
6666
int nche_sto; // number of orders for Chebyshev expansion in stochastic DFT //qinarui 2021-2-5
67+
int nbands_sto; // number of stochastic bands //qianrui 2021-2-5
6768
int seed_sto; // random seed for sDFT
6869
double emax_sto; // Emax & Emin to normalize H
6970
double emin_sto;
70-
std::string stotype;
71-
int nbands_sto; // number of stochastic bands //qianrui 2021-2-5
71+
int bndpar; //parallel for stochastic/deterministic bands
7272

7373
//==========================================================
7474
// electrons / spin
@@ -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/input_conv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void Input_Conv::Convert(void)
6161
GlobalV::KPAR = temp_nproc;
6262
#else
6363
GlobalV::KPAR = INPUT.kpar;
64+
GlobalV::NSTOGROUP = INPUT.bndpar;
6465
#endif
6566
GlobalV::CALCULATION = INPUT.calculation;
6667

source/module_base/global_variable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ int out_mul = 0; // qifeng add 2019/9/10
101101
//----------------------------------------------------------
102102
int NPROC = 1;
103103
int KPAR = 1;
104+
int NSTOGROUP = 1;
104105
int MY_RANK = 0;
105106
int MY_POOL = 0;
107+
int MY_STOGROUP = 0;
106108
int NPROC_IN_POOL = 1;
109+
int NPROC_IN_STOGROUP = 1;
107110
int RANK_IN_POOL = 0;
111+
int RANK_IN_STOGROUP = 0;
108112
int DRANK = -1; // mohan add 2012-01-13, must be -1, so we can recognize who didn't in DIAG_WORLD
109113
int DSIZE = KPAR;
110114
int DCOLOR = -1;

source/module_base/global_variable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ extern int out_mul; // qifeng add 2019/9/10
116116
//========================================================================
117117
extern int NPROC;
118118
extern int KPAR;
119+
extern int NSTOGROUP;
119120
extern int MY_RANK;
120121
extern int MY_POOL;
122+
extern int MY_STOGROUP;
121123
extern int NPROC_IN_POOL;
124+
extern int NPROC_IN_STOGROUP;
122125
extern int RANK_IN_POOL;
126+
extern int RANK_IN_STOGROUP;
123127
extern int DRANK;
124128
extern int DSIZE;
125129
extern int DCOLOR;

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_elecstate/elecstate_pw.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,19 @@ void ElecStatePW::parallelK()
4141
{
4242
#ifdef __MPI
4343
charge->rho_mpi();
44-
if (GlobalV::CALCULATION != "scf-sto" && GlobalV::CALCULATION != "relax-sto"
45-
&& GlobalV::CALCULATION != "md-sto") // qinarui add it temporarily.
46-
{
47-
//==================================
48-
// Reduce all the Energy in each cpu
49-
//==================================
50-
this->eband /= GlobalV::NPROC_IN_POOL;
51-
Parallel_Reduce::reduce_double_all(this->eband);
52-
}
44+
if(GlobalV::CALCULATION.substr(0,3) == "sto") //qinarui add it 2021-7-21
45+
{
46+
GlobalC::en.eband /= GlobalV::NPROC_IN_POOL;
47+
MPI_Allreduce(MPI_IN_PLACE, &GlobalC::en.eband, 1, MPI_DOUBLE, MPI_SUM , STO_WORLD);
48+
}
49+
else
50+
{
51+
//==================================
52+
// Reduce all the Energy in each cpu
53+
//==================================
54+
GlobalC::en.eband /= GlobalV::NPROC_IN_POOL;
55+
Parallel_Reduce::reduce_double_all( GlobalC::en.eband );
56+
}
5357
#endif
5458
return;
5559
}

0 commit comments

Comments
 (0)