Exemple #1
0
 static void ParseSubchunks(const Binary::Data& data, Builder& target)
 {
   try
   {
     Binary::TypedContainer typed(data);
     for (std::size_t pos = 0; pos < typed.GetSize(); )
     {
       const SubChunkHeader* const hdr = typed.GetField<SubChunkHeader>(pos);
       Require(hdr != nullptr);
       if (hdr->ID == 0 && 0 != (pos % 4))
       {
         //in despite of official format description, subchunks can be not aligned by 4 byte boundary
         ++pos;
       }
       else
       {
         Dbg("ParseSubchunk id=%u, type=%u, size=%u", uint_t(hdr->ID), uint_t(hdr->Type), fromLE(hdr->DataSize));
         pos += sizeof(*hdr) + hdr->GetDataSize();
         Require(pos <= typed.GetSize());
         ParseSubchunk(*hdr, target);
       }
     }
   }
   catch (const std::exception&)
   {
     //ignore
   }
 }
Exemple #2
0
/*******************************************************************************************************************//**
 * \brief   Gets all devisors of a number n.
 *
 * Computes all unique products of n's prime factors.
 *
 * \param   n  The number the devisors are computed for.
 *
 * \pre     n > 0
 *
 * \return  A set of the devisors including 1 and n
 **********************************************************************************************************************/
