void killMomentum(void) { Vec3 P = momentum(); int n = numParticles(); Vec3 Pcorr = scale(P, -1/n); forEveryParticleD(&addMomentum, (void*)&Pcorr); }
void Particles::write(std::ofstream & out) const { int N = numParticles(); int size = sizeof(Vec2f) * N; out.write(reinterpret_cast<const char*>(&N), sizeof(int)); out.write(reinterpret_cast<const char*>(&_pos[0]), size); out.write(reinterpret_cast<const char*>(&_vel[0]), size); }
bool physicsCheck(void) { Vec3 P = momentum(); double PPP = length(P) / numParticles(); //printf("%le\n",PPP); if (PPP > 1e-20) { fprintf(stderr, "\nMOMENTUM CONSERVATION VIOLATED! " "Momentum per particle: |P| = %le\n", PPP); return false; } return true; }
void System<DataType,Integrator,Potential,Communicator>::updateForces() { unsigned int numParts = numParticles() ; for (auto i = forces.begin(); i != forces.end(); ++i) { *i = 0 ; } // For each ij interaction calculate force. // for (unsigned int i = 0 ; i < numParts*2 ; i+=2) { for (unsigned int j = i+2 ; j < numParts*2 ; j+=2) { // Get shortest connecting vector in periodic system. // DataType x_comp = (positions[j] - positions[i]) ; x_comp -= totCellLength*std::round(x_comp*totCellLengthInv) ; DataType y_comp = positions[j+1] - positions[i+1] ; y_comp -= totCellLength*std::round(y_comp*totCellLengthInv) ; // Calculate the force for this vector using the distance. // DataType distSqr = x_comp*x_comp + y_comp*y_comp ; // Cutoff distance is when r = 2.5 sigma . // if (distSqr < Potential::cutOffDistSqr) { DataType forceMag = Potential::calcForce(distSqr) ; DataType xForce = forceMag*x_comp ; DataType yForce = forceMag*y_comp ; forces[i] += xForce ; forces[i+1] += yForce ; forces[j] -= xForce ; forces[j+1] -= yForce ; } } } // Consider the ghost particles. // for (unsigned int i = 0 ; i < numParts*2 ; i+=2) { for (unsigned int j = 0 ; j < boundaryGhostPositions.size() ; j+=2) { // Get shortest connecting vector in periodic system. // DataType x_comp = (boundaryGhostPositions[j] - positions[i]) ; x_comp -= totCellLength*std::round(x_comp*totCellLengthInv) ; DataType y_comp = boundaryGhostPositions[j+1] - positions[i+1] ; y_comp -= totCellLength*std::round(y_comp*totCellLengthInv) ; // Calculate the force for this vector using the distance. // DataType distSqr = x_comp*x_comp + y_comp*y_comp ; // Cutoff distance is when r = 2.5 sigma . // if (distSqr < Potential::cutOffDistSqr) { DataType forceMag = Potential::calcForce(distSqr) ; DataType xForce = forceMag*x_comp ; DataType yForce = forceMag*y_comp ; forces[i] += xForce ; forces[i+1] += yForce ; } } } } /* ----- end of member function updateForces ----- */
double getKineticTemperature(void) { return 2.0 / (3.0 * BOLTZMANN_CONSTANT) * kineticEnergy() / numParticles(); }
osgParticle::Particle* ParticleSystem::createParticle(const osgParticle::Particle *ptemplate) { if (numParticles()-numDeadParticles() < mQuota) return osgParticle::ParticleSystem::createParticle(ptemplate); return NULL; }