Exemplo n.º 1
0
particles::pidt::mappings::MoveParticles::ParticleContainer  particles::pidt::mappings::MoveParticles::extractAllParticlesFromDualCellBelongingToOneRank(
  int                                           sourceHeapIndex,
  particles::pidt::Vertex&                      vertex,
  int                                           rank,
  const tarch::la::Vector<DIMENSIONS,double>&   x,
  const tarch::la::Vector<DIMENSIONS,double>&   h
) {
  ParticleContainer  destinationParticles;

  ParticleContainer& localVertexParticles = ParticleHeap::getInstance().getData(sourceHeapIndex);

  for (
    ParticleContainer::iterator p = localVertexParticles.begin();
    p!=localVertexParticles.end();
  ) {
    const bool particleDoesNotTunnel = Vertex::isContainedInDualCell(x,h,p->_persistentRecords._x);

    const int  whichAdjacentCellHoldsParticle =
      peano::utils::dLinearised(Vertex::getDualCellOfParticle(x,p->_persistentRecords._x),2);

    const bool particleBelongsToNeighbouringRank = vertex.getAdjacentRanks()(whichAdjacentCellHoldsParticle)==rank;

    if (particleDoesNotTunnel && particleBelongsToNeighbouringRank) {
      destinationParticles.push_back(*p);
      p = localVertexParticles.erase(p);
    }
    else {
      p++;
    }
  }

  return destinationParticles;
}
	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 );
		}
Exemplo n.º 3
0
void CanonicalEnsembleTest::UpdateNumMoleculesSequential() {
// remove the ifndef when canonicalensemble can be tested in parallel
#ifndef ENABLE_MPI

	delete _domainDecomposition;
	// will be deleted by tearDown()
	_domainDecomposition = new DomainDecompDummy();

	// the halo is cleared for freshly initialized particle containers.
	ParticleContainer* container = initializeFromFile(ParticleContainerFactory::AdaptiveSubCell, "1clj-regular-12x12x12.inp", 1.0);
	vector<Component>& components(_domain->getComponents());
	CanonicalEnsemble ensemble(container, &components);

	ensemble.updateGlobalVariable(NUM_PARTICLES);
	// has the ensemble counted the right number of particles?
	ASSERT_EQUAL(1728ul, ensemble.N());
	// has the ensemble updated the count of particles per component right?
	ASSERT_EQUAL(1728ul, components[0].getNumMolecules());

	Molecule molecule(1729, 0, 5.5, 5.5, 5.5, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., &components);
	container->addParticle(molecule);

	ensemble.updateGlobalVariable(NUM_PARTICLES);
	// has the ensemble counted the right number of particles?
	ASSERT_EQUAL(1729ul, ensemble.N());
	// has the ensemble updated the count of particles per component right?
	ASSERT_EQUAL(1729ul, components[0].getNumMolecules());

#endif
}
	virtual void mt_Update(float delta_time_s, ParticleContainer& particles)
	{
		auto& l_Life = particles.m_Lifespan;
		auto& l_MLife = particles.m_Max_Lifespan;
		auto& l_Col = particles.m_Current_Color;
		auto& l_SCol = particles.m_Start_Color;
		auto& l_FCol = particles.m_Final_Color;
		auto& l_Rot = particles.m_Current_Rotation;
		auto& l_SRot = particles.m_Start_Rotation;
		auto& l_FRot = particles.m_Final_Rotation;
		auto& l_Size = particles.m_Current_Size;
		auto& l_SSize = particles.m_Start_Size;
		auto& l_FSize = particles.m_Final_Size;

		for (std::size_t ii = 0; ii < particles.mt_Get_Alive_Count(); ii++)
		{
			if (l_SCol[ii].r != l_FCol[ii].r)
			{
				l_Col[ii].r = misc::fn_Time_Interpolate<sf::Uint8>(0.0f, l_MLife[ii], l_SCol[ii].r, l_FCol[ii].r, l_Life[ii]);
			}
			if (l_SCol[ii].g != l_FCol[ii].g)
			{
				l_Col[ii].g = misc::fn_Time_Interpolate<sf::Uint8>(0.0f, l_MLife[ii], l_SCol[ii].g, l_FCol[ii].g, l_Life[ii]);
			}
			if (l_SCol[ii].b != l_FCol[ii].b)
			{
				l_Col[ii].b = misc::fn_Time_Interpolate<sf::Uint8>(0.0f, l_MLife[ii], l_SCol[ii].b, l_FCol[ii].b, l_Life[ii]);
			}
			if (l_SCol[ii].a != l_FCol[ii].a)
			{
				l_Col[ii].a = misc::fn_Time_Interpolate<sf::Uint8>(0.0f, l_MLife[ii], l_SCol[ii].a, l_FCol[ii].a, l_Life[ii]);
			}
		}

		for (std::size_t ii = 0; ii < particles.mt_Get_Alive_Count(); ii++)
		{
			if (l_SRot[ii] != l_FRot[ii])
			{
				l_Rot[ii] = misc::fn_Time_Interpolate<float>(0.0f, l_MLife[ii], l_SRot[ii], l_FRot[ii], l_Life[ii]);
			}
		}

		for (std::size_t ii = 0; ii < particles.mt_Get_Alive_Count(); ii++)
		{
			if (l_SSize[ii] != l_FSize[ii])
			{
				l_Size[ii].x = misc::fn_Time_Interpolate<float>(0.0f, l_MLife[ii], l_SSize[ii].x, l_FSize[ii].x, l_Life[ii]);
				l_Size[ii].y = misc::fn_Time_Interpolate<float>(0.0f, l_MLife[ii], l_SSize[ii].y, l_FSize[ii].y, l_Life[ii]);
			}
		}
	}
