Skip to content

Commit

Permalink
check if spin is polarized before constructing epc kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
aodongliu committed May 3, 2024
1 parent 43af2c1 commit d29994c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions include/exchcxx/impl/xc_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct XCKernelImpl {
bool is_mgga() const noexcept { return is_mgga_(); }
bool is_hyb() const noexcept { return is_hyb_(); }
bool is_polarized() const noexcept { return is_polarized_(); }
bool is_epc() const noexcept { return is_epc_(); }
bool is_epc() const noexcept { return is_epc_(); }
bool needs_laplacian() const noexcept { return needs_laplacian_(); }
bool needs_tau() const noexcept { return needs_tau_(); }

Expand Down Expand Up @@ -178,7 +178,7 @@ struct XCKernelImpl {
virtual bool is_mgga_() const noexcept = 0;
virtual bool is_hyb_() const noexcept = 0;
virtual bool is_polarized_() const noexcept = 0;
virtual bool is_epc_() const noexcept = 0;
virtual bool is_epc_() const noexcept = 0;
virtual bool needs_laplacian_() const noexcept = 0;
virtual bool needs_tau_() const noexcept = 0;

Expand Down
15 changes: 10 additions & 5 deletions src/builtin_interface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <exchcxx/impl/builtin/kernel_type.hpp>
#include <exchcxx/impl/builtin/interface.hpp>
#include <exchcxx/impl/builtin/kernels.hpp>
#include <exchcxx/exceptions/exchcxx_exception.hpp>


namespace ExchCXX {
Expand Down Expand Up @@ -117,16 +118,20 @@ std::unique_ptr<BuiltinKernel>
else if( kern == Kernel::PC07OPT_K )
return std::make_unique<BuiltinPC07OPT_K>( polar );

else if( kern == Kernel::EPC17_1)
else if( kern == Kernel::EPC17_1) {
EXCHCXX_BOOL_CHECK("EPC17_1 Needs to be Spin-Polarized!",polar==Spin::Polarized);
return std::make_unique<BuiltinEPC17_1>( polar );
else if( kern == Kernel::EPC17_2)
} else if( kern == Kernel::EPC17_2) {
EXCHCXX_BOOL_CHECK("EPC17_2 Needs to be Spin-Polarized!",polar==Spin::Polarized);
return std::make_unique<BuiltinEPC17_2>( polar );
else if( kern == Kernel::EPC18_1)
} else if( kern == Kernel::EPC18_1) {
EXCHCXX_BOOL_CHECK("EPC18_1 Needs to be Spin-Polarized!",polar==Spin::Polarized);
return std::make_unique<BuiltinEPC18_1>( polar );
else if( kern == Kernel::EPC18_2)
} else if( kern == Kernel::EPC18_2) {
EXCHCXX_BOOL_CHECK("EPC18_2 Needs to be Spin-Polarized!",polar==Spin::Polarized);
return std::make_unique<BuiltinEPC18_2>( polar );

else
} else
throw std::runtime_error("Specified kernel does not have a builtin implementation");


Expand Down
7 changes: 6 additions & 1 deletion src/libxc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,12 @@ bool LibxcKernelImpl::is_polarized_() const noexcept {

bool LibxcKernelImpl::is_epc_() const noexcept {
int xcNumber = xc_info()->number;
return xcNumber == 328 or xcNumber == 329 or xcNumber == 330 or xcNumber or 331;
return
#if XC_MAJOR_VERSION > 7
xcNumber == XC_LDA_C_EPC17 or xcNumber == XC_LDA_C_EPC17_2 or xcNumber == XC_LDA_C_EPC18_1 or xcNumber == XC_LDA_C_EPC18_2;
#else
xcNumber == 328 or xcNumber == 329 or xcNumber == 330 or xcNumber or 331;
#endif
}


Expand Down
1 change: 0 additions & 1 deletion test/reference_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ struct mgga_reference {
lda_reference load_lda_reference_values(ExchCXX::Kernel, ExchCXX::Spin);
gga_reference load_gga_reference_values(ExchCXX::Kernel, ExchCXX::Spin);
mgga_reference load_mgga_reference_values(ExchCXX::Kernel, ExchCXX::Spin, bool need_lap);
lda_reference load_epc_lda_reference_values(ExchCXX::Kernel, ExchCXX::Spin);

lda_reference gen_lda_reference_values(ExchCXX::Backend, ExchCXX::Kernel, ExchCXX::Spin);
gga_reference gen_gga_reference_values(ExchCXX::Backend, ExchCXX::Kernel, ExchCXX::Spin);
Expand Down
8 changes: 6 additions & 2 deletions test/xc_kernel_test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1011,15 +1011,19 @@ TEST_CASE( "Builtin Corectness Test", "[xc-builtin]" ) {
TEST_CASE( "Scale and Increment Interface", "[xc-inc]" ) {

SECTION( "Builtin Unpolarized EXC" ) {
for( auto kern : builtin_supported_kernels )
for( auto kern : builtin_supported_kernels ) {
if(is_epc(kern)) continue;
kernel_test( TestInterface::EXC_INC, Backend::builtin, kern,
Spin::Unpolarized );
}
}

SECTION( "Builtin Unpolarized EXC + VXC" ) {
for( auto kern : builtin_supported_kernels )
for( auto kern : builtin_supported_kernels ) {
if(is_epc(kern)) continue;
kernel_test( TestInterface::EXC_VXC_INC, Backend::builtin, kern,
Spin::Unpolarized );
}
}

SECTION( "Builtin Polarized EXC" ) {
Expand Down

0 comments on commit d29994c

Please sign in to comment.