Exemple #1
0
void static_test(double aexp){

  // Assign density to grid [or use analytical formula]
  if(sim._analytic_matter_density){
    set_analytical_density_field(sim._Rho, sim._ngrid);
  } else {
    assign_particles_to_grid(sim._Rho, sim._ngrid);
  }

  // Solve for gravitational force
  compute_gravitational_acceleration(aexp);

  if(sim._modified_gravity){
    // Initial guess for modified gravity solver
    make_initial_guess(sim._ScalarField, aexp);

    // Solve for scalar field  
    solve_phi_with_multigrid();

    // Compute fifth-force
    calculate_fifth_force();
  }

  // Dump grids
  if(sim._modified_gravity)
    output_grid(sim._ScalarField, sim._ngrid, "scalarfield_grid.txt");
  output_grid(sim._Rho, sim._ngrid, "rho_grid.txt");
  output_grid(sim._Phi, sim._ngrid, "rho_grid.txt");
}
Exemple #2
0
    void jacobi(
        std::size_t n
      , std::size_t iterations, std::size_t block_size
      , std::string output_filename)
    {
        typedef std::vector<double> vector;

        std::shared_ptr<vector> grid_new(new vector(n * n, 1));
        std::shared_ptr<vector> grid_old(new vector(n * n, 1));

        hpx::util::high_resolution_timer t;
        for(std::size_t i = 0; i < iterations; ++i)
        {
            // MSVC is unhappy if the OMP loop variable is unsigned
#pragma omp parallel for schedule(JACOBI_SMP_OMP_SCHEDULE)
            for(boost::int64_t y = 1; y < boost::int64_t(n-1); ++y)
            {
                      double * dst = &(*grid_new)[y * n];
                const double * src = &(*grid_new)[y * n];
                jacobi_kernel(
                    dst
                  , src
                  , n
                );
            }
            std::swap(grid_new, grid_old);
        }

        report_timing(n, iterations, t.elapsed());
        output_grid(output_filename, *grid_old, n);
   }