Exemplo n.º 5
0
void CuboidInitializer::initialize(ParticleContainer& container) {
	double x[] = {0,0,0};
	double m = _config.getMaterialConfig().getM();
	double epsilon = _config.getMaterialConfig().getEpsilon();
	double sigma = _config.getMaterialConfig().getSigma();
	LOG4CXX_DEBUG(logger, "SphereInitializer material: m=" << m << " epsilon=" << epsilon << " sigma=" << sigma);

	const utils::Vector<double,3>& v = _config.getV();
	const utils::Vector<int, 3>& n = _config.getN();

	LOG4CXX_DEBUG(logger, "Initializing CUBE at " << _config.getX().toString());

	for (int i = 0; i < n[0]; i++) {
		for (int j = 0; j < n[1]; j++) {
			for (int k = 0; k < n[2]; k++) {
				x[0] = _config.getX()[0] + ((double)i) * _config.getH();
				x[1] = _config.getX()[1] + ((double)j) * _config.getH();
				x[2] = _config.getX()[2] + ((double)k) * _config.getH();
				LOG4CXX_TRACE(logger, "creating (x,y,z): (" << x[i] << "," << x[j] << "," << x[k] << ")");
				Particle p(x, v, m, epsilon, sigma, _type_id);
				//MaxwellBoltzmannDistribution(p, 0.1, dim);
				container.addParticle(p);
			}
		}
	}
}
Exemplo n.º 6
0
void Statistics::calculateStatistics(ParticleContainer& container, int iteration) {

	int frequency = 2000;

//	if ((iteration + 50) % frequency == 0) {
//		_saveX = true;
//		container.traverseParticles(*this);
//		LOG4CXX_DEBUG(logger, "Saved oldX at iteration "<< iteration);
//	}

	if ((iteration + 25) % frequency == 0) {
//	  _saveX = false;
//	  _diffusionFactor = 0;
//	  container.traverseParticles(*this);
//	  LOG4CXX_DEBUG(logger, "calculated diffusion of " << _diffusionFactor << " at iteration " << iteration);
	  _saveX = true;
	  // reset x
	  container.traverseParticles(*this);
	  LOG4CXX_DEBUG(logger, "Saved oldX at iteration "<< iteration);
	}

	//if ((iteration + 1) % frequency == 0) {
//		// reset counter and count particle pair distances
//		for (int i = 0; i < _numIntervalls; i++) {
//			_distanceCount[i] = 0;
//		}
		//container.traversePairs(*this);
	//}

	if (iteration == 1 || iteration % frequency == 0) {
    _saveX = false;
    container.traverseParticles(*this);
		_diffusionFactor = _diffusionFactor / container.getNumParticles();

		// reset counter and count particle pair distances
		for (int i = 0; i < _numIntervalls; i++) {
		  _distanceCount[i] = 0;
		}
		// count particlePairDistances
		container.traversePairs(*this);
		writeFile(iteration);
	}
}
Exemplo n.º 7
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() );
}
Exemplo n.º 8
0
void FileReader::readFile(ParticleContainer& particles, char* filename) {
	double x[] = {0,0,0};
	double v[] = {1,1,1};
	double m = 1;
    int num_particles = 0;

    std::ifstream input_file(filename);
    string tmp_string;

    if (input_file.is_open()) {

    	getline(input_file, tmp_string);
    	cout << "Read line: " << tmp_string << endl;

    	while (tmp_string.size() == 0 || tmp_string[0] == '#') {
    		getline(input_file, tmp_string);
    		cout << "Read line: " << tmp_string << endl;
    	}

    	istringstream numstream(tmp_string);
    	numstream >> num_particles;
    	cout << "Reading " << num_particles << "." << endl;
    	getline(input_file, tmp_string);
    	cout << "Read line: " << tmp_string << endl;

    	for (int i = 0; i < num_particles; i++) {
    		istringstream datastream(tmp_string);

    		for (int j = 0; j < 3; j++) {
    			datastream >> x[j];

    		}
    		for (int j = 0; j < 3; j++) {
    			datastream >> v[j];
    		}
    		if (datastream.eof()) {
    			cout << "Error reading file: eof reached unexpectedly reading from line " << i << endl;
    			exit(-1);
    		}
    		datastream >> m;
    		Particle p(x, v, m);
    		particles.add(p);

    		getline(input_file, tmp_string);
    		cout << "Read line: " << tmp_string << endl;
    	}
    } else {
Exemplo n.º 9
0
void SphereInitializer::initialize(ParticleContainer& container) {
	utils::Vector<double,3> x(0.);
	double m = _config.getMaterialConfig().getM();
	double epsilon = _config.getMaterialConfig().getEpsilon();
	double sigma = _config.getMaterialConfig().getSigma();
	LOG4CXX_DEBUG(logger, "SphereInitializer material: m=" << m << " epsilon=" << epsilon << " sigma=" << sigma);

	int n = _config.getN();
	double h = _config.getH();
	double radius = ((double)n) * h;
	const utils::Vector<double, 3>& center = _config.getX();

	utils::Vector<double,3> radius_vector = radius;
	utils::Vector<double,3> lower_left_front = center - radius_vector;
	int dim = Configuration::getInstance().getDimension();
	LOG4CXX_DEBUG(logger, "SphereINitializer dimension: " << dim );

	bool two_d = (dim == 2);
	if (two_d) {
		lower_left_front[2] = center[2];
	}

	const utils::Vector<double, 3>& v = _config.getV();

	int innerCount = two_d ? 1 : (2*n);
	LOG4CXX_DEBUG(logger, "Initializing SPHERE at " << _config.getX().toString() << " two_d==" << two_d);

	for (int i = 0; i < n*2; i++) {
		for (int j = 0; j < n*2; j++) {
			for (int k = 0; k < innerCount; k++) {
				x[0] = lower_left_front[0] + ((double)i) * h;
				x[1] = lower_left_front[1] + ((double)j) * h;
				x[2] = lower_left_front[2] + ((double)k) * h;
				LOG4CXX_TRACE(logger, "point at " << x.toString() << "has distance " << (x - center).L2Norm() << " and radius is "<< radius);
				if ((x - center).L2Norm() < radius) {
					LOG4CXX_TRACE(logger, "creating (x,y,z): (" << x[0] << "," << x[1] << "," << x[2] << ")");
					Particle p(x, v, m, epsilon, sigma, _type_id);
					//MaxwellBoltzmannDistribution(p, 0.1, dim);
					container.addParticle(p);
				}
			}
		}
	}
}
Exemplo n.º 10
0
inline
ParticleSystemChild::~ParticleSystemChild()
{
    m_Swarm.clear();
}
Exemplo n.º 11
0
double EnergyCalculator::calculateEnergy(ParticleContainer& container) {
    _energy = 0;
    container.traverseParticles(*this);
    return _energy;
}
Exemplo n.º 12
0
ReturnType SendCouplingMDCommand::executeProcessing()
{
	logger->debug() << "starting SendCouplingMDCommand::executeProcessing" << std::endl;
	CouplingInformationType* couplingInfo = (CouplingInformationType*) this->getData(0);
	Simulation* theSim = (Simulation*) this->getData(1);
	ParticleContainer* moleculeContainer = theSim->getMolecules();

	if (transferContainer == NULL)
	{
		transferContainer = new std::vector<Molecule>[couplingInfo->numberOfBoundaries];
	}

/*	int dim = borderToLook / 2;
	int dir = borderToLook % 2;*/
	int dim, dir;
	outmin = 0;
	outmax = 0;
	double rmin =  moleculeContainer->getBoundingBoxMin(dim);
	double rmax =  moleculeContainer->getBoundingBoxMax(dim);

	logger->debug() << "dim is " << dim << ", dir is " << dir << std::endl;
	logger->debug() << "halo is " << moleculeContainer->get_halo_L(dim) << std::endl;
	Molecule* currentMolecule;

	double low_limit = rmin; // particles below this limit have to be copied or moved to the lower process
	double high_limit = rmax; // particles above(or equal) this limit have to be copied or moved to the higher process

	currentMolecule = moleculeContainer->begin();

	logger->debug() << "low_limit: " << low_limit << " / high_limit: " << high_limit << std::endl;
	while(currentMolecule!=moleculeContainer->end()){
		for (int i = 0; i < couplingInfo->numberOfBoundaries; i++)
		{
			CouplingBoundary currentBoundary = couplingInfo->boundaries[i];
			//const double& rd=currentMolecule->r(dim);
			const double& rd = currentMolecule->r(currentBoundary.outFlowDirection);
			const double& ro1 = currentMolecule->r(currentBoundary.otherDirection[0]);
			const double& ro2 = currentMolecule->r(currentBoundary.otherDirection[1]);
			if ((currentBoundary.lowerHigher == 1) && (rd > high_limit) && isInBounds(ro1,ro2, &currentBoundary))
			{
				outmax++;
				transferContainer[i].push_back(*currentMolecule);
				currentMolecule = moleculeContainer->deleteCurrent ();
				break;
			}
			else if ((currentBoundary.lowerHigher == 0) && (rd < low_limit) && isInBounds(ro1,ro2, &currentBoundary))
			{
				transferContainer[i].push_back(*currentMolecule);
				currentMolecule = moleculeContainer->deleteCurrent();
				outmin++;
				break;
			}
			else
			{
				currentMolecule = moleculeContainer->next();
			}
		}
	}
	logger->debug() << "outmin["<< dim << "] = " << outmin << std::endl;
	logger->debug() << "outmax["<< dim << "] = " << outmax << std::endl;
	//logger->debug() << "there are now " << transferContainer.size() << " molecules to transfer " << std::endl;
	if (getStepInterval() > 0)
	{
		return REPETITION_REQUESTED;
	}
	else
	{
		return EXECUTED;
	}

}
Exemplo n.º 13
0
inline void
ParticleSystemChild::Clear()
{
    m_Swarm.clear();

}
Exemplo n.º 14
0
inline void
ParticleSystemChild::Reserve(dword n)
{
    m_Swarm.reserve(n);

}
Exemplo n.º 15
0
inline dword
ParticleSystemChild::Capacity() const
{
    return m_Swarm.capacity();
}
Exemplo n.º 16
0
inline dword
ParticleSystemChild::Size() const
{
    return m_Swarm.size();
}
Exemplo n.º 17
0
void FileReader::readFile(ParticleContainer& container, char* filename) {
	double x[] = {0,0,0};
	double v[] = {1,1,1};
	double m = 1;
	int num_particles = 0;

	std::ifstream input_file(filename);
	string tmp_string;

	if (input_file.is_open()) {

		getline(input_file, tmp_string);
		LOG4CXX_DEBUG(logger, "Read line: " << tmp_string);

		while (tmp_string.size() == 0 || tmp_string[0] == '#') {
			LOG4CXX_DEBUG(logger,  "Skipped line: " << tmp_string);
			getline(input_file, tmp_string);
			LOG4CXX_DEBUG(logger,  "Read line: " << tmp_string);
		}

		istringstream numstream(tmp_string);
		numstream >> num_particles;
		LOG4CXX_INFO(logger, "Reading " << num_particles << " particles");
		getline(input_file, tmp_string);
		LOG4CXX_TRACE(logger, "Read line: " << tmp_string);

		for (int i = 0; i < num_particles; i++) {
			istringstream datastream(tmp_string);

			for (int j = 0; j < 3; j++) {
				datastream >> x[j];

			}
			for (int j = 0; j < 3; j++) {
				datastream >> v[j];
			}
			if (datastream.eof()) {
				LOG4CXX_FATAL(logger, "Error reading file: eof reached unexpectedly reading from line " << i << "!");
				exit(-1);
			}
			datastream >> m;
			Particle p(x, v, 0);
			container.add(p);

			getline(input_file, tmp_string);
			LOG4CXX_TRACE(logger, "Read line: " << tmp_string);
		}
		// all fixed particles read
		//now cuboid functions etc.
		while(!input_file.eof()) {
			string keyword;
			LOG4CXX_TRACE(logger, "Read line: " << tmp_string);
			istringstream lstream(tmp_string);
			lstream >> keyword;

			if(!keyword.compare("cuboid")) {
				utils::Vector<double, 3> bottomLeft, initialVelocity;
				int nX1, nX2, nX3, type;
				double h, m, bMean;

				lstream >> bottomLeft[0];
				lstream >> bottomLeft[1];
				lstream >> bottomLeft[2];
				lstream >> initialVelocity[0];
				lstream >> initialVelocity[1];
				lstream >> initialVelocity[2];
				lstream >> m;
				lstream >> type;
				lstream >> bMean;
				lstream >> nX1;
				lstream >> nX2;
				lstream >> nX3;
				lstream >> h;

				ParticleGenerator::regularCuboid(container, bottomLeft, nX1, nX2, nX3, h, type, initialVelocity, bMean);
			}
			if(!keyword.compare("particle")){
				LOG4CXX_TRACE(logger, "Generating Particle");

				Particle p(tmp_string);
				container.add(p);

			}
			getline(input_file, tmp_string);
		}
Exemplo n.º 18
0
void VTKWriter::writeOutput(ParticleContainer& container, const std::string& filename, int iteration) {
	initializeOutput(container.getNumParticles());
	container.traverseParticles(*this);
	writeFile(filename, iteration);
}