std::set<uint_t> getDevisors( const uint_t n )
{
   if( n == uint_t(0) )
      return std::set<uint_t>();

   std::vector<uint_t> factors = getPrimeFactors( n );

   std::set<uint_t> devisors;
   std::vector<uint_t> tmpDevisors;

   devisors.insert( uint_t(1) );
   tmpDevisors.reserve( ( size_t(1) << factors.size() ) - size_t(1) );

   for( auto fIt = factors.begin(); fIt != factors.end(); ++fIt )
   {
      tmpDevisors.clear();
      for(auto pIt = devisors.begin(); pIt != devisors.end(); ++pIt)
      {
         tmpDevisors.push_back( *pIt * *fIt );
      }
      devisors.insert( tmpDevisors.begin(), tmpDevisors.end() );
   }

   return devisors;
}
Exemple #3
0
uint_t StaticLevelwiseCurveBalance::operator()( SetupBlockForest & forest, const uint_t numberOfProcesses, const memory_t /*perProcessMemoryLimit*/ )
{
   // TODO: take per process memory limit into account?

   std::vector< SetupBlock * > blocks;
   if( hilbert_ )
      forest.getHilbertOrder( blocks );
   else
      forest.getMortonOrder( blocks );

   uint_t border = uint_t(0);

   for( uint_t level = forest.getNumberOfLevels(); level-- > uint_t(0); )
   {
      std::vector< SetupBlock * > blocksOnLevel;

      for( auto block = blocks.begin(); block != blocks.end(); ++block )
         if( (*block)->getLevel() == level )
            blocksOnLevel.push_back( *block );

      const uint_t nBlocks = blocksOnLevel.size();

      if( nBlocks <= ( numberOfProcesses - border ) )
      {
         for( auto block = blocksOnLevel.begin(); block != blocksOnLevel.end(); ++block )
            (*block)->assignTargetProcess( border++ );

         WALBERLA_ASSERT_LESS_EQUAL( border, numberOfProcesses );

         if( border == numberOfProcesses )
            border = uint_t(0);
      }
      else
      {
         const uint_t reducedNBlocks = nBlocks - ( numberOfProcesses - border);
         const uint_t div = reducedNBlocks / numberOfProcesses;
         const uint_t mod = reducedNBlocks % numberOfProcesses;

         uint_t bIndex = uint_t(0);
         for( uint_t p = 0; p != numberOfProcesses; ++p )
         {
            uint_t count = div;
            if( p < mod ) ++count;
            if( p >= border ) ++count;

            WALBERLA_ASSERT_LESS_EQUAL( bIndex + count, blocksOnLevel.size() );

            for( uint_t i = bIndex; i < ( bIndex + count ); ++i )
               blocksOnLevel[i]->assignTargetProcess( p );
            bIndex += count;
         }

         border = mod;
      }
   }

   return std::min( numberOfProcesses, blocks.size() );
}
Exemple #4
0
uint_t StaticLevelwiseCurveBalanceWeighted::operator()( SetupBlockForest & forest, const uint_t numberOfProcesses, const memory_t /*perProcessMemoryLimit*/ )
{
   // TODO: take per process memory limit into account?

   std::vector< SetupBlock * > blocks;
   if( hilbert_ )
      forest.getHilbertOrder( blocks );
   else
      forest.getMortonOrder( blocks );

   uint_t usedProcesses( uint_t(0) );

   for( uint_t level = uint_t(0); level < forest.getNumberOfLevels(); ++level )
   {
      std::vector< SetupBlock * > blocksOnLevel;

      for( auto block = blocks.begin(); block != blocks.end(); ++block )
         if( (*block)->getLevel() == level )
            blocksOnLevel.push_back( *block );

      workload_t totalWeight( 0 );
      for( auto block = blocksOnLevel.begin(); block != blocksOnLevel.end(); ++block )
      {
         WALBERLA_ASSERT( !( (*block)->getWorkload() < workload_t(0) ) );
         totalWeight += (*block)->getWorkload();
      }

      uint_t c( uint_t(0) );
      for( uint_t p = uint_t(0); p != numberOfProcesses; ++p )
      {
         const workload_t minWeight = totalWeight / workload_c( numberOfProcesses - p );
         workload_t weight( 0 );
         while( weight < minWeight && c < blocksOnLevel.size() )
         {
            blocksOnLevel[c]->assignTargetProcess(p);

            WALBERLA_ASSERT_LESS_EQUAL( p, usedProcesses );
            usedProcesses = p + uint_t(1);

            const workload_t addedWeight = blocksOnLevel[c]->getWorkload();
            weight += addedWeight;
            totalWeight -= addedWeight;
            ++c;
         }
      }
      while( c < blocksOnLevel.size() )
      {
         blocksOnLevel[c]->assignTargetProcess( numberOfProcesses - uint_t(1) );

         WALBERLA_ASSERT_LESS_EQUAL( numberOfProcesses - uint_t(1), usedProcesses );
         usedProcesses = numberOfProcesses;

         ++c;
      }


   }

   return usedProcesses;
}
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 )();
   }
}
static void test() {

   for( uint_t i = 0; i < 5; ++i ) {

      SetupBlockForest forest;

      forest.addRefinementSelectionFunction( refinementSelectionFunctionAll );

      real_t xmin = math::realRandom( real_c(-100), real_c(100) );
      real_t xmax = math::realRandom( xmin + real_c(10), real_c(120) );
      real_t ymin = math::realRandom( real_c(-100), real_c(100) );
      real_t ymax = math::realRandom( ymin + real_c(10), real_c(120) );
      real_t zmin = math::realRandom( real_c(-100), real_c(100) );
      real_t zmax = math::realRandom( zmin + real_c(10), real_c(120) );

      AABB domain( xmin, ymin, zmin, xmax, ymax, zmax );
      forest.init( domain, math::intRandom( uint_t(5), uint_t(20) ), math::intRandom( uint_t(5), uint_t(20) ), math::intRandom( uint_t(5), uint_t(20) ),
                           math::boolRandom(), math::boolRandom(), math::boolRandom() );

      checkNeighborhoodConsistency( forest );
      checkCollectorConsistency( forest );
   }

   for( uint_t i = 0; i < 5; ++i ) {

      SetupBlockForest forest;

      forest.addRefinementSelectionFunction( refinementSelectionFunctionRandom );

      real_t xmin = math::realRandom( real_c(-100), real_c(100) );
      real_t xmax = math::realRandom( xmin + real_c(10), real_c(120) );
      real_t ymin = math::realRandom( real_c(-100), real_c(100) );
      real_t ymax = math::realRandom( ymin + real_c(10), real_c(120) );
      real_t zmin = math::realRandom( real_c(-100), real_c(100) );
      real_t zmax = math::realRandom( zmin + real_c(10), real_c(120) );

      AABB domain( xmin, ymin, zmin, xmax, ymax, zmax );
      forest.init( domain, math::intRandom( uint_t(5), uint_t(20) ), math::intRandom( uint_t(5), uint_t(20) ), math::intRandom( uint_t(5), uint_t(20) ),
                           math::boolRandom(), math::boolRandom(), math::boolRandom() );

      checkNeighborhoodConsistency( forest );
      checkCollectorConsistency( forest );
   }
}
Exemple #7
0
T mod_mul(T a, T b, T m) {
  using uint_t = typename std::make_unsigned<T>::type;
  assert(a >= 0 && b >= 0 && "Does not handle negative numbers");
  assert(uint_t(m) <= uint64_t(INT64_MAX) && "Cannot multiply safely");

  a %= m;
  b %= m;
  if (uint_t(a) <= UINT32_MAX && uint_t(b) <= UINT32_MAX)
    return T(uint64_t(a) * b % m);

  uint_t x = 0, y = a % m;
  while (b > 0) {
    if (b % 2 == 1)
      x = (x + y) % m;
    y = (y * 2) % m;
    b /= 2;
  }
  return x % m;
}
Exemple #8
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" );
}
Exemple #9
0
/* {{{
 * binary search 
 * */
