コード例 #1
0
ファイル: gravity4_.c プロジェクト: tiwanari/soft2
int main(int argc, char *argv[])
{
    const char *space_file = "space.txt";   // 書き出すファイル
    double dt = 1.0;          // 時刻の刻み幅
    const double stop_time = 400;   // 実行時間
    FILE *fp;
    int c;           // オプション指定
    int i;
    double t = 0;
    
    if ((fp = fopen(space_file, "w")) == NULL) {
        fprintf(stderr, "error: cannot open %s.\n", space_file);
        return 1;
    }
    
    // コマンドライン引数の読み込み
    for (i = 0; i < argc; i++) {
        if (strcmp(argv[i], "-d") == 0) {
            if (i + 1 < argc)
                dt = atof(argv[i + 1]); // 刻み幅
        }
    }

    // 繰り返し
    for (i = 0; t <= stop_time; i++, t += dt) {
        update_velocities(dt);
        update_positions(dt);
        if (i % 10 == 0) {
            plot_stars(fp, t);
        }
    }
    
    fclose(fp);
}
コード例 #2
0
ファイル: gravity4.c プロジェクト: opq290/software2
int main(int argc, char *argv[])
{
  const char *space_file = "space.txt";
  FILE *fp;
  if ((fp = fopen(space_file, "w")) == NULL) {
    fprintf(stderr, "error: cannot open %s.\n", space_file);
    return 1;
  }

   double dt;
  const double stop_time = 400;
  int c;
  while((c = getopt(argc,argv,"t:h")) != -1){
    switch(c){
    case 't':
      dt = atof(optarg);
      break;
    case 'h':
      printf ("enter dt\n");
      break;
    }
  }
  int i;
  double t = 0;
  for (i = 0; t <= stop_time; i++, t += dt) {
    update_velocities(dt);
    update_positions(dt);
    if (i % 10 == 0) {
      plot_stars(fp, t);
    }
  }

  fclose(fp);
}
コード例 #3
0
void main(int argc, char *argv[]){
  int t;
  char fname1[100], fname2[100];
  int m = sprintf(fname1,"phi");
  int n = sprintf(fname2,"velocities");

  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&numtasks);
  MPI_Comm_rank(MPI_COMM_WORLD,&taskid);
  numworkers = numtasks - 1;
  allocate_memory_phasefields(MESHX);
#ifdef FLUID
  allocate_memory_FluidVariables(MESHX,pmesh);
#endif
  if(taskid == MASTER) {
    initialize_phasefields();
#ifdef FLUID
    initialize_velocities(MESHX);
#endif
    mpi_distribute(MESHX);
    for (t = 0; t <= phi_timesteps; t++){
#ifdef FLUID
      gauss_siedel();
#endif
      if (t%save_phi == 0) {
        receivefrmworker(phi_old);
        receivefrmworker(u_old);
        receivefrmworker(v_old);
        write2file( t, MESHX, phi_old, fname1);
        write2file1( t, MESHX, u_old, v_old, fname2);
      }
    }
  }else {
    mpi_distribute(MESHX);

    for (t = 0; t <= phi_timesteps; t++){
      mpiexchange(taskid, phi_old, MESHX);
      mpiexchange(taskid, mu_old, MESHX);
      boundary_mpi(taskid, phi_old, MESHX);
      boundary_mpi(taskid, mu_old, MESHX);
      laplacian(phi_old, lap_phi, MESHX);
      laplacian(mu_old, lap_mu, MESHX);
#ifdef FLUID
      computeH(u_old,v_old,Hx,Hy);
      RHS_fn(Hx,Hy,rhs_fn,MESHX, pmesh);
      LHS_fn(MESHX, pmesh);
      boundary_pressure(taskid);
      gauss_siedel();
      ns_solver(start, end, phi_old);
      update_velocities(MESHX);
#endif
      solverloop();
      phi_update();
      if (t%save_phi == 0) {
        sendtomaster(taskid, phi_old);
      }
    }
  }
}
コード例 #4
0
ファイル: game.c プロジェクト: pviolette3/angry_pacman
int run_game(GameData *data)
{
  int cur_shot = 0;
  while(cur_shot < data->num_shots)
  {
    Pacman *cur_pac_shot = (data->shots + cur_shot);
    draw_pacman(cur_pac_shot);
    draw_pebbles(data->pebbles, data->num_pebbles);
    *cur_pac_shot->velocity = *(data->old_velocity);
    Velocity *velocity = cur_pac_shot->velocity;
    while(!KEY_PRESSED(START))
    {
      update_velocities(velocity);
      wait_for_vblank();
      draw_user_velocities(data->velocity_frame_x, data->velocity_frame_y, velocity);
      draw_pacman(cur_pac_shot);
    }
    *(data->old_velocity ) = *cur_pac_shot->velocity;//MUST save old shot

    erase_frame(data->velocity_frame_x, data->bg_color);
    erase_frame(data->velocity_frame_y, data->bg_color);

    //now we run simulation
    fill_frame(data->indicator, GREEN);
    int i = 0;
    while(!off_screen(cur_pac_shot->frame))
    {
      for (i = 0; i < data->num_pebbles; i++) {
        PacmanPebble *cur_pebble = (data->pebbles + i);
        check_collision(cur_pac_shot, cur_pebble);
      }
      wait_for_vblank();
      erase_frame(cur_pac_shot->frame, data->bg_color);
      move_shot(cur_pac_shot);
      draw_pebbles(data->pebbles, data->num_pebbles);
      draw_pacman(cur_pac_shot);
   }

    erase_frame(cur_pac_shot->frame, data->bg_color);
    cur_shot++;
  }
  fill_frame(data->indicator, RED);
  return 0;
}
コード例 #5
0
ファイル: gravity.c プロジェクト: opq290/software2
int main()
{
  const char *space_file = "space.txt";
  FILE *fp;
  if ((fp = fopen(space_file, "w")) == NULL) {
    fprintf(stderr, "error: cannot open %s.\n", space_file);
    return 1;
  }

  const double dt = 1.0;
  const double stop_time = 400;

  int i;
  double t = 0;
  for (i = 0; t <= stop_time; i++, t += dt) {
    update_velocities(dt);
    update_positions(dt);
    if (i % 10 == 0) {
      plot_stars(fp, t);
    }
  }

  fclose(fp);
}