void GetWeightedMean( const ParticleContainer& particles,
						  const WeightContainer& weights,
						  HeadBodyParticle& mean_particle )
		{
			assert( particles.size() == weights.size() );
			int n = static_cast<int>( particles.size() );
			double sum_x = 0.0;
			double sum_y = 0.0;
			double sum_s = 0.0;
			double sum_weight = 0.0;
			std::complex<double> vec_dh(0, 0);
			std::complex<double> vec_db(0, 0);
			for( int i = 0; i < n; ++i ) {
				sum_x += static_cast<double>( particles[i].x() ) * weights[i];
				sum_y += static_cast<double>( particles[i].y() ) * weights[i];
				sum_s += static_cast<double>( particles[i].s() ) * weights[i];
				double dh_phase = static_cast<double>( particles[i].dh() ) * 2 * M_PI / 8.0;
				vec_dh += std::complex<double>( weights[i]*std::cos(dh_phase), weights[i]*std::sin(dh_phase) );
				double db_phase = static_cast<double>( particles[i].db() ) * 2 * M_PI / 8.0;
				vec_db += std::complex<double>( weights[i]*std::cos(db_phase), weights[i]*std::sin(db_phase) );
				sum_weight += weights[i];
			}
			double denominator = 1.0 / sum_weight;
			mean_particle.set_x<double>( sum_x * denominator );
			mean_particle.set_y<double>( sum_y * denominator );
			mean_particle.set_s<double>( sum_s * denominator );
			if( std::norm(vec_dh) <= 1e-10 ) {
				throw std::runtime_error( "Failed to calculate head direction average." );
			}
			if( std::norm(vec_db) <= 1e-10 ) {
				throw std::runtime_error( "Failed to calculate body direction average." );
			}
			mean_particle.set_dh<double>( std::arg(vec_dh) * 8.0 / 2.0 / M_PI );
			mean_particle.set_db<double>( std::arg(vec_db) * 8.0 / 2.0 / M_PI );
		}
Пример #2
0
void particles::pidt::mappings::MoveParticles::prepareSendToNeighbour(
  particles::pidt::Vertex&                      vertex,
  int                                           toRank,
  const tarch::la::Vector<DIMENSIONS,double>&   x,
  const tarch::la::Vector<DIMENSIONS,double>&   h,
  int                                           level
) {
  logTraceInWith5Arguments( "prepareSendToNeighbour(...)", vertex, toRank, x, h, level );

  ParticleContainer  destinationParticles = extractAllParticlesFromDualCellBelongingToOneRank(
    vertex.getVertexIndex(),
    vertex,
    toRank,
    x,
    h
  );

  for (
    ParticleContainer::iterator p = destinationParticles.begin();
    p != destinationParticles.end();
    p++
  ) {
    p->setMovedParticle( particles::pidt::records::Particle::New );

    assertion5(
      Vertex::isContainedInDualCell(x,h,p->_persistentRecords._x),
      x,h,p->toString(),p->_persistentRecords._x - x,level
    );
  }

  ParticleHeap::getInstance().sendData(
    destinationParticles,
    toRank,
    x,
    level,
    peano::heap::NeighbourCommunication
  );

  logTraceOutWith1Argument( "prepareSendToNeighbour(...)", destinationParticles.size() );
}
Пример #3
0
inline dword
ParticleSystemChild::Size() const
{
    return m_Swarm.size();
}