Skip to content

Commit eb7b555

Browse files
linpeizePeizeLin
andauthored
refactor Exx_Info::coulomb_param for RI (#6295)
* refactor Exx_Info::coulomb_param for RI * refactor in_built_xc_func_ext_params() * add precision in ModuleBase::GlobalFunc::TO_STRING() --------- Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent 9b0c1f7 commit eb7b555

22 files changed

Lines changed: 223 additions & 172 deletions

source/module_base/global_function.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ static inline const T* VECTOR_TO_PTR(const std::valarray<T>& v)
236236
// Peize Lin add 2016-07-18
237237
//==========================================================
238238
template <typename T>
239-
std::string TO_STRING(const T& n)
239+
std::string TO_STRING(const T& t, const int n=20) // n=20 since LDBL_EPSILON is 1E-16 or 1E-19
240240
{
241241
std::stringstream newstr;
242-
newstr << n;
242+
newstr << std::setprecision(n) << t;
243243
return newstr.str();
244244
}
245245

source/module_base/gram_schmidt_orth-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Func_Type Gram_Schmidt_Orth<Func_Type,R_Type>::cal_norm( const std::vector<Func_
9595
}
9696
default:
9797
{
98-
throw std::invalid_argument("coordinate must be Cartesian or Sphere "+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
98+
throw std::invalid_argument("coordinate must be Cartesian or Sphere "+std::string(__FILE__)+" line "+std::to_string(__LINE__));
9999
break;
100100
}
101101
}

source/module_base/mathzone_add1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ double Mathzone_Add1::Uni_RadialF
194194

195195
if (newr < 0.0)
196196
{
197-
throw std::runtime_error("newr should >= 0. "+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
197+
throw std::runtime_error("newr should >= 0. "+std::string(__FILE__)+" line "+std::to_string(__LINE__));
198198

199199
}
200200
else if ( rmax <= newr )

source/module_base/random.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Random
3232
const int a = std::rand() % 2;
3333
if(a==0) return between0and1();
3434
else if(a==1) return betweenMinus1and0();
35-
else throw(ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__)); // Peize Lin add to fix warning 2019-05-01
35+
else throw(std::string(__FILE__)+" line "+std::to_string(__LINE__)); // Peize Lin add to fix warning 2019-05-01
3636
}
3737

3838
static double between0and1(void)

source/module_basis/module_ao/ORB_atomic_lm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void Numerical_Orbital_Lm::set_orbital_info
9797
this->psik2[ik] = psi_in[ik];
9898
break;
9999
default:
100-
throw std::domain_error(ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
100+
throw std::domain_error(std::string(__FILE__)+" line "+std::to_string(__LINE__));
101101
}
102102

