From 9d40ac606125cf9d0c893b75f7fb65055bd0ef0f Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Thu, 24 Oct 2024 21:22:24 +0800 Subject: [PATCH 1/3] SCF converges if both drho and dene is smaller than threshold --- docs/advanced/input_files/input-main.md | 2 +- source/module_esolver/esolver_ks.cpp | 2 +- source/module_io/test/read_input_ptest.cpp | 2 +- source/module_parameter/input_parameter.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 1c355366d6..77e2d8ddf4 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -1187,7 +1187,7 @@ Note: In new angle mixing, you should set `mixing_beta_mag >> mixing_beta`. The - **Type**: Real - **Description**: It's the energy threshold for electronic iteration. It represents the total energy error between two sequential densities from electronic iterations. -- **Default**: -1.0. If the user does not set this parameter, it will not take effect. +- **Default**: 1.0. If the user does not set this parameter, it will not take effect. - **Unit**: eV ### scf_thr_type diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index f57ff84d53..329dc7cfd0 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -673,7 +673,7 @@ void ESolver_KS::iter_finish(int& iter) this->pelec->f_en.etot_old = this->pelec->f_en.etot; // add a energy threshold for SCF convergence - if (this->conv_esolver == 0) // only check when density is not converged + if (this->conv_esolver == 1) // only check when density is converged { this->conv_esolver = (iter != 1 && std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); diff --git a/source/module_io/test/read_input_ptest.cpp b/source/module_io/test/read_input_ptest.cpp index a36cb5cd7d..148e1f5d3b 100644 --- a/source/module_io/test/read_input_ptest.cpp +++ b/source/module_io/test/read_input_ptest.cpp @@ -164,7 +164,7 @@ TEST_F(InputParaTest, ParaRead) EXPECT_EQ(PARAM.inp.test_force, 0); EXPECT_EQ(param.inp.test_stress, 0); EXPECT_NEAR(param.inp.scf_thr, 1.0e-8, 1.0e-15); - EXPECT_NEAR(param.inp.scf_ene_thr, -1.0, 1.0e-15); + EXPECT_NEAR(param.inp.scf_ene_thr, 1.0, 1.0e-15); EXPECT_EQ(param.inp.scf_nmax, 50); EXPECT_EQ(param.inp.relax_nmax, 1); EXPECT_EQ(param.inp.out_stru, 0); diff --git a/source/module_parameter/input_parameter.h b/source/module_parameter/input_parameter.h index 17284d4bb9..d4f197672a 100644 --- a/source/module_parameter/input_parameter.h +++ b/source/module_parameter/input_parameter.h @@ -112,7 +112,7 @@ struct Input_para bool gamma_only = false; ///< for plane wave. int scf_nmax = 100; ///< number of max elec iter double scf_thr = -1.0; ///< \sum |rhog_out - rhog_in |^2 - double scf_ene_thr = -1.0; ///< energy threshold for scf convergence, in eV + double scf_ene_thr = 1.0; ///< energy threshold for scf convergence, in eV int scf_thr_type = -1; ///< type of the criterion of scf_thr, 1: reci drho, 2: real drho bool final_scf = false; ///< whether to do final scf From 38a9a560175455a631ded6e71d44a94ba0ab44ce Mon Sep 17 00:00:00 2001 From: Weiqing Zhou Date: Fri, 25 Oct 2024 16:24:53 +0800 Subject: [PATCH 2/3] allow SCF converges at 1-st iteration --- source/module_esolver/esolver_ks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_esolver/esolver_ks.cpp b/source/module_esolver/esolver_ks.cpp index 329dc7cfd0..c6ad6d97c1 100644 --- a/source/module_esolver/esolver_ks.cpp +++ b/source/module_esolver/esolver_ks.cpp @@ -676,7 +676,7 @@ void ESolver_KS::iter_finish(int& iter) if (this->conv_esolver == 1) // only check when density is converged { this->conv_esolver - = (iter != 1 && std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); + = (std::abs(this->pelec->f_en.etot_delta * ModuleBase::Ry_to_eV) < this->scf_ene_thr); } } From cf8461b5056e70b87932adec346bcd60fb860796 Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Sat, 26 Oct 2024 01:56:49 +0000 Subject: [PATCH 3/3] mpi_bcast energies --- source/module_esolver/esolver_ks_pw.cpp | 1 + source/module_esolver/esolver_sdft_pw.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index bf6c0bc450..e92cf6f1c9 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -441,6 +441,7 @@ void ESolver_KS_PW::update_pot(const int istep, const int iter) } this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); this->pelec->f_en.descf = this->pelec->cal_delta_escf(); + MPI_Bcast(&(this->pelec->f_en.descf), 1, MPI_DOUBLE, 0, PARAPW_WORLD); } else { diff --git a/source/module_esolver/esolver_sdft_pw.cpp b/source/module_esolver/esolver_sdft_pw.cpp index 5b79d16818..ec0a6a89c0 100644 --- a/source/module_esolver/esolver_sdft_pw.cpp +++ b/source/module_esolver/esolver_sdft_pw.cpp @@ -231,6 +231,7 @@ void ESolver_SDFT_PW::hamilt2density(int istep, int iter, double ethr) } #endif } + MPI_Bcast(&(this->pelec->f_en.deband), 1, MPI_DOUBLE, 0, PARAPW_WORLD); } double ESolver_SDFT_PW::cal_energy()