From d7435b64022f797a8cfec41a05ad864c65996c62 Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Wed, 4 Dec 2024 17:29:34 +0800 Subject: [PATCH 1/2] move the condition out of cal_sgn --- .../module_xc/xc_functional_libxc.h | 2 -- .../module_xc/xc_functional_libxc_tools.cpp | 31 ++++++++----------- .../module_xc/xc_functional_libxc_vxc.cpp | 4 ++- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc.h b/source/module_hamilt_general/module_xc/xc_functional_libxc.h index f206261076..8ae77688a7 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc.h +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc.h @@ -85,8 +85,6 @@ namespace XC_Functional_Libxc extern std::vector cal_sgn( const double rho_threshold, const double grho_threshold, - const xc_func_type &func, - const int nspin, const std::size_t nrxx, const std::vector &rho, const std::vector &sigma); diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp index 6975d066b7..d9369c5748 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp @@ -119,29 +119,24 @@ std::vector XC_Functional_Libxc::convert_sigma( // sgn for threshold mask std::vector XC_Functional_Libxc::cal_sgn( const double rho_threshold, - const double grho_threshold, - const xc_func_type &func, - const int nspin, + const double grho_threshold, const std::size_t nrxx, const std::vector &rho, const std::vector &sigma) { - std::vector sgn(nrxx*nspin, 1.0); + std::vector sgn(nrxx * 2, 1.0); // to be consistent with "ir*2" in the following code // in the case of GGA correlation for polarized case, - // a cutoff for grho is required to ensure that libxc gives reasonable results - if(nspin==2 && func.info->family != XC_FAMILY_LDA && func.info->kind==XC_CORRELATION) - { - #ifdef _OPENMP - #pragma omp parallel for schedule(static, 512) - #endif - for( int ir=0; ir XC_Functional_Libxc::v_xc_libxc( / xc_func_set_dens_threshold(&func, rho_threshold); // sgn for threshold mask - const std::vector sgn = XC_Functional_Libxc::cal_sgn(rho_threshold, grho_threshold, func, nspin, nrxx, rho, sigma); + const std::vector sgn = (nspin == 2 && func.info->family != XC_FAMILY_LDA && func.info->kind == XC_CORRELATION) + ? XC_Functional_Libxc::cal_sgn(rho_threshold, grho_threshold, nrxx, rho, sigma) + : std::vector(nrxx * nspin, 1.0); std::vector exc ( nrxx ); std::vector vrho ( nrxx * nspin ); From 9dae2db6b70867a959858c8614a5332bb784c733 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:08:29 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- .../module_xc/xc_functional_libxc_tools.cpp | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp index d9369c5748..7ec1f22772 100644 --- a/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp +++ b/source/module_hamilt_general/module_xc/xc_functional_libxc_tools.cpp @@ -15,9 +15,11 @@ std::vector XC_Functional_Libxc::convert_rho( #ifdef _OPENMP #pragma omp parallel for collapse(2) schedule(static, 1024) #endif - for( int is=0; isrho[is][ir] + 1.0/nspin*chr->rho_core[ir]; +} +} return rho; } @@ -63,8 +65,9 @@ XC_Functional_Libxc::cal_gdr( #ifdef _OPENMP #pragma omp parallel for schedule(static, 1024) #endif - for(std::size_t ir=0; ir XC_Functional_Libxc::convert_sigma( const std::size_t nspin = gdr.size(); assert(nspin>0); const std::size_t nrxx = gdr[0].size(); - for(std::size_t is=1; is sigma( nrxx * ((1==nspin)?1:3) ); if( 1==nspin ) @@ -98,8 +102,9 @@ std::vector XC_Functional_Libxc::convert_sigma( #ifdef _OPENMP #pragma omp parallel for schedule(static, 1024) #endif - for( std::size_t ir=0; ir XC_Functional_Libxc::cal_sgn( #endif for (int ir = 0; ir < nrxx; ++ir) { - if (rho[ir * 2] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3])) < grho_threshold) + if (rho[ir * 2] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3])) < grho_threshold) { sgn[ir * 2] = 0.0; - if (rho[ir * 2 + 1] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3 + 2])) < grho_threshold) +} + if (rho[ir * 2 + 1] < rho_threshold || std::sqrt(std::abs(sigma[ir * 3 + 2])) < grho_threshold) { sgn[ir * 2 + 1] = 0.0; +} } return sgn; } @@ -152,9 +159,11 @@ double XC_Functional_Libxc::convert_etxc( #ifdef _OPENMP #pragma omp parallel for collapse(2) reduction(+:etxc) schedule(static, 256) #endif - for( int is=0; is> XC_Functional_Libxc::cal_dh( #ifdef _OPENMP #pragma omp parallel for schedule(static, 1024) #endif - for( std::size_t ir=0; ir> XC_Functional_Libxc::cal_dh( // define two dimensional array dh [ nspin, nrxx ] std::vector> dh(nspin, std::vector(nrxx)); - for( int is=0; is!=nspin; ++is ) + for( int is=0; is!=nspin; ++is ) { XC_Functional::grad_dot( h[is].data(), dh[is].data(), chr->rhopw, tpiba); +} return dh; } @@ -265,8 +276,9 @@ ModuleBase::matrix XC_Functional_Libxc::convert_v_nspin4( assert(PARAM.inp.nspin==4); constexpr double vanishing_charge = 1.0e-10; ModuleBase::matrix v_nspin4(PARAM.inp.nspin, nrxx); - for( int ir=0; ir vanishing_charge ) { const double vs = 0.5 * (v(0,ir)-v(1,ir)); - for(int ipol=1; ipolrho[ipol][ir] / amag[ir]; +} } } }