void neighborhoodTest() { typedef FlagField<wlb::uint8_t> FField; FField ff ( 3,3,3,1 ); auto i = ff.registerFlag("Interface"); auto l = ff.registerFlag("Liquid"); auto g = ff.registerFlag("Gas"); for( auto it = ff.begin(); it != ff.end(); ++it ) addFlag(it, l); ff.addFlag(1,0,0,i); ff.addFlag(1,2,2,g); for( auto it = ff.begin(); it != ff.end(); ++it ) { if (it.x() == 1 && it.y() == 1 && it.z() == 1) { WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q19>(it, i) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q19>(it, g) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q19>(it, l) ); } if (it.x() == 1 && it.y() == 2 && it.z() == 2) { WALBERLA_CHECK( !isFlagInNeighborhood<stencil::D3Q19>(it, i) ); WALBERLA_CHECK( !isFlagInNeighborhood<stencil::D3Q19>(it, g) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q19>(it, l) ); } } ff.removeFlag(1,0,0,i); ff.addFlag(0,0,0,i); ff.removeFlag(1,2,2,g); ff.addFlag(2,2,2,g); for( auto it = ff.begin(); it != ff.end(); ++it ) { if (it.x() == 1 && it.y() == 1 && it.z() == 1) { WALBERLA_CHECK( field::isFlagInNeighborhood<stencil::D3Q27>(it, i) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q27>(it, g) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q27>(it, l) ); } if (it.x() == 2 && it.y() == 2 && it.z() == 2) { WALBERLA_CHECK( !isFlagInNeighborhood<stencil::D3Q27>(it, i) ); WALBERLA_CHECK( !isFlagInNeighborhood<stencil::D3Q27>(it, g) ); WALBERLA_CHECK( isFlagInNeighborhood<stencil::D3Q27>(it, l) ); } } }
void shallowCopyTest() { // Test shallow copy typedef FlagField<wlb::uint8_t> FField; FField ff ( 3,3,3,1 ); ff.registerFlag("FirstFlag"); shared_ptr< FField > sliced = shared_ptr< FField > ( ff.getSlicedField(CellInterval(0,1,0,2,2,2)) ); WALBERLA_CHECK_NOT_NULLPTR( sliced ); sliced->registerFlag("SecondFlag"); WALBERLA_CHECK( ff.flagExists("SecondFlag") ); // Test deep copy FField * f1 = new FField ( 3,3,3,1 ); auto flag1 = f1->registerFlag( "Flag1" ); auto flag2 = f1->registerFlag( "Flag2" ); f1->addFlag( 0,0,0,flag1 ); f1->addFlag( 1,1,1,flag2 ); FField * f2 = f1->clone(); delete f1; WALBERLA_CHECK( f2->flagExists( "Flag1" ) ); WALBERLA_CHECK( f2->flagExists( "Flag2" ) ); WALBERLA_CHECK( f2->isFlagSet( 0,0,0,flag1 ) ); WALBERLA_CHECK( f2->isFlagSet( 1,1,1,flag2 ) ); delete f2; }
void printingTest() { typedef FlagField<wlb::uint8_t> FField; FField ff ( 3,3,3,1 ); auto ns = ff.registerFlag("NoSlip"); auto fs = ff.registerFlag("FreeSlip"); auto ob = ff.registerFlag("Obstacle"); for(cell_idx_t i=0; i < cell_idx_c( ff.xSize() ); ++i) ff.addFlag(i,0,0,ns); for(cell_idx_t i=0; i < cell_idx_c( ff.ySize() ); ++i) ff.addFlag(0,i,0,fs); ff.addFlag(0,1,0,ob); ff.addFlag(1,0,0,ob); //printSlice( cout,ff, 2,0 ); }
int main(int argc, char **argv ) { walberla::Environment env( argc, argv ); const uint_t cells [] = { 6,5,3 }; const uint_t blockCount [] = { 4, 3,2 }; const uint_t nrOfTimeSteps = 20; // Create BlockForest auto blocks = blockforest::createUniformBlockGrid(blockCount[0],blockCount[1],blockCount[2], //blocks cells[0],cells[1],cells[2], //cells 1, //dx false, //one block per process true,true,true); //periodicity LatticeModel latticeModel( lbm::collision_model::SRT(1.5 ) ); // In addition to the normal GhostLayerField's we allocated additionally a field containing the whole global simulation domain for each block // we can then check if the GhostLayer communication is correct, by comparing the small field to the corresponding part of the big field BlockDataID pdfField = lbm::addPdfFieldToStorage( blocks, "PdfField", latticeModel ); BlockDataID scalarField1 = field::addToStorage<ScalarField>( blocks, "ScalarFieldOneGl", real_t(0), field::zyxf, 1 ); BlockDataID scalarField2 = field::addToStorage<ScalarField>( blocks, "ScalarFieldTwoGl", real_t(0), field::zyxf, 2 ); BlockDataID vectorField = field::addToStorage<VectorField>( blocks, "VectorField", Vector3<real_t>(0,0,0) ); BlockDataID flagField = field::addFlagFieldToStorage<FField>( blocks, "FlagField" ); // Init src field with some values for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) // block loop { // Init PDF field PdfField * src = blockIt->getData<PdfField>(pdfField); for( auto cellIt = src->begin(); cellIt != src->end(); ++cellIt ) // over all x,y,z,f { Cell cell ( cellIt.x(), cellIt.y(), cellIt.z() ); blocks->transformBlockLocalToGlobalCell(cell, *blockIt); *cellIt = real_c( ( cell[0] + cell[1] + cell[2] + cellIt.f() ) % cell_idx_t(42) ); } // Init scalarField1 ScalarField * sf = blockIt->getData<ScalarField> ( scalarField1 ); for( auto cellIt = sf->beginWithGhostLayer(); cellIt != sf->end(); ++cellIt ) // over all x,y,z { Cell cell ( cellIt.x(), cellIt.y(), cellIt.z() ); blocks->transformBlockLocalToGlobalCell(cell, *blockIt); *cellIt = real_c( ( cell[0] + cell[1] + cell[2] ) % cell_idx_t(42) ); } // Init scalarField2 sf = blockIt->getData<ScalarField> ( scalarField2 ); for( auto cellIt = sf->beginWithGhostLayer(); cellIt != sf->end(); ++cellIt ) // over all x,y,z { Cell cell ( cellIt.x(), cellIt.y(), cellIt.z() ); blocks->transformBlockLocalToGlobalCell(cell, *blockIt); *cellIt = real_c( ( cell[0] + cell[1] + cell[2] ) % cell_idx_t(42) ); } // Init vector field VectorField * vf = blockIt->getData<VectorField> ( vectorField ); for ( auto cellIt = vf->beginWithGhostLayer(); cellIt != vf->end(); ++cellIt ) { Cell cell ( cellIt.x(), cellIt.y(), cellIt.z() ); blocks->transformBlockLocalToGlobalCell(cell, *blockIt); *cellIt = Vector3<real_t>( real_c(cell[0]), real_c(cell[1]), real_c(cell[2]) ); } // Init Flag field FField * ff = blockIt->getData<FField> ( flagField ); auto flag1 = ff->registerFlag( "AFlag 1" ); auto flag2 = ff->registerFlag( "BFlag 2" ); for ( auto cellIt = ff->beginWithGhostLayer(); cellIt != ff->end(); ++cellIt ) { Cell cell ( cellIt.x(), cellIt.y(), cellIt.z() ); blocks->transformBlockLocalToGlobalCell( cell, *blockIt ); if ( ( cell[0] + cell[1] + cell[2] ) % 2 ) addFlag( cellIt, flag1); else addFlag( cellIt, flag2); } } // Create TimeLoop SweepTimeloop timeloop (blocks, nrOfTimeSteps ); GUI gui (timeloop, blocks, argc, argv); lbm::connectToGui<LatticeModel>( gui ); gui.run(); //timeloop.singleStep(); return EXIT_SUCCESS; }