PHP_METHOD(ip2region_class_entry_ptr,  binarySearch)
{
	long ip;
	datablock_entry  _block;
	uint_t (*func_ptr) (ip2region_t, uint_t, datablock_t);

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ip) == FAILURE) {
		return;
	}

	func_ptr = ip2region_binary_search;
	search(g_resource_ptr, func_ptr, ip, &return_value, &_block);
}
Exemple #10
0
/* {{{ 
 *  btree search string
 * */
PHP_METHOD(ip2region_class_entry_ptr, btreeSearchString)
{
	char *ip = NULL;
	int arg_len;
	datablock_entry  _block;
	uint_t (*func_ptr) (ip2region_t, uint_t, datablock_t);

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ip, &arg_len) == FAILURE) {
		return;
	}

	func_ptr = ip2region_btree_search;

	search(g_resource_ptr, func_ptr, ip2long(ip), &return_value, &_block);
}
Exemple #11
0
static void
apix_dispatch_pending_autovect(uint_t ipl)
{
	uint32_t cpuid = psm_get_cpu_id();
	apix_impl_t *apixp = apixs[cpuid];
	struct autovec *av;

	while ((av = apix_remove_pending_av(apixp, ipl)) != NULL) {
		uint_t r;
		uint_t (*intr)() = av->av_vector;
		caddr_t arg1 = av->av_intarg1;
		caddr_t arg2 = av->av_intarg2;
		dev_info_t *dip = av->av_dip;
		uchar_t vector = av->av_flags & AV_PENTRY_VECTMASK;

		if (intr == NULL)
			continue;

		/* Don't enable interrupts during x-calls */
		if (ipl != XC_HI_PIL)
			sti();

		DTRACE_PROBE4(interrupt__start, dev_info_t *, dip,
		    void *, intr, caddr_t, arg1, caddr_t, arg2);
		r = (*intr)(arg1, arg2);
		DTRACE_PROBE4(interrupt__complete, dev_info_t *, dip,
		    void *, intr, caddr_t, arg1, uint_t, r);

		if (av->av_ticksp && av->av_prilevel <= LOCK_LEVEL)
			atomic_add_64(av->av_ticksp, intr_get_time());

		cli();

		if (vector) {
			if ((av->av_flags & AV_PENTRY_PEND) == 0)
				av->av_flags &= ~AV_PENTRY_VECTMASK;

			apix_post_hardint(vector);
		}

		/* mark it as idle */
		av->av_flags &= ~AV_PENTRY_ONPROC;
	}
}
Exemple #12
0
	StringSeq StringUtil::tokenizeSeq(const char* text, char split /*= ' ' */) {
		StringSeq result;

		if (!text || !text[0])
			return result;

		String str;

		const char* token = text;

		for (; ;) {
			/* skip whitespace */
			while (*token && uint_t(*token) <= ' ' || *token == split) {
				token++;
			}

			if (!*token) break;

			str.clear();

			// handle quoted strings
			if (*token == '\"') {
				token++;
				while (*token && *token != '\"') {
					str += *token++;
				}
				result.push_back(str);
				str.clear();
				if (!*token) {
					break;
				} else {
					token++;
					continue;
				}
			}

			do {
				str+=*token; token++;
			} while (*token != 0 && *token != split);
			result.push_back(str);
		}

		return result;
	}
