diff --git a/src/blockforest/BlockForest.cpp b/src/blockforest/BlockForest.cpp index 2fee938bc7fecf5fa61b9478f515ace38dfdffb7..a156b7e3f0a77352d82ab2bea02851038fbade58 100644 --- a/src/blockforest/BlockForest.cpp +++ b/src/blockforest/BlockForest.cpp @@ -538,10 +538,10 @@ BlockForest::BlockForest( const uint_t process, const char* const filename, cons const BlockID id( buffer, offset, blockIdBytes ); Set<SUID> state; - boost::dynamic_bitset< uint8_t > suidBitset = byteArrayToBitset( buffer, offset + blockIdBytes, suidBytes ); - for( uint_t j = 0; j != suidBitset.size(); ++j ) { - WALBERLA_ASSERT( !suidBitset.test( j ) || j < suidMap.size() ); - if( suidBitset.test( j ) ) + std::vector< bool > suidBoolVec = byteArrayToBoolVector( buffer, offset + blockIdBytes, suidBytes ); + for( uint_t j = 0; j != suidBoolVec.size(); ++j ) { + WALBERLA_ASSERT( !suidBoolVec[ j ] || j < suidMap.size() ); + if( suidBoolVec[j]) state += suidMap[j]; } @@ -560,10 +560,10 @@ BlockForest::BlockForest( const uint_t process, const char* const filename, cons const BlockID id( buffer, offset, blockIdBytes ); Set<SUID> state; - boost::dynamic_bitset< uint8_t > suidBitset = byteArrayToBitset( buffer, offset + blockIdBytes, suidBytes ); - for( uint_t k = 0; k != suidBitset.size(); ++k ) { - WALBERLA_ASSERT( !suidBitset.test( k ) || k < suidMap.size() ); - if( suidBitset.test( k ) ) + std::vector< bool > suidBoolVec = byteArrayToBoolVector( buffer, offset + blockIdBytes, suidBytes ); + for( uint_t k = 0; k != suidBoolVec.size(); ++k ) { + WALBERLA_ASSERT( !suidBoolVec[k] || k < suidMap.size() ); + if( suidBoolVec[k]) state += suidMap[k]; } @@ -584,10 +584,10 @@ BlockForest::BlockForest( const uint_t process, const char* const filename, cons // block state (SUID set) Set<SUID> state; - boost::dynamic_bitset< uint8_t > suidBitset = byteArrayToBitset( buffer, offset + blockIdBytes, suidBytes ); - for( uint_t j = 0; j != suidBitset.size(); ++j ) { - WALBERLA_ASSERT( !suidBitset.test( j ) || j < suidMap.size() ); - if( suidBitset.test( j ) ) + std::vector< bool > suidBoolVec = byteArrayToBoolVector( buffer, offset + blockIdBytes, suidBytes ); + for( uint_t j = 0; j != suidBoolVec.size(); ++j ) { + WALBERLA_ASSERT( !suidBoolVec[j] || j < suidMap.size() ); + if( suidBoolVec[j]) state += suidMap[j]; } @@ -618,10 +618,10 @@ BlockForest::BlockForest( const uint_t process, const char* const filename, cons ids.emplace_back( buffer, offset, blockIdBytes ); Set<SUID> state; - boost::dynamic_bitset< uint8_t > suidBitset = byteArrayToBitset( buffer, offset + blockIdBytes, suidBytes ); - for( uint_t k = 0; k != suidBitset.size(); ++k ) { - WALBERLA_ASSERT( !(suidBitset.test( k ) ) || k < suidMap.size() ); - if( suidBitset.test( k ) ) + std::vector< bool > suidBoolVec = byteArrayToBoolVector( buffer, offset + blockIdBytes, suidBytes ); + for( uint_t k = 0; k != suidBoolVec.size(); ++k ) { + WALBERLA_ASSERT( !suidBoolVec[k] || k < suidMap.size() ); + if( suidBoolVec[k]) state += suidMap[k]; } @@ -1329,14 +1329,14 @@ void BlockForest::saveToFile( const std::string & filename, const Set<SUID> & bl const uint_t suidBytes = ( ( blockStates.size() % 8 == 0 ) ? ( blockStates.size() / 8 ) : ( blockStates.size() / 8 + 1 ) ); - std::map< SUID, boost::dynamic_bitset< uint8_t > > suidMap; + std::map< SUID, std::vector< bool > > suidMap; uint_t i = 0; for( Set<SUID>::const_iterator it = blockStates.begin(); it != blockStates.end(); ++it ) { - boost::dynamic_bitset< uint8_t > suidBitset( 8 * suidBytes ); - suidBitset.set( i, true ); - suidMap[ *it ] = suidBitset; + std::vector< bool > suidBoolVec( 8 * suidBytes ); + suidBoolVec[i] = true; + suidMap[ *it ] = suidBoolVec; ++i; } @@ -2758,7 +2758,7 @@ void BlockForest::update( PhantomBlockForest & phantomForest ) /// \attention 'suidMap' and 'suidBytes' must be identical for every process! /// \see BlockForestFile.h void BlockForest::saveToFile( const std::string & filename, FileIOMode fileIOMode, - const std::map< SUID, boost::dynamic_bitset<uint8_t> > & suidMap, const uint_t suidBytes ) const + const std::map< SUID, std::vector< bool > > & suidMap, const uint_t suidBytes ) const { // process data @@ -2834,7 +2834,7 @@ void BlockForest::saveToFile( const std::string & filename, FileIOMode fileIOMod // block state (SUID set) if( suidBytes > 0 ) { - boost::dynamic_bitset< uint8_t > suidBitset( 8 * suidBytes ); + std::vector< bool > suidBoolVec( 8 * suidBytes ); const Set<SUID> & state = block->second->getState(); for( auto suid = state.begin(); suid != state.end(); ++suid ) @@ -2842,10 +2842,13 @@ void BlockForest::saveToFile( const std::string & filename, FileIOMode fileIOMod WALBERLA_CHECK( suidMap.find( *suid ) != suidMap.end(), "Block state SUID missing from SUID list saved to file." "\n- SUID = " << *suid << "\n- block ID = " << block->first << "\n- block AABB = " << block->second->getAABB() ); - suidBitset |= suidMap.find( *suid )->second; + //Elementwise OR of all elements + for (uint_t i = 0; i < suidBoolVec.size(); ++i) { + suidBoolVec[i] = suidBoolVec[i] | suidMap.find( *suid )->second[i]; + } } - bitsetToByteArray( suidBitset, processDataBuffer, offset ); + boolVectorToByteArray( suidBoolVec, processDataBuffer, offset ); offset += suidBytes; } } diff --git a/src/blockforest/BlockForest.h b/src/blockforest/BlockForest.h index 5d9a28628a7e23aa9029c1707d435bb0ef82fad0..c109a605390f9f6213006de800ee697f4d0a91ab 100644 --- a/src/blockforest/BlockForest.h +++ b/src/blockforest/BlockForest.h @@ -501,7 +501,7 @@ private: void update( PhantomBlockForest & phantomForest ); void saveToFile( const std::string & filename, FileIOMode fileIOMode, - const std::map< SUID, boost::dynamic_bitset<uint8_t> > & suidMap, const uint_t suidBytes ) const; + const std::map< SUID, std::vector< bool > > & suidMap, const uint_t suidBytes ) const; void storeFileHeader( std::vector< uint8_t > & data, uint_t & offset ) const; diff --git a/src/blockforest/SetupBlockForest.cpp b/src/blockforest/SetupBlockForest.cpp index 66201296835f62bb5c9d28f9180d060503bcbbb7..a6c2e9a0a1e8ba22cae9c48d9b24bb8dfe442281 100644 --- a/src/blockforest/SetupBlockForest.cpp +++ b/src/blockforest/SetupBlockForest.cpp @@ -37,8 +37,6 @@ #include "domain_decomposition/MapPointToPeriodicDomain.h" -#include <boost/dynamic_bitset.hpp> - #include <cmath> #include <fstream> #include <iomanip> @@ -1700,7 +1698,7 @@ void SetupBlockForest::saveToFile( const char* const filename ) const { file.write( reinterpret_cast< const char* >( &(buffer[0]) ), numeric_cast< std::streamsize >( buffer.size() ) ); buffer.clear(); - std::map< SUID, boost::dynamic_bitset< uint8_t > > suidMap; + std::map< SUID, std::vector< bool > > suidMap; const uint_t suidBytes = ( ( suids.size() % 8 == 0 ) ? ( suids.size() / 8 ) : ( suids.size() / 8 + 1 ) ); @@ -1709,9 +1707,9 @@ void SetupBlockForest::saveToFile( const char* const filename ) const { uint_t i = 0; for( Set<SUID>::const_iterator it = suids.begin(); it != suids.end(); ++it ) { - boost::dynamic_bitset< uint8_t > suidBitset( 8 * suidBytes ); - suidBitset.set( i, true ); - suidMap[ *it ] = suidBitset; + std::vector< bool > suidBoolVec( 8 * suidBytes ); + suidBoolVec[i] = true; + suidMap[ *it ] = suidBoolVec; // length of its identifier string @@ -1774,16 +1772,18 @@ void SetupBlockForest::saveToFile( const char* const filename ) const { // block state (SUID set) if( suidBytes > 0 ) { - - boost::dynamic_bitset< uint8_t > suidBitset( 8 * suidBytes ); + std::vector< bool > suidBoolVec( 8 * suidBytes ); const Set<SUID>& state = block->getState(); for( Set<SUID>::const_iterator suid = state.begin(); suid != state.end(); ++suid ) { WALBERLA_ASSERT( suidMap.find( *suid ) != suidMap.end() ); - suidBitset |= suidMap[ *suid ]; + //Elementwise OR of all elements + for (uint_t k = 0;k < suidBoolVec.size(); ++k) { + suidBoolVec[k] = suidBoolVec[k] | suidMap.find( *suid )->second[k]; + } } - bitsetToByteArray( suidBitset, buffer, offset ); + boolVectorToByteArray( suidBoolVec, buffer, offset ); offset += suidBytes; } diff --git a/src/core/EndianIndependentSerialization.h b/src/core/EndianIndependentSerialization.h index 36a9e8eb0ecbe5e0e23f6e4acc2ad029bf93acad..e33b8ab3ae731b4aa9b7a0fcb2499d60fbc15fd0 100644 --- a/src/core/EndianIndependentSerialization.h +++ b/src/core/EndianIndependentSerialization.h @@ -24,8 +24,6 @@ #include "DataTypes.h" #include "core/debug/Debug.h" -#include <boost/dynamic_bitset.hpp> - #include <cmath> #include <limits> #include <vector> @@ -146,33 +144,35 @@ REAL_T byteArrayToReal( const std::vector< uint8_t >& array, const uint_t offset } - -inline void bitsetToByteArray( const boost::dynamic_bitset< uint8_t >& bitset, std::vector< uint8_t >& array, const uint_t offset ) +inline void boolVectorToByteArray( const std::vector< bool >& boolVec, std::vector< uint8_t >& array, const uint_t offset ) { static const uint_t bit[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; - const uint_t bytes = bitset.num_blocks(); + WALBERLA_ASSERT_EQUAL( boolVec.size() % 8, uint_t(0) ); + const uint_t bytes = uint_c(boolVec.size() / 8); WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); for( uint_t i = 0; i != bytes; ++i ) { - array[ offset + i ] = uint8_c( bitset[i*8+0]*bit[0] + bitset[i*8+1]*bit[1] + bitset[i*8+2]*bit[2] + bitset[i*8+3]*bit[3] + - bitset[i*8+4]*bit[4] + bitset[i*8+5]*bit[5] + bitset[i*8+6]*bit[6] + bitset[i*8+7]*bit[7] ); + WALBERLA_ASSERT_LESS_EQUAL(offset + i, array.size()); + array[ offset + i ] = uint8_c( boolVec[i*8+0]*bit[0] + boolVec[i*8+1]*bit[1] + boolVec[i*8+2]*bit[2] + boolVec[i*8+3]*bit[3] + + boolVec[i*8+4]*bit[4] + boolVec[i*8+5]*bit[5] + boolVec[i*8+6]*bit[6] + boolVec[i*8+7]*bit[7] ); } } -inline boost::dynamic_bitset< uint8_t > byteArrayToBitset( const std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) + +inline std::vector< bool > byteArrayToBoolVector( const std::vector< uint8_t >& array, const uint_t offset, const uint_t bytes ) { static const uint8_t bit[] = { 1, 2, 4, 8, 16, 32, 64, 128 }; WALBERLA_ASSERT_LESS_EQUAL( offset + bytes, array.size() ); - boost::dynamic_bitset< uint8_t > bitset( 8 * bytes ); + std::vector< bool > boolVec( 8 * bytes ); for( uint_t i = 0; i != bytes; ++i ) for( uint_t j = 0; j != 8; ++j ) - bitset.set( i * 8 + j, (array[ offset + i ] & bit[j]) != uint8_t(0) ); + boolVec[i * 8 + j] = (array[offset + i] & bit[j]) != uint8_t(0); - return bitset; + return boolVec; }