/*============================================================================= * Initial Information Routines *===========================================================================*/ int ne_get_init_info(int neid, /* NemesisI file ID */ int * num_proc, /* Number of processors */ int * num_proc_in_f, /* Number of procs in this file */ char *ftype) { return ex_get_init_info(neid, num_proc, num_proc_in_f, ftype); }
int ne_test_giinf(int fileid) { int error, nproc, nprocf; char ftype[2]; /*-----------------------------Execution Begins-----------------------------*/ error = ex_get_init_info(fileid, &nproc, &nprocf, ftype); if (error < 0) return error; if (nproc != NPROC) return -1; if (nprocf != NPROCF) return -1; if (strcmp(ftype, "s") != 0) return -1; return 0; }
void NemSpread<T,INT>::read_proc_init(int lb_exoid, int proc_info[], int **proc_ids_ptr) /*---------------------------------------------------------------------------- * read_proc_init: * * This function reads information about the processor configuration * which the load balance was generated for and makes assignments for each * processor. *---------------------------------------------------------------------------- * Variable Glossary (after return): * * proc_info[0] = # procs, from load balance file * proc_info[1] = # procs for, from load balance file * proc_info[2] = # procs this processor is responsible for * proc_info[3] = # of extra procs * */ { const char *yo="read_proc_init"; char ftype[2]; if(ex_get_init_info(lb_exoid, &proc_info[0], &proc_info[1], ftype) < 0) { fprintf(stderr, "%s: ERROR, could not get init info!\n", yo); exit(1); } /* Calculate which processor is responsible for what */ proc_info[2] = proc_info[0]; int *proc_ids = (int *)array_alloc(__FILE__, __LINE__, 1, proc_info[2], sizeof(int)); for(int i1=0; i1 < proc_info[2]; i1++) proc_ids[i1] = i1; *proc_ids_ptr = proc_ids; return; } /* End of read_proc_init() *************************************************/
bool exodus_file_query(const char* filename, size_t* real_size, float* version, int* num_mpi_processes, real_array_t* times) { set_ex_opts(); if (!file_exists(filename)) return false; bool valid = true; bool is_parallel = false; int my_real_size = (int)sizeof(real_t); int io_real_size = 0; #if POLYMEC_HAVE_MPI MPI_Info info; MPI_Info_create(&info); int id = ex_open_par(filename, EX_READ, &my_real_size, &io_real_size, version, MPI_COMM_WORLD, info); // Did that work? If not, try the serial opener. if (id < 0) { MPI_Info_free(&info); id = ex_open(filename, EX_READ, &my_real_size, &io_real_size, version); } else is_parallel = true; #else int id = ex_open(filename, EX_READ, &my_real_size, &io_real_size, version); #endif if (id < 0) valid = false; else { *real_size = (size_t)io_real_size; // Make sure that the file has 3D data. ex_init_params mesh_info; int status = ex_get_init_ext(id, &mesh_info); if ((status < 0) || (mesh_info.num_dim != 3)) valid = false; else { // Make sure that each of the element blocks in this file have // valid 3D element types. int num_elem_blocks = (int)mesh_info.num_elem_blk; int elem_block_ids[num_elem_blocks]; ex_get_ids(id, EX_ELEM_BLOCK, elem_block_ids); for (int i = 0; i < num_elem_blocks; ++i) { int elem_block = elem_block_ids[i]; char elem_type_name[MAX_NAME_LENGTH+1]; int num_elem, num_nodes_per_elem, num_faces_per_elem; ex_get_block(id, EX_ELEM_BLOCK, elem_block, elem_type_name, &num_elem, &num_nodes_per_elem, NULL, &num_faces_per_elem, NULL); fe_mesh_element_t elem_type = get_element_type(elem_type_name); if (elem_type == FE_INVALID) { valid = false; break; } } if (valid) { // Query the number of processes for which this file has data. // Recently, we've had to add guards to check to see whether // DIM_NUM_PROCS exists in the file. If it doesn't, we assume that // the file corresponds to a serial data set. int num_proc_in_file; char file_type[2]; int dim_id, status1 = nc_inq_dimid(id, DIM_NUM_PROCS, &dim_id); if (status1 == NC_NOERR) { ex_get_init_info(id, num_mpi_processes, &num_proc_in_file, file_type); if (is_parallel) { ASSERT(*num_mpi_processes == num_proc_in_file); } } else { *num_mpi_processes = num_proc_in_file = 1; } if (times != NULL) { // Ask for the times within the file. int num_times = (int)ex_inquire_int(id, EX_INQ_TIME); real_array_resize(times, num_times); if (num_times > 0) { ex_get_all_times(id, times->data); } } } } ex_close(id); } #if POLYMEC_HAVE_MPI if (is_parallel) MPI_Info_free(&info); #endif return valid; }
char *do_exodus_meta(char *filename) { int exoid; int ndim, nnodes, nelems, nblks, nnsets, nssets; char *title; symrec *ptr; int *ids = NULL; /* * Open the specified exodusII file, read the metadata and set * variables for each item. * Examples include "node_count", "element_count", ... */ exoid = open_exodus_file(filename); if (exoid < 0) return ""; /* read database paramters */ title = (char *)calloc ((MAX_LINE_LENGTH+1),sizeof(char *)); ex_get_init(exoid,title,&ndim,&nnodes,&nelems,&nblks,&nnsets,&nssets); ptr = putsym("ex_title", SVAR, 0); ptr->value.svar = title; ptr = putsym("ex_dimension", VAR, 0); ptr->value.var = ndim; ptr = putsym("ex_node_count", VAR, 0); ptr->value.var = nnodes; ptr = putsym("ex_element_count", VAR, 0); ptr->value.var = nelems; ptr = putsym("ex_block_count", VAR, 0); ptr->value.var = nblks; ptr = putsym("ex_nset_count", VAR, 0); ptr->value.var = nnsets; ptr = putsym("ex_sset_count", VAR, 0); ptr->value.var = nssets; { /* Nemesis Information */ int proc_count; int proc_in_file; char file_type[MAX_STR_LENGTH+1]; int global_nodes; int global_elements; int global_blocks; int global_nsets; int global_ssets; int error; error = ex_get_init_info(exoid, &proc_count, &proc_in_file, file_type); if (error >= 0) { ptr = putsym("ex_processor_count", VAR, 0); ptr->value.var = proc_count; ex_get_init_global(exoid, &global_nodes, &global_elements, &global_blocks, &global_nsets, &global_ssets); ptr = putsym("ex_node_count_global", VAR, 0); ptr->value.var = global_nodes; ptr = putsym("ex_element_count_global", VAR, 0); ptr->value.var = global_elements; } } /* * Read The Element Blocks And Set Variables For Those Also. * The Scheme Is: * -- 'Ex_Block_Ids' Is A List Of Ids. Due To Aprepro Limitations, * This List Is A String, Not An Integer List... * -- Each Block Is Named 'Ex_Block_X' Where X Is Replaced By The * Blocks Position In The List. For Example, The First Block Will * Be Named 'Ex_Block_1' * * -- Each Block Will Have The Following Symbols: * -- Ex_Block_X_Id = Id Of This Element Block * -- Ex_Block_X_Name = Composed Name "Block_" + Id * -- Ex_Block_X_Element_Count = Number Of Elements In Block * -- Ex_Block_X_Nodes_Per_Element = Number Of Nodes Per Element * -- Ex_Block_X_Topology = Type Of Elements In Block * (Lowercased) * -- Ex_Block_X_Attribute_Count = Number Of Attributes. */ ids = malloc(nblks * sizeof(int)); ex_get_elem_blk_ids (exoid, ids); { int i; char *buffer = NULL; char cid[33]; /* arbitrary size, large enough for INT_MAX */ int size = 2048; char *tmp = NULL; buffer = calloc(size, sizeof(char)); if (buffer != NULL) { for (i=0; i < nblks; i++) { sprintf(cid, "%d ", ids[i]); if (strlen(buffer) + strlen(cid) +1 > size) { if (realloc(buffer, size *=2) == NULL) { free(buffer); yyerror("Error allocating memory."); } memset(&buffer[size/2], 0, size/2); } strcat(buffer, cid); } NEWSTR(buffer, tmp); ptr = putsym("ex_block_ids", SVAR, 0); ptr->value.svar = tmp; free(buffer); } } { int i; char var[128]; char type[MAX_STR_LENGTH+1]; char *tmp = NULL; int nel; int nnel; int natr; for (i=0; i < nblks; i++) { ex_get_elem_block(exoid, ids[i], type, &nel, &nnel, &natr); sprintf(var, "ex_block_seq_%d_id", i+1); ptr = putsym(var, VAR, 0); ptr->value.var = ids[i]; sprintf(var, "ex_block_%d_name", ids[i]); ptr = putsym(var, SVAR, 0); sprintf(var, "block_%d", ids[i]); NEWSTR(var, tmp); ptr->value.svar = tmp; sprintf(var, "ex_block_%d_element_count", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = nel; sprintf(var, "ex_block_%d_nodes_per_element", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = nnel; sprintf(var, "ex_block_%d_topology", ids[i]); ptr = putsym(var, SVAR, 0); NEWSTR(type, tmp); /* lowercase the string */ LowerCaseTrim(tmp); ptr->value.svar = tmp; sprintf(var, "ex_block_%d_attribute_count", ids[i]); ptr = putsym(var, VAR, 0); ptr->value.var = natr; } } if (ids != NULL) free(ids); { /* Get timestep count */ int ts_count = ex_inquire_int(exoid, EX_INQ_TIME); ptr = putsym("ex_timestep_count", VAR, 0); ptr->value.var = ts_count; if (ts_count > 0) { int i; symrec *format = getsym("_FORMAT"); char *buffer = NULL; char cid[33]; /* arbitrary size, large enough for double... */ int size = 2048; char *tmp = NULL; double *timesteps = malloc(ts_count * sizeof(double)); ex_get_all_times(exoid, timesteps); buffer = calloc(size, sizeof(char)); if (buffer != NULL) { for (i=0; i < ts_count; i++) { sprintf(cid, format->value.svar, timesteps[i]); if (strlen(buffer) + strlen(cid) +2 > size) { if (realloc(buffer, size *=2) == NULL) { free(buffer); yyerror("Error allocating memory."); } memset(&buffer[size/2], 0, size/2); } strcat(buffer, cid); strcat(buffer, " "); } NEWSTR(buffer, tmp); ptr = putsym("ex_timestep_times", SVAR, 0); ptr->value.svar = tmp; free(buffer); } } } ex_close(exoid); return ""; }