Ejemplo n.º 1
0
void test( const std::string & filename, const Vector3<uint_t> & size, const std::string & datatype, const bool vtkOut )
{
   WALBERLA_LOG_INFO( "Testing unscaled" );
   BinaryRawFile brf( filename, size, datatype );

   auto blocks = blockforest::createUniformBlockGrid( uint_t(1), uint_t( 1 ), uint_t( 1 ), 
      size[0], size[1], size[2], 
      real_t( 1 ), 
      uint_t( 1 ), uint_t( 1 ), uint_t( 1 ) );

   typedef GhostLayerField< uint8_t, uint_t( 1 ) > ScalarField;

   BlockDataID scalarFieldID = field::addToStorage<ScalarField>( blocks, "BinaryRawFile" );

   for ( auto & block : *blocks)
   {
      auto field = block.getData<ScalarField>( scalarFieldID );
      
      CellInterval ci( 0, 0, 0, cell_idx_c( size[0] ) - 1, cell_idx_c( size[1] ) - 1, cell_idx_c( size[2] ) - 1 );

      for (const Cell & c : ci)
      {
         field->get( c ) = brf.get( uint_c( c[0] ), uint_c( c[1] ), uint_c( c[2] ) );
      }
   }

   if (vtkOut)
   {
      WALBERLA_LOG_INFO( "Writing unscaled" );
      auto vtkOutput = vtk::createVTKOutput_BlockData( blocks, "BinaryRawFile" );
      vtkOutput->addCellDataWriter( make_shared< field::VTKWriter< ScalarField, uint8_t > >( scalarFieldID, "BinaryRawFile" ) );
      writeFiles( vtkOutput, true )();
   }
}
Ejemplo n.º 2
0
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();
      }
   }
}
Ejemplo n.º 3
0
std::vector< SphereVtkOutput::Attributes > SphereVtkOutput::getAttributes() const
{
   std::vector< Attributes > attributes;
   attributes.push_back( Attributes( vtk::typeToString< float >(), "mass", uint_c(1) ) );
   attributes.push_back( Attributes( vtk::typeToString< float >(), "radius", uint_c(1) ) );
   attributes.push_back( Attributes( vtk::typeToString< float >(), "velocity", uint_c(3) ) );
   attributes.push_back( Attributes( vtk::typeToString< float >(), "orientation", uint_c(3) ) );
   attributes.push_back( Attributes( vtk::typeToString< int >(),   "rank", uint_c(1) ) );

   return attributes;
}
Ejemplo n.º 4
0
walberla::id_t createSphere(data::ParticleStorage& ps, domain::IDomain& domain)
{
   walberla::id_t uid = 0;
   auto owned = domain.isContainedInProcessSubdomain( uint_c(walberla::mpi::MPIManager::instance()->rank()), Vec3(9,9,9) );
   if (owned)
   {
      data::Particle&& p          = *ps.create();
      p.getPositionRef()          = Vec3(9,9,9);
      p.getInteractionRadiusRef() = radius;
      p.getOwnerRef()             = walberla::mpi::MPIManager::instance()->rank();
      uid = p.getUid();
   }

   walberla::mpi::allReduceInplace(uid, walberla::mpi::SUM);
   return uid;
}
Ejemplo n.º 5
0
int main( int argc, char ** argv )
{
   walberla::Environment env( argc, argv );

   // create blocks
   shared_ptr< StructuredBlockForest > blocks = blockforest::createUniformBlockGrid(
            uint_c( 3), uint_c(2), uint_c( 4), // number of blocks in x,y,z direction
            uint_c(10), uint_c(8), uint_c(12), // how many cells per block (x,y,z)
            real_c(0.5),                       // dx: length of one cell in physical coordinates
            false,                             // one block per process? - "false" means all blocks to one process
            false, false, false );             // no periodicity

   // add a field to all blocks - and store the returned block data ID which is needed to access the field
   BlockDataID fieldID = blocks->addStructuredBlockData< Field<real_t,1> >( &createFields, "My Field" );

   // iterate all blocks and initialize with random values
   for( auto blockIterator = blocks->begin(); blockIterator != blocks->end(); ++blockIterator )
   {
      IBlock & currentBlock = *blockIterator;

      // get the field stored on the current block
      Field<real_t,1> * field = currentBlock.getData< Field<real_t,1> >( fieldID );

      // iterate the field and set random values
      for( auto iter = field->begin(); iter != field->end(); ++iter )
         *iter = real_c( rand() % ARBITRARY_VALUE );
   }

   // create time loop
   const uint_t numberOfTimesteps = uint_c(10); // number of time steps for non-gui runs
   SweepTimeloop timeloop( blocks, numberOfTimesteps );

   // registering the function sweep
   auto pointerToTwoArgFunction = & simpleSweep;
   auto pointerToOneArgFunction = std::bind( pointerToTwoArgFunction, std::placeholders::_1, fieldID );
   timeloop.add() << Sweep( pointerToOneArgFunction, "BogusAlgorithm" );

   // registering the class sweep
   timeloop.add() << Sweep( SimpleSweep(fieldID), "BogusAlgorithmButNowAsFunctor" );

   // two sweeps were registered, so both are executed in each time step

   GUI gui( timeloop, blocks, argc, argv );
   gui.run();

   return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
/*******************************************************************************************************************//**
 * \brief   Query if n is prime.
 *
 * \param   n  The number to be checked.
 *
 * \return  true if n is prime, false if not.
 **********************************************************************************************************************/
bool isPrime( const uint_t n )
{
   switch(n)
   {
   case 0:
   case 1:
      return false;
   case 2:
      return true;
   default:
      if( n % 2 == 0 )
         return false;
      uint_t sqrtN = uint_c( std::sqrt( real_c(n) ) );
      for( uint_t i = 3; i <= sqrtN; i += 2 )
         if( n % i == 0 )
            return false;
      break;
   }

   return true;
}