diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 39c7ee27..12d18c31 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,9 +37,3 @@ repos: # - '-I/Users/togo/.miniforge/envs/dev/include/python3.10' # - '-I/Users/togo/.miniforge/envs/dev/lib/python3.10/site-packages/numpy/core/include' stages: [manual] - -- repo: https://github.com/cheshirekow/cmake-format-precommit - rev: v0.6.13 - hooks: - - id: cmake-format - - id: cmake-lint 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/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 2c943f76..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,6 +0,0 @@ -graft c -graft example -include __nanoversion__.txt -include LICENSE -recursive-include test * -recursive-exclude test *.pyc 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/c/_phono3py.c b/c/_phono3py.c deleted file mode 100644 index 27388cb5..00000000 --- a/c/_phono3py.c +++ /dev/null @@ -1,1877 +0,0 @@ -/* Copyright (C) 2015 Atsushi Togo */ -/* All rights reserved. */ - -/* This file is part of phonopy. */ - -/* 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 phonopy 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. */ - -#include -#include -#include -#include -#include -#include -#include - -// #include "lapack_wrapper.h" -#include "phono3py.h" -#include "phonoc_array.h" - -static PyObject *py_get_interaction(PyObject *self, PyObject *args); -static PyObject *py_get_pp_collision(PyObject *self, PyObject *args); -static PyObject *py_get_pp_collision_with_sigma(PyObject *self, PyObject *args); -static PyObject *py_get_imag_self_energy_with_g(PyObject *self, PyObject *args); -static PyObject *py_get_detailed_imag_self_energy_with_g(PyObject *self, - PyObject *args); -static PyObject *py_get_real_self_energy_at_bands(PyObject *self, - PyObject *args); -static PyObject *py_get_real_self_energy_at_frequency_point(PyObject *self, - PyObject *args); -static PyObject *py_get_collision_matrix(PyObject *self, PyObject *args); -static PyObject *py_get_reducible_collision_matrix(PyObject *self, - PyObject *args); -static PyObject *py_symmetrize_collision_matrix(PyObject *self, PyObject *args); -static PyObject *py_expand_collision_matrix(PyObject *self, PyObject *args); -static PyObject *py_distribute_fc3(PyObject *self, PyObject *args); -static PyObject *py_rotate_delta_fc2s(PyObject *self, PyObject *args); -static PyObject *py_get_isotope_strength(PyObject *self, PyObject *args); -static PyObject *py_get_thm_isotope_strength(PyObject *self, PyObject *args); -static PyObject *py_get_permutation_symmetry_fc3(PyObject *self, - PyObject *args); -static PyObject *py_get_permutation_symmetry_compact_fc3(PyObject *self, - PyObject *args); -static PyObject *py_transpose_compact_fc3(PyObject *self, PyObject *args); -static PyObject *py_get_thm_relative_grid_address(PyObject *self, - PyObject *args); -static PyObject *py_get_neighboring_grid_points(PyObject *self, PyObject *args); -static PyObject *py_get_thm_integration_weights_at_grid_points(PyObject *self, - PyObject *args); -static PyObject *py_tpl_get_triplets_reciprocal_mesh_at_q(PyObject *self, - PyObject *args); -static PyObject *py_tpl_get_BZ_triplets_at_q(PyObject *self, PyObject *args); -static PyObject *py_get_triplets_integration_weights(PyObject *self, - PyObject *args); -static PyObject *py_get_triplets_integration_weights_with_sigma(PyObject *self, - PyObject *args); -static PyObject *py_get_grid_index_from_address(PyObject *self, PyObject *args); -static PyObject *py_get_gr_grid_addresses(PyObject *self, PyObject *args); -static PyObject *py_get_reciprocal_rotations(PyObject *self, PyObject *args); -static PyObject *py_transform_rotations(PyObject *self, PyObject *args); -static PyObject *py_get_snf3x3(PyObject *self, PyObject *args); -static PyObject *py_get_ir_grid_map(PyObject *self, PyObject *args); -static PyObject *py_get_bz_grid_addresses(PyObject *self, PyObject *args); -static PyObject *py_rotate_bz_grid_addresses(PyObject *self, PyObject *args); -static PyObject *py_diagonalize_collision_matrix(PyObject *self, - PyObject *args); -static PyObject *py_pinv_from_eigensolution(PyObject *self, PyObject *args); -static PyObject *py_get_default_colmat_solver(PyObject *self, PyObject *args); -static PyObject *py_lapacke_pinv(PyObject *self, PyObject *args); -static PyObject *py_get_omp_max_threads(PyObject *self, PyObject *args); - -static void show_colmat_info(const PyArrayObject *collision_matrix_py, - const long i_sigma, const long i_temp, - const long adrs_shift); -static Larray *convert_to_larray(PyArrayObject *npyary); -static Darray *convert_to_darray(PyArrayObject *npyary); - -struct module_state { - PyObject *error; -}; - -#if PY_MAJOR_VERSION >= 3 -#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m)) -#else -#define GETSTATE(m) (&_state) -static struct module_state _state; -#endif - -static PyObject *error_out(PyObject *m) { - struct module_state *st = GETSTATE(m); - PyErr_SetString(st->error, "something bad happened"); - return NULL; -} - -static PyMethodDef _phono3py_methods[] = { - {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, - {"interaction", (PyCFunction)py_get_interaction, METH_VARARGS, - "Interaction of triplets"}, - {"pp_collision", (PyCFunction)py_get_pp_collision, METH_VARARGS, - "Collision and ph-ph calculation"}, - {"pp_collision_with_sigma", (PyCFunction)py_get_pp_collision_with_sigma, - METH_VARARGS, "Collision and ph-ph calculation for smearing method"}, - {"imag_self_energy_with_g", (PyCFunction)py_get_imag_self_energy_with_g, - METH_VARARGS, "Imaginary part of self energy at frequency points with g"}, - {"detailed_imag_self_energy_with_g", - (PyCFunction)py_get_detailed_imag_self_energy_with_g, METH_VARARGS, - "Detailed contribution to imaginary part of self energy at frequency " - "points with g"}, - {"real_self_energy_at_bands", (PyCFunction)py_get_real_self_energy_at_bands, - METH_VARARGS, "Real part of self energy from third order force constants"}, - {"real_self_energy_at_frequency_point", - (PyCFunction)py_get_real_self_energy_at_frequency_point, METH_VARARGS, - "Real part of self energy from third order force constants at a frequency " - "point"}, - {"collision_matrix", (PyCFunction)py_get_collision_matrix, METH_VARARGS, - "Collision matrix with g"}, - {"reducible_collision_matrix", - (PyCFunction)py_get_reducible_collision_matrix, METH_VARARGS, - "Collision matrix with g for reducible grid points"}, - {"symmetrize_collision_matrix", (PyCFunction)py_symmetrize_collision_matrix, - METH_VARARGS, "Symmetrize collision matrix"}, - {"expand_collision_matrix", (PyCFunction)py_expand_collision_matrix, - METH_VARARGS, "Expand collision matrix"}, - {"distribute_fc3", (PyCFunction)py_distribute_fc3, METH_VARARGS, - "Distribute least fc3 to full fc3"}, - {"rotate_delta_fc2s", (PyCFunction)py_rotate_delta_fc2s, METH_VARARGS, - "Rotate delta fc2s"}, - {"isotope_strength", (PyCFunction)py_get_isotope_strength, METH_VARARGS, - "Isotope scattering strength"}, - {"thm_isotope_strength", (PyCFunction)py_get_thm_isotope_strength, - METH_VARARGS, "Isotope scattering strength for tetrahedron_method"}, - {"permutation_symmetry_fc3", (PyCFunction)py_get_permutation_symmetry_fc3, - METH_VARARGS, "Set permutation symmetry for fc3"}, - {"permutation_symmetry_compact_fc3", - (PyCFunction)py_get_permutation_symmetry_compact_fc3, METH_VARARGS, - "Set permutation symmetry for compact-fc3"}, - {"transpose_compact_fc3", (PyCFunction)py_transpose_compact_fc3, - METH_VARARGS, "Transpose compact fc3"}, - {"tetrahedra_relative_grid_address", - (PyCFunction)py_get_thm_relative_grid_address, METH_VARARGS, - "Relative grid addresses of vertices of 24 tetrahedra"}, - {"neighboring_grid_points", (PyCFunction)py_get_neighboring_grid_points, - METH_VARARGS, "Neighboring grid points by relative grid addresses"}, - {"integration_weights_at_grid_points", - (PyCFunction)py_get_thm_integration_weights_at_grid_points, METH_VARARGS, - "Integration weights of tetrahedron method at grid points"}, - {"triplets_reciprocal_mesh_at_q", - (PyCFunction)py_tpl_get_triplets_reciprocal_mesh_at_q, METH_VARARGS, - "Triplets on reciprocal mesh points at a specific q-point"}, - {"BZ_triplets_at_q", (PyCFunction)py_tpl_get_BZ_triplets_at_q, METH_VARARGS, - "Triplets in reciprocal primitive lattice are transformed to those in " - "BZ."}, - {"triplets_integration_weights", - (PyCFunction)py_get_triplets_integration_weights, METH_VARARGS, - "Integration weights of tetrahedron method for triplets"}, - {"triplets_integration_weights_with_sigma", - (PyCFunction)py_get_triplets_integration_weights_with_sigma, METH_VARARGS, - "Integration weights of smearing method for triplets"}, - {"grid_index_from_address", (PyCFunction)py_get_grid_index_from_address, - METH_VARARGS, "Grid index from grid address"}, - {"ir_grid_map", (PyCFunction)py_get_ir_grid_map, METH_VARARGS, - "Reciprocal mesh points with ir grid mapping table"}, - {"gr_grid_addresses", (PyCFunction)py_get_gr_grid_addresses, METH_VARARGS, - "Get generalized regular grid addresses"}, - {"reciprocal_rotations", (PyCFunction)py_get_reciprocal_rotations, - METH_VARARGS, "Return rotation matrices in reciprocal space"}, - {"transform_rotations", (PyCFunction)py_transform_rotations, METH_VARARGS, - "Transform rotations to those in generalized regular grid"}, - {"snf3x3", (PyCFunction)py_get_snf3x3, METH_VARARGS, - "Get Smith formal form for 3x3 integer matrix"}, - {"bz_grid_addresses", (PyCFunction)py_get_bz_grid_addresses, METH_VARARGS, - "Get grid addresses including Brillouin zone surface"}, - {"rotate_bz_grid_index", (PyCFunction)py_rotate_bz_grid_addresses, - METH_VARARGS, "Rotate grid point considering Brillouin zone surface"}, - {"diagonalize_collision_matrix", - (PyCFunction)py_diagonalize_collision_matrix, METH_VARARGS, - "Diagonalize and optionally pseudo-inverse using Lapack dsyev(d)"}, - {"pinv_from_eigensolution", (PyCFunction)py_pinv_from_eigensolution, - METH_VARARGS, "Pseudo-inverse from eigensolution"}, - {"default_colmat_solver", (PyCFunction)py_get_default_colmat_solver, - METH_VARARGS, "Return default collison matrix solver by integer value"}, - {"lapacke_pinv", (PyCFunction)py_lapacke_pinv, METH_VARARGS, - "Pseudo inversion using lapacke."}, - {"omp_max_threads", py_get_omp_max_threads, METH_VARARGS, - "Return openmp max number of threads. Return 0 unless openmp is " - "activated. "}, - {NULL, NULL, 0, NULL}}; - -#if PY_MAJOR_VERSION >= 3 - -static int _phono3py_traverse(PyObject *m, visitproc visit, void *arg) { - Py_VISIT(GETSTATE(m)->error); - return 0; -} - -static int _phono3py_clear(PyObject *m) { - Py_CLEAR(GETSTATE(m)->error); - return 0; -} - -static struct PyModuleDef moduledef = { - PyModuleDef_HEAD_INIT, "_phono3py", NULL, - sizeof(struct module_state), _phono3py_methods, NULL, - _phono3py_traverse, _phono3py_clear, NULL}; - -#define INITERROR return NULL - -PyObject *PyInit__phono3py(void) -#else -#define INITERROR return - -void init_phono3py(void) -#endif -{ -#if PY_MAJOR_VERSION >= 3 - PyObject *module = PyModule_Create(&moduledef); -#else - PyObject *module = Py_InitModule("_phono3py", _phono3py_methods); -#endif - struct module_state *st; - - if (module == NULL) INITERROR; - st = GETSTATE(module); - - st->error = PyErr_NewException("_phono3py.Error", NULL, NULL); - if (st->error == NULL) { - Py_DECREF(module); - INITERROR; - } - -#if PY_MAJOR_VERSION >= 3 - return module; -#endif -} - -static PyObject *py_get_interaction(PyObject *self, PyObject *args) { - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_g_zero; - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_triplets; - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - PyArrayObject *py_svecs; - PyArrayObject *py_multi; - PyArrayObject *py_fc3; - PyArrayObject *py_masses; - PyArrayObject *py_p2s_map; - PyArrayObject *py_s2p_map; - PyArrayObject *py_band_indices; - PyArrayObject *py_all_shortest; - double cutoff_frequency; - long symmetrize_fc3_q; - long make_r0_average; - long openmp_per_triplets; - - Darray *fc3_normal_squared; - Darray *freqs; - _lapack_complex_double *eigvecs; - long(*triplets)[3]; - long num_triplets; - char *g_zero; - long(*bz_grid_addresses)[3]; - long *D_diag; - long(*Q)[3]; - double *fc3; - double(*svecs)[3]; - long(*multi)[2]; - double *masses; - char *all_shortest; - long *p2s; - long *s2p; - long *band_indices; - long multi_dims[2]; - long i; - long is_compact_fc3; - - if (!PyArg_ParseTuple(args, "OOOOOOOOOOOOOOOllOdl", &py_fc3_normal_squared, - &py_g_zero, &py_frequencies, &py_eigenvectors, - &py_triplets, &py_bz_grid_addresses, &py_D_diag, - &py_Q, &py_fc3, &py_svecs, &py_multi, &py_masses, - &py_p2s_map, &py_s2p_map, &py_band_indices, - &symmetrize_fc3_q, &make_r0_average, &py_all_shortest, - &cutoff_frequency, &openmp_per_triplets)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - freqs = convert_to_darray(py_frequencies); - /* npy_cdouble and lapack_complex_double may not be compatible. */ - /* So eigenvectors should not be used in Python side */ - eigvecs = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - num_triplets = (long)PyArray_DIMS(py_triplets)[0]; - g_zero = (char *)PyArray_DATA(py_g_zero); - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - fc3 = (double *)PyArray_DATA(py_fc3); - if (PyArray_DIMS(py_fc3)[0] == PyArray_DIMS(py_fc3)[1]) { - is_compact_fc3 = 0; - } else { - is_compact_fc3 = 1; - } - svecs = (double(*)[3])PyArray_DATA(py_svecs); - for (i = 0; i < 2; i++) { - multi_dims[i] = PyArray_DIMS(py_multi)[i]; - } - multi = (long(*)[2])PyArray_DATA(py_multi); - masses = (double *)PyArray_DATA(py_masses); - p2s = (long *)PyArray_DATA(py_p2s_map); - s2p = (long *)PyArray_DATA(py_s2p_map); - band_indices = (long *)PyArray_DATA(py_band_indices); - all_shortest = (char *)PyArray_DATA(py_all_shortest); - - ph3py_get_interaction(fc3_normal_squared, g_zero, freqs, eigvecs, triplets, - num_triplets, bz_grid_addresses, D_diag, Q, fc3, - is_compact_fc3, svecs, multi_dims, multi, masses, p2s, - s2p, band_indices, symmetrize_fc3_q, make_r0_average, - all_shortest, cutoff_frequency, openmp_per_triplets); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - free(freqs); - freqs = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_pp_collision(PyObject *self, PyObject *args) { - PyArrayObject *py_gamma; - PyArrayObject *py_relative_grid_address; - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_bz_map; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - PyArrayObject *py_fc3; - PyArrayObject *py_svecs; - PyArrayObject *py_multi; - PyArrayObject *py_masses; - PyArrayObject *py_p2s_map; - PyArrayObject *py_s2p_map; - PyArrayObject *py_band_indices; - PyArrayObject *py_temperatures; - PyArrayObject *py_all_shortest; - double cutoff_frequency; - long is_NU; - long symmetrize_fc3_q; - long make_r0_average; - long bz_grid_type; - long openmp_per_triplets; - - double *gamma; - long(*relative_grid_address)[4][3]; - double *frequencies; - _lapack_complex_double *eigenvectors; - long(*triplets)[3]; - long num_triplets; - long *triplet_weights; - long(*bz_grid_addresses)[3]; - long *bz_map; - long *D_diag; - long(*Q)[3]; - double *fc3; - double(*svecs)[3]; - long(*multi)[2]; - double *masses; - long *p2s; - long *s2p; - Larray *band_indices; - Darray *temperatures; - char *all_shortest; - long multi_dims[2]; - long i; - long is_compact_fc3; - - if (!PyArg_ParseTuple( - args, "OOOOOOOOlOOOOOOOOOOlllOdl", &py_gamma, - &py_relative_grid_address, &py_frequencies, &py_eigenvectors, - &py_triplets, &py_triplet_weights, &py_bz_grid_addresses, - &py_bz_map, &bz_grid_type, &py_D_diag, &py_Q, &py_fc3, &py_svecs, - &py_multi, &py_masses, &py_p2s_map, &py_s2p_map, &py_band_indices, - &py_temperatures, &is_NU, &symmetrize_fc3_q, &make_r0_average, - &py_all_shortest, &cutoff_frequency, &openmp_per_triplets)) { - return NULL; - } - - gamma = (double *)PyArray_DATA(py_gamma); - relative_grid_address = - (long(*)[4][3])PyArray_DATA(py_relative_grid_address); - frequencies = (double *)PyArray_DATA(py_frequencies); - eigenvectors = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - num_triplets = (long)PyArray_DIMS(py_triplets)[0]; - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - bz_map = (long *)PyArray_DATA(py_bz_map); - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - fc3 = (double *)PyArray_DATA(py_fc3); - if (PyArray_DIMS(py_fc3)[0] == PyArray_DIMS(py_fc3)[1]) { - is_compact_fc3 = 0; - } else { - is_compact_fc3 = 1; - } - svecs = (double(*)[3])PyArray_DATA(py_svecs); - for (i = 0; i < 2; i++) { - multi_dims[i] = PyArray_DIMS(py_multi)[i]; - } - multi = (long(*)[2])PyArray_DATA(py_multi); - masses = (double *)PyArray_DATA(py_masses); - p2s = (long *)PyArray_DATA(py_p2s_map); - s2p = (long *)PyArray_DATA(py_s2p_map); - band_indices = convert_to_larray(py_band_indices); - temperatures = convert_to_darray(py_temperatures); - all_shortest = (char *)PyArray_DATA(py_all_shortest); - - ph3py_get_pp_collision( - gamma, relative_grid_address, frequencies, eigenvectors, triplets, - num_triplets, triplet_weights, bz_grid_addresses, bz_map, bz_grid_type, - D_diag, Q, fc3, is_compact_fc3, svecs, multi_dims, multi, masses, p2s, - s2p, band_indices, temperatures, is_NU, symmetrize_fc3_q, - make_r0_average, all_shortest, cutoff_frequency, openmp_per_triplets); - - free(band_indices); - band_indices = NULL; - free(temperatures); - temperatures = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_pp_collision_with_sigma(PyObject *self, - PyObject *args) { - PyArrayObject *py_gamma; - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - PyArrayObject *py_fc3; - PyArrayObject *py_svecs; - PyArrayObject *py_multi; - PyArrayObject *py_masses; - PyArrayObject *py_p2s_map; - PyArrayObject *py_s2p_map; - PyArrayObject *py_band_indices; - PyArrayObject *py_temperatures; - PyArrayObject *py_all_shortest; - long is_NU; - long symmetrize_fc3_q; - double sigma; - double sigma_cutoff; - long make_r0_average; - double cutoff_frequency; - long openmp_per_triplets; - - double *gamma; - double *frequencies; - _lapack_complex_double *eigenvectors; - long(*triplets)[3]; - long num_triplets; - long *triplet_weights; - long(*bz_grid_addresses)[3]; - long *D_diag; - long(*Q)[3]; - double *fc3; - double(*svecs)[3]; - long(*multi)[2]; - double *masses; - long *p2s; - long *s2p; - Larray *band_indices; - Darray *temperatures; - char *all_shortest; - long multi_dims[2]; - long i; - long is_compact_fc3; - - if (!PyArg_ParseTuple( - args, "OddOOOOOOOOOOOOOOOlllOdl", &py_gamma, &sigma, &sigma_cutoff, - &py_frequencies, &py_eigenvectors, &py_triplets, - &py_triplet_weights, &py_bz_grid_addresses, &py_D_diag, &py_Q, - &py_fc3, &py_svecs, &py_multi, &py_masses, &py_p2s_map, &py_s2p_map, - &py_band_indices, &py_temperatures, &is_NU, &symmetrize_fc3_q, - &make_r0_average, &py_all_shortest, &cutoff_frequency, - &openmp_per_triplets)) { - return NULL; - } - - gamma = (double *)PyArray_DATA(py_gamma); - frequencies = (double *)PyArray_DATA(py_frequencies); - eigenvectors = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - num_triplets = (long)PyArray_DIMS(py_triplets)[0]; - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - fc3 = (double *)PyArray_DATA(py_fc3); - if (PyArray_DIMS(py_fc3)[0] == PyArray_DIMS(py_fc3)[1]) { - is_compact_fc3 = 0; - } else { - is_compact_fc3 = 1; - } - svecs = (double(*)[3])PyArray_DATA(py_svecs); - for (i = 0; i < 2; i++) { - multi_dims[i] = PyArray_DIMS(py_multi)[i]; - } - multi = (long(*)[2])PyArray_DATA(py_multi); - masses = (double *)PyArray_DATA(py_masses); - p2s = (long *)PyArray_DATA(py_p2s_map); - s2p = (long *)PyArray_DATA(py_s2p_map); - band_indices = convert_to_larray(py_band_indices); - temperatures = convert_to_darray(py_temperatures); - all_shortest = (char *)PyArray_DATA(py_all_shortest); - - ph3py_get_pp_collision_with_sigma( - gamma, sigma, sigma_cutoff, frequencies, eigenvectors, triplets, - num_triplets, triplet_weights, bz_grid_addresses, D_diag, Q, fc3, - is_compact_fc3, svecs, multi_dims, multi, masses, p2s, s2p, - band_indices, temperatures, is_NU, symmetrize_fc3_q, make_r0_average, - all_shortest, cutoff_frequency, openmp_per_triplets); - - free(band_indices); - band_indices = NULL; - free(temperatures); - temperatures = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_imag_self_energy_with_g(PyObject *self, - PyObject *args) { - PyArrayObject *py_gamma; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_g; - PyArrayObject *py_g_zero; - double cutoff_frequency, temperature; - long frequency_point_index; - - Darray *fc3_normal_squared; - double *gamma; - double *g; - char *g_zero; - double *frequencies; - long(*triplets)[3]; - long *triplet_weights; - long num_frequency_points; - - if (!PyArg_ParseTuple(args, "OOOOOdOOdl", &py_gamma, &py_fc3_normal_squared, - &py_triplets, &py_triplet_weights, &py_frequencies, - &temperature, &py_g, &py_g_zero, &cutoff_frequency, - &frequency_point_index)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - gamma = (double *)PyArray_DATA(py_gamma); - g = (double *)PyArray_DATA(py_g); - g_zero = (char *)PyArray_DATA(py_g_zero); - frequencies = (double *)PyArray_DATA(py_frequencies); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - num_frequency_points = (long)PyArray_DIMS(py_g)[2]; - - ph3py_get_imag_self_energy_at_bands_with_g( - gamma, fc3_normal_squared, frequencies, triplets, triplet_weights, g, - g_zero, temperature, cutoff_frequency, num_frequency_points, - frequency_point_index); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_detailed_imag_self_energy_with_g(PyObject *self, - PyObject *args) { - PyArrayObject *py_gamma_detail; - PyArrayObject *py_gamma_N; - PyArrayObject *py_gamma_U; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_g; - PyArrayObject *py_g_zero; - double cutoff_frequency, temperature; - - Darray *fc3_normal_squared; - double *gamma_detail; - double *gamma_N; - double *gamma_U; - double *g; - char *g_zero; - double *frequencies; - long(*triplets)[3]; - long *triplet_weights; - long(*bz_grid_addresses)[3]; - - if (!PyArg_ParseTuple(args, "OOOOOOOOdOOd", &py_gamma_detail, &py_gamma_N, - &py_gamma_U, &py_fc3_normal_squared, &py_triplets, - &py_triplet_weights, &py_bz_grid_addresses, - &py_frequencies, &temperature, &py_g, &py_g_zero, - &cutoff_frequency)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - gamma_detail = (double *)PyArray_DATA(py_gamma_detail); - gamma_N = (double *)PyArray_DATA(py_gamma_N); - gamma_U = (double *)PyArray_DATA(py_gamma_U); - g = (double *)PyArray_DATA(py_g); - g_zero = (char *)PyArray_DATA(py_g_zero); - frequencies = (double *)PyArray_DATA(py_frequencies); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - - ph3py_get_detailed_imag_self_energy_at_bands_with_g( - gamma_detail, gamma_N, gamma_U, fc3_normal_squared, frequencies, - triplets, triplet_weights, bz_grid_addresses, g, g_zero, temperature, - cutoff_frequency); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_real_self_energy_at_bands(PyObject *self, - PyObject *args) { - PyArrayObject *py_shift; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_band_indices; - double epsilon, unit_conversion_factor, cutoff_frequency, temperature; - - Darray *fc3_normal_squared; - double *shift; - double *frequencies; - long *band_indices; - long(*triplets)[3]; - long *triplet_weights; - - if (!PyArg_ParseTuple(args, "OOOOOOdddd", &py_shift, &py_fc3_normal_squared, - &py_triplets, &py_triplet_weights, &py_frequencies, - &py_band_indices, &temperature, &epsilon, - &unit_conversion_factor, &cutoff_frequency)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - shift = (double *)PyArray_DATA(py_shift); - frequencies = (double *)PyArray_DATA(py_frequencies); - band_indices = (long *)PyArray_DATA(py_band_indices); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - - ph3py_get_real_self_energy_at_bands( - shift, fc3_normal_squared, band_indices, frequencies, triplets, - triplet_weights, epsilon, temperature, unit_conversion_factor, - cutoff_frequency); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_real_self_energy_at_frequency_point(PyObject *self, - PyObject *args) { - PyArrayObject *py_shift; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplet_weights; - PyArrayObject *py_band_indices; - double frequency_point, epsilon, unit_conversion_factor, cutoff_frequency; - double temperature; - - Darray *fc3_normal_squared; - double *shift; - double *frequencies; - long *band_indices; - long(*triplets)[3]; - long *triplet_weights; - - if (!PyArg_ParseTuple(args, "OdOOOOOdddd", &py_shift, &frequency_point, - &py_fc3_normal_squared, &py_triplets, - &py_triplet_weights, &py_frequencies, - &py_band_indices, &temperature, &epsilon, - &unit_conversion_factor, &cutoff_frequency)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - shift = (double *)PyArray_DATA(py_shift); - frequencies = (double *)PyArray_DATA(py_frequencies); - band_indices = (long *)PyArray_DATA(py_band_indices); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplet_weights = (long *)PyArray_DATA(py_triplet_weights); - - ph3py_get_real_self_energy_at_frequency_point( - shift, frequency_point, fc3_normal_squared, band_indices, frequencies, - triplets, triplet_weights, epsilon, temperature, unit_conversion_factor, - cutoff_frequency); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_collision_matrix(PyObject *self, PyObject *args) { - PyArrayObject *py_collision_matrix; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplets_map; - PyArrayObject *py_map_q; - PyArrayObject *py_g; - PyArrayObject *py_rotated_grid_points; - PyArrayObject *py_rotations_cartesian; - double temperature, unit_conversion_factor, cutoff_frequency; - - Darray *fc3_normal_squared; - double *collision_matrix; - double *g; - double *frequencies; - long(*triplets)[3]; - long *triplets_map; - long *map_q; - long *rotated_grid_points; - long num_gp, num_ir_gp, num_rot; - double *rotations_cartesian; - - if (!PyArg_ParseTuple( - args, "OOOOOOOOOddd", &py_collision_matrix, &py_fc3_normal_squared, - &py_frequencies, &py_g, &py_triplets, &py_triplets_map, &py_map_q, - &py_rotated_grid_points, &py_rotations_cartesian, &temperature, - &unit_conversion_factor, &cutoff_frequency)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - g = (double *)PyArray_DATA(py_g); - frequencies = (double *)PyArray_DATA(py_frequencies); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplets_map = (long *)PyArray_DATA(py_triplets_map); - num_gp = (long)PyArray_DIMS(py_triplets_map)[0]; - map_q = (long *)PyArray_DATA(py_map_q); - rotated_grid_points = (long *)PyArray_DATA(py_rotated_grid_points); - num_ir_gp = (long)PyArray_DIMS(py_rotated_grid_points)[0]; - num_rot = (long)PyArray_DIMS(py_rotated_grid_points)[1]; - rotations_cartesian = (double *)PyArray_DATA(py_rotations_cartesian); - - assert(num_rot == PyArray_DIMS(py_rotations_cartesian)[0]); - assert(num_gp == PyArray_DIMS(py_frequencies)[0]); - - ph3py_get_collision_matrix(collision_matrix, fc3_normal_squared, - frequencies, triplets, triplets_map, map_q, - rotated_grid_points, rotations_cartesian, g, - num_ir_gp, num_gp, num_rot, temperature, - unit_conversion_factor, cutoff_frequency); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_get_reducible_collision_matrix(PyObject *self, - PyObject *args) { - PyArrayObject *py_collision_matrix; - PyArrayObject *py_fc3_normal_squared; - PyArrayObject *py_frequencies; - PyArrayObject *py_triplets; - PyArrayObject *py_triplets_map; - PyArrayObject *py_map_q; - PyArrayObject *py_g; - double temperature, unit_conversion_factor, cutoff_frequency; - - Darray *fc3_normal_squared; - double *collision_matrix; - double *g; - double *frequencies; - long(*triplets)[3]; - long *triplets_map; - long num_gp; - long *map_q; - - if (!PyArg_ParseTuple( - args, "OOOOOOOddd", &py_collision_matrix, &py_fc3_normal_squared, - &py_frequencies, &py_g, &py_triplets, &py_triplets_map, &py_map_q, - &temperature, &unit_conversion_factor, &cutoff_frequency)) { - return NULL; - } - - fc3_normal_squared = convert_to_darray(py_fc3_normal_squared); - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - g = (double *)PyArray_DATA(py_g); - frequencies = (double *)PyArray_DATA(py_frequencies); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - triplets_map = (long *)PyArray_DATA(py_triplets_map); - num_gp = (long)PyArray_DIMS(py_triplets_map)[0]; - map_q = (long *)PyArray_DATA(py_map_q); - - ph3py_get_reducible_collision_matrix( - collision_matrix, fc3_normal_squared, frequencies, triplets, - triplets_map, map_q, g, num_gp, temperature, unit_conversion_factor, - cutoff_frequency); - - free(fc3_normal_squared); - fc3_normal_squared = NULL; - - Py_RETURN_NONE; -} - -static PyObject *py_symmetrize_collision_matrix(PyObject *self, - PyObject *args) { - PyArrayObject *py_collision_matrix; - - double *collision_matrix; - long num_band, num_grid_points, num_temp, num_sigma; - long num_column; - - if (!PyArg_ParseTuple(args, "O", &py_collision_matrix)) { - return NULL; - } - - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - num_sigma = (long)PyArray_DIMS(py_collision_matrix)[0]; - num_temp = (long)PyArray_DIMS(py_collision_matrix)[1]; - num_grid_points = (long)PyArray_DIMS(py_collision_matrix)[2]; - num_band = (long)PyArray_DIMS(py_collision_matrix)[3]; - - if (PyArray_NDIM(py_collision_matrix) == 8) { - num_column = num_grid_points * num_band * 3; - } else { - num_column = num_grid_points * num_band; - } - - ph3py_symmetrize_collision_matrix(collision_matrix, num_column, num_temp, - num_sigma); - - Py_RETURN_NONE; -} - -static PyObject *py_expand_collision_matrix(PyObject *self, PyObject *args) { - PyArrayObject *py_collision_matrix; - PyArrayObject *py_ir_grid_points; - PyArrayObject *py_rot_grid_points; - - double *collision_matrix; - long *rot_grid_points; - long *ir_grid_points; - long num_band, num_grid_points, num_temp, num_sigma, num_rot, num_ir_gp; - - if (!PyArg_ParseTuple(args, "OOO", &py_collision_matrix, &py_ir_grid_points, - &py_rot_grid_points)) { - return NULL; - } - - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - rot_grid_points = (long *)PyArray_DATA(py_rot_grid_points); - ir_grid_points = (long *)PyArray_DATA(py_ir_grid_points); - num_sigma = (long)PyArray_DIMS(py_collision_matrix)[0]; - num_temp = (long)PyArray_DIMS(py_collision_matrix)[1]; - num_grid_points = (long)PyArray_DIMS(py_collision_matrix)[2]; - num_band = (long)PyArray_DIMS(py_collision_matrix)[3]; - num_rot = (long)PyArray_DIMS(py_rot_grid_points)[0]; - num_ir_gp = (long)PyArray_DIMS(py_ir_grid_points)[0]; - - ph3py_expand_collision_matrix(collision_matrix, rot_grid_points, - ir_grid_points, num_ir_gp, num_grid_points, - num_rot, num_sigma, num_temp, num_band); - - Py_RETURN_NONE; -} - -static PyObject *py_get_isotope_strength(PyObject *self, PyObject *args) { - PyArrayObject *py_gamma; - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_band_indices; - PyArrayObject *py_mass_variances; - PyArrayObject *py_ir_grid_points; - PyArrayObject *py_weights; - - long grid_point; - double cutoff_frequency; - double sigma; - - double *gamma; - double *frequencies; - long *ir_grid_points; - double *weights; - _lapack_complex_double *eigenvectors; - long *band_indices; - double *mass_variances; - long num_band, num_band0, num_ir_grid_points; - - if (!PyArg_ParseTuple(args, "OlOOOOOOdd", &py_gamma, &grid_point, - &py_ir_grid_points, &py_weights, &py_mass_variances, - &py_frequencies, &py_eigenvectors, &py_band_indices, - &sigma, &cutoff_frequency)) { - return NULL; - } - - gamma = (double *)PyArray_DATA(py_gamma); - frequencies = (double *)PyArray_DATA(py_frequencies); - eigenvectors = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - ir_grid_points = (long *)PyArray_DATA(py_ir_grid_points); - weights = (double *)PyArray_DATA(py_weights); - band_indices = (long *)PyArray_DATA(py_band_indices); - mass_variances = (double *)PyArray_DATA(py_mass_variances); - num_band = (long)PyArray_DIMS(py_frequencies)[1]; - num_band0 = (long)PyArray_DIMS(py_band_indices)[0]; - num_ir_grid_points = (long)PyArray_DIMS(py_ir_grid_points)[0]; - - ph3py_get_isotope_scattering_strength( - gamma, grid_point, ir_grid_points, weights, mass_variances, frequencies, - eigenvectors, num_ir_grid_points, band_indices, num_band, num_band0, - sigma, cutoff_frequency); - - Py_RETURN_NONE; -} - -static PyObject *py_get_thm_isotope_strength(PyObject *self, PyObject *args) { - PyArrayObject *py_gamma; - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_band_indices; - PyArrayObject *py_mass_variances; - PyArrayObject *py_ir_grid_points; - PyArrayObject *py_weights; - PyArrayObject *py_integration_weights; - long grid_point; - double cutoff_frequency; - - double *gamma; - double *frequencies; - long *ir_grid_points; - double *weights; - _lapack_complex_double *eigenvectors; - long *band_indices; - double *mass_variances; - long num_band, num_band0, num_ir_grid_points; - double *integration_weights; - - if (!PyArg_ParseTuple(args, "OlOOOOOOOd", &py_gamma, &grid_point, - &py_ir_grid_points, &py_weights, &py_mass_variances, - &py_frequencies, &py_eigenvectors, &py_band_indices, - &py_integration_weights, &cutoff_frequency)) { - return NULL; - } - - gamma = (double *)PyArray_DATA(py_gamma); - frequencies = (double *)PyArray_DATA(py_frequencies); - ir_grid_points = (long *)PyArray_DATA(py_ir_grid_points); - weights = (double *)PyArray_DATA(py_weights); - eigenvectors = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - band_indices = (long *)PyArray_DATA(py_band_indices); - mass_variances = (double *)PyArray_DATA(py_mass_variances); - num_band = (long)PyArray_DIMS(py_frequencies)[1]; - num_band0 = (long)PyArray_DIMS(py_band_indices)[0]; - integration_weights = (double *)PyArray_DATA(py_integration_weights); - num_ir_grid_points = (long)PyArray_DIMS(py_ir_grid_points)[0]; - - ph3py_get_thm_isotope_scattering_strength( - gamma, grid_point, ir_grid_points, weights, mass_variances, frequencies, - eigenvectors, num_ir_grid_points, band_indices, num_band, num_band0, - integration_weights, cutoff_frequency); - - Py_RETURN_NONE; -} - -static PyObject *py_distribute_fc3(PyObject *self, PyObject *args) { - PyArrayObject *force_constants_third; - long target; - long source; - PyArrayObject *rotation_cart_inv; - PyArrayObject *atom_mapping_py; - - double *fc3; - double *rot_cart_inv; - long *atom_mapping; - long num_atom; - - if (!PyArg_ParseTuple(args, "OllOO", &force_constants_third, &target, - &source, &atom_mapping_py, &rotation_cart_inv)) { - return NULL; - } - - fc3 = (double *)PyArray_DATA(force_constants_third); - rot_cart_inv = (double *)PyArray_DATA(rotation_cart_inv); - atom_mapping = (long *)PyArray_DATA(atom_mapping_py); - num_atom = (long)PyArray_DIMS(atom_mapping_py)[0]; - - ph3py_distribute_fc3(fc3, target, source, atom_mapping, num_atom, - rot_cart_inv); - - Py_RETURN_NONE; -} - -static PyObject *py_rotate_delta_fc2s(PyObject *self, PyObject *args) { - PyArrayObject *py_fc3; - PyArrayObject *py_delta_fc2s; - PyArrayObject *py_inv_U; - PyArrayObject *py_site_sym_cart; - PyArrayObject *py_rot_map_syms; - - double(*fc3)[3][3][3]; - double(*delta_fc2s)[3][3]; - double *inv_U; - double(*site_sym_cart)[3][3]; - long *rot_map_syms; - long num_atom, num_disp, num_site_sym; - - if (!PyArg_ParseTuple(args, "OOOOO", &py_fc3, &py_delta_fc2s, &py_inv_U, - &py_site_sym_cart, &py_rot_map_syms)) { - return NULL; - } - - /* (num_atom, num_atom, 3, 3, 3) */ - fc3 = (double(*)[3][3][3])PyArray_DATA(py_fc3); - /* (n_u1, num_atom, num_atom, 3, 3) */ - delta_fc2s = (double(*)[3][3])PyArray_DATA(py_delta_fc2s); - /* (3, n_u1 * n_sym) */ - inv_U = (double *)PyArray_DATA(py_inv_U); - /* (n_sym, 3, 3) */ - site_sym_cart = (double(*)[3][3])PyArray_DATA(py_site_sym_cart); - /* (n_sym, natom) */ - rot_map_syms = (long *)PyArray_DATA(py_rot_map_syms); - - num_atom = (long)PyArray_DIMS(py_fc3)[0]; - num_disp = (long)PyArray_DIMS(py_delta_fc2s)[0]; - num_site_sym = (long)PyArray_DIMS(py_site_sym_cart)[0]; - - ph3py_rotate_delta_fc2(fc3, delta_fc2s, inv_U, site_sym_cart, rot_map_syms, - num_atom, num_site_sym, num_disp); - - Py_RETURN_NONE; -} - -static PyObject *py_get_permutation_symmetry_fc3(PyObject *self, - PyObject *args) { - PyArrayObject *py_fc3; - - double *fc3; - long num_atom; - - if (!PyArg_ParseTuple(args, "O", &py_fc3)) { - return NULL; - } - - fc3 = (double *)PyArray_DATA(py_fc3); - num_atom = (long)PyArray_DIMS(py_fc3)[0]; - - ph3py_get_permutation_symmetry_fc3(fc3, num_atom); - - Py_RETURN_NONE; -} - -static PyObject *py_get_permutation_symmetry_compact_fc3(PyObject *self, - PyObject *args) { - PyArrayObject *py_fc3; - PyArrayObject *py_permutations; - PyArrayObject *py_s2pp_map; - PyArrayObject *py_p2s_map; - PyArrayObject *py_nsym_list; - - double *fc3; - long *s2pp; - long *p2s; - long *nsym_list; - long *perms; - long n_patom, n_satom; - - if (!PyArg_ParseTuple(args, "OOOOO", &py_fc3, &py_permutations, - &py_s2pp_map, &py_p2s_map, &py_nsym_list)) { - return NULL; - } - - fc3 = (double *)PyArray_DATA(py_fc3); - perms = (long *)PyArray_DATA(py_permutations); - s2pp = (long *)PyArray_DATA(py_s2pp_map); - p2s = (long *)PyArray_DATA(py_p2s_map); - nsym_list = (long *)PyArray_DATA(py_nsym_list); - n_patom = (long)PyArray_DIMS(py_fc3)[0]; - n_satom = (long)PyArray_DIMS(py_fc3)[1]; - - ph3py_get_permutation_symmetry_compact_fc3(fc3, p2s, s2pp, nsym_list, perms, - n_satom, n_patom); - - Py_RETURN_NONE; -} - -static PyObject *py_transpose_compact_fc3(PyObject *self, PyObject *args) { - PyArrayObject *py_fc3; - PyArrayObject *py_permutations; - PyArrayObject *py_s2pp_map; - PyArrayObject *py_p2s_map; - PyArrayObject *py_nsym_list; - long t_type; - - double *fc3; - long *s2pp; - long *p2s; - long *nsym_list; - long *perms; - long n_patom, n_satom; - - if (!PyArg_ParseTuple(args, "OOOOOl", &py_fc3, &py_permutations, - &py_s2pp_map, &py_p2s_map, &py_nsym_list, &t_type)) { - return NULL; - } - - fc3 = (double *)PyArray_DATA(py_fc3); - perms = (long *)PyArray_DATA(py_permutations); - s2pp = (long *)PyArray_DATA(py_s2pp_map); - p2s = (long *)PyArray_DATA(py_p2s_map); - nsym_list = (long *)PyArray_DATA(py_nsym_list); - n_patom = (long)PyArray_DIMS(py_fc3)[0]; - n_satom = (long)PyArray_DIMS(py_fc3)[1]; - - ph3py_transpose_compact_fc3(fc3, p2s, s2pp, nsym_list, perms, n_satom, - n_patom, t_type); - - Py_RETURN_NONE; -} - -static PyObject *py_get_thm_relative_grid_address(PyObject *self, - PyObject *args) { - PyArrayObject *py_relative_grid_address; - PyArrayObject *py_reciprocal_lattice_py; - - long(*relative_grid_address)[4][3]; - double(*reciprocal_lattice)[3]; - - if (!PyArg_ParseTuple(args, "OO", &py_relative_grid_address, - &py_reciprocal_lattice_py)) { - return NULL; - } - - relative_grid_address = - (long(*)[4][3])PyArray_DATA(py_relative_grid_address); - reciprocal_lattice = (double(*)[3])PyArray_DATA(py_reciprocal_lattice_py); - - ph3py_get_relative_grid_address(relative_grid_address, reciprocal_lattice); - - Py_RETURN_NONE; -} - -static PyObject *py_get_neighboring_grid_points(PyObject *self, - PyObject *args) { - PyArrayObject *py_relative_grid_points; - PyArrayObject *py_grid_points; - PyArrayObject *py_relative_grid_address; - PyArrayObject *py_D_diag; - PyArrayObject *py_bz_grid_address; - PyArrayObject *py_bz_map; - long bz_grid_type; - - long *relative_grid_points; - long *grid_points; - long num_grid_points, num_relative_grid_address; - long(*relative_grid_address)[3]; - long *D_diag; - long(*bz_grid_address)[3]; - long *bz_map; - - if (!PyArg_ParseTuple(args, "OOOOOOl", &py_relative_grid_points, - &py_grid_points, &py_relative_grid_address, - &py_D_diag, &py_bz_grid_address, &py_bz_map, - &bz_grid_type)) { - return NULL; - } - - relative_grid_points = (long *)PyArray_DATA(py_relative_grid_points); - grid_points = (long *)PyArray_DATA(py_grid_points); - num_grid_points = (long)PyArray_DIMS(py_grid_points)[0]; - relative_grid_address = (long(*)[3])PyArray_DATA(py_relative_grid_address); - num_relative_grid_address = (long)PyArray_DIMS(py_relative_grid_address)[0]; - D_diag = (long *)PyArray_DATA(py_D_diag); - bz_grid_address = (long(*)[3])PyArray_DATA(py_bz_grid_address); - bz_map = (long *)PyArray_DATA(py_bz_map); - - ph3py_get_neighboring_gird_points( - relative_grid_points, grid_points, relative_grid_address, D_diag, - bz_grid_address, bz_map, bz_grid_type, num_grid_points, - num_relative_grid_address); - - Py_RETURN_NONE; -} - -static PyObject *py_get_thm_integration_weights_at_grid_points(PyObject *self, - PyObject *args) { - PyArrayObject *py_iw; - PyArrayObject *py_frequency_points; - PyArrayObject *py_relative_grid_address; - PyArrayObject *py_D_diag; - PyArrayObject *py_grid_points; - PyArrayObject *py_frequencies; - PyArrayObject *py_bz_grid_address; - PyArrayObject *py_gp2irgp_map; - PyArrayObject *py_bz_map; - long bz_grid_type; - char *function; - - double *iw; - double *frequency_points; - long num_frequency_points, num_band, num_gp; - long(*relative_grid_address)[4][3]; - long *D_diag; - long *grid_points; - long(*bz_grid_address)[3]; - long *bz_map; - long *gp2irgp_map; - double *frequencies; - - if (!PyArg_ParseTuple(args, "OOOOOOOOOls", &py_iw, &py_frequency_points, - &py_relative_grid_address, &py_D_diag, - &py_grid_points, &py_frequencies, &py_bz_grid_address, - &py_bz_map, &py_gp2irgp_map, &bz_grid_type, - &function)) { - return NULL; - } - - iw = (double *)PyArray_DATA(py_iw); - frequency_points = (double *)PyArray_DATA(py_frequency_points); - num_frequency_points = (long)PyArray_DIMS(py_frequency_points)[0]; - relative_grid_address = - (long(*)[4][3])PyArray_DATA(py_relative_grid_address); - D_diag = (long *)PyArray_DATA(py_D_diag); - grid_points = (long *)PyArray_DATA(py_grid_points); - num_gp = (long)PyArray_DIMS(py_grid_points)[0]; - bz_grid_address = (long(*)[3])PyArray_DATA(py_bz_grid_address); - bz_map = (long *)PyArray_DATA(py_bz_map); - gp2irgp_map = (long *)PyArray_DATA(py_gp2irgp_map); - frequencies = (double *)PyArray_DATA(py_frequencies); - num_band = (long)PyArray_DIMS(py_frequencies)[1]; - - ph3py_get_thm_integration_weights_at_grid_points( - iw, frequency_points, num_frequency_points, num_band, num_gp, - relative_grid_address, D_diag, grid_points, bz_grid_address, bz_map, - bz_grid_type, frequencies, gp2irgp_map, function[0]); - - Py_RETURN_NONE; -} - -static PyObject *py_tpl_get_triplets_reciprocal_mesh_at_q(PyObject *self, - PyObject *args) { - PyArrayObject *py_map_triplets; - PyArrayObject *py_map_q; - PyArrayObject *py_D_diag; - PyArrayObject *py_rotations; - long fixed_grid_number; - long is_time_reversal; - long swappable; - - long *map_triplets; - long *map_q; - long *D_diag; - long(*rot)[3][3]; - long num_rot; - long num_ir; - - if (!PyArg_ParseTuple(args, "OOlOlOl", &py_map_triplets, &py_map_q, - &fixed_grid_number, &py_D_diag, &is_time_reversal, - &py_rotations, &swappable)) { - return NULL; - } - - map_triplets = (long *)PyArray_DATA(py_map_triplets); - map_q = (long *)PyArray_DATA(py_map_q); - D_diag = (long *)PyArray_DATA(py_D_diag); - rot = (long(*)[3][3])PyArray_DATA(py_rotations); - num_rot = (long)PyArray_DIMS(py_rotations)[0]; - num_ir = ph3py_get_triplets_reciprocal_mesh_at_q( - map_triplets, map_q, fixed_grid_number, D_diag, is_time_reversal, - num_rot, rot, swappable); - - return PyLong_FromLong(num_ir); -} - -static PyObject *py_tpl_get_BZ_triplets_at_q(PyObject *self, PyObject *args) { - PyArrayObject *py_triplets; - PyArrayObject *py_bz_grid_address; - PyArrayObject *py_bz_map; - PyArrayObject *py_map_triplets; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - long grid_point; - long bz_grid_type; - - long(*triplets)[3]; - long(*bz_grid_address)[3]; - long *bz_map; - long *map_triplets; - long num_map_triplets; - long *D_diag; - long(*Q)[3]; - long num_ir; - - if (!PyArg_ParseTuple(args, "OlOOOOOl", &py_triplets, &grid_point, - &py_bz_grid_address, &py_bz_map, &py_map_triplets, - &py_D_diag, &py_Q, &bz_grid_type)) { - return NULL; - } - - triplets = (long(*)[3])PyArray_DATA(py_triplets); - bz_grid_address = (long(*)[3])PyArray_DATA(py_bz_grid_address); - bz_map = (long *)PyArray_DATA(py_bz_map); - map_triplets = (long *)PyArray_DATA(py_map_triplets); - num_map_triplets = (long)PyArray_DIMS(py_map_triplets)[0]; - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - - num_ir = ph3py_get_BZ_triplets_at_q(triplets, grid_point, bz_grid_address, - bz_map, map_triplets, num_map_triplets, - D_diag, Q, bz_grid_type); - - return PyLong_FromLong(num_ir); -} - -static PyObject *py_get_triplets_integration_weights(PyObject *self, - PyObject *args) { - PyArrayObject *py_iw; - PyArrayObject *py_iw_zero; - PyArrayObject *py_frequency_points; - PyArrayObject *py_relative_grid_address; - PyArrayObject *py_D_diag; - PyArrayObject *py_triplets; - PyArrayObject *py_frequencies1; - PyArrayObject *py_frequencies2; - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_bz_map; - long bz_grid_type; - long tp_type; - - double *iw; - char *iw_zero; - double *frequency_points; - long(*relative_grid_address)[4][3]; - long *D_diag; - long(*triplets)[3]; - long(*bz_grid_addresses)[3]; - long *bz_map; - double *frequencies1, *frequencies2; - long num_band0, num_band1, num_band2, num_triplets; - - if (!PyArg_ParseTuple(args, "OOOOOOOOOOll", &py_iw, &py_iw_zero, - &py_frequency_points, &py_relative_grid_address, - &py_D_diag, &py_triplets, &py_frequencies1, - &py_frequencies2, &py_bz_grid_addresses, &py_bz_map, - &bz_grid_type, &tp_type)) { - return NULL; - } - - iw = (double *)PyArray_DATA(py_iw); - iw_zero = (char *)PyArray_DATA(py_iw_zero); - frequency_points = (double *)PyArray_DATA(py_frequency_points); - num_band0 = (long)PyArray_DIMS(py_frequency_points)[0]; - relative_grid_address = - (long(*)[4][3])PyArray_DATA(py_relative_grid_address); - D_diag = (long *)PyArray_DATA(py_D_diag); - triplets = (long(*)[3])PyArray_DATA(py_triplets); - num_triplets = (long)PyArray_DIMS(py_triplets)[0]; - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - bz_map = (long *)PyArray_DATA(py_bz_map); - frequencies1 = (double *)PyArray_DATA(py_frequencies1); - frequencies2 = (double *)PyArray_DATA(py_frequencies2); - num_band1 = (long)PyArray_DIMS(py_frequencies1)[1]; - num_band2 = (long)PyArray_DIMS(py_frequencies2)[1]; - - ph3py_get_integration_weight( - iw, iw_zero, frequency_points, num_band0, relative_grid_address, D_diag, - triplets, num_triplets, bz_grid_addresses, bz_map, bz_grid_type, - frequencies1, num_band1, frequencies2, num_band2, tp_type, 1); - - Py_RETURN_NONE; -} - -static PyObject *py_get_triplets_integration_weights_with_sigma( - PyObject *self, PyObject *args) { - PyArrayObject *py_iw; - PyArrayObject *py_iw_zero; - PyArrayObject *py_frequency_points; - PyArrayObject *py_triplets; - PyArrayObject *py_frequencies; - double sigma, sigma_cutoff; - - double *iw; - char *iw_zero; - double *frequency_points; - long(*triplets)[3]; - double *frequencies; - long num_band0, num_band, num_iw, num_triplets; - - if (!PyArg_ParseTuple(args, "OOOOOdd", &py_iw, &py_iw_zero, - &py_frequency_points, &py_triplets, &py_frequencies, - &sigma, &sigma_cutoff)) { - return NULL; - } - - iw = (double *)PyArray_DATA(py_iw); - iw_zero = (char *)PyArray_DATA(py_iw_zero); - frequency_points = (double *)PyArray_DATA(py_frequency_points); - num_band0 = (long)PyArray_DIMS(py_frequency_points)[0]; - triplets = (long(*)[3])PyArray_DATA(py_triplets); - num_triplets = (long)PyArray_DIMS(py_triplets)[0]; - frequencies = (double *)PyArray_DATA(py_frequencies); - num_band = (long)PyArray_DIMS(py_frequencies)[1]; - num_iw = (long)PyArray_DIMS(py_iw)[0]; - - ph3py_get_integration_weight_with_sigma( - iw, iw_zero, sigma, sigma_cutoff, frequency_points, num_band0, triplets, - num_triplets, frequencies, num_band, num_iw); - - Py_RETURN_NONE; -} - -static PyObject *py_get_grid_index_from_address(PyObject *self, - PyObject *args) { - PyArrayObject *py_address; - PyArrayObject *py_D_diag; - - long *address; - long *D_diag; - long gp; - - if (!PyArg_ParseTuple(args, "OO", &py_address, &py_D_diag)) { - return NULL; - } - - address = (long *)PyArray_DATA(py_address); - D_diag = (long *)PyArray_DATA(py_D_diag); - - gp = ph3py_get_grid_index_from_address(address, D_diag); - - return PyLong_FromLong(gp); -} - -static PyObject *py_get_gr_grid_addresses(PyObject *self, PyObject *args) { - PyArrayObject *py_gr_grid_addresses; - PyArrayObject *py_D_diag; - - long(*gr_grid_addresses)[3]; - long *D_diag; - - if (!PyArg_ParseTuple(args, "OO", &py_gr_grid_addresses, &py_D_diag)) { - return NULL; - } - - gr_grid_addresses = (long(*)[3])PyArray_DATA(py_gr_grid_addresses); - D_diag = (long *)PyArray_DATA(py_D_diag); - - ph3py_get_gr_grid_addresses(gr_grid_addresses, D_diag); - - Py_RETURN_NONE; -} - -static PyObject *py_get_reciprocal_rotations(PyObject *self, PyObject *args) { - PyArrayObject *py_rec_rotations; - PyArrayObject *py_rotations; - long is_time_reversal; - - long(*rec_rotations)[3][3]; - long(*rotations)[3][3]; - long num_rot, num_rec_rot; - - if (!PyArg_ParseTuple(args, "OOl", &py_rec_rotations, &py_rotations, - &is_time_reversal)) { - return NULL; - } - - rec_rotations = (long(*)[3][3])PyArray_DATA(py_rec_rotations); - rotations = (long(*)[3][3])PyArray_DATA(py_rotations); - num_rot = (long)PyArray_DIMS(py_rotations)[0]; - - num_rec_rot = ph3py_get_reciprocal_rotations(rec_rotations, rotations, - num_rot, is_time_reversal); - - return PyLong_FromLong(num_rec_rot); -} - -static PyObject *py_transform_rotations(PyObject *self, PyObject *args) { - PyArrayObject *py_transformed_rotations; - PyArrayObject *py_rotations; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - - long(*transformed_rotations)[3][3]; - long(*rotations)[3][3]; - long *D_diag; - long(*Q)[3]; - long num_rot, succeeded; - - if (!PyArg_ParseTuple(args, "OOOO", &py_transformed_rotations, - &py_rotations, &py_D_diag, &py_Q)) { - return NULL; - } - - transformed_rotations = - (long(*)[3][3])PyArray_DATA(py_transformed_rotations); - rotations = (long(*)[3][3])PyArray_DATA(py_rotations); - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - num_rot = (long)PyArray_DIMS(py_transformed_rotations)[0]; - - succeeded = ph3py_transform_rotations(transformed_rotations, rotations, - num_rot, D_diag, Q); - if (succeeded) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -static PyObject *py_get_snf3x3(PyObject *self, PyObject *args) { - PyArrayObject *py_D_diag; - PyArrayObject *py_P; - PyArrayObject *py_Q; - PyArrayObject *py_A; - - long *D_diag; - long(*P)[3]; - long(*Q)[3]; - long(*A)[3]; - long succeeded; - - if (!PyArg_ParseTuple(args, "OOOO", &py_D_diag, &py_P, &py_Q, &py_A)) { - return NULL; - } - - D_diag = (long *)PyArray_DATA(py_D_diag); - P = (long(*)[3])PyArray_DATA(py_P); - Q = (long(*)[3])PyArray_DATA(py_Q); - A = (long(*)[3])PyArray_DATA(py_A); - - succeeded = ph3py_get_snf3x3(D_diag, P, Q, A); - if (succeeded) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -static PyObject *py_get_ir_grid_map(PyObject *self, PyObject *args) { - PyArrayObject *py_grid_mapping_table; - PyArrayObject *py_D_diag; - PyArrayObject *py_is_shift; - PyArrayObject *py_rotations; - - long *D_diag; - long *is_shift; - long(*rot)[3][3]; - long num_rot; - - long *grid_mapping_table; - long num_ir; - - if (!PyArg_ParseTuple(args, "OOOO", &py_grid_mapping_table, &py_D_diag, - &py_is_shift, &py_rotations)) { - return NULL; - } - - D_diag = (long *)PyArray_DATA(py_D_diag); - is_shift = (long *)PyArray_DATA(py_is_shift); - rot = (long(*)[3][3])PyArray_DATA(py_rotations); - num_rot = (long)PyArray_DIMS(py_rotations)[0]; - grid_mapping_table = (long *)PyArray_DATA(py_grid_mapping_table); - - num_ir = ph3py_get_ir_grid_map(grid_mapping_table, D_diag, is_shift, rot, - num_rot); - return PyLong_FromLong(num_ir); -} - -static PyObject *py_get_bz_grid_addresses(PyObject *self, PyObject *args) { - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_bz_map; - PyArrayObject *py_bzg2grg; - PyArrayObject *py_D_diag; - PyArrayObject *py_Q; - PyArrayObject *py_PS; - PyArrayObject *py_reciprocal_lattice; - long type; - - long(*bz_grid_addresses)[3]; - long *bz_map; - long *bzg2grg; - long *D_diag; - long(*Q)[3]; - long *PS; - double(*reciprocal_lattice)[3]; - long num_total_gp; - - if (!PyArg_ParseTuple(args, "OOOOOOOl", &py_bz_grid_addresses, &py_bz_map, - &py_bzg2grg, &py_D_diag, &py_Q, &py_PS, - &py_reciprocal_lattice, &type)) { - return NULL; - } - - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - bz_map = (long *)PyArray_DATA(py_bz_map); - bzg2grg = (long *)PyArray_DATA(py_bzg2grg); - D_diag = (long *)PyArray_DATA(py_D_diag); - Q = (long(*)[3])PyArray_DATA(py_Q); - PS = (long *)PyArray_DATA(py_PS); - reciprocal_lattice = (double(*)[3])PyArray_DATA(py_reciprocal_lattice); - - num_total_gp = - ph3py_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, D_diag, - Q, PS, reciprocal_lattice, type); - - return PyLong_FromLong(num_total_gp); -} - -static PyObject *py_rotate_bz_grid_addresses(PyObject *self, PyObject *args) { - PyArrayObject *py_bz_grid_addresses; - PyArrayObject *py_rotation; - PyArrayObject *py_bz_map; - PyArrayObject *py_D_diag; - PyArrayObject *py_PS; - long bz_grid_index; - long type; - - long(*bz_grid_addresses)[3]; - long(*rotation)[3]; - long *bz_map; - long *D_diag; - long *PS; - long ret_bz_gp; - - if (!PyArg_ParseTuple(args, "lOOOOOl", &bz_grid_index, &py_rotation, - &py_bz_grid_addresses, &py_bz_map, &py_D_diag, &py_PS, - &type)) { - return NULL; - } - - bz_grid_addresses = (long(*)[3])PyArray_DATA(py_bz_grid_addresses); - rotation = (long(*)[3])PyArray_DATA(py_rotation); - bz_map = (long *)PyArray_DATA(py_bz_map); - D_diag = (long *)PyArray_DATA(py_D_diag); - PS = (long *)PyArray_DATA(py_PS); - - ret_bz_gp = ph3py_rotate_bz_grid_index( - bz_grid_index, rotation, bz_grid_addresses, bz_map, D_diag, PS, type); - - return PyLong_FromLong(ret_bz_gp); -} - -static PyObject *py_diagonalize_collision_matrix(PyObject *self, - PyObject *args) { - PyArrayObject *py_collision_matrix; - PyArrayObject *py_eigenvalues; - double cutoff; - long i_sigma, i_temp, is_pinv, solver; - - double *collision_matrix; - double *eigvals; - long num_temp, num_grid_point, num_band; - long num_column, adrs_shift; - long info; - - if (!PyArg_ParseTuple(args, "OOlldll", &py_collision_matrix, - &py_eigenvalues, &i_sigma, &i_temp, &cutoff, &solver, - &is_pinv)) { - return NULL; - } - - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - eigvals = (double *)PyArray_DATA(py_eigenvalues); - - if (PyArray_NDIM(py_collision_matrix) == 2) { - num_temp = 1; - num_column = (long)PyArray_DIM(py_collision_matrix, 1); - } else { - num_temp = (long)PyArray_DIM(py_collision_matrix, 1); - num_grid_point = (long)PyArray_DIM(py_collision_matrix, 2); - num_band = (long)PyArray_DIM(py_collision_matrix, 3); - if (PyArray_NDIM(py_collision_matrix) == 8) { - num_column = num_grid_point * num_band * 3; - } else { - num_column = num_grid_point * num_band; - } - } - adrs_shift = (i_sigma * num_column * num_column * num_temp + - i_temp * num_column * num_column); - - /* show_colmat_info(py_collision_matrix, i_sigma, i_temp, adrs_shift); */ - - info = ph3py_phonopy_dsyev(collision_matrix + adrs_shift, eigvals, - num_column, solver); - if (is_pinv) { - ph3py_pinv_from_eigensolution(collision_matrix + adrs_shift, eigvals, - num_column, cutoff, 0); - } - - return PyLong_FromLong(info); -} - -static PyObject *py_pinv_from_eigensolution(PyObject *self, PyObject *args) { - PyArrayObject *py_collision_matrix; - PyArrayObject *py_eigenvalues; - double cutoff; - long i_sigma, i_temp, pinv_method; - - double *collision_matrix; - double *eigvals; - long num_temp, num_grid_point, num_band; - long num_column, adrs_shift; - - if (!PyArg_ParseTuple(args, "OOlldl", &py_collision_matrix, &py_eigenvalues, - &i_sigma, &i_temp, &cutoff, &pinv_method)) { - return NULL; - } - - collision_matrix = (double *)PyArray_DATA(py_collision_matrix); - eigvals = (double *)PyArray_DATA(py_eigenvalues); - num_temp = (long)PyArray_DIMS(py_collision_matrix)[1]; - num_grid_point = (long)PyArray_DIMS(py_collision_matrix)[2]; - num_band = (long)PyArray_DIMS(py_collision_matrix)[3]; - - if (PyArray_NDIM(py_collision_matrix) == 8) { - num_column = num_grid_point * num_band * 3; - } else { - num_column = num_grid_point * num_band; - } - adrs_shift = (i_sigma * num_column * num_column * num_temp + - i_temp * num_column * num_column); - - /* show_colmat_info(py_collision_matrix, i_sigma, i_temp, adrs_shift); */ - - ph3py_pinv_from_eigensolution(collision_matrix + adrs_shift, eigvals, - num_column, cutoff, pinv_method); - - Py_RETURN_NONE; -} - -static PyObject *py_get_default_colmat_solver(PyObject *self, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) { - return NULL; - } - -#if defined(MKL_LAPACKE) || defined(SCIPY_MKL_H) - return PyLong_FromLong((long)1); -#else - return PyLong_FromLong((long)4); -#endif -} - -static PyObject *py_lapacke_pinv(PyObject *self, PyObject *args) { - PyArrayObject *data_in_py; - PyArrayObject *data_out_py; - double cutoff; - - int m; - int n; - double *data_in; - double *data_out; - int info; - - if (!PyArg_ParseTuple(args, "OOd", &data_out_py, &data_in_py, &cutoff)) { - return NULL; - } - - m = (long)PyArray_DIMS(data_in_py)[0]; - n = (long)PyArray_DIMS(data_in_py)[1]; - data_in = (double *)PyArray_DATA(data_in_py); - data_out = (double *)PyArray_DATA(data_out_py); - - info = ph3py_phonopy_pinv(data_out, data_in, m, n, cutoff); - - return PyLong_FromLong((long)info); -} - -static PyObject *py_get_omp_max_threads(PyObject *self, PyObject *args) { - return PyLong_FromLong(ph3py_get_max_threads()); -} - -static void show_colmat_info(const PyArrayObject *py_collision_matrix, - const long i_sigma, const long i_temp, - const long adrs_shift) { - long i; - - printf(" Array_shape:("); - for (i = 0; i < PyArray_NDIM(py_collision_matrix); i++) { - printf("%d", (int)PyArray_DIM(py_collision_matrix, i)); - if (i < PyArray_NDIM(py_collision_matrix) - 1) { - printf(","); - } else { - printf("), "); - } - } - printf("Data shift:%lu [%lu, %lu]\n", adrs_shift, i_sigma, i_temp); -} - -/** - * @brief Convert numpy "int_" array to phono3py long array structure. - * - * @param npyary - * @return Larray* - */ -static Larray *convert_to_larray(PyArrayObject *npyary) { - long i; - Larray *ary; - - ary = (Larray *)malloc(sizeof(Larray)); - for (i = 0; i < PyArray_NDIM(npyary); i++) { - ary->dims[i] = PyArray_DIMS(npyary)[i]; - } - ary->data = (long *)PyArray_DATA(npyary); - return ary; -} - -/** - * @brief Convert numpy "double" array to phono3py double array structure. - * - * @param npyary - * @return Darray* - * @note PyArray_NDIM receives non-const (PyArrayObject *). - */ -static Darray *convert_to_darray(PyArrayObject *npyary) { - int i; - Darray *ary; - - ary = (Darray *)malloc(sizeof(Darray)); - for (i = 0; i < PyArray_NDIM(npyary); i++) { - ary->dims[i] = PyArray_DIMS(npyary)[i]; - } - ary->data = (double *)PyArray_DATA(npyary); - return ary; -} diff --git a/c/_phononcalc.c b/c/_phononcalc.c deleted file mode 100644 index 941b70da..00000000 --- a/c/_phononcalc.c +++ /dev/null @@ -1,232 +0,0 @@ -/* Copyright (C) 2021 Atsushi Togo */ -/* All rights reserved. */ - -/* This file is part of phonopy. */ - -/* 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 phonopy 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. */ - -#include -#include - -// #include "lapack_wrapper.h" -#include "phononcalc.h" - -static PyObject *py_get_phonons_at_gridpoints(PyObject *self, PyObject *args); - -struct module_state { - PyObject *error; -}; - -#if PY_MAJOR_VERSION >= 3 -#define GETSTATE(m) ((struct module_state *)PyModule_GetState(m)) -#else -#define GETSTATE(m) (&_state) -static struct module_state _state; -#endif - -static PyObject *error_out(PyObject *m) { - struct module_state *st = GETSTATE(m); - PyErr_SetString(st->error, "something bad happened"); - return NULL; -} - -static PyMethodDef _phononcalc_methods[] = { - {"error_out", (PyCFunction)error_out, METH_NOARGS, NULL}, - {"phonons_at_gridpoints", py_get_phonons_at_gridpoints, METH_VARARGS, - "Set phonons at grid points"}, - {NULL, NULL, 0, NULL}}; - -#if PY_MAJOR_VERSION >= 3 - -static int _phononcalc_traverse(PyObject *m, visitproc visit, void *arg) { - Py_VISIT(GETSTATE(m)->error); - return 0; -} - -static int _phononcalc_clear(PyObject *m) { - Py_CLEAR(GETSTATE(m)->error); - return 0; -} - -static struct PyModuleDef moduledef = { - PyModuleDef_HEAD_INIT, "_phononcalc", NULL, - sizeof(struct module_state), _phononcalc_methods, NULL, - _phononcalc_traverse, _phononcalc_clear, NULL}; - -#define INITERROR return NULL - -PyObject *PyInit__phononcalc(void) -#else -#define INITERROR return - -void init_phononcalc(void) -#endif -{ -#if PY_MAJOR_VERSION >= 3 - PyObject *module = PyModule_Create(&moduledef); -#else - PyObject *module = Py_InitModule("_phononcalc", _phononcalc_methods); -#endif - struct module_state *st; - - if (module == NULL) INITERROR; - st = GETSTATE(module); - - st->error = PyErr_NewException("_phononcalc.Error", NULL, NULL); - if (st->error == NULL) { - Py_DECREF(module); - INITERROR; - } - -#if PY_MAJOR_VERSION >= 3 - return module; -#endif -} - -static PyObject *py_get_phonons_at_gridpoints(PyObject *self, PyObject *args) { - PyArrayObject *py_frequencies; - PyArrayObject *py_eigenvectors; - PyArrayObject *py_phonon_done; - PyArrayObject *py_grid_points; - PyArrayObject *py_grid_address; - PyArrayObject *py_QDinv; - PyArrayObject *py_shortest_vectors_fc2; - PyArrayObject *py_multiplicity_fc2; - PyArrayObject *py_positions_fc2; - PyArrayObject *py_fc2; - PyArrayObject *py_masses_fc2; - PyArrayObject *py_p2s_map_fc2; - PyArrayObject *py_s2p_map_fc2; - PyArrayObject *py_reciprocal_lattice; - PyArrayObject *py_born_effective_charge; - PyArrayObject *py_q_direction; - PyArrayObject *py_dielectric_constant; - PyArrayObject *py_dd_q0; - PyArrayObject *py_G_list; - double nac_factor; - double unit_conversion_factor; - double lambda; - char *uplo; - - double(*born)[3][3]; - double(*dielectric)[3]; - double *q_dir; - double *freqs; - _lapack_complex_double *eigvecs; - char *phonon_done; - long *grid_points; - long(*grid_address)[3]; - double(*QDinv)[3]; - double *fc2; - double(*svecs_fc2)[3]; - long(*multi_fc2)[2]; - double(*positions_fc2)[3]; - double *masses_fc2; - long *p2s_fc2; - long *s2p_fc2; - double(*rec_lat)[3]; - double(*dd_q0)[2]; - double(*G_list)[3]; - long num_patom, num_satom, num_phonons, num_grid_points, num_G_points; - - if (!PyArg_ParseTuple( - args, "OOOOOOOOOOOOOdOOOOdOOds", &py_frequencies, &py_eigenvectors, - &py_phonon_done, &py_grid_points, &py_grid_address, &py_QDinv, - &py_fc2, &py_shortest_vectors_fc2, &py_multiplicity_fc2, - &py_positions_fc2, &py_masses_fc2, &py_p2s_map_fc2, &py_s2p_map_fc2, - &unit_conversion_factor, &py_born_effective_charge, - &py_dielectric_constant, &py_reciprocal_lattice, &py_q_direction, - &nac_factor, &py_dd_q0, &py_G_list, &lambda, &uplo)) { - return NULL; - } - - freqs = (double *)PyArray_DATA(py_frequencies); - eigvecs = (_lapack_complex_double *)PyArray_DATA(py_eigenvectors); - phonon_done = (char *)PyArray_DATA(py_phonon_done); - grid_points = (long *)PyArray_DATA(py_grid_points); - grid_address = (long(*)[3])PyArray_DATA(py_grid_address); - QDinv = (double(*)[3])PyArray_DATA(py_QDinv); - fc2 = (double *)PyArray_DATA(py_fc2); - svecs_fc2 = (double(*)[3])PyArray_DATA(py_shortest_vectors_fc2); - multi_fc2 = (long(*)[2])PyArray_DATA(py_multiplicity_fc2); - masses_fc2 = (double *)PyArray_DATA(py_masses_fc2); - p2s_fc2 = (long *)PyArray_DATA(py_p2s_map_fc2); - s2p_fc2 = (long *)PyArray_DATA(py_s2p_map_fc2); - rec_lat = (double(*)[3])PyArray_DATA(py_reciprocal_lattice); - num_patom = (long)PyArray_DIMS(py_multiplicity_fc2)[1]; - num_satom = (long)PyArray_DIMS(py_multiplicity_fc2)[0]; - num_phonons = (long)PyArray_DIMS(py_frequencies)[0]; - num_grid_points = (long)PyArray_DIMS(py_grid_points)[0]; - if ((PyObject *)py_born_effective_charge == Py_None) { - born = NULL; - } else { - born = (double(*)[3][3])PyArray_DATA(py_born_effective_charge); - } - if ((PyObject *)py_dielectric_constant == Py_None) { - dielectric = NULL; - } else { - dielectric = (double(*)[3])PyArray_DATA(py_dielectric_constant); - } - if ((PyObject *)py_q_direction == Py_None) { - q_dir = NULL; - } else { - q_dir = (double *)PyArray_DATA(py_q_direction); - if (fabs(q_dir[0]) < 1e-10 && fabs(q_dir[1]) < 1e-10 && - fabs(q_dir[2]) < 1e-10) { - q_dir = NULL; - } - } - if ((PyObject *)py_dd_q0 == Py_None) { - dd_q0 = NULL; - } else { - dd_q0 = (double(*)[2])PyArray_DATA(py_dd_q0); - } - if ((PyObject *)py_G_list == Py_None) { - G_list = NULL; - num_G_points = 0; - } else { - G_list = (double(*)[3])PyArray_DATA(py_G_list); - num_G_points = (long)PyArray_DIMS(py_G_list)[0]; - } - if ((PyObject *)py_positions_fc2 == Py_None) { - positions_fc2 = NULL; - } else { - positions_fc2 = (double(*)[3])PyArray_DATA(py_positions_fc2); - } - - phcalc_get_phonons_at_gridpoints( - freqs, eigvecs, phonon_done, num_phonons, grid_points, num_grid_points, - grid_address, QDinv, fc2, svecs_fc2, multi_fc2, positions_fc2, - num_patom, num_satom, masses_fc2, p2s_fc2, s2p_fc2, - unit_conversion_factor, born, dielectric, rec_lat, q_dir, nac_factor, - dd_q0, G_list, num_G_points, lambda, uplo[0]); - - Py_RETURN_NONE; -} diff --git a/cmake-format.py b/cmake-format.py deleted file mode 100644 index 4d509443..00000000 --- a/cmake-format.py +++ /dev/null @@ -1,4 +0,0 @@ -with section("format"): - disable = False - line_width = 85 - tab_size = 4 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]