From 4903dbc40fe65f41d945a7597e7d02a4715df92e Mon Sep 17 00:00:00 2001 From: Cristian Le Date: Thu, 21 Nov 2024 13:18:00 +0100 Subject: [PATCH] Refactor CMake build system Signed-off-by: Cristian Le --- CMakeLists.txt | 536 ++------- c/CMakeLists.txt | 59 + ctest/CMakeLists.txt | 42 - ctest/README.md | 16 - ctest/fortran/CMakeLists.txt | 1 - ctest/fortran/gridsysf/CMakeLists.txt | 12 - ctest/fortran/gridsysf/test_gridsysf.f90 | 507 --------- ctest/test_gridsys.cpp | 1328 ---------------------- ctest/test_niggli.cpp | 46 - ctest/utils.c | 26 - ctest/utils.h | 5 - fortran/CMakeLists.txt | 24 - fortran/gridsysf.f90 | 224 ---- pyproject.toml | 2 +- 14 files changed, 160 insertions(+), 2668 deletions(-) create mode 100644 c/CMakeLists.txt delete mode 100644 ctest/CMakeLists.txt delete mode 100644 ctest/README.md delete mode 100644 ctest/fortran/CMakeLists.txt delete mode 100644 ctest/fortran/gridsysf/CMakeLists.txt delete mode 100644 ctest/fortran/gridsysf/test_gridsysf.f90 delete mode 100644 ctest/test_gridsys.cpp delete mode 100644 ctest/test_niggli.cpp delete mode 100644 ctest/utils.c delete mode 100644 ctest/utils.h delete mode 100644 fortran/CMakeLists.txt delete mode 100644 fortran/gridsysf.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index a4d236e2..1728e5de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,439 +1,103 @@ -cmake_minimum_required(VERSION 3.20) - -option(BUILD_PHPHCALC_LIB "Option to build phph calculation module" OFF) -option(BUILD_PHONONCALC_LIB "Option to build phonon calculation module" OFF) -option(BUILD_RECGRID_LIB "Option to build reciprocal space grid module" OFF) -option(BUILD_GRIDSYS_LIB "Option to build gridsys module" OFF) -option(PHONO3PY_WITH_Fortran "enable fortran interface" OFF) -option(PHONO3PY_USE_OMP "Option to search OpenMP library" ON) -option(PHONO3PY_USE_MTBLAS "Use multithread BLAS if it exists" ON) -option(PHONO3PY_WITH_TESTS "build unit tests" OFF) -option(BUILD_SHARED_LIBS "Option to build shared library" OFF) - -if(PHONO3PY_WITH_Fortran) - enable_language(Fortran) - set(BUILD_GRIDSYS_LIB ON) -endif() - -if(PHONO3PY_WITH_TESTS) - set(BUILD_SHARED_LIBS ON) - set(BUILD_GRIDSYS_LIB ON) -endif() - -if((NOT BUILD_PHPHCALC_LIB) - AND (NOT BUILD_PHONONCALC_LIB) - AND (NOT BUILD_GRIDSYS_LIB)) - set(BUILD_NANOBIND_MODULE ON) - message(STATUS "Build nanobind module of ${SKBUILD_PROJECT_NAME}") -else() - set(BUILD_NANOBIND_MODULE OFF) -endif() - -if(BUILD_NANOBIND_MODULE) - project(${SKBUILD_PROJECT_NAME}) - set(DEV_MODULE Development.Module) - find_package( - Python 3.8 REQUIRED - COMPONENTS Interpreter ${DEV_MODULE} - OPTIONAL_COMPONENTS Development.SABIModule) -else() - project(phono3py C) - set(CMAKE_MACOSX_RPATH 1) - set(CMAKE_C_FLAGS_RELEASE "-Wall -O2") - set(CMAKE_C_FLAGS_DEBUG "-g -DLAGWARNING -DTHMWARNING") - - # Version numbers - file(READ ${PROJECT_SOURCE_DIR}/phono3py/version.py version_file) - string(REGEX MATCH "__version__.*([0-9]+)[.]([0-9]+)[.]([0-9]+)" - phono3py_version ${version_file}) - set(MAJOR_VERSION ${CMAKE_MATCH_1}) - set(MINOR_VERSION ${CMAKE_MATCH_2}) - set(MICRO_VERSION ${CMAKE_MATCH_3}) - set(SERIAL "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}") - set(SOSERIAL "1") - include(GNUInstallDirs) -endif() - -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE - Release - CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" - "MinSizeRel" "RelWithDebInfo") -endif() +cmake_minimum_required(VERSION 3.25...3.31) + +#[=============================================================================[ +# Basic project definition # +]=============================================================================] + +list(APPEND CMAKE_MESSAGE_CONTEXT phonopy) +project(phono3py + VERSION ${SKBUILD_PROJECT_VERSION} + DESCRIPTION "A simulation package of phonon-phonon interaction related properties" + HOMEPAGE_URL https://github.com/phonopy/phono3py + LANGUAGES C CXX +) + +# Specify C/C++ standard used in the project. +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_C_EXTENSIONS OFF) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + + +#[=============================================================================[ +# Options # +]=============================================================================] + +include(CMakeDependentOption) +include(FeatureSummary) + +option(PHONO3PY_SHARED_LIBS "Phono3py: Build as a shared library" ${PROJECT_IS_TOP_LEVEL}) +option(PHONO3PY_USE_OMP "Phono3py: Build with OpenMP support" ON) +option(PHONO3PY_USE_MTBLAS "Phono3py: Use multithread BLAS if it exists" ON) + +if (DEFINED BUILD_PHPHCALC_LIB + OR DEFINED BUILD_PHONONCALC_LIB + OR DEFINED BUILD_RECGRID_LIB + OR DEFINED BUILD_GRIDSYS_LIB + OR DEFINED PHONO3PY_WITH_Fortran + OR DEFINED PHONO3PY_WITH_TESTS +) + if (PHONO3PY_IGNORE_OPTIONS) + set(message_type WARNING) + else () + set(message_type SEND_ERROR) + endif () + message(${message_type} + "You have set an option that has been removed\n" + "Please remove it or set PHONO3PY_IGNORE_OPTIONS to ignore this message\n" + "BUILD_PHPHCALC_LIB = ${BUILD_PHPHCALC_LIB}\n" + "BUILD_PHONONCALC_LIB = ${BUILD_PHONONCALC_LIB}\n" + "BUILD_RECGRID_LIB = ${BUILD_RECGRID_LIB}\n" + "BUILD_GRIDSYS_LIB = ${BUILD_GRIDSYS_LIB}\n" + "PHONO3PY_WITH_Fortran = ${PHONO3PY_WITH_Fortran}\n" + "PHONO3PY_WITH_TESTS = ${PHONO3PY_WITH_TESTS}" + ) + if (BUILD_GRIDSYS_LIB OR PHONO3PY_WITH_Fortran) + message(${message_type} + "The non-python libraries have been removed.\n" + "Please contact us and tell us where and how you are using it:\n" + "https://github.com/phonopy/phono3py" + ) + endif () +endif () + +#[=============================================================================[ +# Project configuration # +]=============================================================================] + +include(GNUInstallDirs) + +set(BUILD_SHARED_LIBS ${PHONO3PY_SHARED_LIBS}) message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") -message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") - -if(USE_CONDA_PATH AND DEFINED ENV{CONDA_PREFIX}) - message(STATUS "$ENV{CONDA_PREFIX}") - set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX}) - set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c) - link_directories($ENV{CONDA_PREFIX}/lib) -else() - set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c) -endif() - -if(PHONO3PY_USE_OMP) - message(STATUS "Find OpenMP library") - find_package(OpenMP) - - if(OpenMP_FOUND) - message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}") - message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}") - endif() -else() - message(STATUS "OpenMP is not used.") - set(OpenMP_FOUND OFF) # cmake-lint: disable=C0103 -endif() - -if(BUILD_PHPHCALC_LIB - OR BUILD_PHONONCALC_LIB - OR BUILD_NANOBIND_MODULE) - find_package(BLAS REQUIRED) # set BLAS_LIBRARIES - - if(BLAS_FOUND) - message(STATUS "BLAS libs: ${BLAS_LIBRARIES}") - message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}") - endif() - - find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES - - if(LAPACK_FOUND) - message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}") - message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}") - endif() - - if(BLAS_LIBRARIES MATCHES "libmkl") - message(STATUS "MKL detected: Set C-macro MKL_LAPACKE.") - - if(PHONO3PY_USE_MTBLAS) - message( - STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls." - ) - endif() - endif() - - if(BLAS_LIBRARIES MATCHES "libopenblas") - message(STATUS "OpenBLAS detected.") - - if(PHONO3PY_USE_MTBLAS) - message( - STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls." - ) - endif() - endif() -endif() - -# ################################################################################### -# Reciprocal space grid library # -# ################################################################################### -if(BUILD_RECGRID_LIB - OR BUILD_PHPHCALC_LIB - OR BUILD_NANOBIND_MODULE) - # Source code - set(SOURCES_PHPHCALC - ${PROJECT_SOURCE_DIR}/c/bzgrid.c ${PROJECT_SOURCE_DIR}/c/grgrid.c - ${PROJECT_SOURCE_DIR}/c/lagrid.c ${PROJECT_SOURCE_DIR}/c/snf3x3.c - ${PROJECT_SOURCE_DIR}/c/recgrid.c) - - if(BUILD_SHARED_LIBS) - # Shared library - add_library(recgrid_lib SHARED ${SOURCES_PHPHCALC}) - else() - # Static link library - add_library(recgrid_lib STATIC ${SOURCES_PHPHCALC}) - endif() - - if(NOT BUILD_NANOBIND_MODULE) - if(BUILD_SHARED_LIBS) - set_property(TARGET recgrid_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET recgrid_lib PROPERTY SOVERSION ${SOSERIAL}) - install(TARGETS recgrid_lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - set_property(TARGET recgrid_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET recgrid_lib PROPERTY SOVERSION ${SOSERIAL}) - set_property(TARGET recgrid_lib PROPERTY OUTPUT_NAME recgrid_lib) - install(TARGETS recgrid_lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - - # Header file - install(FILES ${PROJECT_SOURCE_DIR}/c/recgrid.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - endif() -endif() - -# ################################################################################### -# Ph-ph calculation library # -# ################################################################################### -if(BUILD_PHPHCALC_LIB OR BUILD_NANOBIND_MODULE) - # Source code - set(SOURCES_PHPHCALC - ${PROJECT_SOURCE_DIR}/c/collision_matrix.c - ${PROJECT_SOURCE_DIR}/c/fc3.c - ${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c - ${PROJECT_SOURCE_DIR}/c/interaction.c - ${PROJECT_SOURCE_DIR}/c/isotope.c - ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c - ${PROJECT_SOURCE_DIR}/c/phono3py.c - ${PROJECT_SOURCE_DIR}/c/funcs.c - ${PROJECT_SOURCE_DIR}/c/pp_collision.c - ${PROJECT_SOURCE_DIR}/c/real_self_energy.c - ${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c - ${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c - ${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c - ${PROJECT_SOURCE_DIR}/c/triplet.c - ${PROJECT_SOURCE_DIR}/c/triplet_grid.c - ${PROJECT_SOURCE_DIR}/c/triplet_iw.c) - - if(BUILD_SHARED_LIBS) - # Shared library - add_library(phphcalc_lib SHARED ${SOURCES_PHPHCALC}) - - if(OpenMP_FOUND) - target_link_libraries( - phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS LAPACK::LAPACK - OpenMP::OpenMP_C) - else() - target_link_libraries(phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS - LAPACK::LAPACK) - endif() - - target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES}) - - if(BLAS_LIBRARIES MATCHES "libmkl") - if(PHONO3PY_USE_MTBLAS) - target_compile_definitions( - phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS - THM_EPSILON=1e-10) - else() - target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE - THM_EPSILON=1e-10) - endif() - endif() - - if(BLAS_LIBRARIES MATCHES "libopenblas") - if(PHONO3PY_USE_MTBLAS) - target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS - THM_EPSILON=1e-10) - else() - target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10) - endif() - endif() - else() - # Static link library - add_library(phphcalc_lib STATIC ${SOURCES_PHPHCALC}) - - if(OpenMP_FOUND) - target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK - OpenMP::OpenMP_C) - else() - target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK) - endif() - - target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES}) - - if(BLAS_LIBRARIES MATCHES "libmkl") - if(PHONO3PY_USE_MTBLAS) - target_compile_definitions( - phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS - THM_EPSILON=1e-10) - else() - target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE - THM_EPSILON=1e-10) - endif() - endif() - - if(BLAS_LIBRARIES MATCHES "libopenblas") - if(PHONO3PY_USE_MTBLAS) - target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS - THM_EPSILON=1e-10) - else() - target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10) - endif() - endif() - endif() - - if(NOT BUILD_NANOBIND_MODULE) - if(BUILD_SHARED_LIBS) - set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL}) - install(TARGETS phphcalc_lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL}) - set_property(TARGET phphcalc_lib PROPERTY OUTPUT_NAME phphcalc_lib) - install(TARGETS phphcalc_lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - - # Header file - install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - endif() -endif() - -# ################################################################################### -# Phonon calculation library # -# ################################################################################### -if(BUILD_PHONONCALC_LIB OR BUILD_NANOBIND_MODULE) - # Source code - set(SOURCES_PHONONCALC - ${PROJECT_SOURCE_DIR}/c/dynmat.c ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c - ${PROJECT_SOURCE_DIR}/c/phonon.c ${PROJECT_SOURCE_DIR}/c/phononcalc.c) - - if(BUILD_SHARED_LIBS) - # Shared library - add_library(phononcalc_lib SHARED ${SOURCES_PHONONCALC}) - - if(OpenMP_FOUND) - target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK - OpenMP::OpenMP_C) - else() - target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK) - endif() - - target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES}) - - if(BLAS_LIBRARIES MATCHES "libmkl") - target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE - MULTITHREADED_BLAS) - endif() - - if(BLAS_LIBRARIES MATCHES "libopenblas") - target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS) - endif() - - else() - # Static link library - add_library(phononcalc_lib STATIC ${SOURCES_PHONONCALC}) - - if(OpenMP_FOUND) - target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK - OpenMP::OpenMP_C) - else() - target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK) - endif() - - target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES}) - - if(BLAS_LIBRARIES MATCHES "libmkl") - target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE - MULTITHREADED_BLAS) - endif() - - if(BLAS_LIBRARIES MATCHES "libopenblas") - target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS) - endif() - endif() - - if(NOT BUILD_NANOBIND_MODULE) - if(BUILD_SHARED_LIBS) - set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL}) - install(TARGETS phononcalc_lib - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - - else() - set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL}) - set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL}) - set_property(TARGET phononcalc_lib PROPERTY OUTPUT_NAME phononcalc_lib) - install(TARGETS phononcalc_lib - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - - # Header file - install(FILES ${PROJECT_SOURCE_DIR}/c/phononcalc.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) - endif() -endif() - -# ################################################################################### -# gridsys # -# ################################################################################### -if(BUILD_GRIDSYS_LIB) - # Source code - set(SOURCES_GRIDSYS - ${PROJECT_SOURCE_DIR}/c/bzgrid.c - ${PROJECT_SOURCE_DIR}/c/grgrid.c - ${PROJECT_SOURCE_DIR}/c/gridsys.c - ${PROJECT_SOURCE_DIR}/c/lagrid.c - ${PROJECT_SOURCE_DIR}/c/niggli.c - ${PROJECT_SOURCE_DIR}/c/funcs.c - ${PROJECT_SOURCE_DIR}/c/snf3x3.c - ${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c - ${PROJECT_SOURCE_DIR}/c/triplet.c - ${PROJECT_SOURCE_DIR}/c/triplet_grid.c - ${PROJECT_SOURCE_DIR}/c/triplet_iw.c) - - if(BUILD_SHARED_LIBS) - # Shared library - add_library(gridsys SHARED ${SOURCES_GRIDSYS}) - - if(OpenMP_FOUND) - target_link_libraries(gridsys PRIVATE OpenMP::OpenMP_C) - endif() - - target_include_directories(gridsys PRIVATE ${MY_INCLUDES}) - target_compile_definitions(gridsys PRIVATE THM_EPSILON=1e-10) - set_property(TARGET gridsys PROPERTY VERSION ${SERIAL}) - set_property(TARGET gridsys PROPERTY SOVERSION ${SOSERIAL}) - install(TARGETS gridsys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) - else() - # Static link library - add_library(gridsys_static STATIC ${SOURCES_GRIDSYS}) - - if(OpenMP_FOUND) - target_link_libraries(gridsys_static PRIVATE OpenMP::OpenMP_C) - endif() - - target_include_directories(gridsys_static PRIVATE ${MY_INCLUDES}) - target_compile_definitions(gridsys_static PRIVATE THM_EPSILON=1e-10) - set_property(TARGET gridsys_static PROPERTY VERSION ${SERIAL}) - set_property(TARGET gridsys_static PROPERTY SOVERSION ${SOSERIAL}) - set_property(TARGET gridsys_static PROPERTY OUTPUT_NAME gridsys) - install(TARGETS gridsys_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - endif() - - # Header file - install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -endif() - -if(PHONO3PY_WITH_Fortran) - add_subdirectory(fortran) -endif() - -if(PHONO3PY_WITH_TESTS) - if(PHONO3PY_WITH_Fortran) - set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran) - endif() - - add_subdirectory(ctest) -endif() - -if(BUILD_NANOBIND_MODULE) - set_target_properties(phphcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON) - set_target_properties(phononcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON) - - execute_process( - COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir - OUTPUT_STRIP_TRAILING_WHITESPACE - OUTPUT_VARIABLE NB_DIR) - list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}") - find_package(nanobind CONFIG REQUIRED) - nanobind_add_module(_phono3py STABLE_ABI ${PROJECT_SOURCE_DIR}/c/phono3py.h - ${PROJECT_SOURCE_DIR}/c/_phono3py.cpp) - nanobind_add_module(_phononcalc STABLE_ABI ${PROJECT_SOURCE_DIR}/c/phononcalc.h - ${PROJECT_SOURCE_DIR}/c/_phononcalc.cpp) - nanobind_add_module(_recgrid STABLE_ABI ${PROJECT_SOURCE_DIR}/c/recgrid.h - ${PROJECT_SOURCE_DIR}/c/_recgrid.cpp) - - target_link_libraries(_phono3py PRIVATE phphcalc_lib) - target_link_libraries(_phononcalc PRIVATE phononcalc_lib) - target_link_libraries(_recgrid PRIVATE recgrid_lib) - target_compile_definitions(_phono3py PRIVATE THM_EPSILON=1e-10) - install(TARGETS _phono3py LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) - install(TARGETS _phononcalc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) - install(TARGETS _recgrid LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) -endif() +#[=============================================================================[ +# External packages # +]=============================================================================] + +if (PHONOPY_USE_OMP) + find_package(OpenMP REQUIRED COMPONENTS C) +endif () +find_package(Python 3.9 REQUIRED + COMPONENTS Development.Module +) +find_package(nanobind REQUIRED CONFIG) + +find_package(BLAS REQUIRED) +find_package(LAPACK REQUIRED) + +#[=============================================================================[ +# Main definition # +]=============================================================================] + +add_library(phono3py_lib) +set_target_properties(phono3py_lib PROPERTIES + VERSION ${PROJECT_VERSION} + OUTPUT_NAME phono3py +) +nanobind_add_module(_phono3py) +nanobind_add_module(_phononcalc) +nanobind_add_module(_recgrid) +add_subdirectory(c) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt new file mode 100644 index 00000000..6691c764 --- /dev/null +++ b/c/CMakeLists.txt @@ -0,0 +1,59 @@ +target_sources(phono3py_lib PRIVATE + # Reciprocal space grid library + bzgrid.c + grgrid.c + lagrid.c + snf3x3.c + recgrid.c + # Ph-ph calculation library + collision_matrix.c + fc3.c + funcs.c + imag_self_energy_with_g.c + interaction.c + isotope.c + lapack_wrapper.c + phono3py.c + pp_collision.c + real_self_energy.c + real_to_reciprocal.c + reciprocal_to_normal.c + tetrahedron_method.c + triplet.c + triplet_grid.c + triplet_iw.c + # Phonon calculation library + dynmat.c + phonon.c + phononcalc.c + # gridsys + gridsys.c + niggli.c +) +target_sources(_phono3py PRIVATE _phono3py.cpp) +target_sources(_phononcalc PRIVATE _phononcalc.cpp) +target_sources(_recgrid PRIVATE _recgrid.cpp) +target_include_directories(phono3py_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(phono3py_lib PRIVATE + BLAS::BLAS + LAPACK::LAPACK + $<$:OpenMP::OpenMP_C> +) + +target_compile_definitions(phono3py_lib PRIVATE + THM_EPSILON=1e-10 + $<$:MULTITHREADED_BLAS> +) + +target_link_libraries(_phono3py PRIVATE + phono3py_lib +) +install(TARGETS phono3py_lib) +# Fix RPATH for unix systems +set_target_properties(_phono3py _phononcalc _recgrid PROPERTIES + INSTALL_RPATH "$,@loader_path,$ORIGIN>/${CMAKE_INSTALL_LIBDIR}" +) +# For windows systems we need to also install a copy of the dll files +install(TARGETS phono3py_lib RUNTIME DESTINATION .) +install(TARGETS _phono3py _phononcalc _recgrid DESTINATION .) diff --git a/ctest/CMakeLists.txt b/ctest/CMakeLists.txt deleted file mode 100644 index fec75cea..00000000 --- a/ctest/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -enable_language(CXX) -enable_testing() - -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -find_package(GTest) -if(NOT GTest_FOUND) - # pthread (required for GoogleTest) - # https://stackoverflow.com/questions/1620918/cmake-and-libpthread - set(THREADS_PREFER_PTHREAD_FLAG ON) - find_package(Threads REQUIRED) - - # Fetch GoogleTest - include(FetchContent) - - # cmake-lint inline directives must be specified at body scope. See - # https://cmake-format.readthedocs.io/en/latest/lint-inline.html - - # cmake-lint: disable=C0301 - FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a) - FetchContent_MakeAvailable(googletest) -endif() - -foreach(testcase IN ITEMS test_gridsys test_niggli) - add_executable(${testcase} ${CMAKE_CURRENT_SOURCE_DIR}/${testcase}.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/utils.c) - target_link_libraries( - ${testcase} - PUBLIC gridsys - PRIVATE GTest::gtest GTest::gtest_main) - target_include_directories(${testcase} PUBLIC ${PROJECT_SOURCE_DIR}/c - ${CMAKE_CURRENT_SOURCE_DIR}) - gtest_discover_tests(${testcase}) -endforeach() - -if(WITH_Fortran) - add_subdirectory(fortran) -endif() diff --git a/ctest/README.md b/ctest/README.md deleted file mode 100644 index 5dafb74f..00000000 --- a/ctest/README.md +++ /dev/null @@ -1,16 +0,0 @@ -This directory contains tests for grid system C-library. - -Grid system C-library and its tests are created and tested by - -```bash -mkdir build_gridsys && cd build_gridsys -cmake -DCMAKE_INSTALL_PREFIX=. -DWITH_TESTS=on -DGRIDSYS=on .. -cmake --build . -ctest -V --test-dir ctest -``` - -Specific test is performed by - -```bash -ctest -V --test-dir ctest -R test_gridsys.test_gridsys_get_grid_address_from_index -``` diff --git a/ctest/fortran/CMakeLists.txt b/ctest/fortran/CMakeLists.txt deleted file mode 100644 index 99d4d856..00000000 --- a/ctest/fortran/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(gridsysf) diff --git a/ctest/fortran/gridsysf/CMakeLists.txt b/ctest/fortran/gridsysf/CMakeLists.txt deleted file mode 100644 index db66c4b3..00000000 --- a/ctest/fortran/gridsysf/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(NAME gridsysf) - -add_executable(test_${NAME} test_${NAME}.f90) -target_link_libraries(test_${NAME} PRIVATE gridsysf) -# cmake-lint: disable=C0307 -set_target_properties(test_${NAME} PROPERTIES Fortran_MODULE_DIRECTORY - ${LIB_MOD_DIR}) - -add_test( - NAME ${NAME} - COMMAND $ ${CMAKE_CURRENT_BINARY_DIR} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/ctest/fortran/gridsysf/test_gridsysf.f90 b/ctest/fortran/gridsysf/test_gridsysf.f90 deleted file mode 100644 index 36f65927..00000000 --- a/ctest/fortran/gridsysf/test_gridsysf.f90 +++ /dev/null @@ -1,507 +0,0 @@ -program test_gridsysf - use, intrinsic :: iso_c_binding - use gridsysf, only: & - gridsys_get_grid_index_from_address, & - gridsys_rotate_grid_index, & - gridsys_get_double_grid_address, & - gridsys_get_grid_address_from_index, & - gridsys_get_double_grid_index, & - gridsys_get_bz_grid_addresses, & - gridsys_rotate_bz_grid_index, & - gridsys_get_triplets_at_q, & - gridsys_get_bz_triplets_at_q - implicit none - - integer(c_long) :: wurtzite_rec_rotations_without_time_reversal(3, 3, 12) - integer(c_long) :: wurtzite_tilde_rec_rotations_without_time_reversal(3, 3, 12) - - wurtzite_rec_rotations_without_time_reversal(:, :, :) = & - reshape([1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, -1, 0, 0, 0, 0, 1, & - 0, 1, 0, -1, -1, 0, 0, 0, 1, -1, 0, 0, 0, -1, 0, 0, 0, 1, & - -1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, 1, 1, 0, 0, 0, 1, & - 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, -1, 0, 0, 0, 1, & - 1, 0, 0, -1, -1, 0, 0, 0, 1, 0, -1, 0, -1, 0, 0, 0, 0, 1, & - -1, -1, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0, 1, 1, 0, 0, 0, 1], [3, 3, 12]) - - wurtzite_tilde_rec_rotations_without_time_reversal(:, :, :) = & - reshape([1, 0, 0, 0, 1, 0, 0, 0, 1, & - 1, -1, 0, -5, 0, -2, 0, 3, 1, & - 6, -1, 2, -5, -1, -2, -15, 3, -5, & - 11, 0, 4, 0, -1, 0, -30, 0, -11, & - 11, 1, 4, 5, 0, 2, -30, -3, -11, & - 6, 1, 2, 5, 1, 2, -15, -3, -5, & - 6, -1, 2, 5, 0, 2, -15, 3, -5, & - 1, -1, 0, 0, -1, 0, 0, 3, 1, & - 1, 0, 0, -5, -1, -2, 0, 0, 1, & - 6, 1, 2, -5, 0, -2, -15, -3, -5, & - 11, 1, 4, 0, 1, 0, -30, -3, -11, & - 11, 0, 4, 5, 1, 2, -30, 0, -11], [3, 3, 12]) - - write (*, '("[test_gridsys_get_grid_index_from_address]")') - call test_gridsys_get_grid_index_from_address() - write (*, '("[test_gridsys_rotate_grid_index]")') - call test_gridsys_rotate_grid_index() - write (*, '("[test_gridsys_rotate_bz_grid_index]")') - call test_gridsys_rotate_bz_grid_index() - write (*, '("[test_gridsys_get_bz_grid_addresses_wurtzite]")') - call test_gridsys_get_bz_grid_addresses_wurtzite() - write (*, '("[test_gridsys_get_triplets_at_q_wurtzite]")') - call test_gridsys_get_triplets_at_q_wurtzite() - write (*, '("[test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF]")') - call test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF() - -contains - subroutine test_gridsys_get_grid_index_from_address() bind(C) - integer(c_long) :: address(3) - integer(c_long) :: D_diag(3) - integer :: i, j, k, grid_index, ret_grid_index - - D_diag(:) = [3, 4, 5] - grid_index = 0 - do k = 0, D_diag(3) - 1 - address(3) = k - do j = 0, D_diag(2) - 1 - address(2) = j - do i = 0, D_diag(1) - 1 - address(1) = i - ret_grid_index = gridsys_get_grid_index_from_address(address, D_diag) - call assert_int(ret_grid_index, grid_index) - grid_index = grid_index + 1 - end do - end do - end do - write (*, '(" OK")') - end subroutine test_gridsys_get_grid_index_from_address - - subroutine test_gridsys_rotate_grid_index() bind(C) - integer(c_long) :: address(3), d_address(3), rot_address(3) - integer(c_long) :: D_diag(3, 2) - integer(c_long) :: PS(3, 2, 2) - integer(c_long) :: grid_index - integer(c_long) :: rotation(3, 3) - integer :: rot_grid_index, ref_rot_grid_index, i_tilde, i_ps, i_rot - - rotation(:, :) = reshape([0, 1, 0, -1, 0, 0, 0, 0, -1], [3, 3]) - D_diag(:, :) = reshape([1, 5, 15, 5, 5, 3], [3, 2]) - PS(:, :, :) = reshape([ & - 0, 0, 0, -2, 0, 5, 0, 0, 0, 0, 0, 1], & - [3, 2, 2]) - - do i_tilde = 1, 2 - do i_ps = 1, 2 - do i_rot = 1, 12 - if (i_tilde == 1) then - rotation(:, :) = & - wurtzite_tilde_rec_rotations_without_time_reversal(:, :, i_rot) - else - rotation(:, :) = & - wurtzite_rec_rotations_without_time_reversal(:, :, i_rot) - end if - do grid_index = 0, 74 - call gridsys_get_grid_address_from_index(address, grid_index, & - D_diag(:, i_tilde)) - call gridsys_get_double_grid_address(d_address, address, & - PS(:, i_ps, i_tilde)) - rot_address = matmul(transpose(rotation), d_address) - ref_rot_grid_index = gridsys_get_double_grid_index( & - rot_address, D_diag(:, i_tilde), & - PS(:, i_ps, i_tilde)) - rot_grid_index = gridsys_rotate_grid_index( & - grid_index, rotation, D_diag(:, i_tilde), & - PS(:, i_ps, i_tilde)) - call assert_int(rot_grid_index, ref_rot_grid_index) - end do - end do - end do - end do - write (*, '(" OK")') - end subroutine test_gridsys_rotate_grid_index - - subroutine test_gridsys_rotate_bz_grid_index() bind(C) - integer(c_long) :: d_address(3), rot_address(3), ref_d_address(3) - integer(c_long) :: D_diag(3, 2) - integer(c_long) :: PS(3, 2, 2) - integer(c_long) :: grid_index - integer(c_long) :: rotation(3, 3) - integer :: i_tilde, i_ps, i_rot, rot_bz_gp, bz_size - integer(c_long) :: Q(3, 3, 2) - real(c_double) :: rec_lattice(3, 3) - integer(c_long) :: bz_grid_addresses(3, 144) - integer(c_long) :: bz_map(76) - integer(c_long) :: bzg2grg(144) - - Q(:, :, :) = reshape([-1, 0, -6, 0, -1, 0, -1, 0, -5, & - 1, 0, 0, 0, 1, 0, 0, 0, 1], [3, 3, 2]) - rec_lattice(:, :) = reshape([0.3214400514304082, 0.0, 0.0, & - 0.1855835002216734, 0.3711670004433468, 0.0, & - 0.0, 0.0, 0.20088388911209323], [3, 3]) - D_diag(:, :) = reshape([1, 5, 15, 5, 5, 3], [3, 2]) - PS(:, :, :) = reshape([ & - 0, 0, 0, -2, 0, 5, 0, 0, 0, 0, 0, 1], & - [3, 2, 2]) - - do i_tilde = 1, 2 - do i_ps = 1, 2 - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, & - D_diag(:, i_tilde), Q(:, :, i_tilde), PS(:, i_ps, i_tilde), & - rec_lattice, int(2, c_long)) - do i_rot = 1, 12 - if (i_tilde == 1) then - rotation(:, :) = & - wurtzite_tilde_rec_rotations_without_time_reversal(:, :, i_rot) - else - rotation(:, :) = & - wurtzite_rec_rotations_without_time_reversal(:, :, i_rot) - end if - do grid_index = 0, 74 - call gridsys_get_double_grid_address( & - d_address, bz_grid_addresses(:, grid_index + 1), & - PS(:, i_ps, i_tilde)) - rot_address = matmul(transpose(rotation), d_address) - rot_bz_gp = gridsys_rotate_bz_grid_index( & - grid_index, rotation, & - bz_grid_addresses, bz_map, D_diag(:, i_tilde), & - PS(:, i_ps, i_tilde), int(2, c_long)); - call gridsys_get_double_grid_address( & - ref_d_address, & - bz_grid_addresses(:, rot_bz_gp + 1), PS(:, i_ps, i_tilde)) - call assert_1D_array_c_long(ref_d_address, rot_address, 3) - end do - end do - end do - end do - write (*, '(" OK")') - end subroutine test_gridsys_rotate_bz_grid_index - - subroutine test_gridsys_get_bz_grid_addresses_wurtzite() bind(C) - integer(c_long) :: bz_size - integer(c_long) :: PS(3), D_diag(3), Q(3, 3), bz_grid_addresses(3, 144) - integer(c_long) :: bz_map(76), bzg2grg(144) - real(c_double) :: rec_lattice(3, 3) - - integer(c_long) :: ref_bz_grid_addresses(3, 93) - integer(c_long) :: ref_bz_map(76) - integer(c_long) :: ref_bzg2grg(93) - - ref_bz_grid_addresses(:, :) = & - reshape([0, 0, 0, 1, 0, 0, 2, 0, 0, -2, 0, 0, -1, 0, 0, & - 0, 1, 0, 1, 1, 0, 2, 1, 0, -3, 1, 0, -2, 1, 0, & - -1, 1, 0, 0, 2, 0, 1, 2, 0, 1, -3, 0, 2, -3, 0, & - -3, 2, 0, -2, 2, 0, -1, 2, 0, 0, -2, 0, 1, -2, 0, & - 2, -2, 0, -2, 3, 0, 3, -2, 0, -1, -2, 0, -1, 3, 0, & - 0, -1, 0, 1, -1, 0, 2, -1, 0, -2, -1, 0, 3, -1, 0, & - -1, -1, 0, 0, 0, 1, 1, 0, 1, 2, 0, 1, -2, 0, 1, & - -1, 0, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1, -3, 1, 1, & - -2, 1, 1, -1, 1, 1, 0, 2, 1, 1, 2, 1, 1, -3, 1, & - 2, -3, 1, -3, 2, 1, -2, 2, 1, -1, 2, 1, 0, -2, 1, & - 1, -2, 1, 2, -2, 1, -2, 3, 1, 3, -2, 1, -1, -2, 1, & - -1, 3, 1, 0, -1, 1, 1, -1, 1, 2, -1, 1, -2, -1, 1, & - 3, -1, 1, -1, -1, 1, 0, 0, -1, 1, 0, -1, 2, 0, -1, & - -2, 0, -1, -1, 0, -1, 0, 1, -1, 1, 1, -1, 2, 1, -1, & - -3, 1, -1, -2, 1, -1, -1, 1, -1, 0, 2, -1, 1, 2, -1, & - 1, -3, -1, 2, -3, -1, -3, 2, -1, -2, 2, -1, -1, 2, -1, & - 0, -2, -1, 1, -2, -1, 2, -2, -1, -2, 3, -1, 3, -2, -1, & - -1, -2, -1, -1, 3, -1, 0, -1, -1, 1, -1, -1, 2, -1, -1, & - -2, -1, -1, 3, -1, -1, -1, -1, -1], [3, 93]) - ref_bz_map(:) = [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 16, & - 17, 18, 19, 20, 21, 23, 25, 26, 27, 28, 30, 31, 32, 33, & - 34, 35, 36, 37, 38, 40, 41, 42, 43, 45, 47, 48, 49, 50, & - 51, 52, 54, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, & - 68, 69, 71, 72, 73, 74, 76, 78, 79, 80, 81, 82, 83, 85, & - 87, 88, 89, 90, 92, 93] - ref_bzg2grg(:) = [ & - 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11, 12, 12, & - 13, 14, 15, 16, 17, 18, 18, 19, 19, 20, 21, 22, 23, 23, 24, 25, & - 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 36, 37, 37, 38, & - 39, 40, 41, 42, 43, 43, 44, 44, 45, 46, 47, 48, 48, 49, 50, 51, & - 52, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 61, 62, 62, 63, 64, & - 65, 66, 67, 68, 68, 69, 69, 70, 71, 72, 73, 73, 74] - - PS(:) = [0, 0, 0] - D_diag(:) = [5, 5, 3] - Q(:, :) = reshape([1, 0, 0, 0, 1, 0, 0, 0, 1], [3, 3]) - rec_lattice(:, :) = reshape([0.3214400514304082, 0.0, 0.0, & - 0.1855835002216734, 0.3711670004433468, 0.0, & - 0.0, 0.0, 0.20088388911209323], [3, 3]) - - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, & - D_diag, Q, PS, rec_lattice, int(2, c_long)) - - write (*, '("check bz_grid_addresses")', advance='no') - call assert_2D_array_c_long(bz_grid_addresses, ref_bz_grid_addresses, & - shape(ref_bz_grid_addresses)) - write (*, '(" OK")') - - write (*, '("check bz_map")', advance='no') - call assert_1D_array_c_long(bz_map, ref_bz_map, 76) - write (*, '(" OK")') - - write (*, '("check bzg2grg")', advance='no') - call assert_1D_array_c_long(bzg2grg, ref_bzg2grg, 93) - write (*, '(" OK")') - end subroutine test_gridsys_get_bz_grid_addresses_wurtzite - - subroutine test_gridsys_get_triplets_at_q_wurtzite() bind(C) - integer(c_long) :: D_diag(3) - integer(c_long) :: map_triplets(36), map_q(36) - integer(c_long) :: grid_point, is_time_reversal, num_rot, swappable - integer :: i, j, k, n_ir_triplets - - integer :: ref_num_triplets(4) - integer(c_long) :: ref_map_triplets(36, 4), ref_map_q(36, 4) - - grid_point = 1 - D_diag(:) = [3, 3, 4] - num_rot = 12 - ref_num_triplets(:) = [12, 18, 14, 24] - ref_map_triplets(:, :) = & - reshape([ & - 0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 9, 12, 12, 14, 14, 12, 12, & - 18, 19, 18, 21, 21, 23, 23, 21, 21, 9, 10, 9, 12, 12, 14, 14, 12, 12, & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 11, & - 12, 13, 14, 14, 12, 13, 18, 19, 18, 21, 21, 23, & - 23, 21, 21, 11, 10, 9, 13, 12, 14, 14, 13, 12, & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, & - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, & - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31 & - ], [36, 4]) - ref_map_q(:, :) = & - reshape([ & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, & - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, & - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31, & - 0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, & - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, & - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31], & - [36, 4]) - - k = 1 - do i = 0, 1 - do j = 0, 1 - is_time_reversal = 1 - i - swappable = 1 - j - n_ir_triplets = gridsys_get_triplets_at_q( & - map_triplets, map_q, grid_point, & - D_diag, is_time_reversal, num_rot, & - wurtzite_rec_rotations_without_time_reversal, & - swappable) - - call assert_int(n_ir_triplets, ref_num_triplets(k)) - write (*, '("check map_triplets")', advance='no') - call assert_1D_array_c_long(map_triplets, ref_map_triplets(:, k), 36) - write (*, '(" OK")') - write (*, '("check map_q")', advance='no') - call assert_1D_array_c_long(map_q, ref_map_q(:, k), 36) - write (*, '(" OK")') - k = k + 1 - end do - end do - end subroutine test_gridsys_get_triplets_at_q_wurtzite - - subroutine test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF() bind(C) - integer(c_long) :: D_diag(3) - integer(c_long) :: PS(3) - integer(c_long) :: Q(3, 3) - integer(c_long) :: map_triplets(75), map_q(75) - real(c_double) :: rec_lattice(3, 3) - integer(c_long) :: grid_point, is_time_reversal, num_rot, num_gp, swappable - integer :: i, j, k, num_triplets_1, num_triplets_2, bz_size, i_grgp - integer(c_long) :: triplets(3, 75) - integer(c_long) :: bz_grid_addresses(3, 108) - integer(c_long) :: bz_map(75) - integer(c_long) :: bzg2grg(108) - - integer :: ref_num_triplets(4, 2) - integer(c_long) :: ref_triplets(3, 45, 4, 2) - integer(c_long) :: ref_ir_weights(45, 4, 2) - integer :: shape_of_array(2) - integer :: grgp(2) - - grgp(:) = [1, 7] - ref_num_triplets(:, :) = reshape([18, 24, 30, 45, 24, 24, 45, 45], [4, 2]) - ref_triplets(:, :, :, :) = & - reshape([ & - 1, 0, 4, 1, 1, 3, 1, 2, 2, 1, 5, 91, 1, 7, 90, & - 1, 10, 87, 1, 12, 85, 1, 13, 84, 1, 14, 83, 1, 18, 79, & - 1, 19, 77, 1, 23, 74, 1, 31, 66, 1, 32, 65, 1, 33, 64, & - 1, 36, 60, 1, 38, 59, 1, 41, 56, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 0, 4, 1, 1, 3, 1, 2, 2, 1, 5, 91, 1, 7, 90, & - 1, 8, 88, 1, 10, 87, 1, 11, 86, 1, 12, 85, 1, 13, 84, & - 1, 14, 83, 1, 15, 81, 1, 17, 80, 1, 18, 79, 1, 19, 77, & - 1, 23, 74, 1, 31, 66, 1, 32, 65, 1, 33, 64, 1, 34, 63, & - 1, 35, 62, 1, 36, 60, 1, 38, 59, 1, 41, 56, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 0, 4, 1, 1, 3, 1, 2, 2, 1, 3, 1, 1, 4, 0, & - 1, 5, 91, 1, 7, 90, 1, 8, 88, 1, 10, 87, 1, 11, 86, & - 1, 12, 85, 1, 13, 84, 1, 14, 83, 1, 15, 81, 1, 17, 80, & - 1, 18, 79, 1, 19, 77, 1, 21, 76, 1, 22, 75, 1, 23, 74, & - 1, 31, 66, 1, 32, 65, 1, 33, 64, 1, 34, 63, 1, 35, 62, & - 1, 36, 60, 1, 38, 59, 1, 39, 57, 1, 41, 56, 1, 42, 55, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 0, 4, 1, 1, 3, 1, 2, 2, 1, 3, 1, 1, 4, 0, & - 1, 5, 91, 1, 7, 90, 1, 8, 88, 1, 10, 87, 1, 11, 86, & - 1, 12, 85, 1, 13, 84, 1, 14, 83, 1, 15, 81, 1, 17, 80, & - 1, 18, 79, 1, 19, 77, 1, 21, 76, 1, 22, 75, 1, 23, 74, & - 1, 31, 66, 1, 32, 65, 1, 33, 64, 1, 34, 63, 1, 35, 62, & - 1, 36, 60, 1, 38, 59, 1, 39, 57, 1, 41, 56, 1, 42, 55, & - 1, 43, 54, 1, 44, 53, 1, 45, 52, 1, 46, 50, 1, 48, 49, & - 1, 62, 35, 1, 63, 34, 1, 64, 33, 1, 65, 32, 1, 66, 31, & - 1, 67, 29, 1, 69, 28, 1, 70, 26, 1, 72, 25, 1, 73, 24, & - 8, 0, 89, 8, 1, 88, 8, 2, 87, 8, 3, 86, 9, 4, 92, & - 8, 5, 84, 8, 6, 82, 8, 8, 81, 8, 10, 80, 8, 11, 85, & - 8, 12, 78, 8, 13, 76, 8, 14, 75, 8, 17, 79, 8, 19, 71, & - 8, 20, 69, 9, 22, 67, 8, 24, 65, 8, 27, 62, 8, 29, 66, & - 8, 31, 58, 8, 32, 57, 8, 40, 50, 8, 48, 48, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 8, 0, 89, 8, 1, 88, 8, 2, 87, 8, 3, 86, 9, 4, 92, & - 8, 5, 84, 8, 6, 82, 8, 8, 81, 8, 10, 80, 8, 11, 85, & - 8, 12, 78, 8, 13, 76, 8, 14, 75, 8, 17, 79, 8, 19, 71, & - 8, 20, 69, 9, 22, 67, 8, 24, 65, 8, 27, 62, 8, 29, 66, & - 8, 31, 58, 8, 32, 57, 8, 40, 50, 8, 48, 48, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 8, 0, 89, 8, 1, 88, 8, 2, 87, 8, 3, 86, 9, 4, 92, & - 8, 5, 84, 8, 6, 82, 8, 8, 81, 8, 10, 80, 8, 11, 85, & - 8, 12, 78, 8, 13, 76, 8, 14, 75, 8, 16, 74, 8, 17, 79, & - 8, 19, 71, 8, 20, 69, 9, 22, 67, 9, 23, 73, 8, 24, 65, & - 8, 25, 64, 8, 27, 62, 8, 29, 66, 8, 31, 58, 8, 32, 57, & - 8, 33, 56, 8, 34, 55, 8, 40, 50, 9, 41, 49, 9, 42, 54, & - 8, 43, 46, 8, 44, 45, 8, 48, 48, 8, 50, 40, 8, 51, 38, & - 9, 53, 36, 8, 58, 31, 9, 61, 35, 8, 62, 27, 8, 63, 26, & - 8, 71, 19, 9, 72, 18, 8, 79, 17, 8, 81, 8, 8, 89, 0, & - 8, 0, 89, 8, 1, 88, 8, 2, 87, 8, 3, 86, 9, 4, 92, & - 8, 5, 84, 8, 6, 82, 8, 8, 81, 8, 10, 80, 8, 11, 85, & - 8, 12, 78, 8, 13, 76, 8, 14, 75, 8, 16, 74, 8, 17, 79, & - 8, 19, 71, 8, 20, 69, 9, 22, 67, 9, 23, 73, 8, 24, 65, & - 8, 25, 64, 8, 27, 62, 8, 29, 66, 8, 31, 58, 8, 32, 57, & - 8, 33, 56, 8, 34, 55, 8, 40, 50, 9, 41, 49, 9, 42, 54, & - 8, 43, 46, 8, 44, 45, 8, 48, 48, 8, 50, 40, 8, 51, 38, & - 9, 53, 36, 8, 58, 31, 9, 61, 35, 8, 62, 27, 8, 63, 26, & - 8, 71, 19, 9, 72, 18, 8, 79, 17, 8, 81, 8, 8, 89, 0 & - ], & - [3, 45, 4, 2]) - - ref_ir_weights(:, :, :) = & - reshape([ & - 2, 2, 1, 8, 4, 8, 4, 8, 8, 4, 4, 2, 4, 4, 2, 4, 2, 4, 0, 0, 0, 0, 0, & - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 2, 2, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 4, 2, & - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, & - 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, & - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, & - 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 4, & - 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 4, & - 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, & - 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 2, & - 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, & - 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, & - 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1 & - ], [45, 4, 2]) - - num_rot = 12 - num_gp = 75 - D_diag(:) = [1, 5, 15] - PS(:) = [0, 0, 0] - Q(:, :) = reshape([-1, 0, -6, 0, -1, 0, -1, 0, -5], [3, 3]) - rec_lattice(:, :) = reshape([0.3214400514304082, 0.0, 0.0, & - 0.1855835002216734, 0.3711670004433468, 0.0, & - 0.0, 0.0, 0.20088388911209323], [3, 3]) - - bz_size = gridsys_get_bz_grid_addresses( & - bz_grid_addresses, bz_map, bzg2grg, & - D_diag, Q, PS, rec_lattice, int(2, c_long)) - call assert_int(bz_size, 93) - do i_grgp = 1, 2 - grid_point = grgp(i_grgp) - i = 1 - do j = 0, 1 - swappable = 1 - j - do k = 0, 1 - is_time_reversal = 1 - k - num_triplets_1 = gridsys_get_triplets_at_q( & - map_triplets, map_q, grid_point, D_diag, & - is_time_reversal, num_rot, & - wurtzite_tilde_rec_rotations_without_time_reversal, swappable) - num_triplets_2 = gridsys_get_bz_triplets_at_q( & - triplets, bz_map(grid_point + 1), bz_grid_addresses, bz_map, & - map_triplets, num_gp, D_diag, Q, int(2, c_long)) - write (*, '("swappable:", i0, ", is_time_reversal:", i0)', advance='no') swappable, is_time_reversal - call assert_int(num_triplets_1, num_triplets_2) - call assert_int(num_triplets_1, ref_num_triplets(i, i_grgp)) - shape_of_array(:) = [3, num_triplets_2] - call assert_2D_array_c_long( & - triplets, ref_triplets(:, :, i, i_grgp), shape_of_array) - write (*, '(" OK")') - i = i + 1 - end do - end do - end do - - end subroutine test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF - - subroutine assert_int(val, ref_val) - integer, intent(in) :: val, ref_val - if (val /= ref_val) then - print '()' - print '(i0, "/=", i0)', val, ref_val - error stop - end if - end subroutine assert_int - - subroutine assert_1D_array_c_long(vals, ref_vals, size_of_array) - integer(c_long), intent(in) :: vals(:) - integer(c_long), intent(in) :: ref_vals(:) - integer, intent(in) :: size_of_array - integer :: i - - do i = 1, size_of_array - if (vals(i) /= ref_vals(i)) then - print '()' - print '(i0, ":", i0, " ", i0)', i, vals(i), ref_vals(i) - error stop - end if - end do - end subroutine assert_1D_array_c_long - - subroutine assert_2D_array_c_long(vals, ref_vals, shape_of_array) - integer(c_long), intent(in) :: vals(:, :) - integer(c_long), intent(in) :: ref_vals(:, :) - integer, intent(in) :: shape_of_array(:) - integer :: i, j - - do i = 1, shape_of_array(1) - do j = 1, shape_of_array(2) - if (vals(j, i) /= ref_vals(j, i)) then - print '()' - print '("(", i0, ",", i0, "):", i0, " ", i0)', i, j, vals(j, i), ref_vals(j, i) - error stop - end if - end do - end do - end subroutine assert_2D_array_c_long - -end program test_gridsysf diff --git a/ctest/test_gridsys.cpp b/ctest/test_gridsys.cpp deleted file mode 100644 index 0135ed36..00000000 --- a/ctest/test_gridsys.cpp +++ /dev/null @@ -1,1328 +0,0 @@ -#include - -extern "C" { -#include - -#include "gridsys.h" -#include "lagrid.h" -#include "utils.h" -} - -// Point group operations of rutile {R^T} -const long rutile_rec_rotations[16][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, - {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, {{0, -1, 0}, {1, 0, 0}, {0, 0, -1}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, - {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {-1, 0, 0}, {0, 0, -1}}, - {{1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{0, -1, 0}, {-1, 0, 0}, {0, 0, -1}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, {{1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, -1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}}; - -// Symmetry operations of rutile 1x1x2 {R} -const long rutile112_symmetry_operations[32][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, - {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {-1, 0, 0}, {0, 0, -1}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, - {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, {{0, -1, 0}, {1, 0, 0}, {0, 0, -1}}, - {{1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{0, -1, 0}, {-1, 0, 0}, {0, 0, -1}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, {{1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, -1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, - {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {-1, 0, 0}, {0, 0, -1}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, - {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, {{0, -1, 0}, {1, 0, 0}, {0, 0, -1}}, - {{1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{-1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{0, -1, 0}, {-1, 0, 0}, {0, 0, -1}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, {{1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, -1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}}; - -// Point group operations of wurtzite {R^T} (with time reversal) -const long wurtzite_rec_rotations_with_time_reversal[24][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{1, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{0, 1, 0}, {-1, -1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{-1, -1, 0}, {1, 0, 0}, {0, 0, 1}}, {{0, -1, 0}, {1, 1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, {{1, 1, 0}, {0, -1, 0}, {0, 0, 1}}, - {{1, 0, 0}, {-1, -1, 0}, {0, 0, 1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{-1, -1, 0}, {0, 1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {1, 1, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{-1, -1, 0}, {1, 0, 0}, {0, 0, -1}}, - {{0, -1, 0}, {1, 1, 0}, {0, 0, -1}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, - {{1, 1, 0}, {-1, 0, 0}, {0, 0, -1}}, {{0, 1, 0}, {-1, -1, 0}, {0, 0, -1}}, - {{0, -1, 0}, {-1, 0, 0}, {0, 0, -1}}, {{-1, -1, 0}, {0, 1, 0}, {0, 0, -1}}, - {{-1, 0, 0}, {1, 1, 0}, {0, 0, -1}}, {{0, 1, 0}, {1, 0, 0}, {0, 0, -1}}, - {{1, 1, 0}, {0, -1, 0}, {0, 0, -1}}, {{1, 0, 0}, {-1, -1, 0}, {0, 0, -1}}}; - -// Point group operations of wurtzite {R^T} (without time reversal) -const long wurtzite_rec_rotations_without_time_reversal[12][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{1, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{0, 1, 0}, {-1, -1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{-1, -1, 0}, {1, 0, 0}, {0, 0, 1}}, {{0, -1, 0}, {1, 1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, {{1, 1, 0}, {0, -1, 0}, {0, 0, 1}}, - {{1, 0, 0}, {-1, -1, 0}, {0, 0, 1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{-1, -1, 0}, {0, 1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {1, 1, 0}, {0, 0, 1}}}; - -// Transformed point group operations of wurtzite {R^T} (without time reversal) -// D_diag=[1, 5, 15], Q=[[-1, 0, -6], [0, -1, 0], [-1, 0, -5]] -// P=[[1, 0, -2], [0, -1, 0], [-3, 0, 5]] -const long wurtzite_tilde_rec_rotations_without_time_reversal[12][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{1, -1, 0}, {-5, 0, -2}, {0, 3, 1}}, - {{6, -1, 2}, {-5, -1, -2}, {-15, 3, -5}}, - {{11, 0, 4}, {0, -1, 0}, {-30, 0, -11}}, - {{11, 1, 4}, {5, 0, 2}, {-30, -3, -11}}, - {{6, 1, 2}, {5, 1, 2}, {-15, -3, -5}}, - {{6, -1, 2}, {5, 0, 2}, {-15, 3, -5}}, - {{1, -1, 0}, {0, -1, 0}, {0, 3, 1}}, - {{1, 0, 0}, {-5, -1, -2}, {0, 0, 1}}, - {{6, 1, 2}, {-5, 0, -2}, {-15, -3, -5}}, - {{11, 1, 4}, {0, 1, 0}, {-30, -3, -11}}, - {{11, 0, 4}, {5, 1, 2}, {-30, 0, -11}}}; - -// Symmetry operations of wurtzite 1x1x2 {R} -const long wurtzite112_symmetry_operations[24][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{1, -1, 0}, {1, 0, 0}, {0, 0, 1}}, - {{0, -1, 0}, {1, -1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{-1, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {-1, 1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, {{1, 0, 0}, {1, -1, 0}, {0, 0, 1}}, - {{1, -1, 0}, {0, -1, 0}, {0, 0, 1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {-1, 1, 0}, {0, 0, 1}}, {{-1, 1, 0}, {0, 1, 0}, {0, 0, 1}}, - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{1, -1, 0}, {1, 0, 0}, {0, 0, 1}}, - {{0, -1, 0}, {1, -1, 0}, {0, 0, 1}}, {{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}}, - {{-1, 1, 0}, {-1, 0, 0}, {0, 0, 1}}, {{0, 1, 0}, {-1, 1, 0}, {0, 0, 1}}, - {{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}, {{1, 0, 0}, {1, -1, 0}, {0, 0, 1}}, - {{1, -1, 0}, {0, -1, 0}, {0, 0, 1}}, {{0, -1, 0}, {-1, 0, 0}, {0, 0, 1}}, - {{-1, 0, 0}, {-1, 1, 0}, {0, 0, 1}}, {{-1, 1, 0}, {0, 1, 0}, {0, 0, 1}}}; - -const long AgNO2_rec_rotations[8][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 1, 0}, {1, 0, 0}, {-1, -1, -1}}, - {{1, 1, 1}, {0, 0, -1}, {0, -1, 0}}, {{0, 0, -1}, {1, 1, 1}, {-1, 0, 0}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{0, -1, 0}, {-1, 0, 0}, {1, 1, 1}}, - {{-1, -1, -1}, {0, 0, 1}, {0, 1, 0}}, {{0, 0, 1}, {-1, -1, -1}, {1, 0, 0}}}; - -const long AgNO2_tilde_rec_rotations[8][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{5, -12, -2}, {12, -25, -4}, {-60, 120, 19}}, - {{1, 0, 0}, {0, 11, 2}, {0, -60, -11}}, - {{5, -12, -2}, {12, -35, -6}, {-60, 180, 31}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, - {{-5, 12, 2}, {-12, 25, 4}, {60, -120, -19}}, - {{-1, 0, 0}, {0, -11, -2}, {0, 60, 11}}, - {{-5, 12, 2}, {-12, 35, 6}, {60, -180, -31}}}; - -const long AgNO2_tilde_rec_rotations_with_time_reversal_mesh12[8][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{1, 0, 0}, {0, -1, 0}, {4, 0, -1}}, - {{1, 0, 0}, {0, 1, 0}, {4, 4, -1}}, {{1, 0, 0}, {0, -1, 0}, {0, -4, 1}}, - {{-1, 0, 0}, {0, -1, 0}, {0, 0, -1}}, {{-1, 0, 0}, {0, 1, 0}, {-4, 0, 1}}, - {{-1, 0, 0}, {0, -1, 0}, {-4, -4, 1}}, {{-1, 0, 0}, {0, 1, 0}, {0, 4, -1}}, -}; - -// D_diag=[2, 2, 8], Q=[[0, 0, 1], [1, 0, -1], [0, 1, -1]] -const long AgNO2_tilde_rec_rotations_without_time_reversal_mesh12[4][3][3] = { - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, - {{1, 0, 0}, {0, -1, 0}, {4, 0, -1}}, - {{1, 0, 0}, {0, 1, 0}, {4, 4, -1}}, - {{1, 0, 0}, {0, -1, 0}, {0, -4, 1}}}; - -/** - * @brief gridsys_get_all_grid_addresses test - * Return all GR-grid addresses of {(x, y, z)} where x runs fastest. - */ -TEST(test_gridsys, test_gridsys_get_all_grid_addresses) { - long(*gr_grid_addresses)[3]; - long D_diag[3] = {3, 4, 5}; - long n, i, j, k; - long grid_index = 0; - - n = D_diag[0] * D_diag[1] * D_diag[2]; - gr_grid_addresses = (long(*)[3])malloc(sizeof(long[3]) * n); - gridsys_get_all_grid_addresses(gr_grid_addresses, D_diag); - - for (k = 0; k < D_diag[2]; k++) { - for (j = 0; j < D_diag[1]; j++) { - for (i = 0; i < D_diag[0]; i++) { - ASSERT_EQ(gr_grid_addresses[grid_index][0], i); - ASSERT_EQ(gr_grid_addresses[grid_index][1], j); - ASSERT_EQ(gr_grid_addresses[grid_index][2], k); - grid_index++; - } - } - } - free(gr_grid_addresses); - gr_grid_addresses = NULL; -} - -/** - * @brief gridsys_get_double_grid_address - * Return double grid address of single grid address with shift in GR-grid. - * PS can be other than 0 and 1 for non-diagonal grid matrix. - */ -TEST(test_gridsys, test_gridsys_get_double_grid_address) { - long address_double[3]; - long address[3] = {1, 2, 3}; - long PS[8][3] = {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, - {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}}; - long i, j; - - for (i = 0; i < 8; i++) { - gridsys_get_double_grid_address(address_double, address, PS[i]); - for (j = 0; j < 3; j++) { - ASSERT_EQ(address_double[j], address[j] * 2 + PS[i][j]); - } - } -} - -/** - * @brief gridsys_get_grid_address_from_index - * Return single grid address of grid point index in GR-grid. See the definition - * of grid point index at gridsys_get_all_grid_addresses. - */ -TEST(test_gridsys, test_gridsys_get_grid_address_from_index) { - long address[3]; - long D_diag[3] = {3, 4, 5}; - long i, j, k, ll; - long grid_index = 0; - - for (k = 0; k < D_diag[2]; k++) { - for (j = 0; j < D_diag[1]; j++) { - for (i = 0; i < D_diag[0]; i++) { - gridsys_get_grid_address_from_index(address, grid_index, - D_diag); - for (ll = 0; ll < 3; ll++) { - ASSERT_EQ(address[0], i); - ASSERT_EQ(address[1], j); - ASSERT_EQ(address[2], k); - } - grid_index++; - } - } - } -} - -/** - * @brief gridsys_get_double_grid_index - * Return grid point index corresponding to double grid address in GR-grid. - */ -TEST(test_gridsys, test_gridsys_get_double_grid_index) { - long address_double[3], address[3]; - long D_diag[3] = {3, 4, 5}; - long PS[8][3] = {{0, 0, 0}, {0, 0, 3}, {0, 3, 0}, {0, 3, 3}, - {3, 0, 0}, {3, 0, 3}, {3, 3, 0}, {3, 3, 3}}; - long i, j, k, ll, grid_index; - - for (ll = 0; ll < 8; ll++) { - grid_index = 0; - for (k = 0; k < D_diag[2]; k++) { - address[2] = k; - for (j = 0; j < D_diag[1]; j++) { - address[1] = j; - for (i = 0; i < D_diag[0]; i++) { - address[0] = i; - gridsys_get_double_grid_address(address_double, address, - PS[ll]); - ASSERT_EQ(grid_index, gridsys_get_double_grid_index( - address_double, D_diag, PS[ll])); - grid_index++; - } - } - } - } -} - -/** - * @brief gridsys_get_grid_index_from_address - * Return grid point index corresponding to grid address in GR-grid. - */ -TEST(test_gridsys, test_gridsys_get_grid_index_from_address) { - long address[3]; - long D_diag[3] = {3, 4, 5}; - long i, j, k; - long grid_index = 0; - - for (k = 0; k < D_diag[2]; k++) { - address[2] = k; - for (j = 0; j < D_diag[1]; j++) { - address[1] = j; - for (i = 0; i < D_diag[0]; i++) { - address[0] = i; - ASSERT_EQ(grid_index, - gridsys_get_grid_index_from_address(address, D_diag)); - grid_index++; - } - } - } -} - -/** - * @brief gridsys_rotate_grid_index - * Return grid point index of rotated address of given grid point index. - */ -TEST(test_gridsys, test_gridsys_rotate_grid_index) { - long D_diag[2][3] = {{1, 5, 15}, {5, 5, 3}}; - long PS[2][2][3] = {{{0, 0, 0}, {-2, 0, 5}}, {{0, 0, 0}, {0, 0, 1}}}; - long address[3], rot_address[3], d_address[3]; - long i, j, k, ll, i_rot, i_tilde, i_ps, grid_index; - long rec_rotations[2][12][3][3]; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - for (k = 0; k < 3; k++) { - for (ll = 0; ll < 3; ll++) { - if (i == 0) { - rec_rotations[i][j][k][ll] = - wurtzite_tilde_rec_rotations_without_time_reversal - [j][k][ll]; - } else { - rec_rotations[i][j][k][ll] = - wurtzite_rec_rotations_without_time_reversal[j][k] - [ll]; - } - } - } - } - } - - for (i_tilde = 0; i_tilde < 1; i_tilde++) { - for (i_ps = 0; i_ps < 2; i_ps++) { - for (i_rot = 0; i_rot < 12; i_rot++) { - for (grid_index = 0; grid_index < 75; grid_index++) { - gridsys_get_grid_address_from_index(address, grid_index, - D_diag[i_tilde]); - gridsys_get_double_grid_address(d_address, address, - PS[i_tilde][i_ps]); - lagmat_multiply_matrix_vector_l3( - rot_address, rec_rotations[i_tilde][i_rot], d_address); - ASSERT_EQ( - (gridsys_get_double_grid_index( - rot_address, D_diag[i_tilde], PS[i_tilde][i_ps])), - (gridsys_rotate_grid_index( - grid_index, rec_rotations[i_tilde][i_rot], - D_diag[i_tilde], PS[i_tilde][i_ps]))); - } - } - } - } -} - -/** - * @brief gridsys_rotate_bz_grid_index - * Return bz grid point index of rotated bz address of given bz grid point - * index. - */ -TEST(test_gridsys, test_gridsys_rotate_bz_grid_index) { - long D_diag[2][3] = {{1, 5, 15}, {5, 5, 3}}; - long PS[2][2][3] = {{{0, 0, 0}, {-2, 0, 5}}, {{0, 0, 0}, {0, 0, 1}}}; - long address[3], rot_address[3], d_address[3], ref_d_address[3]; - long i, j, k, ll, i_rot, i_tilde, i_ps, grid_index, rot_bz_gp, bz_size; - long rec_rotations[2][12][3][3]; - long bz_grid_addresses[144][3]; - long bz_map[76]; - long bzg2grg[144]; - long Q[2][3][3] = {{{-1, 0, -6}, {0, -1, 0}, {-1, 0, -5}}, - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}; - double rec_lattice[3][3] = {{0.3214400514304082, 0.0, 0.0}, - {0.18558350022167336, 0.37116700044334666, 0.0}, - {0.0, 0.0, 0.20088388911209318}}; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - for (k = 0; k < 3; k++) { - for (ll = 0; ll < 3; ll++) { - if (i == 0) { - rec_rotations[i][j][k][ll] = - wurtzite_tilde_rec_rotations_without_time_reversal - [j][k][ll]; - } else { - rec_rotations[i][j][k][ll] = - wurtzite_rec_rotations_without_time_reversal[j][k] - [ll]; - } - } - } - } - } - - for (i_tilde = 0; i_tilde < 1; i_tilde++) { - for (i_ps = 0; i_ps < 2; i_ps++) { - bz_size = gridsys_get_bz_grid_addresses( - bz_grid_addresses, bz_map, bzg2grg, D_diag[i_tilde], Q[i_tilde], - PS[i_tilde][i_ps], rec_lattice, 2); - for (i_rot = 0; i_rot < 12; i_rot++) { - for (grid_index = 0; grid_index < bz_size; grid_index++) { - gridsys_get_double_grid_address( - d_address, bz_grid_addresses[grid_index], - PS[i_tilde][i_ps]); - lagmat_multiply_matrix_vector_l3( - rot_address, rec_rotations[i_tilde][i_rot], d_address); - rot_bz_gp = gridsys_rotate_bz_grid_index( - grid_index, rec_rotations[i_tilde][i_rot], - bz_grid_addresses, bz_map, D_diag[i_tilde], - PS[i_tilde][i_ps], 2); - gridsys_get_double_grid_address( - ref_d_address, bz_grid_addresses[rot_bz_gp], - PS[i_tilde][i_ps]); - // printf("[%d-%d-%d-%d]\n", i_tilde, i_ps, i_rot, - // grid_index); - for (i = 0; i < 3; i++) { - // printf("%d | %d | %d\n", d_address[i], - // ref_d_address[i], - // rot_address[i]); - ASSERT_EQ(ref_d_address[i], rot_address[i]); - } - // printf("------\n"); - } - } - } - } -} - -/** - * @brief gridsys_get_reciprocal_point_group with rutile symmetry - * Return {R^T} of crystallographic point group {R} with and without time - * reversal symmetry. - */ -TEST(test_gridsys, test_gridsys_get_reciprocal_point_group_rutile) { - long i, j, num_R; - long rec_rotations[48][3][3]; - long is_time_reversal, is_found; - - for (is_time_reversal = 0; is_time_reversal < 2; is_time_reversal++) { - num_R = gridsys_get_reciprocal_point_group( - rec_rotations, rutile112_symmetry_operations, 32, is_time_reversal); - ASSERT_EQ(16, num_R); - for (i = 0; i < 16; i++) { - is_found = 0; - for (j = 0; j < 16; j++) { - if (lagmat_check_identity_matrix_l3(rec_rotations[i], - rutile_rec_rotations[j])) { - is_found = 1; - break; - } - } - ASSERT_TRUE(is_found); - } - } -} - -/** - * @brief gridsys_get_reciprocal_point_group with wurtzite symmetry - * Return {R^T} of crystallographic point group {R} with and without time - * reversal symmetry. - */ -TEST(test_gridsys, test_gridsys_get_reciprocal_point_group_wurtzite) { - long i, j, k, num_R; - long rec_rotations[48][3][3]; - long is_found; - - // Without time reversal symmetry. - num_R = gridsys_get_reciprocal_point_group( - rec_rotations, wurtzite112_symmetry_operations, 24, 0); - ASSERT_EQ(12, num_R); - for (i = 0; i < 12; i++) { - is_found = 0; - for (j = 0; j < 12; j++) { - if (lagmat_check_identity_matrix_l3( - rec_rotations[i], - wurtzite_rec_rotations_without_time_reversal[j])) { - is_found = 1; - break; - } - } - ASSERT_TRUE(is_found); - } - - // With time reversal symmetry. - num_R = gridsys_get_reciprocal_point_group( - rec_rotations, wurtzite112_symmetry_operations, 24, 1); - ASSERT_EQ(24, num_R); - for (i = 0; i < 24; i++) { - is_found = 0; - for (j = 0; j < 24; j++) { - if (lagmat_check_identity_matrix_l3( - rec_rotations[i], - wurtzite_rec_rotations_with_time_reversal[j])) { - is_found = 1; - break; - } - } - ASSERT_TRUE(is_found); - } -} - -/** - * @brief gridsys_get_snf3x3 (1) - * Return D, P, Q of SNF. - */ -TEST(test_gridsys, test_gridsys_get_snf3x3) { - long D_diag[3], P[3][3], Q[3][3]; - long A[3][3] = {{0, 16, 16}, {16, 0, 16}, {6, 6, 0}}; - const long ref_P[3][3] = {{0, -1, 3}, {1, 0, 0}, {-3, 3, -8}}; - const long ref_Q[3][3] = {{1, 8, 17}, {0, 0, -1}, {0, 1, 1}}; - long succeeded; - - succeeded = gridsys_get_snf3x3(D_diag, P, Q, A); - ASSERT_TRUE(succeeded); - ASSERT_EQ(2, D_diag[0]); - ASSERT_EQ(16, D_diag[1]); - ASSERT_EQ(96, D_diag[2]); - ASSERT_TRUE(lagmat_check_identity_matrix_l3(ref_P, P)); - ASSERT_TRUE(lagmat_check_identity_matrix_l3(ref_Q, Q)); -} - -/** - * @brief gridsys_get_snf3x3 (AgNO2) - * Return D, P, Q of SNF. - */ -TEST(test_gridsys, test_gridsys_get_snf3x3_AgNO2) { - long D_diag[3], P[3][3], Q[3][3]; - long A[3][3] = {{0, 5, 5}, {2, 0, 2}, {3, 3, 0}}; - const long ref_P[3][3] = {{0, -1, 1}, {-1, -3, 2}, {6, 15, -10}}; - const long ref_Q[3][3] = {{1, -3, -31}, {0, 1, 11}, {0, 0, 1}}; - long succeeded; - - succeeded = gridsys_get_snf3x3(D_diag, P, Q, A); - ASSERT_TRUE(succeeded); - ASSERT_EQ(1, D_diag[0]); - ASSERT_EQ(1, D_diag[1]); - ASSERT_EQ(60, D_diag[2]); - ASSERT_TRUE(lagmat_check_identity_matrix_l3(ref_P, P)); - ASSERT_TRUE(lagmat_check_identity_matrix_l3(ref_Q, Q)); -} - -/** - * @brief gridsys_transform_rotations - * Transform {R^T} to {R^T} with respect to transformed microzone basis - * vectors in GR-grid - */ -TEST(test_gridsys, test_gridsys_transform_rotations) { - long transformed_rotations[8][3][3]; - const long D_diag[3] = {1, 1, 60}; - const long Q[3][3] = {{1, -3, -31}, {0, 1, 11}, {0, 0, 1}}; - long i, j, is_found, succeeded; - - succeeded = gridsys_transform_rotations(transformed_rotations, - AgNO2_rec_rotations, 8, D_diag, Q); - ASSERT_TRUE(succeeded); - for (i = 0; i < 8; i++) { - is_found = 0; - for (j = 0; j < 8; j++) { - if (lagmat_check_identity_matrix_l3(AgNO2_tilde_rec_rotations[j], - transformed_rotations[i])) { - is_found = 1; - break; - } - } - ASSERT_TRUE(is_found); - } -} - -/** - * @brief gridsys_get_thm_integration_weight - * Return integration weight of linear tetrahedron method - */ -TEST(test_gridsys, test_gridsys_get_thm_integration_weight) { - const double freqs_at[2] = {7.75038996, 8.45225776}; - const double tetra_freqs[24][4] = { - {8.31845176, 8.69248151, 8.78939432, 8.66179133}, - {8.31845176, 8.69248151, 8.57211855, 8.66179133}, - {8.31845176, 8.3073908, 8.78939432, 8.66179133}, - {8.31845176, 8.3073908, 8.16360975, 8.66179133}, - {8.31845176, 8.15781566, 8.57211855, 8.66179133}, - {8.31845176, 8.15781566, 8.16360975, 8.66179133}, - {8.31845176, 8.3073908, 8.16360975, 7.23665561}, - {8.31845176, 8.15781566, 8.16360975, 7.23665561}, - {8.31845176, 8.69248151, 8.57211855, 8.25247917}, - {8.31845176, 8.15781566, 8.57211855, 8.25247917}, - {8.31845176, 8.15781566, 7.40609306, 8.25247917}, - {8.31845176, 8.15781566, 7.40609306, 7.23665561}, - {8.31845176, 8.69248151, 8.78939432, 8.55165578}, - {8.31845176, 8.3073908, 8.78939432, 8.55165578}, - {8.31845176, 8.3073908, 7.56474684, 8.55165578}, - {8.31845176, 8.3073908, 7.56474684, 7.23665561}, - {8.31845176, 8.69248151, 8.60076148, 8.55165578}, - {8.31845176, 8.69248151, 8.60076148, 8.25247917}, - {8.31845176, 7.72920193, 8.60076148, 8.55165578}, - {8.31845176, 7.72920193, 8.60076148, 8.25247917}, - {8.31845176, 7.72920193, 7.56474684, 8.55165578}, - {8.31845176, 7.72920193, 7.56474684, 7.23665561}, - {8.31845176, 7.72920193, 7.40609306, 8.25247917}, - {8.31845176, 7.72920193, 7.40609306, 7.23665561}, - }; - const double iw_I_ref[2] = {0.37259443, 1.79993056}; - const double iw_J_ref[2] = {0.05740597, 0.76331859}; - double iw_I, iw_J; - long i; - - for (i = 0; i < 2; i++) { - ASSERT_LT((fabs(gridsys_get_thm_integration_weight(freqs_at[i], - tetra_freqs, 'I') - - iw_I_ref[i])), - 1e-5); - ASSERT_LT((fabs(gridsys_get_thm_integration_weight(freqs_at[i], - tetra_freqs, 'J') - - iw_J_ref[i])), - 1e-5); - } -} - -/** - * @brief gridsys_get_thm_relative_grid_address - * Return relative grid addresses for linear tetrahedron method. - */ -TEST(test_gridsys, test_gridsys_get_thm_relative_grid_address) { - long all_rel_grid_address[4][24][4][3]; - long rel_grid_addresses[24][4][3]; - double rec_vectors[4][3][3] = {{{-1, 1, 1}, {1, -1, 1}, {1, 1, -1}}, - {{-1, -1, -1}, {1, 1, -1}, {1, -1, 1}}, - {{1, 1, -1}, {-1, -1, -1}, {-1, 1, 1}}, - {{1, -1, 1}, {-1, 1, 1}, {-1, -1, -1}}}; - long i, j, k, ll, main_diagonal; - - gridsys_get_thm_all_relative_grid_address(all_rel_grid_address); - for (i = 0; i < 4; i++) { - main_diagonal = gridsys_get_thm_relative_grid_address( - rel_grid_addresses, rec_vectors[i]); - ASSERT_EQ(i, main_diagonal); - for (j = 0; j < 24; j++) { - for (k = 0; k < 4; k++) { - for (ll = 0; ll < 3; ll++) { - ASSERT_EQ(all_rel_grid_address[i][j][k][ll], - rel_grid_addresses[j][k][ll]); - } - } - } - } -} - -/** - * @brief gridsys_get_ir_grid_map tested by rutile rotations - * Return grid point mapping table to ir-grid points - */ -TEST(test_gridsys, test_gridsys_get_ir_grid_map_rutile) { - long *ir_grid_map; - long n, i, j; - long D_diag[3] = {4, 4, 6}; - long PS[4][3] = {{0, 0, 0}, {1, 1, 0}, {0, 0, 1}, {1, 1, 1}}; - - long ref_ir_grid_maps[4][96] = { - {0, 1, 2, 1, 1, 5, 6, 5, 2, 6, 10, 6, 1, 5, 6, 5, - 16, 17, 18, 17, 17, 21, 22, 21, 18, 22, 26, 22, 17, 21, 22, 21, - 32, 33, 34, 33, 33, 37, 38, 37, 34, 38, 42, 38, 33, 37, 38, 37, - 48, 49, 50, 49, 49, 53, 54, 53, 50, 54, 58, 54, 49, 53, 54, 53, - 32, 33, 34, 33, 33, 37, 38, 37, 34, 38, 42, 38, 33, 37, 38, 37, - 16, 17, 18, 17, 17, 21, 22, 21, 18, 22, 26, 22, 17, 21, 22, 21}, - {0, 1, 1, 0, 1, 5, 5, 1, 1, 5, 5, 1, 0, 1, 1, 0, - 16, 17, 17, 16, 17, 21, 21, 17, 17, 21, 21, 17, 16, 17, 17, 16, - 32, 33, 33, 32, 33, 37, 37, 33, 33, 37, 37, 33, 32, 33, 33, 32, - 48, 49, 49, 48, 49, 53, 53, 49, 49, 53, 53, 49, 48, 49, 49, 48, - 32, 33, 33, 32, 33, 37, 37, 33, 33, 37, 37, 33, 32, 33, 33, 32, - 16, 17, 17, 16, 17, 21, 21, 17, 17, 21, 21, 17, 16, 17, 17, 16}, - {0, 1, 2, 1, 1, 5, 6, 5, 2, 6, 10, 6, 1, 5, 6, 5, - 16, 17, 18, 17, 17, 21, 22, 21, 18, 22, 26, 22, 17, 21, 22, 21, - 32, 33, 34, 33, 33, 37, 38, 37, 34, 38, 42, 38, 33, 37, 38, 37, - 32, 33, 34, 33, 33, 37, 38, 37, 34, 38, 42, 38, 33, 37, 38, 37, - 16, 17, 18, 17, 17, 21, 22, 21, 18, 22, 26, 22, 17, 21, 22, 21, - 0, 1, 2, 1, 1, 5, 6, 5, 2, 6, 10, 6, 1, 5, 6, 5}, - {0, 1, 1, 0, 1, 5, 5, 1, 1, 5, 5, 1, 0, 1, 1, 0, - 16, 17, 17, 16, 17, 21, 21, 17, 17, 21, 21, 17, 16, 17, 17, 16, - 32, 33, 33, 32, 33, 37, 37, 33, 33, 37, 37, 33, 32, 33, 33, 32, - 32, 33, 33, 32, 33, 37, 37, 33, 33, 37, 37, 33, 32, 33, 33, 32, - 16, 17, 17, 16, 17, 21, 21, 17, 17, 21, 21, 17, 16, 17, 17, 16, - 0, 1, 1, 0, 1, 5, 5, 1, 1, 5, 5, 1, 0, 1, 1, 0}}; - - n = D_diag[0] * D_diag[1] * D_diag[2]; - ir_grid_map = (long *)malloc(sizeof(long) * n); - - for (i = 0; i < 4; i++) { - gridsys_get_ir_grid_map(ir_grid_map, rutile_rec_rotations, 16, D_diag, - PS[i]); - for (j = 0; j < n; j++) { - ASSERT_EQ(ref_ir_grid_maps[i][j], ir_grid_map[j]); - } - } - - free(ir_grid_map); - ir_grid_map = NULL; -} - -/** - * @brief gridsys_get_ir_grid_map tested by wurtzite rotations - * Return grid point mapping table to ir-grid points - */ -TEST(test_gridsys, test_gridsys_get_ir_grid_map_wurtzite) { - long *ir_grid_map; - long n, i, j; - long D_diag[3] = {5, 5, 4}; - long PS[2][3] = {{0, 0, 0}, {0, 0, 1}}; - - long ref_ir_grid_maps[2][100] = { - {0, 1, 2, 2, 1, 1, 6, 7, 6, 1, 2, 7, 7, 2, 6, 2, 6, - 2, 7, 7, 1, 1, 6, 7, 6, 25, 26, 27, 27, 26, 26, 31, 32, 31, - 26, 27, 32, 32, 27, 31, 27, 31, 27, 32, 32, 26, 26, 31, 32, 31, 50, - 51, 52, 52, 51, 51, 56, 57, 56, 51, 52, 57, 57, 52, 56, 52, 56, 52, - 57, 57, 51, 51, 56, 57, 56, 25, 26, 27, 27, 26, 26, 31, 32, 31, 26, - 27, 32, 32, 27, 31, 27, 31, 27, 32, 32, 26, 26, 31, 32, 31}, - {0, 1, 2, 2, 1, 1, 6, 7, 6, 1, 2, 7, 7, 2, 6, 2, 6, - 2, 7, 7, 1, 1, 6, 7, 6, 25, 26, 27, 27, 26, 26, 31, 32, 31, - 26, 27, 32, 32, 27, 31, 27, 31, 27, 32, 32, 26, 26, 31, 32, 31, 25, - 26, 27, 27, 26, 26, 31, 32, 31, 26, 27, 32, 32, 27, 31, 27, 31, 27, - 32, 32, 26, 26, 31, 32, 31, 0, 1, 2, 2, 1, 1, 6, 7, 6, 1, - 2, 7, 7, 2, 6, 2, 6, 2, 7, 7, 1, 1, 6, 7, 6}}; - - n = D_diag[0] * D_diag[1] * D_diag[2]; - ir_grid_map = (long *)malloc(sizeof(long) * n); - - for (i = 0; i < 2; i++) { - gridsys_get_ir_grid_map(ir_grid_map, - wurtzite_rec_rotations_with_time_reversal, 24, - D_diag, PS[i]); - for (j = 0; j < n; j++) { - ASSERT_EQ(ref_ir_grid_maps[i][j], ir_grid_map[j]); - } - } - - free(ir_grid_map); - ir_grid_map = NULL; -} - -/** - * @brief gridsys_get_bz_grid_addresses by FCC - * Return BZ grid addresses - */ -TEST(test_gridsys, test_gridsys_get_bz_grid_addresses_FCC) { - long D_diag[3] = {4, 4, 4}; - long ref_bz_addresses[89][3] = { - {0, 0, 0}, {1, 0, 0}, {-2, 0, 0}, {2, 0, 0}, {-1, 0, 0}, - {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {-1, 1, 0}, {0, -2, 0}, - {0, 2, 0}, {1, 2, 0}, {-2, -2, 0}, {2, 2, 0}, {-1, -2, 0}, - {0, -1, 0}, {1, -1, 0}, {-2, -1, 0}, {-1, -1, 0}, {0, 0, 1}, - {1, 0, 1}, {2, 0, 1}, {-1, 0, 1}, {0, 1, 1}, {1, 1, 1}, - {2, 1, 1}, {-1, 1, 1}, {0, 2, 1}, {1, 2, 1}, {2, 2, 1}, - {-1, -2, 1}, {-1, -2, -3}, {-1, 2, 1}, {3, 2, 1}, {0, -1, 1}, - {1, -1, 1}, {-2, -1, 1}, {-2, -1, -3}, {2, -1, 1}, {2, 3, 1}, - {-1, -1, 1}, {0, 0, -2}, {0, 0, 2}, {1, 0, 2}, {-2, 0, -2}, - {2, 0, 2}, {-1, 0, -2}, {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, - {-1, 1, -2}, {-1, 1, 2}, {-1, -3, -2}, {3, 1, 2}, {0, -2, -2}, - {0, 2, 2}, {1, 2, 2}, {-2, -2, -2}, {2, 2, 2}, {-1, -2, -2}, - {0, -1, -2}, {1, -1, -2}, {1, -1, 2}, {1, 3, 2}, {-3, -1, -2}, - {-2, -1, -2}, {-1, -1, -2}, {0, 0, -1}, {1, 0, -1}, {-2, 0, -1}, - {-1, 0, -1}, {0, 1, -1}, {1, 1, -1}, {-2, 1, -1}, {-2, -3, -1}, - {2, 1, -1}, {2, 1, 3}, {-1, 1, -1}, {0, -2, -1}, {1, -2, -1}, - {1, 2, -1}, {1, 2, 3}, {-3, -2, -1}, {-2, -2, -1}, {-1, -2, -1}, - {0, -1, -1}, {1, -1, -1}, {-2, -1, -1}, {-1, -1, -1}, - }; - long ref_bz_map[65] = {0, 1, 2, 4, 5, 6, 7, 8, 9, 11, 12, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - 29, 30, 34, 35, 36, 40, 41, 43, 44, 46, 47, 48, 49, - 50, 54, 56, 57, 59, 60, 61, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 77, 78, 79, 83, 84, 85, 86, 87, 88, 89}; - long ref_bzg2grg[89] = { - 0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 27, 27, 27, 28, 29, - 30, 30, 30, 30, 31, 32, 32, 33, 34, 34, 35, 36, 37, 38, 39, 39, 39, 39, - 40, 40, 41, 42, 42, 43, 44, 45, 45, 45, 45, 46, 47, 48, 49, 50, 51, 52, - 53, 54, 54, 54, 54, 55, 56, 57, 57, 57, 57, 58, 59, 60, 61, 62, 63}; - double rec_lattice[3][3] = {{-1, 1, 1}, {1, -1, 1}, {1, 1, -1}}; - long PS[3] = {0, 0, 0}; - long Q[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; - long bz_grid_addresses[125][3]; - long bz_map[65]; - long bzg2grg[125]; - long bz_size, i, j; - - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, - D_diag, Q, PS, rec_lattice, 2); - ASSERT_EQ(89, bz_size); - for (i = 0; i < 89; i++) { - for (j = 0; j < 3; j++) { - ASSERT_EQ(ref_bz_addresses[i][j], bz_grid_addresses[i][j]); - } - } - for (i = 0; i < 65; i++) { - ASSERT_EQ(ref_bz_map[i], bz_map[i]); - } - for (i = 0; i < 89; i++) { - ASSERT_EQ(ref_bzg2grg[i], bzg2grg[i]); - } -} - -/** - * @brief gridsys_get_bz_grid_addresses by wurtzite - * Return BZ grid addresses - */ -TEST(test_gridsys, test_gridsys_get_bz_grid_addresses_wurtzite_553) { - long ref_bz_addresses[93][3] = { - {0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {-2, 0, 0}, {-1, 0, 0}, - {0, 1, 0}, {1, 1, 0}, {2, 1, 0}, {-3, 1, 0}, {-2, 1, 0}, - {-1, 1, 0}, {0, 2, 0}, {1, 2, 0}, {1, -3, 0}, {2, -3, 0}, - {-3, 2, 0}, {-2, 2, 0}, {-1, 2, 0}, {0, -2, 0}, {1, -2, 0}, - {2, -2, 0}, {-2, 3, 0}, {3, -2, 0}, {-1, -2, 0}, {-1, 3, 0}, - {0, -1, 0}, {1, -1, 0}, {2, -1, 0}, {-2, -1, 0}, {3, -1, 0}, - {-1, -1, 0}, {0, 0, 1}, {1, 0, 1}, {2, 0, 1}, {-2, 0, 1}, - {-1, 0, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1}, {-3, 1, 1}, - {-2, 1, 1}, {-1, 1, 1}, {0, 2, 1}, {1, 2, 1}, {1, -3, 1}, - {2, -3, 1}, {-3, 2, 1}, {-2, 2, 1}, {-1, 2, 1}, {0, -2, 1}, - {1, -2, 1}, {2, -2, 1}, {-2, 3, 1}, {3, -2, 1}, {-1, -2, 1}, - {-1, 3, 1}, {0, -1, 1}, {1, -1, 1}, {2, -1, 1}, {-2, -1, 1}, - {3, -1, 1}, {-1, -1, 1}, {0, 0, -1}, {1, 0, -1}, {2, 0, -1}, - {-2, 0, -1}, {-1, 0, -1}, {0, 1, -1}, {1, 1, -1}, {2, 1, -1}, - {-3, 1, -1}, {-2, 1, -1}, {-1, 1, -1}, {0, 2, -1}, {1, 2, -1}, - {1, -3, -1}, {2, -3, -1}, {-3, 2, -1}, {-2, 2, -1}, {-1, 2, -1}, - {0, -2, -1}, {1, -2, -1}, {2, -2, -1}, {-2, 3, -1}, {3, -2, -1}, - {-1, -2, -1}, {-1, 3, -1}, {0, -1, -1}, {1, -1, -1}, {2, -1, -1}, - {-2, -1, -1}, {3, -1, -1}, {-1, -1, -1}}; - long ref_bz_map[76] = {0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, - 16, 17, 18, 19, 20, 21, 23, 25, 26, 27, 28, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 40, 41, 42, 43, 45, 47, - 48, 49, 50, 51, 52, 54, 56, 57, 58, 59, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 76, 78, 79, - 80, 81, 82, 83, 85, 87, 88, 89, 90, 92, 93}; - long ref_bzg2grg[93] = { - 0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11, 12, 12, - 13, 14, 15, 16, 17, 18, 18, 19, 19, 20, 21, 22, 23, 23, 24, 25, - 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 36, 37, 37, 38, - 39, 40, 41, 42, 43, 43, 44, 44, 45, 46, 47, 48, 48, 49, 50, 51, - 52, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 61, 62, 62, 63, 64, - 65, 66, 67, 68, 68, 69, 69, 70, 71, 72, 73, 73, 74}; - double rec_lattice[3][3] = {{0.3214400514304082, 0.0, 0.0}, - {0.1855835002216734, 0.3711670004433468, 0.0}, - {0.0, 0.0, 0.20088388911209323}}; - long PS[3] = {0, 0, 0}; - long D_diag[3] = {5, 5, 3}; - long Q[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; - long bz_grid_addresses[144][3]; - long bz_map[76]; - long bzg2grg[144]; - long bz_size, i, j; - - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, - D_diag, Q, PS, rec_lattice, 2); - ASSERT_EQ(93, bz_size); - for (i = 0; i < 93; i++) { - for (j = 0; j < 3; j++) { - ASSERT_EQ(ref_bz_addresses[i][j], bz_grid_addresses[i][j]); - } - } - for (i = 0; i < 76; i++) { - ASSERT_EQ(ref_bz_map[i], bz_map[i]); - } - for (i = 0; i < 93; i++) { - ASSERT_EQ(ref_bzg2grg[i], bzg2grg[i]); - } -} - -/** - * @brief gridsys_get_bz_grid_addresses by wurtzite in GR-grid - */ -TEST(test_gridsys, test_gridsys_get_bz_grid_addresses_wurtzite_grg) { - long ref_bz_addresses[93][3] = { - {0, 0, 0}, {0, 1, 0}, {0, 2, 0}, {0, -2, 0}, {0, -1, 0}, - {0, 0, 1}, {0, 1, 1}, {5, 1, -14}, {0, -3, 1}, {5, 2, -14}, - {0, -2, 1}, {0, -1, 1}, {-1, 0, 2}, {-1, 1, 2}, {-1, 2, 2}, - {-1, -2, 2}, {-1, 3, 2}, {-1, -1, 2}, {-1, 0, 3}, {-1, 1, 3}, - {-1, 2, 3}, {-1, -3, 3}, {-1, -2, 3}, {-1, -1, 3}, {4, 0, -11}, - {4, 1, -11}, {4, 2, -11}, {4, 3, -11}, {-1, -2, 4}, {4, -1, -11}, - {-1, -1, 4}, {-2, 0, 5}, {-2, 1, 5}, {-2, 2, 5}, {-2, -2, 5}, - {-2, -1, 5}, {-2, 0, 6}, {-2, 1, 6}, {3, 1, -9}, {-2, -3, 6}, - {3, 2, -9}, {-2, -2, 6}, {-2, -1, 6}, {3, 0, -8}, {3, 1, -8}, - {3, 2, -8}, {3, -2, -8}, {3, 3, -8}, {3, -1, -8}, {-3, 0, 8}, - {-3, 1, 8}, {-3, 2, 8}, {-3, -3, 8}, {-3, -2, 8}, {-3, -1, 8}, - {2, 0, -6}, {2, 1, -6}, {2, 2, -6}, {2, 3, -6}, {-3, -2, 9}, - {2, -1, -6}, {-3, -1, 9}, {2, 0, -5}, {2, 1, -5}, {2, 2, -5}, - {2, -2, -5}, {2, -1, -5}, {-4, 0, 11}, {-4, 1, 11}, {1, 1, -4}, - {-4, -3, 11}, {1, 2, -4}, {-4, -2, 11}, {-4, -1, 11}, {1, 0, -3}, - {1, 1, -3}, {1, 2, -3}, {1, -2, -3}, {1, 3, -3}, {1, -1, -3}, - {1, 0, -2}, {1, 1, -2}, {1, 2, -2}, {1, -3, -2}, {1, -2, -2}, - {1, -1, -2}, {0, 0, -1}, {0, 1, -1}, {0, 2, -1}, {0, 3, -1}, - {-5, -2, 14}, {0, -1, -1}, {-5, -1, 14}}; - long ref_bz_map[76] = {0, 1, 2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 14, - 15, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 29, 31, - 32, 33, 34, 35, 36, 37, 39, 41, 42, 43, 44, 45, 46, - 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 60, 62, 63, - 64, 65, 66, 67, 68, 70, 72, 73, 74, 75, 76, 77, 79, - 80, 81, 82, 84, 85, 86, 87, 88, 89, 91, 93}; - long ref_bzg2grg[93] = { - 0, 1, 2, 3, 4, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, - 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 23, 24, 24, 25, - 26, 27, 28, 29, 30, 31, 31, 32, 32, 33, 34, 35, 36, 37, 38, 38, - 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 48, 48, 49, 49, 50, 51, - 52, 53, 54, 55, 56, 56, 57, 57, 58, 59, 60, 61, 62, 63, 63, 64, - 65, 66, 67, 67, 68, 69, 70, 71, 72, 73, 73, 74, 74}; - double rec_lattice[3][3] = {{0.3214400514304082, 0.0, 0.0}, - {0.1855835002216734, 0.3711670004433468, 0.0}, - {0.0, 0.0, 0.20088388911209323}}; - long PS[3] = {0, 0, 0}; - long D_diag[3] = {1, 5, 15}; - long Q[3][3] = {{-1, 0, -6}, {0, -1, 0}, {-1, 0, -5}}; - long bz_grid_addresses[144][3]; - long bz_map[76]; - long bzg2grg[144]; - long bz_size, i, j; - - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, - D_diag, Q, PS, rec_lattice, 2); - ASSERT_EQ(93, bz_size); - for (i = 0; i < 93; i++) { - for (j = 0; j < 3; j++) { - ASSERT_EQ(ref_bz_addresses[i][j], bz_grid_addresses[i][j]); - } - } - for (i = 0; i < 76; i++) { - ASSERT_EQ(ref_bz_map[i], bz_map[i]); - } - for (i = 0; i < 93; i++) { - ASSERT_EQ(ref_bzg2grg[i], bzg2grg[i]); - } -} - -/** - * @brief gridsys_get_triplets_at_q by wurtzite rotations - * @details Four patterns, is_time_reversal x swappable, are tested. - */ -TEST(test_gridsys, test_gridsys_get_triplets_at_q_wurtzite) { - long D_diag[3] = {3, 3, 4}; - long grid_point = 1; - long map_triplets[36], map_q[36]; - long i, j, k, num_triplets; - long ref_num_triplets[2][2] = {{12, 18}, {14, 24}}; - long is_time_reversal[2] = {1, 0}; - long swappable[2] = {1, 0}; - long count = 0; - long ref_map_triplets[4][36] = { - {0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 9, 12, 12, 14, 14, 12, 12, - 18, 19, 18, 21, 21, 23, 23, 21, 21, 9, 10, 9, 12, 12, 14, 14, 12, 12}, - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13}, - {0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 11, - 12, 13, 14, 14, 12, 13, 18, 19, 18, 21, 21, 23, - 23, 21, 21, 11, 10, 9, 13, 12, 14, 14, 13, 12}, - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31}}; - long ref_map_q[4][36] = { - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13}, - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, - 18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13}, - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31}, - {0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, - 12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, - 23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31}}; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - num_triplets = gridsys_get_triplets_at_q( - map_triplets, map_q, grid_point, D_diag, is_time_reversal[i], - 12, wurtzite_rec_rotations_without_time_reversal, swappable[j]); - ASSERT_EQ(ref_num_triplets[i][j], num_triplets); - for (k = 0; k < 36; k++) { - ASSERT_EQ(ref_map_triplets[count][k], map_triplets[k]); - ASSERT_EQ(ref_map_q[count][k], map_q[k]); - } - count++; - } - } -} - -/** - * @brief gridsys_get_triplets_at_q by AgNO2 rotations - * @details Four patterns, is_time_reversal x swappable, are tested. - */ -TEST(test_gridsys, test_gridsys_get_triplets_at_q_AgNO2) { - long D_diag[3] = {2, 2, 8}; - long grid_point = 1; - long map_triplets[32], map_q[32]; - long i, j, k, num_triplets; - long ref_num_triplets[2][2] = {{8, 16}, {12, 24}}; - long is_time_reversal[2] = {1, 0}; - long swappable[2] = {1, 0}; - long count = 0; - long ref_map_triplets[4][32] = { - {0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 6, 6, - 16, 16, 2, 2, 12, 12, 6, 6, 8, 8, 10, 10, 4, 4, 6, 6}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 6, 7, - 16, 17, 2, 3, 12, 13, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7}, - {0, 0, 2, 2, 4, 5, 6, 7, 8, 9, 10, 10, 12, 13, 7, 6, - 16, 16, 2, 2, 13, 12, 6, 7, 9, 8, 10, 10, 5, 4, 7, 6}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 2, 3, 20, 21, 6, 7, 24, 25, 10, 11, 28, 29, 14, 15}}; - long ref_map_q[4][32] = { - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 6, 7, - 16, 17, 2, 3, 12, 13, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 6, 7, - 16, 17, 2, 3, 12, 13, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 2, 3, 20, 21, 6, 7, 24, 25, 10, 11, 28, 29, 14, 15}, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 2, 3, 20, 21, 6, 7, 24, 25, 10, 11, 28, 29, 14, 15}}; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - num_triplets = gridsys_get_triplets_at_q( - map_triplets, map_q, grid_point, D_diag, is_time_reversal[i], 4, - AgNO2_tilde_rec_rotations_without_time_reversal_mesh12, - swappable[j]); - ASSERT_EQ(ref_num_triplets[i][j], num_triplets); - for (k = 0; k < 32; k++) { - ASSERT_EQ(ref_map_triplets[count][k], map_triplets[k]); - ASSERT_EQ(ref_map_q[count][k], map_q[k]); - } - count++; - } - } -} - -/** - * @brief gridsys_get_triplets_at_q by wurtzite rotations with and without - * force_SNF (i.e., transformed or not transformed rotations) - * @details Four patterns, is_time_reversal x swappable, are tested. - * The lattices generated with and without force_SNF are the same. - * Therefore numbers of unique triplets should agree, which is this test. - */ -TEST(test_gridsys, test_gridsys_get_triplets_at_q_wurtzite_force_SNF) { - long D_diag[2][3] = {{1, 5, 15}, {5, 5, 3}}; - long grid_point = 1; - long map_triplets[75], map_q[75]; - long i, j, k, ll, num_triplets; - long ref_unique_elems[4][2] = {{18, 30}, {24, 45}, {30, 30}, {45, 45}}; - long is_time_reversal[2] = {1, 0}; - long swappable[2] = {1, 0}; - long rec_rotations[2][12][3][3]; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - for (k = 0; k < 3; k++) { - for (ll = 0; ll < 3; ll++) { - if (i == 0) { - rec_rotations[i][j][k][ll] = - wurtzite_tilde_rec_rotations_without_time_reversal - [j][k][ll]; - } else { - rec_rotations[i][j][k][ll] = - wurtzite_rec_rotations_without_time_reversal[j][k] - [ll]; - } - } - } - } - } - - for (i = 0; i < 2; i++) { // force_SNF True or False - for (j = 0; j < 2; j++) { // swappable - for (k = 0; k < 2; k++) { // is_time_reversal - num_triplets = gridsys_get_triplets_at_q( - map_triplets, map_q, grid_point, D_diag[i], - is_time_reversal[k], 12, rec_rotations[i], swappable[j]); - ASSERT_EQ(ref_unique_elems[j * 2 + k][0], num_triplets); - ASSERT_EQ(ref_unique_elems[j * 2 + k][0], - get_num_unique_elems(map_triplets, 75)); - ASSERT_EQ(ref_unique_elems[j * 2 + k][1], - get_num_unique_elems(map_q, 75)); - } - } - } -} - -/** - * @brief gridsys_get_BZ_triplets_at_q by wurtzite rotations with and - * without force_SNF (i.e., transformed or not transformed rotations) - * @details Four patterns, is_time_reversal x swappable, are tested. - */ -TEST(test_gridsys, test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF) { - long ref_triplets[2][8][45][3] = { - {{{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 5, 91}, {1, 7, 90}, - {1, 10, 87}, {1, 12, 85}, {1, 13, 84}, {1, 14, 83}, {1, 18, 79}, - {1, 19, 77}, {1, 23, 74}, {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, - {1, 36, 60}, {1, 38, 59}, {1, 41, 56}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 5, 91}, {1, 7, 90}, - {1, 8, 88}, {1, 10, 87}, {1, 11, 86}, {1, 12, 85}, {1, 13, 84}, - {1, 14, 83}, {1, 15, 81}, {1, 17, 80}, {1, 18, 79}, {1, 19, 77}, - {1, 23, 74}, {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, - {1, 35, 62}, {1, 36, 60}, {1, 38, 59}, {1, 41, 56}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 3, 1}, {1, 4, 0}, - {1, 5, 91}, {1, 7, 90}, {1, 8, 88}, {1, 10, 87}, {1, 11, 86}, - {1, 12, 85}, {1, 13, 84}, {1, 14, 83}, {1, 15, 81}, {1, 17, 80}, - {1, 18, 79}, {1, 19, 77}, {1, 21, 76}, {1, 22, 75}, {1, 23, 74}, - {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, {1, 35, 62}, - {1, 36, 60}, {1, 38, 59}, {1, 39, 57}, {1, 41, 56}, {1, 42, 55}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 3, 1}, {1, 4, 0}, - {1, 5, 91}, {1, 7, 90}, {1, 8, 88}, {1, 10, 87}, {1, 11, 86}, - {1, 12, 85}, {1, 13, 84}, {1, 14, 83}, {1, 15, 81}, {1, 17, 80}, - {1, 18, 79}, {1, 19, 77}, {1, 21, 76}, {1, 22, 75}, {1, 23, 74}, - {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, {1, 35, 62}, - {1, 36, 60}, {1, 38, 59}, {1, 39, 57}, {1, 41, 56}, {1, 42, 55}, - {1, 43, 54}, {1, 44, 53}, {1, 45, 52}, {1, 46, 50}, {1, 48, 49}, - {1, 62, 35}, {1, 63, 34}, {1, 64, 33}, {1, 65, 32}, {1, 66, 31}, - {1, 67, 29}, {1, 69, 28}, {1, 70, 26}, {1, 72, 25}, {1, 73, 24}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 5, 30}, {1, 6, 28}, - {1, 10, 25}, {1, 11, 23}, {1, 13, 21}, {1, 16, 19}, {1, 31, 66}, - {1, 32, 65}, {1, 33, 64}, {1, 36, 92}, {1, 37, 90}, {1, 41, 87}, - {1, 42, 85}, {1, 44, 83}, {1, 47, 81}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 5, 30}, {1, 6, 28}, - {1, 10, 25}, {1, 11, 23}, {1, 13, 21}, {1, 16, 19}, {1, 31, 66}, - {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, {1, 35, 62}, {1, 36, 92}, - {1, 37, 90}, {1, 39, 89}, {1, 40, 88}, {1, 41, 87}, {1, 42, 85}, - {1, 44, 83}, {1, 46, 82}, {1, 47, 81}, {1, 48, 80}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 3, 1}, {1, 4, 0}, - {1, 5, 30}, {1, 6, 28}, {1, 8, 27}, {1, 9, 26}, {1, 10, 25}, - {1, 11, 23}, {1, 13, 21}, {1, 15, 20}, {1, 16, 19}, {1, 17, 18}, - {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, {1, 35, 62}, - {1, 36, 92}, {1, 37, 90}, {1, 39, 89}, {1, 40, 88}, {1, 41, 87}, - {1, 42, 85}, {1, 44, 83}, {1, 46, 82}, {1, 47, 81}, {1, 48, 80}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}}, - {{1, 0, 4}, {1, 1, 3}, {1, 2, 2}, {1, 3, 1}, {1, 4, 0}, - {1, 5, 30}, {1, 6, 28}, {1, 8, 27}, {1, 9, 26}, {1, 10, 25}, - {1, 11, 23}, {1, 13, 21}, {1, 15, 20}, {1, 16, 19}, {1, 17, 18}, - {1, 31, 66}, {1, 32, 65}, {1, 33, 64}, {1, 34, 63}, {1, 35, 62}, - {1, 36, 92}, {1, 37, 90}, {1, 39, 89}, {1, 40, 88}, {1, 41, 87}, - {1, 42, 85}, {1, 44, 83}, {1, 46, 82}, {1, 47, 81}, {1, 48, 80}, - {1, 62, 35}, {1, 63, 34}, {1, 64, 33}, {1, 65, 32}, {1, 66, 31}, - {1, 67, 61}, {1, 68, 59}, {1, 70, 58}, {1, 71, 57}, {1, 72, 56}, - {1, 73, 54}, {1, 75, 52}, {1, 77, 51}, {1, 78, 50}, {1, 79, 49}}}, - {{ - {8, 0, 89}, {8, 1, 88}, {8, 2, 87}, {8, 3, 86}, {9, 4, 92}, - {8, 5, 84}, {8, 6, 82}, {8, 8, 81}, {8, 10, 80}, {8, 11, 85}, - {8, 12, 78}, {8, 13, 76}, {8, 14, 75}, {8, 17, 79}, {8, 19, 71}, - {8, 20, 69}, {9, 22, 67}, {8, 24, 65}, {8, 27, 62}, {8, 29, 66}, - {8, 31, 58}, {8, 32, 57}, {8, 40, 50}, {8, 48, 48}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - }, - { - {8, 0, 89}, {8, 1, 88}, {8, 2, 87}, {8, 3, 86}, {9, 4, 92}, - {8, 5, 84}, {8, 6, 82}, {8, 8, 81}, {8, 10, 80}, {8, 11, 85}, - {8, 12, 78}, {8, 13, 76}, {8, 14, 75}, {8, 17, 79}, {8, 19, 71}, - {8, 20, 69}, {9, 22, 67}, {8, 24, 65}, {8, 27, 62}, {8, 29, 66}, - {8, 31, 58}, {8, 32, 57}, {8, 40, 50}, {8, 48, 48}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - }, - { - {8, 0, 89}, {8, 1, 88}, {8, 2, 87}, {8, 3, 86}, {9, 4, 92}, - {8, 5, 84}, {8, 6, 82}, {8, 8, 81}, {8, 10, 80}, {8, 11, 85}, - {8, 12, 78}, {8, 13, 76}, {8, 14, 75}, {8, 16, 74}, {8, 17, 79}, - {8, 19, 71}, {8, 20, 69}, {9, 22, 67}, {9, 23, 73}, {8, 24, 65}, - {8, 25, 64}, {8, 27, 62}, {8, 29, 66}, {8, 31, 58}, {8, 32, 57}, - {8, 33, 56}, {8, 34, 55}, {8, 40, 50}, {9, 41, 49}, {9, 42, 54}, - {8, 43, 46}, {8, 44, 45}, {8, 48, 48}, {8, 50, 40}, {8, 51, 38}, - {9, 53, 36}, {8, 58, 31}, {9, 61, 35}, {8, 62, 27}, {8, 63, 26}, - {8, 71, 19}, {9, 72, 18}, {8, 79, 17}, {8, 81, 8}, {8, 89, 0}, - }, - { - {8, 0, 89}, {8, 1, 88}, {8, 2, 87}, {8, 3, 86}, {9, 4, 92}, - {8, 5, 84}, {8, 6, 82}, {8, 8, 81}, {8, 10, 80}, {8, 11, 85}, - {8, 12, 78}, {8, 13, 76}, {8, 14, 75}, {8, 16, 74}, {8, 17, 79}, - {8, 19, 71}, {8, 20, 69}, {9, 22, 67}, {9, 23, 73}, {8, 24, 65}, - {8, 25, 64}, {8, 27, 62}, {8, 29, 66}, {8, 31, 58}, {8, 32, 57}, - {8, 33, 56}, {8, 34, 55}, {8, 40, 50}, {9, 41, 49}, {9, 42, 54}, - {8, 43, 46}, {8, 44, 45}, {8, 48, 48}, {8, 50, 40}, {8, 51, 38}, - {9, 53, 36}, {8, 58, 31}, {9, 61, 35}, {8, 62, 27}, {8, 63, 26}, - {8, 71, 19}, {9, 72, 18}, {8, 79, 17}, {8, 81, 8}, {8, 89, 0}, - }, - { - {7, 0, 28}, {8, 1, 27}, {8, 2, 26}, {8, 5, 22}, {8, 6, 20}, - {7, 8, 19}, {7, 11, 16}, {7, 13, 15}, {7, 17, 17}, {7, 31, 90}, - {8, 32, 89}, {8, 33, 88}, {8, 36, 84}, {8, 37, 82}, {7, 39, 81}, - {7, 42, 78}, {7, 44, 77}, {7, 48, 79}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - }, - { - {7, 0, 28}, {8, 1, 27}, {8, 2, 26}, {8, 5, 22}, {8, 6, 20}, - {7, 8, 19}, {7, 11, 16}, {7, 13, 15}, {7, 17, 17}, {7, 31, 90}, - {8, 32, 89}, {8, 33, 88}, {8, 36, 84}, {8, 37, 82}, {7, 39, 81}, - {7, 42, 78}, {7, 44, 77}, {7, 48, 79}, {7, 49, 71}, {7, 50, 70}, - {8, 53, 67}, {7, 56, 65}, {8, 58, 63}, {7, 59, 62}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - }, - { - {7, 0, 28}, {8, 1, 27}, {8, 2, 26}, {8, 5, 22}, {8, 6, 20}, - {7, 8, 19}, {7, 11, 16}, {7, 13, 15}, {7, 17, 17}, {7, 18, 9}, - {7, 19, 8}, {8, 22, 5}, {7, 25, 3}, {8, 27, 1}, {7, 28, 0}, - {7, 31, 90}, {8, 32, 89}, {8, 33, 88}, {8, 36, 84}, {8, 37, 82}, - {7, 39, 81}, {7, 42, 78}, {7, 44, 77}, {7, 48, 79}, {7, 49, 71}, - {7, 50, 70}, {8, 53, 67}, {7, 56, 65}, {8, 58, 63}, {7, 59, 62}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, - }, - { - {7, 0, 28}, {8, 1, 27}, {8, 2, 26}, {8, 5, 22}, {8, 6, 20}, - {7, 8, 19}, {7, 11, 16}, {7, 13, 15}, {7, 17, 17}, {7, 18, 9}, - {7, 19, 8}, {8, 22, 5}, {7, 25, 3}, {8, 27, 1}, {7, 28, 0}, - {7, 31, 90}, {8, 32, 89}, {8, 33, 88}, {8, 36, 84}, {8, 37, 82}, - {7, 39, 81}, {7, 42, 78}, {7, 44, 77}, {7, 48, 79}, {7, 49, 71}, - {7, 50, 70}, {8, 53, 67}, {7, 56, 65}, {8, 58, 63}, {7, 59, 62}, - {7, 62, 59}, {8, 63, 58}, {8, 64, 57}, {8, 67, 53}, {8, 68, 51}, - {7, 70, 50}, {7, 73, 47}, {7, 75, 46}, {7, 79, 48}, {7, 80, 40}, - {7, 81, 39}, {8, 84, 36}, {7, 87, 34}, {8, 89, 32}, {7, 90, 31}, - }}}; - long ref_ir_weights[2][8][45] = { - {{2, 2, 1, 8, 4, 8, 4, 8, 8, 4, 4, 2, 4, 4, 2, 4, 2, 4, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {2, 2, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 4, 2, - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}, - {2, 2, 1, 4, 4, 2, 4, 2, 4, 4, 4, 2, 8, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {2, 2, 1, 4, 4, 2, 4, 2, 4, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}, - {{2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 4, 2, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 2, 4, 2, 4, 2, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 2, - 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1}, - {1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 1, 2, - 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1}, - {2, 4, 4, 4, 4, 2, 2, 2, 1, 4, 8, 8, 8, 8, 4, 4, 4, 2, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {2, 4, 4, 4, 4, 2, 2, 2, 1, 2, 4, 4, 4, 4, 2, 4, 4, 2, 4, 2, 4, 4, 4, - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 2, 2, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 2, 4, 4, 4, 4, 2, 4, 4, - 2, 4, 2, 4, 4, 4, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 2, 2, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 2, 2, - 1, 2, 1, 2, 2, 2, 1, 1, 2, 2, 2, 2, 1, 2, 2, 1, 2, 1, 2, 2, 2, 1}}}; - long ref_num_triplets[2][8] = {{18, 24, 30, 45, 18, 24, 30, 45}, - {24, 24, 45, 45, 18, 24, 30, 45}}; - - long D_diag[2][3] = {{1, 5, 15}, {5, 5, 3}}; - long PS[3] = {0, 0, 0}; - long Q[2][3][3] = {{{-1, 0, -6}, {0, -1, 0}, {-1, 0, -5}}, - {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}; - double rec_lattice[3][3] = {{0.3214400514304082, 0.0, 0.0}, - {0.18558350022167336, 0.37116700044334666, 0.0}, - {0.0, 0.0, 0.20088388911209318}}; - long map_triplets[75], map_q[75], weights[75], ir_weights[75]; - long i, j, k, ll, count, num_triplets_1, num_triplets_2, bz_size, i_grgp, - grid_point, ir_count; - long grgp[2] = {1, 7}; - long is_time_reversal[2] = {1, 0}; - long swappable[2] = {1, 0}; - long rec_rotations[2][12][3][3]; - long triplets[75][3]; - long bz_grid_addresses[108][3]; - long bz_map[76]; - long bzg2grg[108]; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - for (k = 0; k < 3; k++) { - for (ll = 0; ll < 3; ll++) { - if (i == 0) { - rec_rotations[i][j][k][ll] = - wurtzite_tilde_rec_rotations_without_time_reversal - [j][k][ll]; - } else { - rec_rotations[i][j][k][ll] = - wurtzite_rec_rotations_without_time_reversal[j][k] - [ll]; - } - } - } - } - } - - for (i_grgp = 0; i_grgp < 2; i_grgp++) { - count = 0; - grid_point = grgp[i_grgp]; - for (i = 0; i < 2; i++) { // force_SNF True or False - bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, - bzg2grg, D_diag[i], Q[i], - PS, rec_lattice, 2); - ASSERT_EQ(93, bz_size); - // for (ll = 0; ll < 93; ll++) { - // printf("[%ld, %ld, %ld]\n", bz_grid_addresses[ll][0], - // bz_grid_addresses[ll][1], bz_grid_addresses[ll][2]); - // } - for (j = 0; j < 2; j++) { // swappable - for (k = 0; k < 2; k++) { // is_time_reversal - num_triplets_1 = gridsys_get_triplets_at_q( - map_triplets, map_q, grid_point, D_diag[i], - is_time_reversal[k], 12, rec_rotations[i], - swappable[j]); - for (ll = 0; ll < 75; ll++) { - weights[ll] = 0; - ir_weights[ll] = 0; - } - for (ll = 0; ll < 75; ll++) { - weights[map_triplets[ll]]++; - } - ir_count = 0; - for (ll = 0; ll < 75; ll++) { - if (weights[ll] > 0) { - ir_weights[ir_count] = weights[ll]; - ir_count++; - } - } - for (ll = 0; ll < num_triplets_1; ll++) { - ASSERT_EQ(ref_ir_weights[i_grgp][count][ll], - ir_weights[ll]); - } - num_triplets_2 = gridsys_get_bz_triplets_at_q( - triplets, bz_map[grid_point], bz_grid_addresses, bz_map, - map_triplets, 75, D_diag[i], Q[i], 2); - ASSERT_EQ(num_triplets_1, num_triplets_2); - ASSERT_EQ(num_triplets_1, ref_num_triplets[i_grgp][count]); - for (ll = 0; ll < num_triplets_2; ll++) { - // printf("%ld %ld %ld %ld [%ld %ld %ld] [%ld %ld - // %ld]\n", i, - // j, k, ll, ref_triplets[count][ll][0], - // ref_triplets[count][ll][1], - // ref_triplets[count][ll][2], triplets[ll][0], - // triplets[ll][1], triplets[ll][2]); - ASSERT_EQ(ref_triplets[i_grgp][count][ll][0], - triplets[ll][0]); - ASSERT_EQ(ref_triplets[i_grgp][count][ll][1], - triplets[ll][1]); - ASSERT_EQ(ref_triplets[i_grgp][count][ll][2], - triplets[ll][2]); - } - count++; - } - } - } - } -} diff --git a/ctest/test_niggli.cpp b/ctest/test_niggli.cpp deleted file mode 100644 index 03138234..00000000 --- a/ctest/test_niggli.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -extern "C" { -#include - -#include "niggli.h" -} - -/** - * @brief niggli:niggli_reduce - * Run Niggli reduction. - * @return succeeded (1) or not (0) - * @details The test data is imported from spglib test lattice.dat No.467. - */ -TEST(test_gridsys, test_niggli_niggli_reduce) { - /* row vectors */ - const double input_lattice[3][3] = { - {3.7484850618560537, 0.5179527621527573, 0.2725676000178477}, - {2.5954120365612385, 7.9478524331504028, 0.7065992265067038}, - {3.1731369922769055, 0.0785542643845797, 7.7623356251774149}}; - /* row vectors */ - const double ref_niggli_lattice[3][3] = { - {-3.7484850618560537, -0.5179527621527573, -0.2725676000178477}, - {-0.5753480695791482, -0.4393984977681776, 7.4897680251595675}, - {-1.1530730252948151, 7.4298996709976457, 0.4340316264888561}}; - double niggli_lattice[9]; - long i, j; - int succeeded; - - /* row vectors -> column vectors */ - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - niggli_lattice[i * 3 + j] = input_lattice[j][i]; - } - } - succeeded = niggli_reduce(niggli_lattice, 1e-5); - ASSERT_TRUE(succeeded); - /* compare row vectors and column vectors */ - for (i = 0; i < 3; i++) { - for (j = 0; j < 3; j++) { - ASSERT_LT( - (fabs(ref_niggli_lattice[j][i] - niggli_lattice[i * 3 + j])), - 1e-5); - } - } -} diff --git a/ctest/utils.c b/ctest/utils.c deleted file mode 100644 index 14364293..00000000 --- a/ctest/utils.c +++ /dev/null @@ -1,26 +0,0 @@ -#include "utils.h" - -#include -#include - -long get_num_unique_elems(const long array[], const long array_size) { - long i, num_unique_elems; - long *unique_elems; - - num_unique_elems = 0; - unique_elems = (long *)malloc(sizeof(long) * array_size); - for (i = 0; i < array_size; i++) { - unique_elems[i] = 0; - } - for (i = 0; i < array_size; i++) { - unique_elems[array[i]]++; - } - for (i = 0; i < array_size; i++) { - if (unique_elems[i]) { - num_unique_elems++; - } - } - free(unique_elems); - unique_elems = NULL; - return num_unique_elems; -} diff --git a/ctest/utils.h b/ctest/utils.h deleted file mode 100644 index 3b1386f9..00000000 --- a/ctest/utils.h +++ /dev/null @@ -1,5 +0,0 @@ -#ifndef __test_utils_H__ -#define __test_utils_H__ - -long get_num_unique_elems(const long array[], const long array_size); -#endif // __test_utils_H__ diff --git a/fortran/CMakeLists.txt b/fortran/CMakeLists.txt deleted file mode 100644 index a02f1317..00000000 --- a/fortran/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -if(USE_OpenMP) - find_package( - OpenMP - COMPONENTS Fortran - REQUIRED) - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") -endif() - -add_library(gridsysf_static STATIC gridsysf.f90) -set_property(TARGET gridsysf_static PROPERTY VERSION ${PROJECT_VERSION}) -set_property(TARGET gridsysf_static PROPERTY OUTPUT_NAME gridsysf) -target_link_libraries(gridsysf_static PRIVATE gridsys_static) -install(TARGETS gridsysf_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) - -if(BUILD_SHARED_LIBRARIES) - add_library(gridsysf SHARED gridsysf.f90) - set_property(TARGET gridsysf PROPERTY VERSION ${PROJECT_VERSION}) - set_property(TARGET gridsysf PROPERTY SOVERSION ${soserial}) - target_link_libraries(gridsysf PUBLIC gridsys) - install(TARGETS gridsysf LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) -endif() - -install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gridsysf.mod - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/fortran/gridsysf.f90 b/fortran/gridsysf.f90 deleted file mode 100644 index 6e59c584..00000000 --- a/fortran/gridsysf.f90 +++ /dev/null @@ -1,224 +0,0 @@ -! Copyright (C) 2021 Atsushi Togo -! All rights reserved. - -! This file is part of kspclib. - -! Redistribution and use in source and binary forms, with or without -! modification, are permitted provided that the following conditions -! are met: - -! * Redistributions of source code must retain the above copyright -! notice, this list of conditions and the following disclaimer. - -! * Redistributions in binary form must reproduce the above copyright -! notice, this list of conditions and the following disclaimer in -! the documentation and/or other materials provided with the -! distribution. - -! * Neither the name of the kspclib project nor the names of its -! contributors may be used to endorse or promote products derived -! from this software without specific prior written permission. - -! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -! COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -! POSSIBILITY OF SUCH DAMAGE. - -module gridsysf - - use iso_c_binding, only: c_char, c_long, c_double - - implicit none - - private - - interface - - subroutine gridsys_get_all_grid_addresses(gr_grid_addresses, D_diag) bind(c) - import c_long - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(inout) :: gr_grid_addresses(3, *) - end subroutine gridsys_get_all_grid_addresses - - subroutine gridsys_get_double_grid_address(address_double, address, & - PS) bind(c) - import c_long - integer(c_long), intent(inout) :: address_double(3) - integer(c_long), intent(in) :: address(3) - integer(c_long), intent(in) :: PS(3) - end subroutine gridsys_get_double_grid_address - - subroutine gridsys_get_grid_address_from_index(address, grid_index, D_diag) & - bind(c) - import c_long - integer(c_long), intent(inout) :: address(3) - integer(c_long), intent(in), value :: grid_index - integer(c_long), intent(in) :: D_diag(3) - end subroutine gridsys_get_grid_address_from_index - - function gridsys_get_grid_index_from_address(address, D_diag) bind(c) - import c_long - integer(c_long), intent(in) :: address(3) - integer(c_long), intent(in) :: D_diag(3) - integer(c_long) :: gridsys_get_grid_index_from_address - end function gridsys_get_grid_index_from_address - - function gridsys_rotate_grid_index(grid_index, rotation, D_diag, PS) bind(c) - import c_long - integer(c_long), intent(in), value :: grid_index - integer(c_long), intent(in) :: rotation(3, 3) - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: PS(3) - integer(c_long) :: gridsys_rotate_grid_index - end function gridsys_rotate_grid_index - - function gridsys_get_double_grid_index(address_double, D_diag, PS) bind(c) - import c_long - integer(c_long), intent(in) :: address_double(3) - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: PS(3) - integer(c_long) :: gridsys_get_double_grid_index - end function gridsys_get_double_grid_index - - function gridsys_get_reciprocal_point_group(rec_rotations, rotations, & - num_rot, is_time_reversal) bind(c) - import c_long - integer(c_long), intent(inout) :: rec_rotations(3, 3, 48) - integer(c_long), intent(in) :: rotations(3, 3, *) - integer(c_long), intent(in), value :: num_rot - integer(c_long), intent(in), value :: is_time_reversal - integer(c_long) :: gridsys_get_reciprocal_point_group - end function gridsys_get_reciprocal_point_group - - function gridsys_get_snf3x3(D_diag, P, Q, A) bind(c) - import c_long - integer(c_long), intent(inout) :: D_diag(3) - integer(c_long), intent(inout) :: P(3, 3) - integer(c_long), intent(inout) :: Q(3, 3) - integer(c_long), intent(in) :: A(3, 3) - integer(c_long) :: gridsys_get_snf3x3 - end function gridsys_get_snf3x3 - - function gridsys_transform_rotations(transformed_rots, & - rotations, num_rot, D_diag, Q) bind(c) - import c_long - integer(c_long), intent(inout) :: transformed_rots(3, 3, *) - integer(c_long), intent(in) :: rotations(3, 3, *) - integer(c_long), intent(in), value :: num_rot - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: Q(3, 3) - integer(c_long) :: gridsys_transform_rotations - end function gridsys_transform_rotations - - subroutine gridsys_get_ir_grid_map(ir_grid_map, rotations, num_rot, & - D_diag, PS) bind(c) - import c_long - integer(c_long), intent(inout) :: ir_grid_map(*) - integer(c_long), intent(in) :: rotations(3, 3, *) - integer(c_long), intent(in), value :: num_rot - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: PS(3) - end subroutine gridsys_get_ir_grid_map - - function gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, & - bzg2grg, D_diag, Q, PS, & - rec_lattice, bz_grid_type) bind(c) - import c_long, c_double - integer(c_long), intent(inout) :: bz_grid_addresses(3, *) - integer(c_long), intent(inout) :: bz_map(*) - integer(c_long), intent(inout) :: bzg2grg(*) - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: Q(3, 3) - integer(c_long), intent(in) :: PS(3) - real(c_double), intent(in) :: rec_lattice(3, 3) - integer(c_long), intent(in), value :: bz_grid_type - integer(c_long) :: gridsys_get_bz_grid_addresses - end function gridsys_get_bz_grid_addresses - - function gridsys_rotate_bz_grid_index(bz_grid_index, rotation, bz_grid_addresses, & - bz_map, D_diag, PS, bz_grid_type) bind(c) - import c_long - integer(c_long), intent(in), value :: bz_grid_index - integer(c_long), intent(in) :: rotation(3, 3) - integer(c_long), intent(in) :: bz_grid_addresses(3, *) - integer(c_long), intent(in) :: bz_map(*) - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: PS(3) - integer(c_long), intent(in), value :: bz_grid_type - integer(c_long) :: gridsys_rotate_bz_grid_index - end function gridsys_rotate_bz_grid_index - - function gridsys_get_triplets_at_q(map_triplets, map_q, grid_point, & - D_diag, is_time_reversal, num_rot, & - rec_rotations, swappable) bind(c) - import c_long - integer(c_long), intent(inout) :: map_triplets(*) - integer(c_long), intent(inout) :: map_q(*) - integer(c_long), intent(in), value :: grid_point - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in), value :: is_time_reversal - integer(c_long), intent(in), value :: num_rot - integer(c_long), intent(in) :: rec_rotations(3, 3, *) - integer(c_long), intent(in), value :: swappable - integer(c_long) :: gridsys_get_triplets_at_q - end function gridsys_get_triplets_at_q - - function gridsys_get_bz_triplets_at_q(triplets, grid_point, bz_grid_addresses, & - bz_map, map_triplets, num_map_triplets, D_diag, Q, bz_grid_type) bind(c) - import c_long - integer(c_long), intent(inout) :: triplets(3, *) - integer(c_long), intent(in), value :: grid_point - integer(c_long), intent(in) :: bz_grid_addresses(3, *) - integer(c_long), intent(in) :: bz_map(*) - integer(c_long), intent(in) :: map_triplets(*) - integer(c_long), intent(in), value :: num_map_triplets - integer(c_long), intent(in) :: D_diag(3) - integer(c_long), intent(in) :: Q(3, 3) - integer(c_long), intent(in), value :: bz_grid_type - integer(c_long) :: gridsys_get_bz_triplets_at_q - end function gridsys_get_bz_triplets_at_q - - function gridsys_get_thm_integration_weight(omega, & - tetrahedra_omegas, function_char) bind(c) - import c_char, c_double - real(c_double), intent(in), value :: omega - real(c_double), intent(in) :: tetrahedra_omegas(4, 24) - character(kind=c_char), intent(in), value :: function_char - real(c_double) :: gridsys_get_thm_integration_weight - end function gridsys_get_thm_integration_weight - - subroutine gridsys_get_thm_relative_grid_address(relative_grid_addresses, & - rec_lattice) bind(c) - import c_long, c_double - integer(c_long), intent(inout) :: relative_grid_addresses(3, 4, 24) - real(c_double), intent(in) :: rec_lattice(3, 3) - end subroutine gridsys_get_thm_relative_grid_address - - end interface - - public :: gridsys_get_all_grid_addresses, & - gridsys_get_double_grid_address, & - gridsys_get_grid_address_from_index, & - gridsys_get_grid_index_from_address, & - gridsys_rotate_grid_index, & - gridsys_get_double_grid_index, & - gridsys_get_reciprocal_point_group, & - gridsys_get_snf3x3, & - gridsys_transform_rotations, & - gridsys_get_ir_grid_map, & - gridsys_get_bz_grid_addresses, & - gridsys_rotate_bz_grid_index, & - gridsys_get_triplets_at_q, & - gridsys_get_bz_triplets_at_q, & - gridsys_get_thm_integration_weight, & - gridsys_get_thm_relative_grid_address - -end module gridsysf diff --git a/pyproject.toml b/pyproject.toml index 094ad8eb..ad129a0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ phono3py-kdeplot = "phono3py.scripts.phono3py_kdeplot:run" [tool.scikit-build] +wheel.install-dir = "phono3py" cmake.verbose = true logging.level = "INFO" metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" @@ -50,7 +51,6 @@ sdist.include = [ [tool.scikit-build.cmake.define] PHONO3PY_USE_MTBLAS = {env="PHONO3PY_USE_MTBLAS", default="ON"} -USE_CONDA_PATH = {env="USE_CONDA_PATH", default="ON"} PHONO3PY_USE_OMP = {env="PHONO3PY_USE_OMP", default="ON"} [tool.setuptools_scm]