From 97f1aef2c75242091ff5e1924e04756dd8d8a249 Mon Sep 17 00:00:00 2001 From: Stephane Del Pino <stephane.delpino44@gmail.com> Date: Thu, 11 Apr 2019 23:00:38 +0200 Subject: [PATCH] Reformat all code --- src/algebra/TinyMatrix.hpp | 375 ++--- src/algebra/TinyVector.hpp | 143 +- src/language/PastisParser.cpp | 96 +- src/language/PastisParser.hpp | 2 +- src/main.cpp | 382 +++-- src/mesh/CellType.hpp | 31 +- src/mesh/Connectivity.cpp | 125 +- src/mesh/Connectivity.hpp | 418 +++--- src/mesh/ConnectivityComputer.cpp | 174 +-- src/mesh/ConnectivityComputer.hpp | 22 +- src/mesh/ConnectivityDescriptor.hpp | 37 +- src/mesh/ConnectivityDispatcher.cpp | 623 ++++---- src/mesh/ConnectivityDispatcher.hpp | 116 +- src/mesh/ConnectivityMatrix.hpp | 37 +- src/mesh/GmshReader.cpp | 1574 ++++++++++---------- src/mesh/GmshReader.hpp | 85 +- src/mesh/IConnectivity.hpp | 42 +- src/mesh/ItemId.hpp | 31 +- src/mesh/ItemOfItemType.hpp | 10 +- src/mesh/ItemToItemMatrix.hpp | 27 +- src/mesh/ItemType.hpp | 51 +- src/mesh/ItemValue.hpp | 90 +- src/mesh/ItemValueUtils.hpp | 265 ++-- src/mesh/Mesh.hpp | 37 +- src/mesh/MeshData.hpp | 281 ++-- src/mesh/MeshNodeBoundary.hpp | 338 ++--- src/mesh/RefId.hpp | 46 +- src/mesh/RefItemList.hpp | 20 +- src/mesh/SubItemValuePerItem.hpp | 118 +- src/mesh/Synchronizer.hpp | 165 +- src/mesh/SynchronizerManager.cpp | 32 +- src/mesh/SynchronizerManager.hpp | 12 +- src/output/OutputNamedItemValueSet.hpp | 92 +- src/output/VTKWriter.hpp | 435 +++--- src/scheme/AcousticSolver.hpp | 299 ++-- src/scheme/BlockPerfectGas.hpp | 53 +- src/scheme/BoundaryCondition.hpp | 78 +- src/scheme/BoundaryConditionDescriptor.hpp | 81 +- src/scheme/FiniteVolumesEulerUnknowns.hpp | 134 +- src/utils/Array.hpp | 57 +- src/utils/ArrayUtils.hpp | 86 +- src/utils/BacktraceManager.cpp | 38 +- src/utils/BacktraceManager.hpp | 13 +- src/utils/BuildInfo.cpp | 35 +- src/utils/BuildInfo.hpp | 2 +- src/utils/CSRGraph.hpp | 29 +- src/utils/CastArray.hpp | 51 +- src/utils/ConsoleManager.cpp | 29 +- src/utils/ConsoleManager.hpp | 2 +- src/utils/FPEManager.cpp | 62 +- src/utils/FPEManager.hpp | 2 +- src/utils/Messenger.cpp | 47 +- src/utils/Messenger.hpp | 559 ++++--- src/utils/Partitioner.cpp | 70 +- src/utils/Partitioner.hpp | 7 +- src/utils/PastisAssert.hpp | 84 +- src/utils/PastisMacros.hpp | 11 +- src/utils/PastisOStream.cpp | 11 +- src/utils/PastisOStream.hpp | 15 +- src/utils/PastisTraits.hpp | 20 +- src/utils/PastisUtils.cpp | 90 +- src/utils/PastisUtils.hpp | 20 +- src/utils/RevisionInfo.cpp | 19 +- src/utils/RevisionInfo.hpp | 2 +- src/utils/SignalManager.cpp | 102 +- src/utils/SignalManager.hpp | 7 +- src/utils/Timer.hpp | 2 +- src/utils/Types.hpp | 16 +- tests/mpi_test_Messenger.cpp | 338 +++-- tests/mpi_test_main.cpp | 9 +- tests/test_Array.cpp | 188 +-- tests/test_ArrayUtils.cpp | 73 +- tests/test_ItemType.cpp | 62 +- tests/test_PastisAssert.cpp | 29 +- tests/test_RevisionInfo.cpp | 37 +- tests/test_TinyMatrix.cpp | 315 ++-- tests/test_TinyVector.cpp | 98 +- tests/test_main.cpp | 7 +- 78 files changed, 5103 insertions(+), 4518 deletions(-) diff --git a/src/algebra/TinyMatrix.hpp b/src/algebra/TinyMatrix.hpp index 2dde6fc1a..b26cd022f 100644 --- a/src/algebra/TinyMatrix.hpp +++ b/src/algebra/TinyMatrix.hpp @@ -1,46 +1,48 @@ #ifndef TINY_MATRIX_HPP #define TINY_MATRIX_HPP -#include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisMacros.hpp> -#include <Types.hpp> #include <TinyVector.hpp> +#include <Types.hpp> #include <iostream> -template <size_t N, typename T=double> +template <size_t N, typename T = double> class TinyMatrix { public: using data_type = T; private: - T m_values[N*N]; - static_assert((N>0),"TinyMatrix size must be strictly positive"); + T m_values[N * N]; + static_assert((N > 0), "TinyMatrix size must be strictly positive"); PASTIS_FORCEINLINE - constexpr size_t _index(const size_t& i, const size_t& j) const noexcept + constexpr size_t + _index(const size_t& i, const size_t& j) const noexcept { - return i*N+j; + return i * N + j; } template <typename... Args> - PASTIS_FORCEINLINE - constexpr void _unpackVariadicInput(const T& t, Args&&... args) noexcept + PASTIS_FORCEINLINE constexpr void + _unpackVariadicInput(const T& t, Args&&... args) noexcept { - m_values[N*N-1-sizeof...(args)] = t; - if constexpr (sizeof...(args) >0) { - this->_unpackVariadicInput(std::forward<Args>(args)...); - } + m_values[N * N - 1 - sizeof...(args)] = t; + if constexpr (sizeof...(args) > 0) { + this->_unpackVariadicInput(std::forward<Args>(args)...); + } } -public: + public: PASTIS_INLINE - constexpr TinyMatrix operator-() const + constexpr TinyMatrix + operator-() const { TinyMatrix opposed; - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { opposed.m_values[i] = -m_values[i]; } return std::move(opposed); @@ -54,9 +56,10 @@ public: } PASTIS_INLINE - constexpr TinyMatrix& operator*=(const T& t) + constexpr TinyMatrix& + operator*=(const T& t) { - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { m_values[i] *= t; } return *this; @@ -67,27 +70,27 @@ public: { const TinyMatrix& A = *this; TinyMatrix AB; - for (size_t i=0; i<N; ++i) { - for (size_t j=0; j<N; ++j) { - T sum = A(i,0)*B(0,j); - for (size_t k=1; k<N; ++k) { - sum += A(i,k)*B(k,j); + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + T sum = A(i, 0) * B(0, j); + for (size_t k = 1; k < N; ++k) { + sum += A(i, k) * B(k, j); } - AB(i,j) = sum; + AB(i, j) = sum; } } return std::move(AB); } PASTIS_INLINE - constexpr TinyVector<N,T> operator*(const TinyVector<N,T>& x) const + constexpr TinyVector<N, T> operator*(const TinyVector<N, T>& x) const { const TinyMatrix& A = *this; - TinyVector<N,T> Ax; - for (size_t i=0; i<N; ++i) { - T sum = A(i,0)*x[0]; - for (size_t j=1; j<N; ++j) { - sum += A(i,j)*x[j]; + TinyVector<N, T> Ax; + for (size_t i = 0; i < N; ++i) { + T sum = A(i, 0) * x[0]; + for (size_t j = 1; j < N; ++j) { + sum += A(i, j) * x[j]; } Ax[i] = sum; } @@ -95,17 +98,17 @@ public: } PASTIS_INLINE - constexpr friend std::ostream& operator<<(std::ostream& os, const TinyMatrix& A) + constexpr friend std::ostream& + operator<<(std::ostream& os, const TinyMatrix& A) { - if constexpr(N==1) { - os << A(0,0); - } - else { + if constexpr (N == 1) { + os << A(0, 0); + } else { os << '['; - for (size_t i=0; i<N; ++i) { - os << '(' << A(i,0); - for (size_t j=1; j<N; ++j) { - os << ',' << A(i,j); + for (size_t i = 0; i < N; ++i) { + os << '(' << A(i, 0); + for (size_t j = 1; j < N; ++j) { + os << ',' << A(i, j); } os << ')'; } @@ -115,115 +118,131 @@ public: } PASTIS_INLINE - constexpr bool operator==(const TinyMatrix& A) const + constexpr bool + operator==(const TinyMatrix& A) const { - for (size_t i=0; i<N*N; ++i) { - if (m_values[i] != A.m_values[i]) return false; + for (size_t i = 0; i < N * N; ++i) { + if (m_values[i] != A.m_values[i]) + return false; } return true; } PASTIS_INLINE - constexpr bool operator!=(const TinyMatrix& A) const + constexpr bool + operator!=(const TinyMatrix& A) const { return not this->operator==(A); } PASTIS_INLINE - constexpr TinyMatrix operator+(const TinyMatrix& A) const + constexpr TinyMatrix + operator+(const TinyMatrix& A) const { TinyMatrix sum; - for (size_t i=0; i<N*N; ++i) { - sum.m_values[i] = m_values[i]+A.m_values[i]; + for (size_t i = 0; i < N * N; ++i) { + sum.m_values[i] = m_values[i] + A.m_values[i]; } return std::move(sum); } PASTIS_INLINE - constexpr TinyMatrix operator+(TinyMatrix&& A) const + constexpr TinyMatrix + operator+(TinyMatrix&& A) const { - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { A.m_values[i] += m_values[i]; } return std::move(A); } PASTIS_INLINE - constexpr TinyMatrix operator-(const TinyMatrix& A) const + constexpr TinyMatrix + operator-(const TinyMatrix& A) const { TinyMatrix difference; - for (size_t i=0; i<N*N; ++i) { - difference.m_values[i] = m_values[i]-A.m_values[i]; + for (size_t i = 0; i < N * N; ++i) { + difference.m_values[i] = m_values[i] - A.m_values[i]; } return std::move(difference); } PASTIS_INLINE - constexpr TinyMatrix operator-(TinyMatrix&& A) const + constexpr TinyMatrix + operator-(TinyMatrix&& A) const { - for (size_t i=0; i<N*N; ++i) { - A.m_values[i] = m_values[i]-A.m_values[i]; + for (size_t i = 0; i < N * N; ++i) { + A.m_values[i] = m_values[i] - A.m_values[i]; } return std::move(A); } PASTIS_INLINE - constexpr TinyMatrix& operator+=(const TinyMatrix& A) + constexpr TinyMatrix& + operator+=(const TinyMatrix& A) { - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { m_values[i] += A.m_values[i]; } return *this; } PASTIS_INLINE - constexpr void operator+=(const volatile TinyMatrix& A) volatile + constexpr void + operator+=(const volatile TinyMatrix& A) volatile { - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { m_values[i] += A.m_values[i]; } } PASTIS_INLINE - constexpr TinyMatrix& operator-=(const TinyMatrix& A) + constexpr TinyMatrix& + operator-=(const TinyMatrix& A) { - for (size_t i=0; i<N*N; ++i) { + for (size_t i = 0; i < N * N; ++i) { m_values[i] -= A.m_values[i]; } return *this; } PASTIS_INLINE - constexpr T& operator()(const size_t& i, const size_t& j) noexcept(NO_ASSERT) + constexpr T& + operator()(const size_t& i, const size_t& j) noexcept(NO_ASSERT) { - Assert((i<N) and (j<N)); - return m_values[_index(i,j)]; + Assert((i < N) and (j < N)); + return m_values[_index(i, j)]; } PASTIS_INLINE - constexpr const T& operator()(const size_t& i, const size_t& j) const noexcept(NO_ASSERT) + constexpr const T& + operator()(const size_t& i, const size_t& j) const noexcept(NO_ASSERT) { - Assert((i<N) and (j<N)); - return m_values[_index(i,j)]; + Assert((i < N) and (j < N)); + return m_values[_index(i, j)]; } PASTIS_INLINE - constexpr TinyMatrix& operator=(const ZeroType&) noexcept + constexpr TinyMatrix& + operator=(const ZeroType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot assign 'zero' value for non-arithmetic types"); - for (size_t i=0; i<N*N; ++i) { + static_assert(std::is_arithmetic<T>(), + "Cannot assign 'zero' value for non-arithmetic types"); + for (size_t i = 0; i < N * N; ++i) { m_values[i] = 0; } return *this; } PASTIS_INLINE - constexpr TinyMatrix& operator=(const IdentityType&) noexcept + constexpr TinyMatrix& + operator=(const IdentityType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot assign 'identity' value for non-arithmetic types"); - for (size_t i=0; i<N; ++i) { - for (size_t j=0; j<N; ++j) { - m_values[_index(i,j)] = (i==j) ? 1 : 0; + static_assert(std::is_arithmetic<T>(), + "Cannot assign 'identity' value for non-arithmetic types"); + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + m_values[_index(i, j)] = (i == j) ? 1 : 0; } } return *this; @@ -236,10 +255,9 @@ public: constexpr TinyMatrix& operator=(TinyMatrix&& A) noexcept = default; template <typename... Args> - PASTIS_INLINE - constexpr TinyMatrix(const T& t, Args&&... args) noexcept + PASTIS_INLINE constexpr TinyMatrix(const T& t, Args&&... args) noexcept { - static_assert(sizeof...(args)==N*N-1, "wrong number of parameters"); + static_assert(sizeof...(args) == N * N - 1, "wrong number of parameters"); this->_unpackVariadicInput(t, std::forward<Args>(args)...); } @@ -251,8 +269,10 @@ public: PASTIS_INLINE constexpr TinyMatrix(const ZeroType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot construct from 'zero' value for non-arithmetic types"); - for (size_t i=0; i<N*N; ++i) { + static_assert( + std::is_arithmetic<T>(), + "Cannot construct from 'zero' value for non-arithmetic types"); + for (size_t i = 0; i < N * N; ++i) { m_values[i] = 0; } } @@ -260,10 +280,12 @@ public: PASTIS_INLINE constexpr TinyMatrix(const IdentityType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot construct from 'identity' value for non-arithmetic types"); - for (size_t i=0; i<N; ++i) { - for (size_t j=0; j<N; ++j) { - m_values[_index(i,j)] = (i==j) ? 1 : 0; + static_assert( + std::is_arithmetic<T>(), + "Cannot construct from 'identity' value for non-arithmetic types"); + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + m_values[_index(i, j)] = (i == j) ? 1 : 0; } } } @@ -279,38 +301,41 @@ public: }; template <size_t N, typename T> -PASTIS_INLINE -constexpr TinyMatrix<N,T> tensorProduct(const TinyVector<N,T>& x, - const TinyVector<N,T>& y) +PASTIS_INLINE constexpr TinyMatrix<N, T> +tensorProduct(const TinyVector<N, T>& x, const TinyVector<N, T>& y) { - TinyMatrix<N,T> A; - for (size_t i=0; i<N; ++i) { - for (size_t j=0; j<N; ++j) { - A(i,j) = x[i]*y[j]; + TinyMatrix<N, T> A; + for (size_t i = 0; i < N; ++i) { + for (size_t j = 0; j < N; ++j) { + A(i, j) = x[i] * y[j]; } } return std::move(A); } template <size_t N, typename T> -PASTIS_INLINE -constexpr T det(const TinyMatrix<N,T>& A) +PASTIS_INLINE constexpr T +det(const TinyMatrix<N, T>& A) { - static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types"); - static_assert(std::is_floating_point<T>::value, "determinent for arbitrary dimension N is defined for floating point types only"); - TinyMatrix<N,T> M = A; + static_assert(std::is_arithmetic<T>::value, + "determinent is not defined for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, + "determinent for arbitrary dimension N is defined for floating " + "point types only"); + TinyMatrix<N, T> M = A; TinyVector<N, size_t> index; - for (size_t i=0; i<N; ++i) index[i]=i; + for (size_t i = 0; i < N; ++i) + index[i] = i; T determinent = 1; - for (size_t i=0; i<N; ++i) { - for (size_t j=i; j<N; ++j) { - size_t l = j; + for (size_t i = 0; i < N; ++i) { + for (size_t j = i; j < N; ++j) { + size_t l = j; const size_t J = index[j]; - for (size_t k=j+1; k<N; ++k) { - if (std::abs(M(index[k],i)) > std::abs(M(J,i))) { - l=k; + for (size_t k = j + 1; k < N; ++k) { + if (std::abs(M(index[k], i)) > std::abs(M(J, i))) { + l = k; } } if (l != j) { @@ -319,135 +344,139 @@ constexpr T det(const TinyMatrix<N,T>& A) } } const size_t I = index[i]; - if (M(I,i)==0) return 0; - const T inv_Mii = 1./M(I,i); - for (size_t k=i+1; k<N; ++k) { + if (M(I, i) == 0) + return 0; + const T inv_Mii = 1. / M(I, i); + for (size_t k = i + 1; k < N; ++k) { const size_t K = index[k]; - const T factor = M(K,i)*inv_Mii; - for (size_t l=i+1; l<N; ++l) { - M(K,l) -= factor*M(I,l); + const T factor = M(K, i) * inv_Mii; + for (size_t l = i + 1; l < N; ++l) { + M(K, l) -= factor * M(I, l); } } } - for (size_t i=0; i<N; ++i) { - determinent *= M(index[i],i); + for (size_t i = 0; i < N; ++i) { + determinent *= M(index[i], i); } return determinent; } template <typename T> -PASTIS_INLINE -constexpr T det(const TinyMatrix<1,T>& A) +PASTIS_INLINE constexpr T +det(const TinyMatrix<1, T>& A) { - static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types"); - return A(0,0); + static_assert(std::is_arithmetic<T>::value, + "determinent is not defined for non-arithmetic types"); + return A(0, 0); } template <typename T> -PASTIS_INLINE -constexpr T det(const TinyMatrix<2,T>& A) +PASTIS_INLINE constexpr T +det(const TinyMatrix<2, T>& A) { - static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types"); - return A(0,0)*A(1,1)-A(1,0)*A(0,1); + static_assert(std::is_arithmetic<T>::value, + "determinent is not defined for non-arithmetic types"); + return A(0, 0) * A(1, 1) - A(1, 0) * A(0, 1); } template <typename T> -PASTIS_INLINE -constexpr T det(const TinyMatrix<3,T>& A) +PASTIS_INLINE constexpr T +det(const TinyMatrix<3, T>& A) { - static_assert(std::is_arithmetic<T>::value, "determinent is not defined for non-arithmetic types"); - return - A(0,0)*(A(1,1)*A(2,2)-A(2,1)*A(1,2)) - -A(1,0)*(A(0,1)*A(2,2)-A(2,1)*A(0,2)) - +A(2,0)*(A(0,1)*A(1,2)-A(1,1)*A(0,2)); + static_assert(std::is_arithmetic<T>::value, + "determinent is not defined for non-arithmetic types"); + return A(0, 0) * (A(1, 1) * A(2, 2) - A(2, 1) * A(1, 2)) - + A(1, 0) * (A(0, 1) * A(2, 2) - A(2, 1) * A(0, 2)) + + A(2, 0) * (A(0, 1) * A(1, 2) - A(1, 1) * A(0, 2)); } template <size_t N, typename T> -PASTIS_INLINE -constexpr TinyMatrix<N-1,T> getMinor(const TinyMatrix<N,T>& A, - const size_t& I, - const size_t& J) +PASTIS_INLINE constexpr TinyMatrix<N - 1, T> +getMinor(const TinyMatrix<N, T>& A, const size_t& I, const size_t& J) { - static_assert(N>=2, "minor calculation requires at least 2x2 matrices"); - Assert((I<N) and (J<N)); - TinyMatrix<N-1,T> M; - for (size_t i=0; i<I; ++i) { - for (size_t j=0; j<J; ++j) { - M(i,j)=A(i,j); + static_assert(N >= 2, "minor calculation requires at least 2x2 matrices"); + Assert((I < N) and (J < N)); + TinyMatrix<N - 1, T> M; + for (size_t i = 0; i < I; ++i) { + for (size_t j = 0; j < J; ++j) { + M(i, j) = A(i, j); } - for (size_t j=J+1; j<N; ++j) { - M(i,j-1)=A(i,j); + for (size_t j = J + 1; j < N; ++j) { + M(i, j - 1) = A(i, j); } } - for (size_t i=I+1; i<N; ++i) { - for (size_t j=0; j<J; ++j) { - M(i-1,j)=A(i,j); + for (size_t i = I + 1; i < N; ++i) { + for (size_t j = 0; j < J; ++j) { + M(i - 1, j) = A(i, j); } - for (size_t j=J+1; j<N; ++j) { - M(i-1,j-1)=A(i,j); + for (size_t j = J + 1; j < N; ++j) { + M(i - 1, j - 1) = A(i, j); } } return std::move(M); } template <size_t N, typename T> -PASTIS_INLINE -constexpr TinyMatrix<N,T> inverse(const TinyMatrix<N,T>& A); +PASTIS_INLINE constexpr TinyMatrix<N, T> inverse(const TinyMatrix<N, T>& A); template <typename T> -PASTIS_INLINE -constexpr TinyMatrix<1,T> inverse(const TinyMatrix<1,T>& A) +PASTIS_INLINE constexpr TinyMatrix<1, T> +inverse(const TinyMatrix<1, T>& A) { - static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types"); - static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only"); + static_assert(std::is_arithmetic<T>::value, + "inverse is not defined for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, + "inverse is defined for floating point types only"); - TinyMatrix<1,T> A_1(1./A(0,0)); + TinyMatrix<1, T> A_1(1. / A(0, 0)); return std::move(A_1); } template <size_t N, typename T> -PASTIS_INLINE -constexpr T cofactor(const TinyMatrix<N,T>& A, - const size_t& i, - const size_t& j) +PASTIS_INLINE constexpr T +cofactor(const TinyMatrix<N, T>& A, const size_t& i, const size_t& j) { - static_assert(std::is_arithmetic<T>::value, "cofactor is not defined for non-arithmetic types"); - const T sign = ((i+j)%2) ? -1 : 1; + static_assert(std::is_arithmetic<T>::value, + "cofactor is not defined for non-arithmetic types"); + const T sign = ((i + j) % 2) ? -1 : 1; return sign * det(getMinor(A, i, j)); } template <typename T> -PASTIS_INLINE -constexpr TinyMatrix<2,T> inverse(const TinyMatrix<2,T>& A) +PASTIS_INLINE constexpr TinyMatrix<2, T> +inverse(const TinyMatrix<2, T>& A) { - static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types"); - static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only"); + static_assert(std::is_arithmetic<T>::value, + "inverse is not defined for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, + "inverse is defined for floating point types only"); - const T determinent = det(A); - const T inv_determinent = 1./determinent; + const T determinent = det(A); + const T inv_determinent = 1. / determinent; - TinyMatrix<2,T> A_cofactors_T(A(1,1), -A(0,1), - -A(1,0), A(0,0)); + TinyMatrix<2, T> A_cofactors_T(A(1, 1), -A(0, 1), -A(1, 0), A(0, 0)); return std::move(A_cofactors_T *= inv_determinent); } - template <typename T> -PASTIS_INLINE -constexpr TinyMatrix<3,T> inverse(const TinyMatrix<3,T>& A) +PASTIS_INLINE constexpr TinyMatrix<3, T> +inverse(const TinyMatrix<3, T>& A) { - static_assert(std::is_arithmetic<T>::value, "inverse is not defined for non-arithmetic types"); - static_assert(std::is_floating_point<T>::value, "inverse is defined for floating point types only"); + static_assert(std::is_arithmetic<T>::value, + "inverse is not defined for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, + "inverse is defined for floating point types only"); const T determinent = det(A); - TinyMatrix<3,T> A_cofactors_T(cofactor(A,0,0), cofactor(A,1,0), cofactor(A,2,0), - cofactor(A,0,1), cofactor(A,1,1), cofactor(A,2,1), - cofactor(A,0,2), cofactor(A,1,2), cofactor(A,2,2)); + TinyMatrix<3, T> A_cofactors_T( + cofactor(A, 0, 0), cofactor(A, 1, 0), cofactor(A, 2, 0), cofactor(A, 0, 1), + cofactor(A, 1, 1), cofactor(A, 2, 1), cofactor(A, 0, 2), cofactor(A, 1, 2), + cofactor(A, 2, 2)); - return std::move(A_cofactors_T *= 1./determinent); + return std::move(A_cofactors_T *= 1. / determinent); } -#endif // TINYMATRIX_HPP +#endif // TINYMATRIX_HPP diff --git a/src/algebra/TinyVector.hpp b/src/algebra/TinyVector.hpp index 2b7a080ca..8dfdc33f5 100644 --- a/src/algebra/TinyVector.hpp +++ b/src/algebra/TinyVector.hpp @@ -3,14 +3,14 @@ #include <iostream> -#include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisMacros.hpp> #include <Types.hpp> #include <cmath> -template <size_t N, typename T=double> +template <size_t N, typename T = double> class TinyVector { public: @@ -18,46 +18,51 @@ class TinyVector private: T m_values[N]; - static_assert((N>0),"TinyVector size must be strictly positive"); + static_assert((N > 0), "TinyVector size must be strictly positive"); template <typename... Args> - PASTIS_FORCEINLINE - constexpr void _unpackVariadicInput(const T& t, Args&&... args) noexcept + PASTIS_FORCEINLINE constexpr void + _unpackVariadicInput(const T& t, Args&&... args) noexcept { - m_values[N-1-sizeof...(args)] = t; + m_values[N - 1 - sizeof...(args)] = t; if constexpr (sizeof...(args) > 0) { - this->_unpackVariadicInput(std::forward<Args>(args)...); - } + this->_unpackVariadicInput(std::forward<Args>(args)...); + } } public: PASTIS_INLINE - constexpr TinyVector operator-() const + constexpr TinyVector + operator-() const { TinyVector opposed; - for (size_t i=0; i<N; ++i) { - opposed.m_values[i] =-m_values[i]; + for (size_t i = 0; i < N; ++i) { + opposed.m_values[i] = -m_values[i]; } return std::move(opposed); } PASTIS_INLINE - constexpr size_t dimension() const + constexpr size_t + dimension() const { return N; } PASTIS_INLINE - constexpr bool operator==(const TinyVector& v) const + constexpr bool + operator==(const TinyVector& v) const { - for (size_t i=0; i<N; ++i) { - if (m_values[i] != v.m_values[i]) return false; + for (size_t i = 0; i < N; ++i) { + if (m_values[i] != v.m_values[i]) + return false; } return true; } PASTIS_INLINE - constexpr bool operator!=(const TinyVector& v) const + constexpr bool + operator!=(const TinyVector& v) const { return not this->operator==(v); } @@ -65,17 +70,18 @@ class TinyVector PASTIS_INLINE constexpr T operator,(const TinyVector& v) const { - T t = m_values[0]*v.m_values[0]; - for (size_t i=1; i<N; ++i) { - t += m_values[i]*v.m_values[i]; + T t = m_values[0] * v.m_values[0]; + for (size_t i = 1; i < N; ++i) { + t += m_values[i] * v.m_values[i]; } return std::move(t); } PASTIS_INLINE - constexpr TinyVector& operator*=(const T& t) + constexpr TinyVector& + operator*=(const T& t) { - for (size_t i=0; i<N; ++i) { + for (size_t i = 0; i < N; ++i) { m_values[i] *= t; } return *this; @@ -85,7 +91,7 @@ class TinyVector constexpr friend TinyVector operator*(const T& t, const TinyVector& v) { TinyVector w = v; - return std::move(w*=t); + return std::move(w *= t); } PASTIS_INLINE @@ -96,10 +102,11 @@ class TinyVector } PASTIS_INLINE - constexpr friend std::ostream& operator<<(std::ostream& os, const TinyVector& v) + constexpr friend std::ostream& + operator<<(std::ostream& os, const TinyVector& v) { os << '(' << v.m_values[0]; - for (size_t i=1; i<N; ++i) { + for (size_t i = 1; i < N; ++i) { os << ',' << v.m_values[i]; } os << ')'; @@ -107,64 +114,71 @@ class TinyVector } PASTIS_INLINE - constexpr TinyVector operator+(const TinyVector& v) const + constexpr TinyVector + operator+(const TinyVector& v) const { TinyVector sum; - for (size_t i=0; i<N; ++i) { - sum.m_values[i] = m_values[i]+v.m_values[i]; + for (size_t i = 0; i < N; ++i) { + sum.m_values[i] = m_values[i] + v.m_values[i]; } return std::move(sum); } PASTIS_INLINE - constexpr TinyVector operator+(TinyVector&& v) const + constexpr TinyVector + operator+(TinyVector&& v) const { - for (size_t i=0; i<N; ++i) { + for (size_t i = 0; i < N; ++i) { v.m_values[i] += m_values[i]; } return std::move(v); } PASTIS_INLINE - constexpr TinyVector operator-(const TinyVector& v) const + constexpr TinyVector + operator-(const TinyVector& v) const { TinyVector difference; - for (size_t i=0; i<N; ++i) { - difference.m_values[i] = m_values[i]-v.m_values[i]; + for (size_t i = 0; i < N; ++i) { + difference.m_values[i] = m_values[i] - v.m_values[i]; } return std::move(difference); } PASTIS_INLINE - constexpr TinyVector operator-(TinyVector&& v) const + constexpr TinyVector + operator-(TinyVector&& v) const { - for (size_t i=0; i<N; ++i) { - v.m_values[i] = m_values[i]-v.m_values[i]; + for (size_t i = 0; i < N; ++i) { + v.m_values[i] = m_values[i] - v.m_values[i]; } return std::move(v); } PASTIS_INLINE - constexpr TinyVector& operator+=(const TinyVector& v) + constexpr TinyVector& + operator+=(const TinyVector& v) { - for (size_t i=0; i<N; ++i) { + for (size_t i = 0; i < N; ++i) { m_values[i] += v.m_values[i]; } return *this; } PASTIS_INLINE - constexpr void operator+=(const volatile TinyVector& v) volatile + constexpr void + operator+=(const volatile TinyVector& v) volatile { - for (size_t i=0; i<N; ++i) { + for (size_t i = 0; i < N; ++i) { m_values[i] += v.m_values[i]; } } PASTIS_INLINE - constexpr TinyVector& operator-=(const TinyVector& v) + constexpr TinyVector& + operator-=(const TinyVector& v) { - for (size_t i=0; i<N; ++i) { + for (size_t i = 0; i < N; ++i) { m_values[i] -= v.m_values[i]; } return *this; @@ -173,22 +187,24 @@ class TinyVector PASTIS_INLINE constexpr T& operator[](const size_t& i) noexcept(NO_ASSERT) { - Assert(i<N); + Assert(i < N); return m_values[i]; } PASTIS_INLINE constexpr const T& operator[](const size_t& i) const noexcept(NO_ASSERT) { - Assert(i<N); + Assert(i < N); return m_values[i]; } PASTIS_INLINE - constexpr TinyVector& operator=(const ZeroType&) noexcept + constexpr TinyVector& + operator=(const ZeroType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot assign 'zero' value for non-arithmetic types"); - for (size_t i=0; i<N; ++i) { + static_assert(std::is_arithmetic<T>(), + "Cannot assign 'zero' value for non-arithmetic types"); + for (size_t i = 0; i < N; ++i) { m_values[i] = 0; } return *this; @@ -201,10 +217,9 @@ class TinyVector constexpr TinyVector& operator=(TinyVector&& v) noexcept = default; template <typename... Args> - PASTIS_INLINE - constexpr TinyVector(const T& t, Args&&... args) noexcept + PASTIS_INLINE constexpr TinyVector(const T& t, Args&&... args) noexcept { - static_assert(sizeof...(args)==N-1, "wrong number of parameters"); + static_assert(sizeof...(args) == N - 1, "wrong number of parameters"); this->_unpackVariadicInput(t, std::forward<Args>(args)...); } @@ -216,8 +231,10 @@ class TinyVector PASTIS_INLINE constexpr TinyVector(const ZeroType&) noexcept { - static_assert(std::is_arithmetic<T>(),"Cannot construct from 'zero' value for non-arithmetic types"); - for (size_t i=0; i<N; ++i) { + static_assert( + std::is_arithmetic<T>(), + "Cannot construct from 'zero' value for non-arithmetic types"); + for (size_t i = 0; i < N; ++i) { m_values[i] = 0; } } @@ -233,23 +250,25 @@ class TinyVector }; template <size_t N, typename T> -PASTIS_INLINE -constexpr T l2Norm(const TinyVector<N,T>& x) +PASTIS_INLINE constexpr T +l2Norm(const TinyVector<N, T>& x) { - static_assert(std::is_arithmetic<T>(),"Cannot compute L2 norm for non-arithmetic types"); - static_assert(std::is_floating_point<T>::value, "L2 norm is defined for floating point types only"); - return std::sqrt((x,x)); + static_assert(std::is_arithmetic<T>(), + "Cannot compute L2 norm for non-arithmetic types"); + static_assert(std::is_floating_point<T>::value, + "L2 norm is defined for floating point types only"); + return std::sqrt((x, x)); } // Cross product is only defined for K^3 vectors template <typename T> -PASTIS_INLINE -constexpr TinyVector<3,T> crossProduct(const TinyVector<3,T>& u, const TinyVector<3,T>& v) +PASTIS_INLINE constexpr TinyVector<3, T> +crossProduct(const TinyVector<3, T>& u, const TinyVector<3, T>& v) { - TinyVector<3,T> cross_product(u[1]*v[2]-u[2]*v[1], - u[2]*v[0]-u[0]*v[2], - u[0]*v[1]-u[1]*v[0]); + TinyVector<3, T> cross_product(u[1] * v[2] - u[2] * v[1], + u[2] * v[0] - u[0] * v[2], + u[0] * v[1] - u[1] * v[0]); return std::move(cross_product); } -#endif // TINYVECTOR_HPP +#endif // TINYVECTOR_HPP diff --git a/src/language/PastisParser.cpp b/src/language/PastisParser.cpp index 0b110fbe8..bba7434ef 100644 --- a/src/language/PastisParser.cpp +++ b/src/language/PastisParser.cpp @@ -7,8 +7,7 @@ #include <pegtl.hpp> #include <pegtl/analyze.hpp> -namespace language -{ +namespace language { using namespace language; // clang-format off @@ -75,14 +74,16 @@ struct grammar : must<ignored, star<instruction>,eof>{}; // clang-format on -template< typename Rule > -struct my_action : nothing< Rule > {}; +template <typename Rule> +struct my_action : nothing<Rule> +{}; -template<> -struct my_action< integer > +template <> +struct my_action<integer> { - template< typename Input > - static void apply( const Input& in, std::string& v ) + template <typename Input> + static void + apply(const Input& in, std::string& v) { if (v.size() > 0) { v += std::string(", I:") + in.string(); @@ -92,11 +93,12 @@ struct my_action< integer > } }; -template<> -struct my_action< real > +template <> +struct my_action<real> { - template< typename Input > - static void apply( const Input& in, std::string& v ) + template <typename Input> + static void + apply(const Input& in, std::string& v) { if (v.size() > 0) { v += std::string(", R:") + in.string(); @@ -106,17 +108,16 @@ struct my_action< real > } }; - -template< typename Rule > -struct errors - : public normal< Rule > +template <typename Rule> +struct errors : public normal<Rule> { static const std::string error_message; - template< typename Input, typename... States > - static void raise( const Input& in, States&&... /*unused*/ ) + template <typename Input, typename... States> + static void + raise(const Input& in, States&&... /*unused*/) { - throw parse_error(error_message, std::vector{in.position()} ); + throw parse_error(error_message, std::vector{in.position()}); } }; @@ -124,35 +125,36 @@ template <typename Rule> const std::string errors<Rule>::error_message = "parse error..."; template <> -const std::string errors<eolf>::error_message = "parse error expecting expression"; +const std::string errors<eolf>::error_message = + "parse error expecting expression"; -} - -void parser(const std::string& filename) { - std::string name; +} // namespace language - const size_t grammar_issues = language::analyze< language::grammar >(); - - std::cout << "grammar_issues=" << grammar_issues << '\n'; - language::read_input in(filename); - try { - language::parse< language::grammar, language::my_action//, language::errors - >( in, name ); - } - catch(const language::parse_error& e) { - const auto p = e.positions.front(); - std::cerr << rang::style::bold - << p.source << ':' << p.line << ':' << p.byte_in_line<< ": " - << rang::style::reset - << rang::fgB::red << "error: " << rang::fg::reset - << rang::style::bold << e.what() << rang::style::reset << '\n' - << in.line_at( p ) << '\n' - << std::string( p.byte_in_line, ' ' ) - << rang::fgB::yellow << '^' << rang::fg::reset - << std::endl; - std::exit(1); - } +void +parser(const std::string& filename) +{ + std::string name; + + const size_t grammar_issues = language::analyze<language::grammar>(); + + std::cout << "grammar_issues=" << grammar_issues << '\n'; + language::read_input in(filename); + try { + language::parse<language::grammar, + language::my_action //, language::errors + >(in, name); + } catch (const language::parse_error& e) { + const auto p = e.positions.front(); + std::cerr << rang::style::bold << p.source << ':' << p.line << ':' + << p.byte_in_line << ": " << rang::style::reset << rang::fgB::red + << "error: " << rang::fg::reset << rang::style::bold << e.what() + << rang::style::reset << '\n' + << in.line_at(p) << '\n' + << std::string(p.byte_in_line, ' ') << rang::fgB::yellow << '^' + << rang::fg::reset << std::endl; + std::exit(1); + } - std::cout << "Good bye, " << name << "!" << std::endl; - std::exit(0); + std::cout << "Good bye, " << name << "!" << std::endl; + std::exit(0); } diff --git a/src/language/PastisParser.hpp b/src/language/PastisParser.hpp index e746e608c..3a61ef813 100644 --- a/src/language/PastisParser.hpp +++ b/src/language/PastisParser.hpp @@ -5,4 +5,4 @@ void parser(const std::string& filename); -#endif // PASTIS_PARSER_HPP +#endif // PASTIS_PARSER_HPP diff --git a/src/main.cpp b/src/main.cpp index 6620cf4c6..b047d640a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,20 +1,20 @@ -#include <PastisUtils.hpp> #include <PastisOStream.hpp> +#include <PastisUtils.hpp> #include <rang.hpp> #include <Connectivity.hpp> -#include <Mesh.hpp> -#include <BoundaryCondition.hpp> #include <AcousticSolver.hpp> +#include <BoundaryCondition.hpp> +#include <Mesh.hpp> #include <VTKWriter.hpp> #include <Timer.hpp> -#include <TinyVector.hpp> #include <TinyMatrix.hpp> +#include <TinyVector.hpp> #include <BoundaryConditionDescriptor.hpp> @@ -29,22 +29,24 @@ #include <map> #include <regex> -int main(int argc, char *argv[]) +int +main(int argc, char* argv[]) { std::string filename = initialize(argc, argv); - std::regex gmsh_regex("(.*).msh"); - if (not std::regex_match(filename, gmsh_regex)) { - parser(filename); - return 0; - } + std::regex gmsh_regex("(.*).msh"); + if (not std::regex_match(filename, gmsh_regex)) { + parser(filename); + return 0; + } std::map<std::string, double> method_cost_map; SynchronizerManager::create(); if (filename != "") { - pout() << "Reading (gmsh) " << rang::style::underline << filename << rang::style::reset << " ...\n"; + pout() << "Reading (gmsh) " << rang::style::underline << filename + << rang::style::reset << " ...\n"; Timer gmsh_timer; gmsh_timer.reset(); GmshReader gmsh_reader(filename); @@ -55,22 +57,26 @@ int main(int argc, char *argv[]) switch (p_mesh->dimension()) { case 1: { std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX"}; - std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; - for (const auto& sym_boundary_name : sym_boundary_name_list){ - std::shared_ptr<BoundaryDescriptor> boudary_descriptor - = std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); - SymmetryBoundaryConditionDescriptor* sym_bc_descriptor - = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); - - bc_descriptor_list.push_back(std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); + std::vector<std::shared_ptr<BoundaryConditionDescriptor>> + bc_descriptor_list; + for (const auto& sym_boundary_name : sym_boundary_name_list) { + std::shared_ptr<BoundaryDescriptor> boudary_descriptor = + std::shared_ptr<BoundaryDescriptor>( + new NamedBoundaryDescriptor(sym_boundary_name)); + SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = + new SymmetryBoundaryConditionDescriptor(boudary_descriptor); + + bc_descriptor_list.push_back( + std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); } using ConnectivityType = Connectivity1D; - using MeshType = Mesh<ConnectivityType>; - using MeshDataType = MeshData<MeshType>; - using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; + using MeshType = Mesh<ConnectivityType>; + using MeshDataType = MeshData<MeshType>; + using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; - const MeshType& mesh = dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); + const MeshType& mesh = + dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); Timer timer; timer.reset(); @@ -81,16 +87,25 @@ int main(int argc, char *argv[]) for (const auto& bc_descriptor : bc_descriptor_list) { switch (bc_descriptor->type()) { case BoundaryConditionDescriptor::Type::symmetry: { - const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor - = dynamic_cast<const SymmetryBoundaryConditionDescriptor&>(*bc_descriptor); - for (size_t i_ref_node_list=0; i_ref_node_list<mesh.connectivity().numberOfRefItemList<ItemType::node>(); + const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor = + dynamic_cast<const SymmetryBoundaryConditionDescriptor&>( + *bc_descriptor); + for (size_t i_ref_node_list = 0; + i_ref_node_list < + mesh.connectivity().numberOfRefItemList<ItemType::node>(); ++i_ref_node_list) { - const RefNodeList& ref_node_list = mesh.connectivity().refItemList<ItemType::node>(i_ref_node_list); + const RefNodeList& ref_node_list = + mesh.connectivity().refItemList<ItemType::node>( + i_ref_node_list); const RefId& ref = ref_node_list.refId(); if (ref == sym_bc_descriptor.boundaryDescriptor()) { - SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc - = new SymmetryBoundaryCondition<MeshType::Dimension>(MeshFlatNodeBoundary<MeshType::Dimension>(mesh, ref_node_list)); - std::shared_ptr<SymmetryBoundaryCondition<MeshType::Dimension>> bc(sym_bc); + SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc = + new SymmetryBoundaryCondition<MeshType::Dimension>( + MeshFlatNodeBoundary<MeshType::Dimension>( + mesh, ref_node_list)); + std::shared_ptr< + SymmetryBoundaryCondition<MeshType::Dimension>> + bc(sym_bc); bc_list.push_back(BoundaryConditionHandler(bc)); } } @@ -114,55 +129,62 @@ int main(int argc, char *argv[]) const CellValue<const double>& Vj = mesh_data.Vj(); - const double tmax=0.2; - double t=0; + const double tmax = 0.2; + double t = 0; - int itermax=std::numeric_limits<int>::max(); - int iteration=0; + int itermax = std::numeric_limits<int>::max(); + int iteration = 0; - CellValue<double>& rhoj = unknowns.rhoj(); - CellValue<double>& ej = unknowns.ej(); - CellValue<double>& pj = unknowns.pj(); + CellValue<double>& rhoj = unknowns.rhoj(); + CellValue<double>& ej = unknowns.ej(); + CellValue<double>& pj = unknowns.pj(); CellValue<double>& gammaj = unknowns.gammaj(); - CellValue<double>& cj = unknowns.cj(); + CellValue<double>& cj = unknowns.cj(); BlockPerfectGas block_eos(rhoj, ej, pj, gammaj, cj); VTKWriter vtk_writer("mesh", 0.01); - while((t<tmax) and (iteration<itermax)) { - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}},t); - double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); - if (t+dt>tmax) { - dt=tmax-t; + while ((t < tmax) and (iteration < itermax)) { + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t); + double dt = 0.4 * acoustic_solver.acoustic_dt(Vj, cj); + if (t + dt > tmax) { + dt = tmax - t; } - acoustic_solver.computeNextStep(t,dt, unknowns); + acoustic_solver.computeNextStep(t, dt, unknowns); block_eos.updatePandCFromRhoE(); t += dt; ++iteration; } - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, t, true); // forces last output - - pout() << "* " << rang::style::underline << "Final time" << rang::style::reset - << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t, true); // forces last output + + pout() << "* " << rang::style::underline << "Final time" + << rang::style::reset << ": " << rang::fgB::green << t + << rang::fg::reset << " (" << iteration << " iterations)\n"; method_cost_map["AcousticSolverWithMesh"] = timer.seconds(); - { // gnuplot output for density - const CellValue<const Rd>& xj = mesh_data.xj(); + { // gnuplot output for density + const CellValue<const Rd>& xj = mesh_data.xj(); const CellValue<const double>& rhoj = unknowns.rhoj(); std::ofstream fout("rho"); - for (CellId j=0; j<mesh.numberOfCells(); ++j) { + for (CellId j = 0; j < mesh.numberOfCells(); ++j) { fout << xj[j][0] << ' ' << rhoj[j] << '\n'; } } @@ -171,23 +193,28 @@ int main(int argc, char *argv[]) } case 2: { // test case boundary condition description - std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX"}; - std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; - for (const auto& sym_boundary_name : sym_boundary_name_list){ - std::shared_ptr<BoundaryDescriptor> boudary_descriptor - = std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); - SymmetryBoundaryConditionDescriptor* sym_bc_descriptor - = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); - - bc_descriptor_list.push_back(std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); + std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", + "YMIN", "YMAX"}; + std::vector<std::shared_ptr<BoundaryConditionDescriptor>> + bc_descriptor_list; + for (const auto& sym_boundary_name : sym_boundary_name_list) { + std::shared_ptr<BoundaryDescriptor> boudary_descriptor = + std::shared_ptr<BoundaryDescriptor>( + new NamedBoundaryDescriptor(sym_boundary_name)); + SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = + new SymmetryBoundaryConditionDescriptor(boudary_descriptor); + + bc_descriptor_list.push_back( + std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); } using ConnectivityType = Connectivity2D; - using MeshType = Mesh<ConnectivityType>; - using MeshDataType = MeshData<MeshType>; - using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; + using MeshType = Mesh<ConnectivityType>; + using MeshDataType = MeshData<MeshType>; + using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; - const MeshType& mesh = dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); + const MeshType& mesh = + dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); Timer timer; timer.reset(); @@ -198,16 +225,25 @@ int main(int argc, char *argv[]) for (const auto& bc_descriptor : bc_descriptor_list) { switch (bc_descriptor->type()) { case BoundaryConditionDescriptor::Type::symmetry: { - const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor - = dynamic_cast<const SymmetryBoundaryConditionDescriptor&>(*bc_descriptor); - for (size_t i_ref_face_list=0; i_ref_face_list<mesh.connectivity().numberOfRefItemList<ItemType::face>(); + const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor = + dynamic_cast<const SymmetryBoundaryConditionDescriptor&>( + *bc_descriptor); + for (size_t i_ref_face_list = 0; + i_ref_face_list < + mesh.connectivity().numberOfRefItemList<ItemType::face>(); ++i_ref_face_list) { - const RefFaceList& ref_face_list = mesh.connectivity().refItemList<ItemType::face>(i_ref_face_list); + const RefFaceList& ref_face_list = + mesh.connectivity().refItemList<ItemType::face>( + i_ref_face_list); const RefId& ref = ref_face_list.refId(); if (ref == sym_bc_descriptor.boundaryDescriptor()) { - SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc - = new SymmetryBoundaryCondition<MeshType::Dimension>(MeshFlatNodeBoundary<MeshType::Dimension>(mesh, ref_face_list)); - std::shared_ptr<SymmetryBoundaryCondition<MeshType::Dimension>> bc(sym_bc); + SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc = + new SymmetryBoundaryCondition<MeshType::Dimension>( + MeshFlatNodeBoundary<MeshType::Dimension>( + mesh, ref_face_list)); + std::shared_ptr< + SymmetryBoundaryCondition<MeshType::Dimension>> + bc(sym_bc); bc_list.push_back(BoundaryConditionHandler(bc)); } } @@ -229,69 +265,81 @@ int main(int argc, char *argv[]) const CellValue<const double>& Vj = mesh_data.Vj(); - const double tmax=0.2; - double t=0; + const double tmax = 0.2; + double t = 0; - int itermax=std::numeric_limits<int>::max(); - int iteration=0; + int itermax = std::numeric_limits<int>::max(); + int iteration = 0; - CellValue<double>& rhoj = unknowns.rhoj(); - CellValue<double>& ej = unknowns.ej(); - CellValue<double>& pj = unknowns.pj(); + CellValue<double>& rhoj = unknowns.rhoj(); + CellValue<double>& ej = unknowns.ej(); + CellValue<double>& pj = unknowns.pj(); CellValue<double>& gammaj = unknowns.gammaj(); - CellValue<double>& cj = unknowns.cj(); + CellValue<double>& cj = unknowns.cj(); BlockPerfectGas block_eos(rhoj, ej, pj, gammaj, cj); VTKWriter vtk_writer("mesh", 0.01); - while((t<tmax) and (iteration<itermax)) { - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, t); - double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); - if (t+dt>tmax) { - dt=tmax-t; + while ((t < tmax) and (iteration < itermax)) { + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t); + double dt = 0.4 * acoustic_solver.acoustic_dt(Vj, cj); + if (t + dt > tmax) { + dt = tmax - t; } - acoustic_solver.computeNextStep(t,dt, unknowns); + acoustic_solver.computeNextStep(t, dt, unknowns); block_eos.updatePandCFromRhoE(); t += dt; ++iteration; } - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, t, true); // forces last output - - pout() << "* " << rang::style::underline << "Final time" << rang::style::reset - << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t, true); // forces last output + + pout() << "* " << rang::style::underline << "Final time" + << rang::style::reset << ": " << rang::fgB::green << t + << rang::fg::reset << " (" << iteration << " iterations)\n"; method_cost_map["AcousticSolverWithMesh"] = timer.seconds(); break; } case 3: { - std::vector<std::string> sym_boundary_name_list = {"XMIN", "XMAX", "YMIN", "YMAX", "ZMIN", "ZMAX"}; - std::vector<std::shared_ptr<BoundaryConditionDescriptor>> bc_descriptor_list; - for (const auto& sym_boundary_name : sym_boundary_name_list){ - std::shared_ptr<BoundaryDescriptor> boudary_descriptor - = std::shared_ptr<BoundaryDescriptor>(new NamedBoundaryDescriptor(sym_boundary_name)); - SymmetryBoundaryConditionDescriptor* sym_bc_descriptor - = new SymmetryBoundaryConditionDescriptor(boudary_descriptor); - - bc_descriptor_list.push_back(std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); + std::vector<std::string> sym_boundary_name_list = { + "XMIN", "XMAX", "YMIN", "YMAX", "ZMIN", "ZMAX"}; + std::vector<std::shared_ptr<BoundaryConditionDescriptor>> + bc_descriptor_list; + for (const auto& sym_boundary_name : sym_boundary_name_list) { + std::shared_ptr<BoundaryDescriptor> boudary_descriptor = + std::shared_ptr<BoundaryDescriptor>( + new NamedBoundaryDescriptor(sym_boundary_name)); + SymmetryBoundaryConditionDescriptor* sym_bc_descriptor = + new SymmetryBoundaryConditionDescriptor(boudary_descriptor); + + bc_descriptor_list.push_back( + std::shared_ptr<BoundaryConditionDescriptor>(sym_bc_descriptor)); } using ConnectivityType = Connectivity3D; - using MeshType = Mesh<ConnectivityType>; - using MeshDataType = MeshData<MeshType>; - using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; + using MeshType = Mesh<ConnectivityType>; + using MeshDataType = MeshData<MeshType>; + using UnknownsType = FiniteVolumesEulerUnknowns<MeshDataType>; - const MeshType& mesh = dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); + const MeshType& mesh = + dynamic_cast<const MeshType&>(*gmsh_reader.mesh()); Timer timer; timer.reset(); @@ -302,16 +350,25 @@ int main(int argc, char *argv[]) for (const auto& bc_descriptor : bc_descriptor_list) { switch (bc_descriptor->type()) { case BoundaryConditionDescriptor::Type::symmetry: { - const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor - = dynamic_cast<const SymmetryBoundaryConditionDescriptor&>(*bc_descriptor); - for (size_t i_ref_face_list=0; i_ref_face_list<mesh.connectivity().numberOfRefItemList<ItemType::face>(); + const SymmetryBoundaryConditionDescriptor& sym_bc_descriptor = + dynamic_cast<const SymmetryBoundaryConditionDescriptor&>( + *bc_descriptor); + for (size_t i_ref_face_list = 0; + i_ref_face_list < + mesh.connectivity().numberOfRefItemList<ItemType::face>(); ++i_ref_face_list) { - const RefFaceList& ref_face_list = mesh.connectivity().refItemList<ItemType::face>(i_ref_face_list); + const RefFaceList& ref_face_list = + mesh.connectivity().refItemList<ItemType::face>( + i_ref_face_list); const RefId& ref = ref_face_list.refId(); if (ref == sym_bc_descriptor.boundaryDescriptor()) { - SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc - = new SymmetryBoundaryCondition<MeshType::Dimension>(MeshFlatNodeBoundary<MeshType::Dimension>(mesh, ref_face_list)); - std::shared_ptr<SymmetryBoundaryCondition<MeshType::Dimension>> bc(sym_bc); + SymmetryBoundaryCondition<MeshType::Dimension>* sym_bc = + new SymmetryBoundaryCondition<MeshType::Dimension>( + MeshFlatNodeBoundary<MeshType::Dimension>( + mesh, ref_face_list)); + std::shared_ptr< + SymmetryBoundaryCondition<MeshType::Dimension>> + bc(sym_bc); bc_list.push_back(BoundaryConditionHandler(bc)); } } @@ -333,53 +390,61 @@ int main(int argc, char *argv[]) const CellValue<const double>& Vj = mesh_data.Vj(); - const double tmax=0.2; - double t=0; + const double tmax = 0.2; + double t = 0; - int itermax=std::numeric_limits<int>::max(); - int iteration=0; + int itermax = std::numeric_limits<int>::max(); + int iteration = 0; - CellValue<double>& rhoj = unknowns.rhoj(); - CellValue<double>& ej = unknowns.ej(); - CellValue<double>& pj = unknowns.pj(); + CellValue<double>& rhoj = unknowns.rhoj(); + CellValue<double>& ej = unknowns.ej(); + CellValue<double>& pj = unknowns.pj(); CellValue<double>& gammaj = unknowns.gammaj(); - CellValue<double>& cj = unknowns.cj(); + CellValue<double>& cj = unknowns.cj(); BlockPerfectGas block_eos(rhoj, ej, pj, gammaj, cj); VTKWriter vtk_writer("mesh", 0.01); - while((t<tmax) and (iteration<itermax)) { - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, t); - double dt = 0.4*acoustic_solver.acoustic_dt(Vj, cj); - if (t+dt>tmax) { - dt=tmax-t; + while ((t < tmax) and (iteration < itermax)) { + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t); + double dt = 0.4 * acoustic_solver.acoustic_dt(Vj, cj); + if (t + dt > tmax) { + dt = tmax - t; } - acoustic_solver.computeNextStep(t,dt, unknowns); + acoustic_solver.computeNextStep(t, dt, unknowns); block_eos.updatePandCFromRhoE(); t += dt; ++iteration; } - vtk_writer.write(mesh, {NamedItemValue{"density", rhoj}, - NamedItemValue{"velocity", unknowns.uj()}, - NamedItemValue{"coords", mesh.xr()}, - NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, - NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, t, true); // forces last output - - pout() << "* " << rang::style::underline << "Final time" << rang::style::reset - << ": " << rang::fgB::green << t << rang::fg::reset << " (" << iteration << " iterations)\n"; + vtk_writer.write( + mesh, + {NamedItemValue{"density", rhoj}, + NamedItemValue{"velocity", unknowns.uj()}, + NamedItemValue{"coords", mesh.xr()}, + NamedItemValue{"cell_owner", mesh.connectivity().cellOwner()}, + NamedItemValue{"node_owner", mesh.connectivity().nodeOwner()}}, + t, true); // forces last output + + pout() << "* " << rang::style::underline << "Final time" + << rang::style::reset << ": " << rang::fgB::green << t + << rang::fg::reset << " (" << iteration << " iterations)\n"; method_cost_map["AcousticSolverWithMesh"] = timer.seconds(); break; } } - pout() << "* " << rang::fgB::red << "Could not be uglier!" << rang::fg::reset << " (" << __FILE__ << ':' << __LINE__ << ")\n"; + pout() << "* " << rang::fgB::red << "Could not be uglier!" + << rang::fg::reset << " (" << __FILE__ << ':' << __LINE__ << ")\n"; } else { perr() << "Connectivity1D defined by number of nodes no more implemented\n"; @@ -390,20 +455,15 @@ int main(int argc, char *argv[]) finalize(); - std::string::size_type size=0; + std::string::size_type size = 0; for (const auto& method_cost : method_cost_map) { size = std::max(size, method_cost.first.size()); } for (const auto& method_cost : method_cost_map) { - pout() << "* [" - << rang::fgB::cyan - << std::setw(size) << std::left - << method_cost.first - << rang::fg::reset - << "] Execution time: " - << rang::style::bold - << method_cost.second + pout() << "* [" << rang::fgB::cyan << std::setw(size) << std::left + << method_cost.first << rang::fg::reset + << "] Execution time: " << rang::style::bold << method_cost.second << rang::style::reset << '\n'; } diff --git a/src/mesh/CellType.hpp b/src/mesh/CellType.hpp index d3aa4578f..a3b35c894 100644 --- a/src/mesh/CellType.hpp +++ b/src/mesh/CellType.hpp @@ -1,5 +1,5 @@ #ifndef CELL_TYPE_HPP -#define CELL_TYPE_HPP +#define CELL_TYPE_HPP #include <PastisMacros.hpp> #include <string_view> @@ -18,18 +18,27 @@ enum class CellType : unsigned short }; PASTIS_INLINE -std::string_view name(const CellType& cell_type) +std::string_view +name(const CellType& cell_type) { switch (cell_type) { - case CellType::Line: return "line"; - case CellType::Triangle: return "triangle"; - case CellType::Quadrangle: return "quadrangle"; - case CellType::Tetrahedron: return "tetrahedron"; - case CellType::Pyramid: return "pyramid"; - case CellType::Prism: return "prism"; - case CellType::Hexahedron: return "hexahedron"; - default: return "unknown cell type"; + case CellType::Line: + return "line"; + case CellType::Triangle: + return "triangle"; + case CellType::Quadrangle: + return "quadrangle"; + case CellType::Tetrahedron: + return "tetrahedron"; + case CellType::Pyramid: + return "pyramid"; + case CellType::Prism: + return "prism"; + case CellType::Hexahedron: + return "hexahedron"; + default: + return "unknown cell type"; } } -#endif // CELL_TYPE_HPP +#endif // CELL_TYPE_HPP diff --git a/src/mesh/Connectivity.cpp b/src/mesh/Connectivity.cpp index 3a4b45766..86b94b934 100644 --- a/src/mesh/Connectivity.cpp +++ b/src/mesh/Connectivity.cpp @@ -5,42 +5,48 @@ #include <ConnectivityDescriptor.hpp> -template<size_t Dimension> -Connectivity<Dimension>::Connectivity() {} +template <size_t Dimension> +Connectivity<Dimension>::Connectivity() +{} -template<size_t Dimension> -void Connectivity<Dimension>:: -_buildFrom(const ConnectivityDescriptor& descriptor) +template <size_t Dimension> +void +Connectivity<Dimension>::_buildFrom(const ConnectivityDescriptor& descriptor) { - Assert(descriptor.cell_to_node_vector.size() == descriptor.cell_type_vector.size()); - Assert(descriptor.cell_number_vector.size() == descriptor.cell_type_vector.size()); - if constexpr (Dimension>1) { - Assert(descriptor.cell_to_face_vector.size() == descriptor.cell_type_vector.size()); - Assert(descriptor.face_to_node_vector.size() == descriptor.face_number_vector.size()); - Assert(descriptor.face_owner_vector.size() == descriptor.face_number_vector.size()); + Assert(descriptor.cell_to_node_vector.size() == + descriptor.cell_type_vector.size()); + Assert(descriptor.cell_number_vector.size() == + descriptor.cell_type_vector.size()); + if constexpr (Dimension > 1) { + Assert(descriptor.cell_to_face_vector.size() == + descriptor.cell_type_vector.size()); + Assert(descriptor.face_to_node_vector.size() == + descriptor.face_number_vector.size()); + Assert(descriptor.face_owner_vector.size() == + descriptor.face_number_vector.size()); } - auto& cell_to_node_matrix - = m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)]; + auto& cell_to_node_matrix = + m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)]; cell_to_node_matrix = descriptor.cell_to_node_vector; { WeakCellValue<CellType> cell_type(*this); - parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - cell_type[j] = descriptor.cell_type_vector[j]; - }); + parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + cell_type[j] = descriptor.cell_type_vector[j]; + }); m_cell_type = cell_type; } { WeakCellValue<int> cell_number(*this); - cell_number = convert_to_array(descriptor.cell_number_vector); + cell_number = convert_to_array(descriptor.cell_number_vector); m_cell_number = cell_number; } { WeakNodeValue<int> node_number(*this); - node_number = convert_to_array(descriptor.node_number_vector); + node_number = convert_to_array(descriptor.node_number_vector); m_node_number = node_number; } @@ -48,14 +54,14 @@ _buildFrom(const ConnectivityDescriptor& descriptor) WeakCellValue<int> cell_global_index(*this); int first_index = 0; parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - cell_global_index[j] = first_index+j; - }); + cell_global_index[j] = first_index + j; + }); m_cell_global_index = cell_global_index; } { WeakCellValue<int> cell_owner(*this); - cell_owner = convert_to_array(descriptor.cell_owner_vector); + cell_owner = convert_to_array(descriptor.cell_owner_vector); m_cell_owner = cell_owner; } @@ -63,14 +69,14 @@ _buildFrom(const ConnectivityDescriptor& descriptor) const int rank = parallel::rank(); WeakCellValue<bool> cell_is_owned(*this); parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - cell_is_owned[j] = (m_cell_owner[j] == rank); - }); + cell_is_owned[j] = (m_cell_owner[j] == rank); + }); m_cell_is_owned = cell_is_owned; } { WeakNodeValue<int> node_owner(*this); - node_owner = convert_to_array(descriptor.node_owner_vector); + node_owner = convert_to_array(descriptor.node_owner_vector); m_node_owner = node_owner; } @@ -78,25 +84,31 @@ _buildFrom(const ConnectivityDescriptor& descriptor) const int rank = parallel::rank(); WeakNodeValue<bool> node_is_owned(*this); parallel_for(this->numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { - node_is_owned[r] = (m_node_owner[r] == rank); - }); + node_is_owned[r] = (m_node_owner[r] == rank); + }); m_node_is_owned = node_is_owned; } - m_ref_node_list_vector = descriptor.template refItemListVector<ItemType::node>(); - m_ref_cell_list_vector = descriptor.template refItemListVector<ItemType::cell>(); + m_ref_node_list_vector = + descriptor.template refItemListVector<ItemType::node>(); + m_ref_cell_list_vector = + descriptor.template refItemListVector<ItemType::cell>(); - if constexpr (Dimension>1) { - m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::node)] = descriptor.face_to_node_vector; + if constexpr (Dimension > 1) { + m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::node)] = + descriptor.face_to_node_vector; - m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::face)] = descriptor.cell_to_face_vector; + m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::face)] = + descriptor.cell_to_face_vector; { FaceValuePerCell<bool> cell_face_is_reversed(*this); - for (CellId j=0; j<descriptor.cell_face_is_reversed_vector.size(); ++j) { - const auto& face_cells_vector = descriptor.cell_face_is_reversed_vector[j]; - for (unsigned short lj=0; lj<face_cells_vector.size(); ++lj) { - cell_face_is_reversed(j,lj) = face_cells_vector[lj]; + for (CellId j = 0; j < descriptor.cell_face_is_reversed_vector.size(); + ++j) { + const auto& face_cells_vector = + descriptor.cell_face_is_reversed_vector[j]; + for (unsigned short lj = 0; lj < face_cells_vector.size(); ++lj) { + cell_face_is_reversed(j, lj) = face_cells_vector[lj]; } } m_cell_face_is_reversed = cell_face_is_reversed; @@ -104,13 +116,13 @@ _buildFrom(const ConnectivityDescriptor& descriptor) { WeakFaceValue<int> face_number(*this); - face_number = convert_to_array(descriptor.face_number_vector); + face_number = convert_to_array(descriptor.face_number_vector); m_face_number = face_number; } { WeakFaceValue<int> face_owner(*this); - face_owner = convert_to_array(descriptor.face_owner_vector); + face_owner = convert_to_array(descriptor.face_owner_vector); m_face_owner = face_owner; } @@ -118,26 +130,32 @@ _buildFrom(const ConnectivityDescriptor& descriptor) const int rank = parallel::rank(); WeakFaceValue<bool> face_is_owned(*this); parallel_for(this->numberOfFaces(), PASTIS_LAMBDA(const FaceId& l) { - face_is_owned[l] = (m_face_owner[l] == rank); - }); + face_is_owned[l] = (m_face_owner[l] == rank); + }); m_face_is_owned = face_is_owned; } - m_ref_face_list_vector = descriptor.template refItemListVector<ItemType::face>(); + m_ref_face_list_vector = + descriptor.template refItemListVector<ItemType::face>(); - if constexpr (Dimension>2) { - m_item_to_item_matrix[itemTId(ItemType::edge)][itemTId(ItemType::node)] = descriptor.edge_to_node_vector; + if constexpr (Dimension > 2) { + m_item_to_item_matrix[itemTId(ItemType::edge)][itemTId(ItemType::node)] = + descriptor.edge_to_node_vector; - m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::edge)] = descriptor.face_to_edge_vector; + m_item_to_item_matrix[itemTId(ItemType::face)][itemTId(ItemType::edge)] = + descriptor.face_to_edge_vector; - m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::edge)] = descriptor.cell_to_edge_vector; + m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::edge)] = + descriptor.cell_to_edge_vector; { EdgeValuePerFace<bool> face_edge_is_reversed(*this); - for (FaceId l=0; l<descriptor.face_edge_is_reversed_vector.size(); ++l) { - const auto& edge_faces_vector = descriptor.face_edge_is_reversed_vector[l]; - for (unsigned short el=0; el<edge_faces_vector.size(); ++el) { - face_edge_is_reversed(l,el) = edge_faces_vector[el]; + for (FaceId l = 0; l < descriptor.face_edge_is_reversed_vector.size(); + ++l) { + const auto& edge_faces_vector = + descriptor.face_edge_is_reversed_vector[l]; + for (unsigned short el = 0; el < edge_faces_vector.size(); ++el) { + face_edge_is_reversed(l, el) = edge_faces_vector[el]; } } m_face_edge_is_reversed = face_edge_is_reversed; @@ -145,13 +163,13 @@ _buildFrom(const ConnectivityDescriptor& descriptor) { WeakEdgeValue<int> edge_number(*this); - edge_number = convert_to_array(descriptor.edge_number_vector); + edge_number = convert_to_array(descriptor.edge_number_vector); m_edge_number = edge_number; } { WeakEdgeValue<int> edge_owner(*this); - edge_owner = convert_to_array(descriptor.edge_owner_vector); + edge_owner = convert_to_array(descriptor.edge_owner_vector); m_edge_owner = edge_owner; } @@ -159,12 +177,13 @@ _buildFrom(const ConnectivityDescriptor& descriptor) const int rank = parallel::rank(); WeakEdgeValue<bool> edge_is_owned(*this); parallel_for(this->numberOfEdges(), PASTIS_LAMBDA(const EdgeId& e) { - edge_is_owned[e] = (m_edge_owner[e] == rank); - }); + edge_is_owned[e] = (m_edge_owner[e] == rank); + }); m_edge_is_owned = edge_is_owned; } - m_ref_edge_list_vector = descriptor.template refItemListVector<ItemType::edge>(); + m_ref_edge_list_vector = + descriptor.template refItemListVector<ItemType::edge>(); } } } diff --git a/src/mesh/Connectivity.hpp b/src/mesh/Connectivity.hpp index 7e1ebd119..980bb5f9a 100644 --- a/src/mesh/Connectivity.hpp +++ b/src/mesh/Connectivity.hpp @@ -1,8 +1,8 @@ #ifndef CONNECTIVITY_HPP #define CONNECTIVITY_HPP -#include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisMacros.hpp> #include <PastisOStream.hpp> #include <PastisUtils.hpp> @@ -18,21 +18,20 @@ #include <ConnectivityMatrix.hpp> #include <ItemToItemMatrix.hpp> -#include <SubItemValuePerItem.hpp> #include <ConnectivityComputer.hpp> +#include <SubItemValuePerItem.hpp> -#include <vector> #include <algorithm> +#include <vector> #include <CellType.hpp> #include <CSRGraph.hpp> -#include <RefId.hpp> #include <ItemType.hpp> +#include <RefId.hpp> #include <RefItemList.hpp> - #include <SynchronizerManager.hpp> #include <set> @@ -40,13 +39,12 @@ class ConnectivityDescriptor; template <size_t Dim> -class Connectivity final - : public IConnectivity +class Connectivity final : public IConnectivity { public: PASTIS_INLINE - static std::shared_ptr<Connectivity<Dim>> - build(const ConnectivityDescriptor&); + static std::shared_ptr<Connectivity<Dim>> build( + const ConnectivityDescriptor&); private: constexpr static auto& itemTId = ItemTypeId<Dim>::itemTId; @@ -55,12 +53,14 @@ class Connectivity final static constexpr size_t Dimension = Dim; PASTIS_INLINE - size_t dimension() const final + size_t + dimension() const final { return Dimension; } + private: - ConnectivityMatrix m_item_to_item_matrix[Dimension+1][Dimension+1]; + ConnectivityMatrix m_item_to_item_matrix[Dimension + 1][Dimension + 1]; WeakCellValue<const CellType> m_cell_type; WeakCellValue<const int> m_cell_global_index; @@ -85,21 +85,33 @@ class Connectivity final WeakFaceValuePerCell<const bool> m_cell_face_is_reversed; WeakEdgeValuePerFace<const bool> m_face_edge_is_reversed; - WeakNodeValuePerCell<const unsigned short> m_cell_local_numbers_in_their_nodes; - WeakEdgeValuePerCell<const unsigned short> m_cell_local_numbers_in_their_edges; - WeakFaceValuePerCell<const unsigned short> m_cell_local_numbers_in_their_faces; - - WeakCellValuePerFace<const unsigned short> m_face_local_numbers_in_their_cells; - WeakEdgeValuePerFace<const unsigned short> m_face_local_numbers_in_their_edges; - WeakNodeValuePerFace<const unsigned short> m_face_local_numbers_in_their_nodes; - - WeakCellValuePerEdge<const unsigned short> m_edge_local_numbers_in_their_cells; - WeakFaceValuePerEdge<const unsigned short> m_edge_local_numbers_in_their_faces; - WeakNodeValuePerEdge<const unsigned short> m_edge_local_numbers_in_their_nodes; - - WeakCellValuePerNode<const unsigned short> m_node_local_numbers_in_their_cells; - WeakEdgeValuePerNode<const unsigned short> m_node_local_numbers_in_their_edges; - WeakFaceValuePerNode<const unsigned short> m_node_local_numbers_in_their_faces; + WeakNodeValuePerCell<const unsigned short> + m_cell_local_numbers_in_their_nodes; + WeakEdgeValuePerCell<const unsigned short> + m_cell_local_numbers_in_their_edges; + WeakFaceValuePerCell<const unsigned short> + m_cell_local_numbers_in_their_faces; + + WeakCellValuePerFace<const unsigned short> + m_face_local_numbers_in_their_cells; + WeakEdgeValuePerFace<const unsigned short> + m_face_local_numbers_in_their_edges; + WeakNodeValuePerFace<const unsigned short> + m_face_local_numbers_in_their_nodes; + + WeakCellValuePerEdge<const unsigned short> + m_edge_local_numbers_in_their_cells; + WeakFaceValuePerEdge<const unsigned short> + m_edge_local_numbers_in_their_faces; + WeakNodeValuePerEdge<const unsigned short> + m_edge_local_numbers_in_their_nodes; + + WeakCellValuePerNode<const unsigned short> + m_node_local_numbers_in_their_cells; + WeakEdgeValuePerNode<const unsigned short> + m_node_local_numbers_in_their_edges; + WeakFaceValuePerNode<const unsigned short> + m_node_local_numbers_in_their_faces; ConnectivityComputer m_connectivity_computer; @@ -113,15 +125,16 @@ class Connectivity final void _computeCellFaceAndFaceNodeConnectivities(); template <typename SubItemValuePerItemType> - PASTIS_INLINE - const SubItemValuePerItemType& - _lazzyBuildItemNumberInTheirChild(const SubItemValuePerItemType& sub_item_value_per_item) const + PASTIS_INLINE const SubItemValuePerItemType& + _lazzyBuildItemNumberInTheirChild( + const SubItemValuePerItemType& sub_item_value_per_item) const { - using ReversedItemOfItem = typename SubItemValuePerItemType::ItemOfItemType::Reversed; + using ReversedItemOfItem = + typename SubItemValuePerItemType::ItemOfItemType::Reversed; if (not sub_item_value_per_item.isBuilt()) { - const_cast<SubItemValuePerItemType&>(sub_item_value_per_item) - = m_connectivity_computer - . computeLocalItemNumberInChildItem<ReversedItemOfItem>(*this); + const_cast<SubItemValuePerItemType&>(sub_item_value_per_item) = + m_connectivity_computer + .computeLocalItemNumberInChildItem<ReversedItemOfItem>(*this); } return sub_item_value_per_item; } @@ -129,62 +142,66 @@ class Connectivity final friend class ConnectivityComputer; PASTIS_INLINE - const ConnectivityMatrix& _getMatrix(const ItemType& item_type_0, - const ItemType& item_type_1) const + const ConnectivityMatrix& + _getMatrix(const ItemType& item_type_0, const ItemType& item_type_1) const { - const ConnectivityMatrix& connectivity_matrix - = m_item_to_item_matrix[itemTId(item_type_0)][itemTId(item_type_1)]; + const ConnectivityMatrix& connectivity_matrix = + m_item_to_item_matrix[itemTId(item_type_0)][itemTId(item_type_1)]; if (not connectivity_matrix.isBuilt()) { - const_cast<ConnectivityMatrix&>(connectivity_matrix) - = m_connectivity_computer - . computeConnectivityMatrix(*this, item_type_0, item_type_1); - + const_cast<ConnectivityMatrix&>(connectivity_matrix) = + m_connectivity_computer.computeConnectivityMatrix(*this, item_type_0, + item_type_1); } return connectivity_matrix; } public: PASTIS_INLINE - const auto& cellType() const + const auto& + cellType() const { return m_cell_type; } PASTIS_INLINE - const auto& cellNumber() const + const auto& + cellNumber() const { return m_cell_number; } PASTIS_INLINE - const auto& faceNumber() const + const auto& + faceNumber() const { return m_face_number; } PASTIS_INLINE - const auto& edgeNumber() const + const auto& + edgeNumber() const { return m_edge_number; } PASTIS_INLINE - const auto& nodeNumber() const + const auto& + nodeNumber() const { return m_node_number; } template <ItemType item_type> - PASTIS_INLINE - const auto& number() const + PASTIS_INLINE const auto& + number() const { - if constexpr(item_type == ItemType::cell) { + if constexpr (item_type == ItemType::cell) { return m_cell_number; - } else if constexpr(item_type == ItemType::face) { + } else if constexpr (item_type == ItemType::face) { return m_face_number; - } else if constexpr(item_type == ItemType::edge) { + } else if constexpr (item_type == ItemType::edge) { return m_edge_number; - } else if constexpr(item_type == ItemType::node) { + } else if constexpr (item_type == ItemType::node) { return m_node_number; } else { static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); @@ -192,19 +209,22 @@ class Connectivity final } PASTIS_INLINE - const auto& cellOwner() const + const auto& + cellOwner() const { return m_cell_owner; } PASTIS_INLINE - const auto& faceOwner() const + const auto& + faceOwner() const { return m_face_owner; } PASTIS_INLINE - const auto& edgeOwner() const + const auto& + edgeOwner() const { perr() << __FILE__ << ':' << __LINE__ << ": edge owner not built\n"; std::terminate(); @@ -212,22 +232,23 @@ class Connectivity final } PASTIS_INLINE - const auto& nodeOwner() const + const auto& + nodeOwner() const { return m_node_owner; } template <ItemType item_type> - PASTIS_INLINE - const auto& owner() const + PASTIS_INLINE const auto& + owner() const { - if constexpr(item_type == ItemType::cell) { + if constexpr (item_type == ItemType::cell) { return m_cell_owner; - } else if constexpr(item_type == ItemType::face) { + } else if constexpr (item_type == ItemType::face) { return m_face_owner; - } else if constexpr(item_type == ItemType::edge) { + } else if constexpr (item_type == ItemType::edge) { return m_edge_owner; - } else if constexpr(item_type == ItemType::node) { + } else if constexpr (item_type == ItemType::node) { return m_node_owner; } else { static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); @@ -235,19 +256,22 @@ class Connectivity final } PASTIS_INLINE - const auto& cellIsOwned() const + const auto& + cellIsOwned() const { return m_cell_is_owned; } PASTIS_INLINE - const auto& faceIsOwned() const + const auto& + faceIsOwned() const { return m_face_is_owned; } PASTIS_INLINE - const auto& edgeIsOwned() const + const auto& + edgeIsOwned() const { perr() << __FILE__ << ':' << __LINE__ << ": edge is owned not built\n"; std::terminate(); @@ -255,22 +279,23 @@ class Connectivity final } PASTIS_INLINE - const auto& nodeIsOwned() const + const auto& + nodeIsOwned() const { return m_node_is_owned; } template <ItemType item_type> - PASTIS_INLINE - const auto& isOwned() const + PASTIS_INLINE const auto& + isOwned() const { - if constexpr(item_type == ItemType::cell) { + if constexpr (item_type == ItemType::cell) { return m_cell_is_owned; - } else if constexpr(item_type == ItemType::face) { + } else if constexpr (item_type == ItemType::face) { return m_face_is_owned; - } else if constexpr(item_type == ItemType::edge) { + } else if constexpr (item_type == ItemType::edge) { return m_edge_is_owned; - } else if constexpr(item_type == ItemType::node) { + } else if constexpr (item_type == ItemType::node) { return m_node_is_owned; } else { static_assert(is_false_item_type_v<item_type>, "unknown ItemType"); @@ -278,205 +303,245 @@ class Connectivity final } PASTIS_INLINE - const bool& isConnectivityMatrixBuilt(const ItemType& item_type_0, - const ItemType& item_type_1) const + const bool& + isConnectivityMatrixBuilt(const ItemType& item_type_0, + const ItemType& item_type_1) const { - const ConnectivityMatrix& connectivity_matrix - = m_item_to_item_matrix[itemTId(item_type_0)][itemTId(item_type_1)]; + const ConnectivityMatrix& connectivity_matrix = + m_item_to_item_matrix[itemTId(item_type_0)][itemTId(item_type_1)]; return connectivity_matrix.isBuilt(); } - template <ItemType source_item_type, - ItemType target_item_type> - PASTIS_INLINE - auto getItemToItemMatrix() const + template <ItemType source_item_type, ItemType target_item_type> + PASTIS_INLINE auto + getItemToItemMatrix() const { - return ItemToItemMatrix<source_item_type, - target_item_type>(_getMatrix(source_item_type, - target_item_type)); + return ItemToItemMatrix<source_item_type, target_item_type>( + _getMatrix(source_item_type, target_item_type)); } PASTIS_INLINE - auto cellToFaceMatrix() const + auto + cellToFaceMatrix() const { return this->template getItemToItemMatrix<ItemType::cell, ItemType::face>(); } PASTIS_INLINE - auto cellToEdgeMatrix() const + auto + cellToEdgeMatrix() const { return this->template getItemToItemMatrix<ItemType::cell, ItemType::edge>(); } PASTIS_INLINE - auto cellToNodeMatrix() const + auto + cellToNodeMatrix() const { return this->template getItemToItemMatrix<ItemType::cell, ItemType::node>(); } PASTIS_INLINE - auto faceToCellMatrix() const + auto + faceToCellMatrix() const { return this->template getItemToItemMatrix<ItemType::face, ItemType::cell>(); } PASTIS_INLINE - auto faceToEdgeMatrix() const + auto + faceToEdgeMatrix() const { return this->template getItemToItemMatrix<ItemType::face, ItemType::edge>(); } PASTIS_INLINE - auto faceToNodeMatrix() const + auto + faceToNodeMatrix() const { return this->template getItemToItemMatrix<ItemType::face, ItemType::node>(); } PASTIS_INLINE - auto edgeToCellMatrix() const + auto + edgeToCellMatrix() const { return this->template getItemToItemMatrix<ItemType::edge, ItemType::cell>(); } PASTIS_INLINE - auto edgeToFaceMatrix() const + auto + edgeToFaceMatrix() const { return this->template getItemToItemMatrix<ItemType::edge, ItemType::face>(); } PASTIS_INLINE - auto edgeToNodeMatrix() const + auto + edgeToNodeMatrix() const { return this->template getItemToItemMatrix<ItemType::edge, ItemType::node>(); } PASTIS_INLINE - auto nodeToCellMatrix() const + auto + nodeToCellMatrix() const { return this->template getItemToItemMatrix<ItemType::node, ItemType::cell>(); } PASTIS_INLINE - auto nodeToFaceMatrix() const + auto + nodeToFaceMatrix() const { return this->template getItemToItemMatrix<ItemType::node, ItemType::face>(); } PASTIS_INLINE - auto nodeToEdgeMatrix() const + auto + nodeToEdgeMatrix() const { return this->template getItemToItemMatrix<ItemType::node, ItemType::edge>(); } PASTIS_INLINE - const auto& cellFaceIsReversed() const + const auto& + cellFaceIsReversed() const { - static_assert(Dimension>1, "reversed faces makes no sense in dimension 1"); + static_assert(Dimension > 1, + "reversed faces makes no sense in dimension 1"); return m_cell_face_is_reversed; } PASTIS_INLINE - const auto& faceEdgeIsReversed() const + const auto& + faceEdgeIsReversed() const { - static_assert(Dimension>2, "reversed edges makes no sense in dimension 1 or 2"); + static_assert(Dimension > 2, + "reversed edges makes no sense in dimension 1 or 2"); return m_face_edge_is_reversed; } PASTIS_INLINE - const auto& cellLocalNumbersInTheirNodes() const + const auto& + cellLocalNumbersInTheirNodes() const { - return _lazzyBuildItemNumberInTheirChild(m_cell_local_numbers_in_their_nodes); + return _lazzyBuildItemNumberInTheirChild( + m_cell_local_numbers_in_their_nodes); } PASTIS_INLINE - const auto& cellLocalNumbersInTheirEdges() const + const auto& + cellLocalNumbersInTheirEdges() const { - if constexpr (Dimension>2) { - return _lazzyBuildItemNumberInTheirChild(m_cell_local_numbers_in_their_edges); + if constexpr (Dimension > 2) { + return _lazzyBuildItemNumberInTheirChild( + m_cell_local_numbers_in_their_edges); } else { return cellLocalNumbersInTheirFaces(); } } PASTIS_INLINE - const auto& cellLocalNumbersInTheirFaces() const + const auto& + cellLocalNumbersInTheirFaces() const { - if constexpr (Dimension>1) { - return _lazzyBuildItemNumberInTheirChild(m_cell_local_numbers_in_their_faces); + if constexpr (Dimension > 1) { + return _lazzyBuildItemNumberInTheirChild( + m_cell_local_numbers_in_their_faces); } else { return cellLocalNumbersInTheirNodes(); } } PASTIS_INLINE - const auto& faceLocalNumbersInTheirCells() const + const auto& + faceLocalNumbersInTheirCells() const { - if constexpr(Dimension>1) { - return _lazzyBuildItemNumberInTheirChild(m_face_local_numbers_in_their_cells); + if constexpr (Dimension > 1) { + return _lazzyBuildItemNumberInTheirChild( + m_face_local_numbers_in_their_cells); } else { return nodeLocalNumbersInTheirCells(); } } PASTIS_INLINE - const auto& faceLocalNumbersInTheirEdges() const + const auto& + faceLocalNumbersInTheirEdges() const { - static_assert(Dimension>2,"this function has no meaning in 1d or 2d"); - return _lazzyBuildItemNumberInTheirChild(m_face_local_numbers_in_their_edges); + static_assert(Dimension > 2, "this function has no meaning in 1d or 2d"); + return _lazzyBuildItemNumberInTheirChild( + m_face_local_numbers_in_their_edges); } PASTIS_INLINE - const auto& faceLocalNumbersInTheirNodes() const + const auto& + faceLocalNumbersInTheirNodes() const { - static_assert(Dimension>1,"this function has no meaning in 1d"); - return _lazzyBuildItemNumberInTheirChild(m_face_local_numbers_in_their_nodes); + static_assert(Dimension > 1, "this function has no meaning in 1d"); + return _lazzyBuildItemNumberInTheirChild( + m_face_local_numbers_in_their_nodes); } PASTIS_INLINE - const auto& edgeLocalNumbersInTheirCells() const + const auto& + edgeLocalNumbersInTheirCells() const { - if constexpr (Dimension>2) { - return _lazzyBuildItemNumberInTheirChild(m_edge_local_numbers_in_their_cells); + if constexpr (Dimension > 2) { + return _lazzyBuildItemNumberInTheirChild( + m_edge_local_numbers_in_their_cells); } else { return faceLocalNumbersInTheirCells(); } } PASTIS_INLINE - const auto& edgeLocalNumbersInTheirFaces() const + const auto& + edgeLocalNumbersInTheirFaces() const { - static_assert(Dimension>2, "this function has no meaning in 1d or 2d"); - return _lazzyBuildItemNumberInTheirChild(m_edge_local_numbers_in_their_faces); + static_assert(Dimension > 2, "this function has no meaning in 1d or 2d"); + return _lazzyBuildItemNumberInTheirChild( + m_edge_local_numbers_in_their_faces); } PASTIS_INLINE - const auto& edgeLocalNumbersInTheirNodes() const + const auto& + edgeLocalNumbersInTheirNodes() const { - static_assert(Dimension>2, "this function has no meaning in 1d or 2d"); - return _lazzyBuildItemNumberInTheirChild(m_edge_local_numbers_in_their_nodes); + static_assert(Dimension > 2, "this function has no meaning in 1d or 2d"); + return _lazzyBuildItemNumberInTheirChild( + m_edge_local_numbers_in_their_nodes); } PASTIS_INLINE - const auto& nodeLocalNumbersInTheirCells() const + const auto& + nodeLocalNumbersInTheirCells() const { - return _lazzyBuildItemNumberInTheirChild(m_node_local_numbers_in_their_cells); + return _lazzyBuildItemNumberInTheirChild( + m_node_local_numbers_in_their_cells); } PASTIS_INLINE - const auto& nodeLocalNumbersInTheirEdges() const + const auto& + nodeLocalNumbersInTheirEdges() const { - static_assert(Dimension>2, "this function has no meaning in 1d or 2d"); - return _lazzyBuildItemNumberInTheirChild(m_node_local_numbers_in_their_edges); + static_assert(Dimension > 2, "this function has no meaning in 1d or 2d"); + return _lazzyBuildItemNumberInTheirChild( + m_node_local_numbers_in_their_edges); } PASTIS_INLINE - const auto& nodeLocalNumbersInTheirFaces() const + const auto& + nodeLocalNumbersInTheirFaces() const { - static_assert(Dimension>1,"this function has no meaning in 1d"); - return _lazzyBuildItemNumberInTheirChild(m_node_local_numbers_in_their_faces); + static_assert(Dimension > 1, "this function has no meaning in 1d"); + return _lazzyBuildItemNumberInTheirChild( + m_node_local_numbers_in_their_faces); } template <ItemType item_type> - size_t numberOfRefItemList() const + size_t + numberOfRefItemList() const { if constexpr (item_type == ItemType::cell) { return m_ref_cell_list_vector.size(); @@ -489,11 +554,11 @@ class Connectivity final } else { static_assert(is_false_item_type_v<item_type>, "Unexpected item type"); } - } template <ItemType item_type> - const RefItemList<item_type>& refItemList(const size_t& i) const + const RefItemList<item_type>& + refItemList(const size_t& i) const { if constexpr (item_type == ItemType::cell) { return m_ref_cell_list_vector[i]; @@ -509,7 +574,8 @@ class Connectivity final } template <ItemType item_type> - void addRefItemList(const RefItemList<item_type>& ref_item_list) + void + addRefItemList(const RefItemList<item_type>& ref_item_list) { if constexpr (item_type == ItemType::cell) { m_ref_cell_list_vector.push_back(ref_item_list); @@ -525,14 +591,14 @@ class Connectivity final } PASTIS_INLINE - CSRGraph cellToCellGraph() const + CSRGraph + cellToCellGraph() const { std::vector<std::set<int>> cell_cells(this->numberOfCells()); if constexpr (true) { - const auto& face_to_cell_matrix - = this->faceToCellMatrix(); + const auto& face_to_cell_matrix = this->faceToCellMatrix(); - for (FaceId l=0; l<this->numberOfFaces(); ++l) { + for (FaceId l = 0; l < this->numberOfFaces(); ++l) { const auto& face_to_cell = face_to_cell_matrix[l]; if (face_to_cell.size() > 1) { const CellId cell_0 = face_to_cell[0]; @@ -543,14 +609,13 @@ class Connectivity final } } } else { - const auto& node_to_cell_matrix - = this->nodeToCellMatrix(); + const auto& node_to_cell_matrix = this->nodeToCellMatrix(); - for (NodeId l=0; l<this->numberOfNodes(); ++l) { + for (NodeId l = 0; l < this->numberOfNodes(); ++l) { const auto& node_to_cell = node_to_cell_matrix[l]; - for (size_t i_cell=0; i_cell<node_to_cell.size(); ++i_cell) { + for (size_t i_cell = 0; i_cell < node_to_cell.size(); ++i_cell) { const CellId cell_0 = node_to_cell[i_cell]; - for (size_t j_cell=0; j_cell<i_cell; ++j_cell) { + for (size_t j_cell = 0; j_cell < i_cell; ++j_cell) { const CellId cell_1 = node_to_cell[j_cell]; cell_cells[cell_0].insert(cell_1); cell_cells[cell_1].insert(cell_0); @@ -559,15 +624,15 @@ class Connectivity final } } - Array<int> entries(this->numberOfCells()+1); - entries[0]=0; - for (size_t j=0; j<this->numberOfCells(); ++j) { - entries[j+1] = entries[j]+cell_cells[j].size(); + Array<int> entries(this->numberOfCells() + 1); + entries[0] = 0; + for (size_t j = 0; j < this->numberOfCells(); ++j) { + entries[j + 1] = entries[j] + cell_cells[j].size(); } Array<int> neighbors(entries[this->numberOfCells()]); { - size_t k=0; - for (size_t j=0; j<this->numberOfCells(); ++j) { + size_t k = 0; + for (size_t j = 0; j < this->numberOfCells(); ++j) { for (CellId cell_id : cell_cells[j]) { neighbors[k] = m_cell_global_index[cell_id]; ++k; @@ -578,49 +643,55 @@ class Connectivity final } PASTIS_INLINE - size_t numberOfNodes() const final + size_t + numberOfNodes() const final { - const auto& node_to_cell_matrix - = this->_getMatrix(ItemType::node,ItemType::cell); + const auto& node_to_cell_matrix = + this->_getMatrix(ItemType::node, ItemType::cell); return node_to_cell_matrix.numRows(); } PASTIS_INLINE - size_t numberOfEdges() const final + size_t + numberOfEdges() const final { - const auto& edge_to_node_matrix - = this->_getMatrix(ItemType::edge,ItemType::node); + const auto& edge_to_node_matrix = + this->_getMatrix(ItemType::edge, ItemType::node); return edge_to_node_matrix.numRows(); } PASTIS_INLINE - size_t numberOfFaces() const final + size_t + numberOfFaces() const final { - const auto& face_to_node_matrix - = this->_getMatrix(ItemType::face,ItemType::cell); + const auto& face_to_node_matrix = + this->_getMatrix(ItemType::face, ItemType::cell); return face_to_node_matrix.numRows(); } PASTIS_INLINE - size_t numberOfCells() const final + size_t + numberOfCells() const final { - const auto& cell_to_node_matrix - = this->_getMatrix(ItemType::cell,ItemType::node); + const auto& cell_to_node_matrix = + this->_getMatrix(ItemType::cell, ItemType::node); return cell_to_node_matrix.numRows(); } - CellValue<const double> invCellNbNodes() const + CellValue<const double> + invCellNbNodes() const { if (not m_inv_cell_nb_nodes.isBuilt()) { - const auto& cell_to_node_matrix - = m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)]; + const auto& cell_to_node_matrix = + m_item_to_item_matrix[itemTId(ItemType::cell)][itemTId(ItemType::node)]; WeakCellValue<double> inv_cell_nb_nodes(*this); parallel_for(this->numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - const auto& cell_nodes = cell_to_node_matrix.rowConst(j); - inv_cell_nb_nodes[j] = 1./cell_nodes.length; - }); - const_cast<WeakCellValue<const double>&>(m_inv_cell_nb_nodes) = inv_cell_nb_nodes; + const auto& cell_nodes = cell_to_node_matrix.rowConst(j); + inv_cell_nb_nodes[j] = 1. / cell_nodes.length; + }); + const_cast<WeakCellValue<const double>&>(m_inv_cell_nb_nodes) = + inv_cell_nb_nodes; } return m_inv_cell_nb_nodes; @@ -641,8 +712,7 @@ class Connectivity final }; template <size_t Dim> -PASTIS_INLINE -std::shared_ptr<Connectivity<Dim>> +PASTIS_INLINE std::shared_ptr<Connectivity<Dim>> Connectivity<Dim>::build(const ConnectivityDescriptor& descriptor) { std::shared_ptr<Connectivity<Dim>> connectivity_ptr(new Connectivity<Dim>); @@ -655,4 +725,4 @@ using Connectivity3D = Connectivity<3>; using Connectivity2D = Connectivity<2>; using Connectivity1D = Connectivity<1>; -#endif // CONNECTIVITY_HPP +#endif // CONNECTIVITY_HPP diff --git a/src/mesh/ConnectivityComputer.cpp b/src/mesh/ConnectivityComputer.cpp index 294b15591..226ae3ac9 100644 --- a/src/mesh/ConnectivityComputer.cpp +++ b/src/mesh/ConnectivityComputer.cpp @@ -3,62 +3,62 @@ #include <ConnectivityComputer.hpp> #include <map> - template <typename ConnectivityType> -PASTIS_INLINE -ConnectivityMatrix ConnectivityComputer:: -computeConnectivityMatrix(const ConnectivityType& connectivity, - const ItemType& item_type, - const ItemType& child_item_type) const +PASTIS_INLINE ConnectivityMatrix +ConnectivityComputer::computeConnectivityMatrix( + const ConnectivityType& connectivity, + const ItemType& item_type, + const ItemType& child_item_type) const { ConnectivityMatrix item_to_child_item_matrix; if (connectivity.isConnectivityMatrixBuilt(child_item_type, item_type)) { - const ConnectivityMatrix& child_to_item_matrix - = connectivity._getMatrix(child_item_type, item_type); + const ConnectivityMatrix& child_to_item_matrix = + connectivity._getMatrix(child_item_type, item_type); - pout() << "computing connectivity " - << itemName(item_type) << " -> " << itemName(child_item_type) << '\n'; + pout() << "computing connectivity " << itemName(item_type) << " -> " + << itemName(child_item_type) << '\n'; - item_to_child_item_matrix - = this->_computeInverse(child_to_item_matrix); + item_to_child_item_matrix = this->_computeInverse(child_to_item_matrix); } else { - perr() << "unable to compute connectivity " - << itemName(item_type) << " -> " << itemName(child_item_type) << '\n'; + perr() << "unable to compute connectivity " << itemName(item_type) << " -> " + << itemName(child_item_type) << '\n'; std::terminate(); } return item_to_child_item_matrix; } -template -ConnectivityMatrix ConnectivityComputer:: -computeConnectivityMatrix(const Connectivity1D&, const ItemType&, const ItemType&) const; - -template -ConnectivityMatrix ConnectivityComputer:: -computeConnectivityMatrix(const Connectivity2D&, const ItemType&, const ItemType&) const; +template ConnectivityMatrix ConnectivityComputer::computeConnectivityMatrix( + const Connectivity1D&, + const ItemType&, + const ItemType&) const; +template ConnectivityMatrix ConnectivityComputer::computeConnectivityMatrix( + const Connectivity2D&, + const ItemType&, + const ItemType&) const; -template -ConnectivityMatrix ConnectivityComputer:: -computeConnectivityMatrix(const Connectivity3D&, const ItemType&, const ItemType&) const; +template ConnectivityMatrix ConnectivityComputer::computeConnectivityMatrix( + const Connectivity3D&, + const ItemType&, + const ItemType&) const; ConnectivityMatrix -ConnectivityComputer:: -_computeInverse(const ConnectivityMatrix& item_to_child_matrix) const +ConnectivityComputer::_computeInverse( + const ConnectivityMatrix& item_to_child_matrix) const { std::map<unsigned int, std::vector<unsigned int>> child_to_item_vector_map; const size_t& number_of_items = item_to_child_matrix.numRows(); - for (unsigned int j=0; j<number_of_items; ++j) { + for (unsigned int j = 0; j < number_of_items; ++j) { const auto& item_to_child = item_to_child_matrix.rowConst(j); - for (unsigned int r=0; r<item_to_child.length; ++r) { + for (unsigned int r = 0; r < item_to_child.length; ++r) { child_to_item_vector_map[item_to_child(r)].push_back(j); } } { - size_t i=0; + size_t i = 0; for (const auto& [child_item_id, item_vector] : child_to_item_vector_map) { if (child_item_id != i) { perr() << "sparse item numerotation NIY\n"; @@ -68,7 +68,8 @@ _computeInverse(const ConnectivityMatrix& item_to_child_matrix) const } } - std::vector<std::vector<unsigned int>> child_to_items_vector(child_to_item_vector_map.size()); + std::vector<std::vector<unsigned int>> child_to_items_vector( + child_to_item_vector_map.size()); for (const auto& [child_item_id, item_vector] : child_to_item_vector_map) { child_to_items_vector[child_item_id] = item_vector; } @@ -76,31 +77,33 @@ _computeInverse(const ConnectivityMatrix& item_to_child_matrix) const return ConnectivityMatrix(child_to_items_vector); } -template <typename ItemOfItem, - typename ConnectivityType> +template <typename ItemOfItem, typename ConnectivityType> WeakSubItemValuePerItem<const unsigned short, typename ItemOfItem::Reversed> -ConnectivityComputer::computeLocalItemNumberInChildItem(const ConnectivityType& connectivity) const +ConnectivityComputer::computeLocalItemNumberInChildItem( + const ConnectivityType& connectivity) const { using ReversedItemOfItem = typename ItemOfItem::Reversed; - constexpr ItemType item_type = ReversedItemOfItem::item_type; + constexpr ItemType item_type = ReversedItemOfItem::item_type; constexpr ItemType child_item_type = ReversedItemOfItem::sub_item_type; - const ConnectivityMatrix& child_item_to_items_matrix - = connectivity._getMatrix(child_item_type, item_type); - const ConnectivityMatrix& item_to_child_items_matrix - = connectivity._getMatrix(item_type, child_item_type); + const ConnectivityMatrix& child_item_to_items_matrix = + connectivity._getMatrix(child_item_type, item_type); + const ConnectivityMatrix& item_to_child_items_matrix = + connectivity._getMatrix(item_type, child_item_type); - WeakSubItemValuePerItem<unsigned short, ReversedItemOfItem> item_number_in_child_item(connectivity); - for (ItemIdT<item_type> r=0; r<item_to_child_items_matrix.numRows(); ++r) { + WeakSubItemValuePerItem<unsigned short, ReversedItemOfItem> + item_number_in_child_item(connectivity); + for (ItemIdT<item_type> r = 0; r < item_to_child_items_matrix.numRows(); + ++r) { const auto& item_to_child_items = item_to_child_items_matrix.rowConst(r); - for (unsigned short J=0; J<item_to_child_items.length; ++J) { - const unsigned int j = item_to_child_items(J); + for (unsigned short J = 0; J < item_to_child_items.length; ++J) { + const unsigned int j = item_to_child_items(J); const auto& child_item_to_items = child_item_to_items_matrix.rowConst(j); - for (unsigned int R=0; R<child_item_to_items.length; ++R) { + for (unsigned int R = 0; R < child_item_to_items.length; ++R) { if (child_item_to_items(R) == r) { - item_number_in_child_item(r,J) = R; + item_number_in_child_item(r, J) = R; break; } } @@ -113,88 +116,85 @@ ConnectivityComputer::computeLocalItemNumberInChildItem(const ConnectivityType& // 1D template WeakSubItemValuePerItem<const unsigned short, CellOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfCell>(const Connectivity1D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfCell>( + const Connectivity1D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfNode>(const Connectivity1D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfNode>( + const Connectivity1D&) const; // 2D template WeakSubItemValuePerItem<const unsigned short, CellOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfCell>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfCell>( + const Connectivity2D&) const; template WeakSubItemValuePerItem<const unsigned short, CellOfFace> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<FaceOfCell>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<FaceOfCell>( + const Connectivity2D&) const; template WeakSubItemValuePerItem<const unsigned short, FaceOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfFace>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfFace>( + const Connectivity2D&) const; template WeakSubItemValuePerItem<const unsigned short, FaceOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfFace>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfFace>( + const Connectivity2D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfFace> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<FaceOfNode>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<FaceOfNode>( + const Connectivity2D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfNode>(const Connectivity2D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfNode>( + const Connectivity2D&) const; // 3D template WeakSubItemValuePerItem<const unsigned short, CellOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfCell>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfCell>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, CellOfEdge> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<EdgeOfCell>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<EdgeOfCell>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, CellOfFace> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<FaceOfCell>(const Connectivity3D&) const; - +ConnectivityComputer::computeLocalItemNumberInChildItem<FaceOfCell>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, FaceOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfFace>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfFace>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, FaceOfEdge> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<EdgeOfFace>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<EdgeOfFace>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, FaceOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfFace>(const Connectivity3D&) const; - +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfFace>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, EdgeOfNode> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<NodeOfEdge>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<NodeOfEdge>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, EdgeOfFace> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<FaceOfEdge>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<FaceOfEdge>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, EdgeOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfEdge>(const Connectivity3D&) const; - +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfEdge>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfEdge> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<EdgeOfNode>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<EdgeOfNode>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfFace> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<FaceOfNode>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<FaceOfNode>( + const Connectivity3D&) const; template WeakSubItemValuePerItem<const unsigned short, NodeOfCell> -ConnectivityComputer:: -computeLocalItemNumberInChildItem<CellOfNode>(const Connectivity3D&) const; +ConnectivityComputer::computeLocalItemNumberInChildItem<CellOfNode>( + const Connectivity3D&) const; diff --git a/src/mesh/ConnectivityComputer.hpp b/src/mesh/ConnectivityComputer.hpp index d5c6019d5..183f513ae 100644 --- a/src/mesh/ConnectivityComputer.hpp +++ b/src/mesh/ConnectivityComputer.hpp @@ -7,25 +7,23 @@ class ConnectivityComputer { private: - ConnectivityMatrix - _computeInverse(const ConnectivityMatrix& item_to_child_matrix) const; + ConnectivityMatrix _computeInverse( + const ConnectivityMatrix& item_to_child_matrix) const; public: template <typename ConnectivityType> - ConnectivityMatrix - computeConnectivityMatrix(const ConnectivityType& connectivity, - const ItemType& item_type, - const ItemType& child_item_type) const; + ConnectivityMatrix computeConnectivityMatrix( + const ConnectivityType& connectivity, + const ItemType& item_type, + const ItemType& child_item_type) const; - - template <typename ItemOfItem, - typename ConnectivityType> + template <typename ItemOfItem, typename ConnectivityType> WeakSubItemValuePerItem<const unsigned short, typename ItemOfItem::Reversed> computeLocalItemNumberInChildItem(const ConnectivityType& connectivity) const; ConnectivityComputer(const ConnectivityComputer&) = default; - ConnectivityComputer() = default; - ~ConnectivityComputer() = default; + ConnectivityComputer() = default; + ~ConnectivityComputer() = default; }; -#endif // CONNECTIVITY_COMPUTER_HPP +#endif // CONNECTIVITY_COMPUTER_HPP diff --git a/src/mesh/ConnectivityDescriptor.hpp b/src/mesh/ConnectivityDescriptor.hpp index e20b05c11..b6e6bac83 100644 --- a/src/mesh/ConnectivityDescriptor.hpp +++ b/src/mesh/ConnectivityDescriptor.hpp @@ -1,9 +1,9 @@ #ifndef CONNECTIVITY_DESCRIPTOR_HPP #define CONNECTIVITY_DESCRIPTOR_HPP -#include <RefItemList.hpp> -#include <PastisTraits.hpp> #include <ItemOfItemType.hpp> +#include <PastisTraits.hpp> +#include <RefItemList.hpp> #include <vector> @@ -26,19 +26,20 @@ class ConnectivityDescriptor std::vector<std::vector<unsigned int>> edge_to_node_vector; template <typename ItemOfItemT> - auto& itemOfItemVector() + auto& + itemOfItemVector() { - if constexpr (std::is_same_v<ItemOfItemT,NodeOfCell>) { + if constexpr (std::is_same_v<ItemOfItemT, NodeOfCell>) { return cell_to_node_vector; - } else if constexpr (std::is_same_v<ItemOfItemT,FaceOfCell>) { + } else if constexpr (std::is_same_v<ItemOfItemT, FaceOfCell>) { return cell_to_face_vector; - } else if constexpr (std::is_same_v<ItemOfItemT,EdgeOfCell>) { + } else if constexpr (std::is_same_v<ItemOfItemT, EdgeOfCell>) { return cell_to_edge_vector; - } else if constexpr (std::is_same_v<ItemOfItemT,EdgeOfFace>) { + } else if constexpr (std::is_same_v<ItemOfItemT, EdgeOfFace>) { return face_to_edge_vector; - } else if constexpr (std::is_same_v<ItemOfItemT,NodeOfFace>) { + } else if constexpr (std::is_same_v<ItemOfItemT, NodeOfFace>) { return face_to_node_vector; - } else if constexpr (std::is_same_v<ItemOfItemT,NodeOfEdge>) { + } else if constexpr (std::is_same_v<ItemOfItemT, NodeOfEdge>) { return edge_to_node_vector; } else { static_assert(is_false_v<ItemOfItemT>, "Unexpected item of item type"); @@ -56,7 +57,8 @@ class ConnectivityDescriptor std::vector<int> node_number_vector; template <ItemType item_type> - const std::vector<int>& itemNumberVector() const + const std::vector<int>& + itemNumberVector() const { if constexpr (item_type == ItemType::cell) { return cell_number_vector; @@ -77,7 +79,8 @@ class ConnectivityDescriptor std::vector<int> node_owner_vector; template <ItemType item_type> - const std::vector<RefItemList<item_type>>& refItemListVector() const + const std::vector<RefItemList<item_type>>& + refItemListVector() const { if constexpr (item_type == ItemType::cell) { return m_ref_cell_list_vector; @@ -93,7 +96,8 @@ class ConnectivityDescriptor } template <ItemType item_type> - void addRefItemList(const RefItemList<item_type>& ref_item_list) + void + addRefItemList(const RefItemList<item_type>& ref_item_list) { if constexpr (item_type == ItemType::cell) { m_ref_cell_list_vector.push_back(ref_item_list); @@ -111,11 +115,10 @@ class ConnectivityDescriptor ConnectivityDescriptor& operator=(const ConnectivityDescriptor&) = delete; ConnectivityDescriptor& operator=(ConnectivityDescriptor&&) = delete; - ConnectivityDescriptor() = default; + ConnectivityDescriptor() = default; ConnectivityDescriptor(const ConnectivityDescriptor&) = default; - ConnectivityDescriptor(ConnectivityDescriptor&&) = delete; - ~ConnectivityDescriptor() = default; + ConnectivityDescriptor(ConnectivityDescriptor&&) = delete; + ~ConnectivityDescriptor() = default; }; - -#endif // CONNECTIVITY_DESCRIPTOR_HPP +#endif // CONNECTIVITY_DESCRIPTOR_HPP diff --git a/src/mesh/ConnectivityDispatcher.cpp b/src/mesh/ConnectivityDispatcher.cpp index aa26cb6f7..95825d6cb 100644 --- a/src/mesh/ConnectivityDispatcher.cpp +++ b/src/mesh/ConnectivityDispatcher.cpp @@ -19,26 +19,27 @@ ConnectivityDispatcher<Dimension>::_buildNewOwner() this->_dispatchedInfo<ItemType::cell>().m_new_owner = cell_new_owner; } else { - const auto& item_to_cell_matrix - = m_connectivity.template getItemToItemMatrix<item_type,ItemType::cell>(); + const auto& item_to_cell_matrix = + m_connectivity.template getItemToItemMatrix<item_type, ItemType::cell>(); const auto& cell_number = m_connectivity.cellNumber(); - const auto& cell_new_owner = this->_dispatchedInfo<ItemType::cell>().m_new_owner; + const auto& cell_new_owner = + this->_dispatchedInfo<ItemType::cell>().m_new_owner; using ItemId = ItemIdT<item_type>; ItemValue<int, item_type> item_new_owner(m_connectivity); parallel_for(item_new_owner.size(), PASTIS_LAMBDA(const ItemId& l) { - const auto& item_to_cell = item_to_cell_matrix[l]; - CellId Jmin = item_to_cell[0]; + const auto& item_to_cell = item_to_cell_matrix[l]; + CellId Jmin = item_to_cell[0]; - for (size_t j=1; j<item_to_cell.size(); ++j) { - const CellId J = item_to_cell[j]; - if (cell_number[J] < cell_number[Jmin]) { - Jmin=J; - } + for (size_t j = 1; j < item_to_cell.size(); ++j) { + const CellId J = item_to_cell[j]; + if (cell_number[J] < cell_number[Jmin]) { + Jmin = J; } - item_new_owner[l] = cell_new_owner[Jmin]; - }); + } + item_new_owner[l] = cell_new_owner[Jmin]; + }); synchronize(item_new_owner); this->_dispatchedInfo<item_type>().m_new_owner = item_new_owner; @@ -47,8 +48,8 @@ ConnectivityDispatcher<Dimension>::_buildNewOwner() template <int Dimension> template <ItemType item_type> -void ConnectivityDispatcher<Dimension>:: -_buildItemToExchangeLists() +void +ConnectivityDispatcher<Dimension>::_buildItemToExchangeLists() { this->_buildItemListToSend<item_type>(); this->_buildNumberOfItemToExchange<item_type>(); @@ -64,57 +65,62 @@ void ConnectivityDispatcher<Dimension>::_buildItemListToSend() { if constexpr (item_type == ItemType::cell) { - const auto& node_to_cell_matrix - = m_connectivity.nodeToCellMatrix(); - const auto& cell_to_node_matrix - = m_connectivity.cellToNodeMatrix(); + const auto& node_to_cell_matrix = m_connectivity.nodeToCellMatrix(); + const auto& cell_to_node_matrix = m_connectivity.cellToNodeMatrix(); - const auto& cell_new_owner = this->_dispatchedInfo<ItemType::cell>().m_new_owner; + const auto& cell_new_owner = + this->_dispatchedInfo<ItemType::cell>().m_new_owner; - std::vector<std::vector<CellId>> cell_vector_to_send_by_proc(parallel::size()); + std::vector<std::vector<CellId>> cell_vector_to_send_by_proc( + parallel::size()); Array<bool> send_to_rank(parallel::size()); - for (CellId j=0; j<m_connectivity.numberOfCells(); ++j) { + for (CellId j = 0; j < m_connectivity.numberOfCells(); ++j) { send_to_rank.fill(false); const auto& cell_to_node = cell_to_node_matrix[j]; - for (size_t R=0; R<cell_to_node.size(); ++R) { - const NodeId& r = cell_to_node[R]; + for (size_t R = 0; R < cell_to_node.size(); ++R) { + const NodeId& r = cell_to_node[R]; const auto& node_to_cell = node_to_cell_matrix[r]; - for (size_t K=0; K<node_to_cell.size(); ++K) { - const CellId& k = node_to_cell[K]; + for (size_t K = 0; K < node_to_cell.size(); ++K) { + const CellId& k = node_to_cell[K]; send_to_rank[cell_new_owner[k]] = true; } } - for (size_t k=0; k<send_to_rank.size(); ++k) { + for (size_t k = 0; k < send_to_rank.size(); ++k) { if (send_to_rank[k]) { cell_vector_to_send_by_proc[k].push_back(j); } } } - auto& cell_list_to_send_by_proc = this->_dispatchedInfo<ItemType::cell>().m_list_to_send_by_proc; + auto& cell_list_to_send_by_proc = + this->_dispatchedInfo<ItemType::cell>().m_list_to_send_by_proc; cell_list_to_send_by_proc.resize(parallel::size()); - for (size_t i=0; i<parallel::size(); ++i) { - cell_list_to_send_by_proc[i] = convert_to_array(cell_vector_to_send_by_proc[i]); + for (size_t i = 0; i < parallel::size(); ++i) { + cell_list_to_send_by_proc[i] = + convert_to_array(cell_vector_to_send_by_proc[i]); } } else { - const auto& cell_list_to_send_by_proc = this->_dispatchedInfo<ItemType::cell>().m_list_to_send_by_proc; + const auto& cell_list_to_send_by_proc = + this->_dispatchedInfo<ItemType::cell>().m_list_to_send_by_proc; using ItemId = ItemIdT<item_type>; - const auto& cell_to_sub_item_matrix = m_connectivity.template getItemToItemMatrix<ItemType::cell,item_type>(); + const auto& cell_to_sub_item_matrix = + m_connectivity.template getItemToItemMatrix<ItemType::cell, item_type>(); - auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; item_list_to_send_by_proc.resize(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { Array<bool> tag(m_connectivity.template numberOf<item_type>()); tag.fill(false); std::vector<ItemId> item_id_vector; - for (size_t j=0; j<cell_list_to_send_by_proc[i_rank].size(); ++j) { - const CellId& cell_id = cell_list_to_send_by_proc[i_rank][j]; + for (size_t j = 0; j < cell_list_to_send_by_proc[i_rank].size(); ++j) { + const CellId& cell_id = cell_list_to_send_by_proc[i_rank][j]; const auto& cell_sub_item_list = cell_to_sub_item_matrix[cell_id]; - for (size_t r=0; r<cell_sub_item_list.size(); ++r) { + for (size_t r = 0; r < cell_sub_item_list.size(); ++r) { const ItemId& item_id = cell_sub_item_list[r]; if (not tag[item_id]) { item_id_vector.push_back(item_id); @@ -132,61 +138,69 @@ template <ItemType item_type> void ConnectivityDispatcher<Dimension>::_buildNumberOfItemToExchange() { - const auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; Array<unsigned int> nb_item_to_send_by_proc(parallel::size()); - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { nb_item_to_send_by_proc[i] = item_list_to_send_by_proc[i].size(); } - this->_dispatchedInfo<item_type>().m_list_to_send_size_by_proc = nb_item_to_send_by_proc; + this->_dispatchedInfo<item_type>().m_list_to_send_size_by_proc = + nb_item_to_send_by_proc; - this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc - = parallel::allToAll(nb_item_to_send_by_proc); + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc = + parallel::allToAll(nb_item_to_send_by_proc); } - template <int Dimension> -template<typename DataType, ItemType item_type, typename ConnectivityPtr> +template <typename DataType, ItemType item_type, typename ConnectivityPtr> void -ConnectivityDispatcher<Dimension>:: -_gatherFrom(const ItemValue<DataType, item_type, ConnectivityPtr>& data_to_gather, - std::vector<std::remove_const_t<DataType>>& gathered_vector) +ConnectivityDispatcher<Dimension>::_gatherFrom( + const ItemValue<DataType, item_type, ConnectivityPtr>& data_to_gather, + std::vector<std::remove_const_t<DataType>>& gathered_vector) { - std::vector<Array<const DataType>> recv_item_data_by_proc = this->exchange(data_to_gather); - - const auto& recv_id_correspondance_by_proc = this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; - Assert(recv_id_correspondance_by_proc.size()==parallel::size()); - - gathered_vector.resize(this->_dispatchedInfo<item_type>().m_number_to_id_map.size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - Assert(recv_id_correspondance_by_proc[i_rank].size()==recv_item_data_by_proc[i_rank].size()); - for (size_t r=0; r<recv_id_correspondance_by_proc[i_rank].size(); ++r) { - const auto& item_id = recv_id_correspondance_by_proc[i_rank][r]; + std::vector<Array<const DataType>> recv_item_data_by_proc = + this->exchange(data_to_gather); + + const auto& recv_id_correspondance_by_proc = + this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; + Assert(recv_id_correspondance_by_proc.size() == parallel::size()); + + gathered_vector.resize( + this->_dispatchedInfo<item_type>().m_number_to_id_map.size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + Assert(recv_id_correspondance_by_proc[i_rank].size() == + recv_item_data_by_proc[i_rank].size()); + for (size_t r = 0; r < recv_id_correspondance_by_proc[i_rank].size(); ++r) { + const auto& item_id = recv_id_correspondance_by_proc[i_rank][r]; gathered_vector[item_id] = recv_item_data_by_proc[i_rank][r]; } } } template <int Dimension> -template<typename DataType, typename ItemOfItem, typename ConnectivityPtr> -void ConnectivityDispatcher<Dimension>:: -_gatherFrom(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& data_to_gather, - std::vector<Array<std::remove_const_t<DataType>>>& gathered_vector) +template <typename DataType, typename ItemOfItem, typename ConnectivityPtr> +void +ConnectivityDispatcher<Dimension>::_gatherFrom( + const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& + data_to_gather, + std::vector<Array<std::remove_const_t<DataType>>>& gathered_vector) { using MutableDataType = std::remove_const_t<DataType>; constexpr ItemType item_type = ItemOfItem::item_type; - using ItemId = ItemIdT<item_type>; + using ItemId = ItemIdT<item_type>; - const auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; std::vector<Array<MutableDataType>> data_to_send_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { std::vector<MutableDataType> data_by_item_vector; - for (size_t j=0; j<item_list_to_send_by_proc[i_rank].size(); ++j) { + for (size_t j = 0; j < item_list_to_send_by_proc[i_rank].size(); ++j) { const ItemId& item_id = item_list_to_send_by_proc[i_rank][j]; const auto& item_data = data_to_gather.itemValues(item_id); - for (size_t l=0; l<item_data.size(); ++l) { + for (size_t l = 0; l < item_data.size(); ++l) { data_by_item_vector.push_back(item_data[l]); } } @@ -194,24 +208,27 @@ _gatherFrom(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& da } const auto& number_of_sub_item_per_item_to_recv_by_proc = - this->_dispatchedInfo<ItemOfItem>().m_number_of_sub_item_per_item_to_recv_by_proc; - - std::vector<Array<MutableDataType>> recv_data_to_gather_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - recv_data_to_gather_by_proc[i_rank] - = Array<MutableDataType>(sum(number_of_sub_item_per_item_to_recv_by_proc[i_rank])); + this->_dispatchedInfo<ItemOfItem>() + .m_number_of_sub_item_per_item_to_recv_by_proc; + + std::vector<Array<MutableDataType>> recv_data_to_gather_by_proc( + parallel::size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + recv_data_to_gather_by_proc[i_rank] = Array<MutableDataType>( + sum(number_of_sub_item_per_item_to_recv_by_proc[i_rank])); } parallel::exchange(data_to_send_by_proc, recv_data_to_gather_by_proc); const auto& item_list_to_recv_size_by_proc = - this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; - - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - int l=0; - for (size_t i=0; i<item_list_to_recv_size_by_proc[i_rank]; ++i) { - Array<MutableDataType> data_vector(number_of_sub_item_per_item_to_recv_by_proc[i_rank][i]); - for (size_t k=0; k<data_vector.size(); ++k) { + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; + + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + int l = 0; + for (size_t i = 0; i < item_list_to_recv_size_by_proc[i_rank]; ++i) { + Array<MutableDataType> data_vector( + number_of_sub_item_per_item_to_recv_by_proc[i_rank][i]); + for (size_t k = 0; k < data_vector.size(); ++k) { data_vector[k] = recv_data_to_gather_by_proc[i_rank][l++]; } gathered_vector.emplace_back(data_vector); @@ -221,17 +238,20 @@ _gatherFrom(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& da template <int Dimension> void -ConnectivityDispatcher<Dimension>:: -_buildCellNumberIdMap() +ConnectivityDispatcher<Dimension>::_buildCellNumberIdMap() { - const auto recv_cell_number_by_proc = this->exchange(m_connectivity.template number<ItemType::cell>()); - auto& cell_number_id_map = this->_dispatchedInfo<ItemType::cell>().m_number_to_id_map; - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - CellId cell_id=0; - for (size_t i=0; i<recv_cell_number_by_proc[i_rank].size(); ++i) { + const auto recv_cell_number_by_proc = + this->exchange(m_connectivity.template number<ItemType::cell>()); + auto& cell_number_id_map = + this->_dispatchedInfo<ItemType::cell>().m_number_to_id_map; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + CellId cell_id = 0; + for (size_t i = 0; i < recv_cell_number_by_proc[i_rank].size(); ++i) { const int cell_number = recv_cell_number_by_proc[i_rank][i]; - auto [iterator, inserted] = cell_number_id_map.insert(std::make_pair(cell_number, cell_id)); - if (inserted) ++cell_id; + auto [iterator, inserted] = + cell_number_id_map.insert(std::make_pair(cell_number, cell_id)); + if (inserted) + ++cell_id; } } } @@ -241,18 +261,24 @@ template <typename ItemOfItemT> void ConnectivityDispatcher<Dimension>::_buildSubItemNumberToIdMap() { - static_assert(ItemOfItemT::item_type == ItemType::cell, "Dispatcher requires to be built using cell as master entities"); - - const auto& cell_sub_item_number_to_recv_by_proc - = this->_dispatchedInfo<ItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; - - 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) { - int sub_item_id=0; - for (size_t i=0; i<cell_sub_item_number_to_recv_by_proc[i_rank].size(); ++i) { + static_assert( + ItemOfItemT::item_type == ItemType::cell, + "Dispatcher requires to be built using cell as master entities"); + + const auto& cell_sub_item_number_to_recv_by_proc = + this->_dispatchedInfo<ItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; + + 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) { + int sub_item_id = 0; + for (size_t i = 0; i < cell_sub_item_number_to_recv_by_proc[i_rank].size(); + ++i) { int sub_item_number = cell_sub_item_number_to_recv_by_proc[i_rank][i]; - auto [iterator, inserted] = sub_item_number_id_map.insert(std::make_pair(sub_item_number, sub_item_id)); - if (inserted) sub_item_id++; + auto [iterator, inserted] = sub_item_number_id_map.insert( + std::make_pair(sub_item_number, sub_item_id)); + if (inserted) + sub_item_id++; } } } @@ -262,19 +288,22 @@ template <typename SubItemOfItemT> void ConnectivityDispatcher<Dimension>::_buildNumberOfSubItemPerItemToRecvByProc() { - const auto& item_to_sub_item_matrix - = m_connectivity.template getItemToItemMatrix<SubItemOfItemT::item_type, - SubItemOfItemT::sub_item_type>(); + const auto& item_to_sub_item_matrix = + m_connectivity.template getItemToItemMatrix< + SubItemOfItemT::item_type, SubItemOfItemT::sub_item_type>(); - ItemValue<int, SubItemOfItemT::item_type> number_of_sub_item_per_item(m_connectivity); + ItemValue<int, SubItemOfItemT::item_type> number_of_sub_item_per_item( + m_connectivity); using ItemId = ItemIdT<SubItemOfItemT::item_type>; - parallel_for(number_of_sub_item_per_item.size(), PASTIS_LAMBDA(const ItemId& j){ + parallel_for( + number_of_sub_item_per_item.size(), PASTIS_LAMBDA(const ItemId& j) { number_of_sub_item_per_item[j] = item_to_sub_item_matrix[j].size(); }); - this->_dispatchedInfo<SubItemOfItemT>().m_number_of_sub_item_per_item_to_recv_by_proc = - this->exchange(number_of_sub_item_per_item); + this->_dispatchedInfo<SubItemOfItemT>() + .m_number_of_sub_item_per_item_to_recv_by_proc = + this->exchange(number_of_sub_item_per_item); } template <int Dimension> @@ -282,52 +311,59 @@ template <typename SubItemOfItemT> void ConnectivityDispatcher<Dimension>::_buildSubItemNumbersToRecvByProc() { - const std::vector<Array<const int>> sub_item_numbers_to_send_by_proc = - [&] () { - const auto& item_to_sub_item_matrix - = m_connectivity.template getItemToItemMatrix<SubItemOfItemT::item_type, - SubItemOfItemT::sub_item_type>(); - - const auto& sub_item_number = m_connectivity.template number<SubItemOfItemT::sub_item_type>(); - - using ItemId = ItemIdT<SubItemOfItemT::item_type>; - using SubItemId = ItemIdT<SubItemOfItemT::sub_item_type>; - - std::vector<Array<const int>> sub_item_numbers_to_send_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - const auto& item_list_to_send_by_proc - = this->_dispatchedInfo<SubItemOfItemT::item_type>().m_list_to_send_by_proc; - - std::vector<int> sub_item_numbers_by_item_vector; - for (size_t j=0; j<item_list_to_send_by_proc[i_rank].size(); ++j) { - const ItemId& item_id = item_list_to_send_by_proc[i_rank][j]; - const auto& sub_item_list = item_to_sub_item_matrix[item_id]; - for (size_t r=0; r<sub_item_list.size(); ++r) { - const SubItemId& sub_item_id = sub_item_list[r]; - sub_item_numbers_by_item_vector.push_back(sub_item_number[sub_item_id]); - } - } - sub_item_numbers_to_send_by_proc[i_rank] = convert_to_array(sub_item_numbers_by_item_vector); + const std::vector<Array<const int>> sub_item_numbers_to_send_by_proc = [&]() { + const auto& item_to_sub_item_matrix = + m_connectivity.template getItemToItemMatrix< + SubItemOfItemT::item_type, SubItemOfItemT::sub_item_type>(); + + const auto& sub_item_number = + m_connectivity.template number<SubItemOfItemT::sub_item_type>(); + + using ItemId = ItemIdT<SubItemOfItemT::item_type>; + using SubItemId = ItemIdT<SubItemOfItemT::sub_item_type>; + + std::vector<Array<const int>> sub_item_numbers_to_send_by_proc( + parallel::size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<SubItemOfItemT::item_type>() + .m_list_to_send_by_proc; + + std::vector<int> sub_item_numbers_by_item_vector; + for (size_t j = 0; j < item_list_to_send_by_proc[i_rank].size(); ++j) { + const ItemId& item_id = item_list_to_send_by_proc[i_rank][j]; + const auto& sub_item_list = item_to_sub_item_matrix[item_id]; + for (size_t r = 0; r < sub_item_list.size(); ++r) { + const SubItemId& sub_item_id = sub_item_list[r]; + sub_item_numbers_by_item_vector.push_back( + sub_item_number[sub_item_id]); } - return sub_item_numbers_to_send_by_proc; - } (); + } + sub_item_numbers_to_send_by_proc[i_rank] = + convert_to_array(sub_item_numbers_by_item_vector); + } + return sub_item_numbers_to_send_by_proc; + }(); const auto& number_of_sub_item_per_item_to_recv_by_proc = - this->_dispatchedInfo<SubItemOfItemT>().m_number_of_sub_item_per_item_to_recv_by_proc; + this->_dispatchedInfo<SubItemOfItemT>() + .m_number_of_sub_item_per_item_to_recv_by_proc; std::vector<Array<int>> sub_item_numbers_to_recv_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - sub_item_numbers_to_recv_by_proc[i_rank] - = Array<int>(sum(number_of_sub_item_per_item_to_recv_by_proc[i_rank])); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + sub_item_numbers_to_recv_by_proc[i_rank] = + Array<int>(sum(number_of_sub_item_per_item_to_recv_by_proc[i_rank])); } - parallel::exchange(sub_item_numbers_to_send_by_proc, sub_item_numbers_to_recv_by_proc); + parallel::exchange(sub_item_numbers_to_send_by_proc, + sub_item_numbers_to_recv_by_proc); auto& const_sub_item_numbers_to_recv_by_proc = - this->_dispatchedInfo<SubItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; + this->_dispatchedInfo<SubItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; const_sub_item_numbers_to_recv_by_proc.resize(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - const_sub_item_numbers_to_recv_by_proc[i_rank] = sub_item_numbers_to_recv_by_proc[i_rank]; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + const_sub_item_numbers_to_recv_by_proc[i_rank] = + sub_item_numbers_to_recv_by_proc[i_rank]; } } @@ -336,32 +372,35 @@ template <typename ItemOfItemT> void ConnectivityDispatcher<Dimension>::_buildItemToSubItemDescriptor() { - constexpr ItemType item_type = ItemOfItemT::item_type; + constexpr ItemType item_type = ItemOfItemT::item_type; constexpr ItemType sub_item_type = ItemOfItemT::sub_item_type; const auto& item_list_to_recv_size_by_proc = - this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; const auto& number_of_sub_item_per_item_to_recv_by_proc = - this->_dispatchedInfo<ItemOfItemT>().m_number_of_sub_item_per_item_to_recv_by_proc; + this->_dispatchedInfo<ItemOfItemT>() + .m_number_of_sub_item_per_item_to_recv_by_proc; const auto& sub_item_number_id_map = - this->_dispatchedInfo<sub_item_type>().m_number_to_id_map; + this->_dispatchedInfo<sub_item_type>().m_number_to_id_map; const auto& recv_item_of_item_numbers_by_proc = - this->_dispatchedInfo<ItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; + this->_dispatchedInfo<ItemOfItemT>().m_sub_item_numbers_to_recv_by_proc; - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - int l=0; - for (size_t i=0; i<item_list_to_recv_size_by_proc[i_rank]; ++i) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + int l = 0; + for (size_t i = 0; i < item_list_to_recv_size_by_proc[i_rank]; ++i) { std::vector<unsigned int> sub_item_vector; - for (int k=0; k<number_of_sub_item_per_item_to_recv_by_proc[i_rank][i]; ++k) { - const auto& searched_sub_item_id = - sub_item_number_id_map.find(recv_item_of_item_numbers_by_proc[i_rank][l++]); + for (int k = 0; + k < number_of_sub_item_per_item_to_recv_by_proc[i_rank][i]; ++k) { + const auto& searched_sub_item_id = sub_item_number_id_map.find( + recv_item_of_item_numbers_by_proc[i_rank][l++]); Assert(searched_sub_item_id != sub_item_number_id_map.end()); sub_item_vector.push_back(searched_sub_item_id->second); } - m_new_descriptor.itemOfItemVector<ItemOfItemT>().emplace_back(sub_item_vector); + m_new_descriptor.itemOfItemVector<ItemOfItemT>().emplace_back( + sub_item_vector); } } } @@ -369,45 +408,52 @@ ConnectivityDispatcher<Dimension>::_buildItemToSubItemDescriptor() template <int Dimension> template <ItemType item_type> void -ConnectivityDispatcher<Dimension>:: -_buildRecvItemIdCorrespondanceByProc() +ConnectivityDispatcher<Dimension>::_buildRecvItemIdCorrespondanceByProc() { - const auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; using ItemId = ItemIdT<item_type>; - std::vector<Array<const ItemId>> recv_item_id_correspondance_by_proc(parallel::size()); - const ItemValue<const int,item_type>& item_number = - m_connectivity.template number<item_type>(); + std::vector<Array<const ItemId>> recv_item_id_correspondance_by_proc( + parallel::size()); + const ItemValue<const int, item_type>& item_number = + m_connectivity.template number<item_type>(); std::vector<Array<const int>> send_item_number_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { Array<int> send_item_number(item_list_to_send_by_proc[i_rank].size()); const Array<const ItemId> send_item_id = item_list_to_send_by_proc[i_rank]; - parallel_for(send_item_number.size(), PASTIS_LAMBDA(const size_t& j){ - send_item_number[j] = item_number[send_item_id[j]]; - }); + parallel_for(send_item_number.size(), PASTIS_LAMBDA(const size_t& j) { + send_item_number[j] = item_number[send_item_id[j]]; + }); send_item_number_by_proc[i_rank] = send_item_number; } - const auto& item_list_to_recv_size_by_proc = this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; + const auto& item_list_to_recv_size_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; std::vector<Array<int>> recv_item_number_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank < parallel::size(); ++i_rank) { - recv_item_number_by_proc[i_rank] = Array<int>(item_list_to_recv_size_by_proc[i_rank]); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + recv_item_number_by_proc[i_rank] = + Array<int>(item_list_to_recv_size_by_proc[i_rank]); } parallel::exchange(send_item_number_by_proc, recv_item_number_by_proc); - const auto& item_number_to_id_map = this->_dispatchedInfo<item_type>().m_number_to_id_map; - for (size_t i_rank=0; i_rank<item_list_to_recv_size_by_proc.size(); ++i_rank) { - Array<ItemId> item_id_correspondance(item_list_to_recv_size_by_proc[i_rank]); - for (size_t l=0; l<item_list_to_recv_size_by_proc[i_rank]; ++l) { - const int& item_number = recv_item_number_by_proc[i_rank][l]; + const auto& item_number_to_id_map = + this->_dispatchedInfo<item_type>().m_number_to_id_map; + for (size_t i_rank = 0; i_rank < item_list_to_recv_size_by_proc.size(); + ++i_rank) { + Array<ItemId> item_id_correspondance( + item_list_to_recv_size_by_proc[i_rank]); + for (size_t l = 0; l < item_list_to_recv_size_by_proc[i_rank]; ++l) { + const int& item_number = recv_item_number_by_proc[i_rank][l]; const auto& searched_item_id = item_number_to_id_map.find(item_number); Assert(searched_item_id != item_number_to_id_map.end()); item_id_correspondance[l] = searched_item_id->second; } recv_item_id_correspondance_by_proc[i_rank] = item_id_correspondance; } - this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc = recv_item_id_correspondance_by_proc; + this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc = + recv_item_id_correspondance_by_proc; } template <int Dimension> @@ -418,70 +464,80 @@ ConnectivityDispatcher<Dimension>::_buildItemReferenceList() using ItemId = ItemIdT<item_type>; // Getting references - Array<const size_t> number_of_item_ref_list_per_proc - = parallel::allGather(m_connectivity.template numberOfRefItemList<item_type>()); - - const size_t number_of_item_list_sender - = [&] () { - size_t number_of_item_list_sender=0; - for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { - number_of_item_list_sender - += (number_of_item_ref_list_per_proc[i_rank] > 0); - } - return number_of_item_list_sender; - }(); + Array<const size_t> number_of_item_ref_list_per_proc = parallel::allGather( + m_connectivity.template numberOfRefItemList<item_type>()); + + const size_t number_of_item_list_sender = [&]() { + size_t number_of_item_list_sender = 0; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + number_of_item_list_sender += + (number_of_item_ref_list_per_proc[i_rank] > 0); + } + return number_of_item_list_sender; + }(); if (number_of_item_list_sender > 0) { if (number_of_item_list_sender > 1) { - perr() << __FILE__ << ':' << __LINE__ << ": " - << rang::fgB::red - <<"need to check that knowing procs know the same item_ref_lists!" + perr() << __FILE__ << ':' << __LINE__ << ": " << rang::fgB::red + << "need to check that knowing procs know the same item_ref_lists!" << rang::fg::reset << '\n'; } if (number_of_item_list_sender < parallel::size()) { - const size_t sender_rank - = [&] () { - size_t i_rank = 0; - for (; i_rank < parallel::size(); ++i_rank) { - if (number_of_item_ref_list_per_proc[i_rank] > 0) { - break; - } - } - return i_rank; - }(); + const size_t sender_rank = [&]() { + size_t i_rank = 0; + for (; i_rank < parallel::size(); ++i_rank) { + if (number_of_item_ref_list_per_proc[i_rank] > 0) { + break; + } + } + return i_rank; + }(); Assert(number_of_item_list_sender < parallel::size()); // sending references tags - Array<RefId::TagNumberType> ref_tag_list{number_of_item_ref_list_per_proc[sender_rank]}; - if (parallel::rank() == sender_rank){ - for (size_t i_item_ref_list=0; i_item_ref_list<m_connectivity.template numberOfRefItemList<item_type>(); + Array<RefId::TagNumberType> ref_tag_list{ + number_of_item_ref_list_per_proc[sender_rank]}; + if (parallel::rank() == sender_rank) { + for (size_t i_item_ref_list = 0; + i_item_ref_list < + m_connectivity.template numberOfRefItemList<item_type>(); ++i_item_ref_list) { - auto item_ref_list = m_connectivity.template refItemList<item_type>(i_item_ref_list); + auto item_ref_list = + m_connectivity.template refItemList<item_type>(i_item_ref_list); ref_tag_list[i_item_ref_list] = item_ref_list.refId().tagNumber(); } } parallel::broadcast(ref_tag_list, sender_rank); // sending references name size - Array<size_t> ref_name_size_list{number_of_item_ref_list_per_proc[sender_rank]}; - if (parallel::rank() == sender_rank){ - for (size_t i_item_ref_list=0; i_item_ref_list<m_connectivity.template numberOfRefItemList<item_type>(); + Array<size_t> ref_name_size_list{ + number_of_item_ref_list_per_proc[sender_rank]}; + if (parallel::rank() == sender_rank) { + for (size_t i_item_ref_list = 0; + i_item_ref_list < + m_connectivity.template numberOfRefItemList<item_type>(); ++i_item_ref_list) { - auto item_ref_list = m_connectivity.template refItemList<item_type>(i_item_ref_list); - ref_name_size_list[i_item_ref_list] = item_ref_list.refId().tagName().size(); + auto item_ref_list = + m_connectivity.template refItemList<item_type>(i_item_ref_list); + ref_name_size_list[i_item_ref_list] = + item_ref_list.refId().tagName().size(); } } parallel::broadcast(ref_name_size_list, sender_rank); // sending references name size - Array<RefId::TagNameType::value_type> ref_name_cat{sum(ref_name_size_list)}; - if (parallel::rank() == sender_rank){ - size_t i_char=0; - for (size_t i_item_ref_list=0; i_item_ref_list<m_connectivity.template numberOfRefItemList<item_type>(); + Array<RefId::TagNameType::value_type> ref_name_cat{ + sum(ref_name_size_list)}; + if (parallel::rank() == sender_rank) { + size_t i_char = 0; + for (size_t i_item_ref_list = 0; + i_item_ref_list < + m_connectivity.template numberOfRefItemList<item_type>(); ++i_item_ref_list) { - auto item_ref_list = m_connectivity.template refItemList<item_type>(i_item_ref_list); + auto item_ref_list = + m_connectivity.template refItemList<item_type>(i_item_ref_list); for (auto c : item_ref_list.refId().tagName()) { ref_name_cat[i_char++] = c; } @@ -489,35 +545,38 @@ ConnectivityDispatcher<Dimension>::_buildItemReferenceList() } parallel::broadcast(ref_name_cat, sender_rank); - std::vector<RefId> ref_id_list - = [&] () { - std::vector<RefId> ref_id_list; - ref_id_list.reserve(ref_name_size_list.size()); - size_t begining=0; - for (size_t i_ref=0; i_ref < ref_name_size_list.size(); ++i_ref) { - const size_t size = ref_name_size_list[i_ref]; - ref_id_list.emplace_back(ref_tag_list[i_ref], - std::string{&(ref_name_cat[begining]), size}); - begining += size; - } - return ref_id_list; - } (); - - using block_type = int32_t; + std::vector<RefId> ref_id_list = [&]() { + std::vector<RefId> ref_id_list; + ref_id_list.reserve(ref_name_size_list.size()); + size_t begining = 0; + for (size_t i_ref = 0; i_ref < ref_name_size_list.size(); ++i_ref) { + const size_t size = ref_name_size_list[i_ref]; + ref_id_list.emplace_back( + ref_tag_list[i_ref], std::string{&(ref_name_cat[begining]), size}); + begining += size; + } + return ref_id_list; + }(); + + using block_type = int32_t; constexpr size_t block_size = sizeof(block_type); - const size_t nb_block = ref_id_list.size()/block_size + (ref_id_list.size()%block_size != 0); - for (size_t i_block=0; i_block<nb_block; ++i_block) { + const size_t nb_block = ref_id_list.size() / block_size + + (ref_id_list.size() % block_size != 0); + for (size_t i_block = 0; i_block < nb_block; ++i_block) { ItemValue<block_type, item_type> item_references(m_connectivity); item_references.fill(0); if (m_connectivity.template numberOfRefItemList<item_type>() > 0) { - const size_t max_i_ref = std::min(ref_id_list.size(), block_size*(i_block+1)); - for (size_t i_ref=block_size*i_block, i=0; i_ref<max_i_ref; ++i_ref, ++i) { - block_type ref_bit{1<<i}; - auto item_ref_list = m_connectivity.template refItemList<item_type>(i_ref); + const size_t max_i_ref = + std::min(ref_id_list.size(), block_size * (i_block + 1)); + for (size_t i_ref = block_size * i_block, i = 0; i_ref < max_i_ref; + ++i_ref, ++i) { + block_type ref_bit{1 << i}; + auto item_ref_list = + m_connectivity.template refItemList<item_type>(i_ref); const auto& item_list = item_ref_list.list(); - for (size_t i_item=0; i_item<item_list.size(); ++i_item) { + for (size_t i_item = 0; i_item < item_list.size(); ++i_item) { const ItemId& item_id = item_list[i_item]; item_references[item_id] |= ref_bit; } @@ -525,46 +584,53 @@ ConnectivityDispatcher<Dimension>::_buildItemReferenceList() } const auto& nb_item_to_send_by_proc = - this->_dispatchedInfo<item_type>().m_list_to_send_size_by_proc; + this->_dispatchedInfo<item_type>().m_list_to_send_size_by_proc; const auto& send_item_id_by_proc = - this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; - std::vector<Array<const block_type>> send_item_refs_by_proc(parallel::size()); + std::vector<Array<const block_type>> send_item_refs_by_proc( + parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { Array<block_type> send_item_refs(nb_item_to_send_by_proc[i_rank]); const Array<const ItemId> send_item_id = send_item_id_by_proc[i_rank]; parallel_for(send_item_id.size(), PASTIS_LAMBDA(const size_t& l) { - const ItemId& item_id = send_item_id[l]; - send_item_refs[l] = item_references[item_id]; - }); + const ItemId& item_id = send_item_id[l]; + send_item_refs[l] = item_references[item_id]; + }); send_item_refs_by_proc[i_rank] = send_item_refs; } std::vector<Array<block_type>> recv_item_refs_by_proc(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - recv_item_refs_by_proc[i_rank] = Array<block_type>(this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc[i_rank]); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + recv_item_refs_by_proc[i_rank] = + Array<block_type>(this->_dispatchedInfo<item_type>() + .m_list_to_recv_size_by_proc[i_rank]); } parallel::exchange(send_item_refs_by_proc, recv_item_refs_by_proc); const auto& recv_item_id_correspondance_by_proc = - this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; - std::vector<block_type> item_refs(m_new_descriptor.template itemNumberVector<item_type>().size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - for (size_t r=0; r<recv_item_refs_by_proc[i_rank].size(); ++r) { - const ItemId& item_id = recv_item_id_correspondance_by_proc[i_rank][r]; + this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; + std::vector<block_type> item_refs( + m_new_descriptor.template itemNumberVector<item_type>().size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + for (size_t r = 0; r < recv_item_refs_by_proc[i_rank].size(); ++r) { + const ItemId& item_id = + recv_item_id_correspondance_by_proc[i_rank][r]; item_refs[item_id] = recv_item_refs_by_proc[i_rank][r]; } } - const size_t max_i_ref = std::min(ref_id_list.size(), block_size*(i_block+1)); - for (size_t i_ref=block_size*i_block, i=0; i_ref<max_i_ref; ++i_ref, ++i) { - block_type ref_bit{1<<i}; + const size_t max_i_ref = + std::min(ref_id_list.size(), block_size * (i_block + 1)); + for (size_t i_ref = block_size * i_block, i = 0; i_ref < max_i_ref; + ++i_ref, ++i) { + block_type ref_bit{1 << i}; std::vector<ItemId> item_id_vector; - for (uint32_t i_item=0; i_item<item_refs.size(); ++i_item) { + for (uint32_t i_item = 0; i_item < item_refs.size(); ++i_item) { const ItemId item_id{i_item}; if (item_refs[item_id] & ref_bit) { item_id_vector.push_back(item_id); @@ -573,7 +639,8 @@ ConnectivityDispatcher<Dimension>::_buildItemReferenceList() Array<const ItemId> item_id_array = convert_to_array(item_id_vector); - m_new_descriptor.addRefItemList(RefItemList<item_type>(ref_id_list[i_ref], item_id_array)); + m_new_descriptor.addRefItemList( + RefItemList<item_type>(ref_id_list[i_ref], item_id_array)); } } } @@ -584,13 +651,14 @@ template <int Dimension> void ConnectivityDispatcher<Dimension>::_dispatchEdges() { - if constexpr (Dimension>2) { + if constexpr (Dimension > 2) { this->_buildNumberOfSubItemPerItemToRecvByProc<EdgeOfCell>(); this->_buildSubItemNumbersToRecvByProc<EdgeOfCell>(); this->_buildSubItemNumberToIdMap<EdgeOfCell>(); this->_buildItemToExchangeLists<ItemType::edge>(); - this->_gatherFrom(m_connectivity.template number<ItemType::edge>(), m_new_descriptor.edge_number_vector); + this->_gatherFrom(m_connectivity.template number<ItemType::edge>(), + m_new_descriptor.edge_number_vector); this->_buildItemToSubItemDescriptor<EdgeOfCell>(); @@ -602,9 +670,11 @@ ConnectivityDispatcher<Dimension>::_dispatchEdges() this->_buildSubItemNumbersToRecvByProc<EdgeOfFace>(); this->_buildItemToSubItemDescriptor<EdgeOfFace>(); - this->_gatherFrom(m_connectivity.faceEdgeIsReversed(), m_new_descriptor.face_edge_is_reversed_vector); + this->_gatherFrom(m_connectivity.faceEdgeIsReversed(), + m_new_descriptor.face_edge_is_reversed_vector); - this->_gatherFrom(this->_dispatchedInfo<ItemType::edge>().m_new_owner, m_new_descriptor.edge_owner_vector); + this->_gatherFrom(this->_dispatchedInfo<ItemType::edge>().m_new_owner, + m_new_descriptor.edge_owner_vector); this->_buildItemReferenceList<ItemType::edge>(); } @@ -614,7 +684,7 @@ template <int Dimension> void ConnectivityDispatcher<Dimension>::_dispatchFaces() { - if constexpr (Dimension>1) { + if constexpr (Dimension > 1) { this->_buildNumberOfSubItemPerItemToRecvByProc<FaceOfCell>(); this->_buildSubItemNumbersToRecvByProc<FaceOfCell>(); this->_buildSubItemNumberToIdMap<FaceOfCell>(); @@ -624,22 +694,25 @@ ConnectivityDispatcher<Dimension>::_dispatchFaces() this->_buildSubItemNumbersToRecvByProc<NodeOfFace>(); this->_buildItemToSubItemDescriptor<NodeOfFace>(); - this->_gatherFrom(m_connectivity.template number<ItemType::face>(), m_new_descriptor.face_number_vector); + this->_gatherFrom(m_connectivity.template number<ItemType::face>(), + m_new_descriptor.face_number_vector); this->_buildItemToSubItemDescriptor<FaceOfCell>(); - this->_gatherFrom(m_connectivity.cellFaceIsReversed(), m_new_descriptor.cell_face_is_reversed_vector); + this->_gatherFrom(m_connectivity.cellFaceIsReversed(), + m_new_descriptor.cell_face_is_reversed_vector); - this->_gatherFrom(this->_dispatchedInfo<ItemType::face>().m_new_owner, m_new_descriptor.face_owner_vector); + this->_gatherFrom(this->_dispatchedInfo<ItemType::face>().m_new_owner, + m_new_descriptor.face_owner_vector); this->_buildItemReferenceList<ItemType::face>(); } } - template <int Dimension> -ConnectivityDispatcher<Dimension>::ConnectivityDispatcher(const ConnectivityType& connectivity) - : m_connectivity(connectivity) +ConnectivityDispatcher<Dimension>::ConnectivityDispatcher( + const ConnectivityType& connectivity) + : m_connectivity(connectivity) { this->_buildNewOwner<ItemType::cell>(); this->_buildNewOwner<ItemType::face>(); @@ -652,18 +725,23 @@ ConnectivityDispatcher<Dimension>::ConnectivityDispatcher(const ConnectivityType this->_buildSubItemNumbersToRecvByProc<NodeOfCell>(); - this->_gatherFrom(m_connectivity.template number<ItemType::cell>(), m_new_descriptor.cell_number_vector); + this->_gatherFrom(m_connectivity.template number<ItemType::cell>(), + m_new_descriptor.cell_number_vector); this->_buildSubItemNumberToIdMap<NodeOfCell>(); this->_buildItemToExchangeLists<ItemType::node>(); // Fill new descriptor - this->_gatherFrom(m_connectivity.cellType(), m_new_descriptor.cell_type_vector); - this->_gatherFrom(this->_dispatchedInfo<ItemType::cell>().m_new_owner, m_new_descriptor.cell_owner_vector); + this->_gatherFrom(m_connectivity.cellType(), + m_new_descriptor.cell_type_vector); + this->_gatherFrom(this->_dispatchedInfo<ItemType::cell>().m_new_owner, + m_new_descriptor.cell_owner_vector); - this->_gatherFrom(m_connectivity.template number<ItemType::node>(), m_new_descriptor.node_number_vector); - this->_gatherFrom(this->_dispatchedInfo<ItemType::node>().m_new_owner, m_new_descriptor.node_owner_vector); + this->_gatherFrom(m_connectivity.template number<ItemType::node>(), + m_new_descriptor.node_number_vector); + this->_gatherFrom(this->_dispatchedInfo<ItemType::node>().m_new_owner, + m_new_descriptor.node_owner_vector); this->_buildItemToSubItemDescriptor<NodeOfCell>(); @@ -678,6 +756,9 @@ ConnectivityDispatcher<Dimension>::ConnectivityDispatcher(const ConnectivityType m_dispatched_connectivity = ConnectivityType::build(m_new_descriptor); } -template ConnectivityDispatcher<1>::ConnectivityDispatcher(const ConnectivityType&); -template ConnectivityDispatcher<2>::ConnectivityDispatcher(const ConnectivityType&); -template ConnectivityDispatcher<3>::ConnectivityDispatcher(const ConnectivityType&); +template ConnectivityDispatcher<1>::ConnectivityDispatcher( + const ConnectivityType&); +template ConnectivityDispatcher<2>::ConnectivityDispatcher( + const ConnectivityType&); +template ConnectivityDispatcher<3>::ConnectivityDispatcher( + const ConnectivityType&); diff --git a/src/mesh/ConnectivityDispatcher.hpp b/src/mesh/ConnectivityDispatcher.hpp index e0ce2e88e..28829e6f5 100644 --- a/src/mesh/ConnectivityDispatcher.hpp +++ b/src/mesh/ConnectivityDispatcher.hpp @@ -1,12 +1,12 @@ #ifndef CONNECTIVITY_DISPATCHER_HPP #define CONNECTIVITY_DISPATCHER_HPP -#include <Mesh.hpp> #include <ItemValue.hpp> #include <ItemValueUtils.hpp> +#include <Mesh.hpp> -#include <unordered_map> #include <ConnectivityDescriptor.hpp> +#include <unordered_map> template <int Dimension> class ConnectivityDispatcher @@ -37,8 +37,8 @@ class ConnectivityDispatcher DispatchedItemInfo<ItemType::node> m_dispatched_node_info; template <ItemType item_type> - PASTIS_INLINE - DispatchedItemInfo<item_type>& _dispatchedInfo() + PASTIS_INLINE DispatchedItemInfo<item_type>& + _dispatchedInfo() { if constexpr (item_type == ItemType::cell) { return m_dispatched_cell_info; @@ -52,8 +52,8 @@ class ConnectivityDispatcher } template <ItemType item_type> - PASTIS_INLINE - const DispatchedItemInfo<item_type>& _dispatchedInfo() const + PASTIS_INLINE const DispatchedItemInfo<item_type>& + _dispatchedInfo() const { if constexpr (item_type == ItemType::cell) { return m_dispatched_cell_info; @@ -90,8 +90,8 @@ class ConnectivityDispatcher DispatchedItemOfItemInfo<CellOfNode> m_dispatched_cell_of_node_info; template <typename ItemOfItem> - PASTIS_INLINE - DispatchedItemOfItemInfo<ItemOfItem>& _dispatchedInfo() + PASTIS_INLINE DispatchedItemOfItemInfo<ItemOfItem>& + _dispatchedInfo() { if constexpr (std::is_same_v<NodeOfCell, ItemOfItem>) { return m_dispatched_node_of_cell_info; @@ -123,8 +123,8 @@ class ConnectivityDispatcher } template <typename ItemOfItem> - PASTIS_INLINE - const DispatchedItemOfItemInfo<ItemOfItem>& _dispatchedInfo() const + PASTIS_INLINE const DispatchedItemOfItemInfo<ItemOfItem>& + _dispatchedInfo() const { if constexpr (std::is_same_v<NodeOfCell, ItemOfItem>) { return m_dispatched_node_of_cell_info; @@ -178,13 +178,16 @@ class ConnectivityDispatcher void _dispatchEdges(); void _dispatchFaces(); - template<typename DataType, ItemType item_type, typename ConnectivityPtr> - void _gatherFrom(const ItemValue<DataType, item_type, ConnectivityPtr>& data_to_gather, - std::vector<std::remove_const_t<DataType>>& gathered_vector); + template <typename DataType, ItemType item_type, typename ConnectivityPtr> + void _gatherFrom( + const ItemValue<DataType, item_type, ConnectivityPtr>& data_to_gather, + std::vector<std::remove_const_t<DataType>>& gathered_vector); - template<typename DataType, typename ItemOfItem, typename ConnectivityPtr> - void _gatherFrom(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& data_to_gather, - std::vector<Array<std::remove_const_t<DataType>>>& gathered_vector); + template <typename DataType, typename ItemOfItem, typename ConnectivityPtr> + void _gatherFrom( + const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& + data_to_gather, + std::vector<Array<std::remove_const_t<DataType>>>& gathered_vector); template <typename SubItemOfItemT> void _buildNumberOfSubItemPerItemToRecvByProc(); @@ -205,90 +208,101 @@ class ConnectivityDispatcher return m_dispatched_connectivity; } - template<typename DataType, ItemType item_type, typename ConnectivityPtr> + template <typename DataType, ItemType item_type, typename ConnectivityPtr> std::vector<Array<const DataType>> exchange(ItemValue<DataType, item_type, ConnectivityPtr> item_value) const { - using ItemId = ItemIdT<item_type>; + using ItemId = ItemIdT<item_type>; using MutableDataType = std::remove_const_t<DataType>; - std::vector<Array<const DataType>> item_value_to_send_by_proc(parallel::size()); + std::vector<Array<const DataType>> item_value_to_send_by_proc( + parallel::size()); - const auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { const Array<const ItemId>& item_list = item_list_to_send_by_proc[i]; Array<MutableDataType> item_value_list(item_list.size()); - parallel_for (item_list.size(), PASTIS_LAMBDA(const ItemId& item_id) { - item_value_list[item_id] = item_value[item_list[item_id]]; - }); + parallel_for(item_list.size(), PASTIS_LAMBDA(const ItemId& item_id) { + item_value_list[item_id] = item_value[item_list[item_id]]; + }); item_value_to_send_by_proc[i] = item_value_list; } - std::vector<Array<MutableDataType>> recv_item_value_by_proc(parallel::size()); + std::vector<Array<MutableDataType>> recv_item_value_by_proc( + parallel::size()); { - const auto& list_to_recv_size_by_proc = this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; - for (size_t i=0; i<parallel::size(); ++i) { - recv_item_value_by_proc[i] = Array<MutableDataType>(list_to_recv_size_by_proc[i]); + const auto& list_to_recv_size_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; + for (size_t i = 0; i < parallel::size(); ++i) { + recv_item_value_by_proc[i] = + Array<MutableDataType>(list_to_recv_size_by_proc[i]); } } parallel::exchange(item_value_to_send_by_proc, recv_item_value_by_proc); - std::vector<Array<const DataType>> const_recv_item_value_by_proc(parallel::size()); - for (size_t i=0; i<parallel::size(); ++i) { + std::vector<Array<const DataType>> const_recv_item_value_by_proc( + parallel::size()); + for (size_t i = 0; i < parallel::size(); ++i) { const_recv_item_value_by_proc[i] = recv_item_value_by_proc[i]; } return const_recv_item_value_by_proc; } - template<typename DataType, ItemType item_type, typename ConnectivityPtr> + template <typename DataType, ItemType item_type, typename ConnectivityPtr> ItemValue<std::remove_const_t<DataType>, item_type, ConnectivityPtr> dispatch(ItemValue<DataType, item_type, ConnectivityPtr> item_value) const { using ItemId = ItemIdT<item_type>; - Assert(m_dispatched_connectivity.use_count()> 0, + Assert(m_dispatched_connectivity.use_count() > 0, "cannot dispatch quantity before connectivity"); - const auto& item_list_to_send_by_proc = this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; + const auto& item_list_to_send_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_send_by_proc; using MutableDataType = std::remove_const_t<DataType>; std::vector<Array<DataType>> item_value_to_send_by_proc(parallel::size()); - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { const Array<const ItemId>& item_list = item_list_to_send_by_proc[i]; Array<MutableDataType> item_value_list(item_list.size()); - parallel_for (item_list.size(), PASTIS_LAMBDA(const ItemId& item_id) { - item_value_list[item_id] = item_value[item_list[item_id]]; - }); + parallel_for(item_list.size(), PASTIS_LAMBDA(const ItemId& item_id) { + item_value_list[item_id] = item_value[item_list[item_id]]; + }); item_value_to_send_by_proc[i] = item_value_list; } - const auto& item_list_to_recv_size_by_proc = this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; - std::vector<Array<MutableDataType>> recv_item_value_by_proc(parallel::size()); - for (size_t i=0; i<parallel::size(); ++i) { - recv_item_value_by_proc[i] = Array<MutableDataType>(item_list_to_recv_size_by_proc[i]); + const auto& item_list_to_recv_size_by_proc = + this->_dispatchedInfo<item_type>().m_list_to_recv_size_by_proc; + std::vector<Array<MutableDataType>> recv_item_value_by_proc( + parallel::size()); + for (size_t i = 0; i < parallel::size(); ++i) { + recv_item_value_by_proc[i] = + Array<MutableDataType>(item_list_to_recv_size_by_proc[i]); } parallel::exchange(item_value_to_send_by_proc, recv_item_value_by_proc); const auto& recv_item_id_correspondance_by_proc = - this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; - ItemValue<MutableDataType, item_type> new_item_value(*m_dispatched_connectivity); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - const auto& recv_item_id_correspondance = recv_item_id_correspondance_by_proc[i_rank]; + this->_dispatchedInfo<item_type>().m_recv_id_correspondance_by_proc; + ItemValue<MutableDataType, item_type> new_item_value( + *m_dispatched_connectivity); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + const auto& recv_item_id_correspondance = + recv_item_id_correspondance_by_proc[i_rank]; const auto& recv_item_value = recv_item_value_by_proc[i_rank]; parallel_for(recv_item_value.size(), PASTIS_LAMBDA(size_t r) { - const ItemId& item_id = recv_item_id_correspondance[r]; - new_item_value[item_id] = recv_item_value[r]; - }); + const ItemId& item_id = recv_item_id_correspondance[r]; + new_item_value[item_id] = recv_item_value[r]; + }); } return new_item_value; } ConnectivityDispatcher(const ConnectivityType& mesh); ConnectivityDispatcher(const ConnectivityDispatcher&) = delete; - ~ConnectivityDispatcher() = default; + ~ConnectivityDispatcher() = default; }; - -#endif // CONNECTIVITY_DISPATCHER_HPP +#endif // CONNECTIVITY_DISPATCHER_HPP diff --git a/src/mesh/ConnectivityMatrix.hpp b/src/mesh/ConnectivityMatrix.hpp index 18b39a67a..0a2a36c1e 100644 --- a/src/mesh/ConnectivityMatrix.hpp +++ b/src/mesh/ConnectivityMatrix.hpp @@ -1,9 +1,9 @@ #ifndef CONNECTIVITY_MATRIX_HPP #define CONNECTIVITY_MATRIX_HPP -#include <PastisUtils.hpp> #include <Array.hpp> #include <Kokkos_StaticCrsGraph.hpp> +#include <PastisUtils.hpp> class ConnectivityMatrix { @@ -16,51 +16,60 @@ class ConnectivityMatrix public: using HostRowType = HostMatrix::row_map_type; - const bool& isBuilt() const + const bool& + isBuilt() const { return m_is_built; } - auto entries() const + auto + entries() const { return encapsulate(m_host_matrix.entries); // using DataType = typename decltype(m_host_matrix.entries)::value_type; // return Array<DataType>(m_host_matrix.entries); } - const auto& rowsMap() const + const auto& + rowsMap() const { return m_host_matrix.row_map; } PASTIS_INLINE - auto numEntries() const + auto + numEntries() const { return m_host_matrix.entries.extent(0); } PASTIS_INLINE - auto numRows() const + auto + numRows() const { return m_host_matrix.numRows(); } PASTIS_INLINE - auto rowConst(const size_t& j) const + auto + rowConst(const size_t& j) const { return m_host_matrix.rowConst(j); } PASTIS_INLINE - const auto& rowMap(const size_t& j) const + const auto& + rowMap(const size_t& j) const { return m_host_matrix.row_map[j]; } PASTIS_INLINE ConnectivityMatrix(const std::vector<std::vector<unsigned int>>& initializer) - : m_host_matrix{Kokkos::create_staticcrsgraph<HostMatrix>("connectivity_matrix", initializer)}, - m_is_built{true} + : m_host_matrix{Kokkos::create_staticcrsgraph<HostMatrix>( + "connectivity_matrix", + initializer)}, + m_is_built{true} { ; } @@ -68,10 +77,10 @@ class ConnectivityMatrix ConnectivityMatrix& operator=(const ConnectivityMatrix&) = default; ConnectivityMatrix& operator=(ConnectivityMatrix&&) = default; - ConnectivityMatrix() = default; + ConnectivityMatrix() = default; ConnectivityMatrix(const ConnectivityMatrix&) = default; - ConnectivityMatrix(ConnectivityMatrix&&) = default; - ~ConnectivityMatrix() = default; + ConnectivityMatrix(ConnectivityMatrix&&) = default; + ~ConnectivityMatrix() = default; }; -#endif // CONNECTIVITY_MATRIX_HPP +#endif // CONNECTIVITY_MATRIX_HPP diff --git a/src/mesh/GmshReader.cpp b/src/mesh/GmshReader.cpp index 1881f99a4..ea9e7338d 100644 --- a/src/mesh/GmshReader.cpp +++ b/src/mesh/GmshReader.cpp @@ -1,10 +1,10 @@ #include <GmshReader.hpp> #include <PastisMacros.hpp> -#include <iostream> #include <fstream> -#include <set> +#include <iostream> #include <rang.hpp> +#include <set> #include <CellType.hpp> #include <Connectivity.hpp> @@ -12,35 +12,37 @@ #include <Mesh.hpp> #include <MeshData.hpp> -#include <RefItemList.hpp> #include <Messenger.hpp> +#include <RefItemList.hpp> #include <ArrayUtils.hpp> #include <ItemValueUtils.hpp> #include <ConnectivityDispatcher.hpp> -#include <unordered_map> +#include <iomanip> #include <map> #include <regex> -#include <iomanip> +#include <unordered_map> class ErrorHandler { public: - enum Type { - asked, /**< execution request by the user*/ + enum Type + { + asked, /**< execution request by the user*/ compilation, /**< syntax error in a language */ - normal, /**< normal error due to a bad use of ff3d */ - unexpected /**< Unexpected execution error */ + normal, /**< normal error due to a bad use of ff3d */ + unexpected /**< Unexpected execution error */ }; private: - const std::string __filename; /**< The source file name where the error occured */ - const size_t __lineNumber; /**< The line number where exception was raised */ + const std::string + __filename; /**< The source file name where the error occured */ + const size_t __lineNumber; /**< The line number where exception was raised */ const std::string __errorMessage; /**< The reporting message */ - const Type __type; /**< the type of the error */ + const Type __type; /**< the type of the error */ public: /** * Prints the error message @@ -54,10 +56,10 @@ class ErrorHandler * @param e an handled error */ ErrorHandler(const ErrorHandler& e) - : __filename(e.__filename), - __lineNumber(e.__lineNumber), - __errorMessage(e.__errorMessage), - __type(e.__type) + : __filename(e.__filename), + __lineNumber(e.__lineNumber), + __errorMessage(e.__errorMessage), + __type(e.__type) { ; } @@ -85,16 +87,18 @@ class ErrorHandler } }; -void ErrorHandler::writeErrorMessage() const +void +ErrorHandler::writeErrorMessage() const { - switch(__type) { + switch (__type) { case asked: { perr() << "\nremark: exit command explicitly called\n"; [[fallthrough]]; } case normal: { - perr() << '\n' << __filename << ':' << __lineNumber - << ":remark: emitted the following message\n"; + perr() << '\n' + << __filename << ':' << __lineNumber + << ":remark: emitted the following message\n"; perr() << "error: " << __errorMessage << '\n'; break; } @@ -103,40 +107,45 @@ void ErrorHandler::writeErrorMessage() const break; } case unexpected: { - perr() << '\n' << __filename << ':' << __lineNumber << ":\n" << __errorMessage << '\n'; - perr() << "\nUNEXPECTED ERROR: this should not occure, please report it\n"; + perr() << '\n' + << __filename << ':' << __lineNumber << ":\n" + << __errorMessage << '\n'; + perr() + << "\nUNEXPECTED ERROR: this should not occure, please report it\n"; perr() << "\nBUG REPORT: Please send bug reports to:\n" - << " ff3d-dev@nongnu.org or freefem@ann.jussieu.fr\n" - << "or better, use the Bug Tracking System:\n" - << " http://savannah.nongnu.org/bugs/?group=ff3d\n"; + << " ff3d-dev@nongnu.org or freefem@ann.jussieu.fr\n" + << "or better, use the Bug Tracking System:\n" + << " http://savannah.nongnu.org/bugs/?group=ff3d\n"; break; } default: { - perr() << __filename << ':' << __lineNumber << ": " << __errorMessage << '\n'; - perr() << __FILE__ << ':' << __LINE__ << ":remark: error type not implemented!\n"; + perr() << __filename << ':' << __lineNumber << ": " << __errorMessage + << '\n'; + perr() << __FILE__ << ':' << __LINE__ + << ":remark: error type not implemented!\n"; } } } -ErrorHandler:: -ErrorHandler(const std::string& filename, - const size_t& lineNumber, - const std::string& errorMessage, - const Type& type) - : __filename(filename), - __lineNumber(lineNumber), - __errorMessage(errorMessage), - __type(type) +ErrorHandler::ErrorHandler(const std::string& filename, + const size_t& lineNumber, + const std::string& errorMessage, + const Type& type) + : __filename(filename), + __lineNumber(lineNumber), + __errorMessage(errorMessage), + __type(type) { ; } template <int Dimension> -void GmshReader::_dispatch() +void +GmshReader::_dispatch() { using ConnectivityType = Connectivity<Dimension>; - using Rd = TinyVector<Dimension>; - using MeshType = Mesh<ConnectivityType>; + using Rd = TinyVector<Dimension>; + using MeshType = Mesh<ConnectivityType>; if (not m_mesh) { ConnectivityDescriptor descriptor; @@ -149,23 +158,24 @@ void GmshReader::_dispatch() ConnectivityDispatcher<Dimension> dispatcher(mesh.connectivity()); std::shared_ptr dispatched_connectivity = dispatcher.dispatchedConnectivity(); - NodeValue<Rd> dispatched_xr = dispatcher.dispatch(mesh.xr()); + NodeValue<Rd> dispatched_xr = dispatcher.dispatch(mesh.xr()); m_mesh = std::make_shared<MeshType>(dispatched_connectivity, dispatched_xr); } - template <size_t Dimension> class ConnectivityFace; -template<> +template <> class ConnectivityFace<2> { public: friend struct Hash; struct Hash { - size_t operator()(const ConnectivityFace& f) const { + size_t + operator()(const ConnectivityFace& f) const + { size_t hash = 0; hash ^= std::hash<unsigned int>()(f.m_node0_id); hash ^= std::hash<unsigned int>()(f.m_node1_id) >> 1; @@ -182,40 +192,46 @@ class ConnectivityFace<2> bool m_reversed; public: - - std::vector<unsigned int> nodeIdList() const + std::vector<unsigned int> + nodeIdList() const { return {m_node0_id, m_node1_id}; } - bool reversed() const + bool + reversed() const { return m_reversed; } PASTIS_INLINE - bool operator==(const ConnectivityFace& f) const + bool + operator==(const ConnectivityFace& f) const { - return ((m_node0_id == f.m_node0_id) and - (m_node1_id == f.m_node1_id)); + return ((m_node0_id == f.m_node0_id) and (m_node1_id == f.m_node1_id)); } PASTIS_INLINE - bool operator<(const ConnectivityFace& f) const + bool + operator<(const ConnectivityFace& f) const { - return ((m_node_number_vector[m_node0_id] < m_node_number_vector[f.m_node0_id]) or - ((m_node_number_vector[m_node0_id] == m_node_number_vector[f.m_node0_id]) and - (m_node_number_vector[m_node1_id]<m_node_number_vector[f.m_node1_id]))); + return ( + (m_node_number_vector[m_node0_id] < m_node_number_vector[f.m_node0_id]) or + ((m_node_number_vector[m_node0_id] == + m_node_number_vector[f.m_node0_id]) and + (m_node_number_vector[m_node1_id] < + m_node_number_vector[f.m_node1_id]))); } PASTIS_INLINE ConnectivityFace(const std::vector<unsigned int>& node_id_list, const std::vector<int>& node_number_vector) - : m_node_number_vector(node_number_vector) + : m_node_number_vector(node_number_vector) { - Assert(node_id_list.size()==2); + Assert(node_id_list.size() == 2); - if (m_node_number_vector[node_id_list[0]] < m_node_number_vector[node_id_list[1]]) { + if (m_node_number_vector[node_id_list[0]] < + m_node_number_vector[node_id_list[1]]) { m_node0_id = node_id_list[0]; m_node1_id = node_id_list[1]; m_reversed = false; @@ -241,9 +257,11 @@ class ConnectivityFace<3> friend struct Hash; struct Hash { - size_t operator()(const ConnectivityFace& f) const { + size_t + operator()(const ConnectivityFace& f) const + { size_t hash = 0; - for (size_t i=0; i<f.m_node_id_list.size(); ++i) { + for (size_t i = 0; i < f.m_node_id_list.size(); ++i) { hash ^= std::hash<unsigned int>()(f.m_node_id_list[i]) >> i; } return hash; @@ -256,20 +274,23 @@ class ConnectivityFace<3> const std::vector<int>& m_node_number_vector; PASTIS_INLINE - std::vector<unsigned int> _sort(const std::vector<unsigned int>& node_list) + std::vector<unsigned int> + _sort(const std::vector<unsigned int>& node_list) { const auto min_id = std::min_element(node_list.begin(), node_list.end()); - const int shift = std::distance(node_list.begin(), min_id); + const int shift = std::distance(node_list.begin(), min_id); std::vector<unsigned int> rotated_node_list(node_list.size()); - if (node_list[(shift+1)%node_list.size()] > node_list[(shift+node_list.size()-1)%node_list.size()]) { - for (size_t i=0; i<node_list.size(); ++i) { - rotated_node_list[i] = node_list[(shift+node_list.size()-i)%node_list.size()]; + if (node_list[(shift + 1) % node_list.size()] > + node_list[(shift + node_list.size() - 1) % node_list.size()]) { + for (size_t i = 0; i < node_list.size(); ++i) { + rotated_node_list[i] = + node_list[(shift + node_list.size() - i) % node_list.size()]; m_reversed = true; } } else { - for (size_t i=0; i<node_list.size(); ++i) { - rotated_node_list[i] = node_list[(shift+i)%node_list.size()]; + for (size_t i = 0; i < node_list.size(); ++i) { + rotated_node_list[i] = node_list[(shift + i) % node_list.size()]; } } @@ -278,13 +299,15 @@ class ConnectivityFace<3> public: PASTIS_INLINE - const bool& reversed() const + const bool& + reversed() const { return m_reversed; } PASTIS_INLINE - const std::vector<unsigned int>& nodeIdList() const + const std::vector<unsigned int>& + nodeIdList() const { return m_node_id_list; } @@ -292,18 +315,19 @@ class ConnectivityFace<3> PASTIS_INLINE ConnectivityFace(const std::vector<unsigned int>& given_node_id_list, const std::vector<int>& node_number_vector) - : m_reversed(false), - m_node_id_list(_sort(given_node_id_list)), - m_node_number_vector(node_number_vector) + : m_reversed(false), + m_node_id_list(_sort(given_node_id_list)), + m_node_number_vector(node_number_vector) { ; } public: - bool operator==(const ConnectivityFace& f) const + bool + operator==(const ConnectivityFace& f) const { if (m_node_id_list.size() == f.nodeIdList().size()) { - for (size_t j=0; j<m_node_id_list.size(); ++j) { + for (size_t j = 0; j < m_node_id_list.size(); ++j) { if (m_node_id_list[j] != f.nodeIdList()[j]) { return false; } @@ -314,12 +338,16 @@ class ConnectivityFace<3> } PASTIS_INLINE - bool operator<(const ConnectivityFace& f) const + bool + operator<(const ConnectivityFace& f) const { - const size_t min_nb_nodes = std::min(f.m_node_id_list.size(), m_node_id_list.size()); - for (size_t i=0; i<min_nb_nodes; ++i) { - if (m_node_id_list[i] < f.m_node_id_list[i]) return true; - if (m_node_id_list[i] != f.m_node_id_list[i]) return false; + const size_t min_nb_nodes = + std::min(f.m_node_id_list.size(), m_node_id_list.size()); + for (size_t i = 0; i < min_nb_nodes; ++i) { + if (m_node_id_list[i] < f.m_node_id_list[i]) + return true; + if (m_node_id_list[i] != f.m_node_id_list[i]) + return false; } return m_node_id_list.size() < f.m_node_id_list.size(); } @@ -334,8 +362,7 @@ class ConnectivityFace<3> ~ConnectivityFace() = default; }; -GmshReader::GmshReader(const std::string& filename) - : m_filename(filename) +GmshReader::GmshReader(const std::string& filename) : m_filename(filename) { if (parallel::rank() == 0) { try { @@ -356,58 +383,58 @@ GmshReader::GmshReader(const std::string& filename) __keywordList["$EndPhysicalNames"] = ENDPHYSICALNAMES; __numberOfPrimitiveNodes.resize(16); - __numberOfPrimitiveNodes[ 0] = 2; // edge - __numberOfPrimitiveNodes[ 1] = 3; // triangle - __numberOfPrimitiveNodes[ 2] = 4; // quadrangle - __numberOfPrimitiveNodes[ 3] = 4; // Tetrahedron - __numberOfPrimitiveNodes[ 4] = 8; // Hexaredron - __numberOfPrimitiveNodes[ 5] = 6; // Prism - __numberOfPrimitiveNodes[ 6] = 5; // Pyramid - __numberOfPrimitiveNodes[ 7] = 3; // second order edge - __numberOfPrimitiveNodes[ 8] = 6; // second order triangle - __numberOfPrimitiveNodes[ 9] = 9; // second order quadrangle - __numberOfPrimitiveNodes[10] = 10; // second order tetrahedron - __numberOfPrimitiveNodes[11] = 27; // second order hexahedron - __numberOfPrimitiveNodes[12] = 18; // second order prism - __numberOfPrimitiveNodes[13] = 14; // second order pyramid - __numberOfPrimitiveNodes[14] = 1; // point - - __primitivesNames[0] = "edges"; - __supportedPrimitives[0] = true; - __primitivesNames[1] = "triangles"; - __supportedPrimitives[1] = true; - __primitivesNames[2] = "quadrangles"; - __supportedPrimitives[2] = true; - __primitivesNames[3] = "tetrahedra"; - __supportedPrimitives[3] = true; - __primitivesNames[4] = "hexahedra"; - __supportedPrimitives[4] = true; - __primitivesNames[5] = "prisms"; - __supportedPrimitives[5] = false; - __primitivesNames[6] = "pyramids"; - __supportedPrimitives[6] = false; - __primitivesNames[7] = "second order edges"; - __supportedPrimitives[7] = false; - __primitivesNames[8] = "second order triangles"; - __supportedPrimitives[8] = false; - __primitivesNames[9] = "second order quadrangles"; - __supportedPrimitives[9] = false; - __primitivesNames[10] = "second order tetrahedra"; - __supportedPrimitives[10]= false; - __primitivesNames[11] = "second order hexahedra"; - __supportedPrimitives[11]= false; - __primitivesNames[12] = "second order prisms"; - __supportedPrimitives[12]= false; - __primitivesNames[13] = "second order pyramids"; - __supportedPrimitives[13]= false; - __primitivesNames[14] = "point"; - __supportedPrimitives[14]= true; + __numberOfPrimitiveNodes[0] = 2; // edge + __numberOfPrimitiveNodes[1] = 3; // triangle + __numberOfPrimitiveNodes[2] = 4; // quadrangle + __numberOfPrimitiveNodes[3] = 4; // Tetrahedron + __numberOfPrimitiveNodes[4] = 8; // Hexaredron + __numberOfPrimitiveNodes[5] = 6; // Prism + __numberOfPrimitiveNodes[6] = 5; // Pyramid + __numberOfPrimitiveNodes[7] = 3; // second order edge + __numberOfPrimitiveNodes[8] = 6; // second order triangle + __numberOfPrimitiveNodes[9] = 9; // second order quadrangle + __numberOfPrimitiveNodes[10] = 10; // second order tetrahedron + __numberOfPrimitiveNodes[11] = 27; // second order hexahedron + __numberOfPrimitiveNodes[12] = 18; // second order prism + __numberOfPrimitiveNodes[13] = 14; // second order pyramid + __numberOfPrimitiveNodes[14] = 1; // point + + __primitivesNames[0] = "edges"; + __supportedPrimitives[0] = true; + __primitivesNames[1] = "triangles"; + __supportedPrimitives[1] = true; + __primitivesNames[2] = "quadrangles"; + __supportedPrimitives[2] = true; + __primitivesNames[3] = "tetrahedra"; + __supportedPrimitives[3] = true; + __primitivesNames[4] = "hexahedra"; + __supportedPrimitives[4] = true; + __primitivesNames[5] = "prisms"; + __supportedPrimitives[5] = false; + __primitivesNames[6] = "pyramids"; + __supportedPrimitives[6] = false; + __primitivesNames[7] = "second order edges"; + __supportedPrimitives[7] = false; + __primitivesNames[8] = "second order triangles"; + __supportedPrimitives[8] = false; + __primitivesNames[9] = "second order quadrangles"; + __supportedPrimitives[9] = false; + __primitivesNames[10] = "second order tetrahedra"; + __supportedPrimitives[10] = false; + __primitivesNames[11] = "second order hexahedra"; + __supportedPrimitives[11] = false; + __primitivesNames[12] = "second order prisms"; + __supportedPrimitives[12] = false; + __primitivesNames[13] = "second order pyramids"; + __supportedPrimitives[13] = false; + __primitivesNames[14] = "point"; + __supportedPrimitives[14] = true; pout() << "Reading file '" << m_filename << "'\n"; // Getting vertices list GmshReader::Keyword kw = this->__nextKeyword(); - switch(kw.second) { + switch (kw.second) { // case NOD: { // this->__readGmsh1(); // break; @@ -415,22 +442,25 @@ GmshReader::GmshReader(const std::string& filename) case MESHFORMAT: { double fileVersion = this->_getReal(); if (fileVersion != 2.2) { - throw ErrorHandler(__FILE__,__LINE__, - "Cannot read Gmsh format '"+std::to_string(fileVersion)+"'", + throw ErrorHandler(__FILE__, __LINE__, + "Cannot read Gmsh format '" + + std::to_string(fileVersion) + "'", ErrorHandler::normal); } int fileType = this->_getInteger(); - __binary = (fileType == 1); + __binary = (fileType == 1); if ((fileType < 0) or (fileType > 1)) { - throw ErrorHandler(__FILE__,__LINE__, - "Cannot read Gmsh file type '"+std::to_string(fileType)+"'", + throw ErrorHandler(__FILE__, __LINE__, + "Cannot read Gmsh file type '" + + std::to_string(fileType) + "'", ErrorHandler::normal); } int dataSize = this->_getInteger(); if (dataSize != sizeof(double)) { - throw ErrorHandler(__FILE__,__LINE__, - "Data size not supported '"+std::to_string(dataSize)+"'", + throw ErrorHandler(__FILE__, __LINE__, + "Data size not supported '" + + std::to_string(dataSize) + "'", ErrorHandler::normal); } @@ -472,9 +502,10 @@ GmshReader::GmshReader(const std::string& filename) kw = this->__nextKeyword(); if (kw.second != ENDMESHFORMAT) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': expecting $EndMeshFormat, '"+kw.first+"' was found", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': expecting $EndMeshFormat, '" + kw.first + + "' was found", ErrorHandler::normal); } @@ -483,16 +514,16 @@ GmshReader::GmshReader(const std::string& filename) break; } default: { - throw ErrorHandler(__FILE__,__LINE__, - "cannot determine format version of '"+m_filename+"'", + throw ErrorHandler(__FILE__, __LINE__, + "cannot determine format version of '" + + m_filename + "'", ErrorHandler::normal); } } this->__proceedData(); // this->__createMesh(); - } - catch(const ErrorHandler& e) { + } catch (const ErrorHandler& e) { e.writeErrorMessage(); std::exit(0); } @@ -501,28 +532,27 @@ GmshReader::GmshReader(const std::string& filename) if (parallel::size() > 1) { pout() << "Sequential mesh read! Need to be dispatched\n" << std::flush; - const int mesh_dimension - = [&]() { - int mesh_dimension = -1; // unknown mesh dimension - if (m_mesh) { - mesh_dimension = m_mesh->dimension(); - } + const int mesh_dimension = [&]() { + int mesh_dimension = -1; // unknown mesh dimension + if (m_mesh) { + mesh_dimension = m_mesh->dimension(); + } - Array<int> dimensions = parallel::allGather(mesh_dimension); - std::set<int> dimension_set; - for (size_t i=0; i<dimensions.size(); ++i) { - const int i_dimension = dimensions[i]; - if (i_dimension != -1) { - dimension_set.insert(i_dimension); - } - } - if (dimension_set.size() != 1) { - std::cerr << "error dimensions of read mesh parts differ!\n"; - std::exit(1); - } + Array<int> dimensions = parallel::allGather(mesh_dimension); + std::set<int> dimension_set; + for (size_t i = 0; i < dimensions.size(); ++i) { + const int i_dimension = dimensions[i]; + if (i_dimension != -1) { + dimension_set.insert(i_dimension); + } + } + if (dimension_set.size() != 1) { + std::cerr << "error dimensions of read mesh parts differ!\n"; + std::exit(1); + } - return *begin(dimension_set); - }(); + return *begin(dimension_set); + }(); switch (mesh_dimension) { case 1: { this->_dispatch<1>(); @@ -544,14 +574,15 @@ GmshReader::GmshReader(const std::string& filename) } } -void GmshReader::__readVertices() +void +GmshReader::__readVertices() { const int numberOfVerices = this->_getInteger(); pout() << "- Number Of Vertices: " << numberOfVerices << '\n'; - if (numberOfVerices<0) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+this->m_filename - +"': number of vertices is negative", + if (numberOfVerices < 0) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + this->m_filename + + "': number of vertices is negative", ErrorHandler::normal); } @@ -559,12 +590,12 @@ void GmshReader::__readVertices() __vertices = Array<R3>(numberOfVerices); if (not __binary) { - for (int i=0; i<numberOfVerices; ++i) { + for (int i = 0; i < numberOfVerices; ++i) { __verticesNumbers[i] = this->_getInteger(); - const double x = this->_getReal(); - const double y = this->_getReal(); - const double z = this->_getReal(); - __vertices[i] = TinyVector<3, double>(x,y,z); + const double x = this->_getReal(); + const double y = this->_getReal(); + const double z = this->_getReal(); + __vertices[i] = TinyVector<3, double>(x, y, z); } } else { // fseek(m_fin.file()__ifh,1L,SEEK_CUR); @@ -613,8 +644,8 @@ void GmshReader::__readVertices() // if ((elementType < 0) or (elementType > 14)) { // throw ErrorHandler(__FILE__,__LINE__, // "reading file '"+m_filename -// +"': unknown element type '"+std::to_string(elementType)+"'", -// ErrorHandler::normal); +// +"': unknown element type +// '"+std::to_string(elementType)+"'", ErrorHandler::normal); // } // __elementType[i] = elementType; // __references[i] = this->_getInteger(); // physical reference @@ -644,10 +675,10 @@ GmshReader::__readElements2_2() { const int numberOfElements = this->_getInteger(); pout() << "- Number Of Elements: " << numberOfElements << '\n'; - if (numberOfElements<0) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': number of elements is negative", + if (numberOfElements < 0) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': number of elements is negative", ErrorHandler::normal); } @@ -657,26 +688,27 @@ GmshReader::__readElements2_2() __elementVertices.resize(numberOfElements); if (not __binary) { - for (int i=0; i<numberOfElements; ++i) { - __elementNumber[i] = this->_getInteger(); - const int elementType = this->_getInteger()-1; + for (int i = 0; i < numberOfElements; ++i) { + __elementNumber[i] = this->_getInteger(); + const int elementType = this->_getInteger() - 1; if ((elementType < 0) or (elementType > 14)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': unknown element type '"+std::to_string(elementType)+"'", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': unknown element type '" + + std::to_string(elementType) + "'", ErrorHandler::normal); } - __elementType[i] = elementType; - const int numberOfTags = this->_getInteger(); - __references[i] = this->_getInteger(); // physical reference - for (int tag=1; tag<numberOfTags; ++tag) { - this->_getInteger(); // drops remaining tags + __elementType[i] = elementType; + const int numberOfTags = this->_getInteger(); + __references[i] = this->_getInteger(); // physical reference + for (int tag = 1; tag < numberOfTags; ++tag) { + this->_getInteger(); // drops remaining tags } const int numberOfVertices = __numberOfPrimitiveNodes[elementType]; __elementVertices[i].resize(numberOfVertices); - for (int j=0; j<numberOfVertices; ++j) { + for (int j = 0; j < numberOfVertices; ++j) { __elementVertices[i][j] = this->_getInteger(); } } @@ -694,8 +726,8 @@ GmshReader::__readElements2_2() // if ((elementType < 0) or (elementType > 14)) { // throw ErrorHandler(__FILE__,__LINE__, // "reading file '"+m_filename - // +"': unknown element type '"+std::to_string(elementType)+"'", - // ErrorHandler::normal); + // +"': unknown element type + // '"+std::to_string(elementType)+"'", ErrorHandler::normal); // } // int elementTypeNumber = 0; @@ -746,22 +778,23 @@ GmshReader::__readElements2_2() } void -GmshReader:: -__readPhysicalNames2_2() +GmshReader::__readPhysicalNames2_2() { const int number_of_names = this->_getInteger(); - for (int i=0; i<number_of_names; ++i) { + for (int i = 0; i < number_of_names; ++i) { const int physical_dimension = this->_getInteger(); - const int physical_number = this->_getInteger(); + const int physical_number = this->_getInteger(); std::string physical_name; m_fin >> physical_name; physical_name = std::regex_replace(physical_name, std::regex("(\")"), ""); - PhysicalRefId physical_ref_id(physical_dimension, RefId(physical_number, physical_name)); + PhysicalRefId physical_ref_id(physical_dimension, + RefId(physical_number, physical_name)); auto searched_physical_ref_id = m_physical_ref_map.find(physical_number); if (searched_physical_ref_id != m_physical_ref_map.end()) { perr() << "Physical reference id '" << physical_ref_id - << "' already defined as '" << searched_physical_ref_id->second << "'!"; + << "' already defined as '" << searched_physical_ref_id->second + << "'!"; std::exit(0); } m_physical_ref_map[physical_number] = physical_ref_id; @@ -770,155 +803,141 @@ __readPhysicalNames2_2() template <size_t Dimension> void -GmshReader::__computeCellFaceAndFaceNodeConnectivities(ConnectivityDescriptor& descriptor) +GmshReader::__computeCellFaceAndFaceNodeConnectivities( + ConnectivityDescriptor& descriptor) { - static_assert((Dimension==2) or (Dimension==3), + static_assert((Dimension == 2) or (Dimension == 3), "Invalid dimension to compute cell-face connectivities"); using CellFaceInfo = std::tuple<CellId, unsigned short, bool>; - using Face = ConnectivityFace<Dimension>; + using Face = ConnectivityFace<Dimension>; const auto& node_number_vector = descriptor.node_number_vector; Array<unsigned short> cell_nb_faces(descriptor.cell_to_node_vector.size()); std::map<Face, std::vector<CellFaceInfo>> face_cells_map; - for (CellId j=0; j<descriptor.cell_to_node_vector.size(); ++j) { + for (CellId j = 0; j < descriptor.cell_to_node_vector.size(); ++j) { const auto& cell_nodes = descriptor.cell_to_node_vector[j]; - if constexpr (Dimension==2) { + if constexpr (Dimension == 2) { switch (descriptor.cell_type_vector[j]) { - case CellType::Triangle: { - cell_nb_faces[j] = 3; - // face 0 - Face f0({cell_nodes[1], cell_nodes[2]}, node_number_vector); - face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); - - // face 1 - Face f1({cell_nodes[2], cell_nodes[0]}, node_number_vector); - face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); - - // face 2 - Face f2({cell_nodes[0], cell_nodes[1]}, node_number_vector); - face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); - break; - } - case CellType::Quadrangle: { - cell_nb_faces[j] = 4; - // face 0 - Face f0({cell_nodes[0], cell_nodes[1]}, node_number_vector); - face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); - - // face 1 - Face f1({cell_nodes[1], cell_nodes[2]}, node_number_vector); - face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); - - // face 2 - Face f2({cell_nodes[2], cell_nodes[3]}, node_number_vector); - face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); - - // face 3 - Face f3({cell_nodes[3], cell_nodes[0]}, node_number_vector); - face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); - break; - } - default: { - perr() << name(descriptor.cell_type_vector[j]) - << ": unexpected cell type in dimension 2!\n"; - std::terminate(); - } + case CellType::Triangle: { + cell_nb_faces[j] = 3; + // face 0 + Face f0({cell_nodes[1], cell_nodes[2]}, node_number_vector); + face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); + + // face 1 + Face f1({cell_nodes[2], cell_nodes[0]}, node_number_vector); + face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); + + // face 2 + Face f2({cell_nodes[0], cell_nodes[1]}, node_number_vector); + face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); + break; + } + case CellType::Quadrangle: { + cell_nb_faces[j] = 4; + // face 0 + Face f0({cell_nodes[0], cell_nodes[1]}, node_number_vector); + face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); + + // face 1 + Face f1({cell_nodes[1], cell_nodes[2]}, node_number_vector); + face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); + + // face 2 + Face f2({cell_nodes[2], cell_nodes[3]}, node_number_vector); + face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); + + // face 3 + Face f3({cell_nodes[3], cell_nodes[0]}, node_number_vector); + face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); + break; + } + default: { + perr() << name(descriptor.cell_type_vector[j]) + << ": unexpected cell type in dimension 2!\n"; + std::terminate(); + } } - } else if constexpr (Dimension==3) { + } else if constexpr (Dimension == 3) { switch (descriptor.cell_type_vector[j]) { - case CellType::Tetrahedron: { - cell_nb_faces[j] = 4; - // face 0 - Face f0({cell_nodes[1], - cell_nodes[2], - cell_nodes[3]}, node_number_vector); - face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); - - // face 1 - Face f1({cell_nodes[0], - cell_nodes[3], - cell_nodes[2]}, node_number_vector); - face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); - - // face 2 - Face f2({cell_nodes[0], - cell_nodes[1], - cell_nodes[3]}, node_number_vector); - face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); - - // face 3 - Face f3({cell_nodes[0], - cell_nodes[2], - cell_nodes[1]}, node_number_vector); - face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); - break; - } - case CellType::Hexahedron: { - // face 0 - Face f0({cell_nodes[3], - cell_nodes[2], - cell_nodes[1], - cell_nodes[0]}, node_number_vector); - face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); - - // face 1 - Face f1({cell_nodes[4], - cell_nodes[5], - cell_nodes[6], - cell_nodes[7]}, node_number_vector); - face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); - - // face 2 - Face f2({cell_nodes[0], - cell_nodes[4], - cell_nodes[7], - cell_nodes[3]}, node_number_vector); - face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); - - // face 3 - Face f3({cell_nodes[1], - cell_nodes[2], - cell_nodes[6], - cell_nodes[5]}, node_number_vector); - face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); - - // face 4 - Face f4({cell_nodes[0], - cell_nodes[1], - cell_nodes[5], - cell_nodes[4]}, node_number_vector); - face_cells_map[f4].emplace_back(std::make_tuple(j, 4, f4.reversed())); - - // face 5 - Face f5({cell_nodes[3], - cell_nodes[7], - cell_nodes[6], - cell_nodes[2]}, node_number_vector); - face_cells_map[f5].emplace_back(std::make_tuple(j, 5, f5.reversed())); - - cell_nb_faces[j] = 6; - break; - } - default: { - perr() << name(descriptor.cell_type_vector[j]) - << ": unexpected cell type in dimension 3!\n"; - std::terminate(); - } + case CellType::Tetrahedron: { + cell_nb_faces[j] = 4; + // face 0 + Face f0({cell_nodes[1], cell_nodes[2], cell_nodes[3]}, + node_number_vector); + face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); + + // face 1 + Face f1({cell_nodes[0], cell_nodes[3], cell_nodes[2]}, + node_number_vector); + face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); + + // face 2 + Face f2({cell_nodes[0], cell_nodes[1], cell_nodes[3]}, + node_number_vector); + face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); + + // face 3 + Face f3({cell_nodes[0], cell_nodes[2], cell_nodes[1]}, + node_number_vector); + face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); + break; + } + case CellType::Hexahedron: { + // face 0 + Face f0({cell_nodes[3], cell_nodes[2], cell_nodes[1], cell_nodes[0]}, + node_number_vector); + face_cells_map[f0].emplace_back(std::make_tuple(j, 0, f0.reversed())); + + // face 1 + Face f1({cell_nodes[4], cell_nodes[5], cell_nodes[6], cell_nodes[7]}, + node_number_vector); + face_cells_map[f1].emplace_back(std::make_tuple(j, 1, f1.reversed())); + + // face 2 + Face f2({cell_nodes[0], cell_nodes[4], cell_nodes[7], cell_nodes[3]}, + node_number_vector); + face_cells_map[f2].emplace_back(std::make_tuple(j, 2, f2.reversed())); + + // face 3 + Face f3({cell_nodes[1], cell_nodes[2], cell_nodes[6], cell_nodes[5]}, + node_number_vector); + face_cells_map[f3].emplace_back(std::make_tuple(j, 3, f3.reversed())); + + // face 4 + Face f4({cell_nodes[0], cell_nodes[1], cell_nodes[5], cell_nodes[4]}, + node_number_vector); + face_cells_map[f4].emplace_back(std::make_tuple(j, 4, f4.reversed())); + + // face 5 + Face f5({cell_nodes[3], cell_nodes[7], cell_nodes[6], cell_nodes[2]}, + node_number_vector); + face_cells_map[f5].emplace_back(std::make_tuple(j, 5, f5.reversed())); + + cell_nb_faces[j] = 6; + break; + } + default: { + perr() << name(descriptor.cell_type_vector[j]) + << ": unexpected cell type in dimension 3!\n"; + std::terminate(); + } } } } { - descriptor.cell_to_face_vector.resize(descriptor.cell_to_node_vector.size()); - for (CellId j=0; j<descriptor.cell_to_face_vector.size(); ++j) { + descriptor.cell_to_face_vector.resize( + descriptor.cell_to_node_vector.size()); + for (CellId j = 0; j < descriptor.cell_to_face_vector.size(); ++j) { descriptor.cell_to_face_vector[j].resize(cell_nb_faces[j]); } - FaceId l=0; + FaceId l = 0; for (const auto& face_cells_vector : face_cells_map) { const auto& cells_vector = face_cells_vector.second; - for (unsigned short lj=0; lj<cells_vector.size(); ++lj) { - const auto& [cell_number, cell_local_face, reversed] = cells_vector[lj]; + for (unsigned short lj = 0; lj < cells_vector.size(); ++lj) { + const auto& [cell_number, cell_local_face, reversed] = cells_vector[lj]; descriptor.cell_to_face_vector[cell_number][cell_local_face] = l; } ++l; @@ -926,24 +945,28 @@ GmshReader::__computeCellFaceAndFaceNodeConnectivities(ConnectivityDescriptor& d } { - descriptor.cell_face_is_reversed_vector.resize(descriptor.cell_to_node_vector.size()); - for (CellId j=0; j<descriptor.cell_face_is_reversed_vector.size(); ++j) { - descriptor.cell_face_is_reversed_vector[j] = Array<bool>(cell_nb_faces[j]); + descriptor.cell_face_is_reversed_vector.resize( + descriptor.cell_to_node_vector.size()); + for (CellId j = 0; j < descriptor.cell_face_is_reversed_vector.size(); + ++j) { + descriptor.cell_face_is_reversed_vector[j] = + Array<bool>(cell_nb_faces[j]); } for (const auto& face_cells_vector : face_cells_map) { const auto& cells_vector = face_cells_vector.second; - for (unsigned short lj=0; lj<cells_vector.size(); ++lj) { + for (unsigned short lj = 0; lj < cells_vector.size(); ++lj) { const auto& [cell_number, cell_local_face, reversed] = cells_vector[lj]; - descriptor.cell_face_is_reversed_vector[cell_number][cell_local_face] = reversed; + descriptor.cell_face_is_reversed_vector[cell_number][cell_local_face] = + reversed; } } } { descriptor.face_to_node_vector.resize(face_cells_map.size()); - int l=0; + int l = 0; for (const auto& face_info : face_cells_map) { - const Face& face = face_info.first; + const Face& face = face_info.first; descriptor.face_to_node_vector[l] = face.nodeIdList(); ++l; } @@ -952,49 +975,53 @@ GmshReader::__computeCellFaceAndFaceNodeConnectivities(ConnectivityDescriptor& d { // Face numbers may change if numbers are provided in the file descriptor.face_number_vector.resize(face_cells_map.size()); - for (size_t l=0; l<face_cells_map.size(); ++l) { + for (size_t l = 0; l < face_cells_map.size(); ++l) { descriptor.face_number_vector[l] = l; } } } - template <size_t Dimension> void -GmshReader::__computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities(ConnectivityDescriptor& descriptor) +GmshReader::__computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities( + ConnectivityDescriptor& descriptor) { - static_assert(Dimension==3, "Invalid dimension to compute face-edge connectivities"); + static_assert(Dimension == 3, + "Invalid dimension to compute face-edge connectivities"); using FaceEdgeInfo = std::tuple<FaceId, unsigned short, bool>; - using Edge = ConnectivityFace<2>; + using Edge = ConnectivityFace<2>; const auto& node_number_vector = descriptor.node_number_vector; Array<unsigned short> face_nb_edges(descriptor.face_to_node_vector.size()); std::map<Edge, std::vector<FaceEdgeInfo>> edge_faces_map; - for (FaceId l=0; l<descriptor.face_to_node_vector.size(); ++l) { + for (FaceId l = 0; l < descriptor.face_to_node_vector.size(); ++l) { const auto& face_nodes = descriptor.face_to_node_vector[l]; face_nb_edges[l] = face_nodes.size(); - for (size_t r=0; r<face_nodes.size()-1; ++r) { - Edge e({face_nodes[r], face_nodes[r+1]}, node_number_vector); + for (size_t r = 0; r < face_nodes.size() - 1; ++r) { + Edge e({face_nodes[r], face_nodes[r + 1]}, node_number_vector); edge_faces_map[e].emplace_back(std::make_tuple(l, r, e.reversed())); } { - Edge e({face_nodes[face_nodes.size()-1], face_nodes[0]}, node_number_vector); - edge_faces_map[e].emplace_back(std::make_tuple(l, face_nodes.size()-1, e.reversed())); + Edge e({face_nodes[face_nodes.size() - 1], face_nodes[0]}, + node_number_vector); + edge_faces_map[e].emplace_back( + std::make_tuple(l, face_nodes.size() - 1, e.reversed())); } } - std::unordered_map<Edge,EdgeId,typename Edge::Hash> edge_id_map; + std::unordered_map<Edge, EdgeId, typename Edge::Hash> edge_id_map; { - descriptor.face_to_edge_vector.resize(descriptor.face_to_node_vector.size()); - for (FaceId l=0; l<descriptor.face_to_node_vector.size(); ++l) { + descriptor.face_to_edge_vector.resize( + descriptor.face_to_node_vector.size()); + for (FaceId l = 0; l < descriptor.face_to_node_vector.size(); ++l) { descriptor.face_to_edge_vector[l].resize(face_nb_edges[l]); } - EdgeId e=0; + EdgeId e = 0; for (const auto& edge_faces_vector : edge_faces_map) { const auto& faces_vector = edge_faces_vector.second; - for (unsigned short l=0; l<faces_vector.size(); ++l) { - const auto& [face_number, face_local_edge, reversed] = faces_vector[l]; + for (unsigned short l = 0; l < faces_vector.size(); ++l) { + const auto& [face_number, face_local_edge, reversed] = faces_vector[l]; descriptor.face_to_edge_vector[face_number][face_local_edge] = e; } edge_id_map[edge_faces_vector.first] = e; @@ -1003,24 +1030,28 @@ GmshReader::__computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities(ConnectivityDe } { - descriptor.face_edge_is_reversed_vector.resize(descriptor.face_to_node_vector.size()); - for (FaceId j=0; j<descriptor.face_edge_is_reversed_vector.size(); ++j) { - descriptor.face_edge_is_reversed_vector[j] = Array<bool>(face_nb_edges[j]); + descriptor.face_edge_is_reversed_vector.resize( + descriptor.face_to_node_vector.size()); + for (FaceId j = 0; j < descriptor.face_edge_is_reversed_vector.size(); + ++j) { + descriptor.face_edge_is_reversed_vector[j] = + Array<bool>(face_nb_edges[j]); } for (const auto& edge_faces_vector : edge_faces_map) { const auto& faces_vector = edge_faces_vector.second; - for (unsigned short lj=0; lj<faces_vector.size(); ++lj) { + for (unsigned short lj = 0; lj < faces_vector.size(); ++lj) { const auto& [face_number, face_local_edge, reversed] = faces_vector[lj]; - descriptor.face_edge_is_reversed_vector[face_number][face_local_edge] = reversed; + descriptor.face_edge_is_reversed_vector[face_number][face_local_edge] = + reversed; } } } { descriptor.edge_to_node_vector.resize(edge_faces_map.size()); - int e=0; + int e = 0; for (const auto& edge_info : edge_faces_map) { - const Edge& edge = edge_info.first; + const Edge& edge = edge_info.first; descriptor.edge_to_node_vector[e] = edge.nodeIdList(); ++e; } @@ -1029,144 +1060,146 @@ GmshReader::__computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities(ConnectivityDe { // Edge numbers may change if numbers are provided in the file descriptor.edge_number_vector.resize(edge_faces_map.size()); - for (size_t e=0; e<edge_faces_map.size(); ++e) { + for (size_t e = 0; e < edge_faces_map.size(); ++e) { descriptor.edge_number_vector[e] = e; } } { - descriptor.cell_to_node_vector.reserve(descriptor.cell_to_node_vector.size()); - for (CellId j=0; j<descriptor.cell_to_node_vector.size(); ++j) { + descriptor.cell_to_node_vector.reserve( + descriptor.cell_to_node_vector.size()); + for (CellId j = 0; j < descriptor.cell_to_node_vector.size(); ++j) { const auto& cell_nodes = descriptor.cell_to_node_vector[j]; switch (descriptor.cell_type_vector[j]) { - case CellType::Tetrahedron: { - constexpr int local_edge[6][2] = {{0,1}, {0,2}, {0,3}, {1,2}, {2,3}, {3,1}}; - std::vector<unsigned int> cell_edge_vector; - cell_edge_vector.reserve(6); - for (int i_edge=0; i_edge<6; ++i_edge) { - const auto e = local_edge[i_edge]; - Edge edge{{cell_nodes[e[0]],cell_nodes[e[1]]}, node_number_vector}; - auto i = edge_id_map.find(edge); - if (i == edge_id_map.end()) { - std::cerr << "could not find this edge!\n"; - std::terminate(); + case CellType::Tetrahedron: { + constexpr int local_edge[6][2] = {{0, 1}, {0, 2}, {0, 3}, + {1, 2}, {2, 3}, {3, 1}}; + std::vector<unsigned int> cell_edge_vector; + cell_edge_vector.reserve(6); + for (int i_edge = 0; i_edge < 6; ++i_edge) { + const auto e = local_edge[i_edge]; + Edge edge{{cell_nodes[e[0]], cell_nodes[e[1]]}, node_number_vector}; + auto i = edge_id_map.find(edge); + if (i == edge_id_map.end()) { + std::cerr << "could not find this edge!\n"; + std::terminate(); + } + cell_edge_vector.push_back(i->second); } - cell_edge_vector.push_back(i->second); + descriptor.cell_to_edge_vector.emplace_back(cell_edge_vector); + break; } - descriptor.cell_to_edge_vector.emplace_back(cell_edge_vector); - break; - } - case CellType::Hexahedron: { - constexpr int local_edge[12][2] = {{0,1}, {1,2}, {2,3}, {3,0}, - {4,5}, {5,6}, {6,7}, {7,4}, - {0,4}, {1,5}, {2,6}, {3,7}}; - std::vector<unsigned int> cell_edge_vector; - cell_edge_vector.reserve(12); - for (int i_edge=0; i_edge<12; ++i_edge) { - const auto e = local_edge[i_edge]; - Edge edge{{cell_nodes[e[0]],cell_nodes[e[1]]}, node_number_vector}; - auto i = edge_id_map.find(edge); - if (i == edge_id_map.end()) { - std::cerr << "could not find this edge!\n"; - std::terminate(); + case CellType::Hexahedron: { + constexpr int local_edge[12][2] = {{0, 1}, {1, 2}, {2, 3}, {3, 0}, + {4, 5}, {5, 6}, {6, 7}, {7, 4}, + {0, 4}, {1, 5}, {2, 6}, {3, 7}}; + std::vector<unsigned int> cell_edge_vector; + cell_edge_vector.reserve(12); + for (int i_edge = 0; i_edge < 12; ++i_edge) { + const auto e = local_edge[i_edge]; + Edge edge{{cell_nodes[e[0]], cell_nodes[e[1]]}, node_number_vector}; + auto i = edge_id_map.find(edge); + if (i == edge_id_map.end()) { + std::cerr << "could not find this edge!\n"; + std::terminate(); + } + cell_edge_vector.push_back(i->second); } - cell_edge_vector.push_back(i->second); + descriptor.cell_to_edge_vector.emplace_back(cell_edge_vector); + break; + } + default: { + perr() << name(descriptor.cell_type_vector[j]) + << ": unexpected cell type in dimension 3!\n"; + std::terminate(); } - descriptor.cell_to_edge_vector.emplace_back(cell_edge_vector); - break; - } - default: { - perr() << name(descriptor.cell_type_vector[j]) - << ": unexpected cell type in dimension 3!\n"; - std::terminate(); - } } } } } - void GmshReader::__proceedData() { - TinyVector<15,int> elementNumber = zero; - std::vector<std::set<size_t> > elementReferences(15); + TinyVector<15, int> elementNumber = zero; + std::vector<std::set<size_t>> elementReferences(15); - for (size_t i=0; i<__elementType.size(); ++i) { + for (size_t i = 0; i < __elementType.size(); ++i) { const int elementType = __elementType[i]; elementNumber[elementType]++; elementReferences[elementType].insert(__references[i]); } - for (size_t i=0; i<elementNumber.dimension(); ++i) { - if (elementNumber[i]>0) { - pout() << " - Number of " - << __primitivesNames[i] - << ": " << elementNumber[i]; + for (size_t i = 0; i < elementNumber.dimension(); ++i) { + if (elementNumber[i] > 0) { + pout() << " - Number of " << __primitivesNames[i] << ": " + << elementNumber[i]; if (not(__supportedPrimitives[i])) { - pout() << " [" << rang::fg::yellow << "IGNORED" << rang::style::reset << "]"; + pout() << " [" << rang::fg::yellow << "IGNORED" << rang::style::reset + << "]"; } else { pout() << " references: "; - for(std::set<size_t>::const_iterator iref - = elementReferences[i].begin(); - iref != elementReferences[i].end(); ++iref) { - if (iref != elementReferences[i].begin()) pout() << ','; + for (std::set<size_t>::const_iterator iref = + elementReferences[i].begin(); + iref != elementReferences[i].end(); ++iref) { + if (iref != elementReferences[i].begin()) + pout() << ','; pout() << *iref; } switch (i) { // Supported entities - case 0: { // edges + case 0: { // edges __edges = Array<Edge>(elementNumber[i]); __edges_ref.resize(elementNumber[i]); __edges_number.resize(elementNumber[i]); break; } - case 1: { // triangles + case 1: { // triangles __triangles = Array<Triangle>(elementNumber[i]); __triangles_ref.resize(elementNumber[i]); __triangles_number.resize(elementNumber[i]); break; } - case 2: { // quadrangles + case 2: { // quadrangles __quadrangles = Array<Quadrangle>(elementNumber[i]); __quadrangles_ref.resize(elementNumber[i]); __quadrangles_number.resize(elementNumber[i]); break; } - case 3: { // tetrahedra + case 3: { // tetrahedra __tetrahedra = Array<Tetrahedron>(elementNumber[i]); __tetrahedra_ref.resize(elementNumber[i]); __tetrahedra_number.resize(elementNumber[i]); break; } - case 4: {// hexahedra + case 4: { // hexahedra __hexahedra = Array<Hexahedron>(elementNumber[i]); __hexahedra_ref.resize(elementNumber[i]); __hexahedra_number.resize(elementNumber[i]); break; } - case 14: {// point + case 14: { // point __points = Array<Point>(elementNumber[i]); __points_ref.resize(elementNumber[i]); __points_number.resize(elementNumber[i]); break; } // Unsupported entities - case 5: // prism - case 6: // pyramid - case 7: // second order edge - case 8: // second order triangle - case 9: // second order quadrangle - case 10: // second order tetrahedron - case 11: // second order hexahedron - case 12: // second order prism - case 13: // second order pyramid + case 5: // prism + case 6: // pyramid + case 7: // second order edge + case 8: // second order triangle + case 9: // second order quadrangle + case 10: // second order tetrahedron + case 11: // second order hexahedron + case 12: // second order prism + case 13: // second order pyramid default: { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': ff3d cannot read this kind of element", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': ff3d cannot read this kind of element", ErrorHandler::normal); } } @@ -1178,23 +1211,23 @@ GmshReader::__proceedData() pout() << "- Building correspondance table\n"; int minNumber = std::numeric_limits<int>::max(); int maxNumber = std::numeric_limits<int>::min(); - for (size_t i=0; i<__verticesNumbers.size(); ++i) { + for (size_t i = 0; i < __verticesNumbers.size(); ++i) { const int& vertexNumber = __verticesNumbers[i]; - minNumber = std::min(minNumber,vertexNumber); - maxNumber = std::max(maxNumber,vertexNumber); + minNumber = std::min(minNumber, vertexNumber); + maxNumber = std::max(maxNumber, vertexNumber); } - if (minNumber<0) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': ff3d does not implement negative vertices number", + if (minNumber < 0) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': ff3d does not implement negative vertices number", ErrorHandler::normal); } // A value of -1 means that the vertex is unknown - __verticesCorrepondance.resize(maxNumber+1,-1); + __verticesCorrepondance.resize(maxNumber + 1, -1); - for (size_t i=0; i<__verticesNumbers.size(); ++i) { + for (size_t i = 0; i < __verticesNumbers.size(); ++i) { __verticesCorrepondance[__verticesNumbers[i]] = i; } @@ -1202,89 +1235,87 @@ GmshReader::__proceedData() elementNumber = zero; // Element structures filling - for (size_t i=0; i<__elementType.size(); ++i) { + for (size_t i = 0; i < __elementType.size(); ++i) { std::vector<int>& elementVertices = __elementVertices[i]; switch (__elementType[i]) { // Supported entities - case 0: { // edge + case 0: { // edge int& edgeNumber = elementNumber[0]; - const int a = __verticesCorrepondance[elementVertices[0]]; - const int b = __verticesCorrepondance[elementVertices[1]]; - if ((a<0) or (b<0)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': error reading element "+std::to_string(i) - +" [bad vertices definition]", + const int a = __verticesCorrepondance[elementVertices[0]]; + const int b = __verticesCorrepondance[elementVertices[1]]; + if ((a < 0) or (b < 0)) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': error reading element " + std::to_string(i) + + " [bad vertices definition]", ErrorHandler::normal); } - __edges[edgeNumber] - = Edge(a, b); - __edges_ref[edgeNumber] = __references[i]; + __edges[edgeNumber] = Edge(a, b); + __edges_ref[edgeNumber] = __references[i]; __edges_number[edgeNumber] = __elementNumber[i]; - edgeNumber++; // one more edge + edgeNumber++; // one more edge break; } - case 1: { // triangles + case 1: { // triangles int& triangleNumber = elementNumber[1]; const int a = __verticesCorrepondance[elementVertices[0]]; const int b = __verticesCorrepondance[elementVertices[1]]; const int c = __verticesCorrepondance[elementVertices[2]]; - if ((a<0) or (b<0) or (c<0)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': error reading element "+std::to_string(i) - +" [bad vertices definition]", + if ((a < 0) or (b < 0) or (c < 0)) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': error reading element " + std::to_string(i) + + " [bad vertices definition]", ErrorHandler::normal); } - __triangles[triangleNumber] - = Triangle(a, b, c); - __triangles_ref[triangleNumber] = __references[i]; + __triangles[triangleNumber] = Triangle(a, b, c); + __triangles_ref[triangleNumber] = __references[i]; __triangles_number[triangleNumber] = __elementNumber[i]; - triangleNumber++; // one more triangle + triangleNumber++; // one more triangle break; } - case 2: { // quadrangle + case 2: { // quadrangle int& quadrilateralNumber = elementNumber[2]; const int a = __verticesCorrepondance[elementVertices[0]]; const int b = __verticesCorrepondance[elementVertices[1]]; const int c = __verticesCorrepondance[elementVertices[2]]; const int d = __verticesCorrepondance[elementVertices[3]]; - if ((a<0) or (b<0) or (c<0) or (d<0)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': error reading element "+std::to_string(i) - +" [bad vertices definition]", + if ((a < 0) or (b < 0) or (c < 0) or (d < 0)) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': error reading element " + std::to_string(i) + + " [bad vertices definition]", ErrorHandler::normal); } - __quadrangles[quadrilateralNumber] = Quadrangle(a,b,c,d); - __quadrangles_ref[quadrilateralNumber] = __references[i]; + __quadrangles[quadrilateralNumber] = Quadrangle(a, b, c, d); + __quadrangles_ref[quadrilateralNumber] = __references[i]; __quadrangles_number[quadrilateralNumber] = __elementNumber[i]; - quadrilateralNumber++; // one more quadrangle + quadrilateralNumber++; // one more quadrangle break; } - case 3: { // tetrahedra + case 3: { // tetrahedra int& tetrahedronNumber = elementNumber[3]; const int a = __verticesCorrepondance[elementVertices[0]]; const int b = __verticesCorrepondance[elementVertices[1]]; const int c = __verticesCorrepondance[elementVertices[2]]; const int d = __verticesCorrepondance[elementVertices[3]]; - if ((a<0) or (b<0) or (c<0) or (d<0)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': error reading element "+std::to_string(i) - +" [bad vertices definition]", + if ((a < 0) or (b < 0) or (c < 0) or (d < 0)) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': error reading element " + std::to_string(i) + + " [bad vertices definition]", ErrorHandler::normal); } - __tetrahedra[tetrahedronNumber] = Tetrahedron(a, b, c, d); - __tetrahedra_ref[tetrahedronNumber] = __references[i]; + __tetrahedra[tetrahedronNumber] = Tetrahedron(a, b, c, d); + __tetrahedra_ref[tetrahedronNumber] = __references[i]; __tetrahedra_number[tetrahedronNumber] = __elementNumber[i]; - tetrahedronNumber++; // one more tetrahedron + tetrahedronNumber++; // one more tetrahedron break; } - case 4: { // hexaredron + case 4: { // hexaredron int& hexahedronNumber = elementNumber[4]; const int a = __verticesCorrepondance[elementVertices[0]]; @@ -1295,75 +1326,78 @@ GmshReader::__proceedData() const int f = __verticesCorrepondance[elementVertices[5]]; const int g = __verticesCorrepondance[elementVertices[6]]; const int h = __verticesCorrepondance[elementVertices[7]]; - if ((a<0) or (b<0) or (c<0) or (d<0) or (e<0) or (f<0) or (g<0) or (h<0)) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': error reading element "+std::to_string(i) - +" [bad vertices definition]", + if ((a < 0) or (b < 0) or (c < 0) or (d < 0) or (e < 0) or (f < 0) or + (g < 0) or (h < 0)) { + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': error reading element " + std::to_string(i) + + " [bad vertices definition]", ErrorHandler::normal); } - __hexahedra[hexahedronNumber] - = Hexahedron(a, b, c, d, - e, f, g, h); + __hexahedra[hexahedronNumber] = Hexahedron(a, b, c, d, e, f, g, h); __hexahedra_ref[hexahedronNumber] = __references[i]; __hexahedra_number[hexahedronNumber] = __elementNumber[i]; - hexahedronNumber++; // one more hexahedron + hexahedronNumber++; // one more hexahedron break; } // Unsupported entities - case 14:{// point - int& point_number = elementNumber[14]; - const int a = __verticesCorrepondance[elementVertices[0]]; + case 14: { // point + int& point_number = elementNumber[14]; + const int a = __verticesCorrepondance[elementVertices[0]]; __points[point_number] = a; - __points_ref[point_number] = __references[i]; + __points_ref[point_number] = __references[i]; __points_number[point_number] = __elementNumber[i]; point_number++; break; } - case 5: // prism - case 6: // pyramid - case 7: // second order edge - case 8: // second order triangle - case 9: // second order quadrangle - case 10: // second order tetrahedron - case 11: // second order hexahedron - case 12: // second order prism - case 13:{// second order pyramid + case 5: // prism + case 6: // pyramid + case 7: // second order edge + case 8: // second order triangle + case 9: // second order quadrangle + case 10: // second order tetrahedron + case 11: // second order hexahedron + case 12: // second order prism + case 13: { // second order pyramid } default: { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': ff3d cannot read this kind of element", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': ff3d cannot read this kind of element", ErrorHandler::normal); } } } - TinyVector<15,int> dimension0_mask = zero; - dimension0_mask[14]=1; - TinyVector<15,int> dimension1_mask = zero; - dimension1_mask[0]=1; - dimension1_mask[7]=1; - TinyVector<15,int> dimension2_mask = zero; - dimension2_mask[1]=1; - dimension2_mask[2]=1; - dimension2_mask[8]=1; - dimension2_mask[9]=1; - TinyVector<15,int> dimension3_mask = zero; - dimension3_mask[3]=1; - dimension3_mask[4]=1; - dimension3_mask[5]=1; - dimension3_mask[6]=1; - dimension3_mask[10]=1; - dimension3_mask[11]=1; - dimension3_mask[12]=1; - dimension3_mask[13]=1; - - pout() << "- dimension 0 entities: " << (dimension0_mask, elementNumber) << '\n'; - pout() << "- dimension 1 entities: " << (dimension1_mask, elementNumber) << '\n'; - pout() << "- dimension 2 entities: " << (dimension2_mask, elementNumber) << '\n'; - pout() << "- dimension 3 entities: " << (dimension3_mask, elementNumber) << '\n'; - if ((dimension3_mask, elementNumber)>0) { + TinyVector<15, int> dimension0_mask = zero; + dimension0_mask[14] = 1; + TinyVector<15, int> dimension1_mask = zero; + dimension1_mask[0] = 1; + dimension1_mask[7] = 1; + TinyVector<15, int> dimension2_mask = zero; + dimension2_mask[1] = 1; + dimension2_mask[2] = 1; + dimension2_mask[8] = 1; + dimension2_mask[9] = 1; + TinyVector<15, int> dimension3_mask = zero; + dimension3_mask[3] = 1; + dimension3_mask[4] = 1; + dimension3_mask[5] = 1; + dimension3_mask[6] = 1; + dimension3_mask[10] = 1; + dimension3_mask[11] = 1; + dimension3_mask[12] = 1; + dimension3_mask[13] = 1; + + pout() << "- dimension 0 entities: " << (dimension0_mask, elementNumber) + << '\n'; + pout() << "- dimension 1 entities: " << (dimension1_mask, elementNumber) + << '\n'; + pout() << "- dimension 2 entities: " << (dimension2_mask, elementNumber) + << '\n'; + pout() << "- dimension 3 entities: " << (dimension3_mask, elementNumber) + << '\n'; + if ((dimension3_mask, elementNumber) > 0) { const size_t nb_cells = (dimension3_mask, elementNumber); ConnectivityDescriptor descriptor; @@ -1374,46 +1408,47 @@ GmshReader::__proceedData() descriptor.cell_to_node_vector.resize(nb_cells); const size_t nb_tetrahedra = __tetrahedra.size(); - for (size_t j=0; j<nb_tetrahedra; ++j) { + for (size_t j = 0; j < nb_tetrahedra; ++j) { descriptor.cell_to_node_vector[j].resize(4); - for (int r=0; r<4; ++r) { + for (int r = 0; r < 4; ++r) { descriptor.cell_to_node_vector[j][r] = __tetrahedra[j][r]; } - descriptor.cell_type_vector[j] = CellType::Tetrahedron; + descriptor.cell_type_vector[j] = CellType::Tetrahedron; descriptor.cell_number_vector[j] = __tetrahedra_number[j]; } const size_t nb_hexahedra = __hexahedra.size(); - for (size_t j=0; j<nb_hexahedra; ++j) { - const size_t jh = nb_tetrahedra+j; + for (size_t j = 0; j < nb_hexahedra; ++j) { + const size_t jh = nb_tetrahedra + j; descriptor.cell_to_node_vector[jh].resize(8); - for (int r=0; r<8; ++r) { + for (int r = 0; r < 8; ++r) { descriptor.cell_to_node_vector[jh][r] = __hexahedra[j][r]; } - descriptor.cell_type_vector[jh] = CellType::Hexahedron; + descriptor.cell_type_vector[jh] = CellType::Hexahedron; descriptor.cell_number_vector[jh] = __hexahedra_number[j]; } std::map<unsigned int, std::vector<unsigned int>> ref_cells_map; - for (unsigned int r=0; r<__tetrahedra_ref.size(); ++r) { + for (unsigned int r = 0; r < __tetrahedra_ref.size(); ++r) { const unsigned int elem_number = __tetrahedra_ref[r]; - const unsigned int& ref = __tetrahedra_ref[r]; + const unsigned int& ref = __tetrahedra_ref[r]; ref_cells_map[ref].push_back(elem_number); } - for (unsigned int j=0; j<__hexahedra_ref.size(); ++j) { - const size_t elem_number = nb_tetrahedra+j; - const unsigned int& ref = __hexahedra_ref[j]; + for (unsigned int j = 0; j < __hexahedra_ref.size(); ++j) { + const size_t elem_number = nb_tetrahedra + j; + const unsigned int& ref = __hexahedra_ref[j]; ref_cells_map[ref].push_back(elem_number); } - for (const auto& ref_cell_list : ref_cells_map) { Array<CellId> cell_list(ref_cell_list.second.size()); - for (size_t j=0; j<ref_cell_list.second.size(); ++j) { - cell_list[j]=ref_cell_list.second[j]; + for (size_t j = 0; j < ref_cell_list.second.size(); ++j) { + cell_list[j] = ref_cell_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_cell_list.first); - descriptor.addRefItemList(RefCellList(physical_ref_id.refId(), cell_list)); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_cell_list.first); + descriptor.addRefItemList( + RefCellList(physical_ref_id.refId(), cell_list)); } this->__computeCellFaceAndFaceNodeConnectivities<3>(descriptor); @@ -1422,38 +1457,38 @@ GmshReader::__proceedData() { using Face = ConnectivityFace<3>; - const std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map - = [&] { - std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map; - for (FaceId l=0; l<descriptor.face_to_node_vector.size(); ++l) { - const auto& node_vector = descriptor.face_to_node_vector[l]; - face_to_id_map[Face(node_vector, node_number_vector)] = l; - } - return face_to_id_map; - } (); - - std::unordered_map<int, FaceId> face_number_id_map - = [&] { - std::unordered_map<int, FaceId> face_number_id_map; - for (size_t l=0; l< descriptor.face_number_vector.size(); ++l) { - face_number_id_map[descriptor.face_number_vector[l]] = l; - } - Assert(face_number_id_map.size() == descriptor.face_number_vector.size()); - return face_number_id_map; - } (); + const std::unordered_map<Face, FaceId, typename Face::Hash> + face_to_id_map = [&] { + std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map; + for (FaceId l = 0; l < descriptor.face_to_node_vector.size(); ++l) { + const auto& node_vector = descriptor.face_to_node_vector[l]; + face_to_id_map[Face(node_vector, node_number_vector)] = l; + } + return face_to_id_map; + }(); + + std::unordered_map<int, FaceId> face_number_id_map = [&] { + std::unordered_map<int, FaceId> face_number_id_map; + for (size_t l = 0; l < descriptor.face_number_vector.size(); ++l) { + face_number_id_map[descriptor.face_number_vector[l]] = l; + } + Assert(face_number_id_map.size() == + descriptor.face_number_vector.size()); + return face_number_id_map; + }(); std::map<unsigned int, std::vector<unsigned int>> ref_faces_map; - for (unsigned int f=0; f<__triangles.size(); ++f) { - const unsigned int face_id - = [&]{ - auto i = face_to_id_map.find(Face({__triangles[f][0], __triangles[f][1], __triangles[f][2]}, - node_number_vector)); - if (i == face_to_id_map.end()) { - std::cerr << "face not found!\n"; - std::terminate(); - } - return i->second; - }(); + for (unsigned int f = 0; f < __triangles.size(); ++f) { + const unsigned int face_id = [&] { + auto i = face_to_id_map.find( + Face({__triangles[f][0], __triangles[f][1], __triangles[f][2]}, + node_number_vector)); + if (i == face_to_id_map.end()) { + std::cerr << "face not found!\n"; + std::terminate(); + } + return i->second; + }(); const unsigned int& ref = __triangles_ref[f]; ref_faces_map[ref].push_back(face_id); @@ -1466,29 +1501,34 @@ GmshReader::__proceedData() descriptor.face_number_vector[other_face_id]); face_number_id_map.erase(descriptor.face_number_vector[face_id]); - face_number_id_map.erase(descriptor.face_number_vector[other_face_id]); + face_number_id_map.erase( + descriptor.face_number_vector[other_face_id]); - face_number_id_map[descriptor.face_number_vector[face_id]]=face_id; - face_number_id_map[descriptor.face_number_vector[other_face_id]]=other_face_id; + face_number_id_map[descriptor.face_number_vector[face_id]] = + face_id; + face_number_id_map[descriptor.face_number_vector[other_face_id]] = + other_face_id; } else { face_number_id_map.erase(descriptor.face_number_vector[face_id]); descriptor.face_number_vector[face_id] = __quadrangles_number[f]; - face_number_id_map[descriptor.face_number_vector[face_id]] = face_id; + face_number_id_map[descriptor.face_number_vector[face_id]] = + face_id; } } } - for (unsigned int f=0; f<__quadrangles.size(); ++f) { - const unsigned int face_id - = [&]{ - auto i = face_to_id_map.find(Face({__quadrangles[f][0], __quadrangles[f][1], - __quadrangles[f][2], __quadrangles[f][3]}, node_number_vector)); - if (i == face_to_id_map.end()) { - std::cerr << "face not found!\n"; - std::terminate(); - } - return i->second; - }(); + for (unsigned int f = 0; f < __quadrangles.size(); ++f) { + const unsigned int face_id = [&] { + auto i = + face_to_id_map.find(Face({__quadrangles[f][0], __quadrangles[f][1], + __quadrangles[f][2], __quadrangles[f][3]}, + node_number_vector)); + if (i == face_to_id_map.end()) { + std::cerr << "face not found!\n"; + std::terminate(); + } + return i->second; + }(); const unsigned int& ref = __quadrangles_ref[f]; ref_faces_map[ref].push_back(face_id); @@ -1501,63 +1541,69 @@ GmshReader::__proceedData() descriptor.face_number_vector[other_face_id]); face_number_id_map.erase(descriptor.face_number_vector[face_id]); - face_number_id_map.erase(descriptor.face_number_vector[other_face_id]); + face_number_id_map.erase( + descriptor.face_number_vector[other_face_id]); - face_number_id_map[descriptor.face_number_vector[face_id]]=face_id; - face_number_id_map[descriptor.face_number_vector[other_face_id]]=other_face_id; + face_number_id_map[descriptor.face_number_vector[face_id]] = + face_id; + face_number_id_map[descriptor.face_number_vector[other_face_id]] = + other_face_id; } else { face_number_id_map.erase(descriptor.face_number_vector[face_id]); descriptor.face_number_vector[face_id] = __quadrangles_number[f]; - face_number_id_map[descriptor.face_number_vector[face_id]] = face_id; + face_number_id_map[descriptor.face_number_vector[face_id]] = + face_id; } } } for (const auto& ref_face_list : ref_faces_map) { Array<FaceId> face_list(ref_face_list.second.size()); - for (size_t j=0; j<ref_face_list.second.size(); ++j) { - face_list[j]=ref_face_list.second[j]; + for (size_t j = 0; j < ref_face_list.second.size(); ++j) { + face_list[j] = ref_face_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_face_list.first); - descriptor.addRefItemList(RefFaceList{physical_ref_id.refId(), face_list}); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_face_list.first); + descriptor.addRefItemList( + RefFaceList{physical_ref_id.refId(), face_list}); } } this->__computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities<3>(descriptor); { - using Edge = ConnectivityFace<2>; + using Edge = ConnectivityFace<2>; const auto& node_number_vector = descriptor.node_number_vector; - const std::unordered_map<Edge, EdgeId, typename Edge::Hash> edge_to_id_map - = [&] { - std::unordered_map<Edge, EdgeId, typename Edge::Hash> edge_to_id_map; - for (EdgeId l=0; l<descriptor.edge_to_node_vector.size(); ++l) { - const auto& node_vector = descriptor.edge_to_node_vector[l]; - edge_to_id_map[Edge(node_vector, node_number_vector)] = l; - } - return edge_to_id_map; - } (); - - std::unordered_map<int, EdgeId> edge_number_id_map - = [&] { - std::unordered_map<int, EdgeId> edge_number_id_map; - for (size_t l=0; l< descriptor.edge_number_vector.size(); ++l) { - edge_number_id_map[descriptor.edge_number_vector[l]] = l; - } - Assert(edge_number_id_map.size() == descriptor.edge_number_vector.size()); - return edge_number_id_map; - } (); + const std::unordered_map<Edge, EdgeId, typename Edge::Hash> + edge_to_id_map = [&] { + std::unordered_map<Edge, EdgeId, typename Edge::Hash> edge_to_id_map; + for (EdgeId l = 0; l < descriptor.edge_to_node_vector.size(); ++l) { + const auto& node_vector = descriptor.edge_to_node_vector[l]; + edge_to_id_map[Edge(node_vector, node_number_vector)] = l; + } + return edge_to_id_map; + }(); + + std::unordered_map<int, EdgeId> edge_number_id_map = [&] { + std::unordered_map<int, EdgeId> edge_number_id_map; + for (size_t l = 0; l < descriptor.edge_number_vector.size(); ++l) { + edge_number_id_map[descriptor.edge_number_vector[l]] = l; + } + Assert(edge_number_id_map.size() == + descriptor.edge_number_vector.size()); + return edge_number_id_map; + }(); std::map<unsigned int, std::vector<unsigned int>> ref_edges_map; - for (unsigned int e=0; e<__edges.size(); ++e) { - const unsigned int edge_id - = [&]{ - auto i = edge_to_id_map.find(Edge({__edges[e][0], __edges[e][1]}, node_number_vector)); - if (i == edge_to_id_map.end()) { - std::cerr << "edge " << __edges[e][0] << " not found!\n"; - std::terminate(); - } - return i->second; - }(); + for (unsigned int e = 0; e < __edges.size(); ++e) { + const unsigned int edge_id = [&] { + auto i = edge_to_id_map.find( + Edge({__edges[e][0], __edges[e][1]}, node_number_vector)); + if (i == edge_to_id_map.end()) { + std::cerr << "edge " << __edges[e][0] << " not found!\n"; + std::terminate(); + } + return i->second; + }(); const unsigned int& ref = __edges_ref[e]; ref_edges_map[ref].push_back(edge_id); @@ -1569,79 +1615,83 @@ GmshReader::__proceedData() descriptor.edge_number_vector[other_edge_id]); edge_number_id_map.erase(descriptor.edge_number_vector[edge_id]); - edge_number_id_map.erase(descriptor.edge_number_vector[other_edge_id]); + edge_number_id_map.erase( + descriptor.edge_number_vector[other_edge_id]); - edge_number_id_map[descriptor.edge_number_vector[edge_id]]=edge_id; - edge_number_id_map[descriptor.edge_number_vector[other_edge_id]]=other_edge_id; + edge_number_id_map[descriptor.edge_number_vector[edge_id]] = + edge_id; + edge_number_id_map[descriptor.edge_number_vector[other_edge_id]] = + other_edge_id; } else { edge_number_id_map.erase(descriptor.edge_number_vector[edge_id]); descriptor.edge_number_vector[edge_id] = __edges_number[e]; - edge_number_id_map[descriptor.edge_number_vector[edge_id]] = edge_id; + edge_number_id_map[descriptor.edge_number_vector[edge_id]] = + edge_id; } } } for (const auto& ref_edge_list : ref_edges_map) { Array<EdgeId> edge_list(ref_edge_list.second.size()); - for (size_t j=0; j<ref_edge_list.second.size(); ++j) { - edge_list[j]=ref_edge_list.second[j]; + for (size_t j = 0; j < ref_edge_list.second.size(); ++j) { + edge_list[j] = ref_edge_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_edge_list.first); - descriptor.addRefItemList(RefEdgeList{physical_ref_id.refId(), edge_list}); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_edge_list.first); + descriptor.addRefItemList( + RefEdgeList{physical_ref_id.refId(), edge_list}); } } std::map<unsigned int, std::vector<unsigned int>> ref_points_map; - for (unsigned int r=0; r<__points.size(); ++r) { + for (unsigned int r = 0; r < __points.size(); ++r) { const unsigned int point_number = __points[r]; - const unsigned int& ref = __points_ref[r]; + const unsigned int& ref = __points_ref[r]; ref_points_map[ref].push_back(point_number); } for (const auto& ref_point_list : ref_points_map) { Array<NodeId> point_list(ref_point_list.second.size()); - for (size_t j=0; j<ref_point_list.second.size(); ++j) { - point_list[j]=ref_point_list.second[j]; + for (size_t j = 0; j < ref_point_list.second.size(); ++j) { + point_list[j] = ref_point_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_point_list.first); - descriptor.addRefItemList(RefNodeList(physical_ref_id.refId(), point_list)); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_point_list.first); + descriptor.addRefItemList( + RefNodeList(physical_ref_id.refId(), point_list)); } descriptor.cell_owner_vector.resize(nb_cells); std::fill(descriptor.cell_owner_vector.begin(), - descriptor.cell_owner_vector.end(), - parallel::rank()); + descriptor.cell_owner_vector.end(), parallel::rank()); descriptor.face_owner_vector.resize(descriptor.face_number_vector.size()); std::fill(descriptor.face_owner_vector.begin(), - descriptor.face_owner_vector.end(), - parallel::rank()); + descriptor.face_owner_vector.end(), parallel::rank()); descriptor.edge_owner_vector.resize(descriptor.edge_number_vector.size()); std::fill(descriptor.edge_owner_vector.begin(), - descriptor.edge_owner_vector.end(), - parallel::rank()); + descriptor.edge_owner_vector.end(), parallel::rank()); descriptor.node_owner_vector.resize(descriptor.node_number_vector.size()); std::fill(descriptor.node_owner_vector.begin(), - descriptor.node_owner_vector.end(), - parallel::rank()); + descriptor.node_owner_vector.end(), parallel::rank()); std::shared_ptr p_connectivity = Connectivity3D::build(descriptor); - Connectivity3D& connectivity = *p_connectivity; + Connectivity3D& connectivity = *p_connectivity; using MeshType = Mesh<Connectivity3D>; - using Rd = TinyVector<3, double>; + using Rd = TinyVector<3, double>; NodeValue<Rd> xr(connectivity); - for (NodeId i=0; i<__vertices.size(); ++i) { + for (NodeId i = 0; i < __vertices.size(); ++i) { xr[i][0] = __vertices[i][0]; xr[i][1] = __vertices[i][1]; xr[i][2] = __vertices[i][2]; } m_mesh = std::make_shared<MeshType>(p_connectivity, xr); - } else if ((dimension2_mask, elementNumber)>0) { + } else if ((dimension2_mask, elementNumber) > 0) { const size_t nb_cells = (dimension2_mask, elementNumber); ConnectivityDescriptor descriptor; @@ -1652,83 +1702,84 @@ GmshReader::__proceedData() descriptor.cell_to_node_vector.resize(nb_cells); const size_t nb_triangles = __triangles.size(); - for (size_t j=0; j<nb_triangles; ++j) { + for (size_t j = 0; j < nb_triangles; ++j) { descriptor.cell_to_node_vector[j].resize(3); - for (int r=0; r<3; ++r) { + for (int r = 0; r < 3; ++r) { descriptor.cell_to_node_vector[j][r] = __triangles[j][r]; } - descriptor.cell_type_vector[j] = CellType::Triangle; + descriptor.cell_type_vector[j] = CellType::Triangle; descriptor.cell_number_vector[j] = __triangles_number[j]; } const size_t nb_quadrangles = __quadrangles.size(); - for (size_t j=0; j<nb_quadrangles; ++j) { - const size_t jq = j+nb_triangles; + for (size_t j = 0; j < nb_quadrangles; ++j) { + const size_t jq = j + nb_triangles; descriptor.cell_to_node_vector[jq].resize(4); - for (int r=0; r<4; ++r) { + for (int r = 0; r < 4; ++r) { descriptor.cell_to_node_vector[jq][r] = __quadrangles[j][r]; } - descriptor.cell_type_vector[jq] = CellType::Quadrangle; + descriptor.cell_type_vector[jq] = CellType::Quadrangle; descriptor.cell_number_vector[jq] = __quadrangles_number[j]; } std::map<unsigned int, std::vector<unsigned int>> ref_cells_map; - for (unsigned int r=0; r<__triangles_ref.size(); ++r) { + for (unsigned int r = 0; r < __triangles_ref.size(); ++r) { const unsigned int elem_number = __triangles_ref[r]; - const unsigned int& ref = __triangles_ref[r]; + const unsigned int& ref = __triangles_ref[r]; ref_cells_map[ref].push_back(elem_number); } - for (unsigned int j=0; j<__quadrangles_ref.size(); ++j) { - const size_t elem_number = nb_triangles+j; - const unsigned int& ref = __quadrangles_ref[j]; + for (unsigned int j = 0; j < __quadrangles_ref.size(); ++j) { + const size_t elem_number = nb_triangles + j; + const unsigned int& ref = __quadrangles_ref[j]; ref_cells_map[ref].push_back(elem_number); } for (const auto& ref_cell_list : ref_cells_map) { Array<CellId> cell_list(ref_cell_list.second.size()); - for (size_t j=0; j<ref_cell_list.second.size(); ++j) { - cell_list[j]=ref_cell_list.second[j]; + for (size_t j = 0; j < ref_cell_list.second.size(); ++j) { + cell_list[j] = ref_cell_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_cell_list.first); - descriptor.addRefItemList(RefCellList(physical_ref_id.refId(), cell_list)); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_cell_list.first); + descriptor.addRefItemList( + RefCellList(physical_ref_id.refId(), cell_list)); } this->__computeCellFaceAndFaceNodeConnectivities<2>(descriptor); - using Face = ConnectivityFace<2>; + using Face = ConnectivityFace<2>; const auto& node_number_vector = descriptor.node_number_vector; - const std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map - = [&] { - std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map; - for (FaceId l=0; l<descriptor.face_to_node_vector.size(); ++l) { - const auto& node_vector = descriptor.face_to_node_vector[l]; - face_to_id_map[Face(node_vector, node_number_vector)] = l; - } - return face_to_id_map; - } (); - - std::unordered_map<int, FaceId> face_number_id_map - = [&] { - std::unordered_map<int, FaceId> face_number_id_map; - for (size_t l=0; l< descriptor.face_number_vector.size(); ++l) { - face_number_id_map[descriptor.face_number_vector[l]] = l; - } - Assert(face_number_id_map.size() == descriptor.face_number_vector.size()); - return face_number_id_map; - } (); + const std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map = + [&] { + std::unordered_map<Face, FaceId, typename Face::Hash> face_to_id_map; + for (FaceId l = 0; l < descriptor.face_to_node_vector.size(); ++l) { + const auto& node_vector = descriptor.face_to_node_vector[l]; + face_to_id_map[Face(node_vector, node_number_vector)] = l; + } + return face_to_id_map; + }(); + + std::unordered_map<int, FaceId> face_number_id_map = [&] { + std::unordered_map<int, FaceId> face_number_id_map; + for (size_t l = 0; l < descriptor.face_number_vector.size(); ++l) { + face_number_id_map[descriptor.face_number_vector[l]] = l; + } + Assert(face_number_id_map.size() == descriptor.face_number_vector.size()); + return face_number_id_map; + }(); std::map<unsigned int, std::vector<unsigned int>> ref_faces_map; - for (unsigned int e=0; e<__edges.size(); ++e) { - const unsigned int edge_id - = [&]{ - auto i = face_to_id_map.find(Face({__edges[e][0], __edges[e][1]}, node_number_vector)); - if (i == face_to_id_map.end()) { - std::cerr << "face " << __edges[e][0] << " not found!\n"; - std::terminate(); - } - return i->second; - }(); + for (unsigned int e = 0; e < __edges.size(); ++e) { + const unsigned int edge_id = [&] { + auto i = face_to_id_map.find( + Face({__edges[e][0], __edges[e][1]}, node_number_vector)); + if (i == face_to_id_map.end()) { + std::cerr << "face " << __edges[e][0] << " not found!\n"; + std::terminate(); + } + return i->second; + }(); const unsigned int& ref = __edges_ref[e]; ref_faces_map[ref].push_back(edge_id); @@ -1740,10 +1791,12 @@ GmshReader::__proceedData() descriptor.face_number_vector[other_edge_id]); face_number_id_map.erase(descriptor.face_number_vector[edge_id]); - face_number_id_map.erase(descriptor.face_number_vector[other_edge_id]); + face_number_id_map.erase( + descriptor.face_number_vector[other_edge_id]); - face_number_id_map[descriptor.face_number_vector[edge_id]]=edge_id; - face_number_id_map[descriptor.face_number_vector[other_edge_id]]=other_edge_id; + face_number_id_map[descriptor.face_number_vector[edge_id]] = edge_id; + face_number_id_map[descriptor.face_number_vector[other_edge_id]] = + other_edge_id; } else { face_number_id_map.erase(descriptor.face_number_vector[edge_id]); descriptor.face_number_vector[edge_id] = __edges_number[e]; @@ -1754,58 +1807,59 @@ GmshReader::__proceedData() for (const auto& ref_face_list : ref_faces_map) { Array<FaceId> face_list(ref_face_list.second.size()); - for (size_t j=0; j<ref_face_list.second.size(); ++j) { - face_list[j]=ref_face_list.second[j]; + for (size_t j = 0; j < ref_face_list.second.size(); ++j) { + face_list[j] = ref_face_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_face_list.first); - descriptor.addRefItemList(RefFaceList{physical_ref_id.refId(), face_list}); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_face_list.first); + descriptor.addRefItemList( + RefFaceList{physical_ref_id.refId(), face_list}); } std::map<unsigned int, std::vector<unsigned int>> ref_points_map; - for (unsigned int r=0; r<__points.size(); ++r) { + for (unsigned int r = 0; r < __points.size(); ++r) { const unsigned int point_number = __points[r]; - const unsigned int& ref = __points_ref[r]; + const unsigned int& ref = __points_ref[r]; ref_points_map[ref].push_back(point_number); } for (const auto& ref_point_list : ref_points_map) { Array<NodeId> point_list(ref_point_list.second.size()); - for (size_t j=0; j<ref_point_list.second.size(); ++j) { - point_list[j]=ref_point_list.second[j]; + for (size_t j = 0; j < ref_point_list.second.size(); ++j) { + point_list[j] = ref_point_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_point_list.first); - descriptor.addRefItemList(RefNodeList(physical_ref_id.refId(), point_list)); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_point_list.first); + descriptor.addRefItemList( + RefNodeList(physical_ref_id.refId(), point_list)); } descriptor.cell_owner_vector.resize(nb_cells); std::fill(descriptor.cell_owner_vector.begin(), - descriptor.cell_owner_vector.end(), - parallel::rank()); + descriptor.cell_owner_vector.end(), parallel::rank()); descriptor.face_owner_vector.resize(descriptor.face_number_vector.size()); std::fill(descriptor.face_owner_vector.begin(), - descriptor.face_owner_vector.end(), - parallel::rank()); + descriptor.face_owner_vector.end(), parallel::rank()); descriptor.node_owner_vector.resize(descriptor.node_number_vector.size()); std::fill(descriptor.node_owner_vector.begin(), - descriptor.node_owner_vector.end(), - parallel::rank()); + descriptor.node_owner_vector.end(), parallel::rank()); std::shared_ptr p_connectivity = Connectivity2D::build(descriptor); - Connectivity2D& connectivity = *p_connectivity; + Connectivity2D& connectivity = *p_connectivity; using MeshType = Mesh<Connectivity2D>; - using Rd = TinyVector<2, double>; + using Rd = TinyVector<2, double>; NodeValue<Rd> xr(connectivity); - for (NodeId i=0; i<__vertices.size(); ++i) { + for (NodeId i = 0; i < __vertices.size(); ++i) { xr[i][0] = __vertices[i][0]; xr[i][1] = __vertices[i][1]; } m_mesh = std::make_shared<MeshType>(p_connectivity, xr); - } else if ((dimension1_mask, elementNumber)>0) { + } else if ((dimension1_mask, elementNumber) > 0) { const size_t nb_cells = (dimension1_mask, elementNumber); ConnectivityDescriptor descriptor; @@ -1815,50 +1869,49 @@ GmshReader::__proceedData() descriptor.cell_number_vector.resize(nb_cells); descriptor.cell_to_node_vector.resize(nb_cells); - for (size_t j=0; j<nb_cells; ++j) { + for (size_t j = 0; j < nb_cells; ++j) { descriptor.cell_to_node_vector[j].resize(2); - for (int r=0; r<2; ++r) { + for (int r = 0; r < 2; ++r) { descriptor.cell_to_node_vector[j][r] = __edges[j][r]; } - descriptor.cell_type_vector[j] = CellType::Line; - descriptor.cell_number_vector[j] = __edges_number[j]; + descriptor.cell_type_vector[j] = CellType::Line; + descriptor.cell_number_vector[j] = __edges_number[j]; } - std::map<unsigned int, std::vector<unsigned int>> ref_points_map; - for (unsigned int r=0; r<__points.size(); ++r) { + for (unsigned int r = 0; r < __points.size(); ++r) { const unsigned int point_number = __points[r]; - const unsigned int& ref = __points_ref[r]; + const unsigned int& ref = __points_ref[r]; ref_points_map[ref].push_back(point_number); } for (const auto& ref_point_list : ref_points_map) { Array<NodeId> point_list(ref_point_list.second.size()); - for (size_t j=0; j<ref_point_list.second.size(); ++j) { - point_list[j]=ref_point_list.second[j]; + for (size_t j = 0; j < ref_point_list.second.size(); ++j) { + point_list[j] = ref_point_list.second[j]; } - const PhysicalRefId& physical_ref_id = m_physical_ref_map.at(ref_point_list.first); - descriptor.addRefItemList(RefNodeList(physical_ref_id.refId(), point_list)); + const PhysicalRefId& physical_ref_id = + m_physical_ref_map.at(ref_point_list.first); + descriptor.addRefItemList( + RefNodeList(physical_ref_id.refId(), point_list)); } descriptor.cell_owner_vector.resize(nb_cells); std::fill(descriptor.cell_owner_vector.begin(), - descriptor.cell_owner_vector.end(), - parallel::rank()); + descriptor.cell_owner_vector.end(), parallel::rank()); descriptor.node_owner_vector.resize(descriptor.node_number_vector.size()); std::fill(descriptor.node_owner_vector.begin(), - descriptor.node_owner_vector.end(), - parallel::rank()); + descriptor.node_owner_vector.end(), parallel::rank()); std::shared_ptr p_connectivity = Connectivity1D::build(descriptor); - Connectivity1D& connectivity = *p_connectivity; + Connectivity1D& connectivity = *p_connectivity; using MeshType = Mesh<Connectivity1D>; - using Rd = TinyVector<1, double>; + using Rd = TinyVector<1, double>; NodeValue<Rd> xr(connectivity); - for (NodeId i=0; i<__vertices.size(); ++i) { + for (NodeId i = 0; i < __vertices.size(); ++i) { xr[i][0] = __vertices[i][0]; } @@ -1885,23 +1938,23 @@ GmshReader::__nextKeyword() KeywordList::iterator i = __keywordList.find(aKeyword.c_str()); if (i != __keywordList.end()) { - kw.first = (*i).first; + kw.first = (*i).first; kw.second = (*i).second; return kw; } - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': unknown keyword '"+aKeyword+"'", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + "': unknown keyword '" + + aKeyword + "'", ErrorHandler::normal); - kw.first = aKeyword; + kw.first = aKeyword; kw.second = Unknown; return kw; } -void GmshReader:: -__readGmshFormat2_2() +void +GmshReader::__readGmshFormat2_2() { pout() << "- Reading Gmsh format 2.2\n"; GmshReader::Keyword kw = std::make_pair("", Unknown); @@ -1911,9 +1964,10 @@ __readGmshFormat2_2() case NODES: { this->__readVertices(); if (this->__nextKeyword().second != ENDNODES) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': expecting $EndNodes, '"+kw.first+"' was found", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': expecting $EndNodes, '" + kw.first + + "' was found", ErrorHandler::normal); } break; @@ -1922,9 +1976,10 @@ __readGmshFormat2_2() this->__readElements2_2(); kw = this->__nextKeyword(); if (kw.second != ENDELEMENTS) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': expecting $EndElements, '"+kw.first+"' was found", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': expecting $EndElements, '" + kw.first + + "' was found", ErrorHandler::normal); } break; @@ -1932,9 +1987,10 @@ __readGmshFormat2_2() case PHYSICALNAMES: { this->__readPhysicalNames2_2(); if (this->__nextKeyword().second != ENDPHYSICALNAMES) { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': expecting $EndNodes, '"+kw.first+"' was found", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + + "': expecting $EndNodes, '" + kw.first + + "' was found", ErrorHandler::normal); } break; @@ -1944,9 +2000,9 @@ __readGmshFormat2_2() break; } default: { - throw ErrorHandler(__FILE__,__LINE__, - "reading file '"+m_filename - +"': unexpected '"+kw.first+"'", + throw ErrorHandler(__FILE__, __LINE__, + "reading file '" + m_filename + "': unexpected '" + + kw.first + "'", ErrorHandler::normal); } } diff --git a/src/mesh/GmshReader.hpp b/src/mesh/GmshReader.hpp index cd482e637..616532476 100644 --- a/src/mesh/GmshReader.hpp +++ b/src/mesh/GmshReader.hpp @@ -8,17 +8,17 @@ #include <RefId.hpp> -#include <string> #include <array> -#include <vector> -#include <map> #include <fstream> +#include <map> +#include <string> +#include <vector> class ConnectivityDescriptor; class GmshReader { -public: + public: using R3 = TinyVector<3, double>; class PhysicalRefId @@ -28,49 +28,52 @@ public: RefId m_ref_id; public: - friend std::ostream& operator<<(std::ostream& os, - const PhysicalRefId& physical_ref_id) + friend std::ostream& + operator<<(std::ostream& os, const PhysicalRefId& physical_ref_id) { - os << physical_ref_id.m_ref_id << "[dimension " << physical_ref_id.m_dimension << "]"; + os << physical_ref_id.m_ref_id << "[dimension " + << physical_ref_id.m_dimension << "]"; return os; } - bool operator<(const PhysicalRefId& physical_ref_id) const + bool + operator<(const PhysicalRefId& physical_ref_id) const { - return m_ref_id.tagNumber()<physical_ref_id.m_ref_id.tagNumber(); + return m_ref_id.tagNumber() < physical_ref_id.m_ref_id.tagNumber(); } - bool operator==(const PhysicalRefId& physical_ref_id) const + bool + operator==(const PhysicalRefId& physical_ref_id) const { - return m_ref_id.tagNumber()==physical_ref_id.m_ref_id.tagNumber(); + return m_ref_id.tagNumber() == physical_ref_id.m_ref_id.tagNumber(); } - const int& dimension() const + const int& + dimension() const { return m_dimension; } - const RefId& refId() const + const RefId& + refId() const { return m_ref_id; } PhysicalRefId& operator=(const PhysicalRefId&) = default; - PhysicalRefId& operator=(PhysicalRefId&&) =default; - PhysicalRefId(const int& dimension, - const RefId& ref_id) - : m_dimension(dimension), - m_ref_id(ref_id) + PhysicalRefId& operator=(PhysicalRefId&&) = default; + PhysicalRefId(const int& dimension, const RefId& ref_id) + : m_dimension(dimension), m_ref_id(ref_id) { ; } - PhysicalRefId() = default; + PhysicalRefId() = default; PhysicalRefId(const PhysicalRefId&) = default; - PhysicalRefId(PhysicalRefId&&) = default; - ~PhysicalRefId() = default; + PhysicalRefId(PhysicalRefId&&) = default; + ~PhysicalRefId() = default; }; -private: + private: std::ifstream m_fin; const std::string m_filename; @@ -87,27 +90,27 @@ private: std::vector<int> __points_ref; std::vector<int> __points_number; - using Edge = TinyVector<2,unsigned int>; + using Edge = TinyVector<2, unsigned int>; Array<Edge> __edges; std::vector<int> __edges_ref; std::vector<int> __edges_number; - using Triangle = TinyVector<3,unsigned int>; + using Triangle = TinyVector<3, unsigned int>; Array<Triangle> __triangles; std::vector<int> __triangles_ref; std::vector<int> __triangles_number; - using Quadrangle = TinyVector<4,unsigned int>; + using Quadrangle = TinyVector<4, unsigned int>; Array<Quadrangle> __quadrangles; std::vector<int> __quadrangles_ref; std::vector<int> __quadrangles_number; - using Tetrahedron = TinyVector<4,unsigned int>; + using Tetrahedron = TinyVector<4, unsigned int>; Array<Tetrahedron> __tetrahedra; std::vector<int> __tetrahedra_ref; std::vector<int> __tetrahedra_number; - using Hexahedron = TinyVector<8,unsigned int>; + using Hexahedron = TinyVector<8, unsigned int>; Array<Hexahedron> __hexahedra; std::vector<int> __hexahedra_ref; std::vector<int> __hexahedra_number; @@ -156,12 +159,13 @@ private: */ std::map<int, std::string> __primitivesNames; - bool __binary; /**< true if binary format */ - bool __convertEndian; /**< true if needs to adapt endianess */ + bool __binary; /**< true if binary format */ + bool __convertEndian; /**< true if needs to adapt endianess */ std::map<unsigned int, PhysicalRefId> m_physical_ref_map; - int _getInteger() + int + _getInteger() { int i; m_fin >> i; @@ -169,7 +173,8 @@ private: return i; } - double _getReal() + double + _getReal() { double d; m_fin >> d; @@ -193,7 +198,8 @@ private: * List of allowed keyword in mesh file * */ - enum KeywordType { + enum KeywordType + { // gmsh 2.2 MESHFORMAT, ENDMESHFORMAT, @@ -214,7 +220,7 @@ private: */ using KeywordList = std::map<std::string, int>; - KeywordList __keywordList; /**< The keyword list */ + KeywordList __keywordList; /**< The keyword list */ /** * Type for keyword @@ -260,18 +266,21 @@ private: void __readPhysicalNames2_2(); template <size_t Dimension> - void __computeCellFaceAndFaceNodeConnectivities(ConnectivityDescriptor& descriptor); + void __computeCellFaceAndFaceNodeConnectivities( + ConnectivityDescriptor& descriptor); template <size_t Dimension> - void __computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities(ConnectivityDescriptor& descriptor); + void __computeFaceEdgeAndEdgeNodeAndCellEdgeConnectivities( + ConnectivityDescriptor& descriptor); template <int Dimension> void _dispatch(); std::shared_ptr<IMesh> m_mesh; -public: - std::shared_ptr<IMesh> mesh() const + public: + std::shared_ptr<IMesh> + mesh() const { return m_mesh; } @@ -280,4 +289,4 @@ public: ~GmshReader() = default; }; -#endif // GMSH_READER_HPP +#endif // GMSH_READER_HPP diff --git a/src/mesh/IConnectivity.hpp b/src/mesh/IConnectivity.hpp index 63ae03f3a..a5a4bd365 100644 --- a/src/mesh/IConnectivity.hpp +++ b/src/mesh/IConnectivity.hpp @@ -1,28 +1,26 @@ #ifndef ICONNECTIVITY_HPP #define ICONNECTIVITY_HPP -#include <ItemType.hpp> -#include <ItemOfItemType.hpp> #include <ConnectivityMatrix.hpp> +#include <ItemOfItemType.hpp> +#include <ItemType.hpp> #include <memory> class IConnectivity : public std::enable_shared_from_this<IConnectivity> { protected: - template <typename DataType, - typename ItemOfItem, - typename ConnectivityPtr> - friend - class SubItemValuePerItem; + template <typename DataType, typename ItemOfItem, typename ConnectivityPtr> + friend class SubItemValuePerItem; - virtual const ConnectivityMatrix& - _getMatrix(const ItemType& item_type_0, - const ItemType& item_type_1) const = 0; + virtual const ConnectivityMatrix& _getMatrix( + const ItemType& item_type_0, + const ItemType& item_type_1) const = 0; public: virtual size_t dimension() const = 0; - std::shared_ptr<const IConnectivity> shared_ptr() const + std::shared_ptr<const IConnectivity> + shared_ptr() const { return this->shared_from_this(); } @@ -35,37 +33,37 @@ class IConnectivity : public std::enable_shared_from_this<IConnectivity> template <ItemType item_type> size_t numberOf() const = delete; - IConnectivity() = default; + IConnectivity() = default; IConnectivity(const IConnectivity&) = delete; - ~IConnectivity() = default; + ~IConnectivity() = default; }; template <> -PASTIS_INLINE -size_t IConnectivity::numberOf<ItemType::node>() const +PASTIS_INLINE size_t +IConnectivity::numberOf<ItemType::node>() const { return this->numberOfNodes(); } template <> -PASTIS_INLINE -size_t IConnectivity::numberOf<ItemType::edge>() const +PASTIS_INLINE size_t +IConnectivity::numberOf<ItemType::edge>() const { return this->numberOfEdges(); } template <> -PASTIS_INLINE -size_t IConnectivity::numberOf<ItemType::face>() const +PASTIS_INLINE size_t +IConnectivity::numberOf<ItemType::face>() const { return this->numberOfFaces(); } template <> -PASTIS_INLINE -size_t IConnectivity::numberOf<ItemType::cell>() const +PASTIS_INLINE size_t +IConnectivity::numberOf<ItemType::cell>() const { return this->numberOfCells(); } -#endif // ICONNECTIVITY_HPP +#endif // ICONNECTIVITY_HPP diff --git a/src/mesh/ItemId.hpp b/src/mesh/ItemId.hpp index 8fc4161e4..a33e3a8e3 100644 --- a/src/mesh/ItemId.hpp +++ b/src/mesh/ItemId.hpp @@ -1,8 +1,8 @@ #ifndef ITEM_ID_HPP #define ITEM_ID_HPP -#include <PastisMacros.hpp> #include <ItemType.hpp> +#include <PastisMacros.hpp> template <ItemType item_type> class ItemIdT @@ -21,7 +21,8 @@ class ItemIdT } PASTIS_INLINE - constexpr ItemIdT operator++(int) + constexpr ItemIdT + operator++(int) { ItemIdT item_id(m_id); ++m_id; @@ -29,14 +30,16 @@ class ItemIdT } PASTIS_INLINE - constexpr ItemIdT& operator++() + constexpr ItemIdT& + operator++() { ++m_id; return *this; } PASTIS_INLINE - constexpr ItemIdT& operator=(const base_type& id) + constexpr ItemIdT& + operator=(const base_type& id) { m_id = id; return *this; @@ -49,7 +52,7 @@ class ItemIdT constexpr ItemIdT& operator=(ItemIdT&&) = default; PASTIS_INLINE - constexpr ItemIdT(const base_type& id) : m_id{id}{} + constexpr ItemIdT(const base_type& id) : m_id{id} {} PASTIS_INLINE constexpr ItemIdT(const ItemIdT&) = default; @@ -67,23 +70,21 @@ class ItemIdT template <ItemType other_item_type> ItemIdT(const ItemIdT<other_item_type>&) { - static_assert(other_item_type == item_type, - "wrong type of item"); + static_assert(other_item_type == item_type, "wrong type of item"); } template <ItemType other_item_type> - ItemIdT& operator=(const ItemIdT<other_item_type>&) + ItemIdT& + operator=(const ItemIdT<other_item_type>&) { - static_assert(other_item_type == item_type, - "wrong type of item"); + static_assert(other_item_type == item_type, "wrong type of item"); } - template <ItemType other_item_type> - ItemIdT& operator=(ItemIdT<other_item_type>&&) + ItemIdT& + operator=(ItemIdT<other_item_type>&&) { - static_assert(other_item_type == item_type, - "wrong type of item"); + static_assert(other_item_type == item_type, "wrong type of item"); } }; @@ -92,4 +93,4 @@ using EdgeId = ItemIdT<ItemType::edge>; using FaceId = ItemIdT<ItemType::face>; using CellId = ItemIdT<ItemType::cell>; -#endif // ITEM_ID_HPP +#endif // ITEM_ID_HPP diff --git a/src/mesh/ItemOfItemType.hpp b/src/mesh/ItemOfItemType.hpp index 53a7d5ffe..027e35c96 100644 --- a/src/mesh/ItemOfItemType.hpp +++ b/src/mesh/ItemOfItemType.hpp @@ -3,14 +3,14 @@ #include <ItemType.hpp> -template <ItemType sub_item_t, - ItemType item_t> +template <ItemType sub_item_t, ItemType item_t> struct ItemOfItemType { - static_assert(sub_item_t != item_t, "item and its sub-item cannot be of same type"); + static_assert(sub_item_t != item_t, + "item and its sub-item cannot be of same type"); constexpr static ItemType sub_item_type = sub_item_t; - constexpr static ItemType item_type = item_t; + constexpr static ItemType item_type = item_t; using Reversed = ItemOfItemType<item_type, sub_item_type>; }; @@ -31,4 +31,4 @@ using CellOfNode = ItemOfItemType<ItemType::cell, ItemType::node>; using FaceOfNode = ItemOfItemType<ItemType::face, ItemType::node>; using EdgeOfNode = ItemOfItemType<ItemType::edge, ItemType::node>; -#endif // ITEM_OF_ITEM_TYPE_HPP +#endif // ITEM_OF_ITEM_TYPE_HPP diff --git a/src/mesh/ItemToItemMatrix.hpp b/src/mesh/ItemToItemMatrix.hpp index bf62537d3..66e4f8126 100644 --- a/src/mesh/ItemToItemMatrix.hpp +++ b/src/mesh/ItemToItemMatrix.hpp @@ -1,14 +1,13 @@ #ifndef ITEM_TO_ITEM_MATRIX_HPP #define ITEM_TO_ITEM_MATRIX_HPP -#include <ItemType.hpp> #include <ItemId.hpp> +#include <ItemType.hpp> -#include <PastisUtils.hpp> #include <ConnectivityMatrix.hpp> +#include <PastisUtils.hpp> -template <ItemType SourceItemType, - ItemType TargetItemType> +template <ItemType SourceItemType, ItemType TargetItemType> class ItemToItemMatrix { public: @@ -22,9 +21,9 @@ class ItemToItemMatrix const RowType m_row; public: - PASTIS_INLINE - size_t size() const + size_t + size() const { return m_row.length; } @@ -36,8 +35,7 @@ class ItemToItemMatrix } PASTIS_INLINE - SubItemList(const RowType& row) - : m_row{row} + SubItemList(const RowType& row) : m_row{row} { ; } @@ -62,12 +60,14 @@ class ItemToItemMatrix const ConnectivityMatrix& m_connectivity_matrix; public: - auto numberOfEntries() const + auto + numberOfEntries() const { return m_connectivity_matrix.numEntries(); } - auto entries() const + auto + entries() const { return m_connectivity_matrix.entries(); } @@ -80,8 +80,7 @@ class ItemToItemMatrix } template <typename IndexType> - PASTIS_INLINE - const auto& operator[](const IndexType& source_id) const + PASTIS_INLINE const auto& operator[](const IndexType& source_id) const { static_assert(std::is_same_v<IndexType, SourceItemId>, "ItemToItemMatrix must be indexed using correct ItemId"); @@ -91,7 +90,7 @@ class ItemToItemMatrix PASTIS_INLINE ItemToItemMatrix(const ConnectivityMatrix& connectivity_matrix) - : m_connectivity_matrix{connectivity_matrix} + : m_connectivity_matrix{connectivity_matrix} { ; } @@ -112,4 +111,4 @@ class ItemToItemMatrix ~ItemToItemMatrix() = default; }; -#endif // ITEM_TO_ITEM_MATRIX_HPP +#endif // ITEM_TO_ITEM_MATRIX_HPP diff --git a/src/mesh/ItemType.hpp b/src/mesh/ItemType.hpp index e9de61530..659e95aca 100644 --- a/src/mesh/ItemType.hpp +++ b/src/mesh/ItemType.hpp @@ -1,9 +1,9 @@ #ifndef ITEM_TYPE_HPP #define ITEM_TYPE_HPP -#include <utility> #include <limits> #include <string> +#include <utility> enum class ItemType { @@ -14,10 +14,11 @@ enum class ItemType }; PASTIS_INLINE -constexpr std::string_view itemName(const ItemType& item_type) +constexpr std::string_view +itemName(const ItemType& item_type) { std::string_view name; - switch(item_type){ + switch (item_type) { case ItemType::node: { name = "node"; break; @@ -39,24 +40,27 @@ constexpr std::string_view itemName(const ItemType& item_type) } template <size_t Dimension> -struct ItemTypeId {}; +struct ItemTypeId +{}; template <> struct ItemTypeId<1> { PASTIS_INLINE - static constexpr size_t itemTId(const ItemType& item_type) { + static constexpr size_t + itemTId(const ItemType& item_type) + { size_t i = std::numeric_limits<size_t>::max(); - switch(item_type) { + switch (item_type) { case ItemType::cell: { - i=0; + i = 0; break; } case ItemType::edge: case ItemType::face: case ItemType::node: { // in 1d, faces, edges and nodes are the same - i=1; + i = 1; break; } } @@ -68,21 +72,23 @@ template <> struct ItemTypeId<2> { PASTIS_INLINE - static constexpr size_t itemTId(const ItemType& item_type) { + static constexpr size_t + itemTId(const ItemType& item_type) + { size_t i = std::numeric_limits<size_t>::max(); - switch(item_type) { + switch (item_type) { case ItemType::cell: { - i=0; + i = 0; break; } case ItemType::edge: case ItemType::face: { // in 2d, faces and edges are the same - i=1; + i = 1; break; } case ItemType::node: { - i=2; + i = 2; break; } } @@ -94,23 +100,25 @@ template <> struct ItemTypeId<3> { PASTIS_INLINE - static constexpr size_t itemTId(const ItemType& item_type) { + static constexpr size_t + itemTId(const ItemType& item_type) + { size_t i = std::numeric_limits<size_t>::max(); - switch(item_type) { + switch (item_type) { case ItemType::cell: { - i=0; + i = 0; break; } case ItemType::edge: { - i=1; + i = 1; break; } case ItemType::face: { - i=2; + i = 2; break; } case ItemType::node: { - i=3; + i = 3; break; } } @@ -119,7 +127,6 @@ struct ItemTypeId<3> }; template <ItemType item_type> -PASTIS_INLINE -constexpr bool is_false_item_type_v = false; +PASTIS_INLINE constexpr bool is_false_item_type_v = false; -#endif // ITEM_TYPE_HPP +#endif // ITEM_TYPE_HPP diff --git a/src/mesh/ItemValue.hpp b/src/mesh/ItemValue.hpp index 827daa32d..07ce36712 100644 --- a/src/mesh/ItemValue.hpp +++ b/src/mesh/ItemValue.hpp @@ -6,8 +6,8 @@ #include <Array.hpp> -#include <ItemType.hpp> #include <ItemId.hpp> +#include <ItemType.hpp> #include <IConnectivity.hpp> #include <memory> @@ -21,12 +21,12 @@ class ItemValue static constexpr ItemType item_t{item_type}; using data_type = DataType; - using ItemId = ItemIdT<item_type>; + using ItemId = ItemIdT<item_type>; using index_type = ItemId; private: using ConnectivitySharedPtr = std::shared_ptr<const IConnectivity>; - using ConnectivityWeakPtr = std::weak_ptr<const IConnectivity>; + using ConnectivityWeakPtr = std::weak_ptr<const IConnectivity>; static_assert(std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr> or std::is_same_v<ConnectivityPtr, ConnectivityWeakPtr>); @@ -36,18 +36,19 @@ class ItemValue Array<DataType> m_values; // Allow const std:shared_ptr version to access our data - friend ItemValue<std::add_const_t<DataType>, item_type, + friend ItemValue<std::add_const_t<DataType>, + item_type, ConnectivitySharedPtr>; // Allow const std:weak_ptr version to access our data - friend ItemValue<std::add_const_t<DataType>, item_type, - ConnectivityWeakPtr>; + friend ItemValue<std::add_const_t<DataType>, item_type, ConnectivityWeakPtr>; friend PASTIS_INLINE - ItemValue<std::remove_const_t<DataType>,item_type, ConnectivityPtr> - copy(const ItemValue<DataType, item_type, ConnectivityPtr>& source) + ItemValue<std::remove_const_t<DataType>, item_type, ConnectivityPtr> + copy(const ItemValue<DataType, item_type, ConnectivityPtr>& source) { - ItemValue<std::remove_const_t<DataType>, item_type, ConnectivityPtr> image(source); + ItemValue<std::remove_const_t<DataType>, item_type, ConnectivityPtr> image( + source); image.m_values = copy(source.m_values); return image; @@ -55,13 +56,15 @@ class ItemValue public: PASTIS_INLINE - bool isBuilt() const noexcept + bool + isBuilt() const noexcept { return m_connectivity_ptr.use_count() != 0; } PASTIS_INLINE - std::shared_ptr<const IConnectivity> connectivity_ptr() const noexcept + std::shared_ptr<const IConnectivity> + connectivity_ptr() const noexcept { if constexpr (std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr>) { return m_connectivity_ptr; @@ -71,14 +74,16 @@ class ItemValue } PASTIS_INLINE - size_t size() const noexcept(NO_ASSERT) + size_t + size() const noexcept(NO_ASSERT) { Assert(this->isBuilt()); return m_values.size(); } PASTIS_INLINE - void fill(const DataType& data) const noexcept + void + fill(const DataType& data) const noexcept { static_assert(not std::is_const_v<DataType>, "Cannot modify ItemValue of const"); @@ -97,53 +102,54 @@ class ItemValue template <typename IndexType> DataType& operator[](const IndexType&) const noexcept(NO_ASSERT) { - static_assert(std::is_same_v<IndexType,ItemId>, + static_assert(std::is_same_v<IndexType, ItemId>, "ItemValue must be indexed by ItemId"); } PASTIS_INLINE - size_t numberOfItems() const noexcept(NO_ASSERT) + size_t + numberOfItems() const noexcept(NO_ASSERT) { Assert(this->isBuilt()); return m_values.size(); } template <typename DataType2> - PASTIS_INLINE - ItemValue& + PASTIS_INLINE ItemValue& operator=(const Array<DataType2>& values) noexcept(NO_ASSERT) { // ensures that DataType is the same as source DataType2 - static_assert(std::is_same_v<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>, + static_assert(std::is_same_v<std::remove_const_t<DataType>, + std::remove_const_t<DataType2>>, "Cannot assign ItemValue of different type"); // ensures that const is not lost through copy - static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) - or not std::is_const_v<DataType2>), + static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) or + not std::is_const_v<DataType2>), "Cannot assign ItemValue of const to ItemValue of non-const"); Assert((m_values.size() == values.size()), "Cannot assign an array of values of a different size\n"); - Assert ((values.size() == 0) or this->isBuilt(), - "Cannot assign array of values to a non-built ItemValue\n"); + Assert((values.size() == 0) or this->isBuilt(), + "Cannot assign array of values to a non-built ItemValue\n"); m_values = values; return *this; } - template <typename DataType2, - typename ConnectivityPtr2> - PASTIS_INLINE - ItemValue& - operator=(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept + template <typename DataType2, typename ConnectivityPtr2> + PASTIS_INLINE ItemValue& + operator=(const ItemValue<DataType2, item_type, ConnectivityPtr2>& + value_per_item) noexcept { // ensures that DataType is the same as source DataType2 - static_assert(std::is_same_v<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>, + static_assert(std::is_same_v<std::remove_const_t<DataType>, + std::remove_const_t<DataType2>>, "Cannot assign ItemValue of different type"); // ensures that const is not lost through copy - static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) - or not std::is_const_v<DataType2>), + static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) or + not std::is_const_v<DataType2>), "Cannot assign ItemValue of const to ItemValue of non-const"); m_values = value_per_item.m_values; @@ -157,10 +163,10 @@ class ItemValue return *this; } - template <typename DataType2, - typename ConnectivityPtr2> + template <typename DataType2, typename ConnectivityPtr2> PASTIS_INLINE - ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& value_per_item) noexcept + ItemValue(const ItemValue<DataType2, item_type, ConnectivityPtr2>& + value_per_item) noexcept { this->operator=(value_per_item); } @@ -170,11 +176,13 @@ class ItemValue PASTIS_INLINE ItemValue(const IConnectivity& connectivity) noexcept - : m_connectivity_ptr{connectivity.shared_ptr()}, - m_values{connectivity.numberOf<item_type>()} + : m_connectivity_ptr{connectivity.shared_ptr()}, + m_values{connectivity.numberOf<item_type>()} { - static_assert(not std::is_const_v<DataType>, - "Cannot allocate ItemValue of const data: only view is supported"); ; + static_assert( + not std::is_const_v<DataType>, + "Cannot allocate ItemValue of const data: only view is supported"); + ; } PASTIS_INLINE @@ -195,9 +203,9 @@ using CellValue = ItemValue<DataType, ItemType::cell>; // Weak versions: should not be used outside of Connectivity -template <typename DataType, - ItemType item_type> -using WeakItemValue = ItemValue<DataType, item_type, std::weak_ptr<const IConnectivity>>; +template <typename DataType, ItemType item_type> +using WeakItemValue = + ItemValue<DataType, item_type, std::weak_ptr<const IConnectivity>>; template <typename DataType> using WeakNodeValue = WeakItemValue<DataType, ItemType::node>; @@ -211,4 +219,4 @@ using WeakFaceValue = WeakItemValue<DataType, ItemType::face>; template <typename DataType> using WeakCellValue = WeakItemValue<DataType, ItemType::cell>; -#endif // ITEM_VALUE_HPP +#endif // ITEM_VALUE_HPP diff --git a/src/mesh/ItemValueUtils.hpp b/src/mesh/ItemValueUtils.hpp index 6c45be4c2..88f281889 100644 --- a/src/mesh/ItemValueUtils.hpp +++ b/src/mesh/ItemValueUtils.hpp @@ -1,50 +1,51 @@ #ifndef ITEM_VALUE_UTILS_HPP #define ITEM_VALUE_UTILS_HPP -#include <Messenger.hpp> #include <ItemValue.hpp> +#include <Messenger.hpp> #include <Connectivity.hpp> -#include <SynchronizerManager.hpp> #include <Synchronizer.hpp> +#include <SynchronizerManager.hpp> -template <typename DataType, - ItemType item_type> +template <typename DataType, ItemType item_type> std::remove_const_t<DataType> min(const ItemValue<DataType, item_type>& item_value) { using ItemValueType = ItemValue<DataType, item_type>; - using data_type = std::remove_const_t<typename ItemValueType::data_type>; - using index_type = typename ItemValueType::index_type; - - const auto& is_owned - = [&] (const IConnectivity& connectivity) { - Assert((connectivity.dimension()>0) and (connectivity.dimension()<=3), - "unexpected connectivity dimension"); - - switch (connectivity.dimension()) { - case 1: { - const auto& connectivity_1d = static_cast<const Connectivity1D&>(connectivity); - return connectivity_1d.isOwned<item_type>(); - break; - } - case 2: { - const auto& connectivity_2d = static_cast<const Connectivity2D&>(connectivity); - return connectivity_2d.isOwned<item_type>(); - break; - } - case 3: { - const auto& connectivity_3d = static_cast<const Connectivity3D&>(connectivity); - return connectivity_3d.isOwned<item_type>(); - break; - } - default: { - perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; - std::terminate(); - } - } - } (*item_value.connectivity_ptr()); + using data_type = std::remove_const_t<typename ItemValueType::data_type>; + using index_type = typename ItemValueType::index_type; + + const auto& is_owned = [&](const IConnectivity& connectivity) { + Assert((connectivity.dimension() > 0) and (connectivity.dimension() <= 3), + "unexpected connectivity dimension"); + + switch (connectivity.dimension()) { + case 1: { + const auto& connectivity_1d = + static_cast<const Connectivity1D&>(connectivity); + return connectivity_1d.isOwned<item_type>(); + break; + } + case 2: { + const auto& connectivity_2d = + static_cast<const Connectivity2D&>(connectivity); + return connectivity_2d.isOwned<item_type>(); + break; + } + case 3: { + const auto& connectivity_3d = + static_cast<const Connectivity3D&>(connectivity); + return connectivity_3d.isOwned<item_type>(); + break; + } + default: { + perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; + std::terminate(); + } + } + }(*item_value.connectivity_ptr()); using IsOwnedType = std::remove_reference_t<decltype(is_owned)>; @@ -64,7 +65,8 @@ min(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { if ((m_is_owned[i]) and (m_item_value[i] < data)) { data = m_item_value[i]; @@ -72,8 +74,8 @@ min(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { if (src < dst) { dst = src; @@ -81,16 +83,15 @@ min(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { value = std::numeric_limits<data_type>::max(); } PASTIS_INLINE - ItemValueMin(const ItemValueType& item_value, - const IsOwnedType& is_owned) - : m_item_value(item_value), - m_is_owned(is_owned) + ItemValueMin(const ItemValueType& item_value, const IsOwnedType& is_owned) + : m_item_value(item_value), m_is_owned(is_owned) { ; } @@ -103,42 +104,43 @@ min(const ItemValue<DataType, item_type>& item_value) return parallel::allReduceMin(local_min); } -template <typename DataType, - ItemType item_type> +template <typename DataType, ItemType item_type> std::remove_const_t<DataType> max(const ItemValue<DataType, item_type>& item_value) { using ItemValueType = ItemValue<DataType, item_type>; - using data_type = std::remove_const_t<typename ItemValueType::data_type>; - using index_type = typename ItemValueType::index_type; - - const auto& is_owned - = [&] (const IConnectivity& connectivity) { - Assert((connectivity.dimension()>0) and (connectivity.dimension()<=3), - "unexpected connectivity dimension"); - - switch (connectivity.dimension()) { - case 1: { - const auto& connectivity_1d = static_cast<const Connectivity1D&>(connectivity); - return connectivity_1d.isOwned<item_type>(); - break; - } - case 2: { - const auto& connectivity_2d = static_cast<const Connectivity2D&>(connectivity); - return connectivity_2d.isOwned<item_type>(); - break; - } - case 3: { - const auto& connectivity_3d = static_cast<const Connectivity3D&>(connectivity); - return connectivity_3d.isOwned<item_type>(); - break; - } - default: { - perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; - std::terminate(); - } - } - } (*item_value.connectivity_ptr()); + using data_type = std::remove_const_t<typename ItemValueType::data_type>; + using index_type = typename ItemValueType::index_type; + + const auto& is_owned = [&](const IConnectivity& connectivity) { + Assert((connectivity.dimension() > 0) and (connectivity.dimension() <= 3), + "unexpected connectivity dimension"); + + switch (connectivity.dimension()) { + case 1: { + const auto& connectivity_1d = + static_cast<const Connectivity1D&>(connectivity); + return connectivity_1d.isOwned<item_type>(); + break; + } + case 2: { + const auto& connectivity_2d = + static_cast<const Connectivity2D&>(connectivity); + return connectivity_2d.isOwned<item_type>(); + break; + } + case 3: { + const auto& connectivity_3d = + static_cast<const Connectivity3D&>(connectivity); + return connectivity_3d.isOwned<item_type>(); + break; + } + default: { + perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; + std::terminate(); + } + } + }(*item_value.connectivity_ptr()); using IsOwnedType = std::remove_reference_t<decltype(is_owned)>; @@ -158,7 +160,8 @@ max(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { if ((m_is_owned[i]) and (m_item_value[i] > data)) { data = m_item_value[i]; @@ -166,8 +169,8 @@ max(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { if (src > dst) { dst = src; @@ -175,16 +178,15 @@ max(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { value = std::numeric_limits<data_type>::min(); } PASTIS_INLINE - ItemValueMax(const ItemValueType& item_value, - const IsOwnedType& is_owned) - : m_item_value(item_value), - m_is_owned(is_owned) + ItemValueMax(const ItemValueType& item_value, const IsOwnedType& is_owned) + : m_item_value(item_value), m_is_owned(is_owned) { ; } @@ -197,43 +199,43 @@ max(const ItemValue<DataType, item_type>& item_value) return parallel::allReduceMax(local_max); } - -template <typename DataType, - ItemType item_type> +template <typename DataType, ItemType item_type> std::remove_const_t<DataType> sum(const ItemValue<DataType, item_type>& item_value) { using ItemValueType = ItemValue<DataType, item_type>; - using data_type = std::remove_const_t<typename ItemValueType::data_type>; - using index_type = typename ItemValueType::index_type; - - const auto& is_owned - = [&] (const IConnectivity& connectivity) { - Assert((connectivity.dimension()>0) and (connectivity.dimension()<=3), - "unexpected connectivity dimension"); - - switch (connectivity.dimension()) { - case 1: { - const auto& connectivity_1d = static_cast<const Connectivity1D&>(connectivity); - return connectivity_1d.isOwned<item_type>(); - break; - } - case 2: { - const auto& connectivity_2d = static_cast<const Connectivity2D&>(connectivity); - return connectivity_2d.isOwned<item_type>(); - break; - } - case 3: { - const auto& connectivity_3d = static_cast<const Connectivity3D&>(connectivity); - return connectivity_3d.isOwned<item_type>(); - break; - } - default: { - perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; - std::terminate(); - } - } - } (*item_value.connectivity_ptr()); + using data_type = std::remove_const_t<typename ItemValueType::data_type>; + using index_type = typename ItemValueType::index_type; + + const auto& is_owned = [&](const IConnectivity& connectivity) { + Assert((connectivity.dimension() > 0) and (connectivity.dimension() <= 3), + "unexpected connectivity dimension"); + + switch (connectivity.dimension()) { + case 1: { + const auto& connectivity_1d = + static_cast<const Connectivity1D&>(connectivity); + return connectivity_1d.isOwned<item_type>(); + break; + } + case 2: { + const auto& connectivity_2d = + static_cast<const Connectivity2D&>(connectivity); + return connectivity_2d.isOwned<item_type>(); + break; + } + case 3: { + const auto& connectivity_3d = + static_cast<const Connectivity3D&>(connectivity); + return connectivity_3d.isOwned<item_type>(); + break; + } + default: { + perr() << __FILE__ << ':' << __LINE__ << ": unexpected dimension\n"; + std::terminate(); + } + } + }(*item_value.connectivity_ptr()); using IsOwnedType = std::remove_reference_t<decltype(is_owned)>; @@ -253,7 +255,8 @@ sum(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { if (m_is_owned[i]) { data += m_item_value[i]; @@ -261,14 +264,15 @@ sum(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { dst += src; } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { if constexpr (std::is_arithmetic_v<data_type>) { value = 0; @@ -278,10 +282,8 @@ sum(const ItemValue<DataType, item_type>& item_value) } PASTIS_INLINE - ItemValueSum(const ItemValueType& item_value, - const IsOwnedType& is_owned) - : m_item_value(item_value), - m_is_owned(is_owned) + ItemValueSum(const ItemValueType& item_value, const IsOwnedType& is_owned) + : m_item_value(item_value), m_is_owned(is_owned) { ; } @@ -294,18 +296,19 @@ sum(const ItemValue<DataType, item_type>& item_value) return parallel::allReduceSum(local_sum); } -template <typename DataType, - ItemType item_type, - typename ConnectivityPtr> -void synchronize(ItemValue<DataType, item_type, ConnectivityPtr>& item_value) +template <typename DataType, ItemType item_type, typename ConnectivityPtr> +void +synchronize(ItemValue<DataType, item_type, ConnectivityPtr>& item_value) { - static_assert(not std::is_const_v<DataType>, "cannot synchronize ItemValue of const data"); + static_assert(not std::is_const_v<DataType>, + "cannot synchronize ItemValue of const data"); if (parallel::size() > 1) { - auto& manager = SynchronizerManager::instance(); + auto& manager = SynchronizerManager::instance(); const IConnectivity* connectivity = item_value.connectivity_ptr().get(); - Synchronizer& synchronizer = manager.getConnectivitySynchronizer(connectivity); + Synchronizer& synchronizer = + manager.getConnectivitySynchronizer(connectivity); synchronizer.synchronize(item_value); } } -#endif // ITEM_VALUE_UTILS_HPP +#endif // ITEM_VALUE_UTILS_HPP diff --git a/src/mesh/Mesh.hpp b/src/mesh/Mesh.hpp index b103e2294..c9ee9b15a 100644 --- a/src/mesh/Mesh.hpp +++ b/src/mesh/Mesh.hpp @@ -11,62 +11,69 @@ struct IMesh { virtual size_t dimension() const = 0; - ~IMesh() = default; + ~IMesh() = default; }; template <typename ConnectivityType> class Mesh final : public IMesh { -public: + public: using Connectivity = ConnectivityType; static constexpr size_t Dimension = ConnectivityType::Dimension; - using Rd = TinyVector<Dimension>; + using Rd = TinyVector<Dimension>; -private: + private: const std::shared_ptr<const Connectivity> m_connectivity; NodeValue<const Rd> m_xr; NodeValue<Rd> m_mutable_xr; -public: + public: PASTIS_INLINE - size_t dimension() const + size_t + dimension() const { return Dimension; } PASTIS_INLINE - const Connectivity& connectivity() const + const Connectivity& + connectivity() const { return *m_connectivity; } PASTIS_INLINE - size_t numberOfNodes() const + size_t + numberOfNodes() const { return m_connectivity->numberOfNodes(); } PASTIS_INLINE - size_t numberOfFaces() const + size_t + numberOfFaces() const { return m_connectivity->numberOfFaces(); } PASTIS_INLINE - size_t numberOfCells() const + size_t + numberOfCells() const { return m_connectivity->numberOfCells(); } PASTIS_INLINE - const NodeValue<const Rd>& xr() const + const NodeValue<const Rd>& + xr() const { return m_xr; } PASTIS_INLINE - NodeValue<Rd> mutableXr() const + NodeValue<Rd> + mutableXr() const { return m_mutable_xr; } @@ -74,9 +81,7 @@ public: PASTIS_INLINE Mesh(const std::shared_ptr<const Connectivity>& connectivity, NodeValue<Rd>& xr) - : m_connectivity{connectivity}, - m_xr{xr}, - m_mutable_xr{xr} + : m_connectivity{connectivity}, m_xr{xr}, m_mutable_xr{xr} { ; } @@ -89,4 +94,4 @@ public: } }; -#endif // MESH_HPP +#endif // MESH_HPP diff --git a/src/mesh/MeshData.hpp b/src/mesh/MeshData.hpp index 3d5cc9b75..7f307d0db 100644 --- a/src/mesh/MeshData.hpp +++ b/src/mesh/MeshData.hpp @@ -13,14 +13,14 @@ template <typename M> class MeshData { public: - using MeshType = M; + using MeshType = M; static constexpr size_t Dimension = MeshType::Dimension; - static_assert(Dimension>0, "dimension must be strictly positive"); + static_assert(Dimension > 0, "dimension must be strictly positive"); using Rd = TinyVector<Dimension>; - static constexpr double inv_Dimension = 1./Dimension; + static constexpr double inv_Dimension = 1. / Dimension; private: const MeshType& m_mesh; @@ -31,263 +31,268 @@ class MeshData CellValue<const double> m_Vj; PASTIS_INLINE - void _updateCenter() - { // Computes vertices isobarycenter + void + _updateCenter() + { // Computes vertices isobarycenter if constexpr (Dimension == 1) { const NodeValue<const Rd>& xr = m_mesh.xr(); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + m_mesh.connectivity().cellToNodeMatrix(); CellValue<Rd> xj(m_mesh.connectivity()); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - const auto& cell_nodes = cell_to_node_matrix[j]; - xj[j] = 0.5*(xr[cell_nodes[0]]+xr[cell_nodes[1]]); - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + const auto& cell_nodes = cell_to_node_matrix[j]; + xj[j] = 0.5 * (xr[cell_nodes[0]] + xr[cell_nodes[1]]); + }); m_xj = xj; } else { const NodeValue<const Rd>& xr = m_mesh.xr(); - const CellValue<const double>& inv_cell_nb_nodes - = m_mesh.connectivity().invCellNbNodes(); + const CellValue<const double>& inv_cell_nb_nodes = + m_mesh.connectivity().invCellNbNodes(); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + m_mesh.connectivity().cellToNodeMatrix(); CellValue<Rd> xj(m_mesh.connectivity()); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - Rd X = zero; - const auto& cell_nodes = cell_to_node_matrix[j]; - for (size_t R=0; R<cell_nodes.size(); ++R) { - X += xr[cell_nodes[R]]; - } - xj[j] = inv_cell_nb_nodes[j]*X; - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + Rd X = zero; + const auto& cell_nodes = cell_to_node_matrix[j]; + for (size_t R = 0; R < cell_nodes.size(); ++R) { + X += xr[cell_nodes[R]]; + } + xj[j] = inv_cell_nb_nodes[j] * X; + }); m_xj = xj; } } PASTIS_INLINE - void _updateVolume() + void + _updateVolume() { - const NodeValue<const Rd>& xr = m_mesh.xr(); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const NodeValue<const Rd>& xr = m_mesh.xr(); + const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); CellValue<double> Vj(m_mesh.connectivity()); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - double sum_cjr_xr = 0; - const auto& cell_nodes = cell_to_node_matrix[j]; + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + double sum_cjr_xr = 0; + const auto& cell_nodes = cell_to_node_matrix[j]; - for (size_t R=0; R<cell_nodes.size(); ++R) { - sum_cjr_xr += (xr[cell_nodes[R]], m_Cjr(j,R)); - } - Vj[j] = inv_Dimension * sum_cjr_xr; - }); + for (size_t R = 0; R < cell_nodes.size(); ++R) { + sum_cjr_xr += (xr[cell_nodes[R]], m_Cjr(j, R)); + } + Vj[j] = inv_Dimension * sum_cjr_xr; + }); m_Vj = Vj; } PASTIS_INLINE - void _updateCjr() { + void + _updateCjr() + { if constexpr (Dimension == 1) { // Cjr/njr/ljr are constant overtime - } - else if constexpr (Dimension == 2) { + } else if constexpr (Dimension == 2) { const NodeValue<const Rd>& xr = m_mesh.xr(); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + m_mesh.connectivity().cellToNodeMatrix(); { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - const auto& cell_nodes = cell_to_node_matrix[j]; - for (size_t R=0; R<cell_nodes.size(); ++R) { - int Rp1 = (R+1)%cell_nodes.size(); - int Rm1 = (R+cell_nodes.size()-1)%cell_nodes.size(); - Rd half_xrp_xrm = 0.5*(xr[cell_nodes[Rp1]]-xr[cell_nodes[Rm1]]); - Cjr(j,R) = Rd{-half_xrp_xrm[1], half_xrp_xrm[0]}; - } - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + const auto& cell_nodes = cell_to_node_matrix[j]; + for (size_t R = 0; R < cell_nodes.size(); ++R) { + int Rp1 = (R + 1) % cell_nodes.size(); + int Rm1 = (R + cell_nodes.size() - 1) % cell_nodes.size(); + Rd half_xrp_xrm = 0.5 * (xr[cell_nodes[Rp1]] - xr[cell_nodes[Rm1]]); + Cjr(j, R) = Rd{-half_xrp_xrm[1], half_xrp_xrm[0]}; + } + }); m_Cjr = Cjr; } { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - ljr[jr] = l2Norm(m_Cjr[jr]); - }); + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr) { + ljr[jr] = l2Norm(m_Cjr[jr]); + }); m_ljr = ljr; } { NodeValuePerCell<Rd> njr(m_mesh.connectivity()); - parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - njr[jr] = (1./m_ljr[jr])*m_Cjr[jr]; - }); + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr) { + njr[jr] = (1. / m_ljr[jr]) * m_Cjr[jr]; + }); m_njr = njr; } - } else if (Dimension ==3) { + } else if (Dimension == 3) { const NodeValue<const Rd>& xr = m_mesh.xr(); NodeValuePerFace<Rd> Nlr(m_mesh.connectivity()); - const auto& face_to_node_matrix - = m_mesh.connectivity().faceToNodeMatrix(); + const auto& face_to_node_matrix = + m_mesh.connectivity().faceToNodeMatrix(); parallel_for(m_mesh.numberOfFaces(), PASTIS_LAMBDA(const FaceId& l) { - const auto& face_nodes = face_to_node_matrix[l]; - const size_t nb_nodes = face_nodes.size(); - std::vector<Rd> dxr(nb_nodes); - for (size_t r=0; r<nb_nodes; ++r) { - dxr[r] - = xr[face_nodes[(r+1)%nb_nodes]] - - xr[face_nodes[(r+nb_nodes-1)%nb_nodes]]; - } - const double inv_12_nb_nodes = 1./(12.*nb_nodes); - for (size_t r=0; r<nb_nodes; ++r) { - Rd Nr = zero; - const Rd two_dxr = 2*dxr[r]; - for (size_t s=0; s<nb_nodes; ++s) { - Nr += crossProduct((two_dxr - dxr[s]), xr[face_nodes[s]]); - } - Nr *= inv_12_nb_nodes; - Nr -= (1./6.)*crossProduct(dxr[r], xr[face_nodes[r]]); - Nlr(l,r) = Nr; + const auto& face_nodes = face_to_node_matrix[l]; + const size_t nb_nodes = face_nodes.size(); + std::vector<Rd> dxr(nb_nodes); + for (size_t r = 0; r < nb_nodes; ++r) { + dxr[r] = xr[face_nodes[(r + 1) % nb_nodes]] - + xr[face_nodes[(r + nb_nodes - 1) % nb_nodes]]; + } + const double inv_12_nb_nodes = 1. / (12. * nb_nodes); + for (size_t r = 0; r < nb_nodes; ++r) { + Rd Nr = zero; + const Rd two_dxr = 2 * dxr[r]; + for (size_t s = 0; s < nb_nodes; ++s) { + Nr += crossProduct((two_dxr - dxr[s]), xr[face_nodes[s]]); } - }); + Nr *= inv_12_nb_nodes; + Nr -= (1. / 6.) * crossProduct(dxr[r], xr[face_nodes[r]]); + Nlr(l, r) = Nr; + } + }); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + m_mesh.connectivity().cellToNodeMatrix(); - const auto& cell_to_face_matrix - = m_mesh.connectivity().cellToFaceMatrix(); + const auto& cell_to_face_matrix = + m_mesh.connectivity().cellToFaceMatrix(); - const auto& cell_face_is_reversed = m_mesh.connectivity().cellFaceIsReversed(); + const auto& cell_face_is_reversed = + m_mesh.connectivity().cellFaceIsReversed(); { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); - parallel_for(Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - Cjr[jr] = zero; - }); + parallel_for(Cjr.numberOfValues(), + PASTIS_LAMBDA(const size_t& jr) { Cjr[jr] = zero; }); parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - const auto& cell_nodes = cell_to_node_matrix[j]; - - const auto& cell_faces = cell_to_face_matrix[j]; - const auto& face_is_reversed = cell_face_is_reversed.itemValues(j); - - for (size_t L=0; L<cell_faces.size(); ++L) { - const FaceId& l = cell_faces[L]; - const auto& face_nodes = face_to_node_matrix[l]; - - auto local_node_number_in_cell - = [&](const NodeId& node_number) { - for (size_t i_node=0; i_node<cell_nodes.size(); ++i_node) { - if (node_number == cell_nodes[i_node]) { - return i_node; - } - } - return std::numeric_limits<size_t>::max(); - }; - - if (face_is_reversed[L]) { - for (size_t rl = 0; rl<face_nodes.size(); ++rl) { - const size_t R = local_node_number_in_cell(face_nodes[rl]); - Cjr(j, R) -= Nlr(l,rl); - } - } else { - for (size_t rl = 0; rl<face_nodes.size(); ++rl) { - const size_t R = local_node_number_in_cell(face_nodes[rl]); - Cjr(j, R) += Nlr(l,rl); + const auto& cell_nodes = cell_to_node_matrix[j]; + + const auto& cell_faces = cell_to_face_matrix[j]; + const auto& face_is_reversed = cell_face_is_reversed.itemValues(j); + + for (size_t L = 0; L < cell_faces.size(); ++L) { + const FaceId& l = cell_faces[L]; + const auto& face_nodes = face_to_node_matrix[l]; + + auto local_node_number_in_cell = [&](const NodeId& node_number) { + for (size_t i_node = 0; i_node < cell_nodes.size(); ++i_node) { + if (node_number == cell_nodes[i_node]) { + return i_node; } } + return std::numeric_limits<size_t>::max(); + }; + + if (face_is_reversed[L]) { + for (size_t rl = 0; rl < face_nodes.size(); ++rl) { + const size_t R = local_node_number_in_cell(face_nodes[rl]); + Cjr(j, R) -= Nlr(l, rl); + } + } else { + for (size_t rl = 0; rl < face_nodes.size(); ++rl) { + const size_t R = local_node_number_in_cell(face_nodes[rl]); + Cjr(j, R) += Nlr(l, rl); + } } - }); + } + }); m_Cjr = Cjr; } { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - ljr[jr] = l2Norm(m_Cjr[jr]); - }); + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr) { + ljr[jr] = l2Norm(m_Cjr[jr]); + }); m_ljr = ljr; } { NodeValuePerCell<Rd> njr(m_mesh.connectivity()); - parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - njr[jr] = (1./m_ljr[jr])*m_Cjr[jr]; - }); + parallel_for(m_Cjr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr) { + njr[jr] = (1. / m_ljr[jr]) * m_Cjr[jr]; + }); m_njr = njr; } } - static_assert((Dimension<=3), "only 1d, 2d and 3d are implemented"); + static_assert((Dimension <= 3), "only 1d, 2d and 3d are implemented"); } public: PASTIS_INLINE - const MeshType& mesh() const + const MeshType& + mesh() const { return m_mesh; } PASTIS_INLINE - const NodeValuePerCell<const Rd>& Cjr() const + const NodeValuePerCell<const Rd>& + Cjr() const { return m_Cjr; } PASTIS_INLINE - const NodeValuePerCell<const double>& ljr() const + const NodeValuePerCell<const double>& + ljr() const { return m_ljr; } PASTIS_INLINE - const NodeValuePerCell<const Rd>& njr() const + const NodeValuePerCell<const Rd>& + njr() const { return m_njr; } PASTIS_INLINE - const CellValue<const Rd>& xj() const + const CellValue<const Rd>& + xj() const { return m_xj; } PASTIS_INLINE - const CellValue<const double>& Vj() const + const CellValue<const double>& + Vj() const { return m_Vj; } - void updateAllData() + void + updateAllData() { this->_updateCjr(); this->_updateCenter(); this->_updateVolume(); } - MeshData(const MeshType& mesh) - : m_mesh(mesh) + MeshData(const MeshType& mesh) : m_mesh(mesh) { - if constexpr (Dimension==1) { + if constexpr (Dimension == 1) { // in 1d Cjr are computed once for all { NodeValuePerCell<Rd> Cjr(m_mesh.connectivity()); parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - Cjr(j,0)=-1; - Cjr(j,1)= 1; - }); + Cjr(j, 0) = -1; + Cjr(j, 1) = 1; + }); m_Cjr = Cjr; } // in 1d njr=Cjr (here performs a shallow copy) m_njr = m_Cjr; { NodeValuePerCell<double> ljr(m_mesh.connectivity()); - parallel_for(ljr.numberOfValues(), PASTIS_LAMBDA(const size_t& jr){ - ljr[jr] = 1; - }); + parallel_for(ljr.numberOfValues(), + PASTIS_LAMBDA(const size_t& jr) { ljr[jr] = 1; }); m_ljr = ljr; } } @@ -300,4 +305,4 @@ class MeshData } }; -#endif // MESH_DATA_HPP +#endif // MESH_DATA_HPP diff --git a/src/mesh/MeshNodeBoundary.hpp b/src/mesh/MeshNodeBoundary.hpp index ff8ef4a92..f95a2941b 100644 --- a/src/mesh/MeshNodeBoundary.hpp +++ b/src/mesh/MeshNodeBoundary.hpp @@ -20,43 +20,42 @@ class MeshNodeBoundary { protected: Array<const NodeId> m_node_list; + public: MeshNodeBoundary& operator=(const MeshNodeBoundary&) = default; MeshNodeBoundary& operator=(MeshNodeBoundary&&) = default; - const Array<const NodeId>& nodeList() const + const Array<const NodeId>& + nodeList() const { return m_node_list; } template <typename MeshType> - MeshNodeBoundary(const MeshType& mesh, - const RefFaceList& ref_face_list) + MeshNodeBoundary(const MeshType& mesh, const RefFaceList& ref_face_list) { static_assert(Dimension == MeshType::Dimension); - const auto& face_to_cell_matrix - = mesh.connectivity().faceToCellMatrix(); + const auto& face_to_cell_matrix = mesh.connectivity().faceToCellMatrix(); const Array<const FaceId>& face_list = ref_face_list.list(); - parallel_for(face_list.size(), PASTIS_LAMBDA(const int& l){ - const auto& face_cells = face_to_cell_matrix[face_list[l]]; - if (face_cells.size()>1) { - perr() << "internal faces cannot be used to define mesh boundaries\n"; - std::exit(1); - } - }); + parallel_for(face_list.size(), PASTIS_LAMBDA(const int& l) { + const auto& face_cells = face_to_cell_matrix[face_list[l]]; + if (face_cells.size() > 1) { + perr() << "internal faces cannot be used to define mesh boundaries\n"; + std::exit(1); + } + }); Kokkos::vector<unsigned int> node_ids; // not enough but should reduce significantly the number of resizing - node_ids.reserve(Dimension*face_list.size()); - const auto& face_to_node_matrix - = mesh.connectivity().faceToNodeMatrix(); + node_ids.reserve(Dimension * face_list.size()); + const auto& face_to_node_matrix = mesh.connectivity().faceToNodeMatrix(); - for (size_t l=0; l<face_list.size(); ++l) { + for (size_t l = 0; l < face_list.size(); ++l) { const FaceId face_number = face_list[l]; - const auto& face_nodes = face_to_node_matrix[face_number]; + const auto& face_nodes = face_to_node_matrix[face_number]; - for (size_t r=0; r<face_nodes.size(); ++r) { + for (size_t r = 0; r < face_nodes.size(); ++r) { node_ids.push_back(face_nodes[r]); } } @@ -65,29 +64,26 @@ class MeshNodeBoundary node_ids.resize(std::distance(node_ids.begin(), last)); Array<NodeId> node_list(node_ids.size()); - parallel_for(node_ids.size(), PASTIS_LAMBDA(const int& r){ - node_list[r] = node_ids[r]; - }); + parallel_for(node_ids.size(), + PASTIS_LAMBDA(const int& r) { node_list[r] = node_ids[r]; }); m_node_list = node_list; } template <typename MeshType> MeshNodeBoundary(const MeshType&, const RefNodeList& ref_node_list) - : m_node_list(ref_node_list.list()) + : m_node_list(ref_node_list.list()) { static_assert(Dimension == MeshType::Dimension); } - MeshNodeBoundary() = default; + MeshNodeBoundary() = default; MeshNodeBoundary(const MeshNodeBoundary&) = default; - MeshNodeBoundary(MeshNodeBoundary&&) = default; - virtual ~MeshNodeBoundary() = default; + MeshNodeBoundary(MeshNodeBoundary&&) = default; + virtual ~MeshNodeBoundary() = default; }; - template <size_t Dimension> -class MeshFlatNodeBoundary - : public MeshNodeBoundary<Dimension> +class MeshFlatNodeBoundary : public MeshNodeBoundary<Dimension> { public: using Rd = TinyVector<Dimension, double>; @@ -96,21 +92,20 @@ class MeshFlatNodeBoundary const Rd m_outgoing_normal; template <typename MeshType> - PASTIS_INLINE - Rd _getNormal(const MeshType& mesh); + PASTIS_INLINE Rd _getNormal(const MeshType& mesh); template <typename MeshType> - PASTIS_INLINE - void _checkBoundaryIsFlat(const TinyVector<2,double>& normal, - const TinyVector<2,double>& xmin, - const TinyVector<2,double>& xmax, - const MeshType& mesh) const; + PASTIS_INLINE void _checkBoundaryIsFlat(const TinyVector<2, double>& normal, + const TinyVector<2, double>& xmin, + const TinyVector<2, double>& xmax, + const MeshType& mesh) const; template <typename MeshType> - PASTIS_INLINE - Rd _getOutgoingNormal(const MeshType& mesh); + PASTIS_INLINE Rd _getOutgoingNormal(const MeshType& mesh); + public: - const Rd& outgoingNormal() const + const Rd& + outgoingNormal() const { return m_outgoing_normal; } @@ -119,63 +114,60 @@ class MeshFlatNodeBoundary MeshFlatNodeBoundary& operator=(MeshFlatNodeBoundary&&) = default; template <typename MeshType> - MeshFlatNodeBoundary(const MeshType& mesh, - const RefFaceList& ref_face_list) - : MeshNodeBoundary<Dimension>(mesh, ref_face_list), - m_outgoing_normal(_getOutgoingNormal(mesh)) + MeshFlatNodeBoundary(const MeshType& mesh, const RefFaceList& ref_face_list) + : MeshNodeBoundary<Dimension>(mesh, ref_face_list), + m_outgoing_normal(_getOutgoingNormal(mesh)) { ; } template <typename MeshType> - MeshFlatNodeBoundary(const MeshType& mesh, - const RefNodeList& ref_node_list) - : MeshNodeBoundary<Dimension>(mesh, ref_node_list), - m_outgoing_normal(_getOutgoingNormal(mesh)) + MeshFlatNodeBoundary(const MeshType& mesh, const RefNodeList& ref_node_list) + : MeshNodeBoundary<Dimension>(mesh, ref_node_list), + m_outgoing_normal(_getOutgoingNormal(mesh)) { ; } - MeshFlatNodeBoundary() = default; + MeshFlatNodeBoundary() = default; MeshFlatNodeBoundary(const MeshFlatNodeBoundary&) = default; - MeshFlatNodeBoundary(MeshFlatNodeBoundary&&) = default; - virtual ~MeshFlatNodeBoundary() = default; + MeshFlatNodeBoundary(MeshFlatNodeBoundary&&) = default; + virtual ~MeshFlatNodeBoundary() = default; }; -template<> +template <> template <typename MeshType> -void MeshFlatNodeBoundary<2>:: -_checkBoundaryIsFlat(const TinyVector<2,double>& normal, - const TinyVector<2,double>& xmin, - const TinyVector<2,double>& xmax, - const MeshType& mesh) const +void +MeshFlatNodeBoundary<2>::_checkBoundaryIsFlat( + const TinyVector<2, double>& normal, + const TinyVector<2, double>& xmin, + const TinyVector<2, double>& xmax, + const MeshType& mesh) const { static_assert(MeshType::Dimension == 2); - using R2 = TinyVector<2,double>; + using R2 = TinyVector<2, double>; - const R2 origin = 0.5*(xmin+xmax); - const double length = l2Norm(xmax-xmin); + const R2 origin = 0.5 * (xmin + xmax); + const double length = l2Norm(xmax - xmin); const NodeValue<const R2>& xr = mesh.xr(); parallel_for(m_node_list.size(), PASTIS_LAMBDA(const size_t& r) { - const R2& x = xr[m_node_list[r]]; - if ((x-origin,normal)>1E-13*length) { - perr() << "this FlatBoundary is not flat!\n"; - std::exit(1); - } - }); + const R2& x = xr[m_node_list[r]]; + if ((x - origin, normal) > 1E-13 * length) { + perr() << "this FlatBoundary is not flat!\n"; + std::exit(1); + } + }); } template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<1,double> -MeshFlatNodeBoundary<1>:: -_getNormal(const MeshType&) +PASTIS_INLINE TinyVector<1, double> +MeshFlatNodeBoundary<1>::_getNormal(const MeshType&) { static_assert(MeshType::Dimension == 1); - using R = TinyVector<1,double>; + using R = TinyVector<1, double>; if (m_node_list.size() != 1) { perr() << "Node boundaries in 1D require to have exactly 1 node\n"; @@ -187,13 +179,11 @@ _getNormal(const MeshType&) template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<2,double> -MeshFlatNodeBoundary<2>:: -_getNormal(const MeshType& mesh) +PASTIS_INLINE TinyVector<2, double> +MeshFlatNodeBoundary<2>::_getNormal(const MeshType& mesh) { static_assert(MeshType::Dimension == 2); - using R2 = TinyVector<2,double>; + using R2 = TinyVector<2, double>; const NodeValue<const R2>& xr = mesh.xr(); @@ -203,38 +193,39 @@ _getNormal(const MeshType& mesh) R2 xmax(-std::numeric_limits<double>::max(), -std::numeric_limits<double>::max()); - for (size_t r=0; r<m_node_list.size(); ++r) { + for (size_t r = 0; r < m_node_list.size(); ++r) { const R2& x = xr[m_node_list[r]]; - if ((x[0]<xmin[0]) or ((x[0] == xmin[0]) and (x[1] < xmin[1]))) { + if ((x[0] < xmin[0]) or ((x[0] == xmin[0]) and (x[1] < xmin[1]))) { xmin = x; } - if ((x[0]>xmax[0]) or ((x[0] == xmax[0]) and (x[1] > xmax[1]))) { + if ((x[0] > xmax[0]) or ((x[0] == xmax[0]) and (x[1] > xmax[1]))) { xmax = x; } } Array<R2> xmin_array = parallel::allGather(xmin); Array<R2> xmax_array = parallel::allGather(xmax); - for (size_t i=0; i<xmin_array.size(); ++i) { + for (size_t i = 0; i < xmin_array.size(); ++i) { const R2& x = xmin_array[i]; - if ((x[0]<xmin[0]) or ((x[0] == xmin[0]) and (x[1] < xmin[1]))) { + if ((x[0] < xmin[0]) or ((x[0] == xmin[0]) and (x[1] < xmin[1]))) { xmin = x; } } - for (size_t i=0; i<xmax_array.size(); ++i) { + for (size_t i = 0; i < xmax_array.size(); ++i) { const R2& x = xmax_array[i]; - if ((x[0]>xmax[0]) or ((x[0] == xmax[0]) and (x[1] > xmax[1]))) { + if ((x[0] > xmax[0]) or ((x[0] == xmax[0]) and (x[1] > xmax[1]))) { xmax = x; } } if (xmin == xmax) { - perr() << "xmin==xmax (" << xmin << "==" << xmax << ") unable to compute normal"; + perr() << "xmin==xmax (" << xmin << "==" << xmax + << ") unable to compute normal"; std::exit(1); } - R2 dx = xmax-xmin; - dx *= 1./l2Norm(dx); + R2 dx = xmax - xmin; + dx *= 1. / l2Norm(dx); R2 normal(-dx[1], dx[0]); @@ -245,45 +236,43 @@ _getNormal(const MeshType& mesh) template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<3,double> -MeshFlatNodeBoundary<3>:: -_getNormal(const MeshType& mesh) +PASTIS_INLINE TinyVector<3, double> +MeshFlatNodeBoundary<3>::_getNormal(const MeshType& mesh) { static_assert(MeshType::Dimension == 3); - using R3 = TinyVector<3,double>; - + using R3 = TinyVector<3, double>; R3 xmin(std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), std::numeric_limits<double>::max()); R3 ymin = xmin; - R3 zmin = xmin;; + R3 zmin = xmin; + ; - R3 xmax =-xmin; + R3 xmax = -xmin; R3 ymax = xmax; R3 zmax = xmax; const NodeValue<const R3>& xr = mesh.xr(); - for (size_t r=0; r<m_node_list.size(); ++r) { + for (size_t r = 0; r < m_node_list.size(); ++r) { const R3& x = xr[m_node_list[r]]; - if (x[0]<xmin[0]) { + if (x[0] < xmin[0]) { xmin = x; } - if (x[1]<ymin[1]) { + if (x[1] < ymin[1]) { ymin = x; } - if (x[2]<zmin[2]) { + if (x[2] < zmin[2]) { zmin = x; } - if (x[0]>xmax[0]) { + if (x[0] > xmax[0]) { xmax = x; } - if (x[1]>ymax[1]) { + if (x[1] > ymax[1]) { ymax = x; } - if (x[2]>zmax[2]) { + if (x[2] > zmax[2]) { zmax = x; } } @@ -294,64 +283,75 @@ _getNormal(const MeshType& mesh) Array<R3> zmin_array = parallel::allGather(zmin); Array<R3> zmax_array = parallel::allGather(zmax); - for (size_t i=0; i<xmin_array.size(); ++i) { + for (size_t i = 0; i < xmin_array.size(); ++i) { const R3& x = xmin_array[i]; - if (x[0] < xmin[0]) { xmin = x; } + if (x[0] < xmin[0]) { + xmin = x; + } } - for (size_t i=0; i<ymin_array.size(); ++i) { + for (size_t i = 0; i < ymin_array.size(); ++i) { const R3& x = ymin_array[i]; - if (x[1] < ymin[1]) { ymin = x; } + if (x[1] < ymin[1]) { + ymin = x; + } } - for (size_t i=0; i<zmin_array.size(); ++i) { + for (size_t i = 0; i < zmin_array.size(); ++i) { const R3& x = zmin_array[i]; - if (x[2] < zmin[2]) { zmin = x; } + if (x[2] < zmin[2]) { + zmin = x; + } } - for (size_t i=0; i<xmax_array.size(); ++i) { + for (size_t i = 0; i < xmax_array.size(); ++i) { const R3& x = xmax_array[i]; - if (x[0] > xmax[0]) { xmax = x; } + if (x[0] > xmax[0]) { + xmax = x; + } } - for (size_t i=0; i<ymax_array.size(); ++i) { + for (size_t i = 0; i < ymax_array.size(); ++i) { const R3& x = ymax_array[i]; - if (x[1] > ymax[1]) { ymax = x; } + if (x[1] > ymax[1]) { + ymax = x; + } } - for (size_t i=0; i<zmax_array.size(); ++i) { + for (size_t i = 0; i < zmax_array.size(); ++i) { const R3& x = zmax_array[i]; - if (x[2] > zmax[2]) { zmax = x; } + if (x[2] > zmax[2]) { + zmax = x; + } } - const R3 u = xmax-xmin; - const R3 v = ymax-ymin; - const R3 w = zmax-zmin; + const R3 u = xmax - xmin; + const R3 v = ymax - ymin; + const R3 w = zmax - zmin; - const R3 uv = crossProduct(u,v); + const R3 uv = crossProduct(u, v); const double uv_l2 = (uv, uv); - R3 normal = uv; + R3 normal = uv; double normal_l2 = uv_l2; - const R3 uw = crossProduct(u,w); - const double uw_l2 = (uw,uw); + const R3 uw = crossProduct(u, w); + const double uw_l2 = (uw, uw); if (uw_l2 > uv_l2) { - normal = uw; + normal = uw; normal_l2 = uw_l2; } - const R3 vw = crossProduct(v,w); - const double vw_l2 = (vw,vw); + const R3 vw = crossProduct(v, w); + const double vw_l2 = (vw, vw); if (vw_l2 > normal_l2) { - normal = vw; + normal = vw; normal_l2 = vw_l2; } - - if (normal_l2 ==0) { + if (normal_l2 == 0) { perr() << "not able to compute normal!\n"; std::exit(1); } - normal *= 1./sqrt(normal_l2); + normal *= 1. / sqrt(normal_l2); // this->_checkBoundaryIsFlat(normal, xmin, xmax, mesh); @@ -360,32 +360,28 @@ _getNormal(const MeshType& mesh) template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<1,double> -MeshFlatNodeBoundary<1>:: -_getOutgoingNormal(const MeshType& mesh) +PASTIS_INLINE TinyVector<1, double> +MeshFlatNodeBoundary<1>::_getOutgoingNormal(const MeshType& mesh) { static_assert(MeshType::Dimension == 1); - using R = TinyVector<1,double>; + using R = TinyVector<1, double>; const R normal = this->_getNormal(mesh); double max_height = 0; - if (m_node_list.size()>0) { - const NodeValue<const R>& xr = mesh.xr(); - const auto& cell_to_node_matrix - = mesh.connectivity().cellToNodeMatrix(); + if (m_node_list.size() > 0) { + const NodeValue<const R>& xr = mesh.xr(); + const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); - const auto& node_to_cell_matrix - = mesh.connectivity().nodeToCellMatrix(); + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); - const NodeId r0 = m_node_list[0]; - const CellId j0 = node_to_cell_matrix[r0][0]; + const NodeId r0 = m_node_list[0]; + const CellId j0 = node_to_cell_matrix[r0][0]; const auto& j0_nodes = cell_to_node_matrix[j0]; - for (size_t r=0; r<j0_nodes.size(); ++r) { - const double height = (xr[j0_nodes[r]]-xr[r0], normal); + for (size_t r = 0; r < j0_nodes.size(); ++r) { + const double height = (xr[j0_nodes[r]] - xr[r0], normal); if (std::abs(height) > std::abs(max_height)) { max_height = height; } @@ -393,7 +389,7 @@ _getOutgoingNormal(const MeshType& mesh) } Array<double> max_height_array = parallel::allGather(max_height); - for (size_t i=0; i<max_height_array.size(); ++i) { + for (size_t i = 0; i < max_height_array.size(); ++i) { const double height = max_height_array[i]; if (std::abs(height) > std::abs(max_height)) { max_height = height; @@ -409,31 +405,27 @@ _getOutgoingNormal(const MeshType& mesh) template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<2,double> -MeshFlatNodeBoundary<2>:: -_getOutgoingNormal(const MeshType& mesh) +PASTIS_INLINE TinyVector<2, double> +MeshFlatNodeBoundary<2>::_getOutgoingNormal(const MeshType& mesh) { static_assert(MeshType::Dimension == 2); - using R2 = TinyVector<2,double>; + using R2 = TinyVector<2, double>; const R2 normal = this->_getNormal(mesh); double max_height = 0; - if (m_node_list.size()>0) { - const NodeValue<const R2>& xr = mesh.xr(); - const auto& cell_to_node_matrix - = mesh.connectivity().cellToNodeMatrix(); + if (m_node_list.size() > 0) { + const NodeValue<const R2>& xr = mesh.xr(); + const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); - const auto& node_to_cell_matrix - = mesh.connectivity().nodeToCellMatrix(); + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); - const NodeId r0 = m_node_list[0]; - const CellId j0 = node_to_cell_matrix[r0][0]; + const NodeId r0 = m_node_list[0]; + const CellId j0 = node_to_cell_matrix[r0][0]; const auto& j0_nodes = cell_to_node_matrix[j0]; - for (size_t r=0; r<j0_nodes.size(); ++r) { - const double height = (xr[j0_nodes[r]]-xr[r0], normal); + for (size_t r = 0; r < j0_nodes.size(); ++r) { + const double height = (xr[j0_nodes[r]] - xr[r0], normal); if (std::abs(height) > std::abs(max_height)) { max_height = height; } @@ -441,7 +433,7 @@ _getOutgoingNormal(const MeshType& mesh) } Array<double> max_height_array = parallel::allGather(max_height); - for (size_t i=0; i<max_height_array.size(); ++i) { + for (size_t i = 0; i < max_height_array.size(); ++i) { const double height = max_height_array[i]; if (std::abs(height) > std::abs(max_height)) { max_height = height; @@ -457,41 +449,36 @@ _getOutgoingNormal(const MeshType& mesh) template <> template <typename MeshType> -PASTIS_INLINE -TinyVector<3,double> -MeshFlatNodeBoundary<3>:: -_getOutgoingNormal(const MeshType& mesh) +PASTIS_INLINE TinyVector<3, double> +MeshFlatNodeBoundary<3>::_getOutgoingNormal(const MeshType& mesh) { static_assert(MeshType::Dimension == 3); - using R3 = TinyVector<3,double>; + using R3 = TinyVector<3, double>; const R3 normal = this->_getNormal(mesh); double max_height = 0; - if (m_node_list.size()>0) { - const NodeValue<const R3>& xr = mesh.xr(); - const auto& cell_to_node_matrix - = mesh.connectivity().cellToNodeMatrix(); + if (m_node_list.size() > 0) { + const NodeValue<const R3>& xr = mesh.xr(); + const auto& cell_to_node_matrix = mesh.connectivity().cellToNodeMatrix(); - const auto& node_to_cell_matrix - = mesh.connectivity().nodeToCellMatrix(); + const auto& node_to_cell_matrix = mesh.connectivity().nodeToCellMatrix(); - const NodeId r0 = m_node_list[0]; - const CellId j0 = node_to_cell_matrix[r0][0]; + const NodeId r0 = m_node_list[0]; + const CellId j0 = node_to_cell_matrix[r0][0]; const auto& j0_nodes = cell_to_node_matrix[j0]; - for (size_t r=0; r<j0_nodes.size(); ++r) { - const double height = (xr[j0_nodes[r]]-xr[r0], normal); + for (size_t r = 0; r < j0_nodes.size(); ++r) { + const double height = (xr[j0_nodes[r]] - xr[r0], normal); if (std::abs(height) > std::abs(max_height)) { max_height = height; } } - } Array<double> max_height_array = parallel::allGather(max_height); - for (size_t i=0; i<max_height_array.size(); ++i) { + for (size_t i = 0; i < max_height_array.size(); ++i) { const double height = max_height_array[i]; if (std::abs(height) > std::abs(max_height)) { max_height = height; @@ -505,5 +492,4 @@ _getOutgoingNormal(const MeshType& mesh) } } - -#endif // MESH_NODE_BOUNDARY_HPP +#endif // MESH_NODE_BOUNDARY_HPP diff --git a/src/mesh/RefId.hpp b/src/mesh/RefId.hpp index dbd4f1a1b..aebc9d7d7 100644 --- a/src/mesh/RefId.hpp +++ b/src/mesh/RefId.hpp @@ -1,21 +1,22 @@ #ifndef REF_ID_HPP #define REF_ID_HPP -#include <string> #include <iostream> +#include <string> class RefId { public: using TagNumberType = unsigned int; - using TagNameType = std::string; + using TagNameType = std::string; private: TagNumberType m_tag_number; TagNameType m_tag_name; public: - friend std::ostream& operator<<(std::ostream& os, const RefId& ref_id) + friend std::ostream& + operator<<(std::ostream& os, const RefId& ref_id) { if (std::to_string(ref_id.m_tag_number) != ref_id.m_tag_name) { os << ref_id.m_tag_name << '(' << ref_id.m_tag_number << ')'; @@ -25,46 +26,47 @@ class RefId return os; } - bool operator==(const RefId& ref_id) const + bool + operator==(const RefId& ref_id) const { - return ((m_tag_number==ref_id.m_tag_number) and - (m_tag_name==ref_id.m_tag_name)); + return ((m_tag_number == ref_id.m_tag_number) and + (m_tag_name == ref_id.m_tag_name)); } - bool operator<(const RefId& ref_id) const + bool + operator<(const RefId& ref_id) const { - return ((m_tag_number<ref_id.m_tag_number) or - ((m_tag_number==ref_id.m_tag_number) and - (m_tag_name<ref_id.m_tag_name))); + return ((m_tag_number < ref_id.m_tag_number) or + ((m_tag_number == ref_id.m_tag_number) and + (m_tag_name < ref_id.m_tag_name))); } - TagNumberType tagNumber() const + TagNumberType + tagNumber() const { return m_tag_number; } - const TagNameType& tagName() const + const TagNameType& + tagName() const { return m_tag_name; } RefId& operator=(const RefId&) = default; RefId& operator=(RefId&&) = default; - RefId() = default; - RefId(const RefId&) = default; - RefId(RefId&&) = default; + RefId() = default; + RefId(const RefId&) = default; + RefId(RefId&&) = default; - explicit RefId(const TagNumberType& tag_number, - const TagNameType& tag_name) - : m_tag_number(tag_number), - m_tag_name(tag_name) + explicit RefId(const TagNumberType& tag_number, const TagNameType& tag_name) + : m_tag_number(tag_number), m_tag_name(tag_name) { ; } explicit RefId(const TagNumberType& tag_number) - : m_tag_number(tag_number), - m_tag_name(std::to_string(tag_number)) + : m_tag_number(tag_number), m_tag_name(std::to_string(tag_number)) { ; } @@ -72,4 +74,4 @@ class RefId ~RefId() = default; }; -#endif // REF_ID_HPP +#endif // REF_ID_HPP diff --git a/src/mesh/RefItemList.hpp b/src/mesh/RefItemList.hpp index dea69f7ec..a3b9bb71f 100644 --- a/src/mesh/RefItemList.hpp +++ b/src/mesh/RefItemList.hpp @@ -2,8 +2,8 @@ #define REF_ITEM_LIST_HPP #include <Array.hpp> -#include <RefId.hpp> #include <ItemId.hpp> +#include <RefId.hpp> template <ItemType item_type> class RefItemList @@ -16,20 +16,20 @@ class RefItemList Array<const ItemId> m_item_id_list; public: - const RefId& refId() const + const RefId& + refId() const { return m_ref_id; } - const Array<const ItemId>& list() const + const Array<const ItemId>& + list() const { return m_item_id_list; } - RefItemList(const RefId& ref_id, - const Array<const ItemId>& item_id_list) - : m_ref_id(ref_id), - m_item_id_list(item_id_list) + RefItemList(const RefId& ref_id, const Array<const ItemId>& item_id_list) + : m_ref_id(ref_id), m_item_id_list(item_id_list) { ; } @@ -37,9 +37,9 @@ class RefItemList RefItemList& operator=(const RefItemList&) = default; RefItemList& operator=(RefItemList&&) = default; - RefItemList() = default; + RefItemList() = default; RefItemList(const RefItemList&) = default; - ~RefItemList() = default; + ~RefItemList() = default; }; using RefNodeList = RefItemList<ItemType::node>; @@ -47,4 +47,4 @@ using RefEdgeList = RefItemList<ItemType::edge>; using RefFaceList = RefItemList<ItemType::face>; using RefCellList = RefItemList<ItemType::cell>; -#endif // REF_ITEM_LIST_HPP +#endif // REF_ITEM_LIST_HPP diff --git a/src/mesh/SubItemValuePerItem.hpp b/src/mesh/SubItemValuePerItem.hpp index 450554edf..1c70ab8d0 100644 --- a/src/mesh/SubItemValuePerItem.hpp +++ b/src/mesh/SubItemValuePerItem.hpp @@ -12,8 +12,8 @@ #include <ConnectivityMatrix.hpp> #include <IConnectivity.hpp> -#include <ItemType.hpp> #include <ItemOfItemType.hpp> +#include <ItemType.hpp> #include <memory> @@ -27,13 +27,13 @@ class SubItemValuePerItem static constexpr ItemType sub_item_type{ItemOfItem::sub_item_type}; using ItemOfItemType = ItemOfItem; - using data_type = DataType; - using ItemId = ItemIdT<item_type>; - using index_type = ItemId; + using data_type = DataType; + using ItemId = ItemIdT<item_type>; + using index_type = ItemId; private: using ConnectivitySharedPtr = std::shared_ptr<const IConnectivity>; - using ConnectivityWeakPtr = std::weak_ptr<const IConnectivity>; + using ConnectivityWeakPtr = std::weak_ptr<const IConnectivity>; static_assert(std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr> or std::is_same_v<ConnectivityPtr, ConnectivityWeakPtr>); @@ -54,9 +54,8 @@ class SubItemValuePerItem ConnectivityWeakPtr>; public: - using ToShared = SubItemValuePerItem<DataType, - ItemOfItem, - ConnectivitySharedPtr>; + using ToShared = + SubItemValuePerItem<DataType, ItemOfItem, ConnectivitySharedPtr>; class SubView { @@ -71,19 +70,20 @@ class SubItemValuePerItem PASTIS_INLINE const DataType& operator[](const size_t& i) const noexcept(NO_ASSERT) { - Assert(i<m_size); + Assert(i < m_size); return m_sub_values[i]; } PASTIS_FORCEINLINE DataType& operator[](const size_t& i) noexcept(NO_ASSERT) { - Assert(i<m_size); + Assert(i < m_size); return m_sub_values[i]; } PASTIS_INLINE - size_t size() const noexcept + size_t + size() const noexcept { return m_size; } @@ -97,16 +97,16 @@ class SubItemValuePerItem SubView(const Array<DataType>& values, const size_t& begin, const size_t& end) noexcept(NO_ASSERT) - : m_sub_values(&(values[begin])), - m_size(end-begin) + : m_sub_values(&(values[begin])), m_size(end - begin) { - Assert(begin<=end); - Assert(end<=values.size()); + Assert(begin <= end); + Assert(end <= values.size()); } }; PASTIS_INLINE - bool isBuilt() const noexcept + bool + isBuilt() const noexcept { return m_connectivity_ptr.use_count() != 0; } @@ -114,24 +114,26 @@ class SubItemValuePerItem // Following Kokkos logic, these classes are view and const view does allow // changes in data PASTIS_FORCEINLINE - DataType& operator()(const ItemId& j, const size_t& r) const noexcept(NO_ASSERT) + DataType& + operator()(const ItemId& j, const size_t& r) const noexcept(NO_ASSERT) { Assert(this->isBuilt()); - return m_values[m_host_row_map(size_t{j})+r]; + return m_values[m_host_row_map(size_t{j}) + r]; } template <typename IndexType> - PASTIS_FORCEINLINE - DataType& operator()(const IndexType& j, const size_t& r) const noexcept(NO_ASSERT) + PASTIS_FORCEINLINE DataType& + operator()(const IndexType& j, const size_t& r) const noexcept(NO_ASSERT) { static_assert(std::is_same_v<IndexType, ItemId>, "SubItemValuePerItem indexed by ItemId"); Assert(this->isBuilt()); - return m_values[m_host_row_map(size_t{j})+r]; + return m_values[m_host_row_map(size_t{j}) + r]; } PASTIS_INLINE - size_t numberOfValues() const noexcept(NO_ASSERT) + size_t + numberOfValues() const noexcept(NO_ASSERT) { Assert(this->isBuilt()); return m_values.size(); @@ -149,14 +151,16 @@ class SubItemValuePerItem template <typename IndexType> DataType& operator[](const IndexType& i) const noexcept(NO_ASSERT) { - static_assert(std::is_same_v<IndexType, size_t>, - "Access to SubItemValuePerItem's array must be indexed by size_t"); + static_assert( + std::is_same_v<IndexType, size_t>, + "Access to SubItemValuePerItem's array must be indexed by size_t"); Assert(this->isBuilt()); return m_values[i]; } PASTIS_INLINE - size_t numberOfItems() const noexcept(NO_ASSERT) + size_t + numberOfItems() const noexcept(NO_ASSERT) { Assert(this->isBuilt()); Assert(m_host_row_map.extent(0) != 0); @@ -164,47 +168,51 @@ class SubItemValuePerItem } PASTIS_INLINE - size_t numberOfSubValues(const size_t& i_cell) const noexcept(NO_ASSERT) + size_t + numberOfSubValues(const size_t& i_cell) const noexcept(NO_ASSERT) { Assert(this->isBuilt()); - return m_host_row_map(i_cell+1)-m_host_row_map(i_cell); + return m_host_row_map(i_cell + 1) - m_host_row_map(i_cell); } PASTIS_INLINE - SubView itemValues(const size_t& i_cell) noexcept(NO_ASSERT) + SubView + itemValues(const size_t& i_cell) noexcept(NO_ASSERT) { Assert(this->isBuilt()); const auto& cell_begin = m_host_row_map(i_cell); - const auto& cell_end = m_host_row_map(i_cell+1); + const auto& cell_end = m_host_row_map(i_cell + 1); return SubView(m_values, cell_begin, cell_end); } // Following Kokkos logic, these classes are view and const view does allow // changes in data PASTIS_INLINE - SubView itemValues(const size_t& i_cell) const noexcept(NO_ASSERT) + SubView + itemValues(const size_t& i_cell) const noexcept(NO_ASSERT) { Assert(this->isBuilt()); const auto& cell_begin = m_host_row_map(i_cell); - const auto& cell_end = m_host_row_map(i_cell+1); + const auto& cell_end = m_host_row_map(i_cell + 1); return SubView(m_values, cell_begin, cell_end); } - template <typename DataType2, - typename ConnectivityPtr2> - PASTIS_INLINE - SubItemValuePerItem& - operator=(const SubItemValuePerItem<DataType2, ItemOfItem, ConnectivityPtr2>& sub_item_value_per_item) noexcept + template <typename DataType2, typename ConnectivityPtr2> + PASTIS_INLINE SubItemValuePerItem& + operator=(const SubItemValuePerItem<DataType2, ItemOfItem, ConnectivityPtr2>& + sub_item_value_per_item) noexcept { // ensures that DataType is the same as source DataType2 - static_assert(std::is_same_v<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>, + static_assert(std::is_same_v<std::remove_const_t<DataType>, + std::remove_const_t<DataType2>>, "Cannot assign SubItemValuePerItem of different type"); // ensures that const is not lost through copy - static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) - or not std::is_const_v<DataType2>), - "Cannot assign SubItemValuePerItem of const data to SubItemValuePerItem of non-const data"); + static_assert(((std::is_const_v<DataType2> and std::is_const_v<DataType>) or + not std::is_const_v<DataType2>), + "Cannot assign SubItemValuePerItem of const data to " + "SubItemValuePerItem of non-const data"); m_host_row_map = sub_item_value_per_item.m_host_row_map; - m_values = sub_item_value_per_item.m_values; + m_values = sub_item_value_per_item.m_values; if constexpr (std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr> and std::is_same_v<ConnectivityPtr2, ConnectivityWeakPtr>) { @@ -216,10 +224,11 @@ class SubItemValuePerItem return *this; } - template <typename DataType2, - typename ConnectivityPtr2> + template <typename DataType2, typename ConnectivityPtr2> PASTIS_INLINE - SubItemValuePerItem(const SubItemValuePerItem<DataType2, ItemOfItem, ConnectivityPtr2>& sub_item_value_per_item) noexcept + SubItemValuePerItem( + const SubItemValuePerItem<DataType2, ItemOfItem, ConnectivityPtr2>& + sub_item_value_per_item) noexcept { this->operator=(sub_item_value_per_item); } @@ -227,16 +236,19 @@ class SubItemValuePerItem SubItemValuePerItem() = default; SubItemValuePerItem(const IConnectivity& connectivity) noexcept - : m_connectivity_ptr{connectivity.shared_ptr()} + : m_connectivity_ptr{connectivity.shared_ptr()} { static_assert(not std::is_const_v<DataType>, - "Cannot allocate SubItemValuePerItem of const data: only view is supported"); ; + "Cannot allocate SubItemValuePerItem of const data: only " + "view is supported"); + ; - ConnectivityMatrix connectivity_matrix - = connectivity._getMatrix(item_type, sub_item_type); + ConnectivityMatrix connectivity_matrix = + connectivity._getMatrix(item_type, sub_item_type); m_host_row_map = connectivity_matrix.rowsMap(); - m_values = Array<std::remove_const_t<DataType>>(connectivity_matrix.numEntries()); + m_values = + Array<std::remove_const_t<DataType>>(connectivity_matrix.numEntries()); } ~SubItemValuePerItem() = default; @@ -289,9 +301,9 @@ using CellValuePerFace = SubItemValuePerItem<DataType, CellOfFace>; // Weak versions: should not be used outside of Connectivity // Item values at nodes -template <typename DataType, - typename ItemOfItem> -using WeakSubItemValuePerItem = SubItemValuePerItem<DataType, ItemOfItem, std::weak_ptr<const IConnectivity>>; +template <typename DataType, typename ItemOfItem> +using WeakSubItemValuePerItem = + SubItemValuePerItem<DataType, ItemOfItem, std::weak_ptr<const IConnectivity>>; template <typename DataType> using WeakNodeValuePerEdge = WeakSubItemValuePerItem<DataType, NodeOfEdge>; @@ -335,4 +347,4 @@ using WeakCellValuePerEdge = WeakSubItemValuePerItem<DataType, CellOfEdge>; template <typename DataType> using WeakCellValuePerFace = WeakSubItemValuePerItem<DataType, CellOfFace>; -#endif // SUBITEM_VALUE_PER_ITEM_HPP +#endif // SUBITEM_VALUE_PER_ITEM_HPP diff --git a/src/mesh/Synchronizer.hpp b/src/mesh/Synchronizer.hpp index a44a17ed3..e78ca2be7 100644 --- a/src/mesh/Synchronizer.hpp +++ b/src/mesh/Synchronizer.hpp @@ -1,8 +1,8 @@ #ifndef SYNCHRONIZER_HPP #define SYNCHRONIZER_HPP -#include <ItemValue.hpp> #include <Connectivity.hpp> +#include <ItemValue.hpp> #include <map> @@ -24,8 +24,8 @@ class Synchronizer ExchangeItemTypeInfo<ItemType::node> m_provided_node_info; template <ItemType item_type> - PASTIS_INLINE - constexpr auto& _getRequestedItemInfo() + PASTIS_INLINE constexpr auto& + _getRequestedItemInfo() { if constexpr (item_type == ItemType::cell) { return m_requested_cell_info; @@ -39,8 +39,8 @@ class Synchronizer } template <ItemType item_type> - PASTIS_INLINE - constexpr auto& _getProvidedItemInfo() + PASTIS_INLINE constexpr auto& + _getProvidedItemInfo() { if constexpr (item_type == ItemType::cell) { return m_provided_cell_info; @@ -53,93 +53,101 @@ class Synchronizer } } - template <typename ConnectivityType, - ItemType item_type> - void _buildSynchronizeInfo(const ConnectivityType& connectivity) + template <typename ConnectivityType, ItemType item_type> + void + _buildSynchronizeInfo(const ConnectivityType& connectivity) { - const auto& item_owner = connectivity.template owner<item_type>(); - using ItemId = ItemIdT<item_type>; + const auto& item_owner = connectivity.template owner<item_type>(); + using ItemId = ItemIdT<item_type>; auto& requested_item_info = this->_getRequestedItemInfo<item_type>(); - requested_item_info - = [&] () { - std::vector<std::vector<ItemId>> requested_item_vector_info(parallel::size()); - for (ItemId item_id=0; item_id<item_owner.size(); ++item_id) { - if (const size_t owner = item_owner[item_id]; owner != parallel::rank()) { - requested_item_vector_info[owner].emplace_back(item_id); - } - } - std::vector<Array<const ItemId>> requested_item_info(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - const auto& requested_item_vector = requested_item_vector_info[i_rank]; - requested_item_info[i_rank] = convert_to_array(requested_item_vector); - } - return requested_item_info; - }(); + requested_item_info = [&]() { + std::vector<std::vector<ItemId>> requested_item_vector_info( + parallel::size()); + for (ItemId item_id = 0; item_id < item_owner.size(); ++item_id) { + if (const size_t owner = item_owner[item_id]; + owner != parallel::rank()) { + requested_item_vector_info[owner].emplace_back(item_id); + } + } + std::vector<Array<const ItemId>> requested_item_info(parallel::size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + const auto& requested_item_vector = requested_item_vector_info[i_rank]; + requested_item_info[i_rank] = convert_to_array(requested_item_vector); + } + return requested_item_info; + }(); Array<unsigned int> local_number_of_requested_values(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - local_number_of_requested_values[i_rank] = requested_item_info[i_rank].size(); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + local_number_of_requested_values[i_rank] = + requested_item_info[i_rank].size(); } - Array<unsigned int> local_number_of_values_to_send - = parallel::allToAll(local_number_of_requested_values); + Array<unsigned int> local_number_of_values_to_send = + parallel::allToAll(local_number_of_requested_values); - std::vector<Array<const int>> requested_item_number_list_by_proc(parallel::size()); + std::vector<Array<const int>> requested_item_number_list_by_proc( + parallel::size()); const auto& item_number = connectivity.template number<item_type>(); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { const auto& requested_item_info_from_rank = requested_item_info[i_rank]; Array<int> item_number_list{requested_item_info_from_rank.size()}; - parallel_for (requested_item_info_from_rank.size(), PASTIS_LAMBDA(size_t i_item) { - item_number_list[i_item] = item_number[requested_item_info_from_rank[i_item]]; - }); + parallel_for(requested_item_info_from_rank.size(), + PASTIS_LAMBDA(size_t i_item) { + item_number_list[i_item] = + item_number[requested_item_info_from_rank[i_item]]; + }); requested_item_number_list_by_proc[i_rank] = item_number_list; } - std::vector<Array<int>> provided_item_number_list_by_rank(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - provided_item_number_list_by_rank[i_rank] = Array<int>{local_number_of_values_to_send[i_rank]}; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + provided_item_number_list_by_rank[i_rank] = + Array<int>{local_number_of_values_to_send[i_rank]}; } - parallel::exchange(requested_item_number_list_by_proc, provided_item_number_list_by_rank); + parallel::exchange(requested_item_number_list_by_proc, + provided_item_number_list_by_rank); std::map<int, ItemId> item_number_to_id_correspondance; - for (ItemId item_id=0; item_id<item_number.size(); ++item_id) { + for (ItemId item_id = 0; item_id < item_number.size(); ++item_id) { item_number_to_id_correspondance[item_number[item_id]] = item_id; } auto& provided_item_info = this->_getProvidedItemInfo<item_type>(); - provided_item_info - = [&] () { - std::vector<Array<const ItemId>> provided_item_info(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - Array<ItemId> provided_item_id_to_rank{local_number_of_values_to_send[i_rank]}; - const Array<int>& provided_item_number_to_rank = provided_item_number_list_by_rank[i_rank]; - for (size_t i=0; i<provided_item_number_to_rank.size(); ++i) { - provided_item_id_to_rank[i] - = item_number_to_id_correspondance.find(provided_item_number_to_rank[i])->second; - } - provided_item_info[i_rank] = provided_item_id_to_rank; - } - return provided_item_info; - } (); + provided_item_info = [&]() { + std::vector<Array<const ItemId>> provided_item_info(parallel::size()); + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + Array<ItemId> provided_item_id_to_rank{ + local_number_of_values_to_send[i_rank]}; + const Array<int>& provided_item_number_to_rank = + provided_item_number_list_by_rank[i_rank]; + for (size_t i = 0; i < provided_item_number_to_rank.size(); ++i) { + provided_item_id_to_rank[i] = item_number_to_id_correspondance + .find(provided_item_number_to_rank[i]) + ->second; + } + provided_item_info[i_rank] = provided_item_id_to_rank; + } + return provided_item_info; + }(); } template <typename ConnectivityType, typename DataType, ItemType item_type, typename ConnectivityPtr> - PASTIS_INLINE - void _synchronize(const ConnectivityType& connectivity, - ItemValue<DataType, item_type, ConnectivityPtr>& item_value) + PASTIS_INLINE void + _synchronize(const ConnectivityType& connectivity, + ItemValue<DataType, item_type, ConnectivityPtr>& item_value) { static_assert(not std::is_abstract_v<ConnectivityType>, "_synchronize must be called on a concrete connectivity"); using ItemId = ItemIdT<item_type>; - const auto& provided_item_info = this->_getProvidedItemInfo<item_type>(); + const auto& provided_item_info = this->_getProvidedItemInfo<item_type>(); const auto& requested_item_info = this->_getRequestedItemInfo<item_type>(); Assert(requested_item_info.size() == provided_item_info.size()); @@ -149,53 +157,58 @@ class Synchronizer } std::vector<Array<const DataType>> provided_data_list(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - const Array<const ItemId>& provided_item_info_to_rank = provided_item_info[i_rank]; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + const Array<const ItemId>& provided_item_info_to_rank = + provided_item_info[i_rank]; Array<DataType> provided_data{provided_item_info_to_rank.size()}; parallel_for(provided_item_info_to_rank.size(), PASTIS_LAMBDA(size_t i) { - provided_data[i] = item_value[provided_item_info_to_rank[i]]; - }); + provided_data[i] = item_value[provided_item_info_to_rank[i]]; + }); provided_data_list[i_rank] = provided_data; } std::vector<Array<DataType>> requested_data_list(parallel::size()); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { const auto& requested_item_info_from_rank = requested_item_info[i_rank]; - requested_data_list[i_rank] = Array<DataType>{requested_item_info_from_rank.size()}; + requested_data_list[i_rank] = + Array<DataType>{requested_item_info_from_rank.size()}; } parallel::exchange(provided_data_list, requested_data_list); - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { const auto& requested_item_info_from_rank = requested_item_info[i_rank]; - const auto& requested_data = requested_data_list[i_rank]; - parallel_for(requested_item_info_from_rank.size(), PASTIS_LAMBDA(size_t i) { + const auto& requested_data = requested_data_list[i_rank]; + parallel_for( + requested_item_info_from_rank.size(), PASTIS_LAMBDA(size_t i) { item_value[requested_item_info_from_rank[i]] = requested_data[i]; }); } } public: - template <typename DataType, - ItemType item_type, - typename ConnectivityPtr> - PASTIS_INLINE - void synchronize(ItemValue<DataType, item_type, ConnectivityPtr>& item_value) + template <typename DataType, ItemType item_type, typename ConnectivityPtr> + PASTIS_INLINE void + synchronize(ItemValue<DataType, item_type, ConnectivityPtr>& item_value) { - Assert(item_value.connectivity_ptr().use_count()>0, "No connectivity is associated to this ItemValue"); + Assert(item_value.connectivity_ptr().use_count() > 0, + "No connectivity is associated to this ItemValue"); const IConnectivity& connectivity = *item_value.connectivity_ptr(); switch (connectivity.dimension()) { case 1: { - this->_synchronize(static_cast<const Connectivity1D&>(connectivity), item_value); + this->_synchronize(static_cast<const Connectivity1D&>(connectivity), + item_value); break; } case 2: { - this->_synchronize(static_cast<const Connectivity2D&>(connectivity), item_value); + this->_synchronize(static_cast<const Connectivity2D&>(connectivity), + item_value); break; } case 3: { - this->_synchronize(static_cast<const Connectivity3D&>(connectivity), item_value); + this->_synchronize(static_cast<const Connectivity3D&>(connectivity), + item_value); break; } default: { @@ -212,4 +225,4 @@ class Synchronizer } }; -#endif // SYNCHRONIZER_HPP +#endif // SYNCHRONIZER_HPP diff --git a/src/mesh/SynchronizerManager.cpp b/src/mesh/SynchronizerManager.cpp index 1db720e39..27f681bbc 100644 --- a/src/mesh/SynchronizerManager.cpp +++ b/src/mesh/SynchronizerManager.cpp @@ -1,48 +1,48 @@ -#include <SynchronizerManager.hpp> #include <PastisAssert.hpp> +#include <SynchronizerManager.hpp> #include <Messenger.hpp> #include <Synchronizer.hpp> -SynchronizerManager* -SynchronizerManager::m_instance{nullptr}; +SynchronizerManager* SynchronizerManager::m_instance{nullptr}; -SynchronizerManager:: -~SynchronizerManager() +SynchronizerManager::~SynchronizerManager() { - if (m_connectivity_synchronizer_map.size() > 0) - { + if (m_connectivity_synchronizer_map.size() > 0) { perr() << __FILE__ << ':' << __LINE__ - << ": warning: some connectivities are still registered\n";; + << ": warning: some connectivities are still registered\n"; + ; } } -void SynchronizerManager::create() +void +SynchronizerManager::create() { Assert(m_instance == nullptr, "SynchronizerManager is already created"); m_instance = new SynchronizerManager; } -void SynchronizerManager::destroy() +void +SynchronizerManager::destroy() { Assert(m_instance != nullptr, "SynchronizerManager was not created!"); delete m_instance; m_instance = nullptr; } - void -SynchronizerManager:: -deleteConnectivitySynchronizer(const IConnectivity* connectivity) +SynchronizerManager::deleteConnectivitySynchronizer( + const IConnectivity* connectivity) { m_connectivity_synchronizer_map.erase(connectivity); } Synchronizer& -SynchronizerManager:: -getConnectivitySynchronizer(const IConnectivity* connectivity) +SynchronizerManager::getConnectivitySynchronizer( + const IConnectivity* connectivity) { - if (auto connectivity_synchronizer = m_connectivity_synchronizer_map.find(connectivity); + if (auto connectivity_synchronizer = + m_connectivity_synchronizer_map.find(connectivity); connectivity_synchronizer != m_connectivity_synchronizer_map.end()) { return (*connectivity_synchronizer->second); } else { diff --git a/src/mesh/SynchronizerManager.hpp b/src/mesh/SynchronizerManager.hpp index 3fdf57d9b..cdc69f7b8 100644 --- a/src/mesh/SynchronizerManager.hpp +++ b/src/mesh/SynchronizerManager.hpp @@ -1,11 +1,11 @@ #ifndef SYNCHRONIZER_MANAGER_HPP #define SYNCHRONIZER_MANAGER_HPP -#include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisMacros.hpp> -#include <memory> #include <map> +#include <memory> class IConnectivity; class Synchronizer; @@ -13,7 +13,8 @@ class Synchronizer; class SynchronizerManager { private: - std::map<const IConnectivity*, std::shared_ptr<Synchronizer>> m_connectivity_synchronizer_map; + std::map<const IConnectivity*, std::shared_ptr<Synchronizer>> + m_connectivity_synchronizer_map; static SynchronizerManager* m_instance; SynchronizerManager() = default; @@ -24,7 +25,8 @@ class SynchronizerManager static void destroy(); PASTIS_INLINE - static SynchronizerManager& instance() + static SynchronizerManager& + instance() { Assert(m_instance != nullptr, "SynchronizerManager was not created!"); return *m_instance; @@ -34,4 +36,4 @@ class SynchronizerManager Synchronizer& getConnectivitySynchronizer(const IConnectivity*); }; -#endif // SYNCHRONIZER_MANAGER_HPP +#endif // SYNCHRONIZER_MANAGER_HPP diff --git a/src/output/OutputNamedItemValueSet.hpp b/src/output/OutputNamedItemValueSet.hpp index c7ef0eeb9..290a53db2 100644 --- a/src/output/OutputNamedItemValueSet.hpp +++ b/src/output/OutputNamedItemValueSet.hpp @@ -2,28 +2,29 @@ #define OUTPUT_NAMED_ITEM_VALUE_SET_HPP #include <ItemValue.hpp> -#include <TinyVector.hpp> #include <TinyMatrix.hpp> +#include <TinyVector.hpp> -#include <variant> #include <map> #include <string> +#include <variant> -template <typename DataType, - ItemType item_type> +template <typename DataType, ItemType item_type> class NamedItemValue { private: std::string m_name; - ItemValue<const DataType,item_type> m_item_value; + ItemValue<const DataType, item_type> m_item_value; public: - constexpr const std::string& name() const + constexpr const std::string& + name() const { return m_name; } - constexpr const ItemValue<const DataType,item_type>& itemValue() const + constexpr const ItemValue<const DataType, item_type>& + itemValue() const { return m_item_value; } @@ -32,23 +33,24 @@ class NamedItemValue NamedItemValue& operator=(NamedItemValue&&) = default; template <typename ConnectivityPtr> - NamedItemValue(const std::string& name, const ItemValue<DataType,item_type, ConnectivityPtr>& item_value) - : m_name(name), - m_item_value(item_value) + NamedItemValue( + const std::string& name, + const ItemValue<DataType, item_type, ConnectivityPtr>& item_value) + : m_name(name), m_item_value(item_value) { ; } - NamedItemValue(const std::string& name, const ItemValue<const DataType,item_type>& item_value) - : m_name(name), - m_item_value(item_value) + NamedItemValue(const std::string& name, + const ItemValue<const DataType, item_type>& item_value) + : m_name(name), m_item_value(item_value) { ; } NamedItemValue(const NamedItemValue&) = default; - NamedItemValue(NamedItemValue&&) = default; - ~NamedItemValue() = default; + NamedItemValue(NamedItemValue&&) = default; + ~NamedItemValue() = default; }; class OutputNamedItemValueSet @@ -57,66 +59,66 @@ class OutputNamedItemValueSet using ItemValueVariant = std::variant<NodeValue<const int>, NodeValue<const long int>, NodeValue<const double>, - NodeValue<const TinyVector<1,double>>, - NodeValue<const TinyVector<2,double>>, - NodeValue<const TinyVector<3,double>>, + NodeValue<const TinyVector<1, double>>, + NodeValue<const TinyVector<2, double>>, + NodeValue<const TinyVector<3, double>>, CellValue<const int>, CellValue<const long int>, CellValue<const double>, - CellValue<const TinyVector<1,double>>, - CellValue<const TinyVector<2,double>>, - CellValue<const TinyVector<3,double>> - >; + CellValue<const TinyVector<1, double>>, + CellValue<const TinyVector<2, double>>, + CellValue<const TinyVector<3, double>>>; private: std::map<std::string, ItemValueVariant> m_name_itemvariant_map; - template <typename DataType, - ItemType item_type> - PASTIS_FORCEINLINE - constexpr void _doInsert(const NamedItemValue<DataType, item_type>& named_itemvalue) + template <typename DataType, ItemType item_type> + PASTIS_FORCEINLINE constexpr void + _doInsert(const NamedItemValue<DataType, item_type>& named_itemvalue) { - if (m_name_itemvariant_map.find(named_itemvalue.name()) == m_name_itemvariant_map.end()) { - m_name_itemvariant_map[named_itemvalue.name()] = named_itemvalue.itemValue(); + if (m_name_itemvariant_map.find(named_itemvalue.name()) == + m_name_itemvariant_map.end()) { + m_name_itemvariant_map[named_itemvalue.name()] = + named_itemvalue.itemValue(); } } - template <typename DataType, - ItemType item_type, - typename... Args> - PASTIS_FORCEINLINE - constexpr void _unpackVariadicInput(const NamedItemValue<DataType, item_type>& named_itemvalue, - Args&&... args) + template <typename DataType, ItemType item_type, typename... Args> + PASTIS_FORCEINLINE constexpr void + _unpackVariadicInput( + const NamedItemValue<DataType, item_type>& named_itemvalue, + Args&&... args) { _doInsert(named_itemvalue); if constexpr (sizeof...(args) > 0) { - this->_unpackVariadicInput(std::forward<Args>(args)...); - } + this->_unpackVariadicInput(std::forward<Args>(args)...); + } } public: - auto begin() const + auto + begin() const { return m_name_itemvariant_map.begin(); } - auto end() const + auto + end() const { return m_name_itemvariant_map.end(); } - template <typename ...DataType, - ItemType ...item_type> - OutputNamedItemValueSet(NamedItemValue<DataType, item_type>... named_itemvalue) + template <typename... DataType, ItemType... item_type> + OutputNamedItemValueSet( + NamedItemValue<DataType, item_type>... named_itemvalue) { _unpackVariadicInput(named_itemvalue...); } OutputNamedItemValueSet(const OutputNamedItemValueSet&) = default; - OutputNamedItemValueSet() = default; - ~OutputNamedItemValueSet() = default; + OutputNamedItemValueSet() = default; + ~OutputNamedItemValueSet() = default; }; - -#endif // OUTPUT_NAMED_ITEM_VALUE_SET_HPP +#endif // OUTPUT_NAMED_ITEM_VALUE_SET_HPP diff --git a/src/output/VTKWriter.hpp b/src/output/VTKWriter.hpp index 16f49cc41..343281d77 100644 --- a/src/output/VTKWriter.hpp +++ b/src/output/VTKWriter.hpp @@ -1,12 +1,12 @@ #ifndef VTK_WRITER_HPP #define VTK_WRITER_HPP -#include <string> +#include <IConnectivity.hpp> +#include <TinyVector.hpp> #include <fstream> #include <iomanip> #include <sstream> -#include <TinyVector.hpp> -#include <IConnectivity.hpp> +#include <string> #include <ItemValue.hpp> #include <Messenger.hpp> @@ -20,14 +20,17 @@ class VTKWriter double m_last_time; const double m_time_period; - std::string _getFilenamePVTU() + std::string + _getFilenamePVTU() { std::ostringstream sout; sout << m_base_filename; - sout << '.' << std::setfill('0') << std::setw(4) << m_file_number << ".pvtu"; + sout << '.' << std::setfill('0') << std::setw(4) << m_file_number + << ".pvtu"; return sout.str(); } - std::string _getFilenameVTU(const int& rank_number) const + std::string + _getFilenameVTU(const int& rank_number) const { std::ostringstream sout; sout << m_base_filename; @@ -39,81 +42,90 @@ class VTKWriter } template <typename DataType> - void _write_node_pvtu(std::ofstream& os, - const std::string& name, - const NodeValue<const DataType>&) + void + _write_node_pvtu(std::ofstream& os, + const std::string& name, + const NodeValue<const DataType>&) { - os << "<PDataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\"/>\n"; + os << "<PDataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\"/>\n"; } - template <size_t N, - typename DataType> - void _write_node_pvtu(std::ofstream& os, - const std::string& name, - const NodeValue<const TinyVector<N, DataType>>&) + template <size_t N, typename DataType> + void + _write_node_pvtu(std::ofstream& os, + const std::string& name, + const NodeValue<const TinyVector<N, DataType>>&) { - os << "<PDataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\"/>\n"; + os << "<PDataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\" NumberOfComponents=\"" << N << "\"/>\n"; } template <typename DataType> - void _write_node_pvtu(std::ofstream&, - const std::string&, - const CellValue<const DataType>&) {} + void + _write_node_pvtu(std::ofstream&, + const std::string&, + const CellValue<const DataType>&) + {} template <typename DataType> - void _write_cell_pvtu(std::ofstream& os, - const std::string& name, - const CellValue<const DataType>&) + void + _write_cell_pvtu(std::ofstream& os, + const std::string& name, + const CellValue<const DataType>&) { - os << "<PDataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\"/>\n"; + os << "<PDataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\"/>\n"; } - template <size_t N, - typename DataType> - void _write_cell_pvtu(std::ofstream& os, - const std::string& name, - const CellValue<const TinyVector<N, DataType>>&) + template <size_t N, typename DataType> + void + _write_cell_pvtu(std::ofstream& os, + const std::string& name, + const CellValue<const TinyVector<N, DataType>>&) { - os << "<PDataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\"/>\n"; + os << "<PDataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\" NumberOfComponents=\"" << N << "\"/>\n"; } template <typename DataType> - void _write_cell_pvtu(std::ofstream&, - const std::string&, - const NodeValue<const DataType>&) {} + void + _write_cell_pvtu(std::ofstream&, + const std::string&, + const NodeValue<const DataType>&) + {} - template <typename DataType> struct VTKType {}; + template <typename DataType> + struct VTKType + {}; template <typename DataType> - void _write_array(std::ofstream& os, - const std::string& name, - const Array<DataType>& item_value) + void + _write_array(std::ofstream& os, + const std::string& name, + const Array<DataType>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\">\n"; - for (typename Array<DataType>::index_type i=0; - i<item_value.size(); ++i) { + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\">\n"; + for (typename Array<DataType>::index_type i = 0; i < item_value.size(); + ++i) { // The following '+' enforces integer output for char types os << +item_value[i] << ' '; } os << "\n</DataArray>\n"; } - template <size_t N, - typename DataType> - void _write_array(std::ofstream& os, - const std::string& name, - const Array<TinyVector<N, DataType>>& item_value) + template <size_t N, typename DataType> + void + _write_array(std::ofstream& os, + const std::string& name, + const Array<TinyVector<N, DataType>>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\">\n"; - for (typename Array<DataType>::index_type i=0; - i<item_value.size(); ++i) { - for (size_t j=0; j<N; ++j) { + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\" NumberOfComponents=\"" << N << "\">\n"; + for (typename Array<DataType>::index_type i = 0; i < item_value.size(); + ++i) { + for (size_t j = 0; j < N; ++j) { // The following '+' enforces integer output for char types os << +item_value[i][j] << ' '; } @@ -122,30 +134,31 @@ class VTKWriter } template <typename DataType> - void _write_node_value(std::ofstream& os, - const std::string& name, - const NodeValue<const DataType>& item_value) + void + _write_node_value(std::ofstream& os, + const std::string& name, + const NodeValue<const DataType>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\">\n"; - for (NodeId i=0; i<item_value.size(); ++i) { + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\">\n"; + for (NodeId i = 0; i < item_value.size(); ++i) { // The following '+' enforces integer output for char types os << +item_value[i] << ' '; } os << "\n</DataArray>\n"; } - template <size_t N, - typename DataType> - void _write_node_value(std::ofstream& os, - const std::string& name, - const NodeValue<const TinyVector<N, DataType>>& item_value) + template <size_t N, typename DataType> + void + _write_node_value(std::ofstream& os, + const std::string& name, + const NodeValue<const TinyVector<N, DataType>>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\">\n"; - for (NodeId i=0; i<item_value.size(); ++i) { - for (size_t j=0; j<N; ++j) { - // The following '+' enforces integer output for char types + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\" NumberOfComponents=\"" << N << "\">\n"; + for (NodeId i = 0; i < item_value.size(); ++i) { + for (size_t j = 0; j < N; ++j) { + // The following '+' enforces integer output for char types os << +item_value[i][j] << ' '; } } @@ -153,35 +166,38 @@ class VTKWriter } template <typename DataType> - void _write_node_value(std::ofstream&, - const std::string&, - const CellValue<const DataType>&) {} + void + _write_node_value(std::ofstream&, + const std::string&, + const CellValue<const DataType>&) + {} template <typename DataType> - void _write_cell_value(std::ofstream& os, - const std::string& name, - const CellValue<const DataType>& item_value) + void + _write_cell_value(std::ofstream& os, + const std::string& name, + const CellValue<const DataType>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\">\n"; - for (CellId i=0; i<item_value.size(); ++i) { + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\">\n"; + for (CellId i = 0; i < item_value.size(); ++i) { // The following '+' enforces integer output for char types os << +item_value[i] << ' '; } os << "\n</DataArray>\n"; } - template <size_t N, - typename DataType> - void _write_cell_value(std::ofstream& os, - const std::string& name, - const CellValue<const TinyVector<N, DataType>>& item_value) + template <size_t N, typename DataType> + void + _write_cell_value(std::ofstream& os, + const std::string& name, + const CellValue<const TinyVector<N, DataType>>& item_value) { - os << "<DataArray type=\"" << VTKType<DataType>::name - << "\" Name=\"" << name << "\" NumberOfComponents=\"" << N << "\">\n"; - for (CellId i=0; i<item_value.size(); ++i) { - for (size_t j=0; j<N; ++j) { - // The following '+' enforces integer output for char types + os << "<DataArray type=\"" << VTKType<DataType>::name << "\" Name=\"" + << name << "\" NumberOfComponents=\"" << N << "\">\n"; + for (CellId i = 0; i < item_value.size(); ++i) { + for (size_t j = 0; j < N; ++j) { + // The following '+' enforces integer output for char types os << +item_value[i][j] << ' '; } } @@ -189,169 +205,190 @@ class VTKWriter } template <typename DataType> - void _write_cell_value(std::ofstream&, - const std::string&, - const NodeValue<const DataType>&) {} + void + _write_cell_value(std::ofstream&, + const std::string&, + const NodeValue<const DataType>&) + {} public: template <typename MeshType> - void write(const MeshType& mesh, - const OutputNamedItemValueSet& output_named_item_value_set, - const double& time, - const bool& forced_output = false) + void + write(const MeshType& mesh, + const OutputNamedItemValueSet& output_named_item_value_set, + const double& time, + const bool& forced_output = false) { - if (time == m_last_time) return; // output already performed + if (time == m_last_time) + return; // output already performed if ((time - m_last_time >= m_time_period) or forced_output) { m_last_time = time; } else { return; } - if (parallel::rank() == 0) - { // write PVTK file + if (parallel::rank() == 0) { // write PVTK file std::ofstream fout(_getFilenamePVTU()); fout << "<?xml version=\"1.0\"?>\n"; fout << "<VTKFile type=\"PUnstructuredGrid\">\n"; fout << "<PUnstructuredGrid GhostLevel=\"0\">\n"; fout << "<PPoints>\n"; - fout << "<PDataArray Name=\"Positions\" NumberOfComponents=\"3\" type=\"Float64\"/>\n"; + fout << "<PDataArray Name=\"Positions\" NumberOfComponents=\"3\" " + "type=\"Float64\"/>\n"; fout << "</PPoints>\n"; fout << "<PCells>\n"; - fout << "<PDataArray type=\"Int32\" Name=\"connectivity\" NumberOfComponents=\"1\"/>\n"; - fout << "<PDataArray type=\"UInt32\" Name=\"offsets\" NumberOfComponents=\"1\"/>\n"; - fout << "<PDataArray type=\"Int8\" Name=\"types\" NumberOfComponents=\"1\"/>\n"; - for(const auto& [name, item_value_variant] : output_named_item_value_set) { - std::visit([&, name=name](auto&& item_value) { - return this->_write_cell_pvtu(fout, name, item_value); - }, item_value_variant); + fout << "<PDataArray type=\"Int32\" Name=\"connectivity\" " + "NumberOfComponents=\"1\"/>\n"; + fout << "<PDataArray type=\"UInt32\" Name=\"offsets\" " + "NumberOfComponents=\"1\"/>\n"; + fout << "<PDataArray type=\"Int8\" Name=\"types\" " + "NumberOfComponents=\"1\"/>\n"; + for (const auto& [name, item_value_variant] : + output_named_item_value_set) { + std::visit( + [&, name = name](auto&& item_value) { + return this->_write_cell_pvtu(fout, name, item_value); + }, + item_value_variant); } fout << "</PCells>\n"; fout << "<PPointData>\n"; - for(const auto& [name, item_value_variant] : output_named_item_value_set) { - std::visit([&, name=name](auto&& item_value) { - return this->_write_node_pvtu(fout, name, item_value); - }, item_value_variant); + for (const auto& [name, item_value_variant] : + output_named_item_value_set) { + std::visit( + [&, name = name](auto&& item_value) { + return this->_write_node_pvtu(fout, name, item_value); + }, + item_value_variant); } fout << "</PPointData>\n"; fout << "<PCellData>\n"; - for(const auto& [name, item_value_variant] : output_named_item_value_set) { - std::visit([&, name=name](auto&& item_value) { - return this->_write_cell_pvtu(fout, name, item_value); - }, item_value_variant); + for (const auto& [name, item_value_variant] : + output_named_item_value_set) { + std::visit( + [&, name = name](auto&& item_value) { + return this->_write_cell_pvtu(fout, name, item_value); + }, + item_value_variant); } fout << "</PCellData>\n"; - for (size_t i_rank=0; i_rank<parallel::size(); ++i_rank) { - fout << "<Piece Source=\""<< _getFilenameVTU(i_rank) << "\"/>\n"; + for (size_t i_rank = 0; i_rank < parallel::size(); ++i_rank) { + fout << "<Piece Source=\"" << _getFilenameVTU(i_rank) << "\"/>\n"; } fout << "</PUnstructuredGrid>\n"; fout << "</VTKFile>\n"; - } - { // write VTK files + { // write VTK files std::ofstream fout(_getFilenameVTU(parallel::rank())); fout << "<?xml version=\"1.0\"?>\n"; fout << "<VTKFile type=\"UnstructuredGrid\">\n"; fout << "<UnstructuredGrid>\n"; - fout << "<Piece NumberOfPoints=\""<< mesh.numberOfNodes() + fout << "<Piece NumberOfPoints=\"" << mesh.numberOfNodes() << "\" NumberOfCells=\"" << mesh.numberOfCells() << "\">\n"; fout << "<CellData>\n"; - for(const auto& [name, item_value_variant] : output_named_item_value_set) { - std::visit([&, name=name](auto&& item_value) { - return this->_write_cell_value(fout, name, item_value); - }, item_value_variant); + for (const auto& [name, item_value_variant] : + output_named_item_value_set) { + std::visit( + [&, name = name](auto&& item_value) { + return this->_write_cell_value(fout, name, item_value); + }, + item_value_variant); } fout << "</CellData>\n"; fout << "<PointData>\n"; - for(const auto& [name, item_value_variant] : output_named_item_value_set) { - std::visit([&, name=name](auto&& item_value) { - return this->_write_node_value(fout, name, item_value); - }, item_value_variant); + for (const auto& [name, item_value_variant] : + output_named_item_value_set) { + std::visit( + [&, name = name](auto&& item_value) { + return this->_write_node_value(fout, name, item_value); + }, + item_value_variant); } fout << "</PointData>\n"; fout << "<Points>\n"; { - using Rd = TinyVector<MeshType::Dimension>; + using Rd = TinyVector<MeshType::Dimension>; const NodeValue<const Rd>& xr = mesh.xr(); Array<TinyVector<3>> positions(mesh.numberOfNodes()); parallel_for(mesh.numberOfNodes(), PASTIS_LAMBDA(NodeId r) { - for (unsigned short i=0; i<MeshType::Dimension; ++i) { - positions[r][i] = xr[r][i]; - } - for (unsigned short i=MeshType::Dimension; i<3; ++i) { - positions[r][i] = 0; - } - }); + for (unsigned short i = 0; i < MeshType::Dimension; ++i) { + positions[r][i] = xr[r][i]; + } + for (unsigned short i = MeshType::Dimension; i < 3; ++i) { + positions[r][i] = 0; + } + }); _write_array(fout, "Positions", positions); } fout << "</Points>\n"; fout << "<Cells>\n"; { - const auto& cell_to_node_matrix - = mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + mesh.connectivity().cellToNodeMatrix(); _write_array(fout, "connectivity", cell_to_node_matrix.entries()); } { - const auto& cell_to_node_matrix - = mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = + mesh.connectivity().cellToNodeMatrix(); Array<unsigned int> offsets(mesh.numberOfCells()); - unsigned int offset=0; - for (CellId j=0; j<mesh.numberOfCells(); ++j) { + unsigned int offset = 0; + for (CellId j = 0; j < mesh.numberOfCells(); ++j) { const auto& cell_nodes = cell_to_node_matrix[j]; offset += cell_nodes.size(); - offsets[j]=offset; + offsets[j] = offset; } _write_array(fout, "offsets", offsets); } { Array<int8_t> types(mesh.numberOfCells()); - const auto& cell_type - = mesh.connectivity().cellType(); + const auto& cell_type = mesh.connectivity().cellType(); parallel_for(mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - switch (cell_type[j]) { - case CellType::Line: { - types[j]=3; - break; - } - case CellType::Triangle: { - types[j]=5; - break; - } - case CellType::Quadrangle: { - types[j]=9; - break; - } - case CellType::Tetrahedron: { - types[j]=10; - break; - } - case CellType::Pyramid: { - types[j]=14; - break; - } - case CellType::Prism: { - types[j]=13; - break; - } - case CellType::Hexahedron: { - types[j]=12; - break; - } - default: { - std::cerr << __FILE__ << ':' << __LINE__ << ": unknown cell type\n"; - std::exit(1); - } + switch (cell_type[j]) { + case CellType::Line: { + types[j] = 3; + break; + } + case CellType::Triangle: { + types[j] = 5; + break; + } + case CellType::Quadrangle: { + types[j] = 9; + break; + } + case CellType::Tetrahedron: { + types[j] = 10; + break; + } + case CellType::Pyramid: { + types[j] = 14; + break; + } + case CellType::Prism: { + types[j] = 13; + break; + } + case CellType::Hexahedron: { + types[j] = 12; + break; } - }); + default: { + std::cerr << __FILE__ << ':' << __LINE__ + << ": unknown cell type\n"; + std::exit(1); + } + } + }); _write_array(fout, "types", types); } @@ -363,12 +400,11 @@ class VTKWriter m_file_number++; } - VTKWriter(const std::string& base_filename, - const double time_period) - : m_base_filename(base_filename), - m_file_number (0), - m_last_time (-std::numeric_limits<double>::max()), - m_time_period (time_period) + VTKWriter(const std::string& base_filename, const double time_period) + : m_base_filename(base_filename), + m_file_number(0), + m_last_time(-std::numeric_limits<double>::max()), + m_time_period(time_period) {} ~VTKWriter() = default; @@ -380,49 +416,58 @@ struct VTKWriter::VTKType<int8_t> inline const static std::string name{"Int8"}; }; -template <> struct VTKWriter::VTKType<uint8_t> +template <> +struct VTKWriter::VTKType<uint8_t> { inline const static std::string name{"UInt8"}; }; -template <> struct VTKWriter::VTKType<int16_t> +template <> +struct VTKWriter::VTKType<int16_t> { inline const static std::string name{"Int16"}; }; -template <> struct VTKWriter::VTKType<uint16_t> +template <> +struct VTKWriter::VTKType<uint16_t> { inline const static std::string name{"UInt16"}; }; -template <> struct VTKWriter::VTKType<int32_t> +template <> +struct VTKWriter::VTKType<int32_t> { inline const static std::string name{"Int32"}; }; -template <> struct VTKWriter::VTKType<uint32_t> +template <> +struct VTKWriter::VTKType<uint32_t> { inline const static std::string name{"UInt32"}; }; -template <> struct VTKWriter::VTKType<int64_t> +template <> +struct VTKWriter::VTKType<int64_t> { inline const static std::string name{"Int64"}; }; -template <> struct VTKWriter::VTKType<uint64_t> +template <> +struct VTKWriter::VTKType<uint64_t> { inline const static std::string name{"UInt64"}; }; -template <> struct VTKWriter::VTKType<float> +template <> +struct VTKWriter::VTKType<float> { inline const static std::string name{"Float32"}; }; -template <> struct VTKWriter::VTKType<double> +template <> +struct VTKWriter::VTKType<double> { inline const static std::string name{"Float64"}; }; -#endif // VTK_WRITER_HPP +#endif // VTK_WRITER_HPP diff --git a/src/scheme/AcousticSolver.hpp b/src/scheme/AcousticSolver.hpp index cb83a583b..cea444e84 100644 --- a/src/scheme/AcousticSolver.hpp +++ b/src/scheme/AcousticSolver.hpp @@ -8,21 +8,21 @@ #include <BlockPerfectGas.hpp> #include <PastisAssert.hpp> -#include <TinyVector.hpp> -#include <TinyMatrix.hpp> +#include <BoundaryCondition.hpp> +#include <FiniteVolumesEulerUnknowns.hpp> #include <Mesh.hpp> #include <MeshData.hpp> -#include <FiniteVolumesEulerUnknowns.hpp> -#include <BoundaryCondition.hpp> +#include <TinyMatrix.hpp> +#include <TinyVector.hpp> -#include <SubItemValuePerItem.hpp> -#include <Messenger.hpp> #include <ItemValueUtils.hpp> +#include <Messenger.hpp> +#include <SubItemValuePerItem.hpp> -template<typename MeshData> +template <typename MeshData> class AcousticSolver { - using MeshType = typename MeshData::MeshType; + using MeshType = typename MeshData::MeshType; using UnknownsType = FiniteVolumesEulerUnknowns<MeshData>; MeshData& m_mesh_data; @@ -32,7 +32,7 @@ class AcousticSolver constexpr static size_t Dimension = MeshType::Dimension; - using Rd = TinyVector<Dimension>; + using Rd = TinyVector<Dimension>; using Rdd = TinyMatrix<Dimension>; private: @@ -42,47 +42,48 @@ class AcousticSolver const CellValue<const double>& cj) { parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - m_rhocj[j] = rhoj[j]*cj[j]; - }); + m_rhocj[j] = rhoj[j] * cj[j]; + }); return m_rhocj; } PASTIS_INLINE - void computeAjr(const CellValue<const double>& rhocj, - const NodeValuePerCell<const Rd>& Cjr, - const NodeValuePerCell<const double>& /* ljr */, - const NodeValuePerCell<const Rd>& njr) + void + computeAjr(const CellValue<const double>& rhocj, + const NodeValuePerCell<const Rd>& Cjr, + const NodeValuePerCell<const double>& /* ljr */, + const NodeValuePerCell<const Rd>& njr) { parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - const size_t& nb_nodes =m_Ajr.numberOfSubValues(j); - const double& rho_c = rhocj[j]; - for (size_t r=0; r<nb_nodes; ++r) { - m_Ajr(j,r) = tensorProduct(rho_c*Cjr(j,r), njr(j,r)); - } - }); + const size_t& nb_nodes = m_Ajr.numberOfSubValues(j); + const double& rho_c = rhocj[j]; + for (size_t r = 0; r < nb_nodes; ++r) { + m_Ajr(j, r) = tensorProduct(rho_c * Cjr(j, r), njr(j, r)); + } + }); } PASTIS_INLINE const NodeValue<const Rdd> - computeAr(const NodeValuePerCell<const Rdd>& Ajr) { - const auto& node_to_cell_matrix - = m_connectivity.nodeToCellMatrix(); - const auto& node_local_numbers_in_their_cells - = m_connectivity.nodeLocalNumbersInTheirCells(); + computeAr(const NodeValuePerCell<const Rdd>& Ajr) + { + const auto& node_to_cell_matrix = m_connectivity.nodeToCellMatrix(); + const auto& node_local_numbers_in_their_cells = + m_connectivity.nodeLocalNumbersInTheirCells(); parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { - Rdd sum = zero; - const auto& node_to_cell = node_to_cell_matrix[r]; - const auto& node_local_number_in_its_cells - = node_local_numbers_in_their_cells.itemValues(r); - - for (size_t j=0; j<node_to_cell.size(); ++j) { - const CellId J = node_to_cell[j]; - const unsigned int R = node_local_number_in_its_cells[j]; - sum += Ajr(J,R); - } - m_Ar[r] = sum; - }); + Rdd sum = zero; + const auto& node_to_cell = node_to_cell_matrix[r]; + const auto& node_local_number_in_its_cells = + node_local_numbers_in_their_cells.itemValues(r); + + for (size_t j = 0; j < node_to_cell.size(); ++j) { + const CellId J = node_to_cell[j]; + const unsigned int R = node_local_number_in_its_cells[j]; + sum += Ajr(J, R); + } + m_Ar[r] = sum; + }); return m_Ar; } @@ -92,66 +93,69 @@ class AcousticSolver computeBr(const NodeValuePerCell<Rdd>& Ajr, const NodeValuePerCell<const Rd>& Cjr, const CellValue<const Rd>& uj, - const CellValue<const double>& pj) { - const auto& node_to_cell_matrix - = m_connectivity.nodeToCellMatrix(); - const auto& node_local_numbers_in_their_cells - = m_connectivity.nodeLocalNumbersInTheirCells(); + const CellValue<const double>& pj) + { + const auto& node_to_cell_matrix = m_connectivity.nodeToCellMatrix(); + const auto& node_local_numbers_in_their_cells = + m_connectivity.nodeLocalNumbersInTheirCells(); parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { - Rd& br = m_br[r]; - br = zero; - const auto& node_to_cell = node_to_cell_matrix[r]; - const auto& node_local_number_in_its_cells - = node_local_numbers_in_their_cells.itemValues(r); - for (size_t j=0; j<node_to_cell.size(); ++j) { - const CellId J = node_to_cell[j]; - const unsigned int R = node_local_number_in_its_cells[j]; - br += Ajr(J,R)*uj[J] + pj[J]*Cjr(J,R); - } - }); + Rd& br = m_br[r]; + br = zero; + const auto& node_to_cell = node_to_cell_matrix[r]; + const auto& node_local_number_in_its_cells = + node_local_numbers_in_their_cells.itemValues(r); + for (size_t j = 0; j < node_to_cell.size(); ++j) { + const CellId J = node_to_cell[j]; + const unsigned int R = node_local_number_in_its_cells[j]; + br += Ajr(J, R) * uj[J] + pj[J] * Cjr(J, R); + } + }); return m_br; } - void applyBoundaryConditions() + void + applyBoundaryConditions() { for (const auto& handler : m_boundary_condition_list) { switch (handler.boundaryCondition().type()) { case BoundaryCondition::normal_velocity: { - perr() << __FILE__ << ':' << __LINE__ << ": normal_velocity BC NIY\n"; + perr() << __FILE__ << ':' << __LINE__ << ": normal_velocity BC NIY\n"; std::exit(0); break; } case BoundaryCondition::velocity: { - perr() << __FILE__ << ':' << __LINE__ << ": velocity BC NIY\n"; + perr() << __FILE__ << ':' << __LINE__ << ": velocity BC NIY\n"; std::exit(0); break; } case BoundaryCondition::pressure: { // const PressureBoundaryCondition& pressure_bc - // = dynamic_cast<const PressureBoundaryCondition&>(handler.boundaryCondition()); + // = dynamic_cast<const + // PressureBoundaryCondition&>(handler.boundaryCondition()); perr() << __FILE__ << ':' << __LINE__ << ": pressure BC NIY\n"; std::exit(0); break; } case BoundaryCondition::symmetry: { - const SymmetryBoundaryCondition<Dimension>& symmetry_bc - = dynamic_cast<const SymmetryBoundaryCondition<Dimension>&>(handler.boundaryCondition()); + const SymmetryBoundaryCondition<Dimension>& symmetry_bc = + dynamic_cast<const SymmetryBoundaryCondition<Dimension>&>( + handler.boundaryCondition()); const Rd& n = symmetry_bc.outgoingNormal(); - const Rdd I = identity; - const Rdd nxn = tensorProduct(n,n); - const Rdd P = I-nxn; + const Rdd I = identity; + const Rdd nxn = tensorProduct(n, n); + const Rdd P = I - nxn; - const Array<const NodeId>& node_list - = symmetry_bc.nodeList(); - parallel_for(symmetry_bc.numberOfNodes(), PASTIS_LAMBDA(const int& r_number) { - const NodeId r = node_list[r_number]; + const Array<const NodeId>& node_list = symmetry_bc.nodeList(); + parallel_for(symmetry_bc.numberOfNodes(), + PASTIS_LAMBDA(const int& r_number) { + const NodeId r = node_list[r_number]; - m_Ar[r] = P*m_Ar[r]*P + nxn; - m_br[r] = P*m_br[r]; - }); + m_Ar[r] = P * m_Ar[r] * P + nxn; + m_br[r] = P * m_br[r]; + }); break; } } @@ -159,14 +163,13 @@ class AcousticSolver } NodeValue<Rd> - computeUr(const NodeValue<const Rdd>& Ar, - const NodeValue<const Rd>& br) + computeUr(const NodeValue<const Rdd>& Ar, const NodeValue<const Rd>& br) { inverse(Ar, m_inv_Ar); const NodeValue<const Rdd> invAr = m_inv_Ar; parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { - m_ur[r]=invAr[r]*br[r]; - }); + m_ur[r] = invAr[r] * br[r]; + }); return m_ur; } @@ -178,34 +181,36 @@ class AcousticSolver const CellValue<const Rd>& uj, const CellValue<const double>& pj) { - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - const auto& cell_nodes = cell_to_node_matrix[j]; + const auto& cell_nodes = cell_to_node_matrix[j]; - for (size_t r=0; r<cell_nodes.size(); ++r) { - m_Fjr(j,r) = Ajr(j,r)*(uj[j]-ur[cell_nodes[r]])+pj[j]*Cjr(j,r); - } - }); + for (size_t r = 0; r < cell_nodes.size(); ++r) { + m_Fjr(j, r) = + Ajr(j, r) * (uj[j] - ur[cell_nodes[r]]) + pj[j] * Cjr(j, r); + } + }); } - void inverse(const NodeValue<const Rdd>& A, - NodeValue<Rdd>& inv_A) const + void + inverse(const NodeValue<const Rdd>& A, NodeValue<Rdd>& inv_A) const { parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { - inv_A[r] = ::inverse(A[r]); - }); + inv_A[r] = ::inverse(A[r]); + }); } PASTIS_INLINE - void computeExplicitFluxes(const CellValue<const double>& rhoj, - const CellValue<const Rd>& uj, - const CellValue<const double>& pj, - const CellValue<const double>& cj, - const NodeValuePerCell<const Rd>& Cjr, - const NodeValuePerCell<const double>& ljr, - const NodeValuePerCell<const Rd>& njr) { + void + computeExplicitFluxes(const CellValue<const double>& rhoj, + const CellValue<const Rd>& uj, + const CellValue<const double>& pj, + const CellValue<const double>& cj, + const NodeValuePerCell<const Rd>& Cjr, + const NodeValuePerCell<const double>& ljr, + const NodeValuePerCell<const Rd>& njr) + { const CellValue<const double> rhocj = computeRhoCj(rhoj, cj); computeAjr(rhocj, Cjr, ljr, njr); @@ -219,7 +224,7 @@ class AcousticSolver synchronize(m_br); NodeValue<Rd>& ur = m_ur; - ur = computeUr(m_Ar, m_br); + ur = computeUr(m_Ar, m_br); computeFjr(m_Ajr, ur, Cjr, uj, pj); } @@ -235,96 +240,94 @@ class AcousticSolver public: AcousticSolver(MeshData& mesh_data, const std::vector<BoundaryConditionHandler>& bc_list) - : m_mesh_data(mesh_data), - m_mesh(mesh_data.mesh()), - m_connectivity(m_mesh.connectivity()), - m_boundary_condition_list(bc_list), - m_br(m_connectivity), - m_Ajr(m_connectivity), - m_Ar(m_connectivity), - m_inv_Ar(m_connectivity), - m_Fjr(m_connectivity), - m_ur(m_connectivity), - m_rhocj(m_connectivity), - m_Vj_over_cj(m_connectivity) + : m_mesh_data(mesh_data), + m_mesh(mesh_data.mesh()), + m_connectivity(m_mesh.connectivity()), + m_boundary_condition_list(bc_list), + m_br(m_connectivity), + m_Ajr(m_connectivity), + m_Ar(m_connectivity), + m_inv_Ar(m_connectivity), + m_Fjr(m_connectivity), + m_ur(m_connectivity), + m_rhocj(m_connectivity), + m_Vj_over_cj(m_connectivity) { ; } PASTIS_INLINE - double acoustic_dt(const CellValue<const double>& Vj, - const CellValue<const double>& cj) const + double + acoustic_dt(const CellValue<const double>& Vj, + const CellValue<const double>& cj) const { const NodeValuePerCell<const double>& ljr = m_mesh_data.ljr(); - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - const auto& cell_nodes = cell_to_node_matrix[j]; + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + const auto& cell_nodes = cell_to_node_matrix[j]; - double S = 0; - for (size_t r=0; r<cell_nodes.size(); ++r) { - S += ljr(j,r); - } - m_Vj_over_cj[j] = 2*Vj[j]/(S*cj[j]); - }); + double S = 0; + for (size_t r = 0; r < cell_nodes.size(); ++r) { + S += ljr(j, r); + } + m_Vj_over_cj[j] = 2 * Vj[j] / (S * cj[j]); + }); return min(m_Vj_over_cj); } - void computeNextStep(const double&, const double& dt, - UnknownsType& unknowns) + void + computeNextStep(const double&, const double& dt, UnknownsType& unknowns) { CellValue<double>& rhoj = unknowns.rhoj(); - CellValue<Rd>& uj = unknowns.uj(); - CellValue<double>& Ej = unknowns.Ej(); + CellValue<Rd>& uj = unknowns.uj(); + CellValue<double>& Ej = unknowns.Ej(); CellValue<double>& ej = unknowns.ej(); CellValue<double>& pj = unknowns.pj(); CellValue<double>& cj = unknowns.cj(); - const CellValue<const double>& Vj = m_mesh_data.Vj(); - const NodeValuePerCell<const Rd>& Cjr = m_mesh_data.Cjr(); + const CellValue<const double>& Vj = m_mesh_data.Vj(); + const NodeValuePerCell<const Rd>& Cjr = m_mesh_data.Cjr(); const NodeValuePerCell<const double>& ljr = m_mesh_data.ljr(); - const NodeValuePerCell<const Rd>& njr = m_mesh_data.njr(); + const NodeValuePerCell<const Rd>& njr = m_mesh_data.njr(); computeExplicitFluxes(rhoj, uj, pj, cj, Cjr, ljr, njr); const NodeValuePerCell<Rd>& Fjr = m_Fjr; - const NodeValue<const Rd> ur = m_ur; - const auto& cell_to_node_matrix - = m_mesh.connectivity().cellToNodeMatrix(); + const NodeValue<const Rd> ur = m_ur; + const auto& cell_to_node_matrix = m_mesh.connectivity().cellToNodeMatrix(); const CellValue<const double> inv_mj = unknowns.invMj(); parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - const auto& cell_nodes = cell_to_node_matrix[j]; - - Rd momentum_fluxes = zero; - double energy_fluxes = 0; - for (size_t R=0; R<cell_nodes.size(); ++R) { - const NodeId r=cell_nodes[R]; - momentum_fluxes += Fjr(j,R); - energy_fluxes += (Fjr(j,R), ur[r]); - } - uj[j] -= (dt*inv_mj[j]) * momentum_fluxes; - Ej[j] -= (dt*inv_mj[j]) * energy_fluxes; - }); + const auto& cell_nodes = cell_to_node_matrix[j]; + + Rd momentum_fluxes = zero; + double energy_fluxes = 0; + for (size_t R = 0; R < cell_nodes.size(); ++R) { + const NodeId r = cell_nodes[R]; + momentum_fluxes += Fjr(j, R); + energy_fluxes += (Fjr(j, R), ur[r]); + } + uj[j] -= (dt * inv_mj[j]) * momentum_fluxes; + Ej[j] -= (dt * inv_mj[j]) * energy_fluxes; + }); parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { - ej[j] = Ej[j] - 0.5 * (uj[j],uj[j]); - }); + ej[j] = Ej[j] - 0.5 * (uj[j], uj[j]); + }); NodeValue<Rd> mutable_xr = m_mesh.mutableXr(); - parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r){ - mutable_xr[r] += dt*ur[r]; - }); + parallel_for(m_mesh.numberOfNodes(), PASTIS_LAMBDA(const NodeId& r) { + mutable_xr[r] += dt * ur[r]; + }); m_mesh_data.updateAllData(); const CellValue<const double> mj = unknowns.mj(); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - rhoj[j] = mj[j]/Vj[j]; - }); + parallel_for(m_mesh.numberOfCells(), + PASTIS_LAMBDA(const CellId& j) { rhoj[j] = mj[j] / Vj[j]; }); } }; -#endif // ACOUSTIC_SOLVER_HPP +#endif // ACOUSTIC_SOLVER_HPP diff --git a/src/scheme/BlockPerfectGas.hpp b/src/scheme/BlockPerfectGas.hpp index f3ea76520..5c51a4fa0 100644 --- a/src/scheme/BlockPerfectGas.hpp +++ b/src/scheme/BlockPerfectGas.hpp @@ -5,59 +5,56 @@ struct BlockPerfectGas { -private: + private: CellValue<double>& m_rhoj; CellValue<double>& m_ej; CellValue<double>& m_pj; CellValue<double>& m_gammaj; CellValue<double>& m_cj; -public: + public: BlockPerfectGas(CellValue<double>& rhoj, CellValue<double>& ej, CellValue<double>& pj, CellValue<double>& gammaj, CellValue<double>& cj) - : m_rhoj(rhoj), - m_ej(ej), - m_pj(pj), - m_gammaj(gammaj), - m_cj(cj) + : m_rhoj(rhoj), m_ej(ej), m_pj(pj), m_gammaj(gammaj), m_cj(cj) { ; } - void updatePandCFromRhoE() + void + updatePandCFromRhoE() { - const size_t nj = m_ej.size(); - const CellValue<const double>& rho = m_rhoj; - const CellValue<const double>& e = m_ej; + const size_t nj = m_ej.size(); + const CellValue<const double>& rho = m_rhoj; + const CellValue<const double>& e = m_ej; const CellValue<const double>& gamma = m_gammaj; - parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ - const double gamma_minus_one = gamma[j]-1; - m_pj[j] = gamma_minus_one*rho[j]*e[j]; - m_cj[j] = std::sqrt(gamma[j]*gamma_minus_one*e[j]); - }); + parallel_for(nj, PASTIS_LAMBDA(const CellId& j) { + const double gamma_minus_one = gamma[j] - 1; + m_pj[j] = gamma_minus_one * rho[j] * e[j]; + m_cj[j] = std::sqrt(gamma[j] * gamma_minus_one * e[j]); + }); } - void updateEandCFromRhoP() + void + updateEandCFromRhoP() { - const size_t nj = m_ej.size(); - const CellValue<const double>& rho = m_rhoj; - const CellValue<const double>& p = m_pj; + const size_t nj = m_ej.size(); + const CellValue<const double>& rho = m_rhoj; + const CellValue<const double>& p = m_pj; const CellValue<const double>& gamma = m_gammaj; - parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ - m_ej[j] = p[j]/(rho[j]*(gamma[j]-1)); - }); + parallel_for(nj, PASTIS_LAMBDA(const CellId& j) { + m_ej[j] = p[j] / (rho[j] * (gamma[j] - 1)); + }); const CellValue<const double>& e = m_ej; - parallel_for(nj, PASTIS_LAMBDA(const CellId& j){ - m_cj[j] = std::sqrt(gamma[j]*(gamma[j]-1)*e[j]); - }); + parallel_for(nj, PASTIS_LAMBDA(const CellId& j) { + m_cj[j] = std::sqrt(gamma[j] * (gamma[j] - 1) * e[j]); + }); } }; - -#endif // BLOCK_PERFECTGAS_HPP +#endif // BLOCK_PERFECTGAS_HPP diff --git a/src/scheme/BoundaryCondition.hpp b/src/scheme/BoundaryCondition.hpp index 669f546c1..7e7f325f2 100644 --- a/src/scheme/BoundaryCondition.hpp +++ b/src/scheme/BoundaryCondition.hpp @@ -1,18 +1,19 @@ #ifndef BOUNDARY_CONDITION_HANDLER_HPP #define BOUNDARY_CONDITION_HANDLER_HPP -#include <vector> #include <memory> +#include <vector> #include <Array.hpp> -#include <RefItemList.hpp> #include <MeshNodeBoundary.hpp> +#include <RefItemList.hpp> class BoundaryCondition { -public: - enum Type { + public: + enum Type + { velocity, normal_velocity, pressure, @@ -20,16 +21,16 @@ public: }; const Type m_type; -protected: - BoundaryCondition(const Type& type) - : m_type(type) + protected: + BoundaryCondition(const Type& type) : m_type(type) { ; } -public: - const Type& type() const + public: + const Type& + type() const { return m_type; } @@ -37,27 +38,29 @@ public: virtual ~BoundaryCondition() = default; }; -class PressureBoundaryCondition - : public BoundaryCondition +class PressureBoundaryCondition : public BoundaryCondition { -private: + private: const double m_value; const size_t m_number_of_faces; Array<const unsigned int> m_face_list; -public: - double value() const + public: + double + value() const { return m_value; } - const size_t& numberOfFaces() const + const size_t& + numberOfFaces() const { return m_number_of_faces; } - const Array<const unsigned int>& faceList() const + const Array<const unsigned int>& + faceList() const { return m_face_list; } @@ -69,9 +72,8 @@ public: m_number_of_faces(faces.size()) { Array<unsigned int> face_list(faces.size()); - parallel_for(m_number_of_faces, PASTIS_LAMBDA(const int& f){ - face_list[f]=faces[f]; - }); + parallel_for(m_number_of_faces, + PASTIS_LAMBDA(const int& f) { face_list[f] = faces[f]; }); m_face_list = face_list; } @@ -79,32 +81,35 @@ public: }; template <size_t dimension> -class SymmetryBoundaryCondition - : public BoundaryCondition +class SymmetryBoundaryCondition : public BoundaryCondition { -public: + public: using Rd = TinyVector<dimension, double>; -private: - + private: const MeshFlatNodeBoundary<dimension> m_mesh_flat_node_boundary; -public: - const Rd& outgoingNormal() const + + public: + const Rd& + outgoingNormal() const { return m_mesh_flat_node_boundary.outgoingNormal(); } - size_t numberOfNodes() const + size_t + numberOfNodes() const { return m_mesh_flat_node_boundary.nodeList().size(); } - const Array<const NodeId>& nodeList() const + const Array<const NodeId>& + nodeList() const { return m_mesh_flat_node_boundary.nodeList(); } - SymmetryBoundaryCondition(const MeshFlatNodeBoundary<dimension>& mesh_flat_node_boundary) + SymmetryBoundaryCondition( + const MeshFlatNodeBoundary<dimension>& mesh_flat_node_boundary) : BoundaryCondition(BoundaryCondition::symmetry), m_mesh_flat_node_boundary(mesh_flat_node_boundary) { @@ -116,11 +121,12 @@ public: class BoundaryConditionHandler { -private: + private: std::shared_ptr<BoundaryCondition> m_boundary_condition; -public: - const BoundaryCondition& boundaryCondition() const + public: + const BoundaryCondition& + boundaryCondition() const { return *m_boundary_condition; } @@ -135,12 +141,12 @@ public: BoundaryConditionHandler(BoundaryConditionHandler&&) = default; PASTIS_INLINE - BoundaryConditionHandler(std::shared_ptr<BoundaryCondition> boundary_condition) + BoundaryConditionHandler( + std::shared_ptr<BoundaryCondition> boundary_condition) : m_boundary_condition(boundary_condition) - { - } + {} ~BoundaryConditionHandler() = default; }; -#endif // BOUNDARY_CONDITION_HANDLER_HPP +#endif // BOUNDARY_CONDITION_HANDLER_HPP diff --git a/src/scheme/BoundaryConditionDescriptor.hpp b/src/scheme/BoundaryConditionDescriptor.hpp index b84eb2efa..97b57dbdf 100644 --- a/src/scheme/BoundaryConditionDescriptor.hpp +++ b/src/scheme/BoundaryConditionDescriptor.hpp @@ -17,88 +17,90 @@ class BoundaryDescriptor virtual std::ostream& _write(std::ostream& os) const = 0; public: - friend std::ostream& operator<<(std::ostream& os, - const BoundaryDescriptor& bd) + friend std::ostream& + operator<<(std::ostream& os, const BoundaryDescriptor& bd) { return bd._write(os); } - virtual bool operator==(const RefId& ref_id) const =0; - friend bool operator==(const RefId& ref_id, const BoundaryDescriptor& bcd) + virtual bool operator==(const RefId& ref_id) const = 0; + friend bool + operator==(const RefId& ref_id, const BoundaryDescriptor& bcd) { return bcd == ref_id; } - virtual Type type() const = 0; + virtual Type type() const = 0; BoundaryDescriptor(const BoundaryDescriptor&) = default; - BoundaryDescriptor() = default; - virtual ~BoundaryDescriptor() = default; + BoundaryDescriptor() = default; + virtual ~BoundaryDescriptor() = default; }; -class NamedBoundaryDescriptor - : public BoundaryDescriptor +class NamedBoundaryDescriptor : public BoundaryDescriptor { private: std::string m_name; - std::ostream& _write(std::ostream& os) const final + std::ostream& + _write(std::ostream& os) const final { os << '"' << m_name << '"'; return os; } public: - bool operator==(const RefId& ref_id) const final + bool + operator==(const RefId& ref_id) const final { return m_name == ref_id.tagName(); } - Type type() const final + Type + type() const final { return Type::named; } NamedBoundaryDescriptor(const NamedBoundaryDescriptor&) = default; - NamedBoundaryDescriptor(const std::string& name) - : m_name(name) + NamedBoundaryDescriptor(const std::string& name) : m_name(name) { ; } virtual ~NamedBoundaryDescriptor() = default; }; -class NumberedBoundaryDescriptor - : public BoundaryDescriptor +class NumberedBoundaryDescriptor : public BoundaryDescriptor { private: unsigned int m_number; - std::ostream& _write(std::ostream& os) const final + std::ostream& + _write(std::ostream& os) const final { os << '"' << m_number << '"'; return os; } - bool operator==(const RefId& ref_id) const final + bool + operator==(const RefId& ref_id) const final { return m_number == ref_id.tagNumber(); } public: - Type type() const final + Type + type() const final { return Type::numbered; } NumberedBoundaryDescriptor(const NumberedBoundaryDescriptor&) = default; - NumberedBoundaryDescriptor(const unsigned int& number) - : m_number(number) + NumberedBoundaryDescriptor(const unsigned int& number) : m_number(number) { ; } virtual ~NumberedBoundaryDescriptor() = default; }; - class BoundaryConditionDescriptor { public: @@ -106,26 +108,30 @@ class BoundaryConditionDescriptor { symmetry }; + protected: std::shared_ptr<BoundaryDescriptor> m_boundary_descriptor; virtual std::ostream& _write(std::ostream& os) const = 0; public: - friend std::ostream& operator<<(std::ostream& os, const BoundaryConditionDescriptor& bcd) + friend std::ostream& + operator<<(std::ostream& os, const BoundaryConditionDescriptor& bcd) { return bcd._write(os); } virtual Type type() const = 0; - const BoundaryDescriptor& boundaryDescriptor() const + const BoundaryDescriptor& + boundaryDescriptor() const { return *m_boundary_descriptor; } - BoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) - : m_boundary_descriptor(boundary_descriptor) + BoundaryConditionDescriptor( + std::shared_ptr<BoundaryDescriptor> boundary_descriptor) + : m_boundary_descriptor(boundary_descriptor) { ; } @@ -133,30 +139,33 @@ class BoundaryConditionDescriptor virtual ~BoundaryConditionDescriptor() = default; }; - -class SymmetryBoundaryConditionDescriptor - : public BoundaryConditionDescriptor +class SymmetryBoundaryConditionDescriptor : public BoundaryConditionDescriptor { private: - std::ostream& _write(std::ostream& os) const final + std::ostream& + _write(std::ostream& os) const final { os << "symmetry(" << *m_boundary_descriptor << ")"; return os; } + public: - Type type() const final + Type + type() const final { return Type::symmetry; } - SymmetryBoundaryConditionDescriptor(std::shared_ptr<BoundaryDescriptor> boundary_descriptor) - : BoundaryConditionDescriptor(boundary_descriptor) + SymmetryBoundaryConditionDescriptor( + std::shared_ptr<BoundaryDescriptor> boundary_descriptor) + : BoundaryConditionDescriptor(boundary_descriptor) { ; } - SymmetryBoundaryConditionDescriptor(const SymmetryBoundaryConditionDescriptor&) = default; - ~SymmetryBoundaryConditionDescriptor() = default; + SymmetryBoundaryConditionDescriptor( + const SymmetryBoundaryConditionDescriptor&) = default; + ~SymmetryBoundaryConditionDescriptor() = default; }; -#endif // BOUNDARY_CONDITION_DESCRIPTOR_HPP +#endif // BOUNDARY_CONDITION_DESCRIPTOR_HPP diff --git a/src/scheme/FiniteVolumesEulerUnknowns.hpp b/src/scheme/FiniteVolumesEulerUnknowns.hpp index 390e1c91c..6dbe344db 100644 --- a/src/scheme/FiniteVolumesEulerUnknowns.hpp +++ b/src/scheme/FiniteVolumesEulerUnknowns.hpp @@ -1,20 +1,20 @@ #ifndef FINITE_VOLUMES_EULER_UNKNOWNS_HPP #define FINITE_VOLUMES_EULER_UNKNOWNS_HPP -#include <TinyVector.hpp> #include <ItemValue.hpp> +#include <TinyVector.hpp> template <typename TMeshData> class FiniteVolumesEulerUnknowns { -public: + public: using MeshDataType = TMeshData; - using MeshType = typename MeshDataType::MeshType; + using MeshType = typename MeshDataType::MeshType; static constexpr size_t Dimension = MeshType::Dimension; - using Rd = TinyVector<Dimension>; + using Rd = TinyVector<Dimension>; -private: + private: const MeshDataType& m_mesh_data; const MeshType& m_mesh; @@ -29,140 +29,157 @@ private: CellValue<double> m_mj; CellValue<double> m_inv_mj; -public: - CellValue<double>& rhoj() + public: + CellValue<double>& + rhoj() { return m_rhoj; } - const CellValue<const double> rhoj() const + const CellValue<const double> + rhoj() const { return m_rhoj; } - CellValue<Rd>& uj() + CellValue<Rd>& + uj() { return m_uj; } - const CellValue<const Rd> uj() const + const CellValue<const Rd> + uj() const { return m_uj; } - CellValue<double>& Ej() + CellValue<double>& + Ej() { return m_Ej; } - const CellValue<const double> Ej() const + const CellValue<const double> + Ej() const { return m_Ej; } - CellValue<double>& ej() + CellValue<double>& + ej() { return m_ej; } - const CellValue<const double> ej() const + const CellValue<const double> + ej() const { return m_ej; } - CellValue<double>& pj() + CellValue<double>& + pj() { return m_pj; } - const CellValue<const double> pj() const + const CellValue<const double> + pj() const { return m_pj; } - CellValue<double>& gammaj() + CellValue<double>& + gammaj() { return m_gammaj; } - const CellValue<const double> gammaj() const + const CellValue<const double> + gammaj() const { return m_gammaj; } - CellValue<double>& cj() + CellValue<double>& + cj() { return m_cj; } - const CellValue<const double> cj() const + const CellValue<const double> + cj() const { return m_cj; } - CellValue<double>& mj() + CellValue<double>& + mj() { return m_mj; } - const CellValue<const double> mj() const + const CellValue<const double> + mj() const { return m_mj; } - CellValue<double>& invMj() + CellValue<double>& + invMj() { return m_inv_mj; } - const CellValue<const double> invMj() const + const CellValue<const double> + invMj() const { return m_inv_mj; } - void initializeSod() + void + initializeSod() { const CellValue<const Rd>& xj = m_mesh_data.xj(); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - if (xj[j][0]<0.5) { - m_rhoj[j]=1; - } else { - m_rhoj[j]=0.125; - } - }); - - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - if (xj[j][0]<0.5) { - m_pj[j]=1; - } else { - m_pj[j]=0.1; - } - }); - - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - m_uj[j] = zero; - }); - - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - m_gammaj[j] = 1.4; - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + if (xj[j][0] < 0.5) { + m_rhoj[j] = 1; + } else { + m_rhoj[j] = 0.125; + } + }); + + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + if (xj[j][0] < 0.5) { + m_pj[j] = 1; + } else { + m_pj[j] = 0.1; + } + }); + + parallel_for(m_mesh.numberOfCells(), + PASTIS_LAMBDA(const CellId& j) { m_uj[j] = zero; }); + + parallel_for(m_mesh.numberOfCells(), + PASTIS_LAMBDA(const CellId& j) { m_gammaj[j] = 1.4; }); BlockPerfectGas block_eos(m_rhoj, m_ej, m_pj, m_gammaj, m_cj); block_eos.updateEandCFromRhoP(); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - m_Ej[j] = m_ej[j]+0.5*(m_uj[j],m_uj[j]); - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + m_Ej[j] = m_ej[j] + 0.5 * (m_uj[j], m_uj[j]); + }); const CellValue<const double>& Vj = m_mesh_data.Vj(); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - m_mj[j] = m_rhoj[j] * Vj[j]; - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + m_mj[j] = m_rhoj[j] * Vj[j]; + }); - parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j){ - m_inv_mj[j] = 1./m_mj[j]; - }); + parallel_for(m_mesh.numberOfCells(), PASTIS_LAMBDA(const CellId& j) { + m_inv_mj[j] = 1. / m_mj[j]; + }); } FiniteVolumesEulerUnknowns(const MeshDataType& mesh_data) @@ -180,7 +197,6 @@ public: { ; } - }; -#endif // FINITE_VOLUMES_EULER_UNKNOWNS_HPP +#endif // FINITE_VOLUMES_EULER_UNKNOWNS_HPP diff --git a/src/utils/Array.hpp b/src/utils/Array.hpp index a563c6462..e3b631ccf 100644 --- a/src/utils/Array.hpp +++ b/src/utils/Array.hpp @@ -13,7 +13,7 @@ template <typename DataType> class Array { public: - using data_type = DataType; + using data_type = DataType; using index_type = size_t; private: @@ -24,13 +24,14 @@ class Array public: PASTIS_INLINE - size_t size() const noexcept + size_t + size() const noexcept { return m_values.extent(0); } - friend PASTIS_INLINE - Array<std::remove_const_t<DataType>> copy(const Array<DataType>& source) + friend PASTIS_INLINE Array<std::remove_const_t<DataType>> + copy(const Array<DataType>& source) { Array<std::remove_const_t<DataType>> image(source.size()); Kokkos::deep_copy(image.m_values, source.m_values); @@ -38,39 +39,40 @@ class Array return image; } - template <typename DataType2, typename ... RT> - friend PASTIS_INLINE - Array<DataType2> encapsulate(const Kokkos::View<DataType2*, RT...>& values); + template <typename DataType2, typename... RT> + friend PASTIS_INLINE Array<DataType2> encapsulate( + const Kokkos::View<DataType2*, RT...>& values); PASTIS_INLINE DataType& operator[](const index_type& i) const noexcept(NO_ASSERT) { - Assert(i<m_values.extent(0)); + Assert(i < m_values.extent(0)); return m_values[i]; } PASTIS_INLINE - void fill(const DataType& data) const + void + fill(const DataType& data) const { static_assert(not std::is_const<DataType>(), "Cannot modify Array of const"); // could consider to use std::fill - parallel_for(this->size(), PASTIS_LAMBDA(const index_type& i){ - m_values[i] = data; - }); + parallel_for(this->size(), + PASTIS_LAMBDA(const index_type& i) { m_values[i] = data; }); } template <typename DataType2> - PASTIS_INLINE - Array& operator=(const Array<DataType2>& array) noexcept + PASTIS_INLINE Array& + operator=(const Array<DataType2>& array) noexcept { // ensures that DataType is the same as source DataType2 - static_assert(std::is_same<std::remove_const_t<DataType>, std::remove_const_t<DataType2>>(), + static_assert(std::is_same<std::remove_const_t<DataType>, + std::remove_const_t<DataType2>>(), "Cannot assign Array of different type"); // ensures that const is not lost through copy - static_assert(((std::is_const<DataType2>() and std::is_const<DataType>()) - or not std::is_const<DataType2>()), + static_assert(((std::is_const<DataType2>() and std::is_const<DataType>()) or + not std::is_const<DataType2>()), "Cannot assign Array of const to Array of non-const"); m_values = array.m_values; return *this; @@ -83,11 +85,11 @@ class Array Array& operator=(Array&&) = default; PASTIS_INLINE - Array(const size_t& size) - : m_values("anonymous", size) + Array(const size_t& size) : m_values("anonymous", size) { - static_assert(not std::is_const<DataType>(), - "Cannot allocate Array of const data: only view is supported"); + static_assert( + not std::is_const<DataType>(), + "Cannot allocate Array of const data: only view is supported"); } PASTIS_INLINE @@ -110,9 +112,9 @@ class Array ~Array() = default; }; -template <typename DataType, typename ... RT> -PASTIS_INLINE -Array<DataType> encapsulate(const Kokkos::View<DataType*, RT...>& values) +template <typename DataType, typename... RT> +PASTIS_INLINE Array<DataType> +encapsulate(const Kokkos::View<DataType*, RT...>& values) { Array<DataType> array; array.m_values = values; @@ -121,16 +123,15 @@ Array<DataType> encapsulate(const Kokkos::View<DataType*, RT...>& values) // map, multimap, unordered_map and stack cannot be copied this way template <typename Container> -PASTIS_INLINE -Array<std::remove_const_t<typename Container::value_type>> +PASTIS_INLINE Array<std::remove_const_t<typename Container::value_type>> convert_to_array(const Container& given_container) { using DataType = typename Container::value_type; Array<std::remove_const_t<DataType>> array(given_container.size()); - if (given_container.size()>0) { + if (given_container.size() > 0) { std::copy(begin(given_container), end(given_container), &(array[0])); } return array; } -#endif // ARRAY_HPP +#endif // ARRAY_HPP diff --git a/src/utils/ArrayUtils.hpp b/src/utils/ArrayUtils.hpp index 51e423094..30cd1143b 100644 --- a/src/utils/ArrayUtils.hpp +++ b/src/utils/ArrayUtils.hpp @@ -6,18 +6,16 @@ #include <Types.hpp> -template <typename DataType, - template <typename> typename ArrayT> +template <typename DataType, template <typename> typename ArrayT> std::remove_const_t<DataType> min(const ArrayT<DataType>& array) { - using ArrayType = ArrayT<DataType>; - using data_type = std::remove_const_t<typename ArrayType::data_type>; + using ArrayType = ArrayT<DataType>; + using data_type = std::remove_const_t<typename ArrayType::data_type>; using index_type = typename ArrayType::index_type; class ArrayMin { - private: const ArrayType m_array; @@ -31,7 +29,8 @@ min(const ArrayT<DataType>& array) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { if (m_array[i] < data) { data = m_array[i]; @@ -39,8 +38,8 @@ min(const ArrayT<DataType>& array) } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { if (src < dst) { dst = src; @@ -48,14 +47,14 @@ min(const ArrayT<DataType>& array) } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { value = std::numeric_limits<data_type>::max(); } PASTIS_INLINE - ArrayMin(const ArrayType& array) - : m_array(array) + ArrayMin(const ArrayType& array) : m_array(array) { ; } @@ -64,17 +63,15 @@ min(const ArrayT<DataType>& array) ~ArrayMin() = default; }; - return ArrayMin(array); } -template <typename DataType, - template <typename> typename ArrayT> +template <typename DataType, template <typename> typename ArrayT> std::remove_const_t<DataType> max(const ArrayT<DataType>& array) { - using ArrayType = ArrayT<DataType>; - using data_type = std::remove_const_t<typename ArrayType::data_type>; + using ArrayType = ArrayT<DataType>; + using data_type = std::remove_const_t<typename ArrayType::data_type>; using index_type = typename ArrayType::index_type; class ArrayMax @@ -92,7 +89,8 @@ max(const ArrayT<DataType>& array) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { if (m_array[i] > data) { data = m_array[i]; @@ -100,8 +98,8 @@ max(const ArrayT<DataType>& array) } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { if (src > dst) { dst = src; @@ -109,14 +107,14 @@ max(const ArrayT<DataType>& array) } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { value = std::numeric_limits<data_type>::min(); } PASTIS_INLINE - ArrayMax(const ArrayType& array) - : m_array(array) + ArrayMax(const ArrayType& array) : m_array(array) { ; } @@ -128,13 +126,12 @@ max(const ArrayT<DataType>& array) return ArrayMax(array); } -template <typename DataType, - template <typename> typename ArrayT> +template <typename DataType, template <typename> typename ArrayT> std::remove_const_t<DataType> sum(const ArrayT<DataType>& array) { - using ArrayType = ArrayT<DataType>; - using data_type = std::remove_const_t<DataType>; + using ArrayType = ArrayT<DataType>; + using data_type = std::remove_const_t<DataType>; using index_type = typename ArrayType::index_type; class ArraySum @@ -152,20 +149,22 @@ sum(const ArrayT<DataType>& array) } PASTIS_INLINE - void operator()(const index_type& i, data_type& data) const + void + operator()(const index_type& i, data_type& data) const { data += m_array[i]; } PASTIS_INLINE - void join(volatile data_type& dst, - const volatile data_type& src) const + void + join(volatile data_type& dst, const volatile data_type& src) const { dst += src; } PASTIS_INLINE - void init(data_type& value) const + void + init(data_type& value) const { if constexpr (std::is_arithmetic_v<data_type>) { value = 0; @@ -175,8 +174,7 @@ sum(const ArrayT<DataType>& array) } PASTIS_INLINE - ArraySum(const ArrayType& array) - : m_array(array) + ArraySum(const ArrayType& array) : m_array(array) { ; } @@ -188,23 +186,27 @@ sum(const ArrayT<DataType>& array) return ArraySum(array); } -template <template <typename ...SourceT> typename SourceArray, - template <typename ...ImageT> typename ImageArray, - typename ...SourceT, typename ...ImageT> -void value_copy(const SourceArray<SourceT...>& source_array, - ImageArray<ImageT...>& image_array) +template <template <typename... SourceT> typename SourceArray, + template <typename... ImageT> + typename ImageArray, + typename... SourceT, + typename... ImageT> +void +value_copy(const SourceArray<SourceT...>& source_array, + ImageArray<ImageT...>& image_array) { using SourceDataType = typename SourceArray<SourceT...>::data_type; - using ImageDataType = typename ImageArray<ImageT...>::data_type; + using ImageDataType = typename ImageArray<ImageT...>::data_type; - static_assert(std::is_same_v<std::remove_const_t<SourceDataType>,ImageDataType>); + static_assert( + std::is_same_v<std::remove_const_t<SourceDataType>, ImageDataType>); static_assert(not std::is_const_v<ImageDataType>); Assert(source_array.size() == image_array.size()); parallel_for(source_array.size(), PASTIS_LAMBDA(const size_t& i) { - image_array[i] = source_array[i]; - }); + image_array[i] = source_array[i]; + }); } -#endif //ARRAY_UTILS_HPP +#endif // ARRAY_UTILS_HPP diff --git a/src/utils/BacktraceManager.cpp b/src/utils/BacktraceManager.cpp index dd65bb907..4de2a3f7c 100644 --- a/src/utils/BacktraceManager.cpp +++ b/src/utils/BacktraceManager.cpp @@ -3,56 +3,58 @@ #include <iomanip> #include <rang.hpp> -#include <execinfo.h> +#include <cmath> #include <cxxabi.h> +#include <execinfo.h> #include <regex> -#include <cmath> -BacktraceManager:: -BacktraceManager() +BacktraceManager::BacktraceManager() { const int size = 100; - void *buffer[size]; + void* buffer[size]; - int ret = ::backtrace(buffer, size); - char **ptr = backtrace_symbols(buffer, ret); + int ret = ::backtrace(buffer, size); + char** ptr = backtrace_symbols(buffer, ret); - for (int i=2; i<ret; ++i) { + for (int i = 2; i < ret; ++i) { m_lines.push_back(ptr[i]); } free(ptr); } -std::ostream& operator<<(std::ostream& os, - const BacktraceManager& btm) +std::ostream& +operator<<(std::ostream& os, const BacktraceManager& btm) { const std::vector<std::string>& lines = btm.m_lines; const std::regex mangled_function(R"%(\(.*\+)%"); - const int width=std::log10(lines.size())+1; + const int width = std::log10(lines.size()) + 1; - for (size_t i_line=0; i_line<lines.size(); ++i_line) { + for (size_t i_line = 0; i_line < lines.size(); ++i_line) { const auto& line = lines[i_line]; - os << rang::fg::green << "[" << std::setw(width) << i_line+1 << '/' << lines.size() << "] " << rang::fg::reset; + os << rang::fg::green << "[" << std::setw(width) << i_line + 1 << '/' + << lines.size() << "] " << rang::fg::reset; std::smatch matchex; int status = -1; - if (std::regex_search(line, matchex, mangled_function)) { + if (std::regex_search(line, matchex, mangled_function)) { std::string prefix = matchex.prefix().str(); - std::string function = line.substr(matchex.position()+1,matchex.length()-2); + std::string function = + line.substr(matchex.position() + 1, matchex.length() - 2); std::string suffix = matchex.suffix().str(); os << prefix << '('; if (function.size() > 0) { - char* demangled = abi::__cxa_demangle(function.c_str(), NULL, NULL, &status); - if (status==0) { + char* demangled = + abi::__cxa_demangle(function.c_str(), NULL, NULL, &status); + if (status == 0) { os << rang::style::bold << demangled << rang::style::reset; free(demangled); } else { os << rang::style::bold << function << rang::style::reset; } } - os<< '+' << suffix << '\n'; + os << '+' << suffix << '\n'; } else { os << line << '\n'; } diff --git a/src/utils/BacktraceManager.hpp b/src/utils/BacktraceManager.hpp index cb2fdc9f9..9b4162ac5 100644 --- a/src/utils/BacktraceManager.hpp +++ b/src/utils/BacktraceManager.hpp @@ -1,21 +1,22 @@ #ifndef BACKTRACE_MANAGER_HPP #define BACKTRACE_MANAGER_HPP -#include <vector> #include <string> +#include <vector> class BacktraceManager { -private: + private: std::vector<std::string> m_lines; -public: + public: BacktraceManager(); - friend std::ostream& operator<<(std::ostream& os, const BacktraceManager& btm); + friend std::ostream& operator<<(std::ostream& os, + const BacktraceManager& btm); BacktraceManager(const BacktraceManager&) = default; - ~BacktraceManager() = default; + ~BacktraceManager() = default; }; -#endif // BACKTRACE_MANAGER_HPP +#endif // BACKTRACE_MANAGER_HPP diff --git a/src/utils/BuildInfo.cpp b/src/utils/BuildInfo.cpp index 4df473bd2..d8db0d43e 100644 --- a/src/utils/BuildInfo.cpp +++ b/src/utils/BuildInfo.cpp @@ -1,42 +1,45 @@ #include <BuildInfo.hpp> -#include <pastis_config.hpp> #include <pastis_build_info.hpp> +#include <pastis_config.hpp> #include <sstream> #ifdef PASTIS_HAS_MPI #include <mpi.h> -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI -std::string BuildInfo::type() +std::string +BuildInfo::type() { return PASTIS_BUILD_TYPE; } -std::string BuildInfo::compiler() +std::string +BuildInfo::compiler() { std::stringstream compiler_info; - compiler_info << PASTIS_BUILD_COMPILER - << " (" << PASTIS_BUILD_COMPILER_VERSION - << ")" << std::ends; + compiler_info << PASTIS_BUILD_COMPILER << " (" + << PASTIS_BUILD_COMPILER_VERSION << ")" << std::ends; return compiler_info.str(); } -std::string BuildInfo::kokkosDevices() +std::string +BuildInfo::kokkosDevices() { return PASTIS_BUILD_KOKKOS_DEVICES; } -std::string BuildInfo::mpiLibrary() +std::string +BuildInfo::mpiLibrary() { #ifdef PASTIS_HAS_MPI - return [](){ - int length; - char mpi_version[MPI_MAX_LIBRARY_VERSION_STRING]; - MPI_Get_library_version(mpi_version, &length); - return std::string(mpi_version); - }(); + return []() { + int length; + char mpi_version[MPI_MAX_LIBRARY_VERSION_STRING]; + MPI_Get_library_version(mpi_version, &length); + return std::string(mpi_version); + }(); #else return "none"; -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } diff --git a/src/utils/BuildInfo.hpp b/src/utils/BuildInfo.hpp index 86bcd1d26..81d2b4960 100644 --- a/src/utils/BuildInfo.hpp +++ b/src/utils/BuildInfo.hpp @@ -11,4 +11,4 @@ struct BuildInfo static std::string mpiLibrary(); }; -#endif // BUILD_INFO_HPP +#endif // BUILD_INFO_HPP diff --git a/src/utils/CSRGraph.hpp b/src/utils/CSRGraph.hpp index 2ae461eb0..2ef9aafc0 100644 --- a/src/utils/CSRGraph.hpp +++ b/src/utils/CSRGraph.hpp @@ -10,18 +10,21 @@ class CSRGraph Array<int> m_neighbors; public: - size_t numberOfNodes() const + size_t + numberOfNodes() const { - Assert(m_entries.size()>0); - return m_entries.size()-1; + Assert(m_entries.size() > 0); + return m_entries.size() - 1; } - const Array<int>& entries() const + const Array<int>& + entries() const { return m_entries; } - const Array<int>& neighbors() const + const Array<int>& + neighbors() const { return m_neighbors; } @@ -29,18 +32,16 @@ class CSRGraph CSRGraph& operator=(CSRGraph&&) = default; CSRGraph& operator=(const CSRGraph&) = default; - CSRGraph(Array<int> entries, - Array<int> neighbors) - : m_entries(entries), - m_neighbors(neighbors) + CSRGraph(Array<int> entries, Array<int> neighbors) + : m_entries(entries), m_neighbors(neighbors) { - Assert(m_entries.size()>0); + Assert(m_entries.size() > 0); } - CSRGraph() = default; - CSRGraph(CSRGraph&&) = default; + CSRGraph() = default; + CSRGraph(CSRGraph&&) = default; CSRGraph(const CSRGraph&) = default; - ~CSRGraph() = default; + ~CSRGraph() = default; }; -#endif // CSR_GRAPH_HPP +#endif // CSR_GRAPH_HPP diff --git a/src/utils/CastArray.hpp b/src/utils/CastArray.hpp index e6288b686..5f22611a7 100644 --- a/src/utils/CastArray.hpp +++ b/src/utils/CastArray.hpp @@ -4,12 +4,12 @@ #include <Array.hpp> #include <PastisTraits.hpp> -template <typename DataType, - typename CastDataType> +template <typename DataType, typename CastDataType> class CastArray { public: using data_type = CastDataType; + private: const Array<DataType> m_array; const size_t m_size; @@ -17,7 +17,8 @@ class CastArray public: PASTIS_INLINE - const size_t& size() const + const size_t& + size() const { return m_size; } @@ -25,7 +26,7 @@ class CastArray PASTIS_INLINE CastDataType& operator[](const size_t& i) const { - Assert(i<m_size); + Assert(i < m_size); return m_values[i]; } @@ -36,23 +37,25 @@ class CastArray CastArray& operator=(CastArray&&) = default; PASTIS_INLINE - CastArray() - : m_size(0), - m_values(nullptr) + CastArray() : m_size(0), m_values(nullptr) { ; } PASTIS_INLINE CastArray(const Array<DataType>& array) - : m_array (array), - m_size (sizeof(DataType)*array.size()/sizeof(CastDataType)), - m_values((array.size() == 0) ? nullptr : reinterpret_cast<CastDataType*>(&(array[0]))) + : m_array(array), + m_size(sizeof(DataType) * array.size() / sizeof(CastDataType)), + m_values((array.size() == 0) + ? nullptr + : reinterpret_cast<CastDataType*>(&(array[0]))) { - static_assert((std::is_const_v<CastDataType> and std::is_const_v<DataType>) or - (not std::is_const_v<DataType>), "CastArray cannot remove const attribute"); + static_assert( + (std::is_const_v<CastDataType> and std::is_const_v<DataType>) or + (not std::is_const_v<DataType>), + "CastArray cannot remove const attribute"); - if (sizeof(DataType)*array.size() % sizeof(CastDataType)) { + if (sizeof(DataType) * array.size() % sizeof(CastDataType)) { std::cerr << "cannot cast array to the chosen data type\n"; std::exit(1); } @@ -60,12 +63,16 @@ class CastArray PASTIS_INLINE CastArray(DataType& value) - : m_size (sizeof(DataType)/sizeof(CastDataType)), - m_values(reinterpret_cast<CastDataType*>(&(value))) + : m_size(sizeof(DataType) / sizeof(CastDataType)), + m_values(reinterpret_cast<CastDataType*>(&(value))) { - static_assert((std::is_const_v<CastDataType> and std::is_const_v<DataType>) or - (not std::is_const_v<DataType>), "CastArray cannot remove const attribute"); - static_assert(is_trivially_castable<DataType>, "Defining CastArray from non trivially castable type is not allowed"); + static_assert( + (std::is_const_v<CastDataType> and std::is_const_v<DataType>) or + (not std::is_const_v<DataType>), + "CastArray cannot remove const attribute"); + static_assert( + is_trivially_castable<DataType>, + "Defining CastArray from non trivially castable type is not allowed"); } PASTIS_INLINE @@ -85,8 +92,7 @@ template <typename CastDataType> struct cast_array_to { template <typename DataType> - PASTIS_INLINE - static CastArray<DataType, CastDataType> + PASTIS_INLINE static CastArray<DataType, CastDataType> from(const Array<DataType>& array) { return CastArray<DataType, CastDataType>(array); @@ -97,12 +103,11 @@ template <typename CastDataType> struct cast_value_to { template <typename DataType> - PASTIS_INLINE - static CastArray<DataType, CastDataType> + PASTIS_INLINE static CastArray<DataType, CastDataType> from(DataType& value) { return CastArray<DataType, CastDataType>(value); } }; -#endif // CAST_ARRAY_HPP +#endif // CAST_ARRAY_HPP diff --git a/src/utils/ConsoleManager.cpp b/src/utils/ConsoleManager.cpp index cb1052d8e..92de4e8ef 100644 --- a/src/utils/ConsoleManager.cpp +++ b/src/utils/ConsoleManager.cpp @@ -3,39 +3,30 @@ #include <rang.hpp> -bool ConsoleManager::isTerminal(std::ostream& os) +bool +ConsoleManager::isTerminal(std::ostream& os) { return rang::rang_implementation::isTerminal(os.rdbuf()); } -void ConsoleManager::init(const std::string& colorize) +void +ConsoleManager::init(const std::string& colorize) { pout() << "Console management: color "; if (colorize == "auto") { if (isTerminal(pout())) { - pout() << rang::style::bold - << rang::fgB::green - << "enabled" - << rang::fg::reset - << rang::style::reset; + pout() << rang::style::bold << rang::fgB::green << "enabled" + << rang::fg::reset << rang::style::reset; } else { pout() << "disabled"; } pout() << " [auto]\n"; } else if (colorize == "yes") { rang::setControlMode(rang::control::Force); - pout() << rang::style::bold - << rang::fgB::green - << "enabled" - << rang::fg::reset - << rang::style::reset; - pout() << " [" - << rang::style::bold - << rang::fgB::red - << "forced" - << rang::fg::reset - << rang::style::reset - << "]\n"; + pout() << rang::style::bold << rang::fgB::green << "enabled" + << rang::fg::reset << rang::style::reset; + pout() << " [" << rang::style::bold << rang::fgB::red << "forced" + << rang::fg::reset << rang::style::reset << "]\n"; } else if (colorize == "no") { rang::setControlMode(rang::control::Off); pout() << "disabled [forced]\n"; diff --git a/src/utils/ConsoleManager.hpp b/src/utils/ConsoleManager.hpp index ccd555e50..61695670c 100644 --- a/src/utils/ConsoleManager.hpp +++ b/src/utils/ConsoleManager.hpp @@ -9,4 +9,4 @@ struct ConsoleManager static void init(const std::string& colorize); }; -#endif // CONSOLE_MANAGER_HPP +#endif // CONSOLE_MANAGER_HPP diff --git a/src/utils/FPEManager.cpp b/src/utils/FPEManager.cpp index d85226713..72a275f80 100644 --- a/src/utils/FPEManager.cpp +++ b/src/utils/FPEManager.cpp @@ -8,7 +8,7 @@ #ifdef PASTIS_HAS_FENV_H #include <fenv.h> -#define MANAGED_FPE (FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW) +#define MANAGED_FPE (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW) #ifdef SYSTEM_IS_DARWIN // MacOS-X requires definition of feenableexcept and fedisableexcept @@ -16,7 +16,8 @@ // Public domain polyfill for feenableexcept on OS X // http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c PASTIS_INLINE -int feenableexcept(unsigned int excepts) +int +feenableexcept(unsigned int excepts) { static fenv_t fenv; unsigned int new_excepts = excepts & FE_ALL_EXCEPT; @@ -30,13 +31,14 @@ int feenableexcept(unsigned int excepts) // unmask fenv.__control &= ~new_excepts; - fenv.__mxcsr &= ~(new_excepts << 7); + fenv.__mxcsr &= ~(new_excepts << 7); return fesetenv(&fenv) ? -1 : old_excepts; } PASTIS_INLINE -int fedisableexcept(unsigned int excepts) +int +fedisableexcept(unsigned int excepts) { static fenv_t fenv; unsigned int new_excepts = excepts & FE_ALL_EXCEPT; @@ -50,57 +52,49 @@ int fedisableexcept(unsigned int excepts) // mask fenv.__control |= new_excepts; - fenv.__mxcsr |= new_excepts << 7; + fenv.__mxcsr |= new_excepts << 7; return fesetenv(&fenv) ? -1 : old_excepts; } -#endif // SYSTEM_IS_DARWIN +#endif // SYSTEM_IS_DARWIN -void FPEManager::enable() +void +FPEManager::enable() { - pout() << "FE management: " - << rang::style::bold - << rang::fgB::green - << "enabled" - << rang::fg::reset - << rang::style::reset << '\n'; + pout() << "FE management: " << rang::style::bold << rang::fgB::green + << "enabled" << rang::fg::reset << rang::style::reset << '\n'; ::feenableexcept(MANAGED_FPE); } -void FPEManager::disable() +void +FPEManager::disable() { - pout() << "FE management: " - << rang::style::bold - << rang::fgB::red - << "disabled" - << rang::fg::reset - << rang::style::reset << '\n'; + pout() << "FE management: " << rang::style::bold << rang::fgB::red + << "disabled" << rang::fg::reset << rang::style::reset << '\n'; ::fedisableexcept(MANAGED_FPE); } -#else // PASTIS_HAS_FENV_H +#else // PASTIS_HAS_FENV_H -void FPEManager::enable() +void +FPEManager::enable() { - pout() << "FE management: enabled " - << rang::fg::red - << "[not supported]" - << rang::fg::reset << '\n'; + pout() << "FE management: enabled " << rang::fg::red << "[not supported]" + << rang::fg::reset << '\n'; } -void FPEManager::disable() +void +FPEManager::disable() { - pout() << "FE management: disable " - << rang::fg::red - << "[not supported]" - << rang::fg::reset << '\n'; + pout() << "FE management: disable " << rang::fg::red << "[not supported]" + << rang::fg::reset << '\n'; } -#endif // PASTIS_HAS_FENV_H +#endif // PASTIS_HAS_FENV_H - -void FPEManager::init(const bool& enable) +void +FPEManager::init(const bool& enable) { if (enable) { FPEManager::enable(); diff --git a/src/utils/FPEManager.hpp b/src/utils/FPEManager.hpp index 0a1ca447f..f90a477ed 100644 --- a/src/utils/FPEManager.hpp +++ b/src/utils/FPEManager.hpp @@ -8,4 +8,4 @@ struct FPEManager static void init(const bool& enable); }; -#endif // FPEMANAGER_HPP +#endif // FPEMANAGER_HPP diff --git a/src/utils/Messenger.cpp b/src/utils/Messenger.cpp index 6dc4056ef..8562c9453 100644 --- a/src/utils/Messenger.cpp +++ b/src/utils/Messenger.cpp @@ -1,12 +1,12 @@ #include <Messenger.hpp> #include <PastisOStream.hpp> -namespace parallel -{ +namespace parallel { Messenger* Messenger::m_instance = nullptr; -void Messenger::create(int& argc, char* argv[]) +void +Messenger::create(int& argc, char* argv[]) { if (Messenger::m_instance == nullptr) { Messenger::m_instance = new Messenger(argc, argv); @@ -16,7 +16,8 @@ void Messenger::create(int& argc, char* argv[]) } } -void Messenger::destroy() +void +Messenger::destroy() { // One allows multiple destruction to handle unexpected code exit if (Messenger::m_instance != nullptr) { @@ -25,24 +26,22 @@ void Messenger::destroy() } } -Messenger:: -Messenger([[maybe_unused]] int& argc, - [[maybe_unused]] char* argv[]) +Messenger::Messenger([[maybe_unused]] int& argc, [[maybe_unused]] char* argv[]) { #ifdef PASTIS_HAS_MPI MPI_Init(&argc, &argv); - m_rank = [] () { - int rank; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - return rank; - } (); + m_rank = []() { + int rank; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + return rank; + }(); - m_size = [] () { - int size=0; - MPI_Comm_size(MPI_COMM_WORLD, &size); - return size; - } (); + m_size = []() { + int size = 0; + MPI_Comm_size(MPI_COMM_WORLD, &size); + return size; + }(); if (m_rank != 0) { // LCOV_EXCL_START @@ -50,22 +49,22 @@ Messenger([[maybe_unused]] int& argc, perr.setOutput(null_stream); // LCOV_EXCL_STOP } -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } -Messenger:: -~Messenger() +Messenger::~Messenger() { #ifdef PASTIS_HAS_MPI MPI_Finalize(); -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } -void Messenger::barrier() const +void +Messenger::barrier() const { #ifdef PASTIS_HAS_MPI MPI_Barrier(MPI_COMM_WORLD); -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } -} // namespace parallel +} // namespace parallel diff --git a/src/utils/Messenger.hpp b/src/utils/Messenger.hpp index 4a54994a2..f188d6837 100644 --- a/src/utils/Messenger.hpp +++ b/src/utils/Messenger.hpp @@ -1,13 +1,13 @@ #ifndef MESSENGER_HPP #define MESSENGER_HPP -#include <PastisMacros.hpp> #include <PastisAssert.hpp> +#include <PastisMacros.hpp> #include <PastisOStream.hpp> #include <Array.hpp> -#include <CastArray.hpp> #include <ArrayUtils.hpp> +#include <CastArray.hpp> #include <type_traits> #include <vector> @@ -15,12 +15,11 @@ #include <pastis_config.hpp> #ifdef PASTIS_HAS_MPI #include <mpi.h> -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI #include <PastisTraits.hpp> -namespace parallel -{ +namespace parallel { class Messenger { @@ -28,9 +27,9 @@ class Messenger struct helper { #ifdef PASTIS_HAS_MPI - template<typename DataType> - static PASTIS_INLINE - MPI_Datatype mpiType() + template <typename DataType> + static PASTIS_INLINE MPI_Datatype + mpiType() { if constexpr (std::is_const_v<DataType>) { return mpiType<std::remove_const_t<DataType>>(); @@ -42,39 +41,46 @@ class Messenger return MPI_Datatype(); } } -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI private: - template <typename T, - typename Allowed = void> - struct split_cast {}; + template <typename T, typename Allowed = void> + struct split_cast + {}; template <typename T> - struct split_cast<T,std::enable_if_t<not(sizeof(T) % sizeof(int64_t))>> { + struct split_cast<T, std::enable_if_t<not(sizeof(T) % sizeof(int64_t))>> + { using type = int64_t; static_assert(not(sizeof(T) % sizeof(int64_t))); }; template <typename T> - struct split_cast<T,std::enable_if_t<not(sizeof(T) % sizeof(int32_t)) - and(sizeof(T) % sizeof(int64_t))>> { + struct split_cast<T, + std::enable_if_t<not(sizeof(T) % sizeof(int32_t)) and + (sizeof(T) % sizeof(int64_t))>> + { using type = int32_t; static_assert(not(sizeof(T) % sizeof(int32_t))); }; template <typename T> - struct split_cast<T,std::enable_if_t<not(sizeof(T) % sizeof(int16_t)) - and(sizeof(T) % sizeof(int32_t)) - and(sizeof(T) % sizeof(int64_t))>> { + struct split_cast<T, + std::enable_if_t<not(sizeof(T) % sizeof(int16_t)) and + (sizeof(T) % sizeof(int32_t)) and + (sizeof(T) % sizeof(int64_t))>> + { using type = int16_t; static_assert(not(sizeof(T) % sizeof(int16_t))); }; template <typename T> - struct split_cast<T,std::enable_if_t<not(sizeof(T) % sizeof(int8_t)) - and(sizeof(T) % sizeof(int16_t)) - and(sizeof(T) % sizeof(int32_t)) - and(sizeof(T) % sizeof(int64_t))>> { + struct split_cast< + T, + std::enable_if_t< + not(sizeof(T) % sizeof(int8_t)) and (sizeof(T) % sizeof(int16_t)) and + (sizeof(T) % sizeof(int32_t)) and (sizeof(T) % sizeof(int64_t))>> + { using type = int8_t; static_assert(not(sizeof(T) % sizeof(int8_t))); }; @@ -91,151 +97,160 @@ class Messenger size_t m_size{1}; template <typename DataType> - void _allGather(const DataType& data, - Array<DataType> gather) const + void + _allGather(const DataType& data, Array<DataType> gather) const { static_assert(std::is_arithmetic_v<DataType>); - Assert(gather.size() == m_size); // LCOV_EXCL_LINE + Assert(gather.size() == m_size); // LCOV_EXCL_LINE #ifdef PASTIS_HAS_MPI - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); - MPI_Allgather(&data, 1, mpi_datatype, - &(gather[0]), 1, mpi_datatype, + MPI_Allgather(&data, 1, mpi_datatype, &(gather[0]), 1, mpi_datatype, MPI_COMM_WORLD); -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI gather[0] = data; -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } - - - template <template <typename ...SendT> typename SendArrayType, - template <typename ...RecvT> typename RecvArrayType, - typename ...SendT, typename ...RecvT> - void _allGather(const SendArrayType<SendT...>& data_array, - RecvArrayType<RecvT...> gather_array) const + template <template <typename... SendT> typename SendArrayType, + template <typename... RecvT> + typename RecvArrayType, + typename... SendT, + typename... RecvT> + void + _allGather(const SendArrayType<SendT...>& data_array, + RecvArrayType<RecvT...> gather_array) const { - Assert(gather_array.size() == data_array.size()*m_size); // LCOV_EXCL_LINE + Assert(gather_array.size() == + data_array.size() * m_size); // LCOV_EXCL_LINE using SendDataType = typename SendArrayType<SendT...>::data_type; using RecvDataType = typename RecvArrayType<RecvT...>::data_type; - static_assert(std::is_same_v<std::remove_const_t<SendDataType>,RecvDataType>); + static_assert( + std::is_same_v<std::remove_const_t<SendDataType>, RecvDataType>); static_assert(std::is_arithmetic_v<SendDataType>); #ifdef PASTIS_HAS_MPI - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<RecvDataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<RecvDataType>(); - MPI_Allgather(&(data_array[0]), data_array.size(), mpi_datatype, - &(gather_array[0]), data_array.size(), mpi_datatype, + MPI_Allgather(&(data_array[0]), data_array.size(), mpi_datatype, + &(gather_array[0]), data_array.size(), mpi_datatype, MPI_COMM_WORLD); -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI value_copy(data_array, gather_array); -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } template <typename DataType> - void _broadcast_value([[maybe_unused]] DataType& data, - [[maybe_unused]] const size_t& root_rank) const + void + _broadcast_value([[maybe_unused]] DataType& data, + [[maybe_unused]] const size_t& root_rank) const { static_assert(not std::is_const_v<DataType>); static_assert(std::is_arithmetic_v<DataType>); #ifdef PASTIS_HAS_MPI - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); - MPI_Bcast(&data, 1, mpi_datatype, root_rank, MPI_COMM_WORLD); -#endif // PASTIS_HAS_MPI + MPI_Bcast(&data, 1, mpi_datatype, root_rank, MPI_COMM_WORLD); +#endif // PASTIS_HAS_MPI } template <typename ArrayType> - void _broadcast_array([[maybe_unused]] ArrayType& array, - [[maybe_unused]] const size_t& root_rank) const + void + _broadcast_array([[maybe_unused]] ArrayType& array, + [[maybe_unused]] const size_t& root_rank) const { using DataType = typename ArrayType::data_type; static_assert(not std::is_const_v<DataType>); static_assert(std::is_arithmetic_v<DataType>); #ifdef PASTIS_HAS_MPI - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); - MPI_Bcast(&(array[0]), array.size(), mpi_datatype, root_rank, MPI_COMM_WORLD); -#endif // PASTIS_HAS_MPI + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); + MPI_Bcast(&(array[0]), array.size(), mpi_datatype, root_rank, + MPI_COMM_WORLD); +#endif // PASTIS_HAS_MPI } - template <template <typename ...SendT> typename SendArrayType, - template <typename ...RecvT> typename RecvArrayType, - typename ...SendT, typename ...RecvT> - RecvArrayType<RecvT...> _allToAll(const SendArrayType<SendT...>& sent_array, - RecvArrayType<RecvT...>& recv_array) const + template <template <typename... SendT> typename SendArrayType, + template <typename... RecvT> + typename RecvArrayType, + typename... SendT, + typename... RecvT> + RecvArrayType<RecvT...> + _allToAll(const SendArrayType<SendT...>& sent_array, + RecvArrayType<RecvT...>& recv_array) const { #ifdef PASTIS_HAS_MPI using SendDataType = typename SendArrayType<SendT...>::data_type; using RecvDataType = typename RecvArrayType<RecvT...>::data_type; - static_assert(std::is_same_v<std::remove_const_t<SendDataType>,RecvDataType>); + static_assert( + std::is_same_v<std::remove_const_t<SendDataType>, RecvDataType>); static_assert(std::is_arithmetic_v<SendDataType>); - Assert((sent_array.size() % m_size) == 0); // LCOV_EXCL_LINE - Assert(sent_array.size() == recv_array.size()); // LCOV_EXCL_LINE + Assert((sent_array.size() % m_size) == 0); // LCOV_EXCL_LINE + Assert(sent_array.size() == recv_array.size()); // LCOV_EXCL_LINE - const size_t count = sent_array.size()/m_size; + const size_t count = sent_array.size() / m_size; - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<SendDataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<SendDataType>(); - MPI_Alltoall(&(sent_array[0]), count, mpi_datatype, - &(recv_array[0]), count, mpi_datatype, - MPI_COMM_WORLD); -#else // PASTIS_HAS_MPI + MPI_Alltoall(&(sent_array[0]), count, mpi_datatype, &(recv_array[0]), count, + mpi_datatype, MPI_COMM_WORLD); +#else // PASTIS_HAS_MPI value_copy(sent_array, recv_array); -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI return recv_array; } - template <template <typename ...SendT> typename SendArrayType, - template <typename ...RecvT> typename RecvArrayType, - typename ...SendT, typename ...RecvT> - void _exchange(const std::vector<SendArrayType<SendT...>>& sent_array_list, - std::vector<RecvArrayType<RecvT...>>& recv_array_list) const + template <template <typename... SendT> typename SendArrayType, + template <typename... RecvT> + typename RecvArrayType, + typename... SendT, + typename... RecvT> + void + _exchange(const std::vector<SendArrayType<SendT...>>& sent_array_list, + std::vector<RecvArrayType<RecvT...>>& recv_array_list) const { using SendDataType = typename SendArrayType<SendT...>::data_type; using RecvDataType = typename RecvArrayType<RecvT...>::data_type; - static_assert(std::is_same_v<std::remove_const_t<SendDataType>,RecvDataType>); + static_assert( + std::is_same_v<std::remove_const_t<SendDataType>, RecvDataType>); static_assert(std::is_arithmetic_v<SendDataType>); #ifdef PASTIS_HAS_MPI std::vector<MPI_Request> request_list; - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<SendDataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<SendDataType>(); - for (size_t i_send=0; i_send<sent_array_list.size(); ++i_send) { + for (size_t i_send = 0; i_send < sent_array_list.size(); ++i_send) { const auto sent_array = sent_array_list[i_send]; - if (sent_array.size()>0) { + if (sent_array.size() > 0) { MPI_Request request; - MPI_Isend(&(sent_array[0]), sent_array.size(), mpi_datatype, i_send, 0, MPI_COMM_WORLD, &request); + MPI_Isend(&(sent_array[0]), sent_array.size(), mpi_datatype, i_send, 0, + MPI_COMM_WORLD, &request); request_list.push_back(request); } } - for (size_t i_recv=0; i_recv<recv_array_list.size(); ++i_recv) { + for (size_t i_recv = 0; i_recv < recv_array_list.size(); ++i_recv) { auto recv_array = recv_array_list[i_recv]; - if (recv_array.size()>0) { + if (recv_array.size() > 0) { MPI_Request request; - MPI_Irecv(&(recv_array[0]), recv_array.size(), mpi_datatype, i_recv, 0, MPI_COMM_WORLD, &request); + MPI_Irecv(&(recv_array[0]), recv_array.size(), mpi_datatype, i_recv, 0, + MPI_COMM_WORLD, &request); request_list.push_back(request); } } - if (request_list.size()>0) { + if (request_list.size() > 0) { std::vector<MPI_Status> status_list(request_list.size()); - if (MPI_SUCCESS != MPI_Waitall(request_list.size(), &(request_list[0]), &(status_list[0]))) { + if (MPI_SUCCESS != MPI_Waitall(request_list.size(), &(request_list[0]), + &(status_list[0]))) { // LCOV_EXCL_START std::cerr << "Communication error!\n"; std::exit(1); @@ -243,27 +258,29 @@ class Messenger } } -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI Assert(sent_array_list.size() == 1); Assert(recv_array_list.size() == 1); value_copy(sent_array_list[0], recv_array_list[0]); -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } - template <typename DataType, - typename CastDataType> - void _exchange_through_cast(const std::vector<Array<DataType>>& sent_array_list, - std::vector<Array<std::remove_const_t<DataType>>>& recv_array_list) const + template <typename DataType, typename CastDataType> + void + _exchange_through_cast( + const std::vector<Array<DataType>>& sent_array_list, + std::vector<Array<std::remove_const_t<DataType>>>& recv_array_list) const { std::vector<CastArray<DataType, const CastDataType>> sent_cast_array_list; - for (size_t i=0; i<sent_array_list.size(); ++i) { - sent_cast_array_list.emplace_back(cast_array_to<const CastDataType>::from(sent_array_list[i])); + for (size_t i = 0; i < sent_array_list.size(); ++i) { + sent_cast_array_list.emplace_back( + cast_array_to<const CastDataType>::from(sent_array_list[i])); } using MutableDataType = std::remove_const_t<DataType>; std::vector<CastArray<MutableDataType, CastDataType>> recv_cast_array_list; - for (size_t i=0; i<sent_array_list.size(); ++i) { + for (size_t i = 0; i < sent_array_list.size(); ++i) { recv_cast_array_list.emplace_back(recv_array_list[i]); } @@ -275,20 +292,23 @@ class Messenger static void destroy(); PASTIS_INLINE - static Messenger& getInstance() + static Messenger& + getInstance() { - Assert(m_instance != nullptr); // LCOV_EXCL_LINE + Assert(m_instance != nullptr); // LCOV_EXCL_LINE return *m_instance; } PASTIS_INLINE - const size_t& rank() const + const size_t& + rank() const { return m_rank; } PASTIS_INLINE - const size_t& size() const + const size_t& + size() const { return m_size; } @@ -296,87 +316,86 @@ class Messenger void barrier() const; template <typename DataType> - DataType allReduceMin(const DataType& data) const + DataType + allReduceMin(const DataType& data) const { #ifdef PASTIS_HAS_MPI static_assert(not std::is_const_v<DataType>); static_assert(std::is_arithmetic_v<DataType>); - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); DataType min_data = data; MPI_Allreduce(&data, &min_data, 1, mpi_datatype, MPI_MIN, MPI_COMM_WORLD); return min_data; -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI return data; -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } template <typename DataType> - DataType allReduceMax(const DataType& data) const + DataType + allReduceMax(const DataType& data) const { #ifdef PASTIS_HAS_MPI static_assert(not std::is_const_v<DataType>); static_assert(std::is_arithmetic_v<DataType>); - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); DataType max_data = data; MPI_Allreduce(&data, &max_data, 1, mpi_datatype, MPI_MAX, MPI_COMM_WORLD); return max_data; -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI return data; -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } template <typename DataType> - DataType allReduceSum(const DataType& data) const + DataType + allReduceSum(const DataType& data) const { #ifdef PASTIS_HAS_MPI static_assert(not std::is_const_v<DataType>); - if constexpr(std::is_arithmetic_v<DataType>) { - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<DataType>(); + if constexpr (std::is_arithmetic_v<DataType>) { + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<DataType>(); DataType data_sum = data; MPI_Allreduce(&data, &data_sum, 1, mpi_datatype, MPI_SUM, MPI_COMM_WORLD); return data_sum; - } else if (is_trivially_castable<DataType>){ + } else if (is_trivially_castable<DataType>) { using InnerDataType = typename DataType::data_type; - MPI_Datatype mpi_datatype - = Messenger::helper::mpiType<InnerDataType>(); - const int size = sizeof(DataType)/sizeof(InnerDataType); - DataType data_sum = data; - MPI_Allreduce(&data, &data_sum, size, mpi_datatype, MPI_SUM, MPI_COMM_WORLD); + MPI_Datatype mpi_datatype = Messenger::helper::mpiType<InnerDataType>(); + const int size = sizeof(DataType) / sizeof(InnerDataType); + DataType data_sum = data; + MPI_Allreduce(&data, &data_sum, size, mpi_datatype, MPI_SUM, + MPI_COMM_WORLD); return data_sum; } -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI return data; -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI } template <typename DataType> - PASTIS_INLINE - Array<DataType> + PASTIS_INLINE Array<DataType> allGather(const DataType& data) const { static_assert(not std::is_const_v<DataType>); Array<DataType> gather_array(m_size); - if constexpr(std::is_arithmetic_v<DataType>) { + if constexpr (std::is_arithmetic_v<DataType>) { _allGather(data, gather_array); - } else if constexpr(is_trivially_castable<DataType>) { + } else if constexpr (is_trivially_castable<DataType>) { using CastType = helper::split_cast_t<DataType>; - CastArray cast_value_array = cast_value_to<const CastType>::from(data); + CastArray cast_value_array = cast_value_to<const CastType>::from(data); CastArray cast_gather_array = cast_array_to<CastType>::from(gather_array); _allGather(cast_value_array, cast_gather_array); @@ -387,21 +406,21 @@ class Messenger } template <typename DataType> - PASTIS_INLINE - Array<std::remove_const_t<DataType>> + PASTIS_INLINE Array<std::remove_const_t<DataType>> allGather(const Array<DataType>& array) const { using MutableDataType = std::remove_const_t<DataType>; - Array<MutableDataType> gather_array(m_size*array.size()); + Array<MutableDataType> gather_array(m_size * array.size()); - if constexpr(std::is_arithmetic_v<DataType>) { + if constexpr (std::is_arithmetic_v<DataType>) { _allGather(array, gather_array); - } else if constexpr(is_trivially_castable<DataType>) { - using CastType = helper::split_cast_t<DataType>; + } else if constexpr (is_trivially_castable<DataType>) { + using CastType = helper::split_cast_t<DataType>; using MutableCastType = helper::split_cast_t<MutableDataType>; CastArray cast_array = cast_array_to<CastType>::from(array); - CastArray cast_gather_array = cast_array_to<MutableCastType>::from(gather_array); + CastArray cast_gather_array = + cast_array_to<MutableCastType>::from(gather_array); _allGather(cast_array, cast_gather_array); } else { @@ -411,23 +430,22 @@ class Messenger } template <typename SendDataType> - PASTIS_INLINE - Array<std::remove_const_t<SendDataType>> + PASTIS_INLINE Array<std::remove_const_t<SendDataType>> allToAll(const Array<SendDataType>& sent_array) const { #ifndef NDEBUG const size_t min_size = allReduceMin(sent_array.size()); const size_t max_size = allReduceMax(sent_array.size()); - Assert(max_size == min_size); // LCOV_EXCL_LINE -#endif // NDEBUG - Assert((sent_array.size() % m_size) == 0); // LCOV_EXCL_LINE + Assert(max_size == min_size); // LCOV_EXCL_LINE +#endif // NDEBUG + Assert((sent_array.size() % m_size) == 0); // LCOV_EXCL_LINE using DataType = std::remove_const_t<SendDataType>; Array<DataType> recv_array(sent_array.size()); - if constexpr(std::is_arithmetic_v<DataType>) { + if constexpr (std::is_arithmetic_v<DataType>) { _allToAll(sent_array, recv_array); - } else if constexpr(is_trivially_castable<DataType>) { + } else if constexpr (is_trivially_castable<DataType>) { using CastType = helper::split_cast_t<DataType>; auto send_cast_array = cast_array_to<const CastType>::from(sent_array); @@ -440,16 +458,15 @@ class Messenger } template <typename DataType> - PASTIS_INLINE - void broadcast(DataType& data, const size_t& root_rank) const + PASTIS_INLINE void + broadcast(DataType& data, const size_t& root_rank) const { - static_assert(not std::is_const_v<DataType>, - "cannot broadcast const data"); - if constexpr(std::is_arithmetic_v<DataType>) { + static_assert(not std::is_const_v<DataType>, "cannot broadcast const data"); + if constexpr (std::is_arithmetic_v<DataType>) { _broadcast_value(data, root_rank); - } else if constexpr(is_trivially_castable<DataType>) { + } else if constexpr (is_trivially_castable<DataType>) { using CastType = helper::split_cast_t<DataType>; - if constexpr(sizeof(CastType) == sizeof(DataType)) { + if constexpr (sizeof(CastType) == sizeof(DataType)) { CastType& cast_data = reinterpret_cast<CastType&>(data); _broadcast_value(cast_data, root_rank); } else { @@ -462,66 +479,66 @@ class Messenger } template <typename DataType> - PASTIS_INLINE - void broadcast(Array<DataType>& array, - const size_t& root_rank) const + PASTIS_INLINE void + broadcast(Array<DataType>& array, const size_t& root_rank) const { static_assert(not std::is_const_v<DataType>, "cannot broadcast array of const"); - if constexpr(std::is_arithmetic_v<DataType>) { + if constexpr (std::is_arithmetic_v<DataType>) { size_t size = array.size(); _broadcast_value(size, root_rank); if (m_rank != root_rank) { - array = Array<DataType>(size); // LCOV_EXCL_LINE + array = Array<DataType>(size); // LCOV_EXCL_LINE } _broadcast_array(array, root_rank); - } else if constexpr(is_trivially_castable<DataType>) { + } else if constexpr (is_trivially_castable<DataType>) { size_t size = array.size(); _broadcast_value(size, root_rank); if (m_rank != root_rank) { - array = Array<DataType>(size); // LCOV_EXCL_LINE + array = Array<DataType>(size); // LCOV_EXCL_LINE } - using CastType = helper::split_cast_t<DataType>; + using CastType = helper::split_cast_t<DataType>; auto cast_array = cast_array_to<CastType>::from(array); _broadcast_array(cast_array, root_rank); - } else{ + } else { static_assert(is_false_v<DataType>, "unexpected type of data"); } } - template <typename SendDataType, - typename RecvDataType> - PASTIS_INLINE - void exchange(const std::vector<Array<SendDataType>>& send_array_list, - std::vector<Array<RecvDataType>>& recv_array_list) const + template <typename SendDataType, typename RecvDataType> + PASTIS_INLINE void + exchange(const std::vector<Array<SendDataType>>& send_array_list, + std::vector<Array<RecvDataType>>& recv_array_list) const { - static_assert(std::is_same_v<std::remove_const_t<SendDataType>,RecvDataType>, - "send and receive data type do not match"); + static_assert( + std::is_same_v<std::remove_const_t<SendDataType>, RecvDataType>, + "send and receive data type do not match"); static_assert(not std::is_const_v<RecvDataType>, "receive data type cannot be const"); using DataType = std::remove_const_t<SendDataType>; - Assert(send_array_list.size() == m_size); // LCOV_EXCL_LINE - Assert(recv_array_list.size() == m_size); // LCOV_EXCL_LINE + Assert(send_array_list.size() == m_size); // LCOV_EXCL_LINE + Assert(recv_array_list.size() == m_size); // LCOV_EXCL_LINE #ifndef NDEBUG Array<size_t> send_size(m_size); - for (size_t i=0; i<m_size; ++i) { + for (size_t i = 0; i < m_size; ++i) { send_size[i] = send_array_list[i].size(); } Array<size_t> recv_size = allToAll(send_size); - bool correct_sizes = true; - for (size_t i=0; i<m_size; ++i) { + bool correct_sizes = true; + for (size_t i = 0; i < m_size; ++i) { correct_sizes &= (recv_size[i] == recv_array_list[i].size()); } - Assert(correct_sizes); // LCOV_EXCL_LINE -#endif // NDEBUG + Assert(correct_sizes); // LCOV_EXCL_LINE +#endif // NDEBUG - if constexpr(std::is_arithmetic_v<DataType>) { + if constexpr (std::is_arithmetic_v<DataType>) { _exchange(send_array_list, recv_array_list); - } else if constexpr(is_trivially_castable<DataType>) { + } else if constexpr (is_trivially_castable<DataType>) { using CastType = helper::split_cast_t<DataType>; - _exchange_through_cast<SendDataType, CastType>(send_array_list, recv_array_list); + _exchange_through_cast<SendDataType, CastType>(send_array_list, + recv_array_list); } else { static_assert(is_false_v<RecvDataType>, "unexpected type of data"); } @@ -532,154 +549,218 @@ class Messenger }; PASTIS_INLINE -const Messenger& messenger() +const Messenger& +messenger() { return Messenger::getInstance(); } PASTIS_INLINE -const size_t& rank() +const size_t& +rank() { return messenger().rank(); } PASTIS_INLINE -const size_t& size() +const size_t& +size() { return messenger().size(); } PASTIS_INLINE -void barrier() +void +barrier() { return messenger().barrier(); } template <typename DataType> -PASTIS_INLINE -DataType allReduceMax(const DataType& data) +PASTIS_INLINE DataType +allReduceMax(const DataType& data) { return messenger().allReduceMax(data); } template <typename DataType> -PASTIS_INLINE -DataType allReduceMin(const DataType& data) +PASTIS_INLINE DataType +allReduceMin(const DataType& data) { return messenger().allReduceMin(data); } template <typename DataType> -PASTIS_INLINE -DataType allReduceSum(const DataType& data) +PASTIS_INLINE DataType +allReduceSum(const DataType& data) { return messenger().allReduceSum(data); } template <typename DataType> -PASTIS_INLINE -Array<DataType> +PASTIS_INLINE Array<DataType> allGather(const DataType& data) { return messenger().allGather(data); } template <typename DataType> -PASTIS_INLINE -Array<std::remove_const_t<DataType>> +PASTIS_INLINE Array<std::remove_const_t<DataType>> allGather(const Array<DataType>& array) { return messenger().allGather(array); } template <typename DataType> -PASTIS_INLINE -Array<std::remove_const_t<DataType>> +PASTIS_INLINE Array<std::remove_const_t<DataType>> allToAll(const Array<DataType>& array) { return messenger().allToAll(array); } template <typename DataType> -PASTIS_INLINE -void broadcast(DataType& data, const size_t& root_rank) +PASTIS_INLINE void +broadcast(DataType& data, const size_t& root_rank) { messenger().broadcast(data, root_rank); } template <typename DataType> -PASTIS_INLINE -void broadcast(Array<DataType>& array, const size_t& root_rank) +PASTIS_INLINE void +broadcast(Array<DataType>& array, const size_t& root_rank) { messenger().broadcast(array, root_rank); } -template <typename SendDataType, - typename RecvDataType> -PASTIS_INLINE -void exchange(const std::vector<Array<SendDataType>>& sent_array_list, - std::vector<Array<RecvDataType>>& recv_array_list) +template <typename SendDataType, typename RecvDataType> +PASTIS_INLINE void +exchange(const std::vector<Array<SendDataType>>& sent_array_list, + std::vector<Array<RecvDataType>>& recv_array_list) { - static_assert(std::is_same_v<std::remove_const_t<SendDataType>,RecvDataType>, + static_assert(std::is_same_v<std::remove_const_t<SendDataType>, RecvDataType>, "send and receive data type do not match"); static_assert(not std::is_const_v<RecvDataType>, "receive data type cannot be const"); - messenger().exchange(sent_array_list, recv_array_list); + messenger().exchange(sent_array_list, recv_array_list); } #ifdef PASTIS_HAS_MPI -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<char>() {return MPI_CHAR; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<char>() +{ + return MPI_CHAR; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<int8_t>() {return MPI_INT8_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<int8_t>() +{ + return MPI_INT8_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<int16_t>() {return MPI_INT16_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<int16_t>() +{ + return MPI_INT16_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<int32_t>() {return MPI_INT32_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<int32_t>() +{ + return MPI_INT32_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<int64_t>() {return MPI_INT64_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<int64_t>() +{ + return MPI_INT64_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<uint8_t>() {return MPI_UINT8_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<uint8_t>() +{ + return MPI_UINT8_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<uint16_t>() {return MPI_UINT16_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<uint16_t>() +{ + return MPI_UINT16_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<uint32_t>() {return MPI_UINT32_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<uint32_t>() +{ + return MPI_UINT32_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<uint64_t>() {return MPI_UINT64_T; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<uint64_t>() +{ + return MPI_UINT64_T; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<signed long long int>() {return MPI_LONG_LONG_INT; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<signed long long int>() +{ + return MPI_LONG_LONG_INT; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<unsigned long long int>() {return MPI_UNSIGNED_LONG_LONG; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<unsigned long long int>() +{ + return MPI_UNSIGNED_LONG_LONG; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<float>() {return MPI_FLOAT; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<float>() +{ + return MPI_FLOAT; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<double>() {return MPI_DOUBLE; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<double>() +{ + return MPI_DOUBLE; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<long double>() {return MPI_LONG_DOUBLE; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<long double>() +{ + return MPI_LONG_DOUBLE; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<wchar_t>() {return MPI_WCHAR; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<wchar_t>() +{ + return MPI_WCHAR; +} -template<> PASTIS_INLINE MPI_Datatype -Messenger::helper::mpiType<bool>() {return MPI_CXX_BOOL; } +template <> +PASTIS_INLINE MPI_Datatype +Messenger::helper::mpiType<bool>() +{ + return MPI_CXX_BOOL; +} -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI -} // namespace parallel +} // namespace parallel -#endif // MESSENGER_HPP +#endif // MESSENGER_HPP diff --git a/src/utils/Partitioner.cpp b/src/utils/Partitioner.cpp index 709038090..1ab81ef01 100644 --- a/src/utils/Partitioner.cpp +++ b/src/utils/Partitioner.cpp @@ -1,5 +1,5 @@ -#include <Partitioner.hpp> #include <Messenger.hpp> +#include <Partitioner.hpp> #include <pastis_config.hpp> #include <PastisOStream.hpp> @@ -10,24 +10,22 @@ #define REALTYPEWIDTH 64 #include <parmetis.h> - #include <vector> - -Array<int> Partitioner::partition(const CSRGraph& graph) +Array<int> +Partitioner::partition(const CSRGraph& graph) { - pout() << "Partitioning graph into " - << rang::style::bold << parallel::size() << rang::style::reset - << " parts\n"; + pout() << "Partitioning graph into " << rang::style::bold << parallel::size() + << rang::style::reset << " parts\n"; int wgtflag = 0; int numflag = 0; - int ncon = 1; - int npart= parallel::size(); - std::vector<float> tpwgts(npart, 1./npart); + int ncon = 1; + int npart = parallel::size(); + std::vector<float> tpwgts(npart, 1. / npart); std::vector<float> ubvec{1.05}; - std::vector<int> options{1,1,0}; + std::vector<int> options{1, 1, 0}; int edgecut = 0; Array<int> part(0); @@ -35,21 +33,21 @@ Array<int> Partitioner::partition(const CSRGraph& graph) MPI_Comm_group(MPI_COMM_WORLD, &world_group); MPI_Group mesh_group; - std::vector<int> group_ranks - = [&]() { - Array<int> graph_node_owners - = parallel::allGather(static_cast<int>(graph.numberOfNodes())); - std::vector<int> group_ranks; - group_ranks.reserve(graph_node_owners.size()); - for (size_t i=0; i<graph_node_owners.size(); ++i) { - if (graph_node_owners[i] > 0) { - group_ranks.push_back(i); - } - } - return group_ranks; - } (); - - MPI_Group_incl(world_group, group_ranks.size(), &(group_ranks[0]), &mesh_group); + std::vector<int> group_ranks = [&]() { + Array<int> graph_node_owners = + parallel::allGather(static_cast<int>(graph.numberOfNodes())); + std::vector<int> group_ranks; + group_ranks.reserve(graph_node_owners.size()); + for (size_t i = 0; i < graph_node_owners.size(); ++i) { + if (graph_node_owners[i] > 0) { + group_ranks.push_back(i); + } + } + return group_ranks; + }(); + + MPI_Group_incl(world_group, group_ranks.size(), &(group_ranks[0]), + &mesh_group); MPI_Comm parmetis_comm; MPI_Comm_create_group(MPI_COMM_WORLD, mesh_group, 1, &parmetis_comm); @@ -58,16 +56,15 @@ Array<int> Partitioner::partition(const CSRGraph& graph) if (graph.numberOfNodes() > 0) { part = Array<int>(local_number_of_nodes); - std::vector<int> vtxdist{0,local_number_of_nodes}; + std::vector<int> vtxdist{0, local_number_of_nodes}; - const Array<int>& entries = graph.entries(); + const Array<int>& entries = graph.entries(); const Array<int>& neighbors = graph.neighbors(); - int result - = ParMETIS_V3_PartKway(&(vtxdist[0]), &(entries[0]), &(neighbors[0]), - NULL, NULL, &wgtflag, &numflag, - &ncon, &npart, &(tpwgts[0]), &(ubvec[0]), - &(options[0]), &edgecut, &(part[0]), &parmetis_comm); + int result = ParMETIS_V3_PartKway( + &(vtxdist[0]), &(entries[0]), &(neighbors[0]), NULL, NULL, &wgtflag, + &numflag, &ncon, &npart, &(tpwgts[0]), &(ubvec[0]), &(options[0]), + &edgecut, &(part[0]), &parmetis_comm); if (result == METIS_ERROR) { perr() << "Metis Error\n"; std::exit(1); @@ -81,11 +78,12 @@ Array<int> Partitioner::partition(const CSRGraph& graph) return part; } -#else // PASTIS_HAS_MPI +#else // PASTIS_HAS_MPI -Array<int> Partitioner::partition(const CSRGraph&) +Array<int> +Partitioner::partition(const CSRGraph&) { return Array<int>(0); } -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI diff --git a/src/utils/Partitioner.hpp b/src/utils/Partitioner.hpp index 427d67f30..33e9f85f6 100644 --- a/src/utils/Partitioner.hpp +++ b/src/utils/Partitioner.hpp @@ -6,12 +6,11 @@ class Partitioner { public: - Partitioner() = default; + Partitioner() = default; Partitioner(const Partitioner&) = default; - ~Partitioner() = default; + ~Partitioner() = default; Array<int> partition(const CSRGraph& graph); }; - -#endif // PARTITIONER_HPP +#endif // PARTITIONER_HPP diff --git a/src/utils/PastisAssert.hpp b/src/utils/PastisAssert.hpp index 5093a44c2..2c8bd74ce 100644 --- a/src/utils/PastisAssert.hpp +++ b/src/utils/PastisAssert.hpp @@ -3,12 +3,13 @@ #include <PastisMacros.hpp> -#include <rang.hpp> #include <iostream> +#include <rang.hpp> #include <string> template <typename ErrorType> -void printAndThrow(const ErrorType& error) +void +printAndThrow(const ErrorType& error) { throw error; } @@ -23,22 +24,21 @@ class AssertError const std::string m_message; public: - friend - std::ostream& operator<<(std::ostream& os, - const AssertError& assert_error) + friend std::ostream& + operator<<(std::ostream& os, const AssertError& assert_error) { os << '\n' - << rang::style::bold - << "---------- Assertion error -----------\n" + << rang::style::bold << "---------- Assertion error -----------\n" << " at " << assert_error.m_file << ':' << assert_error.m_line << '\n' << " in " << assert_error.m_function << '\n' - << " assertion (" << rang::fgB::red << assert_error.m_test << rang::fg::reset - << ") failed!\n"; + << " assertion (" << rang::fgB::red << assert_error.m_test + << rang::fg::reset << ") failed!\n"; if (not assert_error.m_message.empty()) { os << ' ' << rang::fgB::yellow << assert_error.m_message << rang::fg::reset << '\n'; } - os << "--------------------------------------" << rang::style::reset << '\n'; + os << "--------------------------------------" << rang::style::reset + << '\n'; return os; } @@ -48,12 +48,12 @@ class AssertError int line, std::string function, std::string test, - std::string message="") - : m_file(file), - m_line(line), - m_function(function), - m_test(test), - m_message(message) + std::string message = "") + : m_file(file), + m_line(line), + m_function(function), + m_test(test), + m_message(message) { ; } @@ -62,8 +62,7 @@ class AssertError }; PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES -inline bool -__attribute__((analyzer_noreturn)) +inline bool __attribute__((analyzer_noreturn)) _pastis_assert(const bool& assert) { return assert; @@ -73,42 +72,35 @@ PRAGMA_DIAGNOSTIC_POP #ifdef NDEBUG // Useless test is there to check syntax even in optimized mode. Costs nothing. -#define Assert(assertion,...) \ - if (not _pastis_assert(assertion)) { \ - using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ - static_assert(std::tuple_size_v<vargs_t> <= 1, \ - "too many arguments"); \ +#define Assert(assertion, ...) \ + if (not _pastis_assert(assertion)) { \ + using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ + static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ } -#else // NDEBUG - -#define Assert(assertion,...) \ - if (not _pastis_assert(assertion)) { \ - using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ - static_assert(std::tuple_size_v<vargs_t> <= 1, \ - "too many arguments"); \ - if constexpr(std::tuple_size_v<vargs_t> == 0) { \ - printAndThrow(AssertError(__FILE__, \ - __LINE__, \ - __PRETTY_FUNCTION__, \ - #assertion)); \ - } else { \ - printAndThrow(AssertError(__FILE__, \ - __LINE__, \ - __PRETTY_FUNCTION__, \ - #assertion, \ - #__VA_ARGS__)); \ - } \ +#else // NDEBUG + +#define Assert(assertion, ...) \ + if (not _pastis_assert(assertion)) { \ + using vargs_t = decltype(std::make_tuple(__VA_ARGS__)); \ + static_assert(std::tuple_size_v<vargs_t> <= 1, "too many arguments"); \ + if constexpr (std::tuple_size_v<vargs_t> == 0) { \ + printAndThrow( \ + AssertError(__FILE__, __LINE__, __PRETTY_FUNCTION__, #assertion)); \ + } else { \ + printAndThrow(AssertError(__FILE__, __LINE__, __PRETTY_FUNCTION__, \ + #assertion, #__VA_ARGS__)); \ + } \ } -#endif // NDEBUG +#endif // NDEBUG // stores the current state of Assert macro. This is useful for instance to // noexcept management of Assert throws #ifdef NDEBUG #define NO_ASSERT true -#else // NDEBUG +#else // NDEBUG #define NO_ASSERT false -#endif // NDEBUG +#endif // NDEBUG -#endif // PASTIS_ASSERT_HPP +#endif // PASTIS_ASSERT_HPP diff --git a/src/utils/PastisMacros.hpp b/src/utils/PastisMacros.hpp index 27f686688..efb492440 100644 --- a/src/utils/PastisMacros.hpp +++ b/src/utils/PastisMacros.hpp @@ -14,16 +14,15 @@ #if !defined(__clang__) and defined(__GNUC__) -#define PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES \ - _Pragma ("GCC diagnostic ignored \"-Wattributes\"") -#define PRAGMA_DIAGNOSTIC_POP \ - _Pragma ("GCC diagnostic pop") +#define PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES \ + _Pragma("GCC diagnostic ignored \"-Wattributes\"") +#define PRAGMA_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") -#else // !defined(__clang__) and defined(__GNUC__) +#else // !defined(__clang__) and defined(__GNUC__) #define PRAGMA_DIAGNOSTIC_IGNORED_WATTRIBUTES #define PRAGMA_DIAGNOSTIC_POP #endif -#endif // PASTIS_MACROS_HPP +#endif // PASTIS_MACROS_HPP diff --git a/src/utils/PastisOStream.cpp b/src/utils/PastisOStream.cpp index af188ac6b..180570f80 100644 --- a/src/utils/PastisOStream.cpp +++ b/src/utils/PastisOStream.cpp @@ -1,14 +1,13 @@ #include <PastisOStream.hpp> -#include <sstream> #include <iomanip> +#include <sstream> PastisOStream pout(std::cout); PastisOStream perr(std::cerr); std::stringstream null_stream; -const PastisOStream _null_stream_initializer([]()-> std::stringstream& - { - null_stream.setstate(std::ios::badbit); - return null_stream; - }()); +const PastisOStream _null_stream_initializer([]() -> std::stringstream& { + null_stream.setstate(std::ios::badbit); + return null_stream; +}()); diff --git a/src/utils/PastisOStream.hpp b/src/utils/PastisOStream.hpp index 360313be2..3945f9705 100644 --- a/src/utils/PastisOStream.hpp +++ b/src/utils/PastisOStream.hpp @@ -14,26 +14,27 @@ class PastisOStream public: PASTIS_INLINE - std::ostream& operator()() + std::ostream& + operator()() { return *m_os; } - void setOutput(std::ostream& os) + void + setOutput(std::ostream& os) { m_os = &os; } - PastisOStream(std::ostream& os) - : m_os(&os) + PastisOStream(std::ostream& os) : m_os(&os) { ; } PastisOStream& operator=(const PastisOStream&) = delete; PastisOStream& operator=(PastisOStream&&) = delete; - PastisOStream(const PastisOStream&) = delete; - PastisOStream(PastisOStream&&) = delete; + PastisOStream(const PastisOStream&) = delete; + PastisOStream(PastisOStream&&) = delete; ~PastisOStream() = default; }; @@ -42,4 +43,4 @@ extern PastisOStream pout; extern PastisOStream perr; extern const PastisOStream _null_stream_initializer; -#endif // PASTIS_OSTREAM_HPP +#endif // PASTIS_OSTREAM_HPP diff --git a/src/utils/PastisTraits.hpp b/src/utils/PastisTraits.hpp index 871e30fd1..2192c8b47 100644 --- a/src/utils/PastisTraits.hpp +++ b/src/utils/PastisTraits.hpp @@ -3,23 +3,29 @@ #include <type_traits> -template <size_t N, typename T> class TinyVector; -template <size_t N, typename T> class TinyMatrix; +template <size_t N, typename T> +class TinyVector; +template <size_t N, typename T> +class TinyMatrix; template <typename T> inline constexpr bool is_trivially_castable = std::is_trivial_v<T>; template <size_t N, typename T> -inline constexpr bool is_trivially_castable<TinyVector<N,T>> = is_trivially_castable<T>; +inline constexpr bool is_trivially_castable<TinyVector<N, T>> = + is_trivially_castable<T>; template <size_t N, typename T> -inline constexpr bool is_trivially_castable<const TinyVector<N,T>> = is_trivially_castable<T>; +inline constexpr bool is_trivially_castable<const TinyVector<N, T>> = + is_trivially_castable<T>; template <size_t N, typename T> -inline constexpr bool is_trivially_castable<TinyMatrix<N,T>> = is_trivially_castable<T>; +inline constexpr bool is_trivially_castable<TinyMatrix<N, T>> = + is_trivially_castable<T>; template <size_t N, typename T> -inline constexpr bool is_trivially_castable<const TinyMatrix<N,T>> = is_trivially_castable<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 +#endif // PASTIS_TRAITS_HPP diff --git a/src/utils/PastisUtils.cpp b/src/utils/PastisUtils.cpp index 4a22dec2b..16bfe9dc5 100644 --- a/src/utils/PastisUtils.cpp +++ b/src/utils/PastisUtils.cpp @@ -1,40 +1,40 @@ -#include <PastisUtils.hpp> #include <PastisOStream.hpp> +#include <PastisUtils.hpp> #include <Kokkos_Core.hpp> -#include <RevisionInfo.hpp> #include <BuildInfo.hpp> +#include <RevisionInfo.hpp> #include <Messenger.hpp> #include <rang.hpp> +#include <ConsoleManager.hpp> #include <FPEManager.hpp> #include <SignalManager.hpp> -#include <ConsoleManager.hpp> #include <CLI/CLI.hpp> -std::string initialize(int& argc, char* argv[]) +std::string +initialize(int& argc, char* argv[]) { parallel::Messenger::create(argc, argv); long unsigned number = 10; std::string filename; - pout() << "Pastis version: " - << rang::style::bold << RevisionInfo::version() << rang::style::reset << '\n'; + pout() << "Pastis version: " << rang::style::bold << RevisionInfo::version() + << rang::style::reset << '\n'; - pout() << "-------------------- " - << rang::fg::green - << "git info" - << rang::fg::reset - <<" -------------------------" - << '\n'; - pout() << "tag: " << rang::style::bold << RevisionInfo::gitTag() << rang::style::reset << '\n'; - pout() << "HEAD: " << rang::style::bold << RevisionInfo::gitHead() << rang::style::reset << '\n'; - pout() << "hash: " << rang::style::bold << RevisionInfo::gitHash() << rang::style::reset << " ("; + pout() << "-------------------- " << rang::fg::green << "git info" + << rang::fg::reset << " -------------------------" << '\n'; + pout() << "tag: " << rang::style::bold << RevisionInfo::gitTag() + << rang::style::reset << '\n'; + pout() << "HEAD: " << rang::style::bold << RevisionInfo::gitHead() + << rang::style::reset << '\n'; + pout() << "hash: " << rang::style::bold << RevisionInfo::gitHash() + << rang::style::reset << " ("; if (RevisionInfo::gitIsClean()) { pout() << rang::fgB::green << "clean" << rang::fg::reset; @@ -42,42 +42,47 @@ std::string initialize(int& argc, char* argv[]) pout() << rang::fgB::red << "dirty" << rang::fg::reset; } pout() << ")\n"; - pout() << "-------------------- " - << rang::fg::green - << "build info" - << rang::fg::reset - <<" -----------------------" - << '\n'; - pout() << "type: " << rang::style::bold << BuildInfo::type() << rang::style::reset << '\n'; - pout() << "compiler: " << rang::style::bold << BuildInfo::compiler() << rang::style::reset << '\n'; - pout() << "kokkos: " << rang::style::bold << BuildInfo::kokkosDevices() << rang::style::reset << '\n'; - pout() << "mpi: " << rang::style::bold << BuildInfo::mpiLibrary() << rang::style::reset << '\n'; + pout() << "-------------------- " << rang::fg::green << "build info" + << rang::fg::reset << " -----------------------" << '\n'; + pout() << "type: " << rang::style::bold << BuildInfo::type() + << rang::style::reset << '\n'; + pout() << "compiler: " << rang::style::bold << BuildInfo::compiler() + << rang::style::reset << '\n'; + pout() << "kokkos: " << rang::style::bold << BuildInfo::kokkosDevices() + << rang::style::reset << '\n'; + pout() << "mpi: " << rang::style::bold << BuildInfo::mpiLibrary() + << rang::style::reset << '\n'; pout() << "-------------------------------------------------------\n"; { CLI::App app{"Pastis help"}; - app.add_option("-n,--number", number, "Number of cells");//->required(); + app.add_option("-n,--number", number, "Number of cells"); //->required(); - app.add_option("filename,-f,--filename", filename, "gmsh file");//->required(); + app.add_option("filename,-f,--filename", filename, + "gmsh file"); //->required(); - int threads=-1; - app.add_option("--threads", threads, "Number of Kokkos threads")->check(CLI::Range(1,std::numeric_limits<decltype(threads)>::max())); + int threads = -1; + app.add_option("--threads", threads, "Number of Kokkos threads") + ->check(CLI::Range(1, std::numeric_limits<decltype(threads)>::max())); - std::string colorize="auto"; - app.add_set("--colorize", colorize, {"auto", "yes", "no"}, "Colorize console output", true); + std::string colorize = "auto"; + app.add_set("--colorize", colorize, {"auto", "yes", "no"}, + "Colorize console output", true); bool disable_fpe = false; - app.add_flag("--no-fpe", disable_fpe, "Do not trap floating point exceptions"); + app.add_flag("--no-fpe", disable_fpe, + "Do not trap floating point exceptions"); bool disable_signals = false; app.add_flag("--no-signal", disable_signals, "Do not catches signals"); - std::string pause_on_error="auto"; - app.add_set("--pause-on-error", pause_on_error, {"auto", "yes", "no"}, "Pause for debugging on unexpected error", true); + std::string pause_on_error = "auto"; + app.add_set("--pause-on-error", pause_on_error, {"auto", "yes", "no"}, + "Pause for debugging on unexpected error", true); - std::atexit([](){pout() << rang::style::reset;}); + std::atexit([]() { pout() << rang::style::reset; }); try { app.parse(argc, argv); - } catch (const CLI::ParseError &e) { + } catch (const CLI::ParseError& e) { parallel::Messenger::destroy(); std::exit(app.exit(e, pout(), perr())); } @@ -88,13 +93,9 @@ std::string initialize(int& argc, char* argv[]) SignalManager::init(not disable_signals); } - Kokkos::initialize(argc,argv); - pout() << "-------------------- " - << rang::fg::green - << "exec info" - << rang::fg::reset - <<" ------------------------" - << '\n'; + Kokkos::initialize(argc, argv); + pout() << "-------------------- " << rang::fg::green << "exec info" + << rang::fg::reset << " ------------------------" << '\n'; pout() << rang::style::bold; Kokkos::DefaultExecutionSpace::print_configuration(pout()); @@ -104,7 +105,8 @@ std::string initialize(int& argc, char* argv[]) return filename; } -void finalize() +void +finalize() { Kokkos::finalize(); parallel::Messenger::destroy(); diff --git a/src/utils/PastisUtils.hpp b/src/utils/PastisUtils.hpp index d0a68cfdb..33ae8a2fb 100644 --- a/src/utils/PastisUtils.hpp +++ b/src/utils/PastisUtils.hpp @@ -8,20 +8,20 @@ #include <string> template <typename FunctionType> -PASTIS_FORCEINLINE -void parallel_for(const size_t& size, - const FunctionType& lambda, - const std::string& label = "") +PASTIS_FORCEINLINE void +parallel_for(const size_t& size, + const FunctionType& lambda, + const std::string& label = "") { Kokkos::parallel_for(size, lambda, label); } template <typename ArrayType, typename ReturnType> -PASTIS_FORCEINLINE -void parallel_reduce(const size_t& size, - const ArrayType& array, - ReturnType& value, - const std::string& label = "") +PASTIS_FORCEINLINE void +parallel_reduce(const size_t& size, + const ArrayType& array, + ReturnType& value, + const std::string& label = "") { Kokkos::parallel_reduce(label, size, array, value); } @@ -30,4 +30,4 @@ std::string initialize(int& argc, char* argv[]); void finalize(); -#endif // PASTIS_UTILS_HPP +#endif // PASTIS_UTILS_HPP diff --git a/src/utils/RevisionInfo.cpp b/src/utils/RevisionInfo.cpp index f508dec33..97c99deca 100644 --- a/src/utils/RevisionInfo.cpp +++ b/src/utils/RevisionInfo.cpp @@ -2,12 +2,14 @@ #include <pastis_git_revision.hpp> #include <pastis_version.hpp> -std::string RevisionInfo::version() +std::string +RevisionInfo::version() { return PASTIS_VERSION; } -bool RevisionInfo::hasGitInfo() +bool +RevisionInfo::hasGitInfo() { #ifdef HAS_PASTIS_GIT_INFO return true; @@ -16,7 +18,8 @@ bool RevisionInfo::hasGitInfo() #endif } -std::string RevisionInfo::gitTag() +std::string +RevisionInfo::gitTag() { #ifdef HAS_PASTIS_GIT_INFO return PASTIS_GIT_TAG; @@ -25,7 +28,8 @@ std::string RevisionInfo::gitTag() #endif } -std::string RevisionInfo::gitHead() +std::string +RevisionInfo::gitHead() { #ifdef HAS_PASTIS_GIT_INFO return PASTIS_GIT_HEAD; @@ -34,7 +38,8 @@ std::string RevisionInfo::gitHead() #endif } -std::string RevisionInfo::gitHash() +std::string +RevisionInfo::gitHash() { #ifdef HAS_PASTIS_GIT_INFO return PASTIS_GIT_HASH; @@ -43,7 +48,8 @@ std::string RevisionInfo::gitHash() #endif } -bool RevisionInfo::gitIsClean() +bool +RevisionInfo::gitIsClean() { #ifdef HAS_PASTIS_GIT_INFO return PASTIS_GIT_IS_CLEAN; @@ -51,4 +57,3 @@ bool RevisionInfo::gitIsClean() return false; #endif } - diff --git a/src/utils/RevisionInfo.hpp b/src/utils/RevisionInfo.hpp index bff12f201..e336c8d20 100644 --- a/src/utils/RevisionInfo.hpp +++ b/src/utils/RevisionInfo.hpp @@ -14,4 +14,4 @@ struct RevisionInfo static bool gitIsClean(); }; -#endif // REVISION_INFO_HPP +#endif // REVISION_INFO_HPP diff --git a/src/utils/SignalManager.cpp b/src/utils/SignalManager.cpp index 525db43c8..c7e70f230 100644 --- a/src/utils/SignalManager.cpp +++ b/src/utils/SignalManager.cpp @@ -15,54 +15,59 @@ #include <Messenger.hpp> std::string SignalManager::s_pause_on_error = "auto"; -void SignalManager::setPauseForDebug(const std::string& pause_on_error) +void +SignalManager::setPauseForDebug(const std::string& pause_on_error) { s_pause_on_error = pause_on_error; } -std::string SignalManager::signalName(const int& signal) +std::string +SignalManager::signalName(const int& signal) { switch (signal) { - case SIGILL: return "SIGILL"; - case SIGFPE: return "SIGFPE"; - case SIGABRT: return "SIGABRT"; - case SIGINT: return "SIGINT"; - case SIGSEGV: return "SIGSEGV"; - case SIGTERM: return "SIGTERM"; + case SIGILL: + return "SIGILL"; + case SIGFPE: + return "SIGFPE"; + case SIGABRT: + return "SIGABRT"; + case SIGINT: + return "SIGINT"; + case SIGSEGV: + return "SIGSEGV"; + case SIGTERM: + return "SIGTERM"; } return "SIGNAL undefined!"; } -void SignalManager::pauseForDebug(const int& signal) +void +SignalManager::pauseForDebug(const int& signal) { if (std::string(PASTIS_BUILD_TYPE) != "Release") { if (s_pause_on_error == "yes") { std::cerr << "\n======================================\n" - << rang::style::reset - << rang::fg::reset - << rang::style::bold - << "to attach gdb to this process run\n" - << "\tgdb -pid " - << rang::fg::red - << getpid() - << rang::fg::reset - << '\n' - << "else press Control-C to exit\n" - << rang::style::reset - << "======================================\n" - << std::flush; + << rang::style::reset << rang::fg::reset << rang::style::bold + << "to attach gdb to this process run\n" + << "\tgdb -pid " << rang::fg::red << getpid() << rang::fg::reset + << '\n' + << "else press Control-C to exit\n" + << rang::style::reset + << "======================================\n" + << std::flush; pause(); } } std::exit(signal); } -void SignalManager::handler(int signal) +void +SignalManager::handler(int signal) { - std::signal(SIGFPE, SIG_DFL); + std::signal(SIGFPE, SIG_DFL); std::signal(SIGSEGV, SIG_IGN); std::signal(SIGTERM, SIG_DFL); - std::signal(SIGINT, SIG_DFL); + std::signal(SIGINT, SIG_DFL); std::signal(SIGABRT, SIG_DFL); BacktraceManager bm; @@ -73,52 +78,35 @@ void SignalManager::handler(int signal) if (eptr) { std::rethrow_exception(eptr); } - } - catch(const AssertError& assert_error) { + } catch (const AssertError& assert_error) { std::cerr << assert_error << '\n'; - } - catch(...) { + } catch (...) { std::cerr << "Unknown exception!\n"; } - std::cerr << "\n *** " - << rang::style::reset - << rang::fg::reset - << rang::style::bold - << "Signal " - << rang::fgB::red - << signalName(signal) - << rang::fg::reset - << " caught" - << rang::style::reset - << " ***\n"; + std::cerr << "\n *** " << rang::style::reset << rang::fg::reset + << rang::style::bold << "Signal " << rang::fgB::red + << signalName(signal) << rang::fg::reset << " caught" + << rang::style::reset << " ***\n"; SignalManager::pauseForDebug(signal); - } +} -void SignalManager::init(const bool& enable) +void +SignalManager::init(const bool& enable) { - if (enable) { - std::signal(SIGFPE, SignalManager::handler); + std::signal(SIGFPE, SignalManager::handler); std::signal(SIGSEGV, SignalManager::handler); std::signal(SIGTERM, SignalManager::handler); - std::signal(SIGINT, SignalManager::handler); + std::signal(SIGINT, SignalManager::handler); std::signal(SIGABRT, SignalManager::handler); std::signal(SIGPIPE, SignalManager::handler); - pout() << "Signal management: " - << rang::style::bold - << rang::fgB::green - << "enabled" - << rang::fg::reset - << rang::style::reset << '\n'; + pout() << "Signal management: " << rang::style::bold << rang::fgB::green + << "enabled" << rang::fg::reset << rang::style::reset << '\n'; } else { - pout() << "Signal management: " - << rang::style::bold - << rang::fgB::red - << "disabled" - << rang::fg::reset - << rang::style::reset << '\n'; + pout() << "Signal management: " << rang::style::bold << rang::fgB::red + << "disabled" << rang::fg::reset << rang::style::reset << '\n'; } } diff --git a/src/utils/SignalManager.hpp b/src/utils/SignalManager.hpp index 6232fdee2..3f0159368 100644 --- a/src/utils/SignalManager.hpp +++ b/src/utils/SignalManager.hpp @@ -5,14 +5,15 @@ struct SignalManager { -private: + private: static std::string s_pause_on_error; static std::string signalName(const int& signal); static void pauseForDebug(const int& signal); static void handler(int signal); -public: + + public: static void setPauseForDebug(const std::string& pause_on_error); static void init(const bool& enable); }; -#endif // SIGNAL_MANAGER_HPP +#endif // SIGNAL_MANAGER_HPP diff --git a/src/utils/Timer.hpp b/src/utils/Timer.hpp index 44d4a0c51..c26ea40aa 100644 --- a/src/utils/Timer.hpp +++ b/src/utils/Timer.hpp @@ -5,4 +5,4 @@ using Timer = Kokkos::Timer; -#endif // TIMER_HPP +#endif // TIMER_HPP diff --git a/src/utils/Types.hpp b/src/utils/Types.hpp index 90d0e8407..482190cb6 100644 --- a/src/utils/Types.hpp +++ b/src/utils/Types.hpp @@ -1,10 +1,16 @@ #ifndef TYPES_HPP #define TYPES_HPP -enum class ZeroType { zero }; -constexpr ZeroType zero=ZeroType::zero; +enum class ZeroType +{ + zero +}; +constexpr ZeroType zero = ZeroType::zero; -enum class IdentityType { identity }; -constexpr IdentityType identity=IdentityType::identity; +enum class IdentityType +{ + identity +}; +constexpr IdentityType identity = IdentityType::identity; -#endif // TYPES_HPP +#endif // TYPES_HPP diff --git a/tests/mpi_test_Messenger.cpp b/tests/mpi_test_Messenger.cpp index f6ad79c21..94bf36f13 100644 --- a/tests/mpi_test_Messenger.cpp +++ b/tests/mpi_test_Messenger.cpp @@ -1,26 +1,36 @@ #include <catch.hpp> -#include <Messenger.hpp> #include <Array.hpp> +#include <Messenger.hpp> -#include <pastis_config.hpp> #include <fstream> +#include <pastis_config.hpp> #ifdef PASTIS_HAS_MPI #include <mpi.h> #define IF_MPI(INSTRUCTION) INSTRUCTION #else #define IF_MPI(INSTRUCTION) -#endif // PASTIS_HAS_MPI +#endif // PASTIS_HAS_MPI -namespace mpi_check -{ +namespace mpi_check { struct integer { int m_int; - operator int&() {return m_int;} - operator const int&() const {return m_int;} - integer& operator=(const int& i) {m_int = i; return *this;} + operator int&() + { + return m_int; + } + operator const int&() const + { + return m_int; + } + integer& + operator=(const int& i) + { + m_int = i; + return *this; + } }; struct tri_int @@ -28,82 +38,88 @@ struct tri_int int m_int_0; int m_int_1; int m_int_2; - bool operator==(const tri_int& t) const { - return ((m_int_0 == t.m_int_0) and - (m_int_1 == t.m_int_1) and + bool + operator==(const tri_int& t) const + { + return ((m_int_0 == t.m_int_0) and (m_int_1 == t.m_int_1) and (m_int_2 == t.m_int_2)); } }; - template <typename T> -void test_allToAll() +void +test_allToAll() { Array<T> data_array(parallel::size()); - for (size_t i=0; i< data_array.size(); ++i) { + for (size_t i = 0; i < data_array.size(); ++i) { data_array[i] = parallel::rank(); } auto exchanged_array = parallel::allToAll(data_array); - for (size_t i=0; i< data_array.size(); ++i) { + for (size_t i = 0; i < data_array.size(); ++i) { const size_t value = exchanged_array[i]; REQUIRE(value == i); } } template <> -void test_allToAll<bool>() +void +test_allToAll<bool>() { Array<bool> data_array(parallel::size()); - for (size_t i=0; i< data_array.size(); ++i) { - data_array[i] = ((parallel::rank()%2)==0); + for (size_t i = 0; i < data_array.size(); ++i) { + data_array[i] = ((parallel::rank() % 2) == 0); } auto exchanged_array = parallel::allToAll(data_array); - for (size_t i=0; i< data_array.size(); ++i) { - REQUIRE(exchanged_array[i] == ((i%2)==0)); + for (size_t i = 0; i < data_array.size(); ++i) { + REQUIRE(exchanged_array[i] == ((i % 2) == 0)); } } template <> -void test_allToAll<tri_int>() +void +test_allToAll<tri_int>() { Array<tri_int> data_array(parallel::size()); - for (size_t i=0; i< data_array.size(); ++i) { - const int val = 1+parallel::rank(); - data_array[i] = tri_int{val, 2*val, val+3 }; + for (size_t i = 0; i < data_array.size(); ++i) { + const int val = 1 + parallel::rank(); + data_array[i] = tri_int{val, 2 * val, val + 3}; } auto exchanged_array = parallel::allToAll(data_array); - for (size_t i=0; i< data_array.size(); ++i) { - const int val = 1+i; - REQUIRE(exchanged_array[i] == tri_int{val, 2*val, val+3 }); + for (size_t i = 0; i < data_array.size(); ++i) { + const int val = 1 + i; + REQUIRE(exchanged_array[i] == tri_int{val, 2 * val, val + 3}); } } -} - -TEST_CASE("Messenger", "[mpi]") { +} // namespace mpi_check - SECTION("communication info") { - int rank=0; +TEST_CASE("Messenger", "[mpi]") +{ + SECTION("communication info") + { + int rank = 0; IF_MPI(MPI_Comm_rank(MPI_COMM_WORLD, &rank)); REQUIRE(rank == parallel::rank()); - int size=1; + int size = 1; IF_MPI(MPI_Comm_size(MPI_COMM_WORLD, &size)); REQUIRE(size == parallel::size()); } - SECTION("reduction") { - const int min_value = parallel::allReduceMin(parallel::rank()+3); - REQUIRE(min_value ==3); + SECTION("reduction") + { + const int min_value = parallel::allReduceMin(parallel::rank() + 3); + REQUIRE(min_value == 3); - const int max_value = parallel::allReduceMax(parallel::rank()+3); - REQUIRE(max_value == ((parallel::size()-1) + 3)); + const int max_value = parallel::allReduceMax(parallel::rank() + 3); + REQUIRE(max_value == ((parallel::size() - 1) + 3)); } - SECTION("all to all") { + SECTION("all to all") + { // chars mpi_check::test_allToAll<char>(); mpi_check::test_allToAll<wchar_t>(); @@ -135,137 +151,146 @@ TEST_CASE("Messenger", "[mpi]") { mpi_check::test_allToAll<mpi_check::tri_int>(); #ifndef NDEBUG - SECTION("checking invalid all to all") { + SECTION("checking invalid all to all") + { if (parallel::size() > 1) { - Array<int> invalid_all_to_all(parallel::size()+1); + Array<int> invalid_all_to_all(parallel::size() + 1); REQUIRE_THROWS_AS(parallel::allToAll(invalid_all_to_all), AssertError); - Array<int> different_size_all_to_all(parallel::size()*(parallel::rank()+1)); - REQUIRE_THROWS_AS(parallel::allToAll(different_size_all_to_all), AssertError); + Array<int> different_size_all_to_all(parallel::size() * + (parallel::rank() + 1)); + REQUIRE_THROWS_AS(parallel::allToAll(different_size_all_to_all), + AssertError); } } -#endif // NDEBUG +#endif // NDEBUG } - SECTION("broadcast value") { + SECTION("broadcast value") + { { // simple type - size_t value{(3+parallel::rank())*2}; + size_t value{(3 + parallel::rank()) * 2}; parallel::broadcast(value, 0); REQUIRE(value == 6); } { // trivial simple type - mpi_check::integer value{static_cast<int>((3+parallel::rank())*2)}; + mpi_check::integer value{static_cast<int>((3 + parallel::rank()) * 2)}; parallel::broadcast(value, 0); REQUIRE((value == 6)); } { // compound trivial type - mpi_check::tri_int value{static_cast<int>((3+parallel::rank())*2), - static_cast<int>(2+parallel::rank()), - static_cast<int>(4-parallel::rank())}; + mpi_check::tri_int value{static_cast<int>((3 + parallel::rank()) * 2), + static_cast<int>(2 + parallel::rank()), + static_cast<int>(4 - parallel::rank())}; parallel::broadcast(value, 0); - REQUIRE((value == mpi_check::tri_int{6,2,4})); + REQUIRE((value == mpi_check::tri_int{6, 2, 4})); } } - SECTION("broadcast array") { + SECTION("broadcast array") + { { // simple type Array<size_t> array(3); - array[0] = (3+parallel::rank())*2; - array[1] = 2+parallel::rank(); - array[2] = 4-parallel::rank(); + array[0] = (3 + parallel::rank()) * 2; + array[1] = 2 + parallel::rank(); + array[2] = 4 - parallel::rank(); parallel::broadcast(array, 0); - REQUIRE(((array[0]==6) and (array[1]==2) and (array[2]==4))); + REQUIRE(((array[0] == 6) and (array[1] == 2) and (array[2] == 4))); } { // trivial simple type Array<mpi_check::integer> array(3); - array[0] = static_cast<int>((3+parallel::rank())*2); - array[1] = static_cast<int>(2+parallel::rank()); - array[2] = static_cast<int>(4-parallel::rank()); + array[0] = static_cast<int>((3 + parallel::rank()) * 2); + array[1] = static_cast<int>(2 + parallel::rank()); + array[2] = static_cast<int>(4 - parallel::rank()); parallel::broadcast(array, 0); - REQUIRE(((array[0]==6) and (array[1]==2) and (array[2]==4))); + REQUIRE(((array[0] == 6) and (array[1] == 2) and (array[2] == 4))); } { // compound trivial type Array<mpi_check::tri_int> array(3); - array[0] = mpi_check::tri_int{static_cast<int>((3+parallel::rank())*2), - static_cast<int>(2+parallel::rank()), - static_cast<int>(4-parallel::rank())}; - array[1] = mpi_check::tri_int{static_cast<int>((2+parallel::rank())*4), - static_cast<int>(3+parallel::rank()), - static_cast<int>(1-parallel::rank())}; - array[2] = mpi_check::tri_int{static_cast<int>((5+parallel::rank())), - static_cast<int>(-3+parallel::rank()), + array[0] = + mpi_check::tri_int{static_cast<int>((3 + parallel::rank()) * 2), + static_cast<int>(2 + parallel::rank()), + static_cast<int>(4 - parallel::rank())}; + array[1] = + mpi_check::tri_int{static_cast<int>((2 + parallel::rank()) * 4), + static_cast<int>(3 + parallel::rank()), + static_cast<int>(1 - parallel::rank())}; + array[2] = mpi_check::tri_int{static_cast<int>((5 + parallel::rank())), + static_cast<int>(-3 + parallel::rank()), static_cast<int>(parallel::rank())}; parallel::broadcast(array, 0); - REQUIRE(((array[0] == mpi_check::tri_int{6, 2,4}) and - (array[1] == mpi_check::tri_int{8, 3,1}) and - (array[2] == mpi_check::tri_int{5,-3,0}))); + REQUIRE(((array[0] == mpi_check::tri_int{6, 2, 4}) and + (array[1] == mpi_check::tri_int{8, 3, 1}) and + (array[2] == mpi_check::tri_int{5, -3, 0}))); } } - SECTION("all gather value") { + SECTION("all gather value") + { { // simple type - size_t value{(3+parallel::rank())*2}; + size_t value{(3 + parallel::rank()) * 2}; Array<size_t> gather_array = parallel::allGather(value); REQUIRE(gather_array.size() == parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - REQUIRE((gather_array[i] == (3+i)*2)); + for (size_t i = 0; i < gather_array.size(); ++i) { + REQUIRE((gather_array[i] == (3 + i) * 2)); } } { // trivial simple type - mpi_check::integer value{static_cast<int>((3+parallel::rank())*2)}; + mpi_check::integer value{static_cast<int>((3 + parallel::rank()) * 2)}; Array<mpi_check::integer> gather_array = parallel::allGather(value); REQUIRE(gather_array.size() == parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - const int expected_value = (3+i)*2; + for (size_t i = 0; i < gather_array.size(); ++i) { + const int expected_value = (3 + i) * 2; REQUIRE(gather_array[i] == expected_value); } } { // compound trivial type - mpi_check::tri_int value{static_cast<int>((3+parallel::rank())*2), - static_cast<int>(2+parallel::rank()), - static_cast<int>(4-parallel::rank())}; - Array<mpi_check::tri_int> gather_array - = parallel::allGather(value); + mpi_check::tri_int value{static_cast<int>((3 + parallel::rank()) * 2), + static_cast<int>(2 + parallel::rank()), + static_cast<int>(4 - parallel::rank())}; + Array<mpi_check::tri_int> gather_array = parallel::allGather(value); REQUIRE(gather_array.size() == parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - mpi_check::tri_int expected_value{static_cast<int>((3+i)*2), - static_cast<int>(2+i), - static_cast<int>(4-i)}; + for (size_t i = 0; i < gather_array.size(); ++i) { + mpi_check::tri_int expected_value{static_cast<int>((3 + i) * 2), + static_cast<int>(2 + i), + static_cast<int>(4 - i)}; REQUIRE((gather_array[i] == expected_value)); } } } - SECTION("all gather array") { + SECTION("all gather array") + { { // simple type Array<int> array(3); - for (size_t i=0; i<array.size(); ++i) { - array[i] = (3+parallel::rank())*2+i; + for (size_t i = 0; i < array.size(); ++i) { + array[i] = (3 + parallel::rank()) * 2 + i; } Array<int> gather_array = parallel::allGather(array); - REQUIRE(gather_array.size() == array.size()*parallel::size()); + REQUIRE(gather_array.size() == array.size() * parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - const int expected_value = (3+i/array.size())*2+(i%array.size()); + for (size_t i = 0; i < gather_array.size(); ++i) { + const int expected_value = + (3 + i / array.size()) * 2 + (i % array.size()); REQUIRE((gather_array[i] == expected_value)); } } @@ -273,14 +298,15 @@ TEST_CASE("Messenger", "[mpi]") { { // trivial simple type Array<mpi_check::integer> array(3); - for (size_t i=0; i<array.size(); ++i) { - array[i] = (3+parallel::rank())*2+i; + for (size_t i = 0; i < array.size(); ++i) { + array[i] = (3 + parallel::rank()) * 2 + i; } Array<mpi_check::integer> gather_array = parallel::allGather(array); - REQUIRE(gather_array.size() == array.size()*parallel::size()); + REQUIRE(gather_array.size() == array.size() * parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - const int expected_value = (3+i/array.size())*2+(i%array.size()); + for (size_t i = 0; i < gather_array.size(); ++i) { + const int expected_value = + (3 + i / array.size()) * 2 + (i % array.size()); REQUIRE((gather_array[i] == expected_value)); } } @@ -288,69 +314,71 @@ TEST_CASE("Messenger", "[mpi]") { { // compound trivial type Array<mpi_check::tri_int> array(3); - for (size_t i=0; i<array.size(); ++i) { - array[i] = mpi_check::tri_int{static_cast<int>((3+parallel::rank())*2), - static_cast<int>(2+parallel::rank()+i), - static_cast<int>(4-parallel::rank()-i)}; + for (size_t i = 0; i < array.size(); ++i) { + array[i] = + mpi_check::tri_int{static_cast<int>((3 + parallel::rank()) * 2), + static_cast<int>(2 + parallel::rank() + i), + static_cast<int>(4 - parallel::rank() - i)}; } - Array<mpi_check::tri_int> gather_array - = parallel::allGather(array); - - REQUIRE(gather_array.size() == array.size()*parallel::size()); - for (size_t i=0; i<gather_array.size(); ++i) { - mpi_check::tri_int expected_value{static_cast<int>((3+i/array.size())*2), - static_cast<int>(2+i/array.size()+(i%array.size())), - static_cast<int>(4-i/array.size()-(i%array.size()))}; + Array<mpi_check::tri_int> gather_array = parallel::allGather(array); + + REQUIRE(gather_array.size() == array.size() * parallel::size()); + for (size_t i = 0; i < gather_array.size(); ++i) { + mpi_check::tri_int expected_value{ + static_cast<int>((3 + i / array.size()) * 2), + static_cast<int>(2 + i / array.size() + (i % array.size())), + static_cast<int>(4 - i / array.size() - (i % array.size()))}; REQUIRE((gather_array[i] == expected_value)); } } } - SECTION("all array exchanges") { - { // simple type + SECTION("all array exchanges") + { + { // simple type std::vector<Array<const int>> send_array_list(parallel::size()); - for (size_t i=0; i<send_array_list.size(); ++i) { - Array<int> send_array(i+1); - for (size_t j=0; j<send_array.size(); ++j) { - send_array[j] = (parallel::rank()+1)*j; + for (size_t i = 0; i < send_array_list.size(); ++i) { + Array<int> send_array(i + 1); + for (size_t j = 0; j < send_array.size(); ++j) { + send_array[j] = (parallel::rank() + 1) * j; } send_array_list[i] = send_array; } std::vector<Array<int>> recv_array_list(parallel::size()); - for (size_t i=0; i<recv_array_list.size(); ++i) { - recv_array_list[i] = Array<int>(parallel::rank()+1); + for (size_t i = 0; i < recv_array_list.size(); ++i) { + recv_array_list[i] = Array<int>(parallel::rank() + 1); } parallel::exchange(send_array_list, recv_array_list); - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { const Array<const int> recv_array = recv_array_list[i]; - for (size_t j=0; j<recv_array.size(); ++j) { - REQUIRE(recv_array[j] == (i+1)*j); + for (size_t j = 0; j < recv_array.size(); ++j) { + REQUIRE(recv_array[j] == (i + 1) * j); } } } - { // trivial simple type + { // trivial simple type std::vector<Array<mpi_check::integer>> send_array_list(parallel::size()); - for (size_t i=0; i<send_array_list.size(); ++i) { - Array<mpi_check::integer> send_array(i+1); - for (size_t j=0; j<send_array.size(); ++j) { - send_array[j] = static_cast<int>((parallel::rank()+1)*j); + for (size_t i = 0; i < send_array_list.size(); ++i) { + Array<mpi_check::integer> send_array(i + 1); + for (size_t j = 0; j < send_array.size(); ++j) { + send_array[j] = static_cast<int>((parallel::rank() + 1) * j); } send_array_list[i] = send_array; } std::vector<Array<mpi_check::integer>> recv_array_list(parallel::size()); - for (size_t i=0; i<recv_array_list.size(); ++i) { - recv_array_list[i] = Array<mpi_check::integer>(parallel::rank()+1); + for (size_t i = 0; i < recv_array_list.size(); ++i) { + recv_array_list[i] = Array<mpi_check::integer>(parallel::rank() + 1); } parallel::exchange(send_array_list, recv_array_list); - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { const Array<const mpi_check::integer> recv_array = recv_array_list[i]; - for (size_t j=0; j<recv_array.size(); ++j) { - REQUIRE(recv_array[j] == (i+1)*j); + for (size_t j = 0; j < recv_array.size(); ++j) { + REQUIRE(recv_array[j] == (i + 1) * j); } } } @@ -358,26 +386,26 @@ TEST_CASE("Messenger", "[mpi]") { { // compound trivial type std::vector<Array<mpi_check::tri_int>> send_array_list(parallel::size()); - for (size_t i=0; i<send_array_list.size(); ++i) { - Array<mpi_check::tri_int> send_array(i+1); - for (size_t j=0; j<send_array.size(); ++j) { - send_array[j] = mpi_check::tri_int{static_cast<int>((parallel::rank()+1)*j), - static_cast<int>(parallel::rank()), - static_cast<int>(j)}; + for (size_t i = 0; i < send_array_list.size(); ++i) { + Array<mpi_check::tri_int> send_array(i + 1); + for (size_t j = 0; j < send_array.size(); ++j) { + send_array[j] = mpi_check::tri_int{ + static_cast<int>((parallel::rank() + 1) * j), + static_cast<int>(parallel::rank()), static_cast<int>(j)}; } send_array_list[i] = send_array; } std::vector<Array<mpi_check::tri_int>> recv_array_list(parallel::size()); - for (size_t i=0; i<recv_array_list.size(); ++i) { - recv_array_list[i] = Array<mpi_check::tri_int>(parallel::rank()+1); + for (size_t i = 0; i < recv_array_list.size(); ++i) { + recv_array_list[i] = Array<mpi_check::tri_int>(parallel::rank() + 1); } parallel::exchange(send_array_list, recv_array_list); - for (size_t i=0; i<parallel::size(); ++i) { + for (size_t i = 0; i < parallel::size(); ++i) { const Array<const mpi_check::tri_int> recv_array = recv_array_list[i]; - for (size_t j=0; j<recv_array.size(); ++j) { - mpi_check::tri_int expected_value{static_cast<int>((i+1)*j), + for (size_t j = 0; j < recv_array.size(); ++j) { + mpi_check::tri_int expected_value{static_cast<int>((i + 1) * j), static_cast<int>(i), static_cast<int>(j)}; REQUIRE((recv_array[j] == expected_value)); @@ -387,25 +415,27 @@ TEST_CASE("Messenger", "[mpi]") { } #ifndef NDEBUG - SECTION("checking all array exchange invalid sizes") { + SECTION("checking all array exchange invalid sizes") + { std::vector<Array<const int>> send_array_list(parallel::size()); - for (size_t i=0; i<send_array_list.size(); ++i) { - Array<int> send_array(i+1); + for (size_t i = 0; i < send_array_list.size(); ++i) { + Array<int> send_array(i + 1); send_array.fill(parallel::rank()); send_array_list[i] = send_array; } std::vector<Array<int>> recv_array_list(parallel::size()); - REQUIRE_THROWS_AS(parallel::exchange(send_array_list, recv_array_list), AssertError); + REQUIRE_THROWS_AS(parallel::exchange(send_array_list, recv_array_list), + AssertError); } -#endif // NDEBUG - +#endif // NDEBUG - SECTION("checking barrier") { - for (size_t i=0; i<parallel::size(); ++i) { - if (i==parallel::rank()) { + SECTION("checking barrier") + { + for (size_t i = 0; i < parallel::size(); ++i) { + if (i == parallel::rank()) { std::ofstream file; - if (i==0) { + if (i == 0) { file.open("barrier_test", std::ios_base::out); } else { file.open("barrier_test", std::ios_base::app); @@ -415,7 +445,7 @@ TEST_CASE("Messenger", "[mpi]") { parallel::barrier(); } - { // reading produced file + { // reading produced file std::ifstream file("barrier_test"); std::vector<size_t> number_list; while (file) { @@ -426,7 +456,7 @@ TEST_CASE("Messenger", "[mpi]") { } } REQUIRE(number_list.size() == parallel::size()); - for (size_t i=0; i<number_list.size(); ++i) { + for (size_t i = 0; i < number_list.size(); ++i) { REQUIRE(number_list[i] == i); } } diff --git a/tests/mpi_test_main.cpp b/tests/mpi_test_main.cpp index c3b8593f3..43512cc5e 100644 --- a/tests/mpi_test_main.cpp +++ b/tests/mpi_test_main.cpp @@ -6,16 +6,17 @@ #include <cstdlib> -int main( int argc, char* argv[] ) +int +main(int argc, char* argv[]) { - parallel::Messenger::create(argc, argv); - Kokkos::initialize({4,-1,-1,true}); + parallel::Messenger::create(argc, argv); + Kokkos::initialize({4, -1, -1, true}); if (parallel::rank() != 0) { setenv("GCOV_PREFIX", "/dev/null", 1); } - int result = Catch::Session().run( argc, argv ); + int result = Catch::Session().run(argc, argv); Kokkos::finalize(); parallel::Messenger::destroy(); diff --git a/tests/test_Array.cpp b/tests/test_Array.cpp index 8bac68679..6ddd5e7f2 100644 --- a/tests/test_Array.cpp +++ b/tests/test_Array.cpp @@ -1,155 +1,127 @@ #include <catch.hpp> -#include <PastisAssert.hpp> #include <Array.hpp> +#include <PastisAssert.hpp> #include <Types.hpp> -#include <vector> -#include <set> -#include <list> #include <deque> -#include <valarray> +#include <list> +#include <set> #include <unordered_set> +#include <valarray> +#include <vector> // Instantiate to ensure full coverage is performed template class Array<int>; -TEST_CASE("Array", "[utils]") { - +TEST_CASE("Array", "[utils]") +{ Array<int> a(10); REQUIRE(a.size() == 10); - for (size_t i=0; i<a.size(); ++i) { - a[i] = 2*i; + for (size_t i = 0; i < a.size(); ++i) { + a[i] = 2 * i; } - REQUIRE(((a[0] == 0) and (a[1] == 2) and - (a[2] == 4) and (a[3] == 6) and - (a[4] == 8) and (a[5] ==10) and - (a[6] ==12) and (a[7] ==14) and - (a[8] ==16) and (a[9] ==18))); + REQUIRE(((a[0] == 0) and (a[1] == 2) and (a[2] == 4) and (a[3] == 6) and + (a[4] == 8) and (a[5] == 10) and (a[6] == 12) and (a[7] == 14) and + (a[8] == 16) and (a[9] == 18))); - SECTION("checking for copies") { + SECTION("checking for copies") + { Array<const int> b{a}; - REQUIRE(((b[0] == 0) and (b[1] == 2) and - (b[2] == 4) and (b[3] == 6) and - (b[4] == 8) and (b[5] ==10) and - (b[6] ==12) and (b[7] ==14) and - (b[8] ==16) and (b[9] ==18))); + REQUIRE(((b[0] == 0) and (b[1] == 2) and (b[2] == 4) and (b[3] == 6) and + (b[4] == 8) and (b[5] == 10) and (b[6] == 12) and (b[7] == 14) and + (b[8] == 16) and (b[9] == 18))); Array<int> c{a}; - REQUIRE(((c[0] == 0) and (c[1] == 2) and - (c[2] == 4) and (c[3] == 6) and - (c[4] == 8) and (c[5] ==10) and - (c[6] ==12) and (c[7] ==14) and - (c[8] ==16) and (c[9] ==18))); - + REQUIRE(((c[0] == 0) and (c[1] == 2) and (c[2] == 4) and (c[3] == 6) and + (c[4] == 8) and (c[5] == 10) and (c[6] == 12) and (c[7] == 14) and + (c[8] == 16) and (c[9] == 18))); Array<int> d = std::move(c); - REQUIRE(((d[0] == 0) and (d[1] == 2) and - (d[2] == 4) and (d[3] == 6) and - (d[4] == 8) and (d[5] ==10) and - (d[6] ==12) and (d[7] ==14) and - (d[8] ==16) and (d[9] ==18))); - + REQUIRE(((d[0] == 0) and (d[1] == 2) and (d[2] == 4) and (d[3] == 6) and + (d[4] == 8) and (d[5] == 10) and (d[6] == 12) and (d[7] == 14) and + (d[8] == 16) and (d[9] == 18))); } - SECTION("checking for fill") { + SECTION("checking for fill") + { Array<int> b(10); b.fill(3); - REQUIRE(((b[0] == 3) and (b[1] == 3) and - (b[2] == 3) and (b[3] == 3) and - (b[4] == 3) and (b[5] == 3) and - (b[6] == 3) and (b[7] == 3) and + REQUIRE(((b[0] == 3) and (b[1] == 3) and (b[2] == 3) and (b[3] == 3) and + (b[4] == 3) and (b[5] == 3) and (b[6] == 3) and (b[7] == 3) and (b[8] == 3) and (b[9] == 3))); - } - SECTION("checking for affectations (shallow copy)") { + SECTION("checking for affectations (shallow copy)") + { Array<const int> b; b = a; - REQUIRE(((b[0] == 0) and (b[1] == 2) and - (b[2] == 4) and (b[3] == 6) and - (b[4] == 8) and (b[5] ==10) and - (b[6] ==12) and (b[7] ==14) and - (b[8] ==16) and (b[9] ==18))); - + REQUIRE(((b[0] == 0) and (b[1] == 2) and (b[2] == 4) and (b[3] == 6) and + (b[4] == 8) and (b[5] == 10) and (b[6] == 12) and (b[7] == 14) and + (b[8] == 16) and (b[9] == 18))); Array<int> c; c = a; - REQUIRE(((c[0] == 0) and (c[1] == 2) and - (c[2] == 4) and (c[3] == 6) and - (c[4] == 8) and (c[5] ==10) and - (c[6] ==12) and (c[7] ==14) and - (c[8] ==16) and (c[9] ==18))); + REQUIRE(((c[0] == 0) and (c[1] == 2) and (c[2] == 4) and (c[3] == 6) and + (c[4] == 8) and (c[5] == 10) and (c[6] == 12) and (c[7] == 14) and + (c[8] == 16) and (c[9] == 18))); Array<int> d; d = std::move(c); - REQUIRE(((d[0] == 0) and (d[1] == 2) and - (d[2] == 4) and (d[3] == 6) and - (d[4] == 8) and (d[5] ==10) and - (d[6] ==12) and (d[7] ==14) and - (d[8] ==16) and (d[9] ==18))); - + REQUIRE(((d[0] == 0) and (d[1] == 2) and (d[2] == 4) and (d[3] == 6) and + (d[4] == 8) and (d[5] == 10) and (d[6] == 12) and (d[7] == 14) and + (d[8] == 16) and (d[9] == 18))); } - SECTION("checking for affectations (deep copy)") { + SECTION("checking for affectations (deep copy)") + { Array<int> b(copy(a)); - REQUIRE(((b[0] == 0) and (b[1] == 2) and - (b[2] == 4) and (b[3] == 6) and - (b[4] == 8) and (b[5] ==10) and - (b[6] ==12) and (b[7] ==14) and - (b[8] ==16) and (b[9] ==18))); + REQUIRE(((b[0] == 0) and (b[1] == 2) and (b[2] == 4) and (b[3] == 6) and + (b[4] == 8) and (b[5] == 10) and (b[6] == 12) and (b[7] == 14) and + (b[8] == 16) and (b[9] == 18))); b.fill(2); - REQUIRE(((a[0] == 0) and (a[1] == 2) and - (a[2] == 4) and (a[3] == 6) and - (a[4] == 8) and (a[5] ==10) and - (a[6] ==12) and (a[7] ==14) and - (a[8] ==16) and (a[9] ==18))); + REQUIRE(((a[0] == 0) and (a[1] == 2) and (a[2] == 4) and (a[3] == 6) and + (a[4] == 8) and (a[5] == 10) and (a[6] == 12) and (a[7] == 14) and + (a[8] == 16) and (a[9] == 18))); - REQUIRE(((b[0] == 2) and (b[1] == 2) and - (b[2] == 2) and (b[3] == 2) and - (b[4] == 2) and (b[5] == 2) and - (b[6] == 2) and (b[7] == 2) and + REQUIRE(((b[0] == 2) and (b[1] == 2) and (b[2] == 2) and (b[3] == 2) and + (b[4] == 2) and (b[5] == 2) and (b[6] == 2) and (b[7] == 2) and (b[8] == 2) and (b[9] == 2))); Array<int> c; c = a; - REQUIRE(((c[0] == 0) and (c[1] == 2) and - (c[2] == 4) and (c[3] == 6) and - (c[4] == 8) and (c[5] ==10) and - (c[6] ==12) and (c[7] ==14) and - (c[8] ==16) and (c[9] ==18))); + REQUIRE(((c[0] == 0) and (c[1] == 2) and (c[2] == 4) and (c[3] == 6) and + (c[4] == 8) and (c[5] == 10) and (c[6] == 12) and (c[7] == 14) and + (c[8] == 16) and (c[9] == 18))); c = copy(b); - REQUIRE(((a[0] == 0) and (a[1] == 2) and - (a[2] == 4) and (a[3] == 6) and - (a[4] == 8) and (a[5] ==10) and - (a[6] ==12) and (a[7] ==14) and - (a[8] ==16) and (a[9] ==18))); + REQUIRE(((a[0] == 0) and (a[1] == 2) and (a[2] == 4) and (a[3] == 6) and + (a[4] == 8) and (a[5] == 10) and (a[6] == 12) and (a[7] == 14) and + (a[8] == 16) and (a[9] == 18))); - REQUIRE(((c[0] == 2) and (c[1] == 2) and - (c[2] == 2) and (c[3] == 2) and - (c[4] == 2) and (c[5] == 2) and - (c[6] == 2) and (c[7] == 2) and + REQUIRE(((c[0] == 2) and (c[1] == 2) and (c[2] == 2) and (c[3] == 2) and + (c[4] == 2) and (c[5] == 2) and (c[6] == 2) and (c[7] == 2) and (c[8] == 2) and (c[9] == 2))); } - SECTION("checking for std container conversion") { + SECTION("checking for std container conversion") + { { - std::vector<int> v{1,2,5,3}; + std::vector<int> v{1, 2, 5, 3}; { Array<int> v_array = convert_to_array(v); @@ -170,42 +142,41 @@ TEST_CASE("Array", "[utils]") { { std::vector<int> w; { - Array<int> w_array = convert_to_array(w); + Array<int> w_array = convert_to_array(w); REQUIRE(w_array.size() == 0); } { - Array<const int> w_array = convert_to_array(w); + Array<const int> w_array = convert_to_array(w); REQUIRE(w_array.size() == 0); } } { - std::valarray<int> v{1,2,5,3}; + std::valarray<int> v{1, 2, 5, 3}; Array<int> v_array = convert_to_array(v); REQUIRE(v_array.size() == v.size()); - REQUIRE(((v_array[0] == 1) and (v_array[1] == 2) and - (v_array[2] == 5) and (v_array[3] == 3))); + REQUIRE(((v_array[0] == 1) and (v_array[1] == 2) and (v_array[2] == 5) and + (v_array[3] == 3))); } { - std::set<int> s{4,2,5,3,1,3,2}; + std::set<int> s{4, 2, 5, 3, 1, 3, 2}; Array<int> s_array = convert_to_array(s); REQUIRE(s_array.size() == s.size()); - REQUIRE(((s_array[0] == 1) and (s_array[1] == 2) and - (s_array[2] == 3) and (s_array[3] == 4) and - (s_array[4] == 5))); + REQUIRE(((s_array[0] == 1) and (s_array[1] == 2) and (s_array[2] == 3) and + (s_array[3] == 4) and (s_array[4] == 5))); } { - std::unordered_set<int> us{4,2,5,3,1,3,2}; + std::unordered_set<int> us{4, 2, 5, 3, 1, 3, 2}; Array<int> us_array = convert_to_array(us); REQUIRE(us_array.size() == us.size()); std::set<int> s; - for (size_t i=0; i<us_array.size(); ++i) { + for (size_t i = 0; i < us_array.size(); ++i) { REQUIRE((us.find(us_array[i]) != us.end())); s.insert(us_array[i]); } @@ -213,7 +184,7 @@ TEST_CASE("Array", "[utils]") { } { - std::multiset<int> ms{4,2,5,3,1,3,2}; + std::multiset<int> ms{4, 2, 5, 3, 1, 3, 2}; Array<int> ms_array = convert_to_array(ms); REQUIRE(ms_array.size() == ms.size()); @@ -224,30 +195,29 @@ TEST_CASE("Array", "[utils]") { } { - std::list<int> l{1,3,5,6,2}; + std::list<int> l{1, 3, 5, 6, 2}; Array<int> l_array = convert_to_array(l); REQUIRE(l_array.size() == l.size()); - REQUIRE(((l_array[0] == 1) and (l_array[1] == 3) and - (l_array[2] == 5) and (l_array[3] == 6) and - (l_array[4] == 2))); + REQUIRE(((l_array[0] == 1) and (l_array[1] == 3) and (l_array[2] == 5) and + (l_array[3] == 6) and (l_array[4] == 2))); } { - std::deque<int> q{1,3,5,6,2}; + std::deque<int> q{1, 3, 5, 6, 2}; q.push_front(2); Array<int> q_array = convert_to_array(q); REQUIRE(q_array.size() == q.size()); - REQUIRE(((q_array[0] == 2) and (q_array[1] == 1) and - (q_array[2] == 3) and (q_array[3] == 5) and - (q_array[4] == 6) and (q_array[5] == 2))); + REQUIRE(((q_array[0] == 2) and (q_array[1] == 1) and (q_array[2] == 3) and + (q_array[3] == 5) and (q_array[4] == 6) and (q_array[5] == 2))); } } #ifndef NDEBUG - SECTION("checking for bounds violation") { + SECTION("checking for bounds violation") + { REQUIRE_THROWS_AS(a[10], AssertError); } -#endif // NDEBUG +#endif // NDEBUG } diff --git a/tests/test_ArrayUtils.cpp b/tests/test_ArrayUtils.cpp index 9d5666785..64582023f 100644 --- a/tests/test_ArrayUtils.cpp +++ b/tests/test_ArrayUtils.cpp @@ -1,75 +1,80 @@ #include <catch.hpp> -#include <PastisAssert.hpp> #include <Array.hpp> #include <ArrayUtils.hpp> +#include <PastisAssert.hpp> -#include <TinyVector.hpp> #include <TinyMatrix.hpp> +#include <TinyVector.hpp> // Instantiate to ensure full coverage is performed template class Array<int>; -TEST_CASE("ArrayUtils", "[utils]") { - - SECTION("checking for Array reductions") { +TEST_CASE("ArrayUtils", "[utils]") +{ + SECTION("checking for Array reductions") + { Array<int> a(10); - a[0] =13; + a[0] = 13; a[1] = 1; a[2] = 8; - a[3] =-3; - a[4] =23; - a[5] =-1; - a[6] =13; + a[3] = -3; + a[4] = 23; + a[5] = -1; + a[6] = 13; a[7] = 0; - a[8] =12; + a[8] = 12; a[9] = 9; - SECTION("Min") { + SECTION("Min") + { REQUIRE((min(a) == -3)); } - SECTION("Max") { + SECTION("Max") + { REQUIRE((max(a) == 23)); } - SECTION("Sum") { + SECTION("Sum") + { REQUIRE((sum(a) == 75)); } - SECTION("TinyVector Sum") { - using N2 = TinyVector<2,int>; + SECTION("TinyVector Sum") + { + using N2 = TinyVector<2, int>; Array<N2> b(10); - b[0] ={13, 2}; + b[0] = {13, 2}; b[1] = {1, 3}; b[2] = {8, -2}; - b[3] ={-3, 2}; - b[4] ={23, 4}; - b[5] ={-1, -3}; - b[6] ={13, 17}; + b[3] = {-3, 2}; + b[4] = {23, 4}; + b[5] = {-1, -3}; + b[6] = {13, 17}; b[7] = {0, 9}; - b[8] ={12, 13}; + b[8] = {12, 13}; b[9] = {9, -17}; REQUIRE((sum(b) == N2{75, 28})); } - SECTION("TinyMatrix Sum") { - using N22 = TinyMatrix<2,int>; + SECTION("TinyMatrix Sum") + { + using N22 = TinyMatrix<2, int>; Array<N22> b(10); - b[0] ={13, 2, 0, 1}; - b[1] = {1, 3, 6, 3}; + b[0] = {13, 2, 0, 1}; + b[1] = {1, 3, 6, 3}; b[2] = {8, -2, -1, 21}; - b[3] ={-3, 2, 5, 12}; - b[4] ={23, 4, 7, 1}; - b[5] ={-1, -3, 33, 11}; - b[6] ={13, 17, 12, 13}; - b[7] = {0, 9, 1, 14}; - b[8] ={12, 13, -3,-71}; - b[9] = {9,-17, 0, 16}; + b[3] = {-3, 2, 5, 12}; + b[4] = {23, 4, 7, 1}; + b[5] = {-1, -3, 33, 11}; + b[6] = {13, 17, 12, 13}; + b[7] = {0, 9, 1, 14}; + b[8] = {12, 13, -3, -71}; + b[9] = {9, -17, 0, 16}; REQUIRE((sum(b) == N22{75, 28, 60, 21})); } - } } diff --git a/tests/test_ItemType.cpp b/tests/test_ItemType.cpp index 600b0882e..80ba82920 100644 --- a/tests/test_ItemType.cpp +++ b/tests/test_ItemType.cpp @@ -1,49 +1,51 @@ -#include <catch.hpp> #include <PastisMacros.hpp> +#include <catch.hpp> #include <ItemType.hpp> -TEST_CASE("ItemType", "[connectivity]") { - +TEST_CASE("ItemType", "[connectivity]") +{ ItemType node_type = ItemType::node; ItemType edge_type = ItemType::edge; ItemType face_type = ItemType::face; ItemType cell_type = ItemType::cell; - SECTION("checking for item type differences") { - REQUIRE(((node_type != edge_type) and - (node_type != face_type) and - (node_type != cell_type) and - (edge_type != face_type) and - (edge_type != cell_type) and - (face_type != cell_type))); + SECTION("checking for item type differences") + { + REQUIRE(((node_type != edge_type) and (node_type != face_type) and + (node_type != cell_type) and (edge_type != face_type) and + (edge_type != cell_type) and (face_type != cell_type))); } - SECTION("checking for item type names") { - REQUIRE(itemName(node_type)=="node"); - REQUIRE(itemName(edge_type)=="edge"); - REQUIRE(itemName(face_type)=="face"); - REQUIRE(itemName(cell_type)=="cell"); + SECTION("checking for item type names") + { + REQUIRE(itemName(node_type) == "node"); + REQUIRE(itemName(edge_type) == "edge"); + REQUIRE(itemName(face_type) == "face"); + REQUIRE(itemName(cell_type) == "cell"); } - SECTION("checking for item ids in 1d") { - REQUIRE(ItemTypeId<1>::itemTId(cell_type)==0); - REQUIRE(ItemTypeId<1>::itemTId(edge_type)==1); - REQUIRE(ItemTypeId<1>::itemTId(face_type)==1); - REQUIRE(ItemTypeId<1>::itemTId(node_type)==1); + SECTION("checking for item ids in 1d") + { + REQUIRE(ItemTypeId<1>::itemTId(cell_type) == 0); + REQUIRE(ItemTypeId<1>::itemTId(edge_type) == 1); + REQUIRE(ItemTypeId<1>::itemTId(face_type) == 1); + REQUIRE(ItemTypeId<1>::itemTId(node_type) == 1); } - SECTION("checking for item ids in 2d") { - REQUIRE(ItemTypeId<2>::itemTId(cell_type)==0); - REQUIRE(ItemTypeId<2>::itemTId(edge_type)==1); - REQUIRE(ItemTypeId<2>::itemTId(face_type)==1); - REQUIRE(ItemTypeId<2>::itemTId(node_type)==2); + SECTION("checking for item ids in 2d") + { + REQUIRE(ItemTypeId<2>::itemTId(cell_type) == 0); + REQUIRE(ItemTypeId<2>::itemTId(edge_type) == 1); + REQUIRE(ItemTypeId<2>::itemTId(face_type) == 1); + REQUIRE(ItemTypeId<2>::itemTId(node_type) == 2); } - SECTION("checking for item ids in 3d") { - REQUIRE(ItemTypeId<3>::itemTId(cell_type)==0); - REQUIRE(ItemTypeId<3>::itemTId(edge_type)==1); - REQUIRE(ItemTypeId<3>::itemTId(face_type)==2); - REQUIRE(ItemTypeId<3>::itemTId(node_type)==3); + SECTION("checking for item ids in 3d") + { + REQUIRE(ItemTypeId<3>::itemTId(cell_type) == 0); + REQUIRE(ItemTypeId<3>::itemTId(edge_type) == 1); + REQUIRE(ItemTypeId<3>::itemTId(face_type) == 2); + REQUIRE(ItemTypeId<3>::itemTId(node_type) == 3); } } diff --git a/tests/test_PastisAssert.cpp b/tests/test_PastisAssert.cpp index 90995c30f..e6230e419 100644 --- a/tests/test_PastisAssert.cpp +++ b/tests/test_PastisAssert.cpp @@ -3,27 +3,36 @@ #include <PastisAssert.hpp> #include <string> -TEST_CASE("PastisAssert", "[utils]") { - SECTION("checking for assert error") { +TEST_CASE("PastisAssert", "[utils]") +{ + SECTION("checking for assert error") + { const std::string filename = "filename"; - const int line = 10; + const int line = 10; const std::string function = "function"; - const std::string test = "test"; + const std::string test = "test"; AssertError assert_error(filename, line, function, test); - REQUIRE(Catch::Detail::stringify(assert_error) == "\n---------- Assertion error -----------\n at filename:10\n in function\n assertion (test) failed!\n--------------------------------------\n"); + REQUIRE(Catch::Detail::stringify(assert_error) == + "\n---------- Assertion error -----------\n at filename:10\n in " + "function\n assertion (test) " + "failed!\n--------------------------------------\n"); } - SECTION("checking for assert error with message") { + SECTION("checking for assert error with message") + { const std::string filename = "filename"; - const int line = 10; + const int line = 10; const std::string function = "function"; - const std::string test = "test"; - const std::string message = "message"; + const std::string test = "test"; + const std::string message = "message"; AssertError assert_error(filename, line, function, test, message); - REQUIRE(Catch::Detail::stringify(assert_error) == "\n---------- Assertion error -----------\n at filename:10\n in function\n assertion (test) failed!\n message\n--------------------------------------\n"); + REQUIRE(Catch::Detail::stringify(assert_error) == + "\n---------- Assertion error -----------\n at filename:10\n in " + "function\n assertion (test) failed!\n " + "message\n--------------------------------------\n"); } } diff --git a/tests/test_RevisionInfo.cpp b/tests/test_RevisionInfo.cpp index a426866ed..7906f9e36 100644 --- a/tests/test_RevisionInfo.cpp +++ b/tests/test_RevisionInfo.cpp @@ -5,30 +5,33 @@ #include <pastis_git_revision.hpp> #include <pastis_version.hpp> -TEST_CASE("RevisionInfo", "[utils]") { - - SECTION("checking pastis version") { - REQUIRE( (RevisionInfo::version() == PASTIS_VERSION) ); +TEST_CASE("RevisionInfo", "[utils]") +{ + SECTION("checking pastis version") + { + REQUIRE((RevisionInfo::version() == PASTIS_VERSION)); } - SECTION("checking git info") { + SECTION("checking git info") + { #ifdef HAS_PASTIS_GIT_INFO - REQUIRE( (RevisionInfo::hasGitInfo() == true) ); - REQUIRE( (RevisionInfo::gitTag() == PASTIS_GIT_TAG) ); - REQUIRE( (RevisionInfo::gitHead() == PASTIS_GIT_HEAD) ); - REQUIRE( (RevisionInfo::gitHash() == PASTIS_GIT_HASH) ); - REQUIRE( (RevisionInfo::gitIsClean() == PASTIS_GIT_IS_CLEAN) ); + REQUIRE((RevisionInfo::hasGitInfo() == true)); + REQUIRE((RevisionInfo::gitTag() == PASTIS_GIT_TAG)); + REQUIRE((RevisionInfo::gitHead() == PASTIS_GIT_HEAD)); + REQUIRE((RevisionInfo::gitHash() == PASTIS_GIT_HASH)); + REQUIRE((RevisionInfo::gitIsClean() == PASTIS_GIT_IS_CLEAN)); - SECTION("checking tag") { + SECTION("checking tag") + { std::string tag_from_version = "v"; tag_from_version += std::string(PASTIS_VERSION); - REQUIRE( tag_from_version == RevisionInfo::gitTag()); + REQUIRE(tag_from_version == RevisionInfo::gitTag()); } #else - REQUIRE( (RevisionInfo::hasGitInfo() == false) ); - REQUIRE( (RevisionInfo::gitTag() == "unknown tag") ); - REQUIRE( (RevisionInfo::gitHead() == "unknown head") ); - REQUIRE( (RevisionInfo::gitHash() == "unknown hash") ); - REQUIRE( (RevisionInfo::gitIsClean() == false) ); + REQUIRE((RevisionInfo::hasGitInfo() == false)); + REQUIRE((RevisionInfo::gitTag() == "unknown tag")); + REQUIRE((RevisionInfo::gitHead() == "unknown head")); + REQUIRE((RevisionInfo::gitHash() == "unknown hash")); + REQUIRE((RevisionInfo::gitIsClean() == false)); #endif } } diff --git a/tests/test_TinyMatrix.cpp b/tests/test_TinyMatrix.cpp index 62f613442..6cbefa138 100644 --- a/tests/test_TinyMatrix.cpp +++ b/tests/test_TinyMatrix.cpp @@ -1,239 +1,226 @@ #include <catch.hpp> -#include <TinyMatrix.hpp> -#include <PastisAssert.hpp> #include <Kokkos_Core.hpp> +#include <PastisAssert.hpp> +#include <TinyMatrix.hpp> #include <Types.hpp> // Instantiate to ensure full coverage is performed -template class TinyMatrix<1,int>; -template class TinyMatrix<2,int>; -template class TinyMatrix<3,int>; -template class TinyMatrix<4,double>; - -TEST_CASE("TinyMatrix", "[algebra]") { - TinyMatrix<3, int> A(1,2,3, - 4,5,6, - 7,8,9); - REQUIRE(((A(0,0)==1) and (A(0,1)==2) and (A(0,2)==3) and - (A(1,0)==4) and (A(1,1)==5) and (A(1,2)==6) and - (A(2,0)==7) and (A(2,1)==8) and (A(2,2)==9))); - - TinyMatrix<3,int> B(6,5,3, - 8,34,6, - 35,6,7); - SECTION("checking for opposed matrix") { +template class TinyMatrix<1, int>; +template class TinyMatrix<2, int>; +template class TinyMatrix<3, int>; +template class TinyMatrix<4, double>; + +TEST_CASE("TinyMatrix", "[algebra]") +{ + TinyMatrix<3, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9); + REQUIRE(((A(0, 0) == 1) and (A(0, 1) == 2) and (A(0, 2) == 3) and + (A(1, 0) == 4) and (A(1, 1) == 5) and (A(1, 2) == 6) and + (A(2, 0) == 7) and (A(2, 1) == 8) and (A(2, 2) == 9))); + + TinyMatrix<3, int> B(6, 5, 3, 8, 34, 6, 35, 6, 7); + SECTION("checking for opposed matrix") + { const TinyMatrix<3, int> minus_A = -A; - REQUIRE(((minus_A(0,0)==-1) and (minus_A(0,1)==-2) and (minus_A(0,2)==-3) and - (minus_A(1,0)==-4) and (minus_A(1,1)==-5) and (minus_A(1,2)==-6) and - (minus_A(2,0)==-7) and (minus_A(2,1)==-8) and (minus_A(2,2)==-9))); - } - SECTION("checking for equality and difference tests") { + REQUIRE(((minus_A(0, 0) == -1) and (minus_A(0, 1) == -2) and + (minus_A(0, 2) == -3) and (minus_A(1, 0) == -4) and + (minus_A(1, 1) == -5) and (minus_A(1, 2) == -6) and + (minus_A(2, 0) == -7) and (minus_A(2, 1) == -8) and + (minus_A(2, 2) == -9))); + } + SECTION("checking for equality and difference tests") + { const TinyMatrix<3, int> copy_A = A; - REQUIRE(((copy_A(0,0)==1) and (copy_A(0,1)==2) and (copy_A(0,2)==3) and - (copy_A(1,0)==4) and (copy_A(1,1)==5) and (copy_A(1,2)==6) and - (copy_A(2,0)==7) and (copy_A(2,1)==8) and (copy_A(2,2)==9))); - REQUIRE(copy_A==A); - REQUIRE_FALSE(copy_A!=A); + REQUIRE( + ((copy_A(0, 0) == 1) and (copy_A(0, 1) == 2) and (copy_A(0, 2) == 3) and + (copy_A(1, 0) == 4) and (copy_A(1, 1) == 5) and (copy_A(1, 2) == 6) and + (copy_A(2, 0) == 7) and (copy_A(2, 1) == 8) and (copy_A(2, 2) == 9))); + REQUIRE(copy_A == A); + REQUIRE_FALSE(copy_A != A); - TinyMatrix<3, int> affected_A; affected_A = A; - REQUIRE(affected_A==A); - REQUIRE_FALSE(affected_A!=A); + TinyMatrix<3, int> affected_A; + affected_A = A; + REQUIRE(affected_A == A); + REQUIRE_FALSE(affected_A != A); - REQUIRE(A!=B); - REQUIRE_FALSE(A==B); + REQUIRE(A != B); + REQUIRE_FALSE(A == B); } - SECTION("checking for scalar left product") { - const int a = 2; - const TinyMatrix<3, int> aA = a*A; + SECTION("checking for scalar left product") + { + const int a = 2; + const TinyMatrix<3, int> aA = a * A; - REQUIRE(aA == TinyMatrix<3,int>(2, 4, 6, - 8, 10, 12, - 14, 16, 18)); + REQUIRE(aA == TinyMatrix<3, int>(2, 4, 6, 8, 10, 12, 14, 16, 18)); } - SECTION("checking for scalar seft product") { - const int a = 2; + SECTION("checking for scalar seft product") + { + const int a = 2; TinyMatrix<3, int> copy_A = A; - REQUIRE((copy_A*=a) == TinyMatrix<3,int>(2, 4, 6, - 8, 10, 12, - 14, 16, 18)); + REQUIRE((copy_A *= a) == + TinyMatrix<3, int>(2, 4, 6, 8, 10, 12, 14, 16, 18)); } - SECTION("checking for null matrix management") { + SECTION("checking for null matrix management") + { TinyMatrix<3, int> Z = zero; - REQUIRE(Z == TinyMatrix<3, int>(0,0,0, - 0,0,0, - 0,0,0)); + REQUIRE(Z == TinyMatrix<3, int>(0, 0, 0, 0, 0, 0, 0, 0, 0)); - TinyMatrix<3, int> affected_Z; affected_Z = zero; + TinyMatrix<3, int> affected_Z; + affected_Z = zero; REQUIRE(affected_Z == Z); } - SECTION("checking for identity management") { + SECTION("checking for identity management") + { TinyMatrix<3, int> I = identity; - REQUIRE(I == TinyMatrix<3,int>(1,0,0, - 0,1,0, - 0,0,1)); + REQUIRE(I == TinyMatrix<3, int>(1, 0, 0, 0, 1, 0, 0, 0, 1)); - TinyMatrix<3, int> affected_I; affected_I=identity; - REQUIRE(affected_I==I); + TinyMatrix<3, int> affected_I; + affected_I = identity; + REQUIRE(affected_I == I); } - - SECTION("checking for matrices sum") { - REQUIRE(A+B == TinyMatrix<3,int>(7,7,6, - 12,39,12, - 42,14,16)); + SECTION("checking for matrices sum") + { + REQUIRE(A + B == TinyMatrix<3, int>(7, 7, 6, 12, 39, 12, 42, 14, 16)); TinyMatrix<3, int> ApB = A; ApB += B; - REQUIRE(ApB==A+B); + REQUIRE(ApB == A + B); - TinyMatrix<3, int> Ap2B = A+2*B; - REQUIRE(Ap2B==ApB+B); + TinyMatrix<3, int> Ap2B = A + 2 * B; + REQUIRE(Ap2B == ApB + B); } - SECTION("checking for matrices difference ") { - REQUIRE(A-B == TinyMatrix<3,int>(-5, -3, 0, - -4, -29, 0, - -28, 2, 2)); + SECTION("checking for matrices difference ") + { + REQUIRE(A - B == TinyMatrix<3, int>(-5, -3, 0, -4, -29, 0, -28, 2, 2)); TinyMatrix<3, int> AmB = A; AmB -= B; - REQUIRE(AmB==A-B); + REQUIRE(AmB == A - B); - TinyMatrix<3, int> Am2B = A-2*B; - REQUIRE(Am2B == AmB-B); + TinyMatrix<3, int> Am2B = A - 2 * B; + REQUIRE(Am2B == AmB - B); } - SECTION("checking for matrices product") { - REQUIRE(A*B == TinyMatrix<3,int>(127,91,36, - 274,226,84, - 421,361,132)); + SECTION("checking for matrices product") + { + REQUIRE(A * B == + TinyMatrix<3, int>(127, 91, 36, 274, 226, 84, 421, 361, 132)); } - SECTION("checking for matrix-vector product") { - REQUIRE(A*TinyVector<3,int>(2,-3,5) == TinyVector<3,int>(11,23,35)); + SECTION("checking for matrix-vector product") + { + REQUIRE(A * TinyVector<3, int>(2, -3, 5) == TinyVector<3, int>(11, 23, 35)); } - SECTION("checking for tensor product") { - const TinyVector<3,int> u(1,3,7); - const TinyVector<3,int> v(6,2,-3); + SECTION("checking for tensor product") + { + const TinyVector<3, int> u(1, 3, 7); + const TinyVector<3, int> v(6, 2, -3); - REQUIRE(tensorProduct(u,v)==TinyMatrix<3,int>(6,2,-3, - 18,6,-9, - 42,14,-21)); + REQUIRE(tensorProduct(u, v) == + TinyMatrix<3, int>(6, 2, -3, 18, 6, -9, 42, 14, -21)); } - SECTION("checking for minor calculation") { - TinyMatrix<3,int> A(1,2,3, - 4,5,6, - 7,8,9); - REQUIRE(getMinor(A,0,0)==TinyMatrix<2,int>(5,6, - 8,9)); - REQUIRE(getMinor(A,1,0)==TinyMatrix<2,int>(2,3, - 8,9)); - REQUIRE(getMinor(A,2,0)==TinyMatrix<2,int>(2,3, - 5,6)); + SECTION("checking for minor calculation") + { + TinyMatrix<3, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9); + REQUIRE(getMinor(A, 0, 0) == TinyMatrix<2, int>(5, 6, 8, 9)); + REQUIRE(getMinor(A, 1, 0) == TinyMatrix<2, int>(2, 3, 8, 9)); + REQUIRE(getMinor(A, 2, 0) == TinyMatrix<2, int>(2, 3, 5, 6)); - REQUIRE(getMinor(A,0,1)==TinyMatrix<2,int>(4,6, - 7,9)); - REQUIRE(getMinor(A,1,1)==TinyMatrix<2,int>(1,3, - 7,9)); - REQUIRE(getMinor(A,2,1)==TinyMatrix<2,int>(1,3, - 4,6)); + REQUIRE(getMinor(A, 0, 1) == TinyMatrix<2, int>(4, 6, 7, 9)); + REQUIRE(getMinor(A, 1, 1) == TinyMatrix<2, int>(1, 3, 7, 9)); + REQUIRE(getMinor(A, 2, 1) == TinyMatrix<2, int>(1, 3, 4, 6)); - - REQUIRE(getMinor(A,0,2)==TinyMatrix<2,int>(4,5, - 7,8)); - REQUIRE(getMinor(A,1,2)==TinyMatrix<2,int>(1,2, - 7,8)); - REQUIRE(getMinor(A,2,2)==TinyMatrix<2,int>(1,2, - 4,5)); + REQUIRE(getMinor(A, 0, 2) == TinyMatrix<2, int>(4, 5, 7, 8)); + REQUIRE(getMinor(A, 1, 2) == TinyMatrix<2, int>(1, 2, 7, 8)); + REQUIRE(getMinor(A, 2, 2) == TinyMatrix<2, int>(1, 2, 4, 5)); } - SECTION("checking for cofactors") { - TinyMatrix<3,int> A(1,2,3, - 4,5,6, - 7,8,9); - REQUIRE(cofactor(A,0,0)== (5*9-8*6)); - REQUIRE(cofactor(A,1,0)==-(2*9-8*3)); - REQUIRE(cofactor(A,2,0)== (2*6-5*3)); + SECTION("checking for cofactors") + { + TinyMatrix<3, int> A(1, 2, 3, 4, 5, 6, 7, 8, 9); + REQUIRE(cofactor(A, 0, 0) == (5 * 9 - 8 * 6)); + REQUIRE(cofactor(A, 1, 0) == -(2 * 9 - 8 * 3)); + REQUIRE(cofactor(A, 2, 0) == (2 * 6 - 5 * 3)); - REQUIRE(cofactor(A,0,1)==-(4*9-7*6)); - REQUIRE(cofactor(A,1,1)== (1*9-7*3)); - REQUIRE(cofactor(A,2,1)==-(1*6-4*3)); + REQUIRE(cofactor(A, 0, 1) == -(4 * 9 - 7 * 6)); + REQUIRE(cofactor(A, 1, 1) == (1 * 9 - 7 * 3)); + REQUIRE(cofactor(A, 2, 1) == -(1 * 6 - 4 * 3)); - REQUIRE(cofactor(A,0,2)== (4*8-5*7)); - REQUIRE(cofactor(A,1,2)==-(1*8-7*2)); - REQUIRE(cofactor(A,2,2)== (1*5-4*2)); + REQUIRE(cofactor(A, 0, 2) == (4 * 8 - 5 * 7)); + REQUIRE(cofactor(A, 1, 2) == -(1 * 8 - 7 * 2)); + REQUIRE(cofactor(A, 2, 2) == (1 * 5 - 4 * 2)); } - SECTION("checking for determinant calculations") { - REQUIRE(det(TinyMatrix<1,int>(6))==6); - REQUIRE(det(TinyMatrix<2,int>(3,1, - -3,6))==21); - REQUIRE(det(B)==-1444); - REQUIRE(det(TinyMatrix<4,double> (1,2.3,7,-6.2, - 3,4,9,1, - 4.1,5,2,-3, - 2,27,3,17.5))== Approx(6661.455).epsilon(1E-14)); + SECTION("checking for determinant calculations") + { + REQUIRE(det(TinyMatrix<1, int>(6)) == 6); + REQUIRE(det(TinyMatrix<2, int>(3, 1, -3, 6)) == 21); + REQUIRE(det(B) == -1444); + REQUIRE(det(TinyMatrix<4, double>(1, 2.3, 7, -6.2, 3, 4, 9, 1, 4.1, 5, 2, + -3, 2, 27, 3, 17.5)) == + Approx(6661.455).epsilon(1E-14)); } - SECTION("checking for inverse calculations") { + SECTION("checking for inverse calculations") + { { - const TinyMatrix<1,double> A1(2); - REQUIRE(inverse(A1)(0,0) == Approx(0.5).epsilon(1E-14)); + const TinyMatrix<1, double> A1(2); + REQUIRE(inverse(A1)(0, 0) == Approx(0.5).epsilon(1E-14)); } { - const TinyMatrix<2,double> A2(2,3, - 4,1); - const TinyMatrix<2,double> I = inverse(A2)*A2; - - REQUIRE(I(0,0) == Approx(1).epsilon(1E-14)); - REQUIRE(I(0,1) == Approx(0).margin (1E-14)); - REQUIRE(I(1,0) == Approx(0).margin (1E-14)); - REQUIRE(I(1,1) == Approx(1).epsilon(1E-14)); + const TinyMatrix<2, double> A2(2, 3, 4, 1); + const TinyMatrix<2, double> I = inverse(A2) * A2; + + REQUIRE(I(0, 0) == Approx(1).epsilon(1E-14)); + REQUIRE(I(0, 1) == Approx(0).margin(1E-14)); + REQUIRE(I(1, 0) == Approx(0).margin(1E-14)); + REQUIRE(I(1, 1) == Approx(1).epsilon(1E-14)); } { - const TinyMatrix<3,double> A3(2,3,1, - 4,-1,5, - -2,3,4); - const TinyMatrix<3,double> I = inverse(A3)*A3; - - REQUIRE(I(0,0) == Approx(1).epsilon(1E-14)); - REQUIRE(I(0,1) == Approx(0).margin (1E-14)); - REQUIRE(I(0,2) == Approx(0).margin (1E-14)); - REQUIRE(I(1,0) == Approx(0).margin (1E-14)); - REQUIRE(I(1,1) == Approx(1).epsilon(1E-14)); - REQUIRE(I(1,2) == Approx(0).margin (1E-14)); - REQUIRE(I(2,0) == Approx(0).margin (1E-14)); - REQUIRE(I(2,1) == Approx(0).margin (1E-14)); - REQUIRE(I(2,2) == Approx(1).epsilon(1E-14)); + const TinyMatrix<3, double> A3(2, 3, 1, 4, -1, 5, -2, 3, 4); + const TinyMatrix<3, double> I = inverse(A3) * A3; + + REQUIRE(I(0, 0) == Approx(1).epsilon(1E-14)); + REQUIRE(I(0, 1) == Approx(0).margin(1E-14)); + REQUIRE(I(0, 2) == Approx(0).margin(1E-14)); + REQUIRE(I(1, 0) == Approx(0).margin(1E-14)); + REQUIRE(I(1, 1) == Approx(1).epsilon(1E-14)); + REQUIRE(I(1, 2) == Approx(0).margin(1E-14)); + REQUIRE(I(2, 0) == Approx(0).margin(1E-14)); + REQUIRE(I(2, 1) == Approx(0).margin(1E-14)); + REQUIRE(I(2, 2) == Approx(1).epsilon(1E-14)); } } - SECTION("checking for matrices output") { + SECTION("checking for matrices output") + { REQUIRE(Catch::Detail::stringify(A) == "[(1,2,3)(4,5,6)(7,8,9)]"); - REQUIRE(Catch::Detail::stringify(TinyMatrix<1,int>(7)) == "7"); + REQUIRE(Catch::Detail::stringify(TinyMatrix<1, int>(7)) == "7"); } #ifndef NDEBUG - SECTION("checking for bounds violation") { - REQUIRE_THROWS_AS(A(3,0), AssertError); - REQUIRE_THROWS_AS(A(0,3), AssertError); + SECTION("checking for bounds violation") + { + REQUIRE_THROWS_AS(A(3, 0), AssertError); + REQUIRE_THROWS_AS(A(0, 3), AssertError); - REQUIRE_THROWS_AS(getMinor(A,3,0), AssertError); - REQUIRE_THROWS_AS(getMinor(A,0,3), AssertError); + REQUIRE_THROWS_AS(getMinor(A, 3, 0), AssertError); + REQUIRE_THROWS_AS(getMinor(A, 0, 3), AssertError); - const TinyMatrix<3,int>& constA = A; - REQUIRE_THROWS_AS(constA(3,0), AssertError); - REQUIRE_THROWS_AS(constA(0,3), AssertError); + const TinyMatrix<3, int>& constA = A; + REQUIRE_THROWS_AS(constA(3, 0), AssertError); + REQUIRE_THROWS_AS(constA(0, 3), AssertError); } -#endif // NDEBUG +#endif // NDEBUG } diff --git a/tests/test_TinyVector.cpp b/tests/test_TinyVector.cpp index 5fe7f6165..558ea3772 100644 --- a/tests/test_TinyVector.cpp +++ b/tests/test_TinyVector.cpp @@ -1,83 +1,87 @@ #include <catch.hpp> -#include <TinyVector.hpp> #include <PastisAssert.hpp> +#include <TinyVector.hpp> // Instantiate to ensure full coverage is performed -template class TinyVector<1,int>; -template class TinyVector<3,int>; +template class TinyVector<1, int>; +template class TinyVector<3, int>; -TEST_CASE("TinyVector", "[algebra]") { - TinyVector<3,int> v(1,2,3); +TEST_CASE("TinyVector", "[algebra]") +{ + TinyVector<3, int> v(1, 2, 3); REQUIRE(((v[0] == 1) and (v[1] == 2) and (v[2] == 3))); - REQUIRE(-v == TinyVector<3,int>(-1,-2,-3)); + REQUIRE(-v == TinyVector<3, int>(-1, -2, -3)); REQUIRE(v.dimension() == 3); - const TinyVector<3,int> z = zero; + const TinyVector<3, int> z = zero; REQUIRE(((z[0] == 0) and (z[1] == 0) and (z[2] == 0))); - v = TinyVector<3,int>(3,2,4); + v = TinyVector<3, int>(3, 2, 4); REQUIRE(Catch::Detail::stringify(v) == "(3,2,4)"); - TinyVector<3,int> w(1,2,6); - REQUIRE((v,w)==31); + TinyVector<3, int> w(1, 2, 6); + REQUIRE((v, w) == 31); - w = 2*v; - REQUIRE(w == TinyVector<3,int>(6,4,8)); + w = 2 * v; + REQUIRE(w == TinyVector<3, int>(6, 4, 8)); - TinyVector<3,int> x = v; - REQUIRE(x==v); + TinyVector<3, int> x = v; + REQUIRE(x == v); - x = TinyVector<3,int> (6,4,8); - REQUIRE(x==w); - REQUIRE_FALSE(x==v); - REQUIRE(x!=v); - REQUIRE_FALSE(x!=w); + x = TinyVector<3, int>(6, 4, 8); + REQUIRE(x == w); + REQUIRE_FALSE(x == v); + REQUIRE(x != v); + REQUIRE_FALSE(x != w); - x=v; - REQUIRE(x==v); + x = v; + REQUIRE(x == v); - x+=w; - REQUIRE(x==3*v); + x += w; + REQUIRE(x == 3 * v); - x=v+w; - REQUIRE(x==3*v); + x = v + w; + REQUIRE(x == 3 * v); - x=2*(v+v); - REQUIRE(x==4*v); + x = 2 * (v + v); + REQUIRE(x == 4 * v); - x=v+(w+x); - REQUIRE(x==7*v); + x = v + (w + x); + REQUIRE(x == 7 * v); - x=x-(v+w); - REQUIRE(x==4*v); + x = x - (v + w); + REQUIRE(x == 4 * v); - x-=v+w; - REQUIRE(x==v); + x -= v + w; + REQUIRE(x == v); - x=w-v; - REQUIRE(x==v); + x = w - v; + REQUIRE(x == v); - x=v-2*v; - REQUIRE(x==-v); + x = v - 2 * v; + REQUIRE(x == -v); - TinyVector<3,int> z1; z1 = zero; + TinyVector<3, int> z1; + z1 = zero; REQUIRE(((z1[0] == 0) and (z1[1] == 0) and (z1[2] == 0))); - REQUIRE(l2Norm(TinyVector<2,double>(3,4)) == Approx(5).epsilon(1E-14)); + REQUIRE(l2Norm(TinyVector<2, double>(3, 4)) == Approx(5).epsilon(1E-14)); - SECTION("checking for cross product") { - const TinyVector<3,int> a(1,-2,4); - const TinyVector<3,int> b(3, 1,6); - REQUIRE(crossProduct(a, b) == TinyVector<3,int>(-16,6,7)); + SECTION("checking for cross product") + { + const TinyVector<3, int> a(1, -2, 4); + const TinyVector<3, int> b(3, 1, 6); + REQUIRE(crossProduct(a, b) == TinyVector<3, int>(-16, 6, 7)); } #ifndef NDEBUG - SECTION("checking for bounds validation") { - REQUIRE_THROWS_AS(x[4]=0, AssertError); - const TinyVector<3,int>& const_x = x; + SECTION("checking for bounds validation") + { + REQUIRE_THROWS_AS(x[4] = 0, AssertError); + const TinyVector<3, int>& const_x = x; REQUIRE_THROWS_AS(const_x[-1], AssertError); } -#endif // NDEBUG +#endif // NDEBUG } diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 98ed156f2..050995133 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -3,11 +3,12 @@ #include <Kokkos_Core.hpp> -int main( int argc, char* argv[] ) +int +main(int argc, char* argv[]) { - Kokkos::initialize({4,-1,-1,true}); + Kokkos::initialize({4, -1, -1, true}); - int result = Catch::Session().run( argc, argv ); + int result = Catch::Session().run(argc, argv); Kokkos::finalize(); -- GitLab