static void checkNeighborhoodConsistency( const SetupBlockForest& forest ) {

   std::vector< const SetupBlock* > blocks;
   forest.getBlocks( blocks );

   const int blockssize = int_c( blocks.size() );
#ifdef _OPENMP
   #pragma omp parallel for schedule(static)
#endif
   for( int i = 0; i < blockssize; ++i ) {

      const SetupBlock* const block = blocks[uint_c(i)];

      std::vector< real_t > neighborhoodSectionBlockCenters;

      for( uint_t n = 0; n != 26; ++n ) {

         std::vector< bool > hit( block->getNeighborhoodSectionSize(n), false );

         constructNeighborhoodSectionBlockCenters( n, block->getAABB(), neighborhoodSectionBlockCenters );

         WALBERLA_CHECK_EQUAL( neighborhoodSectionBlockCenters.size() % 3, uint_c(0) );

         for( uint_t p = 0; p != neighborhoodSectionBlockCenters.size(); p += 3 ) {

            real_t x = neighborhoodSectionBlockCenters[p];
            real_t y = neighborhoodSectionBlockCenters[p+1];
            real_t z = neighborhoodSectionBlockCenters[p+2];

            // treat periodicity
            if( x <  forest.getDomain().xMin() && forest.isXPeriodic() ) x = forest.getDomain().xMax() - forest.getDomain().xMin() + x;
            if( x >= forest.getDomain().xMax() && forest.isXPeriodic() ) x = forest.getDomain().xMin() - forest.getDomain().xMax() + x;
            if( y <  forest.getDomain().yMin() && forest.isYPeriodic() ) y = forest.getDomain().yMax() - forest.getDomain().yMin() + y;
            if( y >= forest.getDomain().yMax() && forest.isYPeriodic() ) y = forest.getDomain().yMin() - forest.getDomain().yMax() + y;
            if( z <  forest.getDomain().zMin() && forest.isZPeriodic() ) z = forest.getDomain().zMax() - forest.getDomain().zMin() + z;
            if( z >= forest.getDomain().zMax() && forest.isZPeriodic() ) z = forest.getDomain().zMin() - forest.getDomain().zMax() + z;

            bool noHit = true;
            for( uint_t c = 0; c != block->getNeighborhoodSectionSize(n) && noHit; ++c ) {
               if( block->getNeighbor(n,c)->getAABB().contains(x,y,z) ) {
                  hit[c] = true;
                  noHit = false;
               }
            }

            // either one neighbor must be hit OR the block is located at the border of the (non-periodic) simulation domain
            if( noHit )
               WALBERLA_CHECK( forest.getBlock(x,y,z) == NULL );
         }

         // every neighbor must be hit by at least one point
         for( uint_t c = 0; c != block->getNeighborhoodSectionSize(n); ++c )
            WALBERLA_CHECK( hit[c] );

         neighborhoodSectionBlockCenters.clear();
      }
   }
}
void test(const shared_ptr< DistanceOctree< MeshType > > & distanceOctree, const MeshType & mesh, const AABB & domainAABB, Vector3<uint_t> numBlocks)
{
   Vector3<real_t> blockSize(domainAABB.xSize() / real_c(numBlocks[0]),
      domainAABB.ySize() / real_c(numBlocks[1]),
      domainAABB.zSize() / real_c(numBlocks[2]));

   real_t maxError = blockSize.min() / real_t(10);

   SetupBlockForest setupBlockforest;
   setupBlockforest.addRootBlockExclusionFunction(F(distanceOctree, maxError));
   setupBlockforest.addWorkloadMemorySUIDAssignmentFunction(blockforest::uniformWorkloadAndMemoryAssignment);


   setupBlockforest.init(domainAABB, numBlocks[0], numBlocks[1], numBlocks[2], false, false, false);
   WALBERLA_LOG_DEVEL(setupBlockforest.toString());


   std::vector< Vector3<real_t> > vertexPositions;
   vertexPositions.reserve(mesh.n_vertices());
   for (auto vIt = mesh.vertices_begin(); vIt != mesh.vertices_end(); ++vIt)
   {
      vertexPositions.push_back(toWalberla(mesh.point(*vIt)));
   }

   std::vector< const blockforest::SetupBlock* > setupBlocks;
   setupBlockforest.getBlocks(setupBlocks);

   // Check wether all vertices are located in allocated blocks
   std::vector< Vector3<real_t> > uncoveredVertices(vertexPositions);

   for (auto bIt = setupBlocks.begin(); bIt != setupBlocks.end(); ++bIt)
   {
      const AABB & aabb = (*bIt)->getAABB();

      uncoveredVertices.erase(std::remove_if(uncoveredVertices.begin(), uncoveredVertices.end(), PointInAABB(aabb)), uncoveredVertices.end());
   }

   WALBERLA_CHECK(uncoveredVertices.empty(), "Not all vertices of the mesh are located in allocated blocks!");

   //setupBlockforest.assignAllBlocksToRootProcess();
   //setupBlockforest.writeVTKOutput( "setupblockforest" );
}
示例#3
0
void JacobiIteration::operator()()
{
   WALBERLA_LOG_PROGRESS_ON_ROOT( "Starting Jacobi iteration with a maximum number of " << iterations_ << " iterations" );

   uint_t i( uint_t(0) );
   while( i < iterations_ )
   {
      if( boundary_ )
         boundary_();
      communication_();

      for( auto block = blocks_.begin( requiredSelectors_, incompatibleSelectors_ ); block != blocks_.end(); ++block )
         jacobi_( block.get() );

      if( residualNormThreshold_ > real_t(0) && residualCheckFrequency_ > uint_t(0) )
      {
         if( (i % residualCheckFrequency_) == uint_t(0) )
         {
            if( boundary_ )
               boundary_();
            const real_t residualNorm = residualNorm_();
            WALBERLA_CHECK( math::finite(residualNorm), "Non-finite residual norm detected during the Jacobi iteration, "
                                                        "the simulation has probably diverged." );
            WALBERLA_LOG_DETAIL_ON_ROOT( "Residual norm after " << (i+1) << " Jacobi iterations: " << residualNorm );
            if( residualNorm < residualNormThreshold_ )
            {
               WALBERLA_LOG_PROGRESS_ON_ROOT( "Aborting Jacobi iteration (residual norm threshold reached):"
                                              "\n  residual norm threshold: " << residualNormThreshold_ <<
                                              "\n  residual norm:           " << residualNorm );
               break;
            }
         }
      }

      ++i;
   }

   WALBERLA_LOG_PROGRESS_ON_ROOT( "Jacobi iteration finished after " << i << " iterations" );
}