diff --git a/src/pe/amr/BlockInfo.h b/src/pe/amr/BlockInfo.h new file mode 100644 index 0000000000000000000000000000000000000000..fccc9656bc50865de3e38dadb8454af468935370 --- /dev/null +++ b/src/pe/amr/BlockInfo.h @@ -0,0 +1,87 @@ +//====================================================================================================================== +// +// 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 BlockInfo.h +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include <core/mpi/RecvBuffer.h> +#include <core/mpi/SendBuffer.h> + +#include <ostream> + +namespace walberla { +namespace pe { + +struct BlockInfo +{ + uint_t numberOfLocalBodies; + uint_t numberOfShadowBodies; + + BlockInfo() + : numberOfLocalBodies(0) + , numberOfShadowBodies(0) + {} + + BlockInfo(const uint_t particles, const uint_t sparticles) + : numberOfLocalBodies(particles) + , numberOfShadowBodies(sparticles) + {} + + BlockInfo& operator+=( const BlockInfo& rhs ) + { + numberOfLocalBodies += rhs.numberOfLocalBodies; + numberOfShadowBodies += rhs.numberOfShadowBodies; + return *this; + } +}; + +inline +BlockInfo operator+ ( const BlockInfo& lhs, const BlockInfo& rhs ) +{ + BlockInfo result(lhs); + result += rhs; + return result; +} + +inline +std::ostream& operator<<( std::ostream& os, const BlockInfo& bi ) +{ + os << bi.numberOfLocalBodies << " / " << bi.numberOfShadowBodies; + return os; +} + +template< typename T, // Element type of SendBuffer + typename G> // Growth policy of SendBuffer +mpi::GenericSendBuffer<T,G>& operator<<( mpi::GenericSendBuffer<T,G> & buf, const BlockInfo& info ) +{ + buf.addDebugMarker( "pa" ); + buf << info.numberOfLocalBodies << info.numberOfShadowBodies; + return buf; +} + +template< typename T> // Element type of SendBuffer +mpi::GenericRecvBuffer<T>& operator>>( mpi::GenericRecvBuffer<T> & buf, BlockInfo& info ) +{ + buf.readDebugMarker( "pa" ); + buf >> info.numberOfLocalBodies >> info.numberOfShadowBodies; + return buf; +} + +} +} diff --git a/src/pe/amr/InfoCollection.cpp b/src/pe/amr/InfoCollection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f568a3cca62eada47d72be977d834ca8d98532d6 --- /dev/null +++ b/src/pe/amr/InfoCollection.cpp @@ -0,0 +1,67 @@ +//====================================================================================================================== +// +// 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 InfoCollection.cpp +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#include "InfoCollection.h" + +#include "pe/rigidbody/BodyStorage.h" + +#include "blockforest/BlockID.h" +#include "core/mpi/BufferSystem.h" + +namespace walberla { +namespace pe { + +void createWithNeighborhood(const BlockForest& bf, const BlockDataID storageID, InfoCollection& ic ) +{ + ic.clear(); + + mpi::BufferSystem bs( MPIManager::instance()->comm(), 756 ); + + for (auto blockIt = bf.begin(); blockIt != bf.end(); ++blockIt) + { + const blockforest::Block* block = static_cast<const blockforest::Block*> (&(*blockIt)); + Storage const * storage = block->getData< Storage >( storageID ); + BodyStorage const & localStorage = (*storage)[StorageType::LOCAL]; + BodyStorage const & shadowStorage = (*storage)[StorageType::SHADOW]; + ic.insert( InfoCollection::value_type(block->getId(), BlockInfo(localStorage.size(), shadowStorage.size())) ); + + for( uint_t nb = uint_t(0); nb < block->getNeighborhoodSize(); ++nb ) + { + bs.sendBuffer( block->getNeighborProcess(nb) ) << InfoCollection::value_type(block->getId(), BlockInfo(localStorage.size(), shadowStorage.size())); + } + } + + // size of buffer is unknown and changes with each send + bs.setReceiverInfoFromSendBufferState(false, true); + bs.sendAll(); + + for( auto recvIt = bs.begin(); recvIt != bs.end(); ++recvIt ) + { + while( !recvIt.buffer().isEmpty() ) + { + InfoCollectionPair val; + recvIt.buffer() >> val; + ic.insert(val); + } + } +} + +} +} diff --git a/src/pe/amr/InfoCollection.h b/src/pe/amr/InfoCollection.h new file mode 100644 index 0000000000000000000000000000000000000000..3acdc2f27b01ffa2f3f5d752325d8ffed336845a --- /dev/null +++ b/src/pe/amr/InfoCollection.h @@ -0,0 +1,38 @@ +//====================================================================================================================== +// +// 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 InfoCollection.h +//! \author Sebastian Eibl <sebastian.eibl@fau.de> +// +//====================================================================================================================== + +#pragma once + +#include "BlockInfo.h" + +#include "blockforest/BlockForest.h" + +#include <map> + +namespace walberla { +namespace pe { + +typedef std::map<blockforest::BlockID, BlockInfo> InfoCollection; +typedef std::pair<blockforest::BlockID, BlockInfo> InfoCollectionPair; + +void createWithNeighborhood(const BlockForest& bf, const BlockDataID storageID, InfoCollection& ic ); + +} +}