diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index ca34e025df..d8509f9781 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -194,6 +194,7 @@ - [exx\_hse\_omega](#exx_hse_omega) - [exx\_separate\_loop](#exx_separate_loop) - [exx\_hybrid\_step](#exx_hybrid_step) + - [exx\_mixing\_beta](#exx_mixing_beta) - [exx\_lambda](#exx_lambda) - [exx\_pca\_threshold](#exx_pca_threshold) - [exx\_c\_threshold](#exx_c_threshold) @@ -1730,6 +1731,12 @@ These variables are relevant when using hybrid functionals - **Description**: This variable indicates the maximal electronic iteration number in the evaluation of Fock exchange. - **Default**: 100 +### exx_mixing_beta + +- **Type**: Real +- **Description**: mixing_beta for outer-loop when exx_separate_loop=1 +- **Default**: 1.0 + ### exx_lambda - **Type**: Real diff --git a/source/module_esolver/esolver_ks_lcao.cpp b/source/module_esolver/esolver_ks_lcao.cpp index e9dd90685f..e4ae991f1f 100644 --- a/source/module_esolver/esolver_ks_lcao.cpp +++ b/source/module_esolver/esolver_ks_lcao.cpp @@ -504,6 +504,7 @@ void ESolver_KS_LCAO::eachiterinit(const int istep, const int iter) { if (!GlobalC::exx_info.info_global.separate_loop && this->two_level_step) { + this->mix_DMk_2D.set_mixing_beta(GlobalC::CHR_MIX.get_mixing_beta()); if(GlobalC::CHR_MIX.get_mixing_mode() == "pulay") this->mix_DMk_2D.set_coef_pulay(iter, GlobalC::CHR_MIX); const bool flag_restart = (iter==1) ? true : false; diff --git a/source/module_esolver/esolver_ks_lcao_elec.cpp b/source/module_esolver/esolver_ks_lcao_elec.cpp index 2b83245641..48894797ba 100644 --- a/source/module_esolver/esolver_ks_lcao_elec.cpp +++ b/source/module_esolver/esolver_ks_lcao_elec.cpp @@ -351,7 +351,6 @@ namespace ModuleESolver throw std::invalid_argument( "mixing_mode = " + GlobalC::CHR_MIX.get_mixing_mode() + ", mix_DMk_2D unsupported.\n" + std::string(__FILE__) + " line " + std::to_string(__LINE__)); - this->mix_DMk_2D.set_mixing_beta(GlobalC::CHR_MIX.get_mixing_beta()); } } #endif // __MPI diff --git a/source/module_hamilt_general/module_xc/exx_info.h b/source/module_hamilt_general/module_xc/exx_info.h index be3c5a828b..217cc7a8f0 100644 --- a/source/module_hamilt_general/module_xc/exx_info.h +++ b/source/module_hamilt_general/module_xc/exx_info.h @@ -13,7 +13,7 @@ struct Exx_Info Conv_Coulomb_Pot_K::Ccp_Type ccp_type; double hybrid_alpha = 0.25; double hse_omega = 0.11; - double mixing_beta_for_loop1; + double mixing_beta_for_loop1 = 1.0; bool separate_loop = true; size_t hybrid_step = 1; diff --git a/source/module_ri/Mix_DMk_2D.cpp b/source/module_ri/Mix_DMk_2D.cpp index fe916257e8..ad56cdfdc6 100644 --- a/source/module_ri/Mix_DMk_2D.cpp +++ b/source/module_ri/Mix_DMk_2D.cpp @@ -10,7 +10,7 @@ Mix_DMk_2D &Mix_DMk_2D::set_nks(const int nks, const bool gamma_only_in) { ModuleBase::TITLE("Mix_DMk_2D", "set_nks"); this->gamma_only = gamma_only_in; - if (gamma_only) + if (this->gamma_only) this->mix_DMk_gamma.resize(nks); else this->mix_DMk_k.resize(nks); @@ -20,7 +20,7 @@ Mix_DMk_2D &Mix_DMk_2D::set_nks(const int nks, const bool gamma_only_in) Mix_DMk_2D &Mix_DMk_2D::set_mixing_mode(const Mixing_Mode mixing_mode) { ModuleBase::TITLE("Mix_DMk_2D","set_mixing_mode"); - if(gamma_only) + if(this->gamma_only) for(Mix_Data &mix_one : this->mix_DMk_gamma) mix_one.mixing_mode = mixing_mode; else @@ -32,7 +32,7 @@ Mix_DMk_2D &Mix_DMk_2D::set_mixing_mode(const Mixing_Mode mixing_mode) Mix_DMk_2D &Mix_DMk_2D::set_mixing_beta(const double mixing_beta) { ModuleBase::TITLE("Mix_DMk_2D","set_mixing_beta"); - if(gamma_only) + if(this->gamma_only) for(Mix_Data &mix_one : this->mix_DMk_gamma) mix_one.mixing_beta = mixing_beta; else diff --git a/source/module_ri/Mix_DMk_2D.h b/source/module_ri/Mix_DMk_2D.h index ddc37ef52b..5c8d4114d6 100644 --- a/source/module_ri/Mix_DMk_2D.h +++ b/source/module_ri/Mix_DMk_2D.h @@ -15,65 +15,69 @@ class Mix_DMk_2D { public: -/** - * @brief Sets the number of k-points and gamma_only flag. - * @param nks Number of k-points. - * @param gamma_only_in Flag indicating if only gamma point is mixed. - * @return Reference to the current object. - */ + /** + * @brief Sets the number of k-points and gamma_only flag. + * @param nks Number of k-points. + * @param gamma_only_in Flag indicating if only gamma point is mixed. + * @return Reference to the current object. + */ Mix_DMk_2D &set_nks(const int nks, const bool gamma_only_in); -/** - * @brief Sets the mixing mode. - * @param mixing_mode Mixing mode. - * @return Reference to the current object. - */ + + /** + * @brief Sets the mixing mode. + * @param mixing_mode Mixing mode. + * @return Reference to the current object. + */ Mix_DMk_2D &set_mixing_mode(const Mixing_Mode mixing_mode); - Mix_DMk_2D& set_mixing_beta(const double mixing_beta); - template - Mix_DMk_2D& set_coef_pulay(const int iter, const ChgMix& chr_mix); -/** - * @brief Mixes the density matrix. - * @param dm double Density matrix. - * @param flag_restart Flag indicating if it is a restart. - */ + /** + * @brief Sets the mixing beta. + * @param mixing_beta Mixing beta. + * @return Reference to the current object. + */ + Mix_DMk_2D &set_mixing_beta(const double mixing_beta); + + /** + * @brief Sets the pulay mixing coefficients from class Charge_Mixing. + * @tparam ChgMix Type of the charge mixing coefficient. + * @param iter Iteration step, start from 1. + * @param chr_mix Object of Charge_Mixing. + * @return Reference to the current object. + */ + template + Mix_DMk_2D &set_coef_pulay(const int iter, const ChgMix& chr_mix); + + /** + * @brief Mixes the double density matrix. + * @param dm Double Density matrix. + * @param flag_restart Flag indicating whether restart mixing. + */ void mix(const std::vector &dm, const bool flag_restart); -/** - * @brief Mixes the complex density matrix. - * @param dm Complex density matrix. - * @param flag_restart Flag indicating if it is a restart. - */ + /** + * @brief Mixes the complex density matrix. + * @param dm Complex density matrix. + * @param flag_restart Flag indicating whether restart mixing. + */ void mix(const std::vector &dm, const bool flag_restart); -/** - * @brief Returns the gamma density matrix. - * @return Vector of pointers to gamma density matrices. - */ + /** + * @brief Returns the double density matrix. + * @return Double density matrices for each k-points. + */ std::vector get_DMk_gamma_out() const; -/** - * @brief Returns the k-point density matrix. - * @return Vector of pointers to k-point density matrices. - */ + /** + * @brief Returns the complex density matrix. + * @return Complex density matrices for each k-points. + */ std::vector get_DMk_k_out() const; private: std::vector> mix_DMk_gamma; - std::vector> mix_DMk_k; - bool gamma_only; + std::vector> mix_DMk_k; + bool gamma_only; }; -template -Mix_DMk_2D& Mix_DMk_2D::set_coef_pulay(const int iter, const ChgMix& chr_mix) -{ - ModuleBase::TITLE("Mix_DMk_2D","set_coef_pulay"); - if(gamma_only) - for(Mix_Data &mix_one : this->mix_DMk_gamma) - mix_one.set_coef_pulay(iter, chr_mix); - else - for(Mix_Data &mix_one : this->mix_DMk_k) - mix_one.set_coef_pulay(iter, chr_mix); - return *this; -} +#include "Mix_DMk_2D.hpp" #endif \ No newline at end of file diff --git a/source/module_ri/Mix_DMk_2D.hpp b/source/module_ri/Mix_DMk_2D.hpp new file mode 100644 index 0000000000..d24905fa15 --- /dev/null +++ b/source/module_ri/Mix_DMk_2D.hpp @@ -0,0 +1,25 @@ +//======================= +// AUTHOR : Peize Lin +// DATE : 2023-05-09 +//======================= + +#include "Mix_DMk_2D.h" +#include "module_base/tool_title.h" + +#ifndef MIX_DMK_2D_HPP +#define MIX_DMK_2D_HPP + +template +Mix_DMk_2D& Mix_DMk_2D::set_coef_pulay(const int iter, const ChgMix& chr_mix) +{ + ModuleBase::TITLE("Mix_DMk_2D","set_coef_pulay"); + if(this->gamma_only) + for(Mix_Data &mix_one : this->mix_DMk_gamma) + mix_one.set_coef_pulay(iter, chr_mix); + else + for(Mix_Data &mix_one : this->mix_DMk_k) + mix_one.set_coef_pulay(iter, chr_mix); + return *this; +} + +#endif \ No newline at end of file diff --git a/source/module_ri/Mix_Data.h b/source/module_ri/Mix_Data.h index d82e7f7504..8fd0339eed 100644 --- a/source/module_ri/Mix_Data.h +++ b/source/module_ri/Mix_Data.h @@ -18,13 +18,24 @@ class Mix_Data { public: Mixing_Mode mixing_mode = Mixing_Mode::No; - double mixing_beta = 0; + double mixing_beta = 1.0; const Tdata &get_data_out() const { return this->data_out; } + /** + * @brief Mixes the input data according to the set mixing mode. + * @param data_in Input data to be mixed. + * @param flag_restart Flag indicating whether restart mixing. + */ void mix(const Tdata &data_in, const bool flag_restart); - template - void set_coef_pulay(const int iter, const ChgMix& chr_mix); // iter start from 1 + /** + * @brief Sets the pulay mixing coefficients from class Charge_Mixing. + * @tparam ChgMix Type of the charge mixing coefficient. + * @param iter Iteration step, start from 1. + * @param chr_mix Object of Charge_Mixing. + */ + template + void set_coef_pulay(const int iter, const ChgMix& chr_mix); private: Tdata data_out; diff --git a/source/module_ri/Mix_Data.hpp b/source/module_ri/Mix_Data.hpp index a8911df2ef..cebd40b2fc 100644 --- a/source/module_ri/Mix_Data.hpp +++ b/source/module_ri/Mix_Data.hpp @@ -10,11 +10,6 @@ #include "module_base/tool_title.h" #include "module_elecstate/module_charge/charge_mixing.h" -/** - * @brief Mixes the input data according to the set mixing mode. - * @param data_in Input data to be mixed. - * @param flag_restart Flag indicating if it is a restart. - */ template void Mix_Data::mix(const Tdata &data_in, const bool flag_restart) { @@ -65,12 +60,6 @@ void Mix_Data::pulay_mixing(const Tdata &data_in, const bool flag_restart } } -/** - * @brief Sets the Pulay mixing coefficients. - * @tparam ChgMix Type of the charge mixing coefficient. - * @param iter Iteration number. - * @param chr_mix Charge mixing coefficient. - */ template template void Mix_Data::set_coef_pulay(const int iter, const ChgMix& chr_mix)