Skip to content
Snippets Groups Projects
Commit 8ef2002b authored by Sebastian Eibl's avatar Sebastian Eibl
Browse files

Merge branch '19-loadblockdata-saveblockdata-not-working-for-pe' into 'master'

Resolve "loadBlockData/saveBlockData not working for pe"

Closes #19

See merge request !19
parents bd907d04 5b53ddcd
No related merge requests found
...@@ -47,4 +47,5 @@ ...@@ -47,4 +47,5 @@
#include "pe/synchronization/SyncNextNeighbors.h" #include "pe/synchronization/SyncNextNeighbors.h"
#include "pe/synchronization/SyncShadowOwners.h" #include "pe/synchronization/SyncShadowOwners.h"
#include "pe/utility/CreateWorld.h"
#include "pe/utility/GetBody.h" #include "pe/utility/GetBody.h"
...@@ -746,6 +746,30 @@ void HashGrids::clear() ...@@ -746,6 +746,30 @@ void HashGrids::clear()
} }
//************************************************************************************************* //*************************************************************************************************
//*************************************************************************************************
/*!\brief clears all bodies from the hash grid and reloads bodies from bodystorage and shadowbodystorage
*
* \return void
*/
void HashGrids::reloadBodies()
{
clear();
for (auto bodyIt = bodystorage_.begin(); bodyIt != bodystorage_.end(); ++bodyIt)
{
add( *bodyIt );
}
if( &bodystorage_ != &bodystorageShadowCopies_ )
{
for (auto bodyIt = bodystorageShadowCopies_.begin(); bodyIt != bodystorageShadowCopies_.end(); ++bodyIt)
{
add( *bodyIt );
}
}
}
//*************************************************************************************************
//**Implementation of ICCD interface ******************************************************** //**Implementation of ICCD interface ********************************************************
//************************************************************************************************* //*************************************************************************************************
/*!\brief Contact generation between colliding rigid bodies. /*!\brief Contact generation between colliding rigid bodies.
......
...@@ -272,6 +272,7 @@ public: ...@@ -272,6 +272,7 @@ public:
/*!\name Utility functions */ /*!\name Utility functions */
//@{ //@{
void clear (); void clear ();
void reloadBodies();
//@} //@}
//********************************************************************************************** //**********************************************************************************************
......
...@@ -38,7 +38,8 @@ public: ...@@ -38,7 +38,8 @@ public:
virtual PossibleContacts& generatePossibleContacts( WcTimingTree* tt = NULL ) = 0; virtual PossibleContacts& generatePossibleContacts( WcTimingTree* tt = NULL ) = 0;
PossibleContacts& getPossibleContacts() {return contacts_;} PossibleContacts& getPossibleContacts() {return contacts_;}
virtual int getObservedBodyCount() const = 0; virtual void reloadBodies() {};
virtual int getObservedBodyCount() const = 0;
protected: protected:
PossibleContacts contacts_; PossibleContacts contacts_;
}; };
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "pe/communication/DynamicMarshalling.h" #include "pe/communication/DynamicMarshalling.h"
#include "blockforest/BlockDataHandling.h" #include "blockforest/BlockDataHandling.h"
#include "core/Abort.h"
namespace walberla{ namespace walberla{
namespace pe{ namespace pe{
...@@ -37,14 +38,14 @@ namespace pe{ ...@@ -37,14 +38,14 @@ namespace pe{
template<typename BodyTuple> template<typename BodyTuple>
class StorageDataHandling : public domain_decomposition::BlockDataHandling<Storage>{ class StorageDataHandling : public domain_decomposition::BlockDataHandling<Storage>{
public: public:
Storage * initialize( IBlock * const /*block*/ ) {return new Storage();} Storage * initialize( IBlock * const /*block*/ ) {return new Storage();}
/// must be thread-safe ! /// must be thread-safe !
virtual inline void serialize( IBlock * const block, const BlockDataID & id, mpi::SendBuffer & buffer ); virtual inline void serialize( IBlock * const block, const BlockDataID & id, mpi::SendBuffer & buffer );
/// must be thread-safe ! /// must be thread-safe !
virtual inline Storage * deserialize( IBlock * const block ); virtual inline Storage * deserialize( IBlock * const block );
/// must be thread-safe ! /// must be thread-safe !
virtual inline void deserialize( IBlock * const block, const BlockDataID & id, mpi::RecvBuffer & buffer ); virtual inline void deserialize( IBlock * const block, const BlockDataID & id, mpi::RecvBuffer & buffer );
}; };
template<typename BodyTuple> template<typename BodyTuple>
...@@ -55,6 +56,10 @@ inline void StorageDataHandling<BodyTuple>::serialize( IBlock * const block, con ...@@ -55,6 +56,10 @@ inline void StorageDataHandling<BodyTuple>::serialize( IBlock * const block, con
buffer << localBodyStorage.size(); buffer << localBodyStorage.size();
for (auto bodyIt = localBodyStorage.begin(); bodyIt != localBodyStorage.end(); ++bodyIt) for (auto bodyIt = localBodyStorage.begin(); bodyIt != localBodyStorage.end(); ++bodyIt)
{ {
if ( !block->getAABB().contains( bodyIt->getPosition()) )
{
WALBERLA_ABORT( "Body to be stored not contained within block!" );
}
marshal( buffer, RigidBodyCopyNotification( **bodyIt ) ); marshal( buffer, RigidBodyCopyNotification( **bodyIt ) );
MarshalDynamically<BodyTuple>::execute( buffer, **bodyIt ); MarshalDynamically<BodyTuple>::execute( buffer, **bodyIt );
} }
...@@ -84,6 +89,10 @@ inline void StorageDataHandling<BodyTuple>::deserialize( IBlock * const block, c ...@@ -84,6 +89,10 @@ inline void StorageDataHandling<BodyTuple>::deserialize( IBlock * const block, c
BodyID bd = UnmarshalDynamically<BodyTuple>::execute(buffer, objparam.geomType_, math::AABB(-inf, -inf, -inf, inf, inf, inf), block->getAABB()); BodyID bd = UnmarshalDynamically<BodyTuple>::execute(buffer, objparam.geomType_, math::AABB(-inf, -inf, -inf, inf, inf, inf), block->getAABB());
bd->setRemote( false ); bd->setRemote( false );
if ( !block->getAABB().contains( bd->getPosition()) )
{
WALBERLA_ABORT("Loaded body not contained within block!" );
}
WALBERLA_ASSERT_EQUAL(localBodyStorage.find( bd->getSystemID() ), localBodyStorage.end()); WALBERLA_ASSERT_EQUAL(localBodyStorage.find( bd->getSystemID() ), localBodyStorage.end());
localBodyStorage.add(bd); localBodyStorage.add(bd);
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
// with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
// //
//! \file CreateWorld.cpp //! \file CreateWorld.cpp
//! \author Klaus Iglberger
//! \author Sebastian Eibl <sebastian.eibl@fau.de> //! \author Sebastian Eibl <sebastian.eibl@fau.de>
// //
//====================================================================================================================== //======================================================================================================================
...@@ -34,12 +33,10 @@ ...@@ -34,12 +33,10 @@
namespace walberla { namespace walberla {
namespace pe { namespace pe {
shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf) shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic)
{ {
math::AABB simulationDomain = math::AABB( Vec3(0,0,0), mainConf.getParameter<Vec3>("simulationDomain", Vec3(10, 10, 10)));
Vector3<uint_t> blocks = mainConf.getParameter<Vector3<uint_t>>("blocks", Vector3<uint_t>(3, 3, 3));
Vector3<bool> isPeriodic = mainConf.getParameter<Vector3<bool>>("isPeriodic", Vector3<bool>(true, true, true));
if (isPeriodic[0] && blocks[0]<2) if (isPeriodic[0] && blocks[0]<2)
{ {
WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic x direction (" << blocks[0] << ")! Setting to 2..." ); WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic x direction (" << blocks[0] << ")! Setting to 2..." );
...@@ -56,46 +53,61 @@ shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& m ...@@ -56,46 +53,61 @@ shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& m
blocks[2] = 2; blocks[2] = 2;
} }
// const uint_t numberOfProcesses = blocks[0] * blocks[1] * blocks[2]; return blockforest::createBlockForest( simulationDomain,
blocks[0], blocks[1], blocks[2],
blocks[0], blocks[1], blocks[2],
isPeriodic[0],isPeriodic[1],isPeriodic[2],
false );
}
if( !mainConf.isDefined( "sbfFile" ) ) shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const bool setupRun,
const std::string sbffile)
{
if (isPeriodic[0] && blocks[0]<2)
{ {
WALBERLA_LOG_INFO_ON_ROOT( "No setup file specified: Creation without setup file!" ); WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic x direction (" << blocks[0] << ")! Setting to 2..." );
blocks[0] = 2;
return blockforest::createBlockForest( simulationDomain, }
blocks[0], blocks[1], blocks[2], if (isPeriodic[1] && blocks[1]<2)
blocks[0], blocks[1], blocks[2], {
isPeriodic[0],isPeriodic[1],isPeriodic[2], WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic y direction (" << blocks[1] << ")! Setting to 2..." );
false ); blocks[1] = 2;
}
if (isPeriodic[2] && blocks[2]<2)
{
WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic z direction (" << blocks[2] << ")! Setting to 2..." );
blocks[2] = 2;
} }
// sbf file given -> try to load or save domain decomposition
std::string sbffile = mainConf.getParameter< std::string >( "sbfFile" );
WALBERLA_LOG_INFO_ON_ROOT( "Setup file specified: Using " << sbffile ); WALBERLA_LOG_INFO_ON_ROOT( "Setup file specified: Using " << sbffile );
bool setupRun = mainConf.getParameter< bool >( "setupRun", true );
if (setupRun) if (setupRun)
{ {
WALBERLA_LOG_INFO_ON_ROOT("Setup run. For production run specify 'setupRun = true'"); WALBERLA_LOG_INFO_ON_ROOT("Setup run. For production run specify 'setupRun = false'");
if( MPIManager::instance()->numProcesses() > 1 ) if( MPIManager::instance()->numProcesses() > 1 )
WALBERLA_ABORT( "In this mode you need to start with just one process!" ); WALBERLA_LOG_WARNING_ON_ROOT( "Setup run with more than one process! Only root is doing work! I hope you know what you are doing!" );
WALBERLA_LOG_INFO_ON_ROOT( "Creating the block structure ..." ); WALBERLA_ROOT_SECTION()
{
WALBERLA_LOG_INFO_ON_ROOT( "Creating the block structure ..." );
SetupBlockForest sforest; SetupBlockForest sforest;
sforest.addWorkloadMemorySUIDAssignmentFunction( blockforest::uniformWorkloadAndMemoryAssignment ); sforest.addWorkloadMemorySUIDAssignmentFunction( blockforest::uniformWorkloadAndMemoryAssignment );
sforest.init( simulationDomain, blocks[0], blocks[1], blocks[2], isPeriodic[0], isPeriodic[1], isPeriodic[2] ); sforest.init( simulationDomain, blocks[0], blocks[1], blocks[2], isPeriodic[0], isPeriodic[1], isPeriodic[2] );
// calculate process distribution // calculate process distribution
sforest.balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), blocks[0] * blocks[1] * blocks[2] );
sforest.balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), blocks[0] * blocks[1] * blocks[2] ); sforest.saveToFile( sbffile.c_str() );
sforest.saveToFile( sbffile.c_str() ); WALBERLA_LOG_INFO_ON_ROOT( "SetupBlockForest successfully saved to file!" );
}
WALBERLA_LOG_INFO_ON_ROOT( "SetupBlockForest successfully saved to file!" )
return shared_ptr<BlockForest>(); return shared_ptr<BlockForest>();
} }
...@@ -108,5 +120,26 @@ shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& m ...@@ -108,5 +120,26 @@ shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& m
return shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), sbffile.c_str(), true, false ) ); return shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), sbffile.c_str(), true, false ) );
} }
shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf)
{
math::AABB simulationDomain = math::AABB( Vec3(0,0,0), mainConf.getParameter<Vec3>("simulationDomain", Vec3(10, 10, 10)));
Vector3<uint_t> blocks = mainConf.getParameter<Vector3<uint_t>>("blocks", Vector3<uint_t>(3, 3, 3));
Vector3<bool> isPeriodic = mainConf.getParameter<Vector3<bool>>("isPeriodic", Vector3<bool>(true, true, true));
if( !mainConf.isDefined( "sbfFile" ) )
{
WALBERLA_LOG_INFO_ON_ROOT( "No setup file specified: Creation without setup file!" );
return createBlockForest( simulationDomain, blocks, isPeriodic);
}
// sbf file given -> try to load or save domain decomposition
std::string sbffile = mainConf.getParameter< std::string >( "sbfFile" );
WALBERLA_LOG_INFO_ON_ROOT( "Setup file specified: Using " << sbffile );
bool setupRun = mainConf.getParameter< bool >( "setupRun", true );
return createBlockForest(simulationDomain, blocks, isPeriodic, setupRun, sbffile);
}
} // namespace pe } // namespace pe
} // namespace walberla } // namespace walberla
...@@ -31,6 +31,14 @@ ...@@ -31,6 +31,14 @@
namespace walberla { namespace walberla {
namespace pe { namespace pe {
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic);
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const bool setupRun,
const std::string sbffile);
shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf); shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf);
} // namespace pe } // namespace pe
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
# #
################################################################################################### ###################################################################################################
waLBerla_link_files_to_builddir( *.cfg )
waLBerla_link_files_to_builddir( *.sbf )
waLBerla_compile_test( NAME PE_BODYFLAGS FILES BodyFlags.cpp DEPENDS core ) waLBerla_compile_test( NAME PE_BODYFLAGS FILES BodyFlags.cpp DEPENDS core )
waLBerla_execute_test( NAME PE_BODYFLAGS PROCESSES 8) waLBerla_execute_test( NAME PE_BODYFLAGS PROCESSES 8)
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
using namespace walberla; using namespace walberla;
using namespace walberla::pe; using namespace walberla::pe;
using namespace walberla::blockforest;
typedef boost::tuple<Sphere> BodyTuple ; typedef boost::tuple<Sphere> BodyTuple ;
...@@ -44,22 +43,17 @@ void createDump() ...@@ -44,22 +43,17 @@ void createDump()
{ {
using namespace walberla::grid_generator; using namespace walberla::grid_generator;
BodyStorage globalStorage; shared_ptr<BodyStorage> globalBodyStorage = make_shared<BodyStorage>();
// create blocks // create blocks
shared_ptr< StructuredBlockForest > forest = blockforest::createUniformBlockGrid( auto forest = shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), "SerializeDeserialize.sbf", true, false ) );
uint_c( 2), uint_c( 2), uint_c( 2), // number of blocks in x,y,z direction
uint_c( 1), uint_c( 1), uint_c( 1), // how many cells per block (x,y,z)
real_c(10), // dx: length of one cell in physical coordinates
0, // max blocks per process
false, false, // include metis / force metis
false, false, false ); // full periodicity
BlockDataID storageID = forest->addBlockData( createStorageDataHandling<BodyTuple>() ); auto storageID = forest->addBlockData(createStorageDataHandling<BodyTuple>(), "Storage");
auto ccdID = forest->addBlockData(ccd::createHashGridsDataHandling( globalBodyStorage, storageID ), "CCD");
for (auto it = SCIterator(forest->getDomain(), Vec3(-1,-1,-1), 3); it != SCIterator(); ++it) for (auto it = SCIterator(forest->getDomain(), Vec3(-1,-1,-1), 3); it != SCIterator(); ++it)
{ {
createSphere( globalStorage, forest->getBlockStorage(), storageID, 0, *it, 1); createSphere( *globalBodyStorage, *forest, storageID, 0, *it, 1);
} }
WALBERLA_LOG_DEVEL_ON_ROOT("dumping body storage"); WALBERLA_LOG_DEVEL_ON_ROOT("dumping body storage");
...@@ -68,9 +62,11 @@ void createDump() ...@@ -68,9 +62,11 @@ void createDump()
for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt)
{ {
BodyStorage& localStorage = (*(blockIt->getData< Storage >( storageID )))[0]; BodyStorage& localStorage = (*(blockIt->getData< Storage >( storageID )))[0];
WALBERLA_LOG_DEVEL("DUMPING BLOCK"); WALBERLA_LOG_DEVEL("DUMPING BLOCK (" << blockIt->getId() << ") " << blockIt->getAABB() );
WALBERLA_LOG_DEVEL("aabb: " << blockIt->getAABB());
WALBERLA_LOG_DEVEL("#bodies: " << localStorage.size()); WALBERLA_LOG_DEVEL("#bodies: " << localStorage.size());
ccd::ICCD* ccd = blockIt->getData< ccd::ICCD >( ccdID );
WALBERLA_CHECK_EQUAL( ccd->getObservedBodyCount(), 1000 );
} }
} }
...@@ -78,33 +74,34 @@ void checkDump() ...@@ -78,33 +74,34 @@ void checkDump()
{ {
using namespace walberla::grid_generator; using namespace walberla::grid_generator;
// BodyStorage globalStorage; shared_ptr<BodyStorage> globalBodyStorage = make_shared<BodyStorage>();
// create blocks // create blocks
shared_ptr< StructuredBlockForest > forest = blockforest::createUniformBlockGrid( auto forest = shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), "SerializeDeserialize.sbf", true, false ) );
uint_c( 2), uint_c( 2), uint_c( 2), // number of blocks in x,y,z direction
uint_c( 1), uint_c( 1), uint_c( 1), // how many cells per block (x,y,z)
real_c(10), // dx: length of one cell in physical coordinates
0, // max blocks per process
false, false, // include metis / force metis
false, false, false ); // full periodicity
auto storageID = forest->loadBlockData("BodyStorageDump.dump", createStorageDataHandling<BodyTuple>(), "Storage");
auto ccdID = forest->addBlockData(ccd::createHashGridsDataHandling( globalBodyStorage, storageID ), "CCD");
BlockDataID storageID = forest->loadBlockData("BodyStorageDump.dump", createStorageDataHandling<BodyTuple>()); for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt)
{
ccd::ICCD* ccd = blockIt->getData< ccd::ICCD >( ccdID );
ccd->reloadBodies();
}
for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt)
{ {
ccd::ICCD* ccd = blockIt->getData< ccd::ICCD >( ccdID );
WALBERLA_CHECK_EQUAL( ccd->getObservedBodyCount(), 1000 );
BodyStorage& localStorage = (*(blockIt->getData< Storage >( storageID )))[0]; BodyStorage& localStorage = (*(blockIt->getData< Storage >( storageID )))[0];
WALBERLA_LOG_DEVEL("CHECKING BLOCK"); WALBERLA_LOG_DEVEL("CHECKING BLOCK (" << blockIt->getId() << ") " << blockIt->getAABB() );
WALBERLA_LOG_DEVEL("aabb: " << blockIt->getAABB());
WALBERLA_LOG_DEVEL("#bodies: " << localStorage.size()); WALBERLA_LOG_DEVEL("#bodies: " << localStorage.size());
auto bodyIt = LocalBodyIterator::begin(*blockIt, storageID); auto bodyIt = LocalBodyIterator::begin(*blockIt, storageID);
for (auto it = SCIterator(forest->getDomain(), Vec3(-1,-1,-1), 3); it != SCIterator(); ++it) for (auto it = SCIterator(forest->getDomain(), Vec3(-1,-1,-1), 3); it != SCIterator(); ++it)
{ {
if (blockIt->getAABB().contains(*it)) if (blockIt->getAABB().contains(*it))
{ {
WALBERLA_CHECK_FLOAT_EQUAL( bodyIt->getPosition(), *it); WALBERLA_CHECK_FLOAT_EQUAL( bodyIt->getPosition(), *it, blockIt->getAABB());
++bodyIt; ++bodyIt;
} }
} }
...@@ -116,10 +113,21 @@ int main( int argc, char ** argv ) ...@@ -116,10 +113,21 @@ int main( int argc, char ** argv )
walberla::debug::enterTestMode(); walberla::debug::enterTestMode();
walberla::MPIManager::instance()->initializeMPI( &argc, &argv ); walberla::MPIManager::instance()->initializeMPI( &argc, &argv );
MPIManager::instance()->useWorldComm();
SetBodyTypeIDs<BodyTuple>::execute(); SetBodyTypeIDs<BodyTuple>::execute();
// save SetupBlockForest, if you want to do that run with only one process
createBlockForest( math::AABB(0,0,0,60,60,60),
Vector3<uint_t>(2,2,2), // number of blocks
Vector3<bool>(false, false, false), // periodicity
true, // setup run?
"SerializeDeserialize.sbf" ); // sbf filename
WALBERLA_LOG_DEVEL_ON_ROOT("*** DUMPING ***");
createDump(); createDump();
WALBERLA_MPI_BARRIER();
WALBERLA_LOG_DEVEL_ON_ROOT("*** CHECKING ***");
checkDump(); checkDump();
return EXIT_SUCCESS; return EXIT_SUCCESS;
......
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