/*
 * pcmu_intr_wrapper
 *
 * This routine is used as wrapper around interrupt handlers installed by child
 * device drivers.  This routine invokes the driver interrupt handlers and
 * examines the return codes.
 * There is a count of unclaimed interrupts kept on a per-ino basis. If at
 * least one handler claims the interrupt then the counter is halved and the
 * interrupt state machine is idled. If no handler claims the interrupt then
 * the counter is incremented by one and the state machine is idled.
 * If the count ever reaches the limit value set by pcmu_unclaimed_intr_max
 * then the interrupt state machine is not idled thus preventing any further
 * interrupts on that ino. The state machine will only be idled again if a
 * handler is subsequently added or removed.
 *
 * return value: DDI_INTR_CLAIMED if any handlers claimed the interrupt,
 * DDI_INTR_UNCLAIMED otherwise.
 */
uint_t
pcmu_intr_wrapper(caddr_t arg)
{
	pcmu_ib_ino_info_t *ino_p = (pcmu_ib_ino_info_t *)arg;
	uint_t result = 0, r;
	ih_t *ih_p = ino_p->pino_ih_start;
	int i;
#ifdef	DEBUG
	pcmu_t *pcmu_p = ino_p->pino_ib_p->pib_pcmu_p;
#endif


	for (i = 0; i < ino_p->pino_ih_size; i++, ih_p = ih_p->ih_next) {
		dev_info_t *dip = ih_p->ih_dip;
		uint_t (*handler)() = ih_p->ih_handler;
		caddr_t arg1 = ih_p->ih_handler_arg1;
		caddr_t arg2 = ih_p->ih_handler_arg2;

		if (ih_p->ih_intr_state == PCMU_INTR_STATE_DISABLE) {
			PCMU_DBG3(PCMU_DBG_INTR, pcmu_p->pcmu_dip,
			    "pcmu_intr_wrapper: %s%d interrupt %d is "
			    "disabled\n", ddi_driver_name(dip),
			    ddi_get_instance(dip), ino_p->pino_ino);
			continue;
		}

		DTRACE_PROBE4(pcmu__interrupt__start, dev_info_t, dip,
		    void *, handler, caddr_t, arg1, caddr_t, arg2);

		r = (*handler)(arg1, arg2);
		DTRACE_PROBE4(pcmu__interrupt__complete, dev_info_t, dip,
		    void *, handler, caddr_t, arg1, int, r);

		result += r;
	}

	if (!result) {
		return (pcmu_spurintr(ino_p));
	}
	ino_p->pino_unclaimed = 0;
	/* clear the pending state */
	PCMU_IB_INO_INTR_CLEAR(ino_p->pino_clr_reg);
	return (DDI_INTR_CLAIMED);
}
Exemple #14
0
JNIEXPORT jint JNICALL Java_app_zxtune_core_jni_JniPlayer_analyze
  (JNIEnv* env, jobject self, jbyteArray levels)
{
  return Jni::Call(env, [=] ()
  {
    const auto playerHandle = NativePlayerJni::GetHandle(env, self);
    const auto& player = Player::Storage::Instance().Get(playerHandle);
    typedef AutoArray<jbyteArray, uint8_t> ArrayType;
    ArrayType rawLevels(env, levels);
    if (rawLevels)
    {
      return player->Analyze(rawLevels.Size(), rawLevels.Data());
    }
    else
    {
      return uint_t(0);
    }
  });
}
Exemple #15
0
/*
 * Channel nexus interrupt handler wrapper
 */
