diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e812a607b2a7fd9d32bc307cf753f16cef31a4a0..1a58571600fb6788aa0d0b6b458e62ea5f5073c5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2065,11 +2065,11 @@ benchmark_ClangBuildAnalyzer: - export PATH+=:$(pwd) - mkdir $CI_PROJECT_DIR/build - cd $CI_PROJECT_DIR/build - - cmake .. -DWALBERLA_BUFFER_DEBUG=OFF -DWALBERLA_BUILD_TESTS=OFF -DWALBERLA_BUILD_BENCHMARKS=OFF -DWALBERLA_BUILD_TUTORIALS=OFF -DWALBERLA_BUILD_TOOLS=OFF -DWALBERLA_BUILD_WITH_MPI=ON -DWALBERLA_BUILD_WITH_CUDA=OFF -DWALBERLA_BUILD_WITH_PYTHON=OFF -DWALBERLA_BUILD_WITH_OPENMP=OFF -DCMAKE_BUILD_TYPE=RELEASE -DMPIEXEC_PREFLAGS=$MPIEXEC_PREFLAGS -DWALBERLA_DOUBLE_ACCURACY=ON -DWARNING_ERROR=ON -DWALBERLA_BUILD_WITH_METIS=OFF -DWALBERLA_BUILD_WITH_PARMETIS=OFF -DWALBERLA_OPTIMIZE_FOR_LOCALHOST=ON -DWALBERLA_BUILD_WITH_FASTMATH=ON -DWALBERLA_BUILD_WITH_LTO=ON -DCMAKE_CXX_FLAGS=-ftime-trace -G Ninja + - cmake .. -DWALBERLA_BUFFER_DEBUG=OFF -DWALBERLA_BUILD_TESTS=ON -DWALBERLA_BUILD_BENCHMARKS=ON -DWALBERLA_BUILD_TUTORIALS=ON -DWALBERLA_BUILD_TOOLS=OFF -DWALBERLA_BUILD_WITH_MPI=ON -DWALBERLA_BUILD_WITH_CUDA=OFF -DWALBERLA_BUILD_WITH_PYTHON=OFF -DWALBERLA_BUILD_WITH_OPENMP=OFF -DCMAKE_BUILD_TYPE=RELEASE -DMPIEXEC_PREFLAGS=$MPIEXEC_PREFLAGS -DWALBERLA_DOUBLE_ACCURACY=ON -DWARNING_ERROR=ON -DWALBERLA_BUILD_WITH_METIS=OFF -DWALBERLA_BUILD_WITH_PARMETIS=OFF -DWALBERLA_OPTIMIZE_FOR_LOCALHOST=ON -DWALBERLA_BUILD_WITH_FASTMATH=ON -DWALBERLA_BUILD_WITH_LTO=ON -DCMAKE_CXX_FLAGS=-ftime-trace -G Ninja - cmake . -LAH - - ClangBuildAnalyzer --start src - - ninja src/all - - ClangBuildAnalyzer --stop src CBA + - ClangBuildAnalyzer --start . + - ninja all + - ClangBuildAnalyzer --stop . CBA - ClangBuildAnalyzer --analyze CBA image: i10git.cs.fau.de:5005/walberla/buildenvs/clang:9.0 tags: diff --git a/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp b/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp index 5d2f225f4559cd1ccc7471817226ac18201855d2..8ede6cbb621acce9c8bb881a27efe797f1231008 100644 --- a/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp +++ b/apps/benchmarks/MeshDistance/MeshDistanceBenchmark.cpp @@ -22,6 +22,7 @@ #include "core/debug/TestSubsystem.h" #include "core/logging/Logging.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "core/timing/Timer.h" #include "geometry/containment_octree/ContainmentOctree.h" @@ -164,8 +165,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " [--no-brute-force] [--force-float] MESH_FILE NUM_POINTS NUM_REPETITIONS" ); const std::string & meshFile = args[1]; - const uint_t numPoints = string_to_num<uint_t>( args[2] ); - const uint_t numRepetitions = string_to_num<uint_t>( args[3] ); + const uint_t numPoints = stringToNum<uint_t>( args[2] ); + const uint_t numRepetitions = stringToNum<uint_t>( args[3] ); if(forceFloat) { diff --git a/src/blockforest/BlockForest.h b/src/blockforest/BlockForest.h index 45f39dcef889354810be9a7acd2e9e460d76ddec..695b5cf34040b98e737e6b7be57e1687b6e42355 100644 --- a/src/blockforest/BlockForest.h +++ b/src/blockforest/BlockForest.h @@ -28,6 +28,7 @@ #include "Types.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include "core/timing/TimingPool.h" #include "domain_decomposition/BlockStorage.h" @@ -259,7 +260,7 @@ public: uint_t getMaxDepth() const { #ifdef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID - return ( UINT_BITS - treeIdDigits_ ) / uint_t(3); + return ( math::UINT_BITS - treeIdDigits_ ) / uint_t(3); #else return std::numeric_limits< uint_t >::max(); #endif diff --git a/src/blockforest/BlockID.cpp b/src/blockforest/BlockID.cpp index 060a19b594859675b6324de2cb9704ab3e5e0e38..886567ed93a2812dd5c176ff800ea5c192f4e32d 100644 --- a/src/blockforest/BlockID.cpp +++ b/src/blockforest/BlockID.cpp @@ -51,12 +51,12 @@ BlockID::BlockID( const std::vector< uint8_t >& array, const uint_t offset, cons WALBERLA_ASSERT_UNEQUAL( usedBits_, 0 ); - const uint_t blocks = ( usedBits_ / UINT_BITS ) + ( ( (usedBits_ & ( UINT_BITS - 1 )) == 0 ) ? 0 : 1 ); + const uint_t blocks = ( usedBits_ / math::UINT_BITS ) + ( ( (usedBits_ & ( math::UINT_BITS - 1 )) == 0 ) ? 0 : 1 ); uint_t b = offset; for( uint_t i = 0; i != blocks; ++i ) { blocks_.push_back(0); - for( uint_t j = 0; j != UINT_BYTES && b != offset + bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != offset + bytes; ++j, ++b ) { blocks_.back() |= uint_c( array[b] ) << ( j * 8 ); } } @@ -68,11 +68,11 @@ void BlockID::appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT( !blocks_.empty() ); WALBERLA_ASSERT_LESS( branchId, 8 ); - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); - const uint_t unusedBits = UINT_BITS - ( usedBits_ & ( UINT_BITS - 1 ) ); + const uint_t unusedBits = math::UINT_BITS - ( usedBits_ & ( math::UINT_BITS - 1 ) ); - if( unusedBits < 3 || unusedBits == UINT_BITS ) + if( unusedBits < 3 || unusedBits == math::UINT_BITS ) blocks_.push_back(0); for( uint_t i = static_cast< uint_t >( blocks_.size() ) - 1; i != 0; --i ) @@ -81,8 +81,8 @@ void BlockID::appendBranchId( const uint_t branchId ) blocks_[0] = ( blocks_[0] << 3 ) | branchId; usedBits_ += 3; - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); - WALBERLA_ASSERT_GREATER_EQUAL( blocks_.size() * UINT_BITS, usedBits_ ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_GREATER_EQUAL( blocks_.size() * math::UINT_BITS, usedBits_ ); } @@ -91,19 +91,19 @@ void BlockID::removeBranchId() { WALBERLA_ASSERT( !blocks_.empty() ); WALBERLA_ASSERT_GREATER( usedBits_, 3 ); - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); for( uint_t i = 0; i != static_cast< uint_t >( blocks_.size() ) - 1; ++i ) blocks_[i] = ( blocks_[i] >> 3 ) | ( (blocks_[i+1] & uint_c(7)) << SHIFT ); - const uint_t bits = usedBits_ & ( UINT_BITS - 1 ); + const uint_t bits = usedBits_ & ( math::UINT_BITS - 1 ); if( 0 < bits && bits < 4 ) blocks_.pop_back(); else blocks_.back() >>= 3; usedBits_ -= 3; - WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + UINT_BITS * (blocks_.size()-1) ); + WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_.back() ) + math::UINT_BITS * (blocks_.size()-1) ); WALBERLA_ASSERT( !blocks_.empty() ); } @@ -124,7 +124,7 @@ void BlockID::toByteArray( std::vector< uint8_t >& array, const uint_t offset, c uint_t block = blocks_[i]; - for( uint_t j = 0; j != UINT_BYTES && b != offset + bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != offset + bytes; ++j, ++b ) { array[b] = static_cast< uint8_t >( block & uint_c(255) ); block >>= 8; diff --git a/src/blockforest/BlockID.h b/src/blockforest/BlockID.h index 9a28bc690cdeddbac83a206704a3eb41359bede1..ff64a5b19b9746c5a2b0135f1069c29905813ff9 100644 --- a/src/blockforest/BlockID.h +++ b/src/blockforest/BlockID.h @@ -25,6 +25,7 @@ #include "Utility.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include "core/mpi/RecvBuffer.h" #include "core/mpi/SendBuffer.h" @@ -91,10 +92,10 @@ private: uint_t usedBits_; std::vector< uint_t > blocks_; - static const uint_t SHIFT = UINT_BITS - 3; + static const uint_t SHIFT = math::UINT_BITS - 3; - WALBERLA_STATIC_ASSERT( UINT_BITS > 31 ); - WALBERLA_STATIC_ASSERT( !(UINT_BITS & (UINT_BITS - 1)) ); // power of two + WALBERLA_STATIC_ASSERT( math::UINT_BITS > 31 ); + WALBERLA_STATIC_ASSERT( !(math::UINT_BITS & (math::UINT_BITS - 1)) ); // power of two }; // class BlockID @@ -141,7 +142,7 @@ inline void BlockID::init( const uint_t treeIndex, const uint_t treeIdMarker ) inline uint_t BlockID::getTreeId() const { WALBERLA_ASSERT_GREATER( usedBits_, 0 ); - WALBERLA_ASSERT_LESS_EQUAL( usedBits_, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( usedBits_, math::UINT_BITS ); WALBERLA_CHECK_EQUAL( blocks_.size(), 1 ); WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_[0] ) ); @@ -153,7 +154,7 @@ inline uint_t BlockID::getTreeId() const inline uint_t BlockID::getTreeIndex() const { WALBERLA_ASSERT_GREATER( usedBits_, 0 ); - WALBERLA_ASSERT_LESS_EQUAL( usedBits_, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( usedBits_, math::UINT_BITS ); WALBERLA_CHECK_EQUAL( blocks_.size(), 1 ); WALBERLA_ASSERT_EQUAL( usedBits_, uintMSBPosition( blocks_[0] ) ); @@ -220,7 +221,7 @@ void BlockID::toBuffer( Buffer_T& buffer ) const uint8_t b(0); for( uint_t i = 0; i != blocks_.size(); ++i ) - for( uint_t j = 0; j != UINT_BYTES && b != bytes; ++j, ++b ) + for( uint_t j = 0; j != math::UINT_BYTES && b != bytes; ++j, ++b ) buffer << uint8_c( ( blocks_[i] >> ( uint_c(j) * uint_c(8) ) ) & uint_c(255) ); } @@ -232,22 +233,22 @@ void BlockID::fromBuffer( Buffer_T& buffer ) { uint8_t bytes(0); buffer >> bytes; - const uint_t blocks = ( bytes / UINT_BYTES ) + ( ( (bytes & ( UINT_BYTES - 1 )) == 0 ) ? 0 : 1 ); + const uint_t blocks = ( bytes / math::UINT_BYTES ) + ( ( (bytes & ( math::UINT_BYTES - 1 )) == 0 ) ? 0 : 1 ); uint8_t b(0); blocks_.clear(); for( uint_t i = 0; i != blocks; ++i ) { blocks_.push_back(0); - for( uint_t j = 0; j != UINT_BYTES && b != bytes; ++j, ++b ) { + for( uint_t j = 0; j != math::UINT_BYTES && b != bytes; ++j, ++b ) { uint8_t byte(0); buffer >> byte; blocks_.back() |= uint_c( byte ) << ( uint_c(j) * uint_c(8) ); } } - for( uint_t i = 0; i != UINT_BITS; ++i ) + for( uint_t i = 0; i != math::UINT_BITS; ++i ) if( ( blocks_[ blocks-1 ] & ( uint_c(1) << uint_c(i) ) ) != uint_c(0) ) - usedBits_ = i + 1 + (blocks-1) * UINT_BITS; + usedBits_ = i + 1 + (blocks-1) * math::UINT_BITS; } @@ -278,7 +279,7 @@ public: BlockID getSuperId() const { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); return BlockID( id_ >> 3 ); } BlockID getFatherId() const { return getSuperId(); } - void appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT_LESS_EQUAL( getUsedBits() + 3, UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); id_ = (id_ << 3) + branchId; } + void appendBranchId( const uint_t branchId ) { WALBERLA_ASSERT_LESS_EQUAL( getUsedBits() + 3, math::UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); id_ = (id_ << 3) + branchId; } void removeBranchId() { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); id_ >>= 3; } uint_t getBranchId() const { WALBERLA_ASSERT_GREATER_EQUAL( getUsedBits(), uint_c(4) ); return id_ & uint_c(7); } @@ -317,7 +318,7 @@ inline BlockID::BlockID( const uint_t treeIndex, const uint_t treeIdMarker ) : i inline BlockID::BlockID( const BlockID& id, const uint_t branchId ) : id_( (id.id_ << 3) + branchId ) { - WALBERLA_ASSERT_LESS_EQUAL( id.getUsedBits() + 3, UINT_BITS ); + WALBERLA_ASSERT_LESS_EQUAL( id.getUsedBits() + 3, math::UINT_BITS ); WALBERLA_ASSERT_LESS( branchId, 8 ); } @@ -366,7 +367,7 @@ void BlockID::fromBuffer( Buffer_T& buffer ) { uint8_t bytes(0); buffer >> bytes; - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); id_ = uint_c(0); for( uint8_t i = 0; i != bytes; ++i ) { diff --git a/src/blockforest/PhantomBlockForest.cpp b/src/blockforest/PhantomBlockForest.cpp index d6867a9dd64d4fca4370531be65b5402b18f6084..fe7f8e1d3c09cbdc2b799f3bda07e09b8bbd4539 100644 --- a/src/blockforest/PhantomBlockForest.cpp +++ b/src/blockforest/PhantomBlockForest.cpp @@ -26,6 +26,7 @@ #include "core/debug/CheckFunctions.h" #include "core/debug/Debug.h" #include "core/logging/Logging.h" +#include "core/math/Uint.h" #include "core/mpi/BufferSizeTrait.h" #include "core/mpi/BufferSystem.h" #include "core/mpi/MPIManager.h" @@ -188,7 +189,7 @@ void PhantomBlockForest::initialize( const BlockStateDeterminationFunction & fun depth_ = blockforest_.getDepth(); #ifdef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID - WALBERLA_CHECK_LESS_EQUAL( blockforest_.getTreeIdDigits() + depth_ * uint_t(3), UINT_BITS ); + WALBERLA_CHECK_LESS_EQUAL( blockforest_.getTreeIdDigits() + depth_ * uint_t(3), math::UINT_BITS ); #endif // phantom block neighborhood construction diff --git a/src/blockforest/SetupBlockForest.cpp b/src/blockforest/SetupBlockForest.cpp index b57abcccfa8834fa033f593491c69c3a73aaec8f..449e8bea3d7b7b8d110d1b41de3d37a9ff0ff01b 100644 --- a/src/blockforest/SetupBlockForest.cpp +++ b/src/blockforest/SetupBlockForest.cpp @@ -34,6 +34,7 @@ #include "core/debug/CheckFunctions.h" #include "core/logging/Logging.h" #include "core/math/Sample.h" +#include "core/typeToString.h" #include "domain_decomposition/MapPointToPeriodicDomain.h" diff --git a/src/core/DataTypes.cpp b/src/core/DataTypes.cpp index 529b19e100da5f48cab670dae6fe6341f6178aee..ead9f6fb680c12a053c9ebf4fe9fe9333c443027 100644 --- a/src/core/DataTypes.cpp +++ b/src/core/DataTypes.cpp @@ -24,12 +24,6 @@ namespace walberla { -#ifndef WALBERLA_CXX_COMPILER_IS_MSVC - -const uint_t int_ld<1>::exp; - -#endif - namespace real_comparison { const float Epsilon< float >::value = static_cast< float >(1e-4); diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h index 5bcae7599a2ababcc017f2127f25e18d7cf54f80..3ae37218d98be423b528991c762303b22c602cba 100644 --- a/src/core/DataTypes.h +++ b/src/core/DataTypes.h @@ -28,22 +28,8 @@ #include <limits> #include <memory> #include <stdexcept> -#include <string> #include <type_traits> -#ifdef __GLIBCXX__ -#define HAVE_CXXABI_H -#include <cxxabi.h> -#else -#ifdef __has_include -#if __has_include(<cxxabi.h>) -#define HAVE_CXXABI_H -#include <cxxabi.h> -#endif -#endif -#endif - - namespace walberla { @@ -99,20 +85,6 @@ inline S numeric_cast( T t ) { } - -template<typename S> -inline S string_to_num( std::string & t ); -template <> inline float string_to_num( std::string & t ) { return std::stof(t); } -template <> inline double string_to_num( std::string & t ) { return std::stod(t); } -template <> inline long double string_to_num( std::string & t ) { return std::stold(t); } -template <> inline int string_to_num( std::string & t ) { return std::stoi(t); } -template <> inline long string_to_num( std::string & t ) { return std::stol(t); } -template <> inline long long string_to_num( std::string & t ) { return std::stoll(t); } -template <> inline unsigned long string_to_num( std::string & t ) { return std::stoul(t); } -template <> inline unsigned long long string_to_num( std::string & t ) { return std::stoull(t); } - - - // fixed size signed integral types typedef std::int8_t int8_t; ///< 8 bit signed integer typedef std::int16_t int16_t; ///< 16 bit signed integer @@ -170,60 +142,6 @@ inline void static_assert_uint_t() { !std::numeric_limits<UINT>::is_signed, "Unsigned integer type required/expected!" ); } -template< uint_t size > struct uintFromBitWidth; -template<> struct uintFromBitWidth< 8 > { typedef uint8_t type; }; -template<> struct uintFromBitWidth< 16 > { typedef uint16_t type; }; -template<> struct uintFromBitWidth< 32 > { typedef uint32_t type; }; -template<> struct uintFromBitWidth< 64 > { typedef uint64_t type; }; - -constexpr uint_t leastUnsignedIntegerBitWidth( uint_t width ) -{ - if ( width <= 8 ) return 8; - if ( width <= 16 ) return 16; - if ( width <= 32 ) return 32; - if ( width <= 64 ) return 64; - return width; -} - -/// \brief Provides the smallest unsigned integer type that has at least minSize bits. -/// -/// Example: -/// -/// leastUnsignedInteger< 5 >::type a; // a is an 8-bit unsigned integer -/// leastUnsignedInteger< 9 >::type b; // b is a 16-bit unsigned integer -/// -template< uint_t minSize > -struct leastUnsignedInteger -{ - typedef typename uintFromBitWidth< leastUnsignedIntegerBitWidth( minSize ) >::type type; -}; - -/// \cond internal -static const uint_t UINT_BITS = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ); -static const uint_t UINT_BYTES = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ) >> 3; - -static_assert( !(UINT_BITS & (UINT_BITS - 1)), "Type \"uint_t\" must consist of 2^x Bits!" ); // power of two - -template< int N > -struct int_ld -{ - static_assert( N >= 1 && !(N & (N - 1)), "Calculating log_2(N) -> \"N\" must be a power of two!" ); - static const uint_t exp = 1 + int_ld< (N >> 1) >::exp; -}; - -template< int N > const uint_t int_ld<N>::exp; - -template<> -struct int_ld<1> -{ - static const uint_t exp = 0; -}; - -static const uint_t UINT_BITS_LD = int_ld< std::numeric_limits< uint_t >::digits >::exp; -/// \endcond - - - // data structure specific data types typedef int cell_idx_t; @@ -303,57 +221,6 @@ inline bool floatIsEqual( float lhs, float rhs, const float epsilon = real_compa return std::fabs( lhs - rhs ) < epsilon; } - - -// data type to string conversion - -template< typename T > inline const char* typeToString(); - -#define TypeToString(X) template<> inline const char* typeToString< X >() { \ - static char string[] = #X; \ - return string; \ -} - -TypeToString(bool) -TypeToString(char) -TypeToString(short) -TypeToString(int) -TypeToString(long) -TypeToString(long long) -TypeToString(unsigned char) -TypeToString(unsigned short) -TypeToString(unsigned int) -TypeToString(unsigned long) -TypeToString(unsigned long long) -TypeToString(float) -TypeToString(double) - -#undef TypeToString - -template< typename T > inline const char* typeToString( T ) { return typeToString<T>(); } - -// type info demangling - -inline std::string demangle( const std::string & name ) -{ -#ifdef HAVE_CXXABI_H - int status = 0; - std::size_t size = 0; - const char * demangled = abi::__cxa_demangle( name.c_str(), NULL, &size, &status ); - if( demangled == nullptr ) - { - return name; - } - std::string demangled_str(demangled); - std::free( const_cast<char*>(demangled) ); - return demangled_str; -#else - return name; -#endif -} - - - } // namespace walberla #define WALBERLA_UNUSED(x) (void)(x) diff --git a/src/core/EndianIndependentSerialization.h b/src/core/EndianIndependentSerialization.h index e33b8ab3ae731b4aa9b7a0fcb2499d60fbc15fd0..b45b19c8ed73a29b6c0a5fb22b74e88d5f117459 100644 --- a/src/core/EndianIndependentSerialization.h +++ b/src/core/EndianIndependentSerialization.h @@ -23,6 +23,7 @@ #include "DataTypes.h" #include "core/debug/Debug.h" +#include "core/math/Uint.h" #include <cmath> #include <limits> @@ -52,7 +53,7 @@ namespace walberla { inline void uintToByteArray( uint_t value, std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) { WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); for( uint_t i = 0; i != bytes; ++i ) { @@ -79,7 +80,7 @@ inline void uintToByteArray( uint_t value, std::vector< uint8_t >& array, const inline uint_t byteArrayToUint( const std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) { WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); - WALBERLA_ASSERT_LESS_EQUAL( bytes, UINT_BYTES ); + WALBERLA_ASSERT_LESS_EQUAL( bytes, math::UINT_BYTES ); uint_t value = 0; for( uint_t i = 0; i != bytes; ++i ) diff --git a/src/core/debug/PrintStacktrace.cpp b/src/core/debug/PrintStacktrace.cpp index f939d19d576602db75a7ade1d107abe76da0c52c..7eff6bcb948834578474ebb3649d455dd0c40ee4 100644 --- a/src/core/debug/PrintStacktrace.cpp +++ b/src/core/debug/PrintStacktrace.cpp @@ -20,6 +20,7 @@ //====================================================================================================================== #include "PrintStacktrace.h" +#include "demangle.h" #include "core/DataTypes.h" #include <iostream> diff --git a/src/core/debug/demangle.h b/src/core/debug/demangle.h new file mode 100644 index 0000000000000000000000000000000000000000..2e317436e6d9bace3045ef40a79aa4fdd0f88a85 --- /dev/null +++ b/src/core/debug/demangle.h @@ -0,0 +1,59 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file demangle.h +//! \author Florian Schornbaum <florian.schornbaum@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include <string> + +#ifdef __GLIBCXX__ +#define HAVE_CXXABI_H +#include <cxxabi.h> +#else +#ifdef __has_include +#if __has_include(<cxxabi.h>) +#define HAVE_CXXABI_H +#include <cxxabi.h> +#endif +#endif +#endif + +namespace walberla { +namespace debug { + +inline std::string demangle( const std::string & name ) +{ +#ifdef HAVE_CXXABI_H + int status = 0; + std::size_t size = 0; + const char * demangled = abi::__cxa_demangle( name.c_str(), NULL, &size, &status ); + if( demangled == nullptr ) + { + return name; + } + std::string demangled_str(demangled); + std::free( const_cast<char*>(demangled) ); + return demangled_str; +#else + return name; +#endif +} + +} // namespace debug +} // namespace walberla diff --git a/src/core/logging/Logging.cpp b/src/core/logging/Logging.cpp index 60fc970bc461b770558d9dd674ef5e0060ca639d..0c3718d0f37ad16ae845828d22349b6bbc595ec8 100644 --- a/src/core/logging/Logging.cpp +++ b/src/core/logging/Logging.cpp @@ -22,6 +22,7 @@ #include "Logging.h" #include "core/Filesystem.h" +#include "core/Regex.h" #include <ctime> @@ -195,6 +196,23 @@ std::string Logging::createLog( const std::string & type, const std::string & me } +bool Logging::isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, + const std::string & callerPath, const int line ) const +{ + if( !regexes.empty() ) + { + std::stringstream callerPathAndLine; + callerPathAndLine << callerPath << ":" << line; + + for( auto regex = regexes.begin(); regex != regexes.end(); ++regex ) + if( walberla::regex_search( callerPathAndLine.str(), *regex ) ) + return true; + } + + return false; +} + + } // namespace logging } // namespace walberla diff --git a/src/core/logging/Logging.h b/src/core/logging/Logging.h index d3671e0ea3910bc7736710bfb7110930ff299600..1a43778516e837e874fed0dda040c25508b93c06 100644 --- a/src/core/logging/Logging.h +++ b/src/core/logging/Logging.h @@ -140,8 +140,8 @@ private: inline Logging(); - inline bool isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, - const std::string & callerPath, const int line ) const; + bool isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, + const std::string & callerPath, const int line ) const; inline void logError ( const std::string & message, const std::string & callerPath, const int line ); inline void logDevel ( const std::string & message, const std::string & callerPath, const int line ); @@ -306,24 +306,6 @@ inline bool Logging::logTracing( const std::string & /*callerPath*/, const int / -inline bool Logging::isInIgnoreCallerPaths( const std::vector< walberla::regex > & regexes, - const std::string & callerPath, const int line ) const -{ - if( !regexes.empty() ) - { - std::stringstream callerPathAndLine; - callerPathAndLine << callerPath << ":" << line; - - for( auto regex = regexes.begin(); regex != regexes.end(); ++regex ) - if( walberla::regex_search( callerPathAndLine.str(), *regex ) ) - return true; - } - - return false; -} - - - inline void Logging::logError( const std::string & message, const std::string & callerPath, const int line ) { #ifdef WALBERLA_THREAD_SAFE_LOGGING diff --git a/src/core/math/Uint.cpp b/src/core/math/Uint.cpp index ee16588d1976d9884bd99e3f07abaf4b128ba28c..38f8003e746a3534fcb312a408bbb51b5f0fe6fb 100644 --- a/src/core/math/Uint.cpp +++ b/src/core/math/Uint.cpp @@ -25,8 +25,6 @@ namespace walberla { namespace math { - - template<> uint_t uintMSBPosition< uint64_t >( uint64_t value ) { // for the documentation see the header file uint64_t i; @@ -51,7 +49,11 @@ template<> uint_t uintMSBPosition< uint64_t >( uint64_t value ) { // for the doc return ( i != 0 ) ? (8 + msbLookupTable[i]) : msbLookupTable[value]; } +#ifndef WALBERLA_CXX_COMPILER_IS_MSVC + +const uint_t int_ld<1>::exp; +#endif } // namespace math } // namespace walberla diff --git a/src/core/math/Uint.h b/src/core/math/Uint.h index 71fe07fea66854388b105fc465f5c544ef9d37d8..5a76bc8fa8f52b30c4e52efc16ccc3f8d25c3381 100644 --- a/src/core/math/Uint.h +++ b/src/core/math/Uint.h @@ -193,7 +193,57 @@ template<> inline uint_t uintMSBPosition< uint8_t >( uint8_t value ) { return msbLookupTable[value]; } +template< uint_t size > struct uintFromBitWidth; +template<> struct uintFromBitWidth< 8 > { typedef uint8_t type; }; +template<> struct uintFromBitWidth< 16 > { typedef uint16_t type; }; +template<> struct uintFromBitWidth< 32 > { typedef uint32_t type; }; +template<> struct uintFromBitWidth< 64 > { typedef uint64_t type; }; +constexpr uint_t leastUnsignedIntegerBitWidth( uint_t width ) +{ + if ( width <= 8 ) return 8; + if ( width <= 16 ) return 16; + if ( width <= 32 ) return 32; + if ( width <= 64 ) return 64; + return width; +} + +/// \brief Provides the smallest unsigned integer type that has at least minSize bits. +/// +/// Example: +/// +/// leastUnsignedInteger< 5 >::type a; // a is an 8-bit unsigned integer +/// leastUnsignedInteger< 9 >::type b; // b is a 16-bit unsigned integer +/// +template< uint_t minSize > +struct leastUnsignedInteger +{ + typedef typename uintFromBitWidth< leastUnsignedIntegerBitWidth( minSize ) >::type type; +}; + +/// \cond internal +static const uint_t UINT_BITS = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ); +static const uint_t UINT_BYTES = static_cast< uint_t >( std::numeric_limits< uint_t >::digits ) >> 3; + +static_assert( !(UINT_BITS & (UINT_BITS - 1)), "Type \"uint_t\" must consist of 2^x Bits!" ); // power of two + +template< int N > +struct int_ld +{ + static_assert( N >= 1 && !(N & (N - 1)), "Calculating log_2(N) -> \"N\" must be a power of two!" ); + static const uint_t exp = 1 + int_ld< (N >> 1) >::exp; +}; + +template< int N > const uint_t int_ld<N>::exp; + +template<> +struct int_ld<1> +{ + static const uint_t exp = 0; +}; + +static const uint_t UINT_BITS_LD = int_ld< std::numeric_limits< uint_t >::digits >::exp; +/// \endcond } // namespace math } // namespace walberla diff --git a/src/core/mpi/BufferDataTypeExtensions.h b/src/core/mpi/BufferDataTypeExtensions.h index e1ec3755038f6e13c5df4ede2a738a9c17eb1977..9685d6ac2d7a14b7bd68e162e81c27f7254e02b7 100644 --- a/src/core/mpi/BufferDataTypeExtensions.h +++ b/src/core/mpi/BufferDataTypeExtensions.h @@ -27,6 +27,7 @@ #include "SendBuffer.h" #include "core/Conversion.h" #include "core/DataTypes.h" +#include "core/math/Uint.h" #include "core/Optional.h" #include "core/RandomUUID.h" @@ -276,7 +277,7 @@ template< typename T, // Element type of SendBuffer GenericSendBuffer<T,G>& packBoolVectorWithoutSize(GenericSendBuffer<T,G> & buf, const std::vector<bool> & bools ) { // Use an unsigned type at least as large as the SendBuffer base type as container for the bools - typedef typename leastUnsignedInteger< std::numeric_limits<T>::digits >::type ContainerType; + typedef typename math::leastUnsignedInteger< std::numeric_limits<T>::digits >::type ContainerType; static const size_t NUM_BITS = std::numeric_limits<ContainerType>::digits; auto it = bools.begin(); @@ -297,7 +298,7 @@ template< typename T > // Element type of RecvBuffer GenericRecvBuffer<T>& unpackBoolVectorWithoutSize(GenericRecvBuffer<T> & buf, std::vector<bool> & bools, size_t size ) { // Use an unsigned type at least as large as the RecvBuffer base type as container for the bools - typedef typename leastUnsignedInteger<std::numeric_limits<T>::digits>::type ContainerType; + typedef typename math::leastUnsignedInteger<std::numeric_limits<T>::digits>::type ContainerType; static const size_t NUM_BITS = std::numeric_limits<ContainerType>::digits; bools.resize(size); diff --git a/src/core/stringToNum.h b/src/core/stringToNum.h new file mode 100644 index 0000000000000000000000000000000000000000..00723d913b6c633c560663152467a20fa2cafc6f --- /dev/null +++ b/src/core/stringToNum.h @@ -0,0 +1,40 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file stringToNum.h +//! \author Florian Schornbaum <florian.schornbaum@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include <string> + +namespace walberla { + +template<typename S> +inline S stringToNum( std::string & t ); +template <> inline float stringToNum( std::string & t ) { return std::stof(t); } +template <> inline double stringToNum( std::string & t ) { return std::stod(t); } +template <> inline long double stringToNum( std::string & t ) { return std::stold(t); } +template <> inline int stringToNum( std::string & t ) { return std::stoi(t); } +template <> inline long stringToNum( std::string & t ) { return std::stol(t); } +template <> inline long long stringToNum( std::string & t ) { return std::stoll(t); } +template <> inline unsigned long stringToNum( std::string & t ) { return std::stoul(t); } +template <> inline unsigned long long stringToNum( std::string & t ) { return std::stoull(t); } + +} // namespace walberla + + diff --git a/src/core/typeToString.h b/src/core/typeToString.h new file mode 100644 index 0000000000000000000000000000000000000000..ca49ecefa92ac264fea62ecc6f60c3112c479dd4 --- /dev/null +++ b/src/core/typeToString.h @@ -0,0 +1,52 @@ +//====================================================================================================================== +// +// This file is part of waLBerla. waLBerla is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// waLBerla is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file typeToString.h +//! \author Florian Schornbaum <florian.schornbaum@fau.de> +// +//====================================================================================================================== + +#pragma once + +namespace walberla { + +// data type to string conversion + +template< typename T > inline const char* typeToString(); + +#define TypeToString(X) template<> inline const char* typeToString< X >() { \ + static char string[] = #X; \ + return string; \ +} + +TypeToString(bool) +TypeToString(char) +TypeToString(short) +TypeToString(int) +TypeToString(long) +TypeToString(long long) +TypeToString(unsigned char) +TypeToString(unsigned short) +TypeToString(unsigned int) +TypeToString(unsigned long) +TypeToString(unsigned long long) +TypeToString(float) +TypeToString(double) + +#undef TypeToString + +template< typename T > inline const char* typeToString( T ) { return typeToString<T>(); } + +} // namespace walberla diff --git a/src/domain_decomposition/IBlock.h b/src/domain_decomposition/IBlock.h index 215f8a51d27d714b41192ecaec0d273e721f560d..c25c55ee9a6f5e1224941ee51c3144ebd230adcc 100644 --- a/src/domain_decomposition/IBlock.h +++ b/src/domain_decomposition/IBlock.h @@ -25,6 +25,7 @@ #include "IBlockID.h" #include "core/Abort.h" +#include "core/debug/demangle.h" #include "core/NonCopyable.h" #include "core/debug/Debug.h" #include "core/math/AABB.h" @@ -103,8 +104,8 @@ public: catch (...) {} #ifndef NDEBUG WALBERLA_ABORT( "BlockData access type violation! (The block data you added is of a different type than the block data you are trying to access!)" - "\nThe original data type was: " << demangle( typeInfo_ ) << - "\nYou try to retrieve data of type: " << demangle( typeid(U).name() ) ) + "\nThe original data type was: " << debug::demangle( typeInfo_ ) << + "\nYou try to retrieve data of type: " << debug::demangle( typeid(U).name() ) ) #else WALBERLA_ABORT( "BlockData access type violation! (The block data you added is of a different type than the block data you are trying to access!)" ) #endif diff --git a/src/geometry/containment_octree/ContainmentOctree.h b/src/geometry/containment_octree/ContainmentOctree.h index f83014c05f2418eaa8e74d059e0e964b61499e2c..96d091c006d8554a4af79a374e1c589ad7097813 100644 --- a/src/geometry/containment_octree/ContainmentOctree.h +++ b/src/geometry/containment_octree/ContainmentOctree.h @@ -30,6 +30,7 @@ #include "core/DataTypes.h" #include "core/math/GenericAABB.h" #include "core/math/KahanSummation.h" +#include "core/typeToString.h" #include <queue> #include <vector> diff --git a/src/geometry/initializer/ScalarFieldFromBody.impl.h b/src/geometry/initializer/ScalarFieldFromBody.impl.h index 25f459552406edb2d5accf5c88117e0fead84697..fc40429549525a7d6a52af2abbc2433cbf8b7106 100644 --- a/src/geometry/initializer/ScalarFieldFromBody.impl.h +++ b/src/geometry/initializer/ScalarFieldFromBody.impl.h @@ -30,6 +30,7 @@ #include "core/config/Config.h" #include "core/logging/Logging.h" #include "core/mpi/Reduce.h" +#include "core/stringToNum.h" namespace walberla { @@ -64,7 +65,7 @@ namespace initializer { try { - Value_T value = string_to_num<Value_T>(expression); + Value_T value = stringToNum<Value_T>(expression); init ( *bodyFromConfig ( subBlock ), value, addOrSet, id ); } diff --git a/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h b/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h index 8e65dcfb475790f585984252b79d0e5a2aa6b896..8cbbb951493954da720be381b7ccfcf27b026a3f 100644 --- a/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h +++ b/src/geometry/initializer/ScalarFieldFromCellInterval.impl.h @@ -20,7 +20,7 @@ // //====================================================================================================================== - +#include "core/stringToNum.h" namespace walberla { namespace geometry { @@ -62,7 +62,7 @@ void ScalarFieldFromCellInterval<Field_T>::init( const Config::BlockHandle & blo try { - Value_T value = string_to_num<Value_T>(expression); + Value_T value = stringToNum<Value_T>(expression); init(globalCellInterval, value, id); } diff --git a/src/mesh_common/distance_octree/DistanceOctree.h b/src/mesh_common/distance_octree/DistanceOctree.h index 2c34b9c6c620e76b84568f710367459f20286809..ce1a21c16cd56f8ba9d78d59e3ae4570aa352968 100644 --- a/src/mesh_common/distance_octree/DistanceOctree.h +++ b/src/mesh_common/distance_octree/DistanceOctree.h @@ -33,6 +33,8 @@ #include "core/math/GenericAABB.h" #include "core/math/Vector3.h" +#include "core/typeToString.h" + #include <vector> #include <queue> diff --git a/src/pe/communication/Instantiate.h b/src/pe/communication/Instantiate.h index f10a27dddab2efb0a4a6b9ae375110fce368dd29..8c157be229421932f20220516be72f50b491012f 100644 --- a/src/pe/communication/Instantiate.h +++ b/src/pe/communication/Instantiate.h @@ -28,6 +28,7 @@ //************************************************************************************************* #include "core/Abort.h" +#include "core/debug/demangle.h" #include "core/math/AABB.h" #include "core/math/Vector3.h" @@ -57,7 +58,7 @@ void correctBodyPosition(const math::AABB& domain, const Vec3& center, Vec3& pos template < class BodyT > std::unique_ptr<BodyT> instantiate( mpi::RecvBuffer& /*buffer*/, const math::AABB& /*domain*/, const math::AABB& /*block*/, BodyT*& /*newBody*/ ) { - WALBERLA_ABORT( "Body instantiation not implemented! (" << demangle(typeid(BodyT).name()) << ")" ); + WALBERLA_ABORT( "Body instantiation not implemented! (" << debug::demangle(typeid(BodyT).name()) << ")" ); } } // namespace communication diff --git a/src/vtk/Initialization.cpp b/src/vtk/Initialization.cpp index c69f039f2869d74368481bb492045daa38f7b7fb..0b4fa456757bbe78a96d2b413d134201b809a145 100644 --- a/src/vtk/Initialization.cpp +++ b/src/vtk/Initialization.cpp @@ -24,6 +24,7 @@ #include "core/Abort.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "core/StringUtility.h" #include <functional> @@ -46,9 +47,9 @@ static void splitVector( T& x, T& y, T& z, const Config::BlockHandle& bb, const if( coordinates.size() != 3 ) WALBERLA_ABORT( errorMsg ); - x = string_to_num< T >( coordinates[0] ); - y = string_to_num< T >( coordinates[1] ); - z = string_to_num< T >( coordinates[2] ); + x = stringToNum< T >( coordinates[0] ); + y = stringToNum< T >( coordinates[1] ); + z = stringToNum< T >( coordinates[2] ); } diff --git a/tests/blockforest/BlockIDTest.cpp b/tests/blockforest/BlockIDTest.cpp index 10979b1f6a2a5af7dc96c2fcb90e7b630fb7cd7b..45e8fdbf0794c0a66bbb74a48188eb0a9f56cc96 100644 --- a/tests/blockforest/BlockIDTest.cpp +++ b/tests/blockforest/BlockIDTest.cpp @@ -41,7 +41,7 @@ static void test() { uint_t bit = 1; uint_t mask = 0; - for( uint_t i = 0; i != UINT_BITS; ++i ) { + for( uint_t i = 0; i != math::UINT_BITS; ++i ) { for( uint_t j = 0; j !=10000; ++j ) { @@ -50,7 +50,7 @@ static void test() { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t branches = walberla::math::intRandom<uint8_t>(); #else - const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( UINT_BITS - i - 1 ) / 3 ) ); + const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( math::UINT_BITS - i - 1 ) / 3 ) ); #endif std::vector< uint_t > branch; for( uint_t b = 0; b != branches; ++b ) @@ -102,7 +102,7 @@ static void test() { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t branches = walberla::math::intRandom<uint8_t>(); #else - const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( UINT_BITS - i - 1 ) / 3 ) ); + const uint_t branches = walberla::math::intRandom( uint_t(0), uint_c( ( math::UINT_BITS - i - 1 ) / 3 ) ); #endif BlockID id( treeIndex, bit ); for( uint_t b = 0; b != branches; ++b ) diff --git a/tests/blockforest/SetupBlockForestTest.cpp b/tests/blockforest/SetupBlockForestTest.cpp index f910fe4ecb23ac6099f1676fd44d5ae71e762986..46d6d2cb2c40b66072f4d21bdc5d4ff0cacbf3af 100644 --- a/tests/blockforest/SetupBlockForestTest.cpp +++ b/tests/blockforest/SetupBlockForestTest.cpp @@ -52,8 +52,8 @@ static void refinementSelectionFunctionRandom( SetupBlockForest& forest ) { #ifndef WALBERLA_BLOCKFOREST_PRIMITIVE_BLOCKID const uint_t maxLevel = 25; #else - WALBERLA_ASSERT_GREATER_EQUAL( UINT_BITS, 32 ); - const uint_t maxLevel = ( UINT_BITS - 14 ) / 3; + WALBERLA_ASSERT_GREATER_EQUAL( math::UINT_BITS, 32 ); + const uint_t maxLevel = ( math::UINT_BITS - 14 ) / 3; #endif std::vector< SetupBlock* > blocks; diff --git a/tests/core/DataTypesTest.cpp b/tests/core/DataTypesTest.cpp index 8c8946b666d28cccea67da9cdc4628b4fb83fed2..4250c8d333cd15d674e29991ff77ac4c79272908 100644 --- a/tests/core/DataTypesTest.cpp +++ b/tests/core/DataTypesTest.cpp @@ -22,6 +22,7 @@ #include "core/DataTypes.h" #include "core/debug/Debug.h" #include "core/debug/TestSubsystem.h" +#include "core/math/Uint.h" #include <cstdlib> #include <iostream> @@ -39,17 +40,17 @@ int main( int /*argc*/, char** /*argv*/ ) { debug::enterTestMode(); - WALBERLA_CHECK_EQUAL( UINT_BITS_LD, uintBitsLd( UINT_BITS ) ); + WALBERLA_CHECK_EQUAL( math::UINT_BITS_LD, uintBitsLd( math::UINT_BITS ) ); - WALBERLA_CHECK_EQUAL( int_ld< 2048 >::exp, 11 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 2048 >::exp, 11 ); - WALBERLA_CHECK_EQUAL( int_ld< 64 >::exp, 6 ); - WALBERLA_CHECK_EQUAL( int_ld< 32 >::exp, 5 ); - WALBERLA_CHECK_EQUAL( int_ld< 16 >::exp, 4 ); - WALBERLA_CHECK_EQUAL( int_ld< 8 >::exp, 3 ); - WALBERLA_CHECK_EQUAL( int_ld< 4 >::exp, 2 ); - WALBERLA_CHECK_EQUAL( int_ld< 2 >::exp, 1 ); - WALBERLA_CHECK_EQUAL( int_ld< 1 >::exp, 0 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 64 >::exp, 6 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 32 >::exp, 5 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 16 >::exp, 4 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 8 >::exp, 3 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 4 >::exp, 2 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 2 >::exp, 1 ); + WALBERLA_CHECK_EQUAL( math::int_ld< 1 >::exp, 0 ); return EXIT_SUCCESS; } diff --git a/tests/core/load_balancing/MetisTest.cpp b/tests/core/load_balancing/MetisTest.cpp index 5db60e5ae786e14811fab22cd87cfccb903fa57b..98d13eeb68f65c016a321a084b4741fecdc1065d 100644 --- a/tests/core/load_balancing/MetisTest.cpp +++ b/tests/core/load_balancing/MetisTest.cpp @@ -28,6 +28,7 @@ #include "core/load_balancing/MetisWrapper.h" #include "core/math/Vector2.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/GhostLayerField.h" @@ -60,8 +61,8 @@ int main( int argc, char * argv[] ) } try { - fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) ); - partitions = string_to_num< uint_t >( args.at(3) ); + fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) ); + partitions = stringToNum< uint_t >( args.at(3) ); } catch( std::exception & e ) { diff --git a/tests/core/load_balancing/ParMetisTest.cpp b/tests/core/load_balancing/ParMetisTest.cpp index a9e79d3848dd327abc2d3682b12ed633b1e386fd..a02634c839cf77de7190ca2794696e7863f9bf59 100644 --- a/tests/core/load_balancing/ParMetisTest.cpp +++ b/tests/core/load_balancing/ParMetisTest.cpp @@ -29,6 +29,7 @@ #include "core/math/Vector2.h" #include "core/math/IntegerFactorization.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/GhostLayerField.h" @@ -55,8 +56,8 @@ int main( int argc, char * argv[] ) bool vtk = true; try { - fieldSize.set( string_to_num< uint_t >( args.at(1) ), string_to_num< uint_t >( args.at(2) ) ); - partitions = string_to_num< uint_t >( args.at(3) ); + fieldSize.set( stringToNum< uint_t >( args.at(1) ), stringToNum< uint_t >( args.at(2) ) ); + partitions = stringToNum< uint_t >( args.at(3) ); auto it = std::find( args.begin(), args.end(), "--no-vtk" ); if(it != args.end()) diff --git a/tests/core/mpi/MPITextFileTest.cpp b/tests/core/mpi/MPITextFileTest.cpp index a0ed6e61cc4429ca9f5369b71ec908a8fd4a5bb9..f3e17dbd188ad3f0a091fafa801cfdb58303e252 100644 --- a/tests/core/mpi/MPITextFileTest.cpp +++ b/tests/core/mpi/MPITextFileTest.cpp @@ -27,6 +27,8 @@ #include "core/mpi/MPIManager.h" #include "core/mpi/MPITextFile.h" +#include "core/stringToNum.h" + #include "core/Filesystem.h" #include <vector> @@ -120,7 +122,7 @@ int main( int argc, char * argv[] ) std::string filename; try { - chunkSize = walberla::string_to_num<size_t>( args.at(2) ); + chunkSize = walberla::stringToNum<size_t>( args.at(2) ); filename = args.at( 1 ); } catch( ... ) diff --git a/tests/field/FieldFileIOTest.cpp b/tests/field/FieldFileIOTest.cpp index 1214f01992c75d6a1226ea2306e9386848fe7faf..53d1c106166cab0265eff8f5d96510dd3c6ce960 100644 --- a/tests/field/FieldFileIOTest.cpp +++ b/tests/field/FieldFileIOTest.cpp @@ -28,6 +28,7 @@ #include "core/mpi/Environment.h" #include "core/timing/Timer.h" #include "core/math/IntegerFactorization.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/Field.h" @@ -84,10 +85,10 @@ int main( int argc, char* argv[] ) if( args.size() == 5 ) { - numBlocks = string_to_num<uint_t>( args[1] ); - xBlockSize = string_to_num<uint_t>( args[2] ); - yBlockSize = string_to_num<uint_t>( args[3] ); - zBlockSize = string_to_num<uint_t>( args[4] ); + numBlocks = stringToNum<uint_t>( args[1] ); + xBlockSize = stringToNum<uint_t>( args[2] ); + yBlockSize = stringToNum<uint_t>( args[3] ); + zBlockSize = stringToNum<uint_t>( args[4] ); } else if( args.size() > 5 ) { diff --git a/tests/lbm/DiffusionTest.cpp b/tests/lbm/DiffusionTest.cpp index a01187c455108ab7d76597685d2e835183df4b67..e834fb0626fdbdf74d40eebe5cb455313ce4bf7a 100644 --- a/tests/lbm/DiffusionTest.cpp +++ b/tests/lbm/DiffusionTest.cpp @@ -62,6 +62,7 @@ #include "core/math/Constants.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -198,14 +199,14 @@ int run( int argc, char **argv ) if( argc > 1 ) { std::vector<std::string> args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-d" ) d = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-dim" ) dim = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-dx" ) dx = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-dt" ) dt = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-dv" ) dv = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-v" ) u_in = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-err" ) err = string_to_num<real_t>( args[++i] ); + if( std::string(argv[i]) == "-d" ) d = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-dim" ) dim = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-dx" ) dx = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-dt" ) dt = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-dv" ) dv = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-v" ) u_in = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-err" ) err = stringToNum<real_t>( args[++i] ); else if( std::string(argv[i]) == "--gui" ) useGui = true; else if( std::string(argv[i]) == "--quiet" ) quiet = true; else if( std::string(argv[i]) == "--vtk" ) useVTK = true; diff --git a/tests/lbm/boundary/DiffusionDirichlet.cpp b/tests/lbm/boundary/DiffusionDirichlet.cpp index b9215d4321f5445f0c04360ede0c8b8dd674aaa3..a8c3348f8827fc9d8c38416f3f9040b4b9e09608 100644 --- a/tests/lbm/boundary/DiffusionDirichlet.cpp +++ b/tests/lbm/boundary/DiffusionDirichlet.cpp @@ -59,6 +59,7 @@ #include "core/math/Constants.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -222,12 +223,12 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector<std::string> args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-v" ) velx = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-e" ) error = string_to_num<real_t>( args[++i] ); + if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-v" ) velx = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-e" ) error = stringToNum<real_t>( args[++i] ); else if( std::string(argv[i]) == "--gui" ) useGui = true; else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ diff --git a/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp b/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp index ab7efa8e037dc4adb0a60c9bd57731a6c53cb799..9bcc236e97de9441a4f40eb876f5bdb519051be6 100644 --- a/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp +++ b/tests/lbm/boundary/SimpleDiffusionDirichlet.cpp @@ -51,6 +51,7 @@ #include "core/math/IntegerFactorization.h" #include "core/math/Limits.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -430,13 +431,13 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector<std::string> args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-d" ) dv = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-c" ) closed = string_to_num<int>( args[++i] ) != 0; - else if( std::string(argv[i]) == "-r" ) levels += string_to_num<uint_t>( args[++i] ); + if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-d" ) dv = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-c" ) closed = stringToNum<int>( args[++i] ) != 0; + else if( std::string(argv[i]) == "-r" ) levels += stringToNum<uint_t>( args[++i] ); else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE; diff --git a/tests/lbm/boundary/SimplePABTest.cpp b/tests/lbm/boundary/SimplePABTest.cpp index a1de4f92ff59a1c018ef7501bb5de55a2231dc2d..c02562a964ead68f198dd7be2b18c1880746de03 100644 --- a/tests/lbm/boundary/SimplePABTest.cpp +++ b/tests/lbm/boundary/SimplePABTest.cpp @@ -42,6 +42,7 @@ #include "core/debug/TestSubsystem.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/MPIManager.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -215,11 +216,11 @@ int main( int argc, char **argv ) if( args.size() != 6 ) throw std::invalid_argument( "Wrong number of command line arguments!" ); - channelLength = string_to_num<uint_t>( args[1] ); - channelWidth = string_to_num<uint_t>( args[2] ); - omega = string_to_num<real_t>( args[3] ); - deltaDensity = string_to_num<real_t>( args[4] ); - numTimesteps = string_to_num<uint_t>( args[5] ); + channelLength = stringToNum<uint_t>( args[1] ); + channelWidth = stringToNum<uint_t>( args[2] ); + omega = stringToNum<real_t>( args[3] ); + deltaDensity = stringToNum<real_t>( args[4] ); + numTimesteps = stringToNum<uint_t>( args[5] ); } catch( std::exception & ) { diff --git a/tests/lbm/refinement/NonConstantDiffusion.cpp b/tests/lbm/refinement/NonConstantDiffusion.cpp index d931cb35eacde2a34399d3f264dbfa20356cb96b..3a12591a529feb5a5a401bf60b2158a4f515f4a0 100644 --- a/tests/lbm/refinement/NonConstantDiffusion.cpp +++ b/tests/lbm/refinement/NonConstantDiffusion.cpp @@ -50,6 +50,7 @@ #include "core/math/IntegerFactorization.h" #include "core/math/Limits.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "domain_decomposition/SharedSweep.h" @@ -274,15 +275,15 @@ int main( int argc, char **argv ) if( argc > 1 ) { std::vector<std::string> args( argv, argv + argc ); for( uint_t i = 1; i < uint_c(argc); ++i ) { - if( std::string(argv[i]) == "-l" ) length = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-w" ) width = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-t" ) time = string_to_num<uint_t>( args[++i] ); - else if( std::string(argv[i]) == "-dv" ) dv = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-v" ) v = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-do" ) domega = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-o" ) omega = string_to_num<real_t>( args[++i] ); - else if( std::string(argv[i]) == "-c" ) closed = string_to_num<int>( args[++i] ) != 0; - else if( std::string(argv[i]) == "-r" ) levels += string_to_num<uint_t>( args[++i] ); + if( std::string(argv[i]) == "-l" ) length = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-w" ) width = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-t" ) time = stringToNum<uint_t>( args[++i] ); + else if( std::string(argv[i]) == "-dv" ) dv = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-v" ) v = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-do" ) domega = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-o" ) omega = stringToNum<real_t>( args[++i] ); + else if( std::string(argv[i]) == "-c" ) closed = stringToNum<int>( args[++i] ) != 0; + else if( std::string(argv[i]) == "-r" ) levels += stringToNum<uint_t>( args[++i] ); else if( std::string(argv[i]) == "--vtk" ) useVTK = true; else if( argv[i][0] != '-' ){ std::cerr << "Usage: -option value" << std::endl; return EXIT_FAILURE; diff --git a/tests/mesh/MeshAABBIntersectionTest.cpp b/tests/mesh/MeshAABBIntersectionTest.cpp index 45f38ecc66a5beb721cf72312b500f8b97350a94..451fe062b7f51f7ba96780f3ca03ce271d050355 100644 --- a/tests/mesh/MeshAABBIntersectionTest.cpp +++ b/tests/mesh/MeshAABBIntersectionTest.cpp @@ -24,6 +24,7 @@ #include "core/math/AABB.h" #include "core/mpi/Environment.h" #include "core/Optional.h" +#include "core/stringToNum.h" #include "mesh_common/MeshIO.h" #include "mesh_common/MeshOperations.h" @@ -87,7 +88,7 @@ int main( int argc, char * argv[] ) if( args.size() != 2 ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " NUM_AABBS" ); - const uint_t numAABBs = string_to_num< uint_t >( args[1] ); + const uint_t numAABBs = stringToNum< uint_t >( args[1] ); runTests< mesh::TriangleMesh >( numAABBs ); runTests< mesh::FloatTriangleMesh >( numAABBs ); diff --git a/tests/mesh/MeshAABBSelectionTest.cpp b/tests/mesh/MeshAABBSelectionTest.cpp index 94bdad9a2e27f6ada67c9c7d839c397943bab322..3e92e09e76f6a4f0455aafbd042059158f361feb 100644 --- a/tests/mesh/MeshAABBSelectionTest.cpp +++ b/tests/mesh/MeshAABBSelectionTest.cpp @@ -22,6 +22,7 @@ #include "core/debug/TestSubsystem.h" #include "core/mpi/Environment.h" #include "core/logging/Logging.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -51,8 +52,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BOXES NUM_POINTS_TESTED_PER_BOX" ); const std::string & meshFile = args[1]; - const uint_t numBoxes = string_to_num<uint_t>( args[2] ); - const uint_t numPointsTestedPerBox = string_to_num<uint_t>( args[3] ); + const uint_t numBoxes = stringToNum<uint_t>( args[2] ); + const uint_t numPointsTestedPerBox = stringToNum<uint_t>( args[3] ); auto mesh = make_shared<TriangleMesh>(); mesh::readAndBroadcast( meshFile, *mesh ); diff --git a/tests/mesh/MeshBlockExclusionTest.cpp b/tests/mesh/MeshBlockExclusionTest.cpp index d3cb21efb9ec2a03c051d369d398d5c76d958c07..cebd9c96d457293f9702b118f44cc6623bc2bd3c 100644 --- a/tests/mesh/MeshBlockExclusionTest.cpp +++ b/tests/mesh/MeshBlockExclusionTest.cpp @@ -26,6 +26,7 @@ #include "core/logging/Logging.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -148,7 +149,7 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_BLOCKS" ); const std::string & meshFile = args[1]; - const uint_t numTotalBlocks = string_to_num< uint_t >( args[2] ); + const uint_t numTotalBlocks = stringToNum< uint_t >( args[2] ); run< mesh::TriangleMesh >( meshFile, numTotalBlocks ); run< mesh::FloatTriangleMesh >( meshFile, numTotalBlocks ); diff --git a/tests/mesh/MeshDistancePlausibilityTest.cpp b/tests/mesh/MeshDistancePlausibilityTest.cpp index 8b7ccb5858d9a488ceb82e09026ee357c87f1001..1263b06b38d9bf042f79dc1fa11a6aabc5af4998 100644 --- a/tests/mesh/MeshDistancePlausibilityTest.cpp +++ b/tests/mesh/MeshDistancePlausibilityTest.cpp @@ -26,6 +26,7 @@ #include "core/debug/TestSubsystem.h" #include "core/logging/Logging.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "field/AddToStorage.h" #include "field/vtk/VTKWriter.h" @@ -72,7 +73,7 @@ int main( int argc, char * argv[] ) args.erase( vtkArgIt ); } const std::string & meshFile = args[1]; - real_t dx = string_to_num<real_t>( args[2] ); + real_t dx = stringToNum<real_t>( args[2] ); auto mesh = make_shared<mesh::TriangleMesh>(); mesh::readAndBroadcast( meshFile, *mesh); diff --git a/tests/mesh/MeshInitilizationTest.cpp b/tests/mesh/MeshInitilizationTest.cpp index e3460d3ce38d65c89a29df0c164a647d6deab602..c536f5e343054d084b0a90965a899b3252db5ca3 100644 --- a/tests/mesh/MeshInitilizationTest.cpp +++ b/tests/mesh/MeshInitilizationTest.cpp @@ -27,6 +27,7 @@ #include "core/logging/Logging.h" #include "core/math/IntegerFactorization.h" #include "core/mpi/Environment.h" +#include "core/stringToNum.h" #include "geometry/mesh/TriangleMesh.h" #include "geometry/mesh/TriangleMeshIO.h" @@ -177,8 +178,8 @@ int main( int argc, char * argv[] ) WALBERLA_ABORT_NO_DEBUG_INFO( "USAGE: " << args[0] << " MESH_FILE NUM_PROCESSES NUM_BLOCKS" ); const std::string & meshFile = args[1]; - const uint_t numProcesses = string_to_num< uint_t >( args[2] ); - const uint_t numTotalBlocks = string_to_num< uint_t >( args[3] ); + const uint_t numProcesses = stringToNum< uint_t >( args[2] ); + const uint_t numTotalBlocks = stringToNum< uint_t >( args[3] ); test< mesh::TriangleMesh >( meshFile, numProcesses, numTotalBlocks ); //test< mesh::FloatTriangleMesh >( meshFile, numProcesses, numTotalBlocks );