int test_distribution( char *file_in, char *file_vtk_out, int *local_global_index,
                       int local_num_elems, double *cgup_local ) {
    // Global variables for reading from file
    int nintci, nintcf, nextci, nextcf;
    int **lcc;
    double *bs, *be, *bn, *bw, *bh, *bl, *bp, *su;

    int points_count, **points, *elems;
    double *distr;

    int i;

    // read-in the input file
    int f_status = read_binary_geo( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc,
                                    &bs, &be, &bn, &bw, &bl, &bh, &bp, &su,
                                    &points_count, &points, &elems );

    if( f_status != 0 ) {
        return f_status;
    }

    // Free unnecessary global data
    for( i = nintci; i <= nintcf; i++ ) {
        free( lcc[i] );
    }
    free( lcc );
    free( bs );
    free( be );
    free( bn );
    free( bw );
    free( bh );
    free( bl );
    free( bp );
    free( su );

    // Allocate and fill distr
    if( ( distr = ( double * ) calloc( nintcf - nintci + 1, sizeof( double ) ) ) == NULL ) {
        fprintf( stderr, "malloc(distr) failed\n" );
        return -1;
    }

    for( i = 0; i < local_num_elems; i++ ) {
        distr[local_global_index[i]] = cgup_local[i];
    }

    // Write vtk file
    vtk_write_unstr_grid_header( "test_distribution", file_vtk_out, nintci, nintcf, points_count,
                                 points, elems );
    vtk_append_double( file_vtk_out, "CGUP", nintci, nintcf, distr );

    // Free the rest of global data
    for( i = 0; i < points_count; i++ ) {
        free( points[i] );
    }
    free( points );
    free( elems );
    free( distr );

    return 0;
}
示例#2
0
int test_distribution(char *file_in, char *file_vtk_out, int *local_global_index, int num_elems,
                      double *cgup) {
    int i;
    // Read the geometry from the input file

    /** Simulation parameters parsed from the input datasets */
    int nintci, nintcf;  /// internal cells start and end index
    /// external cells start and end index. The external cells are only ghost cells.
    /// They are accessed only through internal cells
    int nextci, nextcf;
    int **lcc;  /// link cell-to-cell array - stores neighboring information
    /// Boundary coefficients for each volume cell (South, East, North, West, High, Low)
    double *bs, *be, *bn, *bw, *bl, *bh;
    double *bp;  /// Pole coefficient
    double *su;  /// Source values
    /** Geometry data */
    int points_count;  /// total number of points that define the geometry
    int** points;  /// coordinates of the points that define the cells - size [points_cnt][3]
    int* elems;  /// definition of the cells using their nodes (points) - each cell has 8 points
    double* distr;

    int read_input = read_binary_geo(file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be,
                                     &bn, &bw, &bl, &bh, &bp, &su, &points_count, &points, &elems);

    if (read_input != 0)
        printf("Could not read input file in test distribution");

    // allocate the distr vector and initialize it with zeros
    if ((distr = (double*) calloc(sizeof(double), nintcf - nintci + 1)) == NULL ) {
        fprintf(stderr, "calloc failed to allocate distr");
        return -1;
    }

    // copy the locally initialized CGUP vector to the right place in the distr array
    int ind;
    for (i = 0; i < num_elems; i++) {
        ind = local_global_index[i];
        distr[ind] = cgup[i];
    }

    // write the vtk header
    const char experiment_name[] = "test for distribution";
    vtk_write_unstr_grid_header(experiment_name, file_vtk_out, nintci, nintcf, points_count, points,
                                elems);
    // write the values to the vtk file
    vtk_append_double(file_vtk_out, "CGUP", nintci, nintcf, distr);
    return 0;
}
示例#3
0
void finalization(char* file_in, char* out_prefix, int total_iters, double residual_ratio,
                  int nintci, int nintcf, int points_count, int** points, int* elems, double* var,
                  double* cgup, double* su,  int* local_global_index,int num_elems_local) {
    char file_out[100];
    sprintf(file_out, "%s_summary.out", out_prefix);
        int my_rank, num_procs;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);    /// Get current process id
    MPI_Comm_size(MPI_COMM_WORLD, &num_procs);    /// get number of processe
     int num_elems = nintcf-nintci+1;
      int nc_global= 0;
     int i;
    double *su_global = (double*) calloc(sizeof(double), (num_elems));
    double *var_global = (double*) calloc(sizeof(double), (num_elems));
    double *cgup_global = (double*) calloc(sizeof(double), (num_elems));
    
    for (i = 0; i < num_elems_local; i++){
      nc_global = local_global_index[i];
      var_global[nc_global] = var[i];
      su_global[nc_global] = su[i];
      cgup_global[nc_global] = cgup[i];
    }
    double *su_global_sum = (double*) calloc(sizeof(double), (num_elems));
    double *var_global_sum = (double*) calloc(sizeof(double), (num_elems));
    double *cgup_global_sum = (double*) calloc(sizeof(double), (num_elems));
    MPI_Reduce(&var_global[0], &var_global_sum[0], num_elems, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
    MPI_Reduce(&su_global[0], &su_global_sum[0], num_elems, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
    MPI_Reduce(&cgup_global[0], &cgup_global_sum[0], num_elems, MPI_DOUBLE, MPI_SUM,0, MPI_COMM_WORLD);
     if (my_rank == 0){
   int status = store_simulation_stats(file_in, file_out, nintci, nintcf, var_global, total_iters,
                                        residual_ratio);

    sprintf(file_out, "%s_data.vtk", out_prefix);
    
    

    vtk_write_unstr_grid_header(file_in, file_out, nintci, nintcf, points_count, points, elems);
    vtk_append_double(file_out, "CGUP", nintci, nintcf, cgup_global_sum);
    }
    free(su_global);
    free(var_global);
    free(cgup_global);
    free(su_global_sum);
    free(var_global_sum);
    free(cgup_global_sum);
    
   // if ( status != 0 ) fprintf(stderr, "Error when trying to write to file %s\n", file_out);
}
int test_distribution(char *file_in, char *file_vtk_out, int *local_global_index, int num_elems,
                      double *cgup) {
    int nintci;
    int nintcf;
    int nextci;
    int nextcf;
    int** lcc;
    double* bs;
    double* be;
    double* bn;
    double* bw;
    double* bl;
    double* bh;
    double* bp;

    double* su;
    int points_count;
    int** points;
    int* elems;

    double* v = NULL;

    int f_status = read_binary_geo(file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc,
                                   &bs, &be, &bn, &bw,
                                   &bl, &bh, &bp,
                                   &su, &points_count,
                                   &points, &elems);

    int my_rank;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);    /// Get current process id

    vtk_write_unstr_grid_header(file_in, file_vtk_out, 0, nintcf, points_count, points, elems);

    v = (double*) malloc( (size_t)(nintcf+1) * sizeof(double));

    int i;
    for ( i = 0; i <= num_elems; ++i ) {
        v[local_global_index[i]] = cgup[i];
    }


    vtk_append_double(file_vtk_out, "partition", 0, nintcf, v);

    free(v);

    return 0;
}
示例#5
0
void finalization(char* file_in, char* out_prefix, int total_iters, double residual_ratio,
                  int nintci, int nintcf, int points_count, int** points, int* elems, double* var,
                  double* cgup, double* su, double *bp) {
    char file_out[100];
    sprintf(file_out, "%s_summary.out", out_prefix);

//    int status = store_simulation_stats(file_in, file_out, nintci, nintcf, var, total_iters,
  //                                      residual_ratio);

    sprintf(file_out, "%s_data.vtk", out_prefix);
    vtk_write_unstr_grid_header(file_in, file_out, nintci, nintcf, points_count, points, elems);
    vtk_append_double(file_out, "CGUP", nintci, nintcf, cgup);
    vtk_append_double(file_out, "var", nintci, nintcf, var);
    vtk_append_double(file_out, "bp", nintci, nintcf, bp);

    printf("Number of iterations: %d\n", total_iters);

   // if ( status != 0 ) fprintf(stderr, "Error when trying to write to file %s\n", file_out);
}
int test_communication( char *file_in, char *file_vtk_out, int *local_global_index,
                        int local_num_elems, int neighbors_count, int *send_count, int **send_list,
                        int *recv_count, int **recv_list ) {
    // Global variables for reading from file
    int nintci, nintcf, nextci, nextcf;
    int **lcc;
    double *bs, *be, *bn, *bw, *bh, *bl, *bp, *su;

    int points_count, **points, *elems;
    double *commlist;

    int i, j;

    // read-in the input file
    int f_status = read_binary_geo( file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc,
                                    &bs, &be, &bn, &bw, &bl, &bh, &bp, &su,
                                    &points_count, &points, &elems );

    if( f_status != 0 ) {
        return f_status;
    }

    // Free unnecessary global data
    for( i = nintci; i <= nintcf; i++ ) {
        free( lcc[i] );
    }
    free( lcc );
    free( bs );
    free( be );
    free( bn );
    free( bw );
    free( bh );
    free( bl );
    free( bp );
    free( su );

    // Allocate and fill commlist
    if( ( commlist = ( double * ) calloc( nintcf - nintci + 1, sizeof( double ) ) ) == NULL ) {
        fprintf( stderr, "malloc(commlist) failed\n" );
        return -1;
    }

    for( i = 0; i < local_num_elems; i++ ) {
        // internal cells
        commlist[local_global_index[i]] = 15;
    }

    for( i = 0; i < neighbors_count; i++ ) {
        for( j = 0; j < send_count[i]; j++ ) {
            // ghost cell to be sent
            commlist[local_global_index[send_list[i][j]]] = 10;
        }
    }

    for( i = 0; i < neighbors_count; i++ ) {
        for( j = 0; j < recv_count[i]; j++ ) {
            // ghost cell to be received
            commlist[local_global_index[recv_list[i][j]]] = 5;
        }
    }

    // Write vtk file
    vtk_write_unstr_grid_header( "test_communication", file_vtk_out, nintci, nintcf, points_count,
                                 points, elems );
    vtk_append_double( file_vtk_out, "commlist", nintci, nintcf, commlist );

    // Free the rest of global data
    for( i = 0; i < points_count; i++ ) {
        free( points[i] );
    }
    free( points );
    free( elems );
    free( commlist );

    return 0;
}
示例#7
0
int test_distribution(char *file_in, char *file_vtk_out, int *local_global_index,
                      int local_num_elems, double *scalars) {
    
    // global sized variables, for reading the input file
    int nintci_m, nintcf_m;  
    int nextci_m, nextcf_m;
    int **lcc_m; 
    double *bs_m, *be_m, *bn_m, *bw_m, *bh_m, *bl_m;
    double *bp_m;  
    double *su_m;  
    int points_count_m;  
    int** points_m;  
    int* elems_m;  
    int i;

    // read the entire file
    int f_status = read_binary_geo( file_in, &nintci_m, &nintcf_m, &nextci_m,
            &nextcf_m, &lcc_m, &bs_m, &be_m, &bn_m, &bw_m, &bl_m, &bh_m, &bp_m,
            &su_m, &points_count_m, &points_m, &elems_m );
    if ( f_status != 0 ) {
        printf( "Error in reading input file \n" );
        return -1;
    }

    // allocate distribution vector
    double *distr;
    if ( ( distr = (double *) malloc( ( nintcf_m + 1 ) * sizeof(double) ) )
            == NULL ) {
        printf( "malloc failed to allocate distr array" );
        return -1;
    }
    for ( i = nintci_m; i < ( nintcf_m + 1 ); i++ ) {
        distr[i] = 0.0;
    }

    // copy the local values using the generated map
    for ( i = 0; i < local_num_elems; i++ ) {
        distr[local_global_index[i]] = scalars[i];
    }
    // write vtk file
    vtk_write_unstr_grid_header( file_in, file_vtk_out, nintci_m, nintcf_m,
            points_count_m, points_m, elems_m );
    vtk_append_double( file_vtk_out, "SCALARS", nintci_m, nintcf_m, distr );
    printf( "Distribution VTK file succesfully generated! \n" );

    // free the allocated memory
    free( su_m );
    free( bp_m );
    free( bh_m );
    free( bl_m );
    free( bw_m );
    free( bn_m );
    free( be_m );
    free( bs_m );
    free( elems_m );

    for ( i = 0; i < nintcf_m + 1; i++ ) {
        free( lcc_m[i] );
    }
    free( lcc_m );

    for ( i = 0; i < points_count_m; i++ ) {
        free( points_m[i] );
    }
    free( points_m );
    free( distr );

    return 0;
}
示例#8
0
int test_communication(char *file_in, char *file_vtk_out, int *local_global_index, int num_elems,
                       int neighbors_count, int* send_count, int** send_list, int* recv_count, int** recv_list) {
    int i, j, id;
    int my_rank, num_procs;
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);  // Get current process id
    MPI_Comm_size(MPI_COMM_WORLD, &num_procs);  // get number of processes

    // Read the geometry from the input file

    /** Simulation parameters parsed from the input datasets */
    int nintci, nintcf;  /// internal cells start and end index
    /// external cells start and end index. The external cells are only ghost cells.
    /// They are accessed only through internal cells
    int nextci, nextcf;
    int **lcc;  /// link cell-to-cell array - stores neighboring information
    /// Boundary coefficients for each volume cell (South, East, North, West, High, Low)
    double *bs, *be, *bn, *bw, *bl, *bh;
    double *bp;  /// Pole coefficient
    double *su;  /// Source values
    /** Geometry data */
    int points_count;  /// total number of points that define the geometry
    int** points;  /// coordinates of the points that define the cells - size [points_cnt][3]
    int* elems;  /// definition of the cells using their nodes (points) - each cell has 8 points
    double* commlist;
    int ne_g;

    int read_input = read_binary_geo(file_in, &nintci, &nintcf, &nextci, &nextcf, &lcc, &bs, &be,
                                     &bn, &bw, &bl, &bh, &bp, &su, &points_count, &points, &elems);

    if (read_input != 0)
        printf("Could not read input file in test distribution");

    ne_g = nintcf - nintci + 1;
    // allocate the commlist vector and initialize it with zeros
    if ((commlist = (double*) calloc(sizeof(double), ne_g)) == NULL ) {
        fprintf(stderr, "calloc failed to allocate distr");
        return -1;
    }

    // set all internal cells
    for (i = 0; i < num_elems; i++) {
        id = local_global_index[i];  // get global id of the element
        commlist[id] = 15.0;
    }

    // set the elements which are to be sent
    for (i = 0; i < num_procs; i++) {  // for all neighbors in of this process
        for (j = 0; j < send_count[i]; j++) {  // for all elements in the list
            id = send_list[i][j];  // get global id of the element to be sent
            commlist[id] = 10.0;
        }
    }

    // set the elements which are to be received
    for (i = 0; i < num_procs; i++) {  // for all neighbors in of this process
        for (j = 0; j < recv_count[i]; j++) {  // for all elements in the list
            id = recv_list[i][j];  // get global id of the element to be received
            commlist[id] = 5.0;
        }
    }

    // write the vtk header
    const char experiment_name[] = "test for communication";
    vtk_write_unstr_grid_header(experiment_name, file_vtk_out, nintci, nintcf, points_count, points,
                                elems);
    // write the values to the vtk file
    vtk_append_double(file_vtk_out, "commlist", nintci, nintcf, commlist);

    return 0;
}