Commit cb431e5e authored by Sebastian Eibl's avatar Sebastian Eibl

added pe InfoCollection

parent 9b13353d
//======================================================================================================================
//
// 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;
}
}
}
//======================================================================================================================
//
// 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);
}
}
}
}
}
//======================================================================================================================
//
// 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 );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment