diff --git a/source/module_xc/test/CMakeLists.txt b/source/module_xc/test/CMakeLists.txt index 6fc1786e7c..68eb4b2137 100644 --- a/source/module_xc/test/CMakeLists.txt +++ b/source/module_xc/test/CMakeLists.txt @@ -158,4 +158,22 @@ AddTest( TARGET XCTest_BMK LIBS MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. SOURCES test_xc1.cpp ../xc_functional.cpp +) + +AddTest( + TARGET XCTest_SLATER1_SPN + LIBS MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. + SOURCES test_xc2.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp +) + +AddTest( + TARGET XCTest_SLATER_RXC_SPN + LIBS MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. + SOURCES test_xc2.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp +) + +AddTest( + TARGET XCTest_P86_SPN + LIBS MPI::MPI_CXX Libxc::xc # required by global.h; for details, `remove_definitions(-D__MPI)`. + SOURCES test_xc2.cpp ../xc_functional.cpp ../xc_functional_wrapper_xc.cpp ../xc_functional_wrapper_gcxc.cpp ../xc_funct_corr_gga.cpp ../xc_funct_corr_lda.cpp ../xc_funct_exch_gga.cpp ../xc_funct_exch_lda.cpp ../xc_funct_hcth.cpp ) \ No newline at end of file diff --git a/source/module_xc/test/test_xc.cpp b/source/module_xc/test/test_xc.cpp index 33b033990a..4669fc1f24 100644 --- a/source/module_xc/test/test_xc.cpp +++ b/source/module_xc/test/test_xc.cpp @@ -724,7 +724,6 @@ class XCTest_WCX : public testing::Test TEST_F(XCTest_WCX, set_xc_type) { - EXPECT_EQ(XC_Functional::get_func_type(),1); std::vector e_gga_ref = {0.0 ,-0.0035227366077,-0.0734928155169,-0.0052181684189,-0.0000001063768 }; std::vector v1_gga_ref = {0.0 ,0.0027230912249,0.0436861496717,0.0272641442833,0.0000000000788 }; std::vector v2_gga_ref = {-4.1745209791E-03,-4.1145164232E-03,-3.4066592749E-03,-8.0662091283E-02,-3.8681965771E-07}; diff --git a/source/module_xc/test/test_xc2.cpp b/source/module_xc/test/test_xc2.cpp new file mode 100644 index 0000000000..1c5e609c56 --- /dev/null +++ b/source/module_xc/test/test_xc2.cpp @@ -0,0 +1,131 @@ +#include "../xc_functional.h" +#include "gtest/gtest.h" +#include "../exx_global.h" + +namespace ModuleBase +{ + void WARNING_QUIT(const std::string &file,const std::string &description) {return ;} +} + +namespace GlobalV +{ + std::string BASIS_TYPE = ""; + bool CAL_STRESS = 0; + int CAL_FORCE = 0; + int NSPIN = 2; + double XC_TEMPERATURE; +} + +namespace GlobalC +{ + Exx_Global exx_global; +} + +class XCTest_SLATER1_SPN : public testing::Test +{ + protected: + std::vector e_lda, v1_lda, v2_lda; + + void SetUp() + { + std::vector rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04}; + std::vector zeta = {0.0, 0.2, 0.5, 0.8, 1.0}; + + for(int i=0;i<5;i++) + { + double e,v1,v2; + XC_Functional::slater1_spin(rho[i],zeta[i],e,v1,v2); + e_lda.push_back(e); + v1_lda.push_back(v1); + v2_lda.push_back(v2); + } + } +}; + +TEST_F(XCTest_SLATER1_SPN, set_xc_type) +{ + std::vector e_lda_ref = {-1.32218621089,-1.33398308443,-1.34039342564,-0.568290937412,-16.9789364717}; + std::vector v1_lda_ref = {-1.76291494786,-1.87337667608,-1.93557153111,-0.799220801445,-22.6385819622}; + std::vector v2_lda_ref = {-1.76291494786,-1.63654526731,-1.34205034341,-0.384225285821,0}; + + for (int i = 0;i<5;++i) + { + EXPECT_NEAR(e_lda[i],e_lda_ref[i],1.0e-8); + EXPECT_NEAR(v1_lda[i],v1_lda_ref[i],1.0e-8); + EXPECT_NEAR(v2_lda[i],v2_lda_ref[i],1.0e-8); + } +} + +class XCTest_SLATER_RXC_SPN : public testing::Test +{ + protected: + std::vector e_lda, v1_lda, v2_lda; + + void SetUp() + { + std::vector rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04}; + std::vector zeta = {0.0, 0.2, 0.5, 0.8, 1.0}; + + for(int i=0;i<5;i++) + { + double e,v1,v2; + XC_Functional::slater_rxc_spin(rho[i],zeta[i],e,v1,v2); + e_lda.push_back(e); + v1_lda.push_back(v1); + v2_lda.push_back(v2); + } + } +}; + +TEST_F(XCTest_SLATER_RXC_SPN, set_xc_type) +{ + std::vector e_lda_ref = {-0.880392474033,-0.888247554199,-0.892602327244,-0.378797005763,-9.99791043021}; + std::vector v1_lda_ref = {-1.17442450837,-1.24798175209,-1.28947632654,-0.532758325459,-14.0193907595}; + std::vector v2_lda_ref = {-1.17442450837,-1.09028491017,-0.894235359765,-0.2561411064,-0.688843519257}; + + for (int i = 0;i<5;++i) + { + EXPECT_NEAR(e_lda[i],e_lda_ref[i],1.0e-8); + EXPECT_NEAR(v1_lda[i],v1_lda_ref[i],1.0e-8); + EXPECT_NEAR(v2_lda[i],v2_lda_ref[i],1.0e-8); + } +} + +class XCTest_P86_SPN : public testing::Test +{ + protected: + std::vector e_gga, v1_gga, v2_gga, v3_gga; + + void SetUp() + { + std::vector rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04}; + std::vector grho = {0.81E-11, 0.17E+01, 0.36E+02, 0.87E-01, 0.55E+00}; + std::vector zeta = {0.0, 0.2, 0.5, 0.8, 1.0}; + + for(int i=0;i<5;i++) + { + double e,v1,v2,v3; + XC_Functional::perdew86_spin(rho[i],zeta[i],grho[i],e,v1,v2,v3); + e_gga.push_back(e); + v1_gga.push_back(v1); + v2_gga.push_back(v2); + v3_gga.push_back(v3); + } + } +}; + +TEST_F(XCTest_P86_SPN, set_xc_type) +{ + std::vector e_gga_ref = {1.69759930415e-14,0.00308117598269,0.0408000476851,0.00290513793266,8.49954060062e-08}; + std::vector v1_gga_ref = {-1.32642497169e-14,-0.0022804667616,-0.0166964664575,-0.00685850787795,-6.30224371228e-11}; + std::vector v2_gga_ref = {-1.32642497169e-14,-0.00188528133486,-0.00317100883673,0.0160558001336,-2.36727121199e-11}; + std::vector v3_gga_ref = {0.00419160260597,0.00338159500585,0.00145591122701,0.0336591369313,3.09070721877e-07}; + + for (int i = 0;i<5;++i) + { + EXPECT_NEAR(e_gga[i],e_gga_ref[i],1.0e-8); + EXPECT_NEAR(v1_gga[i],v1_gga_ref[i],1.0e-8); + EXPECT_NEAR(v2_gga[i],v2_gga_ref[i],1.0e-8); + EXPECT_NEAR(v3_gga[i],v3_gga_ref[i],1.0e-8); + } +} \ No newline at end of file diff --git a/source/module_xc/xc_funct_corr_gga.cpp b/source/module_xc/xc_funct_corr_gga.cpp index da6402b3c7..c607b646f6 100644 --- a/source/module_xc/xc_funct_corr_gga.cpp +++ b/source/module_xc/xc_funct_corr_gga.cpp @@ -270,7 +270,9 @@ void XC_Functional::perdew86_spin(double rho, double zeta, double grho, double & return; } //end subroutine perdew86_spin -//----------------------------------------------------------------------- +// There seems to be something wrong with it +// lots of terms evaluates to inf / nan in unit test +/* void XC_Functional::ggac_spin(double rho, double zeta, double grho, double &sc, double &v1cup, double &v1cdw, double &v2c) { @@ -364,6 +366,7 @@ void XC_Functional::ggac_spin(double rho, double zeta, double grho, double &sc, v2c = ddh0 + ddh1; return; } // end subroutine ggac_spin +*/ //--------------------------------------------------------------- void XC_Functional::pbec_spin(double rho, double zeta, double grho, const int &iflag, double &sc, diff --git a/source/module_xc/xc_functional.h b/source/module_xc/xc_functional.h index c8608df22d..6c84a65236 100644 --- a/source/module_xc/xc_functional.h +++ b/source/module_xc/xc_functional.h @@ -304,8 +304,8 @@ class XC_Functional static void perdew86_spin(double rho, double zeta, double grho, double &sc, double &v1cup, double &v1cdw, double &v2c); - static void ggac_spin(double rho, double zeta, double grho, double &sc, - double &v1cup, double &v1cdw, double &v2c); + //static void ggac_spin(double rho, double zeta, double grho, double &sc, + // double &v1cup, double &v1cdw, double &v2c); static void pbec_spin(double rho, double zeta, double grho, const int &flag, double &sc, double &v1cup, double &v1cdw, double &v2c); diff --git a/source/module_xc/xc_functional_wrapper_gcxc.cpp b/source/module_xc/xc_functional_wrapper_gcxc.cpp index b525ed2ba9..89e1abb5c3 100644 --- a/source/module_xc/xc_functional_wrapper_gcxc.cpp +++ b/source/module_xc/xc_functional_wrapper_gcxc.cpp @@ -281,7 +281,8 @@ void XC_Functional::gcc_spin(double rho, double &zeta, double grho, double &sc, case XC_GGA_C_P86: //P86 XC_Functional::perdew86_spin(rho, zeta, grho, sc, v1cup, v1cdw, v2c);break; case XC_GGA_C_PW91: //PW91_C - XC_Functional::ggac_spin(rho, zeta, grho, sc, v1cup, v1cdw, v2c);break; + ModuleBase::WARNING_QUIT("xc_wrapper_gcxc","there seems to be something wrong with ggac_spin, better use libxc version instead");break; + //XC_Functional::ggac_spin(rho, zeta, grho, sc, v1cup, v1cdw, v2c); case XC_GGA_C_PBE: //PBC XC_Functional::pbec_spin(rho, zeta, grho, 1, sc, v1cup, v1cdw, v2c);break; case XC_GGA_C_PBE_SOL: //PBCsol