Skip to content

Commit 04def35

Browse files
authored
Fix minor bug of EXX operator and default value (#5252)
* allow calling contributeHR while type::k in opexx * fix the default value of exx parameters * move the test code to the right place * fix test case
1 parent 31afd03 commit 04def35

File tree

5 files changed

+22
-16
lines changed

5 files changed

+22
-16
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,14 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHR()
201201
{
202202
ModuleBase::TITLE("OperatorEXX", "contributeHR");
203203
// Peize Lin add 2016-12-03
204-
if (PARAM.inp.calculation != "nscf" && this->two_level_step != nullptr && *this->two_level_step == 0 && !this->restart) { return; //in the non-exx loop, do nothing
205-
}
204+
if (PARAM.inp.calculation != "nscf" && this->two_level_step != nullptr && *this->two_level_step == 0 && !this->restart) { return; } //in the non-exx loop, do nothing
205+
if (this->add_hexx_type == Add_Hexx_Type::k) { return; }
206+
206207
if (XC_Functional::get_func_type() == 4 || XC_Functional::get_func_type() == 5)
207208
{
208209
// add H(R) normally
209-
if (GlobalC::exx_info.info_ri.real_number) {
210+
if (GlobalC::exx_info.info_ri.real_number)
211+
{
210212
RI_2D_Comm::add_HexxR(
211213
this->current_spin,
212214
GlobalC::exx_info.info_global.hybrid_alpha,
@@ -215,7 +217,9 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHR()
215217
PARAM.globalv.npol,
216218
*this->hR,
217219
this->use_cell_nearest ? &this->cell_nearest : nullptr);
218-
} else {
220+
}
221+
else
222+
{
219223
RI_2D_Comm::add_HexxR(
220224
this->current_spin,
221225
GlobalC::exx_info.info_global.hybrid_alpha,
@@ -224,19 +228,20 @@ void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHR()
224228
PARAM.globalv.npol,
225229
*this->hR,
226230
this->use_cell_nearest ? &this->cell_nearest : nullptr);
227-
}
231+
}
228232
}
229-
if (PARAM.inp.nspin == 2) { this->current_spin = 1 - this->current_spin;
230-
}
233+
if (PARAM.inp.nspin == 2) { this->current_spin = 1 - this->current_spin; }
231234
}
232235

233236
template<typename TK, typename TR>
234237
void OperatorEXX<OperatorLCAO<TK, TR>>::contributeHk(int ik)
235238
{
236239
ModuleBase::TITLE("OperatorEXX", "constributeHR");
237240
// Peize Lin add 2016-12-03
238-
if (PARAM.inp.calculation != "nscf" && this->two_level_step != nullptr && *this->two_level_step == 0 && !this->restart) { return; //in the non-exx loop, do nothing
239-
}
241+
if (PARAM.inp.calculation != "nscf" && this->two_level_step != nullptr && *this->two_level_step == 0 && !this->restart) { return; } //in the non-exx loop, do nothing
242+
243+
if (this->add_hexx_type == Add_Hexx_Type::R) { throw std::invalid_argument("Set Add_Hexx_Type::k sto call OperatorEXX::contributeHk()."); }
244+
240245
if (XC_Functional::get_func_type() == 4 || XC_Functional::get_func_type() == 5)
241246
{
242247
if (this->restart && this->two_level_step != nullptr)

source/module_io/read_input_item_exx_dftu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void ReadInput::item_exx()
8888
read_sync_string(input.exx_real_number);
8989
item.reset_value = [](const Input_Item& item, Parameter& para) {
9090
if (para.input.exx_real_number == "default")
91-
{
91+
{ // to run through here, the default value of para.input.exx_real_number should be "default"
9292
if (para.input.gamma_only)
9393
{
9494
para.input.exx_real_number = "1";
@@ -181,7 +181,7 @@ void ReadInput::item_exx()
181181
read_sync_string(input.exx_ccp_rmesh_times);
182182
item.reset_value = [](const Input_Item& item, Parameter& para) {
183183
if (para.input.exx_ccp_rmesh_times == "default")
184-
{
184+
{ // to run through here, the default value of para.input.exx_ccp_rmesh_times should be "default"
185185
std::string& dft_functional = para.input.dft_functional;
186186
std::string dft_functional_lower = dft_functional;
187187
std::transform(dft_functional.begin(), dft_functional.end(), dft_functional_lower.begin(), tolower);

source/module_io/write_vxc.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ void write_Vxc(const int nspin,
284284
vexxonly_op_ao.contributeHk(ik);
285285
std::vector<TK> vexx_k_mo = cVc(vexxonly_k_ao.get_hk(), &psi(ik, 0, 0), nbasis, nbands, *pv, p2d);
286286
e_orb_exx.emplace_back(orbital_energy(ik, nbands, vexx_k_mo, p2d));
287+
// ======test=======
288+
// exx_energy += all_band_energy(ik, vexx_k_mo, p2d, wg);
289+
// ======test=======
287290
}
288-
// ======test=======
289-
// exx_energy += all_band_energy(ik, vexx_k_mo, p2d, wg);
290-
// ======test=======
291291
#endif
292292
if (PARAM.inp.dft_plus_u)
293293
{

source/module_parameter/input_parameter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ struct Input_para
469469
double exx_mixing_beta = 1.0; ///< mixing_beta for outer-loop when exx_separate_loop=1
470470
double exx_lambda = 0.3; ///< used to compensate for divergence points at G=0 in the
471471
///< evaluation of Fock exchange using lcao_in_pw method
472-
std::string exx_real_number = "0"; ///< exx calculated in real or complex
472+
std::string exx_real_number = "default"; ///< exx calculated in real or complex
473473
double exx_pca_threshold = 0.0001; ///< threshold to screen on-site ABFs in exx
474474
double exx_c_threshold = 0.0001; ///< threshold to screen C matrix in exx
475475
double exx_v_threshold = 0.1; ///< threshold to screen C matrix in exx
@@ -484,7 +484,7 @@ struct Input_para
484484
///< inequality
485485
double exx_cauchy_stress_threshold = 1e-07; ///< threshold to screen exx stress using Cauchy-Schwartz
486486
///< inequality
487-
std::string exx_ccp_rmesh_times = "1"; ///< how many times larger the radial mesh required for
487+
std::string exx_ccp_rmesh_times = "default"; ///< how many times larger the radial mesh required for
488488
///< calculating Columb potential is to that of atomic orbitals
489489
std::string exx_distribute_type = "htime"; ///< distribute type (assuming default as no specific value
490490
///< provided)

tests/integrate/392_NO_GO_LR_HF/INPUT

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

2929
dft_functional hf
3030
exx_real_number 1
31+
exx_ccp_rmesh_times 1
3132

3233
lr_nstates 2
3334
xc_kernel hf

0 commit comments

Comments
 (0)