static uint_t
cnex_intr_wrapper(caddr_t arg)
{
	int 			res;
	uint_t 			(*handler)();
	caddr_t 		handler_arg1;
	caddr_t 		handler_arg2;
	cnex_intr_t 		*iinfo = (cnex_intr_t *)arg;

	ASSERT(iinfo != NULL);

	handler = iinfo->hdlr;
	handler_arg1 = iinfo->arg1;
	handler_arg2 = iinfo->arg2;

	/*
	 * The 'interrupt__start' and 'interrupt__complete' probes
	 * are provided to support 'intrstat' command. These probes
	 * help monitor the interrupts on a per device basis only.
	 * In order to provide the ability to monitor the
	 * activity on a per channel basis, two additional
	 * probes('channelintr__start','channelintr__complete')
	 * are provided here.
	 */
	DTRACE_PROBE4(channelintr__start, uint64_t, iinfo->id,
	    cnex_intr_t *, iinfo, void *, handler, caddr_t, handler_arg1);

	DTRACE_PROBE4(interrupt__start, dev_info_t, iinfo->dip,
	    void *, handler, caddr_t, handler_arg1, caddr_t, handler_arg2);

	D1("cnex_intr_wrapper:ino=0x%llx invoke client handler\n", iinfo->ino);
	res = (*handler)(handler_arg1, handler_arg2);

	DTRACE_PROBE4(interrupt__complete, dev_info_t, iinfo->dip,
	    void *, handler, caddr_t, handler_arg1, int, res);

	DTRACE_PROBE4(channelintr__complete, uint64_t, iinfo->id,
	    cnex_intr_t *, iinfo, void *, handler, caddr_t, handler_arg1);

	return (res);
}
   void checkSphWallLubricationForce()
   {
      const uint_t timestep (timeloop_->getCurrentTimeStep()+1);

      // variables for output of total force - requires MPI-reduction
      pe::Vec3 forceSphr1(0);

      // temporary variables
      real_t gap        (0);

      for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt )
      {
         for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt )
         {
            pe::SphereID sphereI = ( curSphereIt.getBodyID() );
            if ( sphereI->getID() == id1_ )
            {
               for( auto globalBodyIt = globalBodyStorage_->begin(); globalBodyIt != globalBodyStorage_->end(); ++globalBodyIt)
               {
                  if( globalBodyIt->getID() == id2_ )
                  {
                     pe::PlaneID planeJ = static_cast<pe::PlaneID>( globalBodyIt.getBodyID() );
                     gap = pe::getSurfaceDistance(sphereI, planeJ);
                     break;
                  }
               }
               break;
            }
         }
      }

      WALBERLA_MPI_SECTION()
      {
         mpi::reduceInplace( gap, mpi::MAX );
      }
      WALBERLA_ROOT_SECTION()
      {
         if (gap < real_comparison::Epsilon<real_t>::value )
         {
            gap = walberla::math::Limits<real_t>::inf();
            WALBERLA_LOG_INFO_ON_ROOT( "Sphere still too far from wall to calculate gap!" );
         } else {
            WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere and wall: " << gap );
         }
      }

      // get force on sphere
      for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt )
      {
         for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt )
         {
            if( bodyIt->getID() == id1_ )
            {
               forceSphr1 += bodyIt->getForce();
            }
         }
      }

      // MPI reduction of pe forces over all processes
      WALBERLA_MPI_SECTION()
      {
         mpi::reduceInplace( forceSphr1[0], mpi::SUM );
         mpi::reduceInplace( forceSphr1[1], mpi::SUM );
         mpi::reduceInplace( forceSphr1[2], mpi::SUM );
      }
      WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1);

      if ( print_ )
      {
         WALBERLA_ROOT_SECTION()
         {
            std::ofstream file1;
            std::string filename1("Gap_LubricationForceBody1.txt");
            file1.open( filename1.c_str(), std::ofstream::app );
            file1.setf( std::ios::unitbuf );
            file1.precision(15);
            file1 << gap << " " << forceSphr1[0] << std::endl;
            file1.close();
         }
      }

      WALBERLA_ROOT_SECTION()
      {
         if ( timestep == uint_t(26399) )
         {
            // according to the formula from Ding & Aidun 2003
            // F = 6 * M_PI * rho_L * nu_L * relative velocity of both bodies=relative velocity of the sphere * r * r * 1/gap
            // the correct analytically calculated value is 339.292006996217
            // in this geometry setup the relative error is 0.183515322065561 %
            real_t analytical = real_c(6.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(-vel_[0]) * radius_ * radius_ * real_c(1.0)/gap;
            real_t relErr     = std::fabs( analytical - forceSphr1[0] ) / analytical * real_c(100.0);
            WALBERLA_CHECK_LESS( relErr, real_t(1) );
         }
      }

   }
   void checkSphSphLubricationForce()
   {
      const uint_t timestep (timeloop_->getCurrentTimeStep()+1);

      // variables for output of total force - requires MPI-reduction
      pe::Vec3 forceSphr1(0);
      pe::Vec3 forceSphr2(0);

      // temporary variables
      real_t gap        (0);

      // calculate gap between the two spheres
      for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt )
      {
         for( auto curSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); curSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++curSphereIt )
         {
            pe::SphereID sphereI = ( curSphereIt.getBodyID() );
            if ( sphereI->getID() == id1_ )
            {
               for( auto blockIt2 = blocks_->begin(); blockIt2 != blocks_->end(); ++blockIt2 )
               {
                  for( auto oSphereIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt2, bodyStorageID_); oSphereIt != pe::BodyIterator::end<pe::Sphere>(); ++oSphereIt )
                  {
                     pe::SphereID sphereJ = ( oSphereIt.getBodyID() );
                     if ( sphereJ->getID() == id2_ )
                     {
                        gap = pe::getSurfaceDistance( sphereI, sphereJ );
                        break;
                     }
                  }
               }
               break;
            }
         }
      }

      WALBERLA_MPI_SECTION()
      {
         mpi::reduceInplace( gap, mpi::MAX );
      }
      WALBERLA_ROOT_SECTION()
      {
         if (gap < real_comparison::Epsilon<real_t>::value )
         {
            // shadow copies have not been synced yet as the spheres are outside the overlap region
            gap = walberla::math::Limits<real_t>::inf();
            WALBERLA_LOG_INFO_ON_ROOT( "Spheres still too far apart to calculate gap!" );
         } else {
            WALBERLA_LOG_INFO_ON_ROOT( "Gap between sphere 1 and 2: " << gap );
         }
      }


      // get force on spheres
      for( auto blockIt = blocks_->begin(); blockIt != blocks_->end(); ++blockIt )
      {
         for( auto bodyIt = pe::BodyIterator::begin<pe::Sphere>( *blockIt, bodyStorageID_); bodyIt != pe::BodyIterator::end<pe::Sphere>(); ++bodyIt )
         {
            if( bodyIt->getID() == id1_ )
            {
               forceSphr1 += bodyIt->getForce();
            } else if( bodyIt->getID() == id2_ )
            {
               forceSphr2 += bodyIt->getForce();
            }
         }
      }

      // MPI reduction of pe forces over all processes
      WALBERLA_MPI_SECTION()
      {
         mpi::reduceInplace( forceSphr1[0], mpi::SUM );
         mpi::reduceInplace( forceSphr1[1], mpi::SUM );
         mpi::reduceInplace( forceSphr1[2], mpi::SUM );
         mpi::reduceInplace( forceSphr2[0], mpi::SUM );
         mpi::reduceInplace( forceSphr2[1], mpi::SUM );
         mpi::reduceInplace( forceSphr2[2], mpi::SUM );
      }
      WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id1_ << " : " << forceSphr1);
      WALBERLA_LOG_INFO_ON_ROOT("Total force on sphere " << id2_ << " : " << forceSphr2);

      if ( print_ )
      {
         WALBERLA_ROOT_SECTION()
         {
            std::ofstream file1;
            std::string filename1("Gap_LubricationForceBody1.txt");
            file1.open( filename1.c_str(), std::ofstream::app );
            file1.setf( std::ios::unitbuf );
            file1.precision(15);
            file1 << gap << " " << forceSphr1[0] << std::endl;
            file1.close();

            std::ofstream file2;
            std::string filename2("Gap_LubricationForceBody2.txt");
            file2.open( filename2.c_str(), std::ofstream::app );
            file2.setf( std::ios::unitbuf );
            file2.precision(15);
            file2 << gap << " " << forceSphr2[0] << std::endl;
            file2.close();
         }
      }


      WALBERLA_ROOT_SECTION()
      {
         if ( timestep == uint_t(1000) )
         {
            // both force x-components should be the same only with inverted signs
            WALBERLA_CHECK_FLOAT_EQUAL ( forceSphr2[0], -forceSphr1[0] );

            // according to the formula from Ding & Aidun 2003
            // F = 3/2 * M_PI * rho_L * nu_L * relative velocity of both spheres * r * r * 1/gap
            // the correct analytically calculated value is 339.2920063998
            // in this geometry setup the relative error is 0.1246489711 %
            real_t analytical = real_c(3.0)/real_c(2.0) * walberla::math::M_PI * real_c(1.0) * nu_L_ * real_c(2.0) * real_c(vel_[0]) * radius_ * radius_ * real_c(1.0)/gap;
            real_t relErr     = std::fabs( analytical - forceSphr2[0] ) / analytical * real_c(100.0);
            WALBERLA_CHECK_LESS( relErr, real_t(1) );
         }
      }
   }
