Skip to content

Commit ece5cfa

Browse files
dyzhengPeizeLin1041176461
authored
Feature: EXX numerical type is distinguished by new input parameter "exx_real_number" (#1665)
* 1. change distinguishing between exx_lri_double and exx_lri_complex from GlobalV::GAMMA_ONLY_LOCAL to GlobalC::exx_info.info_ri.real_number * Add doc for parameter `exx_real_number` Co-authored-by: linpz <[email protected]> Co-authored-by: jiyuyang <[email protected]> Co-authored-by: PeizeLin <[email protected]>
1 parent fb8a154 commit ece5cfa

File tree

12 files changed

+64
-36
lines changed

12 files changed

+64
-36
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,12 @@ These variables are relevant when using hybrid functionals
14391439
- **Description**: See also the entry [dft_functional](#dft_functional). This parameter is only relevant when dft_functional=`opt_orb`. exx_opt_orb_tolerence determines the threshold when solving for the zeros of spherical Bessel functions. A reasonable choice is 1e-12.
14401440
- **Default**: 0
14411441

1442+
### exx_real_number
1443+
1444+
- **Type**: Boolen
1445+
- **Description**: If set to 1, it will enforce LIBRI to use `double` data type, otherwise, it will enforce LIBRI to use `complex` data type. The default value depends on the [gamma_only](#gamma_only) option.
1446+
- **Default**: 1 if gamma_only else 0
1447+
14421448
[back to top](#full-list-of-input-keywords)
14431449

14441450
## Molecular dynamics

source/input.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ void Input::Default(void)
351351
//----------------------------------------------------------
352352
// exx //Peize Lin add 2018-06-20
353353
//----------------------------------------------------------
354-
355354
exx_hybrid_alpha = "default";
356355
exx_hse_omega = 0.11;
357356

@@ -360,6 +359,7 @@ void Input::Default(void)
360359

361360
exx_lambda = 0.3;
362361

362+
exx_real_number = "default";
363363
exx_pca_threshold = 0;
364364
exx_c_threshold = 0;
365365
exx_v_threshold = 0;
@@ -1561,6 +1561,10 @@ bool Input::Read(const std::string &fn)
15611561
{
15621562
read_value(ifs, exx_lambda);
15631563
}
1564+
else if (strcmp("exx_real_number", word) == 0)
1565+
{
1566+
read_value(ifs, exx_real_number);
1567+
}
15641568
else if (strcmp("exx_pca_threshold", word) == 0)
15651569
{
15661570
read_value(ifs, exx_pca_threshold);
@@ -2167,6 +2171,13 @@ void Input::Default_2(void) // jiyy add 2019-08-04
21672171
else if (dft_functional == "pbe0" || dft_functional == "hse" || dft_functional == "scan0")
21682172
exx_hybrid_alpha = "0.25";
21692173
}
2174+
if (exx_real_number == "default")
2175+
{
2176+
if (gamma_only)
2177+
exx_real_number = "1";
2178+
else
2179+
exx_real_number = "0";
2180+
}
21702181
if (exx_ccp_rmesh_times == "default")
21712182
{
21722183
if (dft_functional == "hf" || dft_functional == "pbe0" || dft_functional == "scan0")
@@ -2472,6 +2483,7 @@ void Input::Bcast()
24722483
Parallel_Common::bcast_bool(exx_separate_loop);
24732484
Parallel_Common::bcast_int(exx_hybrid_step);
24742485
Parallel_Common::bcast_double(exx_lambda);
2486+
Parallel_Common::bcast_string(exx_real_number);
24752487
Parallel_Common::bcast_double(exx_pca_threshold);
24762488
Parallel_Common::bcast_double(exx_c_threshold);
24772489
Parallel_Common::bcast_double(exx_v_threshold);

source/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class Input
351351

352352
double exx_lambda;
353353

354+
std::string exx_real_number;
354355
double exx_pca_threshold;
355356
double exx_c_threshold;
356357
double exx_v_threshold;

source/input_conv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ void Input_Conv::Convert(void)
432432
GlobalC::exx_info.info_global.hybrid_step = INPUT.exx_hybrid_step;
433433
GlobalC::exx_info.info_lip.lambda = INPUT.exx_lambda;
434434

435+
GlobalC::exx_info.info_ri.real_number = std::stoi(INPUT.exx_real_number);
435436
GlobalC::exx_info.info_ri.pca_threshold = INPUT.exx_pca_threshold;
436437
GlobalC::exx_info.info_ri.C_threshold = INPUT.exx_c_threshold;
437438
GlobalC::exx_info.info_ri.V_threshold = INPUT.exx_v_threshold;

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void ESolver_KS_LCAO::Init(Input& inp, UnitCell& ucell)
125125
}
126126

127127
// GlobalC::exx_lcao.init();
128-
if(GlobalV::GAMMA_ONLY_LOCAL)
128+
if(GlobalC::exx_info.info_ri.real_number)
129129
GlobalC::exx_lri_double.init(MPI_COMM_WORLD);
130130
else
131131
GlobalC::exx_lri_complex.init(MPI_COMM_WORLD);
@@ -346,7 +346,7 @@ void ESolver_KS_LCAO::eachiterinit(const int istep, const int iter)
346346
if (!GlobalC::exx_info.info_global.separate_loop && this->two_level_step)
347347
{
348348
//GlobalC::exx_lcao.cal_exx_elec(this->LOC, this->LOWF.wfc_k_grid);
349-
if(GlobalV::GAMMA_ONLY_LOCAL)
349+
if(GlobalC::exx_info.info_ri.real_number)
350350
GlobalC::exx_lri_double.cal_exx_elec(this->LOC, *this->LOWF.ParaV);
351351
else
352352
GlobalC::exx_lri_complex.cal_exx_elec(this->LOC, *this->LOWF.ParaV);
@@ -427,7 +427,7 @@ void ESolver_KS_LCAO::hamilt2density(int istep, int iter, double ethr)
427427
{
428428
XC_Functional::set_xc_type(GlobalC::ucell.atoms[0].ncpp.xc_func);
429429
//GlobalC::exx_lcao.cal_exx_elec(this->LOC, this->LOWF.wfc_k_grid);
430-
if(GlobalV::GAMMA_ONLY_LOCAL)
430+
if(GlobalC::exx_info.info_ri.real_number)
431431
GlobalC::exx_lri_double.cal_exx_elec(this->LOC, *this->LOWF.ParaV);
432432
else
433433
GlobalC::exx_lri_complex.cal_exx_elec(this->LOC, *this->LOWF.ParaV);
@@ -631,7 +631,7 @@ void ESolver_KS_LCAO::afterscf(const int istep)
631631
if (GlobalC::exx_info.info_global.cal_exx) // Peize Lin add if 2022.11.14
632632
{
633633
const std::string file_name_exx = GlobalV::global_out_dir + "HexxR_" + std::to_string(GlobalV::MY_RANK);
634-
if(GlobalV::GAMMA_ONLY_LOCAL)
634+
if(GlobalC::exx_info.info_ri.real_number)
635635
GlobalC::exx_lri_double.write_Hexxs(file_name_exx);
636636
else
637637
GlobalC::exx_lri_complex.write_Hexxs(file_name_exx);
@@ -988,7 +988,7 @@ bool ESolver_KS_LCAO::do_after_converge(int& iter)
988988
}
989989

990990
//GlobalC::exx_lcao.cal_exx_elec(this->LOC, this->LOWF.wfc_k_grid);
991-
if(GlobalV::GAMMA_ONLY_LOCAL)
991+
if(GlobalC::exx_info.info_ri.real_number)
992992
GlobalC::exx_lri_double.cal_exx_elec(this->LOC, *this->LOWF.ParaV);
993993
else
994994
GlobalC::exx_lri_complex.cal_exx_elec(this->LOC, *this->LOWF.ParaV);

source/module_esolver/esolver_ks_lcao_elec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ namespace ModuleESolver
319319
}
320320

321321
//GlobalC::exx_lcao.cal_exx_ions(*this->LOWF.ParaV);
322-
if(GlobalV::GAMMA_ONLY_LOCAL)
322+
if(GlobalC::exx_info.info_ri.real_number)
323323
GlobalC::exx_lri_double.cal_exx_ions();
324324
else
325325
GlobalC::exx_lri_complex.cal_exx_ions();
@@ -468,7 +468,7 @@ namespace ModuleESolver
468468
{
469469
//GlobalC::exx_lcao.cal_exx_elec_nscf(this->LOWF.ParaV[0]);
470470
const std::string file_name_exx = GlobalV::global_out_dir + "HexxR_" + std::to_string(GlobalV::MY_RANK);
471-
if(GlobalV::GAMMA_ONLY_LOCAL)
471+
if(GlobalC::exx_info.info_ri.real_number)
472472
GlobalC::exx_lri_double.read_Hexxs(file_name_exx);
473473
else
474474
GlobalC::exx_lri_complex.read_Hexxs(file_name_exx);

source/module_hamilt/ks_lcao/op_exx_lcao.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,28 @@ void OperatorEXX<OperatorLCAO<T>>::contributeHR()
1818

1919
}
2020

21+
// double and complex<double> are the same temperarily
2122
template<>
2223
void OperatorEXX<OperatorLCAO<double>>::contributeHk(int ik)
2324
{
2425
#ifdef __EXX
2526
// Peize Lin add 2016-12-03
26-
auto &exx_lri = GlobalC::exx_lri_double;
27-
auto &exx_info = GlobalC::exx_info;
2827
if(XC_Functional::get_func_type()==4 || XC_Functional::get_func_type()==5)
2928
{
30-
//if(Exx_Info::Hybrid_Type::HF == GlobalC::exx_info.info_global.hybrid_type) // Peize Lin delete 2022.11.13
31-
//{
32-
// exx_info.info_global.hybrid_alpha = 1.0;
33-
//}
34-
RI_2D_Comm::add_Hexx(
35-
ik,
36-
exx_info.info_global.hybrid_alpha,
37-
exx_lri.Hexxs,
38-
*this->LM->ParaV,
39-
*this->LM);
29+
if(GlobalC::exx_info.info_ri.real_number)
30+
RI_2D_Comm::add_Hexx(
31+
ik,
32+
GlobalC::exx_info.info_global.hybrid_alpha,
33+
GlobalC::exx_lri_double.Hexxs,
34+
*this->LM->ParaV,
35+
*this->LM);
36+
else
37+
RI_2D_Comm::add_Hexx(
38+
ik,
39+
GlobalC::exx_info.info_global.hybrid_alpha,
40+
GlobalC::exx_lri_complex.Hexxs,
41+
*this->LM->ParaV,
42+
*this->LM);
4043
}
4144
#endif
4245
}
@@ -46,20 +49,22 @@ void OperatorEXX<OperatorLCAO<std::complex<double>>>::contributeHk(int ik)
4649
{
4750
#ifdef __EXX
4851
// Peize Lin add 2016-12-03
49-
auto &exx_lri = GlobalC::exx_lri_complex;
50-
auto &exx_info = GlobalC::exx_info;
5152
if(XC_Functional::get_func_type()==4 || XC_Functional::get_func_type()==5)
5253
{
53-
//if(Exx_Info::Hybrid_Type::HF == GlobalC::exx_info.info_global.hybrid_type) // Peize Lin delete 2022.11.13
54-
//{
55-
// exx_info.info_global.hybrid_alpha = 1.0;
56-
//}
57-
RI_2D_Comm::add_Hexx(
58-
ik,
59-
exx_info.info_global.hybrid_alpha,
60-
exx_lri.Hexxs,
61-
*this->LM->ParaV,
62-
*this->LM);
54+
if(GlobalC::exx_info.info_ri.real_number)
55+
RI_2D_Comm::add_Hexx(
56+
ik,
57+
GlobalC::exx_info.info_global.hybrid_alpha,
58+
GlobalC::exx_lri_double.Hexxs,
59+
*this->LM->ParaV,
60+
*this->LM);
61+
else
62+
RI_2D_Comm::add_Hexx(
63+
ik,
64+
GlobalC::exx_info.info_global.hybrid_alpha,
65+
GlobalC::exx_lri_complex.Hexxs,
66+
*this->LM->ParaV,
67+
*this->LM);
6368
}
6469
#endif
6570
}

source/module_xc/exx_info.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct Exx_Info
4040
const Conv_Coulomb_Pot_K::Ccp_Type &ccp_type;
4141
const double &hse_omega;
4242

43+
bool real_number = false;
44+
4345
double pca_threshold = 0;
4446
std::vector<std::string> files_abfs;
4547
double C_threshold = 0;

source/src_io/write_input.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ void Input::Print(const std::string &fn) const
339339
ModuleBase::GlobalFunc::OUTP(ofs, "exx_separate_loop", exx_separate_loop, "0 or 1");
340340
ModuleBase::GlobalFunc::OUTP(ofs, "exx_hybrid_step", exx_hybrid_step, "");
341341
ModuleBase::GlobalFunc::OUTP(ofs, "exx_lambda", exx_lambda, "");
342+
ModuleBase::GlobalFunc::OUTP(ofs, "exx_real_number", exx_real_number, "");
342343
ModuleBase::GlobalFunc::OUTP(ofs, "exx_pca_threshold", exx_pca_threshold, "");
343344
ModuleBase::GlobalFunc::OUTP(ofs, "exx_c_threshold", exx_c_threshold, "");
344345
ModuleBase::GlobalFunc::OUTP(ofs, "exx_v_threshold", exx_v_threshold, "");

source/src_lcao/FORCE_STRESS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void Force_Stress_LCAO::getForceStress(
221221
{
222222
if(isforce)
223223
{
224-
if(GlobalV::GAMMA_ONLY_LOCAL)
224+
if(GlobalC::exx_info.info_ri.real_number)
225225
{
226226
GlobalC::exx_lri_double.cal_exx_force();
227227
force_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_double.force_exx;
@@ -234,7 +234,7 @@ void Force_Stress_LCAO::getForceStress(
234234
}
235235
if(isstress)
236236
{
237-
if(GlobalV::GAMMA_ONLY_LOCAL)
237+
if(GlobalC::exx_info.info_ri.real_number)
238238
{
239239
GlobalC::exx_lri_double.cal_exx_stress();
240240
stress_exx = GlobalC::exx_info.info_global.hybrid_alpha * GlobalC::exx_lri_double.stress_exx;

0 commit comments

Comments
 (0)