Esempio n. 1
0
void write_slice(const char *filename, const Grid3DDevice<double> &grid)
{
  Grid3DHost<double> h_grid;
  h_grid.init_congruent(grid);
  h_grid.copy_all_data(grid);


  int nx = grid.nx();
  int ny = grid.ny();
  int nz = grid.nz();

  ImageFile img;
  img.allocate(nx, ny);

  for (int i=0; i < nx; i++)
    for (int j=0; j < ny; j++) {
      double temperature = h_grid.at(i,j,nz/2);
      if (temperature < -2) temperature = -2;
      if (temperature > 2)  temperature = 2;
      //float3 color = make_float3(temperature, temperature, temperature);
      float3 color = hsv_to_rgb(make_float3((temperature)*360, 1, 1));
      //float3 color = pseudo_temperature((temperature+1)*.5);
      img.set_rgb(i,j,(unsigned char)(255*color.x),(unsigned char)(255*color.y),(unsigned char)(255*color.z));
    }

  img.write_ppm(filename);
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  Eqn_Diffusion1DParams params;
  params.h = 1;
  params.nx = 100;
  params.left.type = BC_NEUMANN;
  params.left.value = 0;
  params.right.type = BC_NEUMANN;
  params.right.value = 0;
  params.diffusion_coefficient = 1;

  params.initial_values.init(100, 0);

  int i,t;

  // initialize to an impulse
  for (i=0; i < 100; i++) {
    if (i < 40) params.initial_values.at(i) = 0;
    else if (i < 60) params.initial_values.at(i) = 1;
    else params.initial_values.at(i) = 0;
  }

  Eqn_Diffusion1D eqn;
  if (!eqn.set_parameters(params))
    assert(false);

  ImageFile img;
  img.allocate(100, 800);

  for (t=0; t < 800; t++) {
    eqn.advance(.1);
    eqn.copy_density_to_host();
    
    for (int i=0; i < 100; i++) {
      float soln_val = eqn.density().at(i);
      if (soln_val > 1.0f) soln_val = 1.0f;
      unsigned char color = (unsigned char) (255 * (soln_val / 1.0f));
      img.set_rgb(i,t, color, color, color);
    }
  }


  img.write_ppm("solution.ppm");

  global_timer_print();

  return 0;
}