Exemple #18
0
 Time::Seconds GetFadeTime() const
 {
   const uint_t val = uint_t(FadeTimeSec[0]) | (uint_t(FadeTimeSec[1]) << 8) | (uint_t(FadeTimeSec[2]) << 16);
   return Time::Seconds(val);
 }
Exemple #19
0
constexpr
eT
binomial_coef(const pT n, const pT k)
{
    return internal::binomial_coef_check<eT>(uint_t(n),uint_t(k));
}
Exemple #20
0
void testScaled( const std::string & filename, const Vector3<uint_t> & size, const std::string & datatype, const bool vtkOut )
{
   WALBERLA_LOG_INFO( "Testing scaled" );
   BinaryRawFile brf( filename, size, datatype );

   Vector3<uint_t> scaledSize( std::max( uint_t( 1 ), size[0] / uint_t( 2 ) ),
                               std::max( uint_t( 1 ), size[1] / uint_t( 3 ) ),
                               std::max( uint_t( 1 ), size[2] / uint_t( 5 ) ) );

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

   BinaryRawFileInterpolator brfi( blocks->getDomain(), brf, BinaryRawFileInterpolator::NEAREST_NEIGHBOR );

   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( scaledSize[0] ) - 1, cell_idx_c( scaledSize[1] ) - 1, cell_idx_c( scaledSize[2] ) - 1 );

      for (const Cell & c : ci)
      {
         auto pos = blocks->getBlockLocalCellCenter( block, c );
         field->get( c ) = brfi.get( pos );
      }
   }

   if (vtkOut)
   {
      WALBERLA_LOG_INFO( "Writing scaled" );
      auto vtkOutput = vtk::createVTKOutput_BlockData( blocks, "BinaryRawFileScaled" );
      vtkOutput->addCellDataWriter( make_shared< field::VTKWriter< ScalarField, uint8_t > >( scalarFieldID, "BinaryRawFile" ) );
      writeFiles( vtkOutput, true )();
   }
}
 uint_t String2Mask(const String& str)
 {
   return std::accumulate(str.begin(), str.end(), uint_t(0), LetterToMask);
 }
