const GFX::ParticleData* ParticleManager::GetParticleData(unsigned int bufferId) { unsigned int index = FindParticle(bufferId); if(index != std::numeric_limits<decltype(index)>::max()) { return &m_particles[index]; } return nullptr; }
void ParticleManager::BufferParticleData(unsigned int bufferId, GFX::Particle* data) { unsigned int index = FindParticle(bufferId); if(index != std::numeric_limits<decltype(index)>::max()) { glBindBuffer(GL_ARRAY_BUFFER, m_particles[index].VBO); glBufferData(GL_ARRAY_BUFFER, m_particles[index].particleCount * sizeof(GFX::Particle), data, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); } }
void ParticleManager::DeleteParticleBuffer(unsigned int bufferId) { unsigned int index = FindParticle(bufferId); if(index != std::numeric_limits<decltype(index)>::max()) { glDeleteBuffers(1, &m_particles[index].VBO); glDeleteVertexArrays(1, &m_particles[index].VAO); m_particles.erase(m_particles.begin() + index); } }
void Compute_Forces(gsl_matrix * Positions, gsl_matrix * Velocities, gsl_matrix * Neighbors, gsl_vector * ListHead, gsl_vector * List, int type1, int type2, gsl_matrix * Forces, gsl_vector * Energy, gsl_vector * Kinetic ) { // RESET MATRICES AND VECTORS // TODO: Redundant? gsl_matrix_set_zero(Forces); gsl_vector_set_zero(Energy); gsl_vector_set_zero(Kinetic); // Begin of parallel region int omp_get_max_threads(); int chunks = NParticles / omp_get_max_threads(); #pragma omp parallel { #pragma omp for schedule (dynamic,chunks) for (int i=0;i<NParticles;i++) { gsl_vector_view vi = gsl_matrix_row(Velocities, i); double * fij = malloc(3*sizeof(double)); // Compute the kinetic energy of particle i (0.5 mi vi^2) double ei = KineticEnergy(&vi.vector, (int) gsl_matrix_get(Positions,i,0)); gsl_vector_set(Kinetic,i,ei); // Obtain the list of neighboring cells to iCell (the cell i belongs to) int iCell = FindParticle(Positions,i); gsl_vector_view NeighboringCells = gsl_matrix_row(Neighbors, iCell); // Obtain the list of neighboring particles that interacts with i // i interacts with all Verlet[j] particles (j = 0 .. NNeighbors-1) int * Verlet = malloc(27 * NParticles * sizeof(int) / (Mx*My*Mz)); int NNeighbors = Compute_VerletList(Positions, i, &NeighboringCells.vector, iCell, ListHead, List, Verlet); // Loop over all the j-neighbors of i-particle for (int j=0;j<NNeighbors;j++) { ei = Compute_Force_ij(Positions, i, Verlet[j], type1, type2, fij); Forces->data[i*Forces->tda + 0] += fij[0]; Forces->data[i*Forces->tda + 1] += fij[1]; Forces->data[i*Forces->tda + 2] += fij[2]; Energy->data[i*Energy->stride] += ei; } free(Verlet); free(fij); } } // End of parallel region }