Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions source/module_xc/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
1 change: 0 additions & 1 deletion source/module_xc/test/test_xc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> e_gga_ref = {0.0 ,-0.0035227366077,-0.0734928155169,-0.0052181684189,-0.0000001063768 };
std::vector<double> v1_gga_ref = {0.0 ,0.0027230912249,0.0436861496717,0.0272641442833,0.0000000000788 };
std::vector<double> v2_gga_ref = {-4.1745209791E-03,-4.1145164232E-03,-3.4066592749E-03,-8.0662091283E-02,-3.8681965771E-07};
Expand Down
131 changes: 131 additions & 0 deletions source/module_xc/test/test_xc2.cpp
Original file line number Diff line number Diff line change
@@ -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<double> e_lda, v1_lda, v2_lda;

void SetUp()
{
std::vector<double> rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04};
std::vector<double> 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<double> e_lda_ref = {-1.32218621089,-1.33398308443,-1.34039342564,-0.568290937412,-16.9789364717};
std::vector<double> v1_lda_ref = {-1.76291494786,-1.87337667608,-1.93557153111,-0.799220801445,-22.6385819622};
std::vector<double> 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<double> e_lda, v1_lda, v2_lda;

void SetUp()
{
std::vector<double> rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04};
std::vector<double> 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<double> e_lda_ref = {-0.880392474033,-0.888247554199,-0.892602327244,-0.378797005763,-9.99791043021};
std::vector<double> v1_lda_ref = {-1.17442450837,-1.24798175209,-1.28947632654,-0.532758325459,-14.0193907595};
std::vector<double> 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<double> e_gga, v1_gga, v2_gga, v3_gga;

void SetUp()
{
std::vector<double> rho = {0.17E+01, 0.17E+01, 0.15E+01, 0.88E-01, 0.18E+04};
std::vector<double> grho = {0.81E-11, 0.17E+01, 0.36E+02, 0.87E-01, 0.55E+00};
std::vector<double> 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<double> e_gga_ref = {1.69759930415e-14,0.00308117598269,0.0408000476851,0.00290513793266,8.49954060062e-08};
std::vector<double> v1_gga_ref = {-1.32642497169e-14,-0.0022804667616,-0.0166964664575,-0.00685850787795,-6.30224371228e-11};
std::vector<double> v2_gga_ref = {-1.32642497169e-14,-0.00188528133486,-0.00317100883673,0.0160558001336,-2.36727121199e-11};
std::vector<double> 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);
}
}
5 changes: 4 additions & 1 deletion source/module_xc/xc_funct_corr_gga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions source/module_xc/xc_functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion source/module_xc/xc_functional_wrapper_gcxc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down