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

extended CreateWorld to start with a refined setup

parent 5e8f1c80
No related merge requests found
......@@ -30,13 +30,32 @@
#include <core/logging/Logging.h>
#include <core/math/AABB.h>
#include <memory>
namespace walberla {
namespace pe {
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const uint_t numberOfProcesses)
class FixedRefinementLevelSelector
{
public:
FixedRefinementLevelSelector( const uint_t level ) : level_(level) {}
void operator()( SetupBlockForest& forest )
{
for( auto block = forest.begin(); block != forest.end(); ++block )
{
if( block->getLevel() < level_ )
block->setMarker( true );
}
}
private:
uint_t level_;
};
std::unique_ptr<SetupBlockForest> createSetupBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const uint_t numberOfProcesses,
const uint_t initialRefinementLevel)
{
WALBERLA_MPI_SECTION()
{
......@@ -59,14 +78,25 @@ shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
blocks[2] = 2;
}
SetupBlockForest sforest;
sforest.addWorkloadMemorySUIDAssignmentFunction( blockforest::uniformWorkloadAndMemoryAssignment );
sforest.init( simulationDomain, blocks[0], blocks[1], blocks[2], isPeriodic[0], isPeriodic[1], isPeriodic[2] );
auto sforest = std::unique_ptr<SetupBlockForest>( new SetupBlockForest() );
sforest->addWorkloadMemorySUIDAssignmentFunction( blockforest::uniformWorkloadAndMemoryAssignment );
sforest->addRefinementSelectionFunction( FixedRefinementLevelSelector(initialRefinementLevel) );
sforest->init( simulationDomain, blocks[0], blocks[1], blocks[2], isPeriodic[0], isPeriodic[1], isPeriodic[2] );
WALBERLA_LOG_INFO_ON_ROOT( "Balancing for " << numberOfProcesses << " processes...");
WALBERLA_LOG_INFO_ON_ROOT( "Balancing " << sforest->getNumberOfBlocks() << " blocks for " << numberOfProcesses << " processes...");
sforest.balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), numberOfProcesses, real_t(0), memory_t(0), false, true );
return shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), sforest, false ) );
sforest->balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), numberOfProcesses, real_t(0), memory_t(0), false, true );
return sforest;
}
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const uint_t numberOfProcesses,
const uint_t initialRefinementLevel)
{
std::unique_ptr<SetupBlockForest> sforest( createSetupBlockForest( simulationDomain, blocks, isPeriodic, numberOfProcesses, initialRefinementLevel ));
return shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), *sforest, false ) );
}
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
......@@ -74,31 +104,9 @@ shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
const Vector3<bool> isPeriodic,
const bool setupRun,
const std::string sbffile,
const uint_t numberOfProcesses)
const uint_t numberOfProcesses,
const uint_t initialRefinementLevel)
{
WALBERLA_MPI_SECTION()
{
MPIManager::instance()->useWorldComm();
}
if (isPeriodic[0] && blocks[0]<2)
{
WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic x direction (" << blocks[0] << ")! Setting to 2..." );
blocks[0] = 2;
}
if (isPeriodic[1] && blocks[1]<2)
{
WALBERLA_LOG_WARNING_ON_ROOT( "To few blocks in periodic y direction (" << blocks[1] << ")! Setting to 2..." );
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;
}
WALBERLA_LOG_INFO_ON_ROOT( "Setup file specified: Using " << sbffile );
if (setupRun)
{
WALBERLA_LOG_INFO_ON_ROOT("Setup run. For production run specify 'setupRun = false'");
......@@ -110,16 +118,8 @@ shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
{
WALBERLA_LOG_INFO_ON_ROOT( "Creating the block structure ..." );
SetupBlockForest sforest;
sforest.addWorkloadMemorySUIDAssignmentFunction( blockforest::uniformWorkloadAndMemoryAssignment );
sforest.init( simulationDomain, blocks[0], blocks[1], blocks[2], isPeriodic[0], isPeriodic[1], isPeriodic[2] );
// calculate process distribution
sforest.balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), numberOfProcesses, real_t(0), memory_t(0), false, true );
sforest.saveToFile( sbffile.c_str() );
std::unique_ptr<SetupBlockForest> sforest( createSetupBlockForest(simulationDomain, blocks, isPeriodic, numberOfProcesses, initialRefinementLevel) );
sforest->saveToFile( sbffile.c_str() );
WALBERLA_LOG_INFO_ON_ROOT( "SetupBlockForest successfully saved to file!" );
}
......@@ -129,13 +129,12 @@ shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
WALBERLA_LOG_INFO_ON_ROOT( "Production Run!" );
WALBERLA_LOG_INFO_ON_ROOT( "Creating the block structure: loading from file \'" << sbffile << "\' ..." );
return shared_ptr< BlockForest >( new BlockForest( uint_c( MPIManager::instance()->rank() ), sbffile.c_str(), true, false ) );
}
shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf)
{
bool setupRun = mainConf.getParameter< bool >( "setupRun", true );
Vec3 simulationCorner = mainConf.getParameter<Vec3>("simulationCorner", Vec3(0, 0, 0));
Vec3 simulationSize = mainConf.getParameter<Vec3>("simulationDomain", Vec3(10, 10, 10));
......@@ -144,19 +143,18 @@ shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& m
Vector3<bool> isPeriodic = mainConf.getParameter<Vector3<bool>>("isPeriodic", Vector3<bool>(true, true, true));
uint_t numberOfProcesses = mainConf.getParameter<uint_t>( "numberOfProcesses",
setupRun ? blocks[0] * blocks[1] * blocks[2] : uint_c(mpi::MPIManager::instance()->numProcesses()) );
uint_t initialRefinementLevel = mainConf.getParameter<uint_t>( "initialRefinementLevel", uint_t(0) );
if( !mainConf.isDefined( "sbfFile" ) )
{
WALBERLA_LOG_INFO_ON_ROOT( "No setup file specified: Creation without setup file!" );
return createBlockForest( simulationDomain, blocks, isPeriodic, numberOfProcesses);
return createBlockForest(simulationDomain, blocks, isPeriodic, numberOfProcesses, initialRefinementLevel);
}
// 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 );
return createBlockForest(simulationDomain, blocks, isPeriodic, setupRun, sbffile, numberOfProcesses);
return createBlockForest(simulationDomain, blocks, isPeriodic, setupRun, sbffile, numberOfProcesses, initialRefinementLevel);
}
} // namespace pe
......
......@@ -34,13 +34,15 @@ namespace pe {
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const uint_t numberOfProcesses = uint_c(mpi::MPIManager::instance()->numProcesses()));
const uint_t numberOfProcesses = uint_c(mpi::MPIManager::instance()->numProcesses()),
const uint_t initialRefinementLevel = uint_t(0));
shared_ptr<BlockForest> createBlockForest(const math::AABB simulationDomain,
Vector3<uint_t> blocks,
const Vector3<bool> isPeriodic,
const bool setupRun,
const std::string sbffile,
const uint_t numberOfProcesses = uint_c(mpi::MPIManager::instance()->numProcesses()));
const uint_t numberOfProcesses = uint_c(mpi::MPIManager::instance()->numProcesses()),
const uint_t initialRefinementLevel = uint_t(0));
shared_ptr<BlockForest> createBlockForestFromConfig(const Config::BlockHandle& mainConf);
} // namespace pe
......
......@@ -25,6 +25,9 @@ waLBerla_execute_test( NAME PE_COLLISION )
waLBerla_compile_test( NAME PE_COLLISIONTOBIASGJK FILES CollisionTobiasGJK.cpp DEPENDS core )
waLBerla_execute_test( NAME PE_COLLISIONTOBIASGJK )
waLBerla_compile_test( NAME PE_CREATEWORLD FILES CreateWorld.cpp DEPENDS core )
waLBerla_execute_test( NAME PE_CREATEWORLD )
waLBerla_compile_test( NAME PE_DELETEBODY FILES DeleteBody.cpp DEPENDS core blockforest )
waLBerla_execute_test( NAME PE_DELETEBODY_NN COMMAND $<TARGET_FILE:PE_DELETEBODY> )
waLBerla_execute_test( NAME PE_DELETEBODY_SO COMMAND $<TARGET_FILE:PE_DELETEBODY> --syncShadowOwners )
......
//======================================================================================================================
//
// 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 HCSITS.cpp
//! \brief checks equality of hash grids and simple ccd
//! \author Sebastian Eibl <sebastian.eibl@fau.de>
//
//======================================================================================================================
#include "pe/basic.h"
#include "pe/utility/CreateWorld.h"
#include "blockforest/all.h"
#include "core/all.h"
#include "domain_decomposition/all.h"
#include "core/debug/TestSubsystem.h"
using namespace walberla;
using namespace walberla::pe;
typedef boost::tuple<Sphere, Plane> BodyTuple ;
int main( int argc, char** argv )
{
walberla::debug::enterTestMode();
Environment env(argc, argv);
WALBERLA_UNUSED(env);
// create blocks
auto forest = createBlockForest(
math::AABB(0,0,0,10,10,10),
Vector3<uint_t>(1,1,1),
Vector3<bool>(false, false, false),
1,
1);
WALBERLA_CHECK_EQUAL( forest->size(), 8);
for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt)
{
blockforest::Block& currentBlock = *(dynamic_cast<blockforest::Block*>(&(*blockIt)));
WALBERLA_CHECK_EQUAL( currentBlock.getLevel(), 1);
}
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