Skip to content

Commit 35d90df

Browse files
committed
Refactor little codes in XC_Functional_Libxc
1 parent 913d2e3 commit 35d90df

13 files changed

+76
-118
lines changed

source/module_hamilt_general/module_xc/test/CMakeLists.txt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AddTest(
99
AddTest(
1010
TARGET XCTest_HSE
1111
LIBS MPI::MPI_CXX Libxc::xc parameter # required by global.h; for details, `remove_definitions(-D__MPI)`.
12-
SOURCES test_xc1.cpp ../xc_functional.cpp
12+
SOURCES test_xc1.cpp ../xc_functional.cpp ../xc_functional_libxc.cpp
1313
)
1414

1515

@@ -26,8 +26,6 @@ AddTest(
2626
SOURCES test_xc3.cpp ../xc_functional_gradcorr.cpp ../xc_functional.cpp
2727
../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp
2828
../xc_functional_libxc.cpp
29-
../xc_functional_libxc_tools.cpp
30-
../xc_functional_libxc_vxc.cpp
3129
../xc_functional_libxc_wrapper_xc.cpp
3230
../xc_functional_libxc_wrapper_gcxc.cpp
3331
../xc_functional_libxc_wrapper_tauxc.cpp
@@ -45,8 +43,6 @@ AddTest(
4543
SOURCES test_xc4.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp
4644
../xc_functional_wrapper_gcxc.cpp
4745
../xc_functional_libxc.cpp
48-
../xc_functional_libxc_tools.cpp
49-
../xc_functional_libxc_vxc.cpp
5046
../xc_functional_libxc_wrapper_xc.cpp
5147
../xc_functional_libxc_wrapper_gcxc.cpp
5248
../xc_functional_libxc_wrapper_tauxc.cpp
@@ -60,14 +56,14 @@ AddTest(
6056
SOURCES test_xc5.cpp ../xc_functional_gradcorr.cpp ../xc_functional.cpp
6157
../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp
6258
../xc_functional_libxc.cpp
63-
../xc_functional_libxc_tools.cpp
64-
../xc_functional_libxc_vxc.cpp
6559
../xc_functional_libxc_wrapper_xc.cpp
6660
../xc_functional_libxc_wrapper_gcxc.cpp
6761
../xc_functional_libxc_wrapper_tauxc.cpp
6862
../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp
6963
../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp
7064
../xc_functional_vxc.cpp
65+
../xc_functional_libxc_vxc.cpp
66+
../xc_functional_libxc_tools.cpp
7167
../../../module_base/matrix.cpp
7268
../../../module_base/memory.cpp
7369
../../../module_base/timer.cpp

source/module_hamilt_general/module_xc/test/test_xc.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "gtest/gtest.h"
22
#include "../xc_functional.h"
3+
#include "../xc_functional_libxc.h"
34
#include "../exx_info.h"
45
#include "xctest.h"
56

@@ -829,7 +830,7 @@ class XCTest_PBE0 : public XCTest
829830
void SetUp()
830831
{
831832
XC_Functional::set_xc_type("PBE0");
832-
XC_Functional::get_hybrid_alpha(0.5);
833+
XC_Functional::set_hybrid_alpha(0.5);
833834
std::vector<double> rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04};
834835
std::vector<double> grho = {0.81E-11, 0.17E+01, 0.36E+02, 0.87E-01, 0.55E+00};
835836

@@ -884,7 +885,7 @@ class XCTest_PBE_LibXC : public XCTest
884885
XC_Functional::xc(rho[i],e,v);
885886
e_lda.push_back(e);
886887
v_lda.push_back(v);
887-
XC_Functional::gcxc_libxc(rho[i],grho[i],e,v1,v2);
888+
XC_Functional_Libxc::gcxc_libxc(XC_Functional::get_func_id(), rho[i],grho[i],e,v1,v2);
888889
e_gga.push_back(e);
889890
v1_gga.push_back(v1);
890891
v2_gga.push_back(v2);

source/module_hamilt_general/module_xc/test/test_xc1.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class XCTest_HSE : public XCTest
3838
void SetUp()
3939
{
4040
XC_Functional::set_xc_type("HSE");
41-
XC_Functional::get_hybrid_alpha(0.5);
41+
XC_Functional::set_hybrid_alpha(0.5);
4242
}
4343
};
4444

@@ -53,7 +53,7 @@ class XCTest_SCAN0 : public XCTest
5353
void SetUp()
5454
{
5555
XC_Functional::set_xc_type("SCAN0");
56-
XC_Functional::get_hybrid_alpha(0.5);
56+
XC_Functional::set_hybrid_alpha(0.5);
5757
}
5858
};
5959

source/module_hamilt_general/module_xc/test/test_xc2.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "gtest/gtest.h"
22
#include "xctest.h"
33
#include "../xc_functional.h"
4+
#include "../xc_functional_libxc.h"
45
#include "../exx_info.h"
56
/************************************************
67
* unit test of functionals
@@ -455,7 +456,7 @@ class XCTest_PBE_SPN_LibXC : public XCTest
455456
double e,v1,v2,v3,v4,v5;
456457
double r1 = rho[i] * (1+zeta[i]) / 2.0;
457458
double r2 = rho[i] * (1-zeta[i]) / 2.0;
458-
XC_Functional::gcxc_spin_libxc(r1,r2,gdr[i],gdr[i],e,v1,v2,v3,v4,v5);
459+
XC_Functional_Libxc::gcxc_spin_libxc(XC_Functional::get_func_id(), r1,r2,gdr[i],gdr[i],e,v1,v2,v3,v4,v5);
459460
e_gga.push_back(e);
460461
v1_gga.push_back(v1+v3);
461462
v2_gga.push_back(v2+v4);
@@ -494,7 +495,7 @@ class XCTest_PZ_SPN_LibXC : public XCTest
494495
double e,v1,v2;
495496
double r1 = rho[i] * (1+zeta[i]) / 2.0;
496497
double r2 = rho[i] * (1-zeta[i]) / 2.0;
497-
XC_Functional::xc_spin_libxc(r1,r2,e,v1,v2);
498+
XC_Functional_Libxc::xc_spin_libxc(XC_Functional::get_func_id(), r1,r2,e,v1,v2);
498499
e_lda.push_back(e);
499500
v1_lda.push_back(v1);
500501
v2_lda.push_back(v2);

source/module_hamilt_general/module_xc/test/test_xc4.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../xc_functional.h"
2+
#include "../xc_functional_libxc.h"
23
#include "gtest/gtest.h"
34
#include "xctest.h"
45
#include "../exx_info.h"
@@ -43,7 +44,7 @@ class XCTest_SCAN : public XCTest
4344
for(int i=0;i<5;i++)
4445
{
4546
double e,v,v1,v2,v3;
46-
XC_Functional::tau_xc(rho[i],grho[i],tau[i],e,v1,v2,v3);
47+
XC_Functional_Libxc::tau_xc(XC_Functional::get_func_id(), rho[i],grho[i],tau[i],e,v1,v2,v3);
4748
e_.push_back(e);
4849
v1_.push_back(v1);
4950
v2_.push_back(v2);

source/module_hamilt_general/module_xc/test/test_xc5.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "../xc_functional.h"
2+
#include "../xc_functional_libxc.h"
23
#include "gtest/gtest.h"
34
#include "xctest.h"
45
#include "../exx_info.h"
@@ -279,15 +280,15 @@ class XCTest_VXC_meta : public XCTest
279280

280281
GlobalV::NSPIN = 1;
281282
std::tuple<double, double, ModuleBase::matrix, ModuleBase::matrix> etxc_vtxc_v
282-
= XC_Functional::v_xc_meta(rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
283+
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
283284
et1 = std::get<0>(etxc_vtxc_v);
284285
vt1 = std::get<1>(etxc_vtxc_v);
285286
v1 = std::get<2>(etxc_vtxc_v);
286287
vtau1 = std::get<3>(etxc_vtxc_v);
287288

288289
GlobalV::NSPIN = 2;
289290
etxc_vtxc_v
290-
= XC_Functional::v_xc_meta(rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
291+
= XC_Functional_Libxc::v_xc_meta(XC_Functional::get_func_id(), rhopw.nrxx,ucell.omega,ucell.tpiba,&chr);
291292
et2 = std::get<0>(etxc_vtxc_v);
292293
vt2 = std::get<1>(etxc_vtxc_v);
293294
v2 = std::get<2>(etxc_vtxc_v);

source/module_hamilt_general/module_xc/xc_functional.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void XC_Functional::set_xc_type(const std::string xc_func_in)
5858
//such as for PBE we have:
5959
// func_id.push_back(XC_GGA_X_PBE);
6060
// func_id.push_back(XC_GGA_C_PBE);
61-
61+
6262
func_id.clear();
6363
std::string xc_func = xc_func_in;
6464
std::transform(xc_func.begin(), xc_func.end(), xc_func.begin(), (::toupper));
@@ -128,7 +128,7 @@ void XC_Functional::set_xc_type(const std::string xc_func_in)
128128
func_id.push_back(XC_GGA_C_PBE);
129129
func_type = 2;
130130
use_libxc = false;
131-
}
131+
}
132132
else if ( xc_func == "BLYP") //B88+LYP
133133
{
134134
func_id.push_back(XC_GGA_X_B88);
@@ -142,14 +142,14 @@ void XC_Functional::set_xc_type(const std::string xc_func_in)
142142
func_id.push_back(XC_GGA_C_P86);
143143
func_type = 2;
144144
use_libxc = false;
145-
}
145+
}
146146
else if ( xc_func == "PW91") //PW91_X+PW91_C
147147
{
148148
func_id.push_back(XC_GGA_X_PW91);
149149
func_id.push_back(XC_GGA_C_PW91);
150150
func_type = 2;
151151
use_libxc = false;
152-
}
152+
}
153153
else if ( xc_func == "HCTH") //HCTH_X+HCTH_C
154154
{
155155
func_id.push_back(XC_GGA_X_HCTH_A);

source/module_hamilt_general/module_xc/xc_functional_libxc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ std::vector<xc_func_type> XC_Functional_Libxc::init_func(const std::vector<int>
5050
std::vector<xc_func_type> funcs;
5151

5252
//-------------------------------------------
53-
// define a function named 'add_func', which
53+
// define a function named 'add_func', which
5454
// initialize a functional according to its ID
5555
//-------------------------------------------
5656
auto add_func = [&]( const int func_id )
@@ -71,17 +71,17 @@ std::vector<xc_func_type> XC_Functional_Libxc::init_func(const std::vector<int>
7171
#ifdef __EXX
7272
else if( id == XC_HYB_GGA_XC_PBEH ) // PBE0
7373
{
74-
add_func( XC_HYB_GGA_XC_PBEH );
75-
double parameter_hse[3] = { GlobalC::exx_info.info_global.hybrid_alpha,
76-
GlobalC::exx_info.info_global.hse_omega,
74+
add_func( XC_HYB_GGA_XC_PBEH );
75+
double parameter_hse[3] = { GlobalC::exx_info.info_global.hybrid_alpha,
76+
GlobalC::exx_info.info_global.hse_omega,
7777
GlobalC::exx_info.info_global.hse_omega };
78-
xc_func_set_ext_params(&funcs.back(), parameter_hse);
78+
xc_func_set_ext_params(&funcs.back(), parameter_hse);
7979
}
8080
else if( id == XC_HYB_GGA_XC_HSE06 ) // HSE06 hybrid functional
8181
{
82-
add_func( XC_HYB_GGA_XC_HSE06 );
83-
double parameter_hse[3] = { GlobalC::exx_info.info_global.hybrid_alpha,
84-
GlobalC::exx_info.info_global.hse_omega,
82+
add_func( XC_HYB_GGA_XC_HSE06 );
83+
double parameter_hse[3] = { GlobalC::exx_info.info_global.hybrid_alpha,
84+
GlobalC::exx_info.info_global.hse_omega,
8585
GlobalC::exx_info.info_global.hse_omega };
8686
xc_func_set_ext_params(&funcs.back(), parameter_hse);
8787
}

source/module_hamilt_general/module_xc/xc_functional_libxc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ namespace XC_Functional_Libxc
149149
// the entire GGA functional, for nspin=2 case
150150
extern void gcxc_spin_libxc(
151151
const std::vector<int> &func_id,
152-
double rhoup, double rhodw,
153-
ModuleBase::Vector3<double> gdr1, ModuleBase::Vector3<double> gdr2,
152+
const double rhoup, const double rhodw,
153+
const ModuleBase::Vector3<double> gdr1, const ModuleBase::Vector3<double> gdr2,
154154
double &sxc, double &v1xcup, double &v1xcdw, double &v2xcup, double &v2xcdw, double &v2xcud);
155155

156156

source/module_hamilt_general/module_xc/xc_functional_libxc_vxc.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ std::tuple<double,double,ModuleBase::matrix,ModuleBase::matrix> XC_Functional_Li
205205
std::vector<double> vtau ( nrxx * nspin );
206206
std::vector<double> vlapl ( nrxx * nspin );
207207

208-
const double rho_th = 1e-8;
209-
const double grho_th = 1e-12;
210-
const double tau_th = 1e-8;
208+
constexpr double rho_th = 1e-8;
209+
constexpr double grho_th = 1e-12;
210+
constexpr double tau_th = 1e-8;
211211
// sgn for threshold mask
212212
std::vector<double> sgn( nrxx * nspin);
213213
#ifdef _OPENMP

0 commit comments

Comments
 (0)