Example #1
0
void run_resolution(int res, double dt, double t1, double Ra, double Pr, bool do_diagnostic=true) {
  Eqn_IncompressibleNS3DParamsD params;
  Eqn_IncompressibleNS3DD eqn;

  init_params(params, res, Ra, Pr);
  UNITTEST_ASSERT_TRUE(eqn.set_parameters(params));

  int next_frame = 1;
  
  CPUTimer clock;
  CPUTimer step_clock;
  int step_count;
  int start_count=0;
  start_count = eqn.num_steps;
  clock.start();
  global_timer_clear_all();
  step_count = eqn.num_steps;
  step_clock.start();

  set_forge_ahead(true);

  for (double t = 0; t <= t1; t += dt) {
    UNITTEST_ASSERT_TRUE(eqn.advance_one_step(dt));

    if (do_diagnostic) {

      double max_u, max_v, max_w;
      eqn.get_u().reduce_maxabs(max_u);
      eqn.get_v().reduce_maxabs(max_v);
      eqn.get_w().reduce_maxabs(max_w); // not used in any calculations, but useful for troubleshooting

      printf("> Max u = %.12f, Max v = %.12f, Max w = %.12f\n", max_u, max_v, max_w);
      fflush(stdout);

      if (t > next_frame * t1/100) {
        char buff[1024];
        sprintf(buff, "output.%04d.ppm", next_frame);
        printf("%s\n", buff);
        write_slice(buff, eqn.get_temperature());
        next_frame++;
      }
    }
    else {

      if (t > next_frame * t1/100) {
        step_clock.stop();
        printf("ms/step = %f\n", step_clock.elapsed_ms() / (eqn.num_steps - step_count));
        char buff[1024];
        sprintf(buff, "output.%04d.ppm", next_frame);
        global_counter_print();
        global_counter_clear_all();
        printf("%s\n", buff);
        write_slice(buff, eqn.get_temperature());
        next_frame++;

        step_count = eqn.num_steps;
        step_clock.start();
      }

      printf("%.4f%% done\r", t/t1 * 100);
    }
  }
  clock.stop();
  printf("Elapsed sec: %.8f\n", clock.elapsed_sec());
  printf("ms/step = %f\n", clock.elapsed_ms() / (eqn.num_steps - start_count));

  printf("\n............ DONE ...............\n\n");
}