Example #1
0
void Simulation::integrateExplicitEuler()
{
	VectorX force;
	computeForces(m_mesh->m_current_positions, force);

	VectorX pos_next;
	pos_next.resize(m_mesh->m_system_dimension);

	//two explicit euler different modes:
	if (m_integration_method == INTEGRATION_EXPLICIT_EULER_DISCRETE)
	{

		//update rule here is xn+1 = xn + m_h*(vn-1 + f(xn-1,vn-1))
		pos_next = m_mesh->m_current_positions +m_h*(m_mesh->m_previous_velocities + force*m_h);
	}
	else if (m_integration_method == INTEGRATION_EXPLICIT_EULER_SYMPLETIC)
	{
		//Sympletic Euler uses the new velocity when computing for the new position
		ScalarType mh_squared = m_h*m_h;

		//vn+1 = vn + h*f(xn,vn)
		//xn+1 = xn + vn+1*h;
		//update rule here is xn+1 = xn + m_h*(vn  + f(xn,vn))
		pos_next = m_mesh->m_current_positions + m_mesh->m_current_velocities*m_h + force*mh_squared;
	}

	updatePosAndVel(pos_next);
}
Example #2
0
void Scene::backwardEulersUpdate (double dT) {
    
    // initialize a changeable substitute for the vector of particles
    std::vector<Particle*> standIn;
    for (int i = 0; i < particles.size(); i++) standIn.push_back(particles[i]);
    
    // compute a forward euler step to find state at t + 1
    forwardEulersUpdate(dT);
    
    // compute forces at t + 1
    std::vector<Vector3d> dVel = computeForces();
    std::vector<Vector3d> dPos;
    for (int i = 0; i < standIn.size(); i++) dPos.push_back(standIn[i]->vel);
    
    // compute acceleration, velocity change and position change in t + 1
    for (int i = 0; i < particles.size(); i++) {
        dVel[i] = dT * dVel[i] / particles[i]->mass;
        dPos[i] = dT * dPos[i];
    }
    
    //update scene velocity and position step based on original position plus vel & pos at t + 1
    for (int i = 0; i < particles.size(); i++) {
        particles[i]->vel = particles[i]->vel + dVel[i];
        particles[i]->pos = particles[i]->pos + dPos[i];
    }
}
Example #3
0
void move(particle_t* Particles){

	double Fold[N_SIMULATION][DIM_SIMULATION];

	for(int i=0;i<N_SIMULATION;i++){
		updateX(Particles+i);
	}

	glutPostRedisplay();

	for(int i=0;i<N_SIMULATION;i++){
		for(int d=0;d<DIM_SIMULATION;d++)
		Fold[i][d]=Particles[i].force[d];
	}
	
	

	computeForces(Particles);

	for(int i=0;i<N_SIMULATION;i++){
		updateV(Particles+i,Fold[i]);
		// check if we are at the walls and redirect the speed!
	}

}
Example #4
0
void SolverThread::stepPhysics(float dt)
{
	computeForces();

	clearStiffnessAssembly();	

	if(bUseStiffnessWarping)
		updateOrientation();
	else
		resetOrientation();

	stiffnessAssembly();
	
	// addPlasticityForce(dt);
 
	dynamicsAssembly(dt);
 
#if SOLVEONGPU
	solveGpu(m_V, m_stiffnessMatrix);
#else
    solve(m_V);
#endif
 
	updatePosition(dt);
	
#if ENABLE_DBG	
	dbglg.write("Re");
	unsigned totalTetrahedra = m_mesh->numTetrahedra();
	FEMTetrahedronMesh::Tetrahedron * tetrahedra = m_mesh->tetrahedra();
	for(unsigned k=0;k<totalTetrahedra;k++) {
	    dbglg.write(k);
		dbglg.write(tetrahedra[k].Re.str());
	}

	dbglg.writeMat33(m_stiffnessMatrix->valueBuf(), 
	    m_stiffnessMatrix->numNonZero(),
	    "K ");

	dbglg.write("Rhs");
	unsigned totalPoints = m_mesh->numPoints();
	for(unsigned k=0;k<totalPoints;k++) {
	    dbglg.write(k);
		dbglg.write(rightHandSide()[k].str());
		dbglg.newLine();
	}
	dbglg.write("F0");
	for(unsigned k=0;k<totalPoints;k++) {
	    dbglg.write(k);
		dbglg.write(m_F0[k].str());
		dbglg.newLine();
	}
#endif
}
Example #5
0
void Simulation::integrateClassicExplicitEuler()
{
	VectorX force;
	computeForces(m_mesh->m_current_positions, force);

	//vn+1 = vn + h*f(xn,vn)
	//xn+1 = xn + vn*h;
	m_mesh->m_previous_velocities = m_mesh->m_current_velocities;
	m_mesh->m_current_velocities = m_mesh->m_current_velocities + m_h*force;
	m_mesh->m_current_positions = m_mesh->m_current_positions + m_h* m_mesh->m_previous_velocities;

	//restaura posição
	
}
void ParticleSimulation::particleDerivate(float* temp)
{
    clearForces();
    computeForces();
    for (int i = 0; i < ps.length; i++)
    {
        *(temp++) = ps.particles[i].velo[0];
        *(temp++) = ps.particles[i].velo[1];
        *(temp++) = ps.particles[i].velo[2];
        *(temp++) = ps.particles[i].force_acc[0] / ps.particles[i].mass;
        *(temp++) = ps.particles[i].force_acc[1] / ps.particles[i].mass;
        *(temp++) = ps.particles[i].force_acc[2] / ps.particles[i].mass;
    }
}
Example #7
0
void Scene::midPointUpdate (double dT) {
    
    std::vector<Particle*> copy;
    for (int i = 0; i < particles.size(); i++) copy.push_back(new Particle(*particles[i]));
    
    // compute a
    std::vector<Vector3d> a1;
    for (int i = 0; i < particles.size(); i++) a1.push_back(particles[i]->vel);
    
    std::vector<Vector3d> a2 = computeForces();
    
    for (int i = 0; i < particles.size(); i++) {
        a1[i] = a1[i]*dT;
        a2[i] = a2[i]*dT/particles[i]->mass;
    }
    
    // alter copy
    for (int i = 0; i < particles.size(); i++) {
        copy[i]->pos = copy[i]->pos + (0.5*a1[i]);
        copy[i]->vel = copy[i]->vel + (0.5*a2[i]);
    }
    
    // compute b
    std::vector<Vector3d> b1;
    for (int i = 0; i < particles.size(); i++) b1.push_back(copy[i]->vel);
    
    std::vector<Vector3d> b2 = computeForces();
    
    for (int i = 0; i < particles.size(); i++) {
        b1[i] = b1[i]*dT;
        b2[i] = b2[i]*dT/particles[i]->mass;
        particles[i]->pos += b1[i];
        particles[i]->vel += b2[i];
        delete copy[i];
    }
    
}
Example #8
0
void Scene::forwardEulersUpdate (double dT) {

  // Initialize Vectors
  std::vector<Vector3d> forces = computeForces();

  for (int i = 0; i < particles.size(); i++) {
    // Position Update
    particles[i]->pos = particles[i]->pos + dT * particles[i]->vel;
        
    // Velocity Update
    Vector3d accel = forces[i] / particles[i]->mass;
    
    particles[i]->vel = particles[i]->vel + dT * accel;
    
  }

}
bool ElasticBand::update(InnerModel *innermodel, WayPoints &road, const RoboCompLaser::TLaserData &laserData,
                         const CurrentTarget &currentTarget, uint iter)
{
	//qDebug() << __FILE__ << __FUNCTION__ << "road size"<<  road.size();
	if (road.isFinished() == true)
		return false;

	/////////////////////////////////////////////
	//Tags all points in the road ar visible or blocked, depending on laser visibility. Only visible points are processed in this iteration
	/////////////////////////////////////////////
	//checkVisiblePoints(innermodel, road, laserData);

	/////////////////////////////////////////////
	//Check if there is a sudden shortcut to take
	/////////////////////////////////////////////
	//shortCut(innermodel, road, laserData);

	/////////////////////////////////////////////
	//Add points to achieve an homogenoeus chain
	/////////////////////////////////////////////
	addPoints(road, currentTarget);

	/////////////////////////////////////////////
	//Remove point too close to each other
	/////////////////////////////////////////////
	cleanPoints(road);

	/////////////////////////////////////////////
	//Compute the scalar magnitudes
	/////////////////////////////////////////////
	computeForces(innermodel, road, laserData);

	/////////////////////////////////////////////
	//Delete half the tail behind, if greater than 6, to release resources
	/////////////////////////////////////////////
	if (road.getIndexOfClosestPointToRobot() > 6)
	{
		for (auto it = road.begin(); it != road.begin() + (road.getIndexOfCurrentPoint() / 2); ++it)
			road.backList.append(it->pos);
		road.erase(road.begin(), road.begin() + (road.getIndexOfCurrentPoint() / 2));
	}
	return true;
}
Example #10
0
void Simulation::integrateExplicitEuler()
{
    // q_{n+1} - 2q_n + q_{n-1} = h^2 * M^{-1} * force(q_{n-1})

    // inertia term 2q_n - q_{n-1} is calculated in calculateInertiaY function

    // calculate force(q_{n-1})
   // VectorX position_previous = m_mesh->m_current_positions - m_mesh->m_current_velocities*m_h;
    VectorX position_previous = m_mesh->m_current_positions - m_mesh->m_current_velocities*m_h;
    VectorX force_previous;
    computeForces(position_previous, force_previous);

	//cout<<force_previous<<endl;
    // update q_{n+1}
    ScalarType h_square = m_h*m_h;
    VectorX pos_next = m_inertia_y + h_square*m_mesh->m_inv_mass_matrix*force_previous;
	//cout<<"pos_next"<<pos_next.block_vector(0)<<endl;
	//cout<<"m_current"<<m_mesh->m_current_positions.block_vector(0)<<endl;
    updatePosAndVel(pos_next);
}
Example #11
0
int main(int argc, char **argv) {

    const int NUM_OF_BODIES_DEFAULT = 1000;
    const int NUM_OF_TIME_STEPS_DEFAULT = 10;

    const int num_of_bodies = (argc > 1) ? atoi(argv[1]) : NUM_OF_BODIES_DEFAULT;
    const int num_of_time_steps = (argc > 2) ? atoi(argv[2]) : NUM_OF_TIME_STEPS_DEFAULT;

    const double delta_t = 0.01;
    const double theta = 1.0;

    printf("Bodies: %d, time steps: %d\n", num_of_bodies, num_of_time_steps);

    Body *bodies = new Body[num_of_bodies];

    clock_t c_beg = clock();

    Domain2D domain(-10.0, 10.0, -10.0, 10.0);

    initBodies(bodies, num_of_bodies, domain);

    for (int t = 0; t < num_of_time_steps; t++) {        
        QuadTree tree(bodies, num_of_bodies, domain);
        computeForces(bodies, num_of_bodies, tree, theta);
        updateBodies(bodies, num_of_bodies, delta_t);
        //printf("%d %d\n", tree.getHeight(), tree.getSize());
    }

    clock_t c_end = clock();

    printf("Time to compute: %.5f seconds\n", float(c_end - c_beg)/CLOCKS_PER_SEC);

    delete[] bodies;

    return 0;
}
Example #12
0
void Scene::rK4Update (double dT) {
    
    // initialize a changeable substitute for the vector of particles
    std::vector<Particle*> standIn;
    for (int i = 0; i < particles.size(); i++) standIn.push_back(new Particle(*particles[i]));
    
    // initialize acceleration, velocity vectors for A
    std::vector<Vector3d> a1;
    for (int i = 0; i < particles.size(); i++) a1.push_back(standIn[i]->vel);
    std::vector<Vector3d> a2 = computeForces();
    
    
    // find A and update standIn
    for (int i = 0; i < standIn.size(); i++) {
        a1[i] = a1[i] * dT;
        a2[i] = dT * a2[i] / standIn[i]->mass;
        
        // find RK4 positions and velocities for B
        standIn[i]->pos = .5 * a1[i] + particles[i]->pos;
        standIn[i]->vel = .5 * a2[i] + particles[i]->vel;
    }
    
    // initialize acceleration, velocity, and position vectors for B
    std::vector<Vector3d> b1;
    for (int i = 0; i < particles.size(); i++) b1.push_back(standIn[i]->vel);
    std::vector<Vector3d> b2 = computeForces();
    
    // find B and update standIn
    for (int i = 0; i < standIn.size(); i++) {
        b1[i] = b1[i] * dT;
        b2[i] = dT * b2[i] / standIn[i]->mass;
        
        // find RK4 positions and velocities for C
        standIn[i]->pos = .5 * b1[i] + particles[i]->pos;
        standIn[i]->vel = .5 * b2[i] + particles[i]->vel;
    }
    
    // initialize acceleration, velocity, vectors for C
    std::vector<Vector3d> c1;
    for (int i = 0; i < particles.size(); i++) c1.push_back(standIn[i]->vel);
    std::vector<Vector3d> c2 = computeForces();
    
    // find C and update standIn
    for (int i = 0; i < standIn.size(); i++) {
        c1[i] = c1[i] * dT;
        c2[i] = dT * c2[i] / standIn[i]->mass;
        
        // find RK4 positions and velocities for D
        standIn[i]->pos = c1[i] + particles[i]->pos;
        standIn[i]->vel = c2[i] + particles[i]->vel;
    }
    
    // initialize acceleration, velocity, and position vectors for D
    std::vector<Vector3d> d1;
    for (int i = 0; i < particles.size(); i++) d1.push_back(standIn[i]->vel);
    std::vector<Vector3d> d2 = computeForces();
    
    // find D
    for (int i = 0; i < standIn.size(); i++) {
        d1[i] = d1[i] * dT;
        d2[i] = dT * d2[i] / standIn[i]->mass;
        
    }
    
    // update poitions and velocities in particle based on Runge-Kutta 4 formula
    for (int i = 0; i < particles.size(); i++) {
        particles[i]->pos = particles[i]->pos + (1/6) * (2 * (b1[i] + c1[i]) +
                                                         a1[i] + d1[i]);
        
        particles[i]->vel = particles[i]->vel + (1/6) * (2 * (b2[i] + c2[i]) +
                                                         a2[i] + d2[i]);
        delete standIn[i];
    }
}
Example #13
0
void initData(particle_t* Particles, int DIM, int N){


		DIM_SIMULATION = DIM;
		N_SIMULATION = N;
		
		srand48(time(NULL));
		
	// initialize 'DARK MATTER PARTICLE' - black hole!!!
	Particles[0].p =(double*)malloc(DIM_SIMULATION*sizeof(double));
		Particles[0].v =(double*)malloc(DIM_SIMULATION*sizeof(double));
		Particles[0].force =(double*)malloc(DIM_SIMULATION*sizeof(double));

		for(int d=0;d<DIM_SIMULATION;d++){
			Particles[0].p[d] = 0;//(drand48()-0.5)*size;
			Particles[0].v[d] = 0;
			Particles[0].force[d] = 0;
     	}
		Particles[0].radius =  radius_all/10 ; // (drand48()+0.5)/10; // radius between 0.05 and 0.15
		Particles[0].r = 1;
		Particles[0].g = 1;
		Particles[0].b = 1;
		Particles[0].m = 1; // make the mass proportional to the volume
	
	 	double rand;
		

	for(int i=1;i<N_SIMULATION;i++){
		// allocate storage for the position velocity and force vectors, respectively.
		Particles[i].p =(double*)malloc(DIM_SIMULATION*sizeof(double));
		Particles[i].v =(double*)malloc(DIM_SIMULATION*sizeof(double));
		Particles[i].force =(double*)malloc(DIM_SIMULATION*sizeof(double));

		for(int d=0;d<DIM_SIMULATION;d++){
		rand = 	(drand48()-0.5)*size; 
		Particles[i].p[d] = rand >= 0 ? rand+1 : rand-1;
		
		Particles[i].v[d] =(drand48()-0.5);
		Particles[i].force[d] = 0;
     	}
		Particles[i].radius =  radius_all ; // (drand48()+0.5)/10; // radius between 0.05 and 0.15
		Particles[i].r =drand48();
		Particles[i].g = drand48();
		Particles[i].b = drand48();
		Particles[i].m = 3e-6; // make the mass proportional to the volume
	}

	computeForces(Particles);



	//DIM_SIMULATION = DIM;
	//N_SIMULATION  = N;
	///*SUN*/
	//Particles[0].p = new double[DIM_SIMULATION];// (double*) malloc(DIM*sizeof(double));
	//Particles[0].v = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[0].force = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));


	//Particles[0].p[0] = 0.;
	//Particles[0].p[1] = 0.;
	//Particles[0].p[2] = 0.;

	//Particles[0].v[0] = 0.;
	//Particles[0].v[1] = 0.;
	//Particles[0].v[2] = 0.;

	//Particles[0].m = 1;

	//Particles[0].r = 0.5f;
	//Particles[0].g = .0f;
	//Particles[0].b = 0.0f;
	//Particles[0].radius = (float)radius_all;


	///*EARTH*/
	//Particles[1].p = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[1].v = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[1].force = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));

	//Particles[1].p[0] = 0.;
	//Particles[1].p[1] = 1.;
	//Particles[1].p[2] = 0.;


	//Particles[1].v[0] = -1.;
	//Particles[1].v[1] = 0.;
	//Particles[1].v[2] = 0.;
	//Particles[1].m = 3.0e-6;

	//Particles[1].r = 0.0f;
	//Particles[1].g = 0.0f;
	//Particles[1].b = 1.0f;
	//Particles[1].radius = (float)radius_all/3;



	///*JUPITER*/
	//Particles[2].p = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[2].v = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[2].force = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));


	//Particles[2].p[0] = 0.;
	//Particles[2].p[1] = 5.36;
	//Particles[2].p[2] = 0.;


	//Particles[2].v[0] = -0.425;
	//Particles[2].v[1] = 0.;
	//Particles[2].v[2] = 0.;
	//Particles[2].m = 9.55e-4;


	//Particles[2].r = 0.4f;
	//Particles[2].g = .0f;
	//Particles[2].b = 1.0f;
	//Particles[2].radius = (float)radius_all/2;

	///*Halley Commet*/
	//Particles[3].p = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[3].v = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));
	//Particles[3].force = new double[DIM_SIMULATION];//(double*) malloc(DIM*sizeof(double));

	//Particles[3].p[0] = 34.75;
    //Particles[3].p[1] = 0.;
	//Particles[3].p[2] = 0.;




	//Particles[3].v[0] = 0.;
	//Particles[3].v[1] = 0.0296;
	//Particles[3].v[2] = 0.;
	//Particles[3].m = 1.e-14;

	//Particles[3].r = 1.0f;
	//Particles[3].g = 0.0f;
	//Particles[3].b = 0.0f;

	//Particles[3].radius = (float)radius_all/2;
	//computeForces(Particles);

}
Example #14
0
int main(int argc, char* argv[]){
  // domain variables
  int iter = 0;
  int i;
  int file_index;
  int max_iter;
  double max_time = 1.0;
  double dt = .0000001;
  double domain_box[4] = {0.0, 0.0, 1.0, 2.0};
  double domain_m_box[4] = {.10, 0.2, 0.90, 2.00};
  int domain_num_cells[2] = {10, 20};
  int pp_cell[2] = {2,2};
  double ipart_dim[2];
  int domain_num_particles[2];
  double test_px, test_py;
  char p_filename[40];
  char p_filename2[40];
  char g_filename[40];

  //timing variables
  double start_time;
  double end_time;

  // patch variables
  int rank = 0;
  int size;
  int num_proc[2];
  double box[4];
  double m_box[4];
  int num_cells[2];
  int halo_cells[4] = {1,1,1,1};
  int num_particles[2];
  int sfactor = 2;

  GridData grid_data;
  Node** grid;

  InitialParticleData ipart_data;
  Particle* particles;
  Particle* post_particles;
  Particle* particle_list;
  Particle* rhalo_parts[8];
  Particle* shalo_parts[8];

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  MPI_Request halo_req[8][2];
  MPI_Status halo_stat[8][2];

  max_iter = (int)(max_time/dt);

  if(rank == 0){
    if(argc == 3){
      num_proc[0] = atoi(argv[1]);
      num_proc[1] = atoi(argv[2]);
    }else if(argc == 6){
      num_proc[0] = atoi(argv[1]);
      num_proc[1] = atoi(argv[2]);
      domain_num_cells[0] = atoi(argv[3]);
      domain_num_cells[1] = atoi(argv[4]);
      max_iter = atoi(argv[5]);
    }
  }

  MPI_Bcast(num_proc,         2, MPI_INT, 0, MPI_COMM_WORLD);
  MPI_Bcast(domain_num_cells, 2, MPI_INT, 0, MPI_COMM_WORLD);
  MPI_Bcast(&max_iter,        1, MPI_INT, 0, MPI_COMM_WORLD);
  MPI_Barrier(MPI_COMM_WORLD);
 
  grid_data.gravity[0] = 0;
  grid_data.gravity[1] = -900.8;
  grid_data.cell_dim[0] = (domain_box[2] - domain_box[0])/domain_num_cells[0];
  grid_data.cell_dim[1] = (domain_box[3] - domain_box[1])/domain_num_cells[1];

  test_px = grid_data.cell_dim[0]/pp_cell[0];
  test_py = grid_data.cell_dim[1]/pp_cell[1];

  domain_num_particles[0] = (int)((domain_m_box[2] - domain_m_box[0])/test_px);
  domain_num_particles[1] = (int)((domain_m_box[3] - domain_m_box[1])/test_py);

  ipart_dim[0] = (domain_m_box[2] - domain_m_box[0])/domain_num_particles[0];
  ipart_dim[1] = (domain_m_box[3] - domain_m_box[1])/domain_num_particles[1];


  decomposeGrid(rank, num_proc, domain_num_cells, num_cells, domain_box, box, halo_cells, &grid_data);
  decomposeMaterial(box, domain_m_box, m_box, ipart_dim, num_particles);

  ipart_data.density = 1000;
  ipart_data.bulk = 3;
  ipart_data.shear = 4;
  ipart_data.E = 90000;
  ipart_data.poisson = .30;
  ipart_data.idim[0] = ipart_dim[0];
  ipart_data.idim[1] = ipart_dim[1];
  ipart_data.velocity[0] = 0;
  ipart_data.velocity[1] = 0;
  ipart_data.box[0] = m_box[0];
  ipart_data.box[1] = m_box[1];
  ipart_data.box[2] = m_box[2];
  ipart_data.box[3] = m_box[3];
  ipart_data.num_particles[0] = num_particles[0];
  ipart_data.num_particles[1] = num_particles[1];
  ipart_data.domain_num_particles[0] = domain_num_particles[0];
  ipart_data.domain_num_particles[1] = domain_num_particles[1];

  grid = createGrid(&grid_data, box, num_cells);
  particles = createMaterial(&grid_data, &ipart_data);
  post_particles = createMaterial(&grid_data, &ipart_data);

  initializeGrid(&grid_data, grid);
	initializeMaterial(&grid_data, &ipart_data, particles);
  
  //allocate halo particles
  allocateHaloParticles(&grid_data, sfactor, pp_cell, rhalo_parts, shalo_parts);
  
  file_index = 0;

  start_time = MPI_Wtime();
  for(iter = 0; iter <= max_iter; iter++){
    gatherHaloParticles(&grid_data, particles, rhalo_parts, shalo_parts);
    sendRecvParticles(&grid_data, rhalo_parts, shalo_parts);
    clearGridValues(&grid_data, grid);
    mapToGrid(&grid_data, grid, particles);
    for(i = 0; i < 8; i++){
      if(grid_data.rank[i] >= 0 && rhalo_parts[i][0].particle_count > 0){
        mapToGrid(&grid_data, grid, rhalo_parts[i]);
      }
    }
    momentumToVelocityOnGrid(&grid_data, grid);
    computeForces(&grid_data, grid, particles);
    for(i = 0; i < 8; i++){
      if(grid_data.rank[i] >= 0 && rhalo_parts[i][0].particle_count > 0){
        computeForces(&grid_data, grid, rhalo_parts[i]);
      }
    }
    computeAcceleration(&grid_data, grid);

    /**
    particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1],
                                    particles, post_particles);
    if(rank == 0){
      //if(iter%100 == 0){
      sprintf(p_filename, "ppart%06d.vtk", file_index);
      //sprintf(p_filename2, "center%06d.vtk", file_index);
      //sprintf(g_filename, "grid_output%06d.vtk", file_index);
      //writeParticlesVtkFile(&grid_data, grid, rhalo_parts[0], p_filename);
      writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename);
      //writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename);
      //writeParticlesVtkFile(&grid_data, grid, particles, p_filename);
      //writeGridVtkFile(&grid_data, grid, g_filename);
      //writeGridVtkFile(&grid_data, grid, g_filename);
      //free(particle_list);
      file_index++;
      //}
    }
    **/

    updateNodalValues(&grid_data, grid, dt);
    updateStressAndStrain(&grid_data, grid, particles, dt);
    pUpdateParticlePosition(&grid_data, grid, particles, post_particles, shalo_parts, dt);
    sendRecvParticles(&grid_data, rhalo_parts, shalo_parts);
    updateParticleList(&grid_data, particles, rhalo_parts);

    /**
    particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1],
                                    particles, post_particles);
    if(rank == 0){
      sprintf(p_filename, "particle_output%06d.vtk", file_index);
      file_index++;
      //sprintf(g_filename, "grid_output%06d.vtk", file_index);
      writeParticlesVtkFile(&grid_data, grid, particles, p_filename);
      //writeParticlesVtkFile(&grid_data, grid, particle_list, p_filename);
      //writeParticlesVtkFile(&grid_data, grid, particles, p_filename);
      //writeGridVtkFile(&grid_data, grid, g_filename);
      free(particle_list);
    }
    **/

    MPI_Barrier(MPI_COMM_WORLD);
  }
  end_time = MPI_Wtime();

  MPI_Barrier(MPI_COMM_WORLD);
  //particle_list = gatherParticles(rank, size, domain_num_particles[0] * domain_num_particles[1],
  //                                particles, post_particles);
  if(rank == 0){
    printf("Parallel, np: %d, iterations: %d, time: %f\n", size, max_iter, end_time-start_time);
    //writeParticlesVtkFile(&grid_data, grid, particle_list, "pparts.vtk");
    //free(particle_list);
  }

  
  freeGrid(grid, &grid_data);
  freeMaterial(particles);
  freeMaterial(post_particles);
  freeHaloParticles(&grid_data, rhalo_parts, shalo_parts);

  //MPI_Barrier(MPI_COMM_WORLD);
  MPI_Finalize();

  return 0;
}
Example #15
0
void OpenCloth::step( float deltaTime ) {
	computeForces(deltaTime);
	integrateVerlet(deltaTime);
	provotDynamicInverse();
}