From abe2c433089f3954c47b9f29b24493a5e3f32c80 Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Thu, 28 Nov 2024 16:52:31 +0100 Subject: [PATCH 1/9] fix option BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE Using the correct option worked. However, it was not listed and declared as option. --- CMakeLists.txt | 4 ++-- README.md | 14 +++++++------- docs/quickstart/installation.rst | 19 +++++++++---------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 787a3dd..aac9db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,8 @@ cmake_dependent_option(BUILD_POLYHEDRAL_GRAVITY_LIBRARY "Builds the library (Def "NOT BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE AND NOT BUILD_POLYHEDRAL_GRAVITY_TESTS" ON) message(STATUS "BUILD_POLYHEDRAL_GRAVITY_LIBRARY = ${BUILD_POLYHEDRAL_GRAVITY_LIBRARY}") # Option to build the python interface -option(BUILD_POLYHEDRAL_PYTHON_INTERFACE "Set this to on if the python interface should be built (Default: ON)" ON) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE = ${BUILD_POLYHEDRAL_PYTHON_INTERFACE}") +option(BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE "Set this to on if the python interface should be built (Default: ON)" ON) +message(STATUS "BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE = ${BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE}") # Option to build tests or not option(BUILD_POLYHEDRAL_GRAVITY_TESTS "Set to on if the tests should be built (Default: ON)" ON) message(STATUS "BUILD_POLYHEDRAL_GRAVITY_TESTS = ${BUILD_POLYHEDRAL_GRAVITY_TESTS}") diff --git a/README.md b/README.md index 194bd1a..706e394 100644 --- a/README.md +++ b/README.md @@ -305,13 +305,13 @@ cmake --build . The following options are available: -| Name (Default) | Options | -|-------------------------------------------:|:--------------------------------------------------------------------------------------------| -| POLYHEDRAL_GRAVITY_PARALLELIZATION (`CPP`) | `CPP` = Serial Execution / `OMP` or `TBB` = Parallel Execution with OpenMP or Intel\'s TBB | -| LOGGING_LEVEL (`INFO`) | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `OFF` | -| BUILD_POLYHEDRAL_GRAVITY_DOCS (`OFF`) | Build this documentation | -| BUILD_POLYHEDRAL_GRAVITY_TESTS (`ON`) | Build the Tests | -| BUILD_POLYHEDRAL_PYTHON_INTERFACE (`ON`) | Build the Python interface | +| Name (Default) | Options | +|-------------------------------------------------:|:--------------------------------------------------------------------------------------------| +| POLYHEDRAL_GRAVITY_PARALLELIZATION (`CPP`) | `CPP` = Serial Execution / `OMP` or `TBB` = Parallel Execution with OpenMP or Intel\'s TBB | +| LOGGING_LEVEL (`INFO`) | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `OFF` | +| BUILD_POLYHEDRAL_GRAVITY_DOCS (`OFF`) | Build this documentation | +| BUILD_POLYHEDRAL_GRAVITY_TESTS (`ON`) | Build the Tests | +| BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE (`ON`) | Build the Python interface | During testing POLYHEDRAL_GRAVITY_PARALLELIZATION=`TBB` has been the most performant. It is further not recommend to change the LOGGING_LEVEL to something else than `INFO=2`. diff --git a/docs/quickstart/installation.rst b/docs/quickstart/installation.rst index f529a47..37d8755 100644 --- a/docs/quickstart/installation.rst +++ b/docs/quickstart/installation.rst @@ -87,16 +87,15 @@ Build Options The available options are the following: -================================================ =================================================================================================================================== -Name (Default) Options -================================================ =================================================================================================================================== -POLYHEDRAL_GRAVITY_PARALLELIZATION (:code:`CPP`) :code:`CPP` = Serial Execution / :code:`OMP` or :code:`TBB` = Parallel Execution with OpenMP or Intel's TBB -LOGGING_LEVEL (:code:`INFO`) :code:`TRACE`, :code:`DEBUG`, :code:`INFO`, :code:`WARN`, :code:`ERROR`, :code:`CRITICAL`, :code:`OFF` -BUILD_POLYHEDRAL_GRAVITY_DOCS (:code:`OFF`) Build this documentation -BUILD_POLYHEDRAL_GRAVITY_TESTS (:code:`ON`) Build the Tests -BUILD_POLYHEDRAL_PYTHON_INTERFACE (:code:`ON`) Build the Python interface -================================================ =================================================================================================================================== - +====================================================== ============================================================================================================ +Name (Default) Options +====================================================== ============================================================================================================ +POLYHEDRAL_GRAVITY_PARALLELIZATION (:code:`CPP`) :code:`CPP` = Serial Execution / :code:`OMP` or :code:`TBB` = Parallel Execution with OpenMP or Intel's TBB +LOGGING_LEVEL (:code:`INFO`) :code:`TRACE`, :code:`DEBUG`, :code:`INFO`, :code:`WARN`, :code:`ERROR`, :code:`CRITICAL`, :code:`OFF` +BUILD_POLYHEDRAL_GRAVITY_DOCS (:code:`OFF`) Build this documentation +BUILD_POLYHEDRAL_GRAVITY_TESTS (:code:`ON`) Build the Tests +BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE (:code:`ON`) Build the Python interface +====================================================== ============================================================================================================ Dependencies (automatically set-up) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 62323b9c07753862178e39f8bf3be3abea891610 Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Thu, 28 Nov 2024 19:01:30 +0100 Subject: [PATCH 2/9] Organize spdlog imports and fix fmt symbol issue. Reorganize spdlog headers in CSVWriter.h and remove unused imports in other files to clean up code dependencies. Add a compile definition in CMakeLists.txt to resolve missing fmt symbols. --- CMakeLists.txt | 4 ++++ src/polyhedralGravity/model/GravityModelDetail.h | 1 - src/polyhedralGravity/output/CSVWriter.h | 2 +- test/model/GravityModelVectorUtility.h | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aac9db3..362ec95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,10 @@ IF(_LIBCPP_DISABLE_AVAILABILITY) add_definitions(-D_LIBCPP_DISABLE_AVAILABILITY) endif () +# Resolves missing fmt symbols when working with spdlog (bundled via brew/ conda on Arm architecture) +# Refer to https://github.com/gabime/spdlog/issues/660 +add_compile_definitions(FMT_HEADER_ONLY) + ####################################################### # Including dependencies needed across multiple targets ####################################################### diff --git a/src/polyhedralGravity/model/GravityModelDetail.h b/src/polyhedralGravity/model/GravityModelDetail.h index ccb3f34..c86a295 100644 --- a/src/polyhedralGravity/model/GravityModelDetail.h +++ b/src/polyhedralGravity/model/GravityModelDetail.h @@ -6,7 +6,6 @@ #include #include -#include "spdlog/spdlog.h" #include "thrust/iterator/zip_iterator.h" #include "thrust/iterator/transform_iterator.h" #include "thrust/iterator/counting_iterator.h" diff --git a/src/polyhedralGravity/output/CSVWriter.h b/src/polyhedralGravity/output/CSVWriter.h index 0e3baab..3c44068 100644 --- a/src/polyhedralGravity/output/CSVWriter.h +++ b/src/polyhedralGravity/output/CSVWriter.h @@ -6,9 +6,9 @@ #include #include #include "polyhedralGravity/model/GravityModelData.h" +#include "spdlog/spdlog.h" #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/fmt/ostr.h" -#include "spdlog/spdlog.h" namespace polyhedralGravity { diff --git a/test/model/GravityModelVectorUtility.h b/test/model/GravityModelVectorUtility.h index cd6a458..a6abde4 100644 --- a/test/model/GravityModelVectorUtility.h +++ b/test/model/GravityModelVectorUtility.h @@ -8,7 +8,6 @@ #include "polyhedralGravity/model/GravityModelData.h" #include "polyhedralGravity/util/UtilityConstants.h" #include "polyhedralGravity/util/UtilityContainer.h" -#include "spdlog/spdlog.h" #include "thrust/iterator/zip_iterator.h" #include "thrust/iterator/transform_iterator.h" #include "thrust/iterator/counting_iterator.h" From b4828a31f97b54059ee2a5187010373d9c7f8c6a Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Fri, 29 Nov 2024 09:35:27 +0100 Subject: [PATCH 3/9] add comment --- cmake/spdlog.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/spdlog.cmake b/cmake/spdlog.cmake index cbb0e49..ed42c6f 100644 --- a/cmake/spdlog.cmake +++ b/cmake/spdlog.cmake @@ -7,6 +7,7 @@ set(SPDLOG_VERSION 1.14.1) # If you install spdlog@1.14.1 via homebrew on ARM macOS, CMake will find spdlog # However, there is a version mismatch between the `fmt` library installed as dependency, and the one actually # being required leading to a linking error (i.e. missing symbols) while compiling! +# Update 29.11.2024: We fixed this by using spdlog has header library (--> top-level CMake file) find_package(spdlog ${SPDLOG_VERSION} QUIET) if(${spdlog_FOUND}) From d7a705ccaa0bbecf80e5780b57dd0faccd14b95a Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Tue, 10 Dec 2024 15:06:06 +0100 Subject: [PATCH 4/9] update tetgen handling to avoid CMake deprecation warning --- cmake/tetgen.cmake | 59 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/cmake/tetgen.cmake b/cmake/tetgen.cmake index 3e56303..1788ab0 100644 --- a/cmake/tetgen.cmake +++ b/cmake/tetgen.cmake @@ -3,47 +3,44 @@ include(FetchContent) message(STATUS "Setting up tetgen") # IMPORTANT NOTE -# We do ot use findPackage here, as we modify the one source file slightly to suppress output via stdout!!! +# We do not use find_package here, as we modify the one source file slightly to suppress output via stdout!!! -#Fetches the version 1.6 for tetgen +# Fetches the version 1.6 for tetgen FetchContent_Declare(tetgen GIT_REPOSITORY https://github.com/libigl/tetgen.git GIT_TAG 4f3bfba3997f20aa1f96cfaff604313a8c2c85b6 # release 1.6 - ) +) -FetchContent_GetProperties(tetgen) -if(NOT tetgen_POPULATED) - FetchContent_Populate(tetgen) +FetchContent_MakeAvailable(tetgen) - # This is ugly, but functional - # We modify one source file in order to prevent console output from the printf function - # without polluting the global include path (which would cause to more uglier issues) - if(NOT EXISTS ${tetgen_SOURCE_DIR}/tetgen_mod.cxx) - message(STATUS "Creating modified tetgen.cxx in order to prevent console output from library") - file(READ ${tetgen_SOURCE_DIR}/tetgen.cxx TETGEN_CXX) +# Modify the tetgen library to suppress console output from the printf function +if(NOT EXISTS ${tetgen_SOURCE_DIR}/tetgen_mod.cxx) + message(STATUS "Creating modified tetgen.cxx in order to prevent console output from library") + file(READ ${tetgen_SOURCE_DIR}/tetgen.cxx TETGEN_CXX) - string(REPLACE - "#include \"tetgen.h\"" - "#include \"tetgen.h\"\n#define printf(fmt, ...) (0)\n" - TETGEN_CXX "${TETGEN_CXX}") + string(REPLACE + "#include \"tetgen.h\"" + "#include \"tetgen.h\"\n#define printf(fmt, ...) (0)\n" + TETGEN_CXX "${TETGEN_CXX}") - file(WRITE ${tetgen_SOURCE_DIR}/tetgen_mod.cxx - "${TETGEN_CXX}" - ) - else() - message(STATUS "A modified tetgen.cxx already exists! It is assumed that is the correct one disabling output") - endif() - - add_library(tetgen STATIC - ${tetgen_SOURCE_DIR}/tetgen_mod.cxx - ${tetgen_SOURCE_DIR}/predicates.cxx - ) + file(WRITE ${tetgen_SOURCE_DIR}/tetgen_mod.cxx + "${TETGEN_CXX}" + ) +else() + message(STATUS "A modified tetgen.cxx already exists! It is assumed that it is the correct one disabling output") +endif() - target_compile_definitions(tetgen PRIVATE -DTETLIBRARY) +# Add the modified version of the tetgen library +add_library(tetgen_lib STATIC + ${tetgen_SOURCE_DIR}/tetgen_mod.cxx + ${tetgen_SOURCE_DIR}/predicates.cxx +) - target_include_directories(tetgen INTERFACE "${tetgen_SOURCE_DIR}") +# Define the TETLIBRARY macro for usage +target_compile_definitions(tetgen_lib PRIVATE -DTETLIBRARY) -endif() +# Include the tetgen source directory for the library +target_include_directories(tetgen_lib INTERFACE "${tetgen_SOURCE_DIR}") # Disable warnings from the library target -target_compile_options(tetgen PRIVATE -w) \ No newline at end of file +target_compile_options(tetgen_lib PRIVATE -w) \ No newline at end of file From a3bf30ccca46b1c6a64e836df5dfdd14e8804dcf Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Tue, 10 Dec 2024 15:06:19 +0100 Subject: [PATCH 5/9] unify Version handling of the implementation --- CMakeLists.txt | 16 +++++++++---- cmake/git.cmake | 23 +++++++++++++++++++ cmake/version.cmake | 12 ++++++++++ setup.py | 23 ++++++++++++++++++- src/CMakeLists.txt | 4 ++-- src/polyhedralGravity/CMakeLists.txt | 2 +- src/polyhedralGravity/Version.h | 15 ++++++++++++ .../PolyhedralGravityPython.cpp | 10 ++++---- 8 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 cmake/git.cmake create mode 100644 cmake/version.cmake create mode 100644 src/polyhedralGravity/Version.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 362ec95..f46e2c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,18 @@ project(polyhedralGravity) set(CMAKE_CXX_STANDARD 17) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Appends the the module path to contain additional CMake modules for this project +# and include everything necessary +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +include(version) +include(git) + +# Set and Print the Version number +polyhedral_gravity_parse_version(POLYHEDRAL_GRAVITY_VERSION) +get_git_commit_hash(POLYHEDRAL_GRAVITY_GIT_HASH) +message(STATUS "Polyhedral Gravity Version ${POLYHEDRAL_GRAVITY_VERSION}") +message(STATUS "Polyhedral Gravity Git Hash ${POLYHEDRAL_GRAVITY_GIT_HASH}") + include(CMakeDependentOption) ##################################### @@ -60,11 +72,7 @@ add_compile_definitions(FMT_HEADER_ONLY) ####################################################### # Including dependencies needed across multiple targets ####################################################### -# Appends the the module path to contain additional CMake modules for this project -# and include everything necessary -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -# Include dependecies include(thrust) include(spdlog) include(tetgen) diff --git a/cmake/git.cmake b/cmake/git.cmake new file mode 100644 index 0000000..aec6d4c --- /dev/null +++ b/cmake/git.cmake @@ -0,0 +1,23 @@ +function(get_git_commit_hash OUTPUT_VAR) + # Ensure Git is available + find_package(Git QUIET REQUIRED) + + # Run a Git command to get the current commit hash + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE GIT_ERROR + ERROR_STRIP_TRAILING_WHITESPACE + ) + + # Check if the Git command was successful + if (NOT GIT_COMMIT_HASH OR GIT_ERROR) + message(WARNING "Failed to retrieve Git commit hash: ${GIT_ERROR}") + set(${OUTPUT_VAR} "UNKNOWN" PARENT_SCOPE) + else() + # Pass the hash back to the calling scope + set(${OUTPUT_VAR} "${GIT_COMMIT_HASH}" PARENT_SCOPE) + endif() +endfunction() \ No newline at end of file diff --git a/cmake/version.cmake b/cmake/version.cmake new file mode 100644 index 0000000..4ed3736 --- /dev/null +++ b/cmake/version.cmake @@ -0,0 +1,12 @@ +function(polyhedral_gravity_parse_version OUTPUT_VAR) + # Read the content of the given header file + file(READ "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/Version.h" HEADER_CONTENTS) + # Extract the version using regex + string(REGEX MATCH "constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+[a-zA-Z0-9]*)\"" VERSION_MATCH "${HEADER_CONTENTS}") + # Set the output variable to the matched version group + if(CMAKE_MATCH_1) + set(${OUTPUT_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE) + else() + message(FATAL_ERROR "Failed to parse POLYHEDRAL_GRAVITY_VERSION from '${HEADER_FILE}'") + endif() +endfunction() \ No newline at end of file diff --git a/setup.py b/setup.py index 26cd85f..736081c 100644 --- a/setup.py +++ b/setup.py @@ -53,6 +53,27 @@ def get_cmake_generator(): else: return None +def get_version(): + """Returns the version of the polyhedral gravity package by reading Version.h.""" + # Construct the path to Version.h relative to the current file + version_file = os.path.join(os.path.dirname(__file__), "src", "polyhedralGravity", "Version.h") + + # Check if the Version.h file exists + if not os.path.exists(version_file): + raise FileNotFoundError(f"Version file not found: {version_file}") + + # Open and read the file + with open(version_file, "r") as file: + content = file.read() + + # Use regex to extract the version string + version_match = re.search(r'POLYHEDRAL_GRAVITY_VERSION\s*=\s*\"([^\"]+)\"', content) + if version_match: + return version_match.group(1) + else: + raise ValueError("Version string not found in Version.h") + + # ----------------------------------------------------------------------------------------- # The following is adapted from https://github.com/pybind/cmake_example/blob/master/setup.py # ----------------------------------------------------------------------------------------- @@ -173,7 +194,7 @@ def build_extension(self, ext): # -------------------------------------------------------------------------------- setup( name="polyhedral_gravity", - version="3.2.1", + version=get_version(), author="Jonas Schuhmacher", author_email="jonas.schuhmacher@tum.de", description="Package to compute full gravity tensor of a given constant density polyhedron for arbitrary points " diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08b5bbb..4a64eea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ if (BUILD_POLYHEDRAL_GRAVITY_LIBRARY) target_link_libraries(${PROJECT_NAME}_lib spdlog::spdlog yaml-cpp::yaml-cpp - tetgen + tetgen_lib xsimd Thrust ) @@ -60,7 +60,7 @@ if(BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE) target_link_libraries(polyhedral_gravity PUBLIC spdlog::spdlog - tetgen + tetgen_lib xsimd Thrust ) diff --git a/src/polyhedralGravity/CMakeLists.txt b/src/polyhedralGravity/CMakeLists.txt index efd3fb1..30bbb4e 100644 --- a/src/polyhedralGravity/CMakeLists.txt +++ b/src/polyhedralGravity/CMakeLists.txt @@ -3,4 +3,4 @@ file(GLOB_RECURSE SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") -add_library(${PROJECT_NAME}_lib OBJECT ${SRC}) +add_library(${PROJECT_NAME}_lib OBJECT ${SRC} Version.h) diff --git a/src/polyhedralGravity/Version.h b/src/polyhedralGravity/Version.h new file mode 100644 index 0000000..49e57d9 --- /dev/null +++ b/src/polyhedralGravity/Version.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace polyhedralGravity { + + /** + * The API version of the polyhedral gravity model's interface. + * This value is utilized across C++ and Python Interface and the single value + * to change in case of updates. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "3.2.1"; + + +}// namespace polyhedralGravity diff --git a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp index e6f4d79..1386baf 100644 --- a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp +++ b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp @@ -10,6 +10,7 @@ #include "polyhedralGravity/model/GravityModelData.h" #include "polyhedralGravity/model/GravityModel.h" #include "polyhedralGravity/model/GravityEvaluable.h" +#include "polyhedralGravity/Version.h" namespace py = pybind11; @@ -43,12 +44,10 @@ PYBIND11_MODULE(polyhedral_gravity, m) { .. note:: *Tsoulis et al.*'s formulation requires that the normals point :code:`OUTWARDS`. - The implementation **can handle both cases and also can automatically determine the property** if initiall set wrong. + The implementation **can handle both cases and also can automatically determine the property** if initially set wrong. Using :code:`AUTOMATIC` (default for first-time-user) or :code:`VERIFY` raises a :code:`ValueError` if the :py:class:`polyhedral_gravity.NormalOrientation` is wrong. Using :code:`HEAL` will re-order the vertex sorting to fix errors. - Using :code:`DISABLE` will turn this check off and avoid :math:`O(n^2)` runtime complexcity of this check! Highly recommened, when you "know your mesh"! - - + Using :code:`DISABLE` will turn this check off and avoid :math:`O(n^2)` runtime complexity of this check! Highly recommended, when you "know your mesh"! The polyhedron's mesh's units must match with the constant density! For example, if the mesh is in :math:`[m]`, then the constant density should be in :math:`[\frac{kg}{m^3}]`. @@ -63,7 +62,7 @@ PYBIND11_MODULE(polyhedral_gravity, m) { parallel=True, ) - or via use the cached approach :py:class:`polyhedral_gravity.GravityEvaluable` (desriable for subsequent evaluations using the same :py:class:`polyhedral_gravity.Polyhedron`) + or via use the cached approach :py:class:`polyhedral_gravity.GravityEvaluable` (desirable for subsequent evaluations using the same :py:class:`polyhedral_gravity.Polyhedron`) .. code-block:: python @@ -103,6 +102,7 @@ PYBIND11_MODULE(polyhedral_gravity, m) { Accordingly, the second derivative tensor is defined as the derivative of :math:`\textbf{g}`. )mydelimiter"; + m.attr("__version__") = POLYHEDRAL_GRAVITY_VERSION; py::enum_(m, "NormalOrientation", R"mydelimiter( The orientation of the plane unit normals of the polyhedron. From 9479f4aa2a4f27364bbc61c0ff73d903ee63f1a0 Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Tue, 10 Dec 2024 15:38:04 +0100 Subject: [PATCH 6/9] add parallelization backend attribute to python interface --- CMakeLists.txt | 3 +++ src/main.cpp | 5 +++++ src/polyhedralGravity/Version.h | 14 ++++++++++++++ .../PolyhedralGravityPython.cpp | 1 + 4 files changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f46e2c8..893ac91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,9 @@ include(clang_format) if (${POLYHEDRAL_GRAVITY_PARALLELIZATION} STREQUAL "TBB") include(tbb) thrust_set_TBB_target(TBB::tbb) + add_compile_definitions(POLYHEDRAL_GRAVITY_TBB) +elseif (${POLYHEDRAL_GRAVITY_PARALLELIZATION} STREQUAL "OMP") + add_compile_definitions(POLYHEDRAL_GRAVITY_OMP) endif () # Thrust set-up i.e. the parallelization library, create targets according to the users specification diff --git a/src/main.cpp b/src/main.cpp index 4692e2c..356456f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,9 +4,14 @@ #include "polyhedralGravity/model/GravityModel.h" #include "polyhedralGravity/output/Logging.h" #include "polyhedralGravity/output/CSVWriter.h" +#include "polyhedralGravity/Version.h" int main(int argc, char *argv[]) { using namespace polyhedralGravity; + + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version " + std::string(POLYHEDRAL_GRAVITY_VERSION)); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: " + std::string(POLYHEDRAL_GRAVITY_PARALLELIZATION)); + if (argc != 2) { SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Wrong program call! " "Please use the program like this:\n" diff --git a/src/polyhedralGravity/Version.h b/src/polyhedralGravity/Version.h index 49e57d9..1c668cb 100644 --- a/src/polyhedralGravity/Version.h +++ b/src/polyhedralGravity/Version.h @@ -11,5 +11,19 @@ namespace polyhedralGravity { */ constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "3.2.1"; + /** + * The API parallelization backend of the polyhedral gravity model's interface. + * This value depends on the CMake configuration. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_PARALLELIZATION = +#ifdef POLYHEDRAL_GRAVITY_TBB + "TBB" +#elifdef POLYHEDRAL_GRAVITY_OMP + "OMP" +#else + "CPP" +#endif + ; + }// namespace polyhedralGravity diff --git a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp index 1386baf..b5212f3 100644 --- a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp +++ b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp @@ -103,6 +103,7 @@ PYBIND11_MODULE(polyhedral_gravity, m) { Accordingly, the second derivative tensor is defined as the derivative of :math:`\textbf{g}`. )mydelimiter"; m.attr("__version__") = POLYHEDRAL_GRAVITY_VERSION; + m.attr("__parallelization__") = POLYHEDRAL_GRAVITY_PARALLELIZATION; py::enum_(m, "NormalOrientation", R"mydelimiter( The orientation of the plane unit normals of the polyhedron. From 58d17e7990e65ae6abdfc1a2d5728c1994148880 Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Fri, 13 Dec 2024 13:22:15 +0100 Subject: [PATCH 7/9] Refactor versioning system and enhance build metadata. Replaced hardcoded versioning with a dynamic CMake-driven system using `Info.h` to embed version, parallelization, and commit metadata directly into the build. Simplified Python version parsing and renamed `LOGGING_LEVEL` to `POLYHEDRAL_GRAVITY_LOGGING_LEVEL` for consistency. Consolidated version management and improved Git commit hash handling. --- .gitignore | 3 +- CMakeLists.txt | 48 +++++++++---------- README.md | 16 +++---- cmake/git.cmake | 35 +++++++++++--- cmake/version.cmake | 12 ----- docs/quickstart/installation.rst | 2 +- setup.py | 22 ++++----- src/main.cpp | 10 ++-- src/polyhedralGravity/CMakeLists.txt | 2 +- src/polyhedralGravity/Info.h.in | 36 ++++++++++++++ src/polyhedralGravity/Version.h | 29 ----------- .../PolyhedralGravityPython.cpp | 12 +++-- version.cmake | 18 +++++++ 13 files changed, 143 insertions(+), 102 deletions(-) delete mode 100644 cmake/version.cmake create mode 100644 src/polyhedralGravity/Info.h.in delete mode 100644 src/polyhedralGravity/Version.h create mode 100644 version.cmake diff --git a/.gitignore b/.gitignore index faa3a36..4020348 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ cmake-build-* build polyhedral_gravity.egg-info dist -docs/Doxyfile \ No newline at end of file +docs/Doxyfile +src/polyhedralGravity/Info.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 893ac91..4c24e15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,15 +7,6 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # Appends the the module path to contain additional CMake modules for this project # and include everything necessary list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) -include(version) -include(git) - -# Set and Print the Version number -polyhedral_gravity_parse_version(POLYHEDRAL_GRAVITY_VERSION) -get_git_commit_hash(POLYHEDRAL_GRAVITY_GIT_HASH) -message(STATUS "Polyhedral Gravity Version ${POLYHEDRAL_GRAVITY_VERSION}") -message(STATUS "Polyhedral Gravity Git Hash ${POLYHEDRAL_GRAVITY_GIT_HASH}") - include(CMakeDependentOption) ##################################### @@ -27,38 +18,30 @@ set(POLYHEDRAL_GRAVITY_PARALLELIZATION "CPP" CACHE STRING "Host parallelization set_property(CACHE POLYHEDRAL_GRAVITY_PARALLELIZATION PROPERTY STRINGS CPP, OMP, TBB) # Set the Logging Level -set(LOGGING_LEVEL_LIST "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF") -set(LOGGING_LEVEL "INFO" CACHE STRING "Set the Logging level, default (INFO), available options: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF") -set_property(CACHE LOGGING_LEVEL PROPERTY STRINGS ${LOGGING_LEVEL_LIST}) +set(POLYHEDRAL_GRAVITY_LOGGING_LEVEL_LIST "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF") +set(POLYHEDRAL_GRAVITY_LOGGING_LEVEL "INFO" CACHE STRING "Set the Logging level, default (INFO), available options: TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL, OFF") +set_property(CACHE POLYHEDRAL_GRAVITY_LOGGING_LEVEL PROPERTY STRINGS ${POLYHEDRAL_GRAVITY_LOGGING_LEVEL_LIST}) # Convert the logging level string to its corresponding number -list(FIND LOGGING_LEVEL_LIST ${LOGGING_LEVEL} LOGGING_LEVEL_INDEX) +list(FIND POLYHEDRAL_GRAVITY_LOGGING_LEVEL_LIST ${POLYHEDRAL_GRAVITY_LOGGING_LEVEL} LOGGING_LEVEL_INDEX) if (${LOGGING_LEVEL_INDEX} EQUAL -1) - message(FATAL_ERROR "Invalid logging level: ${LOGGING_LEVEL}") + message(FATAL_ERROR "Invalid logging level: ${POLYHEDRAL_GRAVITY_LOGGING_LEVEL}") endif () add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${LOGGING_LEVEL_INDEX}) -message(STATUS "Logging level set to ${LOGGING_LEVEL} (=${LOGGING_LEVEL_INDEX})") - -################################### -# What actually to build? - Options -################################### +######################################################### +# What actually to build? - Options, Versions and Output +######################################################### # Build docs option(BUILD_POLYHEDRAL_GRAVITY_DOCS "Builds the documentation (Default: OFF)" OFF) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_DOCS = ${BUILD_POLYHEDRAL_GRAVITY_DOCS}") # Build C++ executable option(BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE "Builds the C++ executable (Default: ON)" ON) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE = ${BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE}") # Build library (default ON), if the executable or tests are built this forced to ON cmake_dependent_option(BUILD_POLYHEDRAL_GRAVITY_LIBRARY "Builds the library (Default: ON)" ON "NOT BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE AND NOT BUILD_POLYHEDRAL_GRAVITY_TESTS" ON) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_LIBRARY = ${BUILD_POLYHEDRAL_GRAVITY_LIBRARY}") # Option to build the python interface option(BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE "Set this to on if the python interface should be built (Default: ON)" ON) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE = ${BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE}") # Option to build tests or not option(BUILD_POLYHEDRAL_GRAVITY_TESTS "Set to on if the tests should be built (Default: ON)" ON) -message(STATUS "BUILD_POLYHEDRAL_GRAVITY_TESTS = ${BUILD_POLYHEDRAL_GRAVITY_TESTS}") - IF(_LIBCPP_DISABLE_AVAILABILITY) message(STATUS "Disabling availability macros for libc++") @@ -69,6 +52,21 @@ endif () # Refer to https://github.com/gabime/spdlog/issues/660 add_compile_definitions(FMT_HEADER_ONLY) +include(git) +include(version.cmake) + +message(STATUS "#################################################################") +message(STATUS "Polyhedral Gravity Version ${POLYHEDRAL_GRAVITY_VERSION}") +message(STATUS "Polyhedral Gravity Commit Hash ${POLYHEDRAL_GRAVITY_COMMIT_HASH}") +message(STATUS "Polyhedral Parallelization Backend ${POLYHEDRAL_GRAVITY_PARALLELIZATION}") +message(STATUS "Polyhedral Gravity Logging Level ${POLYHEDRAL_GRAVITY_LOGGING_LEVEL}") +message(STATUS "#################################################################") +message(STATUS "Polyhedral Gravity Documentation ${BUILD_POLYHEDRAL_GRAVITY_DOCS}") +message(STATUS "Polyhedral Gravity Library ${BUILD_POLYHEDRAL_GRAVITY_LIBRARY}") +message(STATUS "Polyhedral Gravity C++ Executable ${BUILD_POLYHEDRAL_GRAVITY_EXECUTABLE}") +message(STATUS "Polyhedral Gravity Python Interface ${BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE}") +message(STATUS "Polyhedral Gravity Tests ${BUILD_POLYHEDRAL_GRAVITY_TESTS}") +message(STATUS "#################################################################") ####################################################### # Including dependencies needed across multiple targets ####################################################### diff --git a/README.md b/README.md index 706e394..d33be82 100644 --- a/README.md +++ b/README.md @@ -305,16 +305,16 @@ cmake --build . The following options are available: -| Name (Default) | Options | -|-------------------------------------------------:|:--------------------------------------------------------------------------------------------| -| POLYHEDRAL_GRAVITY_PARALLELIZATION (`CPP`) | `CPP` = Serial Execution / `OMP` or `TBB` = Parallel Execution with OpenMP or Intel\'s TBB | -| LOGGING_LEVEL (`INFO`) | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `OFF` | -| BUILD_POLYHEDRAL_GRAVITY_DOCS (`OFF`) | Build this documentation | -| BUILD_POLYHEDRAL_GRAVITY_TESTS (`ON`) | Build the Tests | -| BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE (`ON`) | Build the Python interface | +| Name (Default) | Options | +|-------------------------------------------------------------:|:--------------------------------------------------------------------------------------------| +| POLYHEDRAL_GRAVITY_PARALLELIZATION (`CPP`) | `CPP` = Serial Execution / `OMP` or `TBB` = Parallel Execution with OpenMP or Intel\'s TBB | +| POLYHEDRAL_GRAVITY_LOGGING_LEVEL (`INFO`) | `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `OFF` | +| BUILD_POLYHEDRAL_GRAVITY_DOCS (`OFF`) | Build this documentation | +| BUILD_POLYHEDRAL_GRAVITY_TESTS (`ON`) | Build the Tests | +| BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE (`ON`) | Build the Python interface | During testing POLYHEDRAL_GRAVITY_PARALLELIZATION=`TBB` has been the most performant. -It is further not recommend to change the LOGGING_LEVEL to something else than `INFO=2`. +It is further not recommend to change the POLYHEDRAL_GRAVITY_LOGGING_LEVEL to something else than `INFO=2`. The recommended CMake settings using the `TBB` backend would look like this: diff --git a/cmake/git.cmake b/cmake/git.cmake index aec6d4c..d74ba2f 100644 --- a/cmake/git.cmake +++ b/cmake/git.cmake @@ -1,10 +1,9 @@ -function(get_git_commit_hash OUTPUT_VAR) - # Ensure Git is available - find_package(Git QUIET REQUIRED) +find_package(Git QUIET REQUIRED) - # Run a Git command to get the current commit hash +function(get_git_commit_hash OUTPUT_VAR) + # Run a Git command to get the first 8 characters of the current commit hash execute_process( - COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE @@ -17,7 +16,31 @@ function(get_git_commit_hash OUTPUT_VAR) message(WARNING "Failed to retrieve Git commit hash: ${GIT_ERROR}") set(${OUTPUT_VAR} "UNKNOWN" PARENT_SCOPE) else() - # Pass the hash back to the calling scope + # Pass the short hash back to the calling scope set(${OUTPUT_VAR} "${GIT_COMMIT_HASH}" PARENT_SCOPE) endif() +endfunction() + +function(is_git_working_tree_clean OUTPUT_VAR) + # Run a Git command to check if the working tree is clean + execute_process( + COMMAND ${GIT_EXECUTABLE} diff-index --quiet HEAD -- + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + RESULT_VARIABLE GIT_STATUS_RESULT + ERROR_VARIABLE GIT_ERROR + ERROR_STRIP_TRAILING_WHITESPACE + ) + + # Check the result of the Git command + if (NOT GIT_ERROR AND GIT_STATUS_RESULT EQUAL 0) + # Working tree is clean + set(${OUTPUT_VAR} TRUE PARENT_SCOPE) + else() + # Working tree has uncommitted changes or an error occurred + set(${OUTPUT_VAR} FALSE PARENT_SCOPE) + + if (GIT_ERROR) + message(WARNING "Error while checking Git working tree: ${GIT_ERROR}") + endif() + endif() endfunction() \ No newline at end of file diff --git a/cmake/version.cmake b/cmake/version.cmake deleted file mode 100644 index 4ed3736..0000000 --- a/cmake/version.cmake +++ /dev/null @@ -1,12 +0,0 @@ -function(polyhedral_gravity_parse_version OUTPUT_VAR) - # Read the content of the given header file - file(READ "${PROJECT_SOURCE_DIR}/src/polyhedralGravity/Version.h" HEADER_CONTENTS) - # Extract the version using regex - string(REGEX MATCH "constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = \"([0-9]+\\.[0-9]+\\.[0-9]+[a-zA-Z0-9]*)\"" VERSION_MATCH "${HEADER_CONTENTS}") - # Set the output variable to the matched version group - if(CMAKE_MATCH_1) - set(${OUTPUT_VAR} "${CMAKE_MATCH_1}" PARENT_SCOPE) - else() - message(FATAL_ERROR "Failed to parse POLYHEDRAL_GRAVITY_VERSION from '${HEADER_FILE}'") - endif() -endfunction() \ No newline at end of file diff --git a/docs/quickstart/installation.rst b/docs/quickstart/installation.rst index 37d8755..43339a2 100644 --- a/docs/quickstart/installation.rst +++ b/docs/quickstart/installation.rst @@ -91,7 +91,7 @@ The available options are the following: Name (Default) Options ====================================================== ============================================================================================================ POLYHEDRAL_GRAVITY_PARALLELIZATION (:code:`CPP`) :code:`CPP` = Serial Execution / :code:`OMP` or :code:`TBB` = Parallel Execution with OpenMP or Intel's TBB -LOGGING_LEVEL (:code:`INFO`) :code:`TRACE`, :code:`DEBUG`, :code:`INFO`, :code:`WARN`, :code:`ERROR`, :code:`CRITICAL`, :code:`OFF` +POLYHEDRAL_GRAVITY_LOGGING_LEVEL (:code:`INFO`) :code:`TRACE`, :code:`DEBUG`, :code:`INFO`, :code:`WARN`, :code:`ERROR`, :code:`CRITICAL`, :code:`OFF` BUILD_POLYHEDRAL_GRAVITY_DOCS (:code:`OFF`) Build this documentation BUILD_POLYHEDRAL_GRAVITY_TESTS (:code:`ON`) Build the Tests BUILD_POLYHEDRAL_GRAVITY_PYTHON_INTERFACE (:code:`ON`) Build the Python interface diff --git a/setup.py b/setup.py index 736081c..46d70cb 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ # Modify to change the parallelization (Default value: TBB) "POLYHEDRAL_GRAVITY_PARALLELIZATION": "TBB", # Default value (INFO=2) - "LOGGING_LEVEL": "INFO", + "POLYHEDRAL_GRAVITY_LOGGING_LEVEL": "INFO", # Not required for the python interface (--> OFF) "BUILD_POLYHEDRAL_GRAVITY_DOCS": "OFF", # Not required for the python interface (--> OFF) @@ -54,24 +54,24 @@ def get_cmake_generator(): return None def get_version(): - """Returns the version of the polyhedral gravity package by reading Version.h.""" - # Construct the path to Version.h relative to the current file - version_file = os.path.join(os.path.dirname(__file__), "src", "polyhedralGravity", "Version.h") + """Returns the version of the polyhedral gravity package by reading the CMake file.""" + # Path to the CMake file + cmake_file = os.path.join(os.path.dirname(__file__), "version.cmake" ) - # Check if the Version.h file exists - if not os.path.exists(version_file): - raise FileNotFoundError(f"Version file not found: {version_file}") + # Check if the CMake file exists + if not os.path.exists(cmake_file): + raise FileNotFoundError(f"CMake file not found: {cmake_file}") # Open and read the file - with open(version_file, "r") as file: + with open(cmake_file, "r") as file: content = file.read() - # Use regex to extract the version string - version_match = re.search(r'POLYHEDRAL_GRAVITY_VERSION\s*=\s*\"([^\"]+)\"', content) + # Use regex to extract the PROJECT_VERSION + version_match = re.search(r'set\(PROJECT_VERSION\s+([^\s)]+)\)', content) if version_match: return version_match.group(1) else: - raise ValueError("Version string not found in Version.h") + raise ValueError("Version string not found in CMakeLists.txt") # ----------------------------------------------------------------------------------------- diff --git a/src/main.cpp b/src/main.cpp index 356456f..4acea72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,18 @@ -#include +#include "polyhedralGravity/Info.h" #include "polyhedralGravity/input/ConfigSource.h" #include "polyhedralGravity/input/YAMLConfigReader.h" #include "polyhedralGravity/model/GravityModel.h" -#include "polyhedralGravity/output/Logging.h" #include "polyhedralGravity/output/CSVWriter.h" -#include "polyhedralGravity/Version.h" +#include "polyhedralGravity/output/Logging.h" +#include int main(int argc, char *argv[]) { using namespace polyhedralGravity; - SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version " + std::string(POLYHEDRAL_GRAVITY_VERSION)); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version: " + std::string(POLYHEDRAL_GRAVITY_VERSION)); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Commit Hash: " + std::string(POLYHEDRAL_GRAVITY_COMMIT_HASH)); SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: " + std::string(POLYHEDRAL_GRAVITY_PARALLELIZATION)); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Logging Level: " + std::string(POLYHEDRAL_GRAVITY_LOGGING_LEVEL)); if (argc != 2) { SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Wrong program call! " diff --git a/src/polyhedralGravity/CMakeLists.txt b/src/polyhedralGravity/CMakeLists.txt index 30bbb4e..c2a28b3 100644 --- a/src/polyhedralGravity/CMakeLists.txt +++ b/src/polyhedralGravity/CMakeLists.txt @@ -3,4 +3,4 @@ file(GLOB_RECURSE SRC "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") -add_library(${PROJECT_NAME}_lib OBJECT ${SRC} Version.h) +add_library(${PROJECT_NAME}_lib OBJECT ${SRC} Info.h) diff --git a/src/polyhedralGravity/Info.h.in b/src/polyhedralGravity/Info.h.in new file mode 100644 index 0000000..ecb0c35 --- /dev/null +++ b/src/polyhedralGravity/Info.h.in @@ -0,0 +1,36 @@ +#pragma once + +#include + +// ########################################################################################## +// Please note! The content of this file is automatically modified by the CMake build system +// which replaces the variables +// ########################################################################################## + +namespace polyhedralGravity { + + /** + * The API version of the polyhedral gravity model's interface. + * The value is set by the CMake configuration. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "@POLYHEDRAL_GRAVITY_VERSION@"; + + /** + * The API parallelization backend of the polyhedral gravity model's interface. + * The value is set by the CMake configuration. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_PARALLELIZATION = "@POLYHEDRAL_GRAVITY_PARALLELIZATION@"; + + /** + * The API commit with which it was compiled. + * The value is set by the CMake configuration. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_COMMIT_HASH = "@POLYHEDRAL_GRAVITY_COMMIT_HASH@"; + + /** + * The API's Loggin Level. Determines the amount of output. + * The value is set by the CMake configuration. + */ + constexpr std::string_view POLYHEDRAL_GRAVITY_LOGGING_LEVEL = "@POLYHEDRAL_GRAVITY_LOGGING_LEVEL@"; + +}// namespace polyhedralGravity diff --git a/src/polyhedralGravity/Version.h b/src/polyhedralGravity/Version.h deleted file mode 100644 index 1c668cb..0000000 --- a/src/polyhedralGravity/Version.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -namespace polyhedralGravity { - - /** - * The API version of the polyhedral gravity model's interface. - * This value is utilized across C++ and Python Interface and the single value - * to change in case of updates. - */ - constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "3.2.1"; - - /** - * The API parallelization backend of the polyhedral gravity model's interface. - * This value depends on the CMake configuration. - */ - constexpr std::string_view POLYHEDRAL_GRAVITY_PARALLELIZATION = -#ifdef POLYHEDRAL_GRAVITY_TBB - "TBB" -#elifdef POLYHEDRAL_GRAVITY_OMP - "OMP" -#else - "CPP" -#endif - ; - - -}// namespace polyhedralGravity diff --git a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp index b5212f3..abaf3bb 100644 --- a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp +++ b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp @@ -6,11 +6,11 @@ #include "pybind11/pybind11.h" #include "pybind11/stl.h" -#include "polyhedralGravity/model/Polyhedron.h" -#include "polyhedralGravity/model/GravityModelData.h" -#include "polyhedralGravity/model/GravityModel.h" +#include "polyhedralGravity/Info.h" #include "polyhedralGravity/model/GravityEvaluable.h" -#include "polyhedralGravity/Version.h" +#include "polyhedralGravity/model/GravityModel.h" +#include "polyhedralGravity/model/GravityModelData.h" +#include "polyhedralGravity/model/Polyhedron.h" namespace py = pybind11; @@ -102,8 +102,12 @@ PYBIND11_MODULE(polyhedral_gravity, m) { Accordingly, the second derivative tensor is defined as the derivative of :math:`\textbf{g}`. )mydelimiter"; + + // We embedded the version & compilation information into the Python Interface m.attr("__version__") = POLYHEDRAL_GRAVITY_VERSION; m.attr("__parallelization__") = POLYHEDRAL_GRAVITY_PARALLELIZATION; + m.attr("__commit__") = POLYHEDRAL_GRAVITY_COMMIT_HASH; + m.attr("__logging__") = POLYHEDRAL_GRAVITY_LOGGING_LEVEL; py::enum_(m, "NormalOrientation", R"mydelimiter( The orientation of the plane unit normals of the polyhedron. diff --git a/version.cmake b/version.cmake new file mode 100644 index 0000000..869dc0b --- /dev/null +++ b/version.cmake @@ -0,0 +1,18 @@ +# Modify the version with a new release +set(PROJECT_VERSION 3.2.1) +set(POLYHEDRAL_GRAVITY_VERSION ${PROJECT_VERSION}) + +# Get the Git information +get_git_commit_hash(POLYHEDRAL_GRAVITY_COMMIT_HASH) +is_git_working_tree_clean(POLYHEDRAL_GRAVITY_WORKING_TREE) + +# Append "-modified" to the commit hash if the working tree is not clean +if (NOT ${POLYHEDRAL_GRAVITY_WORKING_TREE}) + set(POLYHEDRAL_GRAVITY_COMMIT_HASH "${POLYHEDRAL_GRAVITY_COMMIT_HASH}+modified") +endif () + +# Configure the output header file +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/src/polyhedralGravity/Info.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/src/polyhedralGravity/Info.h" +) \ No newline at end of file From cb7efe392dbc717ddf4765ced68a1891a119a64f Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Fri, 13 Dec 2024 13:29:19 +0100 Subject: [PATCH 8/9] fix spelling --- src/polyhedralGravity/Info.h.in | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/polyhedralGravity/Info.h.in b/src/polyhedralGravity/Info.h.in index ecb0c35..4180d52 100644 --- a/src/polyhedralGravity/Info.h.in +++ b/src/polyhedralGravity/Info.h.in @@ -10,25 +10,26 @@ namespace polyhedralGravity { /** - * The API version of the polyhedral gravity model's interface. + * The API's version of the polyhedral gravity model's interface. * The value is set by the CMake configuration. */ constexpr std::string_view POLYHEDRAL_GRAVITY_VERSION = "@POLYHEDRAL_GRAVITY_VERSION@"; /** - * The API parallelization backend of the polyhedral gravity model's interface. + * The API's parallelization backend of the polyhedral gravity model's interface. * The value is set by the CMake configuration. */ constexpr std::string_view POLYHEDRAL_GRAVITY_PARALLELIZATION = "@POLYHEDRAL_GRAVITY_PARALLELIZATION@"; /** - * The API commit with which it was compiled. + * The commit hash of the currently compiled version. + * This is appened with '+modified' in case the working tree is not clean. * The value is set by the CMake configuration. */ constexpr std::string_view POLYHEDRAL_GRAVITY_COMMIT_HASH = "@POLYHEDRAL_GRAVITY_COMMIT_HASH@"; /** - * The API's Loggin Level. Determines the amount of output. + * The API's Logging Level. Determines the amount of output. * The value is set by the CMake configuration. */ constexpr std::string_view POLYHEDRAL_GRAVITY_LOGGING_LEVEL = "@POLYHEDRAL_GRAVITY_LOGGING_LEVEL@"; From 161da47a41bef9b4b1372a828d96327f3edfa2ea Mon Sep 17 00:00:00 2001 From: Jonas Schuhmacher Date: Mon, 16 Dec 2024 11:12:47 +0100 Subject: [PATCH 9/9] use const, improve output to console --- src/main.cpp | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4acea72..d8523d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,10 +9,11 @@ int main(int argc, char *argv[]) { using namespace polyhedralGravity; - SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version: " + std::string(POLYHEDRAL_GRAVITY_VERSION)); - SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Commit Hash: " + std::string(POLYHEDRAL_GRAVITY_COMMIT_HASH)); - SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: " + std::string(POLYHEDRAL_GRAVITY_PARALLELIZATION)); - SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Logging Level: " + std::string(POLYHEDRAL_GRAVITY_LOGGING_LEVEL)); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################"); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Version: {}", POLYHEDRAL_GRAVITY_VERSION); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Commit Hash: {}", POLYHEDRAL_GRAVITY_COMMIT_HASH); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Model Parallelization Backend: {}", POLYHEDRAL_GRAVITY_PARALLELIZATION); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Polyhedral Gravity Logging Level: {}", POLYHEDRAL_GRAVITY_LOGGING_LEVEL); if (argc != 2) { SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Wrong program call! " @@ -22,20 +23,28 @@ int main(int argc, char *argv[]) { } try { - std::shared_ptr config = std::make_shared(argv[1]); - auto polyhedralSource = config->getDataSource()->getPolyhedralSource(); - auto density = config->getDensity(); - auto computationPoints = config->getPointsOfInterest(); - auto outputFileName = config->getOutputFileName(); - PolyhedronIntegrity checkPolyhedralInput = config->getMeshInputCheckStatus() ? PolyhedronIntegrity::HEAL : PolyhedronIntegrity::DISABLE; + const std::shared_ptr config = std::make_shared(argv[1]); + const auto polyhedralSource = config->getDataSource()->getPolyhedralSource(); + const auto density = config->getDensity(); + const auto computationPoints = config->getPointsOfInterest(); + const auto outputFileName = config->getOutputFileName(); + const PolyhedronIntegrity checkPolyhedralInput = config->getMeshInputCheckStatus() ? PolyhedronIntegrity::HEAL : PolyhedronIntegrity::DISABLE; + + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################"); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Vertices: {}", std::get<0>(polyhedralSource).size()); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Faces: {}", std::get<1>(polyhedralSource).size()); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Number of Computation Points: {}", computationPoints.size()); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Mesh Check Enabled: {}", config->getMeshInputCheckStatus()); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Output File: {}", outputFileName); + SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "####################################################################################"); SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "The calculation started..."); - auto start = std::chrono::high_resolution_clock::now(); - Polyhedron polyhedron{polyhedralSource, density, NormalOrientation::OUTWARDS, checkPolyhedralInput}; - auto result = GravityModel::evaluate(polyhedron, computationPoints, true); - auto end = std::chrono::high_resolution_clock::now(); - auto duration = end - start; - auto ms = std::chrono::duration_cast(duration); + const auto start = std::chrono::high_resolution_clock::now(); + const Polyhedron polyhedron{polyhedralSource, density, NormalOrientation::OUTWARDS, checkPolyhedralInput}; + const auto result = GravityModel::evaluate(polyhedron, computationPoints, true); + const auto end = std::chrono::high_resolution_clock::now(); + const auto duration = end - start; + const auto ms = std::chrono::duration_cast(duration); SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "The calculation finished. It took {} microseconds.", ms.count()); SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), @@ -46,7 +55,7 @@ int main(int argc, char *argv[]) { if (!outputFileName.empty()) { SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Writing results to specified output file {}", outputFileName); - CSVWriter csvWriter{outputFileName}; + const CSVWriter csvWriter{outputFileName}; csvWriter.printResult(computationPoints, result); SPDLOG_LOGGER_INFO(PolyhedralGravityLogger::DEFAULT_LOGGER.getLogger(), "Writing finished!");