Exemple #22
0
Color3::Color3( uint32_t rgb ) :
  Tuple3<uchar_t>(uchar_t((rgb & 0xff0000) >> 16),uchar_t((rgb & 0x00ff00) >> 8),uchar_t(rgb & 0x0000ff))
{}

Color3::~Color3(){
}

/* ----------------------------------------------------------------------- */


bool Color3::operator==( const Color3& c ) const {
  return 
    (__RED == c.__RED) && 
    (__GREEN == c.__GREEN) && 
    (__BLUE == c.__BLUE);
}


/* ----------------------------------------------------------------------- */

uchar_t Color3::getBlue( ) const {
  return __BLUE;
}

uchar_t& Color3::getBlue( ) {
  return __BLUE;
}

real_t Color3::getBlueClamped( ) const {
  return (real_t)__BLUE / 255;
} 

uchar_t Color3::getGreen( ) const {
  return __GREEN;
}

uchar_t& Color3::getGreen( ) {
  return __GREEN;
} 

real_t Color3::getGreenClamped( ) const {
  return (real_t)__GREEN / 255;
}

 uchar_t Color3::getRed( ) const {
  return __RED;
}

uchar_t& Color3::getRed( ) {
  return __RED;
}

real_t Color3::getRedClamped( ) const {
  return (real_t)__RED / 255;
}
real_t Color3::getAverage() const {
    return (real_t)(__RED + __GREEN +__BLUE)/(real_t)3;
}

real_t Color3::getAverageClamped() const {
    return (real_t)(__RED + __GREEN +__BLUE)/(real_t)765;
}


uint_t Color3::toUint() const {
	return (uint_t(__RED) << 16) + (uint_t(__GREEN) << 8) + uint_t(__BLUE);
}

Color3 Color3::fromUint(uint_t value) {
  Color3 res;
  res.__RED = uchar_t((value & 0xff0000) >> 16);
  res.__GREEN = uchar_t((value & 0x00ff00) >> 8);
  res.__BLUE = uchar_t(value & 0x0000ff);
  return res;
}