103103
switch(psi_type)
@@ -111,7 +111,7 @@ void Numerical_Orbital_Lm::set_orbital_info
111111
}
112112
else
113113
{
114-
throw std::domain_error("flag_sbpool false not finished in Numerical_Orbital_Lm::set_orbital_info_k. "+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
114+
throw std::domain_error("flag_sbpool false not finished in Numerical_Orbital_Lm::set_orbital_info_k. "+std::string(__FILE__)+" line "+std::to_string(__LINE__));
115115
}
116116
break;
117117
default: break;

source/module_hamilt_general/module_xc/exx_info.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@
44
#include "module_ri/conv_coulomb_pot_k.h"
55
#include "xc_functional.h"
66

7+
#include <vector>
8+
#include <map>
9+
#include <unordered_map>
10+
#include <string>
11+
712
struct Exx_Info
813
{
914
struct Exx_Info_Global
1015
{
1116
bool cal_exx = false;
1217

18+
std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> coulomb_param;
19+
// Fock:
20+
// "alpha": "0"
21+
// "Rcut_type": "limits" / "spencer"
22+
// "lambda": "0.3"
23+
// //"Rcut"
24+
// Erfc:
25+
// "alpha": "0"
26+
// "omega": "0.11"
27+
// "Rcut_type": "limits"
28+
// //"Rcut"
29+
1330
Conv_Coulomb_Pot_K::Ccp_Type ccp_type;
1431
double hybrid_alpha = 0.25;
1532
double hse_omega = 0.11;
@@ -35,8 +52,7 @@ struct Exx_Info
3552

3653
struct Exx_Info_RI
3754
{
38-
const Conv_Coulomb_Pot_K::Ccp_Type& ccp_type;
39-
const double& hse_omega;
55+
const std::unordered_map<Conv_Coulomb_Pot_K::Coulomb_Type, std::vector<std::map<std::string,std::string>>> &coulomb_param;
4056

4157
bool real_number = false;
4258

@@ -58,7 +74,7 @@ struct Exx_Info
5874
int abfs_Lmax = 0; // tmp
5975

6076
Exx_Info_RI(const Exx_Info::Exx_Info_Global& info_global)
61-
: ccp_type(info_global.ccp_type), hse_omega(info_global.hse_omega)
77+
: coulomb_param(info_global.coulomb_param)
6278
{
6379
}
6480
};

source/module_hamilt_general/module_xc/xc_functional_libxc.cpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -149,44 +149,52 @@ XC_Functional_Libxc::set_xc_type_libxc(const std::string& xc_func_in)
149149

150150
const std::vector<double> in_built_xc_func_ext_params(const int id)
151151
{
152-
const std::map<int, std::vector<double>> mymap = {
152+
switch(id)
153+
{
153154
// finite temperature XC functionals
154-
{XC_LDA_XC_KSDT, {PARAM.inp.xc_temperature * 0.5}},
155-
{XC_LDA_XC_CORRKSDT, {PARAM.inp.xc_temperature * 0.5}},
156-
{XC_LDA_XC_GDSMFB, {PARAM.inp.xc_temperature * 0.5}},
157-
// hybrid functionals
155+
case XC_LDA_XC_KSDT:
156+
return {PARAM.inp.xc_temperature * 0.5};
157+
case XC_LDA_XC_CORRKSDT:
158+
return {PARAM.inp.xc_temperature * 0.5};
159+
case XC_LDA_XC_GDSMFB:
160+
return {PARAM.inp.xc_temperature * 0.5};
158161
#ifdef __EXX
159-
{XC_HYB_GGA_XC_PBEH, {GlobalC::exx_info.info_global.hybrid_alpha,
160-
GlobalC::exx_info.info_global.hse_omega,
161-
GlobalC::exx_info.info_global.hse_omega}},
162-
{XC_HYB_GGA_XC_HSE06, {GlobalC::exx_info.info_global.hybrid_alpha,
163-
GlobalC::exx_info.info_global.hse_omega,
164-
GlobalC::exx_info.info_global.hse_omega}},
162+
// hybrid functionals
163+
case XC_HYB_GGA_XC_PBEH:
164+
return {GlobalC::exx_info.info_global.hybrid_alpha,
165+
GlobalC::exx_info.info_global.hse_omega,
166+
GlobalC::exx_info.info_global.hse_omega};
167+
case XC_HYB_GGA_XC_HSE06:
168+
return {GlobalC::exx_info.info_global.hybrid_alpha,
169+
GlobalC::exx_info.info_global.hse_omega,
170+
GlobalC::exx_info.info_global.hse_omega};
165171
// short-range of B88_X
166-
{XC_GGA_X_ITYH, {PARAM.inp.exx_hse_omega}},
172+
case XC_GGA_X_ITYH:
173+
return {PARAM.inp.exx_hse_omega};
167174
// short-range of LYP_C
168-
{XC_GGA_C_LYPR, {0.04918, 0.132, 0.2533, 0.349,
169-
0.35/2.29, 2.0/2.29, PARAM.inp.exx_hse_omega}},
175+
case XC_GGA_C_LYPR:
176+
return {0.04918, 0.132, 0.2533, 0.349,
177+
0.35/2.29, 2.0/2.29, PARAM.inp.exx_hse_omega};
170178
#endif
171-
};
172-
auto it = mymap.find(id);
173-
return (it != mymap.end()) ? it->second : std::vector<double>{};
179+
default:
180+
return std::vector<double>{};
181+
}
174182
}
175183

176184
const std::vector<double> external_xc_func_ext_params(const int id)
177185
{
178186
const std::map<int, std::vector<double>> mymap = {
179-
{
180-
PARAM.inp.xc_exch_ext[0],
187+
{
188+
PARAM.inp.xc_exch_ext[0],
181189
std::vector<double>(PARAM.inp.xc_exch_ext.begin()+1,
182-
PARAM.inp.xc_exch_ext.end())
190+
PARAM.inp.xc_exch_ext.end())
183191
},
184-
{
185-
PARAM.inp.xc_corr_ext[0],
192+
{
193+
PARAM.inp.xc_corr_ext[0],
186194
std::vector<double>(PARAM.inp.xc_corr_ext.begin()+1,
187-
PARAM.inp.xc_corr_ext.end())
195+
PARAM.inp.xc_corr_ext.end())
188196
}
189-
};
197+
};
190198
auto it = mymap.find(id);
191199
return (it != mymap.end()) ? it->second : std::vector<double>{};
192200
}

source/module_hamilt_general/module_xc/xc_functional_wrapper_gcxc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void XC_Functional::gcxc(const double &rho, const double &grho, double &sxc,
9494
v2 = v2x + v2c;
9595
break;
9696
default: //SCAN_X,SCAN_C,HSE, and so on
97-
throw std::domain_error("functional unfinished in "+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__));
97+
throw std::domain_error("functional unfinished in "+std::string(__FILE__)+" line "+std::to_string(__LINE__));
9898
}
9999
sxc += s;
100100
v1xc += v1;

source/module_hamilt_general/module_xc/xc_functional_wrapper_xc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void XC_Functional::xc_spin(const double &rho, const double &zeta,
117117

118118
// Cases that are only realized in LIBXC
119119
default:
120-
throw std::domain_error("functional unfinished in "+ModuleBase::GlobalFunc::TO_STRING(__FILE__)+" line "+ModuleBase::GlobalFunc::TO_STRING(__LINE__)); break;
120+
throw std::domain_error("functional unfinished in "+std::string(__FILE__)+" line "+std::to_string(__LINE__)); break;
121121

122122
}
123123
exc += e;

source/module_hsolver/diago_lapack.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ int DiagoLapack<T>::dsygvx_once(const int ncol,
112112
// Throw error if it returns info
113113
if (info)
114114
throw std::runtime_error("info = " + ModuleBase::GlobalFunc::TO_STRING(info) + ".\n"
115-
+ ModuleBase::GlobalFunc::TO_STRING(__FILE__) + " line "
116-
+ ModuleBase::GlobalFunc::TO_STRING(__LINE__));
115+
+ std::string(__FILE__) + " line "
116+
+ std::to_string(__LINE__));
117117
//lwork = work[0];
118118
//work.resize(std::max(lwork, 3), 0);
119119
//iwork.resize(iwork[0], 0);
@@ -205,8 +205,8 @@ int DiagoLapack<T>::zhegvx_once(const int ncol,
205205
206206
if (info)
207207
throw std::runtime_error("info=" + ModuleBase::GlobalFunc::TO_STRING(info) + ". "
208-
+ ModuleBase::GlobalFunc::TO_STRING(__FILE__) + " line "
209-
+ ModuleBase::GlobalFunc::TO_STRING(__LINE__));
208+
+ std::string(__FILE__) + " line "
209+
+ std::to_string(__LINE__));
210210
211211
// GlobalV::ofs_running<<"lwork="<<work[0]<<"\t"<<"lrwork="<<rwork[0]<<"\t"<<"liwork="<<iwork[0]<<std::endl;
212212
@@ -290,7 +290,7 @@ void DiagoLapack<T>::post_processing(const int info, const std::vector<int>& vec
290290
{
291291
const std::string str_info = "info = " + ModuleBase::GlobalFunc::TO_STRING(info) + ".\n";
292292
const std::string str_FILE
293-
= ModuleBase::GlobalFunc::TO_STRING(__FILE__) + " line " + ModuleBase::GlobalFunc::TO_STRING(__LINE__) + ".\n";
293+
= std::string(__FILE__) + " line " + std::to_string(__LINE__) + ".\n";
294294
const std::string str_info_FILE = str_info + str_FILE;
295295

296296
if (info == 0)

0 commit comments

Comments
 (0)