Skip to content

Commit 72bd505

Browse files
authored
Feature: add smooth ethr for all iter methods (#5732)
* update input parameter * add smooth ethr for all methods * fix integrated_test * Update input-main.md
1 parent 815bff5 commit 72bd505

File tree

10 files changed

+35
-18
lines changed

10 files changed

+35
-18
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- [ndx, ndy, ndz](#ndx-ndy-ndz)
3838
- [pw\_seed](#pw_seed)
3939
- [pw\_diag\_thr](#pw_diag_thr)
40+
- [diago\_smooth\_ethr](#diago_smooth_ethr)
4041
- [pw\_diag\_nmax](#pw_diag_nmax)
4142
- [pw\_diag\_ndim](#pw_diag_ndim)
4243
- [erf\_ecut](#erf_ecut)
@@ -777,6 +778,12 @@ These variables are used to control the plane wave related parameters.
777778
- **Description**: Only used when you use `ks_solver = cg/dav/dav_subspace/bpcg`. It indicates the threshold for the first electronic iteration, from the second iteration the pw_diag_thr will be updated automatically. **For nscf calculations with planewave basis set, pw_diag_thr should be <= 1e-3.**
778779
- **Default**: 0.01
779780

781+
### diago_smooth_ethr
782+
783+
- **Type**: bool
784+
- **Description**: If `TRUE`, the smooth threshold strategy, which applies a larger threshold (10e-5) for the empty states, will be implemented in the diagonalization methods. (This strategy should not affect total energy, forces, and other ground-state properties, but computational efficiency will be improved.) If `FALSE`, the smooth threshold strategy will not be applied.
785+
- **Default**: false
786+
780787
### pw_diag_nmax
781788

782789
- **Type**: Integer

source/module_hsolver/hsolver_pw.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace hsolver
2828

2929
#ifdef USE_PAW
3030
template <typename T, typename Device>
31-
void HSolverPW<T, Device>::paw_func_in_kloop(const int ik,
32-
const double tpiba)
31+
void HSolverPW<T, Device>::paw_func_in_kloop(const int ik, const double tpiba)
3332
{
3433
if (this->use_paw)
3534
{
@@ -97,7 +96,7 @@ void HSolverPW<T, Device>::call_paw_cell_set_currentk(const int ik)
9796
}
9897

9998
template <typename T, typename Device>
100-
void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi,
99+
void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi,
101100
elecstate::ElecState* pes,
102101
const double tpiba,
103102
const int nat)
@@ -211,10 +210,10 @@ void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi,
211210
#endif
212211

213212
template <typename T, typename Device>
214-
void HSolverPW<T, Device>::cal_ethr_band(const double& wk,
215-
const double* wg,
216-
const double& ethr,
217-
std::vector<double>& ethrs)
213+
void HSolverPW<T, Device>::cal_smooth_ethr(const double& wk,
214+
const double* wg,
215+
const double& ethr,
216+
std::vector<double>& ethrs)
218217
{
219218
// threshold for classifying occupied and unoccupied bands
220219
const double occ_threshold = 1e-2;
@@ -288,7 +287,7 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
288287
pHamilt->updateHk(ik);
289288

290289
#ifdef USE_PAW
291-
this->paw_func_in_kloop(ik,tpiba);
290+
this->paw_func_in_kloop(ik, tpiba);
292291
#endif
293292

294293
/// update psi pointer for each k point
@@ -297,14 +296,13 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
297296
// template add precondition calculating here
298297
update_precondition(precondition, ik, this->wfc_basis->npwk[ik], Real(pes->pot->get_vl_of_0()));
299298

300-
// only dav_subspace method used smooth threshold for all bands now,
301-
// for other methods, this trick can be added in the future to accelerate calculation without accuracy loss.
302-
if (this->method == "dav_subspace")
299+
// use smooth threshold for all iter methods
300+
if (PARAM.inp.diago_smooth_ethr == true)
303301
{
304-
this->cal_ethr_band(pes->klist->wk[ik],
305-
&pes->wg(ik, 0),
306-
DiagoIterAssist<T, Device>::PW_DIAG_THR,
307-
ethr_band);
302+
this->cal_smooth_ethr(pes->klist->wk[ik],
303+
&pes->wg(ik, 0),
304+
DiagoIterAssist<T, Device>::PW_DIAG_THR,
305+
ethr_band);
308306
}
309307

310308
#ifdef USE_PAW
@@ -347,7 +345,7 @@ void HSolverPW<T, Device>::solve(hamilt::Hamilt<T, Device>* pHamilt,
347345
reinterpret_cast<elecstate::ElecStatePW<T, Device>*>(pes)->psiToRho(psi);
348346

349347
#ifdef USE_PAW
350-
this->paw_func_after_kloop(psi, pes,tpiba,nat);
348+
this->paw_func_after_kloop(psi, pes, tpiba, nat);
351349
#endif
352350

353351
ModuleBase::timer::tick("HSolverPW", "solve");
@@ -473,7 +471,7 @@ void HSolverPW<T, Device>::hamiltSolvePsiK(hamilt::Hamilt<T, Device>* hm,
473471
}
474472
else if (this->method == "bpcg")
475473
{
476-
const int nband = psi.get_nbands();
474+
const int nband = psi.get_nbands();
477475
const int nbasis = psi.get_nbasis();
478476
auto ngk_pointer = psi.get_ngk_pointer();
479477
// hpsi_func (X, HX, ld, nvec) -> HX = H(X), X and HX blockvectors of size ld x nvec

source/module_hsolver/hsolver_pw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class HSolverPW
8888

8989
private:
9090
/// @brief calculate the threshold for iterative-diagonalization for each band
91-
void cal_ethr_band(const double& wk, const double* wg, const double& ethr, std::vector<double>& ethrs);
91+
void cal_smooth_ethr(const double& wk, const double* wg, const double& ethr, std::vector<double>& ethrs);
9292

9393
#ifdef USE_PAW
9494
void paw_func_in_kloop(const int ik,

source/module_io/read_input_item_elec_stru.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ void ReadInput::item_elec_stru()
314314
};
315315
this->add_item(item);
316316
}
317+
{
318+
Input_Item item("diago_smooth_ethr");
319+
item.annotation = "smooth ethr for iter methods";
320+
read_sync_bool(input.diago_smooth_ethr);
321+
this->add_item(item);
322+
}
317323
{
318324
Input_Item item("pw_diag_ndim");
319325
item.annotation = "dimension of workspace for Davidson diagonalization";

source/module_io/test/read_input_ptest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ TEST_F(InputParaTest, ParaRead)
154154
EXPECT_EQ(param.inp.diago_cg_prec, 1);
155155
EXPECT_EQ(param.inp.pw_diag_ndim, 4);
156156
EXPECT_DOUBLE_EQ(param.inp.pw_diag_thr, 1.0e-2);
157+
EXPECT_FALSE(param.inp.diago_smooth_ethr);
157158
EXPECT_EQ(param.inp.nb2d, 0);
158159
EXPECT_EQ(param.inp.nurse, 0);
159160
EXPECT_EQ(param.inp.t_in_h, 1);

source/module_io/test/support/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ erf_height 20 #the height of the energy step for reciprocal
5050
erf_sigma 4 #the width of the energy step for reciprocal vectors
5151
fft_mode 0 #mode of FFTW
5252
pw_diag_thr 0.01 #threshold for eigenvalues is cg electron iterations
53+
diago_smooth_ethr false #smooth ethr for iter methods
5354
scf_thr 1e-08 #charge density error
5455
scf_ene_thr 1e-06 #total energy error threshold
5556
scf_os_stop 1 #whether to stop scf when oscillation is detected

source/module_parameter/input_parameter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ struct Input_para
8686
int nspin = 1; ///< LDA ; LSDA ; non-linear spin
8787
int pw_diag_nmax = 50;
8888
double pw_diag_thr = 0.01; ///< used in cg method
89+
bool diago_smooth_ethr = false; ///< smooth ethr for iter methods
8990
int pw_diag_ndim = 4; ///< dimension of workspace for Davidson diagonalization
9091
int diago_cg_prec = 1; ///< mohan add 2012-03-31
9192

tests/integrate/104_PW_NC_magnetic/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mixing_beta 0.2
2222
mixing_ndim 10
2323

2424
ks_solver dav_subspace
25+
diago_smooth_ethr true
2526
pw_diag_ndim 2
2627
basis_type pw
2728
symmetry 0

tests/integrate/140_PW_15_SO/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lspinorb 1
3434

3535
basis_type pw
3636
ks_solver dav_subspace
37+
diago_smooth_ethr true
3738
pw_diag_ndim 2
3839
chg_extrap second-order
3940
out_dm 0

tests/integrate/160_PW_DJ_PK_PU_SO/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mixing_dmr 1
2727
mixing_gg0 1.1
2828

2929
ks_solver dav_subspace
30+
diago_smooth_ethr true
3031
pw_diag_ndim 2
3132
basis_type pw
3233
gamma_only 0

0 commit comments

Comments
 (0)