void testEmptyCI( const CellInterval & ci ) { WALBERLA_CHECK( ci.empty() ); for(int i = 0; i < 100; ++i) WALBERLA_CHECK( !ci.contains(makeRandomCell()) ); for(int i = 0; i < 100; ++i) WALBERLA_CHECK( !ci.overlaps(makeRandomInterval(1000000)) ); std::stringstream ss; const int forty_two = 42; const int twenty_three = 23; ss << forty_two << ci << twenty_three; CellInterval rci; int i0, i1; ss >> i0 >> rci >> i1; WALBERLA_CHECK_EQUAL( ci, rci ); WALBERLA_CHECK_EQUAL( i0, forty_two ); WALBERLA_CHECK_EQUAL( i1, twenty_three ); WALBERLA_CHECK( !ss.bad() ); WALBERLA_CHECK( ss.eof() ); size_t numIterations = 0; for( auto it = ci.begin(); it != ci.end() && numIterations < 1; ++it ) ++numIterations; WALBERLA_CHECK_EQUAL( numIterations, 0 ); }
void testIterators( const CellInterval & ci ) { uint_t ctr = 0; auto it = ci.begin(); for( cell_idx_t z = ci.zMin(); z <= ci.zMax(); ++z) for( cell_idx_t y = ci.yMin(); y <= ci.yMax(); ++y) for( cell_idx_t x = ci.xMin(); x <= ci.xMax(); ++x, ++it) { WALBERLA_CHECK( ci.contains( *it ) ); WALBERLA_CHECK_EQUAL( x, it->x() ); WALBERLA_CHECK_EQUAL( y, it->y() ); WALBERLA_CHECK_EQUAL( z, it->z() ); ++ctr; } WALBERLA_CHECK_EQUAL( it, ci.end() ); WALBERLA_CHECK_EQUAL( ctr, ci.numCells() ); WALBERLA_CHECK_EQUAL( std::distance( ci.begin(), ci.end() ), ci.numCells() ); ctr = 0; auto it2 = ci.end(); --it2; for( cell_idx_t z = ci.zMax(); z >= ci.zMin(); --z) for( cell_idx_t y = ci.yMax(); y >= ci.yMin(); --y) for( cell_idx_t x = ci.xMax(); x >= ci.xMin(); --x, --it2) { WALBERLA_CHECK( ci.contains( *it2 ) ); WALBERLA_CHECK_EQUAL( x, it2->x() ); WALBERLA_CHECK_EQUAL( y, it2->y() ); WALBERLA_CHECK_EQUAL( z, it2->z() ); ++ctr; } WALBERLA_CHECK_EQUAL( ctr, ci.numCells() ); WALBERLA_CHECK_EQUAL( it2, --ci.begin() ); }
void initF( const shared_ptr< StructuredBlockStorage > & blocks, const BlockDataID & fId ) { for( auto block = blocks->begin(); block != blocks->end(); ++block ) { PdeField_T * f = block->getData< PdeField_T >( fId ); CellInterval xyz = f->xyzSize(); for( auto cell = xyz.begin(); cell != xyz.end(); ++cell ) { const Vector3< real_t > p = blocks->getBlockLocalCellCenter( *block, *cell ); f->get( *cell ) = real_t(4) * math::PI * math::PI * std::sin( real_t(2) * math::PI * p[0] ) * std::sinh( real_t(2) * math::PI * p[1] ); } } }
void initU( const shared_ptr< StructuredBlockStorage > & blocks, const BlockDataID & srcId, const BlockDataID & dstId ) { for( auto block = blocks->begin(); block != blocks->end(); ++block ) { if( blocks->atDomainYMaxBorder( *block ) ) { PdeField_T * src = block->getData< PdeField_T >( srcId ); PdeField_T * dst = block->getData< PdeField_T >( dstId ); CellInterval xyz = src->xyzSizeWithGhostLayer(); xyz.yMin() = xyz.yMax(); for( auto cell = xyz.begin(); cell != xyz.end(); ++cell ) { const Vector3< real_t > p = blocks->getBlockLocalCellCenter( *block, *cell ); src->get( *cell ) = std::sin( real_t(2) * math::PI * p[0] ) * std::sinh( real_t(2) * math::PI * p[1] ); dst->get( *cell ) = std::sin( real_t(2) * math::PI * p[0] ) * std::sinh( real_t(2) * math::PI * p[1] ); } } } }
// function to initialise the field holding the unknown u void initU( const shared_ptr< StructuredBlockStorage > & blocks, const BlockDataID & uID ) { // iterate all blocks with an iterator 'block' for( auto block = blocks->begin(); block != blocks->end(); ++block ) { // get the field data out of the block auto u = block->getData< ScalarField > ( uID ); // obtain a CellInterval object that holds information about the number of cells in x,y,z direction of the field excluding ghost layers CellInterval xyz = u->xyzSize(); // iterate all (inner) cells in the field for( auto cell = xyz.begin(); cell != xyz.end(); ++cell ){ // obtain the physical coordinate of the center of the current cell const Vector3< real_t > p = blocks->getBlockLocalCellCenter( *block, *cell ); // set the initial condition, given by the function u(x,y,0) = sin(PI*x)*sin(PI*y) u->get( *cell ) = std::sin( math::PI * p[0] ) * std::sin( math::PI * p[1] ); } } }
void registerCells( const flag_t, const CellInterval& interval, const BoundaryConfiguration& ) { for( auto cell = interval.begin(); cell != interval.end(); ++cell ) registeredCells_.push_back( cell->x(), cell->y(), cell->z() ); }