diff --git a/CMakeLists.txt b/CMakeLists.txt index 92eca2a..ac57e85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,7 +81,7 @@ else() # if pinning to specific SHA change the FETCHCONTENT_LIBXC_GIT_SHALLOW default to OFF, https://cmake.org/cmake/help/latest/module/ExternalProject.html#git GIT_TAG 7.0.0 GIT_SHALLOW ${FETCHCONTENT_LIBXC_GIT_SHALLOW} - PATCH_COMMAND sed -i -e "s/p->info->family != XC_KINETIC/p->info->kind != XC_KINETIC/g" src/work_mgga_inc.c + PATCH_COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_LIST_DIR}/cmake/patch_libxc_work_mgga.cmake" ) set( Libxc_VERSION 7.0.0 ) diff --git a/cmake/patch_libxc_work_mgga.cmake b/cmake/patch_libxc_work_mgga.cmake new file mode 100644 index 0000000..eaf2d7a --- /dev/null +++ b/cmake/patch_libxc_work_mgga.cmake @@ -0,0 +1,13 @@ +# patch_libxc_work_mgga.cmake +# Portable replacement for: +# sed -i -e "s/p->info->family != XC_KINETIC/p->info->kind != XC_KINETIC/g" src/work_mgga_inc.c +# Run from the libxc source directory via PATCH_COMMAND. + +set(_file "src/work_mgga_inc.c") +if(NOT EXISTS "${_file}") + message(FATAL_ERROR "patch_libxc_work_mgga.cmake: ${_file} not found (cwd=${CMAKE_CURRENT_SOURCE_DIR})") +endif() + +file(READ "${_file}" _content) +string(REPLACE "p->info->family != XC_KINETIC" "p->info->kind != XC_KINETIC" _content "${_content}") +file(WRITE "${_file}" "${_content}") diff --git a/include/exchcxx/exceptions/exchcxx_exception.hpp b/include/exchcxx/exceptions/exchcxx_exception.hpp index 6d6563f..2bfa065 100644 --- a/include/exchcxx/exceptions/exchcxx_exception.hpp +++ b/include/exchcxx/exceptions/exchcxx_exception.hpp @@ -66,7 +66,7 @@ class exchcxx_exception : public std::exception { auto msg = ss.str(); - return strdup( msg.c_str() ); + return _strdup( msg.c_str() ); } public: @@ -77,7 +77,7 @@ class exchcxx_exception : public std::exception { }; #define EXCHCXX_BOOL_CHECK( MSG, V ) \ - if( not (V) ) \ + if( !(V) ) \ throw exchcxx_exception( __FILE__, __LINE__, MSG ); } diff --git a/include/exchcxx/impl/builtin/kernels/deorbitalized.hpp b/include/exchcxx/impl/builtin/kernels/deorbitalized.hpp index e00bc23..e31a41e 100644 --- a/include/exchcxx/impl/builtin/kernels/deorbitalized.hpp +++ b/include/exchcxx/impl/builtin/kernels/deorbitalized.hpp @@ -70,7 +70,6 @@ struct kernel_traits> { static constexpr bool needs_laplacian = true; static constexpr bool is_kedf = false; static constexpr bool is_epc = false; - static constexpr double exx_coeff = xc_traits::exx_coeff + ke_traits::exx_coeff; BUILTIN_KERNEL_EVAL_RETURN eval_exc_unpolar( double rho, double sigma, double lapl, double tau, double& eps ) { diff --git a/include/exchcxx/impl/builtin/kernels/screening_interface.hpp b/include/exchcxx/impl/builtin/kernels/screening_interface.hpp index e34b775..a34c2f6 100644 --- a/include/exchcxx/impl/builtin/kernels/screening_interface.hpp +++ b/include/exchcxx/impl/builtin/kernels/screening_interface.hpp @@ -394,7 +394,7 @@ struct mgga_screening_interface { constexpr auto sigma_tol_sq = traits::sigma_tol * traits::sigma_tol; sigma = safe_max(sigma, sigma_tol_sq); tau = safe_max(tau, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma = enforce_fermi_hole_curvature(sigma, rho, tau); } @@ -421,7 +421,7 @@ struct mgga_screening_interface { sigma_bb = safe_max(sigma_bb, sigma_tol_sq); tau_a = safe_max(tau_a, traits::tau_tol); tau_b = safe_max(tau_b, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma_aa = enforce_fermi_hole_curvature(sigma_aa, rho_a, tau_a); sigma_bb = enforce_fermi_hole_curvature(sigma_bb, rho_b, tau_b); } @@ -450,7 +450,7 @@ struct mgga_screening_interface { constexpr auto sigma_tol_sq = traits::sigma_tol * traits::sigma_tol; sigma = safe_max(sigma, sigma_tol_sq); tau = safe_max(tau, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma = enforce_fermi_hole_curvature(sigma, rho, tau); } traits::eval_exc_vxc_unpolar_impl(rho, sigma, lapl, tau, @@ -489,7 +489,7 @@ struct mgga_screening_interface { sigma_bb = safe_max(sigma_bb, sigma_tol_sq); tau_a = safe_max(tau_a, traits::tau_tol); tau_b = safe_max(tau_b, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma_aa = enforce_fermi_hole_curvature(sigma_aa, rho_a, tau_a); sigma_bb = enforce_fermi_hole_curvature(sigma_bb, rho_b, tau_b); } @@ -519,7 +519,7 @@ BUILTIN_KERNEL_EVAL_RETURN constexpr auto sigma_tol_sq = traits::sigma_tol * traits::sigma_tol; sigma = safe_max(sigma, sigma_tol_sq); tau = safe_max(tau, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma = enforce_fermi_hole_curvature(sigma, rho, tau); } traits::eval_fxc_unpolar_impl(rho, sigma, lapl, tau, @@ -575,7 +575,7 @@ BUILTIN_KERNEL_EVAL_RETURN sigma_bb = safe_max(sigma_bb, sigma_tol_sq); tau_a = safe_max(tau_a, traits::tau_tol); tau_b = safe_max(tau_b, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma_aa = enforce_fermi_hole_curvature(sigma_aa, rho_a, tau_a); sigma_bb = enforce_fermi_hole_curvature(sigma_bb, rho_b, tau_b); } @@ -621,7 +621,7 @@ BUILTIN_KERNEL_EVAL_RETURN sigma = safe_max(sigma, sigma_tol_sq); tau = safe_max(tau, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma = enforce_fermi_hole_curvature(sigma, rho, tau); } @@ -686,7 +686,7 @@ BUILTIN_KERNEL_EVAL_RETURN tau_a = safe_max(tau_a, traits::tau_tol); tau_b = safe_max(tau_b, traits::tau_tol); - if constexpr (not traits::is_kedf) { + if constexpr (!traits::is_kedf) { sigma_aa = enforce_fermi_hole_curvature(sigma_aa, rho_a, tau_a); sigma_bb = enforce_fermi_hole_curvature(sigma_bb, rho_b, tau_b); } diff --git a/include/exchcxx/xc_functional.hpp b/include/exchcxx/xc_functional.hpp index 838e6e6..62d952e 100644 --- a/include/exchcxx/xc_functional.hpp +++ b/include/exchcxx/xc_functional.hpp @@ -92,7 +92,7 @@ class XCFunctional { inline bool sanity_check() const { // Must have one kernel - if( not kernels_.size() ) return false; + if( !kernels_.size() ) return false; // Polarization is all or nothing int polar_one = kernels_.at(0).second.is_polarized(); @@ -103,7 +103,7 @@ class XCFunctional { } ); - if( not polar_all ) return false; + if( !polar_all ) return false; // If we made it, kernel is sane return true; @@ -164,7 +164,7 @@ class XCFunctional { return std::any_of( kernels_.begin(), kernels_.end(), [](const auto& x) { return x.second.is_gga(); } - ) and not is_mgga(); + ) && !is_mgga(); } inline bool is_mgga() const { diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec0adad..a29cd88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,55 @@ add_library( exchcxx ${EXCHCXX_SOURCES} ) # TARGET properties target_compile_features( exchcxx PUBLIC cxx_std_17 ) +if(MSVC) + target_compile_definitions( exchcxx PUBLIC _USE_MATH_DEFINES ) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") # clang-cl + target_compile_options( exchcxx PUBLIC + -Wno-c++98-compat + -Wno-c++98-compat-local-type-template-args + -Wno-c++98-compat-pedantic + -Wno-deprecated-declarations + -Wno-exit-time-destructors + -Wno-extra-semi + -Wno-extra-semi-stmt + -Wno-float-conversion + -Wno-float-equal + -Wno-global-constructors + -Wno-inconsistent-missing-destructor-override + -Wno-missing-prototypes + -Wno-missing-variable-declarations + -Wno-old-style-cast + -Wno-pre-c++14-compat + -Wno-pre-c++17-compat + -Wno-reserved-macro-identifier + -Wno-sign-conversion + -Wno-suggest-destructor-override + -Wno-switch-enum + -Wno-undefined-func-template + -Wno-unsafe-buffer-usage + -Wno-unsafe-buffer-usage-in-libc-call + -Wno-unused-macros + -Wno-unused-parameter + -Wno-unused-variable + ) + else() # cl + target_compile_options( exchcxx PUBLIC + /wd4003 # not enough actual parameters for macro 'identifier' + /wd4061 # enumerator 'enumerator' in switch of enum 'enumeration' is not explicitly handled by a case label + /wd4244 # conversion from 'type1' to 'type2', possible loss of data + /wd4266 # no override available for virtual member function from base 'class'; function is hidden + /wd4267 # conversion from 'size_t' to 'type', possible loss of data + /wd4365 # conversion from 'type1' to 'type2', signed/unsigned mismatch + /wd4514 # unreferenced inline function has been removed + /wd4267 # conversion from 'size_t' to 'type', possible loss of data + /wd4710 # function 'function' not inlined + /wd4711 # function 'function' selected for automatic inline expansion + /wd4800 # forcing value to bool 'true' or 'false' (performance warning) + /wd4820 # 'bytes' bytes padding added after construct 'member_name' + /wd5246 # C-style struct initialization may not be portable + ) + endif() +endif() if( EXCHCXX_ENABLE_LIBXC ) target_link_libraries( exchcxx PUBLIC Libxc::xc ) endif() diff --git a/src/builtin_interface.cxx b/src/builtin_interface.cxx index 3ad7ce2..03a757b 100644 --- a/src/builtin_interface.cxx +++ b/src/builtin_interface.cxx @@ -67,7 +67,7 @@ std::unique_ptr // Bail if polarized eval is requested and not supported EXCHCXX_BOOL_CHECK(kernel_map.key(kern) + " Needs to be Spin-Polarized!", - supports_unpolarized(kern) or polar == Spin::Polarized); + supports_unpolarized(kern) || polar == Spin::Polarized); if( kern == Kernel::SlaterExchange ) return std::make_unique( polar ); diff --git a/src/libxc.cxx b/src/libxc.cxx index fb859bd..8d6b9e6 100644 --- a/src/libxc.cxx +++ b/src/libxc.cxx @@ -256,7 +256,7 @@ std::unique_ptr< XCKernelImpl > LibxcKernelImpl::clone_() const { bool LibxcKernelImpl::is_lda_() const noexcept { return (kernel_.info->family == XC_FAMILY_LDA) #if XC_MAJOR_VERSION > 6 - or (kernel_.info->family == XC_FAMILY_HYB_LDA) + || (kernel_.info->family == XC_FAMILY_HYB_LDA) #endif ; } @@ -264,13 +264,13 @@ bool LibxcKernelImpl::is_lda_() const noexcept { bool LibxcKernelImpl::is_gga_() const noexcept { return (kernel_.info->family == XC_FAMILY_GGA ) - or (kernel_.info->family == XC_FAMILY_HYB_GGA); + || (kernel_.info->family == XC_FAMILY_HYB_GGA); } bool LibxcKernelImpl::is_mgga_() const noexcept { return (kernel_.info->family == XC_FAMILY_MGGA ) - or (kernel_.info->family == XC_FAMILY_HYB_MGGA); + || (kernel_.info->family == XC_FAMILY_HYB_MGGA); } bool LibxcKernelImpl::needs_laplacian_() const noexcept { @@ -294,7 +294,7 @@ bool LibxcKernelImpl::is_epc_() const noexcept { int xcNumber = xc_info()->number; 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; + xcNumber == XC_LDA_C_EPC17 || xcNumber == XC_LDA_C_EPC17_2 || xcNumber == XC_LDA_C_EPC18_1 || xcNumber == XC_LDA_C_EPC18_2; #else false; #endif diff --git a/src/xc_functional.cxx b/src/xc_functional.cxx index 24f99b4..6acfe02 100644 --- a/src/xc_functional.cxx +++ b/src/xc_functional.cxx @@ -711,7 +711,7 @@ LDA_EXC_GENERATOR( XCFunctional::eval_exc ) const { const size_t len_exc_buffer = exc_buffer_len(N); std::vector eps_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) + if( kernels_.size() > 1 && !supports_inc_interface() ) eps_scr.resize( len_exc_buffer ); std::fill_n( eps, len_exc_buffer, 0. ); @@ -749,7 +749,7 @@ LDA_EXC_VXC_GENERATOR( XCFunctional::eval_exc_vxc ) const { const size_t len_vxc_buffer = vrho_buffer_len(N); std::vector eps_scr, vxc_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) { + if( kernels_.size() > 1 && !supports_inc_interface() ) { eps_scr.resize( len_exc_buffer ); vxc_scr.resize( len_vxc_buffer ); } @@ -869,7 +869,7 @@ GGA_EXC_GENERATOR( XCFunctional::eval_exc ) const { const size_t len_exc_buffer = exc_buffer_len(N); std::vector eps_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) + if( kernels_.size() > 1 && !supports_inc_interface() ) eps_scr.resize( len_exc_buffer ); std::fill_n( eps, len_exc_buffer, 0. ); @@ -919,7 +919,7 @@ GGA_EXC_VXC_GENERATOR( XCFunctional::eval_exc_vxc ) const { const size_t len_vsigma_buffer = vsigma_buffer_len(N); std::vector eps_scr, vrho_scr, vsigma_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) { + if( kernels_.size() > 1 && !supports_inc_interface() ) { eps_scr.resize( len_exc_buffer ); vrho_scr.resize( len_vrho_buffer ); vsigma_scr.resize( len_vsigma_buffer ); @@ -988,7 +988,7 @@ GGA_FXC_GENERATOR( XCFunctional::eval_fxc ) const { const size_t len_v2sigma2_buffer = v2sigma2_buffer_len(N); std::vector v2sigma2_scr, v2rhosigma_scr, v2rho2_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) { + if( kernels_.size() > 1 && !supports_inc_interface() ) { v2rho2_scr.resize( len_v2rho2_buffer ); v2rhosigma_scr.resize( len_v2rhosigma_buffer ); v2sigma2_scr.resize( len_v2sigma2_buffer ); @@ -1053,7 +1053,7 @@ GGA_VXC_FXC_GENERATOR( XCFunctional::eval_vxc_fxc ) const { const size_t len_v2sigma2_buffer = v2sigma2_buffer_len(N); std::vector vrho_scr, vsigma_scr, v2rho2_scr, v2rhosigma_scr, v2sigma2_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) { + if( kernels_.size() > 1 && !supports_inc_interface() ) { vrho_scr.resize( len_vrho_buffer ); vsigma_scr.resize( len_vsigma_buffer ); v2rho2_scr.resize( len_v2rho2_buffer ); @@ -1130,7 +1130,7 @@ MGGA_EXC_GENERATOR( XCFunctional::eval_exc ) const { const size_t len_exc_buffer = exc_buffer_len(N); std::vector eps_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) + if( kernels_.size() > 1 && !supports_inc_interface() ) eps_scr.resize( len_exc_buffer ); std::fill_n( eps, len_exc_buffer, 0. ); @@ -1188,7 +1188,7 @@ MGGA_EXC_VXC_GENERATOR( XCFunctional::eval_exc_vxc ) const { const size_t len_vtau_buffer = vtau_buffer_len(N); std::vector eps_scr, vrho_scr, vsigma_scr, vlapl_scr, vtau_scr; - if( kernels_.size() > 1 and not supports_inc_interface() ) { + if( kernels_.size() > 1 && !supports_inc_interface() ) { eps_scr.resize( len_exc_buffer ); vrho_scr.resize( len_vrho_buffer ); vsigma_scr.resize( len_vsigma_buffer ); @@ -1244,7 +1244,7 @@ MGGA_EXC_VXC_GENERATOR( XCFunctional::eval_exc_vxc ) const { _addscal( len_exc_buffer, kernels_[i].first, eps, eps_eval ); _addscal( len_vrho_buffer, kernels_[i].first, vrho, vrho_eval ); - if( kernels_[i].second.is_gga() or kernels_[i].second.is_mgga() ) + if( kernels_[i].second.is_gga() || kernels_[i].second.is_mgga() ) _addscal( len_vsigma_buffer, kernels_[i].first, vsigma, vsigma_eval ); if( kernels_[i].second.needs_laplacian() ) @@ -1258,7 +1258,7 @@ MGGA_EXC_VXC_GENERATOR( XCFunctional::eval_exc_vxc ) const { _scal( len_exc_buffer, kernels_[i].first, eps ); _scal( len_vrho_buffer, kernels_[i].first, vrho ); - if( kernels_[i].second.is_gga() or kernels_[i].second.is_mgga() ) + if( kernels_[i].second.is_gga() || kernels_[i].second.is_mgga() ) _scal( len_vsigma_buffer, kernels_[i].first, vsigma ); if( kernels_[i].second.needs_laplacian() ) @@ -1361,7 +1361,7 @@ MGGA_FXC_GENERATOR( XCFunctional::eval_fxc ) const { if (i) { _addscal(len_v2rho2_buffer, kernels_[i].first, v2rho2, v2rho2_eval); - if( kernels_[i].second.is_gga() or kernels_[i].second.is_mgga() ){ + if( kernels_[i].second.is_gga() || kernels_[i].second.is_mgga() ){ _addscal(len_v2rhosigma_buffer, kernels_[i].first, v2rhosigma, v2rhosigma_eval); _addscal(len_v2sigma2_buffer, kernels_[i].first, v2sigma2, v2sigma2_eval); } @@ -1384,7 +1384,7 @@ MGGA_FXC_GENERATOR( XCFunctional::eval_fxc ) const { _scal(len_v2rho2_buffer, kernels_[i].first, v2rho2); - if (kernels_[i].second.is_gga() or kernels_[i].second.is_mgga()) { + if (kernels_[i].second.is_gga() || kernels_[i].second.is_mgga()) { _scal(len_v2rhosigma_buffer, kernels_[i].first, v2rhosigma); _scal(len_v2sigma2_buffer, kernels_[i].first, v2sigma2); }