From 3ebaba6d73a6f938ff76ed54a87e35a25099a375 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Thu, 4 Apr 2019 11:45:30 +0200 Subject: [PATCH] Add two template helpers - 'template <typename T> is_false_v' and - 'template <ItemType item_type> is_false_item_type_v' Which ever parameter is given these 'inline boolean' are always 'false'. Their purpose is to help writing of 'static_assert'. --- src/mesh/Connectivity.hpp | 25 +++++++++++++++++++------ src/mesh/ConnectivityDispatcher.cpp | 12 ++++++------ src/mesh/ConnectivityDispatcher.hpp | 6 ++---- src/mesh/ItemToItemMatrix.hpp | 2 +- src/mesh/ItemType.hpp | 4 ++++ src/utils/Messenger.hpp | 17 +++++++---------- src/utils/Partitioner.cpp | 2 -- src/utils/PastisTraits.hpp | 3 +++ 8 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp index 27d5e2489..bd8021403 100644 --- a/src/mesh/Connectivity.hpp +++ b/src/mesh/Connectivity.hpp @@ -7,6 +7,8 @@ #include <PastisOStream.hpp> #include <PastisUtils.hpp> +#include <PastisTraits.hpp> + #include <TinyVector.hpp> #include <ItemValue.hpp> @@ -50,6 +52,20 @@ class ConnectivityDescriptor // std::vector<std::vector<unsigned int>> face_to_cell_vector; std::vector<std::vector<unsigned int>> face_to_node_vector; + template <typename ItemOfItemT> + auto& itemOfItemVector() + { + if constexpr (std::is_same_v<ItemOfItemT,NodeOfCell>) { + return cell_by_node_vector; + } else if constexpr (std::is_same_v<ItemOfItemT,FaceOfCell>) { + return cell_to_face_vector; + } else if constexpr (std::is_same_v<ItemOfItemT,NodeOfCell>) { + return face_to_node_vector; + } else { + static_assert(is_false_v<ItemOfItemT>, "Unexpected item of item type"); + } + } + std::vector<Array<bool>> cell_face_is_reversed_vector; std::vector<CellType> cell_type_vector; @@ -228,8 +244,7 @@ class Connectivity final } else if constexpr(item_type == ItemType::node) { return m_node_number; } else { - static_assert(item_type == ItemType::cell, "unknown ItemType"); - return m_cell_number; + static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); } } @@ -272,8 +287,7 @@ class Connectivity final } else if constexpr(item_type == ItemType::node) { return m_node_owner; } else { - static_assert(item_type == ItemType::cell, "unknown ItemType"); - return m_cell_owner; + static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); } } @@ -316,8 +330,7 @@ class Connectivity final } else if constexpr(item_type == ItemType::node) { return m_node_is_owned; } else { - static_assert(item_type == ItemType::cell, "unknown ItemType"); - return m_cell_is_owned; + static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); } } diff --git a/src/mesh/ConnectivityDispatcher.cpp b/src/mesh/ConnectivityDispatcher.cpp index f31fd9e6a..b16f6bd7d 100644 --- a/src/mesh/ConnectivityDispatcher.cpp +++ b/src/mesh/ConnectivityDispatcher.cpp @@ -226,7 +226,7 @@ void ConnectivityDispatcher<Dimension>:: _buildSubItemNumberToIdMap(const std::vector<Array<const int>>& recv_cell_sub_item_number_by_proc) { - static_assert(ItemOfItemT::item_type == ItemType::cell, "Dispatcher requires to be build using cell as master entities"); + static_assert(ItemOfItemT::item_type == ItemType::cell, "Dispatcher requires to be built using cell as master entities"); auto& sub_item_number_id_map = this->_dispatchedInfo<ItemOfItemT::sub_item_type>().m_number_to_id_map; for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { @@ -408,13 +408,13 @@ ConnectivityDispatcher<Dimension>::_dispatchFaces() this->_gatherFrom(this->_dispatchedInfo<ItemType::face>().m_new_owner, m_new_descriptor.face_owner_vector); - std::vector<Array<const int>> recv_number_of_node_per_face_by_proc = - _getRecvNumberOfSubItemPerItemByProc<NodeOfFace>(); + { + std::vector<Array<const int>> recv_number_of_node_per_face_by_proc = + _getRecvNumberOfSubItemPerItemByProc<NodeOfFace>(); - std::vector<Array<const int>> recv_face_node_numbering_by_proc - = this->_getRecvItemSubItemNumberingByProc<NodeOfFace>(recv_number_of_node_per_face_by_proc); + std::vector<Array<const int>> recv_face_node_numbering_by_proc + = this->_getRecvItemSubItemNumberingByProc<NodeOfFace>(recv_number_of_node_per_face_by_proc); - { const auto& node_number_id_map = this->_dispatchedInfo<ItemType::node>().m_number_to_id_map; for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { int l=0; diff --git a/src/mesh/ConnectivityDispatcher.hpp b/src/mesh/ConnectivityDispatcher.hpp index b4becdf23..43dd2e75f 100644 --- a/src/mesh/ConnectivityDispatcher.hpp +++ b/src/mesh/ConnectivityDispatcher.hpp @@ -116,8 +116,7 @@ class ConnectivityDispatcher } else if constexpr (std::is_same_v<CellOfNode, ItemOfItem>) { return m_dispatched_cell_of_node_info; } else { - static_assert(std::is_same_v<NodeOfCell, ItemOfItem>, - "Unexpected ItemOfItem type"); + static_assert(is_false_v<ItemOfItem>, "Unexpected ItemOfItem type"); } } @@ -150,8 +149,7 @@ class ConnectivityDispatcher } else if constexpr (std::is_same_v<CellOfNode, ItemOfItem>) { return m_dispatched_cell_of_node_info; } else { - static_assert(std::is_same_v<NodeOfCell, ItemOfItem>, - "Unexpected ItemOfItem type"); + static_assert(is_false_v<ItemOfItem>, "Unexpected ItemOfItem type"); } } diff --git a/src/mesh/ItemToItemMatrix.hpp b/src/mesh/ItemToItemMatrix.hpp index d10aa5ac1..bf62537d3 100644 --- a/src/mesh/ItemToItemMatrix.hpp +++ b/src/mesh/ItemToItemMatrix.hpp @@ -83,7 +83,7 @@ class ItemToItemMatrix PASTIS_INLINE const auto& operator[](const IndexType& source_id) const { - static_assert(std::is_same<IndexType, SourceItemId>(), + static_assert(std::is_same_v<IndexType, SourceItemId>, "ItemToItemMatrix must be indexed using correct ItemId"); using RowType = decltype(m_connectivity_matrix.rowConst(source_id)); return SubItemList<RowType>(m_connectivity_matrix.rowConst(source_id)); diff --git a/src/mesh/ItemType.hpp b/src/mesh/ItemType.hpp index 1b5f3cb45..e9de61530 100644 --- a/src/mesh/ItemType.hpp +++ b/src/mesh/ItemType.hpp @@ -118,4 +118,8 @@ struct ItemTypeId<3> } }; +template <ItemType item_type> +PASTIS_INLINE +constexpr bool is_false_item_type_v = false; + #endif // ITEM_TYPE_HPP diff --git a/src/utils/Messenger.hpp b/src/utils/Messenger.hpp index 1e32874a7..163489cc5 100644 --- a/src/utils/Messenger.hpp +++ b/src/utils/Messenger.hpp @@ -37,7 +37,7 @@ class Messenger } else { static_assert(std::is_arithmetic_v<DataType>, "Unexpected arithmetic type! Should not occur!"); - static_assert(not std::is_arithmetic_v<DataType>, + static_assert(is_false_v<DataType>, "MPI_Datatype are only defined for arithmetic types!"); return MPI_Datatype(); } @@ -379,7 +379,7 @@ class Messenger _allGather(cast_value_array, cast_gather_array); } else { - static_assert(is_trivially_castable<DataType>, "unexpected type of data"); + static_assert(is_false_v<DataType>, "unexpected type of data"); } return gather_array; } @@ -403,7 +403,7 @@ class Messenger _allGather(cast_array, cast_gather_array); } else { - static_assert(is_trivially_castable<DataType>, "unexpected type of data"); + static_assert(is_false_v<DataType>, "unexpected type of data"); } return gather_array; } @@ -432,7 +432,7 @@ class Messenger auto recv_cast_array = cast_array_to<CastType>::from(recv_array); _allToAll(send_cast_array, recv_cast_array); } else { - static_assert(is_trivially_castable<DataType>, "unexpected type of data"); + static_assert(is_false_v<DataType>, "unexpected type of data"); } return recv_array; } @@ -455,8 +455,7 @@ class Messenger _broadcast_array(cast_array, root_rank); } } else { - static_assert(is_trivially_castable<DataType>, - "unexpected non trivial type of data"); + static_assert(is_false_v<DataType>, "unexpected type of data"); } } @@ -485,8 +484,7 @@ class Messenger auto cast_array = cast_array_to<CastType>::from(array); _broadcast_array(cast_array, root_rank); } else{ - static_assert(is_trivially_castable<DataType>, - "unexpected non trivial type of data"); + static_assert(is_false_v<DataType>, "unexpected type of data"); } } @@ -523,8 +521,7 @@ class Messenger using CastType = helper::split_cast_t<DataType>; _exchange_through_cast<SendDataType, CastType>(send_array_list, recv_array_list); } else { - static_assert(is_trivially_castable<RecvDataType>, - "unexpected non trivial type of data"); + static_assert(is_false_v<RecvDataType>, "unexpected type of data"); } } diff --git a/src/utils/Partitioner.cpp b/src/utils/Partitioner.cpp index 77839a25c..c1da28a49 100644 --- a/src/utils/Partitioner.cpp +++ b/src/utils/Partitioner.cpp @@ -60,8 +60,6 @@ Array<int> Partitioner::partition(const CSRGraph& graph) part = Array<int>(local_number_of_nodes); std::vector<int> vtxdist{0,local_number_of_nodes}; - static_assert(std::is_same<int, int>()); - const Array<int>& entries = graph.entries(); const Array<int>& neighbors = graph.neighbors(); diff --git a/src/utils/PastisTraits.hpp b/src/utils/PastisTraits.hpp index 4f7877ac9..871e30fd1 100644 --- a/src/utils/PastisTraits.hpp +++ b/src/utils/PastisTraits.hpp @@ -19,4 +19,7 @@ inline constexpr bool is_trivially_castable<TinyMatrix<N,T>> = is_trivially_cast template <size_t N, typename T> inline constexpr bool is_trivially_castable<const TinyMatrix<N,T>> = is_trivially_castable<T>; +template <typename T> +inline constexpr bool is_false_v = false; + #endif // PASTIS_TRAITS_HPP -- GitLab