├── .github └── workflows │ ├── build_and_test_compiler_zoo.yml │ ├── scripts │ └── compiler_setup.sh │ └── toolchains │ └── gh-actions.cmake ├── .gitignore ├── CMakeLists.txt ├── INSTALL.md ├── LICENSE.txt ├── README.md ├── bin ├── README.md └── generate_primitive_kernels.py ├── cmake ├── ExchCXXConfig.cmake.in └── FindSYCL.cmake ├── include └── exchcxx │ ├── boilerplate.hpp │ ├── enums │ ├── backend.hpp │ ├── enums.hpp │ ├── functionals.hpp │ ├── kernels.hpp │ └── spin.hpp │ ├── exceptions │ └── exchcxx_exception.hpp │ ├── exchcxx.hpp │ ├── exchcxx_config.hpp.in │ ├── factory │ └── xc_kernel.hpp │ ├── impl │ ├── builtin │ │ ├── constants.hpp │ │ ├── fwd.hpp │ │ ├── interface.hpp │ │ ├── kernel_type.hpp │ │ ├── kernels.hpp │ │ ├── kernels │ │ │ ├── b3lyp.hpp │ │ │ ├── b88.hpp │ │ │ ├── deorbitalized.hpp │ │ │ ├── epc17_1.hpp │ │ │ ├── epc17_2.hpp │ │ │ ├── epc18_1.hpp │ │ │ ├── epc18_2.hpp │ │ │ ├── ft98_x.hpp │ │ │ ├── lyp.hpp │ │ │ ├── m06_2x_c.hpp │ │ │ ├── m06_2x_x.hpp │ │ │ ├── pbe0.hpp │ │ │ ├── pbe_c.hpp │ │ │ ├── pbe_x.hpp │ │ │ ├── pc07_k.hpp │ │ │ ├── pc07opt_k.hpp │ │ │ ├── pkzb_c.hpp │ │ │ ├── pkzb_x.hpp │ │ │ ├── pw91_lda.hpp │ │ │ ├── pw91_lda_mod.hpp │ │ │ ├── pw91_lda_rpa.hpp │ │ │ ├── pz81.hpp │ │ │ ├── pz81_mod.hpp │ │ │ ├── r2scan_c.hpp │ │ │ ├── r2scan_x.hpp │ │ │ ├── r2scanl_c.hpp │ │ │ ├── r2scanl_x.hpp │ │ │ ├── rev_pbe_x.hpp │ │ │ ├── scan_c.hpp │ │ │ ├── scan_x.hpp │ │ │ ├── scanl_c.hpp │ │ │ ├── scanl_x.hpp │ │ │ ├── screening_interface.hpp │ │ │ ├── slater_exchange.hpp │ │ │ ├── vwn3.hpp │ │ │ └── vwn_rpa.hpp │ │ └── util.hpp │ ├── libxc.hpp │ ├── xc_kernel.hpp │ └── xc_kernel_fwd.hpp │ ├── util │ ├── bidirectional_map.hpp │ ├── div_ceil.hpp │ ├── exchcxx_macros.hpp │ ├── named_type.hpp │ ├── param_macros.hpp │ └── unused.hpp │ ├── xc_functional.hpp │ └── xc_kernel.hpp ├── performance ├── CMakeLists.txt └── device_benchmark.cxx ├── src ├── CMakeLists.txt ├── boilerplate.cxx ├── builtin.cxx ├── builtin_interface.cxx ├── builtin_kernel.cxx ├── cuda │ ├── builtin.cu │ ├── exchcxx_cuda.cmake │ ├── libxc_device.cxx │ └── xc_functional_device.cu ├── hip │ ├── builtin.hip │ ├── exchcxx_hip.cmake │ ├── libxc_device.hip │ └── xc_functional_device.hip ├── libxc.cxx ├── libxc_common.hpp ├── sycl │ ├── builtin_sycl.cxx │ ├── exchcxx_sycl.cmake │ ├── libxc_device.cxx │ └── xc_functional_device.cxx ├── xc_functional.cxx └── xc_kernel.cxx └── test ├── CMakeLists.txt ├── boilerplate_test.cxx ├── cmake ├── discovery │ ├── CMakeLists.txt │ └── exchcxx_link_tester.cxx └── subproject │ ├── CMakeLists.txt │ └── exchcxx_link_tester.cxx ├── reference_values.cxx ├── reference_values.hpp ├── ut_common.hpp ├── ut_main.cxx ├── xc_functional_test.cxx └── xc_kernel_test.cxx /.github/workflows/build_and_test_compiler_zoo.yml: -------------------------------------------------------------------------------- 1 | name: Build and Test - Compiler Zoo 2 | 3 | on: [pull_request, workflow_dispatch] 4 | 5 | env: 6 | GH_ACTIONS_TOOLCHAIN: .github/workflows/toolchains/gh-actions.cmake 7 | 8 | jobs: 9 | release_build: 10 | runs-on: ubuntu-latest 11 | container: 12 | image: dbwy/compiler-zoo 13 | strategy: 14 | matrix: 15 | compiler: [ {suite: gnu, version: 12}, {suite: llvm, version: 14} ] 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | 20 | - name: Setup Compiler 21 | shell: bash 22 | run: $GITHUB_WORKSPACE/.github/workflows/scripts/compiler_setup.sh 23 | ${{matrix.compiler.suite}} ${{matrix.compiler.version}} 24 | 25 | - name: Setup Build Type 26 | shell: bash 27 | run: echo "set(CMAKE_BUILD_TYPE Release CACHE BOOL \"\" FORCE)" >> 28 | ${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 29 | 30 | 31 | - name: Configure CMake 32 | shell: bash 33 | run: cmake -S $GITHUB_WORKSPACE -B ${{runner.workspace}}/build 34 | -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install 35 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 36 | 37 | - name: Build 38 | shell: bash 39 | run: cmake --build ${{runner.workspace}}/build -j2 40 | 41 | - name: Test 42 | shell: bash 43 | run: cmake --build ${{runner.workspace}}/build --target test 44 | 45 | debug_build: 46 | runs-on: ubuntu-latest 47 | container: 48 | image: dbwy/compiler-zoo 49 | 50 | steps: 51 | - uses: actions/checkout@v3 52 | 53 | - name: Setup Compiler 54 | shell: bash 55 | run: $GITHUB_WORKSPACE/.github/workflows/scripts/compiler_setup.sh 56 | gnu 12 57 | 58 | - name: Setup Build Type 59 | shell: bash 60 | run: echo "set(CMAKE_BUILD_TYPE Debug CACHE BOOL \"\" FORCE)" >> 61 | ${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 62 | 63 | 64 | - name: Configure CMake 65 | shell: bash 66 | run: cmake -S $GITHUB_WORKSPACE -B ${{runner.workspace}}/build 67 | -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install 68 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 69 | 70 | - name: Build 71 | shell: bash 72 | run: cmake --build ${{runner.workspace}}/build -j2 73 | 74 | - name: Test 75 | shell: bash 76 | run: cmake --build ${{runner.workspace}}/build --target test 77 | 78 | libxc_versions: 79 | name: Test Libxc Compatibility 80 | needs: release_build 81 | runs-on: ubuntu-latest 82 | container: 83 | image: dbwy/compiler-zoo 84 | strategy: 85 | matrix: 86 | libxc_version: [ 6.2.0 ] 87 | 88 | steps: 89 | - uses: actions/checkout@v3 90 | 91 | - name: Setup Compiler 92 | shell: bash 93 | run: $GITHUB_WORKSPACE/.github/workflows/scripts/compiler_setup.sh 94 | gnu 12 95 | 96 | - name: Setup Build Type 97 | shell: bash 98 | run: echo "set(CMAKE_BUILD_TYPE Debug CACHE BOOL \"\" FORCE)" >> 99 | ${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 100 | 101 | - name: Setup Libxc 102 | shell: bash 103 | run: | 104 | git clone https://gitlab.com/libxc/libxc.git ${{runner.workspace}}/libxc 105 | git -C ${{runner.workspace}}/libxc checkout ${{matrix.libxc_version}} 106 | 107 | - name: Configure CMake 108 | shell: bash 109 | run: cmake -S $GITHUB_WORKSPACE -B ${{runner.workspace}}/build 110 | -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install 111 | -DFETCHCONTENT_SOURCE_DIR_LIBXC=${{runner.workspace}}/libxc 112 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 113 | 114 | - name: Build 115 | shell: bash 116 | run: cmake --build ${{runner.workspace}}/build -j2 117 | 118 | # - name: Test 119 | # shell: bash 120 | # run: cmake --build ${{runner.workspace}}/build --target test 121 | 122 | 123 | subproject_build: 124 | name: Build as Subproject 125 | needs: release_build 126 | runs-on: ubuntu-latest 127 | container: 128 | image: dbwy/compiler-zoo 129 | 130 | steps: 131 | - uses: actions/checkout@v3 132 | 133 | - name: Setup Compiler 134 | shell: bash 135 | run: $GITHUB_WORKSPACE/.github/workflows/scripts/compiler_setup.sh gnu 12 136 | 137 | - name: CMake Subproject Configure 138 | shell: bash 139 | run: cmake -S $GITHUB_WORKSPACE/test/cmake/subproject 140 | -B ${{runner.workspace}}/cmake_subproject_build 141 | -DGIT_REVISION=$GITHUB_HEAD_REF 142 | -DFETCHCONTENT_SOURCE_DIR_EXCHCXX=$GITHUB_WORKSPACE 143 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 144 | 145 | - name: CMake Subproject Build 146 | shell: bash 147 | run: cmake --build ${{runner.workspace}}/cmake_subproject_build -j2 148 | 149 | cmake_discovery: 150 | name: CMake Discovery 151 | needs: release_build 152 | runs-on: ubuntu-latest 153 | container: 154 | image: dbwy/compiler-zoo 155 | 156 | steps: 157 | - uses: actions/checkout@v3 158 | 159 | - name: Setup Compiler 160 | shell: bash 161 | run: $GITHUB_WORKSPACE/.github/workflows/scripts/compiler_setup.sh gnu 12 162 | 163 | - name: Configure CMake 164 | shell: bash 165 | run: cmake -S $GITHUB_WORKSPACE -B ${{runner.workspace}}/build 166 | -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install 167 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 168 | 169 | - name: Build 170 | shell: bash 171 | run: cmake --build ${{runner.workspace}}/build -j2 172 | 173 | - name: Install 174 | shell: bash 175 | run: cmake --build ${{runner.workspace}}/build --target install 176 | 177 | - name: CMake Discovery Configure 178 | shell: bash 179 | run: cmake -S $GITHUB_WORKSPACE/test/cmake/discovery -B ${{runner.workspace}}/cmake_discovery_build 180 | -DCMAKE_PREFIX_PATH="${{runner.workspace}}/install;${ENV_PREFIX_PATH}" 181 | -DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/${GH_ACTIONS_TOOLCHAIN} 182 | 183 | - name: CMake Discovery Build 184 | shell: bash 185 | run: cmake --build ${{runner.workspace}}/cmake_discovery_build -j2 186 | -------------------------------------------------------------------------------- /.github/workflows/scripts/compiler_setup.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | export CSUITE=$1 4 | export CVER=$2 5 | 6 | if [[ "${CSUITE}" == "llvm" ]] 7 | then 8 | update-alternatives --set clang /usr/bin/clang-${CVER} 9 | update-alternatives --set clang++ /usr/bin/clang++-${CVER} 10 | update-alternatives --install /usr/bin/cc cc /usr/bin/clang 30 11 | update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 30 12 | elif [[ "${CSUITE}" == "gnu" ]] 13 | then 14 | update-alternatives --set gcc /usr/bin/gcc-${CVER} 15 | update-alternatives --set g++ /usr/bin/g++-${CVER} 16 | update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30 17 | update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30 18 | else 19 | echo "Compiler Suite Not Recognized!" 20 | exit 125 21 | fi 22 | 23 | -------------------------------------------------------------------------------- /.github/workflows/toolchains/gh-actions.cmake: -------------------------------------------------------------------------------- 1 | set( CMAKE_C_COMPILER cc ) 2 | set( CMAKE_CXX_COMPILER c++ ) 3 | 4 | set(CMAKE_CXX_FLAGS_INIT "-march=native") 5 | set(CMAKE_C_FLAGS_INIT "-march=native") 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.*.swp 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.21 FATAL_ERROR ) # Require CMake 3.21+ 2 | include(FetchContent) 3 | 4 | # Set up project definition + version information 5 | project( ExchCXX VERSION 0.1.0 LANGUAGES C CXX ) 6 | 7 | # ExchCXX Options 8 | option( EXCHCXX_ENABLE_BENCHMARK "Enable Performance Benchmark" OFF ) 9 | option( EXCHCXX_ENABLE_CUDA "Enable Device Code (CUDA)" OFF ) 10 | option( EXCHCXX_ENABLE_HIP "Enable Device Code (HIP)" OFF ) 11 | option( EXCHCXX_ENABLE_SYCL "Enable Device Code (SYCL)" OFF ) 12 | option( EXCHCXX_ENABLE_LIBXC "Enable Libxc Backend" ON ) 13 | option( BUILD_SHARED_LIBS "Build Shared Libs" OFF ) 14 | 15 | 16 | # Decided if we're compiling device bindings 17 | if( EXCHCXX_ENABLE_CUDA OR EXCHCXX_ENABLE_SYCL OR EXCHCXX_ENABLE_HIP ) 18 | set( EXCHCXX_ENABLE_DEVICE TRUE CACHE BOOL "Enable Device Code" ) 19 | endif() 20 | 21 | # Die if both CUDA and SYCL are enabled 22 | if( EXCHCXX_ENABLE_CUDA AND EXCHCXX_ENABLE_SYCL ) 23 | message( FATAL_ERROR "CUDA / SYCL bindings are mutually exclusive" ) 24 | endif() 25 | if( EXCHCXX_ENABLE_CUDA AND EXCHCXX_ENABLE_HIP ) 26 | message( FATAL_ERROR "CUDA / HIP bindings are mutually exclusive" ) 27 | endif() 28 | if( EXCHCXX_ENABLE_SYCL AND EXCHCXX_ENABLE_HIP ) 29 | message( FATAL_ERROR "SYCL / HIP bindings are mutually exclusive" ) 30 | endif() 31 | 32 | 33 | # Append local cmake directory to find CMAKE Modules 34 | if( CMAKE_MODULE_PATH ) 35 | list( APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 36 | else() 37 | set( CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 38 | endif() 39 | 40 | # Populate BUILD_TESTING prior to dependencies to avoid clash 41 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 42 | include(CTest) 43 | endif() 44 | 45 | 46 | 47 | # Enable CUDA if desired 48 | if( EXCHCXX_ENABLE_CUDA ) 49 | enable_language( CUDA ) 50 | endif() 51 | 52 | if( EXCHCXX_ENABLE_HIP ) 53 | enable_language( HIP ) 54 | endif() 55 | 56 | 57 | if(EXCHCXX_ENABLE_LIBXC) 58 | 59 | ## Find LibXC 60 | find_package( Libxc 7.0.0 CONFIG QUIET ) 61 | 62 | if( ${Libxc_FOUND} ) 63 | 64 | message( STATUS "Found: Libxc Version ${Libxc_VERSION}" ) 65 | if( Libxc_VERSION VERSION_GREATER_EQUAL "8.0.0" ) 66 | message( FATAL_ERROR "Libxc version 8+ breaks the API currently used in ExchCXX" ) 67 | endif() 68 | 69 | else() 70 | 71 | option( FETCHCONTENT_LIBXC_GIT_SHALLOW "Whether to use GIT_SHALLOW for FetchContent'ing libxc" ON ) 72 | 73 | FetchContent_Declare( 74 | libxc 75 | GIT_REPOSITORY https://gitlab.com/libxc/libxc.git 76 | # if pinning to specific SHA change the FETCHCONTENT_LIBXC_GIT_SHALLOW default to OFF, https://cmake.org/cmake/help/latest/module/ExternalProject.html#git 77 | GIT_TAG 7.0.0 78 | GIT_SHALLOW ${FETCHCONTENT_LIBXC_GIT_SHALLOW} 79 | PATCH_COMMAND sed -i -e "s/p->info->family != XC_KINETIC/p->info->kind != XC_KINETIC/g" src/work_mgga_inc.c 80 | ) 81 | set( Libxc_VERSION 7.0.0 ) 82 | 83 | set( OLD_BUILD_TESTING ${BUILD_TESTING} ) 84 | set( BUILD_TESTING OFF CACHE BOOL "" FORCE ) 85 | 86 | FetchContent_MakeAvailable( libxc ) 87 | add_library( Libxc::xc ALIAS xc ) 88 | target_include_directories( xc 89 | PUBLIC 90 | $ 91 | $ 92 | $ 93 | ) 94 | message( STATUS "Libxc Source: ${libxc_SOURCE_DIR}" ) 95 | 96 | # disable unity builds for libxc 97 | if (CMAKE_UNITY_BUILD) 98 | set_target_properties(xc PROPERTIES UNITY_BUILD OFF) 99 | message(STATUS "Will disable unity-build for Libxc::xc") 100 | endif() 101 | 102 | set( BUILD_TESTING ${OLD_BUILD_TESTING} CACHE BOOL "" FORCE ) 103 | 104 | endif() 105 | 106 | else( EXCHCXX_ENABLE_LIBXC ) 107 | set( Libxc_FOUND FALSE ) 108 | endif( EXCHCXX_ENABLE_LIBXC ) 109 | 110 | add_subdirectory( src ) 111 | 112 | # Testing 113 | if( NOT DEFINED EXCHCXX_ENABLE_TESTS ) 114 | set( EXCHCXX_ENABLE_TESTS ON ) 115 | endif() 116 | 117 | if( CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND EXCHCXX_ENABLE_TESTS AND BUILD_TESTING ) 118 | if(${Libxc_FOUND} OR NOT EXCHCXX_ENABLE_LIBXC) 119 | message(WARNING "ExchCXX Unit Tests Require Local Patch of Libxc - Disabling") 120 | else() 121 | add_subdirectory( test ) 122 | endif() 123 | endif() 124 | 125 | if( EXCHCXX_ENABLE_BENCHMARK AND EXCHCXX_ENABLE_LIBXC ) 126 | add_subdirectory( performance ) 127 | endif() 128 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | # Installation Instructions 2 | 3 | ## Prerequisites 4 | - [CMake](https://cmake.org) v3.21+ 5 | - A C++14 (17 for SYCL builds) compilant C++ compiler 6 | 7 | ## Optional Dependencies 8 | - A [CUDA](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html) compiler, (e.g. `nvcc`, required only if CUDA is enabled) 9 | - A [HIP](https://rocmdocs.amd.com/en/latest/Programming_Guides/HIP-GUIDE.html) compiler, (e.g. `hipcc` or modern `clang++`, required only if HIP is enabled) 10 | - A LLVM SYCL Compiler (e.g. [DPC++](https://github.com/intel/llvm), required only if SYCL enabled) 11 | - Libxc (required only for host API) 12 | 13 | ## Configuration, Compilation and Installation 14 | 15 | ExchCXX provides a CMake build system with automatic dependency management 16 | (through 17 | [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html)). 18 | As such, a simple CMake invocation will often suffice for most purposes 19 | ``` 20 | cmake -S /path/to/ExchCXX -B /path/to/binary [ExchCXX configure options] 21 | cmake --build /path/to/binary # to build without installation 22 | cmake --build /path/to/binary --target install # to install 23 | ``` 24 | 25 | 26 | ExchCXX is linkable both as an installed library as well as a CMake subproject via `FetchContent` 27 | ``` 28 | # ExchCXX Discovery 29 | find_package( exchcxx REQUIRED ) 30 | target_link_libraries( my_target PUBLIC exchcxx::exchcxx ) 31 | ``` 32 | 33 | ``` 34 | # ExchCXX as CMake Subproject 35 | include(FetchContent) 36 | 37 | # Set ExchCXX CMake options (see below) 38 | 39 | # Pull master branch of ExchCXX 40 | FetchContent_Declare( exchcxx 41 | GIT_REPOSITORY https://github/com/wavefunction91/ExchCXX.git 42 | GIT_TAG master 43 | ) 44 | FetchContent_MakeAvailable( exchcxx ) 45 | 46 | # Link to target 47 | target_link_libraries( my_target PUBLIC exchcxx::exchcxx ) 48 | ``` 49 | 50 | ## CMake Variables 51 | 52 | | Variable Name | Description | Default | 53 | |------------------------- |----------------------------------------------------------------|----------| 54 | | `EXCHCXX_ENABLE_TESTS` | Enable Testing Framework (Catch2) | `ON` | 55 | | `EXCHCXX_ENABLE_BENCHMARK` | Enable Performance Benchmark | `OFF` | 56 | | `EXCHCXX_ENABLE_CUDA` | Enable CUDA XC evaluator | `OFF` | 57 | | `EXCHCXX_ENABLE_HIP` | Enable HIP XC evaluator | `OFF` | 58 | | `EXCHCXX_ENABLE_SYCL` | Enable SYCL XC evaluator (experimental) | `OFF` | 59 | 60 | N.B. ExchCXX accelerator bindings are mutally exclusive - this is intentially and will be enforced on configure. 61 | If it would be desirable to support coexistance of these bindings for your application, please open 62 | an [issue](https://github.com/wavefunction91/ExchCXX/issues) 63 | 64 | ## Build Notes 65 | 66 | ### Building with CUDA 67 | 68 | For CUDA builds, [`CMAKE_CUDA_ARCHITECTURES`](https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html) 69 | must be set. For example, to build a fat binary for NVIDIA V100 and A100, 70 | ``` 71 | cmake [source locations] -DCMAKE_CUDA_ARCHITECTURES="70;80" [additional options] 72 | ``` 73 | ExchCXX supports NVIDIA GPUs with CC >= 60. 74 | 75 | ### Building with SYCL 76 | 77 | ExchCXX support for SYCL is experimental, and the mechanism for enabling CMake support 78 | is likely to change in the future. 79 | SYCL builds require C++17 per the SYCL-2020 standard. 80 | Due to the volitility in SYCL compiler development, ExchCXX does not provide automatic means to determine 81 | the SYCL targets (e.g. NVIDIA-PTX, OpenMP, etc) for the platform of interest. As such, these must be 82 | specified manually in `CMAKE_CXX_FLAGS`. For example, building for a NVIDIA-PTX target with the DPC++ 83 | compiler may be achieved via 84 | ``` 85 | cmake [source locations] -DCMAKE_CXX_FLAGS="-fsycl-targets=nvptx64-nvidia-cuda -fsycl" [additional options] 86 | ``` 87 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 2 | through Lawrence Berkeley National Laboratory (subject to receipt of 3 | any required approvals from the U.S. Dept. of Energy). All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | (1) Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 11 | (2) Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | (3) Neither the name of the University of California, Lawrence Berkeley 16 | National Laboratory, U.S. Dept. of Energy nor the names of its contributors 17 | may be used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | 33 | You are under no obligation whatsoever to provide any bug fixes, patches, 34 | or upgrades to the features, functionality or performance of the source 35 | code ("Enhancements") to anyone; however, if you choose to make your 36 | Enhancements available either publicly, or directly to Lawrence Berkeley 37 | National Laboratory, without imposing a separate written license agreement 38 | for such Enhancements, then you hereby grant the following license: a 39 | non-exclusive, royalty-free perpetual license to install, use, modify, 40 | prepare derivative works, incorporate into other computer software, 41 | distribute, and sublicense such enhancements or derivative works thereof, 42 | in binary and source code form. 43 | -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | # Development Scripts and Binaries 2 | 3 | The files in this folder are meant for internal use only: automatatic generation 4 | of builtin kernel implementations, etc. Use at your own risk! 5 | -------------------------------------------------------------------------------- /cmake/ExchCXXConfig.cmake.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.21 FATAL_ERROR) # Require CMake 3.21+ 2 | 3 | get_filename_component(ExchCXX_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 4 | 5 | list(APPEND CMAKE_MODULE_PATH ${ExchCXX_CMAKE_DIR}) 6 | include(CMakeFindDependencyMacro) 7 | 8 | 9 | set( EXCHCXX_ENABLE_CUDA @EXCHCXX_ENABLE_CUDA@ ) 10 | set( EXCHCXX_ENABLE_HIP @EXCHCXX_ENABLE_HIP@ ) 11 | set( EXCHCXX_ENABLE_SYCL @EXCHCXX_ENABLE_SYCL@ ) 12 | set( EXCHCXX_ENABLE_DEVICE @EXCHCXX_ENABLE_DEVICE@ ) 13 | set( EXCHCXX_ENABLE_LIBXC @EXCHCXX_ENABLE_LIBXC@ ) 14 | 15 | if( EXCHCXX_ENABLE_LIBXC ) 16 | find_dependency( Libxc @Libxc_VERSION@ EXACT CONFIG ) 17 | endif() 18 | 19 | if( EXCHCXX_ENABLE_CUDA ) 20 | find_dependency( CUDAToolkit @CUDAToolkit_VERSION@ EXACT ) 21 | endif() 22 | 23 | if( EXCHCXX_ENABLE_HIP ) 24 | find_dependency( hip ) 25 | endif() 26 | 27 | list(REMOVE_AT CMAKE_MODULE_PATH -1) 28 | 29 | if(NOT TARGET ExchCXX::ExchCXX) 30 | include("${ExchCXX_CMAKE_DIR}/ExchCXXTargets.cmake") 31 | endif() 32 | 33 | set(ExchCXX_LIBRARIES ExchCXX::ExchCXX) 34 | -------------------------------------------------------------------------------- /cmake/FindSYCL.cmake: -------------------------------------------------------------------------------- 1 | include( FindPackageHandleStandardArgs ) 2 | include( CheckCXXCompilerFlag ) 3 | check_cxx_compiler_flag("-fsycl" CXX_HAS_FSYCL) 4 | 5 | find_package_handle_standard_args( SYCL 6 | REQUIRED_VARS CXX_HAS_FSYCL 7 | ) 8 | 9 | if( SYCL_FOUND AND NOT TARGET SYCL::SYCL ) 10 | add_library( SYCL::SYCL INTERFACE IMPORTED ) 11 | set_target_properties( SYCL::SYCL PROPERTIES 12 | INTERFACE_COMPILE_OPTIONS "$<$:-fsycl>" 13 | INTERFACE_LINK_OPTIONS "-fsycl" 14 | ) 15 | endif() 16 | -------------------------------------------------------------------------------- /include/exchcxx/boilerplate.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | #include 53 | 54 | namespace ExchCXX { 55 | 56 | void initialize(Spin); 57 | void finalize(); 58 | 59 | bool is_initialized(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /include/exchcxx/enums/backend.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | 49 | namespace ExchCXX { 50 | 51 | enum class Backend { 52 | #ifdef EXCHCXX_ENABLE_LIBXC 53 | libxc, 54 | #endif 55 | builtin 56 | }; 57 | 58 | #ifdef EXCHCXX_ENABLE_LIBXC 59 | using libxc_name_string = detail::NamedType; 60 | #endif 61 | 62 | } 63 | -------------------------------------------------------------------------------- /include/exchcxx/enums/enums.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #include "kernels.hpp" 49 | #include "functionals.hpp" 50 | #include "backend.hpp" 51 | #include "spin.hpp" 52 | -------------------------------------------------------------------------------- /include/exchcxx/enums/functionals.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #include 49 | 50 | namespace ExchCXX { 51 | 52 | enum class Functional { 53 | SVWN3, 54 | SVWN5, 55 | BLYP, 56 | B3LYP, 57 | PBE, 58 | revPBE, 59 | PBE0, 60 | SCAN, 61 | R2SCAN, 62 | R2SCANL, 63 | M062X, 64 | PKZB, 65 | EPC17_1, 66 | EPC17_2, 67 | EPC18_1, 68 | EPC18_2, 69 | }; 70 | 71 | extern BidirectionalMap functional_map; 72 | 73 | std::ostream &operator<<(std::ostream &out, Functional functional); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /include/exchcxx/enums/kernels.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | #include 53 | #include 54 | 55 | namespace ExchCXX { 56 | 57 | enum class Kernel { 58 | // LDA Functionals 59 | SlaterExchange, 60 | VWN3, 61 | VWN5, 62 | PZ81, 63 | PZ81_MOD, 64 | PW91_LDA, 65 | PW91_LDA_MOD, 66 | PW91_LDA_RPA, 67 | /* 68 | Wigner, 69 | RPA, 70 | HedinLundqvist, 71 | GunnarsonLundqvist, 72 | XAlpha, 73 | */ 74 | /* 75 | VWN_RPA, 76 | PerdewZunger, 77 | PerdewZungerMod, 78 | */ 79 | // GGA functionals 80 | PBE_X, 81 | PBE_C, 82 | revPBE_X, 83 | B88, 84 | LYP, 85 | 86 | // MGGA functionals 87 | SCAN_C, 88 | SCAN_X, 89 | SCANL_C, 90 | SCANL_X, 91 | R2SCAN_C, 92 | R2SCAN_X, 93 | R2SCANL_C, 94 | R2SCANL_X, 95 | FT98_X, 96 | M062X_X, 97 | M062X_C, 98 | PKZB_X, 99 | PKZB_C, 100 | 101 | 102 | // KEDFs 103 | PC07_K, 104 | PC07OPT_K, 105 | 106 | // Hybrid GGA functionals 107 | B3LYP, 108 | PBE0, 109 | 110 | // NEO LDA Functionals 111 | EPC17_1, 112 | EPC17_2, 113 | EPC18_1, 114 | EPC18_2, 115 | }; 116 | 117 | inline static bool supports_unpolarized(ExchCXX::Kernel kern) { 118 | switch (kern) { 119 | case ExchCXX::Kernel::EPC17_1: 120 | case ExchCXX::Kernel::EPC17_2: 121 | case ExchCXX::Kernel::EPC18_1: 122 | case ExchCXX::Kernel::EPC18_2: 123 | return false; 124 | default: 125 | return true; 126 | } 127 | } 128 | 129 | 130 | extern BidirectionalMap kernel_map; 131 | 132 | std::ostream& operator<<( std::ostream& out, Kernel kern ); 133 | 134 | } 135 | -------------------------------------------------------------------------------- /include/exchcxx/enums/spin.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | namespace ExchCXX { 49 | 50 | enum class Spin { 51 | Polarized, 52 | Unpolarized 53 | }; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /include/exchcxx/exceptions/exchcxx_exception.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | namespace ExchCXX { 54 | 55 | class exchcxx_exception : public std::exception { 56 | 57 | std::string file_; 58 | int line_; 59 | std::string msg_prefix_; 60 | 61 | const char* what() const noexcept override { 62 | std::stringstream ss; 63 | ss << "EXCHCXX Exception (" << msg_prefix_ << ")" << std::endl 64 | << " File " << file_ << std::endl 65 | << " Line " << line_ << std::endl; 66 | 67 | auto msg = ss.str(); 68 | 69 | return strdup( msg.c_str() ); 70 | } 71 | 72 | public: 73 | 74 | exchcxx_exception( std::string file, int line, std::string msg) : 75 | file_(file), line_(line), msg_prefix_(msg) { } 76 | 77 | }; 78 | 79 | #define EXCHCXX_BOOL_CHECK( MSG, V ) \ 80 | if( not (V) ) \ 81 | throw exchcxx_exception( __FILE__, __LINE__, MSG ); 82 | 83 | } 84 | -------------------------------------------------------------------------------- /include/exchcxx/exchcxx.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #include 49 | #include 50 | #include 51 | 52 | -------------------------------------------------------------------------------- /include/exchcxx/exchcxx_config.hpp.in: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #cmakedefine EXCHCXX_ENABLE_CUDA 49 | #cmakedefine EXCHCXX_ENABLE_HIP 50 | #cmakedefine EXCHCXX_ENABLE_SYCL 51 | #cmakedefine EXCHCXX_ENABLE_DEVICE 52 | #cmakedefine EXCHCXX_ENABLE_LIBXC 53 | 54 | 55 | #ifdef EXCHCXX_ENABLE_CUDA 56 | #include 57 | #endif 58 | 59 | #ifdef EXCHCXX_ENABLE_HIP 60 | #include 61 | #endif 62 | 63 | #ifdef EXCHCXX_ENABLE_SYCL 64 | #include 65 | #endif 66 | -------------------------------------------------------------------------------- /include/exchcxx/factory/xc_kernel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | #include 54 | 55 | namespace ExchCXX { 56 | 57 | #ifdef EXCHCXX_ENABLE_LIBXC 58 | XCKernel libxc_kernel_factory(const Kernel, const Spin ); 59 | XCKernel libxc_kernel_factory(const std::string xc_name, const Spin polar ); 60 | #endif 61 | 62 | XCKernel builtin_kernel_factory( Kernel, Spin ); 63 | 64 | static inline XCKernel kernel_factory( 65 | Backend backend, Kernel kern, Spin polar 66 | ) { 67 | 68 | #ifdef EXCHCXX_ENABLE_LIBXC 69 | if( backend == Backend::libxc ) 70 | return libxc_kernel_factory( kern, polar ); 71 | else 72 | #endif 73 | return builtin_kernel_factory( kern, polar ); 74 | 75 | } 76 | 77 | } // namespace ExchCXX 78 | 79 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/constants.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | #include 52 | 53 | 54 | namespace ExchCXX { 55 | namespace constants { 56 | 57 | constexpr double m_cbrt_2 = 1.259921049894873164767210607278228350570L; 58 | constexpr double m_cbrt_3 = 1.442249570307408382321638310780109588392L; 59 | constexpr double m_cbrt_4 = 1.587401051968199474751705639272308260391L; 60 | constexpr double m_cbrt_6 = 1.817120592832139658891211756327260502428L; 61 | constexpr double m_cbrt_pi = 1.464591887561523263020142527263790391739L; 62 | constexpr double m_pi = 3.14159265358979323846e+00; 63 | constexpr double m_one_ov_pi = 3.18309886183790691216e-01; 64 | constexpr double m_pi_sq = 9.869604401089357992305e+00; 65 | //constexpr double m_cbrt_one_ov_pi = 6.82784063255295725625e-01; 66 | constexpr double m_cbrt_one_ov_pi = 6.82784063255295503581e-01; 67 | constexpr double m_cbrt_pi_sq = 2.145029397111025470934e+00; 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/fwd.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | namespace ExchCXX { 54 | 55 | class BuiltinKernel; 56 | 57 | struct BuiltinSlaterExchange; 58 | struct BuiltinVWN3; 59 | struct BuiltinVWN_RPA; 60 | struct BuiltinPW91_LDA; 61 | struct BuiltinPW91_LDA_MOD; 62 | struct BuiltinPW91_LDA_RPA; 63 | struct BuiltinPZ81; 64 | struct BuiltinPZ81_MOD; 65 | 66 | struct BuiltinB88; 67 | struct BuiltinLYP; 68 | struct BuiltinPBE_X; 69 | struct BuiltinRevPBE_X; 70 | struct BuiltinPBE_C; 71 | 72 | struct BuiltinB3LYP; 73 | struct BuiltinPBE0; 74 | 75 | struct BuiltinSCAN_X; 76 | struct BuiltinSCAN_C; 77 | struct BuiltinR2SCAN_X; 78 | struct BuiltinR2SCAN_C; 79 | struct BuiltinM062X_X; 80 | struct BuiltinM062X_C; 81 | struct BuiltinPKZB_X; 82 | struct BuiltinPKZB_C; 83 | struct BuiltinFT98_X; 84 | 85 | struct BuiltinPC07_K; 86 | struct BuiltinPC07OPT_K; 87 | 88 | template 89 | struct Deorbitalized; 90 | struct BuiltinSCANL_X; 91 | struct BuiltinSCANL_C; 92 | struct BuiltinR2SCANL_X; 93 | struct BuiltinR2SCANL_C; 94 | 95 | struct BuiltinEPC17_1; 96 | struct BuiltinEPC17_2; 97 | struct BuiltinEPC18_1; 98 | struct BuiltinEPC18_2; 99 | 100 | template 101 | struct kernel_traits; 102 | 103 | 104 | 105 | 106 | namespace detail { 107 | template 108 | struct BuiltinKernelImpl; 109 | 110 | class BuiltinKernelInterface; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/interface.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | namespace ExchCXX { 59 | namespace detail { 60 | 61 | class BuiltinKernelInterface : public XCKernelImpl { 62 | 63 | using unique_me = XCKernelImpl::unique_me; 64 | 65 | unique_me clone_() const override; 66 | 67 | Kernel whatami_; 68 | 69 | std::unique_ptr impl_; 70 | 71 | bool is_lda_() const noexcept override; 72 | bool is_gga_() const noexcept override; 73 | bool is_mgga_() const noexcept override; 74 | bool is_hyb_() const noexcept override; 75 | bool is_epc_() const noexcept override; 76 | bool needs_laplacian_() const noexcept override; 77 | bool needs_tau_() const noexcept override; 78 | bool is_polarized_() const noexcept override; 79 | double hyb_exx_() const noexcept override; 80 | 81 | bool supports_inc_interface_() const noexcept override; 82 | 83 | // LDA interface 84 | LDA_EXC_GENERATOR( eval_exc_ ) const override; 85 | LDA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 86 | LDA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 87 | LDA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 88 | 89 | // GGA interface 90 | GGA_EXC_GENERATOR( eval_exc_ ) const override; 91 | GGA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 92 | GGA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 93 | GGA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 94 | 95 | // MGGA interface 96 | MGGA_EXC_GENERATOR( eval_exc_ ) const override; 97 | MGGA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 98 | MGGA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 99 | MGGA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 100 | 101 | #ifdef EXCHCXX_ENABLE_DEVICE 102 | 103 | // LDA interface 104 | LDA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 105 | LDA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 106 | LDA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 107 | LDA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 108 | 109 | // GGA interface 110 | GGA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 111 | GGA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 112 | GGA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 113 | GGA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 114 | 115 | // MGGA interface 116 | MGGA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 117 | MGGA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 118 | MGGA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 119 | MGGA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 120 | 121 | #endif 122 | 123 | public: 124 | 125 | BuiltinKernelInterface() = delete; 126 | 127 | BuiltinKernelInterface( Kernel kern, Spin p); 128 | BuiltinKernelInterface( const BuiltinKernelInterface& ); 129 | BuiltinKernelInterface( BuiltinKernelInterface&& ) noexcept = delete; 130 | 131 | // Destroy interal Builtin data 132 | ~BuiltinKernelInterface() noexcept; 133 | 134 | }; 135 | 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | 68 | #include 69 | #include 70 | 71 | #include 72 | #include 73 | #include 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | #include 80 | #include 81 | #include 82 | #include 83 | #include 84 | 85 | #include 86 | #include 87 | 88 | #include 89 | #include 90 | #include 91 | #include 92 | 93 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/b3lyp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace ExchCXX { 15 | 16 | template <> 17 | struct kernel_traits { 18 | 19 | static constexpr bool is_hyb = true; 20 | static constexpr bool is_lda = false; 21 | static constexpr bool is_gga = true; 22 | static constexpr bool is_mgga = false; 23 | static constexpr bool is_epc = false; 24 | static constexpr double exx_coeff = 0.20; 25 | 26 | static constexpr double b3lyp_ax = 0.72; // % GGA X 27 | static constexpr double b3lyp_ac = 0.81; // % GGA C 28 | 29 | static constexpr double b3lyp_slater_coeff = 1. - exx_coeff - b3lyp_ax; 30 | static constexpr double b3lyp_vwn_coeff = 1. - b3lyp_ac; 31 | 32 | using slater_traits = kernel_traits; 33 | using b88_traits = kernel_traits; 34 | using vwn_traits = kernel_traits; 35 | using lyp_traits = kernel_traits; 36 | 37 | BUILTIN_KERNEL_EVAL_RETURN 38 | eval_exc_unpolar( double rho, double sigma, double& eps ) { 39 | 40 | slater_traits::eval_exc_unpolar( rho, eps ); 41 | double slater_eps = eps; 42 | 43 | b88_traits::eval_exc_unpolar( rho, sigma, eps ); 44 | double b88_eps = eps; 45 | 46 | vwn_traits::eval_exc_unpolar( rho, eps ); 47 | double vwn_eps = eps; 48 | 49 | lyp_traits::eval_exc_unpolar( rho, sigma, eps ); 50 | double lyp_eps = eps; 51 | 52 | eps = b3lyp_slater_coeff * slater_eps + b3lyp_ax * b88_eps + 53 | b3lyp_vwn_coeff * vwn_eps + b3lyp_ac * lyp_eps; 54 | 55 | } 56 | 57 | BUILTIN_KERNEL_EVAL_RETURN 58 | eval_exc_polar( double rho_a, double rho_b, double sigma_aa, 59 | double sigma_ab, double sigma_bb, double& eps ) { 60 | 61 | slater_traits::eval_exc_polar( rho_a, rho_b, eps ); 62 | double slater_eps = eps; 63 | 64 | b88_traits::eval_exc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, eps ); 65 | double b88_eps = eps; 66 | 67 | vwn_traits::eval_exc_polar( rho_a, rho_b, eps ); 68 | double vwn_eps = eps; 69 | 70 | lyp_traits::eval_exc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, eps ); 71 | double lyp_eps = eps; 72 | 73 | eps = b3lyp_slater_coeff * slater_eps + b3lyp_ax * b88_eps + 74 | b3lyp_vwn_coeff * vwn_eps + b3lyp_ac * lyp_eps; 75 | 76 | } 77 | 78 | BUILTIN_KERNEL_EVAL_RETURN 79 | eval_exc_vxc_unpolar( double rho, double sigma, double& eps, double& vrho, 80 | double& vsigma ) { 81 | 82 | slater_traits::eval_exc_vxc_unpolar( rho, eps, vrho ); 83 | double slater_eps = eps; 84 | double slater_vrho = vrho; 85 | 86 | b88_traits::eval_exc_vxc_unpolar( rho, sigma, eps, vrho, vsigma ); 87 | double b88_eps = eps; 88 | double b88_vrho = vrho; 89 | double b88_vsigma = vsigma; 90 | 91 | vwn_traits::eval_exc_vxc_unpolar( rho, eps, vrho ); 92 | double vwn_eps = eps; 93 | double vwn_vrho = vrho; 94 | 95 | lyp_traits::eval_exc_vxc_unpolar( rho, sigma, eps, vrho, vsigma ); 96 | double lyp_eps = eps; 97 | double lyp_vrho = vrho; 98 | double lyp_vsigma = vsigma; 99 | 100 | eps = b3lyp_slater_coeff * slater_eps + b3lyp_ax * b88_eps + 101 | b3lyp_vwn_coeff * vwn_eps + b3lyp_ac * lyp_eps; 102 | 103 | vrho = b3lyp_slater_coeff * slater_vrho + b3lyp_ax * b88_vrho + 104 | b3lyp_vwn_coeff * vwn_vrho + b3lyp_ac * lyp_vrho; 105 | 106 | vsigma = b3lyp_ax * b88_vsigma + b3lyp_ac * lyp_vsigma; 107 | 108 | } 109 | 110 | 111 | 112 | BUILTIN_KERNEL_EVAL_RETURN 113 | eval_exc_vxc_polar( double rho_a, double rho_b, double sigma_aa, double sigma_ab, 114 | double sigma_bb, double& eps, double& vrho_a, double& vrho_b, double& vsigma_aa, 115 | double& vsigma_ab, double& vsigma_bb ) { 116 | 117 | slater_traits::eval_exc_vxc_polar( rho_a, rho_b, eps, vrho_a, vrho_b ); 118 | double slater_eps = eps; 119 | double slater_vrho_a = vrho_a; 120 | double slater_vrho_b = vrho_b; 121 | 122 | b88_traits::eval_exc_vxc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, 123 | eps, vrho_a, vrho_b, vsigma_aa, vsigma_ab, vsigma_bb ); 124 | double b88_eps = eps; 125 | double b88_vrho_a = vrho_a; 126 | double b88_vrho_b = vrho_b; 127 | double b88_vsigma_aa = vsigma_aa; 128 | double b88_vsigma_ab = vsigma_ab; 129 | double b88_vsigma_bb = vsigma_bb; 130 | 131 | vwn_traits::eval_exc_vxc_polar( rho_a, rho_b, eps, vrho_a, vrho_b ); 132 | double vwn_eps = eps; 133 | double vwn_vrho_a = vrho_a; 134 | double vwn_vrho_b = vrho_b; 135 | 136 | lyp_traits::eval_exc_vxc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, 137 | eps, vrho_a, vrho_b, vsigma_aa, vsigma_ab, vsigma_bb ); 138 | double lyp_eps = eps; 139 | double lyp_vrho_a = vrho_a; 140 | double lyp_vrho_b = vrho_b; 141 | double lyp_vsigma_aa = vsigma_aa; 142 | double lyp_vsigma_ab = vsigma_ab; 143 | double lyp_vsigma_bb = vsigma_bb; 144 | 145 | eps = b3lyp_slater_coeff * slater_eps + b3lyp_ax * b88_eps + 146 | b3lyp_vwn_coeff * vwn_eps + b3lyp_ac * lyp_eps; 147 | 148 | vrho_a = b3lyp_slater_coeff * slater_vrho_a + b3lyp_ax * b88_vrho_a + 149 | b3lyp_vwn_coeff * vwn_vrho_a + b3lyp_ac * lyp_vrho_a; 150 | vrho_b = b3lyp_slater_coeff * slater_vrho_b + b3lyp_ax * b88_vrho_b + 151 | b3lyp_vwn_coeff * vwn_vrho_b + b3lyp_ac * lyp_vrho_b; 152 | 153 | vsigma_aa = b3lyp_ax * b88_vsigma_aa + b3lyp_ac * lyp_vsigma_aa; 154 | vsigma_ab = b3lyp_ax * b88_vsigma_ab + b3lyp_ac * lyp_vsigma_ab; 155 | vsigma_bb = b3lyp_ax * b88_vsigma_bb + b3lyp_ac * lyp_vsigma_bb; 156 | 157 | } 158 | 159 | }; 160 | 161 | 162 | 163 | 164 | 165 | 166 | struct BuiltinB3LYP : detail::BuiltinKernelImpl< BuiltinB3LYP > { 167 | 168 | BuiltinB3LYP( Spin p ) : 169 | detail::BuiltinKernelImpl< BuiltinB3LYP >(p) { } 170 | 171 | virtual ~BuiltinB3LYP() = default; 172 | 173 | }; 174 | 175 | } 176 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/deorbitalized.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace ExchCXX { 7 | 8 | 9 | template 10 | struct kernel_traits> { 11 | 12 | using xc_traits = kernel_traits; 13 | using ke_traits = kernel_traits; 14 | 15 | static constexpr bool is_hyb = xc_traits::is_hyb or ke_traits::is_hyb; 16 | static constexpr bool is_lda = false; 17 | static constexpr bool is_gga = false; 18 | static constexpr bool is_mgga = true; 19 | static constexpr bool needs_laplacian = true; 20 | static constexpr bool is_kedf = false; 21 | static constexpr bool is_epc = false; 22 | static constexpr double exx_coeff = xc_traits::exx_coeff + ke_traits::exx_coeff; 23 | 24 | BUILTIN_KERNEL_EVAL_RETURN 25 | eval_exc_unpolar( double rho, double sigma, double lapl, double tau, double& eps ) { 26 | 27 | double TAU; 28 | ke_traits::eval_exc_unpolar(rho, sigma, lapl, 0.0, TAU); 29 | 30 | TAU = TAU * rho; 31 | xc_traits::eval_exc_unpolar(rho, sigma, lapl, TAU, eps); 32 | 33 | } 34 | 35 | BUILTIN_KERNEL_EVAL_RETURN 36 | eval_exc_vxc_unpolar( double rho, double sigma, double lapl, double tau, double& eps, double& vrho, double& vsigma, double& vlapl, double& vtau ) { 37 | 38 | double TAU, vrho_k, vsigma_k, vlapl_k, dummy; 39 | ke_traits::eval_exc_vxc_unpolar(rho, sigma, lapl, 0.0, TAU, vrho_k, vsigma_k, vlapl_k, dummy); 40 | 41 | 42 | TAU = TAU * rho; 43 | xc_traits::eval_exc_vxc_unpolar(rho, sigma, lapl, TAU, eps, vrho, vsigma, vlapl, vtau); 44 | 45 | vrho += vtau * vrho_k; 46 | vsigma += vtau * vsigma_k; 47 | vlapl = vtau * vlapl_k; 48 | vtau = 0.0; 49 | 50 | } 51 | 52 | BUILTIN_KERNEL_EVAL_RETURN 53 | eval_exc_polar( double rho_a, double rho_b, double sigma_aa, double sigma_ab, double sigma_bb, double lapl_a, double lapl_b, double tau_a, double tau_b, double& eps ) { 54 | 55 | double TAU_A, TAU_B; 56 | ke_traits::eval_exc_polar(rho_a, 0.0, sigma_aa, 0.0, 0.0, lapl_a, 0.0, 0.0, 0.0, TAU_A); 57 | ke_traits::eval_exc_polar(rho_b, 0.0, sigma_bb, 0.0, 0.0, lapl_b, 0.0, 0.0, 0.0, TAU_B); 58 | 59 | TAU_A *= rho_a; 60 | TAU_B *= rho_b; 61 | xc_traits::eval_exc_polar(rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, lapl_a, lapl_b, TAU_A, TAU_B, eps); 62 | 63 | } 64 | 65 | BUILTIN_KERNEL_EVAL_RETURN 66 | eval_exc_vxc_polar( double rho_a, double rho_b, double sigma_aa, double sigma_ab, double sigma_bb, double lapl_a, double lapl_b, double tau_a, double tau_b, double& eps, double& vrho_a, double& vrho_b, double& vsigma_aa, double& vsigma_ab, double& vsigma_bb, double& vlapl_a, double& vlapl_b, double& vtau_a, double& vtau_b ) { 67 | 68 | double TAU_A, TAU_B, vrho_a_k, vrho_b_k, vsigma_aa_k, vsigma_bb_k, vlapl_a_k, vlapl_b_k, vtau_k, dummy; 69 | ke_traits::eval_exc_vxc_polar(rho_a, 0.0, sigma_aa, 0.0, 0.0, lapl_a, 0.0, 0.0, 0.0, TAU_A, vrho_a_k, dummy, vsigma_aa_k, dummy, dummy, vlapl_a_k, dummy, dummy, dummy); 70 | ke_traits::eval_exc_vxc_polar(rho_b, 0.0, sigma_bb, 0.0, 0.0, lapl_b, 0.0, 0.0, 0.0, TAU_B, vrho_b_k, dummy, vsigma_bb_k, dummy, dummy, vlapl_b_k, dummy, dummy, dummy); 71 | 72 | TAU_A *= rho_a; 73 | TAU_B *= rho_b; 74 | 75 | xc_traits::eval_exc_vxc_polar(rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, lapl_a, lapl_b, TAU_A, TAU_B, eps, vrho_a, vrho_b, vsigma_aa, vsigma_ab, vsigma_bb, vlapl_a, vlapl_b, vtau_a, vtau_b); 76 | 77 | vrho_a += vtau_a * vrho_a_k; 78 | vrho_b += vtau_b * vrho_b_k; 79 | vsigma_aa += vtau_a * vsigma_aa_k; 80 | //vsigma_ab += .....; 81 | vsigma_bb += vtau_b * vsigma_bb_k; 82 | vlapl_a = vtau_a * vlapl_a_k; 83 | vlapl_b = vtau_b * vlapl_b_k; 84 | vtau_a = 0.0; 85 | vtau_b = 0.0; 86 | } 87 | 88 | 89 | }; 90 | 91 | template 92 | struct Deorbitalized : detail::BuiltinKernelImpl< Deorbitalized > { 93 | 94 | Deorbitalized( Spin p ) : 95 | detail::BuiltinKernelImpl< Deorbitalized >(p) { } 96 | 97 | virtual ~Deorbitalized() = default; 98 | 99 | }; 100 | 101 | } 102 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/epc17_1.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | 13 | namespace ExchCXX { 14 | 15 | template <> 16 | struct kernel_traits< BuiltinEPC17_1 > : 17 | public lda_screening_interface< BuiltinEPC17_1 > { 18 | 19 | static constexpr bool is_lda = true; 20 | static constexpr bool is_gga = false; 21 | static constexpr bool is_mgga = false; 22 | static constexpr bool needs_laplacian = false; 23 | static constexpr bool is_kedf = false; 24 | static constexpr bool is_epc = true; 25 | 26 | static constexpr double dens_tol = 1e-24; 27 | static constexpr double zeta_tol = 1e-15; 28 | static constexpr double sigma_tol = 1.000000000000004e-32; 29 | static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20; 30 | 31 | static constexpr bool is_hyb = false; 32 | static constexpr double exx_coeff = 0.0; 33 | 34 | static constexpr double a = 2.35; 35 | static constexpr double b = 2.40; 36 | static constexpr double c = 3.20; 37 | 38 | BUILTIN_KERNEL_EVAL_RETURN 39 | eval_exc_unpolar_impl( double rho, double& eps ) { 40 | 41 | (void)(eps); 42 | 43 | 44 | const double t2 = rho / 0.2e1 <= dens_tol; 45 | const double t3 = 0.1e1 <= zeta_tol; 46 | const double t4 = zeta_tol - 0.1e1; 47 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 48 | const double t8 = square( 0.1e1 + t6 ); 49 | const double t9 = t8 * rho; 50 | const double t10 = rho * rho; 51 | const double t11 = t8 * t10; 52 | const double t12 = safe_math::sqrt( t11 ); 53 | const double t15 = c * t8; 54 | const double t18 = a - b * t12 / 0.2e1 + t15 * t10 / 0.4e1; 55 | const double t19 = 0.1e1 / t18; 56 | 57 | 58 | eps = piecewise_functor_3( t2, 0.0, -t9 * t19 / 0.4e1 ); 59 | 60 | } 61 | 62 | BUILTIN_KERNEL_EVAL_RETURN 63 | eval_exc_vxc_unpolar_impl( double rho, double& eps, double& vrho ) { 64 | 65 | 66 | 67 | const double t2 = rho / 0.2e1 <= dens_tol; 68 | const double t3 = 0.1e1 <= zeta_tol; 69 | const double t4 = zeta_tol - 0.1e1; 70 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 71 | const double t8 = square( 0.1e1 + t6 ); 72 | const double t9 = t8 * rho; 73 | const double t10 = rho * rho; 74 | const double t11 = t8 * t10; 75 | const double t12 = safe_math::sqrt( t11 ); 76 | const double t15 = c * t8; 77 | const double t18 = a - b * t12 / 0.2e1 + t15 * t10 / 0.4e1; 78 | const double t19 = 0.1e1 / t18; 79 | const double t23 = t18 * t18; 80 | const double t24 = 0.1e1 / t23; 81 | const double t26 = b / t12; 82 | const double t30 = t15 * rho / 0.2e1 - t26 * t9 / 0.2e1; 83 | const double t35 = piecewise_functor_3( t2, 0.0, t9 * t24 * t30 / 0.4e1 - t8 * t19 / 0.4e1 ); 84 | 85 | 86 | eps = piecewise_functor_3( t2, 0.0, -t9 * t19 / 0.4e1 ); 87 | vrho = rho * t35 + eps; 88 | 89 | } 90 | 91 | BUILTIN_KERNEL_EVAL_RETURN 92 | eval_exc_polar_impl( double rho_a, double rho_b, double& eps ) { 93 | 94 | (void)(eps); 95 | 96 | 97 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 98 | const double t4 = rho_a + rho_b; 99 | const double t5 = 0.1e1 / t4; 100 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 101 | const double t9 = zeta_tol - 0.1e1; 102 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 103 | const double t13 = -t9; 104 | const double t14 = rho_a - rho_b; 105 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 106 | const double t17 = 0.1e1 + t16; 107 | const double t18 = t17 * t4; 108 | const double t19 = -t14; 109 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 110 | const double t22 = 0.1e1 + t21; 111 | const double t23 = t4 * t4; 112 | const double t24 = t17 * t23; 113 | const double t25 = t24 * t22; 114 | const double t26 = safe_math::sqrt( t25 ); 115 | const double t29 = c * t17; 116 | const double t30 = t23 * t22; 117 | const double t33 = a - b * t26 / 0.2e1 + t29 * t30 / 0.4e1; 118 | const double t34 = 0.1e1 / t33; 119 | const double t35 = t22 * t34; 120 | 121 | 122 | eps = piecewise_functor_3( t3, 0.0, -t18 * t35 / 0.4e1 ); 123 | 124 | } 125 | 126 | BUILTIN_KERNEL_EVAL_RETURN 127 | eval_exc_vxc_polar_impl( double rho_a, double rho_b, double& eps, double& vrho_a, double& vrho_b ) { 128 | 129 | 130 | 131 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 132 | const double t4 = rho_a + rho_b; 133 | const double t5 = 0.1e1 / t4; 134 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 135 | const double t9 = zeta_tol - 0.1e1; 136 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 137 | const double t13 = -t9; 138 | const double t14 = rho_a - rho_b; 139 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 140 | const double t17 = 0.1e1 + t16; 141 | const double t18 = t17 * t4; 142 | const double t19 = -t14; 143 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 144 | const double t22 = 0.1e1 + t21; 145 | const double t23 = t4 * t4; 146 | const double t24 = t17 * t23; 147 | const double t25 = t24 * t22; 148 | const double t26 = safe_math::sqrt( t25 ); 149 | const double t29 = c * t17; 150 | const double t30 = t23 * t22; 151 | const double t33 = a - b * t26 / 0.2e1 + t29 * t30 / 0.4e1; 152 | const double t34 = 0.1e1 / t33; 153 | const double t35 = t22 * t34; 154 | const double t38 = 0.1e1 / t23; 155 | const double t39 = t14 * t38; 156 | const double t41 = piecewise_functor_5( t8, 0.0, t12, 0.0, t5 - t39 ); 157 | const double t42 = t41 * t4; 158 | const double t44 = t17 * t22; 159 | const double t45 = t44 * t34; 160 | const double t46 = t19 * t38; 161 | const double t48 = piecewise_functor_5( t12, 0.0, t8, 0.0, -t5 - t46 ); 162 | const double t49 = t48 * t34; 163 | const double t51 = t33 * t33; 164 | const double t52 = 0.1e1 / t51; 165 | const double t53 = t22 * t52; 166 | const double t55 = b / t26; 167 | const double t56 = t41 * t23; 168 | const double t58 = t18 * t22; 169 | const double t59 = 0.2e1 * t58; 170 | const double t61 = t56 * t22 + t24 * t48 + t59; 171 | const double t64 = c * t41; 172 | const double t67 = t4 * t22; 173 | const double t69 = t29 * t67 / 0.2e1; 174 | const double t70 = t23 * t48; 175 | const double t73 = -t55 * t61 / 0.4e1 + t64 * t30 / 0.4e1 + t69 + t29 * t70 / 0.4e1; 176 | const double t74 = t53 * t73; 177 | const double t78 = piecewise_functor_3( t3, 0.0, -t18 * t49 / 0.4e1 + t18 * t74 / 0.4e1 - t42 * t35 / 0.4e1 - t45 / 0.4e1 ); 178 | const double t81 = piecewise_functor_5( t8, 0.0, t12, 0.0, -t5 - t39 ); 179 | const double t82 = t81 * t4; 180 | const double t85 = piecewise_functor_5( t12, 0.0, t8, 0.0, t5 - t46 ); 181 | const double t86 = t85 * t34; 182 | const double t88 = t81 * t23; 183 | const double t91 = t88 * t22 + t24 * t85 + t59; 184 | const double t94 = c * t81; 185 | const double t97 = t23 * t85; 186 | const double t100 = -t55 * t91 / 0.4e1 + t94 * t30 / 0.4e1 + t69 + t29 * t97 / 0.4e1; 187 | const double t101 = t53 * t100; 188 | const double t105 = piecewise_functor_3( t3, 0.0, t18 * t101 / 0.4e1 - t18 * t86 / 0.4e1 - t82 * t35 / 0.4e1 - t45 / 0.4e1 ); 189 | 190 | 191 | eps = piecewise_functor_3( t3, 0.0, -t18 * t35 / 0.4e1 ); 192 | vrho_a = t4 * t78 + eps; 193 | vrho_b = t4 * t105 + eps; 194 | 195 | } 196 | 197 | 198 | }; 199 | 200 | struct BuiltinEPC17_1 : detail::BuiltinKernelImpl< BuiltinEPC17_1 > { 201 | 202 | BuiltinEPC17_1( Spin p ) : 203 | detail::BuiltinKernelImpl< BuiltinEPC17_1 >(p) { } 204 | 205 | virtual ~BuiltinEPC17_1() = default; 206 | 207 | }; 208 | 209 | 210 | 211 | } // namespace ExchCXX -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/epc17_2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | 13 | namespace ExchCXX { 14 | 15 | template <> 16 | struct kernel_traits< BuiltinEPC17_2 > : 17 | public lda_screening_interface< BuiltinEPC17_2 > { 18 | 19 | static constexpr bool is_lda = true; 20 | static constexpr bool is_gga = false; 21 | static constexpr bool is_mgga = false; 22 | static constexpr bool needs_laplacian = false; 23 | static constexpr bool is_kedf = false; 24 | static constexpr bool is_epc = true; 25 | 26 | static constexpr double dens_tol = 1e-24; 27 | static constexpr double zeta_tol = 1e-15; 28 | static constexpr double sigma_tol = 1.000000000000004e-32; 29 | static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20; 30 | 31 | static constexpr bool is_hyb = false; 32 | static constexpr double exx_coeff = 0.0; 33 | 34 | static constexpr double a = 2.35; 35 | static constexpr double b = 2.40; 36 | static constexpr double c = 6.60; 37 | 38 | BUILTIN_KERNEL_EVAL_RETURN 39 | eval_exc_unpolar_impl( double rho, double& eps ) { 40 | 41 | (void)(eps); 42 | 43 | 44 | const double t2 = rho / 0.2e1 <= dens_tol; 45 | const double t3 = 0.1e1 <= zeta_tol; 46 | const double t4 = zeta_tol - 0.1e1; 47 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 48 | const double t8 = square( 0.1e1 + t6 ); 49 | const double t9 = t8 * rho; 50 | const double t10 = rho * rho; 51 | const double t11 = t8 * t10; 52 | const double t12 = safe_math::sqrt( t11 ); 53 | const double t15 = c * t8; 54 | const double t18 = a - b * t12 / 0.2e1 + t15 * t10 / 0.4e1; 55 | const double t19 = 0.1e1 / t18; 56 | 57 | 58 | eps = piecewise_functor_3( t2, 0.0, -t9 * t19 / 0.4e1 ); 59 | 60 | } 61 | 62 | BUILTIN_KERNEL_EVAL_RETURN 63 | eval_exc_vxc_unpolar_impl( double rho, double& eps, double& vrho ) { 64 | 65 | 66 | 67 | const double t2 = rho / 0.2e1 <= dens_tol; 68 | const double t3 = 0.1e1 <= zeta_tol; 69 | const double t4 = zeta_tol - 0.1e1; 70 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 71 | const double t8 = square( 0.1e1 + t6 ); 72 | const double t9 = t8 * rho; 73 | const double t10 = rho * rho; 74 | const double t11 = t8 * t10; 75 | const double t12 = safe_math::sqrt( t11 ); 76 | const double t15 = c * t8; 77 | const double t18 = a - b * t12 / 0.2e1 + t15 * t10 / 0.4e1; 78 | const double t19 = 0.1e1 / t18; 79 | const double t23 = t18 * t18; 80 | const double t24 = 0.1e1 / t23; 81 | const double t26 = b / t12; 82 | const double t30 = t15 * rho / 0.2e1 - t26 * t9 / 0.2e1; 83 | const double t35 = piecewise_functor_3( t2, 0.0, t9 * t24 * t30 / 0.4e1 - t8 * t19 / 0.4e1 ); 84 | 85 | 86 | eps = piecewise_functor_3( t2, 0.0, -t9 * t19 / 0.4e1 ); 87 | vrho = rho * t35 + eps; 88 | 89 | } 90 | 91 | BUILTIN_KERNEL_EVAL_RETURN 92 | eval_exc_polar_impl( double rho_a, double rho_b, double& eps ) { 93 | 94 | (void)(eps); 95 | 96 | 97 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 98 | const double t4 = rho_a + rho_b; 99 | const double t5 = 0.1e1 / t4; 100 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 101 | const double t9 = zeta_tol - 0.1e1; 102 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 103 | const double t13 = -t9; 104 | const double t14 = rho_a - rho_b; 105 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 106 | const double t17 = 0.1e1 + t16; 107 | const double t18 = t17 * t4; 108 | const double t19 = -t14; 109 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 110 | const double t22 = 0.1e1 + t21; 111 | const double t23 = t4 * t4; 112 | const double t24 = t17 * t23; 113 | const double t25 = t24 * t22; 114 | const double t26 = safe_math::sqrt( t25 ); 115 | const double t29 = c * t17; 116 | const double t30 = t23 * t22; 117 | const double t33 = a - b * t26 / 0.2e1 + t29 * t30 / 0.4e1; 118 | const double t34 = 0.1e1 / t33; 119 | const double t35 = t22 * t34; 120 | 121 | 122 | eps = piecewise_functor_3( t3, 0.0, -t18 * t35 / 0.4e1 ); 123 | 124 | } 125 | 126 | BUILTIN_KERNEL_EVAL_RETURN 127 | eval_exc_vxc_polar_impl( double rho_a, double rho_b, double& eps, double& vrho_a, double& vrho_b ) { 128 | 129 | 130 | 131 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 132 | const double t4 = rho_a + rho_b; 133 | const double t5 = 0.1e1 / t4; 134 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 135 | const double t9 = zeta_tol - 0.1e1; 136 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 137 | const double t13 = -t9; 138 | const double t14 = rho_a - rho_b; 139 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 140 | const double t17 = 0.1e1 + t16; 141 | const double t18 = t17 * t4; 142 | const double t19 = -t14; 143 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 144 | const double t22 = 0.1e1 + t21; 145 | const double t23 = t4 * t4; 146 | const double t24 = t17 * t23; 147 | const double t25 = t24 * t22; 148 | const double t26 = safe_math::sqrt( t25 ); 149 | const double t29 = c * t17; 150 | const double t30 = t23 * t22; 151 | const double t33 = a - b * t26 / 0.2e1 + t29 * t30 / 0.4e1; 152 | const double t34 = 0.1e1 / t33; 153 | const double t35 = t22 * t34; 154 | const double t38 = 0.1e1 / t23; 155 | const double t39 = t14 * t38; 156 | const double t41 = piecewise_functor_5( t8, 0.0, t12, 0.0, t5 - t39 ); 157 | const double t42 = t41 * t4; 158 | const double t44 = t17 * t22; 159 | const double t45 = t44 * t34; 160 | const double t46 = t19 * t38; 161 | const double t48 = piecewise_functor_5( t12, 0.0, t8, 0.0, -t5 - t46 ); 162 | const double t49 = t48 * t34; 163 | const double t51 = t33 * t33; 164 | const double t52 = 0.1e1 / t51; 165 | const double t53 = t22 * t52; 166 | const double t55 = b / t26; 167 | const double t56 = t41 * t23; 168 | const double t58 = t18 * t22; 169 | const double t59 = 0.2e1 * t58; 170 | const double t61 = t56 * t22 + t24 * t48 + t59; 171 | const double t64 = c * t41; 172 | const double t67 = t4 * t22; 173 | const double t69 = t29 * t67 / 0.2e1; 174 | const double t70 = t23 * t48; 175 | const double t73 = -t55 * t61 / 0.4e1 + t64 * t30 / 0.4e1 + t69 + t29 * t70 / 0.4e1; 176 | const double t74 = t53 * t73; 177 | const double t78 = piecewise_functor_3( t3, 0.0, -t18 * t49 / 0.4e1 + t18 * t74 / 0.4e1 - t42 * t35 / 0.4e1 - t45 / 0.4e1 ); 178 | const double t81 = piecewise_functor_5( t8, 0.0, t12, 0.0, -t5 - t39 ); 179 | const double t82 = t81 * t4; 180 | const double t85 = piecewise_functor_5( t12, 0.0, t8, 0.0, t5 - t46 ); 181 | const double t86 = t85 * t34; 182 | const double t88 = t81 * t23; 183 | const double t91 = t88 * t22 + t24 * t85 + t59; 184 | const double t94 = c * t81; 185 | const double t97 = t23 * t85; 186 | const double t100 = -t55 * t91 / 0.4e1 + t94 * t30 / 0.4e1 + t69 + t29 * t97 / 0.4e1; 187 | const double t101 = t53 * t100; 188 | const double t105 = piecewise_functor_3( t3, 0.0, t18 * t101 / 0.4e1 - t18 * t86 / 0.4e1 - t82 * t35 / 0.4e1 - t45 / 0.4e1 ); 189 | 190 | 191 | eps = piecewise_functor_3( t3, 0.0, -t18 * t35 / 0.4e1 ); 192 | vrho_a = t4 * t78 + eps; 193 | vrho_b = t4 * t105 + eps; 194 | 195 | } 196 | 197 | 198 | }; 199 | 200 | struct BuiltinEPC17_2 : detail::BuiltinKernelImpl< BuiltinEPC17_2 > { 201 | 202 | BuiltinEPC17_2( Spin p ) : 203 | detail::BuiltinKernelImpl< BuiltinEPC17_2 >(p) { } 204 | 205 | virtual ~BuiltinEPC17_2() = default; 206 | 207 | }; 208 | 209 | 210 | 211 | } // namespace ExchCXX -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/epc18_1.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | 13 | namespace ExchCXX { 14 | 15 | template <> 16 | struct kernel_traits< BuiltinEPC18_1 > : 17 | public lda_screening_interface< BuiltinEPC18_1 > { 18 | 19 | static constexpr bool is_lda = true; 20 | static constexpr bool is_gga = false; 21 | static constexpr bool is_mgga = false; 22 | static constexpr bool needs_laplacian = false; 23 | static constexpr bool is_kedf = false; 24 | static constexpr bool is_epc = true; 25 | 26 | static constexpr double dens_tol = 1e-24; 27 | static constexpr double zeta_tol = 1e-15; 28 | static constexpr double sigma_tol = 1.000000000000004e-32; 29 | static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20; 30 | 31 | static constexpr bool is_hyb = false; 32 | static constexpr double exx_coeff = 0.0; 33 | 34 | static constexpr double a = 1.80; 35 | static constexpr double b = 0.10; 36 | static constexpr double c = 0.03; 37 | 38 | BUILTIN_KERNEL_EVAL_RETURN 39 | eval_exc_unpolar_impl( double rho, double& eps ) { 40 | 41 | (void)(eps); 42 | 43 | 44 | const double t2 = rho / 0.2e1 <= dens_tol; 45 | const double t3 = 0.1e1 <= zeta_tol; 46 | const double t4 = zeta_tol - 0.1e1; 47 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 48 | const double t7 = 0.1e1 + t6; 49 | const double t8 = t7 * t7; 50 | const double t9 = t8 * rho; 51 | const double t10 = b * t7; 52 | const double t13 = c * t8; 53 | const double t14 = rho * rho; 54 | const double t17 = -0.4e1 * t10 * rho + 0.16e2 * t13 * t14 + a; 55 | const double t18 = 0.1e1 / t17; 56 | 57 | 58 | eps = piecewise_functor_3( t2, 0.0, -t9 * t18 / 0.4e1 ); 59 | 60 | } 61 | 62 | BUILTIN_KERNEL_EVAL_RETURN 63 | eval_exc_vxc_unpolar_impl( double rho, double& eps, double& vrho ) { 64 | 65 | 66 | 67 | const double t2 = rho / 0.2e1 <= dens_tol; 68 | const double t3 = 0.1e1 <= zeta_tol; 69 | const double t4 = zeta_tol - 0.1e1; 70 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 71 | const double t7 = 0.1e1 + t6; 72 | const double t8 = t7 * t7; 73 | const double t9 = t8 * rho; 74 | const double t10 = b * t7; 75 | const double t13 = c * t8; 76 | const double t14 = rho * rho; 77 | const double t17 = -0.4e1 * t10 * rho + 0.16e2 * t13 * t14 + a; 78 | const double t18 = 0.1e1 / t17; 79 | const double t22 = t17 * t17; 80 | const double t23 = 0.1e1 / t22; 81 | const double t27 = 0.32e2 * t13 * rho - 0.4e1 * t10; 82 | const double t32 = piecewise_functor_3( t2, 0.0, t9 * t23 * t27 / 0.4e1 - t8 * t18 / 0.4e1 ); 83 | 84 | 85 | eps = piecewise_functor_3( t2, 0.0, -t9 * t18 / 0.4e1 ); 86 | vrho = rho * t32 + eps; 87 | 88 | } 89 | 90 | BUILTIN_KERNEL_EVAL_RETURN 91 | eval_exc_polar_impl( double rho_a, double rho_b, double& eps ) { 92 | 93 | (void)(eps); 94 | constexpr double t23 = constants::m_cbrt_2; 95 | constexpr double t24 = t23 * t23; 96 | 97 | 98 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 99 | const double t4 = rho_a + rho_b; 100 | const double t5 = 0.1e1 / t4; 101 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 102 | const double t9 = zeta_tol - 0.1e1; 103 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 104 | const double t13 = -t9; 105 | const double t14 = rho_a - rho_b; 106 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 107 | const double t17 = 0.1e1 + t16; 108 | const double t18 = t17 * t4; 109 | const double t19 = -t14; 110 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 111 | const double t22 = 0.1e1 + t21; 112 | const double t25 = safe_math::cbrt( t18 ); 113 | const double t27 = t22 * t4; 114 | const double t28 = safe_math::cbrt( t27 ); 115 | const double t31 = t24 * t25 / 0.2e1 + t24 * t28 / 0.2e1; 116 | const double t32 = t31 * t31; 117 | const double t33 = t32 * t31; 118 | const double t35 = t32 * t32; 119 | const double t38 = c * t35 * t32 - b * t33 + a; 120 | const double t39 = 0.1e1 / t38; 121 | const double t40 = t22 * t39; 122 | 123 | 124 | eps = piecewise_functor_3( t3, 0.0, -t18 * t40 / 0.4e1 ); 125 | 126 | } 127 | 128 | BUILTIN_KERNEL_EVAL_RETURN 129 | eval_exc_vxc_polar_impl( double rho_a, double rho_b, double& eps, double& vrho_a, double& vrho_b ) { 130 | 131 | constexpr double t23 = constants::m_cbrt_2; 132 | constexpr double t24 = t23 * t23; 133 | 134 | 135 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 136 | const double t4 = rho_a + rho_b; 137 | const double t5 = 0.1e1 / t4; 138 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 139 | const double t9 = zeta_tol - 0.1e1; 140 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 141 | const double t13 = -t9; 142 | const double t14 = rho_a - rho_b; 143 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 144 | const double t17 = 0.1e1 + t16; 145 | const double t18 = t17 * t4; 146 | const double t19 = -t14; 147 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 148 | const double t22 = 0.1e1 + t21; 149 | const double t25 = safe_math::cbrt( t18 ); 150 | const double t27 = t22 * t4; 151 | const double t28 = safe_math::cbrt( t27 ); 152 | const double t31 = t24 * t25 / 0.2e1 + t24 * t28 / 0.2e1; 153 | const double t32 = t31 * t31; 154 | const double t33 = t32 * t31; 155 | const double t35 = t32 * t32; 156 | const double t38 = c * t35 * t32 - b * t33 + a; 157 | const double t39 = 0.1e1 / t38; 158 | const double t40 = t22 * t39; 159 | const double t43 = t4 * t4; 160 | const double t44 = 0.1e1 / t43; 161 | const double t45 = t14 * t44; 162 | const double t47 = piecewise_functor_5( t8, 0.0, t12, 0.0, t5 - t45 ); 163 | const double t48 = t47 * t4; 164 | const double t50 = t17 * t22; 165 | const double t51 = t50 * t39; 166 | const double t52 = t19 * t44; 167 | const double t54 = piecewise_functor_5( t12, 0.0, t8, 0.0, -t5 - t52 ); 168 | const double t55 = t54 * t39; 169 | const double t57 = t38 * t38; 170 | const double t58 = 0.1e1 / t57; 171 | const double t59 = t22 * t58; 172 | const double t60 = b * t32; 173 | const double t61 = t25 * t25; 174 | const double t63 = t24 / t61; 175 | const double t64 = t48 + 0.1e1 + t16; 176 | const double t66 = t28 * t28; 177 | const double t68 = t24 / t66; 178 | const double t70 = t54 * t4 + t21 + 0.1e1; 179 | const double t73 = t63 * t64 / 0.6e1 + t68 * t70 / 0.6e1; 180 | const double t77 = c * t35 * t31; 181 | const double t80 = -0.3e1 * t60 * t73 + 0.6e1 * t77 * t73; 182 | const double t81 = t59 * t80; 183 | const double t85 = piecewise_functor_3( t3, 0.0, -t18 * t55 / 0.4e1 + t18 * t81 / 0.4e1 - t48 * t40 / 0.4e1 - t51 / 0.4e1 ); 184 | const double t88 = piecewise_functor_5( t8, 0.0, t12, 0.0, -t5 - t45 ); 185 | const double t89 = t88 * t4; 186 | const double t92 = piecewise_functor_5( t12, 0.0, t8, 0.0, t5 - t52 ); 187 | const double t93 = t92 * t39; 188 | const double t95 = t89 + 0.1e1 + t16; 189 | const double t98 = t92 * t4 + t21 + 0.1e1; 190 | const double t101 = t63 * t95 / 0.6e1 + t68 * t98 / 0.6e1; 191 | const double t106 = -0.3e1 * t60 * t101 + 0.6e1 * t77 * t101; 192 | const double t107 = t59 * t106; 193 | const double t111 = piecewise_functor_3( t3, 0.0, t18 * t107 / 0.4e1 - t18 * t93 / 0.4e1 - t89 * t40 / 0.4e1 - t51 / 0.4e1 ); 194 | 195 | 196 | eps = piecewise_functor_3( t3, 0.0, -t18 * t40 / 0.4e1 ); 197 | vrho_a = t4 * t85 + eps; 198 | vrho_b = t4 * t111 + eps; 199 | 200 | } 201 | 202 | 203 | }; 204 | 205 | struct BuiltinEPC18_1 : detail::BuiltinKernelImpl< BuiltinEPC18_1 > { 206 | 207 | BuiltinEPC18_1( Spin p ) : 208 | detail::BuiltinKernelImpl< BuiltinEPC18_1 >(p) { } 209 | 210 | virtual ~BuiltinEPC18_1() = default; 211 | 212 | }; 213 | 214 | 215 | 216 | } // namespace ExchCXX -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/epc18_2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | 13 | namespace ExchCXX { 14 | 15 | template <> 16 | struct kernel_traits< BuiltinEPC18_2 > : 17 | public lda_screening_interface< BuiltinEPC18_2 > { 18 | 19 | static constexpr bool is_lda = true; 20 | static constexpr bool is_gga = false; 21 | static constexpr bool is_mgga = false; 22 | static constexpr bool needs_laplacian = false; 23 | static constexpr bool is_kedf = false; 24 | static constexpr bool is_epc = true; 25 | 26 | static constexpr double dens_tol = 1e-24; 27 | static constexpr double zeta_tol = 1e-15; 28 | static constexpr double sigma_tol = 1.000000000000004e-32; 29 | static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20; 30 | 31 | static constexpr bool is_hyb = false; 32 | static constexpr double exx_coeff = 0.0; 33 | 34 | static constexpr double a = 3.90; 35 | static constexpr double b = 0.50; 36 | static constexpr double c = 0.06; 37 | 38 | BUILTIN_KERNEL_EVAL_RETURN 39 | eval_exc_unpolar_impl( double rho, double& eps ) { 40 | 41 | (void)(eps); 42 | 43 | 44 | const double t2 = rho / 0.2e1 <= dens_tol; 45 | const double t3 = 0.1e1 <= zeta_tol; 46 | const double t4 = zeta_tol - 0.1e1; 47 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 48 | const double t7 = 0.1e1 + t6; 49 | const double t8 = t7 * t7; 50 | const double t9 = t8 * rho; 51 | const double t10 = b * t7; 52 | const double t13 = c * t8; 53 | const double t14 = rho * rho; 54 | const double t17 = -0.4e1 * t10 * rho + 0.16e2 * t13 * t14 + a; 55 | const double t18 = 0.1e1 / t17; 56 | 57 | 58 | eps = piecewise_functor_3( t2, 0.0, -t9 * t18 / 0.4e1 ); 59 | 60 | } 61 | 62 | BUILTIN_KERNEL_EVAL_RETURN 63 | eval_exc_vxc_unpolar_impl( double rho, double& eps, double& vrho ) { 64 | 65 | 66 | 67 | const double t2 = rho / 0.2e1 <= dens_tol; 68 | const double t3 = 0.1e1 <= zeta_tol; 69 | const double t4 = zeta_tol - 0.1e1; 70 | const double t6 = piecewise_functor_5( t3, t4, t3, -t4, 0.0 ); 71 | const double t7 = 0.1e1 + t6; 72 | const double t8 = t7 * t7; 73 | const double t9 = t8 * rho; 74 | const double t10 = b * t7; 75 | const double t13 = c * t8; 76 | const double t14 = rho * rho; 77 | const double t17 = -0.4e1 * t10 * rho + 0.16e2 * t13 * t14 + a; 78 | const double t18 = 0.1e1 / t17; 79 | const double t22 = t17 * t17; 80 | const double t23 = 0.1e1 / t22; 81 | const double t27 = 0.32e2 * t13 * rho - 0.4e1 * t10; 82 | const double t32 = piecewise_functor_3( t2, 0.0, t9 * t23 * t27 / 0.4e1 - t8 * t18 / 0.4e1 ); 83 | 84 | 85 | eps = piecewise_functor_3( t2, 0.0, -t9 * t18 / 0.4e1 ); 86 | vrho = rho * t32 + eps; 87 | 88 | } 89 | 90 | BUILTIN_KERNEL_EVAL_RETURN 91 | eval_exc_polar_impl( double rho_a, double rho_b, double& eps ) { 92 | 93 | (void)(eps); 94 | constexpr double t23 = constants::m_cbrt_2; 95 | constexpr double t24 = t23 * t23; 96 | 97 | 98 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 99 | const double t4 = rho_a + rho_b; 100 | const double t5 = 0.1e1 / t4; 101 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 102 | const double t9 = zeta_tol - 0.1e1; 103 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 104 | const double t13 = -t9; 105 | const double t14 = rho_a - rho_b; 106 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 107 | const double t17 = 0.1e1 + t16; 108 | const double t18 = t17 * t4; 109 | const double t19 = -t14; 110 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 111 | const double t22 = 0.1e1 + t21; 112 | const double t25 = safe_math::cbrt( t18 ); 113 | const double t27 = t22 * t4; 114 | const double t28 = safe_math::cbrt( t27 ); 115 | const double t31 = t24 * t25 / 0.2e1 + t24 * t28 / 0.2e1; 116 | const double t32 = t31 * t31; 117 | const double t33 = t32 * t31; 118 | const double t35 = t32 * t32; 119 | const double t38 = c * t35 * t32 - b * t33 + a; 120 | const double t39 = 0.1e1 / t38; 121 | const double t40 = t22 * t39; 122 | 123 | 124 | eps = piecewise_functor_3( t3, 0.0, -t18 * t40 / 0.4e1 ); 125 | 126 | } 127 | 128 | BUILTIN_KERNEL_EVAL_RETURN 129 | eval_exc_vxc_polar_impl( double rho_a, double rho_b, double& eps, double& vrho_a, double& vrho_b ) { 130 | 131 | constexpr double t23 = constants::m_cbrt_2; 132 | constexpr double t24 = t23 * t23; 133 | 134 | 135 | const double t3 = rho_a <= dens_tol && rho_b <= dens_tol; 136 | const double t4 = rho_a + rho_b; 137 | const double t5 = 0.1e1 / t4; 138 | const double t8 = 0.2e1 * rho_a * t5 <= zeta_tol; 139 | const double t9 = zeta_tol - 0.1e1; 140 | const double t12 = 0.2e1 * rho_b * t5 <= zeta_tol; 141 | const double t13 = -t9; 142 | const double t14 = rho_a - rho_b; 143 | const double t16 = piecewise_functor_5( t8, t9, t12, t13, t14 * t5 ); 144 | const double t17 = 0.1e1 + t16; 145 | const double t18 = t17 * t4; 146 | const double t19 = -t14; 147 | const double t21 = piecewise_functor_5( t12, t9, t8, t13, t19 * t5 ); 148 | const double t22 = 0.1e1 + t21; 149 | const double t25 = safe_math::cbrt( t18 ); 150 | const double t27 = t22 * t4; 151 | const double t28 = safe_math::cbrt( t27 ); 152 | const double t31 = t24 * t25 / 0.2e1 + t24 * t28 / 0.2e1; 153 | const double t32 = t31 * t31; 154 | const double t33 = t32 * t31; 155 | const double t35 = t32 * t32; 156 | const double t38 = c * t35 * t32 - b * t33 + a; 157 | const double t39 = 0.1e1 / t38; 158 | const double t40 = t22 * t39; 159 | const double t43 = t4 * t4; 160 | const double t44 = 0.1e1 / t43; 161 | const double t45 = t14 * t44; 162 | const double t47 = piecewise_functor_5( t8, 0.0, t12, 0.0, t5 - t45 ); 163 | const double t48 = t47 * t4; 164 | const double t50 = t17 * t22; 165 | const double t51 = t50 * t39; 166 | const double t52 = t19 * t44; 167 | const double t54 = piecewise_functor_5( t12, 0.0, t8, 0.0, -t5 - t52 ); 168 | const double t55 = t54 * t39; 169 | const double t57 = t38 * t38; 170 | const double t58 = 0.1e1 / t57; 171 | const double t59 = t22 * t58; 172 | const double t60 = b * t32; 173 | const double t61 = t25 * t25; 174 | const double t63 = t24 / t61; 175 | const double t64 = t48 + 0.1e1 + t16; 176 | const double t66 = t28 * t28; 177 | const double t68 = t24 / t66; 178 | const double t70 = t54 * t4 + t21 + 0.1e1; 179 | const double t73 = t63 * t64 / 0.6e1 + t68 * t70 / 0.6e1; 180 | const double t77 = c * t35 * t31; 181 | const double t80 = -0.3e1 * t60 * t73 + 0.6e1 * t77 * t73; 182 | const double t81 = t59 * t80; 183 | const double t85 = piecewise_functor_3( t3, 0.0, -t18 * t55 / 0.4e1 + t18 * t81 / 0.4e1 - t48 * t40 / 0.4e1 - t51 / 0.4e1 ); 184 | const double t88 = piecewise_functor_5( t8, 0.0, t12, 0.0, -t5 - t45 ); 185 | const double t89 = t88 * t4; 186 | const double t92 = piecewise_functor_5( t12, 0.0, t8, 0.0, t5 - t52 ); 187 | const double t93 = t92 * t39; 188 | const double t95 = t89 + 0.1e1 + t16; 189 | const double t98 = t92 * t4 + t21 + 0.1e1; 190 | const double t101 = t63 * t95 / 0.6e1 + t68 * t98 / 0.6e1; 191 | const double t106 = -0.3e1 * t60 * t101 + 0.6e1 * t77 * t101; 192 | const double t107 = t59 * t106; 193 | const double t111 = piecewise_functor_3( t3, 0.0, t18 * t107 / 0.4e1 - t18 * t93 / 0.4e1 - t89 * t40 / 0.4e1 - t51 / 0.4e1 ); 194 | 195 | 196 | eps = piecewise_functor_3( t3, 0.0, -t18 * t40 / 0.4e1 ); 197 | vrho_a = t4 * t85 + eps; 198 | vrho_b = t4 * t111 + eps; 199 | 200 | } 201 | 202 | 203 | }; 204 | 205 | struct BuiltinEPC18_2 : detail::BuiltinKernelImpl< BuiltinEPC18_2 > { 206 | 207 | BuiltinEPC18_2( Spin p ) : 208 | detail::BuiltinKernelImpl< BuiltinEPC18_2 >(p) { } 209 | 210 | virtual ~BuiltinEPC18_2() = default; 211 | 212 | }; 213 | 214 | 215 | 216 | } // namespace ExchCXX -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/pbe0.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace ExchCXX { 13 | 14 | template <> 15 | struct kernel_traits { 16 | 17 | using pbe_x_traits = kernel_traits; 18 | using pbe_c_traits = kernel_traits; 19 | 20 | static constexpr bool is_hyb = true; 21 | static constexpr bool is_lda = false; 22 | static constexpr bool is_gga = true; 23 | static constexpr bool is_mgga = false; 24 | static constexpr double exx_coeff = 0.25; 25 | static constexpr bool is_epc = false; 26 | 27 | 28 | BUILTIN_KERNEL_EVAL_RETURN 29 | eval_exc_unpolar( double rho, double sigma, double& eps ) { 30 | 31 | pbe_x_traits::eval_exc_unpolar( rho, sigma, eps ); 32 | double eps_x = eps; 33 | 34 | pbe_c_traits::eval_exc_unpolar( rho, sigma, eps ); 35 | 36 | eps = (1. - exx_coeff) * eps_x + eps; 37 | 38 | } 39 | 40 | BUILTIN_KERNEL_EVAL_RETURN 41 | eval_exc_polar( double rho_a, double rho_b, double sigma_aa, 42 | double sigma_ab, double sigma_bb, double& eps ) { 43 | 44 | pbe_x_traits::eval_exc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, eps ); 45 | double eps_x = eps; 46 | 47 | pbe_c_traits::eval_exc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, eps ); 48 | 49 | eps = (1. - exx_coeff) * eps_x + eps; 50 | 51 | } 52 | 53 | BUILTIN_KERNEL_EVAL_RETURN 54 | eval_exc_vxc_unpolar( double rho, double sigma, double& eps, double& vrho, 55 | double& vsigma ) { 56 | 57 | pbe_x_traits::eval_exc_vxc_unpolar( rho, sigma, eps, vrho, vsigma ); 58 | double eps_x = eps; 59 | double vrho_x = vrho; 60 | double vsigma_x = vsigma; 61 | 62 | 63 | pbe_c_traits::eval_exc_vxc_unpolar( rho, sigma, eps, vrho, vsigma ); 64 | 65 | eps = (1. - exx_coeff) * eps_x + eps; 66 | vrho = (1. - exx_coeff) * vrho_x + vrho; 67 | vsigma = (1. - exx_coeff) * vsigma_x + vsigma; 68 | 69 | } 70 | 71 | BUILTIN_KERNEL_EVAL_RETURN 72 | eval_exc_vxc_polar( double rho_a, double rho_b, double sigma_aa, 73 | double sigma_ab, double sigma_bb, double& eps, double& vrho_a, 74 | double& vrho_b, double& vsigma_aa, double& vsigma_ab, double& vsigma_bb ) { 75 | 76 | pbe_x_traits::eval_exc_vxc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, 77 | eps, vrho_a, vrho_b, vsigma_aa, vsigma_ab, vsigma_bb ); 78 | double eps_x = eps; 79 | double vrho_x_a = vrho_a; 80 | double vrho_x_b = vrho_b; 81 | double vsigma_x_aa = vsigma_aa; 82 | double vsigma_x_ab = vsigma_ab; 83 | double vsigma_x_bb = vsigma_bb; 84 | 85 | 86 | pbe_c_traits::eval_exc_vxc_polar( rho_a, rho_b, sigma_aa, sigma_ab, sigma_bb, 87 | eps, vrho_a, vrho_b, vsigma_aa, vsigma_ab, vsigma_bb ); 88 | 89 | eps = (1. - exx_coeff) * eps_x + eps; 90 | vrho_a = (1. - exx_coeff) * vrho_x_a + vrho_a; 91 | vrho_b = (1. - exx_coeff) * vrho_x_b + vrho_b; 92 | vsigma_aa = (1. - exx_coeff) * vsigma_x_aa + vsigma_aa; 93 | vsigma_ab = (1. - exx_coeff) * vsigma_x_ab + vsigma_ab; 94 | vsigma_bb = (1. - exx_coeff) * vsigma_x_bb + vsigma_bb; 95 | 96 | } 97 | 98 | }; 99 | 100 | 101 | 102 | 103 | 104 | 105 | struct BuiltinPBE0 : detail::BuiltinKernelImpl< BuiltinPBE0 > { 106 | 107 | BuiltinPBE0( Spin p ) : 108 | detail::BuiltinKernelImpl< BuiltinPBE0 >(p) { } 109 | 110 | virtual ~BuiltinPBE0() = default; 111 | 112 | }; 113 | 114 | } 115 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/r2scanl_c.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace ExchCXX { 10 | 11 | 12 | template <> 13 | struct kernel_traits : 14 | public kernel_traits> { 15 | 16 | static constexpr double dens_tol = 1e-15; 17 | static constexpr double zeta_tol = 1e-15; 18 | static constexpr double sigma_tol = 1.0000000000000027e-20; 19 | static constexpr double tau_tol = 1e-20; 20 | 21 | }; 22 | 23 | struct BuiltinR2SCANL_C : detail::BuiltinKernelImpl< BuiltinR2SCANL_C > { 24 | 25 | BuiltinR2SCANL_C( Spin p ) : 26 | detail::BuiltinKernelImpl< BuiltinR2SCANL_C >(p) { } 27 | 28 | virtual ~BuiltinR2SCANL_C() = default; 29 | 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/r2scanl_x.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace ExchCXX { 10 | 11 | 12 | template <> 13 | struct kernel_traits : 14 | public kernel_traits> { 15 | 16 | static constexpr double dens_tol = 1e-15; 17 | static constexpr double zeta_tol = 1e-15; 18 | static constexpr double sigma_tol = 1.0000000000000027e-20; 19 | static constexpr double tau_tol = 1e-20; 20 | 21 | }; 22 | 23 | struct BuiltinR2SCANL_X : detail::BuiltinKernelImpl< BuiltinR2SCANL_X > { 24 | 25 | BuiltinR2SCANL_X( Spin p ) : 26 | detail::BuiltinKernelImpl< BuiltinR2SCANL_X >(p) { } 27 | 28 | virtual ~BuiltinR2SCANL_X() = default; 29 | 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/scanl_c.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace ExchCXX { 10 | 11 | 12 | template <> 13 | struct kernel_traits : 14 | public kernel_traits> { 15 | 16 | static constexpr double dens_tol = 1e-15; 17 | static constexpr double zeta_tol = 1e-15; 18 | static constexpr double sigma_tol = 1.0000000000000027e-20; 19 | static constexpr double tau_tol = 1e-20; 20 | 21 | }; 22 | 23 | struct BuiltinSCANL_C : detail::BuiltinKernelImpl< BuiltinSCANL_C > { 24 | 25 | BuiltinSCANL_C( Spin p ) : 26 | detail::BuiltinKernelImpl< BuiltinSCANL_C >(p) { } 27 | 28 | virtual ~BuiltinSCANL_C() = default; 29 | 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/scanl_x.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | namespace ExchCXX { 10 | 11 | 12 | template <> 13 | struct kernel_traits : 14 | public kernel_traits> { 15 | 16 | static constexpr double dens_tol = 1e-15; 17 | static constexpr double zeta_tol = 1e-15; 18 | static constexpr double sigma_tol = 1.0000000000000027e-20; 19 | static constexpr double tau_tol = 1e-20; 20 | 21 | }; 22 | 23 | struct BuiltinSCANL_X : detail::BuiltinKernelImpl< BuiltinSCANL_X > { 24 | 25 | BuiltinSCANL_X( Spin p ) : 26 | detail::BuiltinKernelImpl< BuiltinSCANL_X >(p) { } 27 | 28 | virtual ~BuiltinSCANL_X() = default; 29 | 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/kernels/slater_exchange.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | 12 | 13 | namespace ExchCXX { 14 | 15 | template <> 16 | struct kernel_traits< BuiltinSlaterExchange > : 17 | public lda_screening_interface< BuiltinSlaterExchange > { 18 | 19 | static constexpr bool is_lda = true; 20 | static constexpr bool is_gga = false; 21 | static constexpr bool is_mgga = false; 22 | static constexpr bool needs_laplacian = false; 23 | static constexpr bool is_kedf = false; 24 | static constexpr bool is_epc = false; 25 | 26 | static constexpr double dens_tol = 1e-24; 27 | static constexpr double zeta_tol = 1e-15; 28 | static constexpr double sigma_tol = 1.000000000000004e-32; 29 | static constexpr double tau_tol = is_kedf ? 0.0 : 1e-20; 30 | 31 | static constexpr bool is_hyb = false; 32 | static constexpr double exx_coeff = 0.0; 33 | 34 | static constexpr double alpha = 1.0; 35 | 36 | BUILTIN_KERNEL_EVAL_RETURN 37 | eval_exc_unpolar_impl( double rho, double& eps ) { 38 | 39 | (void)(eps); 40 | constexpr double t3 = constants::m_cbrt_3; 41 | constexpr double t4 = constants::m_cbrt_pi; 42 | constexpr double t6 = t3 / t4; 43 | 44 | 45 | const double t2 = rho / 0.2e1 <= dens_tol; 46 | const double t8 = safe_math::cbrt( zeta_tol ); 47 | const double t10 = piecewise_functor_3( 0.1e1 <= zeta_tol, t8 * zeta_tol, 1.0 ); 48 | const double t11 = safe_math::cbrt( rho ); 49 | const double t15 = piecewise_functor_3( t2, 0.0, -0.3e1 / 0.8e1 * t6 * t10 * t11 ); 50 | const double t16 = alpha * t15; 51 | 52 | 53 | eps = 0.2e1 * t16; 54 | 55 | } 56 | 57 | BUILTIN_KERNEL_EVAL_RETURN 58 | eval_exc_vxc_unpolar_impl( double rho, double& eps, double& vrho ) { 59 | 60 | (void)(eps); 61 | constexpr double t3 = constants::m_cbrt_3; 62 | constexpr double t4 = constants::m_cbrt_pi; 63 | constexpr double t6 = t3 / t4; 64 | 65 | 66 | const double t2 = rho / 0.2e1 <= dens_tol; 67 | const double t8 = safe_math::cbrt( zeta_tol ); 68 | const double t10 = piecewise_functor_3( 0.1e1 <= zeta_tol, t8 * zeta_tol, 1.0 ); 69 | const double t11 = safe_math::cbrt( rho ); 70 | const double t15 = piecewise_functor_3( t2, 0.0, -0.3e1 / 0.8e1 * t6 * t10 * t11 ); 71 | const double t16 = alpha * t15; 72 | const double t17 = rho * alpha; 73 | const double t18 = t11 * t11; 74 | const double t23 = piecewise_functor_3( t2, 0.0, -t6 * t10 / t18 / 0.8e1 ); 75 | 76 | 77 | eps = 0.2e1 * t16; 78 | vrho = 0.2e1 * t17 * t23 + 0.2e1 * t16; 79 | 80 | } 81 | 82 | BUILTIN_KERNEL_EVAL_RETURN 83 | eval_exc_polar_impl( double rho_a, double rho_b, double& eps ) { 84 | 85 | (void)(eps); 86 | constexpr double t2 = constants::m_cbrt_3; 87 | constexpr double t3 = constants::m_cbrt_pi; 88 | constexpr double t13 = constants::m_cbrt_2; 89 | constexpr double t5 = t2 / t3; 90 | 91 | 92 | const double t1 = rho_a <= dens_tol; 93 | const double t6 = rho_a + rho_b; 94 | const double t7 = 0.1e1 / t6; 95 | const double t8 = rho_a * t7; 96 | const double t10 = 0.2e1 * t8 <= zeta_tol; 97 | const double t11 = safe_math::cbrt( zeta_tol ); 98 | const double t12 = t11 * zeta_tol; 99 | const double t14 = t13 * rho_a; 100 | const double t15 = safe_math::cbrt( t8 ); 101 | const double t19 = piecewise_functor_3( t10, t12, 0.2e1 * t14 * t7 * t15 ); 102 | const double t20 = safe_math::cbrt( t6 ); 103 | const double t24 = piecewise_functor_3( t1, 0.0, -0.3e1 / 0.8e1 * t5 * t19 * t20 ); 104 | const double t25 = alpha * t24; 105 | const double t26 = rho_b <= dens_tol; 106 | const double t27 = rho_b * t7; 107 | const double t29 = 0.2e1 * t27 <= zeta_tol; 108 | const double t30 = t13 * rho_b; 109 | const double t31 = safe_math::cbrt( t27 ); 110 | const double t35 = piecewise_functor_3( t29, t12, 0.2e1 * t30 * t7 * t31 ); 111 | const double t39 = piecewise_functor_3( t26, 0.0, -0.3e1 / 0.8e1 * t5 * t35 * t20 ); 112 | const double t40 = alpha * t39; 113 | 114 | 115 | eps = t25 + t40; 116 | 117 | } 118 | 119 | BUILTIN_KERNEL_EVAL_RETURN 120 | eval_exc_vxc_polar_impl( double rho_a, double rho_b, double& eps, double& vrho_a, double& vrho_b ) { 121 | 122 | (void)(eps); 123 | constexpr double t2 = constants::m_cbrt_3; 124 | constexpr double t3 = constants::m_cbrt_pi; 125 | constexpr double t13 = constants::m_cbrt_2; 126 | constexpr double t5 = t2 / t3; 127 | 128 | 129 | const double t1 = rho_a <= dens_tol; 130 | const double t6 = rho_a + rho_b; 131 | const double t7 = 0.1e1 / t6; 132 | const double t8 = rho_a * t7; 133 | const double t10 = 0.2e1 * t8 <= zeta_tol; 134 | const double t11 = safe_math::cbrt( zeta_tol ); 135 | const double t12 = t11 * zeta_tol; 136 | const double t14 = t13 * rho_a; 137 | const double t15 = safe_math::cbrt( t8 ); 138 | const double t19 = piecewise_functor_3( t10, t12, 0.2e1 * t14 * t7 * t15 ); 139 | const double t20 = safe_math::cbrt( t6 ); 140 | const double t24 = piecewise_functor_3( t1, 0.0, -0.3e1 / 0.8e1 * t5 * t19 * t20 ); 141 | const double t25 = alpha * t24; 142 | const double t26 = rho_b <= dens_tol; 143 | const double t27 = rho_b * t7; 144 | const double t29 = 0.2e1 * t27 <= zeta_tol; 145 | const double t30 = t13 * rho_b; 146 | const double t31 = safe_math::cbrt( t27 ); 147 | const double t35 = piecewise_functor_3( t29, t12, 0.2e1 * t30 * t7 * t31 ); 148 | const double t39 = piecewise_functor_3( t26, 0.0, -0.3e1 / 0.8e1 * t5 * t35 * t20 ); 149 | const double t40 = alpha * t39; 150 | const double t41 = t13 * t7; 151 | const double t44 = t6 * t6; 152 | const double t45 = 0.1e1 / t44; 153 | const double t48 = 0.2e1 * t14 * t45 * t15; 154 | const double t49 = t15 * t15; 155 | const double t50 = 0.1e1 / t49; 156 | const double t51 = t7 * t50; 157 | const double t53 = -rho_a * t45 + t7; 158 | const double t58 = piecewise_functor_3( t10, 0.0, 0.2e1 * t41 * t15 - t48 + 0.2e1 / 0.3e1 * t14 * t51 * t53 ); 159 | const double t62 = t20 * t20; 160 | const double t63 = 0.1e1 / t62; 161 | const double t66 = t5 * t19 * t63 / 0.8e1; 162 | const double t68 = piecewise_functor_3( t1, 0.0, -0.3e1 / 0.8e1 * t5 * t58 * t20 - t66 ); 163 | const double t69 = alpha * t68; 164 | const double t72 = 0.2e1 * t30 * t45 * t31; 165 | const double t73 = rho_b * rho_b; 166 | const double t74 = t13 * t73; 167 | const double t75 = t44 * t6; 168 | const double t76 = 0.1e1 / t75; 169 | const double t77 = t31 * t31; 170 | const double t78 = 0.1e1 / t77; 171 | const double t79 = t76 * t78; 172 | const double t83 = piecewise_functor_3( t29, 0.0, -t72 - 0.2e1 / 0.3e1 * t74 * t79 ); 173 | const double t89 = t5 * t35 * t63 / 0.8e1; 174 | const double t91 = piecewise_functor_3( t26, 0.0, -0.3e1 / 0.8e1 * t5 * t83 * t20 - t89 ); 175 | const double t92 = alpha * t91; 176 | const double t95 = rho_a * rho_a; 177 | const double t96 = t13 * t95; 178 | const double t97 = t76 * t50; 179 | const double t101 = piecewise_functor_3( t10, 0.0, -t48 - 0.2e1 / 0.3e1 * t96 * t97 ); 180 | const double t106 = piecewise_functor_3( t1, 0.0, -0.3e1 / 0.8e1 * t5 * t101 * t20 - t66 ); 181 | const double t107 = alpha * t106; 182 | const double t110 = t7 * t78; 183 | const double t112 = -rho_b * t45 + t7; 184 | const double t117 = piecewise_functor_3( t29, 0.0, 0.2e1 * t41 * t31 - t72 + 0.2e1 / 0.3e1 * t30 * t110 * t112 ); 185 | const double t122 = piecewise_functor_3( t26, 0.0, -0.3e1 / 0.8e1 * t5 * t117 * t20 - t89 ); 186 | const double t123 = alpha * t122; 187 | 188 | 189 | eps = t25 + t40; 190 | vrho_a = t25 + t40 + t6 * ( t69 + t92 ); 191 | vrho_b = t25 + t40 + t6 * ( t107 + t123 ); 192 | 193 | } 194 | 195 | 196 | }; 197 | 198 | struct BuiltinSlaterExchange : detail::BuiltinKernelImpl< BuiltinSlaterExchange > { 199 | 200 | BuiltinSlaterExchange( Spin p ) : 201 | detail::BuiltinKernelImpl< BuiltinSlaterExchange >(p) { } 202 | 203 | virtual ~BuiltinSlaterExchange() = default; 204 | 205 | }; 206 | 207 | 208 | 209 | } // namespace ExchCXX -------------------------------------------------------------------------------- /include/exchcxx/impl/builtin/util.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #include 49 | 50 | #include 51 | 52 | namespace ExchCXX { 53 | 54 | 55 | #if defined(__CUDACC__) || defined(__HIPCC__) 56 | 57 | #define SAFE_CONSTEXPR_INLINE(TYPE) static inline constexpr TYPE __host__ __device__ 58 | #define SAFE_INLINE(TYPE) static inline TYPE __host__ __device__ 59 | 60 | template 61 | SAFE_INLINE(F) safe_max(F x, F y) { return fmax(x,y); } 62 | template 63 | SAFE_INLINE(F) safe_min(F x, F y) { return fmin(x,y); } 64 | 65 | #elif defined(__SYCL_DEVICE_ONLY__) && defined(EXCHCXX_ENABLE_SYCL) 66 | 67 | #define SAFE_CONSTEXPR_INLINE(TYPE) static __attribute__((always_inline)) constexpr TYPE 68 | #define SAFE_INLINE(TYPE) static __attribute__((always_inline)) TYPE 69 | 70 | template 71 | SAFE_CONSTEXPR_INLINE(F) safe_max(F x, F y) { return sycl::fmax(x,y); } 72 | template 73 | SAFE_CONSTEXPR_INLINE(F) safe_min(F x, F y) { return sycl::fmin(x,y); } 74 | 75 | #else 76 | 77 | #define SAFE_CONSTEXPR_INLINE(TYPE) static inline constexpr TYPE 78 | #define SAFE_INLINE(TYPE) static inline TYPE 79 | 80 | template 81 | SAFE_CONSTEXPR_INLINE(F) safe_max(F x, F y) { return std::max(x,y); } 82 | template 83 | SAFE_CONSTEXPR_INLINE(F) safe_min(F x, F y) { return std::min(x,y); } 84 | 85 | #endif 86 | 87 | #define BUILTIN_KERNEL_EVAL_RETURN SAFE_INLINE(void) 88 | 89 | namespace safe_math { 90 | 91 | #ifdef EXCHCXX_ENABLE_SYCL 92 | namespace sm = sycl; 93 | #else 94 | namespace sm = std; 95 | #endif 96 | 97 | template 98 | SAFE_INLINE(auto) sqrt( T x ) { return sm::sqrt(x); } 99 | 100 | // Apparently C / C++ cbrt differ ever-so-slightly 101 | template 102 | SAFE_INLINE(double) cbrt( T x ) { return ::cbrt(x); } 103 | template 104 | SAFE_INLINE(auto) log( T x ) { return sm::log(x); } 105 | template 106 | SAFE_INLINE(auto) exp( T x ) { return sm::exp(x); } 107 | template 108 | SAFE_INLINE(auto) atan( T x ) { return sm::atan(x); } 109 | template 110 | SAFE_INLINE(auto) pow( T x, U e ) { return sm::pow(x,e); } 111 | 112 | } 113 | 114 | template 115 | struct max_dens_tol { 116 | static constexpr double dens_tol = std::max( 117 | KernelType::dens_tol, max_dens_tol::dens_tol 118 | ); 119 | }; 120 | 121 | template 122 | struct max_dens_tol { 123 | static constexpr double dens_tol = KernelType::dens_tol; 124 | }; 125 | 126 | 127 | template 128 | SAFE_CONSTEXPR_INLINE( F ) square( F x ) { return x*x; } 129 | template 130 | SAFE_INLINE( F ) pow_3_2( F x ) { F y = safe_math::sqrt(x); return y*y*y; } 131 | template 132 | SAFE_INLINE( F ) pow_1_4( F x ) { F y = safe_math::sqrt(x); return safe_math::sqrt(y); } 133 | 134 | template 135 | SAFE_CONSTEXPR_INLINE( F ) piecewise_functor_3( bool b, F x, F y ) { 136 | return b ? x : y; 137 | } 138 | 139 | template 140 | SAFE_CONSTEXPR_INLINE( F ) piecewise_functor_5( bool b, F x, bool c, F y, F z ) { 141 | return b ? x : (c ? y : z); 142 | } 143 | 144 | 145 | 146 | template 147 | SAFE_CONSTEXPR_INLINE( F ) enforce_fermi_hole_curvature(F sigma, F rho, F tau) { 148 | return safe_min(sigma, F(8) * rho * tau); 149 | } 150 | 151 | template 152 | SAFE_CONSTEXPR_INLINE( F ) enforce_polar_sigma_constraints(F sigma_aa, F sigma_ab, F sigma_bb) { 153 | const auto s_ave = 0.5 * (sigma_aa + sigma_bb); 154 | sigma_ab = (sigma_ab >= -s_ave ? sigma_ab : -s_ave); 155 | sigma_ab = (sigma_ab <= s_ave ? sigma_ab : s_ave); 156 | return sigma_ab; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /include/exchcxx/impl/libxc.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | #include 54 | #include 55 | #include // Libxc 56 | #if XC_MAJOR_VERSION > 6 57 | #include // Libxc funcs 58 | #endif 59 | 60 | namespace ExchCXX { 61 | namespace detail { 62 | 63 | class LibxcKernelImpl : public XCKernelImpl { 64 | 65 | using unique_me = XCKernelImpl::unique_me; 66 | 67 | unique_me clone_() const override; 68 | 69 | bool is_lda_() const noexcept override; 70 | bool is_gga_() const noexcept override; 71 | bool is_mgga_() const noexcept override; 72 | bool is_hyb_() const noexcept override; 73 | bool is_polarized_() const noexcept override; 74 | bool is_epc_() const noexcept override; 75 | bool needs_laplacian_() const noexcept override; 76 | bool needs_tau_() const noexcept override; 77 | double hyb_exx_() const noexcept override; 78 | 79 | bool supports_inc_interface_() const noexcept override; 80 | 81 | // LDA interface 82 | LDA_EXC_GENERATOR( eval_exc_ ) const override; 83 | LDA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 84 | LDA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 85 | LDA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 86 | 87 | // GGA interface 88 | GGA_EXC_GENERATOR( eval_exc_ ) const override; 89 | GGA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 90 | GGA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 91 | GGA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 92 | 93 | // MGGA interface 94 | MGGA_EXC_GENERATOR( eval_exc_ ) const override; 95 | MGGA_EXC_VXC_GENERATOR( eval_exc_vxc_ ) const override; 96 | MGGA_EXC_INC_GENERATOR( eval_exc_inc_ ) const override; 97 | MGGA_EXC_VXC_INC_GENERATOR( eval_exc_vxc_inc_ ) const override; 98 | 99 | #ifdef EXCHCXX_ENABLE_DEVICE 100 | 101 | // LDA interface 102 | LDA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 103 | LDA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 104 | LDA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 105 | LDA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 106 | 107 | // GGA interface 108 | GGA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 109 | GGA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 110 | GGA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 111 | GGA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 112 | 113 | // MGGA interface 114 | MGGA_EXC_GENERATOR_DEVICE( eval_exc_device_ ) const override; 115 | MGGA_EXC_VXC_GENERATOR_DEVICE( eval_exc_vxc_device_ ) const override; 116 | MGGA_EXC_INC_GENERATOR_DEVICE( eval_exc_inc_device_ ) const override; 117 | MGGA_EXC_VXC_INC_GENERATOR_DEVICE( eval_exc_vxc_inc_device_ ) const override; 118 | 119 | #endif 120 | 121 | protected: 122 | 123 | int polar_; ///< Spin polarization 124 | xc_func_type kernel_; ///< Libxc kernel definition 125 | 126 | bool initialized_ = false; 127 | void throw_if_uninitialized() const { EXCHCXX_BOOL_CHECK("Kernel Uninitialized", initialized_ ); } 128 | 129 | 130 | auto xc_info() const { 131 | throw_if_uninitialized(); 132 | return kernel_.info; 133 | }; 134 | 135 | LibxcKernelImpl( xc_func_type kern, const int spin_polar, 136 | const bool init ); 137 | 138 | public: 139 | 140 | LibxcKernelImpl() = delete; 141 | 142 | LibxcKernelImpl( const Kernel kern, const Spin polar); 143 | LibxcKernelImpl( const std::string xc_name, const Spin polar); 144 | LibxcKernelImpl( const int kern, const int spin_polar ); 145 | LibxcKernelImpl( const LibxcKernelImpl& ); 146 | 147 | // Destroy interal Libxc data 148 | ~LibxcKernelImpl() noexcept; 149 | 150 | 151 | 152 | 153 | 154 | }; 155 | 156 | } // namespace detail 157 | 158 | } // namespace ExchCXX 159 | 160 | -------------------------------------------------------------------------------- /include/exchcxx/impl/xc_kernel_fwd.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | namespace ExchCXX { 54 | namespace detail { 55 | 56 | struct XCKernelImpl; ///< Fwd decl of XCKernelImpl 57 | 58 | }; // detail 59 | }; // ExchCXX 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /include/exchcxx/util/bidirectional_map.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | #include 49 | 50 | namespace ExchCXX { 51 | 52 | template , 53 | typename CompareVal = std::less > 54 | class BidirectionalMap{ 55 | std::map forward_map_; 56 | std::map reverse_map_; 57 | 58 | public: 59 | BidirectionalMap(std::map map) : forward_map_(map){ 60 | 61 | for (auto &&v : map) { 62 | if (reverse_map_.find(v.second) != reverse_map_.end()){ 63 | throw std::runtime_error("BidirectionalMap must have unique values"); 64 | } 65 | reverse_map_.insert(std::make_pair(v.second, v.first)); 66 | } 67 | 68 | } 69 | 70 | Val value(Key key) { return forward_map_.at(key); } 71 | 72 | Key key(Val val) { return reverse_map_.at(val); } 73 | 74 | bool key_exists(Key key){ 75 | return forward_map_.find(key) != forward_map_.end(); 76 | } 77 | 78 | bool value_exists(Val val){ 79 | return reverse_map_.find(val) != reverse_map_.end(); 80 | } 81 | 82 | }; 83 | 84 | } // namespace ExchCXX 85 | -------------------------------------------------------------------------------- /include/exchcxx/util/div_ceil.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | #include 49 | #include 50 | 51 | namespace ExchCXX { 52 | namespace util { 53 | 54 | template 55 | intmax_t div_ceil( Integral1 i, Integral2 j ) { 56 | 57 | intmax_t i_us = i; 58 | intmax_t j_us = j; 59 | 60 | auto d = std::div(i_us,j_us); 61 | return d.quot + !!d.rem; 62 | 63 | }; 64 | 65 | 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /include/exchcxx/util/named_type.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | namespace ExchCXX { 49 | namespace detail { 50 | 51 | template 52 | class NamedType { 53 | 54 | public: 55 | 56 | constexpr explicit NamedType() : value_() { } 57 | constexpr explicit NamedType(T const& value) : value_(value) {} 58 | constexpr explicit NamedType(T&& value) : value_(std::move(value)) {} 59 | 60 | constexpr NamedType( const NamedType& other ) : value_(other.get()) { } 61 | constexpr NamedType( NamedType&& other ) noexcept : 62 | value_(std::move(other.get())) { }; 63 | 64 | constexpr NamedType& operator=( const NamedType& other ) { 65 | value_ = other.get(); 66 | return *this; 67 | } 68 | constexpr NamedType& operator=( NamedType&& other ) noexcept { 69 | value_ = std::move(other.get()); 70 | return *this; 71 | } 72 | 73 | constexpr T& get() { return value_; } 74 | constexpr T const& get() const {return value_; } 75 | 76 | template 77 | void serialize( Archive& ar ) { 78 | ar( value_ ); 79 | } 80 | 81 | private: 82 | 83 | T value_; 84 | 85 | }; 86 | 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /include/exchcxx/util/param_macros.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | 53 | namespace ExchCXX { 54 | 55 | using host_buffer_type = double*; 56 | using const_host_buffer_type = const double*; 57 | 58 | #ifdef EXCHCXX_ENABLE_DEVICE 59 | using device_buffer_type = double*; 60 | using const_device_buffer_type = const double*; 61 | #endif 62 | 63 | 64 | } 65 | 66 | #define NOTYPE 67 | 68 | // LDA Parameters 69 | #define TYPED_LDA_IPARAMS(INTT,BUFFER) INTT N, BUFFER rho 70 | #define TYPED_LDA_OPARAMS_EXC(BUFFER) BUFFER eps 71 | #define TYPED_LDA_OPARAMS_VXC(BUFFER) BUFFER vxc 72 | #define TYPED_LDA_OPARAMS_FXC(BUFFER) BUFFER fxc 73 | #define TYPED_LDA_OPARAMS_KXC(BUFFER) BUFFER kxc 74 | #define TYPED_LDA_OPARAMS_EXC_VXC(BUFFER) \ 75 | TYPED_LDA_OPARAMS_EXC(BUFFER), TYPED_LDA_OPARAMS_VXC(BUFFER) 76 | 77 | #define LDA_IPARAMS TYPED_LDA_IPARAMS(int,const_host_buffer_type) 78 | #define LDA_OPARAMS_EXC TYPED_LDA_OPARAMS_EXC(host_buffer_type) 79 | #define LDA_OPARAMS_VXC TYPED_LDA_OPARAMS_VXC(host_buffer_type) 80 | #define LDA_OPARAMS_FXC TYPED_LDA_OPARAMS_FXC(host_buffer_type) 81 | #define LDA_OPARAMS_KXC TYPED_LDA_OPARAMS_KXC(host_buffer_type) 82 | #define LDA_OPARAMS_EXC_VXC TYPED_LDA_OPARAMS_EXC_VXC(host_buffer_type) 83 | 84 | #define DEV_LDA_IPARAMS TYPED_LDA_IPARAMS(int,const_device_buffer_type) 85 | #define DEV_LDA_OPARAMS_EXC TYPED_LDA_OPARAMS_EXC(device_buffer_type) 86 | #define DEV_LDA_OPARAMS_VXC TYPED_LDA_OPARAMS_VXC(device_buffer_type) 87 | #define DEV_LDA_OPARAMS_FXC TYPED_LDA_OPARAMS_FXC(device_buffer_type) 88 | #define DEV_LDA_OPARAMS_KXC TYPED_LDA_OPARAMS_KXC(device_buffer_type) 89 | #define DEV_LDA_OPARAMS_EXC_VXC TYPED_LDA_OPARAMS_EXC_VXC(device_buffer_type) 90 | 91 | #define LDA_IPARAMS_NOTYPE TYPED_LDA_IPARAMS(NOTYPE,NOTYPE) 92 | #define LDA_OPARAMS_EXC_NOTYPE TYPED_LDA_OPARAMS_EXC(NOTYPE) 93 | #define LDA_OPARAMS_VXC_NOTYPE TYPED_LDA_OPARAMS_VXC(NOTYPE) 94 | #define LDA_OPARAMS_FXC_NOTYPE TYPED_LDA_OPARAMS_FXC(NOTYPE) 95 | #define LDA_OPARAMS_KXC_NOTYPE TYPED_LDA_OPARAMS_KXC(NOTYPE) 96 | #define LDA_OPARAMS_EXC_VXC_NOTYPE TYPED_LDA_OPARAMS_EXC_VXC(NOTYPE) 97 | 98 | 99 | 100 | // GGA Parameters 101 | #define TYPED_GGA_IPARAMS(INTT,BUFFER) INTT N, BUFFER rho, BUFFER sigma 102 | #define TYPED_GGA_OPARAMS_EXC(BUFFER) BUFFER eps 103 | #define TYPED_GGA_OPARAMS_VXC(BUFFER) BUFFER vrho, BUFFER vsigma 104 | #define TYPED_GGA_OPARAMS_FXC(BUFFER) \ 105 | BUFFER v2rho2, BUFFER v2rhosigma, BUFFER v2sigma2 106 | #define TYPED_GGA_OPARAMS_KXC(BUFFER) \ 107 | BUFFER v3rho3, BUFFER v3rho2sigma, BUFFER v3rhosigma2, BUFFER v3sigma3 108 | 109 | #define TYPED_GGA_OPARAMS_EXC_VXC(BUFFER) \ 110 | TYPED_GGA_OPARAMS_EXC(BUFFER), TYPED_GGA_OPARAMS_VXC(BUFFER) 111 | 112 | 113 | 114 | #define GGA_IPARAMS TYPED_GGA_IPARAMS(int,const_host_buffer_type) 115 | #define GGA_OPARAMS_EXC TYPED_GGA_OPARAMS_EXC(host_buffer_type) 116 | #define GGA_OPARAMS_VXC TYPED_GGA_OPARAMS_VXC(host_buffer_type) 117 | #define GGA_OPARAMS_FXC TYPED_GGA_OPARAMS_FXC(host_buffer_type) 118 | #define GGA_OPARAMS_KXC TYPED_GGA_OPARAMS_KXC(host_buffer_type) 119 | #define GGA_OPARAMS_EXC_VXC TYPED_GGA_OPARAMS_EXC_VXC(host_buffer_type) 120 | 121 | #define DEV_GGA_IPARAMS TYPED_GGA_IPARAMS(int,const_device_buffer_type) 122 | #define DEV_GGA_OPARAMS_EXC TYPED_GGA_OPARAMS_EXC(device_buffer_type) 123 | #define DEV_GGA_OPARAMS_VXC TYPED_GGA_OPARAMS_VXC(device_buffer_type) 124 | #define DEV_GGA_OPARAMS_FXC TYPED_GGA_OPARAMS_FXC(device_buffer_type) 125 | #define DEV_GGA_OPARAMS_KXC TYPED_GGA_OPARAMS_KXC(device_buffer_type) 126 | #define DEV_GGA_OPARAMS_EXC_VXC TYPED_GGA_OPARAMS_EXC_VXC(device_buffer_type) 127 | 128 | #define GGA_IPARAMS_NOTYPE TYPED_GGA_IPARAMS(NOTYPE,NOTYPE) 129 | #define GGA_OPARAMS_EXC_NOTYPE TYPED_GGA_OPARAMS_EXC(NOTYPE) 130 | #define GGA_OPARAMS_VXC_NOTYPE TYPED_GGA_OPARAMS_VXC(NOTYPE) 131 | #define GGA_OPARAMS_FXC_NOTYPE TYPED_GGA_OPARAMS_FXC(NOTYPE) 132 | #define GGA_OPARAMS_KXC_NOTYPE TYPED_GGA_OPARAMS_KXC(NOTYPE) 133 | #define GGA_OPARAMS_EXC_VXC_NOTYPE TYPED_GGA_OPARAMS_EXC_VXC(NOTYPE) 134 | 135 | 136 | // MGGA Parameters 137 | #define TYPED_MGGA_IPARAMS(INTT,BUFFER) \ 138 | INTT N, BUFFER rho, BUFFER sigma, BUFFER lapl, BUFFER tau 139 | #define TYPED_MGGA_OPARAMS_EXC(BUFFER) BUFFER eps 140 | #define TYPED_MGGA_OPARAMS_VXC(BUFFER) \ 141 | BUFFER vrho, BUFFER vsigma, BUFFER vlapl, BUFFER vtau 142 | 143 | #define TYPED_MGGA_OPARAMS_EXC_VXC(BUFFER) \ 144 | TYPED_MGGA_OPARAMS_EXC(BUFFER), TYPED_MGGA_OPARAMS_VXC(BUFFER) 145 | 146 | #define MGGA_IPARAMS TYPED_MGGA_IPARAMS(int,const_host_buffer_type) 147 | #define MGGA_OPARAMS_EXC TYPED_MGGA_OPARAMS_EXC(host_buffer_type) 148 | #define MGGA_OPARAMS_VXC TYPED_MGGA_OPARAMS_VXC(host_buffer_type) 149 | #define MGGA_OPARAMS_EXC_VXC TYPED_MGGA_OPARAMS_EXC_VXC(host_buffer_type) 150 | 151 | #define DEV_MGGA_IPARAMS TYPED_MGGA_IPARAMS(int,const_device_buffer_type) 152 | #define DEV_MGGA_OPARAMS_EXC TYPED_MGGA_OPARAMS_EXC(device_buffer_type) 153 | #define DEV_MGGA_OPARAMS_VXC TYPED_MGGA_OPARAMS_VXC(device_buffer_type) 154 | #define DEV_MGGA_OPARAMS_EXC_VXC TYPED_MGGA_OPARAMS_EXC_VXC(device_buffer_type) 155 | 156 | #define MGGA_IPARAMS_NOTYPE TYPED_MGGA_IPARAMS(NOTYPE,NOTYPE) 157 | #define MGGA_OPARAMS_EXC_NOTYPE TYPED_MGGA_OPARAMS_EXC(NOTYPE) 158 | #define MGGA_OPARAMS_VXC_NOTYPE TYPED_MGGA_OPARAMS_VXC(NOTYPE) 159 | #define MGGA_OPARAMS_EXC_VXC_NOTYPE TYPED_MGGA_OPARAMS_EXC_VXC(NOTYPE) 160 | -------------------------------------------------------------------------------- /include/exchcxx/util/unused.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | #include 49 | 50 | namespace ExchCXX { 51 | 52 | inline static void unused( ) { } 53 | 54 | template 55 | void unused( const T& t, Args&&... args ) { 56 | (void)(t); 57 | unused( std::forward(args)... ); 58 | } 59 | 60 | 61 | template 62 | inline static void disabled_LDA_interface(Args&&... args) { 63 | unused( std::forward(args)... ); 64 | throw std::runtime_error("LDA Interface is disabled for the specified kernel"); 65 | } 66 | 67 | template 68 | inline static void disabled_GGA_interface(Args&&... args) { 69 | unused( std::forward(args)... ); 70 | throw std::runtime_error("GGA Interface is disabled for the specified kernel"); 71 | } 72 | 73 | template 74 | inline static void disabled_MGGA_interface(Args&&... args) { 75 | unused( std::forward(args)... ); 76 | throw std::runtime_error("MGGA Interface is disabled for the specified kernel"); 77 | } 78 | 79 | template 80 | inline static void disabled_INC_interface(Args&&... args) { 81 | unused( std::forward(args)... ); 82 | throw std::runtime_error("INC Interface is disabled for the specified kernel"); 83 | } 84 | 85 | #ifdef EXCHCXX_ENABLE_DEVICE 86 | template 87 | inline static void disabled_LDA_device_interface(Args&&... args) { 88 | unused( std::forward(args)... ); 89 | throw std::runtime_error("LDA Device Interface is disabled for the specified kernel"); 90 | } 91 | 92 | template 93 | inline static void disabled_GGA_device_interface(Args&&... args) { 94 | unused( std::forward(args)... ); 95 | throw std::runtime_error("GGA Device Interface is disabled for the specified kernel"); 96 | } 97 | 98 | template 99 | inline static void disabled_MGGA_device_interface(Args&&... args) { 100 | unused( std::forward(args)... ); 101 | throw std::runtime_error("MGGA Device Interface is disabled for the specified kernel"); 102 | } 103 | 104 | template 105 | inline static void disabled_INC_device_interface(Args&&... args) { 106 | unused( std::forward(args)... ); 107 | throw std::runtime_error("INC Device Interface is disabled for the specified kernel"); 108 | } 109 | #endif 110 | 111 | } 112 | 113 | #define UNUSED_INTERFACE_GENERATOR( APPROX, TYPE, func, qualifiers ) \ 114 | FORWARD_XC_ARGS( APPROX, TYPE, func, disabled_ ## APPROX ## _interface, \ 115 | qualifiers ) 116 | 117 | #define UNUSED_INC_INTERFACE_GENERATOR( APPROX, TYPE, func, qualifiers ) \ 118 | FORWARD_XC_INC_ARGS( APPROX, TYPE, func, disabled_INC_interface, \ 119 | qualifiers ) 120 | 121 | #ifdef EXCHCXX_ENABLE_DEVICE 122 | 123 | #define UNUSED_DEVICE_INTERFACE_GENERATOR( APPROX, TYPE, func, qualifiers ) \ 124 | FORWARD_XC_ARGS_DEVICE( APPROX, TYPE, func, \ 125 | disabled_ ## APPROX ## _device_interface, \ 126 | qualifiers ) 127 | 128 | #define UNUSED_DEVICE_INC_INTERFACE_GENERATOR( APPROX, TYPE, func, qualifiers ) \ 129 | FORWARD_XC_INC_ARGS_DEVICE( APPROX, TYPE, func, disabled_INC_device_interface, \ 130 | qualifiers ) 131 | 132 | #endif 133 | -------------------------------------------------------------------------------- /include/exchcxx/xc_kernel.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | 48 | #ifdef EXCHCXX_HAS_CONFIG_H 49 | #include 50 | #endif 51 | 52 | #include 53 | #include 54 | #include 55 | 56 | // Standard Libs 57 | #include 58 | #include 59 | #include 60 | 61 | 62 | namespace ExchCXX { 63 | 64 | /** 65 | * \brief A class which manages the lifetime and evaluation 66 | * of exchange-correlation (XC) kernels for density functional 67 | * theory. 68 | */ 69 | class XCKernel { 70 | 71 | using impl_ptr = std::unique_ptr< detail::XCKernelImpl >; 72 | 73 | impl_ptr pimpl_; ///< Pointer to implementation 74 | 75 | public: 76 | 77 | // Avoid stateless kernel 78 | XCKernel() = delete; 79 | 80 | XCKernel( const Backend backend, const Kernel kern, 81 | const Spin polar ); 82 | #ifdef EXCHCXX_ENABLE_LIBXC 83 | XCKernel( const libxc_name_string& xc_name, 84 | const Spin polar ); 85 | XCKernel( const Kernel kern, const Spin polar ) : 86 | XCKernel( Backend::libxc, kern, polar ){ }; 87 | #else 88 | XCKernel( const Kernel kern, const Spin polar ) : 89 | XCKernel( Backend::builtin, kern, polar ){ }; 90 | #endif 91 | 92 | XCKernel( impl_ptr&& ptr ) ; 93 | XCKernel( const XCKernel& ) ; 94 | XCKernel( XCKernel&& ) noexcept; 95 | XCKernel& operator=( const XCKernel& ) ; 96 | XCKernel& operator=( XCKernel&& ) noexcept; 97 | 98 | // Destroy interal Libxc data 99 | ~XCKernel() noexcept; 100 | 101 | 102 | 103 | bool is_lda() const noexcept { return pimpl_->is_lda(); } 104 | bool is_gga() const noexcept { return pimpl_->is_gga(); } 105 | bool is_mgga() const noexcept { return pimpl_->is_mgga(); } 106 | bool is_hyb() const noexcept { return pimpl_->is_hyb(); } 107 | bool is_polarized() const noexcept { return pimpl_->is_polarized(); } 108 | bool is_epc() const noexcept { return pimpl_->is_epc(); } 109 | 110 | bool needs_laplacian() const noexcept { return pimpl_->needs_laplacian(); } 111 | bool needs_tau() const noexcept { return pimpl_->needs_tau(); } 112 | 113 | double hyb_exx() const noexcept { return pimpl_->hyb_exx(); } 114 | 115 | bool supports_inc_interface() const noexcept { 116 | return pimpl_->supports_inc_interface(); 117 | } 118 | 119 | inline size_t rho_buffer_len( size_t npts ) const noexcept { 120 | return pimpl_->rho_buffer_len( npts ); 121 | } 122 | inline size_t sigma_buffer_len( size_t npts ) const noexcept { 123 | return pimpl_->sigma_buffer_len( npts ); 124 | } 125 | inline size_t lapl_buffer_len( size_t npts ) const noexcept { 126 | return pimpl_->lapl_buffer_len( npts ); 127 | } 128 | inline size_t tau_buffer_len( size_t npts ) const noexcept { 129 | return pimpl_->tau_buffer_len( npts ); 130 | } 131 | 132 | inline size_t exc_buffer_len( size_t npts ) const noexcept { 133 | return pimpl_->exc_buffer_len( npts ); 134 | } 135 | inline size_t vrho_buffer_len( size_t npts ) const noexcept { 136 | return pimpl_->vrho_buffer_len( npts ); 137 | } 138 | inline size_t vsigma_buffer_len( size_t npts ) const noexcept { 139 | return pimpl_->vsigma_buffer_len( npts ); 140 | } 141 | inline size_t vlapl_buffer_len( size_t npts ) const noexcept { 142 | return pimpl_->vlapl_buffer_len( npts ); 143 | } 144 | inline size_t vtau_buffer_len( size_t npts ) const noexcept { 145 | return pimpl_->vtau_buffer_len( npts ); 146 | } 147 | 148 | 149 | template 150 | void eval_exc( Args&&... args ) const { 151 | pimpl_->eval_exc( std::forward(args)... ); 152 | } 153 | 154 | template 155 | void eval_exc_vxc( Args&&... args ) const { 156 | pimpl_->eval_exc_vxc( std::forward(args)... ); 157 | } 158 | 159 | template 160 | void eval_exc_inc( Args&&... args ) const { 161 | pimpl_->eval_exc_inc( std::forward(args)... ); 162 | } 163 | 164 | template 165 | void eval_exc_vxc_inc( Args&&... args ) const { 166 | pimpl_->eval_exc_vxc_inc( std::forward(args)... ); 167 | } 168 | 169 | // Device code 170 | #ifdef EXCHCXX_ENABLE_DEVICE 171 | 172 | template 173 | void eval_exc_device( Args&&... args ) const { 174 | pimpl_->eval_exc_device( std::forward(args)... ); 175 | } 176 | 177 | template 178 | void eval_exc_vxc_device( Args&&... args ) const { 179 | pimpl_->eval_exc_vxc_device( std::forward(args)... ); 180 | } 181 | 182 | template 183 | void eval_exc_inc_device( Args&&... args ) const { 184 | pimpl_->eval_exc_inc_device( std::forward(args)... ); 185 | } 186 | 187 | template 188 | void eval_exc_vxc_inc_device( Args&&... args ) const { 189 | pimpl_->eval_exc_vxc_inc_device( std::forward(args)... ); 190 | } 191 | 192 | #endif 193 | 194 | 195 | 196 | }; 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | } 207 | 208 | -------------------------------------------------------------------------------- /performance/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( performance_benchmark device_benchmark.cxx ) 2 | target_link_libraries( performance_benchmark PUBLIC exchcxx ) 3 | -------------------------------------------------------------------------------- /performance/device_benchmark.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | 7 | 8 | template 9 | T* safe_cuda_malloc( size_t n ) { 10 | 11 | T* ptr; 12 | auto stat = cudaMalloc( (void**)&ptr, n*sizeof(T) ); 13 | if( stat != cudaSuccess ) 14 | throw std::runtime_error(cudaGetErrorString( stat )); 15 | return ptr; 16 | 17 | } 18 | 19 | template 20 | void safe_cuda_cpy( T* dest, const T* src, size_t len ) { 21 | 22 | auto stat = cudaMemcpy( dest, src, len*sizeof(T), cudaMemcpyDefault ); 23 | if( stat != cudaSuccess ) 24 | throw std::runtime_error(cudaGetErrorString( stat )); 25 | 26 | } 27 | 28 | void cuda_free_all(){ } 29 | template 30 | void cuda_free_all( T* ptr, Args&&... args ) { 31 | 32 | auto stat = cudaFree( ptr ); 33 | if( stat != cudaSuccess ) 34 | throw std::runtime_error(cudaGetErrorString( stat )); 35 | 36 | cuda_free_all( std::forward(args)... ); 37 | 38 | 39 | } 40 | 41 | void device_synchronize() { 42 | auto stat = cudaDeviceSynchronize(); 43 | if( stat != cudaSuccess ) 44 | throw std::runtime_error(cudaGetErrorString( stat )); 45 | } 46 | 47 | void stream_synchronize(cudaStream_t stream) { 48 | auto stat = cudaStreamSynchronize( stream ); 49 | if( stat != cudaSuccess ) 50 | throw std::runtime_error(cudaGetErrorString( stat )); 51 | } 52 | 53 | 54 | template 55 | double time_cpu_op( const Op& op ) { 56 | 57 | auto st = std::chrono::high_resolution_clock::now(); 58 | 59 | op(); 60 | 61 | auto en = std::chrono::high_resolution_clock::now(); 62 | 63 | return std::chrono::duration(en - st).count(); 64 | 65 | } 66 | 67 | template 68 | double time_gpu_op( const Op& op, cudaStream_t stream ) { 69 | 70 | cudaEvent_t st, en; 71 | 72 | auto stat = cudaEventCreate( &st ); 73 | if( stat != cudaSuccess ) 74 | throw std::runtime_error(cudaGetErrorString( stat )); 75 | stat = cudaEventCreate( &en ); 76 | if( stat != cudaSuccess ) 77 | throw std::runtime_error(cudaGetErrorString( stat )); 78 | 79 | stream_synchronize( stream ); 80 | 81 | stat = cudaEventRecord( st, stream ); 82 | if( stat != cudaSuccess ) 83 | throw std::runtime_error(cudaGetErrorString( stat )); 84 | 85 | op(); 86 | 87 | stream_synchronize( stream ); 88 | stat = cudaEventRecord( en, stream ); 89 | if( stat != cudaSuccess ) 90 | throw std::runtime_error(cudaGetErrorString( stat )); 91 | 92 | stat = cudaEventSynchronize( en ); 93 | if( stat != cudaSuccess ) 94 | throw std::runtime_error(cudaGetErrorString( stat )); 95 | 96 | float dur; 97 | stat = cudaEventElapsedTime( &dur, st, en ); 98 | if( stat != cudaSuccess ) 99 | throw std::runtime_error(cudaGetErrorString( stat )); 100 | 101 | stat = cudaEventDestroy( st ); 102 | if( stat != cudaSuccess ) 103 | throw std::runtime_error(cudaGetErrorString( stat )); 104 | stat = cudaEventDestroy( en ); 105 | if( stat != cudaSuccess ) 106 | throw std::runtime_error(cudaGetErrorString( stat )); 107 | 108 | return dur; 109 | 110 | } 111 | 112 | template 113 | auto max_diff_vec( const std::vector& a, const std::vector& b ) { 114 | 115 | assert( a.size() == b.size() ); 116 | 117 | std::vector diff = a; 118 | for( auto i = 0; i < a.size(); ++i ) 119 | diff[i] = std::abs( a[i] - b[i] ); 120 | 121 | return *std::max_element(diff.begin(), diff.end() ); 122 | 123 | } 124 | 125 | int main() { 126 | 127 | 128 | using namespace ExchCXX; 129 | auto kern = Kernel::PBE0; 130 | auto polar = Spin::Unpolarized; 131 | 132 | auto builtin_backend = Backend::builtin; 133 | 134 | XCKernel pbe_libxc( kern, polar ); 135 | XCKernel pbe_built( builtin_backend, kern, polar ); 136 | 137 | int npts = 100000; 138 | std::vector rho( npts, 0.1 ); 139 | std::vector sigma( npts, 0.2 ); 140 | 141 | std::vector eps(npts), vrho(npts), vsigma(npts); 142 | 143 | 144 | double* rho_device = safe_cuda_malloc( npts ); 145 | double* sigma_device = safe_cuda_malloc( npts ); 146 | double* eps_device = safe_cuda_malloc( npts ); 147 | double* vrho_device = safe_cuda_malloc( npts ); 148 | double* vsigma_device = safe_cuda_malloc( npts ); 149 | 150 | safe_cuda_cpy( rho_device, rho.data(), npts ); 151 | safe_cuda_cpy( sigma_device, sigma.data(), npts ); 152 | device_synchronize(); 153 | 154 | cudaStream_t stream = 0; 155 | 156 | int nrep = 5; 157 | 158 | // Warmup CPU 159 | for( int i = 0; i < nrep; ++i ) { 160 | pbe_libxc.eval_exc_vxc( npts, rho.data(), sigma.data(), eps.data(), 161 | vrho.data(), vsigma.data() ); 162 | } 163 | 164 | auto eps_ref = eps; 165 | auto vrho_ref = vrho; 166 | auto vsigma_ref = vsigma; 167 | 168 | // Warmup GPU 169 | for( int i = 0; i < nrep; ++i ) { 170 | pbe_built.eval_exc_vxc_device( npts, rho_device, sigma_device, eps_device, 171 | vrho_device, vsigma_device, stream ); 172 | } 173 | 174 | 175 | // Get timings for CPU 176 | auto libxc_host_dur = time_cpu_op([&]() { 177 | for( int i = 0; i < nrep; ++i ) { 178 | pbe_libxc.eval_exc_vxc( npts, rho.data(), sigma.data(), eps.data(), 179 | vrho.data(), vsigma.data() ); 180 | } 181 | }); 182 | 183 | auto builtin_host_dur = time_cpu_op([&]() { 184 | for( int i = 0; i < nrep; ++i ) { 185 | pbe_built.eval_exc_vxc( npts, rho.data(), sigma.data(), eps.data(), 186 | vrho.data(), vsigma.data() ); 187 | } 188 | }); 189 | 190 | // Get timings for GPU 191 | auto libxc_device_dur = time_gpu_op([&]() { 192 | for( int i = 0; i < nrep; ++i ) { 193 | pbe_libxc.eval_exc_vxc_device( npts, rho_device, sigma_device, eps_device, 194 | vrho_device, vsigma_device, stream ); 195 | } 196 | }, stream); 197 | 198 | auto builtin_device_dur = time_gpu_op([&]() { 199 | for( int i = 0; i < nrep; ++i ) { 200 | pbe_built.eval_exc_vxc_device( npts, rho_device, sigma_device, eps_device, 201 | vrho_device, vsigma_device, stream ); 202 | } 203 | }, stream); 204 | 205 | 206 | safe_cuda_cpy( eps.data(), eps_device, npts ); 207 | safe_cuda_cpy( vrho.data(), vrho_device, npts ); 208 | safe_cuda_cpy( vsigma.data(), vsigma_device, npts ); 209 | 210 | device_synchronize(); 211 | 212 | std::cout << max_diff_vec( eps, eps_ref ) << std::endl; 213 | 214 | 215 | 216 | std::cout << "Libxc Host = " << libxc_host_dur << std::endl; 217 | std::cout << "Built Host = " << builtin_host_dur << std::endl; 218 | std::cout << "Libxc Device = " << libxc_device_dur << std::endl; 219 | std::cout << "Built Device = " << builtin_device_dur << std::endl; 220 | 221 | 222 | 223 | cuda_free_all( rho_device, sigma_device, eps_device, vrho_device, vsigma_device ); 224 | } 225 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( EXCHCXX_SOURCES 2 | xc_kernel.cxx 3 | xc_functional.cxx 4 | boilerplate.cxx 5 | builtin.cxx 6 | builtin_interface.cxx 7 | builtin_kernel.cxx 8 | ) 9 | if(EXCHCXX_ENABLE_LIBXC) 10 | list(APPEND EXCHCXX_SOURCES libxc.cxx) 11 | endif() 12 | message(STATUS ${EXCHCXX_SOURCES}) 13 | 14 | add_library( exchcxx ${EXCHCXX_SOURCES} ) 15 | 16 | # TARGET properties 17 | 18 | target_compile_features( exchcxx PUBLIC cxx_std_17 ) 19 | if( EXCHCXX_ENABLE_LIBXC ) 20 | target_link_libraries( exchcxx PUBLIC Libxc::xc ) 21 | endif() 22 | 23 | # Generate exchcxx_config.hpp 24 | configure_file( 25 | ${PROJECT_SOURCE_DIR}/include/exchcxx/exchcxx_config.hpp.in 26 | ${PROJECT_BINARY_DIR}/include/exchcxx/exchcxx_config.hpp 27 | ) 28 | target_compile_definitions( exchcxx PUBLIC "EXCHCXX_HAS_CONFIG_H=1" ) 29 | 30 | 31 | 32 | # Device specific 33 | if( EXCHCXX_ENABLE_CUDA ) 34 | include( cuda/exchcxx_cuda.cmake ) 35 | endif() 36 | 37 | if( EXCHCXX_ENABLE_HIP ) 38 | include( hip/exchcxx_hip.cmake ) 39 | endif() 40 | 41 | if( EXCHCXX_ENABLE_SYCL ) 42 | include( sycl/exchcxx_sycl.cmake ) 43 | endif() 44 | 45 | 46 | 47 | target_include_directories( exchcxx 48 | PUBLIC 49 | $ 50 | $ 51 | $ 52 | $ 53 | ) 54 | 55 | include( CheckCXXCompilerFlag ) 56 | check_cxx_compiler_flag( -Wall EXCHCXX_CXX_HAS_WALL ) 57 | check_cxx_compiler_flag( -Wextra EXCHCXX_CXX_HAS_WEXTRA ) 58 | check_cxx_compiler_flag( -Wpedantic EXCHCXX_CXX_HAS_WPEDANTIC ) 59 | check_cxx_compiler_flag( -Wnon-virtual-dtor EXCHCXX_CXX_HAS_WNON_VIRTUAL_DTOR ) 60 | check_cxx_compiler_flag( -Wshadow EXCHCXX_CXX_HAS_WSHADOW ) 61 | 62 | if( EXCHCXX_CXX_HAS_WALL ) 63 | target_compile_options( exchcxx PRIVATE $<$: -Wall> ) 64 | endif() 65 | 66 | if( EXCHCXX_CXX_HAS_WEXTRA ) 67 | target_compile_options( exchcxx PRIVATE $<$: -Wextra> ) 68 | endif() 69 | 70 | if( EXCHCXX_CXX_HAS_WPEDANTIC ) 71 | target_compile_options( exchcxx PRIVATE $<$: -Wpedantic> ) 72 | endif() 73 | 74 | if( EXCHCXX_CXX_HAS_WNON_VIRTUAL_DTOR ) 75 | target_compile_options( exchcxx PRIVATE $<$: -Wnon-virtual-dtor -Werror=non-virtual-dtor> ) 76 | endif() 77 | 78 | if( EXCHCXX_CXX_HAS_WSHADOW ) 79 | target_compile_options( exchcxx PRIVATE $<$: -Wshadow -Werror=shadow> ) 80 | endif() 81 | 82 | # INSTALL rules 83 | add_library( ExchCXX::ExchCXX ALIAS exchcxx ) 84 | 85 | 86 | include( GNUInstallDirs ) 87 | set( INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/ExchCXX ) 88 | 89 | # Targets 90 | install(TARGETS exchcxx 91 | EXPORT exchcxx-targets 92 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} 93 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} 94 | ) 95 | 96 | 97 | set_target_properties( exchcxx PROPERTIES EXPORT_NAME ExchCXX ) 98 | 99 | # Install Headers 100 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp" ) 101 | install(DIRECTORY ${PROJECT_BINARY_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.hpp" ) 102 | 103 | # Export target to script 104 | install(EXPORT exchcxx-targets 105 | FILE 106 | ExchCXXTargets.cmake 107 | NAMESPACE 108 | ExchCXX:: 109 | DESTINATION 110 | ${INSTALL_CONFIGDIR} 111 | ) 112 | 113 | # Export build-tree targets also (to be usable by e.g. FetchContent) 114 | export(EXPORT exchcxx-targets 115 | NAMESPACE ExchCXX:: 116 | FILE "${PROJECT_BINARY_DIR}/ExchCXXTargets.cmake") 117 | 118 | #Create a ConfigVersion.cmake file 119 | include(CMakePackageConfigHelpers) 120 | write_basic_package_version_file( 121 | ${CMAKE_CURRENT_BINARY_DIR}/ExchCXXConfigVersion.cmake 122 | VERSION ${PROJECT_VERSION} 123 | COMPATIBILITY AnyNewerVersion 124 | ) 125 | 126 | # Setup ExchCXXConfig.cmake 127 | configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/ExchCXXConfig.cmake.in 128 | ${CMAKE_CURRENT_BINARY_DIR}/ExchCXXConfig.cmake 129 | INSTALL_DESTINATION ${INSTALL_CONFIGDIR} 130 | ) 131 | 132 | #Install the config, configversion and custom find modules 133 | #install(DIRECTORY 134 | # ${PROJECT_SOURCE_DIR}/cmake/ 135 | # DESTINATION ${INSTALL_CONFIGDIR} 136 | # FILES_MATCHING PATTERN "*.cmake" 137 | #) 138 | 139 | install(FILES 140 | ${CMAKE_CURRENT_BINARY_DIR}/ExchCXXConfig.cmake 141 | ${CMAKE_CURRENT_BINARY_DIR}/ExchCXXConfigVersion.cmake 142 | DESTINATION ${INSTALL_CONFIGDIR} 143 | ) 144 | -------------------------------------------------------------------------------- /src/boilerplate.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #include 47 | #include 48 | 49 | namespace ExchCXX { 50 | 51 | static bool initialized_ = false; 52 | 53 | void initialize(Spin polar) { 54 | unused(polar); 55 | initialized_ = true; 56 | } 57 | 58 | void finalize() { 59 | initialized_ = false; 60 | } 61 | 62 | bool is_initialized(){ return initialized_; } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/builtin.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | namespace ExchCXX { 51 | 52 | XCKernel builtin_kernel_factory( Kernel kernel, Spin polar) { 53 | 54 | return XCKernel( 55 | std::make_unique< detail::BuiltinKernelInterface >( kernel, polar ) 56 | ); 57 | 58 | } 59 | 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/cuda/exchcxx_cuda.cmake: -------------------------------------------------------------------------------- 1 | set( EXCHCXX_CUDA_SOURCES 2 | cuda/xc_functional_device.cu 3 | cuda/builtin.cu 4 | ) 5 | if( EXCHCXX_ENABLE_LIBXC ) 6 | list(APPEND EXCHCXX_CUDA_SOURCES cuda/libxc_device.cxx) 7 | endif() 8 | 9 | find_package( CUDAToolkit REQUIRED ) 10 | #add_library( exchcxx_device OBJECT ${EXCHCXX_CUDA_SOURCES} ) 11 | #target_compile_features( exchcxx_device PUBLIC cuda_std_14 cxx_std_14 ) 12 | #target_compile_definitions( exchcxx_device PUBLIC "EXCHCXX_HAS_CONFIG_H=1" ) 13 | #target_link_libraries( exchcxx_device PUBLIC Libxc::xc CUDA::cudart ) 14 | # 15 | #target_include_directories( exchcxx_device 16 | # PRIVATE 17 | # $ 18 | # $ 19 | # $ 20 | # $ 21 | #) 22 | # 23 | #target_compile_options( exchcxx_device 24 | # PRIVATE 25 | # $<$: -Wall -Wextra -Wpedantic -Wnon-virtual-dtor> 26 | # $<$: -Xcudafe --diag_suppress=partial_override -Xptxas -v > 27 | #) 28 | 29 | target_sources( exchcxx PRIVATE ${EXCHCXX_CUDA_SOURCES} ) 30 | target_link_libraries( exchcxx PUBLIC CUDA::cudart ) 31 | target_compile_features( exchcxx PRIVATE cuda_std_14 ) 32 | target_compile_options( exchcxx 33 | PRIVATE 34 | $<$: -Xcudafe --diag_suppress=partial_override -Xptxas -v > 35 | ) 36 | -------------------------------------------------------------------------------- /src/hip/exchcxx_hip.cmake: -------------------------------------------------------------------------------- 1 | set( EXCHCXX_HIP_SOURCES 2 | hip/xc_functional_device.hip 3 | hip/builtin.hip 4 | ) 5 | if( EXCHCXX_ENABLE_LIBXC ) 6 | list(APPEND EXCHCXX_HIP_SOURCES hip/libxc_device.hip) 7 | endif() 8 | 9 | find_package( hip REQUIRED ) 10 | 11 | target_sources( exchcxx PRIVATE ${EXCHCXX_HIP_SOURCES} ) 12 | target_link_libraries( exchcxx PUBLIC hip::host ) 13 | -------------------------------------------------------------------------------- /src/libxc_common.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | #include 49 | #include 50 | 51 | #include 52 | namespace ExchCXX { 53 | 54 | static std::unordered_map< Spin, int > libxc_polar_map { 55 | { Spin::Polarized, XC_POLARIZED }, 56 | { Spin::Unpolarized, XC_UNPOLARIZED } 57 | }; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/sycl/exchcxx_sycl.cmake: -------------------------------------------------------------------------------- 1 | set( EXCHCXX_SYCL_SOURCES 2 | sycl/xc_functional_device.cxx 3 | sycl/builtin_sycl.cxx 4 | ) 5 | if( EXCHCXX_ENABLE_LIBXC ) 6 | list(APPEND EXCHCXX_SYCL_SOURCES sycl/libxc_device.cxx) 7 | endif() 8 | 9 | 10 | target_sources( exchcxx PRIVATE ${EXCHCXX_SYCL_SOURCES} ) 11 | 12 | list( APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ) 13 | find_package( SYCL REQUIRED ) 14 | target_link_libraries( exchcxx PUBLIC SYCL::SYCL ) 15 | 16 | include(CheckCXXCompilerFlag) 17 | check_cxx_compiler_flag("-fno-sycl-id-queries-fit-in-int" EXCHCXX_SYCL_ID_QUERIES_FIT_IN_INT ) 18 | check_cxx_compiler_flag("-fsycl-device-code-split=per_kernel" EXCHCXX_SYCL_DEVICE_CODE_SPLIT_PER_KERNEL ) 19 | check_cxx_compiler_flag("-fno-sycl-early-optimizations" EXCHCXX_SYCL_HAS_NO_EARLY_OPTIMIZATIONS ) 20 | 21 | 22 | if( EXCHCXX_SYCL_ID_QUERIES_FIT_IN_INT ) 23 | target_compile_options( exchcxx PRIVATE 24 | $<$: -fno-sycl-id-queries-fit-in-int> 25 | ) 26 | endif() 27 | 28 | if( EXCHCXX_SYCL_DEVICE_CODE_SPLIT_PER_KERNEL ) 29 | target_compile_options( exchcxx PRIVATE 30 | $<$: -fsycl-device-code-split=per_kernel> 31 | ) 32 | endif() 33 | 34 | if( EXCHCXX_SYCL_HAS_NO_EARLY_OPTIMIZATIONS ) 35 | target_compile_options( exchcxx PRIVATE 36 | $<$: -fno-sycl-early-optimizations> 37 | ) 38 | endif() 39 | -------------------------------------------------------------------------------- /src/xc_kernel.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | namespace ExchCXX { 51 | 52 | BidirectionalMap kernel_map{ 53 | {{"SlaterExchange", Kernel::SlaterExchange}, 54 | {"PBE_X", Kernel::PBE_X}, 55 | {"PBE_C", Kernel::PBE_C}, 56 | {"SCAN_X", Kernel::SCAN_X}, 57 | {"SCAN_C", Kernel::SCAN_C}, 58 | {"SCANL_C", Kernel::SCANL_C}, 59 | {"SCANL_X", Kernel::SCANL_X}, 60 | {"FT98_X", Kernel::FT98_X}, 61 | {"PC07_K", Kernel::PC07_K}, 62 | {"PC07OPT_K", Kernel::PC07OPT_K}, 63 | {"R2SCAN_X", Kernel::R2SCAN_X}, 64 | {"R2SCAN_C", Kernel::R2SCAN_C}, 65 | {"R2SCANL_X", Kernel::R2SCANL_X}, 66 | {"R2SCANL_C", Kernel::R2SCANL_C}, 67 | {"M062X_X", Kernel::M062X_X}, 68 | {"M062X_C", Kernel::M062X_C}, 69 | {"PKZB_X", Kernel::PKZB_X}, 70 | {"PKZB_C", Kernel::PKZB_C}, 71 | {"revPBE_X", Kernel::revPBE_X}, 72 | {"LYP", Kernel::LYP}, 73 | {"B3LYP", Kernel::B3LYP}, 74 | {"PBE0", Kernel::PBE0}, 75 | {"VWN3", Kernel::VWN3}, 76 | {"VWN5", Kernel::VWN5}, 77 | {"PZ81", Kernel::PZ81}, 78 | {"PZ81_MOD", Kernel::PZ81_MOD}, 79 | {"PW91_LDA", Kernel::PW91_LDA}, 80 | {"PW91_LDA_MOD", Kernel::PW91_LDA_MOD}, 81 | {"PW91_LDA_RPA", Kernel::PW91_LDA_RPA}, 82 | {"B88", Kernel::B88}, 83 | {"EPC17_1", Kernel::EPC17_1}, 84 | {"EPC17_2", Kernel::EPC17_2}, 85 | {"EPC18_1", Kernel::EPC18_1}, 86 | {"EPC18_2", Kernel::EPC18_2}}}; 87 | 88 | std::ostream& operator<<( std::ostream& out, Kernel kern ) { 89 | out << kernel_map.key(kern); 90 | return out; 91 | } 92 | 93 | XCKernel::XCKernel( 94 | const Backend backend, 95 | const Kernel kern, 96 | const Spin polar) : 97 | XCKernel( kernel_factory( backend, kern, polar ) ) { } 98 | 99 | #ifdef EXCHCXX_ENABLE_LIBXC 100 | XCKernel::XCKernel( 101 | const libxc_name_string& xc_name, 102 | const Spin polar) : 103 | XCKernel( libxc_kernel_factory( xc_name.get(), polar ) ) { } 104 | #endif 105 | 106 | 107 | XCKernel::XCKernel( impl_ptr&& ptr ) : 108 | pimpl_(std::move(ptr)) { } 109 | 110 | XCKernel::XCKernel( const XCKernel& other ) : 111 | pimpl_(other.pimpl_->clone()) { } 112 | 113 | XCKernel::XCKernel( XCKernel&& other ) noexcept = default; 114 | 115 | XCKernel& XCKernel::operator=( XCKernel&& other ) noexcept =default; 116 | 117 | 118 | XCKernel& XCKernel::operator=( const XCKernel& other ) { 119 | return *this = XCKernel(other); 120 | } 121 | 122 | XCKernel::~XCKernel() noexcept = default; 123 | 124 | } 125 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message(STATUS "Building ExchCXX Unit Tests" ) 2 | find_package( Catch2 CONFIG QUIET ) 3 | if( NOT Catch2_FOUND ) 4 | include( FetchContent ) 5 | FetchContent_Declare( 6 | catch2_download 7 | GIT_REPOSITORY https://github.com/catchorg/Catch2.git 8 | GIT_TAG v3.5.4 9 | ) 10 | if( NOT catch2_download_POPULATED ) 11 | FetchContent_Populate( catch2_download ) 12 | set(CATCH_BUILD_TESTING OFF CACHE BOOL "Build SelfTest project" FORCE) 13 | set(CATCH_INSTALL_DOCS OFF CACHE BOOL "Install documentation alongside library" FORCE) 14 | set(CATCH_INSTALL_HELPERS OFF CACHE BOOL "Install contrib alongside library" FORCE) 15 | add_subdirectory( ${catch2_download_SOURCE_DIR} ${catch2_download_BINARY_DIR} ) 16 | endif() 17 | endif() 18 | 19 | # Global Catch2 executable 20 | add_library( catch2_main STATIC ut_main.cxx) 21 | target_link_libraries( catch2_main PUBLIC Catch2::Catch2WithMain ) 22 | 23 | add_executable( xc_kernel_test xc_kernel_test.cxx reference_values.cxx ) 24 | target_link_libraries( xc_kernel_test PUBLIC exchcxx catch2_main ) 25 | target_compile_features( xc_kernel_test PRIVATE cxx_std_17 ) 26 | 27 | add_executable( xc_functional_test xc_functional_test.cxx ) 28 | target_link_libraries( xc_functional_test PUBLIC exchcxx catch2_main ) 29 | target_compile_features( xc_functional_test PRIVATE cxx_std_17 ) 30 | 31 | add_test( NAME XC_KERNEL COMMAND xc_kernel_test ) 32 | add_test( NAME XC_FUNCTIONAL COMMAND xc_functional_test ) 33 | -------------------------------------------------------------------------------- /test/boilerplate_test.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #include "catch2/catch.hpp" 47 | #include 48 | 49 | TEST_CASE( "ExchCXX Initialize / Finalize" ) { 50 | 51 | // Default is not initialized 52 | REQUIRE( !ExchCXX::is_initialized() ); 53 | 54 | // Make sure the initialization is toggled 55 | ExchCXX::initialize(ExchCXX::Spin::Unpolarized); 56 | REQUIRE( ExchCXX::is_initialized() ); 57 | 58 | // Make sure the initialiazation is reversable 59 | ExchCXX::finalize(); 60 | REQUIRE( !ExchCXX::is_initialized() ); 61 | 62 | } 63 | -------------------------------------------------------------------------------- /test/cmake/discovery/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.17 FATAL_ERROR ) 2 | project( exchcxx_cmake_discovery LANGUAGES C CXX ) 3 | 4 | find_package( ExchCXX REQUIRED ) 5 | add_executable( exchcxx_link_tester exchcxx_link_tester.cxx ) 6 | target_link_libraries( exchcxx_link_tester PUBLIC ExchCXX::ExchCXX ) 7 | -------------------------------------------------------------------------------- /test/cmake/discovery/exchcxx_link_tester.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /test/cmake/subproject/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required( VERSION 3.17 FATAL_ERROR ) 2 | project( exchcxx_cmake_subproject LANGUAGES C CXX ) 3 | 4 | 5 | if( NOT GIT_REVISION ) 6 | # Get current Git Revision 7 | find_package( Git REQUIRED ) 8 | execute_process( 9 | COMMAND ${GIT_EXECUTABLE} rev-parse HEAD 10 | OUTPUT_VARIABLE GIT_REVISION 11 | ERROR_QUIET 12 | ) 13 | string( STRIP "${GIT_REVISION}" GIT_REVISION ) 14 | endif() 15 | 16 | message( STATUS "Pulling GIT_REVISION = ${GIT_REVISION}" ) 17 | 18 | include( FetchContent ) 19 | set( FETCHCONTENT_SOURCE_DIR_EXCHCXX ${CMAKE_CURRENT_LIST_DIR}/../../.. ) 20 | FetchContent_Declare( exchcxx 21 | GIT_REPOSITORY https://github.com/wavefunction91/exchcxx.git 22 | GIT_TAG ${GIT_REVISION} 23 | ) 24 | FetchContent_MakeAvailable( exchcxx ) 25 | 26 | add_executable( exchcxx_link_tester exchcxx_link_tester.cxx ) 27 | target_link_libraries( exchcxx_link_tester PUBLIC ExchCXX::ExchCXX ) 28 | -------------------------------------------------------------------------------- /test/cmake/subproject/exchcxx_link_tester.cxx: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /test/reference_values.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | #pragma once 47 | #include 48 | #include 49 | #include 50 | 51 | 52 | struct lda_reference { 53 | int npts; 54 | std::vector rho; 55 | std::vector exc; 56 | std::vector vrho; 57 | }; 58 | 59 | struct gga_reference { 60 | int npts; 61 | std::vector rho; 62 | std::vector sigma; 63 | std::vector exc; 64 | std::vector vrho; 65 | std::vector vsigma; 66 | }; 67 | 68 | struct mgga_reference { 69 | int npts; 70 | std::vector rho; 71 | std::vector sigma; 72 | std::vector lapl; 73 | std::vector tau; 74 | std::vector exc; 75 | std::vector vrho; 76 | std::vector vsigma; 77 | std::vector vlapl; 78 | std::vector vtau; 79 | }; 80 | 81 | lda_reference load_lda_reference_values(ExchCXX::Kernel, ExchCXX::Spin); 82 | gga_reference load_gga_reference_values(ExchCXX::Kernel, ExchCXX::Spin); 83 | mgga_reference load_mgga_reference_values(ExchCXX::Kernel, ExchCXX::Spin, bool need_lap); 84 | 85 | lda_reference gen_lda_reference_values(ExchCXX::Backend, ExchCXX::Kernel, ExchCXX::Spin); 86 | gga_reference gen_gga_reference_values(ExchCXX::Backend, ExchCXX::Kernel, ExchCXX::Spin); 87 | mgga_reference gen_mgga_reference_values(ExchCXX::Backend, ExchCXX::Kernel, ExchCXX::Spin); 88 | 89 | std::pair> load_reference_density(ExchCXX::Spin); 90 | std::pair> load_reference_sigma(ExchCXX::Spin); 91 | std::pair> load_reference_lapl(ExchCXX::Spin); 92 | std::pair> load_reference_tau(ExchCXX::Spin); 93 | 94 | double load_reference_exx( ExchCXX::Kernel ); 95 | -------------------------------------------------------------------------------- /test/ut_main.cxx: -------------------------------------------------------------------------------- 1 | /** 2 | * ExchCXX Copyright (c) 2020-2022, The Regents of the University of California, 3 | * through Lawrence Berkeley National Laboratory (subject to receipt of 4 | * any required approvals from the U.S. Dept. of Energy). All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * (1) Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * (2) Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * (3) Neither the name of the University of California, Lawrence Berkeley 17 | * National Laboratory, U.S. Dept. of Energy nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | * POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * You are under no obligation whatsoever to provide any bug fixes, patches, 35 | * or upgrades to the features, functionality or performance of the source 36 | * code ("Enhancements") to anyone; however, if you choose to make your 37 | * Enhancements available either publicly, or directly to Lawrence Berkeley 38 | * National Laboratory, without imposing a separate written license agreement 39 | * for such Enhancements, then you hereby grant the following license: a 40 | * non-exclusive, royalty-free perpetual license to install, use, modify, 41 | * prepare derivative works, incorporate into other computer software, 42 | * distribute, and sublicense such enhancements or derivative works thereof, 43 | * in binary and source code form. 44 | */ 45 | 46 | // #define CATCH_CONFIG_MAIN 47 | #include "catch2/catch_all.hpp" 48 | --------------------------------------------------------------------------------