Exemple #3
0
/* Run the game */
void run (struct state *st, struct ui *ui) {
  int k = 0;
  int finished = 0;
  while( !finished ) {
    if (time_to_redraw) {
      k++;
      if (k>=1600) k=0;
      
      int slowdown = game_slowdown(st->speed);
      if (k % slowdown == 0 && st->speed != sp_pause) { 
        kings_move(st);
        simulate(st);
        if (st->show_timeline) {
          if (st->time%10 == 0)
            update_timeline(st);
        }
      }
      output_grid(st, ui, k);
      if (st->show_timeline) {
        if (st->time%10 == 0)
          output_timeline(st, ui);
      }
      time_to_redraw = 0;
      win_or_lose_message(st, k);
    }
    finished = update_from_input(st, ui);
	// refresh();
    pause(); // sleep until woken up by SIGALRM
  }
}
Exemple #4
0
/* run client */
void run_client (struct state *st, struct ui *ui, char *s_server_addr, char *s_server_port, char *s_client_port) {
  int sfd; /* file descriptor of the socket */

  int ret_code; /* code returned by a function */
  
  struct addrinfo srv_addr;

  if ((ret_code = client_init_session 
        (&sfd, s_client_port, &srv_addr, s_server_addr, s_server_port)) != 0) {
    perror("Failed to initialize networking");
    return;
  }
  /* non-blocking mode */
  fcntl(sfd, F_SETFL, O_NONBLOCK);
 
  int k = 0;
  int finished = 0;
  int initialized = 0;
  st->time = 0;
  while( !finished ) {
    if (time_to_redraw) {
      k++;
      if (k>=1600) k=0;
      time_to_redraw = 0;
      
      if (k%50 == 0) 
        send_msg_c (sfd, &srv_addr, MSG_C_IS_ALIVE, 0, 0, 0);

      int msg = client_receive_msg_s (sfd, st);
      if (msg == MSG_S_STATE && initialized != 1) {
        initialized = 1;
        ui_init(st, ui);
      }
      if (initialized) {
        output_grid(st, ui, k);
        /*
        if (st->show_timeline) {
          if (st->time%10 == 0)
            output_timeline(st, ui);
        }
        */
        win_or_lose_message(st, k);
      }
    }
    finished = update_from_input_client(st, ui, sfd, &srv_addr);
    pause();
  }

  close(sfd);
}
Exemple #5
0
int main()
{
	double sta = 1.0/64.;//, stb = 1./512.;
	int sa = 65, i;//, sb = 513/*,j*/;
	FILE *outs;
	init(&U,sa,sa);
	init(&Unew,sa,sa);
	//init(&Ub,sb,sb);
	
	init_cond(&U, sa, sa, sta,sta);
	
	memcpy(&Unew,&U,sizeof(Unew));
	for(i = 0; i<7000; i++)
	{
		iteration(&U,&Unew, sa,sa, sta,sta);
		memcpy(&U,&Unew,sizeof(Unew));
	}
	printf("step a done\n");
	//outs = fopen("../output/out1.dat", "w");
	//output_line(U, sa,sa, sta,sta, outs);
	//fclose(outs);
	
	//interpol(&Ub, sb, sb, stb, stb, 	&U, sa-1, sa-1, sta, sta);
	//init_cond(&Ub, sb, sb, stb, stb);

	//freeArr(&Unew, sa);
	//init(&Unew,sb,sb);
	//init_cond(&Unew, sb, sb, stb, stb);
	//memcpy(&Unew,&Ub,sizeof(Ub));

	//for(i = 0; i<500 /*&& (err>0.0005 || err == 0.0)*/ ; i++)
	//{
		//printf("%d/100\n",i);
		//iteration(&Ub,&Unew, sb,sb, stb,stb);
		//memcpy(&Ub,&Unew,sizeof(Unew));
	//}

	outs = fopen("../output/out3.dat", "w");
	output_grid(U, sa,sa, sta,sta, outs);
	fclose(outs);
	printf("pot. output \n");


	outs = fopen("../output/press.dat", "w");
	output_field_color(U, sa,sa, sta,sta, outs);
	fclose(outs);
	printf("pressure output\n");

	
	outs = fopen("../output/field.dat", "w");
	output_field(U, sa,sa, sta,sta, outs);
	fclose(outs);
	printf("field output\n");
	
	
	system("./lines_of_level");
	system("./Plot_field");
	system("./Plot_col");	
	system("./Plot");
	
	return 0;
}
Exemple #6
0
    void jacobi(
        std::size_t n
      , std::size_t iterations, std::size_t block_size
      , std::string output_filename)
    {
        typedef std::vector<double> vector;

        boost::shared_ptr<vector> grid_new(new vector(n * n, 1));
        boost::shared_ptr<vector> grid_old(new vector(n * n, 1));

        typedef std::vector<hpx::shared_future<void> > deps_vector;

        std::size_t n_block = static_cast<std::size_t>(std::ceil(double(n)/block_size));


        boost::shared_ptr<deps_vector> deps_new(
            new deps_vector(n_block, hpx::make_ready_future()));
        boost::shared_ptr<deps_vector> deps_old(
            new deps_vector(n_block, hpx::make_ready_future()));

        hpx::util::high_resolution_timer t;
        for(std::size_t i = 0; i < iterations; ++i)
        {
            for(std::size_t y = 1, j = 0; y < n -1; y += block_size, ++j)
            {
                std::size_t y_end = (std::min)(y + block_size, n - 1);
                std::vector<hpx::shared_future<void> > trigger;
                trigger.reserve(3);
                trigger.push_back((*deps_old)[j]);
                if(j > 0) trigger.push_back((*deps_old)[j-1]);
                if(j + 1 < n_block) trigger.push_back((*deps_old)[j+1]);

                /*
                 * FIXME: dataflow seems to have some raceconditions
                 * left
                (*deps_new)[j]
                    = hpx::dataflow(
                        hpx::util::bind(
                            jacobi_kernel_wrap
                          , range(y, y_end)
                          , n
                          , boost::ref(*grid_new)
                          , boost::cref(*grid_old)
                        )
                      , trigger
                    );
                */

                (*deps_new)[j] = hpx::when_all(std::move(trigger)).then(
                    hpx::launch::async,
                    hpx::util::bind(
                        jacobi_kernel_wrap
                      , range(y, y_end)
                      , n
                      , boost::ref(*grid_new)
                      , boost::cref(*grid_old)
                    )
                );
            }

            std::swap(grid_new, grid_old);
            std::swap(deps_new, deps_old);
        }
        hpx::wait_all(*deps_new);
        hpx::wait_all(*deps_old);

        report_timing(n, iterations, t.elapsed());
        output_grid(output_filename, *grid_old, n);
   }