diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b302fe373681cdc862851e871c53d3842d0d842..2c72370a010868e6d5b72467c01e05c215367f56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.10) +cmake_minimum_required (VERSION 3.16) # CMake utils list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -22,6 +22,9 @@ if("${PUGS_SHORT_VERSION}" STREQUAL "") message(FATAL_ERROR "Unable to compute short version from PUGS_VERSION=${PUGS_VERSION}") endif() + +set(CMAKE_CONFIGURATION_TYPES "Release;Debug;Coverage" CACHE STRING INTERNAL FORCE ) + # set project version as PUGS_SHORT_VERSION project (Pugs VERSION ${PUGS_SHORT_VERSION}) @@ -34,16 +37,6 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(PUGS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(PUGS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}") -# Change RelWithDebInfo to compile assertions -SET("CMAKE_CXX_FLAGS_RELWITHDEBINFO" - "-g -O2" - CACHE STRING "Flags used by the compiler during release builds with debug info and assertions" - FORCE ) -SET("CMAKE_C_FLAGS_RELWITHDEBINFO" - "-g -O2" - CACHE STRING "Flags used by the compiler during release builds with debug info and assertions" - FORCE ) - # Add new build types set(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage" @@ -68,16 +61,16 @@ mark_as_advanced( CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) if(CMAKE_BUILD_TYPE) - string(REGEX MATCH "(Debug|Release|RelWithDebInfo|MinSizeRel|Coverage)" VALID_BUILD_TYPE "${CMAKE_BUILD_TYPE}") + string(REGEX MATCH "^(Release|Debug|Coverage)$" VALID_BUILD_TYPE "${CMAKE_BUILD_TYPE}") if(NOT VALID_BUILD_TYPE) message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}'") endif() endif() -# Default build type is RelWIthDebInfo +# Default build type is Release if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING - "Choose the type of build: Debug Release RelWithDebInfo MinSizeRel Coverage." + set(CMAKE_BUILD_TYPE "Release" CACHE STRING + "Choose the type of build: Release Debug Coverage." FORCE) endif() @@ -90,8 +83,8 @@ endif() #------------------------------------------------------ # Checks if compiler version is compatible with Pugs sources -set(GNU_CXX_MIN_VERSION "8.0.0") -set(CLANG_CXX_MIN_VERSION "8.0.0") +set(GNU_CXX_MIN_VERSION "9.0.0") +set(CLANG_CXX_MIN_VERSION "10.0.0") # Pugs default compiler flags set(PUGS_CXX_FLAGS "${PUGS_CXX_FLAGS} -Wall -Wextra -pedantic") @@ -107,11 +100,11 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(PUGS_CXX_FLAGS "${PUGS_CXX_FLAGS} -Wsign-compare -Wunused -Wunused-member-function -Wunused-private-field") endif() -if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0") - set(PUGS_STD_LINK_FLAGS "-lstdc++fs") - endif() -endif() +# if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +# if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0") +# set(PUGS_STD_LINK_FLAGS "-lstdc++fs") +# endif() +# endif() #------------------------------------------------------ @@ -327,12 +320,10 @@ endif() # Compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PUGS_CXX_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${PUGS_CXX_FLAGS}") -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${PUGS_CXX_FLAGS}") # Add debug mode for Standard C++ library (not for AppleClang since it is broken) if (NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG=1") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG=1") endif() #------------------------------------------------------ @@ -600,20 +591,29 @@ target_link_libraries( include(PugsDoxygen) # ------------------- Installation -------------------- -# temporary version workaround -if(${CMAKE_VERSION} VERSION_LESS "3.13.0") - install(TARGETS pugs - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -else() - install(TARGETS pugs PugsAlgebra PugsAnalysis PugsUtils PugsLanguage PugsLanguageAST PugsLanguageModules PugsLanguageAlgorithms PugsLanguageUtils PugsMesh PugsScheme PugsOutput +install(TARGETS + pugs + PugsMesh + PugsAlgebra + PugsAnalysis + PugsUtils + PugsLanguage + PugsLanguageAST + PugsLanguageModules + PugsLanguageAlgorithms + PugsMesh + PugsAlgebra + PugsScheme + PugsUtils + PugsOutput + PugsLanguageUtils + kokkos - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -endif() + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +# ------------------- Build options ------------------- message("") message("====== pugs build options ======") message(" version: ${PUGS_VERSION}") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 156e50f3483dc49a054fd667b8b6819e5d3184c9..d13088e4f441d0601c425f5876b24f8976a8fa53 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,10 +3,16 @@ ---- ## Branches -`develop` and `master` branches are protected. This means that one cannot `push` on them, so **before** to do any code change one has to create a working branch. The following conventions are greatly encouraged: +`develop` and `master` branches are protected. This means that one +cannot `push` on them, so **before** to do any code change one has to +create a working branch. The following conventions are greatly +encouraged: * `feature/my_outstanding_feature` -* `issue/issue-number` (if no number is related to the issue please consider [opening an issue](https://gitlab.delpinux.fr/code/pugs/issues) and assign it to yourself) +* `issue/issue-number` (if no number is related to the issue please + consider [opening an + issue](https://gitlab.delpinux.fr/code/pugs/issues) and assign it to + yourself) ---- ## Tests and coverage @@ -18,21 +24,24 @@ Tests are built automatically and are run typing **all tests should be running correctly before any merge request** ### Unit tests -Unit tests are defined in the `tests` directory. New unit tests should be written or updated when needed. +Unit tests are defined in the `tests` directory. New unit tests should +be written or updated when needed. ### Coverage -Preferably, one should install [gcovr](http://www.gcovr.com) and build `pugs` specifying the `Coverage` build type -> `cmake -DCMAKE_BUILD_TYPE=Coverage [...]` +Preferably, one should install [gcovr](http://www.gcovr.com) and build +`pugs` specifying the `Coverage` build type > `cmake +-DCMAKE_BUILD_TYPE=Coverage [...]` However coverage is computed at each `push` by the `gitlab-ci`. ---- -## Update build environment using [Docker](http://www.docker.com) -This is the easiest way to keep your environment update to build `pugs`. +## Up to date build environment using [Docker](http://www.docker.com) +This is the easiest way to keep your environment up to date in order +to build `pugs`. -Running the [docker-pugs.sh](tools/docker-pugs.sh) script creates the image and -runs it in interactive mode. The image will runs the user's permissions and his -home directory is mounted. +Running the [docker-pugs.sh](tools/docker-pugs.sh) script creates the +image and runs it in interactive mode. The image will runs the user's +permissions and his home directory is mounted. **keep in mind that the produced executable will only run inside docker** @@ -40,21 +49,26 @@ home directory is mounted. ## Coding ### `packages` directory -Do not make **any** change in the `packages` directory. This directory contains *third party libraries* that are are mandatory to minimal builds or `pugs`. +Do not make **any** change in the `packages` directory. This directory +contains *third party libraries* that are are mandatory to minimal +builds or `pugs`. -For any changes in this directory -(bug report, suggestion of new library, library upgrades or downgrades) **open an issue**. +For any changes in this directory (bug report, suggestion of new +library, library upgrades or downgrades) **open an issue**. ### Warnings Try to avoid publishing sources that generates compilation warnings. -Also, avoid the use of `#warning` directives and prefer opening an issue. +Also, avoid the use of `#warning` directives and prefer opening an +issue. -`C++` `[[deprecated]]` directive should also be avoid as much as possible. +`C++` `[[deprecated]]` directive should also be avoid as much as +possible. ### Comments -**Do not** comment deprecated code. It is `git`'s job to keep track of old versions. +**Do not** comment deprecated code. It is `git`'s job to keep track of +old versions. Avoid commenting functions bodies: @@ -68,7 +82,10 @@ Avoid commenting functions bodies: `clang-format` is used in `pugs`, so install it and run > `make clang-format` before any commit -A better solution is to configure your favored editor to perform formatting automatically. For instance `emacs` users should copy-past the following code to their `.emacs.el` init file. +A better solution is to configure your favored editor to perform +formatting automatically. For instance `emacs` users should copy-past +the following code to their `.emacs.el` init file. + ```lisp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Clang-format diff --git a/src/language/CMakeLists.txt b/src/language/CMakeLists.txt index 3565082161700da019088f7bfca70b0d9dfe6fd8..2403c045d9e5d26a30f763cc1814ef9f550a4d35 100644 --- a/src/language/CMakeLists.txt +++ b/src/language/CMakeLists.txt @@ -18,12 +18,3 @@ add_dependencies(PugsLanguage PugsLanguageModules PugsLanguageUtils PugsUtils) - -# ------------------- Installation -------------------- -# temporary version workaround -if(${CMAKE_VERSION} VERSION_LESS "3.13.0") - install(TARGETS PugsLanguage - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -endif() diff --git a/src/mesh/CMakeLists.txt b/src/mesh/CMakeLists.txt index 7634b113494dc081bed63091e722dc8ea4b757fa..787113bea8e88b175af3436a3770f7d79d051174 100644 --- a/src/mesh/CMakeLists.txt +++ b/src/mesh/CMakeLists.txt @@ -30,15 +30,3 @@ add_library( MeshRandomizer.cpp MeshTransformer.cpp SynchronizerManager.cpp) - -# Additional dependencies -#add_dependencies(PugsMesh) - -# ------------------- Installation -------------------- -# temporary version workaround -if(${CMAKE_VERSION} VERSION_LESS "3.13.0") - install(TARGETS PugsMesh - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -endif() diff --git a/src/mesh/ItemArray.hpp b/src/mesh/ItemArray.hpp index 3bd7de633659e81eb8fc178f275ee76a449048cf..0033bb24eb99e3e50739ac25a954cca808665746 100644 --- a/src/mesh/ItemArray.hpp +++ b/src/mesh/ItemArray.hpp @@ -171,6 +171,13 @@ class ItemArray return *this; } + friend std::ostream& + operator<<(std::ostream& os, const ItemArray& item_array) + { + os << item_array.m_values; + return os; + } + template <typename DataType2, typename ConnectivityPtr2> PUGS_INLINE ItemArray(const ItemArray<DataType2, item_type, ConnectivityPtr2>& array_per_item) noexcept diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp index 981ebcc196d4d637d9e775231fe14edc8a70a2f2..1b888e704c530d693660fc9ced3138affe740b10 100644 --- a/src/mesh/ItemValue.hpp +++ b/src/mesh/ItemValue.hpp @@ -159,6 +159,13 @@ class ItemValue return *this; } + friend std::ostream& + operator<<(std::ostream& os, const ItemValue& item_value) + { + os << item_value.m_values; + return os; + } + template <typename DataType2, typename ConnectivityPtr2> PUGS_INLINE ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept diff --git a/src/output/CMakeLists.txt b/src/output/CMakeLists.txt index 1f33809033731ac4500ee64a046ba11f55e15802..f3173dd2613ff281671c1dadb9e60d9e6b95bc64 100644 --- a/src/output/CMakeLists.txt +++ b/src/output/CMakeLists.txt @@ -6,12 +6,3 @@ add_library( GnuplotWriter1D.cpp VTKWriter.cpp WriterBase.cpp) - -# ------------------- Installation -------------------- -# temporary version workaround -if(${CMAKE_VERSION} VERSION_LESS "3.13.0") - install(TARGETS PugsMesh - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -endif() diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 741b0d5104cef791cf045fd8cc76cd8b16db30a2..2289a91d5f74c566a18af0f9fbcc8bf85ed844bb 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -112,12 +112,3 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pugs_config.hpp.in" configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pugs_build_info.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/pugs_build_info.hpp" @ONLY) - -# ------------------- Installation -------------------- -# temporary version workaround -if(${CMAKE_VERSION} VERSION_LESS "3.13.0") - install(TARGETS PugsUtils - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -endif() diff --git a/src/utils/Socket.cpp b/src/utils/Socket.cpp index 3582e359be22a257b2b52109f7a3ed57b2944a1b..617f6e167892c14bc0f5484d3740e0cd07f9f28c 100644 --- a/src/utils/Socket.cpp +++ b/src/utils/Socket.cpp @@ -63,7 +63,7 @@ class Socket::Internals int portNumber() const { - return ::ntohs(m_address.sin_port); + return ntohs(m_address.sin_port); } int @@ -180,7 +180,7 @@ connectServerSocket(const std::string& server_name, int port_number) ::memcpy(reinterpret_cast<char*>(&serv_addr.sin_addr.s_addr), reinterpret_cast<char*>(server->h_addr), server->h_length); - serv_addr.sin_port = ::htons(port_number); + serv_addr.sin_port = htons(port_number); if (::connect(socket_internals.m_socket_fd, reinterpret_cast<sockaddr*>(&serv_addr), sizeof(serv_addr))) { throw NormalError(strerror(errno)); diff --git a/tests/test_ItemArray.cpp b/tests/test_ItemArray.cpp index 9b3b95fded76400eb5953d4a3d70f50481dadde8..cf59acf9097d36874ba81804f8862f2623e383bd 100644 --- a/tests/test_ItemArray.cpp +++ b/tests/test_ItemArray.cpp @@ -271,6 +271,27 @@ TEST_CASE("ItemArray", "[mesh]") } } + SECTION("output") + { + auto mesh = MeshDataBaseForTests::get().unordered1DMesh(); + + Table<int> table{mesh->numberOfCells(), 3}; + for (size_t i = 0; i < table.numberOfRows(); ++i) { + for (size_t j = 0; j < table.numberOfColumns(); ++j) { + table(i, j) = 2 * i + 1 + 3 * j; + } + } + + CellArray<int> cell_array{mesh->connectivity(), 3}; + cell_array = table; + + std::ostringstream table_ost; + table_ost << table; + std::ostringstream cell_array_ost; + cell_array_ost << cell_array; + REQUIRE(table_ost.str() == cell_array_ost.str()); + } + #ifndef NDEBUG SECTION("error") { diff --git a/tests/test_ItemValue.cpp b/tests/test_ItemValue.cpp index 5ec3fdb892eb5474b80381a250d1f2dc487574de..fcea4247018a69bb15855b03e45cb5f8df6e9bd6 100644 --- a/tests/test_ItemValue.cpp +++ b/tests/test_ItemValue.cpp @@ -218,6 +218,25 @@ TEST_CASE("ItemValue", "[mesh]") } } + SECTION("output") + { + auto mesh = MeshDataBaseForTests::get().unordered1DMesh(); + + Array<int> array{mesh->numberOfCells()}; + for (size_t i = 0; i < array.size(); ++i) { + array[i] = 2 * i + 1; + } + + CellValue<int> cell_value{mesh->connectivity()}; + cell_value = array; + + std::ostringstream array_ost; + array_ost << array; + std::ostringstream cell_value_ost; + cell_value_ost << cell_value; + REQUIRE(array_ost.str() == cell_value_ost.str()); + } + #ifndef NDEBUG SECTION("error") {