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 787a3dd..4c24e15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,9 @@ 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(CMakeDependentOption) ##################################### @@ -15,52 +18,59 @@ 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_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) # 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++") 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) + +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 ####################################################### -# 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) @@ -76,6 +86,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/README.md b/README.md index 194bd1a..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_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 new file mode 100644 index 0000000..d74ba2f --- /dev/null +++ b/cmake/git.cmake @@ -0,0 +1,46 @@ +find_package(Git QUIET REQUIRED) + +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 --short=8 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 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/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}) 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 diff --git a/docs/quickstart/installation.rst b/docs/quickstart/installation.rst index f529a47..43339a2 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 +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 +====================================================== ============================================================================================================ Dependencies (automatically set-up) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/setup.py b/setup.py index 26cd85f..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) @@ -53,6 +53,27 @@ def get_cmake_generator(): else: return None +def get_version(): + """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 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(cmake_file, "r") as file: + content = file.read() + + # 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 CMakeLists.txt") + + # ----------------------------------------------------------------------------------------- # 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/main.cpp b/src/main.cpp index 4692e2c..d8523d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,20 @@ -#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/output/Logging.h" +#include int main(int argc, char *argv[]) { using namespace polyhedralGravity; + + 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! " "Please use the program like this:\n" @@ -15,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(), @@ -39,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!"); diff --git a/src/polyhedralGravity/CMakeLists.txt b/src/polyhedralGravity/CMakeLists.txt index efd3fb1..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}) +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..4180d52 --- /dev/null +++ b/src/polyhedralGravity/Info.h.in @@ -0,0 +1,37 @@ +#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'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'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 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 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@"; + +}// namespace polyhedralGravity 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/src/polyhedralGravityPython/PolyhedralGravityPython.cpp b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp index e6f4d79..abaf3bb 100644 --- a/src/polyhedralGravityPython/PolyhedralGravityPython.cpp +++ b/src/polyhedralGravityPython/PolyhedralGravityPython.cpp @@ -6,10 +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/model/GravityModel.h" +#include "polyhedralGravity/model/GravityModelData.h" +#include "polyhedralGravity/model/Polyhedron.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 @@ -104,6 +103,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. *Tsoulis et al.* equations require the normals to point outwards of the polyhedron. 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" 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