示例#1
0
文件: nbody.c 项目: schuberm/snsc
int main(int argc, char *argv[])
{
   int npts = 1500;
   int nsteps = 500;
   int outevery = 1;
   int simulation = SIM_RANDOM;
   int status;
   int output = 1;
   double dt = 0.01;
   double time = 0.;
   double tote = 0.;

   status = get_options(argc, argv, &npts, &nsteps, &output, &outevery, &simulation, &dt);
   if (status) return 0;

   pca_time tt,t;
   NBody *mydata;


   tick(&t);
   mydata=allocate_nbody(npts);
   printf("mydata has %d particles in a %d-dimensional space.\n",npts,NDIM);
  
   initialize_particles(mydata, npts, simulation);
  
   tick(&tt);
   calculate_forces(mydata, npts);
   calculate_energy(mydata, npts, &tote);
   tock(&tt);

   for (int i=0;i<nsteps;i++)
   {
      nbody_step(mydata,npts,dt);
      calculate_energy(mydata, npts, &tote);
      time += dt;
      if (output) {
         printf("%i\t%g\t%g\t%g\n", i, dt, time, tote);
//         if (!(i % outevery)) display_particles(mydata,1.3,npts);
      }
   }
  
  
   FILE *outfile=fopen("myparticles.txt","w");
   fprintf(outfile,"positions and forces are:\n");
   for (int i=0;i<npts;i++) 
   {
      for (int j=0;j<NDIM;j++)
         fprintf(outfile,"%12.6f ",mydata[i].x[j]);
      fprintf(outfile,"      ");
      for (int j=0;j<NDIM;j++)
         fprintf(outfile,"%12.6f ",mydata[i].f[j]);
      fprintf(outfile,"\n");
   }


   tock(&t);

   return 0;
}
示例#2
0
	BoardState(int num_queens) : _positions(num_queens), _energy(0.0) {
		for(int i = 0; i < num_queens; i++) {
			_positions[i] = i;
		}
		
		calculate_energy();
	}
示例#3
0
  /**
  *  @brief Calculates thermal solution step for a given scene.
  */
  int calculate(cpu_system_t* system, thermal_solution::task_t* task)
  {    
    int n = system->n_step;
    int k = 4;
    if (n < k)
      k = n;
    const float* u = u_matrix[k];

    const int n_meshes = system->scene->n_meshes;

    float* Tresult = task->temperatures;
    float* En = get_step_energy(system, n);
    float* Tn = get_step_temperatures(system, n);
    
    int r = 0;
    if ((r = calculate_energy(system, Tn, En)) < 0)
      return r;

    for (int m = 0; m != n_meshes; ++m)
    {
      float sum = 0;
      for (int l = 0; l <= k; ++l)
      {
        float* E = get_step_energy(system, n - l);
        sum += u[l] * E[m];
      }

      Tresult[m] = Tn[m] + task->time_delta * sum;
    }

    float* Tnext = get_step_temperatures(system, n + 1);
    memcpy(Tnext, Tresult, sizeof(float) * n_meshes);
    task->n_step = ++system->n_step;
 
    return THERMAL_SOLUTION_OK;
  }
示例#4
0
	BoardState(std::vector<int> positions) : 
	_positions(positions),
	_energy(0.0) {
		
		calculate_energy();
	}