コード例 #1
0
ファイル: PDE.cpp プロジェクト: Iximiel/Tesina-Calcolo2
double PDECond::Passo(){
  for(int i=1; i<X-1;i++){
    for(int j=1; j<Y-1;j++){
      if(M == mSOR)
	succ[i][j] = SOR(i,j);
      else if(M == mGaussSeidel)
	succ[i][j] = GaussSeidel(i,j);
      else
	succ[i][j] = Jacobi(i,j);
    }
  }
  return getErr();//ritorna l'errore la precisione e` decisa dall'utente
}
コード例 #2
0
int main(int argc, char** argv){

  load_conf(argv[1]);

  //Initialisiere Felder
  vector<vector<double> > u_0;
  vector<vector<double> > v_0;
  vector<vector<double> > T;
  init_u(u_0, v_0);
  init_T(T);

  //Erstelle den Temperaturvektor
  std::vector<double> T_Vec = reshape_vector(T);
  //Berechne die BTCS-Matrix
  std::vector<std::vector<double> > M = BCTS_implicit_Matrix(u_0,v_0);
  //Berechne die untere Dreiecksmatrix
  std::vector<std::vector<double> > LD = triangularize(M);

  //Integration
  long int t_start;//TIME LOG
  time(&t_start);
  cout << "W = " << omega<< endl;

  int i_t = 0;//Zähler für die Snapshots
  for(int n=0; n*dt<t_fin; n++){
    //Füge Dirichlet-Randbedingungen in den Vektor ein
    impose_dirichlet(T_Vec,u_0,v_0);
    //Löse das Gleichungssystem
    SOR(T_Vec,M,LD, omega, r_end);

    //Snapshots
    if( (n+1)*dt >= t_snap[i_t] && (n+1)*dt<t_snap[i_t+1]){
      ostringstream snap_name;
      snap_name <<dirname<< (n+1)*dt << "_" << Pe << "_"<< Nx<<"_"<<Ny<<"_"<<dt<<"_"<<b_Q<<".txt";
      save_data(shape_back(T_Vec, T_unten,T_oben), snap_name.str().c_str());
    }
    if((n+1)*dt>=t_snap[i_t]){
      i_t+=1;
    }
  }
  cout<<endl;
  T=shape_back(T_Vec, T_unten, T_oben);
  //TIME LOG
  long int t_finished;
  time(&t_finished);
  cout << "\n\n"<< t_finished-t_start<<endl;
  //print_array(T);
  save_data(T,"aktuell.txt");
  return 0;
}
コード例 #3
0
void driver ( int nx, int ny, int nz, long int it_max, double tol,
              double xlo, double ylo, double zlo,
              double xhi, double yhi, double zhi, int io_interval){
    double *f, *u;
    char * rb;
    int i,j,k;
    double secs = -1.0;
    struct timespec start, finish;

    /* Allocate and initialize  */
    f = ( double * ) malloc ( nx * ny * nz * sizeof ( double ) );  
    u = ( double * ) malloc ( nx * ny * nz * sizeof ( double ) );
    rb = ( char * ) malloc (nx * ny * nz * sizeof ( char ) );

    get_time( &start );
    omp_set_num_threads(6);
    #pragma omp parallel for default(none)\
    	shared(nx, ny, nz, u) private(i, j, k) 
    for ( k = 0; k < nz; k++ ) 
      for ( j = 0; j < ny; j++ ) 
        for ( i = 0; i < nx; i++ ) 
          U(i,j,k) = 0.0;  /* note use of array indexing macro */

    /* set rhs, and exact bcs in u */
    init_prob ( nx, ny, nz, f, u , xlo, ylo, zlo, xhi, yhi, zhi);
    // rb has the red and black positions
    rb_vector(rb, nx, ny, nz);
    /* Solve the Poisson equation  */
    //jacobi ( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval );
    //gauss_seidel ( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval, rb );

    SOR( nx, ny, nz, u, f, tol, it_max, xlo, ylo, zlo, xhi, yhi, zhi, io_interval , rb);
    /* Determine the error  */
    calc_error ( nx, ny, nz, u, f, xlo, ylo, zlo, xhi, yhi, zhi );

    /* get time for initialization and iteration.  */
    get_time(&finish);
    secs = timespec_diff(start,finish);
    printf(" Total time: %15.7e seconds\n",secs);

    free ( u );
    free ( f );
    free (rb);
    return;
}
コード例 #4
0
main(int argc, char *argv[])
{
  int *iterations;
  void SOR(vec_ptr v, int *iterations);
  void SOR_blocked(vec_ptr v, int *iterations, int b);

  long int i, j;
  long int block_size;
  uint64_t acc;
  long int MAXSIZE = N;

  // declare and initialize the vector structure
  vec_ptr v0 = new_vec(MAXSIZE);
  iterations = (int *) malloc(sizeof(int));

  //Get blocked SOR data
  for(i=1000; i<=N; i+=1000) {
    //long int this_size = i - ((i-2)%IDEAL_BLOCK);
    long int this_size = i;
    acc=0;
    for(j=0; j<ITERS; j++) {
      fprintf(stderr, "\n(%d %d)", this_size, j);
      init_vector_rand(v0, this_size);
      set_vec_length(v0, this_size);
      tick();
      SOR(v0, iterations);
      //SOR_blocked(v0, iterations, IDEAL_BLOCK);
      tock();
      acc += get_execution_time();
    }
    //length, time(ns)
    printf("%d, %lld\n", this_size, acc/ ITERS + 0.5);
  }

  printf("\n");
  
}