diff --git a/.gitignore b/.gitignore index 68aabcf42..39c50e7fa 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,9 @@ build2 build* cmake-build* +# pixi lock file +pixi.lock + # ide directory .idea .idea/workspace.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 44031a983..1de8b233d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,28 +6,34 @@ # Distributed under the Boost Software License, Version 1.0. (See accompanying # file LICENSE) -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.10...4.3) #----------------------------------# #<<<<<<<<<< Project name >>>>>>>>>># #----------------------------------# -project(PeriDEM LANGUAGES CXX C) +project(PeriDEM VERSION 0.2.1 LANGUAGES CXX C) set(CMAKE_PROJECT_HOMEPAGE_URL "https://github.com/prashjha/PeriDEM") set(CMAKE_PROJECT_DESCRIPTION "PeriDEM -- Peridynamics-based high-fidelity model for granular media") -# version -set(VERSION_MAJOR 0) -set(VERSION_MINOR 2) -set(VERSION_UPDATE 0) - #----------------------------------# #<<<<<<<<<< Project setting >>>>>>>>>># #----------------------------------# -# config files -configure_file("${PROJECT_SOURCE_DIR}/PeriDEMConfig.h.in" - "${PROJECT_SOURCE_DIR}/src/PeriDEMConfig.h") +# Configure header with version info +configure_file( + "${PROJECT_SOURCE_DIR}/PeriDEMConfig.h.in" + "${PROJECT_BINARY_DIR}/PeriDEMConfig.h" + @ONLY +) + +# Use version from project() for CMake package config +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/PeriDEMConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion +) # executable directory set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin") @@ -159,9 +165,9 @@ endif() if (${Enable_CMAKE_Debug_Build}) message(STATUS "Including key directories") endif() -include_directories(SYSTEM external) -include_directories(${MPI_INCLUDE_PATH}) -include_directories(src) +# include_directories(SYSTEM external) +# include_directories(${MPI_INCLUDE_PATH}) +# include_directories(src) #----------------------------------# #<<<<<<<<<< Subdirectories >>>>>>>>>># @@ -212,12 +218,52 @@ endif() #----------------------------------# add_executable(PeriDEM src/main.cpp) +target_include_directories(PeriDEM + PUBLIC + $ + $ + $ +) target_link_libraries(PeriDEM PUBLIC Model) +install(TARGETS PeriDEM Model Util RW Inp Material Loading Geometry FE Particle NSearch + EXPORT PeriDEMTargets + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib +) + +install(EXPORT PeriDEMTargets + FILE PeriDEMTargets.cmake + NAMESPACE PeriDEM:: + DESTINATION lib/cmake/PeriDEM +) + + #----------------------------------# #<<<<<<<<<< PeriDEM install >>>>>>>>>># #----------------------------------# -install(TARGETS PeriDEM DESTINATION bin) +install(FILES ${PROJECT_BINARY_DIR}/PeriDEMConfig.h DESTINATION include) +install(DIRECTORY src/ DESTINATION include FILES_MATCHING PATTERN "*.h") +install(FILES external/csv/csv.h DESTINATION include/csv) +install(DIRECTORY external/nanoflann/ DESTINATION include/nanoflann FILES_MATCHING PATTERN "*.hpp") +install(DIRECTORY external/taskflow/taskflow/ DESTINATION include/taskflow) +install(DIRECTORY external/fmt/include/ DESTINATION include) + +configure_package_config_file( + cmake/PeriDEMConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/PeriDEMConfig.cmake + INSTALL_DESTINATION lib/cmake/PeriDEM +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/PeriDEMConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/PeriDEMConfigVersion.cmake + ${PROJECT_SOURCE_DIR}/cmake/FindMetis.cmake + DESTINATION lib/cmake/PeriDEM +) + + #----------------------------------# #<<<<<<<<<< Post build operations >>>>>>>>>># diff --git a/PeriDEMConfig.h.in b/PeriDEMConfig.h.in index 507a0b425..ba896ffc0 100644 --- a/PeriDEMConfig.h.in +++ b/PeriDEMConfig.h.in @@ -13,8 +13,12 @@ #include -size_t const MAJOR_VERSION = @VERSION_MAJOR@; -size_t const MINOR_VERSION = @VERSION_MINOR@; -size_t const UPDATE_VERSION = @VERSION_UPDATE@; +#define PERIDEM_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define PERIDEM_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define PERIDEM_VERSION_PATCH @PROJECT_VERSION_PATCH@ + +const size_t MAJOR_VERSION = PERIDEM_VERSION_MAJOR; +const size_t MINOR_VERSION = PERIDEM_VERSION_MINOR; +const size_t UPDATE_VERSION = PERIDEM_VERSION_PATCH; #endif \ No newline at end of file diff --git a/README.md b/README.md index 17391b1ef..198cb455e 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ * [Dependencies](#Dependencies) * [Building the code](#Building-the-code) * [Recommendations for quick build](#Recommendations-for-quick-build) + * [Install & use as a CMake package](#install--use-as-a-cmake-package) - [Running simulations](#Running-simulations) * [Two-particle with wall](#Two-particle-with-wall) * [Compressive test](#Compressive-test) @@ -25,6 +26,7 @@ - [Developers](#Developers) ## Introduction + Implementation of the high-fidelity model of granular media that combines the advantages of peridynamics and discrete element method (DEM). The model has the following advantages over existing mechanical models for granular media: @@ -48,14 +50,17 @@ We have created channels on various platforms: * Email us if interested in joining the workspace. ## Documentation + [Doxygen generated documentation](https://prashjha.github.io/PeriDEM/) details functions and objects in the library. ## Tutorial + We explain the setting-up of simulations in further details in [tutorial](./tutorial/README.md). We consider `two-particle` test setup with non-circular particles and `compressive-test` to discuss the various aspects of simulations. ## Examples + We next highlight some key examples. Further details are available in [examples/README.md](./examples/README.md). ### Two-particle tests @@ -75,6 +80,7 @@ We next highlight some key examples. Further details are available in [examples/ | Concave particles | ### Compressive tests + Setup for this test consists of 502 circular and hexagonal-shaped particles of varying radius and orientation inside a rectangle container. The container's top wall is moving downward at a prescribed speed, resulting in the compression of the particle system. @@ -91,6 +97,7 @@ yielding of the system. For more details, we refer to ### Attrition tests + We consider mix of different particles in a rotating container. Particles considered include circular, triangular, hexagonal, and drum shaped. Particles come in large and small shapes (their sizes are purturbed randomly). In order to to introduce diversity of material properties, we considered large particles to be tougher compared to the smaller ones. Setup files are in [examples/PeriDEM/attrition_tests](./examples/PeriDEM/attrition_tests) | | | @@ -102,14 +109,17 @@ Complex container geometries can be considered as well. For example, the image b ### Single particle deformation + We can use `PeriDEM` executable or `Peridynamics` executable in `apps` directory to simulate the deformation of single particle/structure using peridynamics. See [examples/README.md](./examples/README.md) and [examples/Peridynamics](./examples/Peridynamics) folder. ## Brief implementation details + The main implementation of the model is carried out in the model directory [dem](./src/model/dem). The model is implemented in class [DEMModel](./src/model/dem/demModel.cpp). Function `DEMModel::run()` performs the simulation. We next look at some key methods in `DEMModel` in more details: ### DEMModel::run() + This function does three tasks: ```cpp void model::DEMModel::run(inp::Input *deck) { @@ -129,6 +139,7 @@ In `DEMModel::init()`, the simulation is prepared by reading the input files (such as `.yaml`, `.msh`, `particle_locations.csv` files). ### DEMModel::integrate() + Key steps in `DEMModel::integrate()` are ```cpp void model::DEMModel::run(inp::Input *deck) { @@ -197,6 +208,7 @@ void model::DEMModel::integrateVerlet() { ``` ### DEMModel::computeForces() + The key method in time integration is `DEMModel::computeForces()` In this function, we compute internal and external forces at each node of a particle and also account for the external boundary conditions. This function looks like @@ -220,13 +232,19 @@ void model::DEMModel::computeForces() { ``` ### Further reading + Above gives the basic idea of simulation steps. For more thorough understanding of the implementation, interested readers can look at [demModel.cpp](./src/model/dem/demModel.cpp). ## Installation +The [pixi.toml](pixi.toml) file defines the dependencies and build instructions for the library. It should be used to create a reproducible environment and build the code using Pixi and CMake. + +To install the Pixi package manager, follow the instructions at the official [installation page](https://pixi.sh/dev/installation/#update). + ### Dependencies + Core dependencies are: - [cmake](https://cmake.org/) (>= 3.10.2) - [vtk](https://vtk.org/) (>= 7.1.1) @@ -242,6 +260,7 @@ Following dependencies are included in the `PeriDEM` library in `external` folde - [doxygen-awesome-css](https://github.com/jothepro/doxygen-awesome-css) (>= v2.3.3) ### Building the code + If all the dependencies are installed on the global path (e.g., `/usr/local/`), commands for building the PeriDEM code is as simple as ```sh @@ -261,14 +280,63 @@ make -j 4 directory. You can create the `build` directory either inside or outside the repository. -> :exclamation: As of now, we can only build the library and not install it. - This means you will have to build the package in the `build` directory, and - use the `build/bin/PeriDEM` executable. We plan to provide the method to `install` - the library in the future. - -We refer to [tools/README.md](./tools/README.md) for further details about installing dependencies and building the library in different ubuntu releases. +### Install & use as a CMake package +- Build and install (starting from a fresh clone, e.g., `git clone ... && cd PeriDEM`; create a build dir wherever you like—`build` inside the source is assumed below): + ```sh + # from the source root + mkdir -p build + cmake -S . -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build -- -j$(sysctl -n hw.ncpu) + + # install library in /tmp/peridem-install + cmake --install build --prefix /tmp/peridem-install + ``` + This installs `bin/PeriDEM`, shared libs in `lib/`, headers in `include/`, and the CMake package files under `lib/cmake/PeriDEM`. +- Consume in another CMake project: + ```cmake + cmake_minimum_required(VERSION 3.18) + project(peridem_consumer LANGUAGES CXX) + find_package(PeriDEM REQUIRED) + add_executable(hello main.cpp) + target_link_libraries(hello PRIVATE PeriDEM::Model) # or another PeriDEM library target + ``` + Place this in, e.g., `/tmp/peridem-consumer/CMakeLists.txt`. A minimal `main.cpp` in the same folder: + ```cpp + #include + #include + int main() { + std::cout << "PeriDEM version: " + << PERIDEM_VERSION_MAJOR << "." + << PERIDEM_VERSION_MINOR << "." + << PERIDEM_VERSION_PATCH << "\n"; + } + ``` + Configure and build the consumer (run these inside `/tmp/peridem-consumer`): + ```sh + cmake -S . -B build -DCMAKE_PREFIX_PATH=/tmp/peridem-install + cmake --build build -- -j$(sysctl -n hw.ncpu) + ./build/hello + ``` +- External dependencies required on the target system: MPI, Threads, yaml-cpp, VTK (CommonCore/DataModel/IOXML), BLAS/LAPACK (Accelerate on macOS), Metis (found via bundled `FindMetis.cmake`), plus their transitive libraries. Ensure these are installed and discoverable (e.g., via `CMAKE_PREFIX_PATH` or system paths) when configuring consumers. + +### Using docker to test the library +```sh +# run ubuntu using docker (we are using the same image we use to test the library) +docker run -it prashjha/peridem-base-noble + +# we install pixi and add it to the path +curl -fsSL https://pixi.sh/install.sh | sh +export PATH="/root/.pixi/bin:$PATH" + +# assuming we are now in root of docker image +cd user/ +git clone git@github.com:prashjha/PeriDEM.git +cd PeriDEM/ +pixi run build +``` ### Future plans + We are trying to make PeriDEM MPI-friendly so that we can target large problems. We are moving in following key directions: - MPI parallelism for Peridynamics simulations (deformation of single body subjected to external loading) @@ -285,6 +353,7 @@ If any of the above future directions interest you or if you have new directions in mind, please do reach out to us. ### Ask for help + In the past, `PeriDEM` library depended on large libraries such as `HPX`, `PCL`, `Boost` (explicitly dependence). We have put a lot of efforts into reducing the dependencies to absolutely minimum so that it is easier to build and run `PeriDEM` in different operating systems and clusters. @@ -301,6 +370,7 @@ If you like some help, want to contribute, extend the code, or discuss new ideas please do reach out to us. ## Running simulations + Assuming that the input file is `input.yaml` and all other files such as `.msh` file for particle/wall and particle locations file are created and their filenames with paths are correctly provided in `input.yaml`, we will run the problem (using 4 threads) @@ -311,6 +381,7 @@ with paths are correctly provided in `input.yaml`, we will run the problem (usin Some examples are listed below. ### Two-particle with wall + Navigate to the example directory [examples/PeriDEM/two_particles/twop_wall_concave_diff_material_diff_size/inp](.examples/PeriDEM/two_particles/twop_wall_concave_diff_material_diff_size/inp) and run the example as follows ```sh @@ -334,6 +405,7 @@ to modify simulation parameters and run the simulation using > Here we set all model parameters, create `.yaml` input file, and `.geo` files for meshing. ### Compressive test + Navigate to the example directory [examples/PeriDEM/compressive_test/compression_large_set/inp](./examples/PeriDEM/compressive_test/compression_large_set/inp) and run the example as follows (note that this is a computationally expensive example) ```sh @@ -349,6 +421,7 @@ As before: - run the simulation using [run.sh](./examples/PeriDEM/compressive_test/compression_large_set//run.sh). ## Visualizing results + Simulation files `output_*.vtu` can be loaded in either [ParaView](https://www.paraview.org/) or [VisIt](https://wci.llnl.gov/simulation/computer-codes/visit). @@ -371,12 +444,14 @@ type from **`Surface`** to **`Point Gaussian`**. Next, a couple of things to do regions with elastic deformation and region with fracture. ## Contributing + We welcome contributions to the code. In `Future plans` section above, some potential directions are listed. Please fork this repository, make changes, and make a pull request to the source branch. ## Citations + If this library was useful in your work, we recommend citing the following article: > Jha, P.K., Desai, P.S., Bhattacharya, D. and Lipton, R., 2021. @@ -388,5 +463,6 @@ You can also cite the PeriDEM using zenodo doi: > Prashant K., J. (2024). Peridynamics-based discrete element method (PeriDEM) model of granular systems. Zenodo. https://doi.org/10.5281/zenodo.13888588 ## Developers + - [Prashant K. Jha](https://prashjha.github.io/) (pjha.sci@gmail.com, prashant.jha@sdsmt.edu) diff --git a/cmake/FindMetis.cmake b/cmake/FindMetis.cmake index 548176ad9..aca3c834e 100644 --- a/cmake/FindMetis.cmake +++ b/cmake/FindMetis.cmake @@ -18,13 +18,21 @@ find_path(METIS_INCLUDE metis.h mark_as_advanced(METIS_LIB) mark_as_advanced(METIS_INCLUDE) -if (NOT METIS_LIB) - message(FATAL_ERROR "Metis Library not found. Specify the Metis library location using METIS_DIR.") -else () - include_directories(${METIS_INCLUDE}) +if (METIS_LIB AND METIS_INCLUDE) + set(Metis_FOUND TRUE) + set(METIS_LIBRARIES ${METIS_LIB}) + set(METIS_INCLUDE_DIRS ${METIS_INCLUDE}) if (${Enable_CMAKE_Debug_Build}) message(STATUS "Found Metis library") message(STATUS "METIS_INCLUDE = ${METIS_INCLUDE}") message(STATUS "METIS_LIB = ${METIS_LIB}") endif () +else () + set(Metis_FOUND FALSE) + if (NOT METIS_FIND_QUIETLY) + message(STATUS "Metis Library not found. Specify METIS_DIR or add to CMAKE_PREFIX_PATH.") + endif () + if (METIS_FIND_REQUIRED) + message(FATAL_ERROR "Metis Library not found. Specify the Metis library location using METIS_DIR.") + endif () endif () diff --git a/cmake/PeriDEMConfig.cmake.in b/cmake/PeriDEMConfig.cmake.in new file mode 100644 index 000000000..d5c35598a --- /dev/null +++ b/cmake/PeriDEMConfig.cmake.in @@ -0,0 +1,25 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +find_dependency(MPI REQUIRED) +find_dependency(Threads REQUIRED) +find_dependency(yaml-cpp CONFIG REQUIRED) +find_dependency(VTK COMPONENTS CommonCore CommonDataModel IOXML) +find_dependency(BLAS REQUIRED) +find_dependency(LAPACK REQUIRED) +find_dependency(Metis REQUIRED) +# Provide fmt interface targets using the installed headers (or reuse an existing fmt if already present). +if(NOT TARGET fmt::fmt-header-only) + add_library(fmt::fmt-header-only INTERFACE IMPORTED) + get_filename_component(_peridem_prefix "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) + set_target_properties(fmt::fmt-header-only PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_peridem_prefix}/include" + ) +endif() +if(NOT TARGET fmt::fmt) + add_library(fmt::fmt INTERFACE IMPORTED) + target_link_libraries(fmt::fmt INTERFACE fmt::fmt-header-only) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/PeriDEMTargets.cmake") diff --git a/pixi.toml b/pixi.toml new file mode 100644 index 000000000..ed18292eb --- /dev/null +++ b/pixi.toml @@ -0,0 +1,35 @@ +[workspace] +channels = ["conda-forge"] +name = "PeriDEM" +platforms = ["linux-64", "osx-arm64"] +version = "v0.2.1" + +# Currently can't install, only build? +# c.f. https://github.com/prashjha/PeriDEM/blob/8f73cbd12fbf8d483bb46670661f9f2641d03c37/README.md?plain=1#L264 +[tasks.build] +cmd = """ +rm -rf build && \ +cmake -DEnable_Documentation=OFF \ + -DEnable_Tests=ON \ + -DEnable_High_Load_Tests=OFF \ + -DDisable_Docker_MPI_Tests=ON \ + -DVTK_DIR="$CONDA_PREFIX" \ + -DMETIS_DIR="$CONDA_PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" \ + -S . \ + -B build && \ +cmake build -LH && \ +cmake --build build --clean-first --parallel "$(nproc --ignore=2)" && \ +ctest --verbose --test-dir build/ +""" + +[dependencies] +cxx-compiler = ">=1.11.0,<2" +cmake = "<4" +make = ">=4.4.1,<5" +vtk = ">=9.5.2,<10" +yaml-cpp = ">=0.8.0,<0.9" +metis = ">=5.2.1,<6" +openmpi = ">=5.0.8,<6" +gmsh = ">=4.13.1,<5" # for tests \ No newline at end of file diff --git a/src/PeriDEMConfig.h b/src/PeriDEMConfig.h index 39b18982d..0d968bf65 100644 --- a/src/PeriDEMConfig.h +++ b/src/PeriDEMConfig.h @@ -13,8 +13,12 @@ #include -size_t const MAJOR_VERSION = 0; -size_t const MINOR_VERSION = 2; -size_t const UPDATE_VERSION = 0; +#define PERIDEM_VERSION_MAJOR 0 +#define PERIDEM_VERSION_MINOR 2 +#define PERIDEM_VERSION_PATCH 1 + +const size_t MAJOR_VERSION = PERIDEM_VERSION_MAJOR; +const size_t MINOR_VERSION = PERIDEM_VERSION_MINOR; +const size_t UPDATE_VERSION = PERIDEM_VERSION_PATCH; #endif diff --git a/src/fe/CMakeLists.txt b/src/fe/CMakeLists.txt index 40fbdabe7..da8c3b172 100644 --- a/src/fe/CMakeLists.txt +++ b/src/fe/CMakeLists.txt @@ -11,4 +11,12 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(FE ${SOURCES} elemIncludes.h) -target_link_libraries(FE PUBLIC Util RW ${METIS_LIB}) \ No newline at end of file +target_link_libraries(FE PUBLIC Util RW ${METIS_LIB}) + +target_include_directories(FE + PUBLIC + $ + $ + $ + $ +) diff --git a/src/geometry/CMakeLists.txt b/src/geometry/CMakeLists.txt index 864960cf6..3e4e1b94d 100644 --- a/src/geometry/CMakeLists.txt +++ b/src/geometry/CMakeLists.txt @@ -10,4 +10,12 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(Geometry ${SOURCES}) -target_link_libraries(Geometry PUBLIC Util NSearch fmt::fmt Threads::Threads) +target_link_libraries(Geometry PUBLIC Util NSearch fmt::fmt-header-only Threads::Threads) + +target_include_directories(Geometry + PUBLIC + $ + $ + $ + $ +) diff --git a/src/inp/CMakeLists.txt b/src/inp/CMakeLists.txt index f79b433b9..a7ea86397 100644 --- a/src/inp/CMakeLists.txt +++ b/src/inp/CMakeLists.txt @@ -17,4 +17,11 @@ AUX_SOURCE_DIRECTORY(./pdecks SOURCES) add_library(Inp ${SOURCES}) -target_link_libraries(Inp PUBLIC Util ${YAML_CPP_LIB}) \ No newline at end of file +target_link_libraries(Inp PUBLIC Util ${YAML_CPP_LIB}) + +target_include_directories(Inp + PUBLIC + $ + $ + $ +) \ No newline at end of file diff --git a/src/loading/CMakeLists.txt b/src/loading/CMakeLists.txt index 4b5f6e40f..de9ed8f44 100644 --- a/src/loading/CMakeLists.txt +++ b/src/loading/CMakeLists.txt @@ -10,4 +10,12 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(Loading ${SOURCES}) -target_link_libraries(Loading PUBLIC Util Threads::Threads) \ No newline at end of file +target_link_libraries(Loading PUBLIC Util Threads::Threads) + +target_include_directories(Loading + PUBLIC + $ + $ + $ + $ +) diff --git a/src/material/CMakeLists.txt b/src/material/CMakeLists.txt index a6750a113..8690f79ed 100644 --- a/src/material/CMakeLists.txt +++ b/src/material/CMakeLists.txt @@ -12,3 +12,11 @@ AUX_SOURCE_DIRECTORY(./mparticle SOURCES) add_library(Material ${SOURCES}) target_link_libraries(Material PUBLIC Geometry Threads::Threads) + +target_include_directories(Material + PUBLIC + $ + $ + $ + $ +) diff --git a/src/model/CMakeLists.txt b/src/model/CMakeLists.txt index 8e7ab596d..0df936eda 100644 --- a/src/model/CMakeLists.txt +++ b/src/model/CMakeLists.txt @@ -14,3 +14,12 @@ add_library(Model ${SOURCES}) target_include_directories(Model PUBLIC ${VTK_INCLUDE_DIRS}) target_link_libraries(Model PUBLIC Util RW Inp Material Loading Geometry FE Particle NSearch) + +target_include_directories(Model + PUBLIC + $ + $ + $ + $ + $ +) diff --git a/src/nsearch/CMakeLists.txt b/src/nsearch/CMakeLists.txt index e97085258..11df284d2 100644 --- a/src/nsearch/CMakeLists.txt +++ b/src/nsearch/CMakeLists.txt @@ -14,3 +14,11 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(NSearch ${SOURCES}) # target_link_libraries(NSearch PUBLIC nanoflann::nanoflann) + +target_include_directories(NSearch + PUBLIC + $ + $ + $ + $ +) diff --git a/src/particle/CMakeLists.txt b/src/particle/CMakeLists.txt index dfb5b8db1..c9498e6d7 100644 --- a/src/particle/CMakeLists.txt +++ b/src/particle/CMakeLists.txt @@ -11,3 +11,10 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(Particle ${SOURCES}) target_link_libraries(Particle PUBLIC FE Material Geometry) + +target_include_directories(Particle + PUBLIC + $ + $ + $ +) \ No newline at end of file diff --git a/src/rw/CMakeLists.txt b/src/rw/CMakeLists.txt index ef0d694b1..e3d4f2947 100644 --- a/src/rw/CMakeLists.txt +++ b/src/rw/CMakeLists.txt @@ -10,4 +10,12 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(RW ${SOURCES}) -target_link_libraries(RW PUBLIC ${VTK_LIBRARIES}) \ No newline at end of file +target_link_libraries(RW PUBLIC Util ${VTK_LIBRARIES}) + +target_include_directories(RW + PUBLIC + $ + $ + $ + $ +) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index 756e63345..d958a80f6 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -10,4 +10,11 @@ AUX_SOURCE_DIRECTORY(./ SOURCES) add_library(Util ${SOURCES}) -target_link_libraries(Util PUBLIC ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} fmt::fmt-header-only Threads::Threads MPI::MPI_CXX) \ No newline at end of file +target_link_libraries(Util PUBLIC ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} fmt::fmt-header-only Threads::Threads MPI::MPI_CXX) + +target_include_directories(Util + PUBLIC + $ + $ + $ +) diff --git a/tools/README.md b/tools/README.md index 6a7a86223..3853efa9b 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,204 +1,4 @@ -# PeriDEM: Installation +# PeriDEM: Tools -## Dependencies -Core dependencies are: - - [cmake](https://cmake.org/) (>= 3.10.2) - * recommend to install using `apt-get` or `brew` - - [vtk](https://vtk.org/) (>= 7.1.1) - * recommend to build using script [install_vtk_alone.sh](./compile_scripts/ubuntu/install_vtk_alone.sh) or [install_cmake_and_vtk.sh](./compile_scripts/ubuntu/install_cmake_and_vtk.sh) - * required to output simulation results in `.vtu` format - - [yaml-cpp](https://github.com/jbeder/yaml-cpp) (>= 0.5.2) - * recommend to install using `apt-get` or `brew` - * required to parse input file - - [metis](https://github.com/KarypisLab/METIS) (>= 5.1.0) - * recommend to install using `apt-get` or `brew`. If using `apt-get`, recommend - to create symlink to `libmetis.so` file in `/usr/lib/` directory; - see towards end in script [install_apt-get_libs.sh](./compile_scripts/ubuntu/install_apt-get_libs.sh). - This helps `cmake` locate metis library. - * required to partition the mesh - - MPI - * for parallel simulations - - [libflann-dev](https://www.cs.ubc.ca/research/flann/) (1.9) - * recommend to install using `apt-get` or `brew` - * needed by `nanoflann` library +`tools` directory contains scripts for building library on ubuntu or mac, some details about using docker, and python utility functions. The files in this folder are outdated. For installation, we refer to `pixi.toml` file in base directory. -Following dependencies are included in the `PeriDEM` library in `external` folder (see [PeriDEM/external/README.md](../external/README.md) for more details): - - [fast-cpp-csv-parser](https://github.com/ben-strasser/fast-cpp-csv-parser/tree/master) (version included - master) - * required to read `.csv` files - - [fmt](https://github.com/fmtlib/fmt) (>= 7.1.3, version included - 10.2.1) - * included as external library in the code - * required to output formatted strings - - [nanoflann](https://github.com/jlblancoc/nanoflann) (>= 1.3.2, version included - v1.5.5) - * included as external library in the code - * required for neighbor search - - [taskflow](https://github.com/taskflow/taskflow) (>= 3.7.0) - * included as external library in the code - * required for asynchronous/parallel for loop - - [doxygen-awesome-css](https://github.com/jothepro/doxygen-awesome-css) (>= v2.3.3) - * included as external library in the code - * useful in building better doxygen documentation (see [docs/input-conf.doxy.in](./docs/input-conf.doxy.in) file) - -Additional dependencies for running the examples: - - [gmsh](https://gmsh.info/) (>= 3.0.6) - * recommend to install using `apt-get` or `brew` - * required to build the mesh of various objects in the test - - [python3](https://www.python.org/) - * required to run the test python scripts - - [numpy](https://numpy.org/) - * required to run the test python scripts - -### Building the code -If all the dependencies are installed on the global path (e.g., `/usr/local/`), -commands for building the PeriDEM code is as simple as -```sh -cmake -DEnable_Documentation=OFF - -DEnable_Tests=ON \ - -DEnable_High_Load_Tests=OFF \ - -DDisable_Docker_MPI_Tests=ON \ - -DVTK_DIR="${VTK_DIR}" \ - -DMETIS_DIR="${METIS_DIR}" \ - -DCMAKE_BUILD_TYPE=Release \ - - -make -j 4 - -ctest --verbose -``` - -## Installing dependencies - -> :exclamation: There are some libraries (e.g., tbb) below that are required by our dependencies. - -### Mac -Brew can be used to install all dependencies in mac as follows -```shell -brew install cmake libomp open-mpi tbb \ - yaml-cpp flann gmsh metis vtk -``` -### Ubuntu -1. Essential libraries can be installed using `apt-get` as follows - ```shell - sudo apt-get update - sudo apt-get install -y \ - libopenmpi-dev openmpi-bin \ - libblas-dev liblapack-dev libmpfr-dev libgmp-dev \ - libtbb-dev libasio-dev libglvnd-dev \ - libgmsh-dev gmsh \ - libflann-dev \ - libmetis-dev \ - libyaml-cpp-dev \ - python3-pip - - # for metis, create symlink - sudo ln -sf /usr/lib/x86_64-linux-gnu/libmetis.so /usr/lib/libmetis.so - - # python libs - # NOTE: add '--break-system-packages' at the end if installing in Ubuntu 24.04 (noble) - pip3 install numpy pyvista pandas - ``` -2. For `cmake`, if you are in ubuntu >= 20.04, install using `apt-get` - ```shell - sudo apt-get update \ - sudo apt-get install -y cmake - ``` - If you are in ubuntu < 20.04 (e.g., 18.04 bionic), install by adding new ppa to apt-get as follows - ```shell - # get codename of ubuntu - UBUNTU_CODENAME="$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2)" - # add repo - wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null - sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ ${UBUNTU_CODENAME} main" - echo "fixing public key issue with kitware repo" - if [ "${UBUNTU_CODENAME}" = "bionic" ]; then - gpg --keyserver keyserver.ubuntu.com --recv-keys 6AF7F09730B3F0A4 - gpg --export --armor 6AF7F09730B3F0A4 | sudo apt-key add - - elif [ "${UBUNTU_CODENAME}" = "focal" ]; then - gpg --keyserver keyserver.ubuntu.com --recv-keys 1A127079A92F09ED - gpg --export --armor 1A127079A92F09ED | sudo apt-key add - - else - echo "no fix for UBUNTU_CODENAME = ${UBUNTU_CODENAME} if there is a key error. try building cmake from repository" - fi - - # now you can install recent cmake from apt-get - sudo apt-get update - sudo apt-get install -y cmake - ``` -3. For vtk, if you are in ubuntu >= 22.04, install using `apt-get` as follows: - ```shell - sudo apt-get install -y libvtk9-dev - ``` - If you are in ubuntu < 22.04 (e.g., 18.04 bionic, 20.04 focal), build vtk and install as follows -```shell -# get codename of ubuntu -UBUNTU_CODENAME="$(cat /etc/os-release | grep UBUNTU_CODENAME | cut -d = -f 2)" - -# instal dependency first -if [ "${UBUNTU_CODENAME}" = "focal" ] || [ "${UBUNTU_CODENAME}" = "bionic" ]; then - sudo apt-get install -y libgl1-mesa-dev -fi - -# set some paths where we will download vtk and build -SCRIPTPATH=$( cd $(dirname $0) ; pwd -P ) -BUILDTHREADS="$(cat /proc/cpuinfo | grep processor | wc -l)" # or 12 - -install_at_global="0" # 0 - install in script path, 1 in /usr/local -VTK_INSTALL_PATH="/usr/local" -if [ $install_at_global = "0" ]; then - VTK_INSTALL_PATH=$SCRIPTPATH/install/vtk/$VTK_VERSION/Release -fi -echo "VTK_INSTALL_PATH = ${VTK_INSTALL_PATH}" - -# clone vtk -VTK_MAJOR_VERSION=9 -VTK_MINOR_VERSION=3 -VTK_PATCH_VERSION=0 -VTK_VERSION=$VTK_MAJOR_VERSION.$VTK_MINOR_VERSION.$VTK_PATCH_VERSION -echo "VTK_VERSION = ${VTK_VERSION}" - -git clone --recursive https://gitlab.kitware.com/vtk/vtk.git vtk-source-${VTK_VERSION} -cd vtk-${VTK_VERSION} -git checkout v${VTK_VERSION} - -cd .. && mkdir -p vtk-build-${VTK_VERSION} && cd vtk-build-${VTK_VERSION} -cmake -D CMAKE_BUILD_TYPE:STRING=Release \ - -D CMAKE_INSTALL_PREFIX:STRING=${VTK_INSTALL_PATH} \ - -D BUILD_SHARED_LIBS=ON \ - -D BUILD_TESTING=OFF \ - -D VTK_REQUIRED_OBJCXX_FLAGS='' \ - -D HDF5_BUILD_FRAMEWORKS=OFF \ - -D VTK_BUILD_DOCUMENTATION=OFF \ - -D VTK_BUILD_EXAMPLES=OFF \ - -D VTK_BUILD_SCALED_SOA_ARRAYS=OFF \ - -D VTK_BUILD_SPHINX_DOCUMENTATION=OFF \ - -D VTK_GROUP_ENABLE_MPI=NO \ - -D VTK_GROUP_ENABLE_Qt=DONT_WANT \ - -D VTK_GROUP_ENABLE_Rendering=NO \ - -D VTK_GROUP_ENABLE_Views=NO \ - -D VTK_GROUP_ENABLE_Web=NO \ - -D VTK_Group_MPI=ON \ - -D VTK_USE_MPI=OFF \ - -D VTK_WRAP_PYTHON=OFF \ - ../vtk-source-${VTK_VERSION} -make -j -l$BUILDTHREADS -# installation -if [[ "$install_at_global" = "1" ]]; then - sudo make install -else - make install -fi -echo VTK_LIB_CMAKE_DIR="${VTK_INSTALL_PATH}/lib/cmake/vtk-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" -echo VTK_LIB_DIR="${VTK_INSTALL_PATH}/lib" -echo VTK_INCLUDE_DIR="${VTK_INSTALL_PATH}/include/vtk-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}" -``` - -### Compile scripts -In directory [PeriDEM/tools/compile_scripts](./compile_scripts) various scripts are -included to help install dependencies and compile PeriDEM code. -If you follow this documentation, you probably would not need to look at -those scripts as the dependencies in this library is kept quite small and can -be easily installed using either `apt-get` or `brew`. - -### Docker -For `circle-ci` testing, we use docker images `prashjha/peridem-base-jammy:latest` -(`ubuntu 22.04`) and `prashjha/peridem-base-noble:latest` (`ubuntu 24.04`). -The associated dockerfiles and scripts to use pre-built docker images in compiling code and using for clion remote development can be found in [PeriDEM/tools/docker/README.md](./docker/README.md). diff --git a/tools/compile_scripts/test_peridem_install.sh b/tools/compile_scripts/test_peridem_install.sh new file mode 100755 index 000000000..0636e85e0 --- /dev/null +++ b/tools/compile_scripts/test_peridem_install.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Paths +SRC=/Users/prashant/Dropbox/Work/Simulations/peridem_works/PeriDEM_mac +BUILD="$SRC/build" +PREFIX=/tmp/peridem-install +CONSUMER=/tmp/peridem-consumer +CONSUMER_BUILD="$CONSUMER/build" + +echo "=== Paths ===" +echo "SRC=$SRC" +echo "BUILD=$BUILD" +echo "PREFIX=$PREFIX" +echo "CONSUMER=$CONSUMER" +echo "CONSUMER_BUILD=$CONSUMER_BUILD" + +# 1) remove PeriDEM build +echo "==> rm -rf \"$BUILD\"" +rm -rf "$BUILD" + +# 2) configure & build PeriDEM +echo "==> cmake -S \"$SRC\" -B \"$BUILD\"" +cmake -S "$SRC" -B "$BUILD" +echo "==> cmake --build \"$BUILD\"" +cmake --build "$BUILD" -- -j$(sysctl -n hw.ncpu) + +# 3) install PeriDEM +echo "==> cmake --install \"$BUILD\" --prefix \"$PREFIX\"" +cmake --install "$BUILD" --prefix "$PREFIX" + +# 4) remove consumer build +echo "==> rm -rf \"$CONSUMER_BUILD\"" +rm -rf "$CONSUMER_BUILD" + +# 5) build consumer +echo "==> cmake -S \"$CONSUMER\" -B \"$CONSUMER_BUILD\" -DCMAKE_PREFIX_PATH=\"$PREFIX\"" +cmake -S "$CONSUMER" -B "$CONSUMER_BUILD" -DCMAKE_PREFIX_PATH="$PREFIX" +echo "==> cmake --build \"$CONSUMER_BUILD\"" +cmake --build "$CONSUMER_BUILD" -- -j$(sysctl -n hw.ncpu) + +# 6) run consumer executable +echo "==> \"$CONSUMER_BUILD/hello\"" +"$CONSUMER_BUILD/hello"