From ca38d47c0dfc7d72c51cab4393b1d99ba6b5f669 Mon Sep 17 00:00:00 2001 From: rprat-pro Date: Mon, 1 Apr 2024 19:30:33 +0200 Subject: [PATCH 1/2] add EXADEM_MAX_VERTICES variable --- CMakeLists.txt | 12 +++++++++++- include/exanb/fields.h | 2 +- src/polyhedra/include/exaDEM/compute_vertices.hpp | 2 +- src/polyhedra/include/exaDEM/network.hpp | 2 +- .../include/exaDEM/shape/shape_detection.hpp | 2 +- .../include/exaDEM/shape/shape_detection_driver.hpp | 2 +- src/polyhedra/update_grid_interaction.cpp | 2 +- 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6aad21c..c8332fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,16 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +# ============================================== +# === Set Some default values for polyhedra ==== +# ============================================== +# These values have to be set by exaNBody +set(EXADEM_MAX_VERTICES "8" CACHE STRING "Maximum number of vertices per polyhedron") +message(STATUS "Maximum number of vertices per polyhedron: ${EXADEM_MAX_VERTICES}") +add_compile_options(-DEXADEM_MAX_VERTICES=${EXADEM_MAX_VERTICES}) +#set(USTAMP_COMPILE_DEFINITIONS ${USTAMP_COMPILE_DEFINITIONS} "EXADEM_MAX_VERTICES=${EXADEM_MAX_VERTICES}") +message(STATUS ${USTAMP_COMPILE_DEFINITIONS}) + # ====================================== # === exaNBody application framework === # ====================================== @@ -87,12 +97,12 @@ endif() # ======================================= exaNBodyStartApplication() + # ========================================== # === build application plugins and libs === # ========================================== add_subdirectory(src) - # ============================= # === check exaDEM examples === # ============================= diff --git a/include/exanb/fields.h b/include/exanb/fields.h index 29fde1a..e43c7b7 100644 --- a/include/exanb/fields.h +++ b/include/exanb/fields.h @@ -32,7 +32,7 @@ XSTAMP_DECLARE_FIELD(::exanb::Vec3d , vrot ,"angular velocity"); // XSTAMP_DECLARE_FIELD(::exanb::Vec3d , arot ,"angular acceleration"); // XSTAMP_DECLARE_FIELD(::exanb::Vec3d , inertia ,"inertia values (same value in the diagonal)"); XSTAMP_DECLARE_FIELD(::exanb::Vec3d , friction ,"tmp field"); // -typedef ::onika::oarray_t<::exanb::Vec3d, 8> VerticesType; +typedef ::onika::oarray_t<::exanb::Vec3d, EXADEM_MAX_VERTICES> VerticesType; XSTAMP_DECLARE_FIELD(VerticesType , vertices ,"list to compute vertices"); // diff --git a/src/polyhedra/include/exaDEM/compute_vertices.hpp b/src/polyhedra/include/exaDEM/compute_vertices.hpp index d45f23f..2f003d4 100644 --- a/src/polyhedra/include/exaDEM/compute_vertices.hpp +++ b/src/polyhedra/include/exaDEM/compute_vertices.hpp @@ -8,7 +8,7 @@ namespace exaDEM struct PolyhedraComputeVerticesFunctor { shapes& shps; - ONIKA_HOST_DEVICE_FUNC inline void operator () (const uint8_t type, const double rx, const double ry, const double rz, const double h, const exanb::Quaternion& orient, ::onika::oarray_t<::exanb::Vec3d, 8>& vertices ) const + ONIKA_HOST_DEVICE_FUNC inline void operator () (const uint8_t type, const double rx, const double ry, const double rz, const double h, const exanb::Quaternion& orient, ::onika::oarray_t<::exanb::Vec3d, EXADEM_MAX_VERTICES>& vertices ) const { // h will be used in a next development const auto& shp = shps[type]; diff --git a/src/polyhedra/include/exaDEM/network.hpp b/src/polyhedra/include/exaDEM/network.hpp index 5e4d896..a12e586 100644 --- a/src/polyhedra/include/exaDEM/network.hpp +++ b/src/polyhedra/include/exaDEM/network.hpp @@ -36,7 +36,7 @@ namespace exaDEM double time; ///< Incrementation time value - using signature = std::tuple (*)(const onika::oarray_t&, int, const exaDEM::shape*, const onika::oarray_t&, int, const exaDEM::shape*); + using signature = std::tuple (*)(const onika::oarray_t&, int, const exaDEM::shape*, const onika::oarray_t&, int, const exaDEM::shape*); /** * @brief Array of function pointers for precomputed detection signatures. diff --git a/src/polyhedra/include/exaDEM/shape/shape_detection.hpp b/src/polyhedra/include/exaDEM/shape/shape_detection.hpp index c188cb4..8ff4ea5 100644 --- a/src/polyhedra/include/exaDEM/shape/shape_detection.hpp +++ b/src/polyhedra/include/exaDEM/shape/shape_detection.hpp @@ -9,7 +9,7 @@ namespace exaDEM { using namespace exanb; - using VertexArray = ::onika::oarray_t<::exanb::Vec3d, 8>; + using VertexArray = ::onika::oarray_t<::exanb::Vec3d, EXADEM_MAX_VERTICES>; /** * @brief Normalizes a 3D vector in-place. diff --git a/src/polyhedra/include/exaDEM/shape/shape_detection_driver.hpp b/src/polyhedra/include/exaDEM/shape/shape_detection_driver.hpp index 1033edf..1ba7c65 100644 --- a/src/polyhedra/include/exaDEM/shape/shape_detection_driver.hpp +++ b/src/polyhedra/include/exaDEM/shape/shape_detection_driver.hpp @@ -11,7 +11,7 @@ namespace exaDEM { using namespace exanb; - using VertexArray = ::onika::oarray_t<::exanb::Vec3d, 8>; + using VertexArray = ::onika::oarray_t<::exanb::Vec3d, EXADEM_MAX_VERTICES>; // -> First Filters template diff --git a/src/polyhedra/update_grid_interaction.cpp b/src/polyhedra/update_grid_interaction.cpp index 2ad5ab9..c2c8c6b 100644 --- a/src/polyhedra/update_grid_interaction.cpp +++ b/src/polyhedra/update_grid_interaction.cpp @@ -21,7 +21,7 @@ namespace exaDEM { using namespace exanb; - using VertexArray = ::onika::oarray_t<::exanb::Vec3d, 8>; + using VertexArray = ::onika::oarray_t<::exanb::Vec3d, EXADEM_MAX_VERTICES>; template Date: Mon, 1 Apr 2024 19:50:42 +0200 Subject: [PATCH 2/2] Add security for EXADEM_MAX_VERTICES --- CMakeLists.txt | 4 +--- .../include/exaDEM/shape/shape_reader.hpp | 19 +++++++------------ src/polyhedra/read_shape_file.cpp | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8332fe..14c9987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,10 +19,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # ============================================== # These values have to be set by exaNBody set(EXADEM_MAX_VERTICES "8" CACHE STRING "Maximum number of vertices per polyhedron") -message(STATUS "Maximum number of vertices per polyhedron: ${EXADEM_MAX_VERTICES}") +message(STATUS "Maximum number of vertices per polyhedron: ${EXADEM_MAX_VERTICES}, default is 8 vertices.") add_compile_options(-DEXADEM_MAX_VERTICES=${EXADEM_MAX_VERTICES}) -#set(USTAMP_COMPILE_DEFINITIONS ${USTAMP_COMPILE_DEFINITIONS} "EXADEM_MAX_VERTICES=${EXADEM_MAX_VERTICES}") -message(STATUS ${USTAMP_COMPILE_DEFINITIONS}) # ====================================== # === exaNBody application framework === diff --git a/src/polyhedra/include/exaDEM/shape/shape_reader.hpp b/src/polyhedra/include/exaDEM/shape/shape_reader.hpp index 40fdf5d..8861908 100644 --- a/src/polyhedra/include/exaDEM/shape/shape_reader.hpp +++ b/src/polyhedra/include/exaDEM/shape/shape_reader.hpp @@ -4,17 +4,6 @@ namespace exaDEM { -/* - bool adder(std::ifstream& stream, shape& item, std::string in) - { - switch (in) - { - case "name": - default return false; - } - } -*/ - void add_shape_from_file_shp(shapes& sphs, const std::string file_name) { std::ifstream input( file_name.c_str() ); @@ -39,7 +28,6 @@ namespace exaDEM input >> new_shape.m_name; } - // === keys relative to the OBB if(key == "obb.center") { @@ -88,6 +76,13 @@ namespace exaDEM { int nv = 0; input >> nv; + if( nv >= EXADEM_MAX_VERTICES ) + { + lout << "=== EXADEM ERROR === + lout << "=== Please, increase the maximum number of vertices: cmake ${Path_To_ExaDEM} -DEXADEM_MAX_VERTICES=" << nv << std::endl; + lout << "=== ABORT === + std::abort(); + } assert( nv !=0 ); for(int i = 0; i < nv ; i++) { diff --git a/src/polyhedra/read_shape_file.cpp b/src/polyhedra/read_shape_file.cpp index 13fa4c7..8775a67 100644 --- a/src/polyhedra/read_shape_file.cpp +++ b/src/polyhedra/read_shape_file.cpp @@ -40,7 +40,7 @@ namespace exaDEM inline void execute () override final { auto& collection = *shapes_collection; - std::cout << "read file: " << *filename << std::endl; + lout << "Read file= " << *filename << std::endl; exaDEM::add_shape_from_file_shp(collection, *filename); }; };