Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/module_esolver/esolver_ks_lcao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion source/module_esolver/esolver_ks_lcao_elec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion source/module_hamilt_general/module_xc/exx_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions source/module_ri/Mix_DMk_2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<ModuleBase::matrix> &mix_one : this->mix_DMk_gamma)
mix_one.mixing_mode = mixing_mode;
else
Expand All @@ -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<ModuleBase::matrix> &mix_one : this->mix_DMk_gamma)
mix_one.mixing_beta = mixing_beta;
else
Expand Down
96 changes: 50 additions & 46 deletions source/module_ri/Mix_DMk_2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename ChgMix>
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<typename ChgMix>
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<ModuleBase::matrix> &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<ModuleBase::ComplexMatrix> &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<const ModuleBase::matrix*> 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<const ModuleBase::ComplexMatrix*> get_DMk_k_out() const;

private:
std::vector<Mix_Data<ModuleBase::matrix>> mix_DMk_gamma;
std::vector<Mix_Data<ModuleBase::ComplexMatrix>> mix_DMk_k;
bool gamma_only;
std::vector<Mix_Data<ModuleBase::ComplexMatrix>> mix_DMk_k;
bool gamma_only;
};

template<typename ChgMix>
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<ModuleBase::matrix> &mix_one : this->mix_DMk_gamma)
mix_one.set_coef_pulay(iter, chr_mix);
else
for(Mix_Data<ModuleBase::ComplexMatrix> &mix_one : this->mix_DMk_k)
mix_one.set_coef_pulay(iter, chr_mix);
return *this;
}
#include "Mix_DMk_2D.hpp"

#endif
25 changes: 25 additions & 0 deletions source/module_ri/Mix_DMk_2D.hpp
Original file line number Diff line number Diff line change
@@ -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<typename ChgMix>
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<ModuleBase::matrix> &mix_one : this->mix_DMk_gamma)
mix_one.set_coef_pulay(iter, chr_mix);
else
for(Mix_Data<ModuleBase::ComplexMatrix> &mix_one : this->mix_DMk_k)
mix_one.set_coef_pulay(iter, chr_mix);
return *this;
}

#endif
17 changes: 14 additions & 3 deletions source/module_ri/Mix_Data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename ChgMix>
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<typename ChgMix>
void set_coef_pulay(const int iter, const ChgMix& chr_mix);

private:
Tdata data_out;
Expand Down
11 changes: 0 additions & 11 deletions source/module_ri/Mix_Data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Tdata>
void Mix_Data<Tdata>::mix(const Tdata &data_in, const bool flag_restart)
{
Expand Down Expand Up @@ -65,12 +60,6 @@ void Mix_Data<Tdata>::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<typename Tdata>
template<typename ChgMix>
void Mix_Data<Tdata>::set_coef_pulay(const int iter, const ChgMix& chr_mix)
Expand Down