Skip to content

Commit d7435b6

Browse files
committed
move the condition out of cal_sgn
1 parent a6631a6 commit d7435b6

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

source/module_hamilt_general/module_xc/xc_functional_libxc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ namespace XC_Functional_Libxc
8585
extern std::vector<double> cal_sgn(
8686
const double rho_threshold,
8787
const double grho_threshold,
88-
const xc_func_type &func,
89-
const int nspin,
9088
const std::size_t nrxx,
9189
const std::vector<double> &rho,
9290
const std::vector<double> &sigma);

source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,29 +119,24 @@ std::vector<double> XC_Functional_Libxc::convert_sigma(
119119
// sgn for threshold mask
120120
std::vector<double> XC_Functional_Libxc::cal_sgn(
121121
const double rho_threshold,
122-
const double grho_threshold,
123-
const xc_func_type &func,
124-
const int nspin,
122+
const double grho_threshold,
125123
const std::size_t nrxx,
126124
const std::vector<double> &rho,
127125
const std::vector<double> &sigma)
128126
{
129-
std::vector<double> sgn(nrxx*nspin, 1.0);
127+
std::vector<double> sgn(nrxx * 2, 1.0); // to be consistent with "ir*2" in the following code
130128
// in the case of GGA correlation for polarized case,
131-
// a cutoff for grho is required to ensure that libxc gives reasonable results
132-
if(nspin==2 && func.info->family != XC_FAMILY_LDA && func.info->kind==XC_CORRELATION)
133-
{
134-
#ifdef _OPENMP
135-
#pragma omp parallel for schedule(static, 512)
136-
#endif
137-
for( int ir=0; ir<nrxx; ++ir )
138-
{
139-
if ( rho[ir*2]<rho_threshold || std::sqrt(std::abs(sigma[ir*3]))<grho_threshold )
140-
sgn[ir*2] = 0.0;
141-
if ( rho[ir*2+1]<rho_threshold || std::sqrt(std::abs(sigma[ir*3+2]))<grho_threshold )
142-
sgn[ir*2+1] = 0.0;
143-
}
144-
}
129+
// a cutoff for grho is required to ensure that libxc gives reasonable results
130+
#ifdef _OPENMP
131+
#pragma omp parallel for schedule(static, 512)
132+
#endif
133+
for (int ir = 0; ir < nrxx; ++ir)
134+
{
135+
if (rho[ir * 2] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3])) < grho_threshold)
136+
sgn[ir * 2] = 0.0;
137+
if (rho[ir * 2 + 1] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3 + 2])) < grho_threshold)
138+
sgn[ir * 2 + 1] = 0.0;
139+
}
145140
return sgn;
146141
}
147142

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ std::tuple<double,double,ModuleBase::matrix> XC_Functional_Libxc::v_xc_libxc( /
8686
xc_func_set_dens_threshold(&func, rho_threshold);
8787

8888
// sgn for threshold mask
89-
const std::vector<double> sgn = XC_Functional_Libxc::cal_sgn(rho_threshold, grho_threshold, func, nspin, nrxx, rho, sigma);
89+
const std::vector<double> sgn = (nspin == 2 && func.info->family != XC_FAMILY_LDA && func.info->kind == XC_CORRELATION)
90+
? XC_Functional_Libxc::cal_sgn(rho_threshold, grho_threshold, nrxx, rho, sigma)
91+
: std::vector<double>(nrxx * nspin, 1.0);
9092

9193
std::vector<double> exc ( nrxx );
9294
std::vector<double> vrho ( nrxx * nspin );

0 commit comments

Comments
 (0)