diff --git a/CMakeLists.txt b/CMakeLists.txt index 126ba68b4..8de1f959e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # ############################################################################## # -# triqs_dft_tools - An example application using triqs and cpp2py +# triqs_dft_tools - An example application using triqs # # Copyright (C) ... # @@ -24,11 +24,11 @@ cmake_policy(VERSION ${CMAKE_VERSION}) # ############ # Define Project -project(triqs_dft_tools VERSION 3.3.1 LANGUAGES C CXX Fortran) +project(triqs_dft_tools VERSION 3.3.1 LANGUAGES CXX Fortran) get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY) # ############ -# Load TRIQS and CPP2PY +# Load TRIQS find_package(TRIQS 3.3 REQUIRED) # Get the git hash & print status @@ -67,16 +67,12 @@ if(NOT IS_SUBPROJECT) endif() # Python Support -option(PythonSupport "Build with Python support" ON) -if(PythonSupport AND NOT TRIQS_WITH_PYTHON_SUPPORT) +if(NOT TRIQS_WITH_PYTHON_SUPPORT) message(FATAL_ERROR "TRIQS was installed without Python support. Cannot build the Python Interface. Disable the build with -DPythonSupport=OFF") endif() # Documentation option(Build_Documentation "Build documentation" OFF) -if(NOT IS_SUBPROJECT AND (Build_Documentation AND NOT PythonSupport)) - message(FATAL_ERROR "Build_Documentation=ON requires PythonSupport to be enabled") -endif() # Testing option(Build_Tests "Build tests" ON) @@ -84,44 +80,6 @@ if(Build_Tests) enable_testing() endif() -# ############ -# Global Compilation Settings - -# Build static libraries by default -option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF) - -# Export the list of compile-commands into compile_commands.json -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -# Disable compiler extensions -set(CMAKE_CXX_EXTENSIONS OFF) - -# Provide additional debugging information for Debug builds -add_compile_options($<$:-ggdb3>) - -# Create an Interface target for compiler warnings -add_library(${PROJECT_NAME}_warnings INTERFACE) -target_compile_options(${PROJECT_NAME}_warnings - INTERFACE - -Wall - -Wextra - -Wfloat-conversion - -Wpedantic - -Wno-sign-compare - $<$:-Wno-comma-subscript> - $<$:-Wno-psabi> # Disable notes about ABI changes - $<$:-Wshadow=local> - $<$:-Wno-attributes> - $<$:-Wno-deprecated-declarations> - $<$:-Wno-deprecated-comma-subscript> - $<$:-Wno-unknown-warning-option> - $<$:-Wshadow> - $<$:-Wno-gcc-compat> - $<$:-Wno-c++20-extensions> - $<$:-Wno-c++20-compat> - $<$:-Wno-tautological-constant-compare> -) - # Provide GNU Installation directories include(GNUInstallDirs) @@ -131,9 +89,6 @@ include(GNUInstallDirs) # Find / Build dependencies add_subdirectory(deps) -# Build and install the library -add_subdirectory(c++/${PROJECT_NAME}) - # add here stuff for the Fortran part in DFTTools add_subdirectory(fortran/dmftproj) @@ -143,9 +98,7 @@ if(Build_Tests) endif() # Python -if(PythonSupport) - add_subdirectory(python/${PROJECT_NAME}) -endif() +add_subdirectory(python/${PROJECT_NAME}) # Docs if(NOT IS_SUBPROJECT AND Build_Documentation) @@ -158,7 +111,7 @@ add_subdirectory(bin) # Additional configuration files add_subdirectory(share) -# add packaging for automatic Versioning +# add packaging for automatic versioning add_subdirectory(packaging) # ############# diff --git a/Jenkinsfile b/Jenkinsfile index 155320d43..bde8e3c01 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,8 +24,8 @@ properties([ def platforms = [:] /****************** linux builds (in docker) */ -/* Each platform must have a corresponding Dockerfile.PLATFORM in triqs/packaging */ -def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc", "ubuntu-intel", "sanitize"] +/* Each platform must have a cooresponding Dockerfile.PLATFORM in triqs/packaging */ +def dockerPlatforms = ["ubuntu-clang", "ubuntu-gcc"] /* .each is currently broken in jenkins */ for (int i = 0; i < dockerPlatforms.size(); i++) { def platform = dockerPlatforms[i] diff --git a/c++/CMakeLists.txt b/c++/CMakeLists.txt deleted file mode 100644 index 30655944a..000000000 --- a/c++/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(plovasp/atm) diff --git a/c++/triqs_dft_tools/CMakeLists.txt b/c++/triqs_dft_tools/CMakeLists.txt deleted file mode 100644 index b667c0626..000000000 --- a/c++/triqs_dft_tools/CMakeLists.txt +++ /dev/null @@ -1,101 +0,0 @@ -file(GLOB_RECURSE sources *.cpp) -add_library(${PROJECT_NAME}_c ${sources}) -add_library(${PROJECT_NAME}::${PROJECT_NAME}_c ALIAS ${PROJECT_NAME}_c) - -# Link against triqs and enable warnings -target_link_libraries(${PROJECT_NAME}_c PUBLIC triqs PRIVATE $) - -# Configure target and compilation -set_target_properties(${PROJECT_NAME}_c PROPERTIES - POSITION_INDEPENDENT_CODE ON - VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} -) -target_include_directories(${PROJECT_NAME}_c PUBLIC $) -target_include_directories(${PROJECT_NAME}_c SYSTEM INTERFACE $) -target_link_directories(${PROJECT_NAME}_c PUBLIC $) -target_link_directories(${PROJECT_NAME}_c INTERFACE $) -target_compile_definitions(${PROJECT_NAME}_c PUBLIC - TRIQS_DFT_TOOLS_GIT_HASH=${PROJECT_GIT_HASH} - TRIQS_GIT_HASH=${TRIQS_GIT_HASH} - $<$:TRIQS_DFT_TOOLS_DEBUG> - $<$:TRIQS_DEBUG> - $<$:TRIQS_ARRAYS_ENFORCE_BOUNDCHECK> - ) - -# Install library and headers -install(TARGETS ${PROJECT_NAME}_c EXPORT ${PROJECT_NAME}-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h") - - -# ========= Static Analyzer Checks ========== - -option(ANALYZE_SOURCES OFF "Run static analyzer checks if found (clang-tidy, cppcheck)") -if(ANALYZE_SOURCES) - - # Locate static analyzer tools - find_program(CPPCHECK_EXECUTABLE NAMES "cppcheck" PATHS ENV PATH) - find_program(CLANG_TIDY_EXECUTABLE NAMES "clang-tidy" PATHS ENV PATH) - - # Run clang-tidy if found - if(CLANG_TIDY_EXECUTABLE) - message(STATUS "clang-tidy found: ${CLANG_TIDY_EXECUTABLE}") - set_target_properties(${PROJECT_NAME}_c PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") - else() - message(STATUS "clang-tidy not found in $PATH. Please consider installing clang-tidy for additional checks!") - endif() - - # Run cppcheck if found - if(CPPCHECK_EXECUTABLE) - message(STATUS "cppcheck found: ${CPPCHECK_EXECUTABLE}") - add_custom_command( - TARGET ${PROJECT_NAME}_c - COMMAND ${CPPCHECK_EXECUTABLE} - --enable=warning,style,performance,portability - --std=c++23 - --template=gcc - --verbose - --force - --quiet - ${sources} - WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR} - ) - else() - message(STATUS "cppcheck not found in $PATH. Please consider installing cppcheck for additional checks!") - endif() - -endif() - -# ========= Dynamic Analyzer Checks ========== - -option(ASAN OFF "Compile library and executables with LLVM Address Sanitizer") -if(ASAN) - if(NOT TARGET asan) - find_package(sanitizer REQUIRED COMPONENTS asan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(UBSAN OFF "Compile library and executables with LLVM Undefined Behavior Sanitizer") -if(UBSAN) - if(NOT TARGET ubsan) - find_package(sanitizer REQUIRED COMPONENTS ubsan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(MSAN OFF "Compile library and executables with LLVM Memory Sanitizer") -if(MSAN) - if(NOT TARGET msan) - find_package(sanitizer REQUIRED COMPONENTS msan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() - -option(TSAN OFF "Compile library and executables with LLVM Thread Sanitizer") -if(TSAN) - if(NOT TARGET tsan) - find_package(sanitizer REQUIRED COMPONENTS tsan) - endif() - target_link_libraries(${PROJECT_NAME}_c PUBLIC $) -endif() diff --git a/c++/triqs_dft_tools/converters/vasp.hpp b/c++/triqs_dft_tools/converters/vasp.hpp deleted file mode 100644 index 0aa018d7c..000000000 --- a/c++/triqs_dft_tools/converters/vasp.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "./vasp/argsort.hpp" -#include "./vasp/dos_tetra3d.hpp" diff --git a/c++/triqs_dft_tools/converters/vasp/__init__.py b/c++/triqs_dft_tools/converters/vasp/__init__.py deleted file mode 100644 index db31c97b2..000000000 --- a/c++/triqs_dft_tools/converters/vasp/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ - -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2011 by M. Ferrero, O. Parcollet -# -# DFT tools: Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola -# -# PLOVasp: Copyright (C) 2015 by O. E. Peil -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ - -__all__ = [] diff --git a/c++/triqs_dft_tools/converters/vasp/argsort.cpp b/c++/triqs_dft_tools/converters/vasp/argsort.cpp deleted file mode 100644 index 92fb86c22..000000000 --- a/c++/triqs_dft_tools/converters/vasp/argsort.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#include - -int cmp(const void *a, const void *b) -{ - return (**(const double **)a) < (**(const double **)b) ? -1 : 1; -} - -int icmp(const void *a, const void *b) -{ - return (**(const int **)a) - (**(const int **)b); -} - -void argsort(double *arr, int *inds, double **ptrs, const int n) -{ - int i; - - for (i=0; i < n; i++) - { - ptrs[i] = arr + i; - } - - qsort(ptrs, n, sizeof(double *), cmp); - - for (i=0; i < n; i++) - { - inds[i] = (int)(ptrs[i] - arr); - } -} - -void iargsort(int *iarr, int *inds, int **ptrs, const int n) -{ - int i; - - for (i=0; i < n; i++) - { - ptrs[i] = iarr + i; - } - - qsort(ptrs, n, sizeof(int *), icmp); - - for (i=0; i < n; i++) - { - inds[i] = (int)(ptrs[i] - iarr); - } -} - - diff --git a/c++/triqs_dft_tools/converters/vasp/argsort.hpp b/c++/triqs_dft_tools/converters/vasp/argsort.hpp deleted file mode 100644 index fd4ace4d0..000000000 --- a/c++/triqs_dft_tools/converters/vasp/argsort.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#ifndef __ARGSORT_H__ -#define __ARGSORT_H__ - -void argsort(double *arr, int *inds, double **ptrs, const int n); -void iargsort(int *iarr, int *inds, int **ptrs, const int n); - -#endif diff --git a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp b/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp deleted file mode 100644 index 0e4e74889..000000000 --- a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.cpp +++ /dev/null @@ -1,482 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#include -#include -#include - -#include "argsort.hpp" -#include "dos_tetra3d.hpp" - -//#define __TETRA_DEBUG -#define __TETRA_ARRAY_VIEW - -using nda::array; -using nda::array_view; - -/*************************************************** - - Analytical tetrahedron method as described in -Lambin et al., PRB 29, 6, 3430 (1984). - -***************************************************/ - -/// Main function -//#ifdef __TETRA_ARRAY_VIEW -//void tet_dos3d(double en, array_view& eigk, -// array_view& itt, int ntet, -// array& cti); -//#else -//void tet_dos3d(double en, array& eigk, -// array& itt, int ntet, -// array& cti); -//#endif - - -/// Internal functions -int dos_corner_weights(double en, double *eigs, int *inds, double *ci); -int dos_tet_weights(double en, double *eigs, int *inds, double *ct); -int dos_reorder(double en, double *e, int *inds); - -static double F(double en, double e1, double e2, double e3, double e4); -static double K2(double en, double e1, double e2, double e3); -static double K1(double en, double e1, double e2); - -static void fun_dos_case1(double en, double *eigs, double *ci); -static void fun_dos_case2(double en, double *eigs, double *ci); -static void fun_dos_case3(double en, double *eigs, double *ci); - -static const int NUM_TET_CORNERS = 4; -static const std::complex I(0.0, 1.0); -static const double tol = 1e-8; - -/* - Returns corner contributions to the DOS of a band -*/ -#ifdef __TETRA_ARRAY_VIEW -array dos_tetra_weights_3d(array_view eigk, double en, array_view itt) -#else -array dos_tetra_weights_3d(array eigk, double en, array itt) -#endif -{ - int ntet; /// Number of tetrahedra -// Auxiliary variables and loop indices - - if (itt.shape()[0] != NUM_TET_CORNERS + 1) - { - NDA_RUNTIME_ERROR << " The first dimension of 'itt' must be equal to 5"; - } - - ntet = itt.shape()[1]; - - array cti(NUM_TET_CORNERS, ntet); // Corner weights to be returned - -// tet_dos3d(e, eigk, itt, ntet, cti); - -// -// Main algorithm (transferred from 'tet_dos3d()') -// - double eigs[4], ci[4]; - - int i, it, ik, inds[4]; -#ifdef __TETRA_DEBUG - double ct, ci_sum; -#endif - -// Loop over tetrahedra (triangles) - for (it = 0; it < ntet; it++) - { - for (i = 1; i < 5; i++) - { - ik = itt(i, it); - eigs[i - 1] = eigk(ik); - } - -// Corner weights for a single tetrahedron - dos_corner_weights(en, eigs, inds, ci); - -#ifdef __TETRA_DEBUG - for(i = 0, ci_sum = 0.0; i < 4; i++) - ci_sum += ci[i]; - - flag = dos_tet_weights(en, eigs, inds, &ct); - if(std::abs(ct - ci_sum) > tol) - { - std::cout << " *** Error in weights: it = " << it <<" flag = " << flag << ", en = " << en; - for(i = 0; i < 4; i++) - std::cout << ", e[" << i << "] = " << eigs[i]; - std::cout << ", c_diff = " << std::abs(ct - ci_sum) << std::endl; - - TRIQS_RUNTIME_ERROR << " Failed consistency check"; - } -#endif - - for(i = 0; i < 4; i++) - { - cti(inds[i], it) = ci[i]; - } - - } // it = 1, ntet - - return array_view(cti); -} - -//#ifdef __TETRA_ARRAY_VIEW -//void tet_dos3d(double en, array_view& eigk, -// array_view& itt, int ntet, -// array& cti) -//#else -//void tet_dos3d(double en, array& eigk, -// array& itt, int ntet, -// array& cti) -//#endif -//{ -// double eigs[4], ci[4]; -// -// int i, it, ik, inds[4], flag; -//#ifdef __TETRA_DEBUG -// double ct, ci_sum; -//#endif -// -//// Loop over tetrahedra (triangles) -// for (it = 0; it < ntet; it++) -// { -// for (i = 1; i < 5; i++) -// { -// ik = itt(i, it); -// eigs[i - 1] = eigk(ik); -// } -// -//// Corner weights for a single tetrahedron -// dos_corner_weights(en, eigs, inds, ci); -// -//#ifdef __TETRA_DEBUG -// for(i = 0, ci_sum = 0.0; i < 4; i++) -// ci_sum += ci[i]; -// -// flag = dos_tet_weights(en, eigs, inds, &ct); -// if(std::abs(ct - ci_sum) > tol) -// { -// std::cout << " *** Error in weights: it = " << it <<" flag = " << flag << ", en = " << en; -// for(i = 0; i < 4; i++) -// std::cout << ", e[" << i << "] = " << eigs[i]; -// std::cout << ", c_diff = " << std::abs(ct - ci_sum) << std::endl; -// return; -// } -//#endif -// -// for(i = 0; i < 4; i++) -// { -// cti(inds[i], it) = ci[i]; -// } -// -// } // it = 1, ntet -//} - -/// Corner contributions to DOS -int dos_corner_weights(double en, double *eigs, int *inds, - double *ci) -{ - int flag, i; -// Sort eigenvalues and obtain indices of the sorted array -// eigs: sorted eigenvalues -// inds: index map - flag = dos_reorder(en, eigs, inds); - - switch(flag) - { -// E1 <= E <= E2 - case 1: - fun_dos_case1(en, eigs, ci); - break; - -// E2 <= E <= E3 - case 2: - fun_dos_case2(en, eigs, ci); - break; - -// E3 <= E <= E4 - case 3: - fun_dos_case3(en, eigs, ci); - break; - -// E < E1 || E4 < E - case 4: - case 5: - for(i = 0; i < 4; i++) ci[i] = 0.0; - break; - -// E1 == E4 == E - case 6: - for(i = 0; i < 4; i++) ci[i] = 0.25; - break; - } - - return flag; -} - -/// Total (tetrahedron) contribution to DOS. -/// Here, it is calculated directly using an analytical formula. -/// This is mainly needed for debugging. -int dos_tet_weights(double en, double *eigs, int *inds, - double *ct) -{ - double e1, e2, e3, e4; - std::complex s; - int flag; - flag = dos_reorder(en, eigs, inds); - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - switch(flag) - { -// E1 <= E <= E2 - case 1: - if(std::abs(e2 - e1) > tol && std::abs(e3 - e1) > tol && std::abs(e4 - e1) > tol) - *ct = 3.0 * (en - e1) * (en - e1) / ((e2 - e1) * (e3 - e1) * (e4 - e1)); - else - { - s = fmin(std::abs(e1 - e2), std::abs(e3 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e1)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real((en - e1 + s) * (en - e1 + s) / ((e2 - e1 + s) * (e3 - e1 + s) * (e4 - e1 + s))); - } - - break; - -// E2 <= E <= E3 - case 2: - if(std::abs(e4 - e2) > tol && std::abs(e3 - e2) > tol && std::abs(e4 - e1) > tol && std::abs(e3 - e1) > tol) - *ct = 3.0 * ( - (e3 - en) * (en - e2) / ((e4 - e2) * (e3 - e2) * (e3 - e1)) + - (e4 - en) * (en - e1) / ((e4 - e1) * (e4 - e2) * (e3 - e1))); - else - { - s = fmin(std::abs(e3 - e2), std::abs(e3 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real(( - (e3 - en + s) * (en - e2 + s) / ((e4 - e2 + s) * (e3 - e2 + s) * (e3 - e1 + s)) + - (e4 - en + s) * (en - e1 + s) / ((e4 - e1 + s) * (e4 - e2 + s) * (e3 - e1 + s)))); - } - break; - -// E3 <= E <= E4 - case 3: - if(std::abs(e4 - e2) > tol && std::abs(e4 - e3) > tol && std::abs(e4 - e1) > tol) - *ct = 3.0 * (e4 - en) * (e4 - en) / ((e4 - e1) * (e4 - e2) * (e4 - e3)); - else - { - s = fmin(std::abs(e4 - e2), std::abs(e4 - e1)); - s = fmin(std::abs(s), std::abs(e4 - e3)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - *ct = 3.0 * std::real((e4 - en + s) * (e4 - en + s) / ((e4 - e1 + s) * (e4 - e2 + s) * (e4 - e3 + s))); - } - - break; - -// E < E1 || E4 < E - case 4: - case 5: - *ct = 0.0; - break; - -// E1 == E4 == E - case 6: - *ct = 1.0; - break; - } - - return flag; -} - -/// Sorts eigenvalues and also determines eigenvalue degeneracies. -/// Returns a case number corresponding to a combination of degeneracies. -int dos_reorder(double en, double *e, int *inds) -{ - double *ptrs[4], e_tmp[4]; - int i; - - for(i = 0; i < 4; i++) - e_tmp[i] = e[i]; - - argsort(e_tmp, inds, ptrs, 4); - - for(i = 0; i < 4; i++) - e[i] = e_tmp[inds[i]]; - - if((e[0] <= en && en <= e[3]) && std::abs(e[3] - e[0]) < tol) return 6; - if(e[0] <= en && en <= e[1]) return 1; - if(e[1] <= en && en <= e[2]) return 2; - if(e[2] <= en && en <= e[3]) return 3; - if(en < e[0]) return 4; - if(e[3] < en) return 5; - return -1; -} - -static void fun_dos_case1(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = K2(en, e1, e2, e4) * F(en, e2, e1, e1, e3) + - K2(en, e1, e2, e3) * F(en, e3, e1, e1, e4) + - K2(en, e1, e3, e4) * F(en, e4, e1, e1, e2); - - ci[1] = -K1(en, e1, e2) * F(en, e1, e1, e3, e4); - - ci[2] = -K1(en, e1, e3) * F(en, e1, e1, e2, e4); - - ci[3] = -K1(en, e1, e4) * F(en, e1, e1, e2, e3); -} - -static void fun_dos_case2(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = 0.5 * (K1(en, e3, e1) * ( - F(en, e3, e2, e2, e4) + - F(en, e4, e1, e2, e4) + - F(en, e3, e1, e2, e4)) + - K1(en, e4, e1) * ( - F(en, e4, e1, e2, e3) + - F(en, e4, e2, e2, e3) + - F(en, e3, e1, e2, e3))); - - ci[1] = 0.5 * (K1(en, e3, e2) * ( - F(en, e3, e2, e1, e4) + - F(en, e4, e2, e1, e4) + - F(en, e3, e1, e1, e4)) + - K1(en, e4, e2) * ( - F(en, e3, e2, e1, e3) + - F(en, e4, e1, e1, e3) + - F(en, e4, e2, e1, e3))); - - ci[2] = 0.5 * (-K1(en, e2, e3) * ( - F(en, e3, e2, e1, e4) + - F(en, e4, e2, e1, e4) + - F(en, e3, e1, e1, e4)) - - K1(en, e1, e3) * ( - F(en, e3, e2, e2, e4) + - F(en, e4, e1, e2, e4) + - F(en, e3, e1, e2, e4))); - - ci[3] = 0.5 * (-K1(en, e2, e4) * ( - F(en, e3, e2, e1, e3) + - F(en, e4, e1, e1, e3) + - F(en, e4, e2, e1, e3)) - - K1(en, e1, e4) * ( - F(en, e4, e1, e2, e3) + - F(en, e4, e2, e2, e3) + - F(en, e3, e1, e2, e3))); -} - -static void fun_dos_case3(double en, double *eigs, double *ci) -{ - double e1, e2, e3, e4; - - e1 = eigs[0]; - e2 = eigs[1]; - e3 = eigs[2]; - e4 = eigs[3]; - - ci[0] = K1(en, e4, e1) * F(en, e4, e4, e2, e3); - - ci[1] = K1(en, e4, e2) * F(en, e4, e4, e1, e3); - - ci[2] = K1(en, e4, e3) * F(en, e4, e4, e1, e2); - - ci[3] = -K2(en, e4, e3, e1) * F(en, e4, e3, e2, e4) - - K2(en, e4, e2, e3) * F(en, e4, e2, e1, e4) - - K2(en, e4, e1, e2) * F(en, e4, e1, e3, e4); - -} - -static double F(double en, double e1, double e2, double e3, double e4) -{ - std::complex s; - - if(std::abs(e1 - e3) > tol && std::abs(e4 - e2) > tol) - return (e1 - en) * (en - e2) / ((e1 - e3) * (e4 - e2)); - else - { -// Regularization to avoid division by zero - s = fmin(std::abs(e3 - e1), std::abs(e4 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((e1 - en + s) * (en - e2 + s) / ((e1 - e3 + s) * (e4 - e2 + s))); - } -} - -static double K2(double en, double e1, double e2, double e3) -{ - std::complex s; - - if(std::abs(e1 - e3) > tol && std::abs(e1 - e2) > tol) - return (en - e1) / ((e2 - e1) * (e3 - e1)); - else - { -// Regularization to avoid division by zero - s = fmin(std::abs(e3 - e1), std::abs(e1 - e2)); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((en - e1 + s) / ((e2 - e1 + s) * (e3 - e1 + s))); - } -} - -static double K1(double en, double e1, double e2) -{ - std::complex s; - - if(std::abs(e1 - e2) > tol) - return (e1 - en) / ((e2 - e1) * (e2 - e1)); - else - { -// Regularization to avoid division by zero - s = std::abs(e1 - e2); - s /= 100.0; - s = fmax(std::abs(s), 1.0e-20) * I; - - return std::real((e1 - en + s) / ((e2 - e1 + s) * (e2 - e1 + s))); - } -} - - diff --git a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp b/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp deleted file mode 100644 index ffc16964e..000000000 --- a/c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* -* -* This file is part of the ATM library. -* -* Copyright (C) 2010 by O. E. Peil -* -* TRIQS is free software: you can redistribute it and/or modify it under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, either version 3 of the License, or (at your option) any later -* version. -* -* TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -* details. -* -* You should have received a copy of the GNU General Public License along with -* TRIQS. If not, see . -* -*******************************************************************************/ -#pragma once - -#include - - -/// DOS of a band by analytical tetrahedron method -/// -/// Returns corner weights for all tetrahedra for a given band and real energy. -nda::array -dos_tetra_weights_3d(nda::array_view eigk, /// Band energies for each k-point - double en, /// Energy at which DOS weights are to be calculated - nda::array_view itt /// Tetrahedra defined by k-point indices -); -//array -//dos_tetra_weights_3d(array eigk, /// Band energies for each k-point -// double e, /// Energy at which DOS weights are to be calculated -// array itt /// Tetrahedra defined by k-point indices -//); -int dos_corner_weights(double en, double *eigs, int *inds, double *ci); -int dos_tet_weights(double en, double *eigs, int *inds, double *ct); -int dos_reorder(double en, double *e, int *inds); - - - diff --git a/c++/triqs_dft_tools/converters/vasp/makefile.linux b/c++/triqs_dft_tools/converters/vasp/makefile.linux deleted file mode 100644 index cc21c0ea6..000000000 --- a/c++/triqs_dft_tools/converters/vasp/makefile.linux +++ /dev/null @@ -1,4 +0,0 @@ - -c_atm_mod.so: argsort.c argsort.h dos_tetra3d.c dos_tetra3d.h - python setup.py build_ext --inplace - diff --git a/c++/triqs_dft_tools/converters/vasp/setup.py b/c++/triqs_dft_tools/converters/vasp/setup.py deleted file mode 100644 index 90334b33a..000000000 --- a/c++/triqs_dft_tools/converters/vasp/setup.py +++ /dev/null @@ -1,33 +0,0 @@ - -################################################################################ -# -# TRIQS: a Toolbox for Research in Interacting Quantum Systems -# -# Copyright (C) 2011 by M. Ferrero, O. Parcollet -# -# DFT tools: Copyright (C) 2011 by M. Aichhorn, L. Pourovskii, V. Vildosola -# -# PLOVasp: Copyright (C) 2015 by O. E. Peil -# -# TRIQS is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# TRIQS. If not, see . -# -################################################################################ -from distutils.core import setup, Extension -import numpy - -c_atm_dos_mod = Extension('c_atm_dos', sources=['dos_tetra3d.c', 'argsort.c'], - include_dirs=[numpy.get_include()]) - -setup(ext_modules=[c_atm_dos_mod]) - diff --git a/c++/triqs_dft_tools/triqs_dft_tools.hpp b/c++/triqs_dft_tools/triqs_dft_tools.hpp deleted file mode 100644 index ee70a5dc8..000000000 --- a/c++/triqs_dft_tools/triqs_dft_tools.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -#include "./converters/vasp.hpp" - diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 392370c11..3b938a51a 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -46,22 +46,3 @@ else() message(WARNING "For builds with llvm sanitizers (ASAN/UBSAN) it is recommended to use -DBuild_Deps=Always to avoid false positives.") endif() endif() - -# -- Cpp2Py -- -if(PythonSupport OR (NOT IS_SUBPROJECT AND Build_Documentation)) - external_dependency(Cpp2Py - GIT_REPO https://github.com/TRIQS/cpp2py - VERSION 3.3 - GIT_TAG main - BUILD_ALWAYS - EXCLUDE_FROM_ALL - ) -endif() - -# -- GTest -- -external_dependency(GTest - GIT_REPO https://github.com/google/googletest - GIT_TAG main - BUILD_ALWAYS - EXCLUDE_FROM_ALL -) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 6b95f99db..6ac89abbb 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -1,51 +1,6 @@ # Generate the sphinx config file configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY) -# ----------------------------------------------------------------------------- -# Create an optional target that allows us to regenerate the C++ doc with c++2rst -# ----------------------------------------------------------------------------- -add_custom_target(${PROJECT_NAME}_docs_cpp2rst) -include(${PROJECT_SOURCE_DIR}/share/cmake/extract_flags.cmake) -extract_flags(${PROJECT_NAME}_c BUILD_INTERFACE) -separate_arguments(${PROJECT_NAME}_c_CXXFLAGS) -macro(generate_docs header_file) - add_custom_command( - TARGET ${PROJECT_NAME}_docs_cpp2rst - POST_BUILD - COMMAND rm -rf ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated - COMMAND - PYTHONPATH=${CPP2PY_BINARY_DIR}:$ENV{PYTHONPATH} - PATH=${CPP2PY_BINARY_DIR}/bin:${CPP2PY_ROOT}/bin:$ENV{PATH} - c++2rst - ${header_file} - -N ${PROJECT_NAME} - --output_directory ${CMAKE_CURRENT_SOURCE_DIR}/cpp2rst_generated - -I${PROJECT_SOURCE_DIR}/c++ - --cxxflags="${${PROJECT_NAME}_c_CXXFLAGS}" - ) -endmacro(generate_docs) - -generate_docs(${PROJECT_SOURCE_DIR}/c++/${PROJECT_NAME}/${PROJECT_NAME}.hpp) - -# -------------------------------------------------------- -# Build & Run the C++ doc examples and capture the output -# -------------------------------------------------------- - -add_custom_target(${PROJECT_NAME}_docs_example_output) -file(GLOB_RECURSE ExampleList RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) -foreach(example ${ExampleList}) - get_filename_component(f ${example} NAME_WE) - get_filename_component(d ${example} DIRECTORY) - add_executable(${PROJECT_NAME}_doc_${f} EXCLUDE_FROM_ALL ${example}) - set_property(TARGET ${PROJECT_NAME}_doc_${f} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${d}) - target_link_libraries(${PROJECT_NAME}_doc_${f} triqs) - add_custom_command(TARGET ${PROJECT_NAME}_doc_${f} POST_BUILD - COMMAND ${PROJECT_NAME}_doc_${f} > ${CMAKE_CURRENT_SOURCE_DIR}/${d}/${f}.output 2>/dev/null - WORKING_DIRECTORY ${d} - ) - add_dependencies(${PROJECT_NAME}_docs_example_output ${PROJECT_NAME}_doc_${f}) -endforeach() - # --------------------------------- # Top Sphinx target # --------------------------------- @@ -61,18 +16,6 @@ add_custom_command( COMMAND PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SPHINXBUILD_EXECUTABLE} -j auto -c . -b html ${CMAKE_CURRENT_SOURCE_DIR} html ) -option(Sphinx_Only "When building the documentation, skip the Python Modules and the generation of C++ Api and example outputs" OFF) -if(NOT Sphinx_Only) - # Autodoc usage requires the python modules to be built first - get_property(CPP2PY_MODULES_LIST GLOBAL PROPERTY CPP2PY_MODULES_LIST) - if(CPP2PY_MODULES_LIST) - add_dependencies(${PROJECT_NAME}_docs_sphinx ${CPP2PY_MODULES_LIST}) - endif() - - # Generation of C++ Api and Example Outputs - add_dependencies(${PROJECT_NAME}_docs_sphinx ${PROJECT_NAME}_docs_cpp2rst ${PROJECT_NAME}_docs_example_output) -endif() - # --------------------------------- # Install # --------------------------------- diff --git a/doc/install.rst b/doc/install.rst index d43daa86c..2a3f5cc1b 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -67,7 +67,6 @@ Installation steps #. Compile the code, run the tests and install the application:: - $ make $ make test $ make install diff --git a/python/triqs_dft_tools/CMakeLists.txt b/python/triqs_dft_tools/CMakeLists.txt index 753f31455..72fbf5adf 100644 --- a/python/triqs_dft_tools/CMakeLists.txt +++ b/python/triqs_dft_tools/CMakeLists.txt @@ -3,8 +3,6 @@ configure_file(version.py.in version.py) # All Python files. Copy them in the build dir to have a complete package for the tests. file(GLOB_RECURSE python_sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py) -file(GLOB_RECURSE wrap_generators RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_desc.py) -list(REMOVE_ITEM python_sources "${wrap_generators}") foreach(file ${python_sources}) configure_file(${file} ${file} COPYONLY) endforeach() @@ -13,14 +11,3 @@ endforeach() set(PYTHON_LIB_DEST ${TRIQS_PYTHON_LIB_DEST_ROOT}/${PROJECT_NAME}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.py DESTINATION ${PYTHON_LIB_DEST}) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${TRIQS_PYTHON_LIB_DEST_ROOT} FILES_MATCHING PATTERN "*.py" PATTERN "*_desc.py" EXCLUDE) - -# Build and install any python modules -foreach(gen ${wrap_generators}) - string(REPLACE "_desc.py" "" gen ${gen}) - get_filename_component(module_name ${gen} NAME_WE) - get_filename_component(module_dir ${gen} DIRECTORY) - add_cpp2py_module(NAME ${module_name} DIRECTORY ${module_dir}) - add_library(${PROJECT_NAME}::${module_name} ALIAS ${module_name}) - target_link_libraries(${module_name} ${PROJECT_NAME}_c triqs_py) - install(TARGETS ${module_name} DESTINATION ${PYTHON_LIB_DEST}/${module_dir}) -endforeach() diff --git a/python/triqs_dft_tools/converters/plovasp/atm_desc.py b/python/triqs_dft_tools/converters/plovasp/atm_desc.py deleted file mode 100644 index 0dc18d394..000000000 --- a/python/triqs_dft_tools/converters/plovasp/atm_desc.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated automatically using the command : -# c++2py.py -m atm -o atm --moduledoc "Analytical Tetrahedron Method for DOS" ../../../../c++/triqs_dft_tools/converters/vasp/dos_tetra3d.hpp -from cpp2py.wrap_generator import * - -# The module -module = module_(full_name = "atm", doc = "Analytical Tetrahedron Method for calculating DOS", app_name = "atm") - -# All the triqs C++/Python modules - -# Add here all includes beyond what is automatically included by the triqs modules -module.add_include("triqs_dft_tools/converters/vasp/dos_tetra3d.hpp") - -# Add here anything to add in the C++ code at the start, e.g. namespace using -module.add_preamble(""" -#include -using namespace nda; -""") - -module.add_function ("array dos_tetra_weights_3d (array_view eigk, double en, array_view itt)", doc = """DOS of a band by analytical tetrahedron method\n\n Returns corner weights for all tetrahedra for a given band and real energy.""") - -module.generate_code() diff --git a/python/triqs_dft_tools/converters/plovasp/lintetra.py b/python/triqs_dft_tools/converters/plovasp/lintetra.py new file mode 100644 index 000000000..c96af5956 --- /dev/null +++ b/python/triqs_dft_tools/converters/plovasp/lintetra.py @@ -0,0 +1,236 @@ +import numpy as np + +_TOL = 1e-8 + +def _regularize_scalar(value): + """Regularize a scalar to avoid numerical underflow or division by zero.""" + return max(float(value), 1.0e-20) / 100.0 + +def _select(mask, *arrays): + """Helper to select masked values for multiple arrays efficiently.""" + idx = np.nonzero(mask)[0] + return idx, [a[idx] for a in arrays] + +# === Auxiliary numerical functions (formerly F, K1, K2) === + +def _stable_fraction_F(e_eval, e1, e2, e3, e4): + """ + Stable evaluation of the F-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2, e3, e4 : ndarray + Corner energies of the tetrahedron. + + Returns + ------- + ndarray + Evaluated F-term. + """ + e1, e2, e3, e4, e_eval = map(np.asarray, (e1, e2, e3, e4, e_eval)) + mask = (np.abs(e1 - e3) > _TOL) & (np.abs(e4 - e2) > _TOL) + safe_val = ((e1 - e_eval) * (e_eval - e2)) / ((e1 - e3) * (e4 - e2)) + + s_real = np.maximum(np.minimum(np.abs(e3 - e1), np.abs(e4 - e2)), 1.0e-20) / 100.0 + s = 1j * s_real + num = (e1 - e_eval + s) * (e_eval - e2 + s) + den = (e1 - e3 + s) * (e4 - e2 + s) + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +def _stable_fraction_K1(e_eval, e1, e2): + """ + Stable evaluation of the first K-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2 : ndarray + Corner energies of the tetrahedron. + + Returns + ------- + ndarray + Evaluated K1-term. + """ + e1, e2, e_eval = map(np.asarray, (e1, e2, e_eval)) + mask = np.abs(e1 - e2) > _TOL + safe_val = (e1 - e_eval) / ((e2 - e1) ** 2) + + s_real = np.maximum(np.abs(e1 - e2), 1.0e-20) / 100.0 + s = 1j * s_real + num = e1 - e_eval + s + den = (e2 - e1 + s) ** 2 + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +def _stable_fraction_K2(e_eval, e1, e2, e3): + """ + Stable evaluation of the second K-term used in tetrahedron DOS integration. + + Parameters + ---------- + e_eval : float or ndarray + Evaluation energy. + e1, e2, e3 : ndarray + Corner energies of the tetrahedron. + + Returns + ------- + ndarray + Evaluated K2-term. + """ + e1, e2, e3, e_eval = map(np.asarray, (e1, e2, e3, e_eval)) + mask = (np.abs(e1 - e3) > _TOL) & (np.abs(e1 - e2) > _TOL) + safe_val = (e_eval - e1) / ((e2 - e1) * (e3 - e1)) + + s_real = np.maximum(np.minimum(np.abs(e3 - e1), np.abs(e1 - e2)), 1.0e-20) / 100.0 + s = 1j * s_real + num = e_eval - e1 + s + den = (e2 - e1 + s) * (e3 - e1 + s) + fallback = (num / den).real + return np.where(mask, safe_val, fallback.astype(np.float64)) + + +# === Main driver === + +def dos_tetra_weights_3d(eigenvalues, energy, k_points): + """ + Compute tetrahedron corner weights for 3D DOS integration. + + This version is fully vectorized in NumPy, operating on all tetrahedra + simultaneously without MPI or Python loops. + + Parameters + ---------- + eigenvalues : (n_kpoints,) array_like of float + Energies at k-points. + energy : float + Target energy for DOS evaluation. + k_points : (5, n_tetra) array_like of int + Tetrahedron connectivity. Only rows [1:5] are used for corner indices. + + Returns + ------- + corner_weights : (4, n_tetra) ndarray of float + Corner weights for each tetrahedron at the specified energy. + """ + eigk = np.asarray(eigenvalues, dtype=float) + tetra = np.asarray(k_points, dtype=np.int64) + if tetra.ndim != 2 or tetra.shape[0] != 5: + raise ValueError("k_points must have shape (5, n_tetra)") + + n_tetra = tetra.shape[1] + corners = tetra[1:5, :] # (4, n_tetra) + corner_energies = eigk[corners] + + # Sort each tetrahedron's corner energies ascending + order = np.argsort(corner_energies, axis=0) + sorted_energies = np.take_along_axis(corner_energies, order, axis=0) + + e1, e2, e3, e4 = sorted_energies + e_eval = float(energy) + + # Determine which energy range each tetrahedron falls into + flag_uniform = (e1 <= e_eval) & (e_eval <= e4) & (np.abs(e4 - e1) < _TOL) + flag_case1 = (e1 <= e_eval) & (e_eval <= e2) & (~flag_uniform) + flag_case2 = (e2 <= e_eval) & (e_eval <= e3) + flag_case3 = (e3 <= e_eval) & (e_eval <= e4) + + weights_sorted = np.zeros_like(sorted_energies, dtype=float) + idx = lambda mask: np.nonzero(mask)[0] + + # === Case 6: uniform tetrahedra (degenerate energies) + if flag_uniform.any(): + weights_sorted[:, idx(flag_uniform)] = 0.25 + + # === Case 1 + if flag_case1.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case1, e1, e2, e3, e4) + ee = e_eval + + w0 = (_stable_fraction_K2(ee, ge1, ge2, ge4) * _stable_fraction_F(ee, ge2, ge1, ge1, ge3) + + _stable_fraction_K2(ee, ge1, ge2, ge3) * _stable_fraction_F(ee, ge3, ge1, ge1, ge4) + + _stable_fraction_K2(ee, ge1, ge3, ge4) * _stable_fraction_F(ee, ge4, ge1, ge1, ge2)) + w1 = -_stable_fraction_K1(ee, ge1, ge2) * _stable_fraction_F(ee, ge1, ge1, ge3, ge4) + w2 = -_stable_fraction_K1(ee, ge1, ge3) * _stable_fraction_F(ee, ge1, ge1, ge2, ge4) + w3 = -_stable_fraction_K1(ee, ge1, ge4) * _stable_fraction_F(ee, ge1, ge1, ge2, ge3) + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Case 2 + if flag_case2.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case2, e1, e2, e3, e4) + ee = e_eval + + w0 = 0.5 * ( + _stable_fraction_K1(ee, ge3, ge1) + * (_stable_fraction_F(ee, ge3, ge2, ge2, ge4) + + _stable_fraction_F(ee, ge4, ge1, ge2, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge4)) + + _stable_fraction_K1(ee, ge4, ge1) + * (_stable_fraction_F(ee, ge4, ge1, ge2, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge2, ge3) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge3)) + ) + + w1 = 0.5 * ( + _stable_fraction_K1(ee, ge3, ge2) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge1, ge4)) + + _stable_fraction_K1(ee, ge4, ge2) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge1, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge3)) + ) + + w2 = 0.5 * ( + -_stable_fraction_K1(ee, ge2, ge3) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge1, ge4)) + - _stable_fraction_K1(ee, ge1, ge3) + * (_stable_fraction_F(ee, ge3, ge2, ge2, ge4) + + _stable_fraction_F(ee, ge4, ge1, ge2, ge4) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge4)) + ) + + w3 = 0.5 * ( + -_stable_fraction_K1(ee, ge2, ge4) + * (_stable_fraction_F(ee, ge3, ge2, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge1, ge1, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge1, ge3)) + - _stable_fraction_K1(ee, ge1, ge4) + * (_stable_fraction_F(ee, ge4, ge1, ge2, ge3) + + _stable_fraction_F(ee, ge4, ge2, ge2, ge3) + + _stable_fraction_F(ee, ge3, ge1, ge2, ge3)) + ) + + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Case 3 + if flag_case3.any(): + i, (ge1, ge2, ge3, ge4) = _select(flag_case3, e1, e2, e3, e4) + ee = e_eval + + w0 = _stable_fraction_K1(ee, ge4, ge1) * _stable_fraction_F(ee, ge4, ge4, ge2, ge3) + w1 = _stable_fraction_K1(ee, ge4, ge2) * _stable_fraction_F(ee, ge4, ge4, ge1, ge3) + w2 = _stable_fraction_K1(ee, ge4, ge3) * _stable_fraction_F(ee, ge4, ge4, ge1, ge2) + w3 = ( + -_stable_fraction_K2(ee, ge4, ge3, ge1) * _stable_fraction_F(ee, ge4, ge3, ge2, ge4) + - _stable_fraction_K2(ee, ge4, ge2, ge3) * _stable_fraction_F(ee, ge4, ge2, ge1, ge4) + - _stable_fraction_K2(ee, ge4, ge1, ge2) * _stable_fraction_F(ee, ge4, ge1, ge3, ge4) + ) + + weights_sorted[:, i] = np.vstack([w0, w1, w2, w3]) + + # === Remap to original corner order + corner_weights = np.zeros_like(corner_energies, dtype=float) + corner_weights[order, np.arange(n_tetra)[None, :]] = weights_sorted + + return corner_weights diff --git a/python/triqs_dft_tools/converters/plovasp/proj_shell.py b/python/triqs_dft_tools/converters/plovasp/proj_shell.py index eca79bfc8..2e5aeb882 100644 --- a/python/triqs_dft_tools/converters/plovasp/proj_shell.py +++ b/python/triqs_dft_tools/converters/plovasp/proj_shell.py @@ -34,7 +34,7 @@ import logging import numpy as np -from . import atm +from .lintetra import dos_tetra_weights_3d np.set_printoptions(suppress=True) @@ -437,7 +437,7 @@ def density_of_states(self, el_struct, emesh): for ib, eigk in enumerate(el_struct.eigvals[:, self.ib_min:self.ib_max+1, isp].T): for ie, e in enumerate(emesh): eigk_ef = eigk - el_struct.efermi - cti = atm.dos_tetra_weights_3d(eigk_ef, e, itt) + cti = dos_tetra_weights_3d(eigk_ef, e, itt) for im in range(nlm): for io in range(nion): dos[ie, isp, io, im] += np.sum((cti * w_k[itt[1:, :], ib, isp, io, im].real).sum(0) * itt[0, :]) diff --git a/share/CMakeLists.txt b/share/CMakeLists.txt index 8d258a5f0..4df0478dc 100644 --- a/share/CMakeLists.txt +++ b/share/CMakeLists.txt @@ -6,10 +6,8 @@ if(NOT IS_SUBPROJECT AND NOT CMAKE_INSTALL_PREFIX STREQUAL "/usr/local" ) - if(PythonSupport) - set(EXPORT_PYTHON_PATH "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CPP2PY_PYTHON_LIB_DEST_ROOT}:$PYTHONPATH") - set(MODFILE_PYTHON_PATH "prepend-path PYTHONPATH $root/${CPP2PY_PYTHON_LIB_DEST_ROOT}") - endif() + set(EXPORT_PYTHON_PATH "export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/${CPP2PY_PYTHON_LIB_DEST_ROOT}:$PYTHONPATH") + set(MODFILE_PYTHON_PATH "prepend-path PYTHONPATH $root/${CPP2PY_PYTHON_LIB_DEST_ROOT}") configure_file(${PROJECT_NAME}.modulefile.in ${PROJECT_NAME}.modulefile @ONLY) configure_file(${PROJECT_NAME}vars.sh.in ${PROJECT_NAME}vars.sh @ONLY) diff --git a/share/cmake/CMakeLists.txt b/share/cmake/CMakeLists.txt index c845b7b4d..61f4da427 100644 --- a/share/cmake/CMakeLists.txt +++ b/share/cmake/CMakeLists.txt @@ -7,4 +7,3 @@ install( DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) -install(EXPORT ${PROJECT_NAME}-targets NAMESPACE ${PROJECT_NAME}:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) diff --git a/share/cmake/triqs_dft_tools-config.cmake.in b/share/cmake/triqs_dft_tools-config.cmake.in index b6bb5bbdd..d91cf3e96 100644 --- a/share/cmake/triqs_dft_tools-config.cmake.in +++ b/share/cmake/triqs_dft_tools-config.cmake.in @@ -23,18 +23,12 @@ set(@PROJECT_NAME@_ROOT @CMAKE_INSTALL_PREFIX@ CACHE STRING "@PROJECT_NAME@ root #endfunction() #find_dep(depname 1.0) -# Include the exported targets of this project -include(@CMAKE_INSTALL_FULL_LIBDIR@/cmake/@PROJECT_NAME@/@PROJECT_NAME@-targets.cmake) +## Include the exported targets of this project +#include(@CMAKE_INSTALL_FULL_LIBDIR@/cmake/@PROJECT_NAME@/@PROJECT_NAME@-targets.cmake) message(STATUS "Found @PROJECT_NAME@-config.cmake with version @PROJECT_VERSION@, hash = @PROJECT_GIT_HASH@, root = @CMAKE_INSTALL_PREFIX@") # Was the Project built with Documentation? set(@PROJECT_NAME@_WITH_DOCUMENTATION @Build_Documentation@ CACHE BOOL "Was @PROJECT_NAME@ build with documentation?") -# Was the Project built with PythonSupport? -set(@PROJECT_NAME@_WITH_PYTHON_SUPPORT @PythonSupport@ CACHE BOOL "Was @PROJECT_NAME@ build with python support?") -if(@PythonSupport@) - set(@PROJECT_NAME@_MODULE_DIR @CMAKE_INSTALL_PREFIX@/@CPP2PY_PYTHON_LIB_DEST_ROOT@ CACHE BOOL "The @PROJECT_NAME@ python module directory") -endif() - endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 19467c6a0..543107f70 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,3 @@ -add_subdirectory(c++) - -if(PythonSupport) - add_subdirectory(python) - add_subdirectory(python/plovasp) - add_subdirectory(python/elk) -endif() +add_subdirectory(python) +add_subdirectory(python/plovasp) +add_subdirectory(python/elk) diff --git a/test/c++/CMakeLists.txt b/test/c++/CMakeLists.txt deleted file mode 100644 index 14ac6ae1f..000000000 --- a/test/c++/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copy h5 files to binary dir -file(GLOB_RECURSE all_h5_ref_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.ref.h5) -foreach(file ${all_h5_ref_files}) - configure_file(${file} ${file} COPYONLY) -endforeach() - -# List of all tests -file(GLOB_RECURSE all_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp) - -foreach(test ${all_tests}) - get_filename_component(test_name ${test} NAME_WE) - get_filename_component(test_dir ${test} DIRECTORY) - add_executable(${test_name} ${test}) - target_link_libraries(${test_name} ${PROJECT_NAME}::${PROJECT_NAME}_c ${PROJECT_NAME}_warnings gtest_main) - set_property(TARGET ${test_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - # Run clang-tidy if found - if(CLANG_TIDY_EXECUTABLE) - set_target_properties(${test_name} PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") - endif() - # Run cppcheck if found - if(CPPCHECK_EXECUTABLE) - add_custom_command( - TARGET ${test_name} - COMMAND ${CPPCHECK_EXECUTABLE} - --enable=warning,style,performance,portability - --std=c++20 - --template=gcc - --verbose - --force - --quiet - ${CMAKE_CURRENT_SOURCE_DIR}/${test} - ) - endif() -endforeach() diff --git a/test/c++/converters/vasp/reorder_flag.cpp b/test/c++/converters/vasp/reorder_flag.cpp deleted file mode 100644 index 293b75b8b..000000000 --- a/test/c++/converters/vasp/reorder_flag.cpp +++ /dev/null @@ -1,23 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en; - int inds[4]; - int flag, flag_should; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 1\n\n"); - - flag = dos_reorder(en, e, inds); - flag_should = 3; - - if(check_reorder_flag(flag, flag_should)) return 1; -} - diff --git a/test/c++/converters/vasp/reorder_inds.cpp b/test/c++/converters/vasp/reorder_inds.cpp deleted file mode 100644 index 2e4df33ad..000000000 --- a/test/c++/converters/vasp/reorder_inds.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en; - int inds[4], inds_should[4]; - int flag; - - e[0] = -1.5; - e[1] = -1.0; - e[2] = -1.309017; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 2\n\n"); - - flag = dos_reorder(en, e, inds); - - inds_should[0] = 0; - inds_should[1] = 2; - inds_should[2] = 1; - inds_should[3] = 3; - - if(check_reorder_inds(inds, inds_should)) return 1; -} - diff --git a/test/c++/converters/vasp/testing.hpp b/test/c++/converters/vasp/testing.hpp deleted file mode 100644 index 79ff99e47..000000000 --- a/test/c++/converters/vasp/testing.hpp +++ /dev/null @@ -1,91 +0,0 @@ - -#include -#include -#include - -#define ASSERT(cond, message) if(!(cond)) { \ - printf("*** Fail: %s\n", message); return 1;} - -// -// Functions defined in 'atm_c' library -// -extern int dos_corner_weights(double en, double *eigs, int *inds, - double *ci); -extern int dos_tet_weights(double en, double *eigs, int *inds, - double *ct); -extern int dos_reorder(double en, double *e, int *inds); - - -int check_reorder_flag(int flag, int flag_should); -int check_reorder_inds(int *inds, int *inds_should); -int check_weights_result(double *res, double *r_should); - -// -// Test templates -// -int check_reorder_flag(int flag, int flag_should) -{ - char mess[128]; - sprintf(mess, "Reorder flag should be %d and not %d", flag_should, flag); - ASSERT(flag == flag_should, mess); - return 0; -} - -int check_reorder_inds(int *inds, int *inds_should) -{ - char mess[128], tmp[128], numb[128]; - int i, flag; - - strcpy(mess, "Inds should be "); - numb[0] = '\0'; - flag = 1; - for(i = 0; i < 4; i++) - { - if(inds_should[i] != inds[i]) flag = 0; - sprintf(tmp, " %d", inds_should[i]); - strcat(numb, tmp); - } - strcat(mess, numb); - strcat(mess, " and not"); - numb[0] = '\0'; - for(i = 0; i < 4; i++) - { - sprintf(tmp, " %d", inds[i]); - strcat(numb, tmp); - } - strcat(mess, numb); - - ASSERT(flag, mess); - - return 0; -} - -int check_weights_result(double *res, double *r_should) -{ - const double tol = 1e-14; - int i, flag; - char mess[128], tmp[128]; - - flag = 1; - for(i = 0; i < 4; i++) - { - if(fabs(r_should[i] - res[i]) > tol) - { - flag = 0; - break; - } - } - strcpy(mess, "Success"); - if(!flag) - { - sprintf(mess, "res[%d] should be %20.15lf", i, r_should[i]); - sprintf(tmp, " and not %20.15lf", res[i]); - strcat(mess, tmp); - } - - ASSERT(flag, mess); - - return 0; -} - - diff --git a/test/c++/converters/vasp/tet_weights.cpp b/test/c++/converters/vasp/tet_weights.cpp deleted file mode 100644 index 196786ae2..000000000 --- a/test/c++/converters/vasp/tet_weights.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en, ci_sum, ct, res[4]; - int inds[4]; - int i; - char mess[128]; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 2\n\n"); - - dos_corner_weights(en, e, inds, res); - dos_tet_weights(en, e, inds, &ct); - - for(i = 0, ci_sum = 0.0; i < 4; i++) - { - printf(" res[%d] = %20.15lf\n", i, res[i]); - ci_sum += res[i]; - } - - printf(" Difference: %le\n", fabs(ci_sum - ct)); - - sprintf(mess, "Difference between 'ci_sum' and 'ct' is too large"); - ASSERT(fabs(ci_sum - ct) < 1e-12, mess); -} - diff --git a/test/c++/converters/vasp/weights1.cpp b/test/c++/converters/vasp/weights1.cpp deleted file mode 100644 index b04fa2970..000000000 --- a/test/c++/converters/vasp/weights1.cpp +++ /dev/null @@ -1,27 +0,0 @@ - -#include "testing.hpp" - -int main() -{ - double e[4], en, res[4], r_should[4]; - int inds[4]; - int flag; - - e[0] = -1.5; - e[1] = -1.309017; - e[2] = -1.0; - e[3] = -0.5; - - en = -0.55; - printf("\n Test case 4\n\n"); - - dos_corner_weights(en, e, inds, res); - - r_should[0] = 0.000309016992226; - r_should[1] = 0.000381966005939; - r_should[2] = 0.000618033984453; - r_should[3] = 0.017232002550965; - - if(check_weights_result(res, r_should)) return 1; -} - diff --git a/test/python/CMakeLists.txt b/test/python/CMakeLists.txt index 9c8f0ab55..7287c7a27 100644 --- a/test/python/CMakeLists.txt +++ b/test/python/CMakeLists.txt @@ -15,5 +15,5 @@ foreach(test ${all_tests}) get_filename_component(test_name ${test} NAME_WE) get_filename_component(test_dir ${test} DIRECTORY) add_test(NAME Py_${test_name} COMMAND ${TRIQS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${test_name}.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir}) - set_property(TEST Py_${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH} ${SANITIZER_RT_PRELOAD}) + set_property(TEST Py_${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH}) endforeach() diff --git a/test/python/plovasp/atm/test_atm.py b/test/python/plovasp/atm/test_atm.py index 864d93b8e..4d9f30299 100644 --- a/test/python/plovasp/atm/test_atm.py +++ b/test/python/plovasp/atm/test_atm.py @@ -2,7 +2,7 @@ import os import numpy as np -from triqs_dft_tools.converters.plovasp.atm import dos_tetra_weights_3d +from triqs_dft_tools.converters.plovasp.lintetra import dos_tetra_weights_3d import mytest ################################################################################